Skip to content

Commit abe040d

Browse files
committed
Change commit_if_ok to probe
1 parent 2e677c0 commit abe040d

File tree

4 files changed

+40
-21
lines changed

4 files changed

+40
-21
lines changed

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,11 @@ fn satisfied_from_param_env<'tcx>(
173173
type BreakTy = ();
174174
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
175175
debug!("is_const_evaluatable: candidate={:?}", c);
176-
if let Ok(()) = self.infcx.commit_if_ok(|_| {
176+
if self.infcx.probe(|_| {
177177
let ocx = ObligationCtxt::new_in_snapshot(self.infcx);
178-
if let Ok(()) = ocx.eq(&ObligationCause::dummy(), self.param_env, c.ty(), self.ct.ty())
179-
&& let Ok(()) = ocx.eq(&ObligationCause::dummy(), self.param_env, c, self.ct)
178+
ocx.eq(&ObligationCause::dummy(), self.param_env, c.ty(), self.ct.ty()).is_ok()
179+
&& ocx.eq(&ObligationCause::dummy(), self.param_env, c, self.ct).is_ok()
180180
&& ocx.select_all_or_error().is_empty()
181-
{
182-
Ok(())
183-
} else {
184-
Err(())
185-
}
186181
}) {
187182
ControlFlow::BREAK
188183
} else if let ty::ConstKind::Expr(e) = c.kind() {

src/test/ui/const-generics/generic_const_exprs/const_kind_expr/wf_obligation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ where
1515
[(); (L - 1) + 1 + L]:,
1616
{
1717
foo::<_, L>([(); L + 1 + L]);
18-
//~^ ERROR: mismatched types
19-
//~^^ ERROR: unconstrained generic constant
18+
//~^ ERROR: unconstrained generic constant
2019
}
2120

2221
fn main() {}
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
error[E0308]: mismatched types
2-
--> $DIR/wf_obligation.rs:17:17
3-
|
4-
LL | foo::<_, L>([(); L + 1 + L]);
5-
| ^^^^^^^^^^^^^^^ expected `N + 1 + M`, found `L + 1 + L`
6-
|
7-
= note: expected constant `N + 1 + M`
8-
found constant `L + 1 + L`
9-
101
error: unconstrained generic constant
112
--> $DIR/wf_obligation.rs:17:22
123
|
@@ -15,6 +6,5 @@ LL | foo::<_, L>([(); L + 1 + L]);
156
|
167
= help: try adding a `where` bound using this expression: `where [(); L + 1 + L]:`
178

18-
error: aborting due to 2 previous errors
9+
error: aborting due to previous error
1910

20-
For more information about this error, try `rustc --explain E0308`.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// run-pass
2+
#![feature(generic_const_exprs)]
3+
#![allow(incomplete_features)]
4+
#![allow(dead_code)]
5+
6+
trait Table<const D: usize>: Sync {
7+
const COLUMNS: usize;
8+
}
9+
10+
struct Table1<const D: usize>;
11+
impl<const D: usize> Table<D> for Table1<D> {
12+
const COLUMNS: usize = 123;
13+
}
14+
15+
struct Table2<const D: usize>;
16+
impl<const D: usize> Table<D> for Table2<D> {
17+
const COLUMNS: usize = 456;
18+
}
19+
20+
fn process_table<T: Table<D>, const D: usize>(_table: T)
21+
where
22+
[(); T::COLUMNS]:,
23+
{
24+
}
25+
26+
fn process_all_tables<const D: usize>()
27+
where
28+
[(); Table2::<D>::COLUMNS]:,
29+
[(); Table1::<D>::COLUMNS]:,
30+
{
31+
process_table(Table1::<D>);
32+
process_table(Table2::<D>);
33+
}
34+
35+
fn main() {}

0 commit comments

Comments
 (0)