@@ -20,9 +20,6 @@ pub use closure::*;
20
20
pub use generics:: * ;
21
21
22
22
use crate :: hir:: exports:: ExportMap ;
23
- use crate :: hir:: place:: {
24
- Place as HirPlace , PlaceBase as HirPlaceBase , ProjectionKind as HirProjectionKind ,
25
- } ;
26
23
use crate :: ich:: StableHashingContext ;
27
24
use crate :: middle:: cstore:: CrateStoreDyn ;
28
25
use crate :: mir:: { Body , GeneratorLayout } ;
@@ -352,140 +349,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TyS<'tcx> {
352
349
#[ rustc_diagnostic_item = "Ty" ]
353
350
pub type Ty < ' tcx > = & ' tcx TyS < ' tcx > ;
354
351
355
- #[ derive( Clone , PartialEq , Debug , TyEncodable , TyDecodable , TypeFoldable , Copy , HashStable ) ]
356
- pub enum BorrowKind {
357
- /// Data must be immutable and is aliasable.
358
- ImmBorrow ,
359
-
360
- /// Data must be immutable but not aliasable. This kind of borrow
361
- /// cannot currently be expressed by the user and is used only in
362
- /// implicit closure bindings. It is needed when the closure
363
- /// is borrowing or mutating a mutable referent, e.g.:
364
- ///
365
- /// ```
366
- /// let x: &mut isize = ...;
367
- /// let y = || *x += 5;
368
- /// ```
369
- ///
370
- /// If we were to try to translate this closure into a more explicit
371
- /// form, we'd encounter an error with the code as written:
372
- ///
373
- /// ```
374
- /// struct Env { x: & &mut isize }
375
- /// let x: &mut isize = ...;
376
- /// let y = (&mut Env { &x }, fn_ptr); // Closure is pair of env and fn
377
- /// fn fn_ptr(env: &mut Env) { **env.x += 5; }
378
- /// ```
379
- ///
380
- /// This is then illegal because you cannot mutate a `&mut` found
381
- /// in an aliasable location. To solve, you'd have to translate with
382
- /// an `&mut` borrow:
383
- ///
384
- /// ```
385
- /// struct Env { x: & &mut isize }
386
- /// let x: &mut isize = ...;
387
- /// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x
388
- /// fn fn_ptr(env: &mut Env) { **env.x += 5; }
389
- /// ```
390
- ///
391
- /// Now the assignment to `**env.x` is legal, but creating a
392
- /// mutable pointer to `x` is not because `x` is not mutable. We
393
- /// could fix this by declaring `x` as `let mut x`. This is ok in
394
- /// user code, if awkward, but extra weird for closures, since the
395
- /// borrow is hidden.
396
- ///
397
- /// So we introduce a "unique imm" borrow -- the referent is
398
- /// immutable, but not aliasable. This solves the problem. For
399
- /// simplicity, we don't give users the way to express this
400
- /// borrow, it's just used when translating closures.
401
- UniqueImmBorrow ,
402
-
403
- /// Data is mutable and not aliasable.
404
- MutBorrow ,
405
- }
406
-
407
- pub fn place_to_string_for_capture ( tcx : TyCtxt < ' tcx > , place : & HirPlace < ' tcx > ) -> String {
408
- let name = match place. base {
409
- HirPlaceBase :: Upvar ( upvar_id) => tcx. hir ( ) . name ( upvar_id. var_path . hir_id ) . to_string ( ) ,
410
- _ => bug ! ( "Capture_information should only contain upvars" ) ,
411
- } ;
412
- let mut curr_string = name;
413
-
414
- for ( i, proj) in place. projections . iter ( ) . enumerate ( ) {
415
- match proj. kind {
416
- HirProjectionKind :: Deref => {
417
- curr_string = format ! ( "*{}" , curr_string) ;
418
- }
419
- HirProjectionKind :: Field ( idx, variant) => match place. ty_before_projection ( i) . kind ( ) {
420
- ty:: Adt ( def, ..) => {
421
- curr_string = format ! (
422
- "{}.{}" ,
423
- curr_string,
424
- def. variants[ variant] . fields[ idx as usize ] . ident. name. as_str( )
425
- ) ;
426
- }
427
- ty:: Tuple ( _) => {
428
- curr_string = format ! ( "{}.{}" , curr_string, idx) ;
429
- }
430
- _ => {
431
- bug ! (
432
- "Field projection applied to a type other than Adt or Tuple: {:?}." ,
433
- place. ty_before_projection( i) . kind( )
434
- )
435
- }
436
- } ,
437
- proj => bug ! ( "{:?} unexpected because it isn't captured" , proj) ,
438
- }
439
- }
440
-
441
- curr_string. to_string ( )
442
- }
443
-
444
- /// Part of `MinCaptureInformationMap`; describes the capture kind (&, &mut, move)
445
- /// for a particular capture as well as identifying the part of the source code
446
- /// that triggered this capture to occur.
447
- #[ derive( PartialEq , Clone , Debug , Copy , TyEncodable , TyDecodable , TypeFoldable , HashStable ) ]
448
- pub struct CaptureInfo < ' tcx > {
449
- /// Expr Id pointing to use that resulted in selecting the current capture kind
450
- ///
451
- /// Eg:
452
- /// ```rust,no_run
453
- /// let mut t = (0,1);
454
- ///
455
- /// let c = || {
456
- /// println!("{}",t); // L1
457
- /// t.1 = 4; // L2
458
- /// };
459
- /// ```
460
- /// `capture_kind_expr_id` will point to the use on L2 and `path_expr_id` will point to the
461
- /// use on L1.
462
- ///
463
- /// If the user doesn't enable feature `capture_disjoint_fields` (RFC 2229) then, it is
464
- /// possible that we don't see the use of a particular place resulting in capture_kind_expr_id being
465
- /// None. In such case we fallback on uvpars_mentioned for span.
466
- ///
467
- /// Eg:
468
- /// ```rust,no_run
469
- /// let x = 5;
470
- ///
471
- /// let c = || {
472
- /// let _ = x
473
- /// };
474
- /// ```
475
- ///
476
- /// In this example, if `capture_disjoint_fields` is **not** set, then x will be captured,
477
- /// but we won't see it being used during capture analysis, since it's essentially a discard.
478
- pub capture_kind_expr_id : Option < hir:: HirId > ,
479
- /// Expr Id pointing to use that resulted the corresponding place being captured
480
- ///
481
- /// See `capture_kind_expr_id` for example.
482
- ///
483
- pub path_expr_id : Option < hir:: HirId > ,
484
-
485
- /// Capture mode that was selected
486
- pub capture_kind : UpvarCapture < ' tcx > ,
487
- }
488
-
489
352
impl ty:: EarlyBoundRegion {
490
353
/// Does this early bound region have a name? Early bound regions normally
491
354
/// always have names except when using anonymous lifetimes (`'_`).
@@ -1655,39 +1518,6 @@ impl<'tcx> FieldDef {
1655
1518
}
1656
1519
}
1657
1520
1658
- impl BorrowKind {
1659
- pub fn from_mutbl ( m : hir:: Mutability ) -> BorrowKind {
1660
- match m {
1661
- hir:: Mutability :: Mut => MutBorrow ,
1662
- hir:: Mutability :: Not => ImmBorrow ,
1663
- }
1664
- }
1665
-
1666
- /// Returns a mutability `m` such that an `&m T` pointer could be used to obtain this borrow
1667
- /// kind. Because borrow kinds are richer than mutabilities, we sometimes have to pick a
1668
- /// mutability that is stronger than necessary so that it at least *would permit* the borrow in
1669
- /// question.
1670
- pub fn to_mutbl_lossy ( self ) -> hir:: Mutability {
1671
- match self {
1672
- MutBorrow => hir:: Mutability :: Mut ,
1673
- ImmBorrow => hir:: Mutability :: Not ,
1674
-
1675
- // We have no type corresponding to a unique imm borrow, so
1676
- // use `&mut`. It gives all the capabilities of an `&uniq`
1677
- // and hence is a safe "over approximation".
1678
- UniqueImmBorrow => hir:: Mutability :: Mut ,
1679
- }
1680
- }
1681
-
1682
- pub fn to_user_str ( & self ) -> & ' static str {
1683
- match * self {
1684
- MutBorrow => "mutable" ,
1685
- ImmBorrow => "immutable" ,
1686
- UniqueImmBorrow => "uniquely immutable" ,
1687
- }
1688
- }
1689
- }
1690
-
1691
1521
pub type Attributes < ' tcx > = & ' tcx [ ast:: Attribute ] ;
1692
1522
1693
1523
#[ derive( Debug , PartialEq , Eq ) ]
0 commit comments