add test for builtin types N + N unifying with fn call

This commit is contained in:
Ellen 2021-09-09 15:43:59 +01:00
parent fd9bb30ab8
commit 8295e4a6cf
4 changed files with 33 additions and 5 deletions

View File

@ -1305,7 +1305,7 @@ impl EncodeContext<'a, 'tcx> {
if encode_const {
record!(self.tables.mir_for_ctfe[def_id.to_def_id()] <- self.tcx.mir_for_ctfe(def_id));
// FIXME this feels wrong to have in `encode_mir`
// FIXME(generic_const_exprs): this feels wrong to have in `encode_mir`
let abstract_const = self.tcx.thir_abstract_const(def_id);
if let Ok(Some(abstract_const)) = abstract_const {
record!(self.tables.thir_abstract_consts[def_id.to_def_id()] <- abstract_const);

View File

@ -267,10 +267,16 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
self.is_poly |= expr.ty.definitely_has_param_types_or_consts(self.tcx);
if self.is_poly {
return;
if self.is_poly == false {
visit::walk_expr(self, expr)
}
}
fn visit_pat(&mut self, pat: &thir::Pat<'tcx>) {
self.is_poly |= pat.ty.definitely_has_param_types_or_consts(self.tcx);
if self.is_poly == false {
visit::walk_pat(self, pat);
}
visit::walk_expr(self, expr);
}
fn visit_const(&mut self, ct: &'tcx ty::Const<'tcx>) {
@ -280,6 +286,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
let mut is_poly_vis = IsThirPolymorphic { is_poly: false, thir: body, tcx };
visit::walk_expr(&mut is_poly_vis, &body[body_id]);
debug!("AbstractConstBuilder: is_poly={}", is_poly_vis.is_poly);
if is_poly_vis.is_poly == false {
return Ok(None);
}

View File

@ -1,7 +1,7 @@
// check-pass
#![feature(generic_const_exprs, adt_const_params, const_trait_impl)]
#![allow(incomplete_features)]
// test `N + N` unifies with explicit function calls for non-builtin-types
#[derive(PartialEq, Eq)]
struct Foo(u8);
@ -21,4 +21,15 @@ fn foo<const N: Foo>(a: Evaluatable<{ N + N }>) {
fn bar<const N: Foo>() {}
// test that `N + N` unifies with explicit function calls for builin-types
struct Evaluatable2<const N: usize>;
fn foo2<const N: usize>(a: Evaluatable2<{ N + N }>) {
bar2::<{ std::ops::Add::add(N, N) }>();
//~^ error: unconstrained generic constant
// FIXME(generic_const_exprs) make this not an error
}
fn bar2<const N: usize>() {}
fn main() {}

View File

@ -0,0 +1,10 @@
error: unconstrained generic constant
--> $DIR/unify-op-with-fn-call.rs:28:12
|
LL | bar2::<{ std::ops::Add::add(N, N) }>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: try adding a `where` bound using this expression: `where [(); { std::ops::Add::add(N, N) }]:`
error: aborting due to previous error