From abe040d876f697ef86b1ad395caf68c03ecbf046 Mon Sep 17 00:00:00 2001 From: kadmin Date: Sun, 4 Dec 2022 19:58:03 +0000 Subject: [PATCH] Change commit_if_ok to probe --- .../src/traits/const_evaluatable.rs | 11 ++---- .../const_kind_expr/wf_obligation.rs | 3 +- .../const_kind_expr/wf_obligation.stderr | 12 +------ .../ui/const-generics/issues/issue-105037.rs | 35 +++++++++++++++++++ 4 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 src/test/ui/const-generics/issues/issue-105037.rs diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index f8efe9bfa9f..f449d360c16 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -173,16 +173,11 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Visitor<'a, 'tcx> { type BreakTy = (); fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow { 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); - if let Ok(()) = ocx.eq(&ObligationCause::dummy(), self.param_env, c.ty(), self.ct.ty()) - && let Ok(()) = ocx.eq(&ObligationCause::dummy(), self.param_env, c, self.ct) + ocx.eq(&ObligationCause::dummy(), self.param_env, c.ty(), self.ct.ty()).is_ok() + && ocx.eq(&ObligationCause::dummy(), self.param_env, c, self.ct).is_ok() && ocx.select_all_or_error().is_empty() - { - Ok(()) - } else { - Err(()) - } }) { ControlFlow::BREAK } else if let ty::ConstKind::Expr(e) = c.kind() { diff --git a/src/test/ui/const-generics/generic_const_exprs/const_kind_expr/wf_obligation.rs b/src/test/ui/const-generics/generic_const_exprs/const_kind_expr/wf_obligation.rs index 6093fc70b16..b96e210808b 100644 --- a/src/test/ui/const-generics/generic_const_exprs/const_kind_expr/wf_obligation.rs +++ b/src/test/ui/const-generics/generic_const_exprs/const_kind_expr/wf_obligation.rs @@ -15,8 +15,7 @@ fn ice() [(); (L - 1) + 1 + L]:, { foo::<_, L>([(); L + 1 + L]); - //~^ ERROR: mismatched types - //~^^ ERROR: unconstrained generic constant + //~^ ERROR: unconstrained generic constant } fn main() {} diff --git a/src/test/ui/const-generics/generic_const_exprs/const_kind_expr/wf_obligation.stderr b/src/test/ui/const-generics/generic_const_exprs/const_kind_expr/wf_obligation.stderr index da5194696e6..09e5e3f862a 100644 --- a/src/test/ui/const-generics/generic_const_exprs/const_kind_expr/wf_obligation.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/const_kind_expr/wf_obligation.stderr @@ -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 --> $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]:` -error: aborting due to 2 previous errors +error: aborting due to previous error -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/issues/issue-105037.rs b/src/test/ui/const-generics/issues/issue-105037.rs new file mode 100644 index 00000000000..f7d23949943 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-105037.rs @@ -0,0 +1,35 @@ +// run-pass +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] +#![allow(dead_code)] + +trait Table: Sync { + const COLUMNS: usize; +} + +struct Table1; +impl Table for Table1 { + const COLUMNS: usize = 123; +} + +struct Table2; +impl Table for Table2 { + const COLUMNS: usize = 456; +} + +fn process_table, const D: usize>(_table: T) +where + [(); T::COLUMNS]:, +{ +} + +fn process_all_tables() +where + [(); Table2::::COLUMNS]:, + [(); Table1::::COLUMNS]:, +{ + process_table(Table1::); + process_table(Table2::); +} + +fn main() {}