Move some utils out of rustc_const_eval
This allows us to get rid of the `rustc_const_eval->rustc_borrowck` dependency edge which was delaying the compilation of borrowck. The added utils in `rustc_middle` are small and should not affect compile times there.
This commit is contained in:
parent
e6e956dade
commit
2109fe4e4e
15 changed files with 30 additions and 25 deletions
|
@ -1,5 +1,4 @@
|
|||
use either::Either;
|
||||
use rustc_const_eval::util::CallKind;
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_errors::{
|
||||
|
@ -18,6 +17,7 @@ use rustc_middle::mir::{
|
|||
ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm,
|
||||
};
|
||||
use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty};
|
||||
use rustc_middle::util::CallKind;
|
||||
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::hygiene::DesugaringKind;
|
||||
|
@ -2424,7 +2424,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
Some((method_did, method_substs)),
|
||||
) = (
|
||||
&self.body[loan.reserve_location.block].terminator,
|
||||
rustc_const_eval::util::find_self_call(
|
||||
rustc_middle::util::find_self_call(
|
||||
tcx,
|
||||
self.body,
|
||||
loan.assigned_place.local,
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
//! Borrow checker diagnostics.
|
||||
|
||||
use itertools::Itertools;
|
||||
use rustc_const_eval::util::{call_kind, CallDesugaringKind};
|
||||
use rustc_errors::{Applicability, Diagnostic};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, Namespace};
|
||||
|
@ -15,6 +14,7 @@ use rustc_middle::mir::{
|
|||
};
|
||||
use rustc_middle::ty::print::Print;
|
||||
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
|
||||
use rustc_middle::util::{call_kind, CallDesugaringKind};
|
||||
use rustc_mir_dataflow::move_paths::{InitLocation, LookupResult};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::{symbol::sym, Span, Symbol, DUMMY_SP};
|
||||
|
@ -45,7 +45,7 @@ pub(crate) use mutability_errors::AccessKind;
|
|||
pub(crate) use outlives_suggestion::OutlivesSuggestionBuilder;
|
||||
pub(crate) use region_errors::{ErrorConstraintInfo, RegionErrorKind, RegionErrors};
|
||||
pub(crate) use region_name::{RegionName, RegionNameSource};
|
||||
pub(crate) use rustc_const_eval::util::CallKind;
|
||||
pub(crate) use rustc_middle::util::CallKind;
|
||||
|
||||
pub(super) struct DescribePlaceOpt {
|
||||
pub including_downcast: bool,
|
||||
|
@ -874,7 +874,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
}) = &self.body[location.block].terminator
|
||||
{
|
||||
let Some((method_did, method_substs)) =
|
||||
rustc_const_eval::util::find_self_call(
|
||||
rustc_middle::util::find_self_call(
|
||||
self.infcx.tcx,
|
||||
&self.body,
|
||||
target_temp,
|
||||
|
|
|
@ -15,8 +15,8 @@ use rustc_span::{sym, BytePos, Span};
|
|||
use rustc_target::abi::FieldIdx;
|
||||
|
||||
use crate::diagnostics::BorrowedContentSource;
|
||||
use crate::util::FindAssignments;
|
||||
use crate::MirBorrowckCtxt;
|
||||
use rustc_const_eval::util::collect_writes::FindAssignments;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub(crate) enum AccessKind {
|
||||
|
|
|
@ -88,6 +88,7 @@ mod session_diagnostics;
|
|||
mod type_check;
|
||||
mod universal_regions;
|
||||
mod used_muts;
|
||||
mod util;
|
||||
|
||||
/// A public API provided for the Rust compiler consumers.
|
||||
pub mod consumers;
|
||||
|
|
36
compiler/rustc_borrowck/src/util/collect_writes.rs
Normal file
36
compiler/rustc_borrowck/src/util/collect_writes.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
use rustc_middle::mir::visit::PlaceContext;
|
||||
use rustc_middle::mir::visit::Visitor;
|
||||
use rustc_middle::mir::{Body, Local, Location};
|
||||
|
||||
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<Location>;
|
||||
}
|
||||
|
||||
impl<'tcx> FindAssignments for Body<'tcx> {
|
||||
fn find_assignments(&self, local: Local) -> Vec<Location> {
|
||||
let mut visitor = FindLocalAssignmentVisitor { needle: local, locations: vec![] };
|
||||
visitor.visit_body(self);
|
||||
visitor.locations
|
||||
}
|
||||
}
|
||||
|
||||
// The Visitor walks the MIR to return the assignment statements corresponding
|
||||
// to a Local.
|
||||
struct FindLocalAssignmentVisitor {
|
||||
needle: Local,
|
||||
locations: Vec<Location>,
|
||||
}
|
||||
|
||||
impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor {
|
||||
fn visit_local(&mut self, local: Local, place_context: PlaceContext, location: Location) {
|
||||
if self.needle != local {
|
||||
return;
|
||||
}
|
||||
|
||||
if place_context.is_place_assignment() {
|
||||
self.locations.push(location);
|
||||
}
|
||||
}
|
||||
}
|
3
compiler/rustc_borrowck/src/util/mod.rs
Normal file
3
compiler/rustc_borrowck/src/util/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
mod collect_writes;
|
||||
|
||||
pub use collect_writes::FindAssignments;
|
Loading…
Add table
Add a link
Reference in a new issue