Skip to content

Commit 6a29d86

Browse files
committed
Only apply procedural-masquerade back-compat hack to rental
1 parent 7dc9ff5 commit 6a29d86

7 files changed

+76
-22
lines changed

compiler/rustc_expand/src/base.rs

+29-10
Original file line numberDiff line numberDiff line change
@@ -1240,16 +1240,35 @@ pub(crate) fn pretty_printing_compatibility_hack(nt: &Nonterminal, sess: &ParseS
12401240
if let ast::ItemKind::Enum(enum_def, _) = &item.kind {
12411241
if let [variant] = &*enum_def.variants {
12421242
if variant.ident.name == sym::Input {
1243-
sess.buffer_lint_with_diagnostic(
1244-
&PROC_MACRO_BACK_COMPAT,
1245-
item.ident.span,
1246-
ast::CRATE_NODE_ID,
1247-
"using `procedural-masquerade` crate",
1248-
BuiltinLintDiagnostics::ProcMacroBackCompat(
1249-
"The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. \
1250-
Versions of this crate below 0.1.7 will eventually stop compiling.".to_string())
1251-
);
1252-
return true;
1243+
let filename = sess.source_map().span_to_filename(variant.ident.span);
1244+
let filename = filename.prefer_local();
1245+
let filename = filename.to_string_lossy();
1246+
let rental_prefix = "rental-";
1247+
if let Some(pos) = filename.find(rental_prefix) {
1248+
let mut digits = filename[(pos + rental_prefix.len())..].split(".");
1249+
// Check for a version before `0.5.6`
1250+
if digits.next().and_then(|d| d.parse().ok()) == Some(0usize)
1251+
&& digits
1252+
.next()
1253+
.and_then(|d| d.parse().ok())
1254+
.map_or(false, |d: usize| d <= 5)
1255+
&& digits
1256+
.next()
1257+
.and_then(|d| d[..1].parse().ok())
1258+
.map_or(false, |d: usize| d < 6)
1259+
{
1260+
sess.buffer_lint_with_diagnostic(
1261+
&PROC_MACRO_BACK_COMPAT,
1262+
item.ident.span,
1263+
ast::CRATE_NODE_ID,
1264+
"using outdated version of `rental` crate",
1265+
BuiltinLintDiagnostics::ProcMacroBackCompat(
1266+
"Versions of the `rental` crate below `0.5.6` will eventually stop compiling. \
1267+
Please update to the latest version of `rental`".to_string())
1268+
);
1269+
return true;
1270+
}
1271+
}
12531272
}
12541273
}
12551274
}

src/test/ui/proc-macro/issue-73933-procedural-masquerade.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
extern crate test_macros;
66

77
#[derive(Print)]
8-
enum ProceduralMasqueradeDummyType { //~ WARN using
9-
//~| WARN this was previously
8+
enum ProceduralMasqueradeDummyType {
109
Input
1110
}
1211

src/test/ui/proc-macro/issue-73933-procedural-masquerade.stdout

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input, }
2-
PRINT-DERIVE RE-COLLECTED (DISPLAY): enum ProceduralMasqueradeDummyType { Input }
1+
PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input }
32
PRINT-DERIVE INPUT (DEBUG): TokenStream [
43
Ident {
54
ident: "enum",
@@ -14,9 +13,9 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
1413
stream: TokenStream [
1514
Ident {
1615
ident: "Input",
17-
span: #0 bytes(186..191),
16+
span: #0 bytes(141..146),
1817
},
1918
],
20-
span: #0 bytes(135..193),
19+
span: #0 bytes(135..148),
2120
},
2221
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// check-pass
2+
// aux-build:test-macros.rs
3+
4+
include!("pretty-print-compat-hack/rental-0.5.5.rs");
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
warning: using `procedural-masquerade` crate
2-
--> $DIR/issue-73933-procedural-masquerade.rs:8:6
1+
warning: using outdated version of `rental` crate
2+
--> $DIR/pretty-print-compat-hack/rental-0.5.5.rs:7:6
33
|
44
LL | enum ProceduralMasqueradeDummyType {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `#[warn(proc_macro_back_compat)]` on by default
88
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
99
= 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.
10+
= note: Versions of the `rental` crate below `0.5.6` will eventually stop compiling. Please update to the latest version of `rental`
1111

1212
warning: 1 warning emitted
1313

1414
Future incompatibility report: Future breakage date: None, diagnostic:
15-
warning: using `procedural-masquerade` crate
16-
--> $DIR/issue-73933-procedural-masquerade.rs:8:6
15+
warning: using outdated version of `rental` crate
16+
--> $DIR/pretty-print-compat-hack/rental-0.5.5.rs:7:6
1717
|
1818
LL | enum ProceduralMasqueradeDummyType {
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020
|
2121
= note: `#[warn(proc_macro_back_compat)]` on by default
2222
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2323
= 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.
24+
= note: Versions of the `rental` crate below `0.5.6` will eventually stop compiling. Please update to the latest version of `rental`
2525

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(10794903..10794907),
7+
},
8+
Ident {
9+
ident: "ProceduralMasqueradeDummyType",
10+
span: #0 bytes(10794908..10794937),
11+
},
12+
Group {
13+
delimiter: Brace,
14+
stream: TokenStream [
15+
Ident {
16+
ident: "Input",
17+
span: #0 bytes(10794944..10794949),
18+
},
19+
],
20+
span: #0 bytes(10794938..10794951),
21+
},
22+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// ignore-test this is not a test
2+
3+
#[macro_use]
4+
extern crate test_macros;
5+
6+
#[derive(Print)]
7+
enum ProceduralMasqueradeDummyType {
8+
Input
9+
}
10+
11+
fn main() {}

0 commit comments

Comments
 (0)