Skip to content

Commit 8fe6688

Browse files
committed
better dummy span detection and remove redundant branch
1 parent 9eacd68 commit 8fe6688

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/librustc_resolve/lib.rs

+13-14
Original file line numberDiff line numberDiff line change
@@ -4779,11 +4779,11 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
47794779
if let (
47804780
Ok(snippet),
47814781
NameBindingKind::Import { directive, ..},
4782-
_x @ 1 ... std::u32::MAX,
4782+
_dummy @ false,
47834783
) = (
47844784
cm.span_to_snippet(binding.span),
47854785
binding.kind.clone(),
4786-
binding.span.hi().0,
4786+
binding.span.is_dummy(),
47874787
) {
47884788
let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() {
47894789
format!("Other{}", name)
@@ -4794,28 +4794,27 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
47944794
err.span_suggestion_with_applicability(
47954795
binding.span,
47964796
&rename_msg,
4797-
match (&directive.subclass, snippet.ends_with(";"), snippet.as_ref()) {
4798-
(ImportDirectiveSubclass::SingleImport { .. }, false, "self") =>
4797+
match (&directive.subclass, snippet.as_ref()) {
4798+
(ImportDirectiveSubclass::SingleImport { .. }, "self") =>
47994799
format!("self as {}", suggested_name),
4800-
(ImportDirectiveSubclass::SingleImport { source, .. }, false, _) =>
4800+
(ImportDirectiveSubclass::SingleImport { source, .. }, _) =>
48014801
format!(
4802-
"{} as {}",
4803-
&snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)],
4804-
suggested_name,
4805-
),
4806-
(ImportDirectiveSubclass::SingleImport { source, .. }, true, _) =>
4807-
format!(
4808-
"{} as {};",
4802+
"{} as {}{}",
48094803
&snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)],
48104804
suggested_name,
4805+
if snippet.ends_with(";") {
4806+
";"
4807+
} else {
4808+
""
4809+
}
48114810
),
4812-
(ImportDirectiveSubclass::ExternCrate { source, target, .. }, _, _) =>
4811+
(ImportDirectiveSubclass::ExternCrate { source, target, .. }, _) =>
48134812
format!(
48144813
"extern crate {} as {};",
48154814
source.unwrap_or(target.name),
48164815
suggested_name,
48174816
),
4818-
(_, _, _) => unreachable!(),
4817+
(_, _) => unreachable!(),
48194818
},
48204819
Applicability::MaybeIncorrect,
48214820
);

0 commit comments

Comments
 (0)