]> git.lizzy.rs Git - rust.git/commitdiff
resolve: Fix bad span arithmetics in import conflict diagnostics
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sun, 25 Nov 2018 01:25:59 +0000 (04:25 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sun, 25 Nov 2018 13:41:16 +0000 (16:41 +0300)
src/librustc_resolve/lib.rs
src/test/ui/issues/issue-45829/import-self.rs
src/test/ui/issues/issue-45829/import-self.stderr

index a392ab717c06c9908ae62890235859318e17974b..443b1ccdef836f6828030678cc4b6e5ab4a4da21 100644 (file)
@@ -4999,10 +4999,10 @@ fn report_conflict<'b>(&mut self,
                 err.span_suggestion_with_applicability(
                     binding.span,
                     &rename_msg,
-                    match (&directive.subclass, snippet.as_ref()) {
-                        (ImportDirectiveSubclass::SingleImport { .. }, "self") =>
+                    match directive.subclass {
+                        ImportDirectiveSubclass::SingleImport { type_ns_only: true, .. } =>
                             format!("self as {}", suggested_name),
-                        (ImportDirectiveSubclass::SingleImport { source, .. }, _) =>
+                        ImportDirectiveSubclass::SingleImport { source, .. } =>
                             format!(
                                 "{} as {}{}",
                                 &snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)],
@@ -5013,13 +5013,13 @@ fn report_conflict<'b>(&mut self,
                                     ""
                                 }
                             ),
-                        (ImportDirectiveSubclass::ExternCrate { source, target, .. }, _) =>
+                        ImportDirectiveSubclass::ExternCrate { source, target, .. } =>
                             format!(
                                 "extern crate {} as {};",
                                 source.unwrap_or(target.name),
                                 suggested_name,
                             ),
-                        (_, _) => unreachable!(),
+                        _ => unreachable!(),
                     },
                     Applicability::MaybeIncorrect,
                 );
index 8b13ffd0076d51c30e8483f6515961c58e05e9c9..eb5fb458d827919f0016e29d788834d911935eb7 100644 (file)
@@ -19,4 +19,7 @@ mod foo {
 
 use foo::self;
 
+use foo::A;
+use foo::{self as A};
+
 fn main() {}
index 985dc4e7131cf8454a1b015e36921e936850bcfd..55e51952a8804712297657372a70d84efd41546d 100644 (file)
@@ -25,7 +25,21 @@ help: you can use `as` to change the binding name of the import
 LL | use foo::{self as other_foo};
    |           ^^^^^^^^^^^^^^^^^
 
-error: aborting due to 3 previous errors
+error[E0252]: the name `A` is defined multiple times
+  --> $DIR/import-self.rs:23:11
+   |
+LL | use foo::A;
+   |     ------ previous import of the type `A` here
+LL | use foo::{self as A};
+   |           ^^^^^^^^^ `A` reimported here
+   |
+   = note: `A` must be defined only once in the type namespace of this module
+help: you can use `as` to change the binding name of the import
+   |
+LL | use foo::{self as OtherA};
+   |           ^^^^^^^^^^^^^^
+
+error: aborting due to 4 previous errors
 
-Some errors occurred: E0255, E0429.
-For more information about an error, try `rustc --explain E0255`.
+Some errors occurred: E0252, E0255, E0429.
+For more information about an error, try `rustc --explain E0252`.