diff options
Diffstat (limited to 'compiler')
82 files changed, 637 insertions, 612 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index 50130dc2a27..a4df277a7b0 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -966,8 +966,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { _ => None, }); let is_option_or_result = parent_self_ty.map_or(false, |def_id| { - tcx.is_diagnostic_item(sym::option_type, def_id) - || tcx.is_diagnostic_item(sym::result_type, def_id) + tcx.is_diagnostic_item(sym::Option, def_id) + || tcx.is_diagnostic_item(sym::Result, def_id) }); FnSelfUseKind::Normal { self_arg, implicit_into_iter, is_option_or_result } }); diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index b23ce281bef..855e6850b2e 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -400,8 +400,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { | ty::Opaque(def_id, _) => def_id, _ => return err, }; - let is_option = self.infcx.tcx.is_diagnostic_item(sym::option_type, def_id); - let is_result = self.infcx.tcx.is_diagnostic_item(sym::result_type, def_id); + let is_option = self.infcx.tcx.is_diagnostic_item(sym::Option, def_id); + let is_result = self.infcx.tcx.is_diagnostic_item(sym::Result, def_id); if (is_option || is_result) && use_spans.map_or(true, |v| !v.for_closure()) { err.span_suggestion_verbose( span.shrink_to_hi(), diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 6ffa0095e4b..43032ae81cb 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -277,26 +277,26 @@ fn do_mir_borrowck<'a, 'tcx>( let regioncx = Rc::new(regioncx); - let flow_borrows = Borrows::new(tcx, &body, ®ioncx, &borrow_set) - .into_engine(tcx, &body) + let flow_borrows = Borrows::new(tcx, body, ®ioncx, &borrow_set) + .into_engine(tcx, body) .pass_name("borrowck") .iterate_to_fixpoint(); - let flow_uninits = MaybeUninitializedPlaces::new(tcx, &body, &mdpe) - .into_engine(tcx, &body) + let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &mdpe) + .into_engine(tcx, body) .pass_name("borrowck") .iterate_to_fixpoint(); - let flow_ever_inits = EverInitializedPlaces::new(tcx, &body, &mdpe) - .into_engine(tcx, &body) + let flow_ever_inits = EverInitializedPlaces::new(tcx, body, &mdpe) + .into_engine(tcx, body) .pass_name("borrowck") .iterate_to_fixpoint(); - let movable_generator = match tcx.hir().get(id) { + let movable_generator = !matches!( + tcx.hir().get(id), Node::Expr(&hir::Expr { kind: hir::ExprKind::Closure(.., Some(hir::Movability::Static)), .. - }) => false, - _ => true, - }; + }) + ); for (idx, move_data_results) in promoted_errors { let promoted_body = &promoted[idx]; @@ -374,8 +374,8 @@ fn do_mir_borrowck<'a, 'tcx>( mbcx.report_move_errors(move_errors); rustc_mir_dataflow::visit_results( - &body, - traversal::reverse_postorder(&body).map(|(bb, _)| bb), + body, + traversal::reverse_postorder(body).map(|(bb, _)| bb), &results, &mut mbcx, ); diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index 59f933d422d..0f88995846c 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -332,20 +332,27 @@ pub fn combine_substructure( RefCell::new(f) } +struct TypeParameter { + bound_generic_params: Vec<ast::GenericParam>, + ty: P<ast::Ty>, +} + /// This method helps to extract all the type parameters referenced from a /// type. For a type parameter `<T>`, it looks for either a `TyPath` that /// is not global and starts with `T`, or a `TyQPath`. +/// Also include bound generic params from the input type. fn find_type_parameters( ty: &ast::Ty, ty_param_names: &[Symbol], cx: &ExtCtxt<'_>, -) -> Vec<P<ast::Ty>> { +) -> Vec<TypeParameter> { use rustc_ast::visit; struct Visitor<'a, 'b> { cx: &'a ExtCtxt<'b>, ty_param_names: &'a [Symbol], - types: Vec<P<ast::Ty>>, + bound_generic_params_stack: Vec<ast::GenericParam>, + type_params: Vec<TypeParameter>, } impl<'a, 'b> visit::Visitor<'a> for Visitor<'a, 'b> { @@ -353,7 +360,10 @@ fn find_type_parameters( if let ast::TyKind::Path(_, ref path) = ty.kind { if let Some(segment) = path.segments.first() { if self.ty_param_names.contains(&segment.ident.name) { - self.types.push(P(ty.clone())); + self.type_params.push(TypeParameter { + bound_generic_params: self.bound_generic_params_stack.clone(), + ty: P(ty.clone()), + }); } } } @@ -361,15 +371,35 @@ fn find_type_parameters( visit::walk_ty(self, ty) } + // Place bound generic params on a stack, to extract them when a type is encountered. + fn visit_poly_trait_ref( + &mut self, + trait_ref: &'a ast::PolyTraitRef, + modifier: &'a ast::TraitBoundModifier, + ) { + let stack_len = self.bound_generic_params_stack.len(); + self.bound_generic_params_stack + .extend(trait_ref.bound_generic_params.clone().into_iter()); + + visit::walk_poly_trait_ref(self, trait_ref, modifier); + + self.bound_generic_params_stack.truncate(stack_len); + } + fn visit_mac_call(&mut self, mac: &ast::MacCall) { self.cx.span_err(mac.span(), "`derive` cannot be used on items with type macros"); } } - let mut visitor = Visitor { cx, ty_param_names, types: Vec::new() }; + let mut visitor = Visitor { + cx, + ty_param_names, + bound_generic_params_stack: Vec::new(), + type_params: Vec::new(), + }; visit::Visitor::visit_ty(&mut visitor, ty); - visitor.types + visitor.type_params } impl<'a> TraitDef<'a> { @@ -617,11 +647,11 @@ impl<'a> TraitDef<'a> { ty_params.map(|ty_param| ty_param.ident.name).collect(); for field_ty in field_tys { - let tys = find_type_parameters(&field_ty, &ty_param_names, cx); + let field_ty_params = find_type_parameters(&field_ty, &ty_param_names, cx); - for ty in tys { + for field_ty_param in field_ty_params { // if we have already handled this type, skip it - if let ast::TyKind::Path(_, ref p) = ty.kind { + if let ast::TyKind::Path(_, ref p) = field_ty_param.ty.kind { if p.segments.len() == 1 && ty_param_names.contains(&p.segments[0].ident.name) { @@ -639,8 +669,8 @@ impl<'a> TraitDef<'a> { let predicate = ast::WhereBoundPredicate { span: self.span, - bound_generic_params: Vec::new(), - bounded_ty: ty, + bound_generic_params: field_ty_param.bound_generic_params, + bounded_ty: field_ty_param.ty, bounds, }; diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index 1a0a3a0c340..dca9c1f04d3 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -526,7 +526,7 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> { }; match self.ret.mode { PassMode::Direct(ref attrs) => { - attrs.apply_attrs_to_callsite(llvm::AttributePlace::ReturnValue, &bx.cx, callsite); + attrs.apply_attrs_to_callsite(llvm::AttributePlace::ReturnValue, bx.cx, callsite); } PassMode::Indirect { ref attrs, extra_attrs: _, on_stack } => { assert!(!on_stack); diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index 9690ad8b246..341a8882416 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -105,7 +105,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> { let r = r.unwrap(); // Again, based on how many outputs we have - let outputs = ia.outputs.iter().zip(&outputs).filter(|&(ref o, _)| !o.is_indirect); + let outputs = ia.outputs.iter().zip(&outputs).filter(|&(o, _)| !o.is_indirect); for (i, (_, &place)) in outputs.enumerate() { let v = if num_outputs == 1 { r } else { self.extract_value(r, i as u64) }; OperandValue::Immediate(v).store(self, place); @@ -331,7 +331,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> { let output_type = match &output_types[..] { [] => self.type_void(), [ty] => ty, - tys => self.type_struct(&tys, false), + tys => self.type_struct(tys, false), }; let dialect = match asm_arch { InlineAsmArch::X86 | InlineAsmArch::X86_64 diff --git a/compiler/rustc_codegen_llvm/src/back/lto.rs b/compiler/rustc_codegen_llvm/src/back/lto.rs index 99b30264d09..e2b33509b40 100644 --- a/compiler/rustc_codegen_llvm/src/back/lto.rs +++ b/compiler/rustc_codegen_llvm/src/back/lto.rs @@ -109,7 +109,7 @@ fn prepare_lto( .extend(exported_symbols[&cnum].iter().filter_map(symbol_filter)); } - let archive = ArchiveRO::open(&path).expect("wanted an rlib"); + let archive = ArchiveRO::open(path).expect("wanted an rlib"); let obj_files = archive .iter() .filter_map(|child| child.ok().and_then(|c| c.name().map(|name| (name, c)))) @@ -316,14 +316,14 @@ fn fat_lto( .generic_activity_with_arg("LLVM_fat_lto_link_module", format!("{:?}", name)); info!("linking {:?}", name); let data = bc_decoded.data(); - linker.add(&data).map_err(|()| { + linker.add(data).map_err(|()| { let msg = format!("failed to load bc of {:?}", name); - write::llvm_err(&diag_handler, &msg) + write::llvm_err(diag_handler, &msg) })?; serialized_bitcode.push(bc_decoded); } drop(linker); - save_temp_bitcode(&cgcx, &module, "lto.input"); + save_temp_bitcode(cgcx, &module, "lto.input"); // Fat LTO also suffers from the invalid DWARF issue similar to Thin LTO. // Here we rewrite all `DICompileUnit` pointers if there is only one `DICompileUnit`. @@ -347,14 +347,14 @@ fn fat_lto( ptr as *const *const libc::c_char, symbols_below_threshold.len() as libc::size_t, ); - save_temp_bitcode(&cgcx, &module, "lto.after-restriction"); + save_temp_bitcode(cgcx, &module, "lto.after-restriction"); } if cgcx.no_landing_pads { unsafe { llvm::LLVMRustMarkAllFunctionsNounwind(llmod); } - save_temp_bitcode(&cgcx, &module, "lto.after-nounwind"); + save_temp_bitcode(cgcx, &module, "lto.after-nounwind"); } } @@ -498,7 +498,7 @@ fn thin_lto( symbols_below_threshold.as_ptr(), symbols_below_threshold.len() as u32, ) - .ok_or_else(|| write::llvm_err(&diag_handler, "failed to prepare thin LTO context"))?; + .ok_or_else(|| write::llvm_err(diag_handler, "failed to prepare thin LTO context"))?; let data = ThinData(data); @@ -572,7 +572,7 @@ fn thin_lto( if let Some(path) = key_map_path { if let Err(err) = curr_key_map.save_to_file(&path) { let msg = format!("Error while writing ThinLTO key data: {}", err); - return Err(write::llvm_err(&diag_handler, &msg)); + return Err(write::llvm_err(diag_handler, &msg)); } } @@ -744,8 +744,7 @@ pub unsafe fn optimize_thin_module( // crates but for locally codegened modules we may be able to reuse // that LLVM Context and Module. let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names); - let llmod_raw = - parse_module(llcx, &module_name, thin_module.data(), &diag_handler)? as *const _; + let llmod_raw = parse_module(llcx, module_name, thin_module.data(), &diag_handler)? as *const _; let module = ModuleCodegen { module_llvm: ModuleLlvm { llmod_raw, llcx, tm }, name: thin_module.name().to_string(), @@ -754,7 +753,7 @@ pub unsafe fn optimize_thin_module( { let target = &*module.module_llvm.tm; let llmod = module.module_llvm.llmod(); - save_temp_bitcode(&cgcx, &module, "thin-lto-input"); + save_temp_bitcode(cgcx, &module, "thin-lto-input"); // Before we do much else find the "main" `DICompileUnit` that we'll be // using below. If we find more than one though then rustc has changed @@ -775,7 +774,7 @@ pub unsafe fn optimize_thin_module( .prof .generic_activity_with_arg("LLVM_thin_lto_remove_landing_pads", thin_module.name()); llvm::LLVMRustMarkAllFunctionsNounwind(llmod); - save_temp_bitcode(&cgcx, &module, "thin-lto-after-nounwind"); + save_temp_bitcode(cgcx, &module, "thin-lto-after-nounwind"); } // Up next comes the per-module local analyses that we do for Thin LTO. @@ -947,7 +946,7 @@ pub fn parse_module<'a>( llvm::LLVMRustParseBitcodeForLTO(cx, data.as_ptr(), data.len(), name.as_ptr()).ok_or_else( || { let msg = "failed to parse bitcode for LTO module"; - write::llvm_err(&diag_handler, msg) + write::llvm_err(diag_handler, msg) }, ) } diff --git a/compiler/rustc_codegen_llvm/src/back/write.rs b/compiler/rustc_codegen_llvm/src/back/write.rs index fd91eda4a01..ab48c56a626 100644 --- a/compiler/rustc_codegen_llvm/src/back/write.rs +++ b/compiler/rustc_codegen_llvm/src/back/write.rs @@ -41,7 +41,7 @@ use std::sync::Arc; pub fn llvm_err(handler: &rustc_errors::Handler, msg: &str) -> FatalError { match llvm::last_error() { Some(err) => handler.fatal(&format!("{}: {}", msg, err)), - None => handler.fatal(&msg), + None => handler.fatal(msg), } } @@ -96,7 +96,7 @@ pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> &'static mut ll None }; let config = TargetMachineFactoryConfig { split_dwarf_file }; - target_machine_factory(&tcx.sess, tcx.backend_optimization_level(()))(config) + target_machine_factory(tcx.sess, tcx.backend_optimization_level(()))(config) .unwrap_or_else(|err| llvm_err(tcx.sess.diagnostic(), &err).raise()) } @@ -558,7 +558,7 @@ pub(crate) unsafe fn optimize( let prepare_for_thin_lto = cgcx.lto == Lto::Thin || cgcx.lto == Lto::ThinLocal || (cgcx.lto != Lto::Fat && cgcx.opts.cg.linker_plugin_lto.enabled()); - with_llvm_pmb(llmod, &config, opt_level, prepare_for_thin_lto, &mut |b| { + with_llvm_pmb(llmod, config, opt_level, prepare_for_thin_lto, &mut |b| { llvm::LLVMRustAddLastExtensionPasses( b, extra_passes.as_ptr(), @@ -660,9 +660,9 @@ pub(crate) fn link( let _timer = cgcx.prof.generic_activity_with_arg("LLVM_link_module", format!("{:?}", module.name)); let buffer = ModuleBuffer::new(module.module_llvm.llmod()); - linker.add(&buffer.data()).map_err(|()| { + linker.add(buffer.data()).map_err(|()| { let msg = format!("failed to serialize module {:?}", module.name); - llvm_err(&diag_handler, &msg) + llvm_err(diag_handler, &msg) })?; } drop(linker); diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index dab7d3eaa8c..9f7b8616d78 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -86,7 +86,7 @@ impl ty::layout::HasParamEnv<'tcx> for Builder<'_, '_, 'tcx> { impl HasTargetSpec for Builder<'_, '_, 'tcx> { #[inline] fn target_spec(&self) -> &Target { - &self.cx.target_spec() + self.cx.target_spec() } } diff --git a/compiler/rustc_codegen_llvm/src/callee.rs b/compiler/rustc_codegen_llvm/src/callee.rs index a96ba148a6c..5d68d2b77d4 100644 --- a/compiler/rustc_codegen_llvm/src/callee.rs +++ b/compiler/rustc_codegen_llvm/src/callee.rs @@ -44,7 +44,7 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty()); - let llfn = if let Some(llfn) = cx.get_declared_value(&sym) { + let llfn = if let Some(llfn) = cx.get_declared_value(sym) { // Create a fn pointer with the new signature. let llptrty = fn_abi.ptr_to_llvm_type(cx); @@ -79,7 +79,7 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value llfn } } else { - let llfn = cx.declare_fn(&sym, &fn_abi); + let llfn = cx.declare_fn(sym, fn_abi); debug!("get_fn: not casting pointer!"); attributes::from_fn_attrs(cx, llfn, instance); diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index ef3a90fdeca..1afa6f02836 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -178,7 +178,7 @@ fn check_and_apply_linkage( }; unsafe { // Declare a symbol `foo` with the desired linkage. - let g1 = cx.declare_global(&sym, llty2); + let g1 = cx.declare_global(sym, llty2); llvm::LLVMRustSetLinkage(g1, base::linkage_to_llvm(linkage)); // Declare an internal global `extern_with_linkage_foo` which @@ -188,7 +188,7 @@ fn check_and_apply_linkage( // `extern_with_linkage_foo` will instead be initialized to // zero. let mut real_name = "_rust_extern_with_linkage_".to_string(); - real_name.push_str(&sym); + real_name.push_str(sym); let g2 = cx.define_global(&real_name, llty).unwrap_or_else(|| { cx.sess().span_fatal( cx.tcx.def_span(span_def_id), @@ -202,7 +202,7 @@ fn check_and_apply_linkage( } else { // Generate an external declaration. // FIXME(nagisa): investigate whether it can be changed into define_global - cx.declare_global(&sym, llty) + cx.declare_global(sym, llty) } } @@ -234,7 +234,7 @@ impl CodegenCx<'ll, 'tcx> { _ => self.define_private_global(self.val_ty(cv)), }; llvm::LLVMSetInitializer(gv, cv); - set_global_alignment(&self, gv, align); + set_global_alignment(self, gv, align); llvm::SetUnnamedAddress(gv, llvm::UnnamedAddr::Global); gv } @@ -279,7 +279,7 @@ impl CodegenCx<'ll, 'tcx> { g } else { - check_and_apply_linkage(&self, &fn_attrs, ty, sym, def_id) + check_and_apply_linkage(self, fn_attrs, ty, sym, def_id) }; // Thread-local statics in some other crate need to *always* be linked @@ -369,7 +369,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> { unsafe { let attrs = self.tcx.codegen_fn_attrs(def_id); - let (v, alloc) = match codegen_static_initializer(&self, def_id) { + let (v, alloc) = match codegen_static_initializer(self, def_id) { Ok(v) => v, // Error has already been reported Err(_) => return, @@ -417,7 +417,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> { self.statics_to_rauw.borrow_mut().push((g, new_g)); new_g }; - set_global_alignment(&self, g, self.align_of(ty)); + set_global_alignment(self, g, self.align_of(ty)); llvm::LLVMSetInitializer(g, v); if self.should_assume_dso_local(g, true) { @@ -430,7 +430,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> { llvm::LLVMSetGlobalConstant(g, llvm::True); } - debuginfo::create_global_var_metadata(&self, def_id, g); + debuginfo::create_global_var_metadata(self, def_id, g); if attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) { llvm::set_thread_local_mode(g, self.tls_model); @@ -518,7 +518,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> { ); } } else { - base::set_link_section(g, &attrs); + base::set_link_section(g, attrs); } if attrs.flags.contains(CodegenFnAttrFlags::USED) { diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 7bdbec11d60..257a0ac89d8 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -363,7 +363,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { fn create_used_variable_impl(&self, name: &'static CStr, values: &[&'ll Value]) { let section = cstr!("llvm.metadata"); - let array = self.const_array(&self.type_ptr_to(self.type_i8()), values); + let array = self.const_array(self.type_ptr_to(self.type_i8()), values); unsafe { let g = llvm::LLVMAddGlobal(self.llmod, self.val_ty(array), name.as_ptr()); @@ -447,7 +447,7 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> { } fn sess(&self) -> &Session { - &self.tcx.sess + self.tcx.sess } fn check_overflow(&self) -> bool { diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs index d2a2e739ff3..6830864ba04 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs @@ -73,7 +73,7 @@ pub fn finalize<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) { mapgen.write_coverage_mapping(expressions, counter_regions, coverage_mapping_buffer); }); debug_assert!( - coverage_mapping_buffer.len() > 0, + !coverage_mapping_buffer.is_empty(), "Every `FunctionCoverage` should have at least one counter" ); @@ -311,8 +311,7 @@ fn add_unused_functions<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) { // for each region in it's MIR. // Convert the `HashSet` of `codegenned_def_ids` to a sortable vector, and sort them. - let mut sorted_codegenned_def_ids: Vec<DefId> = - codegenned_def_ids.iter().map(|def_id| *def_id).collect(); + let mut sorted_codegenned_def_ids: Vec<DefId> = codegenned_def_ids.iter().copied().collect(); sorted_codegenned_def_ids.sort_unstable(); let mut first_covered_def_id_by_file: FxHashMap<Symbol, DefId> = FxHashMap::default(); diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs index 093aceda2b7..ef11e2972ea 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs @@ -199,8 +199,8 @@ fn declare_unused_fn(cx: &CodegenCx<'ll, 'tcx>, def_id: &DefId) -> Instance<'tcx ); let llfn = cx.declare_fn( - &tcx.symbol_name(instance).name, - &cx.fn_abi_of_fn_ptr( + tcx.symbol_name(instance).name, + cx.fn_abi_of_fn_ptr( ty::Binder::dummy(tcx.mk_fn_sig( iter::once(tcx.mk_unit()), tcx.mk_unit(), 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 1612922d439..58f8573a2ac 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs @@ -41,7 +41,7 @@ pub fn compute_mir_scopes( // Instantiate all scopes. for idx in 0..mir.source_scopes.len() { let scope = SourceScope::new(idx); - make_mir_scope(cx, instance, &mir, fn_dbg_scope, &has_variables, debug_context, scope); + make_mir_scope(cx, instance, mir, fn_dbg_scope, &has_variables, debug_context, scope); } } @@ -94,7 +94,7 @@ fn make_mir_scope( callee, ); let callee_fn_abi = cx.fn_abi_of_instance(callee, ty::List::empty()); - cx.dbg_scope_fn(callee, &callee_fn_abi, None) + cx.dbg_scope_fn(callee, callee_fn_abi, None) } None => unsafe { llvm::LLVMRustDIBuilderCreateLexicalBlock( diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs index c33d35cc285..ae1f83d944f 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs @@ -59,10 +59,8 @@ pub fn get_or_insert_gdb_debug_scripts_section_global(cx: &CodegenCx<'ll, '_>) - } pub fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool { - let omit_gdb_pretty_printer_section = cx - .tcx - .sess - .contains_name(&cx.tcx.hir().krate_attrs(), sym::omit_gdb_pretty_printer_section); + let omit_gdb_pretty_printer_section = + cx.tcx.sess.contains_name(cx.tcx.hir().krate_attrs(), sym::omit_gdb_pretty_printer_section); !omit_gdb_pretty_printer_section && cx.sess().opts.debuginfo != DebugInfo::None diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 9272435a330..f6ec5e6395f 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -477,7 +477,7 @@ fn subroutine_type_metadata( let signature_metadata: Vec<_> = iter::once( // return type match signature.output().kind() { - ty::Tuple(ref tys) if tys.is_empty() => None, + ty::Tuple(tys) if tys.is_empty() => None, _ => Some(type_metadata(cx, signature.output(), span)), }, ) @@ -647,7 +647,7 @@ pub fn type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>, usage_site_span: Sp ty::Never | ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) => { MetadataCreationResult::new(basic_type_metadata(cx, t), false) } - ty::Tuple(ref elements) if elements.is_empty() => { + ty::Tuple(elements) if elements.is_empty() => { MetadataCreationResult::new(basic_type_metadata(cx, t), false) } ty::Array(typ, _) | ty::Slice(typ) => { @@ -746,7 +746,7 @@ pub fn type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>, usage_site_span: Sp .finalize(cx) } }, - ty::Tuple(ref elements) => { + ty::Tuple(elements) => { let tys: Vec<_> = elements.iter().map(|k| k.expect_ty()).collect(); prepare_tuple_metadata(cx, t, &tys, unique_type_id, usage_site_span, NO_SCOPE_METADATA) .finalize(cx) @@ -932,7 +932,7 @@ fn basic_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType { let (name, encoding) = match t.kind() { ty::Never => ("!", DW_ATE_unsigned), - ty::Tuple(ref elements) if elements.is_empty() => ("()", DW_ATE_unsigned), + ty::Tuple(elements) if elements.is_empty() => ("()", DW_ATE_unsigned), ty::Bool => ("bool", DW_ATE_boolean), ty::Char => ("char", DW_ATE_unsigned_char), ty::Int(int_ty) if msvc_like_names => (int_ty.msvc_basic_name(), DW_ATE_signed), @@ -1123,7 +1123,7 @@ pub fn compile_unit_metadata( let gcov_cu_info = [ path_to_mdstring(debug_context.llcontext, &output_filenames.with_extension("gcno")), - path_to_mdstring(debug_context.llcontext, &gcda_path), + path_to_mdstring(debug_context.llcontext, gcda_path), cu_desc_metadata, ]; let gcov_metadata = llvm::LLVMMDNodeInContext( @@ -1963,17 +1963,13 @@ impl<'tcx> VariantInfo<'_, 'tcx> { } fn source_info(&self, cx: &CodegenCx<'ll, 'tcx>) -> Option<SourceInfo<'ll>> { - match self { - VariantInfo::Generator { def_id, variant_index, .. } => { - let span = cx.tcx.generator_layout(*def_id).unwrap().variant_source_info - [*variant_index] - .span; - if !span.is_dummy() { - let loc = cx.lookup_debug_loc(span.lo()); - return Some(SourceInfo { file: file_metadata(cx, &loc.file), line: loc.line }); - } + if let VariantInfo::Generator { def_id, variant_index, .. } = self { + let span = + cx.tcx.generator_layout(*def_id).unwrap().variant_source_info[*variant_index].span; + if !span.is_dummy() { + let loc = cx.lookup_debug_loc(span.lo()); + return Some(SourceInfo { file: file_metadata(cx, &loc.file), line: loc.line }); } - _ => {} } None } @@ -1994,11 +1990,11 @@ fn describe_enum_variant( let unique_type_id = debug_context(cx) .type_map .borrow_mut() - .get_unique_type_id_of_enum_variant(cx, layout.ty, &variant_name); + .get_unique_type_id_of_enum_variant(cx, layout.ty, variant_name); create_struct_stub( cx, layout.ty, - &variant_name, + variant_name, unique_type_id, Some(containing_scope), DIFlags::FlagZero, @@ -2385,7 +2381,7 @@ fn set_members_of_composite_type( { let mut composite_types_completed = debug_context(cx).composite_types_completed.borrow_mut(); - if !composite_types_completed.insert(&composite_type_metadata) { + if !composite_types_completed.insert(composite_type_metadata) { bug!( "debuginfo::set_members_of_composite_type() - \ Already completed forward declaration re-encountered." diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index fbaf8c8bdf6..894320a7982 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -328,7 +328,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { // name if necessary. let generics = self.tcx().generics_of(enclosing_fn_def_id); let substs = instance.substs.truncate_to(self.tcx(), generics); - let template_parameters = get_template_parameters(self, &generics, substs, &mut name); + let template_parameters = get_template_parameters(self, generics, substs, &mut name); let linkage_name = &mangled_name_of_instance(self, instance).name; // Omit the linkage_name if it is the same as subprogram name. @@ -559,7 +559,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { scope_metadata: &'ll DIScope, file: &rustc_span::SourceFile, ) -> &'ll DILexicalBlock { - metadata::extend_scope_to_file(&self, scope_metadata, file) + metadata::extend_scope_to_file(self, scope_metadata, file) } fn debuginfo_finalize(&self) { diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index be55a0c868a..22dc8d101c8 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -71,7 +71,7 @@ fn get_simple_intrinsic(cx: &CodegenCx<'ll, '_>, name: Symbol) -> Option<(&'ll T sym::roundf64 => "llvm.round.f64", _ => return None, }; - Some(cx.get_intrinsic(&llvm_name)) + Some(cx.get_intrinsic(llvm_name)) } impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> { @@ -743,7 +743,7 @@ fn gen_fn<'ll, 'tcx>( ) -> (&'ll Type, &'ll Value) { let fn_abi = cx.fn_abi_of_fn_ptr(rust_fn_sig, ty::List::empty()); let llty = fn_abi.llvm_type(cx); - let llfn = cx.declare_fn(name, &fn_abi); + let llfn = cx.declare_fn(name, fn_abi); cx.set_frame_pointer_type(llfn); cx.apply_target_cpu_attr(llfn); // FIXME(eddyb) find a nicer way to do this. @@ -1159,7 +1159,7 @@ fn generic_simd_intrinsic( _ => return_error!("unrecognized intrinsic `{}`", name), }; let llvm_name = &format!("llvm.{0}.v{1}{2}", intr_name, in_len, elem_ty_str); - let f = bx.declare_cfn(&llvm_name, llvm::UnnamedAddr::No, fn_ty); + let f = bx.declare_cfn(llvm_name, llvm::UnnamedAddr::No, fn_ty); let c = bx.call(fn_ty, f, &args.iter().map(|arg| arg.immediate()).collect::<Vec<_>>(), None); Ok(c) @@ -1793,7 +1793,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#, let vec_ty = bx.cx.type_vector(elem_ty, in_len as u64); let fn_ty = bx.type_func(&[vec_ty, vec_ty], vec_ty); - let f = bx.declare_cfn(&llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty); + let f = bx.declare_cfn(llvm_intrinsic, llvm::UnnamedAddr::No, fn_ty); let v = bx.call(fn_ty, f, &[lhs, rhs], None); return Ok(v); } diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index c44cc656056..8f4d79e7147 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -339,7 +339,7 @@ impl ModuleLlvm { unsafe { let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names); let llmod_raw = back::lto::parse_module(llcx, name, buffer, handler)?; - let tm_factory_config = TargetMachineFactoryConfig::new(&cgcx, name.to_str().unwrap()); + let tm_factory_config = TargetMachineFactoryConfig::new(cgcx, name.to_str().unwrap()); let tm = match (cgcx.tm_factory)(tm_factory_config) { Ok(m) => m, Err(e) => { diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index d8c2a345fb0..436d906827b 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -789,7 +789,7 @@ pub mod coverageinfo { start_line, start_col, end_line, - end_col: ((1 as u32) << 31) | end_col, + end_col: (1_u32 << 31) | end_col, kind: RegionKind::GapRegion, } } diff --git a/compiler/rustc_codegen_llvm/src/llvm_util.rs b/compiler/rustc_codegen_llvm/src/llvm_util.rs index f9172e43773..c5deb11edd0 100644 --- a/compiler/rustc_codegen_llvm/src/llvm_util.rs +++ b/compiler/rustc_codegen_llvm/src/llvm_util.rs @@ -298,7 +298,7 @@ fn print_target_features(sess: &Session, tm: &llvm::TargetMachine) { for (feature, desc) in &target_features { println!(" {1:0$} - {2}.", max_feature_len, feature, desc); } - if target_features.len() == 0 { + if target_features.is_empty() { println!(" Target features listing is not supported by this LLVM version."); } println!("\nUse +feature to enable a feature, or -feature to disable it."); diff --git a/compiler/rustc_codegen_llvm/src/mono_item.rs b/compiler/rustc_codegen_llvm/src/mono_item.rs index b9022a391e6..88498cf47d8 100644 --- a/compiler/rustc_codegen_llvm/src/mono_item.rs +++ b/compiler/rustc_codegen_llvm/src/mono_item.rs @@ -53,10 +53,10 @@ impl PreDefineMethods<'tcx> for CodegenCx<'ll, 'tcx> { assert!(!instance.substs.needs_infer()); let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty()); - let lldecl = self.declare_fn(symbol_name, &fn_abi); + let lldecl = self.declare_fn(symbol_name, fn_abi); unsafe { llvm::LLVMRustSetLinkage(lldecl, base::linkage_to_llvm(linkage)) }; let attrs = self.tcx.codegen_fn_attrs(instance.def_id()); - base::set_link_section(lldecl, &attrs); + base::set_link_section(lldecl, attrs); if linkage == Linkage::LinkOnceODR || linkage == Linkage::WeakODR { llvm::SetUniqueComdat(self.llmod, lldecl); } @@ -145,10 +145,6 @@ impl CodegenCx<'ll, 'tcx> { // With pie relocation model calls of functions defined in the translation // unit can use copy relocations. - if self.tcx.sess.relocation_model() == RelocModel::Pie && !is_declaration { - return true; - } - - return false; + self.tcx.sess.relocation_model() == RelocModel::Pie && !is_declaration } } diff --git a/compiler/rustc_codegen_llvm/src/type_.rs b/compiler/rustc_codegen_llvm/src/type_.rs index c7f4287e28e..2ae0a08f192 100644 --- a/compiler/rustc_codegen_llvm/src/type_.rs +++ b/compiler/rustc_codegen_llvm/src/type_.rs @@ -248,7 +248,7 @@ impl Type { } fn ptr_to(&self, address_space: AddressSpace) -> &Type { - unsafe { llvm::LLVMPointerType(&self, address_space.0) } + unsafe { llvm::LLVMPointerType(self, address_space.0) } } } diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs index 9e03fc33ae0..f8c919ec2aa 100644 --- a/compiler/rustc_codegen_llvm/src/type_of.rs +++ b/compiler/rustc_codegen_llvm/src/type_of.rs @@ -232,7 +232,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { cx.type_ptr_to(cx.layout_of(self.ty.boxed_ty()).llvm_type(cx)) } ty::FnPtr(sig) => { - cx.fn_ptr_backend_type(&cx.fn_abi_of_fn_ptr(sig, ty::List::empty())) + cx.fn_ptr_backend_type(cx.fn_abi_of_fn_ptr(sig, ty::List::empty())) } _ => self.scalar_llvm_type_at(cx, scalar, Size::ZERO), }; @@ -245,7 +245,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { Variants::Single { index } => Some(index), _ => None, }; - if let Some(ref llty) = cx.type_lowering.borrow().get(&(self.ty, variant_index)) { + if let Some(llty) = cx.type_lowering.borrow().get(&(self.ty, variant_index)) { return llty.lltype; } @@ -270,10 +270,9 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { }; debug!("--> mapped {:#?} to llty={:?}", self, llty); - cx.type_lowering.borrow_mut().insert( - (self.ty, variant_index), - TypeLowering { lltype: llty, field_remapping: field_remapping }, - ); + cx.type_lowering + .borrow_mut() + .insert((self.ty, variant_index), TypeLowering { lltype: llty, field_remapping }); if let Some((llty, layout)) = defer { let (llfields, packed, new_field_remapping) = struct_llfields(cx, layout); diff --git a/compiler/rustc_codegen_llvm/src/va_arg.rs b/compiler/rustc_codegen_llvm/src/va_arg.rs index caafae6c267..591f659f11b 100644 --- a/compiler/rustc_codegen_llvm/src/va_arg.rs +++ b/compiler/rustc_codegen_llvm/src/va_arg.rs @@ -125,7 +125,7 @@ fn emit_aapcs_va_arg( // if the offset >= 0 then the value will be on the stack let mut reg_off_v = bx.load(bx.type_i32(), reg_off, offset_align); let use_stack = bx.icmp(IntPredicate::IntSGE, reg_off_v, zero); - bx.cond_br(use_stack, &on_stack.llbb(), &maybe_reg.llbb()); + bx.cond_br(use_stack, on_stack.llbb(), maybe_reg.llbb()); // The value at this point might be in a register, but there is a chance that // it could be on the stack so we have to update the offset and then check @@ -142,7 +142,7 @@ fn emit_aapcs_va_arg( // Check to see if we have overflowed the registers as a result of this. // If we have then we need to use the stack for this value let use_stack = maybe_reg.icmp(IntPredicate::IntSGT, new_reg_off_v, zero); - maybe_reg.cond_br(use_stack, &on_stack.llbb(), &in_reg.llbb()); + maybe_reg.cond_br(use_stack, on_stack.llbb(), in_reg.llbb()); let top_type = bx.type_i8p(); let top = in_reg.struct_gep(va_list_ty, va_list_addr, reg_top_index); @@ -158,17 +158,17 @@ fn emit_aapcs_va_arg( let reg_type = layout.llvm_type(bx); let reg_addr = in_reg.bitcast(reg_addr, bx.cx.type_ptr_to(reg_type)); let reg_value = in_reg.load(reg_type, reg_addr, layout.align.abi); - in_reg.br(&end.llbb()); + in_reg.br(end.llbb()); // On Stack block let stack_value = emit_ptr_va_arg(&mut on_stack, list, target_ty, false, Align::from_bytes(8).unwrap(), true); - on_stack.br(&end.llbb()); + on_stack.br(end.llbb()); let val = end.phi( layout.immediate_llvm_type(bx), &[reg_value, stack_value], - &[&in_reg.llbb(), &on_stack.llbb()], + &[in_reg.llbb(), on_stack.llbb()], ); *bx = end; diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs index 4c6a2baaef1..7fd7f6b1340 100644 --- a/compiler/rustc_driver/src/lib.rs +++ b/compiler/rustc_driver/src/lib.rs @@ -128,7 +128,7 @@ impl Callbacks for TimePassesCallbacks { } pub fn diagnostics_registry() -> Registry { - Registry::new(&rustc_error_codes::DIAGNOSTICS) + Registry::new(rustc_error_codes::DIAGNOSTICS) } /// This is the primary entry point for rustc. @@ -265,8 +265,8 @@ fn run_compiler( &***compiler.codegen_backend(), compiler.session(), None, - &compiler.output_dir(), - &compiler.output_file(), + compiler.output_dir(), + compiler.output_file(), ); if should_stop == Compilation::Stop { @@ -330,7 +330,7 @@ fn run_compiler( let krate = queries.parse()?.take(); pretty::print_after_parsing( sess, - &compiler.input(), + compiler.input(), &krate, *ppm, compiler.output_file().as_ref().map(|p| &**p), @@ -356,7 +356,7 @@ fn run_compiler( // Lint plugins are registered; now we can process command line flags. if sess.opts.describe_lints { - describe_lints(&sess, &lint_store, true); + describe_lints(sess, lint_store, true); return early_exit(); } } @@ -388,7 +388,7 @@ fn run_compiler( save::process_crate( tcx, &crate_name, - &compiler.input(), + compiler.input(), None, DumpHandler::new( compiler.output_dir().as_ref().map(|p| &**p), @@ -598,7 +598,7 @@ impl RustcDefaultCalls { if let Input::File(file) = compiler.input() { // FIXME: #![crate_type] and #![crate_name] support not implemented yet sess.init_crate_types(collect_crate_types(sess, &[])); - let outputs = compiler.build_output_filenames(&sess, &[]); + let outputs = compiler.build_output_filenames(sess, &[]); let rlink_data = fs::read_to_string(file).unwrap_or_else(|err| { sess.fatal(&format!("failed to read rlink file: {}", err)); }); @@ -606,7 +606,7 @@ impl RustcDefaultCalls { json::decode(&rlink_data).unwrap_or_else(|err| { sess.fatal(&format!("failed to decode rlink: {}", err)); }); - let result = compiler.codegen_backend().link(&sess, codegen_results, &outputs); + let result = compiler.codegen_backend().link(sess, codegen_results, &outputs); abort_on_err(result, sess); } else { sess.fatal("rlink must be a file") @@ -894,9 +894,9 @@ Available lint options: }; println!("Lint groups provided by rustc:\n"); - println!(" {} {}", padded("name"), "sub-lints"); - println!(" {} {}", padded("----"), "---------"); - println!(" {} {}", padded("warnings"), "all lints that are set to issue warnings"); + println!(" {} sub-lints", padded("name")); + println!(" {} ---------", padded("----")); + println!(" {} all lints that are set to issue warnings", padded("warnings")); let print_lint_groups = |lints: Vec<(&'static str, Vec<LintId>)>| { for (name, to) in lints { @@ -1217,7 +1217,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) { } for note in &xs { - handler.note_without_error(¬e); + handler.note_without_error(note); } // If backtraces are enabled, also print the query stack @@ -1326,7 +1326,7 @@ mod signal_handler { std::alloc::alloc(std::alloc::Layout::from_size_align(ALT_STACK_SIZE, 1).unwrap()) as *mut libc::c_void; alt_stack.ss_size = ALT_STACK_SIZE; - libc::sigaltstack(&mut alt_stack, std::ptr::null_mut()); + libc::sigaltstack(&alt_stack, std::ptr::null_mut()); let mut sa: libc::sigaction = std::mem::zeroed(); sa.sa_sigaction = print_stack_trace as libc::sighandler_t; diff --git a/compiler/rustc_driver/src/pretty.rs b/compiler/rustc_driver/src/pretty.rs index ff8920863b1..e52eef0fcbd 100644 --- a/compiler/rustc_driver/src/pretty.rs +++ b/compiler/rustc_driver/src/pretty.rs @@ -296,7 +296,7 @@ struct TypedAnnotation<'tcx> { impl<'tcx> HirPrinterSupport<'tcx> for TypedAnnotation<'tcx> { fn sess(&self) -> &Session { - &self.tcx.sess + self.tcx.sess } fn hir_map(&self) -> Option<hir_map::Map<'tcx>> { @@ -347,8 +347,7 @@ impl<'tcx> pprust_hir::PpAnn for TypedAnnotation<'tcx> { fn get_source(input: &Input, sess: &Session) -> (String, FileName) { let src_name = input.source_name(); let src = String::clone( - &sess - .source_map() + sess.source_map() .get_source_file(&src_name) .expect("get_source_file") .src diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 45dd8868d6c..c44d4361f03 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2533,7 +2533,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { /// within `?` desugaring. pub fn is_try_conversion(&self, span: Span, trait_def_id: DefId) -> bool { span.is_desugaring(DesugaringKind::QuestionMark) - && self.tcx.is_diagnostic_item(sym::from_trait, trait_def_id) + && self.tcx.is_diagnostic_item(sym::From, trait_def_id) } } diff --git a/compiler/rustc_interface/src/callbacks.rs b/compiler/rustc_interface/src/callbacks.rs index 95bd2993456..3c7908fae79 100644 --- a/compiler/rustc_interface/src/callbacks.rs +++ b/compiler/rustc_interface/src/callbacks.rs @@ -41,7 +41,7 @@ fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) { fn track_diagnostic(diagnostic: &Diagnostic) { tls::with_context_opt(|icx| { if let Some(icx) = icx { - if let Some(ref diagnostics) = icx.diagnostics { + if let Some(diagnostics) = icx.diagnostics { let mut diagnostics = diagnostics.lock(); diagnostics.extend(Some(diagnostic.clone())); } diff --git a/compiler/rustc_interface/src/interface.rs b/compiler/rustc_interface/src/interface.rs index 8393826aa12..0861bd290df 100644 --- a/compiler/rustc_interface/src/interface.rs +++ b/compiler/rustc_interface/src/interface.rs @@ -65,13 +65,7 @@ impl Compiler { sess: &Session, attrs: &[ast::Attribute], ) -> OutputFilenames { - util::build_output_filenames( - &self.input, - &self.output_dir, - &self.output_file, - &attrs, - &sess, - ) + util::build_output_filenames(&self.input, &self.output_dir, &self.output_file, attrs, sess) } } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 25a110e0297..a221746f975 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -169,7 +169,7 @@ pub fn create_resolver( ) -> BoxedResolver { tracing::trace!("create_resolver"); BoxedResolver::new(sess, move |sess, resolver_arenas| { - Resolver::new(sess, &krate, &crate_name, metadata_loader, &resolver_arenas) + Resolver::new(sess, krate, crate_name, metadata_loader, resolver_arenas) }) } @@ -201,7 +201,7 @@ pub fn register_plugins<'a>( sess.opts.cg.metadata.clone(), ); sess.stable_crate_id.set(stable_crate_id).expect("not yet initialized"); - rustc_incremental::prepare_session_directory(sess, &crate_name, stable_crate_id)?; + rustc_incremental::prepare_session_directory(sess, crate_name, stable_crate_id)?; if sess.opts.incremental.is_some() { sess.time("incr_comp_garbage_collect_session_directories", || { @@ -219,7 +219,7 @@ pub fn register_plugins<'a>( sess.opts.debugging_opts.no_interleave_lints, sess.unstable_options(), ); - register_lints(&sess, &mut lint_store); + register_lints(sess, &mut lint_store); let registrars = sess.time("plugin_loading", || plugin::load::load_plugins(sess, metadata_loader, &krate)); @@ -244,7 +244,7 @@ fn pre_expansion_lint( rustc_lint::check_ast_crate( sess, lint_store, - &krate, + krate, crate_attrs, true, None, @@ -270,10 +270,10 @@ pub fn configure_and_expand( krate = sess.time("crate_injection", || { let alt_std_name = sess.opts.alt_std_name.as_ref().map(|s| Symbol::intern(s)); - rustc_builtin_macros::standard_library_imports::inject(krate, resolver, &sess, alt_std_name) + rustc_builtin_macros::standard_library_imports::inject(krate, resolver, sess, alt_std_name) }); - util::check_attr_crate_type(&sess, &krate.attrs, &mut resolver.lint_buffer()); + util::check_attr_crate_type(sess, &krate.attrs, &mut resolver.lint_buffer()); // Expand all macros krate = sess.time("macro_expand_crate", || { @@ -310,9 +310,9 @@ pub fn configure_and_expand( // Create the config for macro expansion let features = sess.features_untracked(); - let recursion_limit = get_recursion_limit(&krate.attrs, &sess); + let recursion_limit = get_recursion_limit(&krate.attrs, sess); let cfg = rustc_expand::expand::ExpansionConfig { - features: Some(&features), + features: Some(features), recursion_limit, trace_mac: sess.opts.debugging_opts.trace_macros, should_test: sess.opts.test, @@ -327,7 +327,7 @@ pub fn configure_and_expand( pre_expansion_lint(sess, lint_store, &krate, &crate_attrs, &ident.name.as_str()); (krate.attrs, krate.items) }; - let mut ecx = ExtCtxt::new(&sess, cfg, resolver, Some(&extern_mod_loaded)); + let mut ecx = ExtCtxt::new(sess, cfg, resolver, Some(&extern_mod_loaded)); // Expand macros now! let krate = sess.time("expand_crate", || ecx.monotonic_expander().expand_crate(krate)); @@ -369,7 +369,7 @@ pub fn configure_and_expand( })?; sess.time("maybe_building_test_harness", || { - rustc_builtin_macros::test_harness::inject(&sess, resolver, &mut krate) + rustc_builtin_macros::test_harness::inject(sess, resolver, &mut krate) }); if let Some(PpMode::Source(PpSourceMode::EveryBodyLoops)) = sess.opts.pretty { @@ -392,8 +392,8 @@ pub fn configure_and_expand( // start passing '--crate-type proc-macro' if has_proc_macro_decls && sess.opts.actually_rustdoc && !is_proc_macro_crate { let mut msg = sess.diagnostic().struct_warn( - &"Trying to document proc macro crate \ - without passing '--crate-type proc-macro to rustdoc", + "Trying to document proc macro crate \ + without passing '--crate-type proc-macro to rustdoc", ); msg.warn("The generated documentation may be incorrect"); @@ -403,7 +403,7 @@ pub fn configure_and_expand( let num_crate_types = crate_types.len(); let is_test_crate = sess.opts.test; rustc_builtin_macros::proc_macro_harness::inject( - &sess, + sess, resolver, krate, is_proc_macro_crate, @@ -691,7 +691,7 @@ pub fn prepare_outputs( ); let output_paths = - generated_output_paths(sess, &outputs, compiler.output_file.is_some(), &crate_name); + generated_output_paths(sess, &outputs, compiler.output_file.is_some(), crate_name); // Ensure the source file isn't accidentally overwritten during compilation. if let Some(ref input_path) = compiler.input_path { @@ -832,7 +832,7 @@ pub fn create_global_ctxt<'tcx>( dep_graph, queries.on_disk_cache.as_ref().map(OnDiskCache::as_dyn), queries.as_dyn(), - &crate_name, + crate_name, outputs, ) }) diff --git a/compiler/rustc_interface/src/queries.rs b/compiler/rustc_interface/src/queries.rs index a71b59b9d49..f188ad35605 100644 --- a/compiler/rustc_interface/src/queries.rs +++ b/compiler/rustc_interface/src/queries.rs @@ -110,7 +110,7 @@ impl<'tcx> Queries<'tcx> { &self.compiler.sess } fn codegen_backend(&self) -> &Lrc<Box<dyn CodegenBackend>> { - &self.compiler.codegen_backend() + self.compiler.codegen_backend() } fn dep_graph_future(&self) -> Result<&Query<Option<DepGraphFuture>>> { @@ -181,7 +181,7 @@ impl<'tcx> Queries<'tcx> { &crate_name, ); let krate = resolver.access(|resolver| { - passes::configure_and_expand(&sess, &lint_store, krate, &crate_name, resolver) + passes::configure_and_expand(sess, &lint_store, krate, &crate_name, resolver) })?; Ok((Rc::new(krate), Rc::new(RefCell::new(resolver)), lint_store)) }) @@ -343,7 +343,7 @@ impl Linker { let sess = &self.sess; let dep_graph = self.dep_graph; sess.time("serialize_work_products", || { - rustc_incremental::save_work_product_index(&sess, &dep_graph, work_products) + rustc_incremental::save_work_product_index(sess, &dep_graph, work_products) }); let prof = self.sess.prof.clone(); @@ -386,7 +386,7 @@ impl Compiler { F: for<'tcx> FnOnce(&'tcx Queries<'tcx>) -> T, { let mut _timer = None; - let queries = Queries::new(&self); + let queries = Queries::new(self); let ret = f(&queries); // NOTE: intentionally does not compute the global context if it hasn't been built yet, diff --git a/compiler/rustc_interface/src/util.rs b/compiler/rustc_interface/src/util.rs index a1d1b63c8fa..cffb087af18 100644 --- a/compiler/rustc_interface/src/util.rs +++ b/compiler/rustc_interface/src/util.rs @@ -402,7 +402,7 @@ pub fn get_codegen_sysroot( .iter() .chain(sysroot_candidates.iter()) .map(|sysroot| { - filesearch::make_target_lib_path(&sysroot, &target).with_file_name("codegen-backends") + filesearch::make_target_lib_path(sysroot, target).with_file_name("codegen-backends") }) .find(|f| { info!("codegen backend candidate: {}", f.display()); @@ -619,7 +619,7 @@ pub fn build_output_filenames( .opts .crate_name .clone() - .or_else(|| rustc_attr::find_crate_name(&sess, attrs).map(|n| n.to_string())) + .or_else(|| rustc_attr::find_crate_name(sess, attrs).map(|n| n.to_string())) .unwrap_or_else(|| input.filestem().to_owned()); OutputFilenames::new( diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 4513c8329ca..9b6493222e6 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -812,7 +812,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations { _ => return, } - let debug = match cx.tcx.get_diagnostic_item(sym::debug_trait) { + let debug = match cx.tcx.get_diagnostic_item(sym::Debug) { Some(debug) => debug, None => return, }; diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 8a4a7089437..a4940e5aae7 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -33,9 +33,9 @@ impl LateLintPass<'_> for DefaultHashTypes { // don't lint imports, only actual usages return; } - let replace = if cx.tcx.is_diagnostic_item(sym::hashmap_type, def_id) { + let replace = if cx.tcx.is_diagnostic_item(sym::HashMap, def_id) { "FxHashMap" - } else if cx.tcx.is_diagnostic_item(sym::hashset_type, def_id) { + } else if cx.tcx.is_diagnostic_item(sym::HashSet, def_id) { "FxHashSet" } else { return; diff --git a/compiler/rustc_lint/src/methods.rs b/compiler/rustc_lint/src/methods.rs index 8732845af0c..5558947de0c 100644 --- a/compiler/rustc_lint/src/methods.rs +++ b/compiler/rustc_lint/src/methods.rs @@ -84,7 +84,7 @@ fn lint_cstring_as_ptr( ) { let source_type = cx.typeck_results().expr_ty(source); if let ty::Adt(def, substs) = source_type.kind() { - if cx.tcx.is_diagnostic_item(sym::result_type, def.did) { + if cx.tcx.is_diagnostic_item(sym::Result, def.did) { if let ty::Adt(adt, _) = substs.type_at(0).kind() { if cx.tcx.is_diagnostic_item(sym::cstring_type, adt.did) { cx.struct_span_lint(TEMPORARY_CSTRING_AS_PTR, as_ptr_span, |diag| { diff --git a/compiler/rustc_lint/src/non_fmt_panic.rs b/compiler/rustc_lint/src/non_fmt_panic.rs index ae9c5ce5c3c..b945c764320 100644 --- a/compiler/rustc_lint/src/non_fmt_panic.rs +++ b/compiler/rustc_lint/src/non_fmt_panic.rs @@ -130,14 +130,14 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc ty::Ref(_, r, _) if *r.kind() == ty::Str, ) || matches!( ty.ty_adt_def(), - Some(ty_def) if cx.tcx.is_diagnostic_item(sym::string_type, ty_def.did), + Some(ty_def) if cx.tcx.is_diagnostic_item(sym::String, ty_def.did), ); let (suggest_display, suggest_debug) = cx.tcx.infer_ctxt().enter(|infcx| { - let display = is_str || cx.tcx.get_diagnostic_item(sym::display_trait).map(|t| { + let display = is_str || cx.tcx.get_diagnostic_item(sym::Display).map(|t| { infcx.type_implements_trait(t, ty, InternalSubsts::empty(), cx.param_env).may_apply() }) == Some(true); - let debug = !display && cx.tcx.get_diagnostic_item(sym::debug_trait).map(|t| { + let debug = !display && cx.tcx.get_diagnostic_item(sym::Debug).map(|t| { infcx.type_implements_trait(t, ty, InternalSubsts::empty(), cx.param_env).may_apply() }) == Some(true); (display, debug) diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index d35497c1b38..ac4bffc239b 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -1056,6 +1056,15 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { FfiSafe } + ty::RawPtr(ty::TypeAndMut { ty, .. }) + if match ty.kind() { + ty::Tuple(tuple) => tuple.is_empty(), + _ => false, + } => + { + FfiSafe + } + ty::RawPtr(ty::TypeAndMut { ty, .. }) | ty::Ref(_, ty, _) => { self.check_type_for_ffi(cache, ty) } diff --git a/compiler/rustc_llvm/src/lib.rs b/compiler/rustc_llvm/src/lib.rs index 2f199989d3b..6493bd91ca2 100644 --- a/compiler/rustc_llvm/src/lib.rs +++ b/compiler/rustc_llvm/src/lib.rs @@ -17,6 +17,10 @@ impl RustString { pub fn len(&self) -> usize { self.bytes.borrow().len() } + + pub fn is_empty(&self) -> bool { + self.bytes.borrow().is_empty() + } } /// Appending to a Rust string -- used by RawRustStringOstream. diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index a2211f4c3b2..f8a476266d6 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2408,7 +2408,7 @@ fn for_each_def(tcx: TyCtxt<'_>, mut collect_fn: impl for<'b> FnMut(&'b Ident, N /// /// The implementation uses similar import discovery logic to that of 'use' suggestions. fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> FxHashMap<DefId, Symbol> { - let mut map = FxHashMap::default(); + let mut map: FxHashMap<DefId, Symbol> = FxHashMap::default(); if let TrimmedDefPaths::GoodPath = tcx.sess.opts.trimmed_def_paths { // For good paths causing this bug, the `rustc_middle::ty::print::with_no_trimmed_paths` @@ -2446,8 +2446,29 @@ fn trimmed_def_paths(tcx: TyCtxt<'_>, (): ()) -> FxHashMap<DefId, Symbol> { }); for ((_, symbol), opt_def_id) in unique_symbols_rev.drain() { + use std::collections::hash_map::Entry::{Occupied, Vacant}; + if let Some(def_id) = opt_def_id { - map.insert(def_id, symbol); + match map.entry(def_id) { + Occupied(mut v) => { + // A single DefId can be known under multiple names (e.g., + // with a `pub use ... as ...;`). We need to ensure that the + // name placed in this map is chosen deterministically, so + // if we find multiple names (`symbol`) resolving to the + // same `def_id`, we prefer the lexicographically smallest + // name. + // + // Any stable ordering would be fine here though. + if *v.get() != symbol { + if v.get().as_str() > symbol.as_str() { + v.insert(symbol); + } + } + } + Vacant(v) => { + v.insert(symbol); + } + } } } diff --git a/compiler/rustc_mir_transform/src/function_item_references.rs b/compiler/rustc_mir_transform/src/function_item_references.rs index d96a067fdda..996c158c062 100644 --- a/compiler/rustc_mir_transform/src/function_item_references.rs +++ b/compiler/rustc_mir_transform/src/function_item_references.rs @@ -133,7 +133,7 @@ impl<'a, 'tcx> FunctionItemRefChecker<'a, 'tcx> { /// If the given predicate is the trait `fmt::Pointer`, returns the bound parameter type. fn is_pointer_trait(&self, bound: &PredicateKind<'tcx>) -> Option<Ty<'tcx>> { if let ty::PredicateKind::Trait(predicate) = bound { - if self.tcx.is_diagnostic_item(sym::pointer_trait, predicate.def_id()) { + if self.tcx.is_diagnostic_item(sym::Pointer, predicate.def_id()) { Some(predicate.trait_ref.self_ty()) } else { None diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 719d4134ab8..ae3a9c71c59 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -470,7 +470,7 @@ impl EmbargoVisitor<'tcx> { let hir_id = self.tcx.hir().local_def_id_to_hir_id(local_def_id); let attrs = self.tcx.hir().attrs(hir_id); - if attr::find_transparency(&attrs, md.macro_rules).0 != Transparency::Opaque { + if attr::find_transparency(attrs, md.macro_rules).0 != Transparency::Opaque { return; } @@ -797,7 +797,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { // Re-exports are handled in `visit_mod`. However, in order to avoid looping over // all of the items of a mod in `visit_mod` looking for use statements, we handle // making sure that intermediate use statements have their visibilities updated here. - hir::ItemKind::Use(ref path, _) => { + hir::ItemKind::Use(path, _) => { if item_level.is_some() { self.update_visibility_of_intermediate_use_statements(path.segments.as_ref()); } @@ -1099,11 +1099,11 @@ impl<'tcx> Visitor<'tcx> for NamePrivacyVisitor<'tcx> { } fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { - if let hir::ExprKind::Struct(ref qpath, fields, ref base) = expr.kind { + if let hir::ExprKind::Struct(qpath, fields, ref base) = expr.kind { let res = self.typeck_results().qpath_res(qpath, expr.hir_id); let adt = self.typeck_results().expr_ty(expr).ty_adt_def().unwrap(); let variant = adt.variant_of_res(res); - if let Some(ref base) = *base { + if let Some(base) = *base { // If the expression uses FRU we need to make sure all the unmentioned fields // are checked for privacy (RFC 736). Rather than computing the set of // unmentioned fields, just check them all. @@ -1312,7 +1312,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> { return; } match expr.kind { - hir::ExprKind::Assign(_, ref rhs, _) | hir::ExprKind::Match(ref rhs, ..) => { + hir::ExprKind::Assign(_, rhs, _) | hir::ExprKind::Match(rhs, ..) => { // Do not report duplicate errors for `x = y` and `match x { ... }`. if self.check_expr_pat_type(rhs.hir_id, rhs.span) { return; @@ -1397,7 +1397,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> { } fn visit_local(&mut self, local: &'tcx hir::Local<'tcx>) { - if let Some(ref init) = local.init { + if let Some(init) = local.init { if self.check_expr_pat_type(init.hir_id, init.span) { // Do not report duplicate errors for `let x = y`. return; @@ -1474,7 +1474,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { // .. and it corresponds to a private type in the AST (this returns // `None` for type parameters). match self.tcx.hir().find(self.tcx.hir().local_def_id_to_hir_id(did)) { - Some(Node::Item(ref item)) => !item.vis.node.is_pub(), + Some(Node::Item(item)) => !item.vis.node.is_pub(), Some(_) | None => false, } } else { @@ -1490,7 +1490,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { fn check_generic_bound(&mut self, bound: &hir::GenericBound<'_>) { if let hir::GenericBound::Trait(ref trait_ref, _) = *bound { - if self.path_is_private_type(&trait_ref.trait_ref.path) { + if self.path_is_private_type(trait_ref.trait_ref.path) { self.old_error_set.insert(trait_ref.trait_ref.hir_ref_id); } } @@ -1517,7 +1517,7 @@ impl<'a, 'b, 'tcx, 'v> Visitor<'v> for ObsoleteCheckTypeForPrivatenessVisitor<'a } fn visit_ty(&mut self, ty: &hir::Ty<'_>) { - if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = ty.kind { + if let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = ty.kind { if self.inner.path_is_private_type(path) { self.contains_private = true; // Found what we're looking for, so let's stop working. @@ -1556,7 +1556,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { // namespace (the contents have their own privacies). hir::ItemKind::ForeignMod { .. } => {} - hir::ItemKind::Trait(.., ref bounds, _) => { + hir::ItemKind::Trait(.., bounds, _) => { if !self.trait_is_public(item.def_id) { return; } @@ -1586,7 +1586,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { at_outer_type: true, outer_type_is_public_path: false, }; - visitor.visit_ty(&impl_.self_ty); + visitor.visit_ty(impl_.self_ty); self_contains_private = visitor.contains_private; self_is_public_path = visitor.outer_type_is_public_path; } @@ -1664,12 +1664,12 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { // // Those in 2. are warned via walk_generics and this // call here. - intravisit::walk_path(self, &tr.path); + intravisit::walk_path(self, tr.path); // Those in 3. are warned with this call. for impl_item_ref in impl_.items { let impl_item = self.tcx.hir().impl_item(impl_item_ref.id); - if let hir::ImplItemKind::TyAlias(ref ty) = impl_item.kind { + if let hir::ImplItemKind::TyAlias(ty) = impl_item.kind { self.visit_ty(ty); } } @@ -1739,7 +1739,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { } hir::WherePredicate::RegionPredicate(_) => {} hir::WherePredicate::EqPredicate(eq_pred) => { - self.visit_ty(&eq_pred.rhs_ty); + self.visit_ty(eq_pred.rhs_ty); } } } @@ -1752,7 +1752,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { } fn visit_ty(&mut self, t: &'tcx hir::Ty<'tcx>) { - if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = t.kind { + if let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = t.kind { if self.path_is_private_type(path) { self.old_error_set.insert(t.hir_id); } @@ -2191,7 +2191,7 @@ fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) { let mut visitor = ObsoleteVisiblePrivateTypesVisitor { tcx, - access_levels: &access_levels, + access_levels, in_variant: false, old_error_set: Default::default(), }; diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 0cf9d7af589..8dfa839453d 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -127,7 +127,6 @@ impl<'a> Resolver<'a> { /// If `def_id` refers to a module (in resolver's sense, i.e. a module item, crate root, enum, /// or trait), then this function returns that module's resolver representation, otherwise it /// returns `None`. - /// FIXME: `Module`s for local enums and traits are not currently found. crate fn get_module(&mut self, def_id: DefId) -> Option<Module<'a>> { if let module @ Some(..) = self.module_map.get(&def_id) { return module.copied(); @@ -146,17 +145,21 @@ impl<'a> Resolver<'a> { } else { def_key.disambiguated_data.data.get_opt_name().expect("module without name") }; + let expn_id = if def_kind == DefKind::Mod { + self.cstore().module_expansion_untracked(def_id, &self.session) + } else { + // FIXME: Parent expansions for enums and traits are not kept in metadata. + ExpnId::root() + }; - let module = self.arenas.new_module( + Some(self.new_module( parent, ModuleKind::Def(def_kind, def_id, name), - self.cstore().module_expansion_untracked(def_id, &self.session), + expn_id, self.cstore().get_span_untracked(def_id, &self.session), // FIXME: Account for `#[no_implicit_prelude]` attributes. parent.map_or(false, |module| module.no_implicit_prelude), - ); - self.module_map.insert(def_id, module); - Some(module) + )) } _ => None, } @@ -217,8 +220,7 @@ impl<'a> Resolver<'a> { } crate fn build_reduced_graph_external(&mut self, module: Module<'a>) { - let def_id = module.def_id().expect("unpopulated module without a def-id"); - for child in self.cstore().item_children_untracked(def_id, self.session) { + for child in self.cstore().item_children_untracked(module.def_id(), self.session) { let parent_scope = ParentScope::module(module, self); BuildReducedGraphVisitor { r: self, parent_scope } .build_reduced_graph_for_external_crate_res(child); @@ -759,7 +761,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { } ItemKind::Mod(..) => { - let module = self.r.arenas.new_module( + let module = self.r.new_module( Some(parent), ModuleKind::Def(DefKind::Mod, def_id, ident.name), expansion.to_expn_id(), @@ -768,7 +770,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { || self.r.session.contains_name(&item.attrs, sym::no_implicit_prelude), ); self.r.define(parent, ident, TypeNS, (module, vis, sp, expansion)); - self.r.module_map.insert(def_id, module); // Descend into the module. self.parent_scope.module = module; @@ -799,7 +800,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { } ItemKind::Enum(_, _) => { - let module = self.r.arenas.new_module( + let module = self.r.new_module( Some(parent), ModuleKind::Def(DefKind::Enum, def_id, ident.name), expansion.to_expn_id(), @@ -873,7 +874,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { ItemKind::Trait(..) => { // Add all the items within to a new module. - let module = self.r.arenas.new_module( + let module = self.r.new_module( Some(parent), ModuleKind::Def(DefKind::Trait, def_id, ident.name), expansion.to_expn_id(), @@ -916,7 +917,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { let parent = self.parent_scope.module; let expansion = self.parent_scope.expansion; if self.block_needs_anonymous_module(block) { - let module = self.r.arenas.new_module( + let module = self.r.new_module( Some(parent), ModuleKind::Block(block.id), expansion.to_expn_id(), @@ -936,15 +937,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { let expansion = self.parent_scope.expansion; // Record primary definitions. match res { - Res::Def(kind @ (DefKind::Mod | DefKind::Enum | DefKind::Trait), def_id) => { - let module = self.r.arenas.new_module( - Some(parent), - ModuleKind::Def(kind, def_id, ident.name), - expansion.to_expn_id(), - span, - // FIXME: Account for `#[no_implicit_prelude]` attributes. - parent.no_implicit_prelude, - ); + Res::Def(DefKind::Mod | DefKind::Enum | DefKind::Trait, def_id) => { + let module = self.r.expect_module(def_id); self.r.define(parent, ident, TypeNS, (module, vis, span, expansion)); } Res::Def( diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index ab1f47c81db..dea47c25a8e 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -801,7 +801,7 @@ impl<'a> Resolver<'a> { None => worklist_via_import.pop(), Some(x) => Some(x), } { - let in_module_is_extern = !in_module.def_id().unwrap().is_local(); + let in_module_is_extern = !in_module.def_id().is_local(); // We have to visit module children in deterministic order to avoid // instabilities in reported imports (#43552). in_module.for_each_child(self, |this, ident, ns, name_binding| { @@ -884,7 +884,7 @@ impl<'a> Resolver<'a> { if !is_extern_crate_that_also_appears_in_prelude { // add the module to the lookup - if seen_modules.insert(module.def_id().unwrap()) { + if seen_modules.insert(module.def_id()) { if via_import { &mut worklist_via_import } else { &mut worklist } .push((module, path_segments, child_accessible)); } diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 7556f69c391..bb34776f0b0 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -989,7 +989,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { } if let ModuleOrUniformRoot::Module(module) = module { - if module.def_id() == import.parent_scope.module.def_id() { + if ptr::eq(module, import.parent_scope.module) { // Importing a module into itself is not allowed. return Some(UnresolvedImportError { span: import.span, @@ -1341,7 +1341,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { if module.is_trait() { self.r.session.span_err(import.span, "items in traits are not importable."); return; - } else if module.def_id() == import.parent_scope.module.def_id() { + } else if ptr::eq(module, import.parent_scope.module) { return; } else if let ImportKind::Glob { is_prelude: true, .. } = import.kind { self.r.prelude = Some(module); @@ -1400,7 +1400,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { }); if !reexports.is_empty() { - if let Some(def_id) = module.def_id() { + if let Some(def_id) = module.opt_def_id() { // Call to `expect_local` should be fine because current // code is only called for local modules. self.r.export_map.insert(def_id.expect_local(), reexports); diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index e57e7db3285..7b0dd82f0e6 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1491,7 +1491,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> { // form the path let mut path_segments = path_segments.clone(); path_segments.push(ast::PathSegment::from_ident(ident)); - let module_def_id = module.def_id().unwrap(); + let module_def_id = module.def_id(); if module_def_id == def_id { let path = Path { span: name_binding.span, segments: path_segments, tokens: None }; diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 8ae2d5cdd97..04a1fae8fb7 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -413,7 +413,7 @@ impl ModuleOrUniformRoot<'_> { fn same_def(lhs: Self, rhs: Self) -> bool { match (lhs, rhs) { (ModuleOrUniformRoot::Module(lhs), ModuleOrUniformRoot::Module(rhs)) => { - lhs.def_id() == rhs.def_id() + ptr::eq(lhs, rhs) } ( ModuleOrUniformRoot::CrateRootAndExternPrelude, @@ -602,7 +602,11 @@ impl<'a> ModuleData<'a> { } } - fn def_id(&self) -> Option<DefId> { + fn def_id(&self) -> DefId { + self.opt_def_id().expect("`ModuleData::def_id` is called on a block module") + } + + fn opt_def_id(&self) -> Option<DefId> { match self.kind { ModuleKind::Def(_, def_id, _) => Some(def_id), _ => None, @@ -1071,12 +1075,17 @@ impl<'a> ResolverArenas<'a> { expn_id: ExpnId, span: Span, no_implicit_prelude: bool, + module_map: &mut FxHashMap<DefId, Module<'a>>, ) -> Module<'a> { let module = self.modules.alloc(ModuleData::new(parent, kind, expn_id, span, no_implicit_prelude)); - if module.def_id().map_or(true, |def_id| def_id.is_local()) { + let def_id = module.opt_def_id(); + if def_id.map_or(true, |def_id| def_id.is_local()) { self.local_modules.borrow_mut().push(module); } + if let Some(def_id) = def_id { + module_map.insert(def_id, module); + } module } fn local_modules(&'a self) -> std::cell::Ref<'a, Vec<Module<'a>>> { @@ -1276,12 +1285,14 @@ impl<'a> Resolver<'a> { arenas: &'a ResolverArenas<'a>, ) -> Resolver<'a> { let root_def_id = CRATE_DEF_ID.to_def_id(); + let mut module_map = FxHashMap::default(); let graph_root = arenas.new_module( None, ModuleKind::Def(DefKind::Mod, root_def_id, kw::Empty), ExpnId::root(), krate.span, session.contains_name(&krate.attrs, sym::no_implicit_prelude), + &mut module_map, ); let empty_module = arenas.new_module( None, @@ -1289,9 +1300,8 @@ impl<'a> Resolver<'a> { ExpnId::root(), DUMMY_SP, true, + &mut FxHashMap::default(), ); - let mut module_map = FxHashMap::default(); - module_map.insert(root_def_id, graph_root); let definitions = Definitions::new(session.local_stable_crate_id(), krate.span); let root = definitions.get_root_def(); @@ -1434,6 +1444,18 @@ impl<'a> Resolver<'a> { resolver } + fn new_module( + &mut self, + parent: Option<Module<'a>>, + kind: ModuleKind, + expn_id: ExpnId, + span: Span, + no_implicit_prelude: bool, + ) -> Module<'a> { + let module_map = &mut self.module_map; + self.arenas.new_module(parent, kind, expn_id, span, no_implicit_prelude, module_map) + } + fn create_stable_hashing_context(&self) -> ExpandHasher<'_, 'a> { ExpandHasher { source_map: CachingSourceMapView::new(self.session.source_map()), @@ -1570,7 +1592,7 @@ impl<'a> Resolver<'a> { if let Some(module) = current_trait { if self.trait_may_have_item(Some(module), assoc_item) { - let def_id = module.def_id().unwrap(); + let def_id = module.def_id(); found_traits.push(TraitCandidate { def_id, import_ids: smallvec![] }); } } @@ -2171,8 +2193,9 @@ impl<'a> Resolver<'a> { return self.graph_root; } }; - let module = self - .expect_module(module.def_id().map_or(LOCAL_CRATE, |def_id| def_id.krate).as_def_id()); + let module = self.expect_module( + module.opt_def_id().map_or(LOCAL_CRATE, |def_id| def_id.krate).as_def_id(), + ); debug!( "resolve_crate_root({:?}): got module {:?} ({:?}) (ident.span = {:?})", ident, @@ -2999,7 +3022,7 @@ impl<'a> Resolver<'a> { } let container = match parent.kind { - ModuleKind::Def(kind, _, _) => kind.descr(parent.def_id().unwrap()), + ModuleKind::Def(kind, _, _) => kind.descr(parent.def_id()), ModuleKind::Block(..) => "block", }; diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index ef60608a27c..29af6b38bf4 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -601,7 +601,10 @@ pub fn debug_hygiene_data(verbose: bool) -> String { let expn_data = expn_data.as_ref().expect("no expansion data for an expansion ID"); debug_expn_data((&id.to_expn_id(), expn_data)) }); - data.foreign_expn_data.iter().for_each(debug_expn_data); + // Sort the hash map for more reproducible output. + let mut foreign_expn_data: Vec<_> = data.foreign_expn_data.iter().collect(); + foreign_expn_data.sort_by_key(|(id, _)| (id.krate, id.local_id)); + foreign_expn_data.into_iter().for_each(debug_expn_data); s.push_str("\n\nSyntaxContexts:"); data.syntax_context_data.iter().enumerate().for_each(|(id, ctxt)| { s.push_str(&format!( diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 7cb4e18398c..77baf7d7381 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -169,6 +169,7 @@ symbols! { Default, Deref, DirBuilder, + Display, DoubleEndedIterator, Duration, Encodable, @@ -194,6 +195,7 @@ symbols! { Hasher, Implied, Input, + Into, IntoIterator, IoRead, IoWrite, @@ -204,6 +206,7 @@ symbols! { Left, LinkedList, LintPass, + Mutex, None, Ok, Option, @@ -219,6 +222,7 @@ symbols! { PathBuf, Pending, Pin, + Pointer, Poll, ProcMacro, ProcMacroHack, @@ -242,6 +246,7 @@ symbols! { Send, SeqCst, Some, + String, StructuralEq, StructuralPartialEq, Sync, @@ -249,12 +254,15 @@ symbols! { ToOwned, ToString, Try, + TryFrom, + TryInto, Ty, TyCtxt, TyKind, Unknown, UnsafeArg, Vec, + VecDeque, Yield, _DECLS, _Self, @@ -507,7 +515,6 @@ symbols! { debug_assert_macro, debug_assertions, debug_struct, - debug_trait, debug_trait_builder, debug_tuple, decl_macro, @@ -653,7 +660,6 @@ symbols! { from_output, from_residual, from_size_align_unchecked, - from_trait, from_usize, fsub_fast, fundamental, @@ -676,8 +682,6 @@ symbols! { gt, half_open_range_patterns, hash, - hashmap_type, - hashset_type, hexagon_target_feature, hidden, homogeneous_aggregate, @@ -722,7 +726,6 @@ symbols! { instruction_set, intel, into_iter, - into_trait, intra_doc_pointers, intrinsics, irrefutable_let_patterns, @@ -913,7 +916,6 @@ symbols! { optin_builtin_traits, option, option_env, - option_type, options, or, or_patterns, @@ -955,7 +957,6 @@ symbols! { plugins, pointee_trait, pointer, - pointer_trait, pointer_trait_fmt, poll, position, @@ -1051,7 +1052,6 @@ symbols! { repr_transparent, residual, result, - result_type, rhs, rintf32, rintf64, @@ -1152,7 +1152,6 @@ symbols! { self_in_typedefs, self_struct_ctor, semitransparent, - send_trait, shl, shl_assign, should_panic, @@ -1262,7 +1261,6 @@ symbols! { store, str, str_alloc, - string_type, stringify, struct_field_attributes, struct_inherit, @@ -1277,7 +1275,6 @@ symbols! { suggestion, sym, sync, - sync_trait, t32, target_abi, target_arch, @@ -1323,9 +1320,7 @@ symbols! { truncf64, try_blocks, try_from, - try_from_trait, try_into, - try_into_trait, try_trait_v2, tt, tuple, @@ -1397,8 +1392,6 @@ symbols! { var, variant_count, vec, - vec_type, - vecdeque_type, version, vis, visible_private_types, diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index b751918463b..93ddec61dc4 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -533,9 +533,9 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // example). let trait_is_debug = - self.tcx.is_diagnostic_item(sym::debug_trait, trait_ref.def_id()); + self.tcx.is_diagnostic_item(sym::Debug, trait_ref.def_id()); let trait_is_display = - self.tcx.is_diagnostic_item(sym::display_trait, trait_ref.def_id()); + self.tcx.is_diagnostic_item(sym::Display, trait_ref.def_id()); let in_std_macro = match obligation.cause.span.ctxt().outer_expn_data().macro_def_id { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 325126483b9..b7f1f64cbfd 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -676,7 +676,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { &self, obligation: &PredicateObligation<'tcx>, err: &mut DiagnosticBuilder<'_>, - trait_ref: &ty::Binder<'tcx, ty::TraitRef<'tcx>>, + poly_trait_ref: &ty::Binder<'tcx, ty::TraitRef<'tcx>>, has_custom_message: bool, ) -> bool { let span = obligation.cause.span; @@ -702,10 +702,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { .filter_map(|lang_item| self.tcx.lang_items().require(*lang_item).ok()) .collect(); - never_suggest_borrow.push(self.tcx.get_diagnostic_item(sym::send_trait).unwrap()); + never_suggest_borrow.push(self.tcx.get_diagnostic_item(sym::Send).unwrap()); let param_env = obligation.param_env; - let trait_ref = trait_ref.skip_binder(); + let trait_ref = poly_trait_ref.skip_binder(); let found_ty = trait_ref.self_ty(); let found_ty_str = found_ty.to_string(); @@ -715,25 +715,25 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { let mut_substs = self.tcx.mk_substs_trait(mut_borrowed_found_ty, &[]); // Try to apply the original trait binding obligation by borrowing. - let mut try_borrowing = |new_imm_trait_ref: ty::TraitRef<'tcx>, - new_mut_trait_ref: ty::TraitRef<'tcx>, - expected_trait_ref: ty::TraitRef<'tcx>, + let mut try_borrowing = |new_imm_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>, + new_mut_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>, + expected_trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>, blacklist: &[DefId]| -> bool { - if blacklist.contains(&expected_trait_ref.def_id) { + if blacklist.contains(&expected_trait_ref.def_id()) { return false; } let imm_result = self.predicate_must_hold_modulo_regions(&Obligation::new( ObligationCause::dummy(), param_env, - ty::Binder::dummy(new_imm_trait_ref).without_const().to_predicate(self.tcx), + new_imm_trait_ref.without_const().to_predicate(self.tcx), )); let mut_result = self.predicate_must_hold_modulo_regions(&Obligation::new( ObligationCause::dummy(), param_env, - ty::Binder::dummy(new_mut_trait_ref).without_const().to_predicate(self.tcx), + new_mut_trait_ref.without_const().to_predicate(self.tcx), )); if imm_result || mut_result { @@ -806,19 +806,19 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { }; if let ObligationCauseCode::ImplDerivedObligation(obligation) = &*code { - let expected_trait_ref = obligation.parent_trait_ref.skip_binder(); - let new_imm_trait_ref = - ty::TraitRef::new(obligation.parent_trait_ref.def_id(), imm_substs); - let new_mut_trait_ref = - ty::TraitRef::new(obligation.parent_trait_ref.def_id(), mut_substs); + let expected_trait_ref = obligation.parent_trait_ref; + let new_imm_trait_ref = poly_trait_ref + .rebind(ty::TraitRef::new(obligation.parent_trait_ref.def_id(), imm_substs)); + let new_mut_trait_ref = poly_trait_ref + .rebind(ty::TraitRef::new(obligation.parent_trait_ref.def_id(), mut_substs)); return try_borrowing(new_imm_trait_ref, new_mut_trait_ref, expected_trait_ref, &[]); } else if let ObligationCauseCode::BindingObligation(_, _) | ObligationCauseCode::ItemObligation(_) = &*code { return try_borrowing( - ty::TraitRef::new(trait_ref.def_id, imm_substs), - ty::TraitRef::new(trait_ref.def_id, mut_substs), - trait_ref, + poly_trait_ref.rebind(ty::TraitRef::new(trait_ref.def_id, imm_substs)), + poly_trait_ref.rebind(ty::TraitRef::new(trait_ref.def_id, mut_substs)), + *poly_trait_ref, &never_suggest_borrow[..], ); } else { @@ -1634,8 +1634,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // Special case the primary error message when send or sync is the trait that was // not implemented. - let is_send = self.tcx.is_diagnostic_item(sym::send_trait, trait_ref.def_id); - let is_sync = self.tcx.is_diagnostic_item(sym::sync_trait, trait_ref.def_id); + let is_send = self.tcx.is_diagnostic_item(sym::Send, trait_ref.def_id); + let is_sync = self.tcx.is_diagnostic_item(sym::Sync, trait_ref.def_id); let hir = self.tcx.hir(); let trait_explanation = if is_send || is_sync { let (trait_name, trait_verb) = diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs index 456d3fe7b2f..5befe44802f 100644 --- a/compiler/rustc_typeck/src/astconv/generics.rs +++ b/compiler/rustc_typeck/src/astconv/generics.rs @@ -132,7 +132,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } let kind_ord = param.kind.to_ord(tcx); - let arg_ord = arg.to_ord(&tcx.features()); + let arg_ord = arg.to_ord(tcx.features()); // This note is only true when generic parameters are strictly ordered by their kind. if possible_ordering_error && kind_ord.cmp(&arg_ord) != core::cmp::Ordering::Equal { @@ -423,7 +423,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { is_method_call: IsMethodCall, ) -> GenericArgCountResult { let empty_args = hir::GenericArgs::none(); - let suppress_mismatch = Self::check_impl_trait(tcx, seg, &generics); + let suppress_mismatch = Self::check_impl_trait(tcx, seg, generics); let gen_args = seg.args.unwrap_or(&empty_args); let gen_pos = if is_method_call == IsMethodCall::Yes { diff --git a/compiler/rustc_typeck/src/astconv/mod.rs b/compiler/rustc_typeck/src/astconv/mod.rs index 33df541eb2b..e492fd44185 100644 --- a/compiler/rustc_typeck/src/astconv/mod.rs +++ b/compiler/rustc_typeck/src/astconv/mod.rs @@ -352,8 +352,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { span, def_id, seg, - &generics, - &generic_args, + generics, + generic_args, GenericArgPosition::Type, self_ty.is_some(), infer_args, @@ -363,7 +363,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // Traits always have `Self` as a generic parameter, which means they will not return early // here and so associated type bindings will be handled regardless of whether there are any // non-`Self` generic parameters. - if generics.params.len() == 0 { + if generics.params.is_empty() { return (tcx.intern_substs(&[]), arg_count); } @@ -417,7 +417,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let tcx = self.astconv.tcx(); match (¶m.kind, arg) { (GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => { - self.astconv.ast_region_to_region(<, Some(param)).into() + self.astconv.ast_region_to_region(lt, Some(param)).into() } (&GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => { if has_default { @@ -441,7 +441,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { self.inferred_params.push(ty.span); tcx.ty_error().into() } else { - self.astconv.ast_ty_to_ty(&ty).into() + self.astconv.ast_ty_to_ty(ty).into() } } (GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => { @@ -622,10 +622,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .iter() .map(|binding| { let kind = match binding.kind { - hir::TypeBindingKind::Equality { ref ty } => { + hir::TypeBindingKind::Equality { ty } => { ConvertedBindingKind::Equality(self.ast_ty_to_ty(ty)) } - hir::TypeBindingKind::Constraint { ref bounds } => { + hir::TypeBindingKind::Constraint { bounds } => { ConvertedBindingKind::Constraint(bounds) } }; @@ -908,18 +908,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if let Some((self_ty, where_clause)) = self_ty_where_predicates { let self_ty_def_id = tcx.hir().local_def_id(self_ty).to_def_id(); for clause in where_clause { - match clause { - hir::WherePredicate::BoundPredicate(pred) => { - match pred.bounded_ty.kind { - hir::TyKind::Path(hir::QPath::Resolved(_, path)) => match path.res { - Res::Def(DefKind::TyParam, def_id) if def_id == self_ty_def_id => {} - _ => continue, - }, + if let hir::WherePredicate::BoundPredicate(pred) = clause { + match pred.bounded_ty.kind { + hir::TyKind::Path(hir::QPath::Resolved(_, path)) => match path.res { + Res::Def(DefKind::TyParam, def_id) if def_id == self_ty_def_id => {} _ => continue, - } - search_bounds(pred.bounds); + }, + _ => continue, } - _ => {} + search_bounds(pred.bounds); } } } @@ -1030,7 +1027,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { param_ty: Ty<'tcx>, ast_bounds: &[hir::GenericBound<'_>], ) -> Bounds<'tcx> { - self.compute_bounds_inner(param_ty, &ast_bounds) + self.compute_bounds_inner(param_ty, ast_bounds) } /// Convert the bounds in `ast_bounds` that refer to traits which define an associated type @@ -1231,7 +1228,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } match binding.kind { - ConvertedBindingKind::Equality(ref ty) => { + ConvertedBindingKind::Equality(ty) => { // "Desugar" a constraint like `T: Iterator<Item = u32>` this to // the "projection predicate" for: // @@ -2207,7 +2204,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { assert_eq!(opt_self_ty, None); let path_segs = - self.def_ids_for_value_path_segments(&path.segments, None, kind, def_id); + self.def_ids_for_value_path_segments(path.segments, None, kind, def_id); let generic_segs: FxHashSet<_> = path_segs.iter().map(|PathSeg(_, index)| index).collect(); self.prohibit_generics(path.segments.iter().enumerate().filter_map( @@ -2304,34 +2301,32 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let tcx = self.tcx(); let result_ty = match ast_ty.kind { - hir::TyKind::Slice(ref ty) => tcx.mk_slice(self.ast_ty_to_ty(&ty)), + hir::TyKind::Slice(ref ty) => tcx.mk_slice(self.ast_ty_to_ty(ty)), hir::TyKind::Ptr(ref mt) => { - tcx.mk_ptr(ty::TypeAndMut { ty: self.ast_ty_to_ty(&mt.ty), mutbl: mt.mutbl }) + tcx.mk_ptr(ty::TypeAndMut { ty: self.ast_ty_to_ty(mt.ty), mutbl: mt.mutbl }) } hir::TyKind::Rptr(ref region, ref mt) => { let r = self.ast_region_to_region(region, None); debug!(?r); - let t = self.ast_ty_to_ty_inner(&mt.ty, true); + let t = self.ast_ty_to_ty_inner(mt.ty, true); tcx.mk_ref(r, ty::TypeAndMut { ty: t, mutbl: mt.mutbl }) } hir::TyKind::Never => tcx.types.never, - hir::TyKind::Tup(ref fields) => { - tcx.mk_tup(fields.iter().map(|t| self.ast_ty_to_ty(&t))) - } - hir::TyKind::BareFn(ref bf) => { - require_c_abi_if_c_variadic(tcx, &bf.decl, bf.abi, ast_ty.span); + hir::TyKind::Tup(fields) => tcx.mk_tup(fields.iter().map(|t| self.ast_ty_to_ty(t))), + hir::TyKind::BareFn(bf) => { + require_c_abi_if_c_variadic(tcx, bf.decl, bf.abi, ast_ty.span); tcx.mk_fn_ptr(self.ty_of_fn( ast_ty.hir_id, bf.unsafety, bf.abi, - &bf.decl, + bf.decl, &hir::Generics::empty(), None, Some(ast_ty), )) } - hir::TyKind::TraitObject(ref bounds, ref lifetime, _) => { + hir::TyKind::TraitObject(bounds, ref lifetime, _) => { self.conv_object_ty_poly_trait_ref(ast_ty.span, bounds, lifetime, borrowed) } hir::TyKind::Path(hir::QPath::Resolved(ref maybe_qself, ref path)) => { @@ -2339,7 +2334,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let opt_self_ty = maybe_qself.as_ref().map(|qself| self.ast_ty_to_ty(qself)); self.res_to_ty(opt_self_ty, path, false) } - hir::TyKind::OpaqueDef(item_id, ref lifetimes) => { + hir::TyKind::OpaqueDef(item_id, lifetimes) => { let opaque_ty = tcx.hir().item(item_id); let def_id = item_id.def_id.to_def_id(); @@ -2354,7 +2349,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { debug!(?qself, ?segment); let ty = self.ast_ty_to_ty(qself); - let res = if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = qself.kind { + let res = if let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = qself.kind { path.res } else { Res::Err @@ -2379,7 +2374,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { hir::TyKind::Array(ref ty, ref length) => { let length_def_id = tcx.hir().local_def_id(length.hir_id); let length = ty::Const::from_anon_const(tcx, length_def_id); - let array_ty = tcx.mk_ty(ty::Array(self.ast_ty_to_ty(&ty), length)); + let array_ty = tcx.mk_ty(ty::Array(self.ast_ty_to_ty(ty), length)); self.normalize_ty(ast_ty.span, array_ty) } hir::TyKind::Typeof(ref e) => { @@ -2485,7 +2480,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let input_tys = decl.inputs.iter().map(|a| self.ty_of_arg(a, None)); let output_ty = match decl.output { - hir::FnRetTy::Return(ref output) => { + hir::FnRetTy::Return(output) => { visitor.visit_ty(output); self.ast_ty_to_ty(output) } diff --git a/compiler/rustc_typeck/src/check/cast.rs b/compiler/rustc_typeck/src/check/cast.rs index 4ea7a8694c0..9736a7b2e28 100644 --- a/compiler/rustc_typeck/src/check/cast.rs +++ b/compiler/rustc_typeck/src/check/cast.rs @@ -438,7 +438,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { let mut label = true; // Check `impl From<self.expr_ty> for self.cast_ty {}` for accurate suggestion: if let Ok(snippet) = fcx.tcx.sess.source_map().span_to_snippet(self.expr.span) { - if let Some(from_trait) = fcx.tcx.get_diagnostic_item(sym::from_trait) { + if let Some(from_trait) = fcx.tcx.get_diagnostic_item(sym::From) { let ty = fcx.resolve_vars_if_possible(self.cast_ty); // Erase regions to avoid panic in `prove_value` when calling // `type_implements_trait`. diff --git a/compiler/rustc_typeck/src/check/method/confirm.rs b/compiler/rustc_typeck/src/check/method/confirm.rs index 88be49e96e7..dc54f63f49c 100644 --- a/compiler/rustc_typeck/src/check/method/confirm.rs +++ b/compiler/rustc_typeck/src/check/method/confirm.rs @@ -28,7 +28,7 @@ struct ConfirmContext<'a, 'tcx> { impl<'a, 'tcx> Deref for ConfirmContext<'a, 'tcx> { type Target = FnCtxt<'a, 'tcx>; fn deref(&self) -> &Self::Target { - &self.fcx + self.fcx } } @@ -290,7 +290,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { .autoderef(self.span, self_ty) .include_raw_pointers() .find_map(|(ty, _)| match ty.kind() { - ty::Dynamic(ref data, ..) => Some(closure( + ty::Dynamic(data, ..) => Some(closure( self, ty, data.principal().unwrap_or_else(|| { @@ -323,7 +323,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { self.tcx, self.span, pick.item.def_id, - &generics, + generics, seg, IsMethodCall::Yes, ); @@ -343,7 +343,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { def_id: DefId, ) -> (Option<&'a hir::GenericArgs<'a>>, bool) { if def_id == self.pick.item.def_id { - if let Some(ref data) = self.seg.args { + if let Some(data) = self.seg.args { return (Some(data), false); } } diff --git a/compiler/rustc_typeck/src/check/method/mod.rs b/compiler/rustc_typeck/src/check/method/mod.rs index 113d495f0ce..65b3ceb8698 100644 --- a/compiler/rustc_typeck/src/check/method/mod.rs +++ b/compiler/rustc_typeck/src/check/method/mod.rs @@ -160,7 +160,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .unwrap_or(0); // Account for `foo.bar<T>`; - let sugg_span = span.unwrap_or_else(|| call_expr.span).shrink_to_hi(); + let sugg_span = span.unwrap_or(call_expr.span).shrink_to_hi(); let (suggestion, applicability) = ( format!("({})", (0..params).map(|_| "_").collect::<Vec<_>>().join(", ")), if params > 0 { Applicability::HasPlaceholders } else { Applicability::MaybeIncorrect }, @@ -320,7 +320,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { GenericParamDefKind::Type { .. } => { if param.index == 0 { return self_ty.into(); - } else if let Some(ref input_types) = opt_input_types { + } else if let Some(input_types) = opt_input_types { return input_types[param.index as usize - 1].into(); } } diff --git a/compiler/rustc_typeck/src/check/method/probe.rs b/compiler/rustc_typeck/src/check/method/probe.rs index 5aa579f33a9..9d6db32be63 100644 --- a/compiler/rustc_typeck/src/check/method/probe.rs +++ b/compiler/rustc_typeck/src/check/method/probe.rs @@ -88,7 +88,7 @@ struct ProbeContext<'a, 'tcx> { impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> { type Target = FnCtxt<'a, 'tcx>; fn deref(&self) -> &Self::Target { - &self.fcx + self.fcx } } @@ -614,7 +614,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let lang_items = self.tcx.lang_items(); match *self_ty.value.value.kind() { - ty::Dynamic(ref data, ..) if let Some(p) = data.principal() => { + ty::Dynamic(data, ..) if let Some(p) = data.principal() => { // Subtle: we can't use `instantiate_query_response` here: using it will // commit to all of the type equalities assumed by inference going through // autoderef (see the `method-probe-no-guessing` test). @@ -634,7 +634,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // type variables in any form, so just do that! let (QueryResponse { value: generalized_self_ty, .. }, _ignored_var_values) = self.fcx - .instantiate_canonical_with_fresh_inference_vars(self.span, &self_ty); + .instantiate_canonical_with_fresh_inference_vars(self.span, self_ty); self.assemble_inherent_candidates_from_object(generalized_self_ty); self.assemble_inherent_impl_candidates_for_type(p.def_id()); @@ -1428,7 +1428,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { // match as well (or at least may match, sometimes we // don't have enough information to fully evaluate). match probe.kind { - InherentImplCandidate(ref substs, ref ref_obligations) => { + InherentImplCandidate(substs, ref ref_obligations) => { // Check whether the impl imposes obligations we have to worry about. let impl_def_id = probe.item.container.id(); let impl_bounds = self.tcx.predicates_of(impl_def_id); diff --git a/compiler/rustc_typeck/src/check/method/suggest.rs b/compiler/rustc_typeck/src/check/method/suggest.rs index 0071fd2c494..d849e1d5d28 100644 --- a/compiler/rustc_typeck/src/check/method/suggest.rs +++ b/compiler/rustc_typeck/src/check/method/suggest.rs @@ -328,48 +328,44 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Applicability::MaybeIncorrect, ); } - ExprKind::Path(ref qpath) => { + ExprKind::Path(QPath::Resolved(_, path)) => { // local binding - if let QPath::Resolved(_, path) = qpath { - if let hir::def::Res::Local(hir_id) = path.res { - let span = tcx.hir().span(hir_id); - let snippet = tcx.sess.source_map().span_to_snippet(span); - let filename = tcx.sess.source_map().span_to_filename(span); - - let parent_node = self - .tcx - .hir() - .get(self.tcx.hir().get_parent_node(hir_id)); - let msg = format!( - "you must specify a type for this binding, like `{}`", - concrete_type, - ); - - match (filename, parent_node, snippet) { - ( - FileName::Real(_), - Node::Local(hir::Local { - source: hir::LocalSource::Normal, - ty, - .. - }), - Ok(ref snippet), - ) => { - err.span_suggestion( - // account for `let x: _ = 42;` - // ^^^^ - span.to(ty - .as_ref() - .map(|ty| ty.span) - .unwrap_or(span)), - &msg, - format!("{}: {}", snippet, concrete_type), - Applicability::MaybeIncorrect, - ); - } - _ => { - err.span_label(span, msg); - } + if let hir::def::Res::Local(hir_id) = path.res { + let span = tcx.hir().span(hir_id); + let snippet = tcx.sess.source_map().span_to_snippet(span); + let filename = tcx.sess.source_map().span_to_filename(span); + + let parent_node = + self.tcx.hir().get(self.tcx.hir().get_parent_node(hir_id)); + let msg = format!( + "you must specify a type for this binding, like `{}`", + concrete_type, + ); + + match (filename, parent_node, snippet) { + ( + FileName::Real(_), + Node::Local(hir::Local { + source: hir::LocalSource::Normal, + ty, + .. + }), + Ok(ref snippet), + ) => { + err.span_suggestion( + // account for `let x: _ = 42;` + // ^^^^ + span.to(ty + .as_ref() + .map(|ty| ty.span) + .unwrap_or(span)), + &msg, + format!("{}: {}", snippet, concrete_type), + Applicability::MaybeIncorrect, + ); + } + _ => { + err.span_label(span, msg); } } } @@ -383,11 +379,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Don't show generic arguments when the method can't be found in any implementation (#81576). let mut ty_str_reported = ty_str.clone(); - if let ty::Adt(_, ref generics) = actual.kind() { + if let ty::Adt(_, generics) = actual.kind() { if generics.len() > 0 { let mut autoderef = self.autoderef(span, actual); let candidate_found = autoderef.any(|(ty, _)| { - if let ty::Adt(ref adt_deref, _) = ty.kind() { + if let ty::Adt(adt_deref, _) = ty.kind() { self.tcx .inherent_impls(adt_deref.did) .iter() @@ -482,7 +478,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut label_span_not_found = || { if unsatisfied_predicates.is_empty() { err.span_label(span, format!("{item_kind} not found in `{ty_str}`")); - if let ty::Adt(ref adt, _) = rcvr_ty.kind() { + if let ty::Adt(adt, _) = rcvr_ty.kind() { let mut inherent_impls_candidate = self .tcx .inherent_impls(adt.did) @@ -511,7 +507,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } }) .collect::<Vec<_>>(); - if inherent_impls_candidate.len() > 0 { + if !inherent_impls_candidate.is_empty() { inherent_impls_candidate.sort(); inherent_impls_candidate.dedup(); @@ -565,7 +561,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let is_accessible = field.vis.is_accessible_from(scope, self.tcx); if is_accessible { - if self.is_fn_ty(&field_ty, span) { + if self.is_fn_ty(field_ty, span) { let expr_span = expr.span.to(item_name.span); err.multipart_suggestion( &format!( @@ -605,7 +601,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { label_span_not_found(); } - if self.is_fn_ty(&rcvr_ty, span) { + if self.is_fn_ty(rcvr_ty, span) { fn report_function<T: std::fmt::Display>( err: &mut DiagnosticBuilder<'_>, name: T, @@ -618,7 +614,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let SelfSource::MethodCall(expr) = source { if let Ok(expr_string) = tcx.sess.source_map().span_to_snippet(expr.span) { report_function(&mut err, expr_string); - } else if let ExprKind::Path(QPath::Resolved(_, ref path)) = expr.kind { + } else if let ExprKind::Path(QPath::Resolved(_, path)) = expr.kind { if let Some(segment) = path.segments.last() { report_function(&mut err, segment.ident); } @@ -808,7 +804,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); } - bound_list.sort_by(|(_, a), (_, b)| a.cmp(&b)); // Sort alphabetically. + bound_list.sort_by(|(_, a), (_, b)| a.cmp(b)); // Sort alphabetically. bound_list.dedup_by(|(_, a), (_, b)| a == b); // #35677 bound_list.sort_by_key(|(pos, _)| *pos); // Keep the original predicate order. bound_spans.sort(); @@ -987,7 +983,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { sym::Copy, sym::Hash, sym::Default, - sym::debug_trait, + sym::Debug, ]; let mut derives = unsatisfied_predicates .iter() @@ -1007,12 +1003,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if adt_def.did.is_local() { let diagnostic_items = self.tcx.diagnostic_items(trait_ref.def_id.krate); return derivables.iter().find_map(|trait_derivable| { - let item_def_id = - if let Some(item_def_id) = diagnostic_items.get(trait_derivable) { - item_def_id - } else { - return None; - }; + let item_def_id = diagnostic_items.get(trait_derivable)?; if item_def_id == &trait_pred.trait_ref.def_id && !(adt_def.is_enum() && *trait_derivable == sym::Default) { @@ -1371,9 +1362,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) }; // Obtain the span for `param` and use it for a structured suggestion. - if let (Some(ref param), Some(ref table)) = - (param_type, self.in_progress_typeck_results) - { + if let (Some(param), Some(table)) = (param_type, self.in_progress_typeck_results) { let table_owner = table.borrow().hir_owner; let generics = self.tcx.generics_of(table_owner.to_def_id()); let type_param = generics.type_param(param, self.tcx); @@ -1384,7 +1373,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // We do this to avoid suggesting code that ends up as `T: FooBar`, // instead we suggest `T: Foo + Bar` in that case. match hir.get(id) { - Node::GenericParam(ref param) => { + Node::GenericParam(param) => { let mut impl_trait = false; let has_bounds = if let hir::GenericParamKind::Type { synthetic: Some(_), .. } = @@ -1558,7 +1547,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match ty.kind() { ty::Adt(def, _) => def.did.is_local(), ty::Foreign(did) => did.is_local(), - ty::Dynamic(ref tr, ..) => tr.principal().map_or(false, |d| d.def_id().is_local()), + ty::Dynamic(tr, ..) => tr.principal().map_or(false, |d| d.def_id().is_local()), ty::Param(_) => true, // Everything else (primitive types, etc.) is effectively diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index 8a55f7ebf87..7450b4a4ef1 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -271,22 +271,22 @@ fn primary_body_of( ) -> Option<(hir::BodyId, Option<&hir::Ty<'_>>, Option<&hir::FnSig<'_>>)> { match tcx.hir().get(id) { Node::Item(item) => match item.kind { - hir::ItemKind::Const(ref ty, body) | hir::ItemKind::Static(ref ty, _, body) => { + hir::ItemKind::Const(ty, body) | hir::ItemKind::Static(ty, _, body) => { Some((body, Some(ty), None)) } - hir::ItemKind::Fn(ref sig, .., body) => Some((body, None, Some(&sig))), + hir::ItemKind::Fn(ref sig, .., body) => Some((body, None, Some(sig))), _ => None, }, Node::TraitItem(item) => match item.kind { - hir::TraitItemKind::Const(ref ty, Some(body)) => Some((body, Some(ty), None)), + hir::TraitItemKind::Const(ty, Some(body)) => Some((body, Some(ty), None)), hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => { - Some((body, None, Some(&sig))) + Some((body, None, Some(sig))) } _ => None, }, Node::ImplItem(item) => match item.kind { - hir::ImplItemKind::Const(ref ty, body) => Some((body, Some(ty), None)), - hir::ImplItemKind::Fn(ref sig, body) => Some((body, None, Some(&sig))), + hir::ImplItemKind::Const(ty, body) => Some((body, Some(ty), None)), + hir::ImplItemKind::Fn(ref sig, body) => Some((body, None, Some(sig))), _ => None, }, Node::AnonConst(constant) => Some((constant.body, None, None)), @@ -555,16 +555,13 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt<'_>, id: LocalDefId, span: S // `#[link_section]` may contain arbitrary, or even undefined bytes, but it is // the consumer's responsibility to ensure all bytes that have been read // have defined values. - match tcx.eval_static_initializer(id.to_def_id()) { - Ok(alloc) => { - if alloc.relocations().len() != 0 { - let msg = "statics with a custom `#[link_section]` must be a \ + if let Ok(alloc) = tcx.eval_static_initializer(id.to_def_id()) { + if alloc.relocations().len() != 0 { + let msg = "statics with a custom `#[link_section]` must be a \ simple list of bytes on the wasm target with no \ extra levels of indirection such as references"; - tcx.sess.span_err(span, msg); - } + tcx.sess.span_err(span, msg); } - Err(_) => {} } } @@ -631,7 +628,7 @@ fn missing_items_err( let padding: String = " ".repeat(indentation); for trait_item in missing_items { - let snippet = suggestion_signature(&trait_item, tcx); + let snippet = suggestion_signature(trait_item, tcx); let code = format!("{}{}\n{}", padding, snippet, padding); let msg = format!("implement the missing item: `{}`", snippet); let appl = Applicability::HasPlaceholders; diff --git a/compiler/rustc_typeck/src/check/op.rs b/compiler/rustc_typeck/src/check/op.rs index a574a63d63b..d0a32420df3 100644 --- a/compiler/rustc_typeck/src/check/op.rs +++ b/compiler/rustc_typeck/src/check/op.rs @@ -444,7 +444,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Check if the method would be found if the type param wasn't // involved. If so, it means that adding a trait bound to the param is // enough. Otherwise we do not give the suggestion. - let mut eraser = TypeParamEraser(&self, expr.span); + let mut eraser = TypeParamEraser(self, expr.span); let needs_bound = self .lookup_op_method( eraser.fold_ty(lhs_ty), @@ -475,7 +475,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { bug!("type param visitor stored a non type param: {:?}", ty.kind()); } } else if !suggested_deref && !involves_fn { - suggest_impl_missing(&mut err, lhs_ty, &missing_trait); + suggest_impl_missing(&mut err, lhs_ty, missing_trait); } } err.emit(); @@ -572,7 +572,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { on the left and may require reallocation. This \ requires ownership of the string on the left"; - let string_type = self.tcx.get_diagnostic_item(sym::string_type); + let string_type = self.tcx.get_diagnostic_item(sym::String); let is_std_string = |ty: Ty<'tcx>| match ty.ty_adt_def() { Some(ty_def) => Some(ty_def.did) == string_type, None => false, @@ -718,14 +718,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } Str | Never | Char | Tuple(_) | Array(_, _) => {} - Ref(_, ref lty, _) if *lty.kind() == Str => {} + Ref(_, lty, _) if *lty.kind() == Str => {} _ => { let missing_trait = match op { hir::UnOp::Neg => "std::ops::Neg", hir::UnOp::Not => "std::ops::Not", hir::UnOp::Deref => "std::ops::UnDerf", }; - suggest_impl_missing(&mut err, operand_ty, &missing_trait); + suggest_impl_missing(&mut err, operand_ty, missing_trait); } } } diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index 829268e3cb5..0650291bacb 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -341,7 +341,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Ty<'tcx>, mut def_bm: BindingMode, ) -> (Ty<'tcx>, BindingMode) { - let mut expected = self.resolve_vars_with_obligations(&expected); + let mut expected = self.resolve_vars_with_obligations(expected); // Peel off as many `&` or `&mut` from the scrutinee type as possible. For example, // for `match &&&mut Some(5)` the loop runs three times, aborting when it reaches @@ -587,7 +587,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } if let Some(p) = sub { - self.check_pat(&p, expected, def_bm, TopInfo { parent_pat: Some(&pat), ..ti }); + self.check_pat(p, expected, def_bm, TopInfo { parent_pat: Some(pat), ..ti }); } local_ty @@ -697,8 +697,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } else { let err = self.tcx.ty_error(); for field in fields { - let ti = TopInfo { parent_pat: Some(&pat), ..ti }; - self.check_pat(&field.pat, err, def_bm, ti); + let ti = TopInfo { parent_pat: Some(pat), ..ti }; + self.check_pat(field.pat, err, def_bm, ti); } return err; }; @@ -707,7 +707,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.demand_eqtype_pat(pat.span, expected, pat_ty, ti); // Type-check subpatterns. - if self.check_struct_pat_fields(pat_ty, &pat, variant, fields, etc, def_bm, ti) { + if self.check_struct_pat_fields(pat_ty, pat, variant, fields, etc, def_bm, ti) { pat_ty } else { self.tcx.ty_error() @@ -876,7 +876,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let on_error = || { let parent_pat = Some(pat); for pat in subpats { - self.check_pat(&pat, tcx.ty_error(), def_bm, TopInfo { parent_pat, ..ti }); + self.check_pat(pat, tcx.ty_error(), def_bm, TopInfo { parent_pat, ..ti }); } }; let report_unexpected_res = |res: Res| { @@ -961,7 +961,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; for (i, subpat) in subpats.iter().enumerate_and_adjust(variant.fields.len(), ddpos) { let field_ty = self.field_ty(subpat.span, &variant.fields[i], substs); - self.check_pat(&subpat, field_ty, def_bm, TopInfo { parent_pat: Some(&pat), ..ti }); + self.check_pat(subpat, field_ty, def_bm, TopInfo { parent_pat: Some(pat), ..ti }); self.tcx.check_stability( variant.fields[i].did, @@ -1151,7 +1151,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut expected_len = elements.len(); if ddpos.is_some() { // Require known type only when `..` is present. - if let ty::Tuple(ref tys) = self.structurally_resolved_type(span, expected).kind() { + if let ty::Tuple(tys) = self.structurally_resolved_type(span, expected).kind() { expected_len = tys.len(); } } @@ -1172,12 +1172,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // further errors being emitted when using the bindings. #50333 let element_tys_iter = (0..max_len).map(|_| tcx.ty_error()); for (_, elem) in elements.iter().enumerate_and_adjust(max_len, ddpos) { - self.check_pat(elem, &tcx.ty_error(), def_bm, ti); + self.check_pat(elem, tcx.ty_error(), def_bm, ti); } tcx.mk_tup(element_tys_iter) } else { for (i, elem) in elements.iter().enumerate_and_adjust(max_len, ddpos) { - self.check_pat(elem, &element_tys[i].expect_ty(), def_bm, ti); + self.check_pat(elem, element_tys[i].expect_ty(), def_bm, ti); } pat_ty } @@ -1240,14 +1240,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } }; - self.check_pat(&field.pat, field_ty, def_bm, TopInfo { parent_pat: Some(&pat), ..ti }); + self.check_pat(field.pat, field_ty, def_bm, TopInfo { parent_pat: Some(pat), ..ti }); } let mut unmentioned_fields = variant .fields .iter() .map(|field| (field, field.ident.normalize_to_macros_2_0())) - .filter(|(_, ident)| !used_fields.contains_key(&ident)) + .filter(|(_, ident)| !used_fields.contains_key(ident)) .collect::<Vec<_>>(); let inexistent_fields_err = if !(inexistent_fields.is_empty() || variant.is_recovered()) { @@ -1290,13 +1290,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.non_exhaustive_reachable_pattern(pat, &accessible_unmentioned_fields, adt_ty) } else if !etc { if accessible_unmentioned_fields.is_empty() { - unmentioned_err = Some(self.error_no_accessible_fields(pat, &fields)); + unmentioned_err = Some(self.error_no_accessible_fields(pat, fields)); } else { unmentioned_err = Some(self.error_unmentioned_fields( pat, &accessible_unmentioned_fields, accessible_unmentioned_fields.len() != unmentioned_fields.len(), - &fields, + fields, )); } } @@ -1763,7 +1763,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ti: TopInfo<'tcx>, ) -> Ty<'tcx> { let tcx = self.tcx; - let (box_ty, inner_ty) = if self.check_dereferenceable(span, expected, &inner) { + let (box_ty, inner_ty) = if self.check_dereferenceable(span, expected, inner) { // Here, `demand::subtype` is good enough, but I don't // think any errors can be introduced by using `demand::eqtype`. let inner_ty = self.next_ty_var(TypeVariableOrigin { @@ -1777,7 +1777,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let err = tcx.ty_error(); (err, err) }; - self.check_pat(&inner, inner_ty, def_bm, ti); + self.check_pat(inner, inner_ty, def_bm, ti); box_ty } @@ -1792,7 +1792,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> Ty<'tcx> { let tcx = self.tcx; let expected = self.shallow_resolve(expected); - let (rptr_ty, inner_ty) = if self.check_dereferenceable(pat.span, expected, &inner) { + let (rptr_ty, inner_ty) = if self.check_dereferenceable(pat.span, expected, inner) { // `demand::subtype` would be good enough, but using `eqtype` turns // out to be equally general. See (note_1) for details. @@ -1814,7 +1814,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Look for a case like `fn foo(&foo: u32)` and suggest // `fn foo(foo: &u32)` if let Some(mut err) = err { - self.borrow_pat_suggestion(&mut err, &pat, &inner, &expected); + self.borrow_pat_suggestion(&mut err, pat, inner, expected); err.emit(); } (rptr_ty, inner_ty) @@ -1824,7 +1824,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let err = tcx.ty_error(); (err, err) }; - self.check_pat(&inner, inner_ty, def_bm, TopInfo { parent_pat: Some(&pat), ..ti }); + self.check_pat(inner, inner_ty, def_bm, TopInfo { parent_pat: Some(pat), ..ti }); rptr_ty } @@ -1880,15 +1880,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Type check all the patterns before `slice`. for elt in before { - self.check_pat(&elt, element_ty, def_bm, ti); + self.check_pat(elt, element_ty, def_bm, ti); } // Type check the `slice`, if present, against its expected type. if let Some(slice) = slice { - self.check_pat(&slice, opt_slice_ty.unwrap(), def_bm, ti); + self.check_pat(slice, opt_slice_ty.unwrap(), def_bm, ti); } // Type check the elements after `slice`, if present. for elt in after { - self.check_pat(&elt, element_ty, def_bm, ti); + self.check_pat(elt, element_ty, def_bm, ti); } inferred } diff --git a/compiler/rustc_typeck/src/check/place_op.rs b/compiler/rustc_typeck/src/check/place_op.rs index 64775d7aba9..849bf1e455c 100644 --- a/compiler/rustc_typeck/src/check/place_op.rs +++ b/compiler/rustc_typeck/src/check/place_op.rs @@ -126,7 +126,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { match adjusted_ty.kind() { ty::Adt(ty::AdtDef { did, .. }, _) - if self.tcx.is_diagnostic_item(sym::vec_type, *did) => + if self.tcx.is_diagnostic_item(sym::Vec, *did) => { return self.negative_index(adjusted_ty, index_expr.span, base_expr); } @@ -288,7 +288,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | hir::ExprKind::Index(ref expr, _) | hir::ExprKind::Unary(hir::UnOp::Deref, ref expr) = exprs.last().unwrap().kind { - exprs.push(&expr); + exprs.push(expr); } debug!("convert_place_derefs_to_mutable: exprs={:?}", exprs); @@ -350,10 +350,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } match expr.kind { - hir::ExprKind::Index(ref base_expr, ..) => { + hir::ExprKind::Index(base_expr, ..) => { self.convert_place_op_to_mutable(PlaceOp::Index, expr, base_expr); } - hir::ExprKind::Unary(hir::UnOp::Deref, ref base_expr) => { + hir::ExprKind::Unary(hir::UnOp::Deref, base_expr) => { self.convert_place_op_to_mutable(PlaceOp::Deref, expr, base_expr); } _ => {} diff --git a/compiler/rustc_typeck/src/check/regionck.rs b/compiler/rustc_typeck/src/check/regionck.rs index 134604a0e32..693246a3433 100644 --- a/compiler/rustc_typeck/src/check/regionck.rs +++ b/compiler/rustc_typeck/src/check/regionck.rs @@ -190,7 +190,7 @@ pub struct RegionCtxt<'a, 'tcx> { impl<'a, 'tcx> Deref for RegionCtxt<'a, 'tcx> { type Target = FnCtxt<'a, 'tcx>; fn deref(&self) -> &Self::Target { - &self.fcx + self.fcx } } @@ -292,7 +292,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { self.outlives_environment.add_implied_bounds(self.fcx, fn_sig_tys, body_id.hir_id, span); self.outlives_environment.save_implied_bounds(body_id.hir_id); - self.link_fn_params(&body.params); + self.link_fn_params(body.params); self.visit_body(body); self.visit_region_obligations(body_id.hir_id); @@ -379,13 +379,13 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> { fn visit_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) { // see above - self.constrain_bindings_in_pat(&arm.pat); + self.constrain_bindings_in_pat(arm.pat); intravisit::walk_arm(self, arm); } fn visit_local(&mut self, l: &'tcx hir::Local<'tcx>) { // see above - self.constrain_bindings_in_pat(&l.pat); + self.constrain_bindings_in_pat(l.pat); self.link_local(l); intravisit::walk_local(self, l); } @@ -407,13 +407,13 @@ impl<'a, 'tcx> Visitor<'tcx> for RegionCtxt<'a, 'tcx> { match expr.kind { hir::ExprKind::AddrOf(hir::BorrowKind::Ref, m, ref base) => { - self.link_addr_of(expr, m, &base); + self.link_addr_of(expr, m, base); intravisit::walk_expr(self, expr); } - hir::ExprKind::Match(ref discr, ref arms, _) => { - self.link_match(&discr, &arms[..]); + hir::ExprKind::Match(ref discr, arms, _) => { + self.link_match(discr, &arms[..]); intravisit::walk_expr(self, expr); } @@ -448,7 +448,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { let mut place = self.with_mc(|mc| mc.cat_expr_unadjusted(expr))?; let typeck_results = self.typeck_results.borrow(); - let adjustments = typeck_results.expr_adjustments(&expr); + let adjustments = typeck_results.expr_adjustments(expr); if adjustments.is_empty() { return Ok(place); } @@ -475,7 +475,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { self.link_autoref(expr, &place, autoref); } - place = self.with_mc(|mc| mc.cat_expr_adjusted(expr, place, &adjustment))?; + place = self.with_mc(|mc| mc.cat_expr_adjusted(expr, place, adjustment))?; } Ok(place) @@ -540,10 +540,10 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { None => { return; } - Some(ref expr) => &**expr, + Some(expr) => &*expr, }; let discr_cmt = ignore_err!(self.with_mc(|mc| mc.cat_expr(init_expr))); - self.link_pattern(discr_cmt, &local.pat); + self.link_pattern(discr_cmt, local.pat); } /// Computes the guarantors for any ref bindings in a match and @@ -554,7 +554,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { let discr_cmt = ignore_err!(self.with_mc(|mc| mc.cat_expr(discr))); debug!("discr_cmt={:?}", discr_cmt); for arm in arms { - self.link_pattern(discr_cmt.clone(), &arm.pat); + self.link_pattern(discr_cmt.clone(), arm.pat); } } @@ -567,7 +567,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { let param_cmt = self.with_mc(|mc| mc.cat_rvalue(param.hir_id, param.pat.span, param_ty)); debug!("param_ty={:?} param_cmt={:?} param={:?}", param_ty, param_cmt, param); - self.link_pattern(param_cmt, ¶m.pat); + self.link_pattern(param_cmt, param.pat); } } @@ -582,7 +582,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { if let Some(ty::BindByReference(mutbl)) = mc.typeck_results.extract_binding_mode(self.tcx.sess, *hir_id, *span) { - self.link_region_from_node_type(*span, *hir_id, mutbl, &sub_cmt); + self.link_region_from_node_type(*span, *hir_id, mutbl, sub_cmt); } } }) diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index 1f2ccffa6f2..b7c042a08cf 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -790,7 +790,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // This is a multi-line closure with just a `{` on the first line, // so we put the `let` on its own line. // We take the indentation from the next non-empty line. - let line2 = lines.filter(|line| !line.is_empty()).next().unwrap_or_default(); + let line2 = lines.find(|line| !line.is_empty()).unwrap_or_default(); let indent = line2.split_once(|c: char| !c.is_whitespace()).unwrap_or_default().0; diagnostics_builder.span_suggestion( closure_body_span.with_lo(closure_body_span.lo() + BytePos::from_usize(line1.len())).shrink_to_lo(), @@ -844,14 +844,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> String { let mut reasons = String::new(); - if auto_trait_reasons.len() > 0 { + if !auto_trait_reasons.is_empty() { reasons = format!( "{} trait implementation for closure", auto_trait_reasons.clone().into_iter().collect::<Vec<&str>>().join(", ") ); } - if auto_trait_reasons.len() > 0 && drop_reason { + if !auto_trait_reasons.is_empty() && drop_reason { reasons = format!("{} and ", reasons); } @@ -877,7 +877,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let auto_traits_def_id = vec![ self.tcx.lang_items().clone_trait(), self.tcx.lang_items().sync_trait(), - self.tcx.get_diagnostic_item(sym::send_trait), + self.tcx.get_diagnostic_item(sym::Send), self.tcx.lang_items().unpin_trait(), self.tcx.get_diagnostic_item(sym::unwind_safe_trait), self.tcx.get_diagnostic_item(sym::ref_unwind_safe_trait), @@ -885,13 +885,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let auto_traits = vec!["`Clone`", "`Sync`", "`Send`", "`Unpin`", "`UnwindSafe`", "`RefUnwindSafe`"]; - let root_var_min_capture_list = if let Some(root_var_min_capture_list) = - min_captures.and_then(|m| m.get(&var_hir_id)) - { - root_var_min_capture_list - } else { - return None; - }; + let root_var_min_capture_list = min_captures.and_then(|m| m.get(&var_hir_id))?; let ty = self.infcx.resolve_vars_if_possible(self.node_ty(var_hir_id)); @@ -966,14 +960,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - if capture_problems.len() > 0 { + if !capture_problems.is_empty() { problematic_captures.insert( (capture.info.path_expr_id, capture.to_string(self.tcx)), capture_problems, ); } } - if problematic_captures.len() > 0 { + if !problematic_captures.is_empty() { return Some(problematic_captures); } None @@ -1042,7 +1036,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let is_moved = !projections_list.is_empty(); let is_not_completely_captured = - root_var_min_capture_list.iter().any(|capture| capture.place.projections.len() > 0); + root_var_min_capture_list.iter().any(|capture| !capture.place.projections.is_empty()); if is_moved && is_not_completely_captured @@ -1056,7 +1050,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return Some(diagnostics_info); } - return None; + None } /// Figures out the list of root variables (and their types) that aren't completely @@ -1152,7 +1146,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { )); } - if capture_diagnostic.len() > 0 { + if !capture_diagnostic.is_empty() { need_migrations.push((var_hir_id, responsible_captured_hir_ids)); } } @@ -1857,10 +1851,10 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> { #[instrument(skip(self), level = "debug")] fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) { if !self.capture_information.contains_key(&place_with_id.place) { - self.init_capture_info_for_place(&place_with_id, diag_expr_id); + self.init_capture_info_for_place(place_with_id, diag_expr_id); } - self.adjust_upvar_borrow_kind_for_consume(&place_with_id, diag_expr_id); + self.adjust_upvar_borrow_kind_for_consume(place_with_id, diag_expr_id); } #[instrument(skip(self), level = "debug")] @@ -1997,7 +1991,7 @@ fn restrict_capture_precision<'tcx>( } } - return (place, curr_mode); + (place, curr_mode) } /// Truncate deref of any reference. @@ -2066,7 +2060,7 @@ fn construct_capture_kind_reason_string( place: &Place<'tcx>, capture_info: &ty::CaptureInfo<'tcx>, ) -> String { - let place_str = construct_place_string(tcx, &place); + let place_str = construct_place_string(tcx, place); let capture_kind_str = match capture_info.capture_kind { ty::UpvarCapture::ByValue(_) => "ByValue".into(), @@ -2077,7 +2071,7 @@ fn construct_capture_kind_reason_string( } fn construct_path_string(tcx: TyCtxt<'_>, place: &Place<'tcx>) -> String { - let place_str = construct_place_string(tcx, &place); + let place_str = construct_place_string(tcx, place); format!("{} used here", place_str) } @@ -2087,7 +2081,7 @@ fn construct_capture_info_string( place: &Place<'tcx>, capture_info: &ty::CaptureInfo<'tcx>, ) -> String { - let place_str = construct_place_string(tcx, &place); + let place_str = construct_place_string(tcx, place); let capture_kind_str = match capture_info.capture_kind { ty::UpvarCapture::ByValue(_) => "ByValue".into(), diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index 48204590468..20cf9a75e12 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -144,20 +144,20 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { hir::ItemKind::Fn(ref sig, ..) => { check_item_fn(tcx, item.hir_id(), item.ident, item.span, sig.decl); } - hir::ItemKind::Static(ref ty, ..) => { + hir::ItemKind::Static(ty, ..) => { check_item_type(tcx, item.hir_id(), ty.span, false); } - hir::ItemKind::Const(ref ty, ..) => { + hir::ItemKind::Const(ty, ..) => { check_item_type(tcx, item.hir_id(), ty.span, false); } hir::ItemKind::ForeignMod { items, .. } => { for it in items.iter() { let it = tcx.hir().foreign_item(it.id); match it.kind { - hir::ForeignItemKind::Fn(ref decl, ..) => { + hir::ForeignItemKind::Fn(decl, ..) => { check_item_fn(tcx, it.hir_id(), it.ident, it.span, decl) } - hir::ForeignItemKind::Static(ref ty, ..) => { + hir::ForeignItemKind::Static(ty, ..) => { check_item_type(tcx, it.hir_id(), ty.span, true) } hir::ForeignItemKind::Type => (), @@ -198,7 +198,7 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: LocalDefId) { hir::TraitItemKind::Type(_bounds, Some(ty)) => (None, ty.span), _ => (None, trait_item.span), }; - check_object_unsafe_self_trait_by_name(tcx, &trait_item); + check_object_unsafe_self_trait_by_name(tcx, trait_item); check_associated_item(tcx, trait_item.hir_id(), span, method_sig); let encl_trait_hir_id = tcx.hir().get_parent_item(hir_id); @@ -218,7 +218,7 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: LocalDefId) { // We are looking at the `call` function of the `fn` or `fn_mut` lang item. // Do some rudimentary sanity checking to avoid an ICE later (issue #83471). if let Some(hir::FnSig { decl, span, .. }) = method_sig { - if let &[self_ty, _] = &decl.inputs { + if let [self_ty, _] = decl.inputs { if !matches!(self_ty.kind, hir::TyKind::Rptr(_, _)) { tcx.sess .struct_span_err( @@ -473,7 +473,7 @@ fn check_associated_item( item.def_id, &mut implied_bounds, ); - check_method_receiver(fcx, hir_sig, &item, self_ty); + check_method_receiver(fcx, hir_sig, item, self_ty); } ty::AssocKind::Type => { if let ty::AssocItemContainer::TraitContainer(_) = item.container { @@ -794,7 +794,7 @@ fn check_where_clauses<'tcx, 'fcx>( for param in &generics.params { match param.kind { GenericParamDefKind::Type { .. } => { - if is_our_default(¶m) { + if is_our_default(param) { let ty = tcx.type_of(param.def_id); // Ignore dependent defaults -- that is, where the default of one type // parameter includes another (e.g., `<T, U = T>`). In those cases, we can't @@ -809,7 +809,7 @@ fn check_where_clauses<'tcx, 'fcx>( } } GenericParamDefKind::Const { .. } => { - if is_our_default(¶m) { + if is_our_default(param) { // FIXME(const_generics_defaults): This // is incorrect when dealing with unused substs, for example // for `struct Foo<const N: usize, const M: usize = { 1 - 2 }>` diff --git a/compiler/rustc_typeck/src/check/writeback.rs b/compiler/rustc_typeck/src/check/writeback.rs index 2c0d926dd01..d951df94dcf 100644 --- a/compiler/rustc_typeck/src/check/writeback.rs +++ b/compiler/rustc_typeck/src/check/writeback.rs @@ -140,7 +140,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { // operating on scalars, we clear the overload. fn fix_scalar_builtin_expr(&mut self, e: &hir::Expr<'_>) { match e.kind { - hir::ExprKind::Unary(hir::UnOp::Neg | hir::UnOp::Not, ref inner) => { + hir::ExprKind::Unary(hir::UnOp::Neg | hir::UnOp::Not, inner) => { let inner_ty = self.fcx.node_ty(inner.hir_id); let inner_ty = self.fcx.resolve_vars_if_possible(inner_ty); @@ -150,8 +150,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { typeck_results.node_substs_mut().remove(e.hir_id); } } - hir::ExprKind::Binary(ref op, ref lhs, ref rhs) - | hir::ExprKind::AssignOp(ref op, ref lhs, ref rhs) => { + hir::ExprKind::Binary(ref op, lhs, rhs) | hir::ExprKind::AssignOp(ref op, lhs, rhs) => { let lhs_ty = self.fcx.node_ty(lhs.hir_id); let lhs_ty = self.fcx.resolve_vars_if_possible(lhs_ty); @@ -198,7 +197,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { // All valid indexing looks like this; might encounter non-valid indexes at this point. let base_ty = typeck_results - .expr_ty_adjusted_opt(&base) + .expr_ty_adjusted_opt(base) .map(|t| self.fcx.resolve_vars_if_possible(t).kind()); if base_ty.is_none() { // When encountering `return [0][0]` outside of a `fn` body we can encounter a base @@ -207,7 +206,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { self.tcx().sess.delay_span_bug(e.span, &format!("bad base: `{:?}`", base)); } if let Some(ty::Ref(_, base_ty, _)) = base_ty { - let index_ty = typeck_results.expr_ty_adjusted_opt(&index).unwrap_or_else(|| { + let index_ty = typeck_results.expr_ty_adjusted_opt(index).unwrap_or_else(|| { // When encountering `return [0][0]` outside of a `fn` body we would attempt // to access an unexistend index. We assume that more relevant errors will // already have been emitted, so we only gate on this with an ICE if no diff --git a/compiler/rustc_typeck/src/check_unused.rs b/compiler/rustc_typeck/src/check_unused.rs index 7b5d782b0cb..89ce3700aad 100644 --- a/compiler/rustc_typeck/src/check_unused.rs +++ b/compiler/rustc_typeck/src/check_unused.rs @@ -26,7 +26,7 @@ impl ItemLikeVisitor<'v> for CheckVisitor<'tcx> { if item.vis.node.is_pub() || item.span.is_dummy() { return; } - if let hir::ItemKind::Use(ref path, _) = item.kind { + if let hir::ItemKind::Use(path, _) = item.kind { self.check_import(item.item_id(), path.span); } } diff --git a/compiler/rustc_typeck/src/coherence/inherent_impls.rs b/compiler/rustc_typeck/src/coherence/inherent_impls.rs index 0b6d0a539b5..6a9ba9d4913 100644 --- a/compiler/rustc_typeck/src/coherence/inherent_impls.rs +++ b/compiler/rustc_typeck/src/coherence/inherent_impls.rs @@ -56,7 +56,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> { ty::Foreign(did) => { self.check_def_id(item, did); } - ty::Dynamic(ref data, ..) if data.principal_def_id().is_some() => { + ty::Dynamic(data, ..) if data.principal_def_id().is_some() => { self.check_def_id(item, data.principal_def_id().unwrap()); } ty::Dynamic(..) => { @@ -410,7 +410,7 @@ impl InherentCollect<'tcx> { // OK } _ => { - let to_implement = if assoc_items.len() == 0 { + let to_implement = if assoc_items.is_empty() { String::new() } else { let plural = assoc_items.len() > 1; diff --git a/compiler/rustc_typeck/src/coherence/inherent_impls_overlap.rs b/compiler/rustc_typeck/src/coherence/inherent_impls_overlap.rs index 11ffd61cb2e..b5eb74f708d 100644 --- a/compiler/rustc_typeck/src/coherence/inherent_impls_overlap.rs +++ b/compiler/rustc_typeck/src/coherence/inherent_impls_overlap.rs @@ -187,7 +187,7 @@ impl ItemLikeVisitor<'v> for InherentOverlapChecker<'tcx> { .collect::<FxHashSet<usize>>(); match ids.len() { 0 | 1 => { - let id_to_set = if ids.len() == 0 { + let id_to_set = if ids.is_empty() { // Create a new connected region let region = ConnectedRegion { idents: idents_to_add, diff --git a/compiler/rustc_typeck/src/coherence/mod.rs b/compiler/rustc_typeck/src/coherence/mod.rs index 7ac26a31872..079604f128d 100644 --- a/compiler/rustc_typeck/src/coherence/mod.rs +++ b/compiler/rustc_typeck/src/coherence/mod.rs @@ -221,7 +221,7 @@ fn check_object_overlap<'tcx>( } // check for overlap with the automatic `impl Trait for dyn Trait` - if let ty::Dynamic(ref data, ..) = trait_ref.self_ty().kind() { + if let ty::Dynamic(data, ..) = trait_ref.self_ty().kind() { // This is something like impl Trait1 for Trait2. Illegal // if Trait1 is a supertrait of Trait2 or Trait2 is not object safe. diff --git a/compiler/rustc_typeck/src/collect.rs b/compiler/rustc_typeck/src/collect.rs index 51f9f459af1..f21c5c760ea 100644 --- a/compiler/rustc_typeck/src/collect.rs +++ b/compiler/rustc_typeck/src/collect.rs @@ -199,20 +199,16 @@ crate fn placeholder_type_error( let parent_id = tcx.hir().get_parent_node(hir_ty.hir_id); let parent_node = tcx.hir().get(parent_id); - is_const_or_static = match parent_node { + is_const_or_static = matches!( + parent_node, Node::Item(&hir::Item { kind: hir::ItemKind::Const(..) | hir::ItemKind::Static(..), .. - }) - | Node::TraitItem(&hir::TraitItem { + }) | Node::TraitItem(&hir::TraitItem { kind: hir::TraitItemKind::Const(..), .. - }) - | Node::ImplItem(&hir::ImplItem { - kind: hir::ImplItemKind::Const(..), .. - }) => true, - _ => false, - }; + }) | Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Const(..), .. }) + ); } } @@ -681,10 +677,10 @@ impl ItemCtxt<'tcx> { _ => None, }) .flat_map(|bp| { - let bt = if is_param(self.tcx, &bp.bounded_ty, param_id) { + let bt = if is_param(self.tcx, bp.bounded_ty, param_id) { Some(ty) } else if !only_self_bounds.0 { - Some(self.to_ty(&bp.bounded_ty)) + Some(self.to_ty(bp.bounded_ty)) } else { None }; @@ -723,7 +719,7 @@ impl ItemCtxt<'tcx> { /// `ast_ty_to_ty`, because we want to avoid triggering an all-out /// conversion of the type to avoid inducing unnecessary cycles. fn is_param(tcx: TyCtxt<'_>, ast_ty: &hir::Ty<'_>, param_id: hir::HirId) -> bool { - if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = ast_ty.kind { + if let hir::TyKind::Path(hir::QPath::Resolved(None, path)) = ast_ty.kind { match path.res { Res::SelfTy(Some(def_id), None) | Res::Def(DefKind::TyParam, def_id) => { def_id == tcx.hir().local_def_id(param_id).to_def_id() @@ -776,7 +772,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) { tcx.ensure().generics_of(def_id); tcx.ensure().type_of(def_id); tcx.ensure().predicates_of(def_id); - convert_enum_variant_types(tcx, def_id.to_def_id(), &enum_definition.variants); + convert_enum_variant_types(tcx, def_id.to_def_id(), enum_definition.variants); } hir::ItemKind::Impl { .. } => { tcx.ensure().generics_of(def_id); @@ -1153,11 +1149,11 @@ fn super_predicates_that_define_assoc_type( <dyn AstConv<'_>>::compute_bounds_that_match_assoc_type( &icx, self_param_ty, - &bounds, + bounds, assoc_name, ) } else { - <dyn AstConv<'_>>::compute_bounds(&icx, self_param_ty, &bounds) + <dyn AstConv<'_>>::compute_bounds(&icx, self_param_ty, bounds) }; let superbounds1 = superbounds1.predicates(tcx, self_param_ty); @@ -1334,25 +1330,25 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S match node { Node::TraitItem(item) => match item.kind { hir::TraitItemKind::Fn(ref sig, _) => { - has_late_bound_regions(tcx, &item.generics, &sig.decl) + has_late_bound_regions(tcx, &item.generics, sig.decl) } _ => None, }, Node::ImplItem(item) => match item.kind { hir::ImplItemKind::Fn(ref sig, _) => { - has_late_bound_regions(tcx, &item.generics, &sig.decl) + has_late_bound_regions(tcx, &item.generics, sig.decl) } _ => None, }, Node::ForeignItem(item) => match item.kind { - hir::ForeignItemKind::Fn(ref fn_decl, _, ref generics) => { + hir::ForeignItemKind::Fn(fn_decl, _, ref generics) => { has_late_bound_regions(tcx, generics, fn_decl) } _ => None, }, Node::Item(item) => match item.kind { hir::ItemKind::Fn(ref sig, .., ref generics, _) => { - has_late_bound_regions(tcx, generics, &sig.decl) + has_late_bound_regions(tcx, generics, sig.decl) } _ => None, }, @@ -1374,7 +1370,7 @@ impl<'v> Visitor<'v> for AnonConstInParamTyDetector { } fn visit_generic_param(&mut self, p: &'v hir::GenericParam<'v>) { - if let GenericParamKind::Const { ref ty, default: _ } = p.kind { + if let GenericParamKind::Const { ty, default: _ } = p.kind { let prev = self.in_param_ty; self.in_param_ty = true; self.visit_ty(ty); @@ -1587,7 +1583,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::Generics { let mut own_start = has_self as u32; let parent_count = parent_def_id.map_or(0, |def_id| { let generics = tcx.generics_of(def_id); - assert_eq!(has_self, false); + assert!(!has_self); parent_has_self = generics.has_self; own_start = generics.count() as u32; generics.parent_count + generics.params.len() @@ -1738,9 +1734,9 @@ fn is_suggestable_infer_ty(ty: &hir::Ty<'_>) -> bool { } pub fn get_infer_ret_ty(output: &'hir hir::FnRetTy<'hir>) -> Option<&'hir hir::Ty<'hir>> { - if let hir::FnRetTy::Return(ref ty) = output { + if let hir::FnRetTy::Return(ty) = output { if is_suggestable_infer_ty(ty) { - return Some(&**ty); + return Some(&*ty); } } None @@ -1810,8 +1806,8 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> { hir_id, sig.header.unsafety, sig.header.abi, - &sig.decl, - &generics, + sig.decl, + generics, Some(ident.span), None, ), @@ -1829,15 +1825,13 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> { header.unsafety, header.abi, decl, - &generics, + generics, Some(ident.span), None, ), ForeignItem(&hir::ForeignItem { - kind: ForeignItemKind::Fn(ref fn_decl, _, _), - ident, - .. + kind: ForeignItemKind::Fn(fn_decl, _, _), ident, .. }) => { let abi = tcx.hir().get_foreign_abi(hir_id); compute_sig_of_foreign_fn_decl(tcx, def_id.to_def_id(), fn_decl, abi, ident) @@ -2042,9 +2036,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP match item.kind { ItemKind::Impl(ref impl_) => { if impl_.defaultness.is_default() { - is_default_impl_trait = tcx - .impl_trait_ref(def_id) - .map(|trait_ref| ty::Binder::dummy(trait_ref)); + is_default_impl_trait = tcx.impl_trait_ref(def_id).map(ty::Binder::dummy); } &impl_.generics } @@ -2143,7 +2135,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP GenericParamKind::Lifetime { .. } => { param.bounds.iter().for_each(|bound| match bound { hir::GenericBound::Outlives(lt) => { - let bound = <dyn AstConv<'_>>::ast_region_to_region(&icx, <, None); + let bound = <dyn AstConv<'_>>::ast_region_to_region(&icx, lt, None); let outlives = ty::Binder::dummy(ty::OutlivesPredicate(region, bound)); predicates.insert((outlives.to_predicate(tcx), lt.span)); } @@ -2165,12 +2157,12 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP let param_ty = ty::ParamTy::new(index, name).to_ty(tcx); index += 1; - let mut bounds = <dyn AstConv<'_>>::compute_bounds(&icx, param_ty, ¶m.bounds); + let mut bounds = <dyn AstConv<'_>>::compute_bounds(&icx, param_ty, param.bounds); // Params are implicitly sized unless a `?Sized` bound is found <dyn AstConv<'_>>::add_implicitly_sized( &icx, &mut bounds, - ¶m.bounds, + param.bounds, Some((param.hir_id, ast_generics.where_clause.predicates)), param.span, ); @@ -2189,7 +2181,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP for predicate in where_clause.predicates { match predicate { hir::WherePredicate::BoundPredicate(bound_pred) => { - let ty = icx.to_ty(&bound_pred.bounded_ty); + let ty = icx.to_ty(bound_pred.bounded_ty); let bound_vars = icx.tcx.late_bound_vars(bound_pred.bounded_ty.hir_id); // Keep the type around in a dummy predicate, in case of no bounds. @@ -2410,7 +2402,7 @@ fn explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredicat } else { if matches!(def_kind, DefKind::AnonConst) && tcx.lazy_normalization() { let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); - if let Some(_) = tcx.hir().opt_const_param_default_param_hir_id(hir_id) { + if tcx.hir().opt_const_param_default_param_hir_id(hir_id).is_some() { // In `generics_of` we set the generics' parent to be our parent's parent which means that // we lose out on the predicates of our actual parent if we dont return those predicates here. // (See comment in `generics_of` for more information on why the parent shenanigans is necessary) @@ -2503,10 +2495,10 @@ fn compute_sig_of_foreign_fn_decl<'tcx>( } }; for (input, ty) in iter::zip(decl.inputs, fty.inputs().skip_binder()) { - check(&input, ty) + check(input, ty) } if let hir::FnRetTy::Return(ref ty) = decl.output { - check(&ty, fty.output().skip_binder()) + check(ty, fty.output().skip_binder()) } } @@ -2561,7 +2553,7 @@ fn from_target_feature( let msg = "malformed `target_feature` attribute input"; let code = "enable = \"..\"".to_owned(); tcx.sess - .struct_span_err(span, &msg) + .struct_span_err(span, msg) .span_suggestion(span, "must be of the form", code, Applicability::HasPlaceholders) .emit(); }; @@ -2846,7 +2838,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { tcx, id, attr, - &supported_target_features, + supported_target_features, &mut codegen_fn_attrs.target_features, ); } else if attr.has_name(sym::linkage) { @@ -3113,7 +3105,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs { codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL; } let check_name = |attr: &Attribute, sym| attr.has_name(sym); - if let Some(name) = weak_lang_items::link_name(check_name, &attrs) { + if let Some(name) = weak_lang_items::link_name(check_name, attrs) { codegen_fn_attrs.export_name = Some(name); codegen_fn_attrs.link_name = Some(name); } diff --git a/compiler/rustc_typeck/src/collect/item_bounds.rs b/compiler/rustc_typeck/src/collect/item_bounds.rs index 2bc048ac8a0..26cad8fb180 100644 --- a/compiler/rustc_typeck/src/collect/item_bounds.rs +++ b/compiler/rustc_typeck/src/collect/item_bounds.rs @@ -26,9 +26,9 @@ fn associated_type_bounds<'tcx>( ); let icx = ItemCtxt::new(tcx, assoc_item_def_id); - let mut bounds = <dyn AstConv<'_>>::compute_bounds(&icx, item_ty, &ast_bounds); + let mut bounds = <dyn AstConv<'_>>::compute_bounds(&icx, item_ty, ast_bounds); // Associated types are implicitly sized unless a `?Sized` bound is found - <dyn AstConv<'_>>::add_implicitly_sized(&icx, &mut bounds, &ast_bounds, None, span); + <dyn AstConv<'_>>::add_implicitly_sized(&icx, &mut bounds, ast_bounds, None, span); let trait_def_id = tcx.associated_item(assoc_item_def_id).container.id(); let trait_predicates = tcx.trait_explicit_predicates_and_bounds(trait_def_id.expect_local()); @@ -64,9 +64,9 @@ fn opaque_type_bounds<'tcx>( tcx.mk_opaque(opaque_def_id, InternalSubsts::identity_for_item(tcx, opaque_def_id)); let icx = ItemCtxt::new(tcx, opaque_def_id); - let mut bounds = <dyn AstConv<'_>>::compute_bounds(&icx, item_ty, &ast_bounds); + let mut bounds = <dyn AstConv<'_>>::compute_bounds(&icx, item_ty, ast_bounds); // Opaque types are implicitly sized unless a `?Sized` bound is found - <dyn AstConv<'_>>::add_implicitly_sized(&icx, &mut bounds, &ast_bounds, None, span); + <dyn AstConv<'_>>::add_implicitly_sized(&icx, &mut bounds, ast_bounds, None, span); let bounds = bounds.predicates(tcx, item_ty); debug!("opaque_type_bounds({}) = {:?}", tcx.def_path_str(opaque_def_id), bounds); diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index 7a14d7f3d28..2e607de1d33 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -312,7 +312,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); tcx.mk_fn_def(def_id.to_def_id(), substs) } - TraitItemKind::Const(ref ty, body_id) => body_id + TraitItemKind::Const(ty, body_id) => body_id .and_then(|body_id| { if is_suggestable_infer_ty(ty) { Some(infer_placeholder_type( @@ -323,7 +323,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { } }) .unwrap_or_else(|| icx.to_ty(ty)), - TraitItemKind::Type(_, Some(ref ty)) => icx.to_ty(ty), + TraitItemKind::Type(_, Some(ty)) => icx.to_ty(ty), TraitItemKind::Type(_, None) => { span_bug!(item.span, "associated type missing default"); } @@ -334,14 +334,14 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); tcx.mk_fn_def(def_id.to_def_id(), substs) } - ImplItemKind::Const(ref ty, body_id) => { + ImplItemKind::Const(ty, body_id) => { if is_suggestable_infer_ty(ty) { infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident, "constant") } else { icx.to_ty(ty) } } - ImplItemKind::TyAlias(ref ty) => { + ImplItemKind::TyAlias(ty) => { if tcx.impl_trait_ref(tcx.hir().get_parent_did(hir_id).to_def_id()).is_none() { check_feature_inherent_assoc_ty(tcx, item.span); } @@ -352,7 +352,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { Node::Item(item) => { match item.kind { - ItemKind::Static(ref ty, .., body_id) => { + ItemKind::Static(ty, .., body_id) => { if is_suggestable_infer_ty(ty) { infer_placeholder_type( tcx, @@ -366,7 +366,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { icx.to_ty(ty) } } - ItemKind::Const(ref ty, body_id) => { + ItemKind::Const(ty, body_id) => { if is_suggestable_infer_ty(ty) { infer_placeholder_type( tcx, def_id, body_id, ty.span, item.ident, "constant", @@ -375,8 +375,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { icx.to_ty(ty) } } - ItemKind::TyAlias(ref self_ty, _) - | ItemKind::Impl(hir::Impl { ref self_ty, .. }) => icx.to_ty(self_ty), + ItemKind::TyAlias(self_ty, _) + | ItemKind::Impl(hir::Impl { self_ty, .. }) => icx.to_ty(self_ty), ItemKind::Fn(..) => { let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); tcx.mk_fn_def(def_id.to_def_id(), substs) @@ -395,7 +395,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { .mir_borrowck(owner.expect_local()) .concrete_opaque_types .get_value_matching(|(key, _)| key.def_id == def_id.to_def_id()) - .map(|concrete_ty| *concrete_ty) + .copied() .unwrap_or_else(|| { tcx.sess.delay_span_bug( DUMMY_SP, @@ -446,7 +446,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); tcx.mk_fn_def(def_id.to_def_id(), substs) } - ForeignItemKind::Static(ref t, _) => icx.to_ty(t), + ForeignItemKind::Static(t, _) => icx.to_ty(t), ForeignItemKind::Type => tcx.mk_foreign(def_id.to_def_id()), }, @@ -460,7 +460,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { } }, - Node::Field(field) => icx.to_ty(&field.ty), + Node::Field(field) => icx.to_ty(field.ty), Node::Expr(&Expr { kind: ExprKind::Closure(.., gen), .. }) => { let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); @@ -685,9 +685,9 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> { // // requires us to explicitly process `foo()` in order // to notice the defining usage of `Blah`. - Node::Item(ref it) => locator.visit_item(it), - Node::ImplItem(ref it) => locator.visit_impl_item(it), - Node::TraitItem(ref it) => locator.visit_trait_item(it), + Node::Item(it) => locator.visit_item(it), + Node::ImplItem(it) => locator.visit_impl_item(it), + Node::TraitItem(it) => locator.visit_trait_item(it), other => bug!("{:?} is not a valid scope for an opaque type item", other), } } diff --git a/compiler/rustc_typeck/src/constrained_generic_params.rs b/compiler/rustc_typeck/src/constrained_generic_params.rs index 9b6f0be47ca..88877ad7852 100644 --- a/compiler/rustc_typeck/src/constrained_generic_params.rs +++ b/compiler/rustc_typeck/src/constrained_generic_params.rs @@ -206,7 +206,7 @@ pub fn setup_constraining_predicates<'tcx>( // Then the projection only applies if `T` is known, but it still // does not determine `U`. let inputs = parameters_for(tcx, &projection.projection_ty, true); - let relies_only_on_inputs = inputs.iter().all(|p| input_parameters.contains(&p)); + let relies_only_on_inputs = inputs.iter().all(|p| input_parameters.contains(p)); if !relies_only_on_inputs { continue; } diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index b5c4d6ac261..7d0600b99e3 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -124,12 +124,12 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { #[instrument(skip(self), level = "debug")] pub fn consume_body(&mut self, body: &hir::Body<'_>) { for param in body.params { - let param_ty = return_if_err!(self.mc.pat_ty_adjusted(¶m.pat)); + let param_ty = return_if_err!(self.mc.pat_ty_adjusted(param.pat)); debug!("consume_body: param_ty = {:?}", param_ty); let param_place = self.mc.cat_rvalue(param.hir_id, param.pat.span, param_ty); - self.walk_irrefutable_pat(¶m_place, ¶m.pat); + self.walk_irrefutable_pat(¶m_place, param.pat); } self.consume_expr(&body.value); @@ -145,7 +145,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { fn consume_exprs(&mut self, exprs: &[hir::Expr<'_>]) { for expr in exprs { - self.consume_expr(&expr); + self.consume_expr(expr); } } @@ -184,57 +184,57 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { match expr.kind { hir::ExprKind::Path(_) => {} - hir::ExprKind::Type(ref subexpr, _) => self.walk_expr(subexpr), + hir::ExprKind::Type(subexpr, _) => self.walk_expr(subexpr), - hir::ExprKind::Unary(hir::UnOp::Deref, ref base) => { + hir::ExprKind::Unary(hir::UnOp::Deref, base) => { // *base self.select_from_expr(base); } - hir::ExprKind::Field(ref base, _) => { + hir::ExprKind::Field(base, _) => { // base.f self.select_from_expr(base); } - hir::ExprKind::Index(ref lhs, ref rhs) => { + hir::ExprKind::Index(lhs, rhs) => { // lhs[rhs] self.select_from_expr(lhs); self.consume_expr(rhs); } - hir::ExprKind::Call(ref callee, ref args) => { + hir::ExprKind::Call(callee, args) => { // callee(args) self.consume_expr(callee); self.consume_exprs(args); } - hir::ExprKind::MethodCall(.., ref args, _) => { + hir::ExprKind::MethodCall(.., args, _) => { // callee.m(args) self.consume_exprs(args); } - hir::ExprKind::Struct(_, ref fields, ref opt_with) => { + hir::ExprKind::Struct(_, fields, ref opt_with) => { self.walk_struct_expr(fields, opt_with); } - hir::ExprKind::Tup(ref exprs) => { + hir::ExprKind::Tup(exprs) => { self.consume_exprs(exprs); } hir::ExprKind::If(ref cond_expr, ref then_expr, ref opt_else_expr) => { - self.consume_expr(&cond_expr); - self.consume_expr(&then_expr); + self.consume_expr(cond_expr); + self.consume_expr(then_expr); if let Some(ref else_expr) = *opt_else_expr { - self.consume_expr(&else_expr); + self.consume_expr(else_expr); } } - hir::ExprKind::Let(ref pat, ref expr, _) => { - self.walk_local(expr, pat, |t| t.borrow_expr(&expr, ty::ImmBorrow)); + hir::ExprKind::Let(pat, ref expr, _) => { + self.walk_local(expr, pat, |t| t.borrow_expr(expr, ty::ImmBorrow)); } hir::ExprKind::Match(ref discr, arms, _) => { - let discr_place = return_if_err!(self.mc.cat_expr(&discr)); + let discr_place = return_if_err!(self.mc.cat_expr(discr)); // Matching should not always be considered a use of the place, hence // discr does not necessarily need to be borrowed. @@ -243,7 +243,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { let ExprUseVisitor { ref mc, body_owner: _, delegate: _ } = *self; let mut needs_to_be_read = false; for arm in arms.iter() { - return_if_err!(mc.cat_pattern(discr_place.clone(), &arm.pat, |place, pat| { + return_if_err!(mc.cat_pattern(discr_place.clone(), arm.pat, |place, pat| { match &pat.kind { PatKind::Binding(.., opt_sub_pat) => { // If the opt_sub_pat is None, than the binding does not count as @@ -303,7 +303,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { } if needs_to_be_read { - self.borrow_expr(&discr, ty::ImmBorrow); + self.borrow_expr(discr, ty::ImmBorrow); } else { let closure_def_id = match discr_place.place.base { PlaceBase::Upvar(upvar_id) => Some(upvar_id.closure_expr_id.to_def_id()), @@ -318,7 +318,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { // We always want to walk the discriminant. We want to make sure, for instance, // that the discriminant has been initialized. - self.walk_expr(&discr); + self.walk_expr(discr); } // treatment of the discriminant is handled while walking the arms. @@ -327,7 +327,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { } } - hir::ExprKind::Array(ref exprs) => { + hir::ExprKind::Array(exprs) => { self.consume_exprs(exprs); } @@ -336,10 +336,10 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { // make sure that the thing we are pointing out stays valid // for the lifetime `scope_r` of the resulting ptr: let bk = ty::BorrowKind::from_mutbl(m); - self.borrow_expr(&base, bk); + self.borrow_expr(base, bk); } - hir::ExprKind::InlineAsm(ref asm) => { + hir::ExprKind::InlineAsm(asm) => { for (op, _op_sp) in asm.operands { match op { hir::InlineAsmOperand::In { expr, .. } @@ -360,7 +360,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { } } - hir::ExprKind::LlvmInlineAsm(ref ia) => { + hir::ExprKind::LlvmInlineAsm(ia) => { for (o, output) in iter::zip(&ia.inner.outputs, ia.outputs_exprs) { if o.is_indirect { self.consume_expr(output); @@ -368,7 +368,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { self.mutate_expr(output); } } - self.consume_exprs(&ia.inputs_exprs); + self.consume_exprs(ia.inputs_exprs); } hir::ExprKind::Continue(..) @@ -376,43 +376,43 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { | hir::ExprKind::ConstBlock(..) | hir::ExprKind::Err => {} - hir::ExprKind::Loop(ref blk, ..) => { + hir::ExprKind::Loop(blk, ..) => { self.walk_block(blk); } - hir::ExprKind::Unary(_, ref lhs) => { + hir::ExprKind::Unary(_, lhs) => { self.consume_expr(lhs); } - hir::ExprKind::Binary(_, ref lhs, ref rhs) => { + hir::ExprKind::Binary(_, lhs, rhs) => { self.consume_expr(lhs); self.consume_expr(rhs); } - hir::ExprKind::Block(ref blk, _) => { + hir::ExprKind::Block(blk, _) => { self.walk_block(blk); } hir::ExprKind::Break(_, ref opt_expr) | hir::ExprKind::Ret(ref opt_expr) => { - if let Some(ref expr) = *opt_expr { + if let Some(expr) = *opt_expr { self.consume_expr(expr); } } - hir::ExprKind::Assign(ref lhs, ref rhs, _) => { + hir::ExprKind::Assign(lhs, rhs, _) => { self.mutate_expr(lhs); self.consume_expr(rhs); } - hir::ExprKind::Cast(ref base, _) => { + hir::ExprKind::Cast(base, _) => { self.consume_expr(base); } - hir::ExprKind::DropTemps(ref expr) => { + hir::ExprKind::DropTemps(expr) => { self.consume_expr(expr); } - hir::ExprKind::AssignOp(_, ref lhs, ref rhs) => { + hir::ExprKind::AssignOp(_, lhs, rhs) => { if self.mc.typeck_results.is_method_call(expr) { self.consume_expr(lhs); } else { @@ -421,7 +421,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { self.consume_expr(rhs); } - hir::ExprKind::Repeat(ref base, _) => { + hir::ExprKind::Repeat(base, _) => { self.consume_expr(base); } @@ -433,7 +433,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { self.consume_expr(base); } - hir::ExprKind::Yield(ref value, _) => { + hir::ExprKind::Yield(value, _) => { self.consume_expr(value); } } @@ -441,7 +441,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { fn walk_stmt(&mut self, stmt: &hir::Stmt<'_>) { match stmt.kind { - hir::StmtKind::Local(hir::Local { pat, init: Some(ref expr), .. }) => { + hir::StmtKind::Local(hir::Local { pat, init: Some(expr), .. }) => { self.walk_local(expr, pat, |_| {}); } @@ -453,7 +453,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { } hir::StmtKind::Expr(ref expr) | hir::StmtKind::Semi(ref expr) => { - self.consume_expr(&expr); + self.consume_expr(expr); } } } @@ -462,8 +462,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { where F: FnMut(&mut Self), { - self.walk_expr(&expr); - let expr_place = return_if_err!(self.mc.cat_expr(&expr)); + self.walk_expr(expr); + let expr_place = return_if_err!(self.mc.cat_expr(expr)); f(self); self.walk_irrefutable_pat(&expr_place, &pat); } @@ -478,7 +478,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { } if let Some(ref tail_expr) = blk.expr { - self.consume_expr(&tail_expr); + self.consume_expr(tail_expr); } } @@ -489,17 +489,17 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { ) { // Consume the expressions supplying values for each field. for field in fields { - self.consume_expr(&field.expr); + self.consume_expr(field.expr); } let with_expr = match *opt_with { - Some(ref w) => &**w, + Some(w) => &*w, None => { return; } }; - let with_place = return_if_err!(self.mc.cat_expr(&with_expr)); + let with_place = return_if_err!(self.mc.cat_expr(with_expr)); // Select just those fields of the `with` // expression that will actually be used @@ -569,7 +569,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { } } place_with_id = - return_if_err!(self.mc.cat_expr_adjusted(expr, place_with_id, &adjustment)); + return_if_err!(self.mc.cat_expr_adjusted(expr, place_with_id, adjustment)); } } @@ -615,15 +615,15 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { FakeReadCause::ForMatchedPlace(closure_def_id), discr_place.hir_id, ); - self.walk_pat(discr_place, &arm.pat); + self.walk_pat(discr_place, arm.pat); - if let Some(hir::Guard::If(ref e)) = arm.guard { + if let Some(hir::Guard::If(e)) = arm.guard { self.consume_expr(e) } else if let Some(hir::Guard::IfLet(_, ref e)) = arm.guard { self.consume_expr(e) } - self.consume_expr(&arm.body); + self.consume_expr(arm.body); } /// Walks a pat that occurs in isolation (i.e., top-level of fn argument or @@ -836,7 +836,7 @@ fn delegate_consume<'a, 'tcx>( ) { debug!("delegate_consume(place_with_id={:?})", place_with_id); - let mode = copy_or_move(&mc, place_with_id); + let mode = copy_or_move(mc, place_with_id); match mode { ConsumeMode::Move => delegate.consume(place_with_id, diag_expr_id), diff --git a/compiler/rustc_typeck/src/lib.rs b/compiler/rustc_typeck/src/lib.rs index f8714cdc70c..8ff074e2fe5 100644 --- a/compiler/rustc_typeck/src/lib.rs +++ b/compiler/rustc_typeck/src/lib.rs @@ -143,7 +143,7 @@ fn require_same_types<'tcx>( tcx.infer_ctxt().enter(|ref infcx| { let param_env = ty::ParamEnv::empty(); let mut fulfill_cx = <dyn TraitEngine<'_>>::new(infcx.tcx); - match infcx.at(&cause, param_env).eq(expected, actual) { + match infcx.at(cause, param_env).eq(expected, actual) { Ok(InferOk { obligations, .. }) => { fulfill_cx.register_predicate_obligations(infcx, obligations); } @@ -187,9 +187,11 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) { let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local()); match tcx.hir().find(hir_id) { Some(Node::Item(hir::Item { kind: hir::ItemKind::Fn(_, ref generics, _), .. })) => { - let generics_param_span = - if !generics.params.is_empty() { Some(generics.span) } else { None }; - generics_param_span + if !generics.params.is_empty() { + Some(generics.span) + } else { + None + } } _ => { span_bug!(tcx.def_span(def_id), "main has a non-function type"); diff --git a/compiler/rustc_typeck/src/mem_categorization.rs b/compiler/rustc_typeck/src/mem_categorization.rs index f876d0f2513..440ce04e61a 100644 --- a/compiler/rustc_typeck/src/mem_categorization.rs +++ b/compiler/rustc_typeck/src/mem_categorization.rs @@ -307,13 +307,13 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { if self.typeck_results.is_method_call(expr) { self.cat_overloaded_place(expr, e_base) } else { - let base = self.cat_expr(&e_base)?; + let base = self.cat_expr(e_base)?; self.cat_deref(expr, base) } } hir::ExprKind::Field(ref base, _) => { - let base = self.cat_expr(&base)?; + let base = self.cat_expr(base)?; debug!("cat_expr(cat_field): id={} expr={:?} base={:?}", expr.hir_id, expr, base); let field_idx = self @@ -340,7 +340,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { // dereferencing. self.cat_overloaded_place(expr, base) } else { - let base = self.cat_expr(&base)?; + let base = self.cat_expr(base)?; Ok(self.cat_projection(expr, base, expr_ty, ProjectionKind::Index)) } } @@ -350,7 +350,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { self.cat_res(expr.hir_id, expr.span, expr_ty, res) } - hir::ExprKind::Type(ref e, _) => self.cat_expr(&e), + hir::ExprKind::Type(ref e, _) => self.cat_expr(e), hir::ExprKind::AddrOf(..) | hir::ExprKind::Call(..) @@ -674,31 +674,31 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { op(&place_with_id, pat); match pat.kind { - PatKind::Tuple(ref subpats, dots_pos) => { + PatKind::Tuple(subpats, dots_pos) => { // (p1, ..., pN) let total_fields = self.total_fields_in_tuple(pat.hir_id, pat.span)?; for (i, subpat) in subpats.iter().enumerate_and_adjust(total_fields, dots_pos) { - let subpat_ty = self.pat_ty_adjusted(&subpat)?; + let subpat_ty = self.pat_ty_adjusted(subpat)?; let projection_kind = ProjectionKind::Field(i as u32, VariantIdx::new(0)); let sub_place = self.cat_projection(pat, place_with_id.clone(), subpat_ty, projection_kind); - self.cat_pattern_(sub_place, &subpat, op)?; + self.cat_pattern_(sub_place, subpat, op)?; } } - PatKind::TupleStruct(ref qpath, ref subpats, dots_pos) => { + PatKind::TupleStruct(ref qpath, subpats, dots_pos) => { // S(p1, ..., pN) let variant_index = self.variant_index_for_adt(qpath, pat.hir_id, pat.span)?; let total_fields = self.total_fields_in_adt_variant(pat.hir_id, variant_index, pat.span)?; for (i, subpat) in subpats.iter().enumerate_and_adjust(total_fields, dots_pos) { - let subpat_ty = self.pat_ty_adjusted(&subpat)?; + let subpat_ty = self.pat_ty_adjusted(subpat)?; let projection_kind = ProjectionKind::Field(i as u32, variant_index); let sub_place = self.cat_projection(pat, place_with_id.clone(), subpat_ty, projection_kind); - self.cat_pattern_(sub_place, &subpat, op)?; + self.cat_pattern_(sub_place, subpat, op)?; } } @@ -708,7 +708,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { let variant_index = self.variant_index_for_adt(qpath, pat.hir_id, pat.span)?; for fp in field_pats { - let field_ty = self.pat_ty_adjusted(&fp.pat)?; + let field_ty = self.pat_ty_adjusted(fp.pat)?; let field_index = self .typeck_results .field_indices() @@ -722,18 +722,18 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { field_ty, ProjectionKind::Field(field_index as u32, variant_index), ); - self.cat_pattern_(field_place, &fp.pat, op)?; + self.cat_pattern_(field_place, fp.pat, op)?; } } PatKind::Or(pats) => { for pat in pats { - self.cat_pattern_(place_with_id.clone(), &pat, op)?; + self.cat_pattern_(place_with_id.clone(), pat, op)?; } } PatKind::Binding(.., Some(ref subpat)) => { - self.cat_pattern_(place_with_id, &subpat, op)?; + self.cat_pattern_(place_with_id, subpat, op)?; } PatKind::Box(ref subpat) | PatKind::Ref(ref subpat, _) => { @@ -741,7 +741,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { // PatKind::Ref since that information is already contained // in the type. let subplace = self.cat_deref(pat, place_with_id)?; - self.cat_pattern_(subplace, &subpat, op)?; + self.cat_pattern_(subplace, subpat, op)?; } PatKind::Slice(before, ref slice, after) => { @@ -759,20 +759,20 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { ProjectionKind::Index, ); for before_pat in before { - self.cat_pattern_(elt_place.clone(), &before_pat, op)?; + self.cat_pattern_(elt_place.clone(), before_pat, op)?; } if let Some(ref slice_pat) = *slice { - let slice_pat_ty = self.pat_ty_adjusted(&slice_pat)?; + let slice_pat_ty = self.pat_ty_adjusted(slice_pat)?; let slice_place = self.cat_projection( pat, place_with_id, slice_pat_ty, ProjectionKind::Subslice, ); - self.cat_pattern_(slice_place, &slice_pat, op)?; + self.cat_pattern_(slice_place, slice_pat, op)?; } for after_pat in after { - self.cat_pattern_(elt_place.clone(), &after_pat, op)?; + self.cat_pattern_(elt_place.clone(), after_pat, op)?; } } diff --git a/compiler/rustc_typeck/src/outlives/explicit.rs b/compiler/rustc_typeck/src/outlives/explicit.rs index 2ac1a18cffa..bbf31de527e 100644 --- a/compiler/rustc_typeck/src/outlives/explicit.rs +++ b/compiler/rustc_typeck/src/outlives/explicit.rs @@ -30,20 +30,20 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> { // process predicates and convert to `RequiredPredicates` entry, see below for &(predicate, span) in predicates.predicates { match predicate.kind().skip_binder() { - ty::PredicateKind::TypeOutlives(OutlivesPredicate(ref ty, ref reg)) => { + ty::PredicateKind::TypeOutlives(OutlivesPredicate(ty, reg)) => { insert_outlives_predicate( tcx, - (*ty).into(), + ty.into(), reg, span, &mut required_predicates, ) } - ty::PredicateKind::RegionOutlives(OutlivesPredicate(ref reg1, ref reg2)) => { + ty::PredicateKind::RegionOutlives(OutlivesPredicate(reg1, reg2)) => { insert_outlives_predicate( tcx, - (*reg1).into(), + reg1.into(), reg2, span, &mut required_predicates, diff --git a/compiler/rustc_typeck/src/outlives/mod.rs b/compiler/rustc_typeck/src/outlives/mod.rs index 9c6efffdaf0..957ff252519 100644 --- a/compiler/rustc_typeck/src/outlives/mod.rs +++ b/compiler/rustc_typeck/src/outlives/mod.rs @@ -22,7 +22,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: DefId) -> &[(ty::Predicate if matches!(tcx.def_kind(item_def_id), hir::def::DefKind::AnonConst) && tcx.lazy_normalization() { - if let Some(_) = tcx.hir().opt_const_param_default_param_hir_id(id) { + if tcx.hir().opt_const_param_default_param_hir_id(id).is_some() { // In `generics_of` we set the generics' parent to be our parent's parent which means that // we lose out on the predicates of our actual parent if we dont return those predicates here. // (See comment in `generics_of` for more information on why the parent shenanigans is necessary) diff --git a/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs b/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs index c2038f4e047..8d3862ffc8f 100644 --- a/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs @@ -293,7 +293,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { &self, num_params_to_take: usize, ) -> String { - let fn_sig = self.tcx.hir().get_if_local(self.def_id).and_then(|node| fn_sig(node)); + let fn_sig = self.tcx.hir().get_if_local(self.def_id).and_then(fn_sig); let is_used_in_input = |def_id| { fn_sig.map_or(false, |fn_sig| { fn_sig.decl.inputs.iter().any(|ty| match ty.kind { diff --git a/compiler/rustc_typeck/src/variance/constraints.rs b/compiler/rustc_typeck/src/variance/constraints.rs index 708c0cf4a64..1c8ac10818c 100644 --- a/compiler/rustc_typeck/src/variance/constraints.rs +++ b/compiler/rustc_typeck/src/variance/constraints.rs @@ -293,7 +293,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { self.add_constraints_from_invariant_substs(current, substs, variance); } - ty::Dynamic(ref data, r) => { + ty::Dynamic(data, r) => { // The type `Foo<T+'a>` is contravariant w/r/t `'a`: let contra = self.contravariant(variance); self.add_constraints_from_region(current, r, contra); |
