Skip to content

Commit f2fd2d8

Browse files
Make sure to insert Sized bound first into clauses list
1 parent dd5e502 commit f2fd2d8

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
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(

tests/incremental/hashes/function_interfaces.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ pub fn second_trait_bound<T: Eq + Clone>() {}
217217
pub fn second_builtin_bound<T: Send >() {}
218218

219219
#[cfg(not(any(cfail1,cfail4)))]
220-
#[rustc_clean(cfg = "cfail2", except = "opt_hir_owner_nodes, predicates_of")]
220+
#[rustc_clean(cfg = "cfail2", except = "opt_hir_owner_nodes")]
221221
#[rustc_clean(cfg = "cfail3")]
222222
#[rustc_clean(cfg = "cfail5", except = "opt_hir_owner_nodes, predicates_of")]
223223
#[rustc_clean(cfg = "cfail6")]
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)