Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c7e73ee

Browse files
authoredMar 6, 2024··
Unrolled build for rust-lang#121846
Rollup merge of rust-lang#121846 - bvanjoi:fix-121760, r=petrochenkov only compare ambiguity item that have hard error Fixes rust-lang#121760 An easy fix, r? ``@petrochenkov``
2 parents b6d2d84 + 89954e5 commit c7e73ee

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed
 

‎compiler/rustc_resolve/src/imports.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use crate::errors::{
88
ItemsInTraitsAreNotImportable,
99
};
1010
use crate::Determinacy::{self, *};
11-
use crate::Namespace::*;
1211
use crate::{module_to_string, names_to_string, ImportSuggestion};
12+
use crate::{AmbiguityError, Namespace::*};
1313
use crate::{AmbiguityKind, BindingKey, ResolutionError, Resolver, Segment};
1414
use crate::{Finalize, Module, ModuleOrUniformRoot, ParentScope, PerNS, ScopeSet};
1515
use crate::{NameBinding, NameBindingData, NameBindingKind, PathResult, Used};
@@ -538,7 +538,6 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
538538
.chain(indeterminate_imports.iter().map(|i| (true, i)))
539539
{
540540
let unresolved_import_error = self.finalize_import(*import);
541-
542541
// If this import is unresolved then create a dummy import
543542
// resolution for it so that later resolve stages won't complain.
544543
self.import_dummy_binding(*import, is_indeterminate);
@@ -856,7 +855,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
856855
ImportKind::Single { target_bindings, .. } => target_bindings[TypeNS].get(),
857856
_ => None,
858857
};
859-
let prev_ambiguity_errors_len = self.ambiguity_errors.len();
858+
let ambiguity_errors_len =
859+
|errors: &Vec<AmbiguityError<'_>>| errors.iter().filter(|error| !error.warning).count();
860+
let prev_ambiguity_errors_len = ambiguity_errors_len(&self.ambiguity_errors);
860861
let finalize = Finalize::with_root_span(import.root_id, import.span, import.root_span);
861862

862863
// We'll provide more context to the privacy errors later, up to `len`.
@@ -870,7 +871,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
870871
ignore_binding,
871872
);
872873

873-
let no_ambiguity = self.ambiguity_errors.len() == prev_ambiguity_errors_len;
874+
let no_ambiguity =
875+
ambiguity_errors_len(&self.ambiguity_errors) == prev_ambiguity_errors_len;
874876
import.vis.set(orig_vis);
875877
let module = match path_res {
876878
PathResult::Module(module) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
mod a {
2+
mod b {
3+
mod c {
4+
pub struct E;
5+
}
6+
7+
mod d {
8+
#[derive(Debug)]
9+
pub struct E;
10+
}
11+
12+
pub use self::d::*;
13+
pub use self::c::*;
14+
}
15+
16+
pub use self::b::*;
17+
}
18+
19+
use self::a::E::in_exist;
20+
//~^ ERROR: unresolved import `self::a::E`
21+
//~| WARNING: `E` is ambiguous
22+
//~| WARNING: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
23+
24+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0432]: unresolved import `self::a::E`
2+
--> $DIR/unresolved-seg-after-ambiguous.rs:19:14
3+
|
4+
LL | use self::a::E::in_exist;
5+
| ^ `E` is a struct, not a module
6+
7+
warning: `E` is ambiguous
8+
--> $DIR/unresolved-seg-after-ambiguous.rs:19:14
9+
|
10+
LL | use self::a::E::in_exist;
11+
| ^ ambiguous name
12+
|
13+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
14+
= note: for more information, see issue #114095 <https://github.com/rust-lang/rust/issues/114095>
15+
= note: ambiguous because of multiple glob imports of a name in the same module
16+
note: `E` could refer to the struct imported here
17+
--> $DIR/unresolved-seg-after-ambiguous.rs:13:17
18+
|
19+
LL | pub use self::c::*;
20+
| ^^^^^^^^^^
21+
= help: consider adding an explicit import of `E` to disambiguate
22+
note: `E` could also refer to the struct imported here
23+
--> $DIR/unresolved-seg-after-ambiguous.rs:12:17
24+
|
25+
LL | pub use self::d::*;
26+
| ^^^^^^^^^^
27+
= help: consider adding an explicit import of `E` to disambiguate
28+
= note: `#[warn(ambiguous_glob_imports)]` on by default
29+
30+
error: aborting due to 1 previous error; 1 warning emitted
31+
32+
For more information about this error, try `rustc --explain E0432`.

0 commit comments

Comments
 (0)
Please sign in to comment.