Skip to content

Rustup to rust-lang/rust#66877 #4944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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) => {
Expand All @@ -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;
Expand Down
11 changes: 1 addition & 10 deletions clippy_lints/src/enum_clike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down