Skip to content

rustc: Fix another double-lint issue with crate:: #50982

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 1 commit into from
May 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,10 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
"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() &&
Expand Down Expand Up @@ -903,7 +906,10 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
return
}
warned = true;
this.lint_path_starts_with_module(directive.id, span);
this.lint_path_starts_with_module(
directive.root_id,
directive.root_span,
);
});
}

Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/rust-2018/edition-lint-nested-paths.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
9 changes: 9 additions & 0 deletions src/test/ui/rust-2018/edition-lint-nested-paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@ use foo::{a, b};
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();
}
}
11 changes: 10 additions & 1 deletion src/test/ui/rust-2018/edition-lint-nested-paths.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

4 changes: 1 addition & 3 deletions src/test/ui/rust-2018/edition-lint-paths.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/rust-2018/edition-lint-paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
23 changes: 7 additions & 16 deletions src/test/ui/rust-2018/edition-lint-paths.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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::*`
Expand All @@ -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`
Expand All @@ -67,13 +58,13 @@ 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`
|
= 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