Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate compiler's &Option<T> into Option<&T> #130963

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -207,7 +207,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 @@ -338,7 +338,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 @@ -319,7 +319,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 @@ -364,7 +364,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 @@ -1350,7 +1350,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
);
let qpath = self.lower_qpath(
callee.id,
qself,
qself.as_ref(),
path,
ParamMode::Optional,
AllowReturnTypeNotation::No,
Expand All @@ -1371,7 +1371,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 @@ -1397,7 +1397,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 @@ -283,7 +283,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 @@ -378,8 +378,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 @@ -1117,7 +1117,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 @@ -1236,7 +1236,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 @@ -1897,7 +1897,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 @@ -2048,7 +2048,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 @@ -2124,7 +2124,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 @@ -42,7 +42,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 @@ -60,7 +60,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 @@ -72,7 +72,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 @@ -25,7 +25,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 @@ -1117,9 +1117,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 @@ -1170,12 +1170,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 @@ -1746,7 +1746,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 @@ -2940,7 +2940,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 @@ -2993,7 +2999,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 @@ -3336,7 +3342,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 @@ -3539,7 +3545,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 @@ -220,11 +220,18 @@ 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.
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
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,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 @@ -271,7 +271,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
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_gcc/build_system/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ fn exec_command(
) -> Result<ExitStatus, String> {
let status = get_command_inner(input, cwd, env)
.spawn()
.map_err(|e| command_error(input, &cwd, e))?
.map_err(|e| command_error(input, cwd, e))?
.wait()
.map_err(|e| command_error(input, &cwd, e))?;
.map_err(|e| command_error(input, cwd, e))?;
#[cfg(unix)]
{
if let Some(signal) = status.signal() {
unsafe {
raise(signal as _);
}
// In case the signal didn't kill the current process.
return Err(command_error(input, &cwd, format!("Process received signal {}", signal)));
return Err(command_error(input, cwd, format!("Process received signal {}", signal)));
}
}
Ok(status)
Expand Down Expand Up @@ -92,7 +92,7 @@ fn check_exit_status(
Err(error)
}

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