mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 15:32:06 +00:00
internal: add implicit : Sized
bound to type parameters.
This commit is contained in:
parent
3dae94bf2b
commit
9ce3c075ad
@ -1024,7 +1024,7 @@ pub(crate) fn generic_predicates_for_param_query(
|
||||
let ctx =
|
||||
TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable);
|
||||
let generics = generics(db.upcast(), param_id.parent);
|
||||
resolver
|
||||
let mut predicates: Vec<_> = resolver
|
||||
.where_predicates_in_scope()
|
||||
// we have to filter out all other predicates *first*, before attempting to lower them
|
||||
.filter(|pred| match pred {
|
||||
@ -1038,7 +1038,15 @@ pub(crate) fn generic_predicates_for_param_query(
|
||||
WherePredicate::Lifetime { .. } => false,
|
||||
})
|
||||
.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(
|
||||
|
@ -3520,15 +3520,15 @@ fn foo() {
|
||||
r#"
|
||||
//- minicore: sized
|
||||
struct Foo<T>(T);
|
||||
trait Copy {}
|
||||
trait Clone {}
|
||||
impl<T: Copy + Clone> Foo<T$0> where T: Sized {}
|
||||
trait TraitA {}
|
||||
trait TraitB {}
|
||||
impl<T: TraitA + TraitB> Foo<T$0> where T: Sized {}
|
||||
"#,
|
||||
expect![[r#"
|
||||
*T*
|
||||
|
||||
```rust
|
||||
T: Copy + Clone
|
||||
T: TraitA + TraitB
|
||||
```
|
||||
"#]],
|
||||
);
|
||||
@ -3562,20 +3562,35 @@ impl<T: 'static> Foo<T$0> {}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hover_type_param_not_sized() {
|
||||
fn hover_type_param_sized_bounds() {
|
||||
// implicit `: Sized` bound
|
||||
check(
|
||||
r#"
|
||||
//- minicore: sized
|
||||
trait Trait {}
|
||||
struct Foo<T>(T);
|
||||
trait Copy {}
|
||||
trait Clone {}
|
||||
impl<T: Copy + Clone> Foo<T$0> where T: ?Sized {}
|
||||
impl<T: Trait> Foo<T$0> {}
|
||||
"#,
|
||||
expect![[r#"
|
||||
*T*
|
||||
|
||||
```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…
Reference in New Issue
Block a user