Skip to content

Commit 0e24d74

Browse files
Make sure to insert Sized bound first into clauses list
1 parent 204805a commit 0e24d74

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

compiler/rustc_hir_analysis/src/bounds.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,20 @@ impl<'tcx> Bounds<'tcx> {
5454
span: Span,
5555
polarity: ty::PredicatePolarity,
5656
) {
57-
self.clauses.push((
57+
let clause = (
5858
trait_ref
5959
.map_bound(|trait_ref| {
6060
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity })
6161
})
6262
.to_predicate(tcx),
6363
span,
64-
));
64+
);
65+
// FIXME(-Znext-solver): We can likely remove this hack once the new trait solver lands.
66+
if tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) {
67+
self.clauses.insert(0, clause);
68+
} else {
69+
self.clauses.push(clause);
70+
}
6571
}
6672

6773
pub fn push_projection_bound(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//@ check-pass
2+
// Regression test due to #123279
3+
4+
pub trait Job: AsJob {
5+
fn run_once(&self);
6+
}
7+
8+
impl<F: Fn()> Job for F {
9+
fn run_once(&self) {
10+
todo!()
11+
}
12+
}
13+
14+
pub trait AsJob {}
15+
16+
// Ensure that `T: Sized + Job` by reordering the explicit `Sized` to where
17+
// the implicit sized pred would go.
18+
impl<T: Job + Sized> AsJob for T {}
19+
20+
pub struct LoopingJobService {
21+
job: Box<dyn Job>,
22+
}
23+
24+
impl Job for LoopingJobService {
25+
fn run_once(&self) {
26+
self.job.run_once()
27+
}
28+
}
29+
30+
fn main() {}

0 commit comments

Comments
 (0)