diff options
| author | Yiming Lei <yiming.lei@futurewei.com> | 2022-12-15 22:25:11 -0800 |
|---|---|---|
| committer | Yiming Lei <yiming.lei@futurewei.com> | 2022-12-19 08:38:05 -0800 |
| commit | bd12d151ee63290b317566db770465301e2dd2a9 (patch) | |
| tree | c831c993781eaceeace9a04cf35c9023db0253d9 /compiler/rustc_resolve/src | |
| parent | ba64ba8b0dfd57f7d6d7399d0df7ded37d2af18d (diff) | |
| download | rust-bd12d151ee63290b317566db770465301e2dd2a9.tar.gz rust-bd12d151ee63290b317566db770465301e2dd2a9.zip | |
add function to tell if the current ambiguity error matches a previous one in ambiguity_errors
if 2 errors of the kind and ident and span of the ident, b1, b2 and misc1 misc2 are the same then these 2 ambiguity errors matched prevent identical ambiguity error from pushing into vector of ambiguity_errors this will fix #105177
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/lib.rs | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 24e4b5bdd3f..5d0b4c0419f 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1686,6 +1686,24 @@ impl<'a> Resolver<'a> { .or_insert_with(|| self.arenas.alloc_name_resolution()) } + // Test if AmbiguityError ambi is any identical to any one inside ambiguity_errors + fn matches_previous_ambiguity_error(&mut self, ambi: &AmbiguityError<'_>) -> bool { + for ambiguity_error in &self.ambiguity_errors { + // if the span location and ident as well as its span are the same + if ambiguity_error.kind == ambi.kind + && ambiguity_error.ident == ambi.ident + && ambiguity_error.ident.span == ambi.ident.span + && ambiguity_error.b1.span == ambi.b1.span + && ambiguity_error.b2.span == ambi.b2.span + && ambiguity_error.misc1 == ambi.misc1 + && ambiguity_error.misc2 == ambi.misc2 + { + return true; + } + } + false + } + fn record_use( &mut self, ident: Ident, @@ -1693,14 +1711,18 @@ impl<'a> Resolver<'a> { is_lexical_scope: bool, ) { if let Some((b2, kind)) = used_binding.ambiguity { - self.ambiguity_errors.push(AmbiguityError { + let ambiguity_error = AmbiguityError { kind, ident, b1: used_binding, b2, misc1: AmbiguityErrorMisc::None, misc2: AmbiguityErrorMisc::None, - }); + }; + if !self.matches_previous_ambiguity_error(&ambiguity_error) { + // avoid dumplicated span information to be emitt out + self.ambiguity_errors.push(ambiguity_error); + } } if let NameBindingKind::Import { import, binding, ref used } = used_binding.kind { // Avoid marking `extern crate` items that refer to a name from extern prelude, |
