Skip to content

Commit adbd7be

Browse files
committed
Change a few &Option<T> into Option<&T>
1 parent 7c002ff commit adbd7be

File tree

32 files changed

+146
-116
lines changed

32 files changed

+146
-116
lines changed

compiler/rustc_ast_lowering/src/asm.rs

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

compiler/rustc_ast_lowering/src/delegation.rs

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

compiler/rustc_ast_lowering/src/expr.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
318318
ExprKind::Path(qself, path) => {
319319
let qpath = self.lower_qpath(
320320
e.id,
321-
qself,
321+
qself.as_ref(),
322322
path,
323323
ParamMode::Optional,
324324
AllowReturnTypeNotation::No,
@@ -363,7 +363,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
363363
hir::ExprKind::Struct(
364364
self.arena.alloc(self.lower_qpath(
365365
e.id,
366-
&se.qself,
366+
se.qself.as_ref(),
367367
&se.path,
368368
ParamMode::Optional,
369369
AllowReturnTypeNotation::No,
@@ -1357,7 +1357,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13571357
);
13581358
let qpath = self.lower_qpath(
13591359
callee.id,
1360-
qself,
1360+
qself.as_ref(),
13611361
path,
13621362
ParamMode::Optional,
13631363
AllowReturnTypeNotation::No,
@@ -1378,7 +1378,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13781378
if let Some((qself, path)) = self.extract_unit_struct_path(lhs) {
13791379
let qpath = self.lower_qpath(
13801380
lhs.id,
1381-
qself,
1381+
qself.as_ref(),
13821382
path,
13831383
ParamMode::Optional,
13841384
AllowReturnTypeNotation::No,
@@ -1404,7 +1404,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
14041404
}));
14051405
let qpath = self.lower_qpath(
14061406
lhs.id,
1407-
&se.qself,
1407+
se.qself.as_ref(),
14081408
&se.path,
14091409
ParamMode::Optional,
14101410
AllowReturnTypeNotation::No,

compiler/rustc_ast_lowering/src/format.rs

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

compiler/rustc_ast_lowering/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11291129
fn lower_path_ty(
11301130
&mut self,
11311131
t: &Ty,
1132-
qself: &Option<ptr::P<QSelf>>,
1132+
qself: Option<&ptr::P<QSelf>>,
11331133
path: &Path,
11341134
param_mode: ParamMode,
11351135
itctx: ImplTraitContext,
@@ -1255,7 +1255,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12551255
return self.lower_ty_direct(ty, itctx);
12561256
}
12571257
TyKind::Path(qself, path) => {
1258-
return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
1258+
return self.lower_path_ty(t, qself.as_ref(), path, ParamMode::Explicit, itctx);
12591259
}
12601260
TyKind::ImplicitSelf => {
12611261
let hir_id = self.next_id();
@@ -1919,7 +1919,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19191919
) -> hir::TraitRef<'hir> {
19201920
let path = match self.lower_qpath(
19211921
p.ref_id,
1922-
&None,
1922+
None,
19231923
&p.path,
19241924
ParamMode::Explicit,
19251925
AllowReturnTypeNotation::No,
@@ -2070,7 +2070,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20702070
{
20712071
let qpath = self.lower_qpath(
20722072
ty_id,
2073-
&None,
2073+
None,
20742074
path,
20752075
ParamMode::Optional,
20762076
AllowReturnTypeNotation::No,
@@ -2146,7 +2146,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21462146
{
21472147
let qpath = self.lower_qpath(
21482148
expr.id,
2149-
&None,
2149+
None,
21502150
path,
21512151
ParamMode::Optional,
21522152
AllowReturnTypeNotation::No,

compiler/rustc_ast_lowering/src/pat.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
4141
PatKind::TupleStruct(qself, path, pats) => {
4242
let qpath = self.lower_qpath(
4343
pattern.id,
44-
qself,
44+
qself.as_ref(),
4545
path,
4646
ParamMode::Optional,
4747
AllowReturnTypeNotation::No,
@@ -59,7 +59,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
5959
PatKind::Path(qself, path) => {
6060
let qpath = self.lower_qpath(
6161
pattern.id,
62-
qself,
62+
qself.as_ref(),
6363
path,
6464
ParamMode::Optional,
6565
AllowReturnTypeNotation::No,
@@ -71,7 +71,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
7171
PatKind::Struct(qself, path, fields, etc) => {
7272
let qpath = self.lower_qpath(
7373
pattern.id,
74-
qself,
74+
qself.as_ref(),
7575
path,
7676
ParamMode::Optional,
7777
AllowReturnTypeNotation::No,

compiler/rustc_ast_lowering/src/path.rs

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

compiler/rustc_ast_pretty/src/pprust/state.rs

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

1113-
pub fn print_opt_lifetime(&mut self, lifetime: &Option<ast::Lifetime>) {
1114-
if let Some(lt) = *lifetime {
1115-
self.print_lifetime(lt);
1113+
pub fn print_opt_lifetime(&mut self, lifetime: Option<&ast::Lifetime>) {
1114+
if let Some(lt) = lifetime {
1115+
self.print_lifetime(*lt);
11161116
self.nbsp();
11171117
}
11181118
}
@@ -1163,12 +1163,12 @@ impl<'a> State<'a> {
11631163
}
11641164
ast::TyKind::Ref(lifetime, mt) => {
11651165
self.word("&");
1166-
self.print_opt_lifetime(lifetime);
1166+
self.print_opt_lifetime(lifetime.as_ref());
11671167
self.print_mt(mt, false);
11681168
}
11691169
ast::TyKind::PinnedRef(lifetime, mt) => {
11701170
self.word("&");
1171-
self.print_opt_lifetime(lifetime);
1171+
self.print_opt_lifetime(lifetime.as_ref());
11721172
self.word("pin ");
11731173
self.print_mt(mt, true);
11741174
}
@@ -1752,7 +1752,7 @@ impl<'a> State<'a> {
17521752
}
17531753
SelfKind::Region(lt, m) => {
17541754
self.word("&");
1755-
self.print_opt_lifetime(lt);
1755+
self.print_opt_lifetime(lt.as_ref());
17561756
self.print_mutability(*m, false);
17571757
self.word("self")
17581758
}

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);

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("");

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -2939,7 +2939,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
29392939
span,
29402940
..
29412941
},
2942-
) => self.report_escaping_data(borrow_span, &name, upvar_span, upvar_name, span),
2942+
) => self.report_escaping_data(
2943+
borrow_span,
2944+
name.as_deref(),
2945+
upvar_span,
2946+
upvar_name,
2947+
span,
2948+
),
29432949
(Some(name), explanation) => self.report_local_value_does_not_live_long_enough(
29442950
location,
29452951
&name,
@@ -2992,7 +2998,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
29922998
borrow_span,
29932999
span,
29943000
category,
2995-
opt_place_desc.as_ref(),
3001+
opt_place_desc.as_deref(),
29963002
) {
29973003
return diag;
29983004
}
@@ -3335,7 +3341,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
33353341
borrow_span: Span,
33363342
return_span: Span,
33373343
category: ConstraintCategory<'tcx>,
3338-
opt_place_desc: Option<&String>,
3344+
opt_place_desc: Option<&str>,
33393345
) -> Result<(), Diag<'infcx>> {
33403346
let return_kind = match category {
33413347
ConstraintCategory::Return(_) => "return",
@@ -3538,7 +3544,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
35383544
fn report_escaping_data(
35393545
&self,
35403546
borrow_span: Span,
3541-
name: &Option<String>,
3547+
name: Option<&str>,
35423548
upvar_span: Span,
35433549
upvar_name: Symbol,
35443550
escape_span: Span,

compiler/rustc_borrowck/src/lib.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,19 @@ fn do_mir_borrowck<'tcx>(
217217

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

222222
// We also have a `#[rustc_regions]` annotation that causes us to dump
223223
// information.
224224
let diags = &mut diags::BorrowckDiags::new();
225-
nll::dump_annotation(&infcx, body, &regioncx, &opt_closure_req, &opaque_type_values, diags);
225+
nll::dump_annotation(
226+
&infcx,
227+
body,
228+
&regioncx,
229+
opt_closure_req.as_ref(),
230+
&opaque_type_values,
231+
diags,
232+
);
226233

227234
let movable_coroutine =
228235
// The first argument is the coroutine type passed by value

compiler/rustc_borrowck/src/nll.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ pub(super) fn dump_nll_mir<'tcx>(
205205
infcx: &BorrowckInferCtxt<'tcx>,
206206
body: &Body<'tcx>,
207207
regioncx: &RegionInferenceContext<'tcx>,
208-
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
208+
closure_region_requirements: Option<&ClosureRegionRequirements<'tcx>>,
209209
borrow_set: &BorrowSet<'tcx>,
210210
) {
211211
let tcx = infcx.tcx;
@@ -251,7 +251,7 @@ pub(super) fn dump_nll_mir<'tcx>(
251251
pub(crate) fn emit_nll_mir<'tcx>(
252252
tcx: TyCtxt<'tcx>,
253253
regioncx: &RegionInferenceContext<'tcx>,
254-
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
254+
closure_region_requirements: Option<&ClosureRegionRequirements<'tcx>>,
255255
borrow_set: &BorrowSet<'tcx>,
256256
pass_where: PassWhere,
257257
out: &mut dyn io::Write,
@@ -298,7 +298,7 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
298298
infcx: &'infcx BorrowckInferCtxt<'tcx>,
299299
body: &Body<'tcx>,
300300
regioncx: &RegionInferenceContext<'tcx>,
301-
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
301+
closure_region_requirements: Option<&ClosureRegionRequirements<'tcx>>,
302302
opaque_type_values: &FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>,
303303
diags: &mut crate::diags::BorrowckDiags<'infcx, 'tcx>,
304304
) {

compiler/rustc_borrowck/src/polonius/dump.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn emit_polonius_mir<'tcx>(
7474
crate::nll::emit_nll_mir(
7575
tcx,
7676
regioncx,
77-
closure_region_requirements,
77+
closure_region_requirements.as_ref(),
7878
borrow_set,
7979
pass_where.clone(),
8080
out,

0 commit comments

Comments
 (0)