diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index 88cdb2ec36397..adf242832b271 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -198,7 +198,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 3b85f1737bdd9..1779da9680ef0 100644 --- a/compiler/rustc_ast_lowering/src/delegation.rs +++ b/compiler/rustc_ast_lowering/src/delegation.rs @@ -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, diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 52372bbf991c9..1ec4729e61844 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -278,7 +278,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, @@ -326,7 +326,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, @@ -1287,7 +1287,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ); let qpath = self.lower_qpath( callee.id, - qself, + qself.as_ref(), path, ParamMode::Optional, AllowReturnTypeNotation::No, @@ -1308,7 +1308,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, @@ -1334,7 +1334,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 c6cb7aa7dd5c2..94f7002582d4d 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1206,7 +1206,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, @@ -1340,7 +1340,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(); @@ -2222,7 +2222,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, @@ -2361,7 +2361,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { Res::Def(DefKind::ConstParam, _) => { let qpath = self.lower_qpath( ty_id, - &None, + None, path, ParamMode::Optional, AllowReturnTypeNotation::No, @@ -2440,7 +2440,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { { let qpath = self.lower_qpath( expr.id, - qself, + qself.as_ref(), path, ParamMode::Optional, AllowReturnTypeNotation::No, diff --git a/compiler/rustc_ast_lowering/src/pat.rs b/compiler/rustc_ast_lowering/src/pat.rs index 760f84564f1a2..01debddcde2a9 100644 --- a/compiler/rustc_ast_lowering/src/pat.rs +++ b/compiler/rustc_ast_lowering/src/pat.rs @@ -35,7 +35,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, @@ -53,7 +53,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, @@ -65,7 +65,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 e60488fdc8c74..3ebe613d008f1 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 7e07ccf28a0cb..abd662a571b36 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1107,9 +1107,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(); } } @@ -1160,7 +1160,7 @@ 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::Never => { @@ -1709,7 +1709,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 893bfaf8f712e..6f48d94b3c553 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 8217b6df5b470..64e1c46bd479b 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs @@ -386,18 +386,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)) @@ -578,18 +578,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)) @@ -599,10 +599,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 60ea0d1edbf4e..3b03a838dcfe5 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -2921,7 +2921,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, @@ -2973,7 +2979,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { borrow_span, span, category, - opt_place_desc.as_ref(), + opt_place_desc.as_deref(), ) { return diag; } @@ -3315,7 +3321,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", @@ -3517,7 +3523,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 a11eca0b9c746..c1e3bbdc24dba 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -228,7 +228,7 @@ 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. @@ -236,7 +236,7 @@ fn do_mir_borrowck<'tcx>( &infcx, body, ®ioncx, - &opt_closure_req, + opt_closure_req.as_ref(), &opaque_type_values, &mut diags, ); diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index d85af52b01e36..c6ece85a26997 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -224,7 +224,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; @@ -305,7 +305,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..b4e6f7c635a4b 100644 --- a/compiler/rustc_codegen_gcc/build_system/src/utils.rs +++ b/compiler/rustc_codegen_gcc/build_system/src/utils.rs @@ -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(" "), diff --git a/compiler/rustc_codegen_gcc/src/builder.rs b/compiler/rustc_codegen_gcc/src/builder.rs index acd5358883166..b41f40aa70b7c 100644 --- a/compiler/rustc_codegen_gcc/src/builder.rs +++ b/compiler/rustc_codegen_gcc/src/builder.rs @@ -378,7 +378,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 9d62ccc95d56d..f7d8c019ffd81 100644 --- a/compiler/rustc_codegen_gcc/src/debuginfo.rs +++ b/compiler/rustc_codegen_gcc/src/debuginfo.rs @@ -82,7 +82,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()); } @@ -97,7 +105,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, @@ -122,7 +130,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 489259da85646..e7e01df34dc15 100644 --- a/compiler/rustc_codegen_llvm/src/attributes.rs +++ b/compiler/rustc_codegen_llvm/src/attributes.rs @@ -564,6 +564,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 ac6c2fb1b83a6..412ab7c70880e 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs @@ -40,7 +40,15 @@ pub(crate) fn compute_mir_scopes<'ll, '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()); } @@ -49,7 +57,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, scope: SourceScope, diff --git a/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs b/compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs index f468fbf4497e0..59852a7728eae 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 1dc52c4d0a423..7d53b8a2ac9ae 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -512,7 +512,7 @@ impl Emitter for HumanEmitter { &diag.level, &diag.messages, &fluent_args, - &diag.code, + diag.code, &diag.span, &diag.children, &suggestions, @@ -1289,7 +1289,7 @@ impl HumanEmitter { msp: &MultiSpan, msgs: &[(DiagMessage, Style)], args: &FluentArgs<'_>, - code: &Option, + code: Option, level: &Level, max_line_num_len: usize, is_secondary: bool, @@ -2135,7 +2135,7 @@ impl HumanEmitter { level: &Level, messages: &[(DiagMessage, Style)], args: &FluentArgs<'_>, - code: &Option, + code: Option, span: &MultiSpan, children: &[Subdiag], suggestions: &[CodeSuggestion], @@ -2183,7 +2183,7 @@ impl HumanEmitter { span, &child.messages, args, - &None, + None, &child.level, max_line_num_len, true, @@ -2202,7 +2202,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 a71e14ce463f6..b02ba81500faa 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -265,7 +265,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 { @@ -1324,7 +1324,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 bb5f351137305..b8fd106dbb303 100644 --- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs @@ -370,7 +370,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)?; } @@ -687,7 +687,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 { @@ -702,11 +702,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 a006786aa75b9..40a7c360bc0b0 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 ad05cca66cab3..950eae8b8068f 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; @@ -1164,7 +1164,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() }); } @@ -1229,7 +1229,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 0ac6133e8289f..8fd0ad6342a5d 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1620,7 +1620,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); @@ -3476,7 +3476,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); @@ -3484,7 +3484,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 ca3efc11201e1..417e32c240bd4 100644 --- a/compiler/rustc_query_system/src/query/job.rs +++ b/compiler/rustc_query_system/src/query/job.rs @@ -119,12 +119,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 17486be04dcde..e11d3fa85ec03 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -257,8 +257,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 66c1ff93ce1ce..05d1dd9903b94 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() @@ -912,7 +912,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), ); @@ -1118,14 +1118,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), ); @@ -1180,7 +1180,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), ); @@ -1343,7 +1343,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); }); }) @@ -3088,7 +3093,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), @@ -3465,7 +3470,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, ); @@ -3772,7 +3777,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, @@ -3781,10 +3786,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 @@ -3977,7 +3982,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>, ) { @@ -3993,7 +3998,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, @@ -4277,7 +4282,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, @@ -4321,7 +4326,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, @@ -4345,7 +4350,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), @@ -4369,7 +4374,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), @@ -4594,12 +4599,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 b052d8d72c7d8..14888948c2b4f 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2089,11 +2089,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(s) if s == "loaded" => Some(IncrementalStateAssertion::Loaded), + Some(s) if s == "not-loaded" => Some(IncrementalStateAssertion::NotLoaded), Some(s) => { early_dcx.early_fatal(format!("unexpected incremental state assertion value: {s}")) } @@ -2465,7 +2465,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 unstable_opts.profile && incremental.is_some() { early_dcx.early_fatal("can't instrument with gcov profiling when compiling incrementally");