Skip to content

Commit

Permalink
Change a few &Option<T> into Option<&T>
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed Dec 26, 2024
1 parent 7c002ff commit adbd7be
Show file tree
Hide file tree
Showing 32 changed files with 146 additions and 116 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
if let Some(def_id) = static_def_id {
let path = self.lower_qpath(
sym.id,
&sym.qself,
sym.qself.as_ref(),
&sym.path,
ParamMode::Optional,
AllowReturnTypeNotation::No,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
} else {
let path = self.lower_qpath(
delegation.id,
&delegation.qself,
delegation.qself.as_ref(),
&delegation.path,
ParamMode::Optional,
AllowReturnTypeNotation::No,
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ExprKind::Path(qself, path) => {
let qpath = self.lower_qpath(
e.id,
qself,
qself.as_ref(),
path,
ParamMode::Optional,
AllowReturnTypeNotation::No,
Expand Down Expand Up @@ -363,7 +363,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::ExprKind::Struct(
self.arena.alloc(self.lower_qpath(
e.id,
&se.qself,
se.qself.as_ref(),
&se.path,
ParamMode::Optional,
AllowReturnTypeNotation::No,
Expand Down Expand Up @@ -1357,7 +1357,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
);
let qpath = self.lower_qpath(
callee.id,
qself,
qself.as_ref(),
path,
ParamMode::Optional,
AllowReturnTypeNotation::No,
Expand All @@ -1378,7 +1378,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
if let Some((qself, path)) = self.extract_unit_struct_path(lhs) {
let qpath = self.lower_qpath(
lhs.id,
qself,
qself.as_ref(),
path,
ParamMode::Optional,
AllowReturnTypeNotation::No,
Expand All @@ -1404,7 +1404,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}));
let qpath = self.lower_qpath(
lhs.id,
&se.qself,
se.qself.as_ref(),
&se.path,
ParamMode::Optional,
AllowReturnTypeNotation::No,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast_lowering/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ fn make_argument<'hir>(
fn make_count<'hir>(
ctx: &mut LoweringContext<'_, 'hir>,
sp: Span,
count: &Option<FormatCount>,
count: Option<&FormatCount>,
argmap: &mut FxIndexMap<(usize, ArgumentType), Option<Span>>,
) -> hir::Expr<'hir> {
match count {
Expand Down Expand Up @@ -377,8 +377,8 @@ fn make_format_spec<'hir>(
| ((debug_hex == Some(FormatDebugHex::Lower)) as u32) << 4
| ((debug_hex == Some(FormatDebugHex::Upper)) as u32) << 5;
let flags = ctx.expr_u32(sp, flags);
let precision = make_count(ctx, sp, precision, argmap);
let width = make_count(ctx, sp, width, argmap);
let precision = make_count(ctx, sp, precision.as_ref(), argmap);
let width = make_count(ctx, sp, width.as_ref(), argmap);
let format_placeholder_new = ctx.arena.alloc(ctx.expr_lang_item_type_relative(
sp,
hir::LangItem::FormatPlaceholder,
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_path_ty(
&mut self,
t: &Ty,
qself: &Option<ptr::P<QSelf>>,
qself: Option<&ptr::P<QSelf>>,
path: &Path,
param_mode: ParamMode,
itctx: ImplTraitContext,
Expand Down Expand Up @@ -1255,7 +1255,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
return self.lower_ty_direct(ty, itctx);
}
TyKind::Path(qself, path) => {
return self.lower_path_ty(t, qself, path, ParamMode::Explicit, itctx);
return self.lower_path_ty(t, qself.as_ref(), path, ParamMode::Explicit, itctx);
}
TyKind::ImplicitSelf => {
let hir_id = self.next_id();
Expand Down Expand Up @@ -1919,7 +1919,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
) -> hir::TraitRef<'hir> {
let path = match self.lower_qpath(
p.ref_id,
&None,
None,
&p.path,
ParamMode::Explicit,
AllowReturnTypeNotation::No,
Expand Down Expand Up @@ -2070,7 +2070,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
{
let qpath = self.lower_qpath(
ty_id,
&None,
None,
path,
ParamMode::Optional,
AllowReturnTypeNotation::No,
Expand Down Expand Up @@ -2146,7 +2146,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
{
let qpath = self.lower_qpath(
expr.id,
&None,
None,
path,
ParamMode::Optional,
AllowReturnTypeNotation::No,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_ast_lowering/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
PatKind::TupleStruct(qself, path, pats) => {
let qpath = self.lower_qpath(
pattern.id,
qself,
qself.as_ref(),
path,
ParamMode::Optional,
AllowReturnTypeNotation::No,
Expand All @@ -59,7 +59,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
PatKind::Path(qself, path) => {
let qpath = self.lower_qpath(
pattern.id,
qself,
qself.as_ref(),
path,
ParamMode::Optional,
AllowReturnTypeNotation::No,
Expand All @@ -71,7 +71,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
PatKind::Struct(qself, path, fields, etc) => {
let qpath = self.lower_qpath(
pattern.id,
qself,
qself.as_ref(),
path,
ParamMode::Optional,
AllowReturnTypeNotation::No,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
pub(crate) fn lower_qpath(
&mut self,
id: NodeId,
qself: &Option<ptr::P<QSelf>>,
qself: Option<&ptr::P<QSelf>>,
p: &Path,
param_mode: ParamMode,
allow_return_type_notation: AllowReturnTypeNotation,
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,9 +1110,9 @@ impl<'a> State<'a> {
self.commasep_cmnt(b, exprs, |s, e| s.print_expr(e, FixupContext::default()), |e| e.span)
}

pub fn print_opt_lifetime(&mut self, lifetime: &Option<ast::Lifetime>) {
if let Some(lt) = *lifetime {
self.print_lifetime(lt);
pub fn print_opt_lifetime(&mut self, lifetime: Option<&ast::Lifetime>) {
if let Some(lt) = lifetime {
self.print_lifetime(*lt);
self.nbsp();
}
}
Expand Down Expand Up @@ -1163,12 +1163,12 @@ impl<'a> State<'a> {
}
ast::TyKind::Ref(lifetime, mt) => {
self.word("&");
self.print_opt_lifetime(lifetime);
self.print_opt_lifetime(lifetime.as_ref());
self.print_mt(mt, false);
}
ast::TyKind::PinnedRef(lifetime, mt) => {
self.word("&");
self.print_opt_lifetime(lifetime);
self.print_opt_lifetime(lifetime.as_ref());
self.word("pin ");
self.print_mt(mt, true);
}
Expand Down Expand Up @@ -1752,7 +1752,7 @@ impl<'a> State<'a> {
}
SelfKind::Region(lt, m) => {
self.word("&");
self.print_opt_lifetime(lt);
self.print_opt_lifetime(lt.as_ref());
self.print_mutability(*m, false);
self.word("self")
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<'a> State<'a> {

fn print_expr_struct(
&mut self,
qself: &Option<P<ast::QSelf>>,
qself: Option<&P<ast::QSelf>>,
path: &ast::Path,
fields: &[ast::ExprField],
rest: &ast::StructRest,
Expand Down Expand Up @@ -395,7 +395,7 @@ impl<'a> State<'a> {
self.print_expr_repeat(element, count);
}
ast::ExprKind::Struct(se) => {
self.print_expr_struct(&se.qself, &se.path, &se.fields, &se.rest);
self.print_expr_struct(se.qself.as_ref(), &se.path, &se.fields, &se.rest);
}
ast::ExprKind::Tup(exprs) => {
self.print_expr_tup(exprs);
Expand Down
20 changes: 10 additions & 10 deletions compiler/rustc_ast_pretty/src/pprust/state/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,18 +390,18 @@ impl<'a> State<'a> {
ast::ItemKind::Delegation(deleg) => self.print_delegation(
&item.attrs,
&item.vis,
&deleg.qself,
deleg.qself.as_ref(),
&deleg.path,
DelegationKind::Single,
&deleg.body,
deleg.body.as_ref(),
),
ast::ItemKind::DelegationMac(deleg) => self.print_delegation(
&item.attrs,
&item.vis,
&deleg.qself,
deleg.qself.as_ref(),
&deleg.prefix,
deleg.suffixes.as_ref().map_or(DelegationKind::Glob, |s| DelegationKind::List(s)),
&deleg.body,
deleg.body.as_ref(),
),
}
self.ann.post(self, AnnNode::Item(item))
Expand Down Expand Up @@ -583,18 +583,18 @@ impl<'a> State<'a> {
ast::AssocItemKind::Delegation(deleg) => self.print_delegation(
&item.attrs,
vis,
&deleg.qself,
deleg.qself.as_ref(),
&deleg.path,
DelegationKind::Single,
&deleg.body,
deleg.body.as_ref(),
),
ast::AssocItemKind::DelegationMac(deleg) => self.print_delegation(
&item.attrs,
vis,
&deleg.qself,
deleg.qself.as_ref(),
&deleg.prefix,
deleg.suffixes.as_ref().map_or(DelegationKind::Glob, |s| DelegationKind::List(s)),
&deleg.body,
deleg.body.as_ref(),
),
}
self.ann.post(self, AnnNode::SubItem(id))
Expand All @@ -604,10 +604,10 @@ impl<'a> State<'a> {
&mut self,
attrs: &[ast::Attribute],
vis: &ast::Visibility,
qself: &Option<P<ast::QSelf>>,
qself: Option<&P<ast::QSelf>>,
path: &ast::Path,
kind: DelegationKind<'_>,
body: &Option<P<ast::Block>>,
body: Option<&P<ast::Block>>,
) {
if body.is_some() {
self.head("");
Expand Down
14 changes: 10 additions & 4 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2939,7 +2939,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
span,
..
},
) => self.report_escaping_data(borrow_span, &name, upvar_span, upvar_name, span),
) => self.report_escaping_data(
borrow_span,
name.as_deref(),
upvar_span,
upvar_name,
span,
),
(Some(name), explanation) => self.report_local_value_does_not_live_long_enough(
location,
&name,
Expand Down Expand Up @@ -2992,7 +2998,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
borrow_span,
span,
category,
opt_place_desc.as_ref(),
opt_place_desc.as_deref(),
) {
return diag;
}
Expand Down Expand Up @@ -3335,7 +3341,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
borrow_span: Span,
return_span: Span,
category: ConstraintCategory<'tcx>,
opt_place_desc: Option<&String>,
opt_place_desc: Option<&str>,
) -> Result<(), Diag<'infcx>> {
let return_kind = match category {
ConstraintCategory::Return(_) => "return",
Expand Down Expand Up @@ -3538,7 +3544,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
fn report_escaping_data(
&self,
borrow_span: Span,
name: &Option<String>,
name: Option<&str>,
upvar_span: Span,
upvar_name: Symbol,
escape_span: Span,
Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,19 @@ fn do_mir_borrowck<'tcx>(

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

// We also have a `#[rustc_regions]` annotation that causes us to dump
// information.
let diags = &mut diags::BorrowckDiags::new();
nll::dump_annotation(&infcx, body, &regioncx, &opt_closure_req, &opaque_type_values, diags);
nll::dump_annotation(
&infcx,
body,
&regioncx,
opt_closure_req.as_ref(),
&opaque_type_values,
diags,
);

let movable_coroutine =
// The first argument is the coroutine type passed by value
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ pub(super) fn dump_nll_mir<'tcx>(
infcx: &BorrowckInferCtxt<'tcx>,
body: &Body<'tcx>,
regioncx: &RegionInferenceContext<'tcx>,
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
closure_region_requirements: Option<&ClosureRegionRequirements<'tcx>>,
borrow_set: &BorrowSet<'tcx>,
) {
let tcx = infcx.tcx;
Expand Down Expand Up @@ -251,7 +251,7 @@ pub(super) fn dump_nll_mir<'tcx>(
pub(crate) fn emit_nll_mir<'tcx>(
tcx: TyCtxt<'tcx>,
regioncx: &RegionInferenceContext<'tcx>,
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
closure_region_requirements: Option<&ClosureRegionRequirements<'tcx>>,
borrow_set: &BorrowSet<'tcx>,
pass_where: PassWhere,
out: &mut dyn io::Write,
Expand Down Expand Up @@ -298,7 +298,7 @@ pub(super) fn dump_annotation<'tcx, 'infcx>(
infcx: &'infcx BorrowckInferCtxt<'tcx>,
body: &Body<'tcx>,
regioncx: &RegionInferenceContext<'tcx>,
closure_region_requirements: &Option<ClosureRegionRequirements<'tcx>>,
closure_region_requirements: Option<&ClosureRegionRequirements<'tcx>>,
opaque_type_values: &FxIndexMap<LocalDefId, OpaqueHiddenType<'tcx>>,
diags: &mut crate::diags::BorrowckDiags<'infcx, 'tcx>,
) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/polonius/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn emit_polonius_mir<'tcx>(
crate::nll::emit_nll_mir(
tcx,
regioncx,
closure_region_requirements,
closure_region_requirements.as_ref(),
borrow_set,
pass_where.clone(),
out,
Expand Down
Loading

0 comments on commit adbd7be

Please sign in to comment.