Skip to content

Commit 056edc0

Browse files
Use a bespoke type for the result of mir_const_qualif
1 parent a4ce201 commit 056edc0

File tree

6 files changed

+19
-8
lines changed

6 files changed

+19
-8
lines changed

src/librustc/mir/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -2769,6 +2769,13 @@ pub struct BorrowCheckResult<'tcx> {
27692769
pub used_mut_upvars: SmallVec<[Field; 8]>,
27702770
}
27712771

2772+
/// The result of the `mir_const_qualif` query.
2773+
#[derive(Clone, Copy, Debug, Default, RustcEncodable, RustcDecodable, HashStable)]
2774+
pub struct QualifSet {
2775+
pub has_mut_interior: bool,
2776+
pub needs_drop: bool,
2777+
}
2778+
27722779
/// After we borrow check a closure, we are left with various
27732780
/// requirements that we have inferred between the free regions that
27742781
/// appear in the closure's signature or on its field types. These

src/librustc/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ rustc_queries! {
9393
/// Maps DefId's that have an associated `mir::Body` to the result
9494
/// of the MIR qualify_consts pass. The actual meaning of
9595
/// the value isn't known except to the pass itself.
96-
query mir_const_qualif(key: DefId) -> u8 {
96+
query mir_const_qualif(key: DefId) -> mir::QualifSet {
9797
desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
9898
cache_on_disk_if { key.is_local() }
9999
}

src/librustc_metadata/rmeta/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ impl<'a, 'tcx> CrateMetadata {
952952
.decode((self, tcx))
953953
}
954954

955-
fn mir_const_qualif(&self, id: DefIndex) -> u8 {
955+
fn mir_const_qualif(&self, id: DefIndex) -> mir::QualifSet {
956956
match self.kind(id) {
957957
EntryKind::Const(qualif, _) |
958958
EntryKind::AssocConst(AssocContainer::ImplDefault, qualif, _) |

src/librustc_metadata/rmeta/encoder.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,11 @@ impl EncodeContext<'tcx> {
875875
hir::print::to_string(self.tcx.hir(), |s| s.print_trait_item(ast_item));
876876
let rendered_const = self.lazy(RenderedConst(rendered));
877877

878-
EntryKind::AssocConst(container, ConstQualif { mir: 0 }, rendered_const)
878+
EntryKind::AssocConst(
879+
container,
880+
ConstQualif { mir: Default::default() },
881+
rendered_const,
882+
)
879883
}
880884
ty::AssocKind::Method => {
881885
let fn_data = if let hir::TraitItemKind::Method(m_sig, m) = &ast_item.kind {

src/librustc_metadata/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ enum EntryKind<'tcx> {
295295
/// Additional data for EntryKind::Const and EntryKind::AssocConst
296296
#[derive(Clone, Copy, RustcEncodable, RustcDecodable)]
297297
struct ConstQualif {
298-
mir: u8,
298+
mir: mir::QualifSet,
299299
}
300300

301301
/// Contains a constant which has been rendered to a String.

src/librustc_mir/transform/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::{build, shim};
22
use rustc_index::vec::IndexVec;
33
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
4-
use rustc::mir::{Body, MirPhase, Promoted};
4+
use rustc::mir::{Body, MirPhase, Promoted, QualifSet};
55
use rustc::ty::{TyCtxt, InstanceDef, TypeFoldable};
66
use rustc::ty::query::Providers;
77
use rustc::ty::steal::Steal;
@@ -184,12 +184,12 @@ pub fn run_passes(
184184
body.phase = mir_phase;
185185
}
186186

187-
fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> u8 {
187+
fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> QualifSet {
188188
let const_kind = check_consts::ConstKind::for_item(tcx, def_id);
189189

190190
// No need to const-check a non-const `fn`.
191191
if const_kind.is_none() {
192-
return 0;
192+
return Default::default();
193193
}
194194

195195
// N.B., this `borrow()` is guaranteed to be valid (i.e., the value
@@ -200,7 +200,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> u8 {
200200

201201
if body.return_ty().references_error() {
202202
tcx.sess.delay_span_bug(body.span, "mir_const_qualif: MIR had errors");
203-
return 0;
203+
return Default::default();
204204
}
205205

206206
let item = check_consts::Item {

0 commit comments

Comments
 (0)