Skip to content

Commit 46e6491

Browse files
committed
Auto merge of #4145 - rust-lang:rustup, r=oli-obk
Rustup to rustc 1.36.0-nightly (2268d99 2019-05-26) changelog: none
2 parents 577ee79 + 637e656 commit 46e6491

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

clippy_lints/src/consts.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc::{bug, span_bug};
1111
use rustc_data_structures::sync::Lrc;
1212
use std::cmp::Ordering::{self, Equal};
1313
use std::cmp::PartialOrd;
14-
use std::convert::TryFrom;
1514
use std::convert::TryInto;
1615
use std::hash::{Hash, Hasher};
1716
use syntax::ast::{FloatTy, LitKind};
@@ -341,7 +340,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
341340
};
342341

343342
let result = self.lcx.tcx.const_eval(self.param_env.and(gid)).ok()?;
344-
let result = miri_to_const(self.lcx.tcx, &result);
343+
let result = miri_to_const(&result);
345344
if result.is_some() {
346345
self.needed_resolution = true;
347346
}
@@ -466,7 +465,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
466465
}
467466
}
468467

469-
pub fn miri_to_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, result: &ty::Const<'tcx>) -> Option<Constant> {
468+
pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
470469
use rustc::mir::interpret::{ConstValue, Scalar};
471470
match result.val {
472471
ConstValue::Scalar(Scalar::Bits { bits: b, .. }) => match result.ty.sty {
@@ -487,16 +486,11 @@ pub fn miri_to_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, result: &ty::Const<'
487486
// FIXME: implement other conversions.
488487
_ => None,
489488
},
490-
ConstValue::Slice(Scalar::Ptr(ptr), n) => match result.ty.sty {
489+
ConstValue::Slice { data, start, end } => match result.ty.sty {
491490
ty::Ref(_, tam, _) => match tam.sty {
492-
ty::Str => {
493-
let alloc = tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
494-
let offset = ptr.offset.bytes().try_into().expect("too-large pointer offset");
495-
let n = usize::try_from(n).unwrap();
496-
String::from_utf8(alloc.bytes[offset..(offset + n)].to_owned())
497-
.ok()
498-
.map(Constant::Str)
499-
},
491+
ty::Str => String::from_utf8(data.bytes[start..end].to_owned())
492+
.ok()
493+
.map(Constant::Str),
500494
_ => None,
501495
},
502496
_ => None,

clippy_lints/src/enum_clike.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnportableVariant {
5656
promoted: None,
5757
};
5858
let constant = cx.tcx.const_eval(param_env.and(c_id)).ok();
59-
if let Some(Constant::Int(val)) = constant.and_then(|c| miri_to_const(cx.tcx, &c)) {
59+
if let Some(Constant::Int(val)) = constant.and_then(miri_to_const) {
6060
let mut ty = cx.tcx.type_of(def_id);
6161
if let ty::Adt(adt, _) = ty.sty {
6262
if adt.is_enum() {

0 commit comments

Comments
 (0)