Skip to content

Commit 8295e4a

Browse files
committed
add test for builtin types N + N unifying with fn call
1 parent fd9bb30 commit 8295e4a

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1305,7 +1305,7 @@ impl EncodeContext<'a, 'tcx> {
13051305
if encode_const {
13061306
record!(self.tables.mir_for_ctfe[def_id.to_def_id()] <- self.tcx.mir_for_ctfe(def_id));
13071307

1308-
// FIXME this feels wrong to have in `encode_mir`
1308+
// FIXME(generic_const_exprs): this feels wrong to have in `encode_mir`
13091309
let abstract_const = self.tcx.thir_abstract_const(def_id);
13101310
if let Ok(Some(abstract_const)) = abstract_const {
13111311
record!(self.tables.thir_abstract_consts[def_id.to_def_id()] <- abstract_const);

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,16 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
267267

268268
fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
269269
self.is_poly |= expr.ty.definitely_has_param_types_or_consts(self.tcx);
270-
if self.is_poly {
271-
return;
270+
if self.is_poly == false {
271+
visit::walk_expr(self, expr)
272+
}
273+
}
274+
275+
fn visit_pat(&mut self, pat: &thir::Pat<'tcx>) {
276+
self.is_poly |= pat.ty.definitely_has_param_types_or_consts(self.tcx);
277+
if self.is_poly == false {
278+
visit::walk_pat(self, pat);
272279
}
273-
visit::walk_expr(self, expr);
274280
}
275281

276282
fn visit_const(&mut self, ct: &'tcx ty::Const<'tcx>) {
@@ -280,6 +286,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
280286

281287
let mut is_poly_vis = IsThirPolymorphic { is_poly: false, thir: body, tcx };
282288
visit::walk_expr(&mut is_poly_vis, &body[body_id]);
289+
debug!("AbstractConstBuilder: is_poly={}", is_poly_vis.is_poly);
283290
if is_poly_vis.is_poly == false {
284291
return Ok(None);
285292
}

src/test/ui/const-generics/generic_const_exprs/unify-op-with-fn-call.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// check-pass
21
#![feature(generic_const_exprs, adt_const_params, const_trait_impl)]
32
#![allow(incomplete_features)]
43

4+
// test `N + N` unifies with explicit function calls for non-builtin-types
55
#[derive(PartialEq, Eq)]
66
struct Foo(u8);
77

@@ -21,4 +21,15 @@ fn foo<const N: Foo>(a: Evaluatable<{ N + N }>) {
2121

2222
fn bar<const N: Foo>() {}
2323

24+
// test that `N + N` unifies with explicit function calls for builin-types
25+
struct Evaluatable2<const N: usize>;
26+
27+
fn foo2<const N: usize>(a: Evaluatable2<{ N + N }>) {
28+
bar2::<{ std::ops::Add::add(N, N) }>();
29+
//~^ error: unconstrained generic constant
30+
// FIXME(generic_const_exprs) make this not an error
31+
}
32+
33+
fn bar2<const N: usize>() {}
34+
2435
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: unconstrained generic constant
2+
--> $DIR/unify-op-with-fn-call.rs:28:12
3+
|
4+
LL | bar2::<{ std::ops::Add::add(N, N) }>();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: try adding a `where` bound using this expression: `where [(); { std::ops::Add::add(N, N) }]:`
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)