Skip to content

Commit fdb25e1

Browse files
committed
[WIP] Trait aliases: Imply default trait bounds
1 parent d00ba92 commit fdb25e1

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,33 @@ 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(param.def_id, hir_generics.predicates),
985+
param.span,
986+
);
987+
self.lowerer().add_default_traits(
988+
&mut bounds,
989+
param_ty,
990+
&[],
991+
ImpliedBoundsContext::TyParam(param.def_id, hir_generics.predicates),
992+
param.span,
993+
);
994+
}
995+
// FIXME(fmease): Relevant, too?
996+
hir::GenericParamKind::Const { .. } => {}
997+
}
998+
}
999+
}
1000+
9741001
for predicate in hir_generics.predicates {
9751002
let hir_id = predicate.hir_id;
9761003
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; // has a default `T: Mark` bound
18+
fn f1<T: ?Mark>() where (): A1<T> {}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)