Skip to content

Commit d6a7c1d

Browse files
committed
Extend proc_macro_back_compat lint to procedural-masquerade
We now lint on *any* use of `procedural-masquerade` crate. While this crate still exists, its main reverse dependency (`cssparser`) no longer depends on it. Any crates still depending off should stop doing so, as it only exists to support very old Rust versions. If a crate actually needs to support old versions of rustc via `procedural-masquerade`, then they'll just need to accept the warning until we remove it entirely (at the same time as the back-compat hack). The latest version of `procedural-masquerade` does not work with the latest rustc, but trying to check for the version seems like more trouble than it's worth. While working on this, I realized that the `proc-macro-hack` check was never actually doing anything. The corresponding enum variant in `proc-macro-hack` is named `Value` or `Nested` - it has never been called `Input`. Due to a strange Crater issue, the Crater run that tested adding this did *not* end up testing it - some of the crates that would have failed did not actually have their tests checked, making it seem as though the `proc-macro-hack` check was working. The Crater issue is being discussed at https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/Nearly.20identical.20Crater.20runs.20processed.20a.20crate.20differently/near/230406661 Despite the `proc-macro-hack` check not actually doing anything, we haven't gotten any reports from users about their build being broken. I went ahead and removed it entirely, since it's clear that no one is being affected by the `proc-macro-hack` regression in practice.
1 parent 2ccf063 commit d6a7c1d

7 files changed

+103
-29
lines changed

compiler/rustc_ast/src/token.rs

-27
Original file line numberDiff line numberDiff line change
@@ -784,33 +784,6 @@ impl Nonterminal {
784784
NtTT(tt) => tt.span(),
785785
}
786786
}
787-
788-
/// This nonterminal looks like some specific enums from
789-
/// `proc-macro-hack` and `procedural-masquerade` crates.
790-
/// We need to maintain some special pretty-printing behavior for them due to incorrect
791-
/// asserts in old versions of those crates and their wide use in the ecosystem.
792-
/// See issue #73345 for more details.
793-
/// FIXME(#73933): Remove this eventually.
794-
pub fn pretty_printing_compatibility_hack(&self) -> bool {
795-
let item = match self {
796-
NtItem(item) => item,
797-
NtStmt(stmt) => match &stmt.kind {
798-
ast::StmtKind::Item(item) => item,
799-
_ => return false,
800-
},
801-
_ => return false,
802-
};
803-
804-
let name = item.ident.name;
805-
if name == sym::ProceduralMasqueradeDummyType || name == sym::ProcMacroHack {
806-
if let ast::ItemKind::Enum(enum_def, _) = &item.kind {
807-
if let [variant] = &*enum_def.variants {
808-
return variant.ident.name == sym::Input;
809-
}
810-
}
811-
}
812-
false
813-
}
814787
}
815788

816789
impl PartialEq for Nonterminal {

compiler/rustc_expand/src/base.rs

+40
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ use rustc_attr::{self as attr, Deprecation, Stability};
1010
use rustc_data_structures::fx::FxHashMap;
1111
use rustc_data_structures::sync::{self, Lrc};
1212
use rustc_errors::{DiagnosticBuilder, ErrorReported};
13+
use rustc_lint_defs::builtin::PROC_MACRO_BACK_COMPAT;
14+
use rustc_lint_defs::BuiltinLintDiagnostics;
1315
use rustc_parse::{self, nt_to_tokenstream, parser, MACRO_ARGUMENTS};
1416
use rustc_session::{parse::ParseSess, Limit, Session};
1517
use rustc_span::def_id::DefId;
@@ -1241,3 +1243,41 @@ pub fn get_exprs_from_tts(
12411243
}
12421244
Some(es)
12431245
}
1246+
1247+
/// This nonterminal looks like some specific enums from
1248+
/// `proc-macro-hack` and `procedural-masquerade` crates.
1249+
/// We need to maintain some special pretty-printing behavior for them due to incorrect
1250+
/// asserts in old versions of those crates and their wide use in the ecosystem.
1251+
/// See issue #73345 for more details.
1252+
/// FIXME(#73933): Remove this eventually.
1253+
pub(crate) fn pretty_printing_compatibility_hack(nt: &Nonterminal, sess: &ParseSess) -> bool {
1254+
let item = match nt {
1255+
Nonterminal::NtItem(item) => item,
1256+
Nonterminal::NtStmt(stmt) => match &stmt.kind {
1257+
ast::StmtKind::Item(item) => item,
1258+
_ => return false,
1259+
},
1260+
_ => return false,
1261+
};
1262+
1263+
let name = item.ident.name;
1264+
if name == sym::ProceduralMasqueradeDummyType {
1265+
if let ast::ItemKind::Enum(enum_def, _) = &item.kind {
1266+
if let [variant] = &*enum_def.variants {
1267+
if variant.ident.name == sym::Input {
1268+
sess.buffer_lint_with_diagnostic(
1269+
&PROC_MACRO_BACK_COMPAT,
1270+
item.ident.span,
1271+
ast::CRATE_NODE_ID,
1272+
"using `procedural-masquerade` crate",
1273+
BuiltinLintDiagnostics::ProcMacroBackCompat(
1274+
"The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. \
1275+
Versions of this crate below 0.1.7 will eventually stop compiling.".to_string())
1276+
);
1277+
return true;
1278+
}
1279+
}
1280+
}
1281+
}
1282+
false
1283+
}

compiler/rustc_expand/src/proc_macro.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ impl MultiItemModifier for ProcMacroDerive {
9090
}
9191
_ => unreachable!(),
9292
};
93-
let input = if item.pretty_printing_compatibility_hack() {
93+
let input = if crate::base::pretty_printing_compatibility_hack(&item, &ecx.sess.parse_sess)
94+
{
9495
TokenTree::token(token::Interpolated(Lrc::new(item)), DUMMY_SP).into()
9596
} else {
9697
nt_to_tokenstream(&item, &ecx.sess.parse_sess, CanSynthesizeMissingTokens::Yes)

compiler/rustc_expand/src/proc_macro_server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl FromInternal<(TreeAndSpacing, &'_ ParseSess, &'_ mut Vec<Self>)>
187187
delimiter: Delimiter::None,
188188
stream,
189189
span: DelimSpan::from_single(span),
190-
flatten: nt.pretty_printing_compatibility_hack(),
190+
flatten: crate::base::pretty_printing_compatibility_hack(&nt, sess),
191191
})
192192
}
193193
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// check-pass
2+
// aux-build:test-macros.rs
3+
4+
#[macro_use]
5+
extern crate test_macros;
6+
7+
#[derive(Print)]
8+
enum ProceduralMasqueradeDummyType { //~ WARN using
9+
//~| WARN this was previously
10+
Input
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
warning: using `procedural-masquerade` crate
2+
--> $DIR/issue-73933-procedural-masquerade.rs:8:6
3+
|
4+
LL | enum ProceduralMasqueradeDummyType {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(proc_macro_back_compat)]` on by default
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
10+
= note: The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. Versions of this crate below 0.1.7 will eventually stop compiling.
11+
12+
warning: 1 warning emitted
13+
14+
Future incompatibility report: Future breakage date: None, diagnostic:
15+
warning: using `procedural-masquerade` crate
16+
--> $DIR/issue-73933-procedural-masquerade.rs:8:6
17+
|
18+
LL | enum ProceduralMasqueradeDummyType {
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
|
21+
= note: `#[warn(proc_macro_back_compat)]` on by default
22+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
23+
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
24+
= note: The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. Versions of this crate below 0.1.7 will eventually stop compiling.
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input, }
2+
PRINT-DERIVE RE-COLLECTED (DISPLAY): enum ProceduralMasqueradeDummyType { Input }
3+
PRINT-DERIVE INPUT (DEBUG): TokenStream [
4+
Ident {
5+
ident: "enum",
6+
span: #0 bytes(100..104),
7+
},
8+
Ident {
9+
ident: "ProceduralMasqueradeDummyType",
10+
span: #0 bytes(105..134),
11+
},
12+
Group {
13+
delimiter: Brace,
14+
stream: TokenStream [
15+
Ident {
16+
ident: "Input",
17+
span: #0 bytes(186..191),
18+
},
19+
],
20+
span: #0 bytes(135..193),
21+
},
22+
]

0 commit comments

Comments
 (0)