Skip to content

Commit

Permalink
Use a bespoke type for the result of mir_const_qualif
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Nov 15, 2019
1 parent a4ce201 commit 056edc0
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/librustc/mir/mod.rs
Expand Up @@ -2769,6 +2769,13 @@ pub struct BorrowCheckResult<'tcx> {
pub used_mut_upvars: SmallVec<[Field; 8]>,
}

/// The result of the `mir_const_qualif` query.
#[derive(Clone, Copy, Debug, Default, RustcEncodable, RustcDecodable, HashStable)]
pub struct QualifSet {
pub has_mut_interior: bool,
pub needs_drop: bool,
}

/// After we borrow check a closure, we are left with various
/// requirements that we have inferred between the free regions that
/// appear in the closure's signature or on its field types. These
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/query/mod.rs
Expand Up @@ -93,7 +93,7 @@ rustc_queries! {
/// Maps DefId's that have an associated `mir::Body` to the result
/// of the MIR qualify_consts pass. The actual meaning of
/// the value isn't known except to the pass itself.
query mir_const_qualif(key: DefId) -> u8 {
query mir_const_qualif(key: DefId) -> mir::QualifSet {
desc { |tcx| "const checking `{}`", tcx.def_path_str(key) }
cache_on_disk_if { key.is_local() }
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/rmeta/decoder.rs
Expand Up @@ -952,7 +952,7 @@ impl<'a, 'tcx> CrateMetadata {
.decode((self, tcx))
}

fn mir_const_qualif(&self, id: DefIndex) -> u8 {
fn mir_const_qualif(&self, id: DefIndex) -> mir::QualifSet {
match self.kind(id) {
EntryKind::Const(qualif, _) |
EntryKind::AssocConst(AssocContainer::ImplDefault, qualif, _) |
Expand Down
6 changes: 5 additions & 1 deletion src/librustc_metadata/rmeta/encoder.rs
Expand Up @@ -875,7 +875,11 @@ impl EncodeContext<'tcx> {
hir::print::to_string(self.tcx.hir(), |s| s.print_trait_item(ast_item));
let rendered_const = self.lazy(RenderedConst(rendered));

EntryKind::AssocConst(container, ConstQualif { mir: 0 }, rendered_const)
EntryKind::AssocConst(
container,
ConstQualif { mir: Default::default() },
rendered_const,
)
}
ty::AssocKind::Method => {
let fn_data = if let hir::TraitItemKind::Method(m_sig, m) = &ast_item.kind {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/rmeta/mod.rs
Expand Up @@ -295,7 +295,7 @@ enum EntryKind<'tcx> {
/// Additional data for EntryKind::Const and EntryKind::AssocConst
#[derive(Clone, Copy, RustcEncodable, RustcDecodable)]
struct ConstQualif {
mir: u8,
mir: mir::QualifSet,
}

/// Contains a constant which has been rendered to a String.
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_mir/transform/mod.rs
@@ -1,7 +1,7 @@
use crate::{build, shim};
use rustc_index::vec::IndexVec;
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use rustc::mir::{Body, MirPhase, Promoted};
use rustc::mir::{Body, MirPhase, Promoted, QualifSet};
use rustc::ty::{TyCtxt, InstanceDef, TypeFoldable};
use rustc::ty::query::Providers;
use rustc::ty::steal::Steal;
Expand Down Expand Up @@ -184,12 +184,12 @@ pub fn run_passes(
body.phase = mir_phase;
}

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

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

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

if body.return_ty().references_error() {
tcx.sess.delay_span_bug(body.span, "mir_const_qualif: MIR had errors");
return 0;
return Default::default();
}

let item = check_consts::Item {
Expand Down

0 comments on commit 056edc0

Please sign in to comment.