Skip to content

Commit f851d76

Browse files
committed
use the AST pretty printer (crate rustc_ast_pretty), rustc_ast_pretty::pprust::attribute_to_string to figure the full no_mangle attribute for the error message
1 parent 7ba0447 commit f851d76

File tree

7 files changed

+26
-15
lines changed

7 files changed

+26
-15
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3442,6 +3442,7 @@ dependencies = [
34423442
"rustc_abi",
34433443
"rustc_arena",
34443444
"rustc_ast",
3445+
"rustc_ast_pretty",
34453446
"rustc_attr",
34463447
"rustc_data_structures",
34473448
"rustc_errors",

compiler/rustc_codegen_ssa/Cargo.toml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ regex = "1.4"
1717
rustc_abi = { path = "../rustc_abi" }
1818
rustc_arena = { path = "../rustc_arena" }
1919
rustc_ast = { path = "../rustc_ast" }
20+
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
2021
rustc_attr = { path = "../rustc_attr" }
2122
rustc_data_structures = { path = "../rustc_data_structures" }
2223
rustc_errors = { path = "../rustc_errors" }
@@ -54,8 +55,18 @@ libc = "0.2.50"
5455
[dependencies.object]
5556
version = "0.36.2"
5657
default-features = false
57-
features = ["read_core", "elf", "macho", "pe", "xcoff", "unaligned", "archive", "write", "wasm"]
58+
features = [
59+
"read_core",
60+
"elf",
61+
"macho",
62+
"pe",
63+
"xcoff",
64+
"unaligned",
65+
"archive",
66+
"write",
67+
"wasm",
68+
]
5869

5970
[target.'cfg(windows)'.dependencies.windows]
6071
version = "0.57.0"
61-
features = ["Win32_Globalization"]
72+
features = ["Win32_Globalization"]

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ codegen_ssa_missing_memory_ordering = Atomic intrinsic missing memory ordering
190190
codegen_ssa_missing_query_depgraph =
191191
found CGU-reuse attribute but `-Zquery-dep-graph` was not specified
192192
193-
codegen_ssa_mixed_export_name_and_no_mangle = the `#[{$no_mangle_attr_name}]` attribute may not be used in combination with `#[export_name]`
194-
.label = `#[{$no_mangle_attr_name}]` is ignored
193+
codegen_ssa_mixed_export_name_and_no_mangle = the `{$no_mangle_attr_name}` attribute may not be used in combination with `#[export_name]`
194+
.label = `{$no_mangle_attr_name}` is ignored
195195
.note = `#[export_name]` takes precedence
196-
.suggestion = remove the `#[{$no_mangle_attr_name}]` attribute
196+
.suggestion = remove the `{$no_mangle_attr_name}` attribute
197197
198198
codegen_ssa_msvc_missing_linker = the msvc targets depend on the msvc linker but `link.exe` was not found
199199

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
120120
mixed_export_name_no_mangle_lint_state.track_no_mangle(
121121
attr.span,
122122
tcx.local_def_id_to_hir_id(did),
123-
name.to_ident_string().into(),
123+
rustc_ast_pretty::pprust::attribute_to_string(attr),
124124
);
125125
} else {
126126
tcx.dcx()

tests/ui/attributes/mixed_export_name_and_no_mangle.fixed

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
//@ check-pass
44

55
#![warn(unused_attributes)]
6-
//~^ WARN the `#[no_mangle]` attribute may not be used in combination with `#[export_name]`
6+
//~^ WARN the `#[no_mangle]` attribute may not be used in combination with `#[export_name]` [unused_attributes]
77
#[export_name = "foo"]
88
pub fn bar() {}
99

10-
//~^ WARN the `#[unsafe(no_mangle)]` attribute may not be used in combination with `#[export_name]`
10+
//~^ WARN the `#[unsafe(no_mangle)]` attribute may not be used in combination with `#[export_name]` [unused_attributes]
1111
#[export_name = "baz"]
1212
pub fn bak() {}
1313

14-
1514
fn main() {}

tests/ui/attributes/mixed_export_name_and_no_mangle.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
#![warn(unused_attributes)]
66
#[no_mangle]
7-
//~^ WARN the `#[no_mangle]` attribute may not be used in combination with `#[export_name]`
7+
//~^ WARN the `#[no_mangle]` attribute may not be used in combination with `#[export_name]` [unused_attributes]
88
#[export_name = "foo"]
99
pub fn bar() {}
1010

1111
#[unsafe(no_mangle)]
12-
//~^ WARN the `#[unsafe(no_mangle)]` attribute may not be used in combination with `#[export_name]`
12+
//~^ WARN the `#[unsafe(no_mangle)]` attribute may not be used in combination with `#[export_name]` [unused_attributes]
1313
#[export_name = "baz"]
1414
pub fn bak() {}
1515

16-
1716
fn main() {}

tests/ui/attributes/mixed_export_name_and_no_mangle.stderr

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,21 @@ help: remove the `#[no_mangle]` attribute
1919
LL - #[no_mangle]
2020
|
2121

22-
warning: the `#[unsafe(no_mangle)]` attribute may not be used in combination with `#[export_name]`
22+
warning: the `#[no_mangle]` attribute may not be used in combination with `#[export_name]`
2323
--> $DIR/mixed_export_name_and_no_mangle.rs:11:1
2424
|
2525
LL | #[unsafe(no_mangle)]
26-
| ^^^^^^^^^^^^^^^^^^^^ #[unsafe(no_mangle)]` is ignored
26+
| ^^^^^^^^^^^^^^^^^^^^ `#[no_mangle]` is ignored
2727
|
2828
note: `#[export_name]` takes precedence
2929
--> $DIR/mixed_export_name_and_no_mangle.rs:13:1
3030
|
3131
LL | #[export_name = "baz"]
3232
| ^^^^^^^^^^^^^^^^^^^^^^
33-
help: remove the #[unsafe(no_mangle)]` attribute
33+
help: remove the `#[no_mangle]` attribute
3434
|
3535
LL - #[unsafe(no_mangle)]
3636
|
3737

3838
warning: 2 warnings emitted
39+

0 commit comments

Comments
 (0)