Skip to content

Commit 614fb24

Browse files
committed
Auto merge of rust-lang#17939 - ShoyuVanilla:maybe-sized-fix, r=Veykril
fix: Wrong `Sized` predicate for `generic_predicates_for_param` I found this gathers wrong `Self: Sized` bound while implementing object safety, though I couldn't find proper test for this. If we call `generic_predicates_for_param` to `Bar` in the following code; ```rust trait Foo<T: ?Sized> {} trait Bar<T: Foo<Self> + ?Sized> {} ``` it returns `T: Sized` and `Self: Sized` bound, because normaly, the `?Sized` bound applied properly in L1059 with; https://github.com/rust-lang/rust-analyzer/blob/3723e5910c14f0ffbd13de474b8a8fcc74db04ce/crates/hir-ty/src/lower.rs#L1035-L1061 But we filter them before it is lowered with that function here; https://github.com/rust-lang/rust-analyzer/blob/3723e5910c14f0ffbd13de474b8a8fcc74db04ce/crates/hir-ty/src/lower.rs#L1540-L1586 So, the `?Sized` bounded params are not gathered into `ctx.unsized_types` and thus we are applying them implicit `Sized` bound here; https://github.com/rust-lang/rust-analyzer/blob/3723e5910c14f0ffbd13de474b8a8fcc74db04ce/crates/hir-ty/src/lower.rs#L1591-L1602
2 parents 9cb66c2 + db2e8e1 commit 614fb24

File tree

1 file changed

+4
-0
lines changed
  • src/tools/rust-analyzer/crates/hir-ty/src

1 file changed

+4
-0
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/lower.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1551,6 +1551,10 @@ pub(crate) fn generic_predicates_for_param_query(
15511551
}
15521552
};
15531553
if invalid_target {
1554+
// If this is filtered out without lowering, `?Sized` is not gathered into `ctx.unsized_types`
1555+
if let TypeBound::Path(_, TraitBoundModifier::Maybe) = &**bound {
1556+
ctx.lower_where_predicate(pred, &def, true).for_each(drop);
1557+
}
15541558
return false;
15551559
}
15561560

0 commit comments

Comments
 (0)