Skip to content

Commit b5e92ae

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 722b444 commit b5e92ae

14 files changed

+54
-574
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

-7
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,6 @@ pub(super) fn emit_buffered_lint(
191191
BuiltinLintDiag::LegacyDeriveHelpers(label_span) => {
192192
ctx.emit_span_lint(lint, span, lints::LegacyDeriveHelpers { span: label_span });
193193
}
194-
BuiltinLintDiag::ProcMacroBackCompat { crate_name, fixed_version } => {
195-
ctx.emit_span_lint(
196-
lint,
197-
span,
198-
lints::ProcMacroBackCompat { crate_name, fixed_version },
199-
);
200-
}
201194
BuiltinLintDiag::OrPatternsBackCompat(suggestion_span, suggestion) => {
202195
ctx.emit_span_lint(
203196
lint,

compiler/rustc_lint/src/lints.rs

-8
Original file line numberDiff line numberDiff line change
@@ -2571,14 +2571,6 @@ pub struct LegacyDeriveHelpers {
25712571
pub span: Span,
25722572
}
25732573

2574-
#[derive(LintDiagnostic)]
2575-
#[diag(lint_proc_macro_back_compat)]
2576-
#[note]
2577-
pub struct ProcMacroBackCompat {
2578-
pub crate_name: String,
2579-
pub fixed_version: String,
2580-
}
2581-
25822574
#[derive(LintDiagnostic)]
25832575
#[diag(lint_or_patterns_back_compat)]
25842576
pub struct OrPatternsBackCompat {

compiler/rustc_lint_defs/src/builtin.rs

-48
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ declare_lint_pass! {
7777
POINTER_STRUCTURAL_MATCH,
7878
PRIVATE_BOUNDS,
7979
PRIVATE_INTERFACES,
80-
PROC_MACRO_BACK_COMPAT,
8180
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
8281
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
8382
REDUNDANT_LIFETIMES,
@@ -3792,53 +3791,6 @@ declare_lint! {
37923791
"detects invalid `#[doc(...)]` attributes",
37933792
}
37943793

3795-
declare_lint! {
3796-
/// The `proc_macro_back_compat` lint detects uses of old versions of certain
3797-
/// proc-macro crates, which have hardcoded workarounds in the compiler.
3798-
///
3799-
/// ### Example
3800-
///
3801-
/// ```rust,ignore (needs-dependency)
3802-
///
3803-
/// use time_macros_impl::impl_macros;
3804-
/// struct Foo;
3805-
/// impl_macros!(Foo);
3806-
/// ```
3807-
///
3808-
/// This will produce:
3809-
///
3810-
/// ```text
3811-
/// warning: using an old version of `time-macros-impl`
3812-
/// ::: $DIR/group-compat-hack.rs:27:5
3813-
/// |
3814-
/// LL | impl_macros!(Foo);
3815-
/// | ------------------ in this macro invocation
3816-
/// |
3817-
/// = note: `#[warn(proc_macro_back_compat)]` on by default
3818-
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3819-
/// = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
3820-
/// = 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
3821-
/// = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3822-
/// ```
3823-
///
3824-
/// ### Explanation
3825-
///
3826-
/// Eventually, the backwards-compatibility hacks present in the compiler will be removed,
3827-
/// causing older versions of certain crates to stop compiling.
3828-
/// This is a [future-incompatible] lint to ease the transition to an error.
3829-
/// See [issue #83125] for more details.
3830-
///
3831-
/// [issue #83125]: https://github.com/rust-lang/rust/issues/83125
3832-
/// [future-incompatible]: ../index.md#future-incompatible-lints
3833-
pub PROC_MACRO_BACK_COMPAT,
3834-
Deny,
3835-
"detects usage of old versions of certain proc-macro crates",
3836-
@future_incompatible = FutureIncompatibleInfo {
3837-
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
3838-
reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
3839-
};
3840-
}
3841-
38423794
declare_lint! {
38433795
/// The `rust_2021_incompatible_or_patterns` lint detects usage of old versions of or-patterns.
38443796
///

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)