Skip to content

Commit cf0c2c7

Browse files
committed
Convert proc_macro_back_compat lint to an unconditional error.
We still check for the `rental`/`allsorts-rental` crates. But now if they are detected we just emit a fatal error, instead of emitting a warning and providing alternative behaviour. The original "hack" implementing alternative behaviour was added in #73345. The lint was added in #83127. The tracking issue is #83125. The direct motivation for the change is that providing the alternative behaviour is interfering with #125174 and follow-on work.
1 parent 3607cee commit cf0c2c7

14 files changed

+54
-570
lines changed

compiler/rustc_expand/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ expand_not_a_meta_item =
124124
expand_only_one_word =
125125
must only be one word
126126
127+
expand_proc_macro_back_compat = using an old version of `{$crate_name}`
128+
.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
129+
127130
expand_proc_macro_derive_panicked =
128131
proc-macro derive panicked
129132
.help = message: {$message}

compiler/rustc_expand/src/base.rs

+16-25
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use rustc_data_structures::fx::FxIndexMap;
1414
use rustc_data_structures::sync::{self, Lrc};
1515
use rustc_errors::{DiagCtxt, ErrorGuaranteed, PResult};
1616
use rustc_feature::Features;
17-
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
18-
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiag, RegisteredTools};
17+
use rustc_lint_defs::{BufferedEarlyLint, RegisteredTools};
1918
use rustc_parse::{parser, MACRO_ARGUMENTS};
2019
use rustc_session::config::CollapseMacroDebuginfo;
2120
use rustc_session::{parse::ParseSess, Limit, Session};
@@ -1330,13 +1329,10 @@ pub fn parse_macro_name_and_helper_attrs(
13301329
Some((trait_ident.name, proc_attrs))
13311330
}
13321331

1333-
/// This nonterminal looks like some specific enums from
1334-
/// `proc-macro-hack` and `procedural-masquerade` crates.
1335-
/// We need to maintain some special pretty-printing behavior for them due to incorrect
1336-
/// asserts in old versions of those crates and their wide use in the ecosystem.
1337-
/// See issue #73345 for more details.
1332+
/// If this item looks like a specific enums from `rental`, emit a fatal error.
1333+
/// See #73345 and #83125 for more details.
13381334
/// FIXME(#73933): Remove this eventually.
1339-
fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) -> bool {
1335+
fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) {
13401336
let name = item.ident.name;
13411337
if name == sym::ProceduralMasqueradeDummyType
13421338
&& let ast::ItemKind::Enum(enum_def, _) = &item.kind
@@ -1360,41 +1356,36 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &Session) -> bool {
13601356
};
13611357

13621358
if crate_matches {
1363-
sess.psess.buffer_lint(
1364-
PROC_MACRO_BACK_COMPAT,
1365-
item.ident.span,
1366-
ast::CRATE_NODE_ID,
1367-
BuiltinLintDiag::ProcMacroBackCompat {
1368-
crate_name: "rental".to_string(),
1369-
fixed_version: "0.5.6".to_string(),
1370-
},
1371-
);
1372-
return true;
1359+
// FIXME: make this translatable
1360+
#[allow(rustc::untranslatable_diagnostic)]
1361+
sess.psess.dcx.emit_fatal(errors::ProcMacroBackCompat {
1362+
crate_name: "rental".to_string(),
1363+
fixed_version: "0.5.6".to_string(),
1364+
});
13731365
}
13741366
}
1375-
false
13761367
}
13771368

1378-
pub(crate) fn ann_pretty_printing_compatibility_hack(ann: &Annotatable, sess: &Session) -> bool {
1369+
pub(crate) fn ann_pretty_printing_compatibility_hack(ann: &Annotatable, sess: &Session) {
13791370
let item = match ann {
13801371
Annotatable::Item(item) => item,
13811372
Annotatable::Stmt(stmt) => match &stmt.kind {
13821373
ast::StmtKind::Item(item) => item,
1383-
_ => return false,
1374+
_ => return,
13841375
},
1385-
_ => return false,
1376+
_ => return,
13861377
};
13871378
pretty_printing_compatibility_hack(item, sess)
13881379
}
13891380

1390-
pub(crate) fn nt_pretty_printing_compatibility_hack(nt: &Nonterminal, sess: &Session) -> bool {
1381+
pub(crate) fn nt_pretty_printing_compatibility_hack(nt: &Nonterminal, sess: &Session) {
13911382
let item = match nt {
13921383
Nonterminal::NtItem(item) => item,
13931384
Nonterminal::NtStmt(stmt) => match &stmt.kind {
13941385
ast::StmtKind::Item(item) => item,
1395-
_ => return false,
1386+
_ => return,
13961387
},
1397-
_ => return false,
1388+
_ => return,
13981389
};
13991390
pretty_printing_compatibility_hack(item, sess)
14001391
}

compiler/rustc_expand/src/errors.rs

+10
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,13 @@ pub(crate) struct EmptyDelegationList {
440440
#[primary_span]
441441
pub span: Span,
442442
}
443+
444+
// This used to be the `proc_macro_back_compat` lint (#83125). It was later
445+
// turned into a hard error.
446+
#[derive(Diagnostic)]
447+
#[diag(expand_proc_macro_back_compat)]
448+
#[note]
449+
pub struct ProcMacroBackCompat {
450+
pub crate_name: String,
451+
pub fixed_version: String,
452+
}

compiler/rustc_expand/src/proc_macro.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ use crate::proc_macro_server;
44

55
use rustc_ast as ast;
66
use rustc_ast::ptr::P;
7-
use rustc_ast::token;
87
use rustc_ast::tokenstream::TokenStream;
9-
use rustc_data_structures::sync::Lrc;
108
use rustc_errors::ErrorGuaranteed;
119
use rustc_parse::parser::ForceCollect;
1210
use rustc_session::config::ProcMacroExecutionStrategy;
1311
use rustc_span::profiling::SpannedEventArgRecorder;
14-
use rustc_span::{Span, DUMMY_SP};
12+
use rustc_span::Span;
1513

1614
struct MessagePipe<T> {
1715
tx: std::sync::mpsc::SyncSender<T>,
@@ -120,18 +118,13 @@ impl MultiItemModifier for DeriveProcMacro {
120118
// We need special handling for statement items
121119
// (e.g. `fn foo() { #[derive(Debug)] struct Bar; }`)
122120
let is_stmt = matches!(item, Annotatable::Stmt(..));
123-
let hack = crate::base::ann_pretty_printing_compatibility_hack(&item, &ecx.sess);
124-
let input = if hack {
125-
let nt = match item {
126-
Annotatable::Item(item) => token::NtItem(item),
127-
Annotatable::Stmt(stmt) => token::NtStmt(stmt),
128-
_ => unreachable!(),
129-
};
130-
TokenStream::token_alone(token::Interpolated(Lrc::new(nt)), DUMMY_SP)
131-
} else {
132-
item.to_tokens()
133-
};
134121

122+
// We used to have an alternative behaviour for crates that needed it.
123+
// We had a lint for a long time, but now we just emit a hard error.
124+
// Eventually we might remove the special case hard error check
125+
// altogether. See #73345.
126+
crate::base::ann_pretty_printing_compatibility_hack(&item, &ecx.sess);
127+
let input = item.to_tokens();
135128
let stream = {
136129
let _timer =
137130
ecx.sess.prof.generic_activity_with_arg_recorder("expand_proc_macro", |recorder| {

compiler/rustc_expand/src/proc_macro_server.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -276,21 +276,20 @@ impl FromInternal<(TokenStream, &mut Rustc<'_, '_>)> for Vec<TokenTree<TokenStre
276276

277277
Interpolated(nt) => {
278278
let stream = TokenStream::from_nonterminal_ast(&nt);
279-
// A hack used to pass AST fragments to attribute and derive
280-
// macros as a single nonterminal token instead of a token
281-
// stream. Such token needs to be "unwrapped" and not
282-
// represented as a delimited group.
283-
// FIXME: It needs to be removed, but there are some
284-
// compatibility issues (see #73345).
285-
if crate::base::nt_pretty_printing_compatibility_hack(&nt, rustc.ecx.sess) {
286-
trees.extend(Self::from_internal((stream, rustc)));
287-
} else {
288-
trees.push(TokenTree::Group(Group {
289-
delimiter: pm::Delimiter::None,
290-
stream: Some(stream),
291-
span: DelimSpan::from_single(span),
292-
}))
293-
}
279+
// We used to have an alternative behaviour for crates that
280+
// needed it: a hack used to pass AST fragments to
281+
// attribute and derive macros as a single nonterminal
282+
// token instead of a token stream. Such token needs to be
283+
// "unwrapped" and not represented as a delimited group. We
284+
// had a lint for a long time, but now we just emit a hard
285+
// error. Eventually we might remove the special case hard
286+
// error check altogether. See #73345.
287+
crate::base::nt_pretty_printing_compatibility_hack(&nt, rustc.ecx.sess);
288+
trees.push(TokenTree::Group(Group {
289+
delimiter: pm::Delimiter::None,
290+
stream: Some(stream),
291+
span: DelimSpan::from_single(span),
292+
}))
294293
}
295294

296295
OpenDelim(..) | CloseDelim(..) => unreachable!(),

compiler/rustc_lint/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,6 @@ lint_pattern_in_foreign = patterns aren't allowed in foreign function declaratio
629629
lint_private_extern_crate_reexport =
630630
extern crate `{$ident}` is private, and cannot be re-exported, consider declaring with `pub`
631631
632-
lint_proc_macro_back_compat = using an old version of `{$crate_name}`
633-
.note = older versions of the `{$crate_name}` crate will stop compiling in future versions of Rust; please update to `{$crate_name}` v{$fixed_version}, or switch to one of the `{$crate_name}` alternatives
634-
635632
lint_proc_macro_derive_resolution_fallback = cannot find {$ns} `{$ident}` in this scope
636633
.label = names from parent modules are not accessible without an explicit import
637634

compiler/rustc_lint/src/context/diagnostics.rs

-3
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,6 @@ pub(super) fn decorate_lint(sess: &Session, diagnostic: BuiltinLintDiag, diag: &
159159
BuiltinLintDiag::LegacyDeriveHelpers(label_span) => {
160160
lints::LegacyDeriveHelpers { span: label_span }.decorate_lint(diag);
161161
}
162-
BuiltinLintDiag::ProcMacroBackCompat { crate_name, fixed_version } => {
163-
lints::ProcMacroBackCompat { crate_name, fixed_version }.decorate_lint(diag);
164-
}
165162
BuiltinLintDiag::OrPatternsBackCompat(suggestion_span, suggestion) => {
166163
lints::OrPatternsBackCompat { span: suggestion_span, suggestion }.decorate_lint(diag);
167164
}

compiler/rustc_lint/src/lints.rs

-8
Original file line numberDiff line numberDiff line change
@@ -2542,14 +2542,6 @@ pub struct LegacyDeriveHelpers {
25422542
pub span: Span,
25432543
}
25442544

2545-
#[derive(LintDiagnostic)]
2546-
#[diag(lint_proc_macro_back_compat)]
2547-
#[note]
2548-
pub struct ProcMacroBackCompat {
2549-
pub crate_name: String,
2550-
pub fixed_version: String,
2551-
}
2552-
25532545
#[derive(LintDiagnostic)]
25542546
#[diag(lint_or_patterns_back_compat)]
25552547
pub struct OrPatternsBackCompat {

compiler/rustc_lint_defs/src/builtin.rs

-48
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ declare_lint_pass! {
7575
PATTERNS_IN_FNS_WITHOUT_BODY,
7676
PRIVATE_BOUNDS,
7777
PRIVATE_INTERFACES,
78-
PROC_MACRO_BACK_COMPAT,
7978
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
8079
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
8180
REDUNDANT_LIFETIMES,
@@ -3705,53 +3704,6 @@ declare_lint! {
37053704
"detects invalid `#[doc(...)]` attributes",
37063705
}
37073706

3708-
declare_lint! {
3709-
/// The `proc_macro_back_compat` lint detects uses of old versions of certain
3710-
/// proc-macro crates, which have hardcoded workarounds in the compiler.
3711-
///
3712-
/// ### Example
3713-
///
3714-
/// ```rust,ignore (needs-dependency)
3715-
///
3716-
/// use time_macros_impl::impl_macros;
3717-
/// struct Foo;
3718-
/// impl_macros!(Foo);
3719-
/// ```
3720-
///
3721-
/// This will produce:
3722-
///
3723-
/// ```text
3724-
/// warning: using an old version of `time-macros-impl`
3725-
/// ::: $DIR/group-compat-hack.rs:27:5
3726-
/// |
3727-
/// LL | impl_macros!(Foo);
3728-
/// | ------------------ in this macro invocation
3729-
/// |
3730-
/// = note: `#[warn(proc_macro_back_compat)]` on by default
3731-
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3732-
/// = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
3733-
/// = note: the `time-macros-impl` crate will stop compiling in futures version of Rust. Please update to the latest version of the `time` crate to avoid breakage
3734-
/// = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3735-
/// ```
3736-
///
3737-
/// ### Explanation
3738-
///
3739-
/// Eventually, the backwards-compatibility hacks present in the compiler will be removed,
3740-
/// causing older versions of certain crates to stop compiling.
3741-
/// This is a [future-incompatible] lint to ease the transition to an error.
3742-
/// See [issue #83125] for more details.
3743-
///
3744-
/// [issue #83125]: https://github.com/rust-lang/rust/issues/83125
3745-
/// [future-incompatible]: ../index.md#future-incompatible-lints
3746-
pub PROC_MACRO_BACK_COMPAT,
3747-
Deny,
3748-
"detects usage of old versions of certain proc-macro crates",
3749-
@future_incompatible = FutureIncompatibleInfo {
3750-
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
3751-
reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
3752-
};
3753-
}
3754-
37553707
declare_lint! {
37563708
/// The `rust_2021_incompatible_or_patterns` lint detects usage of old versions of or-patterns.
37573709
///

compiler/rustc_lint_defs/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,6 @@ pub enum BuiltinLintDiag {
618618
is_foreign: bool,
619619
},
620620
LegacyDeriveHelpers(Span),
621-
ProcMacroBackCompat {
622-
crate_name: String,
623-
fixed_version: String,
624-
},
625621
OrPatternsBackCompat(Span, String),
626622
ReservedPrefix(Span, String),
627623
TrailingMacro(bool, Ident),

0 commit comments

Comments
 (0)