Skip to content

Commit b27158d

Browse files
committed
Run rustfmt
1 parent 711adc4 commit b27158d

File tree

5 files changed

+85
-47
lines changed

5 files changed

+85
-47
lines changed

compiler/rustc_mir/src/dataflow/framework/fmt.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -139,18 +139,16 @@ where
139139
V: DebugWithContext<C> + Eq,
140140
{
141141
fn fmt_with(&self, ctxt: &C, f: &mut fmt::Formatter<'_>) -> fmt::Result {
142-
f.debug_set().entries(self.iter_enumerated().map(|this| DebugWithAdapter { this, ctxt })).finish()
142+
f.debug_set()
143+
.entries(self.iter_enumerated().map(|this| DebugWithAdapter { this, ctxt }))
144+
.finish()
143145
}
144146

145147
fn fmt_diff_with(&self, old: &Self, ctxt: &C, f: &mut fmt::Formatter<'_>) -> fmt::Result {
146148
assert_eq!(self.len(), old.len());
147149

148150
for (new, old) in self.iter_enumerated().zip(old.iter_enumerated()) {
149-
write!(f, "{:?}", DebugDiffWithAdapter {
150-
new,
151-
old,
152-
ctxt,
153-
})?;
151+
write!(f, "{:?}", DebugDiffWithAdapter { new, old, ctxt })?;
154152
}
155153

156154
Ok(())
@@ -201,7 +199,8 @@ impl<T, U, C> DebugWithContext<C> for (T, U)
201199
where
202200
T: DebugWithContext<C>,
203201
U: DebugWithContext<C>,
204-
{}
202+
{
203+
}
205204

206205
impl<C> DebugWithContext<C> for rustc_middle::mir::Local {}
207206
impl<C> DebugWithContext<C> for crate::dataflow::move_paths::InitIndex {}

compiler/rustc_mir/src/dataflow/framework/lattice.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ impl JoinSemiLattice for () {
107107
impl<T: JoinSemiLattice + Clone> JoinSemiLattice for Option<T> {
108108
fn join(&mut self, other: &Self) -> bool {
109109
match (self, other) {
110-
(None, None) |
111-
(Some(_), None) => false,
110+
(None, None) | (Some(_), None) => false,
112111
(this @ None, Some(val)) => {
113112
*this = Some(val.clone());
114113
true

compiler/rustc_mir/src/transform/check_consts/qualifs.rs

+64-20
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
//!
33
//! See the `Qualif` trait for more info.
44
5+
use crate::dataflow::{fmt::DebugWithContext, JoinSemiLattice};
56
use rustc_errors::ErrorReported;
7+
use rustc_index::bit_set::BitSet;
8+
use rustc_index::vec::IndexVec;
69
use rustc_middle::mir::*;
710
use rustc_middle::ty::{self, subst::SubstsRef, AdtDef, Ty};
811
use rustc_span::DUMMY_SP;
912
use rustc_trait_selection::traits;
10-
use rustc_index::vec::IndexVec;
11-
use rustc_index::bit_set::BitSet;
12-
use crate::dataflow::{JoinSemiLattice, fmt::DebugWithContext};
1313

1414
use super::ConstCx;
1515

@@ -64,7 +64,11 @@ pub(crate) trait Qualif {
6464

6565
/// Sometimes const fn calls cannot possibly contain the qualif, so we can treat function
6666
/// calls special here.
67-
fn in_any_function_call(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>, _args: Option<Self::Result>) -> Option<Self::Result> {
67+
fn in_any_function_call(
68+
cx: &ConstCx<'_, 'tcx>,
69+
ty: Ty<'tcx>,
70+
_args: Option<Self::Result>,
71+
) -> Option<Self::Result> {
6872
Self::in_any_value_of_ty(cx, ty)
6973
}
7074

@@ -159,7 +163,11 @@ impl Qualif for HasMutInterior {
159163
(!ty.is_freeze(cx.tcx.at(DUMMY_SP), cx.param_env)).then_some(())
160164
}
161165

162-
fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &'tcx AdtDef, _: SubstsRef<'tcx>) -> Option<()> {
166+
fn in_adt_inherently(
167+
cx: &ConstCx<'_, 'tcx>,
168+
adt: &'tcx AdtDef,
169+
_: SubstsRef<'tcx>,
170+
) -> Option<()> {
163171
// Exactly one type, `UnsafeCell`, has the `HasMutInterior` qualif inherently.
164172
// It arises structurally for all other types.
165173
(Some(adt.did) == cx.tcx.lang_items().unsafe_cell_type()).then_some(())
@@ -190,7 +198,7 @@ impl JoinSemiLattice for HasMutInteriorBehindRefState {
190198
(Self::OnlyHasMutInterior, Self::Yes) => {
191199
*self = Self::Yes;
192200
true
193-
},
201+
}
194202
(Self::OnlyHasMutInterior, Self::OnlyHasMutInterior) => false,
195203
}
196204
}
@@ -201,27 +209,47 @@ impl Qualif for HasMutInteriorBehindRef {
201209
type Result = HasMutInteriorBehindRefState;
202210

203211
fn in_qualifs(qualifs: &ConstQualifs) -> Option<HasMutInteriorBehindRefState> {
204-
HasMutInterior::in_qualifs(qualifs).map(|()| HasMutInteriorBehindRefState::OnlyHasMutInterior)
212+
HasMutInterior::in_qualifs(qualifs)
213+
.map(|()| HasMutInteriorBehindRefState::OnlyHasMutInterior)
205214
}
206215

207-
fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> Option<HasMutInteriorBehindRefState> {
216+
fn in_any_value_of_ty(
217+
cx: &ConstCx<'_, 'tcx>,
218+
ty: Ty<'tcx>,
219+
) -> Option<HasMutInteriorBehindRefState> {
208220
match ty.builtin_deref(false) {
209-
None => HasMutInterior::in_any_value_of_ty(cx, ty).map(|()| HasMutInteriorBehindRefState::OnlyHasMutInterior),
210-
Some(tam) => HasMutInterior::in_any_value_of_ty(cx, tam.ty).map(|()| HasMutInteriorBehindRefState::Yes),
221+
None => HasMutInterior::in_any_value_of_ty(cx, ty)
222+
.map(|()| HasMutInteriorBehindRefState::OnlyHasMutInterior),
223+
Some(tam) => HasMutInterior::in_any_value_of_ty(cx, tam.ty)
224+
.map(|()| HasMutInteriorBehindRefState::Yes),
211225
}
212226
}
213227

214228
#[instrument(skip(cx))]
215-
fn in_any_function_call(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>, mut args: Option<Self::Result>) -> Option<Self::Result> {
216-
args.join(&HasMutInterior::in_any_value_of_ty(cx, ty).map(|()| HasMutInteriorBehindRefState::OnlyHasMutInterior));
229+
fn in_any_function_call(
230+
cx: &ConstCx<'_, 'tcx>,
231+
ty: Ty<'tcx>,
232+
mut args: Option<Self::Result>,
233+
) -> Option<Self::Result> {
234+
args.join(
235+
&HasMutInterior::in_any_value_of_ty(cx, ty)
236+
.map(|()| HasMutInteriorBehindRefState::OnlyHasMutInterior),
237+
);
217238
args
218239
}
219240

220-
fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &'tcx AdtDef, substs: SubstsRef<'tcx>) -> Option<HasMutInteriorBehindRefState> {
221-
HasMutInterior::in_adt_inherently(cx, adt, substs).map(|()| HasMutInteriorBehindRefState::OnlyHasMutInterior)
241+
fn in_adt_inherently(
242+
cx: &ConstCx<'_, 'tcx>,
243+
adt: &'tcx AdtDef,
244+
substs: SubstsRef<'tcx>,
245+
) -> Option<HasMutInteriorBehindRefState> {
246+
HasMutInterior::in_adt_inherently(cx, adt, substs)
247+
.map(|()| HasMutInteriorBehindRefState::OnlyHasMutInterior)
222248
}
223249

224-
fn in_value_behind_ref(qualif: Option<HasMutInteriorBehindRefState>) -> Option<HasMutInteriorBehindRefState> {
250+
fn in_value_behind_ref(
251+
qualif: Option<HasMutInteriorBehindRefState>,
252+
) -> Option<HasMutInteriorBehindRefState> {
225253
qualif.map(|_| HasMutInteriorBehindRefState::Yes)
226254
}
227255
}
@@ -244,7 +272,11 @@ impl Qualif for NeedsDrop {
244272
ty.needs_drop(cx.tcx, cx.param_env).then_some(())
245273
}
246274

247-
fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &'tcx AdtDef, _: SubstsRef<'tcx>) -> Option<()> {
275+
fn in_adt_inherently(
276+
cx: &ConstCx<'_, 'tcx>,
277+
adt: &'tcx AdtDef,
278+
_: SubstsRef<'tcx>,
279+
) -> Option<()> {
248280
adt.has_dtor(cx.tcx).then_some(())
249281
}
250282
}
@@ -283,7 +315,11 @@ impl Qualif for CustomEq {
283315

284316
/// Returns `true` if this `Rvalue` contains qualif `Q`.
285317
#[instrument(skip(cx, in_local), fields(Q=std::any::type_name::<Q>()))]
286-
pub(crate) fn in_rvalue<Q, F>(cx: &ConstCx<'_, 'tcx>, in_local: &mut F, rvalue: &Rvalue<'tcx>) -> Option<Q::Result>
318+
pub(crate) fn in_rvalue<Q, F>(
319+
cx: &ConstCx<'_, 'tcx>,
320+
in_local: &mut F,
321+
rvalue: &Rvalue<'tcx>,
322+
) -> Option<Q::Result>
287323
where
288324
Q: Qualif,
289325
F: FnMut(Local) -> Option<Q::Result>,
@@ -342,7 +378,11 @@ where
342378

343379
/// Returns `true` if this `Place` contains qualif `Q`.
344380
#[instrument(skip(cx, in_local), fields(Q=std::any::type_name::<Q>()))]
345-
pub(crate) fn in_place<Q, F>(cx: &ConstCx<'_, 'tcx>, in_local: &mut F, place: PlaceRef<'tcx>) -> Option<Q::Result>
381+
pub(crate) fn in_place<Q, F>(
382+
cx: &ConstCx<'_, 'tcx>,
383+
in_local: &mut F,
384+
place: PlaceRef<'tcx>,
385+
) -> Option<Q::Result>
346386
where
347387
Q: Qualif,
348388
F: FnMut(Local) -> Option<Q::Result>,
@@ -353,7 +393,7 @@ where
353393
match proj_elem {
354394
ProjectionElem::Index(index) => {
355395
result.join(&in_local(index));
356-
},
396+
}
357397

358398
ProjectionElem::Deref
359399
| ProjectionElem::Field(_, _)
@@ -378,7 +418,11 @@ where
378418

379419
/// Returns `true` if this `Operand` contains qualif `Q`.
380420
#[instrument(skip(cx, in_local), fields(Q=std::any::type_name::<Q>()))]
381-
pub(crate) fn in_operand<Q, F>(cx: &ConstCx<'_, 'tcx>, in_local: &mut F, operand: &Operand<'tcx>) -> Option<Q::Result>
421+
pub(crate) fn in_operand<Q, F>(
422+
cx: &ConstCx<'_, 'tcx>,
423+
in_local: &mut F,
424+
operand: &Operand<'tcx>,
425+
) -> Option<Q::Result>
382426
where
383427
Q: Qualif,
384428
F: FnMut(Local) -> Option<Q::Result>,

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

+6-15
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ use rustc_middle::mir::{self, BasicBlock, Location};
77

88
use std::marker::PhantomData;
99

10+
use super::qualifs::QualifsPerLocal;
1011
use super::{qualifs, ConstCx, Qualif};
1112
use crate::dataflow::{self, JoinSemiLattice};
12-
use super::qualifs::QualifsPerLocal;
1313

1414
/// A `Visitor` that propagates qualifs between locals. This defines the transfer function of
1515
/// `FlowSensitiveAnalysis`.
@@ -78,11 +78,8 @@ where
7878
// Though some qualifs merge the call arguments' qualifs into the result qualif.
7979
let mut args_qualif = None;
8080
for arg in args {
81-
let arg = qualifs::in_operand::<Q, _>(
82-
self.ccx,
83-
&mut |l| self.qualifs_per_local.get(l),
84-
arg,
85-
);
81+
let arg =
82+
qualifs::in_operand::<Q, _>(self.ccx, &mut |l| self.qualifs_per_local.get(l), arg);
8683
args_qualif.join(&arg);
8784
}
8885

@@ -120,11 +117,8 @@ where
120117
rvalue: &mir::Rvalue<'tcx>,
121118
location: Location,
122119
) {
123-
let qualif = qualifs::in_rvalue::<Q, _>(
124-
self.ccx,
125-
&mut |l| self.qualifs_per_local.get(l),
126-
rvalue,
127-
);
120+
let qualif =
121+
qualifs::in_rvalue::<Q, _>(self.ccx, &mut |l| self.qualifs_per_local.get(l), rvalue);
128122
if !place.is_indirect() {
129123
self.assign_qualif_direct(place, qualif);
130124
}
@@ -170,10 +164,7 @@ where
170164
FlowSensitiveAnalysis { ccx, _qualif: PhantomData }
171165
}
172166

173-
fn transfer_function(
174-
&self,
175-
state: &'a mut Q::Set,
176-
) -> TransferFunction<'a, 'mir, 'tcx, Q> {
167+
fn transfer_function(&self, state: &'a mut Q::Set) -> TransferFunction<'a, 'mir, 'tcx, Q> {
177168
TransferFunction::<Q>::new(self.ccx, state)
178169
}
179170
}

compiler/rustc_mir/src/transform/check_consts/validation.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ use std::mem;
2121
use std::ops::Deref;
2222

2323
use super::ops::{self, NonConstOp, Status};
24-
use super::qualifs::{self, CustomEq, HasMutInterior, NeedsDrop, QualifsPerLocal, HasMutInteriorBehindRef, HasMutInteriorBehindRefState};
24+
use super::qualifs::{
25+
self, CustomEq, HasMutInterior, HasMutInteriorBehindRef, HasMutInteriorBehindRefState,
26+
NeedsDrop, QualifsPerLocal,
27+
};
2528
use super::resolver::FlowSensitiveAnalysis;
2629
use super::{is_lang_panic_fn, ConstCx, Qualif};
2730
use crate::const_eval::is_unstable_const_fn;
2831
use crate::dataflow::impls::MaybeMutBorrowedLocals;
29-
use crate::dataflow::{self, Analysis, lattice::JoinSemiLattice};
32+
use crate::dataflow::{self, lattice::JoinSemiLattice, Analysis};
3033

3134
// We are using `MaybeMutBorrowedLocals` as a proxy for whether an item may have been mutated
3235
// through a pointer prior to the given point. This is okay even though `MaybeMutBorrowedLocals`
@@ -290,7 +293,9 @@ impl Validator<'mir, 'tcx> {
290293

291294
if let hir::ConstContext::Const = self.const_kind() {
292295
// Ensure that we do not produce references with interior mutability behind them
293-
if let Some(HasMutInteriorBehindRefState::Yes) = self.qualifs.return_place_has_mut_interior_behind_ref(self.ccx) {
296+
if let Some(HasMutInteriorBehindRefState::Yes) =
297+
self.qualifs.return_place_has_mut_interior_behind_ref(self.ccx)
298+
{
294299
// FIXME: Trace the source of the `Yes` in dataflow
295300
self.span = body.local_decls[RETURN_PLACE].source_info.span;
296301
self.check_op(ops::CellBorrow)

0 commit comments

Comments
 (0)