Skip to content

Commit

Permalink
Always qualify literals by type
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Feb 13, 2020
1 parent a1912f2 commit c30254e
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/librustc_mir/transform/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,32 +94,31 @@ pub trait Qualif {
}

Operand::Constant(ref constant) => {
if constant.check_static_ptr(cx.tcx).is_some() {
// `mir_const_qualif` does return the qualifs in the final value of a `static`,
// so we could use value-based qualification here, but we shouldn't do this
// without a good reason.
//
// Note: this uses `constant.literal.ty` which is a reference or pointer to the
// type of the actual `static` item.
Self::in_any_value_of_ty(cx, constant.literal.ty)
} else if let ty::ConstKind::Unevaluated(def_id, _, promoted) = constant.literal.val
{
// Check the qualifs of the value of `const` items.
if let ty::ConstKind::Unevaluated(def_id, _, promoted) = constant.literal.val {
assert!(promoted.is_none());
// Don't peek inside trait associated constants.
if cx.tcx.trait_of_item(def_id).is_some() {
Self::in_any_value_of_ty(cx, constant.literal.ty)
} else {
if cx.tcx.trait_of_item(def_id).is_none() {
let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def_id);
let qualif = Self::in_qualifs(&qualifs);
if !Self::in_qualifs(&qualifs) {
return false;
}

// Just in case the type is more specific than
// the definition, e.g., impl associated const
// with type parameters, take it into account.
qualif && Self::in_any_value_of_ty(cx, constant.literal.ty)
}
} else {
false
}
// Otherwise use the qualifs of the type.
//
// We could use value-based qualification if this is a
// pointer to a static, but we shouldn't do that without a
// good reason.
//
// Note: If this is a pointer to a static, this uses
// `constant.literal.ty` which is a reference or pointer to
// the type of the actual static item.
Self::in_any_value_of_ty(cx, constant.literal.ty)
}
}
}
Expand Down

0 comments on commit c30254e

Please sign in to comment.