Skip to content

Commit 24c190c

Browse files
Rollup merge of #158390 - Jamesbarford:fix/trait-solver-const-bounds, r=fmease
Fix: auto trait, const trait bound Split from #158346. I was fiddling about with the code to understand the behaviour of the snippet below, got confused, and somehow fixed something 🤷 ```rust #![feature(const_trait_impl)] pub struct Outer<T>(Inner<T>); struct Inner<T>(T); impl<T> Unpin for Inner<T> where T: const std::default::Default, {} ``` Fixes #149281
2 parents 60ba47e + 915b021 commit 24c190c

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

compiler/rustc_trait_selection/src/traits/auto_trait.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,12 @@ impl<'tcx> AutoTraitFinder<'tcx> {
607607
// if possible.
608608
predicates.push_back(bound_predicate.rebind(p));
609609
}
610+
ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(p)) => {
611+
let p = bound_predicate.rebind(p);
612+
if self.is_param_no_infer(p.skip_binder().trait_ref.args) && is_new_pred {
613+
self.add_user_pred(computed_preds, predicate);
614+
}
615+
}
610616
ty::PredicateKind::Clause(ty::ClauseKind::Projection(p)) => {
611617
let p = bound_predicate.rebind(p);
612618
debug!(
@@ -811,8 +817,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
811817
| ty::PredicateKind::DynCompatible(..)
812818
| ty::PredicateKind::Subtype(..)
813819
| ty::PredicateKind::Coerce(..)
814-
| ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_))
815-
| ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..)) => {}
820+
| ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_)) => {}
816821
ty::PredicateKind::Ambiguous => return false,
817822

818823
// FIXME(generic_const_exprs): you can absolutely add this as a where clauses
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// We used to ICE here while trying to synthesize auto trait impls.
2+
//@ check-pass
3+
4+
#![feature(const_default)]
5+
#![feature(const_trait_impl)]
6+
7+
pub struct Inner<T>(T);
8+
9+
pub struct Outer<T>(Inner<T>);
10+
11+
impl<T> Unpin for Inner<T>
12+
where
13+
T: const std::default::Default,
14+
{}

0 commit comments

Comments
 (0)