Skip to content

#45829 when a renamed import conflict with a previous import #55113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 23, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
better dummy span detection and remove redundant branch
  • Loading branch information
mockersf committed Oct 22, 2018
commit 8fe6688fcf14508f95db6c96b92f4279ccb0c6be
27 changes: 13 additions & 14 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4779,11 +4779,11 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
if let (
Ok(snippet),
NameBindingKind::Import { directive, ..},
_x @ 1 ... std::u32::MAX,
_dummy @ false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Side note: This could have been just false :)

) = (
cm.span_to_snippet(binding.span),
binding.kind.clone(),
binding.span.hi().0,
binding.span.is_dummy(),
) {
let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() {
format!("Other{}", name)
Expand All @@ -4794,28 +4794,27 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
err.span_suggestion_with_applicability(
binding.span,
&rename_msg,
match (&directive.subclass, snippet.ends_with(";"), snippet.as_ref()) {
(ImportDirectiveSubclass::SingleImport { .. }, false, "self") =>
match (&directive.subclass, snippet.as_ref()) {
(ImportDirectiveSubclass::SingleImport { .. }, "self") =>
format!("self as {}", suggested_name),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imports with self are a simple case, as it's only possible in the form import foo::{ self }

(ImportDirectiveSubclass::SingleImport { source, .. }, false, _) =>
(ImportDirectiveSubclass::SingleImport { source, .. }, _) =>
format!(
"{} as {}",
&snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)],
suggested_name,
),
(ImportDirectiveSubclass::SingleImport { source, .. }, true, _) =>
format!(
"{} as {};",
"{} as {}{}",
&snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)],
suggested_name,
if snippet.ends_with(";") {
";"
} else {
""
}
),
(ImportDirectiveSubclass::ExternCrate { source, target, .. }, _, _) =>
(ImportDirectiveSubclass::ExternCrate { source, target, .. }, _) =>
format!(
"extern crate {} as {};",
source.unwrap_or(target.name),
suggested_name,
),
(_, _, _) => unreachable!(),
(_, _) => unreachable!(),
},
Applicability::MaybeIncorrect,
);
Expand Down