Skip to content

Commit c07a6a9

Browse files
committed
Auto merge of #94063 - Aaron1011:pretty-print-rental, r=lcnr
Only apply `ProceduralMasquerade` hack to older versions of `rental` The latest version of `rental` (v0.5.6) contains a fix that allows it to compile without relying on the pretty-print back-compat hack. Hopefully, there are no longer any crates relying on the affected versions of the (much less popular) `procedural-masquerade` crate. This should allow us to target the pretty-print back-compat hack specifically to older versions of `rental`, and specifically mention upgrading to `rental` v0.5.6 in the lint message.
2 parents 1481fd9 + 541128d commit c07a6a9

File tree

13 files changed

+361
-117
lines changed

13 files changed

+361
-117
lines changed

compiler/rustc_expand/src/base.rs

+35-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_span::edition::Edition;
2222
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
2323
use rustc_span::source_map::SourceMap;
2424
use rustc_span::symbol::{kw, sym, Ident, Symbol};
25-
use rustc_span::{BytePos, FileName, Span, DUMMY_SP};
25+
use rustc_span::{BytePos, FileName, RealFileName, Span, DUMMY_SP};
2626
use smallvec::{smallvec, SmallVec};
2727

2828
use std::default::Default;
@@ -1423,16 +1423,40 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &ParseSess) -> bool {
14231423
if let ast::ItemKind::Enum(enum_def, _) = &item.kind {
14241424
if let [variant] = &*enum_def.variants {
14251425
if variant.ident.name == sym::Input {
1426-
sess.buffer_lint_with_diagnostic(
1427-
&PROC_MACRO_BACK_COMPAT,
1428-
item.ident.span,
1429-
ast::CRATE_NODE_ID,
1430-
"using `procedural-masquerade` crate",
1431-
BuiltinLintDiagnostics::ProcMacroBackCompat(
1432-
"The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. \
1433-
Versions of this crate below 0.1.7 will eventually stop compiling.".to_string())
1434-
);
1435-
return true;
1426+
let filename = sess.source_map().span_to_filename(item.ident.span);
1427+
if let FileName::Real(RealFileName::LocalPath(path)) = filename {
1428+
if let Some(c) = path
1429+
.components()
1430+
.flat_map(|c| c.as_os_str().to_str())
1431+
.find(|c| c.starts_with("rental") || c.starts_with("allsorts-rental"))
1432+
{
1433+
let crate_matches = if c.starts_with("allsorts-rental") {
1434+
true
1435+
} else {
1436+
let mut version = c.trim_start_matches("rental-").split(".");
1437+
version.next() == Some("0")
1438+
&& version.next() == Some("5")
1439+
&& version
1440+
.next()
1441+
.and_then(|c| c.parse::<u32>().ok())
1442+
.map_or(false, |v| v < 6)
1443+
};
1444+
1445+
if crate_matches {
1446+
sess.buffer_lint_with_diagnostic(
1447+
&PROC_MACRO_BACK_COMPAT,
1448+
item.ident.span,
1449+
ast::CRATE_NODE_ID,
1450+
"using an old version of `rental`",
1451+
BuiltinLintDiagnostics::ProcMacroBackCompat(
1452+
"older versions of the `rental` crate will stop compiling in future versions of Rust; \
1453+
please update to `rental` v0.5.6, or switch to one of the `rental` alternatives".to_string()
1454+
)
1455+
);
1456+
return true;
1457+
}
1458+
}
1459+
}
14361460
}
14371461
}
14381462
}

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

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
// aux-build:test-macros.rs
2+
// check-pass
23

34
#[macro_use]
45
extern crate test_macros;
56

67
#[derive(Print)]
78
enum ProceduralMasqueradeDummyType {
8-
//~^ ERROR using
9-
//~| WARN this was previously
10-
//~| ERROR using
11-
//~| WARN this was previously
12-
//~| ERROR using
13-
//~| WARN this was previously
14-
//~| ERROR using
15-
//~| WARN this was previously
169
Input
1710
}
1811

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

-91
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
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",
6-
span: #0 bytes(86..90),
5+
span: #0 bytes(100..104),
76
},
87
Ident {
98
ident: "ProceduralMasqueradeDummyType",
10-
span: #0 bytes(91..120),
9+
span: #0 bytes(105..134),
1110
},
1211
Group {
1312
delimiter: Brace,
1413
stream: TokenStream [
1514
Ident {
1615
ident: "Input",
17-
span: #0 bytes(315..320),
16+
span: #0 bytes(141..146),
1817
},
1918
],
20-
span: #0 bytes(121..322),
19+
span: #0 bytes(135..148),
2120
},
2221
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// aux-build:test-macros.rs
2+
// compile-flags: -Z span-debug
3+
// check-pass
4+
5+
#![no_std] // Don't load unnecessary hygiene information from std
6+
extern crate std;
7+
8+
#[macro_use] extern crate test_macros;
9+
10+
include!("pretty-print-hack/rental-0.5.6/src/lib.rs");
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input }
2+
PRINT-DERIVE INPUT (DEBUG): TokenStream [
3+
Ident {
4+
ident: "enum",
5+
span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:4:1: 4:5 (#0),
6+
},
7+
Ident {
8+
ident: "ProceduralMasqueradeDummyType",
9+
span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:4:6: 4:35 (#0),
10+
},
11+
Group {
12+
delimiter: Brace,
13+
stream: TokenStream [
14+
Ident {
15+
ident: "Input",
16+
span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:13:5: 13:10 (#0),
17+
},
18+
],
19+
span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:4:36: 14:2 (#0),
20+
},
21+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// aux-build:test-macros.rs
2+
// compile-flags: -Z span-debug
3+
4+
#![no_std] // Don't load unnecessary hygiene information from std
5+
extern crate std;
6+
7+
#[macro_use] extern crate test_macros;
8+
9+
mod first {
10+
include!("pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs");
11+
}
12+
13+
mod second {
14+
include!("pretty-print-hack/rental-0.5.5/src/lib.rs");
15+
}
16+
17+
fn main() {}

0 commit comments

Comments
 (0)