Skip to content

Commit 08d9bc5

Browse files
authored
Unrolled build for #147262
Rollup merge of #147262 - JonathanBrouwer:fix-link, r=jieyouxu Make #[link="dl"] an FCW rather than an error Fixes #147254 I forgot to implement the T-lang decision in #143193 (comment), this implements that decision r? ``@jdonszelmann`` Can be reviewed commit-by-commit This needs a beta backport
2 parents e2c96cc + 1c85a1d commit 08d9bc5

File tree

5 files changed

+73
-9
lines changed

5 files changed

+73
-9
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
@@ -874,6 +874,7 @@ symbols! {
874874
div,
875875
div_assign,
876876
diverging_block_default,
877+
dl,
877878
do_not_recommend,
878879
doc,
879880
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 = "...")]`
2+
--> $DIR/link-dl.rs:14:1
3+
|
4+
LL | #[link="dl"]
5+
| ^^^^^^^^^^^^
6+
|
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
10+
11+
error: aborting due to 1 previous error
12+
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+

tests/ui/attributes/link-dl.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Regression test for an issue discovered in https://github.com/rust-lang/rust/pull/143193/files and rediscovered in https://github.com/rust-lang/rust/issues/147254#event-20049906781
2+
// Malformed #[link] attribute was supposed to be deny-by-default report-in-deps FCW,
3+
// but accidentally was landed as a hard error.
4+
//
5+
// revision `default_fcw` tests that with `ill_formed_attribute_input` (the default) denied,
6+
// the attribute produces an FCW
7+
// revision `allowed` tests that with `ill_formed_attribute_input` allowed the test passes
8+
9+
//@ revisions: default_fcw allowed
10+
//@[allowed] check-pass
11+
12+
#[cfg_attr(allowed, allow(ill_formed_attribute_input))]
13+
14+
#[link="dl"]
15+
//[default_fcw]~^ ERROR valid forms for the attribute are
16+
//[default_fcw]~| WARN previously accepted
17+
extern "C" { }
18+
19+
fn main() {}

0 commit comments

Comments
 (0)