mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 14:51:48 +00:00
internal: add implicit : Sized
bound to type parameters.
This commit is contained in:
parent
3dae94bf2b
commit
9ce3c075ad
2 changed files with 34 additions and 11 deletions
|
@ -1024,7 +1024,7 @@ pub(crate) fn generic_predicates_for_param_query(
|
||||||
let ctx =
|
let ctx =
|
||||||
TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
|
TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
|
||||||
let generics = generics(db.upcast(), param_id.parent);
|
let generics = generics(db.upcast(), param_id.parent);
|
||||||
resolver
|
let mut predicates: Vec<_> = resolver
|
||||||
.where_predicates_in_scope()
|
.where_predicates_in_scope()
|
||||||
// we have to filter out all other predicates *first*, before attempting to lower them
|
// we have to filter out all other predicates *first*, before attempting to lower them
|
||||||
.filter(|pred| match pred {
|
.filter(|pred| match pred {
|
||||||
|
@ -1038,7 +1038,15 @@ pub(crate) fn generic_predicates_for_param_query(
|
||||||
WherePredicate::Lifetime { .. } => false,
|
WherePredicate::Lifetime { .. } => false,
|
||||||
})
|
})
|
||||||
.flat_map(|pred| ctx.lower_where_predicate(pred, true).map(|p| make_binders(&generics, p)))
|
.flat_map(|pred| ctx.lower_where_predicate(pred, true).map(|p| make_binders(&generics, p)))
|
||||||
.collect()
|
.collect();
|
||||||
|
|
||||||
|
let subst = generics.bound_vars_subst(DebruijnIndex::INNERMOST);
|
||||||
|
let explicitly_unsized_tys = ctx.unsized_types.into_inner();
|
||||||
|
let implicitly_sized_predicates =
|
||||||
|
implicitly_sized_clauses(db, param_id.parent, &explicitly_unsized_tys, &subst, &resolver)
|
||||||
|
.map(|p| make_binders(&generics, crate::wrap_empty_binders(p)));
|
||||||
|
predicates.extend(implicitly_sized_predicates);
|
||||||
|
predicates.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn generic_predicates_for_param_recover(
|
pub(crate) fn generic_predicates_for_param_recover(
|
||||||
|
|
|
@ -3520,15 +3520,15 @@ fn foo() {
|
||||||
r#"
|
r#"
|
||||||
//- minicore: sized
|
//- minicore: sized
|
||||||
struct Foo<T>(T);
|
struct Foo<T>(T);
|
||||||
trait Copy {}
|
trait TraitA {}
|
||||||
trait Clone {}
|
trait TraitB {}
|
||||||
impl<T: Copy + Clone> Foo<T$0> where T: Sized {}
|
impl<T: TraitA + TraitB> Foo<T$0> where T: Sized {}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
*T*
|
*T*
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
T: Copy + Clone
|
T: TraitA + TraitB
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
@ -3562,20 +3562,35 @@ impl<T: 'static> Foo<T$0> {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hover_type_param_not_sized() {
|
fn hover_type_param_sized_bounds() {
|
||||||
|
// implicit `: Sized` bound
|
||||||
check(
|
check(
|
||||||
r#"
|
r#"
|
||||||
//- minicore: sized
|
//- minicore: sized
|
||||||
|
trait Trait {}
|
||||||
struct Foo<T>(T);
|
struct Foo<T>(T);
|
||||||
trait Copy {}
|
impl<T: Trait> Foo<T$0> {}
|
||||||
trait Clone {}
|
|
||||||
impl<T: Copy + Clone> Foo<T$0> where T: ?Sized {}
|
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
*T*
|
*T*
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
T: Copy + Clone + ?Sized
|
T: Trait
|
||||||
|
```
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
//- minicore: sized
|
||||||
|
trait Trait {}
|
||||||
|
struct Foo<T>(T);
|
||||||
|
impl<T: Trait + ?Sized> Foo<T$0> {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
*T*
|
||||||
|
|
||||||
|
```rust
|
||||||
|
T: Trait + ?Sized
|
||||||
```
|
```
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue