Change commit_if_ok to probe
This commit is contained in:
parent
2e677c0645
commit
abe040d876
4 changed files with 40 additions and 21 deletions
|
@ -173,16 +173,11 @@ fn satisfied_from_param_env<'tcx>(
|
||||||
type BreakTy = ();
|
type BreakTy = ();
|
||||||
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
|
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||||
debug!("is_const_evaluatable: candidate={:?}", c);
|
debug!("is_const_evaluatable: candidate={:?}", c);
|
||||||
if let Ok(()) = self.infcx.commit_if_ok(|_| {
|
if self.infcx.probe(|_| {
|
||||||
let ocx = ObligationCtxt::new_in_snapshot(self.infcx);
|
let ocx = ObligationCtxt::new_in_snapshot(self.infcx);
|
||||||
if let Ok(()) = ocx.eq(&ObligationCause::dummy(), self.param_env, c.ty(), self.ct.ty())
|
ocx.eq(&ObligationCause::dummy(), self.param_env, c.ty(), self.ct.ty()).is_ok()
|
||||||
&& let Ok(()) = ocx.eq(&ObligationCause::dummy(), self.param_env, c, self.ct)
|
&& ocx.eq(&ObligationCause::dummy(), self.param_env, c, self.ct).is_ok()
|
||||||
&& ocx.select_all_or_error().is_empty()
|
&& ocx.select_all_or_error().is_empty()
|
||||||
{
|
|
||||||
Ok(())
|
|
||||||
} else {
|
|
||||||
Err(())
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
ControlFlow::BREAK
|
ControlFlow::BREAK
|
||||||
} else if let ty::ConstKind::Expr(e) = c.kind() {
|
} else if let ty::ConstKind::Expr(e) = c.kind() {
|
||||||
|
|
|
@ -15,8 +15,7 @@ where
|
||||||
[(); (L - 1) + 1 + L]:,
|
[(); (L - 1) + 1 + L]:,
|
||||||
{
|
{
|
||||||
foo::<_, L>([(); L + 1 + L]);
|
foo::<_, L>([(); L + 1 + L]);
|
||||||
//~^ ERROR: mismatched types
|
//~^ ERROR: unconstrained generic constant
|
||||||
//~^^ ERROR: unconstrained generic constant
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,12 +1,3 @@
|
||||||
error[E0308]: mismatched types
|
|
||||||
--> $DIR/wf_obligation.rs:17:17
|
|
||||||
|
|
|
||||||
LL | foo::<_, L>([(); L + 1 + L]);
|
|
||||||
| ^^^^^^^^^^^^^^^ expected `N + 1 + M`, found `L + 1 + L`
|
|
||||||
|
|
|
||||||
= note: expected constant `N + 1 + M`
|
|
||||||
found constant `L + 1 + L`
|
|
||||||
|
|
||||||
error: unconstrained generic constant
|
error: unconstrained generic constant
|
||||||
--> $DIR/wf_obligation.rs:17:22
|
--> $DIR/wf_obligation.rs:17:22
|
||||||
|
|
|
|
||||||
|
@ -15,6 +6,5 @@ LL | foo::<_, L>([(); L + 1 + L]);
|
||||||
|
|
|
|
||||||
= help: try adding a `where` bound using this expression: `where [(); L + 1 + L]:`
|
= help: try adding a `where` bound using this expression: `where [(); L + 1 + L]:`
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to previous error
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0308`.
|
|
||||||
|
|
35
src/test/ui/const-generics/issues/issue-105037.rs
Normal file
35
src/test/ui/const-generics/issues/issue-105037.rs
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
// run-pass
|
||||||
|
#![feature(generic_const_exprs)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
|
trait Table<const D: usize>: Sync {
|
||||||
|
const COLUMNS: usize;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Table1<const D: usize>;
|
||||||
|
impl<const D: usize> Table<D> for Table1<D> {
|
||||||
|
const COLUMNS: usize = 123;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Table2<const D: usize>;
|
||||||
|
impl<const D: usize> Table<D> for Table2<D> {
|
||||||
|
const COLUMNS: usize = 456;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn process_table<T: Table<D>, const D: usize>(_table: T)
|
||||||
|
where
|
||||||
|
[(); T::COLUMNS]:,
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
fn process_all_tables<const D: usize>()
|
||||||
|
where
|
||||||
|
[(); Table2::<D>::COLUMNS]:,
|
||||||
|
[(); Table1::<D>::COLUMNS]:,
|
||||||
|
{
|
||||||
|
process_table(Table1::<D>);
|
||||||
|
process_table(Table2::<D>);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Add table
Add a link
Reference in a new issue