Skip to content

Commit 0a33de0

Browse files
committed
rustc_resolve: inject uniform_paths canaries regardless of the feature-gate, on Rust 2018.
1 parent fb945f0 commit 0a33de0

13 files changed

+237
-7
lines changed

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();

src/librustc_resolve/resolve_imports.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
705705
}
706706
}
707707

708+
let uniform_paths_feature = self.session.features_untracked().uniform_paths;
708709
for ((span, _), (name, results)) in uniform_paths_canaries {
709710
self.per_ns(|this, ns| {
710711
let results = &results[ns];
@@ -736,15 +737,24 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
736737
suggestion_choices.push_str(" or ");
737738
}
738739
write!(suggestion_choices, "`self::{}`", name);
739-
err.span_label(span,
740-
format!("can refer to `self::{}`", name));
740+
if uniform_paths_feature {
741+
err.span_label(span,
742+
format!("can refer to `self::{}`", name));
743+
} else {
744+
err.span_label(span,
745+
format!("may refer to `self::{}` in the future", name));
746+
}
741747
}
742748
for &span in &results.block_scopes {
743749
err.span_label(span,
744750
format!("shadowed by block-scoped `{}`", name));
745751
}
746752
err.help(&format!("write {} explicitly instead", suggestion_choices));
747-
err.note("relative `use` paths enabled by `#![feature(uniform_paths)]`");
753+
if uniform_paths_feature {
754+
err.note("relative `use` paths enabled by `#![feature(uniform_paths)]`");
755+
} else {
756+
err.note("in the future, `#![feature(uniform_paths)]` may become the default");
757+
}
748758
err.emit();
749759
});
750760
}
@@ -930,11 +940,15 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
930940
_ => unreachable!(),
931941
};
932942

943+
// Do not record uses from canaries, to avoid interfering with other
944+
// diagnostics or suggestions that rely on some items not being used.
945+
let record_used = !directive.is_uniform_paths_canary;
946+
933947
let mut all_ns_err = true;
934948
self.per_ns(|this, ns| if !type_ns_only || ns == TypeNS {
935949
if let Ok(binding) = result[ns].get() {
936950
all_ns_err = false;
937-
if this.record_use(ident, ns, binding) {
951+
if record_used && this.record_use(ident, ns, binding) {
938952
if let ModuleOrUniformRoot::Module(module) = module {
939953
this.resolution(module, ident, ns).borrow_mut().binding =
940954
Some(this.dummy_binding);
@@ -946,7 +960,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
946960
if all_ns_err {
947961
let mut all_ns_failed = true;
948962
self.per_ns(|this, ns| if !type_ns_only || ns == TypeNS {
949-
match this.resolve_ident_in_module(module, ident, ns, true, span) {
963+
match this.resolve_ident_in_module(module, ident, ns, record_used, span) {
950964
Ok(_) => all_ns_failed = false,
951965
_ => {}
952966
}
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+

src/tools/rls

Submodule rls updated from 5b5cd9d to fa922de

0 commit comments

Comments
 (0)