Simplify and fix some diagnostics around arrays

This commit is contained in:
Oliver Scherer 2018-12-12 17:19:11 +01:00
parent 88df3a2c97
commit 135132891d

View File

@ -418,20 +418,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
Some(format!("[{}]", self.tcx.type_of(def.did).to_string())),
));
let tcx = self.tcx;
if let ty::LazyConst::Evaluated(len) = len {
if let Some(len) = len.val.try_to_scalar().and_then(|scalar| {
scalar.to_usize(&tcx).ok()
}) {
flags.push((
"_Self".to_owned(),
Some(format!("[{}; {}]", self.tcx.type_of(def.did).to_string(), len)),
));
} else {
flags.push((
"_Self".to_owned(),
Some(format!("[{}; _]", self.tcx.type_of(def.did).to_string())),
));
}
if let Some(len) = len.assert_usize(tcx) {
flags.push((
"_Self".to_owned(),
Some(format!("[{}; {}]", self.tcx.type_of(def.did).to_string(), len)),
));
} else {
flags.push((
"_Self".to_owned(),
Some(format!("[{}; _]", self.tcx.type_of(def.did).to_string())),
));
}
}
}