Skip to content

Rustup to rustc 1.36.0-nightly (2268d9923 2019-05-26) #4145

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 2 commits into from
May 26, 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
18 changes: 6 additions & 12 deletions clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use rustc::{bug, span_bug};
use rustc_data_structures::sync::Lrc;
use std::cmp::Ordering::{self, Equal};
use std::cmp::PartialOrd;
use std::convert::TryFrom;
use std::convert::TryInto;
use std::hash::{Hash, Hasher};
use syntax::ast::{FloatTy, LitKind};
Expand Down Expand Up @@ -341,7 +340,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
};

let result = self.lcx.tcx.const_eval(self.param_env.and(gid)).ok()?;
let result = miri_to_const(self.lcx.tcx, &result);
let result = miri_to_const(&result);
if result.is_some() {
self.needed_resolution = true;
}
Expand Down Expand Up @@ -466,7 +465,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
}
}

pub fn miri_to_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, result: &ty::Const<'tcx>) -> Option<Constant> {
pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
use rustc::mir::interpret::{ConstValue, Scalar};
match result.val {
ConstValue::Scalar(Scalar::Bits { bits: b, .. }) => match result.ty.sty {
Expand All @@ -487,16 +486,11 @@ pub fn miri_to_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, result: &ty::Const<'
// FIXME: implement other conversions.
_ => None,
},
ConstValue::Slice(Scalar::Ptr(ptr), n) => match result.ty.sty {
ConstValue::Slice { data, start, end } => match result.ty.sty {
ty::Ref(_, tam, _) => match tam.sty {
ty::Str => {
let alloc = tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
let offset = ptr.offset.bytes().try_into().expect("too-large pointer offset");
let n = usize::try_from(n).unwrap();
String::from_utf8(alloc.bytes[offset..(offset + n)].to_owned())
.ok()
.map(Constant::Str)
},
ty::Str => String::from_utf8(data.bytes[start..end].to_owned())
.ok()
.map(Constant::Str),
_ => None,
},
_ => None,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/enum_clike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
promoted: None,
};
let constant = cx.tcx.const_eval(param_env.and(c_id)).ok();
if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx.tcx, &c)) {
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.sty {
if adt.is_enum() {
Expand Down