rustc_resolve: inject uniform_paths canaries regardless of the feature-gate, on Rust 2018.
This commit is contained in:
parent
fb945f0ebb
commit
0a33de04cf
13 changed files with 237 additions and 7 deletions
|
|
@ -194,7 +194,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
|
|||
// ergonomically unacceptable.
|
||||
let emit_uniform_paths_canary =
|
||||
!uniform_paths_canary_emitted &&
|
||||
uniform_paths &&
|
||||
self.session.rust_2018() &&
|
||||
starts_with_non_keyword;
|
||||
if emit_uniform_paths_canary {
|
||||
let source = prefix_start.unwrap();
|
||||
|
|
|
|||
|
|
@ -705,6 +705,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
|
|||
}
|
||||
}
|
||||
|
||||
let uniform_paths_feature = self.session.features_untracked().uniform_paths;
|
||||
for ((span, _), (name, results)) in uniform_paths_canaries {
|
||||
self.per_ns(|this, ns| {
|
||||
let results = &results[ns];
|
||||
|
|
@ -736,15 +737,24 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
|
|||
suggestion_choices.push_str(" or ");
|
||||
}
|
||||
write!(suggestion_choices, "`self::{}`", name);
|
||||
err.span_label(span,
|
||||
format!("can refer to `self::{}`", name));
|
||||
if uniform_paths_feature {
|
||||
err.span_label(span,
|
||||
format!("can refer to `self::{}`", name));
|
||||
} else {
|
||||
err.span_label(span,
|
||||
format!("may refer to `self::{}` in the future", name));
|
||||
}
|
||||
}
|
||||
for &span in &results.block_scopes {
|
||||
err.span_label(span,
|
||||
format!("shadowed by block-scoped `{}`", name));
|
||||
}
|
||||
err.help(&format!("write {} explicitly instead", suggestion_choices));
|
||||
err.note("relative `use` paths enabled by `#![feature(uniform_paths)]`");
|
||||
if uniform_paths_feature {
|
||||
err.note("relative `use` paths enabled by `#![feature(uniform_paths)]`");
|
||||
} else {
|
||||
err.note("in the future, `#![feature(uniform_paths)]` may become the default");
|
||||
}
|
||||
err.emit();
|
||||
});
|
||||
}
|
||||
|
|
@ -930,11 +940,15 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
|
|||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
// Do not record uses from canaries, to avoid interfering with other
|
||||
// diagnostics or suggestions that rely on some items not being used.
|
||||
let record_used = !directive.is_uniform_paths_canary;
|
||||
|
||||
let mut all_ns_err = true;
|
||||
self.per_ns(|this, ns| if !type_ns_only || ns == TypeNS {
|
||||
if let Ok(binding) = result[ns].get() {
|
||||
all_ns_err = false;
|
||||
if this.record_use(ident, ns, binding) {
|
||||
if record_used && this.record_use(ident, ns, binding) {
|
||||
if let ModuleOrUniformRoot::Module(module) = module {
|
||||
this.resolution(module, ident, ns).borrow_mut().binding =
|
||||
Some(this.dummy_binding);
|
||||
|
|
@ -946,7 +960,7 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
|
|||
if all_ns_err {
|
||||
let mut all_ns_failed = true;
|
||||
self.per_ns(|this, ns| if !type_ns_only || ns == TypeNS {
|
||||
match this.resolve_ident_in_module(module, ident, ns, true, span) {
|
||||
match this.resolve_ident_in_module(module, ident, ns, record_used, span) {
|
||||
Ok(_) => all_ns_failed = false,
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// edition:2018
|
||||
|
||||
// This test is similar to `ambiguity-macros.rs`, but nested in a module.
|
||||
|
||||
mod foo {
|
||||
pub use std::io;
|
||||
//~^ ERROR `std` import is ambiguous
|
||||
|
||||
macro_rules! m {
|
||||
() => {
|
||||
mod std {
|
||||
pub struct io;
|
||||
}
|
||||
}
|
||||
}
|
||||
m!();
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
error: `std` import is ambiguous
|
||||
--> $DIR/ambiguity-macros-nested.rs:16:13
|
||||
|
|
||||
LL | pub use std::io;
|
||||
| ^^^ can refer to external crate `::std`
|
||||
...
|
||||
LL | / mod std {
|
||||
LL | | pub struct io;
|
||||
LL | | }
|
||||
| |_____________- may refer to `self::std` in the future
|
||||
|
|
||||
= help: write `::std` or `self::std` explicitly instead
|
||||
= note: in the future, `#![feature(uniform_paths)]` may become the default
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// edition:2018
|
||||
|
||||
// This test is similar to `ambiguity.rs`, but with macros defining local items.
|
||||
|
||||
use std::io;
|
||||
//~^ ERROR `std` import is ambiguous
|
||||
|
||||
macro_rules! m {
|
||||
() => {
|
||||
mod std {
|
||||
pub struct io;
|
||||
}
|
||||
}
|
||||
}
|
||||
m!();
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
error: `std` import is ambiguous
|
||||
--> $DIR/ambiguity-macros.rs:15:5
|
||||
|
|
||||
LL | use std::io;
|
||||
| ^^^ can refer to external crate `::std`
|
||||
...
|
||||
LL | / mod std {
|
||||
LL | | pub struct io;
|
||||
LL | | }
|
||||
| |_________- may refer to `self::std` in the future
|
||||
|
|
||||
= help: write `::std` or `self::std` explicitly instead
|
||||
= note: in the future, `#![feature(uniform_paths)]` may become the default
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// edition:2018
|
||||
|
||||
// This test is similar to `ambiguity.rs`, but nested in a module.
|
||||
|
||||
mod foo {
|
||||
pub use std::io;
|
||||
//~^ ERROR `std` import is ambiguous
|
||||
|
||||
mod std {
|
||||
pub struct io;
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
error: `std` import is ambiguous
|
||||
--> $DIR/ambiguity-nested.rs:16:13
|
||||
|
|
||||
LL | pub use std::io;
|
||||
| ^^^ can refer to external crate `::std`
|
||||
...
|
||||
LL | / mod std {
|
||||
LL | | pub struct io;
|
||||
LL | | }
|
||||
| |_____- may refer to `self::std` in the future
|
||||
|
|
||||
= help: write `::std` or `self::std` explicitly instead
|
||||
= note: in the future, `#![feature(uniform_paths)]` may become the default
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// edition:2018
|
||||
|
||||
use std::io;
|
||||
//~^ ERROR `std` import is ambiguous
|
||||
|
||||
mod std {
|
||||
pub struct io;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
error: `std` import is ambiguous
|
||||
--> $DIR/ambiguity.rs:13:5
|
||||
|
|
||||
LL | use std::io;
|
||||
| ^^^ can refer to external crate `::std`
|
||||
...
|
||||
LL | / mod std {
|
||||
LL | | pub struct io;
|
||||
LL | | }
|
||||
| |_- may refer to `self::std` in the future
|
||||
|
|
||||
= help: write `::std` or `self::std` explicitly instead
|
||||
= note: in the future, `#![feature(uniform_paths)]` may become the default
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// edition:2018
|
||||
|
||||
struct std;
|
||||
|
||||
fn main() {
|
||||
fn std() {}
|
||||
enum std {}
|
||||
use std as foo;
|
||||
//~^ ERROR `std` import is ambiguous
|
||||
//~| ERROR `std` import is ambiguous
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
error: `std` import is ambiguous
|
||||
--> $DIR/block-scoped-shadow.rs:18:9
|
||||
|
|
||||
LL | struct std;
|
||||
| ----------- may refer to `self::std` in the future
|
||||
...
|
||||
LL | enum std {}
|
||||
| ----------- shadowed by block-scoped `std`
|
||||
LL | use std as foo;
|
||||
| ^^^ can refer to external crate `::std`
|
||||
|
|
||||
= help: write `::std` or `self::std` explicitly instead
|
||||
= note: in the future, `#![feature(uniform_paths)]` may become the default
|
||||
|
||||
error: `std` import is ambiguous
|
||||
--> $DIR/block-scoped-shadow.rs:18:9
|
||||
|
|
||||
LL | struct std;
|
||||
| ----------- may refer to `self::std` in the future
|
||||
...
|
||||
LL | fn std() {}
|
||||
| ----------- shadowed by block-scoped `std`
|
||||
LL | enum std {}
|
||||
LL | use std as foo;
|
||||
| ^^^
|
||||
|
|
||||
= help: write `self::std` explicitly instead
|
||||
= note: in the future, `#![feature(uniform_paths)]` may become the default
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -1 +1 @@
|
|||
Subproject commit 5b5cd9d45719414196e254ec17baa598acc8cd25
|
||||
Subproject commit fa922de1e5e1f02b576b7a5aa6ded16935693ec5
|
||||
Loading…
Add table
Add a link
Reference in a new issue