From aa4cf72f28b8cca50f27244502c1b32af4301011 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 19 Feb 2020 07:33:19 +0900 Subject: [PATCH] Rustup to rust-lang/rust#69181 --- clippy_lints/src/consts.rs | 7 ++++--- clippy_lints/src/enum_clike.rs | 8 ++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 5a79848c12877..7efc62d4c2e17 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -226,7 +226,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { return self.ifthenelse(cond, then, otherwise); } match e.kind { - ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id), + ExprKind::Path(ref qpath) => self.fetch_path(qpath, e.hir_id, self.tables.expr_ty(e)), ExprKind::Block(ref block, _) => self.block(block), ExprKind::Lit(ref lit) => Some(lit_to_constant(&lit.node, self.tables.expr_ty_opt(e))), ExprKind::Array(ref vec) => self.multi(vec).map(Constant::Vec), @@ -319,7 +319,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { } /// Lookup a possibly constant expression from a `ExprKind::Path`. - fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId) -> Option { + fn fetch_path(&mut self, qpath: &QPath<'_>, id: HirId, ty: Ty<'cc>) -> Option { let res = self.tables.qpath_res(qpath, id); match res { Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => { @@ -334,7 +334,8 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { .lcx .tcx .const_eval_resolve(self.param_env, def_id, substs, None, None) - .ok()?; + .ok() + .map(|val| rustc::ty::Const::from_value(self.lcx.tcx, val, ty))?; let result = miri_to_const(&result); if result.is_some() { self.needed_resolution = true; diff --git a/clippy_lints/src/enum_clike.rs b/clippy_lints/src/enum_clike.rs index 52ac1ff71250a..2e14956ecd7bd 100644 --- a/clippy_lints/src/enum_clike.rs +++ b/clippy_lints/src/enum_clike.rs @@ -46,9 +46,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant { for var in def.variants { if let Some(anon_const) = &var.disr_expr { let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body); - let constant = cx.tcx.const_eval_poly(def_id).ok(); + let mut ty = cx.tcx.type_of(def_id); + let constant = cx + .tcx + .const_eval_poly(def_id) + .ok() + .map(|val| rustc::ty::Const::from_value(cx.tcx, val, ty)); if let Some(Constant::Int(val)) = constant.and_then(miri_to_const) { - let mut ty = cx.tcx.type_of(def_id); if let ty::Adt(adt, _) = ty.kind { if adt.is_enum() { ty = adt.repr.discr_type().to_ty(cx.tcx);