Skip to content

Commit f267d5b

Browse files
lcnrcuviper
authored andcommitted
rename BorrowKind::Shallow to Fake
also adds some comments (cherry picked from commit 992d93f)
1 parent 9425991 commit f267d5b

File tree

30 files changed

+75
-68
lines changed

30 files changed

+75
-68
lines changed

compiler/rustc_borrowck/src/borrow_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl<'tcx> fmt::Display for BorrowData<'tcx> {
7171
fn fmt(&self, w: &mut fmt::Formatter<'_>) -> fmt::Result {
7272
let kind = match self.kind {
7373
mir::BorrowKind::Shared => "",
74-
mir::BorrowKind::Shallow => "shallow ",
74+
mir::BorrowKind::Fake => "fake ",
7575
mir::BorrowKind::Mut { kind: mir::MutBorrowKind::ClosureCapture } => "uniq ",
7676
// FIXME: differentiate `TwoPhaseBorrow`
7777
mir::BorrowKind::Mut {

compiler/rustc_borrowck/src/def_use.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {
4949
// cross suspension points so this behavior is unproblematic.
5050
PlaceContext::MutatingUse(MutatingUseContext::Borrow) |
5151
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) |
52-
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow) |
52+
PlaceContext::NonMutatingUse(NonMutatingUseContext::FakeBorrow) |
5353

5454
// `PlaceMention` and `AscribeUserType` both evaluate the place, which must not
5555
// contain dangling references.

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10251025
self.cannot_uniquely_borrow_by_two_closures(span, &desc_place, issued_span, None)
10261026
}
10271027

1028-
(BorrowKind::Mut { .. }, BorrowKind::Shallow) => {
1028+
(BorrowKind::Mut { .. }, BorrowKind::Fake) => {
10291029
if let Some(immutable_section_description) =
10301030
self.classify_immutable_section(issued_borrow.assigned_place)
10311031
{
@@ -1117,11 +1117,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11171117
)
11181118
}
11191119

1120-
(BorrowKind::Shared, BorrowKind::Shared | BorrowKind::Shallow)
1121-
| (
1122-
BorrowKind::Shallow,
1123-
BorrowKind::Mut { .. } | BorrowKind::Shared | BorrowKind::Shallow,
1124-
) => unreachable!(),
1120+
(BorrowKind::Shared, BorrowKind::Shared | BorrowKind::Fake)
1121+
| (BorrowKind::Fake, BorrowKind::Mut { .. } | BorrowKind::Shared | BorrowKind::Fake) => {
1122+
unreachable!()
1123+
}
11251124
};
11261125

11271126
if issued_spans == borrow_spans {
@@ -2644,7 +2643,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
26442643
let loan_span = loan_spans.args_or_use();
26452644

26462645
let descr_place = self.describe_any_place(place.as_ref());
2647-
if loan.kind == BorrowKind::Shallow {
2646+
if loan.kind == BorrowKind::Fake {
26482647
if let Some(section) = self.classify_immutable_section(loan.assigned_place) {
26492648
let mut err = self.cannot_mutate_in_immutable_section(
26502649
span,

compiler/rustc_borrowck/src/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ impl UseSpans<'_> {
628628
err.subdiagnostic(match kind {
629629
Some(kd) => match kd {
630630
rustc_middle::mir::BorrowKind::Shared
631-
| rustc_middle::mir::BorrowKind::Shallow => {
631+
| rustc_middle::mir::BorrowKind::Fake => {
632632
CaptureVarKind::Immut { kind_span: capture_kind_span }
633633
}
634634

compiler/rustc_borrowck/src/invalidation.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
253253
match rvalue {
254254
&Rvalue::Ref(_ /*rgn*/, bk, place) => {
255255
let access_kind = match bk {
256-
BorrowKind::Shallow => {
257-
(Shallow(Some(ArtificialField::ShallowBorrow)), Read(ReadKind::Borrow(bk)))
256+
BorrowKind::Fake => {
257+
(Shallow(Some(ArtificialField::FakeBorrow)), Read(ReadKind::Borrow(bk)))
258258
}
259259
BorrowKind::Shared => (Deep, Read(ReadKind::Borrow(bk))),
260260
BorrowKind::Mut { .. } => {
@@ -376,8 +376,8 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
376376
// have already taken the reservation
377377
}
378378

379-
(Read(_), BorrowKind::Shallow | BorrowKind::Shared)
380-
| (Read(ReadKind::Borrow(BorrowKind::Shallow)), BorrowKind::Mut { .. }) => {
379+
(Read(_), BorrowKind::Fake | BorrowKind::Shared)
380+
| (Read(ReadKind::Borrow(BorrowKind::Fake)), BorrowKind::Mut { .. }) => {
381381
// Reads don't invalidate shared or shallow borrows
382382
}
383383

@@ -422,7 +422,7 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
422422

423423
// only mutable borrows should be 2-phase
424424
assert!(match borrow.kind {
425-
BorrowKind::Shared | BorrowKind::Shallow => false,
425+
BorrowKind::Shared | BorrowKind::Fake => false,
426426
BorrowKind::Mut { .. } => true,
427427
});
428428

compiler/rustc_borrowck/src/lib.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ use self::ReadOrWrite::{Activation, Read, Reservation, Write};
837837
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
838838
enum ArtificialField {
839839
ArrayLength,
840-
ShallowBorrow,
840+
FakeBorrow,
841841
}
842842

843843
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
@@ -1076,18 +1076,18 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10761076
Control::Continue
10771077
}
10781078

1079-
(Read(_), BorrowKind::Shared | BorrowKind::Shallow)
1080-
| (Read(ReadKind::Borrow(BorrowKind::Shallow)), BorrowKind::Mut { .. }) => {
1079+
(Read(_), BorrowKind::Shared | BorrowKind::Fake)
1080+
| (Read(ReadKind::Borrow(BorrowKind::Fake)), BorrowKind::Mut { .. }) => {
10811081
Control::Continue
10821082
}
10831083

1084-
(Reservation(_), BorrowKind::Shallow | BorrowKind::Shared) => {
1084+
(Reservation(_), BorrowKind::Fake | BorrowKind::Shared) => {
10851085
// This used to be a future compatibility warning (to be
10861086
// disallowed on NLL). See rust-lang/rust#56254
10871087
Control::Continue
10881088
}
10891089

1090-
(Write(WriteKind::Move), BorrowKind::Shallow) => {
1090+
(Write(WriteKind::Move), BorrowKind::Fake) => {
10911091
// Handled by initialization checks.
10921092
Control::Continue
10931093
}
@@ -1195,8 +1195,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11951195
match rvalue {
11961196
&Rvalue::Ref(_ /*rgn*/, bk, place) => {
11971197
let access_kind = match bk {
1198-
BorrowKind::Shallow => {
1199-
(Shallow(Some(ArtificialField::ShallowBorrow)), Read(ReadKind::Borrow(bk)))
1198+
BorrowKind::Fake => {
1199+
(Shallow(Some(ArtificialField::FakeBorrow)), Read(ReadKind::Borrow(bk)))
12001200
}
12011201
BorrowKind::Shared => (Deep, Read(ReadKind::Borrow(bk))),
12021202
BorrowKind::Mut { .. } => {
@@ -1217,7 +1217,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12171217
flow_state,
12181218
);
12191219

1220-
let action = if bk == BorrowKind::Shallow {
1220+
let action = if bk == BorrowKind::Fake {
12211221
InitializationRequiringAction::MatchOn
12221222
} else {
12231223
InitializationRequiringAction::Borrow
@@ -1569,7 +1569,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15691569

15701570
// only mutable borrows should be 2-phase
15711571
assert!(match borrow.kind {
1572-
BorrowKind::Shared | BorrowKind::Shallow => false,
1572+
BorrowKind::Shared | BorrowKind::Fake => false,
15731573
BorrowKind::Mut { .. } => true,
15741574
});
15751575

@@ -2002,14 +2002,14 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20022002
| WriteKind::Replace
20032003
| WriteKind::StorageDeadOrDrop
20042004
| WriteKind::MutableBorrow(BorrowKind::Shared)
2005-
| WriteKind::MutableBorrow(BorrowKind::Shallow),
2005+
| WriteKind::MutableBorrow(BorrowKind::Fake),
20062006
)
20072007
| Write(
20082008
WriteKind::Move
20092009
| WriteKind::Replace
20102010
| WriteKind::StorageDeadOrDrop
20112011
| WriteKind::MutableBorrow(BorrowKind::Shared)
2012-
| WriteKind::MutableBorrow(BorrowKind::Shallow),
2012+
| WriteKind::MutableBorrow(BorrowKind::Fake),
20132013
) => {
20142014
if self.is_mutable(place.as_ref(), is_local_mutation_allowed).is_err()
20152015
&& !self.has_buffered_errors()
@@ -2033,7 +2033,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
20332033
return false;
20342034
}
20352035
Read(
2036-
ReadKind::Borrow(BorrowKind::Mut { .. } | BorrowKind::Shared | BorrowKind::Shallow)
2036+
ReadKind::Borrow(BorrowKind::Mut { .. } | BorrowKind::Shared | BorrowKind::Fake)
20372037
| ReadKind::Copy,
20382038
) => {
20392039
// Access authorized

compiler/rustc_borrowck/src/places_conflict.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ fn place_components_conflict<'tcx>(
204204

205205
match (elem, &base_ty.kind(), access) {
206206
(_, _, Shallow(Some(ArtificialField::ArrayLength)))
207-
| (_, _, Shallow(Some(ArtificialField::ShallowBorrow))) => {
207+
| (_, _, Shallow(Some(ArtificialField::FakeBorrow))) => {
208208
// The array length is like additional fields on the
209209
// type; it does not overlap any existing data there.
210210
// Furthermore, if cannot actually be a prefix of any
@@ -272,10 +272,10 @@ fn place_components_conflict<'tcx>(
272272
// If the second example, where we did, then we still know
273273
// that the borrow can access a *part* of our place that
274274
// our access cares about, so we still have a conflict.
275-
if borrow_kind == BorrowKind::Shallow
275+
if borrow_kind == BorrowKind::Fake
276276
&& borrow_place.projection.len() < access_place.projection.len()
277277
{
278-
debug!("borrow_conflicts_with_place: shallow borrow");
278+
debug!("borrow_conflicts_with_place: fake borrow");
279279
false
280280
} else {
281281
debug!("borrow_conflicts_with_place: full borrow, CONFLICT");

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
745745
PlaceContext::MutatingUse(_) => ty::Invariant,
746746
PlaceContext::NonUse(StorageDead | StorageLive | VarDebugInfo) => ty::Invariant,
747747
PlaceContext::NonMutatingUse(
748-
Inspect | Copy | Move | PlaceMention | SharedBorrow | ShallowBorrow | AddressOf
748+
Inspect | Copy | Move | PlaceMention | SharedBorrow | FakeBorrow | AddressOf
749749
| Projection,
750750
) => ty::Covariant,
751751
PlaceContext::NonUse(AscribeUserTy(variance)) => variance,

compiler/rustc_codegen_ssa/src/mir/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
234234
| PlaceContext::NonMutatingUse(
235235
NonMutatingUseContext::Inspect
236236
| NonMutatingUseContext::SharedBorrow
237-
| NonMutatingUseContext::ShallowBorrow
237+
| NonMutatingUseContext::FakeBorrow
238238
| NonMutatingUseContext::AddressOf
239239
| NonMutatingUseContext::Projection,
240240
) => {

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
415415
BorrowKind::Shared => {
416416
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow)
417417
}
418-
BorrowKind::Shallow => {
419-
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow)
418+
BorrowKind::Fake => {
419+
PlaceContext::NonMutatingUse(NonMutatingUseContext::FakeBorrow)
420420
}
421421
BorrowKind::Mut { .. } => {
422422
PlaceContext::MutatingUse(MutatingUseContext::Borrow)
@@ -491,7 +491,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
491491
self.check_mut_borrow(place.local, hir::BorrowKind::Raw)
492492
}
493493

494-
Rvalue::Ref(_, BorrowKind::Shared | BorrowKind::Shallow, place)
494+
Rvalue::Ref(_, BorrowKind::Shared | BorrowKind::Fake, place)
495495
| Rvalue::AddressOf(Mutability::Not, place) => {
496496
let borrowed_place_has_mut_interior = qualifs::in_place::<HasMutInterior, _>(
497497
&self.ccx,

compiler/rustc_const_eval/src/transform/check_consts/resolver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ where
105105
fn ref_allows_mutation(&self, kind: mir::BorrowKind, place: mir::Place<'tcx>) -> bool {
106106
match kind {
107107
mir::BorrowKind::Mut { .. } => true,
108-
mir::BorrowKind::Shared | mir::BorrowKind::Shallow => {
108+
mir::BorrowKind::Shared | mir::BorrowKind::Fake => {
109109
self.shared_borrow_allows_mutation(place)
110110
}
111111
}

compiler/rustc_const_eval/src/transform/promote_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ impl<'tcx> Validator<'_, 'tcx> {
454454
match kind {
455455
// Reject these borrow types just to be safe.
456456
// FIXME(RalfJung): could we allow them? Should we? No point in it until we have a usecase.
457-
BorrowKind::Shallow | BorrowKind::Mut { kind: MutBorrowKind::ClosureCapture } => {
457+
BorrowKind::Fake | BorrowKind::Mut { kind: MutBorrowKind::ClosureCapture } => {
458458
return Err(Unpromotable);
459459
}
460460

compiler/rustc_const_eval/src/transform/validate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -821,11 +821,11 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
821821
}
822822
match rvalue {
823823
Rvalue::Use(_) | Rvalue::CopyForDeref(_) | Rvalue::Aggregate(..) => {}
824-
Rvalue::Ref(_, BorrowKind::Shallow, _) => {
824+
Rvalue::Ref(_, BorrowKind::Fake, _) => {
825825
if self.mir_phase >= MirPhase::Runtime(RuntimePhase::Initial) {
826826
self.fail(
827827
location,
828-
"`Assign` statement with a `Shallow` borrow should have been removed in runtime MIR",
828+
"`Assign` statement with a `Fake` borrow should have been removed in runtime MIR",
829829
);
830830
}
831831
}

compiler/rustc_middle/src/mir/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
924924
Ref(region, borrow_kind, ref place) => {
925925
let kind_str = match borrow_kind {
926926
BorrowKind::Shared => "",
927-
BorrowKind::Shallow => "shallow ",
927+
BorrowKind::Fake => "fake ",
928928
BorrowKind::Mut { .. } => "mut ",
929929
};
930930

compiler/rustc_middle/src/mir/statement.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -443,15 +443,15 @@ impl<'tcx> Rvalue<'tcx> {
443443
impl BorrowKind {
444444
pub fn mutability(&self) -> Mutability {
445445
match *self {
446-
BorrowKind::Shared | BorrowKind::Shallow => Mutability::Not,
446+
BorrowKind::Shared | BorrowKind::Fake => Mutability::Not,
447447
BorrowKind::Mut { .. } => Mutability::Mut,
448448
}
449449
}
450450

451451
pub fn allows_two_phase_borrow(&self) -> bool {
452452
match *self {
453453
BorrowKind::Shared
454-
| BorrowKind::Shallow
454+
| BorrowKind::Fake
455455
| BorrowKind::Mut { kind: MutBorrowKind::Default | MutBorrowKind::ClosureCapture } => {
456456
false
457457
}

compiler/rustc_middle/src/mir/syntax.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub enum AnalysisPhase {
123123
/// * [`TerminatorKind::FalseEdge`]
124124
/// * [`StatementKind::FakeRead`]
125125
/// * [`StatementKind::AscribeUserType`]
126-
/// * [`Rvalue::Ref`] with `BorrowKind::Shallow`
126+
/// * [`Rvalue::Ref`] with `BorrowKind::Fake`
127127
///
128128
/// Furthermore, `Deref` projections must be the first projection within any place (if they
129129
/// appear at all)
@@ -182,7 +182,7 @@ pub enum BorrowKind {
182182
/// should not prevent `if let None = x { ... }`, for example, because the
183183
/// mutating `(*x as Some).0` can't affect the discriminant of `x`.
184184
/// We can also report errors with this kind of borrow differently.
185-
Shallow,
185+
Fake,
186186

187187
/// Data is mutable and not aliasable.
188188
Mut { kind: MutBorrowKind },

compiler/rustc_middle/src/mir/tcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl BorrowKind {
273273

274274
// We have no type corresponding to a shallow borrow, so use
275275
// `&` as an approximation.
276-
BorrowKind::Shallow => hir::Mutability::Not,
276+
BorrowKind::Fake => hir::Mutability::Not,
277277
}
278278
}
279279
}

compiler/rustc_middle/src/mir/visit.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -647,8 +647,8 @@ macro_rules! make_mir_visitor {
647647
BorrowKind::Shared => PlaceContext::NonMutatingUse(
648648
NonMutatingUseContext::SharedBorrow
649649
),
650-
BorrowKind::Shallow => PlaceContext::NonMutatingUse(
651-
NonMutatingUseContext::ShallowBorrow
650+
BorrowKind::Fake => PlaceContext::NonMutatingUse(
651+
NonMutatingUseContext::FakeBorrow
652652
),
653653
BorrowKind::Mut { .. } =>
654654
PlaceContext::MutatingUse(MutatingUseContext::Borrow),
@@ -1253,8 +1253,8 @@ pub enum NonMutatingUseContext {
12531253
Move,
12541254
/// Shared borrow.
12551255
SharedBorrow,
1256-
/// Shallow borrow.
1257-
ShallowBorrow,
1256+
/// A fake borrow.
1257+
FakeBorrow,
12581258
/// AddressOf for *const pointer.
12591259
AddressOf,
12601260
/// PlaceMention statement.
@@ -1333,7 +1333,7 @@ impl PlaceContext {
13331333
matches!(
13341334
self,
13351335
PlaceContext::NonMutatingUse(
1336-
NonMutatingUseContext::SharedBorrow | NonMutatingUseContext::ShallowBorrow
1336+
NonMutatingUseContext::SharedBorrow | NonMutatingUseContext::FakeBorrow
13371337
) | PlaceContext::MutatingUse(MutatingUseContext::Borrow)
13381338
)
13391339
}

compiler/rustc_mir_build/src/build/expr/as_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
690690
fake_borrow_temp.into(),
691691
Rvalue::Ref(
692692
tcx.lifetimes.re_erased,
693-
BorrowKind::Shallow,
693+
BorrowKind::Fake,
694694
Place { local: base_place.local, projection },
695695
),
696696
);

compiler/rustc_mir_build/src/build/matches/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
20042004
let re_erased = tcx.lifetimes.re_erased;
20052005
let scrutinee_source_info = self.source_info(scrutinee_span);
20062006
for &(place, temp) in fake_borrows {
2007-
let borrow = Rvalue::Ref(re_erased, BorrowKind::Shallow, place);
2007+
let borrow = Rvalue::Ref(re_erased, BorrowKind::Fake, place);
20082008
self.cfg.push_assign(block, scrutinee_source_info, Place::from(temp), borrow);
20092009
}
20102010

0 commit comments

Comments
 (0)