@@ -66,7 +66,6 @@ use crate::hir::def::{CtorOf, Res, DefKind, CtorKind};
6666use crate :: ty:: adjustment;
6767use crate :: ty:: { self , DefIdTree , Ty , TyCtxt } ;
6868use crate :: ty:: fold:: TypeFoldable ;
69- use crate :: ty:: layout:: VariantIdx ;
7069
7170use crate :: hir:: { MutImmutable , MutMutable , PatKind } ;
7271use crate :: hir:: pat_util:: EnumerateAndAdjustIterator ;
@@ -79,7 +78,6 @@ use std::borrow::Cow;
7978use std:: fmt;
8079use std:: hash:: { Hash , Hasher } ;
8180use rustc_data_structures:: fx:: FxIndexMap ;
82- use rustc_data_structures:: indexed_vec:: Idx ;
8381use std:: rc:: Rc ;
8482use crate :: util:: nodemap:: ItemLocalSet ;
8583
@@ -198,79 +196,6 @@ pub struct cmt_<'tcx> {
198196
199197pub 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-
274199pub trait HirNode {
275200 fn hir_id ( & self ) -> hir:: HirId ;
276201 fn span ( & self ) -> Span ;
0 commit comments