This commit is contained in:
Yuki Okushi 2019-12-23 08:39:33 +09:00
parent 6d12259811
commit d5316163b6
2 changed files with 7 additions and 19 deletions

View file

@ -6,7 +6,7 @@ use rustc::hir::def::{DefKind, Res};
use rustc::hir::*;
use rustc::lint::LateContext;
use rustc::ty::subst::{Subst, SubstsRef};
use rustc::ty::{self, Instance, Ty, TyCtxt};
use rustc::ty::{self, Ty, TyCtxt};
use rustc::{bug, span_bug};
use rustc_data_structures::sync::Lrc;
use std::cmp::Ordering::{self, Equal};
@ -328,8 +328,6 @@ 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<Constant> {
use rustc::mir::interpret::GlobalId;
let res = self.tables.qpath_res(qpath, id);
match res {
Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
@ -339,13 +337,12 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
} else {
substs.subst(self.lcx.tcx, self.substs)
};
let instance = Instance::resolve(self.lcx.tcx, self.param_env, def_id, substs)?;
let gid = GlobalId {
instance,
promoted: None,
};
let result = self.lcx.tcx.const_eval(self.param_env.and(gid)).ok()?;
let result = self
.lcx
.tcx
.const_eval_resolve(self.param_env, def_id, substs, None)
.ok()?;
let result = miri_to_const(&result);
if result.is_some() {
self.needed_resolution = true;

View file

@ -6,9 +6,7 @@ use crate::utils::span_lint;
use rustc::declare_lint_pass;
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::mir::interpret::GlobalId;
use rustc::ty;
use rustc::ty::subst::InternalSubsts;
use rustc::ty::util::IntTypeExt;
use rustc_session::declare_tool_lint;
use std::convert::TryFrom;
@ -48,15 +46,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
if let ItemKind::Enum(def, _) = &item.kind {
for var in def.variants {
if let Some(anon_const) = &var.disr_expr {
let param_env = ty::ParamEnv::empty();
let def_id = cx.tcx.hir().body_owner_def_id(anon_const.body);
let substs = InternalSubsts::identity_for_item(cx.tcx, def_id);
let instance = ty::Instance::new(def_id, substs);
let c_id = GlobalId {
instance,
promoted: None,
};
let constant = cx.tcx.const_eval(param_env.and(c_id)).ok();
let constant = cx.tcx.const_eval_poly(def_id).ok();
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 {