Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only apply ProceduralMasquerade hack to older versions of rental #94063

Merged
merged 3 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 35 additions & 11 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use rustc_span::edition::Edition;
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId};
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::{BytePos, FileName, Span, DUMMY_SP};
use rustc_span::{BytePos, FileName, RealFileName, Span, DUMMY_SP};
use smallvec::{smallvec, SmallVec};

use std::default::Default;
Expand Down Expand Up @@ -1423,16 +1423,40 @@ fn pretty_printing_compatibility_hack(item: &Item, sess: &ParseSess) -> bool {
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(item.ident.span);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this only lint if ProceduralMasqueradeDummyType::Input is used in the rental crate, instead of - what i would expect - being from the rental crate but used in any other crate.

apart from this this change seems good to me, even though I am not too knowledgeable about this backcompat issue ^^ with this nit resolved, r=me after a compiler fcp

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct - this type is an implementation detail of rental, and only gets used from a macro: https://github.com/jpernst/rental/blob/61188eb97f5d99b10fc1fdd469b259c4ab4bf940/src/lib.rs#L90-L98

Since it's in a macro, the file path will always be pointing to rental.

if let FileName::Real(RealFileName::LocalPath(path)) = filename {
if let Some(c) = path
.components()
.flat_map(|c| c.as_os_str().to_str())
.find(|c| c.starts_with("rental") || c.starts_with("allsorts-rental"))
{
let crate_matches = if c.starts_with("allsorts-rental") {
true
} else {
let mut version = c.trim_start_matches("rental-").split(".");
version.next() == Some("0")
&& version.next() == Some("5")
&& version
.next()
.and_then(|c| c.parse::<u32>().ok())
.map_or(false, |v| v < 6)
};

if crate_matches {
sess.buffer_lint_with_diagnostic(
&PROC_MACRO_BACK_COMPAT,
item.ident.span,
ast::CRATE_NODE_ID,
"using an old version of `rental`",
BuiltinLintDiagnostics::ProcMacroBackCompat(
"older versions of the `rental` crate will stop compiling in future versions of Rust; \
please update to `rental` v0.5.6, or switch to one of the `rental` alternatives".to_string()
)
);
return true;
}
}
}
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/test/ui/proc-macro/issue-73933-procedural-masquerade.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
// aux-build:test-macros.rs
// check-pass

#[macro_use]
extern crate test_macros;

#[derive(Print)]
enum ProceduralMasqueradeDummyType {
//~^ ERROR using
//~| WARN this was previously
//~| ERROR using
//~| WARN this was previously
//~| ERROR using
//~| WARN this was previously
//~| ERROR using
//~| WARN this was previously
Input
}

Expand Down
91 changes: 0 additions & 91 deletions src/test/ui/proc-macro/issue-73933-procedural-masquerade.stderr

This file was deleted.

11 changes: 5 additions & 6 deletions src/test/ui/proc-macro/issue-73933-procedural-masquerade.stdout
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
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",
span: #0 bytes(86..90),
span: #0 bytes(100..104),
},
Ident {
ident: "ProceduralMasqueradeDummyType",
span: #0 bytes(91..120),
span: #0 bytes(105..134),
},
Group {
delimiter: Brace,
stream: TokenStream [
Ident {
ident: "Input",
span: #0 bytes(315..320),
span: #0 bytes(141..146),
},
],
span: #0 bytes(121..322),
span: #0 bytes(135..148),
},
]
12 changes: 12 additions & 0 deletions src/test/ui/proc-macro/pretty-print-hack-hide.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// aux-build:test-macros.rs
// compile-flags: -Z span-debug
// check-pass

#![no_std] // Don't load unnecessary hygiene information from std
extern crate std;

#[macro_use] extern crate test_macros;

include!("pretty-print-hack/rental-0.5.6/src/lib.rs");

fn main() {}
21 changes: 21 additions & 0 deletions src/test/ui/proc-macro/pretty-print-hack-hide.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input }
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
ident: "enum",
span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:4:1: 4:5 (#0),
},
Ident {
ident: "ProceduralMasqueradeDummyType",
span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:4:6: 4:35 (#0),
},
Group {
delimiter: Brace,
stream: TokenStream [
Ident {
ident: "Input",
span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:13:5: 13:10 (#0),
},
],
span: $DIR/pretty-print-hack/rental-0.5.6/src/lib.rs:4:36: 14:2 (#0),
},
]
17 changes: 17 additions & 0 deletions src/test/ui/proc-macro/pretty-print-hack-show.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// aux-build:test-macros.rs
// compile-flags: -Z span-debug

#![no_std] // Don't load unnecessary hygiene information from std
extern crate std;

#[macro_use] extern crate test_macros;

mod first {
include!("pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs");
}

mod second {
include!("pretty-print-hack/rental-0.5.5/src/lib.rs");
}

fn main() {}
Loading