Skip to content

Commit f6a35d7

Browse files
committed
Extend proc_macro_back_compat lint to js-sys
With this PR, we now lint for all cases where we perform some kind of proc-macro back-compat hack. The `js-sys` had an internal fix made to properly handle `None`-delimited groups, so we need to manually check the version in the filename. As a result, we no longer apply the back-compat hack to cases where the version number is missing file the file path. This should not affect any users of the `crates.io` crate.
1 parent 9f4bc3e commit f6a35d7

File tree

5 files changed

+90
-16
lines changed

5 files changed

+90
-16
lines changed

compiler/rustc_expand/src/proc_macro_server.rs

+30-4
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,8 @@ fn ident_name_compatibility_hack(
739739

740740
let time_macros_impl =
741741
macro_name == sym::impl_macros && matches_prefix("time-macros-impl", "lib.rs");
742-
if time_macros_impl
743-
|| (macro_name == sym::arrays && matches_prefix("js-sys", "lib.rs"))
744-
{
742+
let js_sys = macro_name == sym::arrays && matches_prefix("js-sys", "lib.rs");
743+
if time_macros_impl || js_sys {
745744
let snippet = source_map.span_to_snippet(orig_span);
746745
if snippet.as_deref() == Ok("$name") {
747746
if time_macros_impl {
@@ -754,8 +753,35 @@ fn ident_name_compatibility_hack(
754753
"the `time-macros-impl` crate will stop compiling in futures version of Rust. \
755754
Please update to the latest version of the `time` crate to avoid breakage".to_string())
756755
);
756+
return Some((*ident, *is_raw));
757+
}
758+
if js_sys {
759+
if let Some(c) = path
760+
.components()
761+
.flat_map(|c| c.as_os_str().to_str())
762+
.find(|c| c.starts_with("js-sys"))
763+
{
764+
let mut version = c.trim_start_matches("js-sys-").split(".");
765+
if version.next() == Some("0")
766+
&& version.next() == Some("3")
767+
&& version
768+
.next()
769+
.and_then(|c| c.parse::<u32>().ok())
770+
.map_or(false, |v| v < 40)
771+
{
772+
rustc.sess.buffer_lint_with_diagnostic(
773+
&PROC_MACRO_BACK_COMPAT,
774+
orig_span,
775+
ast::CRATE_NODE_ID,
776+
"using an old version of `js-sys`",
777+
BuiltinLintDiagnostics::ProcMacroBackCompat(
778+
"older versions of the `js-sys` crate will stop compiling in future versions of Rust; \
779+
please update to `js-sys` v0.3.40 or above".to_string())
780+
);
781+
return Some((*ident, *is_raw));
782+
}
783+
}
757784
}
758-
return Some((*ident, *is_raw));
759785
}
760786
}
761787

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

+8-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ mod with_version {
4343
struct Foo;
4444
impl_macros!(Foo); //~ WARN using an old version
4545
//~| WARN this was previously
46-
arrays!(Foo);
46+
arrays!(Foo); //~ WARN using an old version
47+
//~| WARN this was previously
4748
other!(Foo);
4849
}
4950

@@ -77,5 +78,11 @@ mod actori_web_version_test {
7778
tuple_from_req!(Foo);
7879
}
7980

81+
mod with_good_js_sys_version {
82+
include!("js-sys-0.3.40/src/lib.rs");
83+
struct Foo;
84+
arrays!(Foo);
85+
}
86+
8087

8188
fn main() {}

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

+38-5
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,29 @@ 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: using an old version of `js-sys`
35+
--> $DIR/js-sys-0.3.17/src/lib.rs:5:32
36+
|
37+
LL | #[my_macro] struct Two($name);
38+
| ^^^^^
39+
|
40+
::: $DIR/group-compat-hack.rs:46:5
41+
|
42+
LL | arrays!(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: older versions of the `js-sys` crate will stop compiling in future versions of Rust; please update to `js-sys` v0.3.40 or above
48+
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
49+
3450
warning: using an old version of `actix-web`
3551
--> $DIR/actix-web/src/extract.rs:5:34
3652
|
3753
LL | #[my_macro] struct Three($T);
3854
| ^^
3955
|
40-
::: $DIR/group-compat-hack.rs:54:5
56+
::: $DIR/group-compat-hack.rs:55:5
4157
|
4258
LL | tuple_from_req!(Foo);
4359
| --------------------- in this macro invocation
@@ -53,7 +69,7 @@ warning: using an old version of `actix-web`
5369
LL | #[my_macro] struct Three($T);
5470
| ^^
5571
|
56-
::: $DIR/group-compat-hack.rs:62:5
72+
::: $DIR/group-compat-hack.rs:63:5
5773
|
5874
LL | tuple_from_req!(Foo);
5975
| --------------------- in this macro invocation
@@ -63,7 +79,7 @@ LL | tuple_from_req!(Foo);
6379
= 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
6480
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
6581

66-
warning: 4 warnings emitted
82+
warning: 5 warnings emitted
6783

6884
Future incompatibility report: Future breakage date: None, diagnostic:
6985
warning: using an old version of `time-macros-impl`
@@ -100,14 +116,31 @@ LL | impl_macros!(Foo);
100116
= 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
101117
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
102118

119+
Future breakage date: None, diagnostic:
120+
warning: using an old version of `js-sys`
121+
--> $DIR/js-sys-0.3.17/src/lib.rs:5:32
122+
|
123+
LL | #[my_macro] struct Two($name);
124+
| ^^^^^
125+
|
126+
::: $DIR/group-compat-hack.rs:46:5
127+
|
128+
LL | arrays!(Foo);
129+
| ------------- in this macro invocation
130+
|
131+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
132+
= note: for more information, see issue #83125 <https://github.com/rust-lang/rust/issues/83125>
133+
= note: older versions of the `js-sys` crate will stop compiling in future versions of Rust; please update to `js-sys` v0.3.40 or above
134+
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
135+
103136
Future breakage date: None, diagnostic:
104137
warning: using an old version of `actix-web`
105138
--> $DIR/actix-web/src/extract.rs:5:34
106139
|
107140
LL | #[my_macro] struct Three($T);
108141
| ^^
109142
|
110-
::: $DIR/group-compat-hack.rs:54:5
143+
::: $DIR/group-compat-hack.rs:55:5
111144
|
112145
LL | tuple_from_req!(Foo);
113146
| --------------------- in this macro invocation
@@ -124,7 +157,7 @@ warning: using an old version of `actix-web`
124157
LL | #[my_macro] struct Three($T);
125158
| ^^
126159
|
127-
::: $DIR/group-compat-hack.rs:62:5
160+
::: $DIR/group-compat-hack.rs:63:5
128161
|
129162
LL | tuple_from_req!(Foo);
130163
| --------------------- in this macro invocation
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/time-macros-impl/src/lib.rs:5:21: 5:27 (#6) }, Ident { ident: "One", span: $DIR/time-macros-impl/src/lib.rs:5:28: 5:31 (#6) }, Group { delimiter: Parenthesis, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:27:18: 27:21 (#0) }], span: $DIR/time-macros-impl/src/lib.rs:5:31: 5:38 (#6) }, Punct { ch: ';', spacing: Alone, span: $DIR/time-macros-impl/src/lib.rs:5:38: 5:39 (#6) }]
2-
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/js-sys/src/lib.rs:5:21: 5:27 (#10) }, Ident { ident: "Two", span: $DIR/js-sys/src/lib.rs:5:28: 5:31 (#10) }, Group { delimiter: Parenthesis, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:29:13: 29:16 (#0) }], span: $DIR/js-sys/src/lib.rs:5:31: 5:38 (#10) }, Punct { ch: ';', spacing: Alone, span: $DIR/js-sys/src/lib.rs:5:38: 5:39 (#10) }]
2+
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/js-sys/src/lib.rs:5:21: 5:27 (#10) }, Ident { ident: "Two", span: $DIR/js-sys/src/lib.rs:5:28: 5:31 (#10) }, Group { delimiter: Parenthesis, stream: TokenStream [Group { delimiter: None, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:29:13: 29:16 (#0) }], span: $DIR/js-sys/src/lib.rs:5:32: 5:37 (#10) }], span: $DIR/js-sys/src/lib.rs:5:31: 5:38 (#10) }, Punct { ch: ';', spacing: Alone, span: $DIR/js-sys/src/lib.rs:5:38: 5:39 (#10) }]
33
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/group-compat-hack.rs:22:25: 22:31 (#14) }, Ident { ident: "Three", span: $DIR/group-compat-hack.rs:22:32: 22:37 (#14) }, Group { delimiter: Parenthesis, stream: TokenStream [Group { delimiter: None, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:30:12: 30:15 (#0) }], span: $DIR/group-compat-hack.rs:22:38: 22:43 (#14) }], span: $DIR/group-compat-hack.rs:22:37: 22:44 (#14) }, Punct { ch: ';', spacing: Alone, span: $DIR/group-compat-hack.rs:22:44: 22:45 (#14) }]
44
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/time-macros-impl-0.1.0/src/lib.rs:5:21: 5:27 (#20) }, Ident { ident: "One", span: $DIR/time-macros-impl-0.1.0/src/lib.rs:5:28: 5:31 (#20) }, Group { delimiter: Parenthesis, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:44:18: 44:21 (#0) }], span: $DIR/time-macros-impl-0.1.0/src/lib.rs:5:31: 5:38 (#20) }, Punct { ch: ';', spacing: Alone, span: $DIR/time-macros-impl-0.1.0/src/lib.rs:5:38: 5:39 (#20) }]
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) }]
6-
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) }]
7-
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: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) }]
6+
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:48:12: 48: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) }]
7+
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:55:21: 55: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:63:21: 63: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:71:21: 71: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:78:21: 78: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) }]
11+
Called proc_macro_hack with TokenStream [Ident { ident: "struct", span: $DIR/js-sys-0.3.40/src/lib.rs:5:21: 5:27 (#53) }, Ident { ident: "Two", span: $DIR/js-sys-0.3.40/src/lib.rs:5:28: 5:31 (#53) }, Group { delimiter: Parenthesis, stream: TokenStream [Group { delimiter: None, stream: TokenStream [Ident { ident: "Foo", span: $DIR/group-compat-hack.rs:84:13: 84:16 (#0) }], span: $DIR/js-sys-0.3.40/src/lib.rs:5:32: 5:37 (#53) }], span: $DIR/js-sys-0.3.40/src/lib.rs:5:31: 5:38 (#53) }, Punct { ch: ';', spacing: Alone, span: $DIR/js-sys-0.3.40/src/lib.rs:5:38: 5:39 (#53) }]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// ignore-test this is not a test
2+
3+
macro_rules! arrays {
4+
($name:ident) => {
5+
#[my_macro] struct Two($name);
6+
}
7+
}

0 commit comments

Comments
 (0)