Skip to content

Commit 125516a

Browse files
petrochenkovweiznich
authored andcommitted
resolve: Remove artificial import ambiguity errors
1 parent 774a3d1 commit 125516a

22 files changed

+51
-213
lines changed

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13881388
for ns in [Namespace::MacroNS, Namespace::TypeNS, Namespace::ValueNS] {
13891389
if let Ok(binding) = self.early_resolve_ident_in_lexical_scope(
13901390
ident,
1391-
ScopeSet::All(ns, false),
1391+
ScopeSet::All(ns),
13921392
&parent_scope,
13931393
None,
13941394
false,
@@ -1798,10 +1798,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
17981798
_ => None,
17991799
}
18001800
} else {
1801-
let scopes = ScopeSet::All(ns_to_try, opt_ns.is_none());
18021801
self.early_resolve_ident_in_lexical_scope(
18031802
ident,
1804-
scopes,
1803+
ScopeSet::All(ns_to_try),
18051804
parent_scope,
18061805
None,
18071806
false,

compiler/rustc_resolve/src/ident.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
8888

8989
let rust_2015 = ctxt.edition().is_rust_2015();
9090
let (ns, macro_kind, is_absolute_path) = match scope_set {
91-
ScopeSet::All(ns, _) => (ns, None, false),
91+
ScopeSet::All(ns) => (ns, None, false),
9292
ScopeSet::AbsolutePath(ns) => (ns, None, true),
9393
ScopeSet::Macro(macro_kind) => (MacroNS, Some(macro_kind), false),
9494
ScopeSet::Late(ns, ..) => (ns, None, false),
@@ -397,11 +397,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
397397
return Err(Determinacy::Determined);
398398
}
399399

400-
let (ns, macro_kind, is_import) = match scope_set {
401-
ScopeSet::All(ns, is_import) => (ns, None, is_import),
402-
ScopeSet::AbsolutePath(ns) => (ns, None, false),
403-
ScopeSet::Macro(macro_kind) => (MacroNS, Some(macro_kind), false),
404-
ScopeSet::Late(ns, ..) => (ns, None, false),
400+
let (ns, macro_kind) = match scope_set {
401+
ScopeSet::All(ns) => (ns, None),
402+
ScopeSet::AbsolutePath(ns) => (ns, None),
403+
ScopeSet::Macro(macro_kind) => (MacroNS, Some(macro_kind)),
404+
ScopeSet::Late(ns, ..) => (ns, None),
405405
};
406406

407407
// This is *the* result, resolution from the scope closest to the resolved identifier.
@@ -631,9 +631,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
631631
let derive_helper_compat =
632632
Res::NonMacroAttr(NonMacroAttrKind::DeriveHelperCompat);
633633

634-
let ambiguity_error_kind = if is_import {
635-
Some(AmbiguityKind::Import)
636-
} else if is_builtin(innermost_res) || is_builtin(res) {
634+
let ambiguity_error_kind = if is_builtin(innermost_res)
635+
|| is_builtin(res)
636+
{
637637
Some(AmbiguityKind::BuiltinAttr)
638638
} else if innermost_res == derive_helper_compat
639639
|| res == derive_helper_compat && innermost_res != derive_helper
@@ -853,10 +853,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
853853
}
854854
}
855855

856-
let scopes = ScopeSet::All(ns, true);
857856
let binding = self.early_resolve_ident_in_lexical_scope(
858857
ident,
859-
scopes,
858+
ScopeSet::All(ns),
860859
parent_scope,
861860
finalize,
862861
finalize.is_some(),
@@ -1495,10 +1494,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14951494
_ => Err(Determinacy::determined(finalize.is_some())),
14961495
}
14971496
} else {
1498-
let scopes = ScopeSet::All(ns, opt_ns.is_none());
14991497
this.early_resolve_ident_in_lexical_scope(
15001498
ident,
1501-
scopes,
1499+
ScopeSet::All(ns),
15021500
parent_scope,
15031501
finalize,
15041502
finalize.is_some(),

compiler/rustc_resolve/src/imports.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
934934
if let Ok(initial_binding) = initial_binding {
935935
let initial_res = initial_binding.res();
936936
if res != initial_res && this.ambiguity_errors.is_empty() {
937+
// FIXME: This is actually a bug elsewhere, probably in glob
938+
// resolution, but we currently downgrade it to an error here
939+
// instead of fixing the root cause.
937940
this.ambiguity_errors.push(AmbiguityError {
938941
kind: AmbiguityKind::Import,
939942
ident,
@@ -1216,7 +1219,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12161219

12171220
match this.early_resolve_ident_in_lexical_scope(
12181221
target,
1219-
ScopeSet::All(ns, false),
1222+
ScopeSet::All(ns),
12201223
&import.parent_scope,
12211224
None,
12221225
false,

compiler/rustc_resolve/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ enum Scope<'a> {
130130
#[derive(Clone, Copy)]
131131
enum ScopeSet<'a> {
132132
/// All scopes with the given namespace.
133-
All(Namespace, /*is_import*/ bool),
133+
All(Namespace),
134134
/// Crate root, then extern prelude (used for mixed 2015-2018 mode in macros).
135135
AbsolutePath(Namespace),
136136
/// All scopes with macro namespace and the given macro kind restriction.
@@ -1529,7 +1529,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15291529
}
15301530
}
15311531

1532-
self.visit_scopes(ScopeSet::All(TypeNS, false), parent_scope, ctxt, |this, scope, _, _| {
1532+
self.visit_scopes(ScopeSet::All(TypeNS), parent_scope, ctxt, |this, scope, _, _| {
15331533
match scope {
15341534
Scope::Module(module, _) => {
15351535
this.traits_in_module(module, assoc_item, &mut found_traits);

compiler/rustc_resolve/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
638638
self.prohibit_imported_non_macro_attrs(None, res.ok(), path_span);
639639
res
640640
} else {
641-
let scope_set = kind.map_or(ScopeSet::All(MacroNS, false), ScopeSet::Macro);
641+
let scope_set = kind.map_or(ScopeSet::All(MacroNS), ScopeSet::Macro);
642642
let binding = self.early_resolve_ident_in_lexical_scope(
643643
path[0].ident,
644644
scope_set,

tests/ui/imports/issue-56125.stderr

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,47 +22,50 @@ error[E0659]: `issue_56125` is ambiguous
2222
LL | use issue_56125::last_segment::*;
2323
| ^^^^^^^^^^^ ambiguous name
2424
|
25-
= note: ambiguous because of multiple potential import sources
25+
= note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
2626
= note: `issue_56125` could refer to a crate passed with `--extern`
2727
= help: use `::issue_56125` to refer to this crate unambiguously
2828
note: `issue_56125` could also refer to the module imported here
2929
--> $DIR/issue-56125.rs:6:9
3030
|
3131
LL | use issue_56125::last_segment::*;
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33-
= help: use `self::issue_56125` to refer to this module unambiguously
33+
= help: consider adding an explicit import of `issue_56125` to disambiguate
34+
= help: or use `self::issue_56125` to refer to this module unambiguously
3435

3536
error[E0659]: `issue_56125` is ambiguous
3637
--> $DIR/issue-56125.rs:11:9
3738
|
3839
LL | use issue_56125::non_last_segment::non_last_segment::*;
3940
| ^^^^^^^^^^^ ambiguous name
4041
|
41-
= note: ambiguous because of multiple potential import sources
42+
= note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
4243
= note: `issue_56125` could refer to a crate passed with `--extern`
4344
= help: use `::issue_56125` to refer to this crate unambiguously
4445
note: `issue_56125` could also refer to the module imported here
4546
--> $DIR/issue-56125.rs:11:9
4647
|
4748
LL | use issue_56125::non_last_segment::non_last_segment::*;
4849
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
49-
= help: use `self::issue_56125` to refer to this module unambiguously
50+
= help: consider adding an explicit import of `issue_56125` to disambiguate
51+
= help: or use `self::issue_56125` to refer to this module unambiguously
5052

5153
error[E0659]: `issue_56125` is ambiguous
5254
--> $DIR/issue-56125.rs:18:9
5355
|
5456
LL | use issue_56125::*;
5557
| ^^^^^^^^^^^ ambiguous name
5658
|
57-
= note: ambiguous because of multiple potential import sources
59+
= note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
5860
= note: `issue_56125` could refer to a crate passed with `--extern`
5961
= help: use `::issue_56125` to refer to this crate unambiguously
6062
note: `issue_56125` could also refer to the module imported here
6163
--> $DIR/issue-56125.rs:18:9
6264
|
6365
LL | use issue_56125::*;
6466
| ^^^^^^^^^^^^^^
65-
= help: use `self::issue_56125` to refer to this module unambiguously
67+
= help: consider adding an explicit import of `issue_56125` to disambiguate
68+
= help: or use `self::issue_56125` to refer to this module unambiguously
6669

6770
error: aborting due to 4 previous errors
6871

tests/ui/imports/issue-57539.stderr

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ error[E0659]: `core` is ambiguous
44
LL | use core;
55
| ^^^^ ambiguous name
66
|
7-
= note: ambiguous because of multiple potential import sources
7+
= note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
88
= note: `core` could refer to a built-in crate
99
= help: use `::core` to refer to this crate unambiguously
1010
note: `core` could also refer to the module imported here
1111
--> $DIR/issue-57539.rs:5:9
1212
|
1313
LL | use crate::*;
1414
| ^^^^^^^^
15-
= help: use `self::core` to refer to this module unambiguously
15+
= help: consider adding an explicit import of `core` to disambiguate
16+
= help: or use `self::core` to refer to this module unambiguously
1617

1718
error: aborting due to previous error
1819

tests/ui/proc-macro/derive-helper-shadowing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ macro_rules! gen_helper_use {
2323
struct S {
2424
#[empty_helper] // OK, no ambiguity, derive helpers have highest priority
2525
field: [u8; {
26-
use empty_helper; //~ ERROR `empty_helper` is ambiguous
26+
use empty_helper; // OK, no ambiguity, derive helpers have highest priority
2727

2828
#[empty_helper] // OK, no ambiguity, derive helpers have highest priority
2929
struct U;

tests/ui/proc-macro/derive-helper-shadowing.stderr

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,6 @@ LL | gen_helper_use!();
3333
crate::empty_helper
3434
= note: this error originates in the macro `gen_helper_use` (in Nightly builds, run with -Z macro-backtrace for more info)
3535

36-
error[E0659]: `empty_helper` is ambiguous
37-
--> $DIR/derive-helper-shadowing.rs:26:13
38-
|
39-
LL | use empty_helper;
40-
| ^^^^^^^^^^^^ ambiguous name
41-
|
42-
= note: ambiguous because of multiple potential import sources
43-
note: `empty_helper` could refer to the derive helper attribute defined here
44-
--> $DIR/derive-helper-shadowing.rs:22:10
45-
|
46-
LL | #[derive(Empty)]
47-
| ^^^^^
48-
note: `empty_helper` could also refer to the attribute macro imported here
49-
--> $DIR/derive-helper-shadowing.rs:10:5
50-
|
51-
LL | use test_macros::empty_attr as empty_helper;
52-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
53-
= help: use `crate::empty_helper` to refer to this attribute macro unambiguously
54-
5536
error[E0659]: `empty_helper` is ambiguous
5637
--> $DIR/derive-helper-shadowing.rs:19:3
5738
|
@@ -84,6 +65,6 @@ LL | #[derive(Empty)]
8465
= note: for more information, see issue #79202 <https://github.com/rust-lang/rust/issues/79202>
8566
= note: `#[warn(legacy_derive_helpers)]` on by default
8667

87-
error: aborting due to 5 previous errors; 1 warning emitted
68+
error: aborting due to 4 previous errors; 1 warning emitted
8869

8970
For more information about this error, try `rustc --explain E0659`.

tests/ui/rust-2018/uniform-paths/ambiguity-macros-nested.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0659]: `std` is ambiguous
44
LL | pub use std::io;
55
| ^^^ ambiguous name
66
|
7-
= note: ambiguous because of multiple potential import sources
7+
= note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution
88
= note: `std` could refer to a built-in crate
99
= help: use `::std` to refer to this crate unambiguously
1010
note: `std` could also refer to the module defined here

tests/ui/rust-2018/uniform-paths/ambiguity-macros.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0659]: `std` is ambiguous
44
LL | use std::io;
55
| ^^^ ambiguous name
66
|
7-
= note: ambiguous because of multiple potential import sources
7+
= note: ambiguous because of a conflict between a macro-expanded name and a less macro-expanded name from outer scope during import or macro resolution
88
= note: `std` could refer to a built-in crate
99
= help: use `::std` to refer to this crate unambiguously
1010
note: `std` could also refer to the module defined here

tests/ui/rust-2018/uniform-paths/ambiguity-nested.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
// check-pass
12
// edition:2018
23

34
// This test is similar to `ambiguity.rs`, but nested in a module.
45

56
#![allow(non_camel_case_types)]
67

78
mod foo {
8-
pub use std::io;
9-
//~^ ERROR `std` is ambiguous
9+
pub use std::io; // OK
1010

1111
mod std {
1212
pub struct io;

tests/ui/rust-2018/uniform-paths/ambiguity-nested.stderr

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/ui/rust-2018/uniform-paths/ambiguity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
// check-pass
12
// edition:2018
23

34
#![allow(non_camel_case_types)]
45

5-
use std::io;
6-
//~^ ERROR `std` is ambiguous
6+
use std::io; // OK
77

88
mod std {
99
pub struct io;

tests/ui/rust-2018/uniform-paths/ambiguity.stderr

Lines changed: 0 additions & 21 deletions
This file was deleted.

tests/ui/rust-2018/uniform-paths/block-scoped-shadow-nested.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// check-pass
12
// edition:2018
23

34
mod my {
@@ -13,7 +14,7 @@ mod sub {
1314
fn foo() {
1415
use my::sub;
1516
{
16-
use sub::bar; //~ ERROR `sub` is ambiguous
17+
use sub::bar; // OK
1718
}
1819
}
1920

tests/ui/rust-2018/uniform-paths/block-scoped-shadow-nested.stderr

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// check-pass
12
// edition:2018
23

34
#![allow(non_camel_case_types)]
@@ -8,14 +9,11 @@ struct std;
89

910
fn main() {
1011
enum Foo { A, B }
11-
use Foo::*;
12-
//~^ ERROR `Foo` is ambiguous
12+
use Foo::*; // OK
1313

1414
let _ = (A, B);
1515

1616
fn std() {}
1717
enum std {}
18-
use std as foo;
19-
//~^ ERROR `std` is ambiguous
20-
//~| ERROR `std` is ambiguous
18+
use std as foo; // OK
2119
}

0 commit comments

Comments
 (0)