Skip to content

Commit 1a4f1f3

Browse files
committed
Auto merge of #56206 - petrochenkov:betaregr, r=alexcrichton
[beta] resolve: Fix some stable-to-beta regressions Fixes #56182 (stable-to-beta regression) Fixes #56187 (stable-to-beta regression)
2 parents 1c16fa4 + 3cf550e commit 1a4f1f3

File tree

7 files changed

+88
-34
lines changed

7 files changed

+88
-34
lines changed

src/librustc_resolve/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -5001,10 +5001,10 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
50015001
err.span_suggestion_with_applicability(
50025002
binding.span,
50035003
&rename_msg,
5004-
match (&directive.subclass, snippet.as_ref()) {
5005-
(ImportDirectiveSubclass::SingleImport { .. }, "self") =>
5004+
match directive.subclass {
5005+
ImportDirectiveSubclass::SingleImport { type_ns_only: true, .. } =>
50065006
format!("self as {}", suggested_name),
5007-
(ImportDirectiveSubclass::SingleImport { source, .. }, _) =>
5007+
ImportDirectiveSubclass::SingleImport { source, .. } =>
50085008
format!(
50095009
"{} as {}{}",
50105010
&snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)],
@@ -5015,13 +5015,13 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
50155015
""
50165016
}
50175017
),
5018-
(ImportDirectiveSubclass::ExternCrate { source, target, .. }, _) =>
5018+
ImportDirectiveSubclass::ExternCrate { source, target, .. } =>
50195019
format!(
50205020
"extern crate {} as {};",
50215021
source.unwrap_or(target.name),
50225022
suggested_name,
50235023
),
5024-
(_, _) => unreachable!(),
5024+
_ => unreachable!(),
50255025
},
50265026
Applicability::MaybeIncorrect,
50275027
);

src/librustc_resolve/resolve_imports.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,8 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
865865
}
866866
PathResult::NonModule(path_res) if path_res.base_def() == Def::Err => {
867867
// The error was already reported earlier.
868-
assert!(directive.imported_module.get().is_none());
868+
assert!(!self.ambiguity_errors.is_empty() ||
869+
directive.imported_module.get().is_none());
869870
return None;
870871
}
871872
PathResult::Indeterminate | PathResult::NonModule(..) => unreachable!(),

src/test/ui/imports/auxiliary/issue-56125.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
pub mod issue_56125 {}
2+
13
pub mod last_segment {
24
pub mod issue_56125 {}
35
}

src/test/ui/imports/issue-56125.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,24 @@
22
// compile-flags:--extern issue_56125
33
// aux-build:issue-56125.rs
44

5-
use issue_56125::last_segment::*;
6-
//~^ ERROR `issue_56125` is ambiguous
7-
//~| ERROR unresolved import `issue_56125::last_segment`
8-
use issue_56125::non_last_segment::non_last_segment::*;
9-
//~^ ERROR `issue_56125` is ambiguous
10-
//~| ERROR failed to resolve: could not find `non_last_segment` in `issue_56125`
5+
#![feature(uniform_paths)]
6+
7+
mod m1 {
8+
use issue_56125::last_segment::*;
9+
//~^ ERROR `issue_56125` is ambiguous
10+
//~| ERROR unresolved import `issue_56125::last_segment`
11+
}
12+
13+
mod m2 {
14+
use issue_56125::non_last_segment::non_last_segment::*;
15+
//~^ ERROR `issue_56125` is ambiguous
16+
//~| ERROR failed to resolve: could not find `non_last_segment` in `issue_56125`
17+
}
18+
19+
mod m3 {
20+
mod empty {}
21+
use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
22+
use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
23+
}
1124

1225
fn main() {}
+40-19
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,67 @@
11
error[E0433]: failed to resolve: could not find `non_last_segment` in `issue_56125`
2-
--> $DIR/issue-56125.rs:8:18
2+
--> $DIR/issue-56125.rs:14:22
33
|
4-
LL | use issue_56125::non_last_segment::non_last_segment::*;
5-
| ^^^^^^^^^^^^^^^^ could not find `non_last_segment` in `issue_56125`
4+
LL | use issue_56125::non_last_segment::non_last_segment::*;
5+
| ^^^^^^^^^^^^^^^^ could not find `non_last_segment` in `issue_56125`
66

77
error[E0432]: unresolved import `issue_56125::last_segment`
8-
--> $DIR/issue-56125.rs:5:18
8+
--> $DIR/issue-56125.rs:8:22
99
|
10-
LL | use issue_56125::last_segment::*;
11-
| ^^^^^^^^^^^^ could not find `last_segment` in `issue_56125`
10+
LL | use issue_56125::last_segment::*;
11+
| ^^^^^^^^^^^^ could not find `last_segment` in `issue_56125`
12+
13+
error[E0432]: unresolved import `empty::issue_56125`
14+
--> $DIR/issue-56125.rs:21:9
15+
|
16+
LL | use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
17+
| ^^^^^^^^^^^^^^^^^^ no `issue_56125` in `m3::empty`
1218

1319
error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
14-
--> $DIR/issue-56125.rs:5:5
20+
--> $DIR/issue-56125.rs:8:9
1521
|
16-
LL | use issue_56125::last_segment::*;
17-
| ^^^^^^^^^^^ ambiguous name
22+
LL | use issue_56125::last_segment::*;
23+
| ^^^^^^^^^^^ ambiguous name
1824
|
1925
= note: `issue_56125` could refer to an extern crate passed with `--extern`
2026
= help: use `::issue_56125` to refer to this extern crate unambiguously
2127
note: `issue_56125` could also refer to the module imported here
22-
--> $DIR/issue-56125.rs:5:5
28+
--> $DIR/issue-56125.rs:8:9
2329
|
24-
LL | use issue_56125::last_segment::*;
25-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
LL | use issue_56125::last_segment::*;
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2632
= help: use `self::issue_56125` to refer to this module unambiguously
2733

2834
error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
29-
--> $DIR/issue-56125.rs:8:5
35+
--> $DIR/issue-56125.rs:14:9
3036
|
31-
LL | use issue_56125::non_last_segment::non_last_segment::*;
32-
| ^^^^^^^^^^^ ambiguous name
37+
LL | use issue_56125::non_last_segment::non_last_segment::*;
38+
| ^^^^^^^^^^^ ambiguous name
3339
|
3440
= note: `issue_56125` could refer to an extern crate passed with `--extern`
3541
= help: use `::issue_56125` to refer to this extern crate unambiguously
3642
note: `issue_56125` could also refer to the module imported here
37-
--> $DIR/issue-56125.rs:5:5
43+
--> $DIR/issue-56125.rs:14:9
3844
|
39-
LL | use issue_56125::last_segment::*;
40-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
45+
LL | use issue_56125::non_last_segment::non_last_segment::*;
46+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4147
= help: use `self::issue_56125` to refer to this module unambiguously
4248

43-
error: aborting due to 4 previous errors
49+
error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
50+
--> $DIR/issue-56125.rs:22:9
51+
|
52+
LL | use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
53+
| ^^^^^^^^^^^ ambiguous name
54+
|
55+
= note: `issue_56125` could refer to an extern crate passed with `--extern`
56+
= help: use `::issue_56125` to refer to this extern crate unambiguously
57+
note: `issue_56125` could also refer to the unresolved item imported here
58+
--> $DIR/issue-56125.rs:21:9
59+
|
60+
LL | use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
61+
| ^^^^^^^^^^^^^^^^^^
62+
= help: use `self::issue_56125` to refer to this unresolved item unambiguously
63+
64+
error: aborting due to 6 previous errors
4465

4566
Some errors occurred: E0432, E0433, E0659.
4667
For more information about an error, try `rustc --explain E0432`.

src/test/ui/issues/issue-45829/import-self.rs

+3
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,7 @@ use foo as self;
1919

2020
use foo::self;
2121

22+
use foo::A;
23+
use foo::{self as A};
24+
2225
fn main() {}

src/test/ui/issues/issue-45829/import-self.stderr

+17-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,21 @@ help: you can use `as` to change the binding name of the import
2525
LL | use foo::{self as other_foo};
2626
| ^^^^^^^^^^^^^^^^^
2727

28-
error: aborting due to 3 previous errors
28+
error[E0252]: the name `A` is defined multiple times
29+
--> $DIR/import-self.rs:23:11
30+
|
31+
LL | use foo::A;
32+
| ------ previous import of the type `A` here
33+
LL | use foo::{self as A};
34+
| ^^^^^^^^^ `A` reimported here
35+
|
36+
= note: `A` must be defined only once in the type namespace of this module
37+
help: you can use `as` to change the binding name of the import
38+
|
39+
LL | use foo::{self as OtherA};
40+
| ^^^^^^^^^^^^^^
41+
42+
error: aborting due to 4 previous errors
2943

30-
Some errors occurred: E0255, E0429.
31-
For more information about an error, try `rustc --explain E0255`.
44+
Some errors occurred: E0252, E0255, E0429.
45+
For more information about an error, try `rustc --explain E0252`.

0 commit comments

Comments
 (0)