@@ -228,7 +228,7 @@ impl<'tcx> Mir<'tcx> {
228
228
pub fn temps_iter < ' a > ( & ' a self ) -> impl Iterator < Item =Local > + ' a {
229
229
( self . arg_count +1 ..self . local_decls . len ( ) ) . filter_map ( move |index| {
230
230
let local = Local :: new ( index) ;
231
- if self . local_decls [ local] . is_user_variable {
231
+ if self . local_decls [ local] . is_user_variable . is_some ( ) {
232
232
None
233
233
} else {
234
234
Some ( local)
@@ -241,7 +241,7 @@ impl<'tcx> Mir<'tcx> {
241
241
pub fn vars_iter < ' a > ( & ' a self ) -> impl Iterator < Item =Local > + ' a {
242
242
( self . arg_count +1 ..self . local_decls . len ( ) ) . filter_map ( move |index| {
243
243
let local = Local :: new ( index) ;
244
- if self . local_decls [ local] . is_user_variable {
244
+ if self . local_decls [ local] . is_user_variable . is_some ( ) {
245
245
Some ( local)
246
246
} else {
247
247
None
@@ -255,7 +255,7 @@ impl<'tcx> Mir<'tcx> {
255
255
( 1 ..self . local_decls . len ( ) ) . filter_map ( move |index| {
256
256
let local = Local :: new ( index) ;
257
257
let decl = & self . local_decls [ local] ;
258
- if ( decl. is_user_variable || index < self . arg_count + 1 )
258
+ if ( decl. is_user_variable . is_some ( ) || index < self . arg_count + 1 )
259
259
&& decl. mutability == Mutability :: Mut
260
260
{
261
261
Some ( local)
@@ -351,7 +351,7 @@ impl<'tcx> IndexMut<BasicBlock> for Mir<'tcx> {
351
351
}
352
352
}
353
353
354
- #[ derive( Clone , Debug ) ]
354
+ #[ derive( Copy , Clone , Debug ) ]
355
355
pub enum ClearCrossCrate < T > {
356
356
Clear ,
357
357
Set ( T )
@@ -382,6 +382,16 @@ pub enum Mutability {
382
382
Not ,
383
383
}
384
384
385
+ impl From < Mutability > for hir:: Mutability {
386
+ fn from ( m : Mutability ) -> Self {
387
+ match m {
388
+ Mutability :: Mut => hir:: MutMutable ,
389
+ Mutability :: Not => hir:: MutImmutable ,
390
+ }
391
+ }
392
+ }
393
+
394
+
385
395
#[ derive( Copy , Clone , Debug , PartialEq , Eq , RustcEncodable , RustcDecodable ) ]
386
396
pub enum BorrowKind {
387
397
/// Data must be immutable and is aliasable.
@@ -463,6 +473,33 @@ pub enum LocalKind {
463
473
ReturnPointer ,
464
474
}
465
475
476
+ #[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug , RustcEncodable , RustcDecodable ) ]
477
+ pub struct VarBindingForm {
478
+ /// Is variable bound via `x`, `mut x`, `ref x`, or `ref mut x`?
479
+ pub binding_mode : ty:: BindingMode ,
480
+ /// If an explicit type was provided for this variable binding,
481
+ /// this holds the source Span of that type.
482
+ ///
483
+ /// NOTE: If you want to change this to a `HirId`, be wary that
484
+ /// doing so breaks incremental compilation (as of this writing),
485
+ /// while a `Span` does not cause our tests to fail.
486
+ pub opt_ty_info : Option < Span > ,
487
+ }
488
+
489
+ #[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug , RustcEncodable , RustcDecodable ) ]
490
+ pub enum BindingForm {
491
+ /// This is a binding for a non-`self` binding, or a `self` that has an explicit type.
492
+ Var ( VarBindingForm ) ,
493
+ /// Binding for a `self`/`&self`/`&mut self` binding where the type is implicit.
494
+ ImplicitSelf ,
495
+ }
496
+
497
+ CloneTypeFoldableAndLiftImpls ! { BindingForm , }
498
+
499
+ impl_stable_hash_for ! ( struct self :: VarBindingForm { binding_mode, opt_ty_info } ) ;
500
+
501
+ impl_stable_hash_for ! ( enum self :: BindingForm { Var ( binding) , ImplicitSelf , } ) ;
502
+
466
503
/// A MIR local.
467
504
///
468
505
/// This can be a binding declared by the user, a temporary inserted by the compiler, a function
@@ -474,8 +511,14 @@ pub struct LocalDecl<'tcx> {
474
511
/// Temporaries and the return place are always mutable.
475
512
pub mutability : Mutability ,
476
513
477
- /// True if this corresponds to a user-declared local variable.
478
- pub is_user_variable : bool ,
514
+ /// Some(binding_mode) if this corresponds to a user-declared local variable.
515
+ ///
516
+ /// This is solely used for local diagnostics when generating
517
+ /// warnings/errors when compiling the current crate, and
518
+ /// therefore it need not be visible across crates. pnkfelix
519
+ /// currently hypothesized we *need* to wrap this in a
520
+ /// `ClearCrossCrate` as long as it carries as `HirId`.
521
+ pub is_user_variable : Option < ClearCrossCrate < BindingForm > > ,
479
522
480
523
/// True if this is an internal local
481
524
///
@@ -605,7 +648,7 @@ impl<'tcx> LocalDecl<'tcx> {
605
648
} ,
606
649
visibility_scope : OUTERMOST_SOURCE_SCOPE ,
607
650
internal : false ,
608
- is_user_variable : false
651
+ is_user_variable : None ,
609
652
}
610
653
}
611
654
@@ -622,7 +665,7 @@ impl<'tcx> LocalDecl<'tcx> {
622
665
} ,
623
666
visibility_scope : OUTERMOST_SOURCE_SCOPE ,
624
667
internal : true ,
625
- is_user_variable : false
668
+ is_user_variable : None ,
626
669
}
627
670
}
628
671
@@ -641,7 +684,7 @@ impl<'tcx> LocalDecl<'tcx> {
641
684
visibility_scope : OUTERMOST_SOURCE_SCOPE ,
642
685
internal : false ,
643
686
name : None , // FIXME maybe we do want some name here?
644
- is_user_variable : false
687
+ is_user_variable : None ,
645
688
}
646
689
}
647
690
}
0 commit comments