Skip to content

Commit 13a98d1

Browse files
committed
Change a few &Option<T> into Option<&T>
1 parent e93e096 commit 13a98d1

File tree

32 files changed

+141
-121
lines changed

32 files changed

+141
-121
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,
@@ -367,7 +367,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
367367
hir::ExprKind::Struct(
368368
self.arena.alloc(self.lower_qpath(
369369
e.id,
370-
&se.qself,
370+
se.qself.as_ref(),
371371
&se.path,
372372
ParamMode::Optional,
373373
AllowReturnTypeNotation::No,
@@ -1353,7 +1353,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13531353
);
13541354
let qpath = self.lower_qpath(
13551355
callee.id,
1356-
qself,
1356+
qself.as_ref(),
13571357
path,
13581358
ParamMode::Optional,
13591359
AllowReturnTypeNotation::No,
@@ -1374,7 +1374,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13741374
if let Some((qself, path)) = self.extract_unit_struct_path(lhs) {
13751375
let qpath = self.lower_qpath(
13761376
lhs.id,
1377-
qself,
1377+
qself.as_ref(),
13781378
path,
13791379
ParamMode::Optional,
13801380
AllowReturnTypeNotation::No,
@@ -1400,7 +1400,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14001400
}));
14011401
let qpath = self.lower_qpath(
14021402
lhs.id,
1403-
&se.qself,
1403+
se.qself.as_ref(),
14041404
&se.path,
14051405
ParamMode::Optional,
14061406
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
@@ -1119,7 +1119,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11191119
fn lower_path_ty(
11201120
&mut self,
11211121
t: &Ty,
1122-
qself: &Option<ptr::P<QSelf>>,
1122+
qself: Option<&ptr::P<QSelf>>,
11231123
path: &Path,
11241124
param_mode: ParamMode,
11251125
itctx: ImplTraitContext,
@@ -1238,7 +1238,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12381238
return self.lower_ty_direct(ty, itctx);
12391239
}
12401240
TyKind::Path(qself, path) => {
1241-
return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
1241+
return self.lower_path_ty(t, qself.as_ref(), path, ParamMode::Explicit, itctx);
12421242
}
12431243
TyKind::ImplicitSelf => {
12441244
let hir_id = self.next_id();
@@ -1898,7 +1898,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18981898
) -> hir::TraitRef<'hir> {
18991899
let path = match self.lower_qpath(
19001900
p.ref_id,
1901-
&None,
1901+
None,
19021902
&p.path,
19031903
ParamMode::Explicit,
19041904
AllowReturnTypeNotation::No,
@@ -2050,7 +2050,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20502050
{
20512051
let qpath = self.lower_qpath(
20522052
ty_id,
2053-
&None,
2053+
None,
20542054
path,
20552055
ParamMode::Optional,
20562056
AllowReturnTypeNotation::No,
@@ -2126,7 +2126,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21262126
{
21272127
let qpath = self.lower_qpath(
21282128
expr.id,
2129-
&None,
2129+
None,
21302130
path,
21312131
ParamMode::Optional,
21322132
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
}
@@ -1738,7 +1738,7 @@ impl<'a> State<'a> {
17381738
}
17391739
SelfKind::Region(lt, m) => {
17401740
self.word("&");
1741-
self.print_opt_lifetime(lt);
1741+
self.print_opt_lifetime(lt.as_ref());
17421742
self.print_mutability(*m, false);
17431743
self.word("self")
17441744
}

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

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

152152
fn print_expr_struct(
153153
&mut self,
154-
qself: &Option<P<ast::QSelf>>,
154+
qself: Option<&P<ast::QSelf>>,
155155
path: &ast::Path,
156156
fields: &[ast::ExprField],
157157
rest: &ast::StructRest,
@@ -388,7 +388,7 @@ impl<'a> State<'a> {
388388
self.print_expr_repeat(element, count);
389389
}
390390
ast::ExprKind::Struct(se) => {
391-
self.print_expr_struct(&se.qself, &se.path, &se.fields, &se.rest);
391+
self.print_expr_struct(se.qself.as_ref(), &se.path, &se.fields, &se.rest);
392392
}
393393
ast::ExprKind::Tup(exprs) => {
394394
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
@@ -2935,7 +2935,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
29352935
span,
29362936
..
29372937
},
2938-
) => self.report_escaping_data(borrow_span, &name, upvar_span, upvar_name, span),
2938+
) => self.report_escaping_data(
2939+
borrow_span,
2940+
name.as_deref(),
2941+
upvar_span,
2942+
upvar_name,
2943+
span,
2944+
),
29392945
(Some(name), explanation) => self.report_local_value_does_not_live_long_enough(
29402946
location,
29412947
&name,
@@ -2988,7 +2994,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
29882994
borrow_span,
29892995
span,
29902996
category,
2991-
opt_place_desc.as_ref(),
2997+
opt_place_desc.as_deref(),
29922998
) {
29932999
return diag;
29943000
}
@@ -3331,7 +3337,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
33313337
borrow_span: Span,
33323338
return_span: Span,
33333339
category: ConstraintCategory<'tcx>,
3334-
opt_place_desc: Option<&String>,
3340+
opt_place_desc: Option<&str>,
33353341
) -> Result<(), Diag<'infcx>> {
33363342
let return_kind = match category {
33373343
ConstraintCategory::Return(_) => "return",
@@ -3534,7 +3540,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
35343540
fn report_escaping_data(
35353541
&self,
35363542
borrow_span: Span,
3537-
name: &Option<String>,
3543+
name: Option<&str>,
35383544
upvar_span: Span,
35393545
upvar_name: Symbol,
35403546
escape_span: Span,

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,11 @@ 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(&infcx, body, &regioncx, opt_closure_req.as_ref(), &opaque_type_values, diags);
228228

229229
let movable_coroutine =
230230
// 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
}

Diff for: compiler/rustc_codegen_gcc/src/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
379379
gcc_func,
380380
args.into(),
381381
&func_name,
382-
original_function_name,
382+
original_function_name.map(String::as_str),
383383
)
384384
};
385385
let args_adjusted = args.len() != previous_arg_count;

0 commit comments

Comments
 (0)