|
1 | 1 | //! A copy of the `Qualif` trait in `qualify_consts.rs` that is suitable for the new validator.
|
2 | 2 |
|
3 |
| -use rustc::hir::def_id::DefId; |
4 | 3 | use rustc::mir::*;
|
5 | 4 | use rustc::ty::{self, Ty};
|
6 | 5 | use syntax_pos::DUMMY_SP;
|
@@ -33,12 +32,6 @@ pub trait Qualif {
|
33 | 32 | /// of the type.
|
34 | 33 | fn in_any_value_of_ty(_cx: &ConstCx<'_, 'tcx>, _ty: Ty<'tcx>) -> bool;
|
35 | 34 |
|
36 |
| - fn in_static(cx: &ConstCx<'_, 'tcx>, def_id: DefId) -> bool { |
37 |
| - // `mir_const_qualif` does return the qualifs in the final value of a `static`, so we could |
38 |
| - // use value-based qualification here, but we shouldn't do this without a good reason. |
39 |
| - Self::in_any_value_of_ty(cx, cx.tcx.type_of(def_id)) |
40 |
| - } |
41 |
| - |
42 | 35 | fn in_projection_structurally(
|
43 | 36 | cx: &ConstCx<'_, 'tcx>,
|
44 | 37 | per_local: &impl Fn(Local) -> bool,
|
@@ -101,8 +94,14 @@ pub trait Qualif {
|
101 | 94 | }
|
102 | 95 |
|
103 | 96 | Operand::Constant(ref constant) => {
|
104 |
| - if let Some(static_) = constant.check_static_ptr(cx.tcx) { |
105 |
| - Self::in_static(cx, static_) |
| 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) |
106 | 105 | } else if let ty::ConstKind::Unevaluated(def_id, _) = constant.literal.val {
|
107 | 106 | // Don't peek inside trait associated constants.
|
108 | 107 | if cx.tcx.trait_of_item(def_id).is_some() {
|
|
0 commit comments