From 6288a721f5ea59a59b4304a7b70c92d7755e8aa8 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 15 Apr 2024 21:00:49 -0400 Subject: [PATCH 01/16] Delay span bug when Self resolves to DefKind::{Mod,Trait} --- .../src/hir_ty_lowering/mod.rs | 11 +++++++ tests/ui/resolve/incorrect-self-res.rs | 17 +++++++++++ tests/ui/resolve/incorrect-self-res.stderr | 30 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 tests/ui/resolve/incorrect-self-res.rs create mode 100644 tests/ui/resolve/incorrect-self-res.stderr diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 63aeb165a4808..b15bf54234d07 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -1879,6 +1879,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { self.set_tainted_by_errors(e); Ty::new_error(self.tcx(), e) } + Res::Def(..) => { + assert_eq!( + path.segments.get(0).map(|seg| seg.ident.name), + Some(kw::SelfUpper), + "only expected incorrect resolution for `Self`" + ); + Ty::new_error( + self.tcx(), + self.tcx().dcx().span_delayed_bug(span, "incorrect resolution for `Self`"), + ) + } _ => span_bug!(span, "unexpected resolution: {:?}", path.res), } } diff --git a/tests/ui/resolve/incorrect-self-res.rs b/tests/ui/resolve/incorrect-self-res.rs new file mode 100644 index 0000000000000..ca97e6989940a --- /dev/null +++ b/tests/ui/resolve/incorrect-self-res.rs @@ -0,0 +1,17 @@ +fn module() { + fn test(&mut self) { + //~^ ERROR `self` parameter is only allowed in associated functions + } + mod Self {} + //~^ ERROR expected identifier, found keyword `Self` +} + +fn trait_() { + fn test(&mut self) { + //~^ ERROR `self` parameter is only allowed in associated functions + } + trait Self {} + //~^ ERROR expected identifier, found keyword `Self` +} + +fn main() {} diff --git a/tests/ui/resolve/incorrect-self-res.stderr b/tests/ui/resolve/incorrect-self-res.stderr new file mode 100644 index 0000000000000..406bfb98011b5 --- /dev/null +++ b/tests/ui/resolve/incorrect-self-res.stderr @@ -0,0 +1,30 @@ +error: expected identifier, found keyword `Self` + --> $DIR/incorrect-self-res.rs:5:9 + | +LL | mod Self {} + | ^^^^ expected identifier, found keyword + +error: expected identifier, found keyword `Self` + --> $DIR/incorrect-self-res.rs:13:11 + | +LL | trait Self {} + | ^^^^ expected identifier, found keyword + +error: `self` parameter is only allowed in associated functions + --> $DIR/incorrect-self-res.rs:2:13 + | +LL | fn test(&mut self) { + | ^^^^^^^^^ not semantically valid as function parameter + | + = note: associated functions are those in `impl` or `trait` definitions + +error: `self` parameter is only allowed in associated functions + --> $DIR/incorrect-self-res.rs:10:13 + | +LL | fn test(&mut self) { + | ^^^^^^^^^ not semantically valid as function parameter + | + = note: associated functions are those in `impl` or `trait` definitions + +error: aborting due to 4 previous errors + From 27374a0214a7b057c19af3af85253268095d8db8 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 6 Mar 2024 16:39:02 +1100 Subject: [PATCH 02/16] Avoid unnecessary `rustc_span::DUMMY_SP` usage. In some cases `DUMMY_SP` is already imported. In other cases this commit adds the necessary import, in files where `DUMMY_SP` is used more than once. --- compiler/rustc_ast_pretty/src/pprust/tests.rs | 10 ++++------ .../rustc_builtin_macros/src/deriving/generic/ty.rs | 3 +-- .../rustc_hir_analysis/src/collect/predicates_of.rs | 2 +- compiler/rustc_hir_typeck/src/coercion.rs | 11 +++++------ compiler/rustc_hir_typeck/src/fallback.rs | 9 +++------ compiler/rustc_hir_typeck/src/method/confirm.rs | 4 ++-- compiler/rustc_hir_typeck/src/method/suggest.rs | 13 ++++--------- compiler/rustc_mir_transform/src/gvn.rs | 4 ++-- compiler/rustc_parse/src/parser/item.rs | 7 ++----- .../src/traits/const_evaluatable.rs | 9 ++++----- src/librustdoc/clean/types.rs | 2 +- src/librustdoc/html/render/mod.rs | 6 +++--- src/tools/clippy/clippy_lints/src/non_copy_const.rs | 8 +++----- 13 files changed, 35 insertions(+), 53 deletions(-) diff --git a/compiler/rustc_ast_pretty/src/pprust/tests.rs b/compiler/rustc_ast_pretty/src/pprust/tests.rs index 3b2b60a86f06e..5b5ffbc6f8821 100644 --- a/compiler/rustc_ast_pretty/src/pprust/tests.rs +++ b/compiler/rustc_ast_pretty/src/pprust/tests.rs @@ -3,6 +3,7 @@ use super::*; use rustc_ast as ast; use rustc_span::create_default_session_globals_then; use rustc_span::symbol::Ident; +use rustc_span::DUMMY_SP; use thin_vec::ThinVec; fn fun_to_string( @@ -28,10 +29,7 @@ fn test_fun_to_string() { create_default_session_globals_then(|| { let abba_ident = Ident::from_str("abba"); - let decl = ast::FnDecl { - inputs: ThinVec::new(), - output: ast::FnRetTy::Default(rustc_span::DUMMY_SP), - }; + let decl = ast::FnDecl { inputs: ThinVec::new(), output: ast::FnRetTy::Default(DUMMY_SP) }; let generics = ast::Generics::default(); assert_eq!( fun_to_string(&decl, ast::FnHeader::default(), abba_ident, &generics), @@ -48,7 +46,7 @@ fn test_variant_to_string() { let var = ast::Variant { ident, vis: ast::Visibility { - span: rustc_span::DUMMY_SP, + span: DUMMY_SP, kind: ast::VisibilityKind::Inherited, tokens: None, }, @@ -56,7 +54,7 @@ fn test_variant_to_string() { id: ast::DUMMY_NODE_ID, data: ast::VariantData::Unit(ast::DUMMY_NODE_ID), disr_expr: None, - span: rustc_span::DUMMY_SP, + span: DUMMY_SP, is_placeholder: false, }; diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs index 603cefdd38629..1888332468326 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs @@ -8,8 +8,7 @@ use rustc_ast::{self as ast, Expr, GenericArg, GenericParamKind, Generics, SelfK use rustc_expand::base::ExtCtxt; use rustc_span::source_map::respan; use rustc_span::symbol::{kw, Ident, Symbol}; -use rustc_span::Span; -use rustc_span::DUMMY_SP; +use rustc_span::{Span, DUMMY_SP}; use thin_vec::ThinVec; /// A path, e.g., `::std::option::Option::` (global). Has support diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index efd3ceebe6ca5..472657290ed1f 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -37,7 +37,7 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic // from the trait itself that *shouldn't* be shown as the source of // an obligation and instead be skipped. Otherwise we'd use // `tcx.def_span(def_id);` - let span = rustc_span::DUMMY_SP; + let span = DUMMY_SP; result.predicates = tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once(( diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 53043fc6c68e9..9ebb5f95f05fd 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -59,8 +59,7 @@ use rustc_middle::ty::visit::TypeVisitableExt; use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt}; use rustc_session::parse::feature_err; use rustc_span::symbol::sym; -use rustc_span::DesugaringKind; -use rustc_span::{BytePos, Span}; +use rustc_span::{BytePos, DesugaringKind, Span, DUMMY_SP}; use rustc_target::spec::abi::Abi; use rustc_trait_selection::infer::InferCtxtExt as _; use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt; @@ -1045,7 +1044,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let source = self.resolve_vars_with_obligations(expr_ty); debug!("coercion::can_with_predicates({:?} -> {:?})", source, target); - let cause = self.cause(rustc_span::DUMMY_SP, ObligationCauseCode::ExprAssignable); + let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable); // We don't ever need two-phase here since we throw out the result of the coercion let coerce = Coerce::new(self, cause, AllowTwoPhase::No); self.probe(|_| { @@ -1062,11 +1061,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// how many dereference steps needed to achieve `expr_ty <: target`. If /// it's not possible, return `None`. pub fn deref_steps(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> Option { - let cause = self.cause(rustc_span::DUMMY_SP, ObligationCauseCode::ExprAssignable); + let cause = self.cause(DUMMY_SP, ObligationCauseCode::ExprAssignable); // We don't ever need two-phase here since we throw out the result of the coercion let coerce = Coerce::new(self, cause, AllowTwoPhase::No); coerce - .autoderef(rustc_span::DUMMY_SP, expr_ty) + .autoderef(DUMMY_SP, expr_ty) .find_map(|(ty, steps)| self.probe(|_| coerce.unify(ty, target)).ok().map(|_| steps)) } @@ -1077,7 +1076,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// trait or region sub-obligations. (presumably we could, but it's not /// particularly important for diagnostics...) pub fn deref_once_mutably_for_diagnostic(&self, expr_ty: Ty<'tcx>) -> Option> { - self.autoderef(rustc_span::DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| { + self.autoderef(DUMMY_SP, expr_ty).nth(1).and_then(|(deref_ty, _)| { self.infcx .type_implements_trait( self.tcx.lang_items().deref_mut_trait()?, diff --git a/compiler/rustc_hir_typeck/src/fallback.rs b/compiler/rustc_hir_typeck/src/fallback.rs index 69399b50695d1..c0b3984e3e17d 100644 --- a/compiler/rustc_hir_typeck/src/fallback.rs +++ b/compiler/rustc_hir_typeck/src/fallback.rs @@ -5,6 +5,7 @@ use rustc_data_structures::{ }; use rustc_infer::infer::{DefineOpaqueTypes, InferOk}; use rustc_middle::ty::{self, Ty}; +use rustc_span::DUMMY_SP; #[derive(Copy, Clone)] pub enum DivergingFallbackBehavior { @@ -102,7 +103,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { // that field is only used for type fallback diagnostics. for effect in unsolved_effects { let expected = self.tcx.consts.true_; - let cause = self.misc(rustc_span::DUMMY_SP); + let cause = self.misc(DUMMY_SP); match self.at(&cause, self.param_env).eq(DefineOpaqueTypes::Yes, expected, effect) { Ok(InferOk { obligations, value: () }) => { self.register_predicates(obligations); @@ -165,11 +166,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> { }; debug!("fallback_if_possible(ty={:?}): defaulting to `{:?}`", ty, fallback); - let span = self - .infcx - .type_var_origin(ty) - .map(|origin| origin.span) - .unwrap_or(rustc_span::DUMMY_SP); + let span = self.infcx.type_var_origin(ty).map(|origin| origin.span).unwrap_or(DUMMY_SP); self.demand_eqtype(span, ty, fallback); self.fallback_has_occurred.set(true); true diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index 36860e446fc2b..02759064abd42 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -173,7 +173,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { let Some((ty, n)) = autoderef.nth(pick.autoderefs) else { return Ty::new_error_with_message( self.tcx, - rustc_span::DUMMY_SP, + DUMMY_SP, format!("failed autoderef {}", pick.autoderefs), ); }; @@ -608,7 +608,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { let span = predicates .iter() .find_map(|(p, span)| if p == pred { Some(span) } else { None }) - .unwrap_or(rustc_span::DUMMY_SP); + .unwrap_or(DUMMY_SP); Some((trait_pred, span)) } _ => None, diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 8a16e726451a1..46227e406a328 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -1844,23 +1844,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { has_unsuggestable_args = true; match arg.unpack() { GenericArgKind::Lifetime(_) => self - .next_region_var(RegionVariableOrigin::MiscVariable( - rustc_span::DUMMY_SP, - )) + .next_region_var(RegionVariableOrigin::MiscVariable(DUMMY_SP)) .into(), GenericArgKind::Type(_) => self .next_ty_var(TypeVariableOrigin { - span: rustc_span::DUMMY_SP, + span: DUMMY_SP, param_def_id: None, }) .into(), GenericArgKind::Const(arg) => self .next_const_var( arg.ty(), - ConstVariableOrigin { - span: rustc_span::DUMMY_SP, - param_def_id: None, - }, + ConstVariableOrigin { span: DUMMY_SP, param_def_id: None }, ) .into(), } @@ -2758,7 +2753,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let SelfSource::QPath(ty) = self_source else { return; }; - for (deref_ty, _) in self.autoderef(rustc_span::DUMMY_SP, rcvr_ty).skip(1) { + for (deref_ty, _) in self.autoderef(DUMMY_SP, rcvr_ty).skip(1) { if let Ok(pick) = self.probe_for_name( Mode::Path, item_name, diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index d4f736d2a50f6..8e8d78226c30a 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -1202,7 +1202,7 @@ impl<'tcx> VnState<'_, 'tcx> { // not give the same value as the former mention. && value.is_deterministic() { - return Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_: value }); + return Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_: value }); } let op = self.evaluated[index].as_ref()?; @@ -1219,7 +1219,7 @@ impl<'tcx> VnState<'_, 'tcx> { assert!(!value.may_have_provenance(self.tcx, op.layout.size)); let const_ = Const::Val(value, op.layout.ty); - Some(ConstOperand { span: rustc_span::DUMMY_SP, user_ty: None, const_ }) + Some(ConstOperand { span: DUMMY_SP, user_ty: None, const_ }) } /// If there is a local which is assigned `index`, and its assignment strictly dominates `loc`, diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 003479b9d8ec3..1260c20fd55fa 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1968,11 +1968,8 @@ impl<'a> Parser<'a> { } else if matches!(is_raw, IdentIsRaw::No) && ident.is_reserved() { let snapshot = self.create_snapshot_for_diagnostic(); let err = if self.check_fn_front_matter(false, Case::Sensitive) { - let inherited_vis = Visibility { - span: rustc_span::DUMMY_SP, - kind: VisibilityKind::Inherited, - tokens: None, - }; + let inherited_vis = + Visibility { span: DUMMY_SP, kind: VisibilityKind::Inherited, tokens: None }; // We use `parse_fn` to get a span for the function let fn_parse_mode = FnParseMode { req_name: |_| true, req_body: true }; match self.parse_fn( diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 9ca1dd4557dc8..a8be5627fed81 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -8,15 +8,14 @@ //! In this case we try to build an abstract representation of this constant using //! `thir_abstract_const` which can then be checked for structural equality with other //! generic constants mentioned in the `caller_bounds` of the current environment. + use rustc_hir::def::DefKind; use rustc_infer::infer::InferCtxt; use rustc_middle::mir::interpret::ErrorHandled; - use rustc_middle::traits::ObligationCause; use rustc_middle::ty::abstract_const::NotConstEvaluatable; use rustc_middle::ty::{self, TyCtxt, TypeVisitable, TypeVisitableExt, TypeVisitor}; - -use rustc_span::Span; +use rustc_span::{Span, DUMMY_SP}; use crate::traits::ObligationCtxt; @@ -116,12 +115,12 @@ pub fn is_const_evaluatable<'tcx>( tcx.dcx() .struct_span_fatal( // Slightly better span than just using `span` alone - if span == rustc_span::DUMMY_SP { tcx.def_span(uv.def) } else { span }, + if span == DUMMY_SP { tcx.def_span(uv.def) } else { span }, "failed to evaluate generic const expression", ) .with_note("the crate this constant originates from uses `#![feature(generic_const_exprs)]`") .with_span_suggestion_verbose( - rustc_span::DUMMY_SP, + DUMMY_SP, "consider enabling this feature", "#![feature(generic_const_exprs)]\n", rustc_errors::Applicability::MaybeIncorrect, diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index b592bd76e4c34..aeb7137b7224f 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -408,7 +408,7 @@ impl Item { pub(crate) fn attr_span(&self, tcx: TyCtxt<'_>) -> rustc_span::Span { span_of_fragments(&self.attrs.doc_strings) - .unwrap_or_else(|| self.span(tcx).map_or(rustc_span::DUMMY_SP, |span| span.inner())) + .unwrap_or_else(|| self.span(tcx).map_or(DUMMY_SP, |span| span.inner())) } /// Combine all doc strings into a single value handling indentation and newlines as needed. diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 4e46f847fd76a..a949f79575368 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -56,7 +56,7 @@ use rustc_middle::ty::{self, TyCtxt}; use rustc_session::RustcVersion; use rustc_span::{ symbol::{sym, Symbol}, - BytePos, FileName, RealFileName, + BytePos, FileName, RealFileName, DUMMY_SP, }; use serde::ser::SerializeMap; use serde::{Serialize, Serializer}; @@ -2414,7 +2414,7 @@ fn render_call_locations(mut w: W, cx: &mut Context<'_>, item: &c let contents = match fs::read_to_string(&path) { Ok(contents) => contents, Err(err) => { - let span = item.span(tcx).map_or(rustc_span::DUMMY_SP, |span| span.inner()); + let span = item.span(tcx).map_or(DUMMY_SP, |span| span.inner()); tcx.dcx().span_err(span, format!("failed to read file {}: {err}", path.display())); return false; } @@ -2495,7 +2495,7 @@ fn render_call_locations(mut w: W, cx: &mut Context<'_>, item: &c file.start_pos + BytePos(byte_max), )) })() - .unwrap_or(rustc_span::DUMMY_SP); + .unwrap_or(DUMMY_SP); let mut decoration_info = FxHashMap::default(); decoration_info.insert("highlight focus", vec![byte_ranges.remove(0)]); diff --git a/src/tools/clippy/clippy_lints/src/non_copy_const.rs b/src/tools/clippy/clippy_lints/src/non_copy_const.rs index 73fc34c2450f9..5ca388d67a177 100644 --- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs +++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs @@ -18,7 +18,7 @@ use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult, GlobalId}; use rustc_middle::ty::adjustment::Adjust; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_session::impl_lint_pass; -use rustc_span::{sym, InnerSpan, Span}; +use rustc_span::{sym, DUMMY_SP, InnerSpan, Span}; use rustc_target::abi::VariantIdx; // FIXME: this is a correctness problem but there's no suitable @@ -290,9 +290,7 @@ impl NonCopyConst { promoted: None, }; let param_env = cx.tcx.param_env(def_id).with_reveal_all_normalized(cx.tcx); - let result = cx - .tcx - .const_eval_global_id_for_typeck(param_env, cid, rustc_span::DUMMY_SP); + let result = cx.tcx.const_eval_global_id_for_typeck(param_env, cid, DUMMY_SP); self.is_value_unfrozen_raw(cx, result, ty) } @@ -303,7 +301,7 @@ impl NonCopyConst { cx.tcx, cx.param_env, ty::UnevaluatedConst::new(def_id, args), - rustc_span::DUMMY_SP, + DUMMY_SP, ); self.is_value_unfrozen_raw(cx, result, ty) } From e93f75428934cce6c14b34fdb44d06affe3f4802 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 6 Mar 2024 16:54:36 +1100 Subject: [PATCH 03/16] Always use `ty::` qualifier for `TyKind` enum variants. Because that's the way it should be done. --- .../rustc_const_eval/src/transform/check_consts/ops.rs | 9 +++++---- compiler/rustc_hir_typeck/src/method/prelude2021.rs | 8 ++++---- compiler/rustc_hir_typeck/src/pat.rs | 4 ++-- src/librustdoc/html/render/type_layout.rs | 5 ++--- src/tools/clippy/clippy_lints/src/derivable_impls.rs | 6 +++--- .../clippy/clippy_lints/src/from_raw_with_void_ptr.rs | 4 ++-- src/tools/clippy/clippy_lints/src/functions/result.rs | 6 +++--- .../clippy/clippy_lints/src/implicit_saturating_add.rs | 3 ++- src/tools/clippy/clippy_lints/src/large_enum_variant.rs | 6 +++--- .../clippy/clippy_lints/src/methods/unnecessary_join.rs | 6 +++--- src/tools/clippy/clippy_lints/src/mut_key.rs | 4 ++-- .../clippy/clippy_lints/src/zero_sized_map_values.rs | 4 ++-- 12 files changed, 33 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index e87e60f62dc88..9775f1980c59b 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -9,9 +9,10 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::traits::{ImplSource, Obligation, ObligationCause}; use rustc_middle::mir::{self, CallSource}; use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_middle::ty::TraitRef; -use rustc_middle::ty::{suggest_constraining_type_param, Adt, Closure, FnDef, FnPtr, Param, Ty}; -use rustc_middle::ty::{GenericArgKind, GenericArgsRef}; +use rustc_middle::ty::{ + self as middle_ty, suggest_constraining_type_param, Closure, FnDef, FnPtr, GenericArgKind, + GenericArgsRef, Param, TraitRef, Ty, +}; use rustc_middle::util::{call_kind, CallDesugaringKind, CallKind}; use rustc_session::parse::feature_err; use rustc_span::symbol::sym; @@ -123,7 +124,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> { ); } } - Adt(..) => { + middle_ty::Adt(..) => { let obligation = Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref); diff --git a/compiler/rustc_hir_typeck/src/method/prelude2021.rs b/compiler/rustc_hir_typeck/src/method/prelude2021.rs index 8196412834510..22eef8e53dae0 100644 --- a/compiler/rustc_hir_typeck/src/method/prelude2021.rs +++ b/compiler/rustc_hir_typeck/src/method/prelude2021.rs @@ -8,7 +8,7 @@ use hir::ItemKind; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_infer::infer::type_variable::TypeVariableOrigin; -use rustc_middle::ty::{Adt, Array, Ref, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_session::lint::builtin::RUST_2021_PRELUDE_COLLISIONS; use rustc_span::symbol::kw::{Empty, Underscore}; use rustc_span::symbol::{sym, Ident}; @@ -44,7 +44,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // but `[T; N].into_iter()` doesn't resolve to IntoIterator::into_iter // before Rust 2021, which results in the same problem. // It is only a problem for arrays. - sym::into_iter if let Array(..) = self_ty.kind() => { + sym::into_iter if let ty::Array(..) = self_ty.kind() => { // In this case, it wasn't really a prelude addition that was the problem. // Instead, the problem is that the array-into_iter hack will no longer apply in Rust 2021. rustc_lint::ARRAY_INTO_ITER @@ -64,7 +64,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pick.autoref_or_ptr_adjustment, Some(probe::AutorefOrPtrAdjustment::Autoref { .. }) ) - && matches!(self_ty.kind(), Ref(..)) + && matches!(self_ty.kind(), ty::Ref(..)) { return; } @@ -278,7 +278,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // the user has written the self type with generics already which we (naively) do by looking // for a "<" in `self_ty_name`. if !self_ty_name.contains('<') { - if let Adt(def, _) = self_ty.kind() { + if let ty::Adt(def, _) = self_ty.kind() { let generics = self.tcx.generics_of(def.did()); if !generics.params.is_empty() { let counts = generics.own_counts(); diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index db4bd132b7e30..506eb4b888594 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -11,7 +11,7 @@ use rustc_hir::{self as hir, BindingAnnotation, ByRef, HirId, Mutability, Pat, P use rustc_infer::infer; use rustc_infer::infer::type_variable::TypeVariableOrigin; use rustc_middle::mir::interpret::ErrorHandled; -use rustc_middle::ty::{self, Adt, Ty, TypeVisitableExt}; +use rustc_middle::ty::{self, Ty, TypeVisitableExt}; use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS; use rustc_span::edit_distance::find_best_match_for_name; use rustc_span::hygiene::DesugaringKind; @@ -1046,7 +1046,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } _ => { let (type_def_id, item_def_id) = match pat_ty.kind() { - Adt(def, _) => match res { + ty::Adt(def, _) => match res { Res::Def(DefKind::Const, def_id) => (Some(def.did()), Some(def_id)), _ => (None, None), }, diff --git a/src/librustdoc/html/render/type_layout.rs b/src/librustdoc/html/render/type_layout.rs index 738ea0aee7e9d..a27e327f2353a 100644 --- a/src/librustdoc/html/render/type_layout.rs +++ b/src/librustdoc/html/render/type_layout.rs @@ -3,8 +3,7 @@ use askama::Template; use rustc_data_structures::captures::Captures; use rustc_hir::def_id::DefId; use rustc_middle::span_bug; -use rustc_middle::ty::layout::LayoutError; -use rustc_middle::ty::Adt; +use rustc_middle::ty::{self, layout::LayoutError}; use rustc_span::symbol::Symbol; use rustc_target::abi::{Primitive, TagEncoding, Variants}; @@ -57,7 +56,7 @@ pub(crate) fn document_type_layout<'a, 'cx: 'a>( variants .iter_enumerated() .map(|(variant_idx, variant_layout)| { - let Adt(adt, _) = type_layout.ty.kind() else { + let ty::Adt(adt, _) = type_layout.ty.kind() else { span_bug!(tcx.def_span(ty_def_id), "not an adt") }; let name = adt.variant(variant_idx).name; diff --git a/src/tools/clippy/clippy_lints/src/derivable_impls.rs b/src/tools/clippy/clippy_lints/src/derivable_impls.rs index 80327586fedcc..0c9ad5e8d0015 100644 --- a/src/tools/clippy/clippy_lints/src/derivable_impls.rs +++ b/src/tools/clippy/clippy_lints/src/derivable_impls.rs @@ -9,7 +9,7 @@ use rustc_hir::{ }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, PointerCoercion}; -use rustc_middle::ty::{self, Adt, AdtDef, GenericArgsRef, Ty, TypeckResults}; +use rustc_middle::ty::{self, AdtDef, GenericArgsRef, Ty, TypeckResults}; use rustc_session::impl_lint_pass; use rustc_span::sym; @@ -79,7 +79,7 @@ fn is_path_self(e: &Expr<'_>) -> bool { fn contains_trait_object(ty: Ty<'_>) -> bool { match ty.kind() { ty::Ref(_, ty, _) => contains_trait_object(*ty), - Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object), + ty::Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object), ty::Dynamic(..) => true, _ => false, } @@ -198,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { && let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir) && let ImplItemKind::Fn(_, b) = &impl_item.kind && let Body { value: func_expr, .. } = cx.tcx.hir().body(*b) - && let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() + && let &ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() && let attrs = cx.tcx.hir().attrs(item.hir_id()) && !attrs.iter().any(|attr| attr.doc_str().is_some()) && cx.tcx.hir().attrs(impl_item_hir).is_empty() diff --git a/src/tools/clippy/clippy_lints/src/from_raw_with_void_ptr.rs b/src/tools/clippy/clippy_lints/src/from_raw_with_void_ptr.rs index ba2495c17a21a..d62d008d480f7 100644 --- a/src/tools/clippy/clippy_lints/src/from_raw_with_void_ptr.rs +++ b/src/tools/clippy/clippy_lints/src/from_raw_with_void_ptr.rs @@ -4,7 +4,7 @@ use clippy_utils::ty::is_c_void; use rustc_hir::def_id::DefId; use rustc_hir::{Expr, ExprKind, QPath}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::RawPtr; +use rustc_middle::ty; use rustc_session::declare_lint_pass; use rustc_span::sym; @@ -44,7 +44,7 @@ impl LateLintPass<'_> for FromRawWithVoidPtr { && seg.ident.name == sym!(from_raw) && let Some(type_str) = path_def_id(cx, ty).and_then(|id| def_id_matches_type(cx, id)) && let arg_kind = cx.typeck_results().expr_ty(arg).kind() - && let RawPtr(ty, _) = arg_kind + && let ty::RawPtr(ty, _) = arg_kind && is_c_void(cx, *ty) { let msg = format!("creating a `{type_str}` from a void raw pointer"); diff --git a/src/tools/clippy/clippy_lints/src/functions/result.rs b/src/tools/clippy/clippy_lints/src/functions/result.rs index 93f088d3e3392..c3a0b40a677aa 100644 --- a/src/tools/clippy/clippy_lints/src/functions/result.rs +++ b/src/tools/clippy/clippy_lints/src/functions/result.rs @@ -2,7 +2,7 @@ use rustc_errors::Diag; use rustc_hir as hir; use rustc_lint::{LateContext, LintContext}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{Adt, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_span::{sym, Span}; use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then}; @@ -25,7 +25,7 @@ fn result_err_ty<'tcx>( .tcx .instantiate_bound_regions_with_erased(cx.tcx.fn_sig(id).instantiate_identity().output()) && is_type_diagnostic_item(cx, ty, sym::Result) - && let Adt(_, args) = ty.kind() + && let ty::Adt(_, args) = ty.kind() { let err_ty = args.type_at(1); Some((hir_ty, err_ty)) @@ -86,7 +86,7 @@ fn check_result_unit_err(cx: &LateContext<'_>, err_ty: Ty<'_>, fn_header_span: S } fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty_span: Span, large_err_threshold: u64) { - if let Adt(adt, subst) = err_ty.kind() + if let ty::Adt(adt, subst) = err_ty.kind() && let Some(local_def_id) = err_ty .ty_adt_def() .expect("already checked this is adt") diff --git a/src/tools/clippy/clippy_lints/src/implicit_saturating_add.rs b/src/tools/clippy/clippy_lints/src/implicit_saturating_add.rs index b8d7e8f3b07c7..f225c6e7f049f 100644 --- a/src/tools/clippy/clippy_lints/src/implicit_saturating_add.rs +++ b/src/tools/clippy/clippy_lints/src/implicit_saturating_add.rs @@ -7,7 +7,7 @@ use rustc_data_structures::packed::Pu128; use rustc_errors::Applicability; use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{Int, IntTy, Ty, Uint, UintTy}; +use rustc_middle::ty::{IntTy, Ty, UintTy}; use rustc_session::declare_lint_pass; declare_clippy_lint! { @@ -97,6 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd { } fn get_int_max(ty: Ty<'_>) -> Option { + use rustc_middle::ty::{Int, Uint}; match ty.peel_refs().kind() { Int(IntTy::I8) => i8::MAX.try_into().ok(), Int(IntTy::I16) => i16::MAX.try_into().ok(), diff --git a/src/tools/clippy/clippy_lints/src/large_enum_variant.rs b/src/tools/clippy/clippy_lints/src/large_enum_variant.rs index 6feb188557643..0bf7389ef9cc8 100644 --- a/src/tools/clippy/clippy_lints/src/large_enum_variant.rs +++ b/src/tools/clippy/clippy_lints/src/large_enum_variant.rs @@ -7,7 +7,7 @@ use rustc_errors::Applicability; use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{Adt, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_session::impl_lint_pass; use rustc_span::Span; @@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant { } if let ItemKind::Enum(ref def, _) = item.kind { let ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); - let Adt(adt, subst) = ty.kind() else { + let ty::Adt(adt, subst) = ty.kind() else { panic!("already checked whether this is an enum") }; if adt.variants().len() <= 1 { @@ -167,7 +167,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant { } fn maybe_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { - if let Adt(_def, args) = ty.kind() + if let ty::Adt(_def, args) = ty.kind() && args.types().next().is_some() && let Some(copy_trait) = cx.tcx.lang_items().copy_trait() { diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_join.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_join.rs index c3ad4db387592..efd1a718504ce 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_join.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_join.rs @@ -4,7 +4,7 @@ use rustc_ast::ast::LitKind; use rustc_errors::Applicability; use rustc_hir::{Expr, ExprKind, LangItem}; use rustc_lint::LateContext; -use rustc_middle::ty::{Ref, Slice}; +use rustc_middle::ty; use rustc_span::Span; use super::UNNECESSARY_JOIN; @@ -18,9 +18,9 @@ pub(super) fn check<'tcx>( ) { let applicability = Applicability::MachineApplicable; let collect_output_adjusted_type = cx.typeck_results().expr_ty_adjusted(join_self_arg); - if let Ref(_, ref_type, _) = collect_output_adjusted_type.kind() + if let ty::Ref(_, ref_type, _) = collect_output_adjusted_type.kind() // the turbofish for collect is ::> - && let Slice(slice) = ref_type.kind() + && let ty::Slice(slice) = ref_type.kind() && is_type_lang_item(cx, *slice, LangItem::String) // the argument for join is "" && let ExprKind::Lit(spanned) = &join_arg.kind diff --git a/src/tools/clippy/clippy_lints/src/mut_key.rs b/src/tools/clippy/clippy_lints/src/mut_key.rs index 79f0a398d55dd..8c2f43c97f4d9 100644 --- a/src/tools/clippy/clippy_lints/src/mut_key.rs +++ b/src/tools/clippy/clippy_lints/src/mut_key.rs @@ -4,7 +4,7 @@ use clippy_utils::{def_path_def_ids, trait_ref_of_method}; use rustc_data_structures::fx::FxHashSet; use rustc_hir as hir; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{Adt, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_session::impl_lint_pass; use rustc_span::def_id::LocalDefId; use rustc_span::symbol::sym; @@ -153,7 +153,7 @@ impl MutableKeyType { // generics (because the compiler cannot ensure immutability for unknown types). fn check_ty_<'tcx>(&self, cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) { let ty = ty.peel_refs(); - if let Adt(def, args) = ty.kind() { + if let ty::Adt(def, args) = ty.kind() { let is_keyed_type = [sym::HashMap, sym::BTreeMap, sym::HashSet, sym::BTreeSet] .iter() .any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did())); diff --git a/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs b/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs index d1f7c6417c7e1..e14480b86556f 100644 --- a/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs +++ b/src/tools/clippy/clippy_lints/src/zero_sized_map_values.rs @@ -4,7 +4,7 @@ use rustc_hir::{self as hir, HirId, ItemKind, Node}; use rustc_hir_analysis::lower_ty; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::layout::LayoutOf as _; -use rustc_middle::ty::{Adt, Ty, TypeVisitableExt}; +use rustc_middle::ty::{self, Ty, TypeVisitableExt}; use rustc_session::declare_lint_pass; use rustc_span::sym; @@ -49,7 +49,7 @@ impl LateLintPass<'_> for ZeroSizedMapValues { && !in_trait_impl(cx, hir_ty.hir_id) && let ty = ty_from_hir_ty(cx, hir_ty) && (is_type_diagnostic_item(cx, ty, sym::HashMap) || is_type_diagnostic_item(cx, ty, sym::BTreeMap)) - && let Adt(_, args) = ty.kind() + && let ty::Adt(_, args) = ty.kind() && let ty = args.type_at(1) // Fixes https://github.com/rust-lang/rust-clippy/issues/7447 because of // https://github.com/rust-lang/rust/blob/master/compiler/rustc_middle/src/ty/sty.rs#L968 From 4b27cc8b7ab0551475ce1799e8cc43c5d1327f7e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 6 Mar 2024 17:24:13 +1100 Subject: [PATCH 04/16] Avoid lots of `hir::HirId{,Map,Set}` qualifiers. Because they're a bit redundant. --- compiler/rustc_ast_lowering/src/expr.rs | 11 +++-- compiler/rustc_ast_lowering/src/lib.rs | 37 ++++++--------- .../src/collect/resolve_bound_vars.rs | 20 ++++---- .../src/hir_ty_lowering/mod.rs | 37 +++++---------- compiler/rustc_hir_pretty/src/lib.rs | 17 +++---- compiler/rustc_hir_typeck/src/expr.rs | 2 +- .../rustc_hir_typeck/src/expr_use_visitor.rs | 22 ++++----- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 38 +++++++-------- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 19 +++----- .../src/fn_ctxt/suggestions.rs | 8 ++-- .../rustc_hir_typeck/src/gather_locals.rs | 12 ++--- compiler/rustc_hir_typeck/src/lib.rs | 6 +-- .../src/mem_categorization.rs | 30 +++++------- compiler/rustc_hir_typeck/src/method/probe.rs | 15 +++--- .../rustc_hir_typeck/src/typeck_root_ctxt.rs | 6 +-- compiler/rustc_hir_typeck/src/upvar.rs | 29 ++++++------ compiler/rustc_hir_typeck/src/writeback.rs | 25 +++++----- compiler/rustc_lint/src/late.rs | 9 ++-- compiler/rustc_middle/src/middle/region.rs | 14 ++---- compiler/rustc_middle/src/mir/mod.rs | 2 +- compiler/rustc_middle/src/thir.rs | 14 +++--- compiler/rustc_middle/src/traits/mod.rs | 31 ++++++------ compiler/rustc_middle/src/ty/closure.rs | 13 ++--- .../rustc_middle/src/ty/typeck_results.rs | 47 +++++++++---------- compiler/rustc_mir_build/src/build/mod.rs | 10 ++-- .../rustc_mir_build/src/check_unsafety.rs | 24 ++++------ compiler/rustc_passes/src/hir_stats.rs | 4 +- compiler/rustc_passes/src/liveness.rs | 2 +- compiler/rustc_passes/src/naked_functions.rs | 6 +-- compiler/rustc_passes/src/upvars.rs | 2 +- .../src/traits/error_reporting/suggestions.rs | 4 +- .../src/functions/not_unsafe_ptr_arg_deref.rs | 4 +- .../clippy_lints/src/index_refutable_slice.rs | 13 ++--- .../src/operators/assign_op_pattern.rs | 33 ++++++------- src/tools/clippy/clippy_lints/src/ptr.rs | 4 +- .../src/significant_drop_tightening.rs | 18 +++---- 36 files changed, 276 insertions(+), 312 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 389cf4e313216..66841c094ceca 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -14,6 +14,7 @@ use rustc_ast::*; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; +use rustc_hir::HirId; use rustc_middle::span_bug; use rustc_session::errors::report_lit_error; use rustc_span::source_map::{respan, Spanned}; @@ -701,8 +702,8 @@ impl<'hir> LoweringContext<'_, 'hir> { pub(super) fn maybe_forward_track_caller( &mut self, span: Span, - outer_hir_id: hir::HirId, - inner_hir_id: hir::HirId, + outer_hir_id: HirId, + inner_hir_id: HirId, ) { if self.tcx.features().async_fn_track_caller && let Some(attrs) = self.attrs.get(&outer_hir_id.local_id) @@ -1048,7 +1049,7 @@ impl<'hir> LoweringContext<'_, 'hir> { binder: &ClosureBinder, capture_clause: CaptureBy, closure_id: NodeId, - closure_hir_id: hir::HirId, + closure_hir_id: HirId, coroutine_kind: CoroutineKind, decl: &FnDecl, body: &Expr, @@ -2036,7 +2037,7 @@ impl<'hir> LoweringContext<'_, 'hir> { &mut self, sp: Span, ident: Ident, - binding: hir::HirId, + binding: HirId, ) -> &'hir hir::Expr<'hir> { self.arena.alloc(self.expr_ident_mut(sp, ident, binding)) } @@ -2045,7 +2046,7 @@ impl<'hir> LoweringContext<'_, 'hir> { &mut self, span: Span, ident: Ident, - binding: hir::HirId, + binding: HirId, ) -> hir::Expr<'hir> { let hir_id = self.next_id(); let res = Res::Local(binding); diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 5005c22d4cc3a..7f153c52fcb8c 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -56,7 +56,7 @@ use rustc_hir as hir; use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res}; use rustc_hir::def_id::{LocalDefId, LocalDefIdMap, CRATE_DEF_ID, LOCAL_CRATE}; use rustc_hir::{ - ConstArg, GenericArg, ItemLocalMap, MissingLifetimeKind, ParamName, TraitCandidate, + ConstArg, GenericArg, HirId, ItemLocalMap, MissingLifetimeKind, ParamName, TraitCandidate, }; use rustc_index::{Idx, IndexSlice, IndexVec}; use rustc_macros::extension; @@ -107,7 +107,7 @@ struct LoweringContext<'a, 'hir> { /// When inside an `async` context, this is the `HirId` of the /// `task_context` local bound to the resume argument of the coroutine. - task_context: Option, + task_context: Option, /// Used to get the current `fn`'s def span to point to when using `await` /// outside of an `async fn`. @@ -661,18 +661,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { /// `HirIdValidator` later on, which makes sure that all `NodeId`s got mapped /// properly. Calling the method twice with the same `NodeId` is fine though. #[instrument(level = "debug", skip(self), ret)] - fn lower_node_id(&mut self, ast_node_id: NodeId) -> hir::HirId { + fn lower_node_id(&mut self, ast_node_id: NodeId) -> HirId { assert_ne!(ast_node_id, DUMMY_NODE_ID); match self.node_id_to_local_id.entry(ast_node_id) { - Entry::Occupied(o) => { - hir::HirId { owner: self.current_hir_id_owner, local_id: *o.get() } - } + Entry::Occupied(o) => HirId { owner: self.current_hir_id_owner, local_id: *o.get() }, Entry::Vacant(v) => { // Generate a new `HirId`. let owner = self.current_hir_id_owner; let local_id = self.item_local_id_counter; - let hir_id = hir::HirId { owner, local_id }; + let hir_id = HirId { owner, local_id }; v.insert(local_id); self.item_local_id_counter.increment_by(1); @@ -693,12 +691,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { /// Generate a new `HirId` without a backing `NodeId`. #[instrument(level = "debug", skip(self), ret)] - fn next_id(&mut self) -> hir::HirId { + fn next_id(&mut self) -> HirId { let owner = self.current_hir_id_owner; let local_id = self.item_local_id_counter; assert_ne!(local_id, hir::ItemLocalId::ZERO); self.item_local_id_counter.increment_by(1); - hir::HirId { owner, local_id } + HirId { owner, local_id } } #[instrument(level = "trace", skip(self))] @@ -706,7 +704,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let res: Result = res.apply_id(|id| { let owner = self.current_hir_id_owner; let local_id = self.node_id_to_local_id.get(&id).copied().ok_or(())?; - Ok(hir::HirId { owner, local_id }) + Ok(HirId { owner, local_id }) }); trace!(?res); @@ -889,7 +887,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { ret } - fn lower_attrs(&mut self, id: hir::HirId, attrs: &[Attribute]) -> Option<&'hir [Attribute]> { + fn lower_attrs(&mut self, id: HirId, attrs: &[Attribute]) -> Option<&'hir [Attribute]> { if attrs.is_empty() { None } else { @@ -921,7 +919,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { Attribute { kind, id: attr.id, style: attr.style, span: self.lower_span(attr.span) } } - fn alias_attrs(&mut self, id: hir::HirId, target_id: hir::HirId) { + fn alias_attrs(&mut self, id: HirId, target_id: HirId) { debug_assert_eq!(id.owner, self.current_hir_id_owner); debug_assert_eq!(target_id.owner, self.current_hir_id_owner); if let Some(&a) = self.attrs.get(&target_id.local_id) { @@ -2421,11 +2419,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.pat(span, hir::PatKind::Struct(qpath, fields, false)) } - fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, hir::HirId) { + fn pat_ident(&mut self, span: Span, ident: Ident) -> (&'hir hir::Pat<'hir>, HirId) { self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::NONE) } - fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, hir::HirId) { + fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, HirId) { self.pat_ident_binding_mode_mut(span, ident, hir::BindingAnnotation::NONE) } @@ -2434,7 +2432,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { span: Span, ident: Ident, bm: hir::BindingAnnotation, - ) -> (&'hir hir::Pat<'hir>, hir::HirId) { + ) -> (&'hir hir::Pat<'hir>, HirId) { let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm); (self.arena.alloc(pat), hir_id) } @@ -2444,7 +2442,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { span: Span, ident: Ident, bm: hir::BindingAnnotation, - ) -> (hir::Pat<'hir>, hir::HirId) { + ) -> (hir::Pat<'hir>, HirId) { let hir_id = self.next_id(); ( @@ -2476,12 +2474,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } } - fn ty_path( - &mut self, - mut hir_id: hir::HirId, - span: Span, - qpath: hir::QPath<'hir>, - ) -> hir::Ty<'hir> { + fn ty_path(&mut self, mut hir_id: HirId, span: Span, qpath: hir::QPath<'hir>) -> hir::Ty<'hir> { let kind = match qpath { hir::QPath::Resolved(None, path) => { // Turn trait object paths into `TyKind::TraitObject` instead. diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index 3d16f1420d997..7f33580b52fb8 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -13,7 +13,7 @@ use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{self, Visitor}; -use rustc_hir::{GenericArg, GenericParam, GenericParamKind, HirIdMap, LifetimeName, Node}; +use rustc_hir::{GenericArg, GenericParam, GenericParamKind, HirId, HirIdMap, LifetimeName, Node}; use rustc_macros::extension; use rustc_middle::bug; use rustc_middle::hir::nested_filter; @@ -107,7 +107,7 @@ enum Scope<'a> { /// queried later. However, if we enter an elision scope, we have to /// later append the elided bound vars to the list and need to know what /// to append to. - hir_id: hir::HirId, + hir_id: HirId, s: ScopeRef<'a>, @@ -781,7 +781,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> { } } - fn visit_path(&mut self, path: &hir::Path<'tcx>, hir_id: hir::HirId) { + fn visit_path(&mut self, path: &hir::Path<'tcx>, hir_id: HirId) { for (i, segment) in path.segments.iter().enumerate() { let depth = path.segments.len() - i - 1; if let Some(args) = segment.args { @@ -983,7 +983,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { } } - fn record_late_bound_vars(&mut self, hir_id: hir::HirId, binder: Vec) { + fn record_late_bound_vars(&mut self, hir_id: HirId, binder: Vec) { if let Some(old) = self.map.late_bound_vars.insert(hir_id, binder) { bug!( "overwrote bound vars for {hir_id:?}:\nold={old:?}\nnew={:?}", @@ -1010,12 +1010,8 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { /// already in scope (for a fn item, that will be 0, but for a method it might not be). Late /// bound lifetimes are resolved by name and associated with a binder ID (`binder_id`), so the /// ordering is not important there. - fn visit_early_late( - &mut self, - hir_id: hir::HirId, - generics: &'tcx hir::Generics<'tcx>, - walk: F, - ) where + fn visit_early_late(&mut self, hir_id: HirId, generics: &'tcx hir::Generics<'tcx>, walk: F) + where F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>), { let mut named_late_bound_vars = 0; @@ -1062,7 +1058,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { self.with(scope, walk); } - fn visit_early(&mut self, hir_id: hir::HirId, generics: &'tcx hir::Generics<'tcx>, walk: F) + fn visit_early(&mut self, hir_id: HirId, generics: &'tcx hir::Generics<'tcx>, walk: F) where F: for<'b, 'c> FnOnce(&'b mut BoundVarContext<'c, 'tcx>), { @@ -1288,7 +1284,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { ); } - fn resolve_type_ref(&mut self, param_def_id: LocalDefId, hir_id: hir::HirId) { + fn resolve_type_ref(&mut self, param_def_id: LocalDefId, hir_id: HirId) { // Walk up the scope chain, tracking the number of fn scopes // that we pass through, until we find a lifetime with the // given name or we run out of scopes. diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 63aeb165a4808..0fe02856a62fb 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -35,7 +35,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Namespace, Res}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::{walk_generics, Visitor as _}; -use rustc_hir::{GenericArg, GenericArgs}; +use rustc_hir::{GenericArg, GenericArgs, HirId}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_infer::traits::ObligationCause; use rustc_middle::middle::stability::AllowUnstable; @@ -158,7 +158,7 @@ pub trait HirTyLowerer<'tcx> { fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option>; /// Record the lowered type of a HIR node in this context. - fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, span: Span); + fn record_ty(&self, hir_id: HirId, ty: Ty<'tcx>, span: Span); /// The inference context of the lowering context if applicable. fn infcx(&self) -> Option<&InferCtxt<'tcx>>; @@ -999,7 +999,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { #[instrument(level = "debug", skip_all, ret)] pub fn lower_assoc_path( &self, - hir_ref_id: hir::HirId, + hir_ref_id: HirId, span: Span, qself_ty: Ty<'tcx>, qself: &'tcx hir::Ty<'tcx>, @@ -1200,7 +1200,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { segment: &hir::PathSegment<'tcx>, adt_did: DefId, self_ty: Ty<'tcx>, - block: hir::HirId, + block: HirId, span: Span, ) -> Result, DefId)>, ErrorGuaranteed> { let tcx = self.tcx(); @@ -1349,13 +1349,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { } } - fn probe_assoc_ty( - &self, - name: Ident, - block: hir::HirId, - span: Span, - scope: DefId, - ) -> Option { + fn probe_assoc_ty(&self, name: Ident, block: HirId, span: Span, scope: DefId) -> Option { let (item, def_scope) = self.probe_assoc_ty_unchecked(name, block, scope)?; self.check_assoc_ty(item, name, def_scope, block, span); Some(item) @@ -1364,7 +1358,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { fn probe_assoc_ty_unchecked( &self, name: Ident, - block: hir::HirId, + block: HirId, scope: DefId, ) -> Option<(DefId, DefId)> { let tcx = self.tcx(); @@ -1381,14 +1375,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { Some((item.def_id, def_scope)) } - fn check_assoc_ty( - &self, - item: DefId, - name: Ident, - def_scope: DefId, - block: hir::HirId, - span: Span, - ) { + fn check_assoc_ty(&self, item: DefId, name: Ident, def_scope: DefId, block: HirId, span: Span) { let tcx = self.tcx(); let kind = DefKind::AssocTy; @@ -1714,7 +1701,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { &self, opt_self_ty: Option>, path: &hir::Path<'tcx>, - hir_id: hir::HirId, + hir_id: HirId, permit_variants: bool, ) -> Ty<'tcx> { debug!(?path.res, ?opt_self_ty, ?path.segments); @@ -1887,7 +1874,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { /// /// Early-bound type parameters get lowered to [`ty::Param`] /// and late-bound ones to [`ty::Bound`]. - pub(crate) fn lower_ty_param(&self, hir_id: hir::HirId) -> Ty<'tcx> { + pub(crate) fn lower_ty_param(&self, hir_id: HirId) -> Ty<'tcx> { let tcx = self.tcx(); match tcx.named_bound_var(hir_id) { Some(rbv::ResolvedArg::LateBound(debruijn, index, def_id)) => { @@ -1914,7 +1901,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { /// /// Early-bound const parameters get lowered to [`ty::ConstKind::Param`] /// and late-bound ones to [`ty::ConstKind::Bound`]. - pub(crate) fn lower_const_param(&self, hir_id: hir::HirId, param_ty: Ty<'tcx>) -> Const<'tcx> { + pub(crate) fn lower_const_param(&self, hir_id: HirId, param_ty: Ty<'tcx>) -> Const<'tcx> { let tcx = self.tcx(); match tcx.named_bound_var(hir_id) { Some(rbv::ResolvedArg::EarlyBound(def_id)) => { @@ -2341,7 +2328,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { #[instrument(level = "debug", skip(self, hir_id, unsafety, abi, decl, generics, hir_ty), ret)] pub fn lower_fn_ty( &self, - hir_id: hir::HirId, + hir_id: HirId, unsafety: hir::Unsafety, abi: abi::Abi, decl: &hir::FnDecl<'tcx>, @@ -2469,7 +2456,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { /// corresponds to the return type. fn suggest_trait_fn_ty_for_impl_fn_infer( &self, - fn_hir_id: hir::HirId, + fn_hir_id: HirId, arg_idx: Option, ) -> Option> { let tcx = self.tcx(); diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 151e4a368499d..0ba2a473966c7 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -9,9 +9,10 @@ use rustc_ast_pretty::pp::Breaks::{Consistent, Inconsistent}; use rustc_ast_pretty::pp::{self, Breaks}; use rustc_ast_pretty::pprust::{Comments, PrintState}; use rustc_hir as hir; -use rustc_hir::LifetimeParamKind; -use rustc_hir::{BindingAnnotation, ByRef, GenericArg, GenericParam, GenericParamKind, Node, Term}; -use rustc_hir::{GenericBound, PatKind, RangeEnd, TraitBoundModifier}; +use rustc_hir::{ + BindingAnnotation, ByRef, GenericArg, GenericBound, GenericParam, GenericParamKind, HirId, + LifetimeParamKind, Node, PatKind, RangeEnd, Term, TraitBoundModifier, +}; use rustc_span::source_map::SourceMap; use rustc_span::symbol::{kw, Ident, Symbol}; use rustc_span::FileName; @@ -20,7 +21,7 @@ use rustc_target::spec::abi::Abi; use std::cell::Cell; use std::vec; -pub fn id_to_string(map: &dyn rustc_hir::intravisit::Map<'_>, hir_id: hir::HirId) -> String { +pub fn id_to_string(map: &dyn rustc_hir::intravisit::Map<'_>, hir_id: HirId) -> String { to_string(&map, |s| s.print_node(map.hir_node(hir_id))) } @@ -28,7 +29,7 @@ pub enum AnnNode<'a> { Name(&'a Symbol), Block(&'a hir::Block<'a>), Item(&'a hir::Item<'a>), - SubItem(hir::HirId), + SubItem(HirId), Expr(&'a hir::Expr<'a>), Pat(&'a hir::Pat<'a>), Arm(&'a hir::Arm<'a>), @@ -65,12 +66,12 @@ impl PpAnn for &dyn rustc_hir::intravisit::Map<'_> { pub struct State<'a> { pub s: pp::Printer, comments: Option>, - attrs: &'a dyn Fn(hir::HirId) -> &'a [ast::Attribute], + attrs: &'a dyn Fn(HirId) -> &'a [ast::Attribute], ann: &'a (dyn PpAnn + 'a), } impl<'a> State<'a> { - fn attrs(&self, id: hir::HirId) -> &'a [ast::Attribute] { + fn attrs(&self, id: HirId) -> &'a [ast::Attribute] { (self.attrs)(id) } @@ -159,7 +160,7 @@ pub fn print_crate<'a>( krate: &hir::Mod<'_>, filename: FileName, input: String, - attrs: &'a dyn Fn(hir::HirId) -> &'a [ast::Attribute], + attrs: &'a dyn Fn(HirId) -> &'a [ast::Attribute], ann: &'a dyn PpAnn, ) -> String { let mut s = State { diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 5a9fbc0aef5fc..8923137fdd82d 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -2851,7 +2851,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span: Span, base_ty: Ty<'tcx>, mod_id: DefId, - hir_id: hir::HirId, + hir_id: HirId, ) -> Vec<(Vec<&'tcx ty::FieldDef>, GenericArgsRef<'tcx>)> { debug!("get_field_candidates(span: {:?}, base_t: {:?}", span, base_ty); diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs index 5986b95966635..a0a5a75d3820a 100644 --- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs @@ -13,7 +13,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_hir as hir; use rustc_hir::def::Res; use rustc_hir::def_id::LocalDefId; -use rustc_hir::PatKind; +use rustc_hir::{HirId, PatKind}; use rustc_infer::infer::InferCtxt; use rustc_middle::hir::place::ProjectionKind; use rustc_middle::mir::FakeReadCause; @@ -39,20 +39,20 @@ pub trait Delegate<'tcx> { /// diagnostics. Around pattern matching such as `let pat = expr`, the diagnostic /// id will be the id of the expression `expr` but the place itself will have /// the id of the binding in the pattern `pat`. - fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId); + fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId); /// The value found at `place` is being borrowed with kind `bk`. /// `diag_expr_id` is the id used for diagnostics (see `consume` for more details). fn borrow( &mut self, place_with_id: &PlaceWithHirId<'tcx>, - diag_expr_id: hir::HirId, + diag_expr_id: HirId, bk: ty::BorrowKind, ); /// The value found at `place` is being copied. /// `diag_expr_id` is the id used for diagnostics (see `consume` for more details). - fn copy(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) { + fn copy(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) { // In most cases, copying data from `x` is equivalent to doing `*&x`, so by default // we treat a copy of `x` as a borrow of `x`. self.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow) @@ -60,12 +60,12 @@ pub trait Delegate<'tcx> { /// The path at `assignee_place` is being assigned to. /// `diag_expr_id` is the id used for diagnostics (see `consume` for more details). - fn mutate(&mut self, assignee_place: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId); + fn mutate(&mut self, assignee_place: &PlaceWithHirId<'tcx>, diag_expr_id: HirId); /// The path at `binding_place` is a binding that is being initialized. /// /// This covers cases such as `let x = 42;` - fn bind(&mut self, binding_place: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) { + fn bind(&mut self, binding_place: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) { // Bindings can normally be treated as a regular assignment, so by default we // forward this to the mutate callback. self.mutate(binding_place, diag_expr_id) @@ -76,7 +76,7 @@ pub trait Delegate<'tcx> { &mut self, place_with_id: &PlaceWithHirId<'tcx>, cause: FakeReadCause, - diag_expr_id: hir::HirId, + diag_expr_id: HirId, ); } @@ -154,7 +154,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { self.mc.tcx() } - fn delegate_consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) { + fn delegate_consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) { delegate_consume(&self.mc, self.delegate, place_with_id, diag_expr_id) } @@ -775,8 +775,8 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { /// closure as the DefId. fn walk_captures(&mut self, closure_expr: &hir::Closure<'_>) { fn upvar_is_local_variable( - upvars: Option<&FxIndexMap>, - upvar_id: hir::HirId, + upvars: Option<&FxIndexMap>, + upvar_id: HirId, body_owner_is_closure: bool, ) -> bool { upvars.map(|upvars| !upvars.contains_key(&upvar_id)).unwrap_or(body_owner_is_closure) @@ -902,7 +902,7 @@ fn delegate_consume<'a, 'tcx>( mc: &mc::MemCategorizationContext<'a, 'tcx>, delegate: &mut (dyn Delegate<'tcx> + 'a), place_with_id: &PlaceWithHirId<'tcx>, - diag_expr_id: hir::HirId, + diag_expr_id: HirId, ) { debug!("delegate_consume(place_with_id={:?})", place_with_id); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 2d5ba447e4e68..786754ed12f09 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -10,7 +10,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::lang_items::LangItem; -use rustc_hir::{ExprKind, GenericArg, Node, QPath}; +use rustc_hir::{ExprKind, GenericArg, HirId, Node, QPath}; use rustc_hir_analysis::hir_ty_lowering::errors::GenericsArgsErrExtend; use rustc_hir_analysis::hir_ty_lowering::generics::{ check_generic_arg_count_for_call, lower_generic_args, @@ -47,7 +47,7 @@ use std::slice; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Produces warning on the given node, if the current point in the /// function is unreachable, and there hasn't been another warning. - pub(in super::super) fn warn_if_unreachable(&self, id: hir::HirId, span: Span, kind: &str) { + pub(in super::super) fn warn_if_unreachable(&self, id: HirId, span: Span, kind: &str) { // FIXME: Combine these two 'if' expressions into one once // let chains are implemented if let Diverges::Always { span: orig_span, custom_note } = self.diverges.get() { @@ -130,14 +130,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { format!("{self:p}") } - pub fn local_ty(&self, span: Span, nid: hir::HirId) -> Ty<'tcx> { + pub fn local_ty(&self, span: Span, nid: HirId) -> Ty<'tcx> { self.locals.borrow().get(&nid).cloned().unwrap_or_else(|| { span_bug!(span, "no type for local variable {}", self.tcx.hir().node_to_string(nid)) }) } #[inline] - pub fn write_ty(&self, id: hir::HirId, ty: Ty<'tcx>) { + pub fn write_ty(&self, id: HirId, ty: Ty<'tcx>) { debug!("write_ty({:?}, {:?}) in fcx {}", id, self.resolve_vars_if_possible(ty), self.tag()); let mut typeck = self.typeck_results.borrow_mut(); let mut node_ty = typeck.node_types_mut(); @@ -161,7 +161,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn write_field_index( &self, - hir_id: hir::HirId, + hir_id: HirId, index: FieldIdx, nested_fields: Vec<(Ty<'tcx>, FieldIdx)>, ) { @@ -174,7 +174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[instrument(level = "debug", skip(self))] pub(in super::super) fn write_resolution( &self, - hir_id: hir::HirId, + hir_id: HirId, r: Result<(DefKind, DefId), ErrorGuaranteed>, ) { self.typeck_results.borrow_mut().type_dependent_defs_mut().insert(hir_id, r); @@ -183,7 +183,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[instrument(level = "debug", skip(self))] pub fn write_method_call_and_enforce_effects( &self, - hir_id: hir::HirId, + hir_id: HirId, span: Span, method: MethodCallee<'tcx>, ) { @@ -192,7 +192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.write_args(hir_id, method.args); } - pub fn write_args(&self, node_id: hir::HirId, args: GenericArgsRef<'tcx>) { + pub fn write_args(&self, node_id: HirId, args: GenericArgsRef<'tcx>) { if !args.is_empty() { debug!("write_args({:?}, {:?}) in fcx {}", node_id, args, self.tag()); @@ -210,7 +210,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[instrument(skip(self), level = "debug")] pub fn write_user_type_annotation_from_args( &self, - hir_id: hir::HirId, + hir_id: HirId, def_id: DefId, args: GenericArgsRef<'tcx>, user_self_ty: Option>, @@ -230,7 +230,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[instrument(skip(self), level = "debug")] pub fn write_user_type_annotation( &self, - hir_id: hir::HirId, + hir_id: HirId, canonical_user_type_annotation: CanonicalUserType<'tcx>, ) { debug!("fcx {}", self.tag()); @@ -464,7 +464,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { t.has_free_regions() || t.has_aliases() || t.has_infer_types() } - pub fn node_ty(&self, id: hir::HirId) -> Ty<'tcx> { + pub fn node_ty(&self, id: HirId) -> Ty<'tcx> { match self.typeck_results.borrow().node_types().get(id) { Some(&t) => t, None if let Some(e) = self.tainted_by_errors() => Ty::new_error(self.tcx, e), @@ -478,7 +478,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - pub fn node_ty_opt(&self, id: hir::HirId) -> Option> { + pub fn node_ty_opt(&self, id: HirId) -> Option> { match self.typeck_results.borrow().node_types().get(id) { Some(&t) => Some(t), None if let Some(e) = self.tainted_by_errors() => Some(Ty::new_error(self.tcx, e)), @@ -742,7 +742,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, lang_item: hir::LangItem, span: Span, - hir_id: hir::HirId, + hir_id: HirId, ) -> (Res, Ty<'tcx>) { let def_id = self.tcx.require_lang_item(lang_item, Some(span)); let def_kind = self.tcx.def_kind(def_id); @@ -790,7 +790,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn resolve_ty_and_res_fully_qualified_call( &self, qpath: &'tcx QPath<'tcx>, - hir_id: hir::HirId, + hir_id: HirId, span: Span, args: Option<&'tcx [hir::Expr<'tcx>]>, ) -> (Res, Option>, &'tcx [hir::PathSegment<'tcx>]) { @@ -984,7 +984,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// suggestion can be made, `None` otherwise. pub fn get_fn_decl( &self, - blk_id: hir::HirId, + blk_id: HirId, ) -> Option<(LocalDefId, &'tcx hir::FnDecl<'tcx>, bool)> { // Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or // `while` before reaching it, as block tail returns are not available in them. @@ -1080,7 +1080,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { res: Res, span: Span, path_span: Span, - hir_id: hir::HirId, + hir_id: HirId, ) -> (Ty<'tcx>, Res) { let tcx = self.tcx; @@ -1450,7 +1450,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span: Span, def_id: DefId, args: GenericArgsRef<'tcx>, - hir_id: hir::HirId, + hir_id: HirId, ) { self.add_required_obligations_with_code(span, def_id, args, |idx, span| { if span.is_dummy() { @@ -1541,7 +1541,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub(in super::super) fn with_breakable_ctxt R, R>( &self, - id: hir::HirId, + id: HirId, ctxt: BreakableCtxt<'tcx>, f: F, ) -> (BreakableCtxt<'tcx>, R) { @@ -1580,7 +1580,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } /// Returns `true` if an expression is contained inside the LHS of an assignment expression. - pub(in super::super) fn expr_in_place(&self, mut expr_id: hir::HirId) -> bool { + pub(in super::super) fn expr_in_place(&self, mut expr_id: HirId) -> bool { let mut contained_in_place = false; while let hir::Node::Expr(parent_expr) = self.tcx.parent_hir_node(expr_id) { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index f346c6446e009..4a73ce2e64095 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -24,7 +24,7 @@ use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::DefId; use rustc_hir::intravisit::Visitor; -use rustc_hir::{ExprKind, Node, QPath}; +use rustc_hir::{ExprKind, HirId, Node, QPath}; use rustc_hir_analysis::check::intrinsicck::InlineAsmCtxt; use rustc_hir_analysis::check::potentially_plural_count; use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; @@ -1489,7 +1489,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn check_struct_path( &self, qpath: &QPath<'tcx>, - hir_id: hir::HirId, + hir_id: HirId, ) -> Result<(&'tcx ty::VariantDef, Ty<'tcx>), ErrorGuaranteed> { let path_span = qpath.span(); let (def, ty) = self.finish_resolving_struct_path(qpath, path_span, hir_id); @@ -1554,7 +1554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn check_decl_initializer( &self, - hir_id: hir::HirId, + hir_id: HirId, pat: &'tcx hir::Pat<'tcx>, init: &'tcx hir::Expr<'tcx>, ) -> Ty<'tcx> { @@ -1879,7 +1879,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty } - fn parent_item_span(&self, id: hir::HirId) -> Option { + fn parent_item_span(&self, id: HirId) -> Option { let node = self.tcx.hir_node_by_def_id(self.tcx.hir().get_parent_item(id).def_id); match node { Node::Item(&hir::Item { kind: hir::ItemKind::Fn(_, _, body_id), .. }) @@ -1897,7 +1897,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Given a function block's `HirId`, returns its `FnDecl` if it exists, or `None` otherwise. pub(crate) fn get_parent_fn_decl( &self, - blk_id: hir::HirId, + blk_id: HirId, ) -> Option<(&'tcx hir::FnDecl<'tcx>, Ident)> { let parent = self.tcx.hir_node_by_def_id(self.tcx.hir().get_parent_item(blk_id).def_id); self.get_node_fn_decl(parent).map(|(_, fn_decl, ident, _)| (fn_decl, ident)) @@ -1939,12 +1939,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expr.span } - fn overwrite_local_ty_if_err( - &self, - hir_id: hir::HirId, - pat: &'tcx hir::Pat<'tcx>, - ty: Ty<'tcx>, - ) { + fn overwrite_local_ty_if_err(&self, hir_id: HirId, pat: &'tcx hir::Pat<'tcx>, ty: Ty<'tcx>) { if let Err(guar) = ty.error_reported() { struct OverwritePatternsWithError { pat_hir_ids: Vec, @@ -1977,7 +1972,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, qpath: &QPath<'tcx>, path_span: Span, - hir_id: hir::HirId, + hir_id: HirId, ) -> (Res, LoweredTy<'tcx>) { match *qpath { QPath::Resolved(ref maybe_qself, path) => { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index ce203eae95fd0..43e5ab0ed53f8 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -71,7 +71,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expr: &'tcx hir::Expr<'tcx>, expected: Ty<'tcx>, found: Ty<'tcx>, - blk_id: hir::HirId, + blk_id: HirId, ) -> bool { let expr = expr.peel_drop_temps(); let mut pointing_at_return_type = false; @@ -1031,7 +1031,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn_decl: &hir::FnDecl<'tcx>, expected: Ty<'tcx>, found: Ty<'tcx>, - id: hir::HirId, + id: HirId, fn_id: LocalDefId, ) { if !expected.is_unit() { @@ -1600,12 +1600,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - fn is_loop(&self, id: hir::HirId) -> bool { + fn is_loop(&self, id: HirId) -> bool { let node = self.tcx.hir_node(id); matches!(node, Node::Expr(Expr { kind: ExprKind::Loop(..), .. })) } - fn is_local_statement(&self, id: hir::HirId) -> bool { + fn is_local_statement(&self, id: HirId) -> bool { let node = self.tcx.hir_node(id); matches!(node, Node::Stmt(Stmt { kind: StmtKind::Let(..), .. })) } diff --git a/compiler/rustc_hir_typeck/src/gather_locals.rs b/compiler/rustc_hir_typeck/src/gather_locals.rs index 0b985e40c4e0e..fe0a46924de46 100644 --- a/compiler/rustc_hir_typeck/src/gather_locals.rs +++ b/compiler/rustc_hir_typeck/src/gather_locals.rs @@ -1,7 +1,7 @@ use crate::FnCtxt; use rustc_hir as hir; use rustc_hir::intravisit::{self, Visitor}; -use rustc_hir::PatKind; +use rustc_hir::{HirId, PatKind}; use rustc_infer::infer::type_variable::TypeVariableOrigin; use rustc_middle::ty::Ty; use rustc_middle::ty::UserType; @@ -33,7 +33,7 @@ impl<'a> DeclOrigin<'a> { /// /// It must have a hir_id, as this is how we connect gather_locals to the check functions. pub(super) struct Declaration<'a> { - pub hir_id: hir::HirId, + pub hir_id: HirId, pub pat: &'a hir::Pat<'a>, pub ty: Option<&'a hir::Ty<'a>>, pub span: Span, @@ -48,8 +48,8 @@ impl<'a> From<&'a hir::LetStmt<'a>> for Declaration<'a> { } } -impl<'a> From<(&'a hir::LetExpr<'a>, hir::HirId)> for Declaration<'a> { - fn from((let_expr, hir_id): (&'a hir::LetExpr<'a>, hir::HirId)) -> Self { +impl<'a> From<(&'a hir::LetExpr<'a>, HirId)> for Declaration<'a> { + fn from((let_expr, hir_id): (&'a hir::LetExpr<'a>, HirId)) -> Self { let hir::LetExpr { pat, ty, span, init, is_recovered: _ } = *let_expr; Declaration { hir_id, pat, ty, span, init: Some(init), origin: DeclOrigin::LetExpr } } @@ -60,7 +60,7 @@ pub(super) struct GatherLocalsVisitor<'a, 'tcx> { // parameters are special cases of patterns, but we want to handle them as // *distinct* cases. so track when we are hitting a pattern *within* an fn // parameter. - outermost_fn_param_pat: Option<(Span, hir::HirId)>, + outermost_fn_param_pat: Option<(Span, HirId)>, } impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> { @@ -68,7 +68,7 @@ impl<'a, 'tcx> GatherLocalsVisitor<'a, 'tcx> { Self { fcx, outermost_fn_param_pat: None } } - fn assign(&mut self, span: Span, nid: hir::HirId, ty_opt: Option>) -> Ty<'tcx> { + fn assign(&mut self, span: Span, nid: HirId, ty_opt: Option>) -> Ty<'tcx> { match ty_opt { None => { // Infer the variable's type. diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 901edb9ecd5bf..121815ecc0ba5 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -57,7 +57,7 @@ use rustc_errors::{codes::*, struct_span_code_err, ErrorGuaranteed}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::Visitor; -use rustc_hir::{HirIdMap, Node}; +use rustc_hir::{HirId, HirIdMap, Node}; use rustc_hir_analysis::check::check_abi; use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer; use rustc_infer::infer::type_variable::TypeVariableOrigin; @@ -339,13 +339,13 @@ pub struct EnclosingBreakables<'tcx> { } impl<'tcx> EnclosingBreakables<'tcx> { - fn find_breakable(&mut self, target_id: hir::HirId) -> &mut BreakableCtxt<'tcx> { + fn find_breakable(&mut self, target_id: HirId) -> &mut BreakableCtxt<'tcx> { self.opt_find_breakable(target_id).unwrap_or_else(|| { bug!("could not find enclosing breakable with id {}", target_id); }) } - fn opt_find_breakable(&mut self, target_id: hir::HirId) -> Option<&mut BreakableCtxt<'tcx>> { + fn opt_find_breakable(&mut self, target_id: HirId) -> Option<&mut BreakableCtxt<'tcx>> { match self.by_id.get(&target_id) { Some(ix) => Some(&mut self.stack[*ix]), None => None, diff --git a/compiler/rustc_hir_typeck/src/mem_categorization.rs b/compiler/rustc_hir_typeck/src/mem_categorization.rs index f2425d034495a..859877962fe78 100644 --- a/compiler/rustc_hir_typeck/src/mem_categorization.rs +++ b/compiler/rustc_hir_typeck/src/mem_categorization.rs @@ -58,24 +58,24 @@ use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind, Res}; use rustc_hir::def_id::LocalDefId; use rustc_hir::pat_util::EnumerateAndAdjustIterator; -use rustc_hir::PatKind; +use rustc_hir::{HirId, PatKind}; use rustc_infer::infer::InferCtxt; use rustc_span::Span; use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT}; use rustc_trait_selection::infer::InferCtxtExt; pub(crate) trait HirNode { - fn hir_id(&self) -> hir::HirId; + fn hir_id(&self) -> HirId; } impl HirNode for hir::Expr<'_> { - fn hir_id(&self) -> hir::HirId { + fn hir_id(&self) -> HirId { self.hir_id } } impl HirNode for hir::Pat<'_> { - fn hir_id(&self) -> hir::HirId { + fn hir_id(&self) -> HirId { self.hir_id } } @@ -86,7 +86,7 @@ pub(crate) struct MemCategorizationContext<'a, 'tcx> { infcx: &'a InferCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, body_owner: LocalDefId, - upvars: Option<&'tcx FxIndexMap>, + upvars: Option<&'tcx FxIndexMap>, } pub(crate) type McResult = Result; @@ -127,11 +127,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { self.infcx.tainted_by_errors().is_some() } - fn resolve_type_vars_or_error( - &self, - id: hir::HirId, - ty: Option>, - ) -> McResult> { + fn resolve_type_vars_or_error(&self, id: HirId, ty: Option>) -> McResult> { match ty { Some(ty) => { let ty = self.resolve_vars_if_possible(ty); @@ -153,7 +149,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { } } - pub(crate) fn node_ty(&self, hir_id: hir::HirId) -> McResult> { + pub(crate) fn node_ty(&self, hir_id: HirId) -> McResult> { self.resolve_type_vars_or_error(hir_id, self.typeck_results.node_type_opt(hir_id)) } @@ -377,7 +373,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { #[instrument(level = "debug", skip(self, span), ret)] pub(crate) fn cat_res( &self, - hir_id: hir::HirId, + hir_id: HirId, span: Span, expr_ty: Ty<'tcx>, res: Res, @@ -416,7 +412,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { /// environment and upvar reference as appropriate. Only regionck cares /// about these dereferences, so we let it compute them as needed. #[instrument(level = "debug", skip(self), ret)] - fn cat_upvar(&self, hir_id: hir::HirId, var_id: hir::HirId) -> McResult> { + fn cat_upvar(&self, hir_id: HirId, var_id: HirId) -> McResult> { let closure_expr_def_id = self.body_owner; let upvar_id = ty::UpvarId { @@ -429,7 +425,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { } #[instrument(level = "debug", skip(self), ret)] - pub(crate) fn cat_rvalue(&self, hir_id: hir::HirId, expr_ty: Ty<'tcx>) -> PlaceWithHirId<'tcx> { + pub(crate) fn cat_rvalue(&self, hir_id: HirId, expr_ty: Ty<'tcx>) -> PlaceWithHirId<'tcx> { PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::Rvalue, Vec::new()) } @@ -523,7 +519,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { fn variant_index_for_adt( &self, qpath: &hir::QPath<'_>, - pat_hir_id: hir::HirId, + pat_hir_id: HirId, span: Span, ) -> McResult { let res = self.typeck_results.qpath_res(qpath, pat_hir_id); @@ -556,7 +552,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { /// Here `pat_hir_id` is the HirId of the pattern itself. fn total_fields_in_adt_variant( &self, - pat_hir_id: hir::HirId, + pat_hir_id: HirId, variant_index: VariantIdx, span: Span, ) -> McResult { @@ -573,7 +569,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> { /// Returns the total number of fields in a tuple used within a Tuple pattern. /// Here `pat_hir_id` is the HirId of the pattern itself. - fn total_fields_in_tuple(&self, pat_hir_id: hir::HirId, span: Span) -> McResult { + fn total_fields_in_tuple(&self, pat_hir_id: HirId, span: Span) -> McResult { let ty = self.typeck_results.node_type(pat_hir_id); match ty.kind() { ty::Tuple(args) => Ok(args.len()), diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 28e17e1de36c3..f8cc34398a751 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -8,6 +8,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; use rustc_hir as hir; use rustc_hir::def::DefKind; +use rustc_hir::HirId; use rustc_hir_analysis::autoderef::{self, Autoderef}; use rustc_infer::infer::canonical::OriginalQueryValues; use rustc_infer::infer::canonical::{Canonical, QueryResponse}; @@ -86,7 +87,7 @@ pub(crate) struct ProbeContext<'a, 'tcx> { Vec<(ty::Predicate<'tcx>, Option>, Option>)>, >, - scope_expr_id: hir::HirId, + scope_expr_id: HirId, } impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> { @@ -263,7 +264,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { mode: Mode, return_type: Ty<'tcx>, self_ty: Ty<'tcx>, - scope_expr_id: hir::HirId, + scope_expr_id: HirId, candidate_filter: impl Fn(&ty::AssocItem) -> bool, ) -> Vec { let method_names = self @@ -307,7 +308,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return_type: Option>, is_suggestion: IsSuggestion, self_ty: Ty<'tcx>, - scope_expr_id: hir::HirId, + scope_expr_id: HirId, scope: ProbeScope, ) -> PickResult<'tcx> { self.probe_op( @@ -331,7 +332,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return_type: Option>, is_suggestion: IsSuggestion, self_ty: Ty<'tcx>, - scope_expr_id: hir::HirId, + scope_expr_id: HirId, scope: ProbeScope, ) -> Vec> { self.probe_op( @@ -362,7 +363,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return_type: Option>, is_suggestion: IsSuggestion, self_ty: Ty<'tcx>, - scope_expr_id: hir::HirId, + scope_expr_id: HirId, scope: ProbeScope, op: OP, ) -> Result> @@ -589,7 +590,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { return_type: Option>, orig_steps_var_values: &'a OriginalQueryValues<'tcx>, steps: &'tcx [CandidateStep<'tcx>], - scope_expr_id: hir::HirId, + scope_expr_id: HirId, ) -> ProbeContext<'a, 'tcx> { ProbeContext { fcx, @@ -1381,7 +1382,7 @@ impl<'tcx> Pick<'tcx> { &self, tcx: TyCtxt<'tcx>, span: Span, - scope_expr_id: hir::HirId, + scope_expr_id: HirId, ) { if self.unstable_candidates.is_empty() { return; diff --git a/compiler/rustc_hir_typeck/src/typeck_root_ctxt.rs b/compiler/rustc_hir_typeck/src/typeck_root_ctxt.rs index 694ddd0e3e887..31ce271a5fc48 100644 --- a/compiler/rustc_hir_typeck/src/typeck_root_ctxt.rs +++ b/compiler/rustc_hir_typeck/src/typeck_root_ctxt.rs @@ -3,7 +3,7 @@ use super::callee::DeferredCallResolution; use rustc_data_structures::unord::{UnordMap, UnordSet}; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; -use rustc_hir::HirIdMap; +use rustc_hir::{HirId, HirIdMap}; use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt}; use rustc_middle::ty::visit::TypeVisitableExt; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -52,9 +52,9 @@ pub(crate) struct TypeckRootCtxt<'tcx> { pub(super) deferred_cast_checks: RefCell>>, - pub(super) deferred_transmute_checks: RefCell, Ty<'tcx>, hir::HirId)>>, + pub(super) deferred_transmute_checks: RefCell, Ty<'tcx>, HirId)>>, - pub(super) deferred_asm_checks: RefCell, hir::HirId)>>, + pub(super) deferred_asm_checks: RefCell, HirId)>>, pub(super) deferred_coroutine_interiors: RefCell)>>, diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index 86f36eedd9007..60a5838cafcea 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -38,6 +38,7 @@ use rustc_errors::{Applicability, MultiSpan}; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; use rustc_hir::intravisit::{self, Visitor}; +use rustc_hir::HirId; use rustc_infer::infer::UpvarRegion; use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection, ProjectionKind}; use rustc_middle::mir::FakeReadCause; @@ -88,7 +89,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] enum UpvarMigrationInfo { /// We previously captured all of `x`, but now we capture some sub-path. - CapturingPrecise { source_expr: Option, var_name: String }, + CapturingPrecise { source_expr: Option, var_name: String }, CapturingNothing { // where the variable appears in the closure (but is not captured) use_span: Span, @@ -131,7 +132,7 @@ struct MigrationLintNote { /// Intermediate format to store the hir id of the root variable and a HashSet containing /// information on why the root variable should be fully captured struct NeededMigration { - var_hir_id: hir::HirId, + var_hir_id: HirId, diagnostics_info: Vec, } @@ -163,7 +164,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { #[instrument(skip(self, body), level = "debug")] fn analyze_closure( &self, - closure_hir_id: hir::HirId, + closure_hir_id: HirId, span: Span, body_id: hir::BodyId, body: &'tcx hir::Body<'tcx>, @@ -1098,7 +1099,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn compute_2229_migrations_for_trait( &self, min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>, - var_hir_id: hir::HirId, + var_hir_id: HirId, closure_clause: hir::CaptureBy, ) -> Option>> { let auto_traits_def_id = [ @@ -1210,7 +1211,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { closure_span: Span, min_captures: Option<&ty::RootVariableMinCaptureList<'tcx>>, closure_clause: hir::CaptureBy, - var_hir_id: hir::HirId, + var_hir_id: HirId, ) -> Option> { let ty = self.resolve_vars_if_possible(self.node_ty(var_hir_id)); @@ -1650,7 +1651,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn place_for_root_variable( &self, closure_def_id: LocalDefId, - var_hir_id: hir::HirId, + var_hir_id: HirId, ) -> Place<'tcx> { let upvar_id = ty::UpvarId::new(var_hir_id, closure_def_id); @@ -1881,7 +1882,7 @@ fn apply_capture_kind_on_capture_ty<'tcx>( } /// Returns the Span of where the value with the provided HirId would be dropped -fn drop_location_span(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> Span { +fn drop_location_span(tcx: TyCtxt<'_>, hir_id: HirId) -> Span { let owner_id = tcx.hir().get_enclosing_scope(hir_id).unwrap(); let owner_node = tcx.hir_node(owner_id); @@ -1933,7 +1934,7 @@ struct InferBorrowKind<'tcx> { /// Place { V1, [ProjectionKind::Field(Index=1, Variant=0)] } : CaptureKind { E2, MutableBorrow } /// ``` capture_information: InferredCaptureInformation<'tcx>, - fake_reads: Vec<(Place<'tcx>, FakeReadCause, hir::HirId)>, + fake_reads: Vec<(Place<'tcx>, FakeReadCause, HirId)>, } impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> { @@ -1941,7 +1942,7 @@ impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> { &mut self, place: &PlaceWithHirId<'tcx>, cause: FakeReadCause, - diag_expr_id: hir::HirId, + diag_expr_id: HirId, ) { let PlaceBase::Upvar(_) = place.place.base else { return }; @@ -1956,7 +1957,7 @@ impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> { } #[instrument(skip(self), level = "debug")] - fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) { + fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) { let PlaceBase::Upvar(upvar_id) = place_with_id.place.base else { return }; assert_eq!(self.closure_def_id, upvar_id.closure_expr_id); @@ -1974,7 +1975,7 @@ impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> { fn borrow( &mut self, place_with_id: &PlaceWithHirId<'tcx>, - diag_expr_id: hir::HirId, + diag_expr_id: HirId, bk: ty::BorrowKind, ) { let PlaceBase::Upvar(upvar_id) = place_with_id.place.base else { return }; @@ -2005,7 +2006,7 @@ impl<'tcx> euv::Delegate<'tcx> for InferBorrowKind<'tcx> { } #[instrument(skip(self), level = "debug")] - fn mutate(&mut self, assignee_place: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) { + fn mutate(&mut self, assignee_place: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) { self.borrow(assignee_place, diag_expr_id, ty::BorrowKind::MutBorrow); } } @@ -2192,14 +2193,14 @@ fn construct_capture_info_string<'tcx>( format!("{place_str} -> {capture_kind_str}") } -fn var_name(tcx: TyCtxt<'_>, var_hir_id: hir::HirId) -> Symbol { +fn var_name(tcx: TyCtxt<'_>, var_hir_id: HirId) -> Symbol { tcx.hir().name(var_hir_id) } #[instrument(level = "debug", skip(tcx))] fn should_do_rust_2021_incompatible_closure_captures_analysis( tcx: TyCtxt<'_>, - closure_id: hir::HirId, + closure_id: HirId, ) -> bool { if tcx.sess.at_least_rust_2021() { return false; diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index 6604bf094c14a..875f8b23a84b8 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -7,6 +7,7 @@ use rustc_data_structures::unord::ExtendUnord; use rustc_errors::{ErrorGuaranteed, StashKey}; use rustc_hir as hir; use rustc_hir::intravisit::{self, Visitor}; +use rustc_hir::HirId; use rustc_infer::infer::error_reporting::TypeAnnotationNeeded::E0282; use rustc_middle::traits::ObligationCause; use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion}; @@ -134,7 +135,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { self.fcx.tcx } - fn write_ty_to_typeck_results(&mut self, hir_id: hir::HirId, ty: Ty<'tcx>) { + fn write_ty_to_typeck_results(&mut self, hir_id: HirId, ty: Ty<'tcx>) { debug!("write_ty_to_typeck_results({:?}, {:?})", hir_id, ty); assert!( !ty.has_infer() && !ty.has_placeholders() && !ty.has_free_regions(), @@ -461,7 +462,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { fcx_typeck_results.closure_kind_origins().items_in_stable_order(); for (local_id, origin) in fcx_closure_kind_origins { - let hir_id = hir::HirId { owner: common_hir_owner, local_id }; + let hir_id = HirId { owner: common_hir_owner, local_id }; let place_span = origin.0; let place = self.resolve(origin.1.clone(), &place_span); self.typeck_results.closure_kind_origins_mut().insert(hir_id, (place_span, place)); @@ -490,7 +491,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { let mut errors_buffer = Vec::new(); for (local_id, c_ty) in sorted_user_provided_types { - let hir_id = hir::HirId { owner: common_hir_owner, local_id }; + let hir_id = HirId { owner: common_hir_owner, local_id }; if let ty::UserType::TypeOf(_, user_args) = c_ty.value { // This is a unit-testing mechanism. @@ -513,7 +514,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { self.typeck_results.user_provided_types_mut().extend( fcx_typeck_results.user_provided_types().items().map(|(local_id, c_ty)| { - let hir_id = hir::HirId { owner: common_hir_owner, local_id }; + let hir_id = HirId { owner: common_hir_owner, local_id }; if cfg!(debug_assertions) && c_ty.has_infer() { span_bug!( @@ -604,7 +605,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { } } - fn visit_field_id(&mut self, hir_id: hir::HirId) { + fn visit_field_id(&mut self, hir_id: HirId) { if let Some(index) = self.fcx.typeck_results.borrow_mut().field_indices_mut().remove(hir_id) { self.typeck_results.field_indices_mut().insert(hir_id, index); @@ -617,7 +618,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { } #[instrument(skip(self, span), level = "debug")] - fn visit_node_id(&mut self, span: Span, hir_id: hir::HirId) { + fn visit_node_id(&mut self, span: Span, hir_id: HirId) { // Export associated path extensions and method resolutions. if let Some(def) = self.fcx.typeck_results.borrow_mut().type_dependent_defs_mut().remove(hir_id) @@ -644,7 +645,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { } #[instrument(skip(self, span), level = "debug")] - fn visit_adjustments(&mut self, span: Span, hir_id: hir::HirId) { + fn visit_adjustments(&mut self, span: Span, hir_id: HirId) { let adjustment = self.fcx.typeck_results.borrow_mut().adjustments_mut().remove(hir_id); match adjustment { None => { @@ -660,7 +661,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { } #[instrument(skip(self, span), level = "debug")] - fn visit_pat_adjustments(&mut self, span: Span, hir_id: hir::HirId) { + fn visit_pat_adjustments(&mut self, span: Span, hir_id: HirId) { let adjustment = self.fcx.typeck_results.borrow_mut().pat_adjustments_mut().remove(hir_id); match adjustment { None => { @@ -691,7 +692,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { let fcx_liberated_fn_sigs = fcx_typeck_results.liberated_fn_sigs().items_in_stable_order(); for (local_id, &fn_sig) in fcx_liberated_fn_sigs { - let hir_id = hir::HirId { owner: common_hir_owner, local_id }; + let hir_id = HirId { owner: common_hir_owner, local_id }; let fn_sig = self.resolve(fn_sig, &hir_id); self.typeck_results.liberated_fn_sigs_mut().insert(hir_id, fn_sig); } @@ -705,7 +706,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { let fcx_fru_field_types = fcx_typeck_results.fru_field_types().items_in_stable_order(); for (local_id, ftys) in fcx_fru_field_types { - let hir_id = hir::HirId { owner: common_hir_owner, local_id }; + let hir_id = HirId { owner: common_hir_owner, local_id }; let ftys = self.resolve(ftys.clone(), &hir_id); self.typeck_results.fru_field_types_mut().insert(hir_id, ftys); } @@ -719,7 +720,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { for (local_id, &(container, ref indices)) in fcx_typeck_results.offset_of_data().items_in_stable_order() { - let hir_id = hir::HirId { owner: common_hir_owner, local_id }; + let hir_id = HirId { owner: common_hir_owner, local_id }; let container = self.resolve(container, &hir_id); self.typeck_results.offset_of_data_mut().insert(hir_id, (container, indices.clone())); } @@ -754,7 +755,7 @@ impl Locatable for Span { } } -impl Locatable for hir::HirId { +impl Locatable for HirId { fn to_span(&self, tcx: TyCtxt<'_>) -> Span { tcx.hir().span(*self) } diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs index 99207e3f315cf..ca188277b9dee 100644 --- a/compiler/rustc_lint/src/late.rs +++ b/compiler/rustc_lint/src/late.rs @@ -20,6 +20,7 @@ use rustc_data_structures::sync::{join, Lrc}; use rustc_hir as hir; use rustc_hir::def_id::{LocalDefId, LocalModDefId}; use rustc_hir::intravisit as hir_visit; +use rustc_hir::HirId; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, TyCtxt}; use rustc_session::lint::LintPass; @@ -53,7 +54,7 @@ impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> { /// Merge the lints specified by any lint attributes into the /// current lint context, call the provided function, then reset the /// lints in effect to their previous state. - fn with_lint_attrs(&mut self, id: hir::HirId, f: F) + fn with_lint_attrs(&mut self, id: HirId, f: F) where F: FnOnce(&mut Self), { @@ -81,7 +82,7 @@ impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> { self.context.param_env = old_param_env; } - fn process_mod(&mut self, m: &'tcx hir::Mod<'tcx>, n: hir::HirId) { + fn process_mod(&mut self, m: &'tcx hir::Mod<'tcx>, n: HirId) { lint_callback!(self, check_mod, m, n); hir_visit::walk_mod(self, m, n); } @@ -231,7 +232,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas hir_visit::walk_inf(self, inf); } - fn visit_mod(&mut self, m: &'tcx hir::Mod<'tcx>, _: Span, n: hir::HirId) { + fn visit_mod(&mut self, m: &'tcx hir::Mod<'tcx>, _: Span, n: HirId) { if !self.context.only_module { self.process_mod(m, n); } @@ -305,7 +306,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas hir_visit::walk_lifetime(self, lt); } - fn visit_path(&mut self, p: &hir::Path<'tcx>, id: hir::HirId) { + fn visit_path(&mut self, p: &hir::Path<'tcx>, id: HirId) { lint_callback!(self, check_path, p, id); hir_visit::walk_path(self, p); } diff --git a/compiler/rustc_middle/src/middle/region.rs b/compiler/rustc_middle/src/middle/region.rs index b9914f6cb7a00..5ae60e0427719 100644 --- a/compiler/rustc_middle/src/middle/region.rs +++ b/compiler/rustc_middle/src/middle/region.rs @@ -10,7 +10,7 @@ use crate::ty::TyCtxt; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::unord::UnordMap; use rustc_hir as hir; -use rustc_hir::{HirIdMap, Node}; +use rustc_hir::{HirId, HirIdMap, Node}; use rustc_macros::HashStable; use rustc_span::{Span, DUMMY_SP}; @@ -164,10 +164,10 @@ impl Scope { self.id } - pub fn hir_id(&self, scope_tree: &ScopeTree) -> Option { + pub fn hir_id(&self, scope_tree: &ScopeTree) -> Option { scope_tree .root_body - .map(|hir_id| hir::HirId { owner: hir_id.owner, local_id: self.item_local_id() }) + .map(|hir_id| HirId { owner: hir_id.owner, local_id: self.item_local_id() }) } /// Returns the span of this `Scope`. Note that in general the @@ -207,7 +207,7 @@ pub type ScopeDepth = u32; #[derive(Default, Debug, HashStable)] pub struct ScopeTree { /// If not empty, this body is the root of this region hierarchy. - pub root_body: Option, + pub root_body: Option, /// Maps from a scope ID to the enclosing scope id; /// this is usually corresponding to the lexical nesting, though @@ -341,11 +341,7 @@ impl ScopeTree { self.var_map.insert(var, lifetime); } - pub fn record_rvalue_candidate( - &mut self, - var: hir::HirId, - candidate_type: RvalueCandidateType, - ) { + pub fn record_rvalue_candidate(&mut self, var: HirId, candidate_type: RvalueCandidateType) { debug!("record_rvalue_candidate(var={var:?}, type={candidate_type:?})"); match &candidate_type { RvalueCandidateType::Borrow { lifetime: Some(lifetime), .. } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 601bfc770f4d7..d3d6756aa46cc 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1545,7 +1545,7 @@ pub struct SourceScopeData<'tcx> { #[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)] pub struct SourceScopeLocalData { /// An `HirId` with lint levels equivalent to this scope's lint levels. - pub lint_root: hir::HirId, + pub lint_root: HirId, } /// A collection of projections into user types. diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index f10b204cd477b..8763e94c8b05e 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -12,7 +12,7 @@ use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_errors::{DiagArgValue, IntoDiagArg}; use rustc_hir as hir; use rustc_hir::def_id::DefId; -use rustc_hir::{BindingAnnotation, ByRef, MatchSource, RangeEnd}; +use rustc_hir::{BindingAnnotation, ByRef, HirId, MatchSource, RangeEnd}; use rustc_index::newtype_index; use rustc_index::IndexVec; use rustc_middle::middle::region; @@ -115,13 +115,13 @@ pub struct Param<'tcx> { /// Whether this param is `self`, and how it is bound. pub self_kind: Option, /// HirId for lints. - pub hir_id: Option, + pub hir_id: Option, } #[derive(Copy, Clone, Debug, HashStable)] pub enum LintLevel { Inherited, - Explicit(hir::HirId), + Explicit(HirId), } #[derive(Clone, Debug, HashStable)] @@ -167,7 +167,7 @@ pub struct ClosureExpr<'tcx> { pub args: UpvarArgs<'tcx>, pub upvars: Box<[ExprId]>, pub movability: Option, - pub fake_reads: Vec<(ExprId, FakeReadCause, hir::HirId)>, + pub fake_reads: Vec<(ExprId, FakeReadCause, HirId)>, } #[derive(Clone, Debug, HashStable)] @@ -184,7 +184,7 @@ pub enum BlockSafety { /// A compiler-generated unsafe block BuiltinUnsafe, /// An `unsafe` block. The `HirId` is the ID of the block. - ExplicitUnsafe(hir::HirId), + ExplicitUnsafe(HirId), } #[derive(Clone, Debug, HashStable)] @@ -233,7 +233,7 @@ pub enum StmtKind<'tcx> { } #[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, HashStable, TyEncodable, TyDecodable)] -pub struct LocalVarId(pub hir::HirId); +pub struct LocalVarId(pub HirId); /// A THIR expression. #[derive(Clone, Debug, HashStable)] @@ -356,7 +356,7 @@ pub enum ExprKind<'tcx> { /// A `match` expression. Match { scrutinee: ExprId, - scrutinee_hir_id: hir::HirId, + scrutinee_hir_id: HirId, arms: Box<[ArmId]>, match_source: MatchSource, }, diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 790e11b8e4bdd..28f6184a34e33 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -19,6 +19,7 @@ use rustc_data_structures::sync::Lrc; use rustc_errors::{Applicability, Diag, EmissionGuarantee}; use rustc_hir as hir; use rustc_hir::def_id::DefId; +use rustc_hir::HirId; use rustc_span::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_span::symbol::Symbol; use rustc_span::{Span, DUMMY_SP}; @@ -262,10 +263,10 @@ pub enum ObligationCauseCode<'tcx> { /// expression that caused the obligation, and the `usize` /// indicates exactly which predicate it is in the list of /// instantiated predicates. - ExprItemObligation(DefId, rustc_hir::HirId, usize), + ExprItemObligation(DefId, HirId, usize), /// Combines `ExprItemObligation` and `BindingObligation`. - ExprBindingObligation(DefId, Span, rustc_hir::HirId, usize), + ExprBindingObligation(DefId, Span, HirId, usize), /// A type like `&'a T` is WF only if `T: 'a`. ReferenceOutlivesReferent(Ty<'tcx>), @@ -287,9 +288,9 @@ pub enum ObligationCauseCode<'tcx> { /// `S { ... }` must be `Sized`. StructInitializerSized, /// Type of each variable must be `Sized`. - VariableType(hir::HirId), + VariableType(HirId), /// Argument type must be `Sized`. - SizedArgumentType(Option), + SizedArgumentType(Option), /// Return type must be `Sized`. SizedReturnType, /// Return type of a call expression must be `Sized`. @@ -335,9 +336,9 @@ pub enum ObligationCauseCode<'tcx> { FunctionArgumentObligation { /// The node of the relevant argument in the function call. - arg_hir_id: hir::HirId, + arg_hir_id: HirId, /// The node of the function call. - call_hir_id: hir::HirId, + call_hir_id: HirId, /// The obligation introduced by this argument. parent_code: InternedObligationCauseCode<'tcx>, }, @@ -402,18 +403,18 @@ pub enum ObligationCauseCode<'tcx> { ReturnNoExpression, /// `return` with an expression - ReturnValue(hir::HirId), + ReturnValue(HirId), /// Opaque return type of this function OpaqueReturnType(Option<(Ty<'tcx>, Span)>), /// Block implicit return - BlockTailExpression(hir::HirId, hir::MatchSource), + BlockTailExpression(HirId, hir::MatchSource), /// #[feature(trivial_bounds)] is not enabled TrivialBound, - AwaitableExpr(hir::HirId), + AwaitableExpr(HirId), ForLoopIterator, @@ -431,8 +432,8 @@ pub enum ObligationCauseCode<'tcx> { MatchImpl(ObligationCause<'tcx>, DefId), BinOp { - lhs_hir_id: hir::HirId, - rhs_hir_id: Option, + lhs_hir_id: HirId, + rhs_hir_id: Option, rhs_span: Option, rhs_is_lit: bool, output_ty: Option>, @@ -562,10 +563,10 @@ pub enum StatementAsExpression { #[derive(Clone, Debug, PartialEq, Eq, HashStable, TyEncodable, TyDecodable)] #[derive(TypeVisitable, TypeFoldable)] pub struct MatchExpressionArmCause<'tcx> { - pub arm_block_id: Option, + pub arm_block_id: Option, pub arm_ty: Ty<'tcx>, pub arm_span: Span, - pub prior_arm_block_id: Option, + pub prior_arm_block_id: Option, pub prior_arm_ty: Ty<'tcx>, pub prior_arm_span: Span, pub scrut_span: Span, @@ -578,8 +579,8 @@ pub struct MatchExpressionArmCause<'tcx> { #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(TypeFoldable, TypeVisitable, HashStable, TyEncodable, TyDecodable)] pub struct IfExpressionCause<'tcx> { - pub then_id: hir::HirId, - pub else_id: hir::HirId, + pub then_id: HirId, + pub else_id: HirId, pub then_ty: Ty<'tcx>, pub else_ty: Ty<'tcx>, pub outer_span: Option, diff --git a/compiler/rustc_middle/src/ty/closure.rs b/compiler/rustc_middle/src/ty/closure.rs index 211d403998f88..11167515b7ca0 100644 --- a/compiler/rustc_middle/src/ty/closure.rs +++ b/compiler/rustc_middle/src/ty/closure.rs @@ -10,6 +10,7 @@ use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::FxIndexMap; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; +use rustc_hir::HirId; use rustc_span::def_id::LocalDefIdMap; use rustc_span::symbol::Ident; use rustc_span::{Span, Symbol}; @@ -25,7 +26,7 @@ pub const CAPTURE_STRUCT_LOCAL: mir::Local = mir::Local::from_u32(1); #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, TyEncodable, TyDecodable, HashStable)] #[derive(TypeFoldable, TypeVisitable)] pub struct UpvarPath { - pub hir_id: hir::HirId, + pub hir_id: HirId, } /// Upvars do not get their own `NodeId`. Instead, we use the pair of @@ -39,7 +40,7 @@ pub struct UpvarId { } impl UpvarId { - pub fn new(var_hir_id: hir::HirId, closure_def_id: LocalDefId) -> UpvarId { + pub fn new(var_hir_id: HirId, closure_def_id: LocalDefId) -> UpvarId { UpvarId { var_path: UpvarPath { hir_id: var_hir_id }, closure_expr_id: closure_def_id } } } @@ -68,7 +69,7 @@ pub type MinCaptureInformationMap<'tcx> = LocalDefIdMap = FxIndexMap>; +pub type RootVariableMinCaptureList<'tcx> = FxIndexMap>; /// Part of `MinCaptureInformationMap`; List of `CapturePlace`s. pub type MinCaptureList<'tcx> = Vec>; @@ -135,7 +136,7 @@ impl<'tcx> CapturedPlace<'tcx> { /// Returns the hir-id of the root variable for the captured place. /// e.g., if `a.b.c` was captured, would return the hir-id for `a`. - pub fn get_root_variable(&self) -> hir::HirId { + pub fn get_root_variable(&self) -> HirId { match self.place.base { HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id, base => bug!("Expected upvar, found={:?}", base), @@ -286,12 +287,12 @@ pub struct CaptureInfo { /// /// In this example, if `capture_disjoint_fields` is **not** set, then x will be captured, /// but we won't see it being used during capture analysis, since it's essentially a discard. - pub capture_kind_expr_id: Option, + pub capture_kind_expr_id: Option, /// Expr Id pointing to use that resulted the corresponding place being captured /// /// See `capture_kind_expr_id` for example. /// - pub path_expr_id: Option, + pub path_expr_id: Option, /// Capture mode that was selected pub capture_kind: UpvarCapture, diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index 995feeaa1487f..818fb78793efd 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -192,7 +192,7 @@ pub struct TypeckResults<'tcx> { /// we never capture `t`. This becomes an issue when we build MIR as we require /// information on `t` in order to create place `t.0` and `t.1`. We can solve this /// issue by fake reading `t`. - pub closure_fake_reads: LocalDefIdMap, FakeReadCause, hir::HirId)>>, + pub closure_fake_reads: LocalDefIdMap, FakeReadCause, HirId)>>, /// Tracks the rvalue scoping rules which defines finer scoping for rvalue expressions /// by applying extended parameter rules. @@ -251,7 +251,7 @@ impl<'tcx> TypeckResults<'tcx> { } /// Returns the final resolution of a `QPath` in an `Expr` or `Pat` node. - pub fn qpath_res(&self, qpath: &hir::QPath<'_>, id: hir::HirId) -> Res { + pub fn qpath_res(&self, qpath: &hir::QPath<'_>, id: HirId) -> Res { match *qpath { hir::QPath::Resolved(_, path) => path.res, hir::QPath::TypeRelative(..) | hir::QPath::LangItem(..) => self @@ -289,11 +289,11 @@ impl<'tcx> TypeckResults<'tcx> { LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.field_indices } } - pub fn field_index(&self, id: hir::HirId) -> FieldIdx { + pub fn field_index(&self, id: HirId) -> FieldIdx { self.field_indices().get(id).cloned().expect("no index for a field") } - pub fn opt_field_index(&self, id: hir::HirId) -> Option { + pub fn opt_field_index(&self, id: HirId) -> Option { self.field_indices().get(id).cloned() } @@ -305,7 +305,7 @@ impl<'tcx> TypeckResults<'tcx> { LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.nested_fields } } - pub fn nested_field_tys_and_indices(&self, id: hir::HirId) -> &[(Ty<'tcx>, FieldIdx)] { + pub fn nested_field_tys_and_indices(&self, id: HirId) -> &[(Ty<'tcx>, FieldIdx)] { self.nested_fields().get(id).map_or(&[], Vec::as_slice) } @@ -327,13 +327,13 @@ impl<'tcx> TypeckResults<'tcx> { LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.node_types } } - pub fn node_type(&self, id: hir::HirId) -> Ty<'tcx> { + pub fn node_type(&self, id: HirId) -> Ty<'tcx> { self.node_type_opt(id).unwrap_or_else(|| { bug!("node_type: no type for node {}", tls::with(|tcx| tcx.hir().node_to_string(id))) }) } - pub fn node_type_opt(&self, id: hir::HirId) -> Option> { + pub fn node_type_opt(&self, id: HirId) -> Option> { validate_hir_id_for_typeck_results(self.hir_owner, id); self.node_types.get(&id.local_id).cloned() } @@ -342,12 +342,12 @@ impl<'tcx> TypeckResults<'tcx> { LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.node_args } } - pub fn node_args(&self, id: hir::HirId) -> GenericArgsRef<'tcx> { + pub fn node_args(&self, id: HirId) -> GenericArgsRef<'tcx> { validate_hir_id_for_typeck_results(self.hir_owner, id); self.node_args.get(&id.local_id).cloned().unwrap_or_else(|| GenericArgs::empty()) } - pub fn node_args_opt(&self, id: hir::HirId) -> Option> { + pub fn node_args_opt(&self, id: HirId) -> Option> { validate_hir_id_for_typeck_results(self.hir_owner, id); self.node_args.get(&id.local_id).cloned() } @@ -512,7 +512,7 @@ impl<'tcx> TypeckResults<'tcx> { LocalTableInContextMut { hir_owner: self.hir_owner, data: &mut self.fru_field_types } } - pub fn is_coercion_cast(&self, hir_id: hir::HirId) -> bool { + pub fn is_coercion_cast(&self, hir_id: HirId) -> bool { validate_hir_id_for_typeck_results(self.hir_owner, hir_id); self.coercion_casts.contains(&hir_id.local_id) } @@ -546,7 +546,7 @@ impl<'tcx> TypeckResults<'tcx> { /// would result in lookup errors, or worse, in silently wrong data being /// stored/returned. #[inline] -fn validate_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) { +fn validate_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: HirId) { if hir_id.owner != hir_owner { invalid_hir_id_for_typeck_results(hir_owner, hir_id); } @@ -554,7 +554,7 @@ fn validate_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) { #[cold] #[inline(never)] -fn invalid_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: hir::HirId) { +fn invalid_hir_id_for_typeck_results(hir_owner: OwnerId, hir_id: HirId) { ty::tls::with(|tcx| { bug!( "node {} cannot be placed in TypeckResults with hir_owner {:?}", @@ -570,12 +570,12 @@ pub struct LocalTableInContext<'a, V> { } impl<'a, V> LocalTableInContext<'a, V> { - pub fn contains_key(&self, id: hir::HirId) -> bool { + pub fn contains_key(&self, id: HirId) -> bool { validate_hir_id_for_typeck_results(self.hir_owner, id); self.data.contains_key(&id.local_id) } - pub fn get(&self, id: hir::HirId) -> Option<&'a V> { + pub fn get(&self, id: HirId) -> Option<&'a V> { validate_hir_id_for_typeck_results(self.hir_owner, id); self.data.get(&id.local_id) } @@ -592,10 +592,10 @@ impl<'a, V> LocalTableInContext<'a, V> { } } -impl<'a, V> ::std::ops::Index for LocalTableInContext<'a, V> { +impl<'a, V> ::std::ops::Index for LocalTableInContext<'a, V> { type Output = V; - fn index(&self, key: hir::HirId) -> &V { + fn index(&self, key: HirId) -> &V { self.get(key).expect("LocalTableInContext: key not found") } } @@ -606,35 +606,32 @@ pub struct LocalTableInContextMut<'a, V> { } impl<'a, V> LocalTableInContextMut<'a, V> { - pub fn get_mut(&mut self, id: hir::HirId) -> Option<&mut V> { + pub fn get_mut(&mut self, id: HirId) -> Option<&mut V> { validate_hir_id_for_typeck_results(self.hir_owner, id); self.data.get_mut(&id.local_id) } - pub fn get(&mut self, id: hir::HirId) -> Option<&V> { + pub fn get(&mut self, id: HirId) -> Option<&V> { validate_hir_id_for_typeck_results(self.hir_owner, id); self.data.get(&id.local_id) } - pub fn entry(&mut self, id: hir::HirId) -> Entry<'_, hir::ItemLocalId, V> { + pub fn entry(&mut self, id: HirId) -> Entry<'_, hir::ItemLocalId, V> { validate_hir_id_for_typeck_results(self.hir_owner, id); self.data.entry(id.local_id) } - pub fn insert(&mut self, id: hir::HirId, val: V) -> Option { + pub fn insert(&mut self, id: HirId, val: V) -> Option { validate_hir_id_for_typeck_results(self.hir_owner, id); self.data.insert(id.local_id, val) } - pub fn remove(&mut self, id: hir::HirId) -> Option { + pub fn remove(&mut self, id: HirId) -> Option { validate_hir_id_for_typeck_results(self.hir_owner, id); self.data.remove(&id.local_id) } - pub fn extend( - &mut self, - items: UnordItems<(hir::HirId, V), impl Iterator>, - ) { + pub fn extend(&mut self, items: UnordItems<(HirId, V), impl Iterator>) { self.data.extend_unord(items.map(|(id, value)| { validate_hir_id_for_typeck_results(self.hir_owner, id); (id.local_id, value) diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index 6972bc00e0b2e..b5d72619a3871 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -9,7 +9,7 @@ use rustc_data_structures::sorted_map::SortedIndexMultiMap; use rustc_errors::ErrorGuaranteed; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; -use rustc_hir::{self as hir, BindingAnnotation, ByRef, Node}; +use rustc_hir::{self as hir, BindingAnnotation, ByRef, HirId, Node}; use rustc_index::bit_set::GrowableBitSet; use rustc_index::{Idx, IndexSlice, IndexVec}; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; @@ -158,7 +158,7 @@ struct Builder<'a, 'tcx> { cfg: CFG<'tcx>, def_id: LocalDefId, - hir_id: hir::HirId, + hir_id: HirId, parent_module: DefId, check_overflow: bool, fn_span: Span, @@ -222,7 +222,7 @@ struct Builder<'a, 'tcx> { coverage_branch_info: Option, } -type CaptureMap<'tcx> = SortedIndexMultiMap>; +type CaptureMap<'tcx> = SortedIndexMultiMap>; #[derive(Debug)] struct Capture<'tcx> { @@ -721,7 +721,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { thir: &'a Thir<'tcx>, infcx: InferCtxt<'tcx>, def: LocalDefId, - hir_id: hir::HirId, + hir_id: HirId, span: Span, arg_count: usize, return_ty: Ty<'tcx>, @@ -981,7 +981,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn set_correct_source_scope_for_arg( &mut self, - arg_hir_id: hir::HirId, + arg_hir_id: HirId, original_source_scope: SourceScope, pattern_span: Span, ) { diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 8aa9a75d96af0..9ee0fb79bf4ff 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -1,10 +1,8 @@ -use std::borrow::Cow; - use crate::build::ExprCategory; use crate::errors::*; use rustc_errors::DiagArgValue; -use rustc_hir::{self as hir, BindingAnnotation, ByRef, Mutability}; +use rustc_hir::{self as hir, BindingAnnotation, ByRef, HirId, Mutability}; use rustc_middle::mir::BorrowKind; use rustc_middle::thir::visit::Visitor; use rustc_middle::thir::*; @@ -16,6 +14,7 @@ use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::symbol::Symbol; use rustc_span::{sym, Span}; +use std::borrow::Cow; use std::mem; use std::ops::Bound; @@ -24,7 +23,7 @@ struct UnsafetyVisitor<'a, 'tcx> { thir: &'a Thir<'tcx>, /// The `HirId` of the current scope, which would be the `HirId` /// of the current HIR node, modulo adjustments. Used for lint levels. - hir_context: hir::HirId, + hir_context: HirId, /// The current "safety context". This notably tracks whether we are in an /// `unsafe` block, and whether it has been used. safety_context: SafetyContext, @@ -123,7 +122,7 @@ impl<'tcx> UnsafetyVisitor<'_, 'tcx> { fn warn_unused_unsafe( &mut self, - hir_id: hir::HirId, + hir_id: HirId, block_span: Span, enclosing_unsafe: Option, ) { @@ -537,22 +536,17 @@ enum SafetyContext { Safe, BuiltinUnsafeBlock, UnsafeFn, - UnsafeBlock { - span: Span, - hir_id: hir::HirId, - used: bool, - nested_used_blocks: Vec, - }, + UnsafeBlock { span: Span, hir_id: HirId, used: bool, nested_used_blocks: Vec }, } #[derive(Clone, Copy)] struct NestedUsedBlock { - hir_id: hir::HirId, + hir_id: HirId, span: Span, } struct UnusedUnsafeWarning { - hir_id: hir::HirId, + hir_id: HirId, block_span: Span, enclosing_unsafe: Option, } @@ -585,7 +579,7 @@ impl UnsafeOpKind { pub fn emit_unsafe_op_in_unsafe_fn_lint( &self, tcx: TyCtxt<'_>, - hir_id: hir::HirId, + hir_id: HirId, span: Span, suggest_unsafe_block: bool, ) { @@ -726,7 +720,7 @@ impl UnsafeOpKind { &self, tcx: TyCtxt<'_>, span: Span, - hir_context: hir::HirId, + hir_context: HirId, unsafe_op_in_unsafe_fn_allowed: bool, ) { let note_non_inherited = tcx.hir().parent_iter(hir_context).find(|(id, node)| { diff --git a/compiler/rustc_passes/src/hir_stats.rs b/compiler/rustc_passes/src/hir_stats.rs index 72c6a714e4d5f..49408c5618b0e 100644 --- a/compiler/rustc_passes/src/hir_stats.rs +++ b/compiler/rustc_passes/src/hir_stats.rs @@ -389,7 +389,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_fn(self, fk, fd, b, id) } - fn visit_use(&mut self, p: &'v hir::UsePath<'v>, hir_id: hir::HirId) { + fn visit_use(&mut self, p: &'v hir::UsePath<'v>, hir_id: HirId) { // This is `visit_use`, but the type is `Path` so record it that way. self.record("Path", Id::None, p); hir_visit::walk_use(self, p, hir_id) @@ -462,7 +462,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { hir_visit::walk_lifetime(self, lifetime) } - fn visit_path(&mut self, path: &hir::Path<'v>, _id: hir::HirId) { + fn visit_path(&mut self, path: &hir::Path<'v>, _id: HirId) { self.record("Path", Id::None, path); hir_visit::walk_path(self, path) } diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index 125084f47505e..c7729302783fc 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -602,7 +602,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { String::from_utf8(wr).unwrap() } - fn log_liveness(&self, entry_ln: LiveNode, hir_id: hir::HirId) { + fn log_liveness(&self, entry_ln: LiveNode, hir_id: HirId) { // hack to skip the loop unless debug! is enabled: debug!( "^^ liveness computation results for body {} (entry={:?})", diff --git a/compiler/rustc_passes/src/naked_functions.rs b/compiler/rustc_passes/src/naked_functions.rs index bd34b0597e255..a1f37ee3b8347 100644 --- a/compiler/rustc_passes/src/naked_functions.rs +++ b/compiler/rustc_passes/src/naked_functions.rs @@ -5,7 +5,7 @@ use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::{LocalDefId, LocalModDefId}; use rustc_hir::intravisit::Visitor; -use rustc_hir::{ExprKind, InlineAsmOperand, StmtKind}; +use rustc_hir::{ExprKind, HirIdSet, InlineAsmOperand, StmtKind}; use rustc_middle::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_session::lint::builtin::UNDEFINED_NAKED_FUNCTION_ABI; @@ -94,7 +94,7 @@ fn check_no_patterns(tcx: TyCtxt<'_>, params: &[hir::Param<'_>]) { /// Checks that function parameters aren't used in the function body. fn check_no_parameters_use<'tcx>(tcx: TyCtxt<'tcx>, body: &'tcx hir::Body<'tcx>) { - let mut params = hir::HirIdSet::default(); + let mut params = HirIdSet::default(); for param in body.params { param.pat.each_binding(|_binding_mode, hir_id, _span, _ident| { params.insert(hir_id); @@ -105,7 +105,7 @@ fn check_no_parameters_use<'tcx>(tcx: TyCtxt<'tcx>, body: &'tcx hir::Body<'tcx>) struct CheckParameters<'tcx> { tcx: TyCtxt<'tcx>, - params: hir::HirIdSet, + params: HirIdSet, } impl<'tcx> Visitor<'tcx> for CheckParameters<'tcx> { diff --git a/compiler/rustc_passes/src/upvars.rs b/compiler/rustc_passes/src/upvars.rs index 4d44e8762b0d1..2eed58d10bb7b 100644 --- a/compiler/rustc_passes/src/upvars.rs +++ b/compiler/rustc_passes/src/upvars.rs @@ -66,7 +66,7 @@ impl CaptureCollector<'_, '_> { } impl<'tcx> Visitor<'tcx> for CaptureCollector<'_, 'tcx> { - fn visit_path(&mut self, path: &hir::Path<'tcx>, _: hir::HirId) { + fn visit_path(&mut self, path: &hir::Path<'tcx>, _: HirId) { if let Res::Local(var_id) = path.res { self.visit_local_use(var_id, path.span); } 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 bbb634dacdfb4..ae38649da0297 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -4251,7 +4251,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { type_diffs: &[TypeError<'tcx>], span: Span, prev_ty: Ty<'tcx>, - body_id: hir::HirId, + body_id: HirId, param_env: ty::ParamEnv<'tcx>, ) -> Vec))>> { let ocx = ObligationCtxt::new(self.infcx); @@ -4757,7 +4757,7 @@ impl<'v> Visitor<'v> for ReturnsVisitor<'v> { /// Collect all the awaited expressions within the input expression. #[derive(Default)] struct AwaitsVisitor { - awaits: Vec, + awaits: Vec, } impl<'v> Visitor<'v> for AwaitsVisitor { diff --git a/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index 2d757883f2662..995dd782cbbd1 100644 --- a/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -1,4 +1,4 @@ -use rustc_hir::{self as hir, intravisit, HirIdSet}; +use rustc_hir::{self as hir, intravisit, HirId, HirIdSet}; use rustc_lint::LateContext; use rustc_middle::ty; use rustc_span::def_id::LocalDefId; @@ -74,7 +74,7 @@ fn check_raw_ptr<'tcx>( } } -fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option { +fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option { if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_, _))) = ( &arg.pat.kind, cx.maybe_typeck_results() diff --git a/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs b/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs index 4d1f89b1d9d92..6ddc8346511dc 100644 --- a/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs +++ b/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs @@ -7,6 +7,7 @@ use clippy_utils::{is_expn_of, is_lint_allowed, path_to_local}; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_errors::Applicability; use rustc_hir as hir; +use rustc_hir::HirId; use rustc_hir::intravisit::{self, Visitor}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::hir::nested_filter; @@ -87,9 +88,9 @@ impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice { extract_msrv_attr!(LateContext); } -fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap { - let mut removed_pat: FxHashSet = FxHashSet::default(); - let mut slices: FxIndexMap = FxIndexMap::default(); +fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap { + let mut removed_pat: FxHashSet = FxHashSet::default(); + let mut slices: FxIndexMap = FxIndexMap::default(); pat.walk_always(|pat| { // We'll just ignore mut and ref mut for simplicity sake right now if let hir::PatKind::Binding( @@ -206,10 +207,10 @@ impl SliceLintInformation { fn filter_lintable_slices<'tcx>( cx: &LateContext<'tcx>, - slice_lint_info: FxIndexMap, + slice_lint_info: FxIndexMap, max_suggested_slice: u64, scope: &'tcx hir::Expr<'tcx>, -) -> FxIndexMap { +) -> FxIndexMap { let mut visitor = SliceIndexLintingVisitor { cx, slice_lint_info, @@ -223,7 +224,7 @@ fn filter_lintable_slices<'tcx>( struct SliceIndexLintingVisitor<'a, 'tcx> { cx: &'a LateContext<'tcx>, - slice_lint_info: FxIndexMap, + slice_lint_info: FxIndexMap, max_suggested_slice: u64, } diff --git a/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs b/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs index 2f85130fba118..435eb9048f587 100644 --- a/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs +++ b/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs @@ -6,6 +6,7 @@ use clippy_utils::{binop_traits, eq_expr_value, trait_ref_of_method}; use core::ops::ControlFlow; use rustc_errors::Applicability; use rustc_hir as hir; +use rustc_hir::{HirId, HirIdSet}; use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; use rustc_lint::LateContext; use rustc_middle::mir::FakeReadCause; @@ -98,10 +99,10 @@ pub(super) fn check<'tcx>( } } -fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet { - struct S(hir::HirIdSet); +fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet { + struct S(HirIdSet); impl Delegate<'_> for S { - fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: hir::HirId, kind: BorrowKind) { + fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) { if matches!(kind, BorrowKind::ImmBorrow | BorrowKind::UniqueImmBorrow) { self.0.insert(match place.place.base { PlaceBase::Local(id) => id, @@ -111,13 +112,13 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet } } - fn consume(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} - fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} - fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: hir::HirId) {} - fn copy(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} + fn consume(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {} + fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {} + fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: HirId) {} + fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {} } - let mut s = S(hir::HirIdSet::default()); + let mut s = S(HirIdSet::default()); let infcx = cx.tcx.infer_ctxt().build(); let mut v = ExprUseVisitor::new( &mut s, @@ -130,10 +131,10 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet s.0 } -fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet { - struct S(hir::HirIdSet); +fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> HirIdSet { + struct S(HirIdSet); impl Delegate<'_> for S { - fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: hir::HirId, kind: BorrowKind) { + fn borrow(&mut self, place: &PlaceWithHirId<'_>, _: HirId, kind: BorrowKind) { if matches!(kind, BorrowKind::MutBorrow) { self.0.insert(match place.place.base { PlaceBase::Local(id) => id, @@ -143,13 +144,13 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet } } - fn consume(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} - fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} - fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: hir::HirId) {} - fn copy(&mut self, _: &PlaceWithHirId<'_>, _: hir::HirId) {} + fn consume(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {} + fn mutate(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {} + fn fake_read(&mut self, _: &PlaceWithHirId<'_>, _: FakeReadCause, _: HirId) {} + fn copy(&mut self, _: &PlaceWithHirId<'_>, _: HirId) {} } - let mut s = S(hir::HirIdSet::default()); + let mut s = S(HirIdSet::default()); let infcx = cx.tcx.infer_ctxt().build(); let mut v = ExprUseVisitor::new( &mut s, diff --git a/src/tools/clippy/clippy_lints/src/ptr.rs b/src/tools/clippy/clippy_lints/src/ptr.rs index 83b32000a9f97..d6592622f0bb8 100644 --- a/src/tools/clippy/clippy_lints/src/ptr.rs +++ b/src/tools/clippy/clippy_lints/src/ptr.rs @@ -8,7 +8,7 @@ use clippy_utils::{get_expr_use_or_unification_node, is_lint_allowed, path_def_i use hir::LifetimeName; use rustc_errors::{Applicability, MultiSpan}; use rustc_hir::def_id::DefId; -use rustc_hir::hir_id::HirIdMap; +use rustc_hir::hir_id::{HirId, HirIdMap}; use rustc_hir::intravisit::{walk_expr, Visitor}; use rustc_hir::{ self as hir, AnonConst, BinOpKind, BindingAnnotation, Body, Expr, ExprKind, FnRetTy, FnSig, GenericArg, @@ -324,7 +324,7 @@ struct PtrArgReplacement { struct PtrArg<'tcx> { idx: usize, - emission_id: hir::HirId, + emission_id: HirId, span: Span, ty_did: DefId, ty_name: Symbol, diff --git a/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs b/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs index d3540bc8e1c38..038eb92d652b4 100644 --- a/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs +++ b/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs @@ -5,7 +5,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap}; use rustc_errors::Applicability; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::{walk_expr, Visitor}; -use rustc_hir::{self as hir}; +use rustc_hir::{self as hir, HirId}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::ty::{GenericArgKind, Ty}; use rustc_session::impl_lint_pass; @@ -55,7 +55,7 @@ impl_lint_pass!(SignificantDropTightening<'_> => [SIGNIFICANT_DROP_TIGHTENING]); #[derive(Default)] pub struct SignificantDropTightening<'tcx> { - apas: FxIndexMap, + apas: FxIndexMap, /// Auxiliary structure used to avoid having to verify the same type multiple times. seen_types: FxHashSet>, type_cache: FxHashMap, bool>, @@ -359,9 +359,9 @@ impl<'ap, 'lc, 'others, 'stmt, 'tcx> Visitor<'tcx> for StmtsChecker<'ap, 'lc, 'o /// Auxiliary parameters used on each block check of an item struct AuxParams<'others, 'stmt, 'tcx> { //// See [AuxParamsAttr]. - apas: &'others mut FxIndexMap, + apas: &'others mut FxIndexMap, /// The current block identifier that is being visited. - curr_block_hir_id: hir::HirId, + curr_block_hir_id: HirId, /// The current block span that is being visited. curr_block_span: Span, /// The current statement that is being visited. @@ -369,10 +369,10 @@ struct AuxParams<'others, 'stmt, 'tcx> { } impl<'others, 'stmt, 'tcx> AuxParams<'others, 'stmt, 'tcx> { - fn new(apas: &'others mut FxIndexMap, curr_stmt: &'stmt hir::Stmt<'tcx>) -> Self { + fn new(apas: &'others mut FxIndexMap, curr_stmt: &'stmt hir::Stmt<'tcx>) -> Self { Self { apas, - curr_block_hir_id: hir::HirId::INVALID, + curr_block_hir_id: HirId::INVALID, curr_block_span: DUMMY_SP, curr_stmt: Cow::Borrowed(curr_stmt), } @@ -389,7 +389,7 @@ struct AuxParamsAttr { has_expensive_expr_after_last_attr: bool, /// The identifier of the block that involves the first `#[has_significant_drop]`. - first_block_hir_id: hir::HirId, + first_block_hir_id: HirId, /// The span of the block that involves the first `#[has_significant_drop]`. first_block_span: Span, /// The binding or variable that references the initial construction of the type marked with @@ -414,7 +414,7 @@ impl Default for AuxParamsAttr { Self { counter: 0, has_expensive_expr_after_last_attr: false, - first_block_hir_id: hir::HirId::INVALID, + first_block_hir_id: HirId::INVALID, first_bind_ident: Ident::empty(), first_block_span: DUMMY_SP, first_method_span: DUMMY_SP, @@ -428,7 +428,7 @@ impl Default for AuxParamsAttr { fn dummy_stmt_expr<'any>(expr: &'any hir::Expr<'any>) -> hir::Stmt<'any> { hir::Stmt { - hir_id: hir::HirId::INVALID, + hir_id: HirId::INVALID, kind: hir::StmtKind::Expr(expr), span: DUMMY_SP, } From b03ae74c84977517639449e35473fcedd6409ab3 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 16 Apr 2024 15:48:47 +1000 Subject: [PATCH 05/16] Rename a tiny module. So it doesn't clash with `rustc_middle::ty`. --- .../rustc_const_eval/src/transform/check_consts/check.rs | 2 +- .../rustc_const_eval/src/transform/check_consts/ops.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_const_eval/src/transform/check_consts/check.rs b/compiler/rustc_const_eval/src/transform/check_consts/check.rs index 543996c86baca..1ea30e3a2aff9 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/check.rs @@ -168,7 +168,7 @@ impl<'ck, 'mir, 'tcx> TypeVisitor> for LocalReturnTyVisitor<'ck, 'm match t.kind() { ty::FnPtr(_) => {} ty::Ref(_, _, hir::Mutability::Mut) => { - self.checker.check_op(ops::ty::MutRef(self.kind)); + self.checker.check_op(ops::mut_ref::MutRef(self.kind)); t.super_visit_with(self) } _ => t.super_visit_with(self), diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index 9775f1980c59b..dda8f3ed87d28 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -10,8 +10,8 @@ use rustc_infer::traits::{ImplSource, Obligation, ObligationCause}; use rustc_middle::mir::{self, CallSource}; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{ - self as middle_ty, suggest_constraining_type_param, Closure, FnDef, FnPtr, GenericArgKind, - GenericArgsRef, Param, TraitRef, Ty, + self, suggest_constraining_type_param, Closure, FnDef, FnPtr, GenericArgKind, GenericArgsRef, + Param, TraitRef, Ty, }; use rustc_middle::util::{call_kind, CallDesugaringKind, CallKind}; use rustc_session::parse::feature_err; @@ -124,7 +124,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> { ); } } - middle_ty::Adt(..) => { + ty::Adt(..) => { let obligation = Obligation::new(tcx, ObligationCause::dummy(), param_env, trait_ref); @@ -621,7 +621,7 @@ impl<'tcx> NonConstOp<'tcx> for ThreadLocalAccess { } /// Types that cannot appear in the signature or locals of a `const fn`. -pub mod ty { +pub mod mut_ref { use super::*; #[derive(Debug)] From 81b7944163b48ce051248bc84f30b6ea65d7c1c0 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Fri, 22 Mar 2024 18:05:56 +0300 Subject: [PATCH 06/16] create new build step `clippy` Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/check.rs | 111 +------ src/bootstrap/src/core/build_steps/clippy.rs | 307 +++++++++++++++++++ src/bootstrap/src/core/build_steps/mod.rs | 1 + src/bootstrap/src/core/builder.rs | 14 +- src/bootstrap/src/core/config/tests.rs | 2 +- 5 files changed, 335 insertions(+), 100 deletions(-) create mode 100644 src/bootstrap/src/core/build_steps/clippy.rs diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index 37d91b14ca1b6..654ef1ec6a7f8 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -11,6 +11,14 @@ use crate::core::config::TargetSelection; use crate::{Compiler, Mode, Subcommand}; use std::path::{Path, PathBuf}; +pub fn cargo_subcommand(kind: Kind) -> &'static str { + match kind { + Kind::Check | Kind::Clippy => "check", + Kind::Fix => "fix", + _ => unreachable!(), + } +} + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Std { pub target: TargetSelection, @@ -22,97 +30,6 @@ pub struct Std { crates: Vec, } -/// Returns args for the subcommand itself (not for cargo) -fn args(builder: &Builder<'_>) -> Vec { - fn strings<'a>(arr: &'a [&str]) -> impl Iterator + 'a { - arr.iter().copied().map(String::from) - } - - if let Subcommand::Clippy { fix, allow_dirty, allow_staged, allow, deny, warn, forbid } = - &builder.config.cmd - { - // disable the most spammy clippy lints - let ignored_lints = [ - "many_single_char_names", // there are a lot in stdarch - "collapsible_if", - "type_complexity", - "missing_safety_doc", // almost 3K warnings - "too_many_arguments", - "needless_lifetimes", // people want to keep the lifetimes - "wrong_self_convention", - ]; - let mut args = vec![]; - if *fix { - #[rustfmt::skip] - args.extend(strings(&[ - "--fix", "-Zunstable-options", - // FIXME: currently, `--fix` gives an error while checking tests for libtest, - // possibly because libtest is not yet built in the sysroot. - // As a workaround, avoid checking tests and benches when passed --fix. - "--lib", "--bins", "--examples", - ])); - - if *allow_dirty { - args.push("--allow-dirty".to_owned()); - } - - if *allow_staged { - args.push("--allow-staged".to_owned()); - } - } - - args.extend(strings(&["--"])); - - if deny.is_empty() && forbid.is_empty() { - args.extend(strings(&["--cap-lints", "warn"])); - } - - let all_args = std::env::args().collect::>(); - args.extend(get_clippy_rules_in_order(&all_args, allow, deny, warn, forbid)); - - args.extend(ignored_lints.iter().map(|lint| format!("-Aclippy::{}", lint))); - args.extend(builder.config.free_args.clone()); - args - } else { - builder.config.free_args.clone() - } -} - -/// We need to keep the order of the given clippy lint rules before passing them. -/// Since clap doesn't offer any useful interface for this purpose out of the box, -/// we have to handle it manually. -pub(crate) fn get_clippy_rules_in_order( - all_args: &[String], - allow_rules: &[String], - deny_rules: &[String], - warn_rules: &[String], - forbid_rules: &[String], -) -> Vec { - let mut result = vec![]; - - for (prefix, item) in - [("-A", allow_rules), ("-D", deny_rules), ("-W", warn_rules), ("-F", forbid_rules)] - { - item.iter().for_each(|v| { - let rule = format!("{prefix}{v}"); - let position = all_args.iter().position(|t| t == &rule).unwrap(); - result.push((position, rule)); - }); - } - - result.sort_by_key(|&(position, _)| position); - result.into_iter().map(|v| v.1).collect() -} - -fn cargo_subcommand(kind: Kind) -> &'static str { - match kind { - Kind::Check => "check", - Kind::Clippy => "clippy", - Kind::Fix => "fix", - _ => unreachable!(), - } -} - impl Std { pub fn new(target: TargetSelection) -> Self { Self { target, crates: vec![] } @@ -164,7 +81,7 @@ impl Step for Std { run_cargo( builder, cargo, - args(builder), + builder.config.free_args.clone(), &libstd_stamp(builder, compiler, target), vec![], true, @@ -221,7 +138,7 @@ impl Step for Std { run_cargo( builder, cargo, - args(builder), + builder.config.free_args.clone(), &libstd_test_stamp(builder, compiler, target), vec![], true, @@ -318,7 +235,7 @@ impl Step for Rustc { run_cargo( builder, cargo, - args(builder), + builder.config.free_args.clone(), &librustc_stamp(builder, compiler, target), vec![], true, @@ -384,7 +301,7 @@ impl Step for CodegenBackend { run_cargo( builder, cargo, - args(builder), + builder.config.free_args.clone(), &codegen_backend_stamp(builder, compiler, target, backend), vec![], true, @@ -450,7 +367,7 @@ impl Step for RustAnalyzer { run_cargo( builder, cargo, - args(builder), + builder.config.free_args.clone(), &stamp(builder, compiler, target), vec![], true, @@ -513,7 +430,7 @@ macro_rules! tool_check_step { run_cargo( builder, cargo, - args(builder), + builder.config.free_args.clone(), &stamp(builder, compiler, target), vec![], true, diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs new file mode 100644 index 0000000000000..e2c2d3c9ef83d --- /dev/null +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -0,0 +1,307 @@ +use std::path::Path; + +use crate::builder::Builder; +use crate::builder::ShouldRun; +use crate::core::builder; +use crate::core::builder::crate_description; +use crate::core::builder::Alias; +use crate::core::builder::RunConfig; +use crate::core::builder::Step; +use crate::Mode; +use crate::Subcommand; +use crate::TargetSelection; + +use super::check; +use super::compile; +use super::compile::librustc_stamp; +use super::compile::libstd_stamp; +use super::compile::run_cargo; +use super::compile::rustc_cargo; +use super::compile::std_cargo; +use super::tool::prepare_tool_cargo; +use super::tool::SourceType; + +// Disable the most spammy clippy lints +const IGNORED_RULES_FOR_STD_AND_RUSTC: &[&str] = &[ + "many_single_char_names", // there are a lot in stdarch + "collapsible_if", + "type_complexity", + "missing_safety_doc", // almost 3K warnings + "too_many_arguments", + "needless_lifetimes", // people want to keep the lifetimes + "wrong_self_convention", +]; + +fn lint_args(builder: &Builder<'_>, ignored_rules: &[&str]) -> Vec { + fn strings<'a>(arr: &'a [&str]) -> impl Iterator + 'a { + arr.iter().copied().map(String::from) + } + + let Subcommand::Clippy { fix, allow_dirty, allow_staged, allow, deny, warn, forbid } = + &builder.config.cmd + else { + unreachable!("clippy::lint_args can only be called from `clippy` subcommands."); + }; + + let mut args = vec![]; + if *fix { + #[rustfmt::skip] + args.extend(strings(&[ + "--fix", "-Zunstable-options", + // FIXME: currently, `--fix` gives an error while checking tests for libtest, + // possibly because libtest is not yet built in the sysroot. + // As a workaround, avoid checking tests and benches when passed --fix. + "--lib", "--bins", "--examples", + ])); + + if *allow_dirty { + args.push("--allow-dirty".to_owned()); + } + + if *allow_staged { + args.push("--allow-staged".to_owned()); + } + } + + args.extend(strings(&["--"])); + + if deny.is_empty() && forbid.is_empty() { + args.extend(strings(&["--cap-lints", "warn"])); + } + + let all_args = std::env::args().collect::>(); + args.extend(get_clippy_rules_in_order(&all_args, allow, deny, warn, forbid)); + + args.extend(ignored_rules.iter().map(|lint| format!("-Aclippy::{}", lint))); + args.extend(builder.config.free_args.clone()); + args +} + +/// We need to keep the order of the given clippy lint rules before passing them. +/// Since clap doesn't offer any useful interface for this purpose out of the box, +/// we have to handle it manually. +pub(crate) fn get_clippy_rules_in_order( + all_args: &[String], + allow_rules: &[String], + deny_rules: &[String], + warn_rules: &[String], + forbid_rules: &[String], +) -> Vec { + let mut result = vec![]; + + for (prefix, item) in + [("-A", allow_rules), ("-D", deny_rules), ("-W", warn_rules), ("-F", forbid_rules)] + { + item.iter().for_each(|v| { + let rule = format!("{prefix}{v}"); + let position = all_args.iter().position(|t| t == &rule).unwrap(); + result.push((position, rule)); + }); + } + + result.sort_by_key(|&(position, _)| position); + result.into_iter().map(|v| v.1).collect() +} + +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Std { + pub target: TargetSelection, + /// Whether to lint only a subset of crates. + crates: Vec, +} + +impl Step for Std { + type Output = (); + const DEFAULT: bool = true; + + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + run.crate_or_deps("sysroot").path("library") + } + + fn make_run(run: RunConfig<'_>) { + let crates = run.make_run_crates(Alias::Library); + run.builder.ensure(Std { target: run.target, crates }); + } + + fn run(self, builder: &Builder<'_>) { + builder.update_submodule(&Path::new("library").join("stdarch")); + + let target = self.target; + let compiler = builder.compiler(builder.top_stage, builder.config.build); + + let mut cargo = + builder::Cargo::new(builder, compiler, Mode::Std, SourceType::InTree, target, "clippy"); + + std_cargo(builder, target, compiler.stage, &mut cargo); + + if matches!(builder.config.cmd, Subcommand::Fix { .. }) { + // By default, cargo tries to fix all targets. Tell it not to fix tests until we've added `test` to the sysroot. + cargo.arg("--lib"); + } + + for krate in &*self.crates { + cargo.arg("-p").arg(krate); + } + + let _guard = builder.msg_check( + format_args!("library artifacts{}", crate_description(&self.crates)), + target, + ); + + run_cargo( + builder, + cargo, + lint_args(builder, IGNORED_RULES_FOR_STD_AND_RUSTC), + &libstd_stamp(builder, compiler, target), + vec![], + true, + false, + ); + } +} + +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct Rustc { + pub target: TargetSelection, + /// Whether to lint only a subset of crates. + crates: Vec, +} + +impl Step for Rustc { + type Output = (); + const ONLY_HOSTS: bool = true; + const DEFAULT: bool = true; + + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + run.crate_or_deps("rustc-main").path("compiler") + } + + fn make_run(run: RunConfig<'_>) { + let crates = run.make_run_crates(Alias::Compiler); + run.builder.ensure(Rustc { target: run.target, crates }); + } + + /// Lints the compiler. + /// + /// This will lint the compiler for a particular stage of the build using + /// the `compiler` targeting the `target` architecture. + fn run(self, builder: &Builder<'_>) { + let compiler = builder.compiler(builder.top_stage, builder.config.build); + let target = self.target; + + if compiler.stage != 0 { + // If we're not in stage 0, then we won't have a std from the beta + // compiler around. That means we need to make sure there's one in + // the sysroot for the compiler to find. Otherwise, we're going to + // fail when building crates that need to generate code (e.g., build + // scripts and their dependencies). + builder.ensure(compile::Std::new(compiler, compiler.host)); + builder.ensure(compile::Std::new(compiler, target)); + } else { + builder.ensure(check::Std::new(target)); + } + + let mut cargo = builder::Cargo::new( + builder, + compiler, + Mode::Rustc, + SourceType::InTree, + target, + "clippy", + ); + + rustc_cargo(builder, &mut cargo, target, compiler.stage); + + // Explicitly pass -p for all compiler crates -- this will force cargo + // to also check the tests/benches/examples for these crates, rather + // than just the leaf crate. + for krate in &*self.crates { + cargo.arg("-p").arg(krate); + } + + let _guard = builder.msg_check( + format_args!("compiler artifacts{}", crate_description(&self.crates)), + target, + ); + + run_cargo( + builder, + cargo, + lint_args(builder, IGNORED_RULES_FOR_STD_AND_RUSTC), + &librustc_stamp(builder, compiler, target), + vec![], + true, + false, + ); + } +} + +macro_rules! lint_any { + ($( + $name:ident, $path:expr, $tool_name:expr + $(,is_external_tool = $external:expr)* + $(,is_unstable_tool = $unstable:expr)* + $(,allow_features = $allow_features:expr)? + ; + )+) => { + $( + + #[derive(Debug, Clone, Hash, PartialEq, Eq)] + pub struct $name { + pub target: TargetSelection, + } + + impl Step for $name { + type Output = (); + + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + run.path($path) + } + + fn make_run(run: RunConfig<'_>) { + run.builder.ensure($name { + target: run.target, + }); + } + + fn run(self, builder: &Builder<'_>) -> Self::Output { + let compiler = builder.compiler(builder.top_stage, builder.config.build); + let target = self.target; + + builder.ensure(check::Rustc::new(target, builder)); + + let cargo = prepare_tool_cargo( + builder, + compiler, + Mode::ToolRustc, + target, + "clippy", + $path, + SourceType::InTree, + &[], + ); + + run_cargo( + builder, + cargo, + lint_args(builder, &[]), + &libstd_stamp(builder, compiler, target), + vec![], + true, + false, + ); + } + } + )+ + } +} + +lint_any!( + Bootstrap, "src/bootstrap", "bootstrap"; + BuildHelper, "src/tools/build_helper", "build_helper"; + CoverageDump, "src/tools/coverage-dump", "coverage-dump"; + Tidy, "src/tools/tidy", "tidy"; + Compiletest, "src/tools/compiletest", "compiletest"; + RemoteTestServer, "src/tools/remote-test-server", "remote-test-server"; + RemoteTestClient, "src/tools/remote-test-client", "remote-test-client"; +); diff --git a/src/bootstrap/src/core/build_steps/mod.rs b/src/bootstrap/src/core/build_steps/mod.rs index 50d83789be82a..9b7378165de41 100644 --- a/src/bootstrap/src/core/build_steps/mod.rs +++ b/src/bootstrap/src/core/build_steps/mod.rs @@ -1,5 +1,6 @@ pub(crate) mod check; pub(crate) mod clean; +pub(crate) mod clippy; pub(crate) mod compile; pub(crate) mod dist; pub(crate) mod doc; diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index f31bc46d25fcb..6ee37acc90541 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -13,7 +13,7 @@ use std::process::Command; use std::sync::OnceLock; use std::time::{Duration, Instant}; -use crate::core::build_steps::llvm; +use crate::core::build_steps::{clippy, llvm}; use crate::core::build_steps::tool::{self, SourceType}; use crate::core::build_steps::{check, clean, compile, dist, doc, install, run, setup, test}; use crate::core::config::flags::{Color, Subcommand}; @@ -726,7 +726,17 @@ impl<'a> Builder<'a> { tool::CoverageDump, tool::LlvmBitcodeLinker ), - Kind::Check | Kind::Clippy | Kind::Fix => describe!( + Kind::Clippy => describe!( + clippy::Std, + clippy::Rustc, + clippy::Bootstrap, + clippy::BuildHelper, + clippy::CoverageDump, + clippy::Tidy, + clippy::RemoteTestServer, + clippy::RemoteTestClient, + ), + Kind::Check | Kind::Fix => describe!( check::Std, check::Rustc, check::Rustdoc, diff --git a/src/bootstrap/src/core/config/tests.rs b/src/bootstrap/src/core/config/tests.rs index 8cd538953c56d..59e16b6542728 100644 --- a/src/bootstrap/src/core/config/tests.rs +++ b/src/bootstrap/src/core/config/tests.rs @@ -1,5 +1,5 @@ use super::{flags::Flags, ChangeIdWrapper, Config}; -use crate::core::build_steps::check::get_clippy_rules_in_order; +use crate::core::build_steps::clippy::get_clippy_rules_in_order; use crate::core::config::{LldMode, TomlConfig}; use clap::CommandFactory; From 8a865a0fa9b1aacbcf84ad64ddb9f125f6007544 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Fri, 22 Mar 2024 18:15:18 +0300 Subject: [PATCH 07/16] create `Builder::msg_clippy` Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/clippy.rs | 11 +++-------- src/bootstrap/src/core/builder.rs | 3 ++- src/bootstrap/src/lib.rs | 10 ++++++++++ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index e2c2d3c9ef83d..190ea1752d84c 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -134,16 +134,11 @@ impl Step for Std { std_cargo(builder, target, compiler.stage, &mut cargo); - if matches!(builder.config.cmd, Subcommand::Fix { .. }) { - // By default, cargo tries to fix all targets. Tell it not to fix tests until we've added `test` to the sysroot. - cargo.arg("--lib"); - } - for krate in &*self.crates { cargo.arg("-p").arg(krate); } - let _guard = builder.msg_check( + let _guard = builder.msg_clippy( format_args!("library artifacts{}", crate_description(&self.crates)), target, ); @@ -213,13 +208,13 @@ impl Step for Rustc { rustc_cargo(builder, &mut cargo, target, compiler.stage); // Explicitly pass -p for all compiler crates -- this will force cargo - // to also check the tests/benches/examples for these crates, rather + // to also lint the tests/benches/examples for these crates, rather // than just the leaf crate. for krate in &*self.crates { cargo.arg("-p").arg(krate); } - let _guard = builder.msg_check( + let _guard = builder.msg_clippy( format_args!("compiler artifacts{}", crate_description(&self.crates)), target, ); diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 6ee37acc90541..9d2352135c2f6 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -13,9 +13,9 @@ use std::process::Command; use std::sync::OnceLock; use std::time::{Duration, Instant}; -use crate::core::build_steps::{clippy, llvm}; use crate::core::build_steps::tool::{self, SourceType}; use crate::core::build_steps::{check, clean, compile, dist, doc, install, run, setup, test}; +use crate::core::build_steps::{clippy, llvm}; use crate::core::config::flags::{Color, Subcommand}; use crate::core::config::{DryRun, SplitDebuginfo, TargetSelection}; use crate::prepare_behaviour_dump_dir; @@ -672,6 +672,7 @@ impl Kind { Kind::Doc => "Documenting", Kind::Run => "Running", Kind::Suggest => "Suggesting", + Kind::Clippy => "Linting", _ => { let title_letter = self.as_str()[0..1].to_ascii_uppercase(); return format!("{title_letter}{}ing", &self.as_str()[1..]); diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 1a8322c0dfd88..e1ae9fe2bf71a 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -1078,6 +1078,16 @@ impl Build { } } + #[must_use = "Groups should not be dropped until the Step finishes running"] + #[track_caller] + fn msg_clippy( + &self, + what: impl Display, + target: impl Into>, + ) -> Option { + self.msg(Kind::Clippy, self.config.stage, what, self.config.build, target) + } + #[must_use = "Groups should not be dropped until the Step finishes running"] #[track_caller] fn msg_check( From 77ba3f289109ae9823d86a9ad8dbf160b42ad76e Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Fri, 22 Mar 2024 18:23:01 +0300 Subject: [PATCH 08/16] support different `Kind`s in `Builder::msg_tool` Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/clippy.rs | 12 +++++++++++- src/bootstrap/src/core/build_steps/tool.rs | 7 +++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index 190ea1752d84c..21ac6c505c309 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -5,6 +5,7 @@ use crate::builder::ShouldRun; use crate::core::builder; use crate::core::builder::crate_description; use crate::core::builder::Alias; +use crate::core::builder::Kind; use crate::core::builder::RunConfig; use crate::core::builder::Step; use crate::Mode; @@ -233,7 +234,7 @@ impl Step for Rustc { macro_rules! lint_any { ($( - $name:ident, $path:expr, $tool_name:expr + $name:ident, $path:expr, $readable_name:expr $(,is_external_tool = $external:expr)* $(,is_unstable_tool = $unstable:expr)* $(,allow_features = $allow_features:expr)? @@ -276,6 +277,15 @@ macro_rules! lint_any { &[], ); + let _guard = builder.msg_tool( + Kind::Clippy, + Mode::ToolRustc, + $readable_name, + compiler.stage, + &compiler.host, + &target, + ); + run_cargo( builder, cargo, diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index 8d1ff2fcb245f..45b1d5a05f35c 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -36,8 +36,9 @@ struct ToolBuild { impl Builder<'_> { #[track_caller] - fn msg_tool( + pub(crate) fn msg_tool( &self, + kind: Kind, mode: Mode, tool: &str, build_stage: u32, @@ -47,7 +48,7 @@ impl Builder<'_> { match mode { // depends on compiler stage, different to host compiler Mode::ToolRustc => self.msg_sysroot_tool( - Kind::Build, + kind, build_stage, format_args!("tool {tool}"), *host, @@ -100,6 +101,7 @@ impl Step for ToolBuild { cargo.allow_features(self.allow_features); } let _guard = builder.msg_tool( + Kind::Build, self.mode, self.tool, self.compiler.stage, @@ -481,6 +483,7 @@ impl Step for Rustdoc { ); let _guard = builder.msg_tool( + Kind::Build, Mode::ToolRustc, "rustdoc", build_compiler.stage, From 489e5d0ad0894cdfdf0e639d723a2cff88f7610a Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Fri, 22 Mar 2024 18:43:06 +0300 Subject: [PATCH 09/16] for clippy, skip output handling in `run_cargo` Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/compile.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 9420e40d6c2b2..b2ee2c8f1f798 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -2012,7 +2012,7 @@ pub fn run_cargo( crate::exit!(1); } - if builder.config.dry_run() { + if builder.config.dry_run() || builder.kind == Kind::Clippy { return Vec::new(); } From bbacfe0cb64c4541097ed21f3cb0d3511bf0028f Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Fri, 22 Mar 2024 18:52:37 +0300 Subject: [PATCH 10/16] add simple top-level doc-comment for build_steps/clippy Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/clippy.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index 21ac6c505c309..7374c2b1cf290 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -1,3 +1,5 @@ +//! Implementation of running clippy on the compiler, standard library and various tools. + use std::path::Path; use crate::builder::Builder; From a01897345cead40cd3c349529a67e796a4395a09 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Fri, 22 Mar 2024 19:00:48 +0300 Subject: [PATCH 11/16] fix sysroot bug and update step message format Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/clippy.rs | 25 +++++--------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index 7374c2b1cf290..15d676bea2050 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -141,10 +141,8 @@ impl Step for Std { cargo.arg("-p").arg(krate); } - let _guard = builder.msg_clippy( - format_args!("library artifacts{}", crate_description(&self.crates)), - target, - ); + let _guard = + builder.msg_clippy(format_args!("library{}", crate_description(&self.crates)), target); run_cargo( builder, @@ -187,17 +185,8 @@ impl Step for Rustc { let compiler = builder.compiler(builder.top_stage, builder.config.build); let target = self.target; - if compiler.stage != 0 { - // If we're not in stage 0, then we won't have a std from the beta - // compiler around. That means we need to make sure there's one in - // the sysroot for the compiler to find. Otherwise, we're going to - // fail when building crates that need to generate code (e.g., build - // scripts and their dependencies). - builder.ensure(compile::Std::new(compiler, compiler.host)); - builder.ensure(compile::Std::new(compiler, target)); - } else { - builder.ensure(check::Std::new(target)); - } + builder.ensure(compile::Std::new(compiler, compiler.host)); + builder.ensure(compile::Std::new(compiler, target)); let mut cargo = builder::Cargo::new( builder, @@ -217,10 +206,8 @@ impl Step for Rustc { cargo.arg("-p").arg(krate); } - let _guard = builder.msg_clippy( - format_args!("compiler artifacts{}", crate_description(&self.crates)), - target, - ); + let _guard = + builder.msg_clippy(format_args!("compiler{}", crate_description(&self.crates)), target); run_cargo( builder, From 5253fe4520dc14934f9cd99859da42a18686550f Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Fri, 22 Mar 2024 19:02:02 +0300 Subject: [PATCH 12/16] update `mingw-check` clippy invocation Previously this command was linting compiler and library together. As we no longer run clippy on the entire tree unless it's explicitly requested, we need to update this command by adding `library` path. Signed-off-by: onur-ozkan --- src/ci/docker/host-x86_64/mingw-check/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/host-x86_64/mingw-check/Dockerfile b/src/ci/docker/host-x86_64/mingw-check/Dockerfile index 6918574814fff..ae8dfadec738a 100644 --- a/src/ci/docker/host-x86_64/mingw-check/Dockerfile +++ b/src/ci/docker/host-x86_64/mingw-check/Dockerfile @@ -46,7 +46,7 @@ ENV SCRIPT python3 ../x.py --stage 2 test src/tools/expand-yaml-anchors && \ # We also skip the x86_64-unknown-linux-gnu target as it is well-tested by other jobs. python3 ../x.py check --stage 0 --set build.optimized-compiler-builtins=false core alloc std --target=aarch64-unknown-linux-gnu,i686-pc-windows-msvc,i686-unknown-linux-gnu,x86_64-apple-darwin,x86_64-pc-windows-gnu,x86_64-pc-windows-msvc && \ python3 ../x.py check --target=i686-pc-windows-gnu --host=i686-pc-windows-gnu && \ - python3 ../x.py clippy compiler -Aclippy::all -Dclippy::correctness && \ + python3 ../x.py clippy compiler library -Aclippy::all -Dclippy::correctness && \ python3 ../x.py build --stage 0 src/tools/build-manifest && \ python3 ../x.py test --stage 0 src/tools/compiletest && \ python3 ../x.py test --stage 0 core alloc std test proc_macro && \ From 16cf0e660737e23a32e48c2459c219ff433a9518 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Fri, 22 Mar 2024 20:19:24 +0300 Subject: [PATCH 13/16] allow running clippy on most of the in-tree tools Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/check.rs | 4 +- src/bootstrap/src/core/build_steps/clippy.rs | 49 +++++++++++++++---- src/bootstrap/src/core/build_steps/compile.rs | 2 +- src/bootstrap/src/core/builder.rs | 22 ++++++++- 4 files changed, 63 insertions(+), 14 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index 654ef1ec6a7f8..927d72e8ccb4b 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -13,7 +13,9 @@ use std::path::{Path, PathBuf}; pub fn cargo_subcommand(kind: Kind) -> &'static str { match kind { - Kind::Check | Kind::Clippy => "check", + Kind::Check + // We ensure check steps for both std and rustc from build_steps/clippy, so handle `Kind::Clippy` as well. + | Kind::Clippy => "check", Kind::Fix => "fix", _ => unreachable!(), } diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index 15d676bea2050..33323ec1e5de1 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -185,8 +185,17 @@ impl Step for Rustc { let compiler = builder.compiler(builder.top_stage, builder.config.build); let target = self.target; - builder.ensure(compile::Std::new(compiler, compiler.host)); - builder.ensure(compile::Std::new(compiler, target)); + if compiler.stage != 0 { + // If we're not in stage 0, then we won't have a std from the beta + // compiler around. That means we need to make sure there's one in + // the sysroot for the compiler to find. Otherwise, we're going to + // fail when building crates that need to generate code (e.g., build + // scripts and their dependencies). + builder.ensure(compile::Std::new(compiler, compiler.host)); + builder.ensure(compile::Std::new(compiler, target)); + } else { + builder.ensure(check::Std::new(target)); + } let mut cargo = builder::Cargo::new( builder, @@ -197,7 +206,7 @@ impl Step for Rustc { "clippy", ); - rustc_cargo(builder, &mut cargo, target, compiler.stage); + rustc_cargo(builder, &mut cargo, target, &compiler); // Explicitly pass -p for all compiler crates -- this will force cargo // to also lint the tests/benches/examples for these crates, rather @@ -224,9 +233,7 @@ impl Step for Rustc { macro_rules! lint_any { ($( $name:ident, $path:expr, $readable_name:expr - $(,is_external_tool = $external:expr)* - $(,is_unstable_tool = $unstable:expr)* - $(,allow_features = $allow_features:expr)? + $(,lint_by_default = $lint_by_default:expr)* ; )+) => { $( @@ -238,6 +245,7 @@ macro_rules! lint_any { impl Step for $name { type Output = (); + const DEFAULT: bool = if false $(|| $lint_by_default)* { true } else { false }; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { run.path($path) @@ -275,11 +283,15 @@ macro_rules! lint_any { &target, ); + let stamp = builder + .cargo_out(compiler, Mode::ToolRustc, target) + .join(format!(".{}-check.stamp", stringify!($name).to_lowercase())); + run_cargo( builder, cargo, lint_args(builder, &[]), - &libstd_stamp(builder, compiler, target), + &stamp, vec![], true, false, @@ -293,9 +305,26 @@ macro_rules! lint_any { lint_any!( Bootstrap, "src/bootstrap", "bootstrap"; BuildHelper, "src/tools/build_helper", "build_helper"; - CoverageDump, "src/tools/coverage-dump", "coverage-dump"; - Tidy, "src/tools/tidy", "tidy"; + BuildManifest, "src/tools/build-manifest", "build-manifest"; + CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri"; + Clippy, "src/tools/clippy", "clippy"; + CollectLicenseMetadata, "src/tools/collect-license-metadata", "collect-license-metadata"; Compiletest, "src/tools/compiletest", "compiletest"; - RemoteTestServer, "src/tools/remote-test-server", "remote-test-server"; + CoverageDump, "src/tools/coverage-dump", "coverage-dump"; + Jsondocck, "src/tools/jsondocck", "jsondocck"; + Jsondoclint, "src/tools/jsondoclint", "jsondoclint"; + LintDocs, "src/tools/lint-docs", "lint-docs"; + LlvmBitcodeLinker, "src/tools/llvm-bitcode-linker", "llvm-bitcode-linker"; + Miri, "src/tools/miri", "miri"; + MiroptTestTools, "src/tools/miropt-test-tools", "miropt-test-tools"; + OptDist, "src/tools/opt-dist", "opt-dist"; RemoteTestClient, "src/tools/remote-test-client", "remote-test-client"; + RemoteTestServer, "src/tools/remote-test-server", "remote-test-server"; + Rls, "src/tools/rls", "rls"; + RustAnalyzer, "src/tools/rust-analyzer", "rust-analyzer"; + RustDemangler, "src/tools/rust-demangler", "rust-demangler"; + Rustdoc, "src/tools/rustdoc", "clippy"; + Rustfmt, "src/tools/rustfmt", "rustfmt"; + RustInstaller, "src/tools/rust-installer", "rust-installer"; + Tidy, "src/tools/tidy", "tidy"; ); diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index b2ee2c8f1f798..9420e40d6c2b2 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -2012,7 +2012,7 @@ pub fn run_cargo( crate::exit!(1); } - if builder.config.dry_run() || builder.kind == Kind::Clippy { + if builder.config.dry_run() { return Vec::new(); } diff --git a/src/bootstrap/src/core/builder.rs b/src/bootstrap/src/core/builder.rs index 9d2352135c2f6..499a74be6b151 100644 --- a/src/bootstrap/src/core/builder.rs +++ b/src/bootstrap/src/core/builder.rs @@ -732,10 +732,28 @@ impl<'a> Builder<'a> { clippy::Rustc, clippy::Bootstrap, clippy::BuildHelper, + clippy::BuildManifest, + clippy::CargoMiri, + clippy::Clippy, + clippy::CollectLicenseMetadata, + clippy::Compiletest, clippy::CoverageDump, - clippy::Tidy, - clippy::RemoteTestServer, + clippy::Jsondocck, + clippy::Jsondoclint, + clippy::LintDocs, + clippy::LlvmBitcodeLinker, + clippy::Miri, + clippy::MiroptTestTools, + clippy::OptDist, clippy::RemoteTestClient, + clippy::RemoteTestServer, + clippy::Rls, + clippy::RustAnalyzer, + clippy::RustDemangler, + clippy::Rustdoc, + clippy::Rustfmt, + clippy::RustInstaller, + clippy::Tidy, ), Kind::Check | Kind::Fix => describe!( check::Std, From 9a67a6cb0433d1403c913a842a94bbb26a01c4d8 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 17 Apr 2024 08:37:04 +1000 Subject: [PATCH 14/16] Reinstate nnethercote to the review rotation. --- triagebot.toml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/triagebot.toml b/triagebot.toml index 6f8ed2edbfb3f..731642ca74cbe 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -800,6 +800,7 @@ compiler-team = [ compiler-team-contributors = [ "@TaKO8Ki", "@Nadrieril", + "@nnethercote", "@fmease", "@fee1-dead", "@BoxyUwU", @@ -857,14 +858,17 @@ parser = [ "@compiler-errors", "@davidtwco", "@estebank", + "@nnethercote", "@petrochenkov", "@spastorino", ] lexer = [ + "@nnethercote", "@petrochenkov", "@estebank", ] arena = [ + "@nnethercote", "@spastorino", ] mir = [ From e480cabe3ae2b9363ebf92ab702c310f72c13a5a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 16 Apr 2024 18:19:27 -0700 Subject: [PATCH 15/16] Fix empty-set symbol in comments --- compiler/rustc_ast/src/token.rs | 2 +- compiler/rustc_parse/src/parser/item.rs | 2 +- library/proc_macro/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index f07036dea0f86..5b41ac8a69ee0 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -51,7 +51,7 @@ pub enum Delimiter { Brace, /// `[ ... ]` Bracket, - /// `Ø ... Ø` + /// `∅ ... ∅` /// An invisible delimiter, that may, for example, appear around tokens coming from a /// "macro variable" `$var`. It is important to preserve operator priorities in cases like /// `$var * 3` where `$var` is `1 + 2`. diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index b711ee9a8ee78..1b335573b16db 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1063,7 +1063,7 @@ impl<'a> Parser<'a> { /// Parses a `UseTreeKind::Nested(list)`. /// /// ```text - /// USE_TREE_LIST = Ø | (USE_TREE `,`)* USE_TREE [`,`] + /// USE_TREE_LIST = ∅ | (USE_TREE `,`)* USE_TREE [`,`] /// ``` fn parse_use_tree_list(&mut self) -> PResult<'a, ThinVec<(UseTree, ast::NodeId)>> { self.parse_delim_comma_seq(Delimiter::Brace, |p| { diff --git a/library/proc_macro/src/lib.rs b/library/proc_macro/src/lib.rs index a3ebef45c8849..c8db028b651f6 100644 --- a/library/proc_macro/src/lib.rs +++ b/library/proc_macro/src/lib.rs @@ -811,7 +811,7 @@ pub enum Delimiter { /// `[ ... ]` #[stable(feature = "proc_macro_lib2", since = "1.29.0")] Bracket, - /// `Ø ... Ø` + /// `∅ ... ∅` /// An invisible delimiter, that may, for example, appear around tokens coming from a /// "macro variable" `$var`. It is important to preserve operator priorities in cases like /// `$var * 3` where `$var` is `1 + 2`. From c021367de1897288f81e7f8bba23c2d2325e57f4 Mon Sep 17 00:00:00 2001 From: beetrees Date: Wed, 17 Apr 2024 03:10:09 +0100 Subject: [PATCH 16/16] Make the comments for `ReturnDest` variants doc comments --- compiler/rustc_codegen_ssa/src/mir/block.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 24f2c50e882fb..452398e6d8285 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -1861,12 +1861,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } enum ReturnDest<'tcx, V> { - // Do nothing; the return value is indirect or ignored. + /// Do nothing; the return value is indirect or ignored. Nothing, - // Store the return value to the pointer. + /// Store the return value to the pointer. Store(PlaceRef<'tcx, V>), - // Store an indirect return value to an operand local place. + /// Store an indirect return value to an operand local place. IndirectOperand(PlaceRef<'tcx, V>, mir::Local), - // Store a direct return value to an operand local place. + /// Store a direct return value to an operand local place. DirectOperand(mir::Local), }