Skip to content

Commit be085d7

Browse files
committed
Remove rustc_mir dependency from rustc_borrowck
1 parent 4bb6b4a commit be085d7

File tree

15 files changed

+229
-2046
lines changed

15 files changed

+229
-2046
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -2954,7 +2954,6 @@ dependencies = [
29542954
"rustc 0.0.0",
29552955
"rustc_data_structures 0.0.0",
29562956
"rustc_errors 0.0.0",
2957-
"rustc_mir 0.0.0",
29582957
"syntax 0.0.0",
29592958
"syntax_pos 0.0.0",
29602959
]

src/librustc/middle/borrowck.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
use crate::ich::StableHashingContext;
2-
use crate::hir::HirId;
3-
use crate::util::nodemap::FxHashSet;
42

53
use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
64
StableHasherResult};
@@ -18,7 +16,6 @@ impl_stable_hash_for!(enum self::SignalledError { SawSomeError, NoErrorsSeen });
1816

1917
#[derive(Debug, Default, RustcEncodable, RustcDecodable)]
2018
pub struct BorrowCheckResult {
21-
pub used_mut_nodes: FxHashSet<HirId>,
2219
pub signalled_any_error: SignalledError,
2320
}
2421

@@ -27,10 +24,8 @@ impl<'a> HashStable<StableHashingContext<'a>> for BorrowCheckResult {
2724
hcx: &mut StableHashingContext<'a>,
2825
hasher: &mut StableHasher<W>) {
2926
let BorrowCheckResult {
30-
ref used_mut_nodes,
3127
ref signalled_any_error,
3228
} = *self;
33-
used_mut_nodes.hash_stable(hcx, hasher);
3429
signalled_any_error.hash_stable(hcx, hasher);
3530
}
3631
}

src/librustc/middle/mem_categorization.rs

-75
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ use crate::hir::def::{CtorOf, Res, DefKind, CtorKind};
6666
use crate::ty::adjustment;
6767
use crate::ty::{self, DefIdTree, Ty, TyCtxt};
6868
use crate::ty::fold::TypeFoldable;
69-
use crate::ty::layout::VariantIdx;
7069

7170
use crate::hir::{MutImmutable, MutMutable, PatKind};
7271
use crate::hir::pat_util::EnumerateAndAdjustIterator;
@@ -79,7 +78,6 @@ use std::borrow::Cow;
7978
use std::fmt;
8079
use std::hash::{Hash, Hasher};
8180
use rustc_data_structures::fx::FxIndexMap;
82-
use rustc_data_structures::indexed_vec::Idx;
8381
use std::rc::Rc;
8482
use crate::util::nodemap::ItemLocalSet;
8583

@@ -198,79 +196,6 @@ pub struct cmt_<'tcx> {
198196

199197
pub type cmt<'tcx> = Rc<cmt_<'tcx>>;
200198

201-
pub enum ImmutabilityBlame<'tcx> {
202-
ImmLocal(hir::HirId),
203-
ClosureEnv(LocalDefId),
204-
LocalDeref(hir::HirId),
205-
AdtFieldDeref(&'tcx ty::AdtDef, &'tcx ty::FieldDef)
206-
}
207-
208-
impl<'tcx> cmt_<'tcx> {
209-
fn resolve_field(&self, field_index: usize) -> Option<(&'tcx ty::AdtDef, &'tcx ty::FieldDef)>
210-
{
211-
let adt_def = match self.ty.sty {
212-
ty::Adt(def, _) => def,
213-
ty::Tuple(..) => return None,
214-
// closures get `Categorization::Upvar` rather than `Categorization::Interior`
215-
_ => bug!("interior cmt {:?} is not an ADT", self)
216-
};
217-
let variant_def = match self.cat {
218-
Categorization::Downcast(_, variant_did) => {
219-
adt_def.variant_with_id(variant_did)
220-
}
221-
_ => {
222-
assert_eq!(adt_def.variants.len(), 1);
223-
&adt_def.variants[VariantIdx::new(0)]
224-
}
225-
};
226-
Some((adt_def, &variant_def.fields[field_index]))
227-
}
228-
229-
pub fn immutability_blame(&self) -> Option<ImmutabilityBlame<'tcx>> {
230-
match self.cat {
231-
Categorization::Deref(ref base_cmt, BorrowedPtr(ty::ImmBorrow, _)) => {
232-
// try to figure out where the immutable reference came from
233-
match base_cmt.cat {
234-
Categorization::Local(hir_id) =>
235-
Some(ImmutabilityBlame::LocalDeref(hir_id)),
236-
Categorization::Interior(ref base_cmt, InteriorField(field_index)) => {
237-
base_cmt.resolve_field(field_index.0).map(|(adt_def, field_def)| {
238-
ImmutabilityBlame::AdtFieldDeref(adt_def, field_def)
239-
})
240-
}
241-
Categorization::Upvar(Upvar { id, .. }) => {
242-
if let NoteClosureEnv(..) = self.note {
243-
Some(ImmutabilityBlame::ClosureEnv(id.closure_expr_id))
244-
} else {
245-
None
246-
}
247-
}
248-
_ => None
249-
}
250-
}
251-
Categorization::Local(hir_id) => {
252-
Some(ImmutabilityBlame::ImmLocal(hir_id))
253-
}
254-
Categorization::Rvalue(..) |
255-
Categorization::Upvar(..) |
256-
Categorization::Deref(_, UnsafePtr(..)) => {
257-
// This should not be reachable up to inference limitations.
258-
None
259-
}
260-
Categorization::Interior(ref base_cmt, _) |
261-
Categorization::Downcast(ref base_cmt, _) |
262-
Categorization::Deref(ref base_cmt, _) => {
263-
base_cmt.immutability_blame()
264-
}
265-
Categorization::ThreadLocal(..) |
266-
Categorization::StaticItem => {
267-
// Do we want to do something here?
268-
None
269-
}
270-
}
271-
}
272-
}
273-
274199
pub trait HirNode {
275200
fn hir_id(&self) -> hir::HirId;
276201
fn span(&self) -> Span;

src/librustc_borrowck/Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
authors = ["The Rust Project Developers"]
3-
name = "rustc_borrowck"
3+
name = "rustc_ast_borrowck"
44
version = "0.0.0"
55
edition = "2018"
66

77
[lib]
8-
name = "rustc_borrowck"
8+
name = "rustc_ast_borrowck"
99
path = "lib.rs"
1010
test = false
1111
doctest = false
@@ -18,6 +18,5 @@ syntax_pos = { path = "../libsyntax_pos" }
1818
# refers to the borrowck-specific graphviz adapter traits.
1919
dot = { path = "../libgraphviz", package = "graphviz" }
2020
rustc = { path = "../librustc" }
21-
rustc_mir = { path = "../librustc_mir" }
2221
errors = { path = "../librustc_errors", package = "rustc_errors" }
2322
rustc_data_structures = { path = "../librustc_data_structures" }

0 commit comments

Comments
 (0)