diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index 569a15b0e07ba..e2b6ba5bd48d9 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -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, diff --git a/compiler/rustc_ast_lowering/src/delegation.rs b/compiler/rustc_ast_lowering/src/delegation.rs index 70c94f4019ae2..c6434bb8f6266 100644 --- a/compiler/rustc_ast_lowering/src/delegation.rs +++ b/compiler/rustc_ast_lowering/src/delegation.rs @@ -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, diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 3032042ff9fee..da68767ccfa8e 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -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, @@ -367,7 +367,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, @@ -1353,7 +1353,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ); let qpath = self.lower_qpath( callee.id, - qself, + qself.as_ref(), path, ParamMode::Optional, AllowReturnTypeNotation::No, @@ -1374,7 +1374,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, @@ -1400,7 +1400,7 @@ impl<'hir> LoweringContext<'_, 'hir> { })); let qpath = self.lower_qpath( lhs.id, - &se.qself, + se.qself.as_ref(), &se.path, ParamMode::Optional, AllowReturnTypeNotation::No, diff --git a/compiler/rustc_ast_lowering/src/format.rs b/compiler/rustc_ast_lowering/src/format.rs index 653116e1fe00d..44b6136a23087 100644 --- a/compiler/rustc_ast_lowering/src/format.rs +++ b/compiler/rustc_ast_lowering/src/format.rs @@ -283,7 +283,7 @@ fn make_argument<'hir>( fn make_count<'hir>( ctx: &mut LoweringContext<'_, 'hir>, sp: Span, - count: &Option, + count: Option<&FormatCount>, argmap: &mut FxIndexMap<(usize, ArgumentType), Option>, ) -> hir::Expr<'hir> { match count { @@ -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, diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 96546239f4c27..fffff5860bb96 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1119,7 +1119,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn lower_path_ty( &mut self, t: &Ty, - qself: &Option>, + qself: Option<&ptr::P>, path: &Path, param_mode: ParamMode, itctx: ImplTraitContext, @@ -1238,7 +1238,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(); @@ -1898,7 +1898,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, @@ -2050,7 +2050,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { { let qpath = self.lower_qpath( ty_id, - &None, + None, path, ParamMode::Optional, AllowReturnTypeNotation::No, @@ -2126,7 +2126,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { { let qpath = self.lower_qpath( expr.id, - &None, + None, path, ParamMode::Optional, AllowReturnTypeNotation::No, diff --git a/compiler/rustc_ast_lowering/src/pat.rs b/compiler/rustc_ast_lowering/src/pat.rs index ace7bfb5c73f2..16ec3555a5de7 100644 --- a/compiler/rustc_ast_lowering/src/pat.rs +++ b/compiler/rustc_ast_lowering/src/pat.rs @@ -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, @@ -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, @@ -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, diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 133793e26ea3c..ef4038ab0f7bd 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -25,7 +25,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { pub(crate) fn lower_qpath( &mut self, id: NodeId, - qself: &Option>, + qself: Option<&ptr::P>, p: &Path, param_mode: ParamMode, allow_return_type_notation: AllowReturnTypeNotation, diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index d7c531f37608d..e163568b391e5 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -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) { - 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(); } } @@ -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); } @@ -1738,7 +1738,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") } diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs index 04ec135c4289d..9caf0067ddd07 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs @@ -151,7 +151,7 @@ impl<'a> State<'a> { fn print_expr_struct( &mut self, - qself: &Option>, + qself: Option<&P>, path: &ast::Path, fields: &[ast::ExprField], rest: &ast::StructRest, @@ -388,7 +388,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); diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs index 1ae765c0130f6..eb091147702a0 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs @@ -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)) @@ -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)) @@ -604,10 +604,10 @@ impl<'a> State<'a> { &mut self, attrs: &[ast::Attribute], vis: &ast::Visibility, - qself: &Option>, + qself: Option<&P>, path: &ast::Path, kind: DelegationKind<'_>, - body: &Option>, + body: Option<&P>, ) { if body.is_some() { self.head(""); diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index c11103af476e3..9d7ff13b59111 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -2935,7 +2935,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, @@ -2988,7 +2994,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { borrow_span, span, category, - opt_place_desc.as_ref(), + opt_place_desc.as_deref(), ) { return diag; } @@ -3331,7 +3337,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", @@ -3534,7 +3540,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { fn report_escaping_data( &self, borrow_span: Span, - name: &Option, + name: Option<&str>, upvar_span: Span, upvar_name: Symbol, escape_span: Span, diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 9b7474c220848..f8e5b72ede15a 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -220,11 +220,11 @@ 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, ®ioncx, &opt_closure_req, &borrow_set); + nll::dump_nll_mir(&infcx, body, ®ioncx, 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, ®ioncx, &opt_closure_req, &opaque_type_values, diags); + nll::dump_annotation(&infcx, body, ®ioncx, opt_closure_req.as_ref(), &opaque_type_values, diags); let movable_coroutine = // The first argument is the coroutine type passed by value diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index be02e2f48dfd8..873139ac9961f 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -190,7 +190,7 @@ pub(super) fn dump_nll_mir<'tcx>( infcx: &BorrowckInferCtxt<'tcx>, body: &Body<'tcx>, regioncx: &RegionInferenceContext<'tcx>, - closure_region_requirements: &Option>, + closure_region_requirements: Option<&ClosureRegionRequirements<'tcx>>, borrow_set: &BorrowSet<'tcx>, ) { let tcx = infcx.tcx; @@ -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>, + closure_region_requirements: Option<&ClosureRegionRequirements<'tcx>>, opaque_type_values: &FxIndexMap>, diags: &mut crate::diags::BorrowckDiags<'infcx, 'tcx>, ) { diff --git a/compiler/rustc_codegen_gcc/build_system/src/utils.rs b/compiler/rustc_codegen_gcc/build_system/src/utils.rs index 401c23948e5d3..9721c5fe879ba 100644 --- a/compiler/rustc_codegen_gcc/build_system/src/utils.rs +++ b/compiler/rustc_codegen_gcc/build_system/src/utils.rs @@ -21,9 +21,9 @@ fn exec_command( ) -> Result { 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() { @@ -31,7 +31,7 @@ fn exec_command( 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) @@ -92,7 +92,7 @@ fn check_exit_status( Err(error) } -fn command_error(input: &[&dyn AsRef], cwd: &Option<&Path>, error: D) -> String { +fn command_error(input: &[&dyn AsRef], cwd: Option<&Path>, error: D) -> String { format!( "Command `{}`{} failed to run: {error:?}", input.iter().map(|s| s.as_ref().to_str().unwrap()).collect::>().join(" "), @@ -112,7 +112,7 @@ pub fn run_command_with_env( env: Option<&HashMap>, ) -> Result { 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) } diff --git a/compiler/rustc_codegen_gcc/src/builder.rs b/compiler/rustc_codegen_gcc/src/builder.rs index 9a142326ad196..9446e5b1604a2 100644 --- a/compiler/rustc_codegen_gcc/src/builder.rs +++ b/compiler/rustc_codegen_gcc/src/builder.rs @@ -379,7 +379,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { gcc_func, args.into(), &func_name, - original_function_name, + original_function_name.map(String::as_str), ) }; let args_adjusted = args.len() != previous_arg_count; diff --git a/compiler/rustc_codegen_gcc/src/debuginfo.rs b/compiler/rustc_codegen_gcc/src/debuginfo.rs index 6aeb656c1ab40..18d939afac71b 100644 --- a/compiler/rustc_codegen_gcc/src/debuginfo.rs +++ b/compiler/rustc_codegen_gcc/src/debuginfo.rs @@ -86,7 +86,15 @@ fn compute_mir_scopes<'gcc, 'tcx>( // Instantiate all scopes. for idx in 0..mir.source_scopes.len() { let scope = SourceScope::new(idx); - make_mir_scope(cx, instance, mir, &variables, debug_context, &mut instantiated, scope); + make_mir_scope( + cx, + instance, + mir, + variables.as_ref(), + debug_context, + &mut instantiated, + scope, + ); } assert!(instantiated.count() == mir.source_scopes.len()); } @@ -101,7 +109,7 @@ fn make_mir_scope<'gcc, 'tcx>( cx: &CodegenCx<'gcc, 'tcx>, _instance: Instance<'tcx>, mir: &Body<'tcx>, - variables: &Option>, + variables: Option<&BitSet>, debug_context: &mut FunctionDebugContext<'tcx, (), Location<'gcc>>, instantiated: &mut BitSet, scope: SourceScope, @@ -126,7 +134,7 @@ fn make_mir_scope<'gcc, 'tcx>( return; }; - if let Some(ref vars) = *variables { + if let Some(vars) = variables { if !vars.contains(scope) && scope_data.inlined.is_none() { // Do not create a DIScope if there are no variables defined in this // MIR `SourceScope`, and it's not `inlined`, to avoid debuginfo bloat. diff --git a/compiler/rustc_codegen_gcc/src/intrinsic/llvm.rs b/compiler/rustc_codegen_gcc/src/intrinsic/llvm.rs index 0a448ded6b1ae..e6319e98e909f 100644 --- a/compiler/rustc_codegen_gcc/src/intrinsic/llvm.rs +++ b/compiler/rustc_codegen_gcc/src/intrinsic/llvm.rs @@ -43,7 +43,7 @@ pub fn adjust_intrinsic_arguments<'a, 'b, 'gcc, 'tcx>( gcc_func: FunctionPtrType<'gcc>, mut args: Cow<'b, [RValue<'gcc>]>, func_name: &str, - original_function_name: Option<&String>, + original_function_name: Option<&str>, ) -> Cow<'b, [RValue<'gcc>]> { // TODO: this might not be a good way to workaround the missing tile builtins. if func_name == "__builtin_trap" { @@ -546,7 +546,7 @@ pub fn adjust_intrinsic_arguments<'a, 'b, 'gcc, 'tcx>( | "__builtin_ia32_vfmaddsubps256" | "__builtin_ia32_vfmaddsubpd" => { if let Some(original_function_name) = original_function_name { - match &**original_function_name { + match original_function_name { "llvm.x86.fma.vfmsubadd.pd.256" | "llvm.x86.fma.vfmsubadd.ps" | "llvm.x86.fma.vfmsubadd.ps.256" diff --git a/compiler/rustc_codegen_llvm/src/attributes.rs b/compiler/rustc_codegen_llvm/src/attributes.rs index cb958c1d4d771..d417e8741d9e7 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -541,6 +541,6 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>( attributes::apply_to_llfn(llfn, Function, &to_add); } -fn wasm_import_module(tcx: TyCtxt<'_>, id: DefId) -> Option<&String> { - tcx.wasm_import_module_map(id.krate).get(&id) +fn wasm_import_module(tcx: TyCtxt<'_>, id: DefId) -> Option<&str> { + tcx.wasm_import_module_map(id.krate).get(&id).map(String::as_str) } diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs index 07bd0f4d1c171..bf5fb3b58bad1 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs @@ -49,7 +49,7 @@ pub(crate) fn compute_mir_scopes<'ll, 'tcx>( cx, instance, mir, - &variables, + variables.as_ref(), debug_context, &mut instantiated, &mut discriminators, @@ -63,7 +63,7 @@ fn make_mir_scope<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>, mir: &Body<'tcx>, - variables: &Option>, + variables: Option<&BitSet>, debug_context: &mut FunctionDebugContext<'tcx, &'ll DIScope, &'ll DILocation>, instantiated: &mut BitSet, discriminators: &mut FxHashMap, diff --git a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs index b4a651b10b10a..fccda5e155c24 100644 --- a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs +++ b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs @@ -62,7 +62,7 @@ impl Emitter for AnnotateSnippetEmitter { &diag.level, &diag.messages, &fluent_args, - &diag.code, + diag.code, &diag.span, &diag.children, &suggestions, @@ -130,7 +130,7 @@ impl AnnotateSnippetEmitter { level: &Level, messages: &[(DiagMessage, Style)], args: &FluentArgs<'_>, - code: &Option, + code: Option, msp: &MultiSpan, _children: &[Subdiag], _suggestions: &[CodeSuggestion], diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 4352de3ad25fe..e71251ee13051 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -402,23 +402,23 @@ impl DiagInner { ) -> ( &Level, &[(DiagMessage, Style)], - &Option, + Option, &MultiSpan, &[Subdiag], &Suggestions, Vec<(&DiagArgName, &DiagArgValue)>, - &Option, + Option<&IsLint>, ) { ( &self.level, &self.messages, - &self.code, + self.code, &self.span, &self.children, &self.suggestions, self.args.iter().collect(), // omit self.sort_span - &self.is_lint, + self.is_lint.as_ref(), // omit self.emitted_at ) } diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index a386129e8145e..736a685b5cee2 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -517,7 +517,7 @@ impl Emitter for HumanEmitter { &diag.level, &diag.messages, &fluent_args, - &diag.code, + diag.code, &diag.span, &diag.children, &suggestions, @@ -1389,7 +1389,7 @@ impl HumanEmitter { msp: &MultiSpan, msgs: &[(DiagMessage, Style)], args: &FluentArgs<'_>, - code: &Option, + code: Option, level: &Level, max_line_num_len: usize, is_secondary: bool, @@ -2315,7 +2315,7 @@ impl HumanEmitter { level: &Level, messages: &[(DiagMessage, Style)], args: &FluentArgs<'_>, - code: &Option, + code: Option, span: &MultiSpan, children: &[Subdiag], suggestions: &[CodeSuggestion], @@ -2378,7 +2378,7 @@ impl HumanEmitter { span, &child.messages, args, - &None, + None, &child.level, max_line_num_len, true, @@ -2398,7 +2398,7 @@ impl HumanEmitter { &MultiSpan::new(), &[(sugg.msg.to_owned(), Style::HeaderMsg)], args, - &None, + None, &Level::Help, max_line_num_len, true, diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 8fa797db24661..abe832081471d 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -268,7 +268,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<() match header.map(|h| h.polarity) { // `None` means this is an inherent impl Some(ty::ImplPolarity::Positive) | None => { - res = res.and(check_impl(tcx, item, impl_.self_ty, &impl_.of_trait)); + res = res.and(check_impl(tcx, item, impl_.self_ty, impl_.of_trait.as_ref())); } Some(ty::ImplPolarity::Negative) => { let ast::ImplPolarity::Negative(span) = impl_.polarity else { @@ -1328,7 +1328,7 @@ fn check_impl<'tcx>( tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>, hir_self_ty: &hir::Ty<'_>, - hir_trait_ref: &Option>, + hir_trait_ref: Option<&hir::TraitRef<'_>>, ) -> Result<(), ErrorGuaranteed> { enter_wf_checking_ctxt(tcx, item.span, item.owner_id.def_id, |wfcx| { match hir_trait_ref { diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs index 2a00530c43436..d5de74e5e74b2 100644 --- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs @@ -369,7 +369,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx self.consume_exprs(args)?; } - hir::ExprKind::Struct(_, fields, ref opt_with) => { + hir::ExprKind::Struct(_, fields, opt_with) => { self.walk_struct_expr(fields, opt_with)?; } @@ -686,7 +686,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx fn walk_struct_expr<'hir>( &self, fields: &[hir::ExprField<'_>], - opt_with: &Option<&'hir hir::Expr<'_>>, + opt_with: Option<&'hir hir::Expr<'_>>, ) -> Result<(), Cx::Error> { // Consume the expressions supplying values for each field. for field in fields { @@ -701,11 +701,8 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx } } - let with_expr = match *opt_with { - Some(w) => &*w, - None => { - return Ok(()); - } + let Some(with_expr) = opt_with else { + return Ok(()); }; let with_place = self.cat_expr(with_expr)?; diff --git a/compiler/rustc_incremental/src/assert_dep_graph.rs b/compiler/rustc_incremental/src/assert_dep_graph.rs index 1f46155abc882..a85be066b9fa3 100644 --- a/compiler/rustc_incremental/src/assert_dep_graph.rs +++ b/compiler/rustc_incremental/src/assert_dep_graph.rs @@ -236,7 +236,7 @@ fn dump_graph(query: &DepGraphQuery) { EdgeFilter::new(&string).unwrap_or_else(|e| bug!("invalid filter: {}", e)); let sources = node_set(query, &edge_filter.source); let targets = node_set(query, &edge_filter.target); - filter_nodes(query, &sources, &targets) + filter_nodes(query, sources.as_ref(), targets.as_ref()) } Err(_) => query.nodes().into_iter().map(|n| n.kind).collect(), }; @@ -318,8 +318,8 @@ fn node_set<'q>( fn filter_nodes<'q>( query: &'q DepGraphQuery, - sources: &Option>, - targets: &Option>, + sources: Option<&FxIndexSet<&'q DepNode>>, + targets: Option<&FxIndexSet<&'q DepNode>>, ) -> FxIndexSet { if let Some(sources) = sources { if let Some(targets) = targets { diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index 7ea4ded2b052c..05e66aa941f9e 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -96,7 +96,7 @@ use std::cmp; use std::collections::hash_map::Entry; use std::fs::{self, File}; use std::io::Write; -use std::path::{Path, PathBuf}; +use std::path::Path; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::sync; @@ -1183,7 +1183,7 @@ fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[Co // Output monomorphization stats per def_id if let SwitchWithOptPath::Enabled(ref path) = tcx.sess.opts.unstable_opts.dump_mono_stats { if let Err(err) = - dump_mono_items_stats(tcx, codegen_units, path, tcx.crate_name(LOCAL_CRATE)) + dump_mono_items_stats(tcx, codegen_units, path.as_deref(), tcx.crate_name(LOCAL_CRATE)) { tcx.dcx().emit_fatal(CouldntDumpMonoStats { error: err.to_string() }); } @@ -1248,7 +1248,7 @@ fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[Co fn dump_mono_items_stats<'tcx>( tcx: TyCtxt<'tcx>, codegen_units: &[CodegenUnit<'tcx>], - output_directory: &Option, + output_directory: Option<&Path>, crate_name: Symbol, ) -> Result<(), Box> { let output_directory = if let Some(ref directory) = output_directory { diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 4430d2d14313b..b0a7e1b08636c 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1617,7 +1617,7 @@ impl<'a> Parser<'a> { let mac = P(MacCall { path, args: self.parse_delim_args()? }); (lo.to(self.prev_token.span), ExprKind::MacCall(mac)) } else if self.check(&token::OpenDelim(Delimiter::Brace)) - && let Some(expr) = self.maybe_parse_struct_expr(&qself, &path) + && let Some(expr) = self.maybe_parse_struct_expr(qself.as_ref(), &path) { if qself.is_some() { self.psess.gated_spans.gate(sym::more_qualified_paths, path.span); @@ -3482,7 +3482,7 @@ impl<'a> Parser<'a> { fn maybe_parse_struct_expr( &mut self, - qself: &Option>, + qself: Option<&P>, path: &ast::Path, ) -> Option>> { let struct_allowed = !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL); @@ -3490,7 +3490,7 @@ impl<'a> Parser<'a> { if let Err(err) = self.expect(&token::OpenDelim(Delimiter::Brace)) { return Some(Err(err)); } - let expr = self.parse_expr_struct(qself.clone(), path.clone(), true); + let expr = self.parse_expr_struct(qself.cloned(), path.clone(), true); if let (Ok(expr), false) = (&expr, struct_allowed) { // This is a struct literal, but we don't can't accept them here. self.dcx().emit_err(errors::StructLiteralNotAllowedHere { diff --git a/compiler/rustc_query_system/src/dep_graph/serialized.rs b/compiler/rustc_query_system/src/dep_graph/serialized.rs index a4fb0a5b07220..f0bae2ee75e40 100644 --- a/compiler/rustc_query_system/src/dep_graph/serialized.rs +++ b/compiler/rustc_query_system/src/dep_graph/serialized.rs @@ -498,7 +498,7 @@ impl EncoderState { node: DepNode, edge_count: usize, edges: impl FnOnce(&mut Self) -> Vec, - record_graph: &Option>, + record_graph: Option<&Lock>, ) -> DepNodeIndex { let index = DepNodeIndex::new(self.total_node_count); @@ -538,7 +538,7 @@ impl EncoderState { fn encode_node( &mut self, node: &NodeInfo, - record_graph: &Option>, + record_graph: Option<&Lock>, ) -> DepNodeIndex { node.encode::(&mut self.encoder); self.record(node.node, node.edges.len(), |_| node.edges[..].to_vec(), record_graph) @@ -554,7 +554,7 @@ impl EncoderState { fn encode_promoted_node( &mut self, prev_index: SerializedDepNodeIndex, - record_graph: &Option>, + record_graph: Option<&Lock>, prev_index_to_index: &IndexVec>, ) -> DepNodeIndex { let node = self.previous.index_to_node(prev_index); @@ -704,7 +704,7 @@ impl GraphEncoder { ) -> DepNodeIndex { let _prof_timer = self.profiler.generic_activity("incr_comp_encode_dep_graph"); let node = NodeInfo { node, fingerprint, edges }; - self.status.lock().as_mut().unwrap().encode_node(&node, &self.record_graph) + self.status.lock().as_mut().unwrap().encode_node(&node, self.record_graph.as_ref()) } /// Encodes a node that was promoted from the previous graph. It reads the information directly from @@ -718,7 +718,7 @@ impl GraphEncoder { let _prof_timer = self.profiler.generic_activity("incr_comp_encode_dep_graph"); self.status.lock().as_mut().unwrap().encode_promoted_node( prev_index, - &self.record_graph, + self.record_graph.as_ref(), prev_index_to_index, ) } diff --git a/compiler/rustc_query_system/src/query/job.rs b/compiler/rustc_query_system/src/query/job.rs index 2a7d759ab3576..acd27563094e8 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -100,12 +100,12 @@ impl QueryJobId { pub(super) fn find_cycle_in_stack( &self, query_map: QueryMap, - current_job: &Option, + current_job: Option<&QueryJobId>, span: Span, ) -> CycleError { // Find the waitee amongst `current_job` parents let mut cycle = Vec::new(); - let mut current_job = Option::clone(current_job); + let mut current_job = current_job.cloned(); while let Some(job) = current_job { let info = query_map.get(&job).unwrap(); diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index aac8ab87c64e6..45c905e4001e6 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -254,8 +254,11 @@ where Q: QueryConfig, Qcx: QueryContext, { - let error = - try_execute.find_cycle_in_stack(qcx.collect_active_jobs(), &qcx.current_query_job(), span); + let error = try_execute.find_cycle_in_stack( + qcx.collect_active_jobs(), + qcx.current_query_job().as_ref(), + span, + ); (mk_cycle(query, qcx, error), None) } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index fc92dc8b4ed71..8c57406776afe 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -802,7 +802,7 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r PathSource::Type }; - self.smart_resolve_path(ty.id, qself, path, source); + self.smart_resolve_path(ty.id, qself.as_ref(), path, source); // Check whether we should interpret this as a bare trait object. if qself.is_none() @@ -911,7 +911,7 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r this.visit_generic_params(&tref.bound_generic_params, false); this.smart_resolve_path( tref.trait_ref.ref_id, - &None, + None, &tref.trait_ref.path, PathSource::Trait(AliasPossibility::Maybe), ); @@ -1105,14 +1105,14 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r if !check_ns(TypeNS) && check_ns(ValueNS) { self.smart_resolve_path( *id, - &None, + None, path, PathSource::PreciseCapturingArg(ValueNS), ); } else { self.smart_resolve_path( *id, - &None, + None, path, PathSource::PreciseCapturingArg(TypeNS), ); @@ -1167,7 +1167,7 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r |this| { this.smart_resolve_path( ty.id, - &None, + None, path, PathSource::Expr(None), ); @@ -1328,7 +1328,12 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r self.with_rib(ValueNS, RibKind::InlineAsmSym, |this| { this.with_rib(TypeNS, RibKind::InlineAsmSym, |this| { this.with_label_rib(RibKind::InlineAsmSym, |this| { - this.smart_resolve_path(sym.id, &sym.qself, &sym.path, PathSource::Expr(None)); + this.smart_resolve_path( + sym.id, + sym.qself.as_ref(), + &sym.path, + PathSource::Expr(None), + ); visit::walk_inline_asm_sym(this, sym); }); }) @@ -3073,7 +3078,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { self.diag_metadata.currently_processing_impl_trait = Some((trait_ref.clone(), self_type.clone())); let res = self.smart_resolve_path_fragment( - &None, + None, &path, PathSource::Trait(AliasPossibility::No), Finalize::new(trait_ref.ref_id, trait_ref.path.span), @@ -3450,7 +3455,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { fn resolve_delegation(&mut self, delegation: &'ast Delegation) { self.smart_resolve_path( delegation.id, - &delegation.qself, + delegation.qself.as_ref(), &delegation.path, PathSource::Delegation, ); @@ -3757,7 +3762,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { PatKind::TupleStruct(ref qself, ref path, ref sub_patterns) => { self.smart_resolve_path( pat.id, - qself, + qself.as_ref(), path, PathSource::TupleStruct( pat.span, @@ -3766,10 +3771,10 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { ); } PatKind::Path(ref qself, ref path) => { - self.smart_resolve_path(pat.id, qself, path, PathSource::Pat); + self.smart_resolve_path(pat.id, qself.as_ref(), path, PathSource::Pat); } PatKind::Struct(ref qself, ref path, ..) => { - self.smart_resolve_path(pat.id, qself, path, PathSource::Struct); + self.smart_resolve_path(pat.id, qself.as_ref(), path, PathSource::Struct); } PatKind::Or(ref ps) => { // Add a new set of bindings to the stack. `Or` here records that when a @@ -3962,7 +3967,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { fn smart_resolve_path( &mut self, id: NodeId, - qself: &Option>, + qself: Option<&P>, path: &Path, source: PathSource<'ast>, ) { @@ -3978,7 +3983,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { #[instrument(level = "debug", skip(self))] fn smart_resolve_path_fragment( &mut self, - qself: &Option>, + qself: Option<&P>, path: &[Segment], source: PathSource<'ast>, finalize: Finalize, @@ -4263,7 +4268,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { // Resolve in alternative namespaces if resolution in the primary namespace fails. fn resolve_qpath_anywhere( &mut self, - qself: &Option>, + qself: Option<&P>, path: &[Segment], primary_ns: Namespace, span: Span, @@ -4307,7 +4312,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { /// Handles paths that may refer to associated items. fn resolve_qpath( &mut self, - qself: &Option>, + qself: Option<&P>, path: &[Segment], ns: Namespace, finalize: Finalize, @@ -4331,7 +4336,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { let num_privacy_errors = self.r.privacy_errors.len(); // Make sure that `A` in `::B::C` is a trait. let trait_res = self.smart_resolve_path_fragment( - &None, + None, &path[..qself.position], PathSource::Trait(AliasPossibility::No), Finalize::new(finalize.node_id, qself.path_span), @@ -4355,7 +4360,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { // but with `qself` set to `None`. let ns = if qself.position + 1 == path.len() { ns } else { TypeNS }; let partial_res = self.smart_resolve_path_fragment( - &None, + None, &path[..=qself.position], PathSource::TraitItem(ns), Finalize::with_root_span(finalize.node_id, finalize.path_span, qself.path_span), @@ -4580,12 +4585,12 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { // Next, resolve the node. match expr.kind { ExprKind::Path(ref qself, ref path) => { - self.smart_resolve_path(expr.id, qself, path, PathSource::Expr(parent)); + self.smart_resolve_path(expr.id, qself.as_ref(), path, PathSource::Expr(parent)); visit::walk_expr(self, expr); } ExprKind::Struct(ref se) => { - self.smart_resolve_path(expr.id, &se.qself, &se.path, PathSource::Struct); + self.smart_resolve_path(expr.id, se.qself.as_ref(), &se.path, PathSource::Struct); // This is the same as `visit::walk_expr(self, expr);`, but we want to pass the // parent in for accurate suggestions when encountering `Foo { bar }` that should // have been `Foo { bar: self.bar }`. diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index cb6d539cdf940..101bc967f2b68 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2123,11 +2123,11 @@ fn select_debuginfo(matches: &getopts::Matches, cg: &CodegenOptions) -> DebugInf fn parse_assert_incr_state( early_dcx: &EarlyDiagCtxt, - opt_assertion: &Option, + opt_assertion: Option<&str>, ) -> Option { match opt_assertion { - Some(s) if s.as_str() == "loaded" => Some(IncrementalStateAssertion::Loaded), - Some(s) if s.as_str() == "not-loaded" => Some(IncrementalStateAssertion::NotLoaded), + Some("loaded") => Some(IncrementalStateAssertion::Loaded), + Some("not-loaded") => Some(IncrementalStateAssertion::NotLoaded), Some(s) => { early_dcx.early_fatal(format!("unexpected incremental state assertion value: {s}")) } @@ -2358,7 +2358,8 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M let incremental = cg.incremental.as_ref().map(PathBuf::from); - let assert_incr_state = parse_assert_incr_state(early_dcx, &unstable_opts.assert_incr_state); + let assert_incr_state = + parse_assert_incr_state(early_dcx, unstable_opts.assert_incr_state.as_deref()); if cg.profile_generate.enabled() && cg.profile_use.is_some() { early_dcx.early_fatal("options `-C profile-generate` and `-C profile-use` are exclusive");