Skip to content

Commit e39c959

Browse files
committed
rustc: Fix another double-lint issue with crate::
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
1 parent d034ae5 commit e39c959

7 files changed

+44
-24
lines changed

src/librustc_resolve/resolve_imports.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,10 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
684684
"cannot glob-import all possible crates".to_string()));
685685
}
686686
GlobImport { .. } if self.session.features_untracked().extern_absolute_paths => {
687-
self.lint_path_starts_with_module(directive.id, span);
687+
self.lint_path_starts_with_module(
688+
directive.root_id,
689+
directive.root_span,
690+
);
688691
}
689692
SingleImport { source, target, .. } => {
690693
let crate_root = if source.name == keywords::Crate.name() &&
@@ -903,7 +906,10 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
903906
return
904907
}
905908
warned = true;
906-
this.lint_path_starts_with_module(directive.id, span);
909+
this.lint_path_starts_with_module(
910+
directive.root_id,
911+
directive.root_span,
912+
);
907913
});
908914
}
909915

src/test/ui/rust-2018/edition-lint-nested-paths.fixed

+9
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@ use crate::foo::{a, b};
2020
mod foo {
2121
crate fn a() {}
2222
crate fn b() {}
23+
crate fn c() {}
2324
}
2425

2526
fn main() {
2627
a();
2728
b();
29+
30+
{
31+
use crate::foo::{self as x, c};
32+
//~^ ERROR absolute paths must start with
33+
//~| this was previously accepted
34+
x::a();
35+
c();
36+
}
2837
}

src/test/ui/rust-2018/edition-lint-nested-paths.rs

+9
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@ use foo::{a, b};
2020
mod foo {
2121
crate fn a() {}
2222
crate fn b() {}
23+
crate fn c() {}
2324
}
2425

2526
fn main() {
2627
a();
2728
b();
29+
30+
{
31+
use foo::{self as x, c};
32+
//~^ ERROR absolute paths must start with
33+
//~| this was previously accepted
34+
x::a();
35+
c();
36+
}
2837
}

src/test/ui/rust-2018/edition-lint-nested-paths.stderr

+10-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,14 @@ LL | #![deny(absolute_path_not_starting_with_crate)]
1212
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
1313
= note: for more information, see issue TBD
1414

15-
error: aborting due to previous error
15+
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
16+
--> $DIR/edition-lint-nested-paths.rs:31:13
17+
|
18+
LL | use foo::{self as x, c};
19+
| ^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{self as x, c}`
20+
|
21+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
22+
= note: for more information, see issue TBD
23+
24+
error: aborting due to 2 previous errors
1625

src/test/ui/rust-2018/edition-lint-paths.fixed

+1-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ pub mod foo {
3030
//~| WARN this was previously accepted
3131
use crate::{bar as something_else};
3232

33-
use {crate::Bar as SomethingElse, crate::main};
33+
use crate::{Bar as SomethingElse, main};
3434
//~^ ERROR absolute
3535
//~| WARN this was previously accepted
36-
//~| ERROR absolute
37-
//~| WARN this was previously accepted
3836

3937
use crate::{Bar as SomethingElse2, main as another_main};
4038

src/test/ui/rust-2018/edition-lint-paths.rs

-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ pub mod foo {
3333
use {Bar as SomethingElse, main};
3434
//~^ ERROR absolute
3535
//~| WARN this was previously accepted
36-
//~| ERROR absolute
37-
//~| WARN this was previously accepted
3836

3937
use crate::{Bar as SomethingElse2, main as another_main};
4038

src/test/ui/rust-2018/edition-lint-paths.stderr

+7-16
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,16 @@ LL | use bar;
2222
= note: for more information, see issue TBD
2323

2424
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
25-
--> $DIR/edition-lint-paths.rs:33:10
25+
--> $DIR/edition-lint-paths.rs:33:9
2626
|
2727
LL | use {Bar as SomethingElse, main};
28-
| ^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::Bar as SomethingElse`
28+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::{Bar as SomethingElse, main}`
2929
|
3030
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
3131
= note: for more information, see issue TBD
3232

3333
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
34-
--> $DIR/edition-lint-paths.rs:33:32
35-
|
36-
LL | use {Bar as SomethingElse, main};
37-
| ^^^^ help: use `crate`: `crate::main`
38-
|
39-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
40-
= note: for more information, see issue TBD
41-
42-
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
43-
--> $DIR/edition-lint-paths.rs:47:5
34+
--> $DIR/edition-lint-paths.rs:45:5
4435
|
4536
LL | use bar::Bar;
4637
| ^^^^^^^^ help: use `crate`: `crate::bar::Bar`
@@ -49,7 +40,7 @@ LL | use bar::Bar;
4940
= note: for more information, see issue TBD
5041

5142
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
52-
--> $DIR/edition-lint-paths.rs:59:9
43+
--> $DIR/edition-lint-paths.rs:57:9
5344
|
5445
LL | use *;
5546
| ^ help: use `crate`: `crate::*`
@@ -58,7 +49,7 @@ LL | use *;
5849
= note: for more information, see issue TBD
5950

6051
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
61-
--> $DIR/edition-lint-paths.rs:64:6
52+
--> $DIR/edition-lint-paths.rs:62:6
6253
|
6354
LL | impl ::foo::SomeTrait for u32 { }
6455
| ^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::SomeTrait`
@@ -67,13 +58,13 @@ LL | impl ::foo::SomeTrait for u32 { }
6758
= note: for more information, see issue TBD
6859

6960
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
70-
--> $DIR/edition-lint-paths.rs:69:13
61+
--> $DIR/edition-lint-paths.rs:67:13
7162
|
7263
LL | let x = ::bar::Bar;
7364
| ^^^^^^^^^^ help: use `crate`: `crate::bar::Bar`
7465
|
7566
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
7667
= note: for more information, see issue TBD
7768

78-
error: aborting due to 8 previous errors
69+
error: aborting due to 7 previous errors
7970

0 commit comments

Comments
 (0)