Skip to content

Commit 2fa76df

Browse files
committed
Change a few &Option<T> into Option<&T>
1 parent 974ccc1 commit 2fa76df

File tree

31 files changed

+144
-114
lines changed

31 files changed

+144
-114
lines changed

Diff for: compiler/rustc_ast_lowering/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
207207
if let Some(def_id) = static_def_id {
208208
let path = self.lower_qpath(
209209
sym.id,
210-
&sym.qself,
210+
sym.qself.as_ref(),
211211
&sym.path,
212212
ParamMode::Optional,
213213
AllowReturnTypeNotation::No,

Diff for: compiler/rustc_ast_lowering/src/delegation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
338338
} else {
339339
let path = self.lower_qpath(
340340
delegation.id,
341-
&delegation.qself,
341+
delegation.qself.as_ref(),
342342
&delegation.path,
343343
ParamMode::Optional,
344344
AllowReturnTypeNotation::No,

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
319319
ExprKind::Path(qself, path) => {
320320
let qpath = self.lower_qpath(
321321
e.id,
322-
qself,
322+
qself.as_ref(),
323323
path,
324324
ParamMode::Optional,
325325
AllowReturnTypeNotation::No,
@@ -364,7 +364,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
364364
hir::ExprKind::Struct(
365365
self.arena.alloc(self.lower_qpath(
366366
e.id,
367-
&se.qself,
367+
se.qself.as_ref(),
368368
&se.path,
369369
ParamMode::Optional,
370370
AllowReturnTypeNotation::No,
@@ -1350,7 +1350,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13501350
);
13511351
let qpath = self.lower_qpath(
13521352
callee.id,
1353-
qself,
1353+
qself.as_ref(),
13541354
path,
13551355
ParamMode::Optional,
13561356
AllowReturnTypeNotation::No,
@@ -1371,7 +1371,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13711371
if let Some((qself, path)) = self.extract_unit_struct_path(lhs) {
13721372
let qpath = self.lower_qpath(
13731373
lhs.id,
1374-
qself,
1374+
qself.as_ref(),
13751375
path,
13761376
ParamMode::Optional,
13771377
AllowReturnTypeNotation::No,
@@ -1397,7 +1397,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13971397
}));
13981398
let qpath = self.lower_qpath(
13991399
lhs.id,
1400-
&se.qself,
1400+
se.qself.as_ref(),
14011401
&se.path,
14021402
ParamMode::Optional,
14031403
AllowReturnTypeNotation::No,

Diff for: compiler/rustc_ast_lowering/src/format.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ fn make_argument<'hir>(
283283
fn make_count<'hir>(
284284
ctx: &mut LoweringContext<'_, 'hir>,
285285
sp: Span,
286-
count: &Option<FormatCount>,
286+
count: Option<&FormatCount>,
287287
argmap: &mut FxIndexMap<(usize, ArgumentType), Option<Span>>,
288288
) -> hir::Expr<'hir> {
289289
match count {
@@ -378,8 +378,8 @@ fn make_format_spec<'hir>(
378378
| ((debug_hex == Some(FormatDebugHex::Lower)) as u32) << 4
379379
| ((debug_hex == Some(FormatDebugHex::Upper)) as u32) << 5;
380380
let flags = ctx.expr_u32(sp, flags);
381-
let precision = make_count(ctx, sp, precision, argmap);
382-
let width = make_count(ctx, sp, width, argmap);
381+
let precision = make_count(ctx, sp, precision.as_ref(), argmap);
382+
let width = make_count(ctx, sp, width.as_ref(), argmap);
383383
let format_placeholder_new = ctx.arena.alloc(ctx.expr_lang_item_type_relative(
384384
sp,
385385
hir::LangItem::FormatPlaceholder,

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11171117
fn lower_path_ty(
11181118
&mut self,
11191119
t: &Ty,
1120-
qself: &Option<ptr::P<QSelf>>,
1120+
qself: Option<&ptr::P<QSelf>>,
11211121
path: &Path,
11221122
param_mode: ParamMode,
11231123
itctx: ImplTraitContext,
@@ -1236,7 +1236,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12361236
return self.lower_ty_direct(ty, itctx);
12371237
}
12381238
TyKind::Path(qself, path) => {
1239-
return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
1239+
return self.lower_path_ty(t, qself.as_ref(), path, ParamMode::Explicit, itctx);
12401240
}
12411241
TyKind::ImplicitSelf => {
12421242
let hir_id = self.next_id();
@@ -1897,7 +1897,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18971897
) -> hir::TraitRef<'hir> {
18981898
let path = match self.lower_qpath(
18991899
p.ref_id,
1900-
&None,
1900+
None,
19011901
&p.path,
19021902
ParamMode::Explicit,
19031903
AllowReturnTypeNotation::No,
@@ -2048,7 +2048,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20482048
{
20492049
let qpath = self.lower_qpath(
20502050
ty_id,
2051-
&None,
2051+
None,
20522052
path,
20532053
ParamMode::Optional,
20542054
AllowReturnTypeNotation::No,
@@ -2124,7 +2124,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21242124
{
21252125
let qpath = self.lower_qpath(
21262126
expr.id,
2127-
&None,
2127+
None,
21282128
path,
21292129
ParamMode::Optional,
21302130
AllowReturnTypeNotation::No,

Diff for: compiler/rustc_ast_lowering/src/pat.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
4242
PatKind::TupleStruct(qself, path, pats) => {
4343
let qpath = self.lower_qpath(
4444
pattern.id,
45-
qself,
45+
qself.as_ref(),
4646
path,
4747
ParamMode::Optional,
4848
AllowReturnTypeNotation::No,
@@ -60,7 +60,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
6060
PatKind::Path(qself, path) => {
6161
let qpath = self.lower_qpath(
6262
pattern.id,
63-
qself,
63+
qself.as_ref(),
6464
path,
6565
ParamMode::Optional,
6666
AllowReturnTypeNotation::No,
@@ -72,7 +72,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
7272
PatKind::Struct(qself, path, fields, etc) => {
7373
let qpath = self.lower_qpath(
7474
pattern.id,
75-
qself,
75+
qself.as_ref(),
7676
path,
7777
ParamMode::Optional,
7878
AllowReturnTypeNotation::No,

Diff for: compiler/rustc_ast_lowering/src/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2525
pub(crate) fn lower_qpath(
2626
&mut self,
2727
id: NodeId,
28-
qself: &Option<ptr::P<QSelf>>,
28+
qself: Option<&ptr::P<QSelf>>,
2929
p: &Path,
3030
param_mode: ParamMode,
3131
allow_return_type_notation: AllowReturnTypeNotation,

Diff for: compiler/rustc_ast_pretty/src/pprust/state.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1117,9 +1117,9 @@ impl<'a> State<'a> {
11171117
self.commasep_cmnt(b, exprs, |s, e| s.print_expr(e, FixupContext::default()), |e| e.span)
11181118
}
11191119

1120-
pub fn print_opt_lifetime(&mut self, lifetime: &Option<ast::Lifetime>) {
1121-
if let Some(lt) = *lifetime {
1122-
self.print_lifetime(lt);
1120+
pub fn print_opt_lifetime(&mut self, lifetime: Option<&ast::Lifetime>) {
1121+
if let Some(lt) = lifetime {
1122+
self.print_lifetime(*lt);
11231123
self.nbsp();
11241124
}
11251125
}
@@ -1170,12 +1170,12 @@ impl<'a> State<'a> {
11701170
}
11711171
ast::TyKind::Ref(lifetime, mt) => {
11721172
self.word("&");
1173-
self.print_opt_lifetime(lifetime);
1173+
self.print_opt_lifetime(lifetime.as_ref());
11741174
self.print_mt(mt, false);
11751175
}
11761176
ast::TyKind::PinnedRef(lifetime, mt) => {
11771177
self.word("&");
1178-
self.print_opt_lifetime(lifetime);
1178+
self.print_opt_lifetime(lifetime.as_ref());
11791179
self.word("pin ");
11801180
self.print_mt(mt, true);
11811181
}
@@ -1746,7 +1746,7 @@ impl<'a> State<'a> {
17461746
}
17471747
SelfKind::Region(lt, m) => {
17481748
self.word("&");
1749-
self.print_opt_lifetime(lt);
1749+
self.print_opt_lifetime(lt.as_ref());
17501750
self.print_mutability(*m, false);
17511751
self.word("self")
17521752
}

Diff for: compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'a> State<'a> {
147147

148148
fn print_expr_struct(
149149
&mut self,
150-
qself: &Option<P<ast::QSelf>>,
150+
qself: Option<&P<ast::QSelf>>,
151151
path: &ast::Path,
152152
fields: &[ast::ExprField],
153153
rest: &ast::StructRest,
@@ -395,7 +395,7 @@ impl<'a> State<'a> {
395395
self.print_expr_repeat(element, count);
396396
}
397397
ast::ExprKind::Struct(se) => {
398-
self.print_expr_struct(&se.qself, &se.path, &se.fields, &se.rest);
398+
self.print_expr_struct(se.qself.as_ref(), &se.path, &se.fields, &se.rest);
399399
}
400400
ast::ExprKind::Tup(exprs) => {
401401
self.print_expr_tup(exprs);

Diff for: compiler/rustc_ast_pretty/src/pprust/state/item.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -390,18 +390,18 @@ impl<'a> State<'a> {
390390
ast::ItemKind::Delegation(deleg) => self.print_delegation(
391391
&item.attrs,
392392
&item.vis,
393-
&deleg.qself,
393+
deleg.qself.as_ref(),
394394
&deleg.path,
395395
DelegationKind::Single,
396-
&deleg.body,
396+
deleg.body.as_ref(),
397397
),
398398
ast::ItemKind::DelegationMac(deleg) => self.print_delegation(
399399
&item.attrs,
400400
&item.vis,
401-
&deleg.qself,
401+
deleg.qself.as_ref(),
402402
&deleg.prefix,
403403
deleg.suffixes.as_ref().map_or(DelegationKind::Glob, |s| DelegationKind::List(s)),
404-
&deleg.body,
404+
deleg.body.as_ref(),
405405
),
406406
}
407407
self.ann.post(self, AnnNode::Item(item))
@@ -583,18 +583,18 @@ impl<'a> State<'a> {
583583
ast::AssocItemKind::Delegation(deleg) => self.print_delegation(
584584
&item.attrs,
585585
vis,
586-
&deleg.qself,
586+
deleg.qself.as_ref(),
587587
&deleg.path,
588588
DelegationKind::Single,
589-
&deleg.body,
589+
deleg.body.as_ref(),
590590
),
591591
ast::AssocItemKind::DelegationMac(deleg) => self.print_delegation(
592592
&item.attrs,
593593
vis,
594-
&deleg.qself,
594+
deleg.qself.as_ref(),
595595
&deleg.prefix,
596596
deleg.suffixes.as_ref().map_or(DelegationKind::Glob, |s| DelegationKind::List(s)),
597-
&deleg.body,
597+
deleg.body.as_ref(),
598598
),
599599
}
600600
self.ann.post(self, AnnNode::SubItem(id))
@@ -604,10 +604,10 @@ impl<'a> State<'a> {
604604
&mut self,
605605
attrs: &[ast::Attribute],
606606
vis: &ast::Visibility,
607-
qself: &Option<P<ast::QSelf>>,
607+
qself: Option<&P<ast::QSelf>>,
608608
path: &ast::Path,
609609
kind: DelegationKind<'_>,
610-
body: &Option<P<ast::Block>>,
610+
body: Option<&P<ast::Block>>,
611611
) {
612612
if body.is_some() {
613613
self.head("");

Diff for: compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -2940,7 +2940,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
29402940
span,
29412941
..
29422942
},
2943-
) => self.report_escaping_data(borrow_span, &name, upvar_span, upvar_name, span),
2943+
) => self.report_escaping_data(
2944+
borrow_span,
2945+
name.as_deref(),
2946+
upvar_span,
2947+
upvar_name,
2948+
span,
2949+
),
29442950
(Some(name), explanation) => self.report_local_value_does_not_live_long_enough(
29452951
location,
29462952
&name,
@@ -2993,7 +2999,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
29932999
borrow_span,
29943000
span,
29953001
category,
2996-
opt_place_desc.as_ref(),
3002+
opt_place_desc.as_deref(),
29973003
) {
29983004
return diag;
29993005
}
@@ -3336,7 +3342,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
33363342
borrow_span: Span,
33373343
return_span: Span,
33383344
category: ConstraintCategory<'tcx>,
3339-
opt_place_desc: Option<&String>,
3345+
opt_place_desc: Option<&str>,
33403346
) -> Result<(), Diag<'infcx>> {
33413347
let return_kind = match category {
33423348
ConstraintCategory::Return(_) => "return",
@@ -3539,7 +3545,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
35393545
fn report_escaping_data(
35403546
&self,
35413547
borrow_span: Span,
3542-
name: &Option<String>,
3548+
name: Option<&str>,
35433549
upvar_span: Span,
35443550
upvar_name: Symbol,
35453551
escape_span: Span,

Diff for: compiler/rustc_borrowck/src/lib.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,18 @@ fn do_mir_borrowck<'tcx>(
220220

221221
// Dump MIR results into a file, if that is enabled. This let us
222222
// write unit-tests, as well as helping with debugging.
223-
nll::dump_nll_mir(&infcx, body, &regioncx, &opt_closure_req, &borrow_set);
223+
nll::dump_nll_mir(&infcx, body, &regioncx, opt_closure_req.as_ref(), &borrow_set);
224224

225225
// We also have a `#[rustc_regions]` annotation that causes us to dump
226226
// information.
227-
nll::dump_annotation(&infcx, body, &regioncx, &opt_closure_req, &opaque_type_values, diags);
227+
nll::dump_annotation(
228+
&infcx,
229+
body,
230+
&regioncx,
231+
opt_closure_req.as_ref(),
232+
&opaque_type_values,
233+
diags,
234+
);
228235

229236
let movable_coroutine =
230237
// The first argument is the coroutine type passed by value

Diff for: compiler/rustc_borrowck/src/nll.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub(super) fn dump_nll_mir<'tcx>(
190190
infcx: &BorrowckInferCtxt<'tcx>,
191191
body: &Body<'tcx>,
192192
regioncx: &RegionInferenceContext<'tcx>,
193-
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
193+
closure_region_requirements: Option<&ClosureRegionRequirements<'tcx>>,
194194
borrow_set: &BorrowSet<'tcx>,
195195
) {
196196
let tcx = infcx.tcx;
@@ -271,7 +271,7 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
271271
infcx: &'infcx BorrowckInferCtxt<'tcx>,
272272
body: &Body<'tcx>,
273273
regioncx: &RegionInferenceContext<'tcx>,
274-
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
274+
closure_region_requirements: Option<&ClosureRegionRequirements<'tcx>>,
275275
opaque_type_values: &FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>,
276276
diags: &mut crate::diags::BorrowckDiags<'infcx, 'tcx>,
277277
) {

Diff for: compiler/rustc_codegen_gcc/build_system/src/utils.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ fn exec_command(
2121
) -> Result<ExitStatus, String> {
2222
let status = get_command_inner(input, cwd, env)
2323
.spawn()
24-
.map_err(|e| command_error(input, &cwd, e))?
24+
.map_err(|e| command_error(input, cwd, e))?
2525
.wait()
26-
.map_err(|e| command_error(input, &cwd, e))?;
26+
.map_err(|e| command_error(input, cwd, e))?;
2727
#[cfg(unix)]
2828
{
2929
if let Some(signal) = status.signal() {
3030
unsafe {
3131
raise(signal as _);
3232
}
3333
// In case the signal didn't kill the current process.
34-
return Err(command_error(input, &cwd, format!("Process received signal {}", signal)));
34+
return Err(command_error(input, cwd, format!("Process received signal {}", signal)));
3535
}
3636
}
3737
Ok(status)
@@ -92,7 +92,7 @@ fn check_exit_status(
9292
Err(error)
9393
}
9494

95-
fn command_error<D: Debug>(input: &[&dyn AsRef<OsStr>], cwd: &Option<&Path>, error: D) -> String {
95+
fn command_error<D: Debug>(input: &[&dyn AsRef<OsStr>], cwd: Option<&Path>, error: D) -> String {
9696
format!(
9797
"Command `{}`{} failed to run: {error:?}",
9898
input.iter().map(|s| s.as_ref().to_str().unwrap()).collect::<Vec<_>>().join(" "),
@@ -112,7 +112,7 @@ pub fn run_command_with_env(
112112
env: Option<&HashMap<String, String>>,
113113
) -> Result<Output, String> {
114114
let output =
115-
get_command_inner(input, cwd, env).output().map_err(|e| command_error(input, &cwd, e))?;
115+
get_command_inner(input, cwd, env).output().map_err(|e| command_error(input, cwd, e))?;
116116
check_exit_status(input, cwd, output.status, Some(&output), true)?;
117117
Ok(output)
118118
}

0 commit comments

Comments
 (0)