Skip to content

Commit c30254e

Browse files
committed
Always qualify literals by type
1 parent a1912f2 commit c30254e

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/librustc_mir/transform/check_consts/qualifs.rs

+16-17
Original file line numberDiff line numberDiff line change
@@ -94,32 +94,31 @@ pub trait Qualif {
9494
}
9595

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

115107
// Just in case the type is more specific than
116108
// the definition, e.g., impl associated const
117109
// with type parameters, take it into account.
118-
qualif && Self::in_any_value_of_ty(cx, constant.literal.ty)
119110
}
120-
} else {
121-
false
122111
}
112+
// Otherwise use the qualifs of the type.
113+
//
114+
// We could use value-based qualification if this is a
115+
// pointer to a static, but we shouldn't do that without a
116+
// good reason.
117+
//
118+
// Note: If this is a pointer to a static, this uses
119+
// `constant.literal.ty` which is a reference or pointer to
120+
// the type of the actual static item.
121+
Self::in_any_value_of_ty(cx, constant.literal.ty)
123122
}
124123
}
125124
}

0 commit comments

Comments
 (0)