1
Fork 0

Move trait bound modifiers into hir::PolyTraitRef

This commit is contained in:
Michael Goulet 2024-10-13 09:16:03 -04:00
parent f6648f252a
commit 7500e09b8b
32 changed files with 102 additions and 100 deletions

View file

@ -86,7 +86,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
}
hir::TyKind::TraitObject(bounds, ..) => {
for (bound, _) in bounds {
for bound in bounds {
self.current_index.shift_in(1);
self.visit_poly_trait_ref(bound);
self.current_index.shift_out(1);

View file

@ -599,7 +599,7 @@ impl<'a, 'tcx> Visitor<'tcx> for HirTraitObjectVisitor<'a> {
_,
) = t.kind
{
for (ptr, _) in poly_trait_refs {
for ptr in poly_trait_refs {
if Some(self.1) == ptr.trait_ref.trait_def_id() {
self.0.push(ptr.span);
}

View file

@ -894,7 +894,9 @@ fn foo(&self) -> Self::T { String::new() }
// FIXME: we would want to call `resolve_vars_if_possible` on `ty` before suggesting.
let trait_bounds = bounds.iter().filter_map(|bound| match bound {
hir::GenericBound::Trait(ptr, hir::TraitBoundModifier::None) => Some(ptr),
hir::GenericBound::Trait(ptr) if ptr.modifiers == hir::TraitBoundModifier::None => {
Some(ptr)
}
_ => None,
});

View file

@ -740,9 +740,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
) if std::iter::zip(*last_bounds, *exp_bounds).all(|(left, right)| match (
left, right,
) {
(hir::GenericBound::Trait(tl, ml), hir::GenericBound::Trait(tr, mr))
// FIXME: Suspicious
(hir::GenericBound::Trait(tl), hir::GenericBound::Trait(tr))
if tl.trait_ref.trait_def_id() == tr.trait_ref.trait_def_id()
&& ml == mr =>
&& tl.modifiers == tr.modifiers =>
{
true
}

View file

@ -439,7 +439,7 @@ pub fn report_dyn_incompatibility<'tcx>(
if tcx.parent_hir_node(hir_id).fn_sig().is_some() {
// Do not suggest `impl Trait` when dealing with things like super-traits.
err.span_suggestion_verbose(
ty.span.until(trait_ref.0.span),
ty.span.until(trait_ref.span),
"consider using an opaque type instead",
"impl ",
Applicability::MaybeIncorrect,

View file

@ -3074,11 +3074,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
match ty.kind {
hir::TyKind::TraitObject(traits, _, _) => {
let (span, kw) = match traits {
[(first, _), ..] if first.span.lo() == ty.span.lo() => {
[first, ..] if first.span.lo() == ty.span.lo() => {
// Missing `dyn` in front of trait object.
(ty.span.shrink_to_lo(), "dyn ")
}
[(first, _), ..] => (ty.span.until(first.span), ""),
[first, ..] => (ty.span.until(first.span), ""),
[] => span_bug!(ty.span, "trait object with no traits: {ty:?}"),
};
let needs_parens = traits.len() != 1;
@ -5162,7 +5162,7 @@ pub fn suggest_desugaring_async_fn_to_impl_future_in_trait<'tcx>(
let async_span = tcx.sess.source_map().span_extend_while_whitespace(async_span);
let future = tcx.hir_node_by_def_id(opaque_def_id).expect_opaque_ty();
let [hir::GenericBound::Trait(trait_ref, _)] = future.bounds else {
let [hir::GenericBound::Trait(trait_ref)] = future.bounds else {
// `async fn` should always lower to a single bound... but don't ICE.
return None;
};

View file

@ -125,7 +125,7 @@ fn sized_trait_bound_spans<'tcx>(
bounds: hir::GenericBounds<'tcx>,
) -> impl 'tcx + Iterator<Item = Span> {
bounds.iter().filter_map(move |b| match b {
hir::GenericBound::Trait(trait_ref, hir::TraitBoundModifier::None)
hir::GenericBound::Trait(trait_ref)
if trait_has_sized_self(
tcx,
trait_ref.trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise()),