Skip to content

Commit dc04e35

Browse files
authored
Unrolled build for rust-lang#125596
Rollup merge of rust-lang#125596 - nnethercote:rental-hard-error, r=estebank 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 rust-lang#73345. The lint was added in rust-lang#83127. The tracking issue is rust-lang#83125. The direct motivation for the change is that providing the alternative behaviour is interfering with rust-lang#125174 and follow-on work. r? ``@estebank``
2 parents 23e040a + cf0c2c7 commit dc04e35

15 files changed

+76
-602
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

+38-56
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,80 +1329,63 @@ 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;
1341-
if name == sym::ProceduralMasqueradeDummyType {
1342-
if let ast::ItemKind::Enum(enum_def, _) = &item.kind {
1343-
if let [variant] = &*enum_def.variants {
1344-
if variant.ident.name == sym::Input {
1345-
let filename = sess.source_map().span_to_filename(item.ident.span);
1346-
if let FileName::Real(real) = filename {
1347-
if let Some(c) = real
1348-
.local_path()
1349-
.unwrap_or(Path::new(""))
1350-
.components()
1351-
.flat_map(|c| c.as_os_str().to_str())
1352-
.find(|c| c.starts_with("rental") || c.starts_with("allsorts-rental"))
1353-
{
1354-
let crate_matches = if c.starts_with("allsorts-rental") {
1355-
true
1356-
} else {
1357-
let mut version = c.trim_start_matches("rental-").split('.');
1358-
version.next() == Some("0")
1359-
&& version.next() == Some("5")
1360-
&& version
1361-
.next()
1362-
.and_then(|c| c.parse::<u32>().ok())
1363-
.is_some_and(|v| v < 6)
1364-
};
1365-
1366-
if crate_matches {
1367-
sess.psess.buffer_lint(
1368-
PROC_MACRO_BACK_COMPAT,
1369-
item.ident.span,
1370-
ast::CRATE_NODE_ID,
1371-
BuiltinLintDiag::ProcMacroBackCompat {
1372-
crate_name: "rental".to_string(),
1373-
fixed_version: "0.5.6".to_string(),
1374-
},
1375-
);
1376-
return true;
1377-
}
1378-
}
1379-
}
1380-
}
1381-
}
1337+
if name == sym::ProceduralMasqueradeDummyType
1338+
&& let ast::ItemKind::Enum(enum_def, _) = &item.kind
1339+
&& let [variant] = &*enum_def.variants
1340+
&& variant.ident.name == sym::Input
1341+
&& let FileName::Real(real) = sess.source_map().span_to_filename(item.ident.span)
1342+
&& let Some(c) = real
1343+
.local_path()
1344+
.unwrap_or(Path::new(""))
1345+
.components()
1346+
.flat_map(|c| c.as_os_str().to_str())
1347+
.find(|c| c.starts_with("rental") || c.starts_with("allsorts-rental"))
1348+
{
1349+
let crate_matches = if c.starts_with("allsorts-rental") {
1350+
true
1351+
} else {
1352+
let mut version = c.trim_start_matches("rental-").split('.');
1353+
version.next() == Some("0")
1354+
&& version.next() == Some("5")
1355+
&& version.next().and_then(|c| c.parse::<u32>().ok()).is_some_and(|v| v < 6)
1356+
};
1357+
1358+
if crate_matches {
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+
});
13821365
}
13831366
}
1384-
false
13851367
}
13861368

1387-
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) {
13881370
let item = match ann {
13891371
Annotatable::Item(item) => item,
13901372
Annotatable::Stmt(stmt) => match &stmt.kind {
13911373
ast::StmtKind::Item(item) => item,
1392-
_ => return false,
1374+
_ => return,
13931375
},
1394-
_ => return false,
1376+
_ => return,
13951377
};
13961378
pretty_printing_compatibility_hack(item, sess)
13971379
}
13981380

1399-
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) {
14001382
let item = match nt {
14011383
Nonterminal::NtItem(item) => item,
14021384
Nonterminal::NtStmt(stmt) => match &stmt.kind {
14031385
ast::StmtKind::Item(item) => item,
1404-
_ => return false,
1386+
_ => return,
14051387
},
1406-
_ => return false,
1388+
_ => return,
14071389
};
14081390
pretty_printing_compatibility_hack(item, sess)
14091391
}

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/mbe/transcribe.rs

-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ pub(super) fn transcribe<'a>(
267267
// some of the unnecessary whitespace.
268268
let ident = MacroRulesNormalizedIdent::new(original_ident);
269269
if let Some(cur_matched) = lookup_cur_matched(ident, interp, &repeats) {
270-
// njn: explain the use of alone here
271270
let tt = match cur_matched {
272271
MatchedSingle(ParseNtResult::Tt(tt)) => {
273272
// `tt`s are emitted into the output stream directly as "raw tokens",

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
@@ -635,9 +635,6 @@ lint_pattern_in_foreign = patterns aren't allowed in foreign function declaratio
635635
lint_private_extern_crate_reexport =
636636
extern crate `{$ident}` is private, and cannot be re-exported, consider declaring with `pub`
637637
638-
lint_proc_macro_back_compat = using an old version of `{$crate_name}`
639-
.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
640-
641638
lint_proc_macro_derive_resolution_fallback = cannot find {$ns} `{$ident}` in this scope
642639
.label = names from parent modules are not accessible without an explicit import
643640

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
@@ -2649,14 +2649,6 @@ pub struct LegacyDeriveHelpers {
26492649
pub span: Span,
26502650
}
26512651

2652-
#[derive(LintDiagnostic)]
2653-
#[diag(lint_proc_macro_back_compat)]
2654-
#[note]
2655-
pub struct ProcMacroBackCompat {
2656-
pub crate_name: String,
2657-
pub fixed_version: String,
2658-
}
2659-
26602652
#[derive(LintDiagnostic)]
26612653
#[diag(lint_or_patterns_back_compat)]
26622654
pub struct OrPatternsBackCompat {

compiler/rustc_lint_defs/src/builtin.rs

-48
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ declare_lint_pass! {
7676
PATTERNS_IN_FNS_WITHOUT_BODY,
7777
PRIVATE_BOUNDS,
7878
PRIVATE_INTERFACES,
79-
PROC_MACRO_BACK_COMPAT,
8079
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
8180
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
8281
REDUNDANT_LIFETIMES,
@@ -3664,53 +3663,6 @@ declare_lint! {
36643663
"detects invalid `#[doc(...)]` attributes",
36653664
}
36663665

3667-
declare_lint! {
3668-
/// The `proc_macro_back_compat` lint detects uses of old versions of certain
3669-
/// proc-macro crates, which have hardcoded workarounds in the compiler.
3670-
///
3671-
/// ### Example
3672-
///
3673-
/// ```rust,ignore (needs-dependency)
3674-
///
3675-
/// use time_macros_impl::impl_macros;
3676-
/// struct Foo;
3677-
/// impl_macros!(Foo);
3678-
/// ```
3679-
///
3680-
/// This will produce:
3681-
///
3682-
/// ```text
3683-
/// warning: using an old version of `time-macros-impl`
3684-
/// ::: $DIR/group-compat-hack.rs:27:5
3685-
/// |
3686-
/// LL | impl_macros!(Foo);
3687-
/// | ------------------ in this macro invocation
3688-
/// |
3689-
/// = note: `#[warn(proc_macro_back_compat)]` on by default
3690-
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
3691-
/// = note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
3692-
/// = 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
3693-
/// = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3694-
/// ```
3695-
///
3696-
/// ### Explanation
3697-
///
3698-
/// Eventually, the backwards-compatibility hacks present in the compiler will be removed,
3699-
/// causing older versions of certain crates to stop compiling.
3700-
/// This is a [future-incompatible] lint to ease the transition to an error.
3701-
/// See [issue #83125] for more details.
3702-
///
3703-
/// [issue #83125]: https://github.com/rust-lang/rust/issues/83125
3704-
/// [future-incompatible]: ../index.md#future-incompatible-lints
3705-
pub PROC_MACRO_BACK_COMPAT,
3706-
Deny,
3707-
"detects usage of old versions of certain proc-macro crates",
3708-
@future_incompatible = FutureIncompatibleInfo {
3709-
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
3710-
reference: "issue #83125 <https://github.com/rust-lang/rust/issues/83125>",
3711-
};
3712-
}
3713-
37143666
declare_lint! {
37153667
/// The `rust_2021_incompatible_or_patterns` lint detects usage of old versions of or-patterns.
37163668
///

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)