Skip to content

Commit 8bbea5e

Browse files
committed
Remove old code for detecting duplicate assoc ty in dyn.
Fixes <#150936> The last place where `OverlappingAsssocItemConstraints::Forbidden` was constructed was removed in a previous commit. As a result, this code path is now unreachable.
1 parent f8eab33 commit 8bbea5e

6 files changed

Lines changed: 11 additions & 88 deletions

File tree

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ use tracing::{debug, instrument};
1212

1313
use super::ItemCtxt;
1414
use super::predicates_of::assert_only_contains_predicates_from;
15-
use crate::hir_ty_lowering::{
16-
HirTyLowerer, ImpliedBoundsContext, OverlappingAsssocItemConstraints, PredicateFilter,
17-
};
15+
use crate::hir_ty_lowering::{HirTyLowerer, ImpliedBoundsContext, PredicateFilter};
1816

1917
/// For associated types we include both bounds written on the type
2018
/// (`type X: Trait`) and predicates from the trait: `where Self::X: Trait`.
@@ -39,14 +37,7 @@ fn associated_type_bounds<'tcx>(
3937

4038
let icx = ItemCtxt::new(tcx, assoc_item_def_id);
4139
let mut bounds = Vec::new();
42-
icx.lowerer().lower_bounds(
43-
item_ty,
44-
hir_bounds,
45-
&mut bounds,
46-
ty::List::empty(),
47-
filter,
48-
OverlappingAsssocItemConstraints::Allowed,
49-
);
40+
icx.lowerer().lower_bounds(item_ty, hir_bounds, &mut bounds, ty::List::empty(), filter);
5041

5142
match filter {
5243
PredicateFilter::All
@@ -366,14 +357,7 @@ fn opaque_type_bounds<'tcx>(
366357
ty::print::with_reduced_queries!({
367358
let icx = ItemCtxt::new(tcx, opaque_def_id);
368359
let mut bounds = Vec::new();
369-
icx.lowerer().lower_bounds(
370-
item_ty,
371-
hir_bounds,
372-
&mut bounds,
373-
ty::List::empty(),
374-
filter,
375-
OverlappingAsssocItemConstraints::Allowed,
376-
);
360+
icx.lowerer().lower_bounds(item_ty, hir_bounds, &mut bounds, ty::List::empty(), filter);
377361
// Implicit bounds are added to opaque types unless a `?Trait` bound is found
378362
match filter {
379363
PredicateFilter::All

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ use crate::collect::ItemCtxt;
1818
use crate::constrained_generic_params as cgp;
1919
use crate::delegation::inherit_predicates_for_delegation_item;
2020
use crate::hir_ty_lowering::{
21-
HirTyLowerer, ImpliedBoundsContext, OverlappingAsssocItemConstraints, PredicateFilter,
22-
RegionInferReason,
21+
HirTyLowerer, ImpliedBoundsContext, PredicateFilter, RegionInferReason,
2322
};
2423

2524
/// Returns a list of all type predicates (explicit and implicit) for the definition with
@@ -194,7 +193,6 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
194193
&mut bounds,
195194
ty::List::empty(),
196195
PredicateFilter::All,
197-
OverlappingAsssocItemConstraints::Allowed,
198196
);
199197
icx.lowerer().add_implicit_sizedness_bounds(
200198
&mut bounds,
@@ -295,7 +293,6 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
295293
&mut bounds,
296294
bound_vars,
297295
PredicateFilter::All,
298-
OverlappingAsssocItemConstraints::Allowed,
299296
);
300297
predicates.extend(bounds);
301298
}
@@ -675,14 +672,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
675672

676673
let self_param_ty = tcx.types.self_param;
677674
let mut bounds = Vec::new();
678-
icx.lowerer().lower_bounds(
679-
self_param_ty,
680-
superbounds,
681-
&mut bounds,
682-
ty::List::empty(),
683-
filter,
684-
OverlappingAsssocItemConstraints::Allowed,
685-
);
675+
icx.lowerer().lower_bounds(self_param_ty, superbounds, &mut bounds, ty::List::empty(), filter);
686676
match filter {
687677
PredicateFilter::All
688678
| PredicateFilter::SelfOnly
@@ -1040,7 +1030,6 @@ impl<'tcx> ItemCtxt<'tcx> {
10401030
&mut bounds,
10411031
bound_vars,
10421032
filter,
1043-
OverlappingAsssocItemConstraints::Allowed,
10441033
);
10451034
}
10461035

@@ -1126,7 +1115,6 @@ pub(super) fn const_conditions<'tcx>(
11261115
&mut bounds,
11271116
bound_vars,
11281117
PredicateFilter::ConstIfConst,
1129-
OverlappingAsssocItemConstraints::Allowed,
11301118
);
11311119
}
11321120
_ => {}
@@ -1149,7 +1137,6 @@ pub(super) fn const_conditions<'tcx>(
11491137
&mut bounds,
11501138
ty::List::empty(),
11511139
PredicateFilter::ConstIfConst,
1152-
OverlappingAsssocItemConstraints::Allowed,
11531140
);
11541141
}
11551142

compiler/rustc_hir_analysis/src/diagnostics.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -430,18 +430,6 @@ pub(crate) struct ParenthesizedFnTraitExpansion {
430430
pub expanded_type: String,
431431
}
432432

433-
#[derive(Diagnostic)]
434-
#[diag("the value of the associated type `{$item_name}` in trait `{$def_path}` is already specified", code = E0719)]
435-
pub(crate) struct ValueOfAssociatedStructAlreadySpecified {
436-
#[primary_span]
437-
#[label("re-bound here")]
438-
pub span: Span,
439-
#[label("`{$item_name}` bound here first")]
440-
pub prev_span: Span,
441-
pub item_name: Ident,
442-
pub def_path: String,
443-
}
444-
445433
#[derive(Diagnostic)]
446434
#[diag("unconstrained opaque type")]
447435
#[note("`{$name}` must be used in combination with a concrete type within the same {$what}")]

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::ops::ControlFlow;
22

3-
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
3+
use rustc_data_structures::fx::FxIndexSet;
44
use rustc_errors::codes::*;
55
use rustc_errors::struct_span_code_err;
66
use rustc_hir as hir;
@@ -18,8 +18,8 @@ use tracing::{debug, instrument};
1818

1919
use crate::diagnostics;
2020
use crate::hir_ty_lowering::{
21-
AssocItemQSelf, GenericsArgsErrExtend, HirTyLowerer, ImpliedBoundsContext,
22-
OverlappingAsssocItemConstraints, PredicateFilter, RegionInferReason,
21+
AssocItemQSelf, GenericsArgsErrExtend, HirTyLowerer, ImpliedBoundsContext, PredicateFilter,
22+
RegionInferReason,
2323
};
2424

2525
#[derive(Debug, Default)]
@@ -315,7 +315,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
315315
bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
316316
bound_vars: &'tcx ty::List<ty::BoundVariableKind<'tcx>>,
317317
predicate_filter: PredicateFilter,
318-
overlapping_assoc_constraints: OverlappingAsssocItemConstraints,
319318
) where
320319
'tcx: 'hir,
321320
{
@@ -340,7 +339,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
340339
param_ty,
341340
bounds,
342341
predicate_filter,
343-
overlapping_assoc_constraints,
344342
);
345343
}
346344
hir::GenericBound::Outlives(lifetime) => {
@@ -374,14 +372,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
374372
/// the `trait_ref` here will be `for<'a> T: Iterator`.
375373
/// The `constraint` data however is from *inside* the binder
376374
/// (e.g., `&'a u32`) and hence may reference bound regions.
377-
#[instrument(level = "debug", skip(self, bounds, duplicates, path_span))]
375+
#[instrument(level = "debug", skip(self, bounds, path_span))]
378376
pub(super) fn lower_assoc_item_constraint(
379377
&self,
380378
hir_ref_id: hir::HirId,
381379
trait_ref: ty::PolyTraitRef<'tcx>,
382380
constraint: &hir::AssocItemConstraint<'tcx>,
383381
bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
384-
duplicates: Option<&mut FxIndexMap<DefId, Span>>,
385382
path_span: Span,
386383
predicate_filter: PredicateFilter,
387384
) -> Result<(), ErrorGuaranteed> {
@@ -437,20 +434,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
437434
)
438435
.expect("failed to find associated item");
439436

440-
if let Some(duplicates) = duplicates {
441-
duplicates
442-
.entry(assoc_item.def_id)
443-
.and_modify(|prev_span| {
444-
self.dcx().emit_err(diagnostics::ValueOfAssociatedStructAlreadySpecified {
445-
span: constraint.span,
446-
prev_span: *prev_span,
447-
item_name: constraint.ident,
448-
def_path: tcx.def_path_str(assoc_item.container_id(tcx)),
449-
});
450-
})
451-
.or_insert(constraint.span);
452-
}
453-
454437
let projection_term = if let ty::AssocTag::Fn = assoc_tag {
455438
let bound_vars = tcx.late_bound_vars(constraint.hir_id);
456439
ty::Binder::bind_with_vars(
@@ -597,7 +580,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
597580
bounds,
598581
projection_ty.bound_vars(),
599582
predicate_filter,
600-
OverlappingAsssocItemConstraints::Allowed,
601583
);
602584
}
603585
PredicateFilter::SelfOnly

compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_trait.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ use tracing::{debug, instrument};
2626
use super::HirTyLowerer;
2727
use crate::diagnostics::DynTraitAssocItemBindingMentionsSelf;
2828
use crate::hir_ty_lowering::{
29-
GenericArgCountMismatch, ImpliedBoundsContext, OverlappingAsssocItemConstraints,
30-
PredicateFilter, RegionInferReason,
29+
GenericArgCountMismatch, ImpliedBoundsContext, PredicateFilter, RegionInferReason,
3130
};
3231

3332
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
@@ -70,7 +69,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
7069
dummy_self,
7170
&mut user_written_bounds,
7271
PredicateFilter::SelfOnly,
73-
OverlappingAsssocItemConstraints::Allowed,
7472
);
7573
if let Err(GenericArgCountMismatch { invalid_args, .. }) = result.correct {
7674
potential_assoc_items.extend(invalid_args);

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::{assert_matches, slice};
2323

2424
use rustc_abi::FIRST_VARIANT;
2525
use rustc_ast::LitKind;
26-
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
26+
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
2727
use rustc_errors::codes::*;
2828
use rustc_errors::{
2929
Applicability, Diag, DiagCtxtHandle, ErrorGuaranteed, FatalError, StashKey,
@@ -331,15 +331,6 @@ pub(crate) enum GenericArgPosition {
331331
Value(IsMethodCall),
332332
}
333333

334-
/// Whether to allow duplicate associated iten constraints in a trait ref, e.g.
335-
/// `Trait<Assoc = Ty, Assoc = Ty>`. This is forbidden in `dyn Trait<...>`
336-
/// but allowed everywhere else.
337-
#[derive(Clone, Copy, Debug, PartialEq)]
338-
pub(crate) enum OverlappingAsssocItemConstraints {
339-
Allowed,
340-
Forbidden,
341-
}
342-
343334
/// A marker denoting that the generic arguments that were
344335
/// provided did not match the respective generic parameters.
345336
#[derive(Clone, Debug)]
@@ -956,7 +947,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
956947
self_ty: Ty<'tcx>,
957948
bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
958949
predicate_filter: PredicateFilter,
959-
overlapping_assoc_item_constraints: OverlappingAsssocItemConstraints,
960950
) -> GenericArgCountResult {
961951
let tcx = self.tcx();
962952

@@ -1135,10 +1125,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
11351125
}
11361126
}
11371127

1138-
let mut dup_constraints = (overlapping_assoc_item_constraints
1139-
== OverlappingAsssocItemConstraints::Forbidden)
1140-
.then_some(FxIndexMap::default());
1141-
11421128
for constraint in constraints {
11431129
// Don't register any associated item constraints for negative bounds,
11441130
// since we should have emitted an error for them earlier, and they
@@ -1157,7 +1143,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
11571143
poly_trait_ref,
11581144
constraint,
11591145
bounds,
1160-
dup_constraints.as_mut(),
11611146
constraint.span,
11621147
predicate_filter,
11631148
);
@@ -3137,7 +3122,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
31373122
&mut bounds,
31383123
ty::List::empty(),
31393124
PredicateFilter::All,
3140-
OverlappingAsssocItemConstraints::Allowed,
31413125
);
31423126
self.add_implicit_sizedness_bounds(
31433127
&mut bounds,

0 commit comments

Comments
 (0)