mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Skip no_mangle if the item has no name.
This commit is contained in:
parent
84487b212d
commit
3102722ef4
@ -103,7 +103,22 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
||||
codegen_fn_attrs.flags |= CodegenFnAttrFlags::ALLOCATOR_ZEROED
|
||||
}
|
||||
sym::naked => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED,
|
||||
sym::no_mangle => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE,
|
||||
sym::no_mangle => {
|
||||
if tcx.opt_item_name(did.to_def_id()).is_some() {
|
||||
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE
|
||||
} else {
|
||||
tcx.sess
|
||||
.struct_span_err(
|
||||
attr.span,
|
||||
format!(
|
||||
"`#[no_mangle]` cannot be used on {} {} as it has no name",
|
||||
tcx.def_descr_article(did.to_def_id()),
|
||||
tcx.def_descr(did.to_def_id()),
|
||||
),
|
||||
)
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
sym::no_coverage => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_COVERAGE,
|
||||
sym::rustc_std_internal_symbol => {
|
||||
codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL
|
||||
|
11
tests/ui/attributes/no-mangle-closure.rs
Normal file
11
tests/ui/attributes/no-mangle-closure.rs
Normal file
@ -0,0 +1,11 @@
|
||||
// Check that we do not ICE when `no_mangle` is applied to something that has no name.
|
||||
|
||||
#![crate_type = "lib"]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
|
||||
pub struct S([usize; 8]);
|
||||
|
||||
pub fn outer_function(x: S, y: S) -> usize {
|
||||
(#[no_mangle] || y.0[0])()
|
||||
//~^ ERROR `#[no_mangle]` cannot be used on a closure as it has no name
|
||||
}
|
8
tests/ui/attributes/no-mangle-closure.stderr
Normal file
8
tests/ui/attributes/no-mangle-closure.stderr
Normal file
@ -0,0 +1,8 @@
|
||||
error: `#[no_mangle]` cannot be used on a closure as it has no name
|
||||
--> $DIR/no-mangle-closure.rs:9:6
|
||||
|
|
||||
LL | (#[no_mangle] || y.0[0])()
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user