From 31a61ccc38201a13c2549b20772daf15ce0e0309 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 30 Dec 2020 18:48:40 +0100 Subject: [PATCH] Move rustc_mir::borrow_check to new crate rustc_borrowck. --- Cargo.lock | 29 ++++- compiler/rustc_borrowck/Cargo.toml | 30 +++++ .../src}/borrow_set.rs | 10 +- .../src}/borrowck_errors.rs | 2 +- .../src}/constraint_generation.rs | 2 +- .../src}/constraints/graph.rs | 2 +- .../src}/constraints/mod.rs | 2 +- .../src}/consumers.rs | 0 .../src/dataflow.rs} | 113 ++++++++++++++++-- .../src}/def_use.rs | 0 .../src}/diagnostics/bound_region_errors.rs | 4 +- .../src}/diagnostics/conflict_errors.rs | 28 ++--- .../src}/diagnostics/explain_borrow.rs | 16 +-- .../src}/diagnostics/find_use.rs | 2 +- .../src}/diagnostics/mod.rs | 11 +- .../src}/diagnostics/move_errors.rs | 12 +- .../src}/diagnostics/mutability_errors.rs | 6 +- .../src}/diagnostics/outlives_suggestion.rs | 8 +- .../src}/diagnostics/region_errors.rs | 10 +- .../src}/diagnostics/region_name.rs | 2 +- .../src}/diagnostics/var_name.rs | 4 +- .../src}/facts.rs | 11 +- .../src}/invalidation.rs | 8 +- .../mod.rs => rustc_borrowck/src/lib.rs} | 59 ++++++--- .../src}/location.rs | 0 .../src}/member_constraints.rs | 0 .../src}/nll.rs | 16 +-- .../src}/path_utils.rs | 10 +- .../src}/place_ext.rs | 2 +- .../src}/places_conflict.rs | 6 +- .../src}/prefixes.rs | 0 .../src}/region_infer/dump_mir.rs | 2 +- .../src}/region_infer/graphviz.rs | 2 +- .../src}/region_infer/mod.rs | 22 ++-- .../src}/region_infer/opaque_types.rs | 4 +- .../src}/region_infer/reverse_sccs.rs | 4 +- .../src}/region_infer/values.rs | 0 .../src}/renumber.rs | 0 .../src}/type_check/canonical.rs | 2 +- .../src}/type_check/constraint_conversion.rs | 2 +- .../src}/type_check/free_region_relations.rs | 4 +- .../src}/type_check/input_output.rs | 7 +- .../src}/type_check/liveness/local_use_map.rs | 4 +- .../src}/type_check/liveness/mod.rs | 8 +- .../src}/type_check/liveness/polonius.rs | 7 +- .../src}/type_check/liveness/trace.rs | 9 +- .../src}/type_check/mod.rs | 14 +-- .../src}/type_check/relate_tys.rs | 6 +- .../src}/universal_regions.rs | 2 +- .../src}/used_muts.rs | 5 +- compiler/rustc_interface/Cargo.toml | 1 + compiler/rustc_interface/src/passes.rs | 2 + compiler/rustc_mir/Cargo.toml | 14 +-- .../src/dataflow/drop_flag_effects.rs | 2 +- .../rustc_mir/src/dataflow/framework/mod.rs | 3 +- .../src/dataflow/framework/visitor.rs | 93 -------------- compiler/rustc_mir/src/dataflow/impls/mod.rs | 2 - compiler/rustc_mir/src/dataflow/mod.rs | 15 +-- .../rustc_mir/src/dataflow/move_paths/mod.rs | 14 ++- compiler/rustc_mir/src/lib.rs | 27 ++--- .../rustc_mir/src/transform/promote_consts.rs | 2 +- compiler/rustc_mir/src/util/collect_writes.rs | 2 +- compiler/rustc_mir/src/util/mod.rs | 3 +- compiler/rustc_mir/src/util/pretty.rs | 2 +- 64 files changed, 374 insertions(+), 317 deletions(-) create mode 100644 compiler/rustc_borrowck/Cargo.toml rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/borrow_set.rs (98%) rename compiler/{rustc_mir/src/util => rustc_borrowck/src}/borrowck_errors.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/constraint_generation.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/constraints/graph.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/constraints/mod.rs (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/consumers.rs (100%) rename compiler/{rustc_mir/src/dataflow/impls/borrows.rs => rustc_borrowck/src/dataflow.rs} (79%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/def_use.rs (100%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/bound_region_errors.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/conflict_errors.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/explain_borrow.rs (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/find_use.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/mod.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/move_errors.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/mutability_errors.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/outlives_suggestion.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/region_errors.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/region_name.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/diagnostics/var_name.rs (97%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/facts.rs (95%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/invalidation.rs (98%) rename compiler/{rustc_mir/src/borrow_check/mod.rs => rustc_borrowck/src/lib.rs} (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/location.rs (100%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/member_constraints.rs (100%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/nll.rs (97%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/path_utils.rs (96%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/place_ext.rs (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/places_conflict.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/prefixes.rs (100%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/region_infer/dump_mir.rs (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/region_infer/graphviz.rs (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/region_infer/mod.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/region_infer/opaque_types.rs (97%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/region_infer/reverse_sccs.rs (95%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/region_infer/values.rs (100%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/renumber.rs (100%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/canonical.rs (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/constraint_conversion.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/free_region_relations.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/input_output.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/liveness/local_use_map.rs (97%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/liveness/mod.rs (96%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/liveness/polonius.rs (96%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/liveness/trace.rs (98%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/mod.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/type_check/relate_tys.rs (96%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/universal_regions.rs (99%) rename compiler/{rustc_mir/src/borrow_check => rustc_borrowck/src}/used_muts.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 6849c40a54f..81549bd1d20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3598,6 +3598,32 @@ dependencies = [ "rustc_span", ] +[[package]] +name = "rustc_borrowck" +version = "0.0.0" +dependencies = [ + "either", + "itertools 0.9.0", + "polonius-engine", + "rustc_data_structures", + "rustc_errors", + "rustc_graphviz", + "rustc_hir", + "rustc_index", + "rustc_infer", + "rustc_lexer", + "rustc_middle", + "rustc_mir", + "rustc_serialize", + "rustc_session", + "rustc_span", + "rustc_target", + "rustc_trait_selection", + "rustc_traits", + "smallvec", + "tracing", +] + [[package]] name = "rustc_builtin_macros" version = "0.0.0" @@ -3888,6 +3914,7 @@ dependencies = [ "rustc_ast_lowering", "rustc_ast_passes", "rustc_attr", + "rustc_borrowck", "rustc_builtin_macros", "rustc_codegen_llvm", "rustc_codegen_ssa", @@ -4059,7 +4086,6 @@ dependencies = [ "rustc_hir", "rustc_index", "rustc_infer", - "rustc_lexer", "rustc_macros", "rustc_middle", "rustc_serialize", @@ -4067,7 +4093,6 @@ dependencies = [ "rustc_span", "rustc_target", "rustc_trait_selection", - "rustc_traits", "smallvec", "tracing", ] diff --git a/compiler/rustc_borrowck/Cargo.toml b/compiler/rustc_borrowck/Cargo.toml new file mode 100644 index 00000000000..e919c2cbc4f --- /dev/null +++ b/compiler/rustc_borrowck/Cargo.toml @@ -0,0 +1,30 @@ +[package] +authors = ["The Rust Project Developers"] +name = "rustc_borrowck" +version = "0.0.0" +edition = "2018" + +[lib] +doctest = false + +[dependencies] +either = "1.5.0" +itertools = "0.9" +tracing = "0.1" +polonius-engine = "0.13.0" +smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } +rustc_data_structures = { path = "../rustc_data_structures" } +rustc_errors = { path = "../rustc_errors" } +rustc_graphviz = { path = "../rustc_graphviz" } +rustc_hir = { path = "../rustc_hir" } +rustc_index = { path = "../rustc_index" } +rustc_infer = { path = "../rustc_infer" } +rustc_lexer = { path = "../rustc_lexer" } +rustc_middle = { path = "../rustc_middle" } +rustc_mir = { path = "../rustc_mir" } +rustc_serialize = { path = "../rustc_serialize" } +rustc_session = { path = "../rustc_session" } +rustc_target = { path = "../rustc_target" } +rustc_trait_selection = { path = "../rustc_trait_selection" } +rustc_traits = { path = "../rustc_traits" } +rustc_span = { path = "../rustc_span" } diff --git a/compiler/rustc_mir/src/borrow_check/borrow_set.rs b/compiler/rustc_borrowck/src/borrow_set.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/borrow_set.rs rename to compiler/rustc_borrowck/src/borrow_set.rs index 288eda32e41..eb4d815bfc3 100644 --- a/compiler/rustc_mir/src/borrow_check/borrow_set.rs +++ b/compiler/rustc_borrowck/src/borrow_set.rs @@ -1,14 +1,14 @@ -use crate::borrow_check::nll::ToRegionVid; -use crate::borrow_check::path_utils::allow_two_phase_borrow; -use crate::borrow_check::place_ext::PlaceExt; -use crate::dataflow::indexes::BorrowIndex; -use crate::dataflow::move_paths::MoveData; +use crate::nll::ToRegionVid; +use crate::path_utils::allow_two_phase_borrow; +use crate::place_ext::PlaceExt; +use crate::BorrowIndex; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_index::bit_set::BitSet; use rustc_middle::mir::traversal; use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor}; use rustc_middle::mir::{self, Body, Local, Location}; use rustc_middle::ty::{RegionVid, TyCtxt}; +use rustc_mir::dataflow::move_paths::MoveData; use std::fmt; use std::ops::Index; diff --git a/compiler/rustc_mir/src/util/borrowck_errors.rs b/compiler/rustc_borrowck/src/borrowck_errors.rs similarity index 99% rename from compiler/rustc_mir/src/util/borrowck_errors.rs rename to compiler/rustc_borrowck/src/borrowck_errors.rs index 56d8045813c..5702203d7c4 100644 --- a/compiler/rustc_mir/src/util/borrowck_errors.rs +++ b/compiler/rustc_borrowck/src/borrowck_errors.rs @@ -2,7 +2,7 @@ use rustc_errors::{struct_span_err, DiagnosticBuilder, DiagnosticId}; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::{MultiSpan, Span}; -impl<'cx, 'tcx> crate::borrow_check::MirBorrowckCtxt<'cx, 'tcx> { +impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> { crate fn cannot_move_when_borrowed(&self, span: Span, desc: &str) -> DiagnosticBuilder<'cx> { struct_span_err!(self, span, E0505, "cannot move out of {} because it is borrowed", desc,) } diff --git a/compiler/rustc_mir/src/borrow_check/constraint_generation.rs b/compiler/rustc_borrowck/src/constraint_generation.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/constraint_generation.rs rename to compiler/rustc_borrowck/src/constraint_generation.rs index c84928523d9..a40f148cdf8 100644 --- a/compiler/rustc_mir/src/borrow_check/constraint_generation.rs +++ b/compiler/rustc_borrowck/src/constraint_generation.rs @@ -9,7 +9,7 @@ use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, RegionVid, Ty}; -use crate::borrow_check::{ +use crate::{ borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, nll::ToRegionVid, places_conflict, region_infer::values::LivenessValues, }; diff --git a/compiler/rustc_mir/src/borrow_check/constraints/graph.rs b/compiler/rustc_borrowck/src/constraints/graph.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/constraints/graph.rs rename to compiler/rustc_borrowck/src/constraints/graph.rs index 9e4cfb2cc00..cb9e0234c49 100644 --- a/compiler/rustc_mir/src/borrow_check/constraints/graph.rs +++ b/compiler/rustc_borrowck/src/constraints/graph.rs @@ -4,7 +4,7 @@ use rustc_middle::mir::ConstraintCategory; use rustc_middle::ty::{RegionVid, VarianceDiagInfo}; use rustc_span::DUMMY_SP; -use crate::borrow_check::{ +use crate::{ constraints::OutlivesConstraintIndex, constraints::{OutlivesConstraint, OutlivesConstraintSet}, type_check::Locations, diff --git a/compiler/rustc_mir/src/borrow_check/constraints/mod.rs b/compiler/rustc_borrowck/src/constraints/mod.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/constraints/mod.rs rename to compiler/rustc_borrowck/src/constraints/mod.rs index b944479ca45..98378a98684 100644 --- a/compiler/rustc_mir/src/borrow_check/constraints/mod.rs +++ b/compiler/rustc_borrowck/src/constraints/mod.rs @@ -5,7 +5,7 @@ use rustc_middle::ty::{RegionVid, VarianceDiagInfo}; use std::fmt; use std::ops::Index; -use crate::borrow_check::type_check::Locations; +use crate::type_check::Locations; crate mod graph; diff --git a/compiler/rustc_mir/src/borrow_check/consumers.rs b/compiler/rustc_borrowck/src/consumers.rs similarity index 100% rename from compiler/rustc_mir/src/borrow_check/consumers.rs rename to compiler/rustc_borrowck/src/consumers.rs diff --git a/compiler/rustc_mir/src/dataflow/impls/borrows.rs b/compiler/rustc_borrowck/src/dataflow.rs similarity index 79% rename from compiler/rustc_mir/src/dataflow/impls/borrows.rs rename to compiler/rustc_borrowck/src/dataflow.rs index c92cff1433f..cb440b2cbb9 100644 --- a/compiler/rustc_mir/src/dataflow/impls/borrows.rs +++ b/compiler/rustc_borrowck/src/dataflow.rs @@ -1,18 +1,111 @@ -use rustc_middle::mir::{self, Body, Location, Place}; -use rustc_middle::ty::RegionVid; -use rustc_middle::ty::TyCtxt; - use rustc_data_structures::fx::FxHashMap; use rustc_index::bit_set::BitSet; - -use crate::borrow_check::{ - places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext, ToRegionVid, -}; -use crate::dataflow::{self, fmt::DebugWithContext, GenKill}; - +use rustc_middle::mir::{self, BasicBlock, Body, Location, Place}; +use rustc_middle::ty::RegionVid; +use rustc_middle::ty::TyCtxt; +use rustc_mir::dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces}; +use rustc_mir::dataflow::ResultsVisitable; +use rustc_mir::dataflow::{self, fmt::DebugWithContext, GenKill}; +use rustc_mir::dataflow::{Analysis, Direction, Results}; use std::fmt; use std::iter; +use crate::{ + places_conflict, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext, ToRegionVid, +}; + +/// A tuple with named fields that can hold either the results or the transient state of the +/// dataflow analyses used by the borrow checker. +#[derive(Debug)] +pub struct BorrowckAnalyses { + pub borrows: B, + pub uninits: U, + pub ever_inits: E, +} + +/// The results of the dataflow analyses used by the borrow checker. +pub type BorrowckResults<'mir, 'tcx> = BorrowckAnalyses< + Results<'tcx, Borrows<'mir, 'tcx>>, + Results<'tcx, MaybeUninitializedPlaces<'mir, 'tcx>>, + Results<'tcx, EverInitializedPlaces<'mir, 'tcx>>, +>; + +/// The transient state of the dataflow analyses used by the borrow checker. +pub type BorrowckFlowState<'mir, 'tcx> = + as ResultsVisitable<'tcx>>::FlowState; + +macro_rules! impl_visitable { + ( $( + $T:ident { $( $field:ident : $A:ident ),* $(,)? } + )* ) => { $( + impl<'tcx, $($A),*, D: Direction> ResultsVisitable<'tcx> for $T<$( Results<'tcx, $A> ),*> + where + $( $A: Analysis<'tcx, Direction = D>, )* + { + type Direction = D; + type FlowState = $T<$( $A::Domain ),*>; + + fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState { + $T { + $( $field: self.$field.analysis.bottom_value(body) ),* + } + } + + fn reset_to_block_entry( + &self, + state: &mut Self::FlowState, + block: BasicBlock, + ) { + $( state.$field.clone_from(&self.$field.entry_set_for_block(block)); )* + } + + fn reconstruct_before_statement_effect( + &self, + state: &mut Self::FlowState, + stmt: &mir::Statement<'tcx>, + loc: Location, + ) { + $( self.$field.analysis + .apply_before_statement_effect(&mut state.$field, stmt, loc); )* + } + + fn reconstruct_statement_effect( + &self, + state: &mut Self::FlowState, + stmt: &mir::Statement<'tcx>, + loc: Location, + ) { + $( self.$field.analysis + .apply_statement_effect(&mut state.$field, stmt, loc); )* + } + + fn reconstruct_before_terminator_effect( + &self, + state: &mut Self::FlowState, + term: &mir::Terminator<'tcx>, + loc: Location, + ) { + $( self.$field.analysis + .apply_before_terminator_effect(&mut state.$field, term, loc); )* + } + + fn reconstruct_terminator_effect( + &self, + state: &mut Self::FlowState, + term: &mir::Terminator<'tcx>, + loc: Location, + ) { + $( self.$field.analysis + .apply_terminator_effect(&mut state.$field, term, loc); )* + } + } + )* } +} + +impl_visitable! { + BorrowckAnalyses { borrows: B, uninits: U, ever_inits: E } +} + rustc_index::newtype_index! { pub struct BorrowIndex { DEBUG_FORMAT = "bw{}" diff --git a/compiler/rustc_mir/src/borrow_check/def_use.rs b/compiler/rustc_borrowck/src/def_use.rs similarity index 100% rename from compiler/rustc_mir/src/borrow_check/def_use.rs rename to compiler/rustc_borrowck/src/def_use.rs diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs rename to compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs index ac30093ba82..76e779bfec6 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs @@ -14,8 +14,8 @@ use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_ use std::fmt; use std::rc::Rc; -use crate::borrow_check::region_infer::values::RegionElement; -use crate::borrow_check::MirBorrowckCtxt; +use crate::region_infer::values::RegionElement; +use crate::MirBorrowckCtxt; #[derive(Clone)] crate struct UniverseInfo<'tcx>(UniverseInfoInner<'tcx>); diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs rename to compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 6561fe37c1c..8f6181f410d 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -15,11 +15,11 @@ use rustc_span::symbol::sym; use rustc_span::{BytePos, MultiSpan, Span, DUMMY_SP}; use rustc_trait_selection::infer::InferCtxtExt; -use crate::dataflow::drop_flag_effects; -use crate::dataflow::indexes::{MoveOutIndex, MovePathIndex}; -use crate::util::borrowck_errors; +use crate::borrowck_errors; +use rustc_mir::dataflow::drop_flag_effects; +use rustc_mir::dataflow::move_paths::{MoveOutIndex, MovePathIndex}; -use crate::borrow_check::{ +use crate::{ borrow_set::BorrowData, diagnostics::Instance, prefixes::IsPrefixOf, InitializationRequiringAction, MirBorrowckCtxt, PrefixSet, WriteKind, }; @@ -49,7 +49,7 @@ enum StorageDeadOrDrop<'tcx> { } impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { - pub(in crate::borrow_check) fn report_use_of_moved_or_uninitialized( + pub(crate) fn report_use_of_moved_or_uninitialized( &mut self, location: Location, desired_action: InitializationRequiringAction, @@ -441,7 +441,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } } - pub(in crate::borrow_check) fn report_move_out_while_borrowed( + pub(crate) fn report_move_out_while_borrowed( &mut self, location: Location, (place, span): (Place<'tcx>, Span), @@ -489,7 +489,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { err.buffer(&mut self.errors_buffer); } - pub(in crate::borrow_check) fn report_use_while_mutably_borrowed( + pub(crate) fn report_use_while_mutably_borrowed( &mut self, location: Location, (place, _span): (Place<'tcx>, Span), @@ -535,7 +535,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { err } - pub(in crate::borrow_check) fn report_conflicting_borrow( + pub(crate) fn report_conflicting_borrow( &mut self, location: Location, (place, span): (Place<'tcx>, Span), @@ -798,7 +798,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// cannot borrow `a.u` (via `a.u.z.c`) as immutable because it is also borrowed as /// mutable (via `a.u.s.b`) [E0502] /// ``` - pub(in crate::borrow_check) fn describe_place_for_conflicting_borrow( + pub(crate) fn describe_place_for_conflicting_borrow( &self, first_borrowed_place: Place<'tcx>, second_borrowed_place: Place<'tcx>, @@ -875,7 +875,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// short a lifetime. (But sometimes it is more useful to report /// it as a more direct conflict between the execution of a /// `Drop::drop` with an aliasing borrow.) - pub(in crate::borrow_check) fn report_borrowed_value_does_not_live_long_enough( + pub(crate) fn report_borrowed_value_does_not_live_long_enough( &mut self, location: Location, borrow: &BorrowData<'tcx>, @@ -1634,7 +1634,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { (result, reinits_reachable) } - pub(in crate::borrow_check) fn report_illegal_mutation_of_borrowed( + pub(crate) fn report_illegal_mutation_of_borrowed( &mut self, location: Location, (place, span): (Place<'tcx>, Span), @@ -1695,7 +1695,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { Some((method_did, method_substs)), ) = ( &self.body[loan.reserve_location.block].terminator, - crate::util::find_self_call( + rustc_mir::util::find_self_call( tcx, self.body, loan.assigned_place.local, @@ -1726,7 +1726,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// assigned; `err_place` is a place providing a reason why /// `place` is not mutable (e.g., the non-`mut` local `x` in an /// assignment to `x.f`). - pub(in crate::borrow_check) fn report_illegal_reassignment( + pub(crate) fn report_illegal_reassignment( &mut self, _location: Location, (place, span): (Place<'tcx>, Span), @@ -2226,7 +2226,7 @@ enum AnnotatedBorrowFnSignature<'tcx> { impl<'tcx> AnnotatedBorrowFnSignature<'tcx> { /// Annotate the provided diagnostic with information about borrow from the fn signature that /// helps explain. - pub(in crate::borrow_check) fn emit( + pub(crate) fn emit( &self, cx: &mut MirBorrowckCtxt<'_, 'tcx>, diag: &mut DiagnosticBuilder<'_>, diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rs rename to compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index f40a2db330a..2d12a682e7a 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -15,8 +15,8 @@ use rustc_middle::ty::{self, RegionVid, TyCtxt}; use rustc_span::symbol::Symbol; use rustc_span::Span; -use crate::borrow_check::region_infer::BlameConstraint; -use crate::borrow_check::{ +use crate::region_infer::BlameConstraint; +use crate::{ borrow_set::BorrowData, nll::ConstraintDescription, region_infer::Cause, MirBorrowckCtxt, WriteKind, }; @@ -24,7 +24,7 @@ use crate::borrow_check::{ use super::{find_use, RegionName, UseSpans}; #[derive(Debug)] -pub(in crate::borrow_check) enum BorrowExplanation { +pub(crate) enum BorrowExplanation { UsedLater(LaterUseKind, Span, Option), UsedLaterInLoop(LaterUseKind, Span, Option), UsedLaterWhenDropped { @@ -43,7 +43,7 @@ pub(in crate::borrow_check) enum BorrowExplanation { } #[derive(Clone, Copy, Debug)] -pub(in crate::borrow_check) enum LaterUseKind { +pub(crate) enum LaterUseKind { TraitCapture, ClosureCapture, Call, @@ -52,13 +52,13 @@ pub(in crate::borrow_check) enum LaterUseKind { } impl BorrowExplanation { - pub(in crate::borrow_check) fn is_explained(&self) -> bool { + pub(crate) fn is_explained(&self) -> bool { match self { BorrowExplanation::Unexplained => false, _ => true, } } - pub(in crate::borrow_check) fn add_explanation_to_diagnostic<'tcx>( + pub(crate) fn add_explanation_to_diagnostic<'tcx>( &self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>, @@ -267,7 +267,7 @@ impl BorrowExplanation { _ => {} } } - pub(in crate::borrow_check) fn add_lifetime_bound_suggestion_to_diagnostic( + pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic( &self, err: &mut DiagnosticBuilder<'_>, category: &ConstraintCategory, @@ -326,7 +326,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// - second half is the place being accessed /// /// [d]: https://rust-lang.github.io/rfcs/2094-nll.html#leveraging-intuition-framing-errors-in-terms-of-points - pub(in crate::borrow_check) fn explain_why_borrow_contains_point( + pub(crate) fn explain_why_borrow_contains_point( &self, location: Location, borrow: &BorrowData<'tcx>, diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/find_use.rs b/compiler/rustc_borrowck/src/diagnostics/find_use.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/find_use.rs rename to compiler/rustc_borrowck/src/diagnostics/find_use.rs index 8d8cdfb5293..ab4536f00fc 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/find_use.rs +++ b/compiler/rustc_borrowck/src/diagnostics/find_use.rs @@ -1,7 +1,7 @@ use std::collections::VecDeque; use std::rc::Rc; -use crate::borrow_check::{ +use crate::{ def_use::{self, DefUse}, nll::ToRegionVid, region_infer::{Cause, RegionInferenceContext}, diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs rename to compiler/rustc_borrowck/src/diagnostics/mod.rs index 55c6410ed32..980894d6b4d 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -12,6 +12,7 @@ use rustc_middle::mir::{ }; use rustc_middle::ty::print::Print; use rustc_middle::ty::{self, DefIdTree, Instance, Ty, TyCtxt}; +use rustc_mir::dataflow::move_paths::{InitLocation, LookupResult}; use rustc_span::{ hygiene::{DesugaringKind, ForLoopLoc}, symbol::sym, @@ -21,7 +22,6 @@ use rustc_target::abi::VariantIdx; use super::borrow_set::BorrowData; use super::MirBorrowckCtxt; -use crate::dataflow::move_paths::{InitLocation, LookupResult}; mod find_use; mod outlives_suggestion; @@ -899,9 +899,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { kind: TerminatorKind::Call { fn_span, from_hir_call, .. }, .. }) = &self.body[location.block].terminator { - let (method_did, method_substs) = if let Some(info) = - crate::util::find_self_call(self.infcx.tcx, &self.body, target_temp, location.block) - { + let (method_did, method_substs) = if let Some(info) = rustc_mir::util::find_self_call( + self.infcx.tcx, + &self.body, + target_temp, + location.block, + ) { info } else { return normal_ret; diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs rename to compiler/rustc_borrowck/src/diagnostics/move_errors.rs index 66e06325fa9..dd4886312da 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -2,16 +2,16 @@ use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::mir::*; use rustc_middle::ty; +use rustc_mir::dataflow::move_paths::{ + IllegalMoveOrigin, IllegalMoveOriginKind, LookupResult, MoveError, MovePathIndex, +}; use rustc_span::source_map::DesugaringKind; use rustc_span::{sym, Span, DUMMY_SP}; use rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions; -use crate::borrow_check::diagnostics::UseSpans; -use crate::borrow_check::prefixes::PrefixSet; -use crate::borrow_check::MirBorrowckCtxt; -use crate::dataflow::move_paths::{ - IllegalMoveOrigin, IllegalMoveOriginKind, LookupResult, MoveError, MovePathIndex, -}; +use crate::diagnostics::UseSpans; +use crate::prefixes::PrefixSet; +use crate::MirBorrowckCtxt; // Often when desugaring a pattern match we may have many individual moves in // MIR that are all part of one operation from the user's point-of-view. For diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs rename to compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 4e079ed865a..b3578afbbb6 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -14,10 +14,10 @@ use rustc_span::source_map::DesugaringKind; use rustc_span::symbol::{kw, Symbol}; use rustc_span::{BytePos, Span}; -use crate::borrow_check::diagnostics::BorrowedContentSource; -use crate::borrow_check::MirBorrowckCtxt; -use crate::util::collect_writes::FindAssignments; +use crate::diagnostics::BorrowedContentSource; +use crate::MirBorrowckCtxt; use rustc_errors::{Applicability, DiagnosticBuilder}; +use rustc_mir::util::collect_writes::FindAssignments; #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub(crate) enum AccessKind { diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/outlives_suggestion.rs b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/outlives_suggestion.rs rename to compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs index 7dc3434bf33..9de0c62f186 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/outlives_suggestion.rs +++ b/compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs @@ -1,16 +1,14 @@ //! Contains utilities for generating suggestions for borrowck errors related to unsatisfied //! outlives constraints. -use std::collections::BTreeMap; - use rustc_data_structures::fx::FxHashSet; use rustc_errors::DiagnosticBuilder; use rustc_middle::ty::RegionVid; +use smallvec::SmallVec; +use std::collections::BTreeMap; use tracing::debug; -use smallvec::SmallVec; - -use crate::borrow_check::MirBorrowckCtxt; +use crate::MirBorrowckCtxt; use super::{ErrorConstraintInfo, RegionName, RegionNameSource}; diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs rename to compiler/rustc_borrowck/src/diagnostics/region_errors.rs index cbb8f064bb8..57d2a3c5ce9 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -11,10 +11,10 @@ use rustc_middle::ty::{self, RegionVid, Ty}; use rustc_span::symbol::{kw, sym}; use rustc_span::{BytePos, Span}; -use crate::util::borrowck_errors; +use crate::borrowck_errors; -use crate::borrow_check::region_infer::BlameConstraint; -use crate::borrow_check::{ +use crate::region_infer::BlameConstraint; +use crate::{ nll::ConstraintDescription, region_infer::{values::RegionElement, TypeTest}, universal_regions::DefiningTy, @@ -152,7 +152,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } /// Produces nice borrowck error diagnostics for all the errors collected in `nll_errors`. - pub(in crate::borrow_check) fn report_region_errors(&mut self, nll_errors: RegionErrors<'tcx>) { + pub(crate) fn report_region_errors(&mut self, nll_errors: RegionErrors<'tcx>) { // Iterate through all the errors, producing a diagnostic for each one. The diagnostics are // buffered in the `MirBorrowckCtxt`. @@ -265,7 +265,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { /// ``` /// /// Here we would be invoked with `fr = 'a` and `outlived_fr = `'b`. - pub(in crate::borrow_check) fn report_region_error( + pub(crate) fn report_region_error( &mut self, fr: RegionVid, fr_origin: NllRegionVariableOrigin, diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs rename to compiler/rustc_borrowck/src/diagnostics/region_name.rs index 1f168c612f1..5edb52b0b65 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -10,7 +10,7 @@ use rustc_middle::ty::{self, RegionVid, Ty}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; -use crate::borrow_check::{nll::ToRegionVid, universal_regions::DefiningTy, MirBorrowckCtxt}; +use crate::{nll::ToRegionVid, universal_regions::DefiningTy, MirBorrowckCtxt}; /// A name for a particular region used in emitting diagnostics. This name could be a generated /// name like `'1`, a name used by the user like `'a`, or a name like `'static`. diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/var_name.rs b/compiler/rustc_borrowck/src/diagnostics/var_name.rs similarity index 97% rename from compiler/rustc_mir/src/borrow_check/diagnostics/var_name.rs rename to compiler/rustc_borrowck/src/diagnostics/var_name.rs index 4abc623fc5f..00f62806753 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/var_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/var_name.rs @@ -1,5 +1,5 @@ -use crate::borrow_check::Upvar; -use crate::borrow_check::{nll::ToRegionVid, region_infer::RegionInferenceContext}; +use crate::Upvar; +use crate::{nll::ToRegionVid, region_infer::RegionInferenceContext}; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::mir::{Body, Local}; use rustc_middle::ty::{RegionVid, TyCtxt}; diff --git a/compiler/rustc_mir/src/borrow_check/facts.rs b/compiler/rustc_borrowck/src/facts.rs similarity index 95% rename from compiler/rustc_mir/src/borrow_check/facts.rs rename to compiler/rustc_borrowck/src/facts.rs index 215dead5bd1..ed3f846e4ad 100644 --- a/compiler/rustc_mir/src/borrow_check/facts.rs +++ b/compiler/rustc_borrowck/src/facts.rs @@ -1,10 +1,11 @@ -use crate::borrow_check::location::{LocationIndex, LocationTable}; -use crate::dataflow::indexes::{BorrowIndex, MovePathIndex}; +use crate::location::{LocationIndex, LocationTable}; +use crate::BorrowIndex; use polonius_engine::AllFacts as PoloniusFacts; use polonius_engine::Atom; use rustc_index::vec::Idx; use rustc_middle::mir::Local; use rustc_middle::ty::{RegionVid, TyCtxt}; +use rustc_mir::dataflow::move_paths::MovePathIndex; use std::error::Error; use std::fmt::Debug; use std::fs::{self, File}; @@ -100,12 +101,6 @@ impl Atom for LocationIndex { } } -impl Atom for MovePathIndex { - fn index(self) -> usize { - Idx::index(self) - } -} - struct FactWriter<'w> { location_table: &'w LocationTable, dir: &'w Path, diff --git a/compiler/rustc_mir/src/borrow_check/invalidation.rs b/compiler/rustc_borrowck/src/invalidation.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/invalidation.rs rename to compiler/rustc_borrowck/src/invalidation.rs index b83a427f475..016fe0bb6de 100644 --- a/compiler/rustc_mir/src/borrow_check/invalidation.rs +++ b/compiler/rustc_borrowck/src/invalidation.rs @@ -7,12 +7,10 @@ use rustc_middle::mir::{Statement, StatementKind}; use rustc_middle::ty::TyCtxt; use std::iter; -use crate::dataflow::indexes::BorrowIndex; - -use crate::borrow_check::{ +use crate::{ borrow_set::BorrowSet, facts::AllFacts, location::LocationTable, path_utils::*, AccessDepth, - Activation, ArtificialField, Deep, JustWrite, LocalMutationIsAllowed, MutateMode, Read, - ReadKind, ReadOrWrite, Reservation, Shallow, Write, WriteAndRead, WriteKind, + Activation, ArtificialField, BorrowIndex, Deep, JustWrite, LocalMutationIsAllowed, MutateMode, + Read, ReadKind, ReadOrWrite, Reservation, Shallow, Write, WriteAndRead, WriteKind, }; pub(super) fn generate_invalidates<'tcx>( diff --git a/compiler/rustc_mir/src/borrow_check/mod.rs b/compiler/rustc_borrowck/src/lib.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/mod.rs rename to compiler/rustc_borrowck/src/lib.rs index 1dcb0676562..9fe3d79e4ed 100644 --- a/compiler/rustc_mir/src/borrow_check/mod.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -1,5 +1,22 @@ //! This query borrow-checks the MIR to (further) ensure it is not broken. +#![feature(bool_to_option)] +#![feature(box_patterns)] +#![feature(const_panic)] +#![feature(crate_visibility_modifier)] +#![feature(format_args_capture)] +#![feature(in_band_lifetimes)] +#![feature(iter_zip)] +#![feature(min_specialization)] +#![feature(stmt_expr_attributes)] +#![feature(trusted_step)] +#![feature(try_blocks)] + +#[macro_use] +extern crate rustc_middle; +#[macro_use] +extern crate tracing; + use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::graph::dominators::Dominators; use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorReported}; @@ -29,14 +46,13 @@ use std::iter; use std::mem; use std::rc::Rc; -use crate::dataflow; -use crate::dataflow::impls::{ - Borrows, EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces, +use rustc_mir::dataflow::impls::{ + EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces, }; -use crate::dataflow::indexes::{BorrowIndex, InitIndex, MoveOutIndex, MovePathIndex}; -use crate::dataflow::move_paths::{InitLocation, LookupResult, MoveData, MoveError}; -use crate::dataflow::MoveDataParamEnv; -use crate::dataflow::{Analysis, BorrowckFlowState as Flows, BorrowckResults}; +use rustc_mir::dataflow::move_paths::{InitIndex, MoveOutIndex, MovePathIndex}; +use rustc_mir::dataflow::move_paths::{InitLocation, LookupResult, MoveData, MoveError}; +use rustc_mir::dataflow::Analysis; +use rustc_mir::dataflow::MoveDataParamEnv; use self::diagnostics::{AccessKind, RegionName}; use self::location::LocationTable; @@ -47,9 +63,10 @@ use facts::AllFacts; use self::path_utils::*; mod borrow_set; +mod borrowck_errors; mod constraint_generation; mod constraints; -pub mod consumers; +mod dataflow; mod def_use; mod diagnostics; mod facts; @@ -67,15 +84,19 @@ mod type_check; mod universal_regions; mod used_muts; -crate use borrow_set::{BorrowData, BorrowSet}; -crate use nll::{PoloniusOutput, ToRegionVid}; -crate use place_ext::PlaceExt; -crate use places_conflict::{places_conflict, PlaceConflictBias}; -crate use region_infer::RegionInferenceContext; +// A public API provided for the Rust compiler consumers. +pub mod consumers; + +use borrow_set::{BorrowData, BorrowSet}; +use dataflow::{BorrowIndex, BorrowckFlowState as Flows, BorrowckResults, Borrows}; +use nll::{PoloniusOutput, ToRegionVid}; +use place_ext::PlaceExt; +use places_conflict::{places_conflict, PlaceConflictBias}; +use region_infer::RegionInferenceContext; // FIXME(eddyb) perhaps move this somewhere more centrally. #[derive(Debug)] -crate struct Upvar<'tcx> { +struct Upvar<'tcx> { place: CapturedPlace<'tcx>, /// If true, the capture is behind a reference. @@ -352,7 +373,7 @@ fn do_mir_borrowck<'a, 'tcx>( mbcx.report_move_errors(move_errors); - dataflow::visit_results( + rustc_mir::dataflow::visit_results( &body, traversal::reverse_postorder(&body).map(|(bb, _)| bb), &results, @@ -495,8 +516,8 @@ pub struct BodyWithBorrowckFacts<'tcx> { pub location_table: LocationTable, } -crate struct MirBorrowckCtxt<'cx, 'tcx> { - crate infcx: &'cx InferCtxt<'cx, 'tcx>, +struct MirBorrowckCtxt<'cx, 'tcx> { + infcx: &'cx InferCtxt<'cx, 'tcx>, param_env: ParamEnv<'tcx>, body: &'cx Body<'tcx>, move_data: &'cx MoveData<'tcx>, @@ -594,7 +615,7 @@ crate struct MirBorrowckCtxt<'cx, 'tcx> { // 2. loans made in overlapping scopes do not conflict // 3. assignments do not affect things loaned out as immutable // 4. moves do not affect things loaned out in any way -impl<'cx, 'tcx> dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx> { +impl<'cx, 'tcx> rustc_mir::dataflow::ResultsVisitor<'cx, 'tcx> for MirBorrowckCtxt<'cx, 'tcx> { type FlowState = Flows<'cx, 'tcx>; fn visit_statement_before_primary_effect( @@ -2344,7 +2365,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// then returns the index of the field being projected. Note that this closure will always /// be `self` in the current MIR, because that is the only time we directly access the fields /// of a closure type. - pub fn is_upvar_field_projection(&self, place_ref: PlaceRef<'tcx>) -> Option { + fn is_upvar_field_projection(&self, place_ref: PlaceRef<'tcx>) -> Option { path_utils::is_upvar_field_projection(self.infcx.tcx, &self.upvars, place_ref, self.body()) } } diff --git a/compiler/rustc_mir/src/borrow_check/location.rs b/compiler/rustc_borrowck/src/location.rs similarity index 100% rename from compiler/rustc_mir/src/borrow_check/location.rs rename to compiler/rustc_borrowck/src/location.rs diff --git a/compiler/rustc_mir/src/borrow_check/member_constraints.rs b/compiler/rustc_borrowck/src/member_constraints.rs similarity index 100% rename from compiler/rustc_mir/src/borrow_check/member_constraints.rs rename to compiler/rustc_borrowck/src/member_constraints.rs diff --git a/compiler/rustc_mir/src/borrow_check/nll.rs b/compiler/rustc_borrowck/src/nll.rs similarity index 97% rename from compiler/rustc_mir/src/borrow_check/nll.rs rename to compiler/rustc_borrowck/src/nll.rs index 66ca94d3b41..d40990d4676 100644 --- a/compiler/rustc_mir/src/borrow_check/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -20,13 +20,13 @@ use std::str::FromStr; use self::mir_util::PassWhere; use polonius_engine::{Algorithm, Output}; -use crate::dataflow::impls::MaybeInitializedPlaces; -use crate::dataflow::move_paths::{InitKind, InitLocation, MoveData}; -use crate::dataflow::ResultsCursor; -use crate::util as mir_util; -use crate::util::pretty; +use rustc_mir::dataflow::impls::MaybeInitializedPlaces; +use rustc_mir::dataflow::move_paths::{InitKind, InitLocation, MoveData}; +use rustc_mir::dataflow::ResultsCursor; +use rustc_mir::util as mir_util; +use rustc_mir::util::pretty; -use crate::borrow_check::{ +use crate::{ borrow_set::BorrowSet, constraint_generation, diagnostics::RegionErrors, @@ -56,7 +56,7 @@ crate struct NllOutput<'tcx> { /// Rewrites the regions in the MIR to use NLL variables, also scraping out the set of universal /// regions (e.g., region parameters) declared on the function. That set will need to be given to /// `compute_regions`. -pub(in crate::borrow_check) fn replace_regions_in_mir<'cx, 'tcx>( +pub(crate) fn replace_regions_in_mir<'cx, 'tcx>( infcx: &InferCtxt<'cx, 'tcx>, param_env: ty::ParamEnv<'tcx>, body: &mut Body<'tcx>, @@ -155,7 +155,7 @@ fn populate_polonius_move_facts( /// Computes the (non-lexical) regions from the input MIR. /// /// This may result in errors being reported. -pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>( +pub(crate) fn compute_regions<'cx, 'tcx>( infcx: &InferCtxt<'cx, 'tcx>, universal_regions: UniversalRegions<'tcx>, body: &Body<'tcx>, diff --git a/compiler/rustc_mir/src/borrow_check/path_utils.rs b/compiler/rustc_borrowck/src/path_utils.rs similarity index 96% rename from compiler/rustc_mir/src/borrow_check/path_utils.rs rename to compiler/rustc_borrowck/src/path_utils.rs index 80de3b4e363..d5d00b467ee 100644 --- a/compiler/rustc_mir/src/borrow_check/path_utils.rs +++ b/compiler/rustc_borrowck/src/path_utils.rs @@ -1,8 +1,8 @@ -use crate::borrow_check::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation}; -use crate::borrow_check::places_conflict; -use crate::borrow_check::AccessDepth; -use crate::borrow_check::Upvar; -use crate::dataflow::indexes::BorrowIndex; +use crate::borrow_set::{BorrowData, BorrowSet, TwoPhaseActivation}; +use crate::places_conflict; +use crate::AccessDepth; +use crate::BorrowIndex; +use crate::Upvar; use rustc_data_structures::graph::dominators::Dominators; use rustc_middle::mir::BorrowKind; use rustc_middle::mir::{BasicBlock, Body, Field, Location, Place, PlaceRef, ProjectionElem}; diff --git a/compiler/rustc_mir/src/borrow_check/place_ext.rs b/compiler/rustc_borrowck/src/place_ext.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/place_ext.rs rename to compiler/rustc_borrowck/src/place_ext.rs index 52fac3e53ee..83ff1595b0b 100644 --- a/compiler/rustc_mir/src/borrow_check/place_ext.rs +++ b/compiler/rustc_borrowck/src/place_ext.rs @@ -1,4 +1,4 @@ -use crate::borrow_check::borrow_set::LocalsStateAtExit; +use crate::borrow_set::LocalsStateAtExit; use rustc_hir as hir; use rustc_middle::mir::ProjectionElem; use rustc_middle::mir::{Body, Mutability, Place}; diff --git a/compiler/rustc_mir/src/borrow_check/places_conflict.rs b/compiler/rustc_borrowck/src/places_conflict.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/places_conflict.rs rename to compiler/rustc_borrowck/src/places_conflict.rs index d21550a8e1a..773e9e90b0c 100644 --- a/compiler/rustc_mir/src/borrow_check/places_conflict.rs +++ b/compiler/rustc_borrowck/src/places_conflict.rs @@ -1,6 +1,6 @@ -use crate::borrow_check::ArtificialField; -use crate::borrow_check::Overlap; -use crate::borrow_check::{AccessDepth, Deep, Shallow}; +use crate::ArtificialField; +use crate::Overlap; +use crate::{AccessDepth, Deep, Shallow}; use rustc_hir as hir; use rustc_middle::mir::{Body, BorrowKind, Local, Place, PlaceElem, PlaceRef, ProjectionElem}; use rustc_middle::ty::{self, TyCtxt}; diff --git a/compiler/rustc_mir/src/borrow_check/prefixes.rs b/compiler/rustc_borrowck/src/prefixes.rs similarity index 100% rename from compiler/rustc_mir/src/borrow_check/prefixes.rs rename to compiler/rustc_borrowck/src/prefixes.rs diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/dump_mir.rs b/compiler/rustc_borrowck/src/region_infer/dump_mir.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/region_infer/dump_mir.rs rename to compiler/rustc_borrowck/src/region_infer/dump_mir.rs index 213ebff12ab..cfd3acb6bde 100644 --- a/compiler/rustc_mir/src/borrow_check/region_infer/dump_mir.rs +++ b/compiler/rustc_borrowck/src/region_infer/dump_mir.rs @@ -4,7 +4,7 @@ //! context internal state. use super::{OutlivesConstraint, RegionInferenceContext}; -use crate::borrow_check::type_check::Locations; +use crate::type_check::Locations; use rustc_infer::infer::NllRegionVariableOrigin; use rustc_middle::ty::TyCtxt; use std::io::{self, Write}; diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/graphviz.rs b/compiler/rustc_borrowck/src/region_infer/graphviz.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/region_infer/graphviz.rs rename to compiler/rustc_borrowck/src/region_infer/graphviz.rs index b944d74e6f2..95048d50f11 100644 --- a/compiler/rustc_mir/src/borrow_check/region_infer/graphviz.rs +++ b/compiler/rustc_borrowck/src/region_infer/graphviz.rs @@ -6,7 +6,7 @@ use std::borrow::Cow; use std::io::{self, Write}; use super::*; -use crate::borrow_check::constraints::OutlivesConstraint; +use crate::constraints::OutlivesConstraint; use rustc_graphviz as dot; impl<'tcx> RegionInferenceContext<'tcx> { diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/region_infer/mod.rs rename to compiler/rustc_borrowck/src/region_infer/mod.rs index a96cdbc13f3..48e45a9b1ce 100644 --- a/compiler/rustc_mir/src/borrow_check/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -17,7 +17,7 @@ use rustc_middle::mir::{ use rustc_middle::ty::{self, subst::SubstsRef, RegionVid, Ty, TyCtxt, TypeFoldable}; use rustc_span::Span; -use crate::borrow_check::{ +use crate::{ constraints::{ graph::NormalConstraintGraph, ConstraintSccIndex, OutlivesConstraint, OutlivesConstraintSet, }, @@ -132,33 +132,33 @@ pub(crate) struct AppliedMemberConstraint { /// /// The vector if `AppliedMemberConstraint` elements is kept sorted /// by this field. - pub(in crate::borrow_check) member_region_scc: ConstraintSccIndex, + pub(crate) member_region_scc: ConstraintSccIndex, /// The "best option" that `apply_member_constraint` found -- this was /// added as an "ad-hoc" lower-bound to `member_region_scc`. - pub(in crate::borrow_check) min_choice: ty::RegionVid, + pub(crate) min_choice: ty::RegionVid, /// The "member constraint index" -- we can find out details about /// the constraint from /// `set.member_constraints[member_constraint_index]`. - pub(in crate::borrow_check) member_constraint_index: NllMemberConstraintIndex, + pub(crate) member_constraint_index: NllMemberConstraintIndex, } pub(crate) struct RegionDefinition<'tcx> { /// What kind of variable is this -- a free region? existential /// variable? etc. (See the `NllRegionVariableOrigin` for more /// info.) - pub(in crate::borrow_check) origin: NllRegionVariableOrigin, + pub(crate) origin: NllRegionVariableOrigin, /// Which universe is this region variable defined in? This is /// most often `ty::UniverseIndex::ROOT`, but when we encounter /// forall-quantifiers like `for<'a> { 'a = 'b }`, we would create /// the variable for `'a` in a fresh universe that extends ROOT. - pub(in crate::borrow_check) universe: ty::UniverseIndex, + pub(crate) universe: ty::UniverseIndex, /// If this is 'static or an early-bound region, then this is /// `Some(X)` where `X` is the name of the region. - pub(in crate::borrow_check) external_name: Option>, + pub(crate) external_name: Option>, } /// N.B., the variants in `Cause` are intentionally ordered. Lower @@ -245,7 +245,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// /// The `outlives_constraints` and `type_tests` are an initial set /// of constraints produced by the MIR type check. - pub(in crate::borrow_check) fn new( + pub(crate) fn new( var_infos: VarInfos, universal_regions: Rc>, placeholder_indices: Rc, @@ -534,7 +534,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// Once region solving has completed, this function will return /// the member constraints that were applied to the value of a given /// region `r`. See `AppliedMemberConstraint`. - pub(in crate::borrow_check) fn applied_member_constraints( + pub(crate) fn applied_member_constraints( &self, r: impl ToRegionVid, ) -> &[AppliedMemberConstraint] { @@ -1088,7 +1088,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// include the CFG anyhow. /// - For each `end('x)` element in `'r`, compute the mutual LUB, yielding /// a result `'y`. - pub(in crate::borrow_check) fn universal_upper_bound(&self, r: RegionVid) -> RegionVid { + pub(crate) fn universal_upper_bound(&self, r: RegionVid) -> RegionVid { debug!("universal_upper_bound(r={:?}={})", r, self.region_value_str(r)); // Find the smallest universal region that contains all other @@ -1115,7 +1115,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// Therefore, this method should only be used in diagnostic code, /// where displaying *some* named universal region is better than /// falling back to 'static. - pub(in crate::borrow_check) fn approx_universal_upper_bound(&self, r: RegionVid) -> RegionVid { + pub(crate) fn approx_universal_upper_bound(&self, r: RegionVid) -> RegionVid { debug!("approx_universal_upper_bound(r={:?}={})", r, self.region_value_str(r)); // Find the smallest universal region that contains all other diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs similarity index 97% rename from compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs rename to compiler/rustc_borrowck/src/region_infer/opaque_types.rs index 12fceeff088..39b83e50431 100644 --- a/compiler/rustc_mir/src/borrow_check/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -47,7 +47,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// which has no `external_name` in which case we use `'empty` as the /// region to pass to `infer_opaque_definition_from_instantiation`. #[instrument(skip(self, infcx))] - pub(in crate::borrow_check) fn infer_opaque_types( + pub(crate) fn infer_opaque_types( &self, infcx: &InferCtxt<'_, 'tcx>, opaque_ty_decls: VecMap, Ty<'tcx>>, @@ -105,7 +105,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// that the regions produced are in fact equal to the named region they are /// replaced with. This is fine because this function is only to improve the /// region names in error messages. - pub(in crate::borrow_check) fn name_regions(&self, tcx: TyCtxt<'tcx>, ty: T) -> T + pub(crate) fn name_regions(&self, tcx: TyCtxt<'tcx>, ty: T) -> T where T: TypeFoldable<'tcx>, { diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/reverse_sccs.rs b/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs similarity index 95% rename from compiler/rustc_mir/src/borrow_check/region_infer/reverse_sccs.rs rename to compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs index 5d345a6e63d..056907dcb16 100644 --- a/compiler/rustc_mir/src/borrow_check/region_infer/reverse_sccs.rs +++ b/compiler/rustc_borrowck/src/region_infer/reverse_sccs.rs @@ -1,5 +1,5 @@ -use crate::borrow_check::constraints::ConstraintSccIndex; -use crate::borrow_check::RegionInferenceContext; +use crate::constraints::ConstraintSccIndex; +use crate::RegionInferenceContext; use itertools::Itertools; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::graph::vec_graph::VecGraph; diff --git a/compiler/rustc_mir/src/borrow_check/region_infer/values.rs b/compiler/rustc_borrowck/src/region_infer/values.rs similarity index 100% rename from compiler/rustc_mir/src/borrow_check/region_infer/values.rs rename to compiler/rustc_borrowck/src/region_infer/values.rs diff --git a/compiler/rustc_mir/src/borrow_check/renumber.rs b/compiler/rustc_borrowck/src/renumber.rs similarity index 100% rename from compiler/rustc_mir/src/borrow_check/renumber.rs rename to compiler/rustc_borrowck/src/renumber.rs diff --git a/compiler/rustc_mir/src/borrow_check/type_check/canonical.rs b/compiler/rustc_borrowck/src/type_check/canonical.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/type_check/canonical.rs rename to compiler/rustc_borrowck/src/type_check/canonical.rs index b501716a899..7a8c0a3da1f 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/canonical.rs +++ b/compiler/rustc_borrowck/src/type_check/canonical.rs @@ -8,7 +8,7 @@ use rustc_span::Span; use rustc_trait_selection::traits::query::type_op::{self, TypeOpOutput}; use rustc_trait_selection::traits::query::Fallible; -use crate::borrow_check::diagnostics::{ToUniverseInfo, UniverseInfo}; +use crate::diagnostics::{ToUniverseInfo, UniverseInfo}; use super::{Locations, NormalizeLocation, TypeChecker}; diff --git a/compiler/rustc_mir/src/borrow_check/type_check/constraint_conversion.rs b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/type_check/constraint_conversion.rs rename to compiler/rustc_borrowck/src/type_check/constraint_conversion.rs index 446a0f8e72f..b0207468485 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/constraint_conversion.rs +++ b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs @@ -9,7 +9,7 @@ use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::DUMMY_SP; -use crate::borrow_check::{ +use crate::{ constraints::OutlivesConstraint, nll::ToRegionVid, region_infer::TypeTest, diff --git a/compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs rename to compiler/rustc_borrowck/src/type_check/free_region_relations.rs index 6426098d843..e1e8f6a61ad 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/free_region_relations.rs +++ b/compiler/rustc_borrowck/src/type_check/free_region_relations.rs @@ -13,7 +13,7 @@ use rustc_trait_selection::traits::query::type_op::{self, TypeOp}; use std::rc::Rc; use type_op::TypeOpOutput; -use crate::borrow_check::{ +use crate::{ nll::ToRegionVid, type_check::constraint_conversion, type_check::{Locations, MirTypeckRegionConstraints}, @@ -55,7 +55,7 @@ type RegionBoundPairs<'tcx> = Vec<(ty::Region<'tcx>, GenericKind<'tcx>)>; type NormalizedInputsAndOutput<'tcx> = Vec>; crate struct CreateResult<'tcx> { - pub(in crate::borrow_check) universal_region_relations: Frozen>, + crate universal_region_relations: Frozen>, crate region_bound_pairs: RegionBoundPairs<'tcx>, crate normalized_inputs_and_output: NormalizedInputsAndOutput<'tcx>, } diff --git a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs b/compiler/rustc_borrowck/src/type_check/input_output.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/type_check/input_output.rs rename to compiler/rustc_borrowck/src/type_check/input_output.rs index ba9b6926526..9d6f6f60a94 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/input_output.rs +++ b/compiler/rustc_borrowck/src/type_check/input_output.rs @@ -7,16 +7,15 @@ //! `RETURN_PLACE` the MIR arguments) are always fully normalized (and //! contain revealed `impl Trait` values). +use rustc_index::vec::Idx; use rustc_infer::infer::LateBoundRegionConversionTime; use rustc_middle::mir::*; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::{self, Ty}; +use rustc_span::Span; use rustc_trait_selection::traits::query::normalize::AtExt; -use rustc_index::vec::Idx; -use rustc_span::Span; - -use crate::borrow_check::universal_regions::UniversalRegions; +use crate::universal_regions::UniversalRegions; use super::{Locations, TypeChecker}; diff --git a/compiler/rustc_mir/src/borrow_check/type_check/liveness/local_use_map.rs b/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs similarity index 97% rename from compiler/rustc_mir/src/borrow_check/type_check/liveness/local_use_map.rs rename to compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs index 7e8a33efe11..8b74abd94c0 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/liveness/local_use_map.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs @@ -3,8 +3,8 @@ use rustc_index::vec::IndexVec; use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::{Body, Local, Location}; -use crate::borrow_check::def_use::{self, DefUse}; -use crate::borrow_check::region_infer::values::{PointIndex, RegionValueElements}; +use crate::def_use::{self, DefUse}; +use crate::region_infer::values::{PointIndex, RegionValueElements}; /// A map that cross references each local with the locations where it /// is defined (assigned), used, or dropped. Used during liveness diff --git a/compiler/rustc_mir/src/borrow_check/type_check/liveness/mod.rs b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs similarity index 96% rename from compiler/rustc_mir/src/borrow_check/type_check/liveness/mod.rs rename to compiler/rustc_borrowck/src/type_check/liveness/mod.rs index a34ae281b70..265c14bb286 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/liveness/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs @@ -3,11 +3,11 @@ use rustc_middle::mir::{Body, Local}; use rustc_middle::ty::{RegionVid, TyCtxt}; use std::rc::Rc; -use crate::dataflow::impls::MaybeInitializedPlaces; -use crate::dataflow::move_paths::MoveData; -use crate::dataflow::ResultsCursor; +use rustc_mir::dataflow::impls::MaybeInitializedPlaces; +use rustc_mir::dataflow::move_paths::MoveData; +use rustc_mir::dataflow::ResultsCursor; -use crate::borrow_check::{ +use crate::{ constraints::OutlivesConstraintSet, facts::{AllFacts, AllFactsExt}, location::LocationTable, diff --git a/compiler/rustc_mir/src/borrow_check/type_check/liveness/polonius.rs b/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs similarity index 96% rename from compiler/rustc_mir/src/borrow_check/type_check/liveness/polonius.rs rename to compiler/rustc_borrowck/src/type_check/liveness/polonius.rs index d285098c52a..7c087d38eb7 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/liveness/polonius.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/polonius.rs @@ -1,10 +1,9 @@ -use crate::borrow_check::def_use::{self, DefUse}; -use crate::borrow_check::location::{LocationIndex, LocationTable}; -use crate::dataflow::indexes::MovePathIndex; -use crate::dataflow::move_paths::{LookupResult, MoveData}; +use crate::def_use::{self, DefUse}; +use crate::location::{LocationIndex, LocationTable}; use rustc_middle::mir::visit::{MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::{Body, Local, Location, Place}; use rustc_middle::ty::subst::GenericArg; +use rustc_mir::dataflow::move_paths::{LookupResult, MoveData, MovePathIndex}; use super::TypeChecker; diff --git a/compiler/rustc_mir/src/borrow_check/type_check/liveness/trace.rs b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs similarity index 98% rename from compiler/rustc_mir/src/borrow_check/type_check/liveness/trace.rs rename to compiler/rustc_borrowck/src/type_check/liveness/trace.rs index 566c11811e6..c7d776bfde0 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/liveness/trace.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/trace.rs @@ -8,12 +8,11 @@ use rustc_trait_selection::traits::query::type_op::outlives::DropckOutlives; use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput}; use std::rc::Rc; -use crate::dataflow::impls::MaybeInitializedPlaces; -use crate::dataflow::indexes::MovePathIndex; -use crate::dataflow::move_paths::{HasMoveData, MoveData}; -use crate::dataflow::ResultsCursor; +use rustc_mir::dataflow::impls::MaybeInitializedPlaces; +use rustc_mir::dataflow::move_paths::{HasMoveData, MoveData, MovePathIndex}; +use rustc_mir::dataflow::ResultsCursor; -use crate::borrow_check::{ +use crate::{ region_infer::values::{self, PointIndex, RegionValueElements}, type_check::liveness::local_use_map::LocalUseMap, type_check::liveness::polonius, diff --git a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/type_check/mod.rs rename to compiler/rustc_borrowck/src/type_check/mod.rs index 639bcb8fa94..63075d066a6 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -41,14 +41,14 @@ use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp; use rustc_trait_selection::traits::query::Fallible; use rustc_trait_selection::traits::{self, ObligationCause, PredicateObligations}; -use crate::dataflow::impls::MaybeInitializedPlaces; -use crate::dataflow::move_paths::MoveData; -use crate::dataflow::ResultsCursor; -use crate::transform::{ +use rustc_mir::dataflow::impls::MaybeInitializedPlaces; +use rustc_mir::dataflow::move_paths::MoveData; +use rustc_mir::dataflow::ResultsCursor; +use rustc_mir::transform::{ check_consts::ConstCx, promote_consts::is_const_fn_in_array_repeat_expression, }; -use crate::borrow_check::{ +use crate::{ borrow_set::BorrowSet, constraints::{OutlivesConstraint, OutlivesConstraintSet}, diagnostics::UniverseInfo, @@ -68,7 +68,7 @@ use crate::borrow_check::{ macro_rules! span_mirbug { ($context:expr, $elem:expr, $($message:tt)*) => ({ - $crate::borrow_check::type_check::mirbug( + $crate::type_check::mirbug( $context.tcx(), $context.last_span, &format!( @@ -887,7 +887,7 @@ struct BorrowCheckContext<'a, 'tcx> { crate struct MirTypeckResults<'tcx> { crate constraints: MirTypeckRegionConstraints<'tcx>, - pub(in crate::borrow_check) universal_region_relations: Frozen>, + crate universal_region_relations: Frozen>, crate opaque_type_values: VecMap, Ty<'tcx>>, } diff --git a/compiler/rustc_mir/src/borrow_check/type_check/relate_tys.rs b/compiler/rustc_borrowck/src/type_check/relate_tys.rs similarity index 96% rename from compiler/rustc_mir/src/borrow_check/type_check/relate_tys.rs rename to compiler/rustc_borrowck/src/type_check/relate_tys.rs index 971c4daa6b3..0b9c33ccb77 100644 --- a/compiler/rustc_mir/src/borrow_check/type_check/relate_tys.rs +++ b/compiler/rustc_borrowck/src/type_check/relate_tys.rs @@ -5,9 +5,9 @@ use rustc_middle::ty::relate::TypeRelation; use rustc_middle::ty::{self, Const, Ty}; use rustc_trait_selection::traits::query::Fallible; -use crate::borrow_check::constraints::OutlivesConstraint; -use crate::borrow_check::diagnostics::UniverseInfo; -use crate::borrow_check::type_check::{BorrowCheckContext, Locations}; +use crate::constraints::OutlivesConstraint; +use crate::diagnostics::UniverseInfo; +use crate::type_check::{BorrowCheckContext, Locations}; /// Adds sufficient constraints to ensure that `a R b` where `R` depends on `v`: /// diff --git a/compiler/rustc_mir/src/borrow_check/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/universal_regions.rs rename to compiler/rustc_borrowck/src/universal_regions.rs index 3c9b4272b36..bebd1937029 100644 --- a/compiler/rustc_mir/src/borrow_check/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -26,7 +26,7 @@ use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef}; use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt}; use std::iter; -use crate::borrow_check::nll::ToRegionVid; +use crate::nll::ToRegionVid; #[derive(Debug)] pub struct UniversalRegions<'tcx> { diff --git a/compiler/rustc_mir/src/borrow_check/used_muts.rs b/compiler/rustc_borrowck/src/used_muts.rs similarity index 99% rename from compiler/rustc_mir/src/borrow_check/used_muts.rs rename to compiler/rustc_borrowck/src/used_muts.rs index e027056842d..6022a980950 100644 --- a/compiler/rustc_mir/src/borrow_check/used_muts.rs +++ b/compiler/rustc_borrowck/src/used_muts.rs @@ -1,11 +1,10 @@ +use rustc_data_structures::fx::FxHashSet; use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::{ Local, Location, Place, Statement, StatementKind, Terminator, TerminatorKind, }; -use rustc_data_structures::fx::FxHashSet; - -use crate::borrow_check::MirBorrowckCtxt; +use crate::MirBorrowckCtxt; impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// Walks the MIR adding to the set of `used_mut` locals that will be ignored for the purposes diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml index dad5b256e42..970267d626c 100644 --- a/compiler/rustc_interface/Cargo.toml +++ b/compiler/rustc_interface/Cargo.toml @@ -14,6 +14,7 @@ rayon = { version = "0.3.1", package = "rustc-rayon" } smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } rustc_ast = { path = "../rustc_ast" } rustc_attr = { path = "../rustc_attr" } +rustc_borrowck = { path = "../rustc_borrowck" } rustc_builtin_macros = { path = "../rustc_builtin_macros" } rustc_expand = { path = "../rustc_expand" } rustc_parse = { path = "../rustc_parse" } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 1d542db9b69..df03ff59f46 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -4,6 +4,7 @@ use crate::util; use rustc_ast::mut_visit::MutVisitor; use rustc_ast::{self as ast, visit}; +use rustc_borrowck as mir_borrowck; use rustc_codegen_ssa::back::link::emit_metadata; use rustc_codegen_ssa::traits::CodegenBackend; use rustc_data_structures::parallel; @@ -739,6 +740,7 @@ pub static DEFAULT_QUERY_PROVIDERS: SyncLazy = SyncLazy::new(|| { proc_macro_decls::provide(providers); rustc_middle::hir::provide(providers); mir::provide(providers); + mir_borrowck::provide(providers); mir_build::provide(providers); rustc_privacy::provide(providers); typeck::provide(providers); diff --git a/compiler/rustc_mir/Cargo.toml b/compiler/rustc_mir/Cargo.toml index 3049fb3b383..43c7b681e05 100644 --- a/compiler/rustc_mir/Cargo.toml +++ b/compiler/rustc_mir/Cargo.toml @@ -8,30 +8,28 @@ doctest = false [dependencies] either = "1.5.0" -rustc_graphviz = { path = "../rustc_graphviz" } gsgdt = "0.1.2" itertools = "0.9" -tracing = "0.1" polonius-engine = "0.13.0" regex = "1" -rustc_middle = { path = "../rustc_middle" } +smallvec = { version = "1.0", features = ["union", "may_dangle"] } +tracing = "0.1" +rustc_apfloat = { path = "../rustc_apfloat" } +rustc_ast = { path = "../rustc_ast" } rustc_attr = { path = "../rustc_attr" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } +rustc_graphviz = { path = "../rustc_graphviz" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } rustc_infer = { path = "../rustc_infer" } -rustc_lexer = { path = "../rustc_lexer" } rustc_macros = { path = "../rustc_macros" } +rustc_middle = { path = "../rustc_middle" } rustc_serialize = { path = "../rustc_serialize" } rustc_session = { path = "../rustc_session" } rustc_target = { path = "../rustc_target" } rustc_trait_selection = { path = "../rustc_trait_selection" } -rustc_traits = { path = "../rustc_traits" } -rustc_ast = { path = "../rustc_ast" } rustc_span = { path = "../rustc_span" } -rustc_apfloat = { path = "../rustc_apfloat" } -smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } [dev-dependencies] coverage_test_macros = { path = "src/transform/coverage/test_macros" } diff --git a/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs b/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs index d16366fded9..d4f8f994ae9 100644 --- a/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs +++ b/compiler/rustc_mir/src/dataflow/drop_flag_effects.rs @@ -204,7 +204,7 @@ pub(crate) fn drop_flag_effects_for_location<'tcx, F>( for_location_inits(tcx, body, move_data, loc, |mpi| callback(mpi, DropFlagState::Present)); } -pub(crate) fn for_location_inits<'tcx, F>( +pub fn for_location_inits<'tcx, F>( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, move_data: &MoveData<'tcx>, diff --git a/compiler/rustc_mir/src/dataflow/framework/mod.rs b/compiler/rustc_mir/src/dataflow/framework/mod.rs index a5badc07d10..0bf62db1ada 100644 --- a/compiler/rustc_mir/src/dataflow/framework/mod.rs +++ b/compiler/rustc_mir/src/dataflow/framework/mod.rs @@ -50,8 +50,7 @@ pub use self::cursor::{ResultsCursor, ResultsRefCursor}; pub use self::direction::{Backward, Direction, Forward}; pub use self::engine::{Engine, Results}; pub use self::lattice::{JoinSemiLattice, MeetSemiLattice}; -pub use self::visitor::{visit_results, ResultsVisitor}; -pub use self::visitor::{BorrowckFlowState, BorrowckResults}; +pub use self::visitor::{visit_results, ResultsVisitable, ResultsVisitor}; /// Define the domain of a dataflow problem. /// diff --git a/compiler/rustc_mir/src/dataflow/framework/visitor.rs b/compiler/rustc_mir/src/dataflow/framework/visitor.rs index 82eb734ed06..84136c4d78c 100644 --- a/compiler/rustc_mir/src/dataflow/framework/visitor.rs +++ b/compiler/rustc_mir/src/dataflow/framework/visitor.rs @@ -1,7 +1,6 @@ use rustc_middle::mir::{self, BasicBlock, Location}; use super::{Analysis, Direction, Results}; -use crate::dataflow::impls::{borrows::Borrows, EverInitializedPlaces, MaybeUninitializedPlaces}; /// Calls the corresponding method in `ResultsVisitor` for every location in a `mir::Body` with the /// dataflow state at that location. @@ -186,95 +185,3 @@ where self.analysis.apply_terminator_effect(state, term, loc); } } - -/// A tuple with named fields that can hold either the results or the transient state of the -/// dataflow analyses used by the borrow checker. -#[derive(Debug)] -pub struct BorrowckAnalyses { - pub borrows: B, - pub uninits: U, - pub ever_inits: E, -} - -/// The results of the dataflow analyses used by the borrow checker. -pub type BorrowckResults<'mir, 'tcx> = BorrowckAnalyses< - Results<'tcx, Borrows<'mir, 'tcx>>, - Results<'tcx, MaybeUninitializedPlaces<'mir, 'tcx>>, - Results<'tcx, EverInitializedPlaces<'mir, 'tcx>>, ->; - -/// The transient state of the dataflow analyses used by the borrow checker. -pub type BorrowckFlowState<'mir, 'tcx> = - as ResultsVisitable<'tcx>>::FlowState; - -macro_rules! impl_visitable { - ( $( - $T:ident { $( $field:ident : $A:ident ),* $(,)? } - )* ) => { $( - impl<'tcx, $($A),*, D: Direction> ResultsVisitable<'tcx> for $T<$( Results<'tcx, $A> ),*> - where - $( $A: Analysis<'tcx, Direction = D>, )* - { - type Direction = D; - type FlowState = $T<$( $A::Domain ),*>; - - fn new_flow_state(&self, body: &mir::Body<'tcx>) -> Self::FlowState { - $T { - $( $field: self.$field.analysis.bottom_value(body) ),* - } - } - - fn reset_to_block_entry( - &self, - state: &mut Self::FlowState, - block: BasicBlock, - ) { - $( state.$field.clone_from(&self.$field.entry_set_for_block(block)); )* - } - - fn reconstruct_before_statement_effect( - &self, - state: &mut Self::FlowState, - stmt: &mir::Statement<'tcx>, - loc: Location, - ) { - $( self.$field.analysis - .apply_before_statement_effect(&mut state.$field, stmt, loc); )* - } - - fn reconstruct_statement_effect( - &self, - state: &mut Self::FlowState, - stmt: &mir::Statement<'tcx>, - loc: Location, - ) { - $( self.$field.analysis - .apply_statement_effect(&mut state.$field, stmt, loc); )* - } - - fn reconstruct_before_terminator_effect( - &self, - state: &mut Self::FlowState, - term: &mir::Terminator<'tcx>, - loc: Location, - ) { - $( self.$field.analysis - .apply_before_terminator_effect(&mut state.$field, term, loc); )* - } - - fn reconstruct_terminator_effect( - &self, - state: &mut Self::FlowState, - term: &mir::Terminator<'tcx>, - loc: Location, - ) { - $( self.$field.analysis - .apply_terminator_effect(&mut state.$field, term, loc); )* - } - } - )* } -} - -impl_visitable! { - BorrowckAnalyses { borrows: B, uninits: U, ever_inits: E } -} diff --git a/compiler/rustc_mir/src/dataflow/impls/mod.rs b/compiler/rustc_mir/src/dataflow/impls/mod.rs index 185f0edfeb6..020a7b188fd 100644 --- a/compiler/rustc_mir/src/dataflow/impls/mod.rs +++ b/compiler/rustc_mir/src/dataflow/impls/mod.rs @@ -21,13 +21,11 @@ use crate::dataflow::drop_flag_effects; use crate::dataflow::framework::SwitchIntEdgeEffects; mod borrowed_locals; -pub(super) mod borrows; mod init_locals; mod liveness; mod storage_liveness; pub use self::borrowed_locals::{MaybeBorrowedLocals, MaybeMutBorrowedLocals}; -pub use self::borrows::Borrows; pub use self::init_locals::MaybeInitializedLocals; pub use self::liveness::MaybeLiveLocals; pub use self::storage_liveness::{MaybeRequiresStorage, MaybeStorageLive}; diff --git a/compiler/rustc_mir/src/dataflow/mod.rs b/compiler/rustc_mir/src/dataflow/mod.rs index 8a426cc1015..bb38f90a3ba 100644 --- a/compiler/rustc_mir/src/dataflow/mod.rs +++ b/compiler/rustc_mir/src/dataflow/mod.rs @@ -5,9 +5,9 @@ use rustc_span::symbol::{sym, Symbol}; pub(crate) use self::drop_flag_effects::*; pub use self::framework::{ - fmt, graphviz, lattice, visit_results, Analysis, AnalysisDomain, Backward, BorrowckFlowState, - BorrowckResults, Engine, Forward, GenKill, GenKillAnalysis, JoinSemiLattice, Results, - ResultsCursor, ResultsRefCursor, ResultsVisitor, SwitchIntEdgeEffects, + fmt, lattice, visit_results, Analysis, AnalysisDomain, Backward, Direction, Engine, Forward, + GenKill, GenKillAnalysis, JoinSemiLattice, Results, ResultsCursor, ResultsRefCursor, + ResultsVisitable, ResultsVisitor, }; use self::move_paths::MoveData; @@ -18,15 +18,12 @@ pub mod impls; pub mod move_paths; pub(crate) mod indexes { - pub(crate) use super::{ - impls::borrows::BorrowIndex, - move_paths::{InitIndex, MoveOutIndex, MovePathIndex}, - }; + pub(crate) use super::move_paths::MovePathIndex; } pub struct MoveDataParamEnv<'tcx> { - pub(crate) move_data: MoveData<'tcx>, - pub(crate) param_env: ty::ParamEnv<'tcx>, + pub move_data: MoveData<'tcx>, + pub param_env: ty::ParamEnv<'tcx>, } pub(crate) fn has_rustc_mir_with( diff --git a/compiler/rustc_mir/src/dataflow/move_paths/mod.rs b/compiler/rustc_mir/src/dataflow/move_paths/mod.rs index 7c630259186..699ec4bbff8 100644 --- a/compiler/rustc_mir/src/dataflow/move_paths/mod.rs +++ b/compiler/rustc_mir/src/dataflow/move_paths/mod.rs @@ -19,6 +19,12 @@ rustc_index::newtype_index! { } } +impl polonius_engine::Atom for MovePathIndex { + fn index(self) -> usize { + rustc_index::vec::Idx::index(self) + } +} + rustc_index::newtype_index! { pub struct MoveOutIndex { DEBUG_FORMAT = "mo{}" @@ -276,7 +282,7 @@ impl fmt::Debug for Init { } impl Init { - crate fn span<'tcx>(&self, body: &Body<'tcx>) -> Span { + pub fn span<'tcx>(&self, body: &Body<'tcx>) -> Span { match self.location { InitLocation::Argument(local) => body.local_decls[local].source_info.span, InitLocation::Statement(location) => body.source_info(location).span, @@ -338,12 +344,12 @@ impl MovePathLookup { #[derive(Debug)] pub struct IllegalMoveOrigin<'tcx> { - pub(crate) location: Location, - pub(crate) kind: IllegalMoveOriginKind<'tcx>, + pub location: Location, + pub kind: IllegalMoveOriginKind<'tcx>, } #[derive(Debug)] -pub(crate) enum IllegalMoveOriginKind<'tcx> { +pub enum IllegalMoveOriginKind<'tcx> { /// Illegal move due to attempt to move from behind a reference. BorrowedContent { /// The place the reference refers to: if erroneous code was trying to diff --git a/compiler/rustc_mir/src/lib.rs b/compiler/rustc_mir/src/lib.rs index e439a247c7f..16dddc949df 100644 --- a/compiler/rustc_mir/src/lib.rs +++ b/compiler/rustc_mir/src/lib.rs @@ -4,40 +4,35 @@ Rust MIR: a lowered representation of Rust. */ -#![feature(nll)] -#![feature(in_band_lifetimes)] #![feature(array_windows)] #![feature(assert_matches)] #![cfg_attr(bootstrap, feature(bindings_after_at))] +#![feature(associated_type_defaults)] #![feature(bool_to_option)] #![feature(box_patterns)] +#![feature(control_flow_enum)] #![feature(crate_visibility_modifier)] #![feature(decl_macro)] #![feature(exact_size_is_empty)] -#![feature(format_args_capture)] +#![feature(in_band_lifetimes)] #![feature(iter_zip)] -#![feature(never_type)] #![feature(map_try_insert)] #![feature(min_specialization)] #![feature(slice_ptr_get)] -#![feature(trusted_len)] -#![feature(try_blocks)] -#![feature(associated_type_defaults)] -#![feature(stmt_expr_attributes)] -#![feature(trait_alias)] #![feature(option_get_or_insert_default)] #![feature(once_cell)] -#![feature(control_flow_enum)] -#![feature(try_reserve)] -#![feature(try_reserve_kind)] -#![recursion_limit = "256"] +#![feature(never_type)] +#![feature(stmt_expr_attributes)] +#![feature(trait_alias)] +#![feature(trusted_len)] +#![feature(trusted_step)] +#![feature(try_blocks)] #[macro_use] extern crate tracing; #[macro_use] extern crate rustc_middle; -mod borrow_check; pub mod const_eval; pub mod dataflow; pub mod interpret; @@ -46,13 +41,9 @@ mod shim; pub mod transform; pub mod util; -// A public API provided for the Rust compiler consumers. -pub use self::borrow_check::consumers; - use rustc_middle::ty::query::Providers; pub fn provide(providers: &mut Providers) { - borrow_check::provide(providers); const_eval::provide(providers); shim::provide(providers); transform::provide(providers); diff --git a/compiler/rustc_mir/src/transform/promote_consts.rs b/compiler/rustc_mir/src/transform/promote_consts.rs index 1b43670ba3a..6822ad2d7b5 100644 --- a/compiler/rustc_mir/src/transform/promote_consts.rs +++ b/compiler/rustc_mir/src/transform/promote_consts.rs @@ -1058,7 +1058,7 @@ pub fn promote_candidates<'tcx>( /// This function returns `true` if the function being called in the array /// repeat expression is a `const` function. -crate fn is_const_fn_in_array_repeat_expression<'tcx>( +pub fn is_const_fn_in_array_repeat_expression<'tcx>( ccx: &ConstCx<'_, 'tcx>, place: &Place<'tcx>, body: &Body<'tcx>, diff --git a/compiler/rustc_mir/src/util/collect_writes.rs b/compiler/rustc_mir/src/util/collect_writes.rs index ecf3b08a96e..9c56fd722bd 100644 --- a/compiler/rustc_mir/src/util/collect_writes.rs +++ b/compiler/rustc_mir/src/util/collect_writes.rs @@ -2,7 +2,7 @@ use rustc_middle::mir::visit::PlaceContext; use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::{Body, Local, Location}; -crate trait FindAssignments { +pub trait FindAssignments { // Finds all statements that assign directly to local (i.e., X = ...) // and returns their locations. fn find_assignments(&self, local: Local) -> Vec; diff --git a/compiler/rustc_mir/src/util/mod.rs b/compiler/rustc_mir/src/util/mod.rs index 3e466b5060f..8f9db6daba7 100644 --- a/compiler/rustc_mir/src/util/mod.rs +++ b/compiler/rustc_mir/src/util/mod.rs @@ -1,5 +1,4 @@ pub mod aggregate; -pub mod borrowck_errors; pub mod elaborate_drops; pub mod patch; pub mod storage; @@ -10,7 +9,7 @@ mod find_self_call; mod generic_graph; pub(crate) mod generic_graphviz; mod graphviz; -pub(crate) mod pretty; +pub mod pretty; pub(crate) mod spanview; pub use self::aggregate::expand_aggregate; diff --git a/compiler/rustc_mir/src/util/pretty.rs b/compiler/rustc_mir/src/util/pretty.rs index 92591db668c..ec1aa5b476b 100644 --- a/compiler/rustc_mir/src/util/pretty.rs +++ b/compiler/rustc_mir/src/util/pretty.rs @@ -250,7 +250,7 @@ fn create_dump_file_with_basename( /// bit of MIR-related data. Used by `mir-dump`, but also by other /// bits of code (e.g., NLL inference) that dump graphviz data or /// other things, and hence takes the extension as an argument. -pub(crate) fn create_dump_file( +pub fn create_dump_file( tcx: TyCtxt<'_>, extension: &str, pass_num: Option<&dyn Display>,