Skip to content

Commit ffd787c

Browse files
committed
Auto merge of #152688 - fmease:implied-preds-default-bounds, r=<try>
[WIP] Trait aliases: Imply default trait bounds
2 parents 1396514 + 365e6d2 commit ffd787c

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,39 @@ impl<'tcx> ItemCtxt<'tcx> {
971971
) -> Vec<(ty::Clause<'tcx>, Span)> {
972972
let mut bounds = Vec::new();
973973

974+
if let PredicateFilter::All = filter {
975+
for param in hir_generics.params {
976+
match param.kind {
977+
hir::GenericParamKind::Lifetime { .. } => (),
978+
hir::GenericParamKind::Type { .. } => {
979+
let param_ty = self.lowerer().lower_ty_param(param.hir_id);
980+
self.lowerer().add_implicit_sizedness_bounds(
981+
&mut bounds,
982+
param_ty,
983+
&[],
984+
ImpliedBoundsContext::TyParam(
985+
param.def_id,
986+
hir_generics.predicates,
987+
),
988+
param.span,
989+
);
990+
self.lowerer().add_default_traits(
991+
&mut bounds,
992+
param_ty,
993+
&[],
994+
ImpliedBoundsContext::TyParam(
995+
param.def_id,
996+
hir_generics.predicates,
997+
),
998+
param.span,
999+
);
1000+
}
1001+
// FIXME(fmease): Relevant, too?
1002+
hir::GenericParamKind::Const { .. } => {}
1003+
}
1004+
}
1005+
}
1006+
9741007
for predicate in hir_generics.predicates {
9751008
let hir_id = predicate.hir_id;
9761009
let hir::WherePredicateKind::BoundPredicate(predicate) = predicate.kind else {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// FIXME(fmease): Write a nice description!
2+
// Write a nice description!
3+
// Write a nice description!
4+
// issue: <https://github.com/rust-lang/rust/issues/152687>
5+
6+
//@ check-pass
7+
8+
#![feature(trait_alias)]
9+
#![feature(sized_hierarchy)] // only used for test case (B)
10+
11+
trait A0<T: Sized> =;
12+
fn f0<T: ?Sized>() where (): A0<T> {}
13+
14+
trait A1<T> =; // has default `T: Sized` bound
15+
fn f1<T: ?Sized>() where (): A1<T> {}
16+
17+
//
18+
19+
trait B0<T: std::marker::MetaSized> =;
20+
fn g0<T: std::marker::PointeeSized>() where (): B0<T> {}
21+
22+
trait B1<T: ?Sized> =; // has a default `T: MetaSized` bound
23+
fn g1<T: std::marker::PointeeSized>() where (): B1<T> {}
24+
25+
fn main() {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// FIXME(fmease): Write a nice description!
2+
// Write a nice description!
3+
// Write a nice description!
4+
// issue: <https://github.com/rust-lang/rust/issues/152687>
5+
6+
//@ compile-flags: -Zexperimental-default-bounds
7+
//@ check-pass
8+
9+
#![feature(trait_alias, more_maybe_bounds, lang_items, auto_traits)]
10+
11+
#[lang = "default_trait1"]
12+
auto trait Mark {}
13+
14+
trait A0<T: Mark> = ?Mark;
15+
fn f0<T: ?Mark>() where (): A0<T> {}
16+
17+
trait A1<T: Mark> = ?Mark; // has a default `T: Mark` bound
18+
fn f<T: ?Mark>() where (): A1<T> {}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)