diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 5efaea44b3b9d..476be94efd9e4 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -2,12 +2,11 @@ use std::any::Any; use std::default::Default; use std::iter; use std::path::Component::Prefix; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::rc::Rc; use std::sync::Arc; use rustc_ast::attr::MarkedAttrs; -use rustc_ast::token::MetaVarKind; use rustc_ast::tokenstream::TokenStream; use rustc_ast::visit::{AssocCtxt, Visitor}; use rustc_ast::{self as ast, AttrVec, Attribute, HasAttrs, Item, NodeId, PatKind, Safety}; @@ -22,14 +21,14 @@ use rustc_hir::limit::Limit; use rustc_hir::{Stability, find_attr}; use rustc_lint_defs::RegisteredTools; use rustc_parse::MACRO_ARGUMENTS; -use rustc_parse::parser::{AllowConstBlockItems, ForceCollect, Parser}; +use rustc_parse::parser::Parser; use rustc_session::Session; use rustc_session::parse::ParseSess; use rustc_span::def_id::{CrateNum, DefId, LocalDefId}; use rustc_span::edition::Edition; use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind}; use rustc_span::source_map::SourceMap; -use rustc_span::{DUMMY_SP, FileName, Ident, Span, Symbol, kw, sym}; +use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw}; use smallvec::{SmallVec, smallvec}; use thin_vec::ThinVec; @@ -1421,80 +1420,3 @@ pub fn resolve_path(sess: &Session, path: impl Into, span: Span) -> PRe } } } - -/// If this item looks like a specific enums from `rental`, emit a fatal error. -/// See #73345 and #83125 for more details. -/// FIXME(#73933): Remove this eventually. -fn pretty_printing_compatibility_hack(item: &Item, psess: &ParseSess) { - if let ast::ItemKind::Enum(ident, _, enum_def) = &item.kind - && ident.name == sym::ProceduralMasqueradeDummyType - && let [variant] = &*enum_def.variants - && variant.ident.name == sym::Input - && let FileName::Real(real) = psess.source_map().span_to_filename(ident.span) - && let Some(c) = real - .local_path() - .unwrap_or(Path::new("")) - .components() - .flat_map(|c| c.as_os_str().to_str()) - .find(|c| c.starts_with("rental") || c.starts_with("allsorts-rental")) - { - let crate_matches = if c.starts_with("allsorts-rental") { - true - } else { - let mut version = c.trim_start_matches("rental-").split('.'); - version.next() == Some("0") - && version.next() == Some("5") - && version.next().and_then(|c| c.parse::().ok()).is_some_and(|v| v < 6) - }; - - if crate_matches { - psess.dcx().emit_fatal(errors::ProcMacroBackCompat { - crate_name: "rental".to_string(), - fixed_version: "0.5.6".to_string(), - }); - } - } -} - -pub(crate) fn ann_pretty_printing_compatibility_hack(ann: &Annotatable, psess: &ParseSess) { - let item = match ann { - Annotatable::Item(item) => item, - Annotatable::Stmt(stmt) => match &stmt.kind { - ast::StmtKind::Item(item) => item, - _ => return, - }, - _ => return, - }; - pretty_printing_compatibility_hack(item, psess) -} - -pub(crate) fn stream_pretty_printing_compatibility_hack( - kind: MetaVarKind, - stream: &TokenStream, - psess: &ParseSess, -) { - let item = match kind { - MetaVarKind::Item => { - let mut parser = Parser::new(psess, stream.clone(), None); - // No need to collect tokens for this simple check. - parser - .parse_item(ForceCollect::No, AllowConstBlockItems::No) - .expect("failed to reparse item") - .expect("an actual item") - } - MetaVarKind::Stmt => { - let mut parser = Parser::new(psess, stream.clone(), None); - // No need to collect tokens for this simple check. - let stmt = parser - .parse_stmt(ForceCollect::No) - .expect("failed to reparse") - .expect("an actual stmt"); - match &stmt.kind { - ast::StmtKind::Item(item) => item.clone(), - _ => return, - } - } - _ => return, - }; - pretty_printing_compatibility_hack(&item, psess) -} diff --git a/compiler/rustc_expand/src/errors.rs b/compiler/rustc_expand/src/errors.rs index b6fcc13321ee7..c7b0e0d211a4a 100644 --- a/compiler/rustc_expand/src/errors.rs +++ b/compiler/rustc_expand/src/errors.rs @@ -446,18 +446,6 @@ pub(crate) struct GlobDelegationTraitlessQpath { pub span: Span, } -// This used to be the `proc_macro_back_compat` lint (#83125). It was later -// turned into a hard error. -#[derive(Diagnostic)] -#[diag("using an old version of `{$crate_name}`")] -#[note( - "older versions of the `{$crate_name}` crate no longer compile; please update to `{$crate_name}` v{$fixed_version}, or switch to one of the `{$crate_name}` alternatives" -)] -pub(crate) struct ProcMacroBackCompat { - pub crate_name: String, - pub fixed_version: String, -} - pub(crate) use metavar_exprs::*; mod metavar_exprs { use super::*; diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs index e678557008133..a892b21d76227 100644 --- a/compiler/rustc_expand/src/proc_macro.rs +++ b/compiler/rustc_expand/src/proc_macro.rs @@ -105,11 +105,6 @@ impl MultiItemModifier for DeriveProcMacro { // (e.g. `fn foo() { #[derive(Debug)] struct Bar; }`) let is_stmt = matches!(item, Annotatable::Stmt(..)); - // We used to have an alternative behaviour for crates that needed it. - // We had a lint for a long time, but now we just emit a hard error. - // Eventually we might remove the special case hard error check - // altogether. See #73345. - crate::base::ann_pretty_printing_compatibility_hack(&item, &ecx.sess.psess); let input = item.to_tokens(); let invoc_id = ecx.current_expansion.id; diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index 947b8a6e3e5ee..1da14ce0155d3 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -103,8 +103,8 @@ impl ToInternal for LitKind { } } -impl FromInternal<(TokenStream, &mut Rustc<'_, '_>)> for Vec> { - fn from_internal((stream, rustc): (TokenStream, &mut Rustc<'_, '_>)) -> Self { +impl FromInternal for Vec> { + fn from_internal(stream: TokenStream) -> Self { use rustc_ast::token::*; // Estimate the capacity as `stream.len()` rounded up to the next power @@ -115,22 +115,6 @@ impl FromInternal<(TokenStream, &mut Rustc<'_, '_>)> for Vec { - // We used to have an alternative behaviour for crates that - // needed it: a hack used to pass AST fragments to - // attribute and derive macros as a single nonterminal - // token instead of a token stream. Such token needs to be - // "unwrapped" and not represented as a delimited group. We - // had a lint for a long time, but now we just emit a hard - // error. Eventually we might remove the special case hard - // error check altogether. See #73345. - if let Delimiter::Invisible(InvisibleOrigin::MetaVar(kind)) = delim { - crate::base::stream_pretty_printing_compatibility_hack( - kind, - &stream, - rustc.psess(), - ); - } - // In `mk_delimited` we avoid nesting invisible delimited // of the same `MetaVarKind`. Here we do the same but // ignore the `MetaVarKind` because it is discarded when we @@ -687,7 +671,7 @@ impl server::Server for Rustc<'_, '_> { &mut self, stream: Self::TokenStream, ) -> Vec> { - FromInternal::from_internal((stream, self)) + FromInternal::from_internal(stream) } fn span_debug(&mut self, span: Self::Span) -> String { diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 5623b984b2420..1d38b41c25dfb 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -327,7 +327,6 @@ symbols! { Pointer, Poll, ProcMacro, - ProceduralMasqueradeDummyType, Range, RangeBounds, RangeCopy, diff --git a/tests/ui/proc-macro/pretty-print-hack-hide.rs b/tests/ui/proc-macro/pretty-print-hack-hide.rs deleted file mode 100644 index fd98f16a780ea..0000000000000 --- a/tests/ui/proc-macro/pretty-print-hack-hide.rs +++ /dev/null @@ -1,12 +0,0 @@ -//@ proc-macro: test-macros.rs -//@ compile-flags: -Z span-debug -//@ check-pass - -#![no_std] // Don't load unnecessary hygiene information from std -extern crate std; - -#[macro_use] extern crate test_macros; - -include!("pretty-print-hack/rental-0.5.6/src/lib.rs"); - -fn main() {} diff --git a/tests/ui/proc-macro/pretty-print-hack-hide.stdout b/tests/ui/proc-macro/pretty-print-hack-hide.stdout deleted file mode 100644 index ea796bb269768..0000000000000 --- a/tests/ui/proc-macro/pretty-print-hack-hide.stdout +++ /dev/null @@ -1,21 +0,0 @@ -PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input } -PRINT-DERIVE INPUT (DEBUG): TokenStream [ - Ident { - ident: "enum", - span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:4:1: 4:5 (#0), - }, - Ident { - ident: "ProceduralMasqueradeDummyType", - span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:4:6: 4:35 (#0), - }, - Group { - delimiter: Brace, - stream: TokenStream [ - Ident { - ident: "Input", - span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:13:5: 13:10 (#0), - }, - ], - span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:4:36: 14:2 (#0), - }, -] diff --git a/tests/ui/proc-macro/pretty-print-hack-show.local.stderr b/tests/ui/proc-macro/pretty-print-hack-show.local.stderr deleted file mode 100644 index 889cd0c90ebb2..0000000000000 --- a/tests/ui/proc-macro/pretty-print-hack-show.local.stderr +++ /dev/null @@ -1,6 +0,0 @@ -error: using an old version of `rental` - | - = note: older versions of the `rental` crate no longer compile; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives - -error: aborting due to 1 previous error - diff --git a/tests/ui/proc-macro/pretty-print-hack-show.remapped.stderr b/tests/ui/proc-macro/pretty-print-hack-show.remapped.stderr deleted file mode 100644 index 889cd0c90ebb2..0000000000000 --- a/tests/ui/proc-macro/pretty-print-hack-show.remapped.stderr +++ /dev/null @@ -1,6 +0,0 @@ -error: using an old version of `rental` - | - = note: older versions of the `rental` crate no longer compile; please update to `rental` v0.5.6, or switch to one of the `rental` alternatives - -error: aborting due to 1 previous error - diff --git a/tests/ui/proc-macro/pretty-print-hack-show.rs b/tests/ui/proc-macro/pretty-print-hack-show.rs deleted file mode 100644 index 08e26c8114276..0000000000000 --- a/tests/ui/proc-macro/pretty-print-hack-show.rs +++ /dev/null @@ -1,21 +0,0 @@ -//@ proc-macro: test-macros.rs -//@ compile-flags: -Z span-debug -//@ revisions: local remapped -//@ [remapped] remap-src-base - -#![no_std] // Don't load unnecessary hygiene information from std -extern crate std; - -#[macro_use] extern crate test_macros; - -mod first { - include!("pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs"); -} - -mod second { - include!("pretty-print-hack/rental-0.5.5/src/lib.rs"); -} - -fn main() {} - -//~? ERROR using an old version of `rental` diff --git a/tests/ui/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs b/tests/ui/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs deleted file mode 100644 index a27176a38e224..0000000000000 --- a/tests/ui/proc-macro/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs +++ /dev/null @@ -1,14 +0,0 @@ -//@ ignore-auxiliary (used by `../../../pretty-print-hack-show.rs`) - -#[derive(Print)] -enum ProceduralMasqueradeDummyType { -//~^ ERROR using -//~| WARN this was previously -//~| ERROR using -//~| WARN this was previously -//~| ERROR using -//~| WARN this was previously -//~| ERROR using -//~| WARN this was previously - Input -} diff --git a/tests/ui/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs b/tests/ui/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs deleted file mode 100644 index a27176a38e224..0000000000000 --- a/tests/ui/proc-macro/pretty-print-hack/rental-0.5.5/src/lib.rs +++ /dev/null @@ -1,14 +0,0 @@ -//@ ignore-auxiliary (used by `../../../pretty-print-hack-show.rs`) - -#[derive(Print)] -enum ProceduralMasqueradeDummyType { -//~^ ERROR using -//~| WARN this was previously -//~| ERROR using -//~| WARN this was previously -//~| ERROR using -//~| WARN this was previously -//~| ERROR using -//~| WARN this was previously - Input -} diff --git a/tests/ui/proc-macro/pretty-print-hack/rental-0.5.6/src/lib.rs b/tests/ui/proc-macro/pretty-print-hack/rental-0.5.6/src/lib.rs deleted file mode 100644 index 765ee4be656e3..0000000000000 --- a/tests/ui/proc-macro/pretty-print-hack/rental-0.5.6/src/lib.rs +++ /dev/null @@ -1,14 +0,0 @@ -//@ ignore-auxiliary (used by `../../../pretty-print-hack/hide.rs`) - -#[derive(Print)] -enum ProceduralMasqueradeDummyType { -//~^ ERROR using -//~| WARN this was previously -//~| ERROR using -//~| WARN this was previously -//~| ERROR using -//~| WARN this was previously -//~| ERROR using -//~| WARN this was previously - Input -}