-
Notifications
You must be signed in to change notification settings - Fork 13.3k
#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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cac95ee
#45829 when a renamed import conflict with a previous import
mockersf ad4cea4
apply review
mockersf 2ba567f
fix other tests failing due to change in case or new suggestion for e…
mockersf 4520b30
and style fix
mockersf 9eacd68
manage cases with tabs or other whitespaces
mockersf 8fe6688
better dummy span detection and remove redundant branch
mockersf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1234,7 +1234,7 @@ impl<'a> NameBinding<'a> { | |
match self.kind { | ||
NameBindingKind::Import { | ||
directive: &ImportDirective { | ||
subclass: ImportDirectiveSubclass::ExternCrate(_), .. | ||
subclass: ImportDirectiveSubclass::ExternCrate { .. }, .. | ||
}, .. | ||
} => true, | ||
_ => false, | ||
|
@@ -1248,15 +1248,6 @@ impl<'a> NameBinding<'a> { | |
} | ||
} | ||
|
||
fn is_renamed_extern_crate(&self) -> bool { | ||
if let NameBindingKind::Import { directive, ..} = self.kind { | ||
if let ImportDirectiveSubclass::ExternCrate(Some(_)) = directive.subclass { | ||
return true; | ||
} | ||
} | ||
false | ||
} | ||
|
||
fn is_glob_import(&self) -> bool { | ||
match self.kind { | ||
NameBindingKind::Import { directive, .. } => directive.is_glob(), | ||
|
@@ -3803,7 +3794,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { | |
if let NameBindingKind::Import { directive: d, .. } = binding.kind { | ||
// Careful: we still want to rewrite paths from | ||
// renamed extern crates. | ||
if let ImportDirectiveSubclass::ExternCrate(None) = d.subclass { | ||
if let ImportDirectiveSubclass::ExternCrate { source: None, .. } = d.subclass { | ||
return | ||
} | ||
} | ||
|
@@ -4783,10 +4774,17 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { | |
}; | ||
|
||
let cm = self.session.source_map(); | ||
let rename_msg = "You can use `as` to change the binding name of the import"; | ||
|
||
if let (Ok(snippet), false) = (cm.span_to_snippet(binding.span), | ||
binding.is_renamed_extern_crate()) { | ||
let rename_msg = "you can use `as` to change the binding name of the import"; | ||
|
||
if let ( | ||
Ok(snippet), | ||
NameBindingKind::Import { directive, ..}, | ||
_dummy @ false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Side note: This could have been just |
||
) = ( | ||
cm.span_to_snippet(binding.span), | ||
binding.kind.clone(), | ||
binding.span.is_dummy(), | ||
) { | ||
let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() { | ||
format!("Other{}", name) | ||
} else { | ||
|
@@ -4795,13 +4793,30 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> { | |
|
||
err.span_suggestion_with_applicability( | ||
mockersf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
binding.span, | ||
rename_msg, | ||
if snippet.ends_with(';') { | ||
format!("{} as {};", &snippet[..snippet.len() - 1], suggested_name) | ||
} else { | ||
format!("{} as {}", snippet, suggested_name) | ||
&rename_msg, | ||
match (&directive.subclass, snippet.as_ref()) { | ||
(ImportDirectiveSubclass::SingleImport { .. }, "self") => | ||
format!("self as {}", suggested_name), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imports with |
||
(ImportDirectiveSubclass::SingleImport { source, .. }, _) => | ||
format!( | ||
"{} as {}{}", | ||
&snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)], | ||
suggested_name, | ||
if snippet.ends_with(";") { | ||
";" | ||
} else { | ||
"" | ||
} | ||
), | ||
mockersf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(ImportDirectiveSubclass::ExternCrate { source, target, .. }, _) => | ||
format!( | ||
"extern crate {} as {};", | ||
source.unwrap_or(target.name), | ||
suggested_name, | ||
), | ||
(_, _) => unreachable!(), | ||
}, | ||
Applicability::MachineApplicable, | ||
Applicability::MaybeIncorrect, | ||
); | ||
} else { | ||
err.span_label(binding.span, rename_msg); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source is the optional original name if the import is renamed, target is the name it's imported at (so the original name if there was no rename)