Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,33 @@ impl<'tcx> ItemCtxt<'tcx> {
) -> Vec<(ty::Clause<'tcx>, Span)> {
let mut bounds = Vec::new();

if let PredicateFilter::All = filter {
for param in hir_generics.params {
match param.kind {
hir::GenericParamKind::Lifetime { .. } => (),
hir::GenericParamKind::Type { .. } => {
let param_ty = self.lowerer().lower_ty_param(param.hir_id);
self.lowerer().add_implicit_sizedness_bounds(
&mut bounds,
param_ty,
&[],
ImpliedBoundsContext::TyParam(param.def_id, hir_generics.predicates),
param.span,
);
self.lowerer().add_default_traits(
&mut bounds,
param_ty,
&[],
ImpliedBoundsContext::TyParam(param.def_id, hir_generics.predicates),
param.span,
);
}
// FIXME(fmease): Relevant, too?
hir::GenericParamKind::Const { .. } => {}
}
}
}

for predicate in hir_generics.predicates {
let hir_id = predicate.hir_id;
let hir::WherePredicateKind::BoundPredicate(predicate) = predicate.kind else {
Expand Down
25 changes: 25 additions & 0 deletions tests/ui/traits/alias/default-trait-bounds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// FIXME(fmease): Write a nice description!
// Write a nice description!
// Write a nice description!
// issue: <https://github.com/rust-lang/rust/issues/152687>

//@ check-pass

#![feature(trait_alias)]
#![feature(sized_hierarchy)] // only used for test case (B)

trait A0<T: Sized> =;
fn f0<T: ?Sized>() where (): A0<T> {}

trait A1<T> =; // has default `T: Sized` bound
fn f1<T: ?Sized>() where (): A1<T> {}

//

trait B0<T: std::marker::MetaSized> =;
fn g0<T: std::marker::PointeeSized>() where (): B0<T> {}

trait B1<T: ?Sized> =; // has a default `T: MetaSized` bound
fn g1<T: std::marker::PointeeSized>() where (): B1<T> {}

fn main() {}
20 changes: 20 additions & 0 deletions tests/ui/traits/alias/more-default-trait-bounds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// FIXME(fmease): Write a nice description!
// Write a nice description!
// Write a nice description!
// issue: <https://github.com/rust-lang/rust/issues/152687>

//@ compile-flags: -Zexperimental-default-bounds
//@ check-pass

#![feature(trait_alias, more_maybe_bounds, lang_items, auto_traits)]

#[lang = "default_trait1"]
auto trait Mark {}

trait A0<T: Mark> = ?Mark;
fn f0<T: ?Mark>() where (): A0<T> {}

trait A1<T> = ?Mark; // has a default `T: Mark` bound
fn f1<T: ?Mark>() where (): A1<T> {}

fn main() {}
Loading