Skip to content

Commit 60dd0df

Browse files
Address review comments
1 parent 389907a commit 60dd0df

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

compiler/rustc_error_codes/src/error_codes/E0719.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
An associated item value was specified more than once in a trait object.
1+
An associated item was specified more than once in a trait object.
22

33
Erroneous code example:
44

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ use tracing::{debug, instrument};
2121
use super::errors::GenericsArgsErrExtend;
2222
use crate::errors;
2323
use crate::hir_ty_lowering::{
24-
AssocItemQSelf, FeedConstTy, HirTyLowerer, PredicateFilter, RegionInferReason,
24+
AssocItemQSelf, FeedConstTy, HirTyLowerer, OverlappingAsssocItemConstraints, PredicateFilter,
25+
RegionInferReason,
2526
};
2627

2728
#[derive(Debug, Default)]
@@ -362,7 +363,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
362363
param_ty,
363364
bounds,
364365
predicate_filter,
365-
false,
366+
OverlappingAsssocItemConstraints::Allowed,
366367
);
367368
}
368369
hir::GenericBound::Outlives(lifetime) => {

compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_trait.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ use tracing::{debug, instrument};
2323

2424
use super::HirTyLowerer;
2525
use crate::errors::SelfInTypeAlias;
26-
use crate::hir_ty_lowering::{GenericArgCountMismatch, PredicateFilter, RegionInferReason};
26+
use crate::hir_ty_lowering::{
27+
GenericArgCountMismatch, OverlappingAsssocItemConstraints, PredicateFilter, RegionInferReason,
28+
};
2729

2830
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2931
/// Lower a trait object type from the HIR to our internal notion of a type.
@@ -60,7 +62,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
6062
dummy_self,
6163
&mut user_written_bounds,
6264
PredicateFilter::SelfOnly,
63-
true,
65+
OverlappingAsssocItemConstraints::Forbidden,
6466
);
6567
if let Err(GenericArgCountMismatch { invalid_args, .. }) = result.correct {
6668
potential_assoc_types.extend(invalid_args);

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ pub(crate) enum GenericArgPosition {
332332
MethodCall,
333333
}
334334

335+
/// Whether to allow duplicate associated iten constraints in a trait ref, e.g.
336+
/// `Trait<Assoc = Ty, Assoc = Ty>`. This is forbidden in `dyn Trait<...>`
337+
/// but allowed everywhere else.
338+
#[derive(Clone, Copy, Debug, PartialEq)]
339+
pub(crate) enum OverlappingAsssocItemConstraints {
340+
Allowed,
341+
Forbidden,
342+
}
343+
335344
/// A marker denoting that the generic arguments that were
336345
/// provided did not match the respective generic parameters.
337346
#[derive(Clone, Debug)]
@@ -752,7 +761,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
752761
self_ty: Ty<'tcx>,
753762
bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
754763
predicate_filter: PredicateFilter,
755-
for_dyn: bool,
764+
overlapping_assoc_item_constraints: OverlappingAsssocItemConstraints,
756765
) -> GenericArgCountResult {
757766
let tcx = self.tcx();
758767

@@ -909,7 +918,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
909918
}
910919
}
911920

912-
let mut dup_constraints = FxIndexMap::default();
921+
let mut dup_constraints = (overlapping_assoc_item_constraints
922+
== OverlappingAsssocItemConstraints::Forbidden)
923+
.then_some(FxIndexMap::default());
924+
913925
for constraint in trait_segment.args().constraints {
914926
// Don't register any associated item constraints for negative bounds,
915927
// since we should have emitted an error for them earlier, and they
@@ -928,7 +940,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
928940
poly_trait_ref,
929941
constraint,
930942
bounds,
931-
for_dyn.then_some(&mut dup_constraints),
943+
dup_constraints.as_mut(),
932944
constraint.span,
933945
predicate_filter,
934946
);

0 commit comments

Comments
 (0)