Skip to content

Commit 7a7f34c

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 b029f1b commit 7a7f34c

6 files changed

Lines changed: 10 additions & 87 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/errors.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: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use tracing::{debug, instrument};
1919

2020
use crate::errors;
2121
use crate::hir_ty_lowering::{
22-
AssocItemQSelf, GenericsArgsErrExtend, HirTyLowerer, ImpliedBoundsContext,
23-
OverlappingAsssocItemConstraints, PredicateFilter, RegionInferReason,
22+
AssocItemQSelf, GenericsArgsErrExtend, HirTyLowerer, ImpliedBoundsContext, PredicateFilter,
23+
RegionInferReason,
2424
};
2525

2626
#[derive(Debug, Default)]
@@ -363,7 +363,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
363363
bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
364364
bound_vars: &'tcx ty::List<ty::BoundVariableKind<'tcx>>,
365365
predicate_filter: PredicateFilter,
366-
overlapping_assoc_constraints: OverlappingAsssocItemConstraints,
367366
) where
368367
'tcx: 'hir,
369368
{
@@ -388,7 +387,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
388387
param_ty,
389388
bounds,
390389
predicate_filter,
391-
overlapping_assoc_constraints,
392390
);
393391
}
394392
hir::GenericBound::Outlives(lifetime) => {
@@ -422,14 +420,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
422420
/// the `trait_ref` here will be `for<'a> T: Iterator`.
423421
/// The `constraint` data however is from *inside* the binder
424422
/// (e.g., `&'a u32`) and hence may reference bound regions.
425-
#[instrument(level = "debug", skip(self, bounds, duplicates, path_span))]
423+
#[instrument(level = "debug", skip(self, bounds, path_span))]
426424
pub(super) fn lower_assoc_item_constraint(
427425
&self,
428426
hir_ref_id: hir::HirId,
429427
trait_ref: ty::PolyTraitRef<'tcx>,
430428
constraint: &hir::AssocItemConstraint<'tcx>,
431429
bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
432-
duplicates: Option<&mut FxIndexMap<DefId, Span>>,
433430
path_span: Span,
434431
predicate_filter: PredicateFilter,
435432
) -> Result<(), ErrorGuaranteed> {
@@ -485,20 +482,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
485482
)
486483
.expect("failed to find associated item");
487484

488-
if let Some(duplicates) = duplicates {
489-
duplicates
490-
.entry(assoc_item.def_id)
491-
.and_modify(|prev_span| {
492-
self.dcx().emit_err(errors::ValueOfAssociatedStructAlreadySpecified {
493-
span: constraint.span,
494-
prev_span: *prev_span,
495-
item_name: constraint.ident,
496-
def_path: tcx.def_path_str(assoc_item.container_id(tcx)),
497-
});
498-
})
499-
.or_insert(constraint.span);
500-
}
501-
502485
let projection_term = if let ty::AssocTag::Fn = assoc_tag {
503486
let bound_vars = tcx.late_bound_vars(constraint.hir_id);
504487
ty::Binder::bind_with_vars(
@@ -646,7 +629,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
646629
bounds,
647630
projection_ty.bound_vars(),
648631
predicate_filter,
649-
OverlappingAsssocItemConstraints::Allowed,
650632
);
651633
}
652634
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
@@ -28,8 +28,7 @@ use tracing::{debug, instrument};
2828
use super::HirTyLowerer;
2929
use crate::errors::DynTraitAssocItemBindingMentionsSelf;
3030
use crate::hir_ty_lowering::{
31-
GenericArgCountMismatch, ImpliedBoundsContext, OverlappingAsssocItemConstraints,
32-
PredicateFilter, RegionInferReason,
31+
GenericArgCountMismatch, ImpliedBoundsContext, PredicateFilter, RegionInferReason,
3332
};
3433

3534
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
@@ -72,7 +71,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
7271
dummy_self,
7372
&mut user_written_bounds,
7473
PredicateFilter::SelfOnly,
75-
OverlappingAsssocItemConstraints::Allowed,
7674
);
7775
if let Err(GenericArgCountMismatch { invalid_args, .. }) = result.correct {
7876
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)]
@@ -958,7 +949,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
958949
self_ty: Ty<'tcx>,
959950
bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
960951
predicate_filter: PredicateFilter,
961-
overlapping_assoc_item_constraints: OverlappingAsssocItemConstraints,
962952
) -> GenericArgCountResult {
963953
let tcx = self.tcx();
964954

@@ -1137,10 +1127,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
11371127
}
11381128
}
11391129

1140-
let mut dup_constraints = (overlapping_assoc_item_constraints
1141-
== OverlappingAsssocItemConstraints::Forbidden)
1142-
.then_some(FxIndexMap::default());
1143-
11441130
for constraint in constraints {
11451131
// Don't register any associated item constraints for negative bounds,
11461132
// since we should have emitted an error for them earlier, and they
@@ -1159,7 +1145,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
11591145
poly_trait_ref,
11601146
constraint,
11611147
bounds,
1162-
dup_constraints.as_mut(),
11631148
constraint.span,
11641149
predicate_filter,
11651150
);
@@ -3057,7 +3042,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
30573042
&mut bounds,
30583043
ty::List::empty(),
30593044
PredicateFilter::All,
3060-
OverlappingAsssocItemConstraints::Allowed,
30613045
);
30623046
self.add_implicit_sizedness_bounds(
30633047
&mut bounds,

0 commit comments

Comments
 (0)