Skip to content

Commit

Permalink
add test for builtin types N + N unifying with fn call
Browse files Browse the repository at this point in the history
  • Loading branch information
BoxyUwU committed Sep 9, 2021
1 parent fd9bb30 commit 8295e4a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 10 additions & 3 deletions compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>) {
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);

Expand All @@ -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() {}
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 8295e4a

Please sign in to comment.