]> git.lizzy.rs Git - rust.git/commitdiff
rustc: Fix another double-lint issue with `crate::`
authorAlex Crichton <alex@alexcrichton.com>
Tue, 22 May 2018 22:34:30 +0000 (15:34 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 22 May 2018 22:59:51 +0000 (15:59 -0700)
This commit fixes another issue in the `absolute_path_not_starting_with_crate`
lint where it warns twice about an import which may contain `self`. It turns out
there were a few more locations that needed updating to use `root_id` and
`root_span` introduced in #50970 and after that it looks to work like a charm!

Closes #50978

src/librustc_resolve/resolve_imports.rs
src/test/ui/rust-2018/edition-lint-nested-paths.fixed
src/test/ui/rust-2018/edition-lint-nested-paths.rs
src/test/ui/rust-2018/edition-lint-nested-paths.stderr
src/test/ui/rust-2018/edition-lint-paths.fixed
src/test/ui/rust-2018/edition-lint-paths.rs
src/test/ui/rust-2018/edition-lint-paths.stderr

index e87f594ac99ed0f7f07496d52f6315c00a9d8cd3..91de3a34cc84abc48c837bb8a10690809dfce2cf 100644 (file)
@@ -684,7 +684,10 @@ fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> Option<(Spa
                                  "cannot glob-import all possible crates".to_string()));
                 }
                 GlobImport { .. } if self.session.features_untracked().extern_absolute_paths => {
-                    self.lint_path_starts_with_module(directive.id, span);
+                    self.lint_path_starts_with_module(
+                        directive.root_id,
+                        directive.root_span,
+                    );
                 }
                 SingleImport { source, target, .. } => {
                     let crate_root = if source.name == keywords::Crate.name() &&
@@ -903,7 +906,10 @@ fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> Option<(Spa
                     return
                 }
                 warned = true;
-                this.lint_path_starts_with_module(directive.id, span);
+                this.lint_path_starts_with_module(
+                    directive.root_id,
+                    directive.root_span,
+                );
             });
         }
 
index 308f2ac406edfe8588d39512a52a13031f6bf812..2c14e9a982498461ae249d420b7e5510c985d5a5 100644 (file)
@@ -20,9 +20,18 @@ use crate::foo::{a, b};
 mod foo {
     crate fn a() {}
     crate fn b() {}
+    crate fn c() {}
 }
 
 fn main() {
     a();
     b();
+
+    {
+        use crate::foo::{self as x, c};
+        //~^ ERROR absolute paths must start with
+        //~| this was previously accepted
+        x::a();
+        c();
+    }
 }
index df8b585ef6c394141fb1dc31fc8d1b4728c94cf1..611436b03ab1bd502b925a4b3d902e8860f294b8 100644 (file)
 mod foo {
     crate fn a() {}
     crate fn b() {}
+    crate fn c() {}
 }
 
 fn main() {
     a();
     b();
+
+    {
+        use foo::{self as x, c};
+        //~^ ERROR absolute paths must start with
+        //~| this was previously accepted
+        x::a();
+        c();
+    }
 }
index 40d8e4e90e673168e9e92ff9b359e06ad4e0e3b2..185d96690966009fda215e8bc8bc4a590442b77e 100644 (file)
@@ -12,5 +12,14 @@ LL | #![deny(absolute_path_not_starting_with_crate)]
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
    = note: for more information, see issue TBD
 
-error: aborting due to previous error
+error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
+  --> $DIR/edition-lint-nested-paths.rs:31:13
+   |
+LL |         use foo::{self as x, c};
+   |             ^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{self as x, c}`
+   |
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
+   = note: for more information, see issue TBD
+
+error: aborting due to 2 previous errors
 
index 80eb52a3e5d2f943203d62d92d16906ec2941bee..d452ff20fda9ffc608c0729cdd408d57a7af0f63 100644 (file)
@@ -30,11 +30,9 @@ pub mod foo {
     //~| WARN this was previously accepted
     use crate::{bar as something_else};
 
-    use {crate::Bar as SomethingElse, crate::main};
+    use crate::{Bar as SomethingElse, main};
     //~^ ERROR absolute
     //~| WARN this was previously accepted
-    //~| ERROR absolute
-    //~| WARN this was previously accepted
 
     use crate::{Bar as SomethingElse2, main as another_main};
 
index f2ca342635b6c4e9842abd06782a1123e0347823..3d6d5b052bbbaf68fb82f1bfe8f83923015ad905 100644 (file)
@@ -33,8 +33,6 @@ pub mod foo {
     use {Bar as SomethingElse, main};
     //~^ ERROR absolute
     //~| WARN this was previously accepted
-    //~| ERROR absolute
-    //~| WARN this was previously accepted
 
     use crate::{Bar as SomethingElse2, main as another_main};
 
index 9f3bef062cac52e791a7ba302508ab5aa4c065a0..0416e51b1afcdbc94f5234549f20184f24d85afe 100644 (file)
@@ -22,25 +22,16 @@ LL |     use bar;
    = note: for more information, see issue TBD
 
 error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
-  --> $DIR/edition-lint-paths.rs:33:10
+  --> $DIR/edition-lint-paths.rs:33:9
    |
 LL |     use {Bar as SomethingElse, main};
-   |          ^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::Bar as SomethingElse`
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::{Bar as SomethingElse, main}`
    |
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
    = note: for more information, see issue TBD
 
 error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
-  --> $DIR/edition-lint-paths.rs:33:32
-   |
-LL |     use {Bar as SomethingElse, main};
-   |                                ^^^^ help: use `crate`: `crate::main`
-   |
-   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
-   = note: for more information, see issue TBD
-
-error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
-  --> $DIR/edition-lint-paths.rs:47:5
+  --> $DIR/edition-lint-paths.rs:45:5
    |
 LL | use bar::Bar;
    |     ^^^^^^^^ help: use `crate`: `crate::bar::Bar`
@@ -49,7 +40,7 @@ LL | use bar::Bar;
    = note: for more information, see issue TBD
 
 error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
-  --> $DIR/edition-lint-paths.rs:59:9
+  --> $DIR/edition-lint-paths.rs:57:9
    |
 LL |     use *;
    |         ^ help: use `crate`: `crate::*`
@@ -58,7 +49,7 @@ LL |     use *;
    = note: for more information, see issue TBD
 
 error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
-  --> $DIR/edition-lint-paths.rs:64:6
+  --> $DIR/edition-lint-paths.rs:62:6
    |
 LL | impl ::foo::SomeTrait for u32 { }
    |      ^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::SomeTrait`
@@ -67,7 +58,7 @@ LL | impl ::foo::SomeTrait for u32 { }
    = note: for more information, see issue TBD
 
 error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
-  --> $DIR/edition-lint-paths.rs:69:13
+  --> $DIR/edition-lint-paths.rs:67:13
    |
 LL |     let x = ::bar::Bar;
    |             ^^^^^^^^^^ help: use `crate`: `crate::bar::Bar`
@@ -75,5 +66,5 @@ LL |     let x = ::bar::Bar;
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
    = note: for more information, see issue TBD
 
-error: aborting due to 8 previous errors
+error: aborting due to 7 previous errors