Make sure to insert Sized bound first into clauses list

This commit is contained in:
Michael Goulet 2024-03-31 17:20:00 -04:00
parent dd5e502d4b
commit f2fd2d8c70
3 changed files with 39 additions and 3 deletions

View File

@ -54,14 +54,20 @@ impl<'tcx> Bounds<'tcx> {
span: Span,
polarity: ty::PredicatePolarity,
) {
self.clauses.push((
let clause = (
trait_ref
.map_bound(|trait_ref| {
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity })
})
.to_predicate(tcx),
span,
));
);
// FIXME(-Znext-solver): We can likely remove this hack once the new trait solver lands.
if tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) {
self.clauses.insert(0, clause);
} else {
self.clauses.push(clause);
}
}
pub fn push_projection_bound(

View File

@ -217,7 +217,7 @@ pub fn second_trait_bound<T: Eq + Clone>() {}
pub fn second_builtin_bound<T: Send >() {}
#[cfg(not(any(cfail1,cfail4)))]
#[rustc_clean(cfg = "cfail2", except = "opt_hir_owner_nodes, predicates_of")]
#[rustc_clean(cfg = "cfail2", except = "opt_hir_owner_nodes")]
#[rustc_clean(cfg = "cfail3")]
#[rustc_clean(cfg = "cfail5", except = "opt_hir_owner_nodes, predicates_of")]
#[rustc_clean(cfg = "cfail6")]

View File

@ -0,0 +1,30 @@
//@ check-pass
// Regression test due to #123279
pub trait Job: AsJob {
fn run_once(&self);
}
impl<F: Fn()> Job for F {
fn run_once(&self) {
todo!()
}
}
pub trait AsJob {}
// Ensure that `T: Sized + Job` by reordering the explicit `Sized` to where
// the implicit sized pred would go.
impl<T: Job + Sized> AsJob for T {}
pub struct LoopingJobService {
job: Box<dyn Job>,
}
impl Job for LoopingJobService {
fn run_once(&self) {
self.job.run_once()
}
}
fn main() {}