1
Fork 0

Forbid ?Trait bounds repetitions

This commit is contained in:
Bryanskiy 2024-07-26 16:33:30 +03:00
parent 2a73553513
commit fd9d0bfbac
5 changed files with 72 additions and 11 deletions

View file

@ -75,16 +75,22 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
}
}
if unbounds.len() > 1 && !tcx.features().more_maybe_bounds {
self.tcx()
.sess
.create_feature_err(
errors::MultipleRelaxedDefaultBounds {
spans: unbounds.iter().map(|ptr| ptr.span).collect(),
},
sym::more_maybe_bounds,
)
.emit();
let mut unique_bounds = FxIndexSet::default();
let mut seen_repeat = false;
for unbound in &unbounds {
if let Res::Def(DefKind::Trait, unbound_def_id) = unbound.trait_ref.path.res {
seen_repeat |= !unique_bounds.insert(unbound_def_id);
}
}
if unbounds.len() > 1 {
let err = errors::MultipleRelaxedDefaultBounds {
spans: unbounds.iter().map(|ptr| ptr.span).collect(),
};
if seen_repeat {
self.dcx().emit_err(err);
} else if !tcx.features().more_maybe_bounds {
self.tcx().sess.create_feature_err(err, sym::more_maybe_bounds).emit();
};
}
let mut seen_sized_unbound = false;