Skip to content

Commit

Permalink
Auto merge of #56206 - petrochenkov:betaregr, r=alexcrichton
Browse files Browse the repository at this point in the history
[beta] resolve: Fix some stable-to-beta regressions

Fixes #56182 (stable-to-beta regression)
Fixes #56187 (stable-to-beta regression)
  • Loading branch information
bors committed Nov 25, 2018
2 parents 1c16fa4 + 3cf550e commit 1a4f1f3
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 34 deletions.
10 changes: 5 additions & 5 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5001,10 +5001,10 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
err.span_suggestion_with_applicability(
binding.span,
&rename_msg,
match (&directive.subclass, snippet.as_ref()) {
(ImportDirectiveSubclass::SingleImport { .. }, "self") =>
match directive.subclass {
ImportDirectiveSubclass::SingleImport { type_ns_only: true, .. } =>
format!("self as {}", suggested_name),
(ImportDirectiveSubclass::SingleImport { source, .. }, _) =>
ImportDirectiveSubclass::SingleImport { source, .. } =>
format!(
"{} as {}{}",
&snippet[..((source.span.hi().0 - binding.span.lo().0) as usize)],
Expand All @@ -5015,13 +5015,13 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
""
}
),
(ImportDirectiveSubclass::ExternCrate { source, target, .. }, _) =>
ImportDirectiveSubclass::ExternCrate { source, target, .. } =>
format!(
"extern crate {} as {};",
source.unwrap_or(target.name),
suggested_name,
),
(_, _) => unreachable!(),
_ => unreachable!(),
},
Applicability::MaybeIncorrect,
);
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,8 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
}
PathResult::NonModule(path_res) if path_res.base_def() == Def::Err => {
// The error was already reported earlier.
assert!(directive.imported_module.get().is_none());
assert!(!self.ambiguity_errors.is_empty() ||
directive.imported_module.get().is_none());
return None;
}
PathResult::Indeterminate | PathResult::NonModule(..) => unreachable!(),
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/imports/auxiliary/issue-56125.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod issue_56125 {}

pub mod last_segment {
pub mod issue_56125 {}
}
Expand Down
25 changes: 19 additions & 6 deletions src/test/ui/imports/issue-56125.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@
// compile-flags:--extern issue_56125
// aux-build:issue-56125.rs

use issue_56125::last_segment::*;
//~^ ERROR `issue_56125` is ambiguous
//~| ERROR unresolved import `issue_56125::last_segment`
use issue_56125::non_last_segment::non_last_segment::*;
//~^ ERROR `issue_56125` is ambiguous
//~| ERROR failed to resolve: could not find `non_last_segment` in `issue_56125`
#![feature(uniform_paths)]

mod m1 {
use issue_56125::last_segment::*;
//~^ ERROR `issue_56125` is ambiguous
//~| ERROR unresolved import `issue_56125::last_segment`
}

mod m2 {
use issue_56125::non_last_segment::non_last_segment::*;
//~^ ERROR `issue_56125` is ambiguous
//~| ERROR failed to resolve: could not find `non_last_segment` in `issue_56125`
}

mod m3 {
mod empty {}
use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
}

fn main() {}
59 changes: 40 additions & 19 deletions src/test/ui/imports/issue-56125.stderr
Original file line number Diff line number Diff line change
@@ -1,46 +1,67 @@
error[E0433]: failed to resolve: could not find `non_last_segment` in `issue_56125`
--> $DIR/issue-56125.rs:8:18
--> $DIR/issue-56125.rs:14:22
|
LL | use issue_56125::non_last_segment::non_last_segment::*;
| ^^^^^^^^^^^^^^^^ could not find `non_last_segment` in `issue_56125`
LL | use issue_56125::non_last_segment::non_last_segment::*;
| ^^^^^^^^^^^^^^^^ could not find `non_last_segment` in `issue_56125`

error[E0432]: unresolved import `issue_56125::last_segment`
--> $DIR/issue-56125.rs:5:18
--> $DIR/issue-56125.rs:8:22
|
LL | use issue_56125::last_segment::*;
| ^^^^^^^^^^^^ could not find `last_segment` in `issue_56125`
LL | use issue_56125::last_segment::*;
| ^^^^^^^^^^^^ could not find `last_segment` in `issue_56125`

error[E0432]: unresolved import `empty::issue_56125`
--> $DIR/issue-56125.rs:21:9
|
LL | use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
| ^^^^^^^^^^^^^^^^^^ no `issue_56125` in `m3::empty`

error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
--> $DIR/issue-56125.rs:5:5
--> $DIR/issue-56125.rs:8:9
|
LL | use issue_56125::last_segment::*;
| ^^^^^^^^^^^ ambiguous name
LL | use issue_56125::last_segment::*;
| ^^^^^^^^^^^ ambiguous name
|
= note: `issue_56125` could refer to an extern crate passed with `--extern`
= help: use `::issue_56125` to refer to this extern crate unambiguously
note: `issue_56125` could also refer to the module imported here
--> $DIR/issue-56125.rs:5:5
--> $DIR/issue-56125.rs:8:9
|
LL | use issue_56125::last_segment::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | use issue_56125::last_segment::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: use `self::issue_56125` to refer to this module unambiguously

error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
--> $DIR/issue-56125.rs:8:5
--> $DIR/issue-56125.rs:14:9
|
LL | use issue_56125::non_last_segment::non_last_segment::*;
| ^^^^^^^^^^^ ambiguous name
LL | use issue_56125::non_last_segment::non_last_segment::*;
| ^^^^^^^^^^^ ambiguous name
|
= note: `issue_56125` could refer to an extern crate passed with `--extern`
= help: use `::issue_56125` to refer to this extern crate unambiguously
note: `issue_56125` could also refer to the module imported here
--> $DIR/issue-56125.rs:5:5
--> $DIR/issue-56125.rs:14:9
|
LL | use issue_56125::last_segment::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | use issue_56125::non_last_segment::non_last_segment::*;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: use `self::issue_56125` to refer to this module unambiguously

error: aborting due to 4 previous errors
error[E0659]: `issue_56125` is ambiguous (name vs any other name during import resolution)
--> $DIR/issue-56125.rs:22:9
|
LL | use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
| ^^^^^^^^^^^ ambiguous name
|
= note: `issue_56125` could refer to an extern crate passed with `--extern`
= help: use `::issue_56125` to refer to this extern crate unambiguously
note: `issue_56125` could also refer to the unresolved item imported here
--> $DIR/issue-56125.rs:21:9
|
LL | use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
| ^^^^^^^^^^^^^^^^^^
= help: use `self::issue_56125` to refer to this unresolved item unambiguously

error: aborting due to 6 previous errors

Some errors occurred: E0432, E0433, E0659.
For more information about an error, try `rustc --explain E0432`.
3 changes: 3 additions & 0 deletions src/test/ui/issues/issue-45829/import-self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ use foo as self;

use foo::self;

use foo::A;
use foo::{self as A};

fn main() {}
20 changes: 17 additions & 3 deletions src/test/ui/issues/issue-45829/import-self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,21 @@ help: you can use `as` to change the binding name of the import
LL | use foo::{self as other_foo};
| ^^^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors
error[E0252]: the name `A` is defined multiple times
--> $DIR/import-self.rs:23:11
|
LL | use foo::A;
| ------ previous import of the type `A` here
LL | use foo::{self as A};
| ^^^^^^^^^ `A` reimported here
|
= note: `A` must be defined only once in the type namespace of this module
help: you can use `as` to change the binding name of the import
|
LL | use foo::{self as OtherA};
| ^^^^^^^^^^^^^^

error: aborting due to 4 previous errors

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

0 comments on commit 1a4f1f3

Please sign in to comment.