diff --git a/Cargo.lock b/Cargo.lock index 563d99d5475c4..4bcc334ffd5d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3892,8 +3892,6 @@ dependencies = [ "icu_list", "icu_locale", "intl-memoizer", - "rustc_ast", - "rustc_ast_pretty", "rustc_baked_icu_data", "rustc_data_structures", "rustc_macros", @@ -3910,7 +3908,6 @@ dependencies = [ "anstream", "anstyle", "derive_setters", - "rustc_ast", "rustc_data_structures", "rustc_error_codes", "rustc_error_messages", @@ -3996,7 +3993,6 @@ dependencies = [ "rustc_data_structures", "rustc_error_messages", "rustc_hashes", - "rustc_hir_id", "rustc_index", "rustc_lint_defs", "rustc_macros", @@ -4033,17 +4029,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "rustc_hir_id" -version = "0.0.0" -dependencies = [ - "rustc_data_structures", - "rustc_index", - "rustc_macros", - "rustc_serialize", - "rustc_span", -] - [[package]] name = "rustc_hir_pretty" version = "0.0.0" @@ -4224,10 +4209,8 @@ dependencies = [ name = "rustc_lint_defs" version = "0.0.0" dependencies = [ - "rustc_ast", "rustc_data_structures", "rustc_error_messages", - "rustc_hir_id", "rustc_macros", "rustc_serialize", "rustc_span", diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index ae4989fcbc6c9..01f72943362fb 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -30,6 +30,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_data_structures::tagged_ptr::Tag; use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable}; pub use rustc_span::AttrId; +pub use rustc_span::node_id::{self, CRATE_NODE_ID, DUMMY_NODE_ID, NodeId}; use rustc_span::{ ByteSymbol, DUMMY_SP, ErrorGuaranteed, HashStableContext, Ident, Span, Spanned, Symbol, kw, respan, sym, @@ -370,8 +371,6 @@ impl ParenthesizedArgs { } } -pub use crate::node_id::{CRATE_NODE_ID, DUMMY_NODE_ID, NodeId}; - /// Modifiers on a trait bound like `[const]`, `?` and `!`. #[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Walkable)] pub struct TraitBoundModifiers { diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs index 4178db1bfb09d..8faabc9ef9dbd 100644 --- a/compiler/rustc_ast/src/lib.rs +++ b/compiler/rustc_ast/src/lib.rs @@ -29,7 +29,6 @@ pub mod entry; pub mod expand; pub mod format; pub mod mut_visit; -pub mod node_id; pub mod token; pub mod tokenstream; pub mod visit; diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 0541d39318f47..a55739bad69c8 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -1117,8 +1117,8 @@ fn validate_generic_param_order(dcx: DiagCtxtHandle<'_>, generics: &[GenericPara dcx.emit_err(errors::OutOfOrderParams { spans: spans.clone(), sugg_span: span, - param_ord, - max_param, + param_ord: param_ord.to_string(), + max_param: max_param.to_string(), ordered_params: &ordered_params, }); } diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index b3a22c0c99549..a6b75cb70a548 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -1,7 +1,6 @@ //! Errors emitted by ast_passes. use rustc_abi::ExternAbi; -use rustc_ast::ParamKindOrd; use rustc_errors::codes::*; use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic}; use rustc_macros::{Diagnostic, Subdiagnostic}; @@ -632,8 +631,8 @@ pub(crate) struct OutOfOrderParams<'a> { applicability = "machine-applicable" )] pub sugg_span: Span, - pub param_ord: &'a ParamKindOrd, - pub max_param: &'a ParamKindOrd, + pub param_ord: String, + pub max_param: String, pub ordered_params: &'a str, } diff --git a/compiler/rustc_builtin_macros/src/env.rs b/compiler/rustc_builtin_macros/src/env.rs index f60113dbfc9bc..d9af43fcd1c3d 100644 --- a/compiler/rustc_builtin_macros/src/env.rs +++ b/compiler/rustc_builtin_macros/src/env.rs @@ -9,6 +9,7 @@ use std::env::VarError; use rustc_ast::token::{self, LitKind}; use rustc_ast::tokenstream::TokenStream; use rustc_ast::{ExprKind, GenericArg, Mutability}; +use rustc_ast_pretty::pprust; use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult}; use rustc_span::edit_distance::edit_distance; use rustc_span::{Ident, Span, Symbol, kw, sym}; @@ -158,13 +159,13 @@ pub(crate) fn expand_env<'cx>( cx.dcx().emit_err(errors::EnvNotDefined::CargoEnvVar { span, var: *symbol, - var_expr: &var_expr, + var_expr: pprust::expr_to_string(&var_expr), }) } else { cx.dcx().emit_err(errors::EnvNotDefined::CustomEnvVar { span, var: *symbol, - var_expr: &var_expr, + var_expr: pprust::expr_to_string(&var_expr), }) } } diff --git a/compiler/rustc_builtin_macros/src/errors.rs b/compiler/rustc_builtin_macros/src/errors.rs index b5ac84337465a..7022115cb68aa 100644 --- a/compiler/rustc_builtin_macros/src/errors.rs +++ b/compiler/rustc_builtin_macros/src/errors.rs @@ -553,7 +553,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for EnvNotDefinedWithUserMessag } #[derive(Diagnostic)] -pub(crate) enum EnvNotDefined<'a> { +pub(crate) enum EnvNotDefined { #[diag("environment variable `{$var}` not defined at compile time")] #[help("`{$var}` may not be available for the current Cargo target")] #[help( @@ -563,7 +563,7 @@ pub(crate) enum EnvNotDefined<'a> { #[primary_span] span: Span, var: Symbol, - var_expr: &'a rustc_ast::Expr, + var_expr: String, }, #[diag("environment variable `{$var}` not defined at compile time")] #[help("there is a similar Cargo environment variable: `{$suggested_var}`")] @@ -579,7 +579,7 @@ pub(crate) enum EnvNotDefined<'a> { #[primary_span] span: Span, var: Symbol, - var_expr: &'a rustc_ast::Expr, + var_expr: String, }, } diff --git a/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs b/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs index 4ca890fee1918..ae8dd6fc7a8cb 100644 --- a/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs +++ b/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs @@ -822,7 +822,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( return_error!(InvalidMonomorphization::FloatingPointVector { span, name, - f_ty: *f, + f_ty: f.name_str().to_string(), in_ty }); } diff --git a/compiler/rustc_codegen_ssa/src/errors.rs b/compiler/rustc_codegen_ssa/src/errors.rs index cec84f60a7b0e..e81991b1cc71d 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -12,8 +12,8 @@ use rustc_errors::{ Level, msg, }; use rustc_macros::{Diagnostic, Subdiagnostic}; +use rustc_middle::ty::Ty; use rustc_middle::ty::layout::LayoutError; -use rustc_middle::ty::{FloatTy, Ty}; use rustc_span::{Span, Symbol}; use crate::assert_module_sources::CguReuse; @@ -729,7 +729,7 @@ pub enum InvalidMonomorphization<'tcx> { #[primary_span] span: Span, name: Symbol, - f_ty: FloatTy, + f_ty: String, in_ty: Ty<'tcx>, }, diff --git a/compiler/rustc_error_messages/Cargo.toml b/compiler/rustc_error_messages/Cargo.toml index f280aaff11260..687aff5e9229a 100644 --- a/compiler/rustc_error_messages/Cargo.toml +++ b/compiler/rustc_error_messages/Cargo.toml @@ -9,8 +9,6 @@ fluent-bundle = "0.16" icu_list = { version = "2.0", default-features = false, features = ["alloc"] } icu_locale = { version = "2.0", default-features = false } intl-memoizer = "0.5.1" -rustc_ast = { path = "../rustc_ast" } -rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_baked_icu_data = { path = "../rustc_baked_icu_data" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_error_messages/src/diagnostic_impls.rs b/compiler/rustc_error_messages/src/diagnostic_impls.rs index 3b664cce5776f..38b086eaa80d3 100644 --- a/compiler/rustc_error_messages/src/diagnostic_impls.rs +++ b/compiler/rustc_error_messages/src/diagnostic_impls.rs @@ -5,8 +5,6 @@ use std::num::ParseIntError; use std::path::{Path, PathBuf}; use std::process::ExitStatus; -use rustc_ast as ast; -use rustc_ast_pretty::pprust; use rustc_span::edition::Edition; use crate::{DiagArgValue, IntoDiagArg}; @@ -69,7 +67,6 @@ macro_rules! into_diag_arg_for_number { } into_diag_arg_using_display!( - ast::ParamKindOrd, std::io::Error, Box, std::num::NonZero, @@ -142,30 +139,6 @@ impl IntoDiagArg for PathBuf { } } -impl IntoDiagArg for ast::Expr { - fn into_diag_arg(self, _: &mut Option) -> DiagArgValue { - DiagArgValue::Str(Cow::Owned(pprust::expr_to_string(&self))) - } -} - -impl IntoDiagArg for ast::Path { - fn into_diag_arg(self, _: &mut Option) -> DiagArgValue { - DiagArgValue::Str(Cow::Owned(pprust::path_to_string(&self))) - } -} - -impl IntoDiagArg for ast::token::Token { - fn into_diag_arg(self, _: &mut Option) -> DiagArgValue { - DiagArgValue::Str(pprust::token_to_string(&self)) - } -} - -impl IntoDiagArg for ast::token::TokenKind { - fn into_diag_arg(self, _: &mut Option) -> DiagArgValue { - DiagArgValue::Str(pprust::token_kind_to_string(&self)) - } -} - impl IntoDiagArg for std::ffi::CString { fn into_diag_arg(self, _: &mut Option) -> DiagArgValue { DiagArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned())) @@ -178,28 +151,8 @@ impl IntoDiagArg for rustc_data_structures::small_c_str::SmallCStr { } } -impl IntoDiagArg for ast::Visibility { - fn into_diag_arg(self, _: &mut Option) -> DiagArgValue { - let s = pprust::vis_to_string(&self); - let s = s.trim_end().to_string(); - DiagArgValue::Str(Cow::Owned(s)) - } -} - impl IntoDiagArg for Backtrace { fn into_diag_arg(self, _: &mut Option) -> DiagArgValue { DiagArgValue::Str(Cow::from(self.to_string())) } } - -impl IntoDiagArg for ast::util::parser::ExprPrecedence { - fn into_diag_arg(self, _: &mut Option) -> DiagArgValue { - DiagArgValue::Number(self as i32) - } -} - -impl IntoDiagArg for ast::FloatTy { - fn into_diag_arg(self, _: &mut Option) -> DiagArgValue { - DiagArgValue::Str(Cow::Borrowed(self.name_str())) - } -} diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml index 386467c3e1edb..000aafd540e4d 100644 --- a/compiler/rustc_errors/Cargo.toml +++ b/compiler/rustc_errors/Cargo.toml @@ -9,7 +9,6 @@ annotate-snippets = { version = "0.12.15", features = ["simd"] } anstream = "0.6.20" anstyle = "1.0.13" derive_setters = "0.1.6" -rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_error_codes = { path = "../rustc_error_codes" } rustc_error_messages = { path = "../rustc_error_messages" } diff --git a/compiler/rustc_errors/src/decorate_diag.rs b/compiler/rustc_errors/src/decorate_diag.rs index 18c0c571fd1b8..2c6950a8b1349 100644 --- a/compiler/rustc_errors/src/decorate_diag.rs +++ b/compiler/rustc_errors/src/decorate_diag.rs @@ -1,11 +1,11 @@ use std::any::Any; -/// This module provides types and traits for buffering lints until later in compilation. -use rustc_ast::node_id::NodeId; use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::sync::{DynSend, DynSync}; use rustc_error_messages::MultiSpan; use rustc_lint_defs::{AttributeLintKind, Lint, LintId}; +/// This module provides types and traits for buffering lints until later in compilation. +use rustc_span::node_id::NodeId; use crate::{Diag, DiagCtxtHandle, Diagnostic, Level}; diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs index 6c5732f497f8a..aef8e95c52f2d 100644 --- a/compiler/rustc_expand/src/errors.rs +++ b/compiler/rustc_expand/src/errors.rs @@ -1,6 +1,5 @@ use std::borrow::Cow; -use rustc_ast::ast; use rustc_errors::codes::*; use rustc_hir::limit::Limit; use rustc_macros::{Diagnostic, Subdiagnostic}; @@ -230,7 +229,7 @@ pub(crate) struct WrongFragmentKind<'a> { #[primary_span] pub span: Span, pub kind: &'a str, - pub name: &'a ast::Path, + pub name: String, } #[derive(Diagnostic)] @@ -249,7 +248,7 @@ pub(crate) struct IncompleteParse<'a> { pub descr: String, #[label("caused by the macro expansion here")] pub label_span: Span, - pub macro_path: &'a ast::Path, + pub macro_path: String, pub kind_name: &'a str, #[note("macros cannot expand to match arms")] pub expands_to_match_arm: bool, diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 9f5a01452fdc3..cd3b21a7f1be7 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -713,8 +713,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> { mac: &ast::MacCall, span: Span, ) -> ErrorGuaranteed { - let guar = - self.cx.dcx().emit_err(WrongFragmentKind { span, kind: kind.name(), name: &mac.path }); + let name = pprust::path_to_string(&mac.path); + let guar = self.cx.dcx().emit_err(WrongFragmentKind { span, kind: kind.name(), name }); self.cx.macro_error_and_trace_macros_diag(); guar } @@ -1218,7 +1218,7 @@ pub(crate) fn ensure_complete_parse<'a>( span: def_site_span, descr, label_span: span, - macro_path, + macro_path: pprust::path_to_string(macro_path), kind_name, expands_to_match_arm, add_semicolon, diff --git a/compiler/rustc_hir/Cargo.toml b/compiler/rustc_hir/Cargo.toml index 13e73acf07375..bc3ea9b207657 100644 --- a/compiler/rustc_hir/Cargo.toml +++ b/compiler/rustc_hir/Cargo.toml @@ -14,7 +14,6 @@ rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_error_messages = { path = "../rustc_error_messages" } rustc_hashes = { path = "../rustc_hashes" } -rustc_hir_id = { path = "../rustc_hir_id" } rustc_index = { path = "../rustc_index" } rustc_lint_defs = { path = "../rustc_lint_defs" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index ec701cbe9a469..0e100d106657c 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -512,7 +512,7 @@ impl DefKind { /// pointing to the definition of `str_to_string` in the current crate. // #[derive(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Debug, HashStable_Generic)] -pub enum Res { +pub enum Res { /// Definition having a unique ID (`DefId`), corresponds to something defined in user code. /// /// **Not bound to a specific namespace.** diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 15afa9a929099..4cfbf0b06a3dc 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -33,8 +33,7 @@ use tracing::debug; use crate::attrs::AttributeKind; use crate::def::{CtorKind, DefKind, MacroKinds, PerNS, Res}; -use crate::def_id::{DefId, LocalDefIdMap}; -pub(crate) use crate::hir_id::{HirId, ItemLocalId, ItemLocalMap, OwnerId}; +use crate::def_id::{DefId, HirId, ItemLocalId, ItemLocalMap, LocalDefIdMap, OwnerId}; use crate::intravisit::{FnKind, VisitorExt}; use crate::lints::DelayedLints; @@ -4794,7 +4793,7 @@ impl<'hir> OwnerNode<'hir> { | OwnerNode::TraitItem(TraitItem { owner_id, .. }) | OwnerNode::ImplItem(ImplItem { owner_id, .. }) | OwnerNode::ForeignItem(ForeignItem { owner_id, .. }) => *owner_id, - OwnerNode::Crate(..) => crate::CRATE_HIR_ID.owner, + OwnerNode::Crate(..) => crate::def_id::CRATE_HIR_ID.owner, OwnerNode::Synthetic => unreachable!(), } } diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index 9ffcd3461f2de..b3fd3c767ae5f 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -69,6 +69,7 @@ use rustc_ast::visit::{VisitorResult, try_visit, visit_opt, walk_list}; use rustc_span::def_id::LocalDefId; use rustc_span::{Ident, Span, Symbol}; +use crate::def_id::HirId; use crate::hir::*; pub trait IntoVisitor<'hir> { diff --git a/compiler/rustc_hir/src/lib.rs b/compiler/rustc_hir/src/lib.rs index c2d9f879cd601..f0a9eb7c0e552 100644 --- a/compiler/rustc_hir/src/lib.rs +++ b/compiler/rustc_hir/src/lib.rs @@ -23,8 +23,11 @@ pub mod def_path_hash_map; pub mod definitions; pub mod diagnostic_items; pub use rustc_span::def_id; +pub use rustc_span::def_id::{ + CRATE_HIR_ID, CRATE_OWNER_ID, HirId, HirIdMap, HirIdMapEntry, HirIdSet, ItemLocalId, + ItemLocalMap, ItemLocalMapEntry, ItemLocalSet, OwnerId, +}; mod hir; -pub use rustc_hir_id::{self as hir_id, *}; pub mod intravisit; pub mod lang_items; pub mod limit; diff --git a/compiler/rustc_hir/src/pat_util.rs b/compiler/rustc_hir/src/pat_util.rs index 8dd1e4e829274..6538046658f96 100644 --- a/compiler/rustc_hir/src/pat_util.rs +++ b/compiler/rustc_hir/src/pat_util.rs @@ -3,8 +3,8 @@ use std::iter::Enumerate; use rustc_span::{Ident, Span}; use crate::def::{CtorOf, DefKind, Res}; -use crate::def_id::{DefId, DefIdSet}; -use crate::hir::{self, BindingMode, ByRef, HirId, PatKind}; +use crate::def_id::{DefId, DefIdSet, HirId}; +use crate::hir::{self, BindingMode, ByRef, PatKind}; pub struct EnumerateAndAdjust { enumerate: Enumerate, diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs index f2cfeaf027f3b..c4dd5a02f9294 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -3,10 +3,10 @@ use rustc_span::HashStableContext; use rustc_span::def_id::DefPathHash; use crate::HashIgnoredAttrId; +use crate::def_id::ItemLocalId; use crate::hir::{ AttributeMap, BodyId, ForeignItemId, ImplItemId, ItemId, OwnerNodes, TraitItemId, }; -use crate::hir_id::ItemLocalId; use crate::lints::DelayedLints; impl ToStableHashKey for BodyId { diff --git a/compiler/rustc_hir_id/Cargo.toml b/compiler/rustc_hir_id/Cargo.toml deleted file mode 100644 index c357a4f62d968..0000000000000 --- a/compiler/rustc_hir_id/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "rustc_hir_id" -version = "0.0.0" -edition = "2024" - -[dependencies] -# tidy-alphabetical-start -rustc_data_structures = { path = "../rustc_data_structures" } -rustc_index = { path = "../rustc_index" } -rustc_macros = { path = "../rustc_macros" } -rustc_serialize = { path = "../rustc_serialize" } -rustc_span = { path = "../rustc_span" } -# tidy-alphabetical-end diff --git a/compiler/rustc_hir_id/src/lib.rs b/compiler/rustc_hir_id/src/lib.rs deleted file mode 100644 index f37a19e9c1fe7..0000000000000 --- a/compiler/rustc_hir_id/src/lib.rs +++ /dev/null @@ -1,196 +0,0 @@ -//! Library containing Id types from `rustc_hir`, split out so crates can use it without depending -//! on all of `rustc_hir` (which is large and depends on other large things like `rustc_target`). -#![allow(internal_features)] -#![feature(negative_impls)] -#![feature(rustc_attrs)] - -use std::fmt::{self, Debug}; - -use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey}; -use rustc_macros::{Decodable, Encodable, HashStable_Generic}; -use rustc_span::HashStableContext; -use rustc_span::def_id::{CRATE_DEF_ID, DefId, DefIndex, DefPathHash, LocalDefId}; - -#[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)] -pub struct OwnerId { - pub def_id: LocalDefId, -} - -impl Debug for OwnerId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - // Example: DefId(0:1 ~ aa[7697]::{use#0}) - Debug::fmt(&self.def_id, f) - } -} - -impl From for HirId { - fn from(owner: OwnerId) -> HirId { - HirId { owner, local_id: ItemLocalId::ZERO } - } -} - -impl From for DefId { - fn from(value: OwnerId) -> Self { - value.to_def_id() - } -} - -impl OwnerId { - #[inline] - pub fn to_def_id(self) -> DefId { - self.def_id.to_def_id() - } -} - -impl rustc_index::Idx for OwnerId { - #[inline] - fn new(idx: usize) -> Self { - OwnerId { def_id: LocalDefId { local_def_index: DefIndex::from_usize(idx) } } - } - - #[inline] - fn index(self) -> usize { - self.def_id.local_def_index.as_usize() - } -} - -impl HashStable for OwnerId { - #[inline] - fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { - self.to_stable_hash_key(hcx).hash_stable(hcx, hasher); - } -} - -impl ToStableHashKey for OwnerId { - type KeyType = DefPathHash; - - #[inline] - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { - hcx.def_path_hash(self.to_def_id()) - } -} - -/// Uniquely identifies a node in the HIR of the current crate. It is -/// composed of the `owner`, which is the `LocalDefId` of the directly enclosing -/// `hir::Item`, `hir::TraitItem`, or `hir::ImplItem` (i.e., the closest "item-like"), -/// and the `local_id` which is unique within the given owner. -/// -/// This two-level structure makes for more stable values: One can move an item -/// around within the source code, or add or remove stuff before it, without -/// the `local_id` part of the `HirId` changing, which is a very useful property in -/// incremental compilation where we have to persist things through changes to -/// the code base. -#[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)] -#[rustc_pass_by_value] -pub struct HirId { - pub owner: OwnerId, - pub local_id: ItemLocalId, -} - -// To ensure correctness of incremental compilation, -// `HirId` must not implement `Ord` or `PartialOrd`. -// See https://github.com/rust-lang/rust/issues/90317. -impl !Ord for HirId {} -impl !PartialOrd for HirId {} - -impl Debug for HirId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - // Example: HirId(DefId(0:1 ~ aa[7697]::{use#0}).10) - // Don't use debug_tuple to always keep this on one line. - write!(f, "HirId({:?}.{:?})", self.owner, self.local_id) - } -} - -impl HirId { - /// Signal local id which should never be used. - pub const INVALID: HirId = - HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::INVALID }; - - #[inline] - pub fn expect_owner(self) -> OwnerId { - assert_eq!(self.local_id.index(), 0); - self.owner - } - - #[inline] - pub fn as_owner(self) -> Option { - if self.local_id.index() == 0 { Some(self.owner) } else { None } - } - - #[inline] - pub fn is_owner(self) -> bool { - self.local_id.index() == 0 - } - - #[inline] - pub fn make_owner(owner: LocalDefId) -> Self { - Self { owner: OwnerId { def_id: owner }, local_id: ItemLocalId::ZERO } - } -} - -impl fmt::Display for HirId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{self:?}") - } -} - -rustc_data_structures::define_stable_id_collections!(HirIdMap, HirIdSet, HirIdMapEntry, HirId); -rustc_data_structures::define_id_collections!( - ItemLocalMap, - ItemLocalSet, - ItemLocalMapEntry, - ItemLocalId -); - -rustc_index::newtype_index! { - /// An `ItemLocalId` uniquely identifies something within a given "item-like"; - /// that is, within a `hir::Item`, `hir::TraitItem`, or `hir::ImplItem`. There is no - /// guarantee that the numerical value of a given `ItemLocalId` corresponds to - /// the node's position within the owning item in any way, but there is a - /// guarantee that the `ItemLocalId`s within an owner occupy a dense range of - /// integers starting at zero, so a mapping that maps all or most nodes within - /// an "item-like" to something else can be implemented by a `Vec` instead of a - /// tree or hash map. - #[stable_hash_generic] - #[encodable] - #[orderable] - pub struct ItemLocalId {} -} - -impl ItemLocalId { - /// Signal local id which should never be used. - pub const INVALID: ItemLocalId = ItemLocalId::MAX; -} - -impl StableOrd for ItemLocalId { - const CAN_USE_UNSTABLE_SORT: bool = true; - - // `Ord` is implemented as just comparing the ItemLocalId's numerical - // values and these are not changed by (de-)serialization. - const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); -} - -/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_ID`. -pub const CRATE_HIR_ID: HirId = - HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::ZERO }; - -pub const CRATE_OWNER_ID: OwnerId = OwnerId { def_id: CRATE_DEF_ID }; - -impl ToStableHashKey for HirId { - type KeyType = (DefPathHash, ItemLocalId); - - #[inline] - fn to_stable_hash_key(&self, hcx: &mut Hcx) -> (DefPathHash, ItemLocalId) { - let def_path_hash = self.owner.def_id.to_stable_hash_key(hcx); - (def_path_hash, self.local_id) - } -} - -impl ToStableHashKey for ItemLocalId { - type KeyType = ItemLocalId; - - #[inline] - fn to_stable_hash_key(&self, _: &mut Hcx) -> ItemLocalId { - *self - } -} diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 6f64d07b01d66..b465ea01d1aeb 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -18,9 +18,10 @@ use rustc_ast_pretty::pprust::state::MacHeader; use rustc_ast_pretty::pprust::{Comments, PrintState}; use rustc_hir as hir; use rustc_hir::attrs::{AttributeKind, PrintAttribute}; +use rustc_hir::def_id::{CRATE_HIR_ID, HirId}; use rustc_hir::{ BindingMode, ByRef, ConstArg, ConstArgExprField, ConstArgKind, GenericArg, GenericBound, - GenericParam, GenericParamKind, HirId, ImplicitSelfKind, LifetimeParamKind, Node, PatKind, + GenericParam, GenericParamKind, ImplicitSelfKind, LifetimeParamKind, Node, PatKind, PreciseCapturingArg, RangeEnd, Term, TyFieldPath, TyPatKind, }; use rustc_span::source_map::SourceMap; @@ -286,7 +287,7 @@ pub fn print_crate<'a>( // Print all attributes, regardless of actual style, as inner attributes // since this is the crate root with nothing above it to print outer // attributes. - for attr in s.attrs(hir::CRATE_HIR_ID) { + for attr in s.attrs(CRATE_HIR_ID) { s.print_attribute_as_style(attr, ast::AttrStyle::Inner); } diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 2b859b65c9f8f..5bb74520a10f6 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -671,7 +671,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> { continue; } - let (level, lint_id) = match Level::from_attr(attr) { + let (level, lint_id) = match Level::from_attr(attr.name(), || attr.id()) { None => continue, // This is the only lint level with a `LintExpectationId` that can be created from // an attribute. diff --git a/compiler/rustc_lint_defs/Cargo.toml b/compiler/rustc_lint_defs/Cargo.toml index c8201d5ea8ccc..99869acd1d64e 100644 --- a/compiler/rustc_lint_defs/Cargo.toml +++ b/compiler/rustc_lint_defs/Cargo.toml @@ -5,10 +5,8 @@ edition = "2024" [dependencies] # tidy-alphabetical-start -rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_error_messages = { path = "../rustc_error_messages" } -rustc_hir_id = { path = "../rustc_hir_id" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index a77b7bc7d9483..52cdbb6dff0ac 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -1,18 +1,15 @@ use std::borrow::Cow; use std::fmt::Display; -use rustc_ast::AttrId; -use rustc_ast::attr::AttributeExt; use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::stable_hasher::{ HashStable, StableCompare, StableHasher, ToStableHashKey, }; use rustc_error_messages::{DiagArgValue, IntoDiagArg}; -use rustc_hir_id::{HirId, ItemLocalId}; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; -use rustc_span::def_id::DefPathHash; +use rustc_span::def_id::{DefPathHash, HirId, ItemLocalId}; pub use rustc_span::edition::Edition; -use rustc_span::{HashStableContext, Ident, Span, Symbol, sym}; +use rustc_span::{AttrId, HashStableContext, Ident, Span, Symbol, sym}; use serde::{Deserialize, Serialize}; pub use self::Level::*; @@ -248,8 +245,11 @@ impl Level { } /// Converts an `Attribute` to a level. - pub fn from_attr(attr: &impl AttributeExt) -> Option<(Self, Option)> { - attr.name().and_then(|name| Self::from_symbol(name, || Some(attr.id()))) + pub fn from_attr( + attr_name: Option, + attr_id: impl Fn() -> AttrId, + ) -> Option<(Self, Option)> { + attr_name.and_then(|name| Self::from_symbol(name, || Some(attr_id()))) } /// Converts a `Symbol` to a level. diff --git a/compiler/rustc_middle/src/query/keys.rs b/compiler/rustc_middle/src/query/keys.rs index ad101cf34da3b..550b220f9eb7a 100644 --- a/compiler/rustc_middle/src/query/keys.rs +++ b/compiler/rustc_middle/src/query/keys.rs @@ -6,8 +6,7 @@ use std::hash::Hash; use rustc_ast::tokenstream::TokenStream; use rustc_data_structures::stable_hasher::HashStable; -use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId}; -use rustc_hir::hir_id::OwnerId; +use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId, OwnerId}; use rustc_span::{DUMMY_SP, Ident, LocalExpnId, Span, Symbol}; use crate::dep_graph::DepNodeIndex; diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index b8399215cf810..97c5574bc8b43 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -7,8 +7,7 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::unord::{ExtendUnord, UnordItems, UnordSet}; use rustc_errors::ErrorGuaranteed; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap}; -use rustc_hir::hir_id::OwnerId; +use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap, OwnerId}; use rustc_hir::{ self as hir, BindingMode, ByRef, HirId, ItemLocalId, ItemLocalMap, ItemLocalSet, Mutability, }; diff --git a/compiler/rustc_mir_build/src/builder/scope.rs b/compiler/rustc_mir_build/src/builder/scope.rs index 91610e768d012..6baf82f1335d0 100644 --- a/compiler/rustc_mir_build/src/builder/scope.rs +++ b/compiler/rustc_mir_build/src/builder/scope.rs @@ -1298,7 +1298,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { break; } - if self.tcx.hir_attrs(id).iter().any(|attr| Level::from_attr(attr).is_some()) { + if self + .tcx + .hir_attrs(id) + .iter() + .any(|attr| Level::from_attr(attr.name(), || attr.id()).is_some()) + { // This is a rare case. It's for a node path that doesn't reach the root due to an // intervening lint level attribute. This result doesn't get cached. return id; diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index cc1e0ff85dae4..c9777f41d445f 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -4,8 +4,7 @@ use std::borrow::Cow; use std::path::PathBuf; use rustc_ast::token::{self, InvisibleOrigin, MetaVarKind, Token}; -use rustc_ast::util::parser::ExprPrecedence; -use rustc_ast::{Path, Visibility}; +use rustc_ast_pretty::pprust; use rustc_errors::codes::*; use rustc_errors::{ Applicability, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, @@ -657,7 +656,7 @@ pub(crate) struct ExpectedStructField { #[primary_span] #[label("expected one of `,`, `:`, or `{\"}\"}`")] pub span: Span, - pub token: Token, + pub token: Cow<'static, str>, #[label("while parsing this struct field")] pub ident_span: Span, } @@ -875,7 +874,7 @@ pub(crate) struct ComparisonInterpretedAsGeneric { #[primary_span] #[label("not interpreted as comparison")] pub comparison: Span, - pub r#type: Path, + pub r#type: String, #[label("interpreted as generic arguments")] pub args: Span, #[subdiagnostic] @@ -897,7 +896,7 @@ pub(crate) struct ShiftInterpretedAsGeneric { #[primary_span] #[label("not interpreted as shift")] pub shift: Span, - pub r#type: Path, + pub r#type: String, #[label("interpreted as generic arguments")] pub args: Span, #[subdiagnostic] @@ -919,7 +918,7 @@ pub(crate) struct FoundExprWouldBeStmt { #[primary_span] #[label("expected expression")] pub span: Span, - pub token: Token, + pub token: Cow<'static, str>, #[subdiagnostic] pub suggestion: ExprParenthesesNeeded, } @@ -1028,7 +1027,7 @@ pub(crate) struct ParenthesesWithStructFields { applicability = "maybe-incorrect" )] pub(crate) struct BracesForStructLiteral { - pub r#type: Path, + pub r#type: String, #[suggestion_part(code = " {{ ")] pub first: Span, #[suggestion_part(code = " }}")] @@ -1041,7 +1040,7 @@ pub(crate) struct BracesForStructLiteral { applicability = "maybe-incorrect" )] pub(crate) struct NoFieldsForFnCall { - pub r#type: Path, + pub r#type: String, #[suggestion_part(code = "")] pub fields: Vec, } @@ -1513,7 +1512,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for ExpectedIdentifier { ); diag.span(self.span); if add_token { - diag.arg("token", self.token); + diag.arg("token", pprust::token_to_string(&self.token)); } if let Some(sugg) = self.suggest_raw { @@ -1579,7 +1578,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for ExpectedSemi { ); diag.span(self.span); if add_token { - diag.arg("token", self.token); + diag.arg("token", pprust::token_to_string(&self.token)); } if let Some(unexpected_token_label) = self.unexpected_token_label { @@ -2220,7 +2219,7 @@ pub(crate) struct VisibilityNotFollowedByItem { #[primary_span] #[label("the visibility")] pub span: Span, - pub vis: Visibility, + pub vis: String, } #[derive(Diagnostic)] @@ -2535,14 +2534,14 @@ pub(crate) enum UnexpectedTokenAfterStructName { #[primary_span] #[label("expected `where`, `{\"{\"}`, `(`, or `;` after struct name")] span: Span, - token: Token, + token: Cow<'static, str>, }, #[diag("expected `where`, `{\"{\"}`, `(`, or `;` after struct name, found keyword `{$token}`")] Keyword { #[primary_span] #[label("expected `where`, `{\"{\"}`, `(`, or `;` after struct name")] span: Span, - token: Token, + token: Cow<'static, str>, }, #[diag( "expected `where`, `{\"{\"}`, `(`, or `;` after struct name, found reserved keyword `{$token}`" @@ -2551,7 +2550,7 @@ pub(crate) enum UnexpectedTokenAfterStructName { #[primary_span] #[label("expected `where`, `{\"{\"}`, `(`, or `;` after struct name")] span: Span, - token: Token, + token: Cow<'static, str>, }, #[diag( "expected `where`, `{\"{\"}`, `(`, or `;` after struct name, found doc comment `{$token}`" @@ -2560,7 +2559,7 @@ pub(crate) enum UnexpectedTokenAfterStructName { #[primary_span] #[label("expected `where`, `{\"{\"}`, `(`, or `;` after struct name")] span: Span, - token: Token, + token: Cow<'static, str>, }, #[diag("expected `where`, `{\"{\"}`, `(`, or `;` after struct name, found metavar")] MetaVar { @@ -2573,13 +2572,14 @@ pub(crate) enum UnexpectedTokenAfterStructName { #[primary_span] #[label("expected `where`, `{\"{\"}`, `(`, or `;` after struct name")] span: Span, - token: Token, + token: Cow<'static, str>, }, } impl UnexpectedTokenAfterStructName { - pub(crate) fn new(span: Span, token: Token) -> Self { - match TokenDescription::from_token(&token) { + pub(crate) fn new(span: Span, orig_token: Token) -> Self { + let token = pprust::token_to_string(&orig_token); + match TokenDescription::from_token(&orig_token) { Some(TokenDescription::ReservedIdentifier) => Self::ReservedIdentifier { span, token }, Some(TokenDescription::Keyword) => Self::Keyword { span, token }, Some(TokenDescription::ReservedKeyword) => Self::ReservedKeyword { span, token }, @@ -2632,13 +2632,13 @@ pub(crate) enum UnexpectedNonterminal { Ident { #[primary_span] span: Span, - token: Token, + token: Cow<'static, str>, }, #[diag("expected a lifetime, found `{$token}`")] Lifetime { #[primary_span] span: Span, - token: Token, + token: Cow<'static, str>, }, } @@ -3214,7 +3214,7 @@ pub(crate) struct UnexpectedVertVertInPattern { pub(crate) struct TrailingVertSuggestion { #[primary_span] pub span: Span, - pub token: Token, + pub token: Cow<'static, str>, } #[derive(Diagnostic)] @@ -3226,7 +3226,7 @@ pub(crate) struct TrailingVertNotAllowed { pub suggestion: TrailingVertSuggestion, #[label("while parsing this or-pattern starting here")] pub start: Option, - pub token: Token, + pub token: Cow<'static, str>, #[note("alternatives in or-patterns are separated with `|`, not `||`")] pub note_double_vert: bool, } @@ -3443,8 +3443,10 @@ pub(crate) struct UnexpectedExpressionInPattern { pub span: Span, /// Was a `RangePatternBound` expected? pub is_bound: bool, - /// The unexpected expr's precedence (used in match arm guard suggestions). - pub expr_precedence: ExprPrecedence, + /// The unexpected expr's precedence. Not used directly in the error message, but needed for + /// the stashing of this error to work correctly. We store a `u32` rather than an + /// `ExprPrecedence` to avoid having to impl `IntoDiagArg` for `ExprPrecedence`. + pub expr_precedence: u32, } #[derive(Subdiagnostic)] diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index c18e8c631fecc..33489e06550f4 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -18,6 +18,7 @@ use rustc_ast::{ FnRetTy, Guard, Label, MacCall, MetaItemLit, MgcaDisambiguation, Movability, Param, RangeLimits, StmtKind, Ty, TyKind, UnOp, UnsafeBinderCastKind, YieldKind, }; +use rustc_ast_pretty::pprust; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_errors::{Applicability, Diag, PResult, StashKey, Subdiagnostic}; use rustc_literal_escaper::unescape_char; @@ -352,7 +353,7 @@ impl<'a> Parser<'a> { fn error_found_expr_would_be_stmt(&self, lhs: &Expr) { self.dcx().emit_err(errors::FoundExprWouldBeStmt { span: self.token.span, - token: self.token, + token: pprust::token_to_string(&self.token), suggestion: ExprParenthesesNeeded::surrounding(lhs.span), }); } @@ -729,7 +730,7 @@ impl<'a> Parser<'a> { token::Lt => { self.dcx().emit_err(errors::ComparisonInterpretedAsGeneric { comparison: self.token.span, - r#type: path, + r#type: pprust::path_to_string(&path), args: args_span, suggestion: errors::ComparisonInterpretedAsGenericSugg { left: expr.span.shrink_to_lo(), @@ -739,7 +740,7 @@ impl<'a> Parser<'a> { } token::Shl => self.dcx().emit_err(errors::ShiftInterpretedAsGeneric { shift: self.token.span, - r#type: path, + r#type: pprust::path_to_string(&path), args: args_span, suggestion: errors::ShiftInterpretedAsGenericSugg { left: expr.span.shrink_to_lo(), @@ -1304,16 +1305,17 @@ impl<'a> Parser<'a> { self.span_to_snippet(close_paren).is_ok_and(|snippet| snippet == ")") { err.cancel(); + let type_str = pprust::path_to_string(&path); self.dcx() .create_err(errors::ParenthesesWithStructFields { span, braces_for_struct: errors::BracesForStructLiteral { first: open_paren, second: close_paren, - r#type: path.clone(), + r#type: type_str.clone(), }, no_fields_for_fn: errors::NoFieldsForFnCall { - r#type: path, + r#type: type_str, fields: fields .into_iter() .map(|field| field.span.until(field.expr.span)) @@ -4040,7 +4042,7 @@ impl<'a> Parser<'a> { return Err(this.dcx().create_err(errors::ExpectedStructField { span: this.look_ahead(1, |t| t.span), ident_span: this.token.span, - token: this.look_ahead(1, |t| *t), + token: pprust::token_to_string(&this.look_ahead(1, |t| *t)), })); } let (ident, expr) = if is_shorthand { diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index ab3683f598208..95320609a370c 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -192,9 +192,11 @@ impl<'a> Parser<'a> { // At this point, we have failed to parse an item. if !matches!(vis.kind, VisibilityKind::Inherited) { - let mut err = this - .dcx() - .create_err(errors::VisibilityNotFollowedByItem { span: vis.span, vis }); + let vis_str = pprust::vis_to_string(&vis).trim_end().to_string(); + let mut err = this.dcx().create_err(errors::VisibilityNotFollowedByItem { + span: vis.span, + vis: vis_str, + }); if let Some((ident, _)) = this.token.ident() && !ident.is_used_keyword() && let Some((similar_kw, is_incorrect_case)) = ident diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index ddf1b10e5235d..f12879143b107 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -1,6 +1,7 @@ use rustc_ast::token::NtExprKind::*; use rustc_ast::token::NtPatKind::*; use rustc_ast::token::{self, InvisibleOrigin, MetaVarKind, NonterminalKind, Token}; +use rustc_ast_pretty::pprust; use rustc_errors::PResult; use rustc_span::{Ident, kw}; @@ -173,7 +174,7 @@ impl<'a> Parser<'a> { } else { Err(self.dcx().create_err(UnexpectedNonterminal::Ident { span: self.token.span, - token: self.token, + token: pprust::token_to_string(&self.token), })) } } @@ -195,7 +196,7 @@ impl<'a> Parser<'a> { } else { Err(self.dcx().create_err(UnexpectedNonterminal::Lifetime { span: self.token.span, - token: self.token, + token: pprust::token_to_string(&self.token), })) } } diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index bdcbb1eb42a88..bc5fa639be8a2 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -367,14 +367,15 @@ impl<'a> Parser<'a> { match (is_end_ahead, &self.token.kind) { (true, token::Or | token::OrOr) => { // A `|` or possibly `||` token shouldn't be here. Ban it. + let token = pprust::token_to_string(&self.token); self.dcx().emit_err(TrailingVertNotAllowed { span: self.token.span, start: lo, suggestion: TrailingVertSuggestion { span: self.prev_token.span.shrink_to_hi().with_hi(self.token.span.hi()), - token: self.token, + token: token.clone(), }, - token: self.token, + token, note_double_vert: self.token.kind == token::OrOr, }); self.bump(); @@ -502,7 +503,7 @@ impl<'a> Parser<'a> { .create_err(UnexpectedExpressionInPattern { span, is_bound, - expr_precedence: expr.precedence(), + expr_precedence: expr.precedence() as u32, }) .stash(span, StashKey::ExprInPat) .unwrap(), diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index 8a56d716a3003..4382b60b0f6bc 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -558,3 +558,187 @@ impl LocalModDefId { self.0.is_top_level_module() } } + +#[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable)] +pub struct OwnerId { + pub def_id: LocalDefId, +} + +impl fmt::Debug for OwnerId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // Example: DefId(0:1 ~ aa[7697]::{use#0}) + fmt::Debug::fmt(&self.def_id, f) + } +} + +impl From for HirId { + fn from(owner: OwnerId) -> HirId { + HirId { owner, local_id: ItemLocalId::ZERO } + } +} + +impl From for DefId { + fn from(value: OwnerId) -> Self { + value.to_def_id() + } +} + +impl OwnerId { + #[inline] + pub fn to_def_id(self) -> DefId { + self.def_id.to_def_id() + } +} + +impl rustc_index::Idx for OwnerId { + #[inline] + fn new(idx: usize) -> Self { + OwnerId { def_id: LocalDefId { local_def_index: DefIndex::from_usize(idx) } } + } + + #[inline] + fn index(self) -> usize { + self.def_id.local_def_index.as_usize() + } +} + +impl HashStable for OwnerId { + #[inline] + fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) { + self.to_stable_hash_key(hcx).hash_stable(hcx, hasher); + } +} + +impl ToStableHashKey for OwnerId { + type KeyType = DefPathHash; + + #[inline] + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> DefPathHash { + hcx.def_path_hash(self.to_def_id()) + } +} + +/// Uniquely identifies a node in the HIR of the current crate. It is +/// composed of the `owner`, which is the `LocalDefId` of the directly enclosing +/// `hir::Item`, `hir::TraitItem`, or `hir::ImplItem` (i.e., the closest "item-like"), +/// and the `local_id` which is unique within the given owner. +/// +/// This two-level structure makes for more stable values: One can move an item +/// around within the source code, or add or remove stuff before it, without +/// the `local_id` part of the `HirId` changing, which is a very useful property in +/// incremental compilation where we have to persist things through changes to +/// the code base. +#[derive(Copy, Clone, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)] +#[rustc_pass_by_value] +pub struct HirId { + pub owner: OwnerId, + pub local_id: ItemLocalId, +} + +// To ensure correctness of incremental compilation, +// `HirId` must not implement `Ord` or `PartialOrd`. +// See https://github.com/rust-lang/rust/issues/90317. +impl !Ord for HirId {} +impl !PartialOrd for HirId {} + +impl fmt::Debug for HirId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // Example: HirId(DefId(0:1 ~ aa[7697]::{use#0}).10) + // Don't use debug_tuple to always keep this on one line. + write!(f, "HirId({:?}.{:?})", self.owner, self.local_id) + } +} + +impl HirId { + /// Signal local id which should never be used. + pub const INVALID: HirId = + HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::INVALID }; + + #[inline] + pub fn expect_owner(self) -> OwnerId { + assert_eq!(self.local_id.index(), 0); + self.owner + } + + #[inline] + pub fn as_owner(self) -> Option { + if self.local_id.index() == 0 { Some(self.owner) } else { None } + } + + #[inline] + pub fn is_owner(self) -> bool { + self.local_id.index() == 0 + } + + #[inline] + pub fn make_owner(owner: LocalDefId) -> Self { + Self { owner: OwnerId { def_id: owner }, local_id: ItemLocalId::ZERO } + } +} + +impl fmt::Display for HirId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{self:?}") + } +} + +rustc_data_structures::define_stable_id_collections!(HirIdMap, HirIdSet, HirIdMapEntry, HirId); +rustc_data_structures::define_id_collections!( + ItemLocalMap, + ItemLocalSet, + ItemLocalMapEntry, + ItemLocalId +); + +rustc_index::newtype_index! { + /// An `ItemLocalId` uniquely identifies something within a given "item-like"; + /// that is, within a `hir::Item`, `hir::TraitItem`, or `hir::ImplItem`. There is no + /// guarantee that the numerical value of a given `ItemLocalId` corresponds to + /// the node's position within the owning item in any way, but there is a + /// guarantee that the `ItemLocalId`s within an owner occupy a dense range of + /// integers starting at zero, so a mapping that maps all or most nodes within + /// an "item-like" to something else can be implemented by a `Vec` instead of a + /// tree or hash map. + #[stable_hash_generic] + #[encodable] + #[orderable] + pub struct ItemLocalId {} +} + +impl ItemLocalId { + /// Signal local id which should never be used. + pub const INVALID: ItemLocalId = ItemLocalId::MAX; +} + +impl StableOrd for ItemLocalId { + const CAN_USE_UNSTABLE_SORT: bool = true; + + // `Ord` is implemented as just comparing the ItemLocalId's numerical + // values and these are not changed by (de-)serialization. + const THIS_IMPLEMENTATION_HAS_BEEN_TRIPLE_CHECKED: () = (); +} + +/// The `HirId` corresponding to `CRATE_NODE_ID` and `CRATE_DEF_ID`. +pub const CRATE_HIR_ID: HirId = + HirId { owner: OwnerId { def_id: CRATE_DEF_ID }, local_id: ItemLocalId::ZERO }; + +pub const CRATE_OWNER_ID: OwnerId = OwnerId { def_id: CRATE_DEF_ID }; + +impl ToStableHashKey for HirId { + type KeyType = (DefPathHash, ItemLocalId); + + #[inline] + fn to_stable_hash_key(&self, hcx: &mut Hcx) -> (DefPathHash, ItemLocalId) { + let def_path_hash = self.owner.def_id.to_stable_hash_key(hcx); + (def_path_hash, self.local_id) + } +} + +impl ToStableHashKey for ItemLocalId { + type KeyType = ItemLocalId; + + #[inline] + fn to_stable_hash_key(&self, _: &mut Hcx) -> ItemLocalId { + *self + } +} diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 97de708290fb4..02f4c5a4aa562 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -55,6 +55,7 @@ pub use hygiene::{ pub mod def_id; use def_id::{CrateNum, DefId, DefIndex, DefPathHash, LOCAL_CRATE, LocalDefId, StableCrateId}; pub mod edit_distance; +pub mod node_id; mod span_encoding; pub use span_encoding::{DUMMY_SP, Span}; diff --git a/compiler/rustc_ast/src/node_id.rs b/compiler/rustc_span/src/node_id.rs similarity index 100% rename from compiler/rustc_ast/src/node_id.rs rename to compiler/rustc_span/src/node_id.rs diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_bench.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_bench.snap index 294623f073864..1b240bbac1b7b 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_bench.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_bench.snap @@ -49,7 +49,6 @@ expression: bench - Set({bench::compiler/rustc_hashes}) - Set({bench::compiler/rustc_hir}) - Set({bench::compiler/rustc_hir_analysis}) - - Set({bench::compiler/rustc_hir_id}) - Set({bench::compiler/rustc_hir_pretty}) - Set({bench::compiler/rustc_hir_typeck}) - Set({bench::compiler/rustc_incremental}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_build_compiler.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_build_compiler.snap index d5da908c8a443..6315bf390b5cf 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_build_compiler.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_build_compiler.snap @@ -31,7 +31,6 @@ expression: build compiler - Set({build::compiler/rustc_hashes}) - Set({build::compiler/rustc_hir}) - Set({build::compiler/rustc_hir_analysis}) - - Set({build::compiler/rustc_hir_id}) - Set({build::compiler/rustc_hir_pretty}) - Set({build::compiler/rustc_hir_typeck}) - Set({build::compiler/rustc_incremental}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check.snap index 242a2272b4d16..bd1d7ecb832c9 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check.snap @@ -33,7 +33,6 @@ expression: check - Set({check::compiler/rustc_hashes}) - Set({check::compiler/rustc_hir}) - Set({check::compiler/rustc_hir_analysis}) - - Set({check::compiler/rustc_hir_id}) - Set({check::compiler/rustc_hir_pretty}) - Set({check::compiler/rustc_hir_typeck}) - Set({check::compiler/rustc_incremental}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiler.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiler.snap index dab86b792127f..b024a32162bd6 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiler.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiler.snap @@ -33,7 +33,6 @@ expression: check compiler - Set({check::compiler/rustc_hashes}) - Set({check::compiler/rustc_hir}) - Set({check::compiler/rustc_hir_analysis}) - - Set({check::compiler/rustc_hir_id}) - Set({check::compiler/rustc_hir_pretty}) - Set({check::compiler/rustc_hir_typeck}) - Set({check::compiler/rustc_incremental}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiletest_include_default_paths.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiletest_include_default_paths.snap index e43d5380a398d..9e9e4e79e205b 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiletest_include_default_paths.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_check_compiletest_include_default_paths.snap @@ -33,7 +33,6 @@ expression: check compiletest --include-default-paths - Set({check::compiler/rustc_hashes}) - Set({check::compiler/rustc_hir}) - Set({check::compiler/rustc_hir_analysis}) - - Set({check::compiler/rustc_hir_id}) - Set({check::compiler/rustc_hir_pretty}) - Set({check::compiler/rustc_hir_typeck}) - Set({check::compiler/rustc_incremental}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_clippy.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_clippy.snap index 827f2f8b60acb..afbf236971ad4 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_clippy.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_clippy.snap @@ -48,7 +48,6 @@ expression: clippy - Set({clippy::compiler/rustc_hashes}) - Set({clippy::compiler/rustc_hir}) - Set({clippy::compiler/rustc_hir_analysis}) - - Set({clippy::compiler/rustc_hir_id}) - Set({clippy::compiler/rustc_hir_pretty}) - Set({clippy::compiler/rustc_hir_typeck}) - Set({clippy::compiler/rustc_incremental}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_fix.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_fix.snap index d380cb416acf8..4f26410b976b5 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_fix.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_fix.snap @@ -33,7 +33,6 @@ expression: fix - Set({fix::compiler/rustc_hashes}) - Set({fix::compiler/rustc_hir}) - Set({fix::compiler/rustc_hir_analysis}) - - Set({fix::compiler/rustc_hir_id}) - Set({fix::compiler/rustc_hir_pretty}) - Set({fix::compiler/rustc_hir_typeck}) - Set({fix::compiler/rustc_incremental}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test.snap index ac2f315d39d96..9c20ddc1cb2a3 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test.snap @@ -99,7 +99,6 @@ expression: test - Set({test::compiler/rustc_hashes}) - Set({test::compiler/rustc_hir}) - Set({test::compiler/rustc_hir_analysis}) - - Set({test::compiler/rustc_hir_id}) - Set({test::compiler/rustc_hir_pretty}) - Set({test::compiler/rustc_hir_typeck}) - Set({test::compiler/rustc_incremental}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage.snap index 09adbb0041ae6..23e83275efb05 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_coverage.snap @@ -98,7 +98,6 @@ expression: test --skip=coverage - Set({test::compiler/rustc_hashes}) - Set({test::compiler/rustc_hir}) - Set({test::compiler/rustc_hir_analysis}) - - Set({test::compiler/rustc_hir_id}) - Set({test::compiler/rustc_hir_pretty}) - Set({test::compiler/rustc_hir_typeck}) - Set({test::compiler/rustc_incremental}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests.snap index b5fccfcb966bb..00ceb770fe631 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests.snap @@ -62,7 +62,6 @@ expression: test --skip=tests - Set({test::compiler/rustc_hashes}) - Set({test::compiler/rustc_hir}) - Set({test::compiler/rustc_hir_analysis}) - - Set({test::compiler/rustc_hir_id}) - Set({test::compiler/rustc_hir_pretty}) - Set({test::compiler/rustc_hir_typeck}) - Set({test::compiler/rustc_incremental}) diff --git a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests_etc.snap b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests_etc.snap index 9ad8914f58e30..74e67c17e0805 100644 --- a/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests_etc.snap +++ b/src/bootstrap/src/core/builder/cli_paths/snapshots/x_test_skip_tests_etc.snap @@ -42,7 +42,6 @@ expression: test --skip=tests --skip=coverage-map --skip=coverage-run --skip=lib - Set({test::compiler/rustc_hashes}) - Set({test::compiler/rustc_hir}) - Set({test::compiler/rustc_hir_analysis}) - - Set({test::compiler/rustc_hir_id}) - Set({test::compiler/rustc_hir_pretty}) - Set({test::compiler/rustc_hir_typeck}) - Set({test::compiler/rustc_incremental}) diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index f34b284dbb9cc..aca8b05767031 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -1816,7 +1816,7 @@ mod snapshot { insta::assert_snapshot!( ctx.config("check") .path("compiler") - .render_steps(), @"[check] rustc 0 -> rustc 1 (73 crates)"); + .render_steps(), @"[check] rustc 0 -> rustc 1 (72 crates)"); } #[test] @@ -1842,7 +1842,7 @@ mod snapshot { ctx.config("check") .path("compiler") .stage(1) - .render_steps(), @"[check] rustc 0 -> rustc 1 (73 crates)"); + .render_steps(), @"[check] rustc 0 -> rustc 1 (72 crates)"); } #[test] @@ -1856,7 +1856,7 @@ mod snapshot { [build] llvm [build] rustc 0 -> rustc 1 [build] rustc 1 -> std 1 - [check] rustc 1 -> rustc 2 (73 crates) + [check] rustc 1 -> rustc 2 (72 crates) "); } @@ -1872,7 +1872,7 @@ mod snapshot { [build] rustc 0 -> rustc 1 [build] rustc 1 -> std 1 [check] rustc 1 -> std 1 - [check] rustc 1 -> rustc 2 (73 crates) + [check] rustc 1 -> rustc 2 (72 crates) [check] rustc 1 -> rustc 2 [check] rustc 1 -> Rustdoc 2 [check] rustc 1 -> rustc_codegen_cranelift 2 @@ -1968,7 +1968,7 @@ mod snapshot { ctx.config("check") .paths(&["library", "compiler"]) .args(&args) - .render_steps(), @"[check] rustc 0 -> rustc 1 (73 crates)"); + .render_steps(), @"[check] rustc 0 -> rustc 1 (72 crates)"); } #[test] diff --git a/src/tools/clippy/clippy_lints/src/cargo/mod.rs b/src/tools/clippy/clippy_lints/src/cargo/mod.rs index 0aa6e4c3e8e27..93b8bb32cc989 100644 --- a/src/tools/clippy/clippy_lints/src/cargo/mod.rs +++ b/src/tools/clippy/clippy_lints/src/cargo/mod.rs @@ -9,7 +9,7 @@ use clippy_config::Conf; use clippy_utils::diagnostics::span_lint; use clippy_utils::is_lint_allowed; use rustc_data_structures::fx::FxHashSet; -use rustc_hir::hir_id::CRATE_HIR_ID; +use rustc_hir::def_id::CRATE_HIR_ID; use rustc_lint::{LateContext, LateLintPass, Lint}; use rustc_session::impl_lint_pass; use rustc_span::DUMMY_SP; diff --git a/src/tools/clippy/clippy_lints/src/collapsible_if.rs b/src/tools/clippy/clippy_lints/src/collapsible_if.rs index 52e602bbac577..8a12d1093b4b4 100644 --- a/src/tools/clippy/clippy_lints/src/collapsible_if.rs +++ b/src/tools/clippy/clippy_lints/src/collapsible_if.rs @@ -238,7 +238,7 @@ impl CollapsibleIf { }, [attr] - if matches!(Level::from_attr(attr), Some((Level::Expect, _))) + if matches!(Level::from_attr(attr.name(), || attr.id()), Some((Level::Expect, _))) && let Some(metas) = attr.meta_item_list() && let Some(MetaItemInner::MetaItem(meta_item)) = metas.first() && let [tool, lint_name] = meta_item.path.segments.as_slice() diff --git a/src/tools/clippy/clippy_lints/src/entry.rs b/src/tools/clippy/clippy_lints/src/entry.rs index f700cb6773439..1dcdf12d3ad70 100644 --- a/src/tools/clippy/clippy_lints/src/entry.rs +++ b/src/tools/clippy/clippy_lints/src/entry.rs @@ -8,8 +8,7 @@ use clippy_utils::{ }; use core::fmt::{self, Write}; use rustc_errors::Applicability; -use rustc_hir::def_id::DefId; -use rustc_hir::hir_id::HirIdSet; +use rustc_hir::def_id::{DefId, HirIdSet}; use rustc_hir::intravisit::{Visitor, walk_body, walk_expr}; use rustc_hir::{Block, Expr, ExprKind, HirId, Pat, Stmt, StmtKind, UnOp}; use rustc_lint::{LateContext, LateLintPass}; diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs b/src/tools/clippy/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs index cdef98be14af3..e9b7f577a7a12 100644 --- a/src/tools/clippy/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs +++ b/src/tools/clippy/clippy_lints/src/methods/iter_on_single_or_empty_collections.rs @@ -6,7 +6,7 @@ use clippy_utils::ty::{ExprFnSig, expr_sig, ty_sig}; use clippy_utils::{as_some_expr, get_expr_use_or_unification_node, is_none_expr, std_or_core, sym}; use rustc_errors::Applicability; -use rustc_hir::hir_id::HirId; +use rustc_hir::def_id::HirId; use rustc_hir::{Expr, ExprKind, Node}; use rustc_lint::LateContext; use rustc_middle::ty::Binder; diff --git a/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs b/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs index 6c45964da0dab..b092fc431d774 100644 --- a/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs +++ b/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs @@ -4,8 +4,7 @@ use clippy_utils::res::{MaybeQPath, MaybeResPath}; use core::cell::Cell; use rustc_data_structures::fx::FxHashMap; use rustc_errors::Applicability; -use rustc_hir::def_id::DefId; -use rustc_hir::hir_id::HirIdMap; +use rustc_hir::def_id::{DefId, HirIdMap}; use rustc_hir::{ Body, Expr, ExprKind, HirId, ImplItem, ImplItemImplKind, ImplItemKind, Node, PatKind, TraitItem, TraitItemKind, }; diff --git a/src/tools/clippy/clippy_lints/src/ptr/ptr_arg.rs b/src/tools/clippy/clippy_lints/src/ptr/ptr_arg.rs index 4bfff64b1bd48..dec7a7afd2cb9 100644 --- a/src/tools/clippy/clippy_lints/src/ptr/ptr_arg.rs +++ b/src/tools/clippy/clippy_lints/src/ptr/ptr_arg.rs @@ -6,7 +6,7 @@ use clippy_utils::{VEC_METHODS_SHADOWING_SLICE_METHODS, get_expr_use_or_unificat use hir::LifetimeKind; use rustc_abi::ExternAbi; use rustc_errors::Applicability; -use rustc_hir::hir_id::{HirId, HirIdMap}; +use rustc_hir::def_id::{HirId, HirIdMap}; use rustc_hir::intravisit::{Visitor, walk_expr}; use rustc_hir::{ self as hir, AnonConst, BindingMode, Body, Expr, ExprKind, FnSig, GenericArg, Lifetime, Mutability, Node, OwnerId, diff --git a/src/tools/clippy/clippy_lints/src/redundant_type_annotations.rs b/src/tools/clippy/clippy_lints/src/redundant_type_annotations.rs index 3ffb00e2ee9d1..a7cbb52726b04 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_type_annotations.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_type_annotations.rs @@ -58,7 +58,7 @@ fn is_same_type<'tcx>(cx: &LateContext<'tcx>, ty_resolved_path: hir::def::Res, f false } -fn func_hir_id_to_func_ty<'tcx>(cx: &LateContext<'tcx>, hir_id: hir::hir_id::HirId) -> Option> { +fn func_hir_id_to_func_ty<'tcx>(cx: &LateContext<'tcx>, hir_id: hir::def_id::HirId) -> Option> { if let Some((defkind, func_defid)) = cx.typeck_results().type_dependent_def(hir_id) && defkind == DefKind::AssocFn && let Some(init_ty) = cx.tcx.type_of(func_defid).no_bound_vars() diff --git a/src/tools/clippy/clippy_lints/src/returns/needless_return.rs b/src/tools/clippy/clippy_lints/src/returns/needless_return.rs index 04e4f379e37c1..3bf7c00182721 100644 --- a/src/tools/clippy/clippy_lints/src/returns/needless_return.rs +++ b/src/tools/clippy/clippy_lints/src/returns/needless_return.rs @@ -181,7 +181,7 @@ fn check_final_expr<'tcx>( match cx.tcx.hir_attrs(expr.hir_id) { [] => {}, [attr] => { - if matches!(Level::from_attr(attr), Some((Level::Expect, _))) + if matches!(Level::from_attr(attr.name(), || attr.id()), Some((Level::Expect, _))) && let metas = attr.meta_item_list() && let Some(lst) = metas && let [MetaItemInner::MetaItem(meta_item), ..] = lst.as_slice() diff --git a/src/tools/clippy/clippy_lints/src/shadow.rs b/src/tools/clippy/clippy_lints/src/shadow.rs index 4ddf82773d872..dc7dd7ae4055b 100644 --- a/src/tools/clippy/clippy_lints/src/shadow.rs +++ b/src/tools/clippy/clippy_lints/src/shadow.rs @@ -6,8 +6,7 @@ use clippy_utils::source::snippet; use clippy_utils::visitors::{Descend, Visitable, for_each_expr}; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def::Res; -use rustc_hir::def_id::LocalDefId; -use rustc_hir::hir_id::ItemLocalId; +use rustc_hir::def_id::{LocalDefId, ItemLocalId}; use rustc_hir::{ Block, Body, BodyOwnerKind, Expr, ExprKind, HirId, LetExpr, LocalSource, Node, Pat, PatKind, QPath, UnOp, }; diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index a8ff9b4cf6fb5..e092b0d258083 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -89,9 +89,8 @@ use rustc_data_structures::unhash::UnindexMap; use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk}; use rustc_hir::attrs::CfgEntry; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::def_id::{DefId, LocalDefId, LocalModDefId}; +use rustc_hir::def_id::{DefId, HirIdMap, HirIdSet, LocalDefId, LocalModDefId}; use rustc_hir::definitions::{DefPath, DefPathData}; -use rustc_hir::hir_id::{HirIdMap, HirIdSet}; use rustc_hir::intravisit::{Visitor, walk_expr}; use rustc_hir::{ self as hir, Arm, BindingMode, Block, BlockCheckMode, Body, ByRef, Closure, ConstArgKind, CoroutineDesugaring,