Skip to content

Commit 390d1ef

Browse files
committed
Extend proc_macro_back_compat lint to actix-web
Unlike the other cases of this lint, there's no simple way to detect if an old version of the relevant crate (`syn`) is in use. The `actix-web` crate only depends on `pin-project` v1.0.0, so checking the version of `actix-web` does not guarantee that a new enough version of `pin-project` (and therefore `syn`) is in use. Instead, we rely on the fact that virtually all of the regressed crates are pinned to a pre-1.0 version of `pin-project`. When this is the case, bumping the `actix-web` dependency will pull in the *latest* version of `pin-project`, which has an explicit dependency on a newer v dependency on a newer version of `syn`. The lint message tells users to update `actix-web`, since that's what they're most likely to have control over. We could potentially tell them to run `cargo update -p syn`, but I think it's more straightforward to suggest an explicit change to the `Cargo.toml` The `actori-web` fork had its last commit over a year ago, and appears to just be a renamed fork of `actix-web`. Therefore, I've removed the `actori-web` check entirely - any crates that actually get broken can simply update `syn` themselves.
1 parent 0464f63 commit 390d1ef

File tree

5 files changed

+108
-24
lines changed

5 files changed

+108
-24
lines changed

Diff for: compiler/rustc_expand/src/proc_macro_server.rs

+29-17
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ impl ToInternal<token::DelimToken> for Delimiter {
5353
}
5454
}
5555

56-
impl FromInternal<(TreeAndSpacing, &'_ ParseSess, &'_ mut Vec<Self>)>
56+
impl FromInternal<(TreeAndSpacing, &'_ mut Vec<Self>, &mut Rustc<'_>)>
5757
for TokenTree<Group, Punct, Ident, Literal>
5858
{
5959
fn from_internal(
60-
((tree, spacing), sess, stack): (TreeAndSpacing, &ParseSess, &mut Vec<Self>),
60+
((tree, spacing), stack, rustc): (TreeAndSpacing, &mut Vec<Self>, &mut Rustc<'_>),
6161
) -> Self {
6262
use rustc_ast::token::*;
6363

@@ -146,10 +146,10 @@ impl FromInternal<(TreeAndSpacing, &'_ ParseSess, &'_ mut Vec<Self>)>
146146
SingleQuote => op!('\''),
147147

148148
Ident(name, false) if name == kw::DollarCrate => tt!(Ident::dollar_crate()),
149-
Ident(name, is_raw) => tt!(Ident::new(sess, name, is_raw)),
149+
Ident(name, is_raw) => tt!(Ident::new(rustc.sess, name, is_raw)),
150150
Lifetime(name) => {
151151
let ident = symbol::Ident::new(name, span).without_first_quote();
152-
stack.push(tt!(Ident::new(sess, ident.name, false)));
152+
stack.push(tt!(Ident::new(rustc.sess, ident.name, false)));
153153
tt!(Punct::new('\'', true))
154154
}
155155
Literal(lit) => tt!(Literal { lit }),
@@ -179,15 +179,15 @@ impl FromInternal<(TreeAndSpacing, &'_ ParseSess, &'_ mut Vec<Self>)>
179179
}
180180

181181
Interpolated(nt) => {
182-
if let Some((name, is_raw)) = ident_name_compatibility_hack(&nt, span, sess) {
183-
TokenTree::Ident(Ident::new(sess, name.name, is_raw, name.span))
182+
if let Some((name, is_raw)) = ident_name_compatibility_hack(&nt, span, rustc) {
183+
TokenTree::Ident(Ident::new(rustc.sess, name.name, is_raw, name.span))
184184
} else {
185-
let stream = nt_to_tokenstream(&nt, sess, CanSynthesizeMissingTokens::No);
185+
let stream = nt_to_tokenstream(&nt, rustc.sess, CanSynthesizeMissingTokens::No);
186186
TokenTree::Group(Group {
187187
delimiter: Delimiter::None,
188188
stream,
189189
span: DelimSpan::from_single(span),
190-
flatten: crate::base::pretty_printing_compatibility_hack(&nt, sess),
190+
flatten: crate::base::pretty_printing_compatibility_hack(&nt, rustc.sess),
191191
})
192192
}
193193
}
@@ -449,7 +449,7 @@ impl server::TokenStreamIter for Rustc<'_> {
449449
loop {
450450
let tree = iter.stack.pop().or_else(|| {
451451
let next = iter.cursor.next_with_spacing()?;
452-
Some(TokenTree::from_internal((next, self.sess, &mut iter.stack)))
452+
Some(TokenTree::from_internal((next, &mut iter.stack, self)))
453453
})?;
454454
// A hack used to pass AST fragments to attribute and derive macros
455455
// as a single nonterminal token instead of a token stream.
@@ -719,11 +719,11 @@ impl server::Span for Rustc<'_> {
719719
fn ident_name_compatibility_hack(
720720
nt: &Nonterminal,
721721
orig_span: Span,
722-
sess: &ParseSess,
722+
rustc: &mut Rustc<'_>,
723723
) -> Option<(rustc_span::symbol::Ident, bool)> {
724724
if let NtIdent(ident, is_raw) = nt {
725725
if let ExpnKind::Macro(_, macro_name) = orig_span.ctxt().outer_expn_data().kind {
726-
let source_map = sess.source_map();
726+
let source_map = rustc.sess.source_map();
727727
let filename = source_map.span_to_filename(orig_span);
728728
if let FileName::Real(RealFileName::Named(path)) = filename {
729729
let matches_prefix = |prefix, filename| {
@@ -745,7 +745,7 @@ fn ident_name_compatibility_hack(
745745
let snippet = source_map.span_to_snippet(orig_span);
746746
if snippet.as_deref() == Ok("$name") {
747747
if time_macros_impl {
748-
sess.buffer_lint_with_diagnostic(
748+
rustc.sess.buffer_lint_with_diagnostic(
749749
&PROC_MACRO_BACK_COMPAT,
750750
orig_span,
751751
ast::CRATE_NODE_ID,
@@ -759,13 +759,25 @@ fn ident_name_compatibility_hack(
759759
}
760760
}
761761

762-
if macro_name == sym::tuple_from_req
763-
&& (matches_prefix("actix-web", "extract.rs")
764-
|| matches_prefix("actori-web", "extract.rs"))
765-
{
762+
if macro_name == sym::tuple_from_req && matches_prefix("actix-web", "extract.rs") {
766763
let snippet = source_map.span_to_snippet(orig_span);
767764
if snippet.as_deref() == Ok("$T") {
768-
return Some((*ident, *is_raw));
765+
if let FileName::Real(RealFileName::Named(macro_path)) =
766+
source_map.span_to_filename(rustc.def_site)
767+
{
768+
if macro_path.to_string_lossy().contains("pin-project-internal-0.") {
769+
rustc.sess.buffer_lint_with_diagnostic(
770+
&PROC_MACRO_BACK_COMPAT,
771+
orig_span,
772+
ast::CRATE_NODE_ID,
773+
"using an old version of `actix-web`",
774+
BuiltinLintDiagnostics::ProcMacroBackCompat(
775+
"the version of `actix-web` you are using might stop compiling in future versions of Rust; \
776+
please update to the latest version of the `actix-web` crate to avoid breakage".to_string())
777+
);
778+
return Some((*ident, *is_raw));
779+
}
780+
}
769781
}
770782
}
771783
}

Diff for: src/test/ui/proc-macro/group-compat-hack/auxiliary/group-compat-hack.rs renamed to src/test/ui/proc-macro/group-compat-hack/auxiliary/pin-project-internal-0.4.0.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// no-prefer-dynamic
33

44
#![crate_type = "proc-macro"]
5+
#![crate_name = "group_compat_hack"]
6+
7+
// This file has an unusual name in order to trigger the back-compat
8+
// code in the compiler
59

610
extern crate proc_macro;
711
use proc_macro::TokenStream;

Diff for: src/test/ui/proc-macro/group-compat-hack/group-compat-hack.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
// aux-build:group-compat-hack.rs
2+
// aux-build:pin-project-internal-0.4.0.rs
33
// compile-flags: -Z span-debug
44

55
#![no_std] // Don't load unnecessary hygiene information from std
@@ -51,14 +51,16 @@ mod actix_web_test {
5151
include!("actix-web/src/extract.rs");
5252

5353
struct Foo;
54-
tuple_from_req!(Foo);
54+
tuple_from_req!(Foo); //~ WARN using an old version
55+
//~| WARN this was previously
5556
}
5657

5758
mod actix_web_version_test {
5859
include!("actix-web-2.0.0/src/extract.rs");
5960

6061
struct Foo;
61-
tuple_from_req!(Foo);
62+
tuple_from_req!(Foo); //~ WARN using an old version
63+
//~| WARN this was previously
6264
}
6365

6466
mod actori_web_test {

Diff for: src/test/ui/proc-macro/group-compat-hack/group-compat-hack.stderr

+67-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,39 @@ LL | impl_macros!(Foo);
3131
= note: the `time-macros-impl` crate will stop compiling in futures version of Rust. Please update to the latest version of the `time` crate to avoid breakage
3232
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
3333

34-
warning: 2 warnings emitted
34+
warning: using an old version of `actix-web`
35+
--> $DIR/actix-web/src/extract.rs:5:34
36+
|
37+
LL | #[my_macro] struct Three($T);
38+
| ^^
39+
|
40+
::: $DIR/group-compat-hack.rs:54:5
41+
|
42+
LL | tuple_from_req!(Foo);
43+
| --------------------- in this macro invocation
44+
|
45+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
46+
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
47+
= note: the version of `actix-web` you are using might stop compiling in future versions of Rust; please update to the latest version of the `actix-web` crate to avoid breakage
48+
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
49+
50+
warning: using an old version of `actix-web`
51+
--> $DIR/actix-web-2.0.0/src/extract.rs:5:34
52+
|
53+
LL | #[my_macro] struct Three($T);
54+
| ^^
55+
|
56+
::: $DIR/group-compat-hack.rs:62:5
57+
|
58+
LL | tuple_from_req!(Foo);
59+
| --------------------- in this macro invocation
60+
|
61+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
62+
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
63+
= note: the version of `actix-web` you are using might stop compiling in future versions of Rust; please update to the latest version of the `actix-web` crate to avoid breakage
64+
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
65+
66+
warning: 4 warnings emitted
3567

3668
Future incompatibility report: Future breakage date: None, diagnostic:
3769
warning: using an old version of `time-macros-impl`
@@ -68,3 +100,37 @@ LL | impl_macros!(Foo);
68100
= note: the `time-macros-impl` crate will stop compiling in futures version of Rust. Please update to the latest version of the `time` crate to avoid breakage
69101
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
70102

103+
Future breakage date: None, diagnostic:
104+
warning: using an old version of `actix-web`
105+
--> $DIR/actix-web/src/extract.rs:5:34
106+
|
107+
LL | #[my_macro] struct Three($T);
108+
| ^^
109+
|
110+
::: $DIR/group-compat-hack.rs:54:5
111+
|
112+
LL | tuple_from_req!(Foo);
113+
| --------------------- in this macro invocation
114+
|
115+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
116+
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
117+
= note: the version of `actix-web` you are using might stop compiling in future versions of Rust; please update to the latest version of the `actix-web` crate to avoid breakage
118+
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
119+
120+
Future breakage date: None, diagnostic:
121+
warning: using an old version of `actix-web`
122+
--> $DIR/actix-web-2.0.0/src/extract.rs:5:34
123+
|
124+
LL | #[my_macro] struct Three($T);
125+
| ^^
126+
|
127+
::: $DIR/group-compat-hack.rs:62:5
128+
|
129+
LL | tuple_from_req!(Foo);
130+
| --------------------- in this macro invocation
131+
|
132+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
133+
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
134+
= note: the version of `actix-web` you are using might stop compiling in future versions of Rust; please update to the latest version of the `actix-web` crate to avoid breakage
135+
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
136+

Diff for: src/test/ui/proc-macro/group-compat-hack/group-compat-hack.stdout

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/tim
55
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/js-sys-0.3.17/src/lib.rs:5:21: 5:27 (#24) }, Ident { ident: "Two", span: $DIR/js-sys-0.3.17/src/lib.rs:5:28: 5:31 (#24) }, Group { delimiter: Parenthesis, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:46:13: 46:16 (#0) }], span: $DIR/js-sys-0.3.17/src/lib.rs:5:31: 5:38 (#24) }, Punct { ch: ';', spacing: Alone, span: $DIR/js-sys-0.3.17/src/lib.rs:5:38: 5:39 (#24) }]
66
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/group-compat-hack.rs:39:25: 39:31 (#28) }, Ident { ident: "Three", span: $DIR/group-compat-hack.rs:39:32: 39:37 (#28) }, Group { delimiter: Parenthesis, stream: TokenStream [Group { delimiter: None, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:47:12: 47:15 (#0) }], span: $DIR/group-compat-hack.rs:39:38: 39:43 (#28) }], span: $DIR/group-compat-hack.rs:39:37: 39:44 (#28) }, Punct { ch: ';', spacing: Alone, span: $DIR/group-compat-hack.rs:39:44: 39:45 (#28) }]
77
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/actix-web/src/extract.rs:5:21: 5:27 (#33) }, Ident { ident: "Three", span: $DIR/actix-web/src/extract.rs:5:28: 5:33 (#33) }, Group { delimiter: Parenthesis, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:54:21: 54:24 (#0) }], span: $DIR/actix-web/src/extract.rs:5:33: 5:37 (#33) }, Punct { ch: ';', spacing: Alone, span: $DIR/actix-web/src/extract.rs:5:37: 5:38 (#33) }]
8-
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/actix-web-2.0.0/src/extract.rs:5:21: 5:27 (#38) }, Ident { ident: "Three", span: $DIR/actix-web-2.0.0/src/extract.rs:5:28: 5:33 (#38) }, Group { delimiter: Parenthesis, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:61:21: 61:24 (#0) }], span: $DIR/actix-web-2.0.0/src/extract.rs:5:33: 5:37 (#38) }, Punct { ch: ';', spacing: Alone, span: $DIR/actix-web-2.0.0/src/extract.rs:5:37: 5:38 (#38) }]
9-
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/actori-web/src/extract.rs:5:21: 5:27 (#43) }, Ident { ident: "Four", span: $DIR/actori-web/src/extract.rs:5:28: 5:32 (#43) }, Group { delimiter: Parenthesis, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:68:21: 68:24 (#0) }], span: $DIR/actori-web/src/extract.rs:5:32: 5:36 (#43) }, Punct { ch: ';', spacing: Alone, span: $DIR/actori-web/src/extract.rs:5:36: 5:37 (#43) }]
10-
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/actori-web-2.0.0/src/extract.rs:5:21: 5:27 (#48) }, Ident { ident: "Four", span: $DIR/actori-web-2.0.0/src/extract.rs:5:28: 5:32 (#48) }, Group { delimiter: Parenthesis, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:75:21: 75:24 (#0) }], span: $DIR/actori-web-2.0.0/src/extract.rs:5:32: 5:36 (#48) }, Punct { ch: ';', spacing: Alone, span: $DIR/actori-web-2.0.0/src/extract.rs:5:36: 5:37 (#48) }]
8+
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/actix-web-2.0.0/src/extract.rs:5:21: 5:27 (#38) }, Ident { ident: "Three", span: $DIR/actix-web-2.0.0/src/extract.rs:5:28: 5:33 (#38) }, Group { delimiter: Parenthesis, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:62:21: 62:24 (#0) }], span: $DIR/actix-web-2.0.0/src/extract.rs:5:33: 5:37 (#38) }, Punct { ch: ';', spacing: Alone, span: $DIR/actix-web-2.0.0/src/extract.rs:5:37: 5:38 (#38) }]
9+
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/actori-web/src/extract.rs:5:21: 5:27 (#43) }, Ident { ident: "Four", span: $DIR/actori-web/src/extract.rs:5:28: 5:32 (#43) }, Group { delimiter: Parenthesis, stream: TokenStream [Group { delimiter: None, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:70:21: 70:24 (#0) }], span: $DIR/actori-web/src/extract.rs:5:33: 5:35 (#43) }], span: $DIR/actori-web/src/extract.rs:5:32: 5:36 (#43) }, Punct { ch: ';', spacing: Alone, span: $DIR/actori-web/src/extract.rs:5:36: 5:37 (#43) }]
10+
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/actori-web-2.0.0/src/extract.rs:5:21: 5:27 (#48) }, Ident { ident: "Four", span: $DIR/actori-web-2.0.0/src/extract.rs:5:28: 5:32 (#48) }, Group { delimiter: Parenthesis, stream: TokenStream [Group { delimiter: None, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:77:21: 77:24 (#0) }], span: $DIR/actori-web-2.0.0/src/extract.rs:5:33: 5:35 (#48) }], span: $DIR/actori-web-2.0.0/src/extract.rs:5:32: 5:36 (#48) }, Punct { ch: ';', spacing: Alone, span: $DIR/actori-web-2.0.0/src/extract.rs:5:36: 5:37 (#48) }]

0 commit comments

Comments
 (0)