Skip to content

Commit 449516f

Browse files
committed
rustc_resolve: inject uniform_paths canary always on Rust 2018.
1 parent e0e7cf3 commit 449516f

12 files changed

+236
-6
lines changed

Diff for: src/librustc_resolve/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
194194
// ergonomically unacceptable.
195195
let emit_uniform_paths_canary =
196196
!uniform_paths_canary_emitted &&
197-
uniform_paths &&
197+
self.session.rust_2018() &&
198198
starts_with_non_keyword;
199199
if emit_uniform_paths_canary {
200200
let source = prefix_start.unwrap();

Diff for: src/librustc_resolve/resolve_imports.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
708708
}
709709
}
710710

711+
let uniform_paths_feature = self.session.features_untracked().uniform_paths;
711712
for ((span, _), (name, results)) in uniform_paths_canaries {
712713
self.per_ns(|this, ns| {
713714
let results = &results[ns];
@@ -739,15 +740,24 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
739740
suggestion_choices.push_str(" or ");
740741
}
741742
write!(suggestion_choices, "`self::{}`", name);
742-
err.span_label(span,
743-
format!("can refer to `self::{}`", name));
743+
if uniform_paths_feature {
744+
err.span_label(span,
745+
format!("can refer to `self::{}`", name));
746+
} else {
747+
err.span_label(span,
748+
format!("may refer to `self::{}` in the future", name));
749+
}
744750
}
745751
for &span in &results.block_scopes {
746752
err.span_label(span,
747753
format!("shadowed by block-scoped `{}`", name));
748754
}
749755
err.help(&format!("write {} explicitly instead", suggestion_choices));
750-
err.note("relative `use` paths enabled by `#![feature(uniform_paths)]`");
756+
if uniform_paths_feature {
757+
err.note("relative `use` paths enabled by `#![feature(uniform_paths)]`");
758+
} else {
759+
err.note("in the future, `#![feature(uniform_paths)]` may become the default");
760+
}
751761
err.emit();
752762
});
753763
}
@@ -933,11 +943,15 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
933943
_ => unreachable!(),
934944
};
935945

946+
// Do not record uses from canaries, to avoid interfering with other
947+
// diagnostics or suggestions that rely on some items not being used.
948+
let record_used = !directive.is_uniform_paths_canary;
949+
936950
let mut all_ns_err = true;
937951
self.per_ns(|this, ns| if !type_ns_only || ns == TypeNS {
938952
if let Ok(binding) = result[ns].get() {
939953
all_ns_err = false;
940-
if this.record_use(ident, ns, binding, directive.span) {
954+
if record_used && this.record_use(ident, ns, binding, directive.span) {
941955
if let ModuleOrUniformRoot::Module(module) = module {
942956
this.resolution(module, ident, ns).borrow_mut().binding =
943957
Some(this.dummy_binding);
@@ -949,7 +963,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
949963
if all_ns_err {
950964
let mut all_ns_failed = true;
951965
self.per_ns(|this, ns| if !type_ns_only || ns == TypeNS {
952-
match this.resolve_ident_in_module(module, ident, ns, true, span) {
966+
match this.resolve_ident_in_module(module, ident, ns, record_used, span) {
953967
Ok(_) => all_ns_failed = false,
954968
_ => {}
955969
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// edition:2018
12+
13+
// This test is similar to `ambiguity-macros.rs`, but nested in a module.
14+
15+
mod foo {
16+
pub use std::io;
17+
//~^ ERROR `std` import is ambiguous
18+
19+
macro_rules! m {
20+
() => {
21+
mod std {
22+
pub struct io;
23+
}
24+
}
25+
}
26+
m!();
27+
}
28+
29+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: `std` import is ambiguous
2+
--> $DIR/ambiguity-macros-nested.rs:16:13
3+
|
4+
LL | pub use std::io;
5+
| ^^^ can refer to external crate `::std`
6+
...
7+
LL | / mod std {
8+
LL | | pub struct io;
9+
LL | | }
10+
| |_____________- may refer to `self::std` in the future
11+
|
12+
= help: write `::std` or `self::std` explicitly instead
13+
= note: in the future, `#![feature(uniform_paths)]` may become the default
14+
15+
error: aborting due to previous error
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// edition:2018
12+
13+
// This test is similar to `ambiguity.rs`, but with macros defining local items.
14+
15+
use std::io;
16+
//~^ ERROR `std` import is ambiguous
17+
18+
macro_rules! m {
19+
() => {
20+
mod std {
21+
pub struct io;
22+
}
23+
}
24+
}
25+
m!();
26+
27+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: `std` import is ambiguous
2+
--> $DIR/ambiguity-macros.rs:15:5
3+
|
4+
LL | use std::io;
5+
| ^^^ can refer to external crate `::std`
6+
...
7+
LL | / mod std {
8+
LL | | pub struct io;
9+
LL | | }
10+
| |_________- may refer to `self::std` in the future
11+
|
12+
= help: write `::std` or `self::std` explicitly instead
13+
= note: in the future, `#![feature(uniform_paths)]` may become the default
14+
15+
error: aborting due to previous error
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// edition:2018
12+
13+
// This test is similar to `ambiguity.rs`, but nested in a module.
14+
15+
mod foo {
16+
pub use std::io;
17+
//~^ ERROR `std` import is ambiguous
18+
19+
mod std {
20+
pub struct io;
21+
}
22+
}
23+
24+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: `std` import is ambiguous
2+
--> $DIR/ambiguity-nested.rs:16:13
3+
|
4+
LL | pub use std::io;
5+
| ^^^ can refer to external crate `::std`
6+
...
7+
LL | / mod std {
8+
LL | | pub struct io;
9+
LL | | }
10+
| |_____- may refer to `self::std` in the future
11+
|
12+
= help: write `::std` or `self::std` explicitly instead
13+
= note: in the future, `#![feature(uniform_paths)]` may become the default
14+
15+
error: aborting due to previous error
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// edition:2018
12+
13+
use std::io;
14+
//~^ ERROR `std` import is ambiguous
15+
16+
mod std {
17+
pub struct io;
18+
}
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: `std` import is ambiguous
2+
--> $DIR/ambiguity.rs:13:5
3+
|
4+
LL | use std::io;
5+
| ^^^ can refer to external crate `::std`
6+
...
7+
LL | / mod std {
8+
LL | | pub struct io;
9+
LL | | }
10+
| |_- may refer to `self::std` in the future
11+
|
12+
= help: write `::std` or `self::std` explicitly instead
13+
= note: in the future, `#![feature(uniform_paths)]` may become the default
14+
15+
error: aborting due to previous error
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// edition:2018
12+
13+
struct std;
14+
15+
fn main() {
16+
fn std() {}
17+
enum std {}
18+
use std as foo;
19+
//~^ ERROR `std` import is ambiguous
20+
//~| ERROR `std` import is ambiguous
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error: `std` import is ambiguous
2+
--> $DIR/block-scoped-shadow.rs:18:9
3+
|
4+
LL | struct std;
5+
| ----------- may refer to `self::std` in the future
6+
...
7+
LL | enum std {}
8+
| ----------- shadowed by block-scoped `std`
9+
LL | use std as foo;
10+
| ^^^ can refer to external crate `::std`
11+
|
12+
= help: write `::std` or `self::std` explicitly instead
13+
= note: in the future, `#![feature(uniform_paths)]` may become the default
14+
15+
error: `std` import is ambiguous
16+
--> $DIR/block-scoped-shadow.rs:18:9
17+
|
18+
LL | struct std;
19+
| ----------- may refer to `self::std` in the future
20+
...
21+
LL | fn std() {}
22+
| ----------- shadowed by block-scoped `std`
23+
LL | enum std {}
24+
LL | use std as foo;
25+
| ^^^
26+
|
27+
= help: write `self::std` explicitly instead
28+
= note: in the future, `#![feature(uniform_paths)]` may become the default
29+
30+
error: aborting due to 2 previous errors
31+

0 commit comments

Comments
 (0)