Skip to content

Commit 9ce3c07

Browse files
committed
internal: add implicit : Sized bound to type parameters.
1 parent 3dae94b commit 9ce3c07

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

crates/hir_ty/src/lower.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ pub(crate) fn generic_predicates_for_param_query(
10241024
let ctx =
10251025
TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
10261026
let generics = generics(db.upcast(), param_id.parent);
1027-
resolver
1027+
let mut predicates: Vec<_> = resolver
10281028
.where_predicates_in_scope()
10291029
// we have to filter out all other predicates *first*, before attempting to lower them
10301030
.filter(|pred| match pred {
@@ -1038,7 +1038,15 @@ pub(crate) fn generic_predicates_for_param_query(
10381038
WherePredicate::Lifetime { .. } => false,
10391039
})
10401040
.flat_map(|pred| ctx.lower_where_predicate(pred, true).map(|p| make_binders(&generics, p)))
1041-
.collect()
1041+
.collect();
1042+
1043+
let subst = generics.bound_vars_subst(DebruijnIndex::INNERMOST);
1044+
let explicitly_unsized_tys = ctx.unsized_types.into_inner();
1045+
let implicitly_sized_predicates =
1046+
implicitly_sized_clauses(db, param_id.parent, &explicitly_unsized_tys, &subst, &resolver)
1047+
.map(|p| make_binders(&generics, crate::wrap_empty_binders(p)));
1048+
predicates.extend(implicitly_sized_predicates);
1049+
predicates.into()
10421050
}
10431051

10441052
pub(crate) fn generic_predicates_for_param_recover(

crates/ide/src/hover.rs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3520,15 +3520,15 @@ fn foo() {
35203520
r#"
35213521
//- minicore: sized
35223522
struct Foo<T>(T);
3523-
trait Copy {}
3524-
trait Clone {}
3525-
impl<T: Copy + Clone> Foo<T$0> where T: Sized {}
3523+
trait TraitA {}
3524+
trait TraitB {}
3525+
impl<T: TraitA + TraitB> Foo<T$0> where T: Sized {}
35263526
"#,
35273527
expect![[r#"
35283528
*T*
35293529
35303530
```rust
3531-
T: Copy + Clone
3531+
T: TraitA + TraitB
35323532
```
35333533
"#]],
35343534
);
@@ -3562,20 +3562,35 @@ impl<T: 'static> Foo<T$0> {}
35623562
}
35633563

35643564
#[test]
3565-
fn hover_type_param_not_sized() {
3565+
fn hover_type_param_sized_bounds() {
3566+
// implicit `: Sized` bound
35663567
check(
35673568
r#"
35683569
//- minicore: sized
3570+
trait Trait {}
35693571
struct Foo<T>(T);
3570-
trait Copy {}
3571-
trait Clone {}
3572-
impl<T: Copy + Clone> Foo<T$0> where T: ?Sized {}
3572+
impl<T: Trait> Foo<T$0> {}
3573+
"#,
3574+
expect![[r#"
3575+
*T*
3576+
3577+
```rust
3578+
T: Trait
3579+
```
3580+
"#]],
3581+
);
3582+
check(
3583+
r#"
3584+
//- minicore: sized
3585+
trait Trait {}
3586+
struct Foo<T>(T);
3587+
impl<T: Trait + ?Sized> Foo<T$0> {}
35733588
"#,
35743589
expect![[r#"
35753590
*T*
35763591
35773592
```rust
3578-
T: Copy + Clone + ?Sized
3593+
T: Trait + ?Sized
35793594
```
35803595
"#]],
35813596
);

0 commit comments

Comments
 (0)