diff options
| author | Ellen <supbscripter@gmail.com> | 2021-09-07 00:05:59 +0100 |
|---|---|---|
| committer | Ellen <supbscripter@gmail.com> | 2021-09-09 01:32:03 +0100 |
| commit | fc63e9a8fb619ad79d2d24db06078652a2a6c1ba (patch) | |
| tree | 9715ab02f44382c748b70c523dab32131960f2cd | |
| parent | 08e86440165619c57e0072eb742c7dad3cfd0950 (diff) | |
| download | rust-fc63e9a8fb619ad79d2d24db06078652a2a6c1ba.tar.gz rust-fc63e9a8fb619ad79d2d24db06078652a2a6c1ba.zip | |
dont build abstract const for monomorphic consts
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/const_evaluatable.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 7d69ec54bdf..3e1719e08ac 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -267,7 +267,36 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> { let builder = AbstractConstBuilder { tcx, body_id, body: Lrc::new(body), nodes: IndexVec::new() }; - // FIXME non-constants should return Ok(None) + struct IsThirPolymorphic<'a, 'tcx> { + is_poly: bool, + thir: &'a thir::Thir<'tcx>, + tcx: TyCtxt<'tcx>, + } + + use thir::visit; + impl<'a, 'tcx: 'a> visit::Visitor<'a, 'tcx> for IsThirPolymorphic<'a, 'tcx> { + fn thir(&self) -> &'a thir::Thir<'tcx> { + &self.thir + } + + 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; + } + visit::walk_expr(self, expr); + } + + fn visit_const(&mut self, ct: &'tcx ty::Const<'tcx>) { + self.is_poly |= ct.definitely_has_param_types_or_consts(self.tcx); + } + } + + let mut is_poly_vis = IsThirPolymorphic { is_poly: false, thir: body, tcx }; + visit::walk_expr(&mut is_poly_vis, &body[body_id]); + if is_poly_vis.is_poly == false { + return Ok(None); + } Ok(Some(builder)) } |
