Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5a19ffe

Browse files
committedAug 13, 2021
Auto merge of #86492 - hyd-dev:no-mangle-method, r=petrochenkov
Associated functions that contain extern indicator or have `#[rustc_std_internal_symbol]` are reachable Previously these fails to link with ``undefined reference to `foo'``: <details> <summary>Example 1</summary> ```rs struct AssocFn; impl AssocFn { #[no_mangle] fn foo() {} } fn main() { extern "Rust" { fn foo(); } unsafe { foo() } } ``` ([Playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=f1244afcdd26e2a28445f6e82ca46b50)) </details> <details> <summary>Example 2</summary> ```rs #![crate_name = "lib"] #![crate_type = "lib"] struct AssocFn; impl AssocFn { #[no_mangle] fn foo() {} } ``` ```rs extern crate lib; fn main() { extern "Rust" { fn foo(); } unsafe { foo() } } ``` </details> But I believe they should link successfully, because this works: <details> ```rs #[no_mangle] fn foo() {} fn main() { extern "Rust" { fn foo(); } unsafe { foo() } } ``` ([Playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=789b3f283ee6126f53939429103ed98d)) </details> This PR fixes the problem, by adding associated functions that have "custom linkage" to `reachable_set`, just like normal functions. I haven't tested whether #76211 and [Miri](rust-lang/miri#1837) are fixed by this PR yet, but I'm submitting this anyway since this fixes the examples above. I added a `run-pass` test that combines my two examples above, but I'm not sure if that's the right way to test this. Maybe I should add / modify an existing codegen test (`src/test/codegen/export-no-mangle.rs`?) instead?
2 parents 881aeab + 9315a0c commit 5a19ffe

19 files changed

+920
-251
lines changed
 

‎compiler/rustc_ast_passes/src/ast_validation.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14991499
}
15001500

15011501
fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) {
1502+
if self.session.contains_name(&item.attrs, sym::no_mangle) {
1503+
self.check_nomangle_item_asciionly(item.ident, item.span);
1504+
}
1505+
15021506
if ctxt == AssocCtxt::Trait || !self.in_trait_impl {
15031507
self.check_defaultness(item.span, item.kind.defaultness());
15041508
}

‎compiler/rustc_lint/src/builtin.rs

+64-22
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,25 @@ impl EarlyLintPass for UnsafeCode {
417417
}
418418
}
419419

420+
fn check_impl_item(&mut self, cx: &EarlyContext<'_>, it: &ast::AssocItem) {
421+
if let ast::AssocItemKind::Fn(..) = it.kind {
422+
if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::no_mangle) {
423+
self.report_overriden_symbol_name(
424+
cx,
425+
attr.span,
426+
"declaration of a `no_mangle` method",
427+
);
428+
}
429+
if let Some(attr) = cx.sess().find_by_name(&it.attrs, sym::export_name) {
430+
self.report_overriden_symbol_name(
431+
cx,
432+
attr.span,
433+
"declaration of a method with `export_name`",
434+
);
435+
}
436+
}
437+
}
438+
420439
fn check_fn(&mut self, cx: &EarlyContext<'_>, fk: FnKind<'_>, span: Span, _: ast::NodeId) {
421440
if let FnKind::Fn(
422441
ctxt,
@@ -1115,31 +1134,37 @@ declare_lint_pass!(InvalidNoMangleItems => [NO_MANGLE_CONST_ITEMS, NO_MANGLE_GEN
11151134
impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
11161135
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
11171136
let attrs = cx.tcx.hir().attrs(it.hir_id());
1137+
let check_no_mangle_on_generic_fn = |no_mangle_attr: &ast::Attribute,
1138+
impl_generics: Option<&hir::Generics<'_>>,
1139+
generics: &hir::Generics<'_>,
1140+
span| {
1141+
for param in
1142+
generics.params.iter().chain(impl_generics.map(|g| g.params).into_iter().flatten())
1143+
{
1144+
match param.kind {
1145+
GenericParamKind::Lifetime { .. } => {}
1146+
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
1147+
cx.struct_span_lint(NO_MANGLE_GENERIC_ITEMS, span, |lint| {
1148+
lint.build("functions generic over types or consts must be mangled")
1149+
.span_suggestion_short(
1150+
no_mangle_attr.span,
1151+
"remove this attribute",
1152+
String::new(),
1153+
// Use of `#[no_mangle]` suggests FFI intent; correct
1154+
// fix may be to monomorphize source by hand
1155+
Applicability::MaybeIncorrect,
1156+
)
1157+
.emit();
1158+
});
1159+
break;
1160+
}
1161+
}
1162+
}
1163+
};
11181164
match it.kind {
11191165
hir::ItemKind::Fn(.., ref generics, _) => {
11201166
if let Some(no_mangle_attr) = cx.sess().find_by_name(attrs, sym::no_mangle) {
1121-
for param in generics.params {
1122-
match param.kind {
1123-
GenericParamKind::Lifetime { .. } => {}
1124-
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
1125-
cx.struct_span_lint(NO_MANGLE_GENERIC_ITEMS, it.span, |lint| {
1126-
lint.build(
1127-
"functions generic over types or consts must be mangled",
1128-
)
1129-
.span_suggestion_short(
1130-
no_mangle_attr.span,
1131-
"remove this attribute",
1132-
String::new(),
1133-
// Use of `#[no_mangle]` suggests FFI intent; correct
1134-
// fix may be to monomorphize source by hand
1135-
Applicability::MaybeIncorrect,
1136-
)
1137-
.emit();
1138-
});
1139-
break;
1140-
}
1141-
}
1142-
}
1167+
check_no_mangle_on_generic_fn(no_mangle_attr, None, generics, it.span);
11431168
}
11441169
}
11451170
hir::ItemKind::Const(..) => {
@@ -1170,6 +1195,23 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
11701195
});
11711196
}
11721197
}
1198+
hir::ItemKind::Impl(hir::Impl { ref generics, items, .. }) => {
1199+
for it in items {
1200+
if let hir::AssocItemKind::Fn { .. } = it.kind {
1201+
if let Some(no_mangle_attr) = cx
1202+
.sess()
1203+
.find_by_name(cx.tcx.hir().attrs(it.id.hir_id()), sym::no_mangle)
1204+
{
1205+
check_no_mangle_on_generic_fn(
1206+
no_mangle_attr,
1207+
Some(generics),
1208+
cx.tcx.hir().get_generics(it.id.def_id.to_def_id()).unwrap(),
1209+
it.span,
1210+
);
1211+
}
1212+
}
1213+
}
1214+
}
11731215
_ => {}
11741216
}
11751217
}

‎compiler/rustc_lint/src/nonstandard_style.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,14 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
391391
_: Span,
392392
id: hir::HirId,
393393
) {
394+
let attrs = cx.tcx.hir().attrs(id);
394395
match &fk {
395-
FnKind::Method(ident, ..) => match method_context(cx, id) {
396+
FnKind::Method(ident, sig, ..) => match method_context(cx, id) {
396397
MethodLateContext::PlainImpl => {
398+
if sig.header.abi != Abi::Rust && cx.sess().contains_name(attrs, sym::no_mangle)
399+
{
400+
return;
401+
}
397402
self.check_snake_case(cx, "method", ident);
398403
}
399404
MethodLateContext::TraitAutoImpl => {
@@ -402,7 +407,6 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
402407
_ => (),
403408
},
404409
FnKind::ItemFn(ident, _, header, _) => {
405-
let attrs = cx.tcx.hir().attrs(id);
406410
// Skip foreign-ABI #[no_mangle] functions (Issue #31924)
407411
if header.abi != Abi::Rust && cx.sess().contains_name(attrs, sym::no_mangle) {
408412
return;

‎compiler/rustc_passes/src/check_attr.rs

+20-12
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,10 @@ impl CheckAttrVisitor<'tcx> {
962962
}
963963
}
964964

965+
fn is_impl_item(&self, hir_id: HirId) -> bool {
966+
matches!(self.tcx.hir().get(hir_id), hir::Node::ImplItem(..))
967+
}
968+
965969
/// Checks if `#[export_name]` is applied to a function or static. Returns `true` if valid.
966970
fn check_export_name(
967971
&self,
@@ -971,7 +975,8 @@ impl CheckAttrVisitor<'tcx> {
971975
target: Target,
972976
) -> bool {
973977
match target {
974-
Target::Static | Target::Fn | Target::Method(..) => true,
978+
Target::Static | Target::Fn => true,
979+
Target::Method(..) if self.is_impl_item(hir_id) => true,
975980
// FIXME(#80564): We permit struct fields, match arms and macro defs to have an
976981
// `#[export_name]` attribute with just a lint, because we previously
977982
// erroneously allowed it and some crates used it accidentally, to to be compatible
@@ -985,9 +990,9 @@ impl CheckAttrVisitor<'tcx> {
985990
.sess
986991
.struct_span_err(
987992
attr.span,
988-
"attribute should be applied to a function or static",
993+
"attribute should be applied to a free function, impl method or static",
989994
)
990-
.span_label(*span, "not a function or static")
995+
.span_label(*span, "not a free function, impl method or static")
991996
.emit();
992997
false
993998
}
@@ -1169,7 +1174,8 @@ impl CheckAttrVisitor<'tcx> {
11691174
/// Checks if `#[no_mangle]` is applied to a function or static.
11701175
fn check_no_mangle(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
11711176
match target {
1172-
Target::Static | Target::Fn | Target::Method(..) => {}
1177+
Target::Static | Target::Fn => {}
1178+
Target::Method(..) if self.is_impl_item(hir_id) => {}
11731179
// FIXME(#80564): We permit struct fields, match arms and macro defs to have an
11741180
// `#[no_mangle]` attribute with just a lint, because we previously
11751181
// erroneously allowed it and some crates used it accidentally, to to be compatible
@@ -1181,14 +1187,16 @@ impl CheckAttrVisitor<'tcx> {
11811187
// FIXME: #[no_mangle] was previously allowed on non-functions/statics and some
11821188
// crates used this, so only emit a warning.
11831189
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
1184-
lint.build("attribute should be applied to a function or static")
1185-
.warn(
1186-
"this was previously accepted by the compiler but is \
1187-
being phased out; it will become a hard error in \
1188-
a future release!",
1189-
)
1190-
.span_label(*span, "not a function or static")
1191-
.emit();
1190+
lint.build(
1191+
"attribute should be applied to a free function, impl method or static",
1192+
)
1193+
.warn(
1194+
"this was previously accepted by the compiler but is \
1195+
being phased out; it will become a hard error in \
1196+
a future release!",
1197+
)
1198+
.span_label(*span, "not a free function, impl method or static")
1199+
.emit();
11921200
});
11931201
}
11941202
}

‎compiler/rustc_passes/src/reachable.rs

+21-13
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,15 @@ impl<'tcx> ReachableContext<'tcx> {
211211
if !self.any_library {
212212
// If we are building an executable, only explicitly extern
213213
// types need to be exported.
214-
if let Node::Item(item) = *node {
215-
let reachable = if let hir::ItemKind::Fn(ref sig, ..) = item.kind {
216-
sig.header.abi != Abi::Rust
217-
} else {
218-
false
219-
};
220-
let codegen_attrs = self.tcx.codegen_fn_attrs(item.def_id);
214+
if let Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), def_id, .. })
215+
| Node::ImplItem(hir::ImplItem {
216+
kind: hir::ImplItemKind::Fn(sig, ..),
217+
def_id,
218+
..
219+
}) = *node
220+
{
221+
let reachable = sig.header.abi != Abi::Rust;
222+
let codegen_attrs = self.tcx.codegen_fn_attrs(*def_id);
221223
let is_extern = codegen_attrs.contains_extern_indicator();
222224
let std_internal =
223225
codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL);
@@ -335,17 +337,23 @@ struct CollectPrivateImplItemsVisitor<'a, 'tcx> {
335337
worklist: &'a mut Vec<LocalDefId>,
336338
}
337339

338-
impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx> {
339-
fn visit_item(&mut self, item: &hir::Item<'_>) {
340+
impl CollectPrivateImplItemsVisitor<'_, '_> {
341+
fn push_to_worklist_if_has_custom_linkage(&mut self, def_id: LocalDefId) {
340342
// Anything which has custom linkage gets thrown on the worklist no
341343
// matter where it is in the crate, along with "special std symbols"
342344
// which are currently akin to allocator symbols.
343-
let codegen_attrs = self.tcx.codegen_fn_attrs(item.def_id);
345+
let codegen_attrs = self.tcx.codegen_fn_attrs(def_id);
344346
if codegen_attrs.contains_extern_indicator()
345347
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL)
346348
{
347-
self.worklist.push(item.def_id);
349+
self.worklist.push(def_id);
348350
}
351+
}
352+
}
353+
354+
impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx> {
355+
fn visit_item(&mut self, item: &hir::Item<'_>) {
356+
self.push_to_worklist_if_has_custom_linkage(item.def_id);
349357

350358
// We need only trait impls here, not inherent impls, and only non-exported ones
351359
if let hir::ItemKind::Impl(hir::Impl { of_trait: Some(ref trait_ref), ref items, .. }) =
@@ -375,8 +383,8 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
375383

376384
fn visit_trait_item(&mut self, _trait_item: &hir::TraitItem<'_>) {}
377385

378-
fn visit_impl_item(&mut self, _impl_item: &hir::ImplItem<'_>) {
379-
// processed in visit_item above
386+
fn visit_impl_item(&mut self, impl_item: &hir::ImplItem<'_>) {
387+
self.push_to_worklist_if_has_custom_linkage(impl_item.def_id);
380388
}
381389

382390
fn visit_foreign_item(&mut self, _foreign_item: &hir::ForeignItem<'_>) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![crate_type = "lib"]
2+
3+
struct Bar;
4+
5+
impl Bar {
6+
#[no_mangle]
7+
fn bar() -> u8 {
8+
2
9+
}
10+
}
11+
12+
trait Foo {
13+
fn baz() -> u8;
14+
}
15+
16+
impl Foo for Bar {
17+
#[no_mangle]
18+
fn baz() -> u8 {
19+
3
20+
}
21+
}

‎src/test/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.rs

+22-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//~ NOTE: not an `extern crate` item
2-
//~^ NOTE: not a function or static
2+
//~^ NOTE: not a free function, impl method or static
33
//~^^ NOTE: not a function or closure
44
// This is testing whether various builtin attributes signals an
55
// error or warning when put in "weird" places.
@@ -25,7 +25,7 @@
2525
#![no_link]
2626
//~^ ERROR: attribute should be applied to an `extern crate` item
2727
#![export_name = "2200"]
28-
//~^ ERROR: attribute should be applied to a function or static
28+
//~^ ERROR: attribute should be applied to a free function, impl method or static
2929
#![inline]
3030
//~^ ERROR: attribute should be applied to function or closure
3131
#[inline]
@@ -83,27 +83,37 @@ mod no_link {
8383
}
8484

8585
#[export_name = "2200"]
86-
//~^ ERROR attribute should be applied to a function or static
86+
//~^ ERROR attribute should be applied to a free function, impl method or static
8787
mod export_name {
88-
//~^ NOTE not a function or static
88+
//~^ NOTE not a free function, impl method or static
8989

9090
mod inner { #![export_name="2200"] }
91-
//~^ ERROR attribute should be applied to a function or static
92-
//~| NOTE not a function or static
91+
//~^ ERROR attribute should be applied to a free function, impl method or static
92+
//~| NOTE not a free function, impl method or static
9393

9494
#[export_name = "2200"] fn f() { }
9595

9696
#[export_name = "2200"] struct S;
97-
//~^ ERROR attribute should be applied to a function or static
98-
//~| NOTE not a function or static
97+
//~^ ERROR attribute should be applied to a free function, impl method or static
98+
//~| NOTE not a free function, impl method or static
9999

100100
#[export_name = "2200"] type T = S;
101-
//~^ ERROR attribute should be applied to a function or static
102-
//~| NOTE not a function or static
101+
//~^ ERROR attribute should be applied to a free function, impl method or static
102+
//~| NOTE not a free function, impl method or static
103103

104104
#[export_name = "2200"] impl S { }
105-
//~^ ERROR attribute should be applied to a function or static
106-
//~| NOTE not a function or static
105+
//~^ ERROR attribute should be applied to a free function, impl method or static
106+
//~| NOTE not a free function, impl method or static
107+
108+
trait Tr {
109+
#[export_name = "2200"] fn foo();
110+
//~^ ERROR attribute should be applied to a free function, impl method or static
111+
//~| NOTE not a free function, impl method or static
112+
113+
#[export_name = "2200"] fn bar() {}
114+
//~^ ERROR attribute should be applied to a free function, impl method or static
115+
//~| NOTE not a free function, impl method or static
116+
}
107117
}
108118

109119
#[start]

‎src/test/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr

+30-18
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,31 @@ LL | #[inline = "2100"] fn f() { }
1717
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
1818

1919
error: `start` attribute can only be used on functions
20-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:109:1
20+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:119:1
2121
|
2222
LL | #[start]
2323
| ^^^^^^^^
2424

2525
error: `start` attribute can only be used on functions
26-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:112:17
26+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:122:17
2727
|
2828
LL | mod inner { #![start] }
2929
| ^^^^^^^^^
3030

3131
error: `start` attribute can only be used on functions
32-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:117:5
32+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:127:5
3333
|
3434
LL | #[start] struct S;
3535
| ^^^^^^^^
3636

3737
error: `start` attribute can only be used on functions
38-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:120:5
38+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:130:5
3939
|
4040
LL | #[start] type T = S;
4141
| ^^^^^^^^
4242

4343
error: `start` attribute can only be used on functions
44-
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:123:5
44+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:133:5
4545
|
4646
LL | #[start] impl S { }
4747
| ^^^^^^^^
@@ -76,7 +76,7 @@ LL | |
7676
LL | | }
7777
| |_- not an `extern crate` item
7878

79-
error: attribute should be applied to a function or static
79+
error: attribute should be applied to a free function, impl method or static
8080
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:85:1
8181
|
8282
LL | #[export_name = "2200"]
@@ -87,17 +87,17 @@ LL | |
8787
LL | |
8888
LL | | mod inner { #![export_name="2200"] }
8989
... |
90-
LL | |
90+
LL | | }
9191
LL | | }
92-
| |_- not a function or static
92+
| |_- not a free function, impl method or static
9393

9494
error: attribute should be applied to an `extern crate` item
9595
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:25:1
9696
|
9797
LL | #![no_link]
9898
| ^^^^^^^^^^^
9999

100-
error: attribute should be applied to a function or static
100+
error: attribute should be applied to a free function, impl method or static
101101
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:27:1
102102
|
103103
LL | #![export_name = "2200"]
@@ -199,31 +199,43 @@ error: attribute should be applied to an `extern crate` item
199199
LL | #[no_link] impl S { }
200200
| ^^^^^^^^^^ ---------- not an `extern crate` item
201201

202-
error: attribute should be applied to a function or static
202+
error: attribute should be applied to a free function, impl method or static
203203
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:90:17
204204
|
205205
LL | mod inner { #![export_name="2200"] }
206-
| ------------^^^^^^^^^^^^^^^^^^^^^^-- not a function or static
206+
| ------------^^^^^^^^^^^^^^^^^^^^^^-- not a free function, impl method or static
207207

208-
error: attribute should be applied to a function or static
208+
error: attribute should be applied to a free function, impl method or static
209209
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:96:5
210210
|
211211
LL | #[export_name = "2200"] struct S;
212-
| ^^^^^^^^^^^^^^^^^^^^^^^ --------- not a function or static
212+
| ^^^^^^^^^^^^^^^^^^^^^^^ --------- not a free function, impl method or static
213213

214-
error: attribute should be applied to a function or static
214+
error: attribute should be applied to a free function, impl method or static
215215
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:100:5
216216
|
217217
LL | #[export_name = "2200"] type T = S;
218-
| ^^^^^^^^^^^^^^^^^^^^^^^ ----------- not a function or static
218+
| ^^^^^^^^^^^^^^^^^^^^^^^ ----------- not a free function, impl method or static
219219

220-
error: attribute should be applied to a function or static
220+
error: attribute should be applied to a free function, impl method or static
221221
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:104:5
222222
|
223223
LL | #[export_name = "2200"] impl S { }
224-
| ^^^^^^^^^^^^^^^^^^^^^^^ ---------- not a function or static
224+
| ^^^^^^^^^^^^^^^^^^^^^^^ ---------- not a free function, impl method or static
225+
226+
error: attribute should be applied to a free function, impl method or static
227+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:109:9
228+
|
229+
LL | #[export_name = "2200"] fn foo();
230+
| ^^^^^^^^^^^^^^^^^^^^^^^ --------- not a free function, impl method or static
231+
232+
error: attribute should be applied to a free function, impl method or static
233+
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:113:9
234+
|
235+
LL | #[export_name = "2200"] fn bar() {}
236+
| ^^^^^^^^^^^^^^^^^^^^^^^ ----------- not a free function, impl method or static
225237

226-
error: aborting due to 32 previous errors
238+
error: aborting due to 34 previous errors
227239

228240
Some errors have detailed explanations: E0518, E0658.
229241
For more information about an error, try `rustc --explain E0518`.

‎src/test/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -295,31 +295,43 @@ mod automatically_derived {
295295
}
296296

297297
#[no_mangle]
298-
//~^ WARN attribute should be applied to a function or static [unused_attributes]
298+
//~^ WARN attribute should be applied to a free function, impl method or static [unused_attributes]
299299
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
300300
mod no_mangle {
301-
//~^ NOTE not a function or static
301+
//~^ NOTE not a free function, impl method or static
302302
mod inner { #![no_mangle] }
303-
//~^ WARN attribute should be applied to a function or static [unused_attributes]
303+
//~^ WARN attribute should be applied to a free function, impl method or static [unused_attributes]
304304
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
305-
//~| NOTE not a function or static
305+
//~| NOTE not a free function, impl method or static
306306

307307
#[no_mangle] fn f() { }
308308

309309
#[no_mangle] struct S;
310-
//~^ WARN attribute should be applied to a function or static [unused_attributes]
310+
//~^ WARN attribute should be applied to a free function, impl method or static [unused_attributes]
311311
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
312-
//~| NOTE not a function or static
312+
//~| NOTE not a free function, impl method or static
313313

314314
#[no_mangle] type T = S;
315-
//~^ WARN attribute should be applied to a function or static [unused_attributes]
315+
//~^ WARN attribute should be applied to a free function, impl method or static [unused_attributes]
316316
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
317-
//~| NOTE not a function or static
317+
//~| NOTE not a free function, impl method or static
318318

319319
#[no_mangle] impl S { }
320-
//~^ WARN attribute should be applied to a function or static [unused_attributes]
320+
//~^ WARN attribute should be applied to a free function, impl method or static [unused_attributes]
321321
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
322-
//~| NOTE not a function or static
322+
//~| NOTE not a free function, impl method or static
323+
324+
trait Tr {
325+
#[no_mangle] fn foo();
326+
//~^ WARN attribute should be applied to a free function, impl method or static [unused_attributes]
327+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
328+
//~| NOTE not a free function, impl method or static
329+
330+
#[no_mangle] fn bar() {}
331+
//~^ WARN attribute should be applied to a free function, impl method or static [unused_attributes]
332+
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
333+
//~| NOTE not a free function, impl method or static
334+
}
323335
}
324336

325337
#[should_panic]

‎src/test/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr

+160-144
Large diffs are not rendered by default.

‎src/test/ui/generics/generic-no-mangle.fixed

+142
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,146 @@ pub fn baz(x: &i32) -> &i32 { x }
1414
#[no_mangle]
1515
pub fn qux<'a>(x: &'a i32) -> &i32 { x }
1616

17+
pub struct Foo;
18+
19+
impl Foo {
20+
21+
pub fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled
22+
23+
24+
pub extern "C" fn bar<T>() {} //~ ERROR functions generic over types or consts must be mangled
25+
26+
#[no_mangle]
27+
pub fn baz(x: &i32) -> &i32 { x }
28+
29+
#[no_mangle]
30+
pub fn qux<'a>(x: &'a i32) -> &i32 { x }
31+
}
32+
33+
trait Trait1 {
34+
fn foo<T>();
35+
extern "C" fn bar<T>();
36+
fn baz(x: &i32) -> &i32;
37+
fn qux<'a>(x: &'a i32) -> &i32;
38+
}
39+
40+
impl Trait1 for Foo {
41+
42+
fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled
43+
44+
45+
extern "C" fn bar<T>() {} //~ ERROR functions generic over types or consts must be mangled
46+
47+
#[no_mangle]
48+
fn baz(x: &i32) -> &i32 { x }
49+
50+
#[no_mangle]
51+
fn qux<'a>(x: &'a i32) -> &i32 { x }
52+
}
53+
54+
trait Trait2<T> {
55+
fn foo();
56+
fn foo2<U>();
57+
extern "C" fn bar();
58+
fn baz(x: &i32) -> &i32;
59+
fn qux<'a>(x: &'a i32) -> &i32;
60+
}
61+
62+
impl<T> Trait2<T> for Foo {
63+
64+
fn foo() {} //~ ERROR functions generic over types or consts must be mangled
65+
66+
67+
fn foo2<U>() {} //~ ERROR functions generic over types or consts must be mangled
68+
69+
70+
extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled
71+
72+
73+
fn baz(x: &i32) -> &i32 { x } //~ ERROR functions generic over types or consts must be mangled
74+
75+
76+
fn qux<'a>(x: &'a i32) -> &i32 { x } //~ ERROR functions generic over types or consts must be mangled
77+
}
78+
79+
pub struct Bar<T>(T);
80+
81+
impl<T> Bar<T> {
82+
83+
pub fn foo() {} //~ ERROR functions generic over types or consts must be mangled
84+
85+
86+
pub extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled
87+
88+
89+
pub fn baz<U>() {} //~ ERROR functions generic over types or consts must be mangled
90+
}
91+
92+
impl Bar<i32> {
93+
#[no_mangle]
94+
pub fn qux() {}
95+
}
96+
97+
trait Trait3 {
98+
fn foo();
99+
extern "C" fn bar();
100+
fn baz<U>();
101+
}
102+
103+
impl<T> Trait3 for Bar<T> {
104+
105+
fn foo() {} //~ ERROR functions generic over types or consts must be mangled
106+
107+
108+
extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled
109+
110+
111+
fn baz<U>() {} //~ ERROR functions generic over types or consts must be mangled
112+
}
113+
114+
pub struct Baz<'a>(&'a i32);
115+
116+
impl<'a> Baz<'a> {
117+
#[no_mangle]
118+
pub fn foo() {}
119+
120+
#[no_mangle]
121+
pub fn bar<'b>(x: &'b i32) -> &i32 { x }
122+
}
123+
124+
trait Trait4 {
125+
fn foo();
126+
fn bar<'a>(x: &'a i32) -> &i32;
127+
}
128+
129+
impl Trait4 for Bar<i32> {
130+
#[no_mangle]
131+
fn foo() {}
132+
133+
#[no_mangle]
134+
fn bar<'b>(x: &'b i32) -> &i32 { x }
135+
}
136+
137+
impl<'a> Trait4 for Baz<'a> {
138+
#[no_mangle]
139+
fn foo() {}
140+
141+
#[no_mangle]
142+
fn bar<'b>(x: &'b i32) -> &i32 { x }
143+
}
144+
145+
trait Trait5<T> {
146+
fn foo();
147+
}
148+
149+
impl Trait5<i32> for Foo {
150+
#[no_mangle]
151+
fn foo() {}
152+
}
153+
154+
impl Trait5<i32> for Bar<i32> {
155+
#[no_mangle]
156+
fn foo() {}
157+
}
158+
17159
fn main() {}

‎src/test/ui/generics/generic-no-mangle.rs

+142
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,146 @@ pub fn baz(x: &i32) -> &i32 { x }
1414
#[no_mangle]
1515
pub fn qux<'a>(x: &'a i32) -> &i32 { x }
1616

17+
pub struct Foo;
18+
19+
impl Foo {
20+
#[no_mangle]
21+
pub fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled
22+
23+
#[no_mangle]
24+
pub extern "C" fn bar<T>() {} //~ ERROR functions generic over types or consts must be mangled
25+
26+
#[no_mangle]
27+
pub fn baz(x: &i32) -> &i32 { x }
28+
29+
#[no_mangle]
30+
pub fn qux<'a>(x: &'a i32) -> &i32 { x }
31+
}
32+
33+
trait Trait1 {
34+
fn foo<T>();
35+
extern "C" fn bar<T>();
36+
fn baz(x: &i32) -> &i32;
37+
fn qux<'a>(x: &'a i32) -> &i32;
38+
}
39+
40+
impl Trait1 for Foo {
41+
#[no_mangle]
42+
fn foo<T>() {} //~ ERROR functions generic over types or consts must be mangled
43+
44+
#[no_mangle]
45+
extern "C" fn bar<T>() {} //~ ERROR functions generic over types or consts must be mangled
46+
47+
#[no_mangle]
48+
fn baz(x: &i32) -> &i32 { x }
49+
50+
#[no_mangle]
51+
fn qux<'a>(x: &'a i32) -> &i32 { x }
52+
}
53+
54+
trait Trait2<T> {
55+
fn foo();
56+
fn foo2<U>();
57+
extern "C" fn bar();
58+
fn baz(x: &i32) -> &i32;
59+
fn qux<'a>(x: &'a i32) -> &i32;
60+
}
61+
62+
impl<T> Trait2<T> for Foo {
63+
#[no_mangle]
64+
fn foo() {} //~ ERROR functions generic over types or consts must be mangled
65+
66+
#[no_mangle]
67+
fn foo2<U>() {} //~ ERROR functions generic over types or consts must be mangled
68+
69+
#[no_mangle]
70+
extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled
71+
72+
#[no_mangle]
73+
fn baz(x: &i32) -> &i32 { x } //~ ERROR functions generic over types or consts must be mangled
74+
75+
#[no_mangle]
76+
fn qux<'a>(x: &'a i32) -> &i32 { x } //~ ERROR functions generic over types or consts must be mangled
77+
}
78+
79+
pub struct Bar<T>(T);
80+
81+
impl<T> Bar<T> {
82+
#[no_mangle]
83+
pub fn foo() {} //~ ERROR functions generic over types or consts must be mangled
84+
85+
#[no_mangle]
86+
pub extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled
87+
88+
#[no_mangle]
89+
pub fn baz<U>() {} //~ ERROR functions generic over types or consts must be mangled
90+
}
91+
92+
impl Bar<i32> {
93+
#[no_mangle]
94+
pub fn qux() {}
95+
}
96+
97+
trait Trait3 {
98+
fn foo();
99+
extern "C" fn bar();
100+
fn baz<U>();
101+
}
102+
103+
impl<T> Trait3 for Bar<T> {
104+
#[no_mangle]
105+
fn foo() {} //~ ERROR functions generic over types or consts must be mangled
106+
107+
#[no_mangle]
108+
extern "C" fn bar() {} //~ ERROR functions generic over types or consts must be mangled
109+
110+
#[no_mangle]
111+
fn baz<U>() {} //~ ERROR functions generic over types or consts must be mangled
112+
}
113+
114+
pub struct Baz<'a>(&'a i32);
115+
116+
impl<'a> Baz<'a> {
117+
#[no_mangle]
118+
pub fn foo() {}
119+
120+
#[no_mangle]
121+
pub fn bar<'b>(x: &'b i32) -> &i32 { x }
122+
}
123+
124+
trait Trait4 {
125+
fn foo();
126+
fn bar<'a>(x: &'a i32) -> &i32;
127+
}
128+
129+
impl Trait4 for Bar<i32> {
130+
#[no_mangle]
131+
fn foo() {}
132+
133+
#[no_mangle]
134+
fn bar<'b>(x: &'b i32) -> &i32 { x }
135+
}
136+
137+
impl<'a> Trait4 for Baz<'a> {
138+
#[no_mangle]
139+
fn foo() {}
140+
141+
#[no_mangle]
142+
fn bar<'b>(x: &'b i32) -> &i32 { x }
143+
}
144+
145+
trait Trait5<T> {
146+
fn foo();
147+
}
148+
149+
impl Trait5<i32> for Foo {
150+
#[no_mangle]
151+
fn foo() {}
152+
}
153+
154+
impl Trait5<i32> for Bar<i32> {
155+
#[no_mangle]
156+
fn foo() {}
157+
}
158+
17159
fn main() {}

‎src/test/ui/generics/generic-no-mangle.stderr

+121-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,125 @@ LL | #[no_mangle]
2020
LL | pub extern "C" fn bar<T>() {}
2121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2222

23-
error: aborting due to 2 previous errors
23+
error: functions generic over types or consts must be mangled
24+
--> $DIR/generic-no-mangle.rs:21:5
25+
|
26+
LL | #[no_mangle]
27+
| ------------ help: remove this attribute
28+
LL | pub fn foo<T>() {}
29+
| ^^^^^^^^^^^^^^^^^^
30+
31+
error: functions generic over types or consts must be mangled
32+
--> $DIR/generic-no-mangle.rs:24:5
33+
|
34+
LL | #[no_mangle]
35+
| ------------ help: remove this attribute
36+
LL | pub extern "C" fn bar<T>() {}
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
39+
error: functions generic over types or consts must be mangled
40+
--> $DIR/generic-no-mangle.rs:42:5
41+
|
42+
LL | #[no_mangle]
43+
| ------------ help: remove this attribute
44+
LL | fn foo<T>() {}
45+
| ^^^^^^^^^^^^^^
46+
47+
error: functions generic over types or consts must be mangled
48+
--> $DIR/generic-no-mangle.rs:45:5
49+
|
50+
LL | #[no_mangle]
51+
| ------------ help: remove this attribute
52+
LL | extern "C" fn bar<T>() {}
53+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
54+
55+
error: functions generic over types or consts must be mangled
56+
--> $DIR/generic-no-mangle.rs:64:5
57+
|
58+
LL | #[no_mangle]
59+
| ------------ help: remove this attribute
60+
LL | fn foo() {}
61+
| ^^^^^^^^^^^
62+
63+
error: functions generic over types or consts must be mangled
64+
--> $DIR/generic-no-mangle.rs:67:5
65+
|
66+
LL | #[no_mangle]
67+
| ------------ help: remove this attribute
68+
LL | fn foo2<U>() {}
69+
| ^^^^^^^^^^^^^^^
70+
71+
error: functions generic over types or consts must be mangled
72+
--> $DIR/generic-no-mangle.rs:70:5
73+
|
74+
LL | #[no_mangle]
75+
| ------------ help: remove this attribute
76+
LL | extern "C" fn bar() {}
77+
| ^^^^^^^^^^^^^^^^^^^^^^
78+
79+
error: functions generic over types or consts must be mangled
80+
--> $DIR/generic-no-mangle.rs:73:5
81+
|
82+
LL | #[no_mangle]
83+
| ------------ help: remove this attribute
84+
LL | fn baz(x: &i32) -> &i32 { x }
85+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86+
87+
error: functions generic over types or consts must be mangled
88+
--> $DIR/generic-no-mangle.rs:76:5
89+
|
90+
LL | #[no_mangle]
91+
| ------------ help: remove this attribute
92+
LL | fn qux<'a>(x: &'a i32) -> &i32 { x }
93+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
94+
95+
error: functions generic over types or consts must be mangled
96+
--> $DIR/generic-no-mangle.rs:83:5
97+
|
98+
LL | #[no_mangle]
99+
| ------------ help: remove this attribute
100+
LL | pub fn foo() {}
101+
| ^^^^^^^^^^^^^^^
102+
103+
error: functions generic over types or consts must be mangled
104+
--> $DIR/generic-no-mangle.rs:86:5
105+
|
106+
LL | #[no_mangle]
107+
| ------------ help: remove this attribute
108+
LL | pub extern "C" fn bar() {}
109+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
110+
111+
error: functions generic over types or consts must be mangled
112+
--> $DIR/generic-no-mangle.rs:89:5
113+
|
114+
LL | #[no_mangle]
115+
| ------------ help: remove this attribute
116+
LL | pub fn baz<U>() {}
117+
| ^^^^^^^^^^^^^^^^^^
118+
119+
error: functions generic over types or consts must be mangled
120+
--> $DIR/generic-no-mangle.rs:105:5
121+
|
122+
LL | #[no_mangle]
123+
| ------------ help: remove this attribute
124+
LL | fn foo() {}
125+
| ^^^^^^^^^^^
126+
127+
error: functions generic over types or consts must be mangled
128+
--> $DIR/generic-no-mangle.rs:108:5
129+
|
130+
LL | #[no_mangle]
131+
| ------------ help: remove this attribute
132+
LL | extern "C" fn bar() {}
133+
| ^^^^^^^^^^^^^^^^^^^^^^
134+
135+
error: functions generic over types or consts must be mangled
136+
--> $DIR/generic-no-mangle.rs:111:5
137+
|
138+
LL | #[no_mangle]
139+
| ------------ help: remove this attribute
140+
LL | fn baz<U>() {}
141+
| ^^^^^^^^^^^^^^
142+
143+
error: aborting due to 17 previous errors
24144

‎src/test/ui/lint/issue-31924-non-snake-ffi.rs

+7
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,11 @@
55
#[no_mangle]
66
pub extern "C" fn SparklingGenerationForeignFunctionInterface() {} // OK
77

8+
pub struct Foo;
9+
10+
impl Foo {
11+
#[no_mangle]
12+
pub extern "C" fn SparklingGenerationForeignFunctionInterface() {} // OK
13+
}
14+
815
fn main() {}

‎src/test/ui/lint/lint-unsafe-code.rs

+24
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,33 @@ macro_rules! unsafe_in_macro {
3131
#[no_mangle] fn foo() {} //~ ERROR: declaration of a `no_mangle` function
3232
#[no_mangle] static FOO: u32 = 5; //~ ERROR: declaration of a `no_mangle` static
3333

34+
trait AssocFnTrait {
35+
fn foo();
36+
}
37+
38+
struct AssocFnFoo;
39+
40+
impl AssocFnFoo {
41+
#[no_mangle] fn foo() {} //~ ERROR: declaration of a `no_mangle` method
42+
}
43+
44+
impl AssocFnTrait for AssocFnFoo {
45+
#[no_mangle] fn foo() {} //~ ERROR: declaration of a `no_mangle` method
46+
}
47+
3448
#[export_name = "bar"] fn bar() {} //~ ERROR: declaration of a function with `export_name`
3549
#[export_name = "BAR"] static BAR: u32 = 5; //~ ERROR: declaration of a static with `export_name`
3650

51+
struct AssocFnBar;
52+
53+
impl AssocFnBar {
54+
#[export_name = "bar"] fn bar() {} //~ ERROR: declaration of a method with `export_name`
55+
}
56+
57+
impl AssocFnTrait for AssocFnBar {
58+
#[export_name = "bar"] fn foo() {} //~ ERROR: declaration of a method with `export_name`
59+
}
60+
3761
unsafe fn baz() {} //~ ERROR: declaration of an `unsafe` function
3862
unsafe trait Foo {} //~ ERROR: declaration of an `unsafe` trait
3963
unsafe impl Foo for Bar {} //~ ERROR: implementation of an `unsafe` trait

‎src/test/ui/lint/lint-unsafe-code.stderr

+48-16
Original file line numberDiff line numberDiff line change
@@ -19,96 +19,128 @@ LL | #[no_mangle] static FOO: u32 = 5;
1919
|
2020
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
2121

22+
error: declaration of a `no_mangle` method
23+
--> $DIR/lint-unsafe-code.rs:41:5
24+
|
25+
LL | #[no_mangle] fn foo() {}
26+
| ^^^^^^^^^^^^
27+
|
28+
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
29+
30+
error: declaration of a `no_mangle` method
31+
--> $DIR/lint-unsafe-code.rs:45:5
32+
|
33+
LL | #[no_mangle] fn foo() {}
34+
| ^^^^^^^^^^^^
35+
|
36+
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
37+
2238
error: declaration of a function with `export_name`
23-
--> $DIR/lint-unsafe-code.rs:34:1
39+
--> $DIR/lint-unsafe-code.rs:48:1
2440
|
2541
LL | #[export_name = "bar"] fn bar() {}
2642
| ^^^^^^^^^^^^^^^^^^^^^^
2743
|
2844
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
2945

3046
error: declaration of a static with `export_name`
31-
--> $DIR/lint-unsafe-code.rs:35:1
47+
--> $DIR/lint-unsafe-code.rs:49:1
3248
|
3349
LL | #[export_name = "BAR"] static BAR: u32 = 5;
3450
| ^^^^^^^^^^^^^^^^^^^^^^
3551
|
3652
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
3753

54+
error: declaration of a method with `export_name`
55+
--> $DIR/lint-unsafe-code.rs:54:5
56+
|
57+
LL | #[export_name = "bar"] fn bar() {}
58+
| ^^^^^^^^^^^^^^^^^^^^^^
59+
|
60+
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
61+
62+
error: declaration of a method with `export_name`
63+
--> $DIR/lint-unsafe-code.rs:58:5
64+
|
65+
LL | #[export_name = "bar"] fn foo() {}
66+
| ^^^^^^^^^^^^^^^^^^^^^^
67+
|
68+
= note: the linker's behavior with multiple libraries exporting duplicate symbol names is undefined and Rust cannot provide guarantees when you manually override them
69+
3870
error: declaration of an `unsafe` function
39-
--> $DIR/lint-unsafe-code.rs:37:1
71+
--> $DIR/lint-unsafe-code.rs:61:1
4072
|
4173
LL | unsafe fn baz() {}
4274
| ^^^^^^^^^^^^^^^^^^
4375

4476
error: declaration of an `unsafe` trait
45-
--> $DIR/lint-unsafe-code.rs:38:1
77+
--> $DIR/lint-unsafe-code.rs:62:1
4678
|
4779
LL | unsafe trait Foo {}
4880
| ^^^^^^^^^^^^^^^^^^^
4981

5082
error: implementation of an `unsafe` trait
51-
--> $DIR/lint-unsafe-code.rs:39:1
83+
--> $DIR/lint-unsafe-code.rs:63:1
5284
|
5385
LL | unsafe impl Foo for Bar {}
5486
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
5587

5688
error: declaration of an `unsafe` method
57-
--> $DIR/lint-unsafe-code.rs:42:5
89+
--> $DIR/lint-unsafe-code.rs:66:5
5890
|
5991
LL | unsafe fn baz(&self);
6092
| ^^^^^^^^^^^^^^^^^^^^^
6193

6294
error: implementation of an `unsafe` method
63-
--> $DIR/lint-unsafe-code.rs:43:5
95+
--> $DIR/lint-unsafe-code.rs:67:5
6496
|
6597
LL | unsafe fn provided(&self) {}
6698
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6799

68100
error: implementation of an `unsafe` method
69-
--> $DIR/lint-unsafe-code.rs:44:5
101+
--> $DIR/lint-unsafe-code.rs:68:5
70102
|
71103
LL | unsafe fn provided_override(&self) {}
72104
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
73105

74106
error: implementation of an `unsafe` method
75-
--> $DIR/lint-unsafe-code.rs:48:5
107+
--> $DIR/lint-unsafe-code.rs:72:5
76108
|
77109
LL | unsafe fn baz(&self) {}
78110
| ^^^^^^^^^^^^^^^^^^^^^^^
79111

80112
error: implementation of an `unsafe` method
81-
--> $DIR/lint-unsafe-code.rs:49:5
113+
--> $DIR/lint-unsafe-code.rs:73:5
82114
|
83115
LL | unsafe fn provided_override(&self) {}
84116
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
85117

86118
error: implementation of an `unsafe` method
87-
--> $DIR/lint-unsafe-code.rs:68:5
119+
--> $DIR/lint-unsafe-code.rs:92:5
88120
|
89121
LL | unsafe fn provided_override(&self) {}
90122
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
91123

92124
error: implementation of an `unsafe` method
93-
--> $DIR/lint-unsafe-code.rs:79:5
125+
--> $DIR/lint-unsafe-code.rs:103:5
94126
|
95127
LL | unsafe fn provided(&self) {}
96128
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97129

98130
error: implementation of an `unsafe` method
99-
--> $DIR/lint-unsafe-code.rs:85:5
131+
--> $DIR/lint-unsafe-code.rs:109:5
100132
|
101133
LL | unsafe fn provided(&self) {}
102134
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103135

104136
error: implementation of an `unsafe` method
105-
--> $DIR/lint-unsafe-code.rs:89:5
137+
--> $DIR/lint-unsafe-code.rs:113:5
106138
|
107139
LL | unsafe fn baz(&self) {}
108140
| ^^^^^^^^^^^^^^^^^^^^^^^
109141

110142
error: usage of an `unsafe` block
111-
--> $DIR/lint-unsafe-code.rs:100:5
143+
--> $DIR/lint-unsafe-code.rs:124:5
112144
|
113145
LL | unsafe {}
114146
| ^^^^^^^^^
@@ -172,5 +204,5 @@ LL | unsafe_in_macro!()
172204
|
173205
= note: this error originates in the macro `unsafe_in_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
174206

175-
error: aborting due to 22 previous errors
207+
error: aborting due to 26 previous errors
176208

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// aux-build: no-mangle-associated-fn.rs
2+
// run-pass
3+
4+
extern crate no_mangle_associated_fn;
5+
6+
struct Foo;
7+
8+
impl Foo {
9+
#[no_mangle]
10+
fn foo() -> u8 {
11+
1
12+
}
13+
}
14+
15+
trait Bar {
16+
fn qux() -> u8;
17+
}
18+
19+
impl Bar for Foo {
20+
#[no_mangle]
21+
fn qux() -> u8 {
22+
4
23+
}
24+
}
25+
26+
fn main() {
27+
extern "Rust" {
28+
fn foo() -> u8;
29+
fn bar() -> u8;
30+
fn baz() -> u8;
31+
fn qux() -> u8;
32+
}
33+
assert_eq!(unsafe { foo() }, 1);
34+
assert_eq!(unsafe { bar() }, 2);
35+
assert_eq!(unsafe { baz() }, 3);
36+
assert_eq!(unsafe { qux() }, 4);
37+
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
#[no_mangle]
22
pub fn řųśť() {} //~ `#[no_mangle]` requires ASCII identifier
33

4+
pub struct Foo;
5+
6+
impl Foo {
7+
#[no_mangle]
8+
pub fn řųśť() {} //~ `#[no_mangle]` requires ASCII identifier
9+
}
10+
11+
trait Bar {
12+
fn řųśť();
13+
}
14+
15+
impl Bar for Foo {
16+
#[no_mangle]
17+
fn řųśť() {} //~ `#[no_mangle]` requires ASCII identifier
18+
}
19+
420
fn main() {}

‎src/test/ui/rfc-2457/no_mangle_nonascii_forbidden.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ error[E0754]: `#[no_mangle]` requires ASCII identifier
44
LL | pub fn řųśť() {}
55
| ^^^^^^^^^^^^^
66

7-
error: aborting due to previous error
7+
error[E0754]: `#[no_mangle]` requires ASCII identifier
8+
--> $DIR/no_mangle_nonascii_forbidden.rs:8:5
9+
|
10+
LL | pub fn řųśť() {}
11+
| ^^^^^^^^^^^^^
12+
13+
error[E0754]: `#[no_mangle]` requires ASCII identifier
14+
--> $DIR/no_mangle_nonascii_forbidden.rs:17:5
15+
|
16+
LL | fn řųśť() {}
17+
| ^^^^^^^^^
18+
19+
error: aborting due to 3 previous errors
820

921
For more information about this error, try `rustc --explain E0754`.

0 commit comments

Comments
 (0)
Please sign in to comment.