/// Miscellaneous bits of metadata for better ambiguity error reporting.
#[derive(Clone, Copy, PartialEq)]
enum AmbiguityErrorMisc {
+ SuggestCrate,
SuggestSelf,
FromPrelude,
None,
`{ident}` to disambiguate", ident = ident))
}
if b.is_extern_crate() && ident.span.rust_2018() {
- help_msgs.push(format!("use `::{ident}` to refer to this {thing} unambiguously",
- ident = ident, thing = b.descr()))
- }
- if misc == AmbiguityErrorMisc::SuggestSelf {
- help_msgs.push(format!("use `self::{ident}` to refer to this {thing} unambiguously",
- ident = ident, thing = b.descr()))
+ help_msgs.push(format!(
+ "use `::{ident}` to refer to this {thing} unambiguously",
+ ident = ident, thing = b.descr(),
+ ))
+ }
+ if misc == AmbiguityErrorMisc::SuggestCrate {
+ help_msgs.push(format!(
+ "use `crate::{ident}` to refer to this {thing} unambiguously",
+ ident = ident, thing = b.descr(),
+ ))
+ } else if misc == AmbiguityErrorMisc::SuggestSelf {
+ help_msgs.push(format!(
+ "use `self::{ident}` to refer to this {thing} unambiguously",
+ ident = ident, thing = b.descr(),
+ ))
}
if b.span.is_dummy() {
use errors::Applicability;
use std::cell::Cell;
-use std::mem;
+use std::{mem, ptr};
use rustc_data_structures::sync::Lrc;
#[derive(Clone, Debug)]
bitflags! {
struct Flags: u8 {
- const MACRO_RULES = 1 << 0;
- const MODULE = 1 << 1;
- const PRELUDE = 1 << 2;
- const MISC_SUGGEST_SELF = 1 << 3;
- const MISC_FROM_PRELUDE = 1 << 4;
+ const MACRO_RULES = 1 << 0;
+ const MODULE = 1 << 1;
+ const PRELUDE = 1 << 2;
+ const MISC_SUGGEST_CRATE = 1 << 3;
+ const MISC_SUGGEST_SELF = 1 << 4;
+ const MISC_FROM_PRELUDE = 1 << 5;
}
}
path_span,
);
match binding {
- Ok(binding) => Ok((binding, Flags::MODULE)),
+ Ok(binding) => Ok((binding, Flags::MODULE | Flags::MISC_SUGGEST_CRATE)),
Err((Determinacy::Undetermined, Weak::No)) =>
return Err(Determinacy::determined(force)),
Err((Determinacy::Undetermined, Weak::Yes)) =>
self.current_module = orig_current_module;
match binding {
Ok(binding) => {
- let misc_flags = if module.is_normal() {
+ let misc_flags = if ptr::eq(module, self.graph_root) {
+ Flags::MISC_SUGGEST_CRATE
+ } else if module.is_normal() {
Flags::MISC_SUGGEST_SELF
} else {
Flags::empty()
None
};
if let Some(kind) = ambiguity_error_kind {
- let misc = |f: Flags| if f.contains(Flags::MISC_SUGGEST_SELF) {
+ let misc = |f: Flags| if f.contains(Flags::MISC_SUGGEST_CRATE) {
+ AmbiguityErrorMisc::SuggestCrate
+ } else if f.contains(Flags::MISC_SUGGEST_SELF) {
AmbiguityErrorMisc::SuggestSelf
} else if f.contains(Flags::MISC_FROM_PRELUDE) {
AmbiguityErrorMisc::FromPrelude
};
self.ambiguity_errors.push(AmbiguityError {
kind,
- ident,
+ ident: orig_ident,
b1: innermost_binding,
b2: binding,
misc1: misc(innermost_flags),
|
LL | use plugin::helper;
| ^^^^^^^^^^^^^^
- = help: use `self::helper` to refer to this attribute macro unambiguously
+ = help: use `crate::helper` to refer to this attribute macro unambiguously
error: aborting due to previous error
|
LL | use builtin_attrs::*;
| ^^^^^^^^^^^^^^^^
- = help: use `self::repr` to refer to this attribute macro unambiguously
+ = help: use `crate::repr` to refer to this attribute macro unambiguously
error[E0659]: `repr` is ambiguous (built-in attribute vs any other name)
--> $DIR/ambiguous-builtin-attrs.rs:11:19
|
LL | use builtin_attrs::*;
| ^^^^^^^^^^^^^^^^
- = help: use `self::repr` to refer to this attribute macro unambiguously
+ = help: use `crate::repr` to refer to this attribute macro unambiguously
error[E0659]: `repr` is ambiguous (built-in attribute vs any other name)
--> $DIR/ambiguous-builtin-attrs.rs:20:34
|
LL | use builtin_attrs::*;
| ^^^^^^^^^^^^^^^^
- = help: use `self::repr` to refer to this attribute macro unambiguously
+ = help: use `crate::repr` to refer to this attribute macro unambiguously
error[E0659]: `repr` is ambiguous (built-in attribute vs any other name)
--> $DIR/ambiguous-builtin-attrs.rs:22:11
|
LL | use builtin_attrs::*;
| ^^^^^^^^^^^^^^^^
- = help: use `self::repr` to refer to this attribute macro unambiguously
+ = help: use `crate::repr` to refer to this attribute macro unambiguously
error[E0659]: `feature` is ambiguous (built-in attribute vs any other name)
--> $DIR/ambiguous-builtin-attrs.rs:3:4
|
LL | use builtin_attrs::*;
| ^^^^^^^^^^^^^^^^
- = help: use `self::feature` to refer to this attribute macro unambiguously
+ = help: use `crate::feature` to refer to this attribute macro unambiguously
error: aborting due to 6 previous errors
|
LL | use derive_helper_shadowing::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
- = help: use `self::my_attr` to refer to this attribute macro unambiguously
+ = help: use `crate::my_attr` to refer to this attribute macro unambiguously
error: aborting due to previous error
// edition:2018
// compile-flags:--extern edition_imports_2015
// aux-build:edition-imports-2015.rs
-// error-pattern: `Ambiguous` is ambiguous
-// error-pattern: `edition_imports_2015` is ambiguous
mod edition_imports_2015 {
pub struct Path;
pub struct Ambiguous {}
fn check() {
- edition_imports_2015::gen_ambiguous!();
+ edition_imports_2015::gen_ambiguous!(); //~ ERROR `Ambiguous` is ambiguous
+ //~| ERROR `edition_imports_2015` is ambiguous
}
}
error[E0659]: `Ambiguous` is ambiguous (name vs any other name during import resolution)
- --> <::edition_imports_2015::gen_ambiguous macros>:1:15
+ --> $DIR/edition-imports-virtual-2015-ambiguity.rs:15:9
|
-LL | ( ) => { use Ambiguous ; type A = :: edition_imports_2015 :: Path ; }
- | ^^^^^^^^^ ambiguous name
+LL | edition_imports_2015::gen_ambiguous!(); //~ ERROR `Ambiguous` is ambiguous
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ambiguous name
|
note: `Ambiguous` could refer to the struct defined here
- --> $DIR/edition-imports-virtual-2015-ambiguity.rs:11:1
+ --> $DIR/edition-imports-virtual-2015-ambiguity.rs:9:1
|
LL | pub struct Ambiguous {}
| ^^^^^^^^^^^^^^^^^^^^^^^
+ = help: use `crate::Ambiguous` to refer to this struct unambiguously
note: `Ambiguous` could also refer to the struct defined here
- --> $DIR/edition-imports-virtual-2015-ambiguity.rs:14:5
+ --> $DIR/edition-imports-virtual-2015-ambiguity.rs:12:5
|
LL | pub struct Ambiguous {}
| ^^^^^^^^^^^^^^^^^^^^^^^
= help: use `self::Ambiguous` to refer to this struct unambiguously
+ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error[E0659]: `edition_imports_2015` is ambiguous (name in the crate root vs extern crate during absolute path resolution)
- --> <::edition_imports_2015::gen_ambiguous macros>:1:39
+ --> $DIR/edition-imports-virtual-2015-ambiguity.rs:15:9
|
-LL | ( ) => { use Ambiguous ; type A = :: edition_imports_2015 :: Path ; }
- | ^^^^^^^^^^^^^^^^^^^^ ambiguous name
+LL | edition_imports_2015::gen_ambiguous!(); //~ ERROR `Ambiguous` is ambiguous
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ambiguous name
|
= note: `edition_imports_2015` could refer to an extern crate passed with `--extern`
- = help: use `::edition_imports_2015` to refer to this extern crate unambiguously
note: `edition_imports_2015` could also refer to the module defined here
- --> $DIR/edition-imports-virtual-2015-ambiguity.rs:7:1
+ --> $DIR/edition-imports-virtual-2015-ambiguity.rs:5:1
|
LL | / mod edition_imports_2015 {
LL | | pub struct Path;
LL | | }
| |_^
+ = help: use `crate::edition_imports_2015` to refer to this module unambiguously
+ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to 2 previous errors
fn main() {
panic!(); //~ ERROR `panic` is ambiguous
+ //~| ERROR `panic` is ambiguous
}
mod inner3 {
= help: consider adding an explicit import of `exported` to disambiguate
error[E0659]: `include` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution)
- --> $DIR/local-modularized-tricky-fail-1.rs:56:1
+ --> $DIR/local-modularized-tricky-fail-1.rs:57:1
|
LL | include!(); //~ ERROR `include` is ambiguous
| ^^^^^^^ ambiguous name
...
LL | define_include!();
| ------------------ in this macro invocation
- = help: use `self::include` to refer to this macro unambiguously
+ = help: use `crate::include` to refer to this macro unambiguously
error[E0659]: `panic` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution)
--> $DIR/local-modularized-tricky-fail-1.rs:45:5
...
LL | define_panic!();
| ---------------- in this macro invocation
- = help: use `self::panic` to refer to this macro unambiguously
+ = help: use `crate::panic` to refer to this macro unambiguously
error[E0659]: `panic` is ambiguous (macro-expanded name vs less macro-expanded name from outer scope during import/macro resolution)
- --> <::std::macros::panic macros>:1:13
+ --> $DIR/local-modularized-tricky-fail-1.rs:45:5
|
-LL | ( ) => ( { panic ! ( "explicit panic" ) } ) ; ( $ msg : expr ) => (
- | ^^^^^ ambiguous name
+LL | panic!(); //~ ERROR `panic` is ambiguous
+ | ^^^^^^^^^ ambiguous name
|
= note: `panic` could refer to a macro from prelude
note: `panic` could also refer to the macro defined here
...
LL | define_panic!();
| ---------------- in this macro invocation
- = help: use `self::panic` to refer to this macro unambiguously
+ = help: use `crate::panic` to refer to this macro unambiguously
+ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
error: aborting due to 4 previous errors
LL | | pub use two_macros::m;
LL | | }
| |_^
- = help: use `self::baz` to refer to this module unambiguously
+ = help: use `crate::baz` to refer to this module unambiguously
error: aborting due to 2 previous errors
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
+...
+LL | include!();
+ | ----------- in this macro invocation
|
note: `m` could refer to the macro defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
| ^ ambiguous name
+...
+LL | include!();
+ | ----------- in this macro invocation
|
note: `m` could refer to the macro defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
+...
+LL | include!();
+ | ----------- in this macro invocation
|
note: `m` could refer to the macro defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
+...
+LL | include!();
+ | ----------- in this macro invocation
|
note: `m` could refer to the macro defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
+...
+LL | include!();
+ | ----------- in this macro invocation
|
note: `m` could refer to the macro defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
| ^ ambiguous name
+...
+LL | include!();
+ | ----------- in this macro invocation
|
note: `m` could refer to the macro defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
+...
+LL | include!();
+ | ----------- in this macro invocation
|
note: `m` could refer to the macro defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | macro_rules! gen_invoc { () => { m!() } } //~ ERROR `m` is ambiguous
| ^ ambiguous name
+...
+LL | include!();
+ | ----------- in this macro invocation
|
note: `m` could refer to the macro defined here
--> $DIR/restricted-shadowing-legacy.rs:88:9
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
+...
+LL | include!();
+ | ----------- in this macro invocation
|
note: `m` could refer to the macro defined here
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | macro gen_invoc() { m!() } //~ ERROR `m` is ambiguous
| ^ ambiguous name
+...
+LL | include!();
+ | ----------- in this macro invocation
|
note: `m` could refer to the macro defined here
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
+...
+LL | include!();
+ | ----------- in this macro invocation
|
note: `m` could refer to the macro defined here
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
+...
+LL | include!();
+ | ----------- in this macro invocation
|
note: `m` could refer to the macro defined here
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | m!(); //~ ERROR `m` is ambiguous
| ^ ambiguous name
+...
+LL | include!();
+ | ----------- in this macro invocation
|
note: `m` could refer to the macro defined here
--> $DIR/restricted-shadowing-modern.rs:91:9
|
LL | macro gen_invoc() { m!() } //~ ERROR `m` is ambiguous
| ^ ambiguous name
+...
+LL | include!();
+ | ----------- in this macro invocation
|
note: `m` could refer to the macro defined here
--> $DIR/restricted-shadowing-modern.rs:91:9
...
LL | m!();
| ----- in this macro invocation
- = help: use `self::std` to refer to this module unambiguously
+ = help: use `crate::std` to refer to this module unambiguously
error: aborting due to previous error
LL | | pub struct io;
LL | | }
| |_^
- = help: use `self::std` to refer to this module unambiguously
+ = help: use `crate::std` to refer to this module unambiguously
error: aborting due to previous error
LL | | pub fn bar() {}
LL | | }
| |_^
- = help: use `self::sub` to refer to this module unambiguously
+ = help: use `crate::sub` to refer to this module unambiguously
error: aborting due to previous error
|
LL | enum Foo {}
| ^^^^^^^^^^^
- = help: use `self::Foo` to refer to this enum unambiguously
+ = help: use `crate::Foo` to refer to this enum unambiguously
error[E0659]: `std` is ambiguous (name vs any other name during import resolution)
--> $DIR/block-scoped-shadow.rs:26:9
|
LL | struct std;
| ^^^^^^^^^^^
- = help: use `self::std` to refer to this struct unambiguously
+ = help: use `crate::std` to refer to this struct unambiguously
error[E0659]: `std` is ambiguous (name vs any other name during import resolution)
--> $DIR/block-scoped-shadow.rs:26:9
|
LL | struct std;
| ^^^^^^^^^^^
- = help: use `self::std` to refer to this unit struct unambiguously
+ = help: use `crate::std` to refer to this unit struct unambiguously
error: aborting due to 3 previous errors