Skip to content

Commit 1c85a1d

Browse files
Make #[link="dl"] a warning rather than an error
1 parent 5c95f8b commit 1c85a1d

File tree

4 files changed

+47
-28
lines changed

4 files changed

+47
-28
lines changed

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,22 @@ impl<S: Stage> CombineAttributeParser<S> for LinkParser {
6565
cx: &'c mut AcceptContext<'_, '_, S>,
6666
args: &'c ArgParser<'_>,
6767
) -> impl IntoIterator<Item = Self::Item> + 'c {
68-
let mut result = None;
69-
let Some(items) = args.list() else {
70-
cx.expected_list(cx.attr_span);
71-
return result;
68+
let items = match args {
69+
ArgParser::List(list) => list,
70+
// This is an edgecase added because making this a hard error would break too many crates
71+
// Specifically `#[link = "dl"]` is accepted with a FCW
72+
// For more information, see https://github.com/rust-lang/rust/pull/143193
73+
ArgParser::NameValue(nv) if nv.value_as_str().is_some_and(|v| v == sym::dl) => {
74+
let suggestions = <Self as CombineAttributeParser<S>>::TEMPLATE
75+
.suggestions(cx.attr_style, "link");
76+
let span = cx.attr_span;
77+
cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
78+
return None;
79+
}
80+
_ => {
81+
cx.expected_list(cx.attr_span);
82+
return None;
83+
}
7284
};
7385

7486
let sess = cx.sess();
@@ -113,7 +125,7 @@ impl<S: Stage> CombineAttributeParser<S> for LinkParser {
113125
}
114126
};
115127
if !cont {
116-
return result;
128+
return None;
117129
}
118130
}
119131

@@ -202,7 +214,7 @@ impl<S: Stage> CombineAttributeParser<S> for LinkParser {
202214
}
203215
let Some((name, name_span)) = name else {
204216
cx.emit_err(LinkRequiresName { span: cx.attr_span });
205-
return result;
217+
return None;
206218
};
207219

208220
// Do this outside of the loop so that `import_name_type` can be specified before `kind`.
@@ -218,15 +230,14 @@ impl<S: Stage> CombineAttributeParser<S> for LinkParser {
218230
cx.emit_err(RawDylibNoNul { span: name_span });
219231
}
220232

221-
result = Some(LinkEntry {
233+
Some(LinkEntry {
222234
span: cx.attr_span,
223235
kind: kind.unwrap_or(NativeLibKind::Unspecified),
224236
name,
225237
cfg,
226238
verbatim,
227239
import_name_type,
228-
});
229-
result
240+
})
230241
}
231242
}
232243

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ symbols! {
873873
div,
874874
div_assign,
875875
diverging_block_default,
876+
dl,
876877
do_not_recommend,
877878
doc,
878879
doc_alias,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Future incompatibility report: Future breakage diagnostic:
2+
warning: valid forms for the attribute are `#[link(name = "...")]`, `#[link(name = "...", import_name_type = "decorated|noprefix|undecorated")]`, `#[link(name = "...", kind = "dylib|static|...")]`, `#[link(name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated")]`, and `#[link(name = "...", wasm_import_module = "...")]`
3+
--> $DIR/link-dl.rs:14:1
4+
|
5+
LL | #[link="dl"]
6+
| ^^^^^^^^^^^^
7+
|
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
10+
Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
error[E0539]: malformed `link` attribute input
1+
error: valid forms for the attribute are `#[link(name = "...")]`, `#[link(name = "...", import_name_type = "decorated|noprefix|undecorated")]`, `#[link(name = "...", kind = "dylib|static|...")]`, `#[link(name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated")]`, and `#[link(name = "...", wasm_import_module = "...")]`
22
--> $DIR/link-dl.rs:14:1
33
|
44
LL | #[link="dl"]
5-
| ^^^^^^^^^^^^ expected this to be a list
5+
| ^^^^^^^^^^^^
66
|
7-
= note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute>
8-
help: try changing it to one of the following valid forms of the attribute
9-
|
10-
LL - #[link="dl"]
11-
LL + #[link(name = "...")]
12-
|
13-
LL - #[link="dl"]
14-
LL + #[link(name = "...", import_name_type = "decorated|noprefix|undecorated")]
15-
|
16-
LL - #[link="dl"]
17-
LL + #[link(name = "...", kind = "dylib|static|...")]
18-
|
19-
LL - #[link="dl"]
20-
LL + #[link(name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated")]
21-
|
22-
= and 1 other candidate
7+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
9+
= note: `#[deny(ill_formed_attribute_input)]` (part of `#[deny(future_incompatible)]`) on by default
2310

2411
error: aborting due to 1 previous error
2512

26-
For more information about this error, try `rustc --explain E0539`.
13+
Future incompatibility report: Future breakage diagnostic:
14+
error: valid forms for the attribute are `#[link(name = "...")]`, `#[link(name = "...", import_name_type = "decorated|noprefix|undecorated")]`, `#[link(name = "...", kind = "dylib|static|...")]`, `#[link(name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated")]`, and `#[link(name = "...", wasm_import_module = "...")]`
15+
--> $DIR/link-dl.rs:14:1
16+
|
17+
LL | #[link="dl"]
18+
| ^^^^^^^^^^^^
19+
|
20+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
21+
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
22+
= note: `#[deny(ill_formed_attribute_input)]` (part of `#[deny(future_incompatible)]`) on by default
23+

0 commit comments

Comments
 (0)