Skip to content

Commit c67a051

Browse files
committed
Check hypothetically failing conversion
1 parent 8a41720 commit c67a051

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

clippy_lints/src/consts.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::cmp::Ordering::{self, Equal};
1212
use std::cmp::PartialOrd;
1313
use std::convert::TryInto;
1414
use std::hash::{Hash, Hasher};
15+
use std::convert::TryFrom;
1516
use syntax::ast::{FloatTy, LitKind};
1617
use syntax::ptr::P;
1718
use syntax_pos::symbol::Symbol;
@@ -446,7 +447,7 @@ pub fn miri_to_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, result: &ty::Const<'
446447
ty::Str => {
447448
let alloc = tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
448449
let offset = ptr.offset.bytes().try_into().expect("too-large pointer offset");
449-
let n = n as usize;
450+
let n = usize::try_from(n).unwrap();
450451
String::from_utf8(alloc.bytes[offset..(offset + n)].to_owned())
451452
.ok()
452453
.map(Constant::Str)

0 commit comments

Comments
 (0)