diff --git a/Cargo.lock b/Cargo.lock index 53cff99b4a199..6b5491fb754de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3853,8 +3853,6 @@ dependencies = [ "icu_list", "icu_locale", "intl-memoizer", - "rustc_ast", - "rustc_ast_pretty", "rustc_baked_icu_data", "rustc_data_structures", "rustc_macros", @@ -4186,7 +4184,6 @@ dependencies = [ name = "rustc_lint_defs" version = "0.0.0" dependencies = [ - "rustc_ast", "rustc_data_structures", "rustc_error_messages", "rustc_hir_id", diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 770189d8c7999..cc1bc5d5344a5 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_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 5831636a81b2c..3d51770f6ba79 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -510,6 +510,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) { gate_all!(try_blocks_heterogeneous, "`try bikeshed` expression is experimental"); gate_all!(unsafe_binders, "unsafe binder types are experimental"); gate_all!(unsafe_fields, "`unsafe` fields are experimental"); + gate_all!(view_types, "view types are experimental"); gate_all!(where_clause_attrs, "attributes in `where` clause are unstable"); gate_all!(yeet_expr, "`do yeet` expression is experimental"); // tidy-alphabetical-end 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 ad641beb87d98..c64d6871269a6 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 bdb8316f3965d..a32592b45e5ea 100644 --- a/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs +++ b/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs @@ -828,7 +828,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 c3afcd6f40333..280cbb590781d 100644 --- a/compiler/rustc_codegen_ssa/src/errors.rs +++ b/compiler/rustc_codegen_ssa/src/errors.rs @@ -13,8 +13,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; @@ -748,7 +748,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_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs index d74b1787d83c8..a9493b8654805 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 fe363e7d4a511..d708caaf01318 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_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index 3bb4bc863def2..9712879fce6f7 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -723,6 +723,8 @@ declare_features! ( (internal, unsized_fn_params, "1.49.0", Some(48055)), /// Allows using the `#[used(linker)]` (or `#[used(compiler)]`) attribute. (unstable, used_with_arg, "1.60.0", Some(93798)), + /// Allows view types. + (unstable, view_types, "CURRENT_RUSTC_VERSION", Some(155938)), /// Target features on wasm. (unstable, wasm_target_feature, "1.30.0", Some(150260)), /// Allows use of attributes in `where` clauses. 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..2ca62f7fa8cdc 100644 --- a/compiler/rustc_lint_defs/Cargo.toml +++ b/compiler/rustc_lint_defs/Cargo.toml @@ -5,7 +5,6 @@ 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" } diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 94f03125ae8eb..23621f2243917 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -1,8 +1,6 @@ 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, @@ -12,7 +10,7 @@ use rustc_hir_id::{HirId, ItemLocalId}; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; use rustc_span::def_id::DefPathHash; pub use rustc_span::edition::Edition; -use rustc_span::{HashStableContext, Ident, Symbol, sym}; +use rustc_span::{AttrId, HashStableContext, Ident, Symbol, sym}; use serde::{Deserialize, Serialize}; pub use self::Level::*; @@ -248,8 +246,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_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 1829592d6d16e..4043b9bca61c5 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, } @@ -1511,7 +1510,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 { @@ -1577,7 +1576,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 { @@ -2218,7 +2217,7 @@ pub(crate) struct VisibilityNotFollowedByItem { #[primary_span] #[label("the visibility")] pub span: Span, - pub vis: Visibility, + pub vis: String, } #[derive(Diagnostic)] @@ -2533,14 +2532,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}`" @@ -2549,7 +2548,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}`" @@ -2558,7 +2557,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 { @@ -2571,13 +2570,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 }, @@ -2630,13 +2630,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>, }, } @@ -3212,7 +3212,7 @@ pub(crate) struct UnexpectedVertVertInPattern { pub(crate) struct TrailingVertSuggestion { #[primary_span] pub span: Span, - pub token: Token, + pub token: Cow<'static, str>, } #[derive(Diagnostic)] @@ -3224,7 +3224,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, } @@ -3441,8 +3441,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 d55548dd72180..35c271cb70204 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)) @@ -4038,7 +4040,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 96bd59e2519e1..bd45bbb6a8582 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 37b76fc26a486..6ca7f89c76776 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}; @@ -176,7 +177,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), })) } } @@ -198,7 +199,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 f36127ec8f0a8..4e6d76fefd9c2 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_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 072975f445bf4..b5151cf20ab02 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -19,7 +19,7 @@ use crate::errors::{ NeedPlusAfterTraitObjectLifetime, NestedCVariadicType, ReturnTypesUseThinArrow, }; use crate::parser::item::FrontMatterParsingMode; -use crate::parser::{FnContext, FnParseMode}; +use crate::parser::{ExpTokenPair, FnContext, FnParseMode}; use crate::{exp, maybe_recover_from_interpolated_ty_qpath}; /// Signals whether parsing a type should allow `+`. @@ -768,6 +768,25 @@ impl<'a> Parser<'a> { self.bump_with((dyn_tok, dyn_tok_sp)); } let ty = self.parse_ty_no_plus()?; + if self.token == TokenKind::Dot && self.look_ahead(1, |t| t.kind == TokenKind::OpenBrace) { + // & [mut] . { } + // ^ + // we are here + let view_start_span = self.token.span; + self.bump(); + let fields = self + .parse_delim_comma_seq( + ExpTokenPair { tok: TokenKind::OpenBrace, token_type: TokenType::OpenBrace }, + ExpTokenPair { tok: TokenKind::CloseBrace, token_type: TokenType::CloseBrace }, + |p| p.parse_ident(), + )? + .0; + // FIXME(scrabsha): actually propagate field view in the AST. + let _ = fields; + let view_end_span = self.prev_token.span; + let span = view_start_span.to(view_end_span); + self.psess.gated_spans.gate(sym::view_types, span); + } Ok(match pinned { Pinnedness::Not => TyKind::Ref(opt_lifetime, MutTy { ty, mutbl }), Pinnedness::Pinned => TyKind::PinnedRef(opt_lifetime, MutTy { ty, mutbl }), diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 4cacdbd3408a5..3db4921d6ec0a 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -2232,6 +2232,7 @@ symbols! { verbatim, version, vfp2, + view_types, vis, visible_private_types, volatile, diff --git a/compiler/rustc_target/src/spec/targets/riscv32gc_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/targets/riscv32gc_unknown_linux_gnu.rs index c11edf7c618c2..b936a2ba2570d 100644 --- a/compiler/rustc_target/src/spec/targets/riscv32gc_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/targets/riscv32gc_unknown_linux_gnu.rs @@ -23,6 +23,7 @@ pub(crate) fn target() -> Target { llvm_abiname: LlvmAbi::Ilp32d, max_atomic_width: Some(32), supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]), + mcount: "\u{1}_mcount".into(), ..base::linux_gnu::opts() }, } diff --git a/compiler/rustc_target/src/spec/targets/riscv64a23_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/targets/riscv64a23_unknown_linux_gnu.rs index f9a7d307c74a3..74a8a88dff674 100644 --- a/compiler/rustc_target/src/spec/targets/riscv64a23_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/targets/riscv64a23_unknown_linux_gnu.rs @@ -23,6 +23,7 @@ pub(crate) fn target() -> Target { llvm_abiname: LlvmAbi::Lp64d, max_atomic_width: Some(64), supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]), + mcount: "\u{1}_mcount".into(), ..base::linux_gnu::opts() }, } diff --git a/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_linux_gnu.rs index 76c9ad65700c2..f362e694db4d2 100644 --- a/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/targets/riscv64gc_unknown_linux_gnu.rs @@ -23,6 +23,7 @@ pub(crate) fn target() -> Target { llvm_abiname: LlvmAbi::Lp64d, max_atomic_width: Some(64), supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]), + mcount: "\u{1}_mcount".into(), ..base::linux_gnu::opts() }, } 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/returns/needless_return.rs b/src/tools/clippy/clippy_lints/src/returns/needless_return.rs index 619a70cd8dd10..b9bacc2b73a17 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/tests/ui/issues/issue-31769.rs b/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.rs similarity index 70% rename from tests/ui/issues/issue-31769.rs rename to tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.rs index 354c1be9ed554..f295ecf302598 100644 --- a/tests/ui/issues/issue-31769.rs +++ b/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.rs @@ -1,3 +1,4 @@ +//! Regression test for fn main() { #[inline] struct Foo; //~ ERROR attribute cannot be used on #[repr(C)] fn foo() {} //~ ERROR attribute should be applied to a struct, enum, or union diff --git a/tests/ui/issues/issue-31769.stderr b/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.stderr similarity index 77% rename from tests/ui/issues/issue-31769.stderr rename to tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.stderr index 0f75e84f2a704..fc8e22f171c20 100644 --- a/tests/ui/issues/issue-31769.stderr +++ b/tests/ui/attributes/dont-allow-inline-and-repr-at-invalid-positions.stderr @@ -1,5 +1,5 @@ error: `#[inline]` attribute cannot be used on structs - --> $DIR/issue-31769.rs:2:5 + --> $DIR/dont-allow-inline-and-repr-at-invalid-positions.rs:3:5 | LL | #[inline] struct Foo; | ^^^^^^^^^ @@ -7,7 +7,7 @@ LL | #[inline] struct Foo; = help: `#[inline]` can only be applied to functions error[E0517]: attribute should be applied to a struct, enum, or union - --> $DIR/issue-31769.rs:3:12 + --> $DIR/dont-allow-inline-and-repr-at-invalid-positions.rs:4:12 | LL | #[repr(C)] fn foo() {} | ^ ----------- not a struct, enum, or union diff --git a/tests/ui/issues/issue-33202.rs b/tests/ui/attributes/repr-on-single-variant-Enum.rs similarity index 67% rename from tests/ui/issues/issue-33202.rs rename to tests/ui/attributes/repr-on-single-variant-Enum.rs index 3fef98606afab..ab45c76ef5aae 100644 --- a/tests/ui/issues/issue-33202.rs +++ b/tests/ui/attributes/repr-on-single-variant-Enum.rs @@ -1,3 +1,4 @@ +//! Regression test for //@ run-pass #[repr(C)] pub enum CPOption { diff --git a/tests/ui/feature-gates/feature-gate-view-types.rs b/tests/ui/feature-gates/feature-gate-view-types.rs new file mode 100644 index 0000000000000..eb0c26d61db4a --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-view-types.rs @@ -0,0 +1,17 @@ +struct Foo { + a: usize, + b: usize, +} + +fn bar(a: &mut Foo.{ a }, b: &mut Foo.{ b }) { + //~^ ERROR view types are experimental + //~| ERROR view types are experimental + a.a += 1; + b.b += 1; +} + +fn main() { + let mut foo = Foo { a: 0, b: 0 }; + bar(&mut foo, &mut foo); + //~^ ERROR cannot borrow `foo` as mutable more than once at a time +} diff --git a/tests/ui/feature-gates/feature-gate-view-types.stderr b/tests/ui/feature-gates/feature-gate-view-types.stderr new file mode 100644 index 0000000000000..661783ec59202 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-view-types.stderr @@ -0,0 +1,33 @@ +error[E0658]: view types are experimental + --> $DIR/feature-gate-view-types.rs:6:19 + | +LL | fn bar(a: &mut Foo.{ a }, b: &mut Foo.{ b }) { + | ^^^^^^ + | + = note: see issue #155938 for more information + = help: add `#![feature(view_types)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0658]: view types are experimental + --> $DIR/feature-gate-view-types.rs:6:38 + | +LL | fn bar(a: &mut Foo.{ a }, b: &mut Foo.{ b }) { + | ^^^^^^ + | + = note: see issue #155938 for more information + = help: add `#![feature(view_types)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error[E0499]: cannot borrow `foo` as mutable more than once at a time + --> $DIR/feature-gate-view-types.rs:15:19 + | +LL | bar(&mut foo, &mut foo); + | --- -------- ^^^^^^^^ second mutable borrow occurs here + | | | + | | first mutable borrow occurs here + | first borrow later used by call + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0499, E0658. +For more information about an error, try `rustc --explain E0499`. diff --git a/tests/ui/issues/issue-38763.rs b/tests/ui/foreign/foreign-fn-with-more-than-8-byte-arg-size.rs similarity index 72% rename from tests/ui/issues/issue-38763.rs rename to tests/ui/foreign/foreign-fn-with-more-than-8-byte-arg-size.rs index 87c758db1723c..4bd78a423cd2c 100644 --- a/tests/ui/issues/issue-38763.rs +++ b/tests/ui/foreign/foreign-fn-with-more-than-8-byte-arg-size.rs @@ -1,3 +1,4 @@ +//! Regression test for //@ run-pass //@ needs-threads diff --git a/tests/ui/issues/issue-19001.rs b/tests/ui/recursion/recursive-struct-with-raw-pointer-field.rs similarity index 73% rename from tests/ui/issues/issue-19001.rs rename to tests/ui/recursion/recursive-struct-with-raw-pointer-field.rs index 51aebf88c95fb..97fa08fab1d93 100644 --- a/tests/ui/issues/issue-19001.rs +++ b/tests/ui/recursion/recursive-struct-with-raw-pointer-field.rs @@ -1,3 +1,4 @@ +//! Regression test for //@ run-pass #![allow(dead_code)] // check that we handle recursive arrays correctly in `type_of`