diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index e1c218c640851..221b396b6ae32 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -1240,16 +1240,35 @@ pub(crate) fn pretty_printing_compatibility_hack(nt: &Nonterminal, sess: &ParseS if let ast::ItemKind::Enum(enum_def, _) = &item.kind { if let [variant] = &*enum_def.variants { if variant.ident.name == sym::Input { - sess.buffer_lint_with_diagnostic( - &PROC_MACRO_BACK_COMPAT, - item.ident.span, - ast::CRATE_NODE_ID, - "using `procedural-masquerade` crate", - BuiltinLintDiagnostics::ProcMacroBackCompat( - "The `procedural-masquerade` crate has been unnecessary since Rust 1.30.0. \ - Versions of this crate below 0.1.7 will eventually stop compiling.".to_string()) - ); - return true; + let filename = sess.source_map().span_to_filename(variant.ident.span); + let filename = filename.prefer_local(); + let filename = filename.to_string_lossy(); + let rental_prefix = "rental-"; + if let Some(pos) = filename.find(rental_prefix) { + let mut digits = filename[(pos + rental_prefix.len())..].split("."); + // Check for a version before `0.5.6` + if digits.next().and_then(|d| d.parse().ok()) == Some(0usize) + && digits + .next() + .and_then(|d| d.parse().ok()) + .map_or(false, |d: usize| d <= 5) + && digits + .next() + .and_then(|d| d[..1].parse().ok()) + .map_or(false, |d: usize| d < 6) + { + sess.buffer_lint_with_diagnostic( + &PROC_MACRO_BACK_COMPAT, + item.ident.span, + ast::CRATE_NODE_ID, + "using outdated version of `rental` crate", + BuiltinLintDiagnostics::ProcMacroBackCompat( + "Versions of the `rental` crate below `0.5.6` will eventually stop compiling. \ + Please update to the latest version of `rental`".to_string()) + ); + return true; + } + } } } } diff --git a/src/test/ui/proc-macro/issue-73933-procedural-masquerade.rs b/src/test/ui/proc-macro/issue-73933-procedural-masquerade.rs index abc3d2691a307..371139651213f 100644 --- a/src/test/ui/proc-macro/issue-73933-procedural-masquerade.rs +++ b/src/test/ui/proc-macro/issue-73933-procedural-masquerade.rs @@ -5,8 +5,7 @@ extern crate test_macros; #[derive(Print)] -enum ProceduralMasqueradeDummyType { //~ WARN using -//~| WARN this was previously +enum ProceduralMasqueradeDummyType { Input } diff --git a/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stdout b/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stdout index 8edd68f8a3b84..8cd981e03f118 100644 --- a/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stdout +++ b/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stdout @@ -1,5 +1,4 @@ -PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input, } -PRINT-DERIVE RE-COLLECTED (DISPLAY): enum ProceduralMasqueradeDummyType { Input } +PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input } PRINT-DERIVE INPUT (DEBUG): TokenStream [ Ident { ident: "enum", @@ -14,9 +13,9 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ stream: TokenStream [ Ident { ident: "Input", - span: #0 bytes(186..191), + span: #0 bytes(141..146), }, ], - span: #0 bytes(135..193), + span: #0 bytes(135..148), }, ] diff --git a/src/test/ui/proc-macro/issue-84428-rental-back-compat.rs b/src/test/ui/proc-macro/issue-84428-rental-back-compat.rs new file mode 100644 index 0000000000000..003c33d8db733 --- /dev/null +++ b/src/test/ui/proc-macro/issue-84428-rental-back-compat.rs @@ -0,0 +1,4 @@ +// check-pass +// aux-build:test-macros.rs + +include!("pretty-print-compat-hack/rental-0.5.5.rs"); diff --git a/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stderr b/src/test/ui/proc-macro/issue-84428-rental-back-compat.stderr similarity index 63% rename from src/test/ui/proc-macro/issue-73933-procedural-masquerade.stderr rename to src/test/ui/proc-macro/issue-84428-rental-back-compat.stderr index 0b930705e3510..ec197af7f6fbe 100644 --- a/src/test/ui/proc-macro/issue-73933-procedural-masquerade.stderr +++ b/src/test/ui/proc-macro/issue-84428-rental-back-compat.stderr @@ -1,5 +1,5 @@ -warning: using `procedural-masquerade` crate - --> $DIR/issue-73933-procedural-masquerade.rs:8:6 +warning: using outdated version of `rental` crate + --> $DIR/pretty-print-compat-hack/rental-0.5.5.rs:7:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -7,13 +7,13 @@ LL | enum ProceduralMasqueradeDummyType { = note: `#[warn(proc_macro_back_compat)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #83125 - = 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. + = note: Versions of the `rental` crate below `0.5.6` will eventually stop compiling. Please update to the latest version of `rental` warning: 1 warning emitted Future incompatibility report: Future breakage date: None, diagnostic: -warning: using `procedural-masquerade` crate - --> $DIR/issue-73933-procedural-masquerade.rs:8:6 +warning: using outdated version of `rental` crate + --> $DIR/pretty-print-compat-hack/rental-0.5.5.rs:7:6 | LL | enum ProceduralMasqueradeDummyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -21,5 +21,5 @@ LL | enum ProceduralMasqueradeDummyType { = note: `#[warn(proc_macro_back_compat)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #83125 - = 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. + = note: Versions of the `rental` crate below `0.5.6` will eventually stop compiling. Please update to the latest version of `rental` diff --git a/src/test/ui/proc-macro/issue-84428-rental-back-compat.stdout b/src/test/ui/proc-macro/issue-84428-rental-back-compat.stdout new file mode 100644 index 0000000000000..693306fc86bd1 --- /dev/null +++ b/src/test/ui/proc-macro/issue-84428-rental-back-compat.stdout @@ -0,0 +1,22 @@ +PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input, } +PRINT-DERIVE RE-COLLECTED (DISPLAY): enum ProceduralMasqueradeDummyType { Input } +PRINT-DERIVE INPUT (DEBUG): TokenStream [ + Ident { + ident: "enum", + span: #0 bytes(10794903..10794907), + }, + Ident { + ident: "ProceduralMasqueradeDummyType", + span: #0 bytes(10794908..10794937), + }, + Group { + delimiter: Brace, + stream: TokenStream [ + Ident { + ident: "Input", + span: #0 bytes(10794944..10794949), + }, + ], + span: #0 bytes(10794938..10794951), + }, +] diff --git a/src/test/ui/proc-macro/pretty-print-compat-hack/rental-0.5.5.rs b/src/test/ui/proc-macro/pretty-print-compat-hack/rental-0.5.5.rs new file mode 100644 index 0000000000000..b0a4a895ca14b --- /dev/null +++ b/src/test/ui/proc-macro/pretty-print-compat-hack/rental-0.5.5.rs @@ -0,0 +1,11 @@ +// ignore-test this is not a test + +#[macro_use] +extern crate test_macros; + +#[derive(Print)] +enum ProceduralMasqueradeDummyType { + Input +} + +fn main() {}