diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2022-08-13 12:32:01 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2022-10-13 16:50:24 +0000 |
| commit | 112ce807261d46befe78b947944c02ecca829a7d (patch) | |
| tree | 92f248a823155b1ccc267b652ec2726f50eaaa07 /compiler/rustc_hir_analysis/src/impl_wf_check.rs | |
| parent | 4891d57f7aab37b5d6a84f2901c0bb8903111d53 (diff) | |
| download | rust-112ce807261d46befe78b947944c02ecca829a7d.tar.gz rust-112ce807261d46befe78b947944c02ecca829a7d.zip | |
Report duplicate definition in impls with overlap check.
Diffstat (limited to 'compiler/rustc_hir_analysis/src/impl_wf_check.rs')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/impl_wf_check.rs | 40 |
1 files changed, 1 insertions, 39 deletions
diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check.rs b/compiler/rustc_hir_analysis/src/impl_wf_check.rs index 69155a422b0..a84257b939c 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check.rs @@ -11,7 +11,7 @@ use crate::constrained_generic_params as cgp; use min_specialization::check_min_specialization; -use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::fx::FxHashSet; use rustc_errors::struct_span_err; use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; @@ -19,8 +19,6 @@ use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, TyCtxt, TypeVisitable}; use rustc_span::{Span, Symbol}; -use std::collections::hash_map::Entry::{Occupied, Vacant}; - mod min_specialization; /// Checks that all the type/lifetime parameters on an impl also @@ -59,7 +57,6 @@ fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: LocalDefId) { for id in module.items() { if matches!(tcx.def_kind(id.def_id), DefKind::Impl) { enforce_impl_params_are_constrained(tcx, id.def_id.def_id); - enforce_impl_items_are_distinct(tcx, id.def_id.def_id); if min_specialization { check_min_specialization(tcx, id.def_id.def_id); } @@ -194,38 +191,3 @@ fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: Symbol } err.emit(); } - -/// Enforce that we do not have two items in an impl with the same name. -fn enforce_impl_items_are_distinct(tcx: TyCtxt<'_>, impl_def_id: LocalDefId) { - if tcx.impl_trait_ref(impl_def_id).is_some() { - return; - } - let mut seen_type_items = FxHashMap::default(); - let mut seen_value_items = FxHashMap::default(); - for &impl_item_ref in tcx.associated_item_def_ids(impl_def_id) { - let impl_item = tcx.associated_item(impl_item_ref); - let seen_items = match impl_item.kind { - ty::AssocKind::Type => &mut seen_type_items, - _ => &mut seen_value_items, - }; - let span = tcx.def_span(impl_item_ref); - let ident = impl_item.ident(tcx); - match seen_items.entry(ident.normalize_to_macros_2_0()) { - Occupied(entry) => { - let mut err = struct_span_err!( - tcx.sess, - span, - E0201, - "duplicate definitions with name `{}`:", - ident - ); - err.span_label(*entry.get(), format!("previous definition of `{}` here", ident)); - err.span_label(span, "duplicate definition"); - err.emit(); - } - Vacant(entry) => { - entry.insert(span); - } - } - } -} |
