diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 555374a138c433818150ddb38683fd2b1be7c869..7c432c9c7eb242d1896048f427dbf5eb35cc9dc4 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -4,7 +4,7 @@ use crate::hir::def::{CtorKind, Namespace}; use crate::hir::def_id::DefId; -use crate::hir::{self, HirId, InlineAsm as HirInlineAsm}; +use crate::hir::{self, InlineAsm as HirInlineAsm}; use crate::mir::interpret::{ConstValue, InterpError, Scalar}; use crate::mir::visit::MirVisitable; use rustc_apfloat::ieee::{Double, Single}; @@ -138,16 +138,16 @@ pub struct Mir<'tcx> { /// If this MIR was built for a constant, this will be 0. pub arg_count: usize, - /// Names and capture modes of all the closure upvars, assuming - /// the first argument is either the closure or a reference to it. - pub upvar_decls: Vec, - /// Mark an argument local (which must be a tuple) as getting passed as /// its individual components at the LLVM level. /// /// This is used for the "rust-call" ABI. pub spread_arg: Option, + /// Names and capture modes of all the closure upvars, assuming + /// the first argument is either the closure or a reference to it. + pub upvar_decls: Vec, + /// Mark this MIR of a const context other than const functions as having converted a `&&` or /// `||` expression into `&` or `|` respectively. This is problematic because if we ever stop /// this conversion from happening and use short circuiting, we will cause the following code @@ -986,13 +986,8 @@ pub fn new_return_place(return_ty: Ty<'_>, span: Span) -> LocalDecl<'_> { pub struct UpvarDecl { pub debug_name: Name, - /// `HirId` of the captured variable - pub var_hir_id: ClearCrossCrate, - /// If true, the capture is behind a reference. pub by_ref: bool, - - pub mutability: Mutability, } /////////////////////////////////////////////////////////////////////////// diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index b9fec22da63ca380ca46fb517da99ef63276156c..c58b570d8fc9fb74710378ef83a8338836cd8245 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -556,10 +556,10 @@ fn limit_capture_mutability( ); // Not in a closure debug_assert!( - this.upvar_decls.len() > upvar_index.index(), + this.upvar_mutbls.len() > upvar_index.index(), "Unexpected capture place" ); - this.upvar_decls[upvar_index.index()].mutability + this.upvar_mutbls[upvar_index.index()] } _ => bug!("Unexpected capture place"), }; diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 7fe86d11c9ee4df56e961f8ab70ed920e36128d8..cd2fa10927f6717fcfdda36a212cda68ccaa8a65 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -376,6 +376,7 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { local_decls: IndexVec>, canonical_user_type_annotations: ty::CanonicalUserTypeAnnotations<'tcx>, upvar_decls: Vec, + upvar_mutbls: Vec, unit_temp: Option>, /// Cached block with the `RESUME` terminator; this is created @@ -625,6 +626,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>, let fn_def_id = tcx_hir.local_def_id_from_hir_id(fn_id); // Gather the upvars of a closure, if any. + let mut upvar_mutbls = vec![]; // In analyze_closure() in upvar.rs we gathered a list of upvars used by a // closure and we stored in a map called upvar_list in TypeckTables indexed // with the closure's DefId. Here, we run through that vec of UpvarIds for @@ -644,24 +646,24 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>, }; let mut decl = UpvarDecl { debug_name: keywords::Invalid.name(), - var_hir_id: ClearCrossCrate::Set(var_hir_id), by_ref, - mutability: Mutability::Not, }; + let mut mutability = Mutability::Not; if let Some(Node::Binding(pat)) = tcx_hir.find(var_node_id) { if let hir::PatKind::Binding(_, _, ident, _) = pat.node { decl.debug_name = ident.name; if let Some(&bm) = hir.tables.pat_binding_modes().get(pat.hir_id) { if bm == ty::BindByValue(hir::MutMutable) { - decl.mutability = Mutability::Mut; + mutability = Mutability::Mut; } else { - decl.mutability = Mutability::Not; + mutability = Mutability::Not; } } else { tcx.sess.delay_span_bug(pat.span, "missing binding mode"); } } } + upvar_mutbls.push(mutability); decl }) .collect(); @@ -672,7 +674,8 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>, safety, return_ty, return_ty_span, - upvar_decls); + upvar_decls, + upvar_mutbls); let call_site_scope = region::Scope { id: body.value.hir_id.local_id, @@ -734,7 +737,7 @@ fn construct_const<'a, 'gcx, 'tcx>( let ty = hir.tables().expr_ty_adjusted(ast_expr); let owner_id = tcx.hir().body_owner(body_id); let span = tcx.hir().span(owner_id); - let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, ty_span,vec![]); + let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, ty_span, vec![], vec![]); let mut block = START_BLOCK; let expr = builder.hir.mirror(ast_expr); @@ -762,7 +765,7 @@ fn construct_error<'a, 'gcx, 'tcx>(hir: Cx<'a, 'gcx, 'tcx>, let owner_id = hir.tcx().hir().body_owner(body_id); let span = hir.tcx().hir().span(owner_id); let ty = hir.tcx().types.err; - let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, span, vec![]); + let mut builder = Builder::new(hir, span, 0, Safety::Safe, ty, span, vec![], vec![]); let source_info = builder.source_info(span); builder.cfg.terminate(START_BLOCK, source_info, TerminatorKind::Unreachable); builder.finish(None) @@ -775,7 +778,8 @@ fn new(hir: Cx<'a, 'gcx, 'tcx>, safety: Safety, return_ty: Ty<'tcx>, return_span: Span, - upvar_decls: Vec) + upvar_decls: Vec, + upvar_mutbls: Vec) -> Builder<'a, 'gcx, 'tcx> { let lint_level = LintLevel::Explicit(hir.root_lint_level); let mut builder = Builder { @@ -798,6 +802,7 @@ fn new(hir: Cx<'a, 'gcx, 'tcx>, ), canonical_user_type_annotations: IndexVec::new(), upvar_decls, + upvar_mutbls, var_indices: Default::default(), unit_temp: None, cached_resume_block: None,