add test for builtin types N + N unifying with fn call
This commit is contained in:
parent
fd9bb30ab8
commit
8295e4a6cf
4 changed files with 33 additions and 5 deletions
|
@ -1305,7 +1305,7 @@ impl EncodeContext<'a, 'tcx> {
|
||||||
if encode_const {
|
if encode_const {
|
||||||
record!(self.tables.mir_for_ctfe[def_id.to_def_id()] <- self.tcx.mir_for_ctfe(def_id));
|
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);
|
let abstract_const = self.tcx.thir_abstract_const(def_id);
|
||||||
if let Ok(Some(abstract_const)) = abstract_const {
|
if let Ok(Some(abstract_const)) = abstract_const {
|
||||||
record!(self.tables.thir_abstract_consts[def_id.to_def_id()] <- abstract_const);
|
record!(self.tables.thir_abstract_consts[def_id.to_def_id()] <- abstract_const);
|
||||||
|
|
|
@ -267,10 +267,16 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
|
||||||
|
|
||||||
fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
|
fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
|
||||||
self.is_poly |= expr.ty.definitely_has_param_types_or_consts(self.tcx);
|
self.is_poly |= expr.ty.definitely_has_param_types_or_consts(self.tcx);
|
||||||
if self.is_poly {
|
if self.is_poly == false {
|
||||||
return;
|
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>) {
|
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 };
|
let mut is_poly_vis = IsThirPolymorphic { is_poly: false, thir: body, tcx };
|
||||||
visit::walk_expr(&mut is_poly_vis, &body[body_id]);
|
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 {
|
if is_poly_vis.is_poly == false {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// check-pass
|
|
||||||
#![feature(generic_const_exprs, adt_const_params, const_trait_impl)]
|
#![feature(generic_const_exprs, adt_const_params, const_trait_impl)]
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
// test `N + N` unifies with explicit function calls for non-builtin-types
|
||||||
#[derive(PartialEq, Eq)]
|
#[derive(PartialEq, Eq)]
|
||||||
struct Foo(u8);
|
struct Foo(u8);
|
||||||
|
|
||||||
|
@ -21,4 +21,15 @@ fn foo<const N: Foo>(a: Evaluatable<{ N + N }>) {
|
||||||
|
|
||||||
fn bar<const N: Foo>() {}
|
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() {}
|
fn main() {}
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue