Skip to content

Commit fc63e9a

Browse files
committed
dont build abstract const for monomorphic consts
1 parent 08e8644 commit fc63e9a

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,36 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
267267
let builder =
268268
AbstractConstBuilder { tcx, body_id, body: Lrc::new(body), nodes: IndexVec::new() };
269269

270-
// FIXME non-constants should return Ok(None)
270+
struct IsThirPolymorphic<'a, 'tcx> {
271+
is_poly: bool,
272+
thir: &'a thir::Thir<'tcx>,
273+
tcx: TyCtxt<'tcx>,
274+
}
275+
276+
use thir::visit;
277+
impl<'a, 'tcx: 'a> visit::Visitor<'a, 'tcx> for IsThirPolymorphic<'a, 'tcx> {
278+
fn thir(&self) -> &'a thir::Thir<'tcx> {
279+
&self.thir
280+
}
281+
282+
fn visit_expr(&mut self, expr: &thir::Expr<'tcx>) {
283+
self.is_poly |= expr.ty.definitely_has_param_types_or_consts(self.tcx);
284+
if self.is_poly {
285+
return;
286+
}
287+
visit::walk_expr(self, expr);
288+
}
289+
290+
fn visit_const(&mut self, ct: &'tcx ty::Const<'tcx>) {
291+
self.is_poly |= ct.definitely_has_param_types_or_consts(self.tcx);
292+
}
293+
}
294+
295+
let mut is_poly_vis = IsThirPolymorphic { is_poly: false, thir: body, tcx };
296+
visit::walk_expr(&mut is_poly_vis, &body[body_id]);
297+
if is_poly_vis.is_poly == false {
298+
return Ok(None);
299+
}
271300

272301
Ok(Some(builder))
273302
}

0 commit comments

Comments
 (0)