Skip to content

Commit 730221e

Browse files
Fix double error for #[no_mangle] on closures
1 parent 82224f6 commit 730221e

File tree

6 files changed

+9
-21
lines changed

6 files changed

+9
-21
lines changed

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ impl<S: Stage> NoArgsAttributeParser<S> for NoMangleParser {
362362
Allow(Target::Static),
363363
Allow(Target::Method(MethodKind::Inherent)),
364364
Allow(Target::Method(MethodKind::TraitImpl)),
365+
Error(Target::Closure),
365366
]);
366367
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoMangle;
367368
}

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,6 @@ codegen_ssa_multiple_main_functions = entry symbol `main` declared multiple time
223223
224224
codegen_ssa_no_field = no field `{$name}`
225225
226-
codegen_ssa_no_mangle_nameless = `#[no_mangle]` cannot be used on {$definition} as it has no name
227-
228226
codegen_ssa_no_module_named =
229227
no module named `{$user_path}` (mangled: {$cgu_name}). available modules: {$cgu_names}
230228

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_span::{Ident, Span, sym};
1919
use rustc_target::spec::SanitizerSet;
2020

2121
use crate::errors;
22-
use crate::errors::NoMangleNameless;
2322
use crate::target_features::{
2423
check_target_feature_trait_unsafe, check_tied_features, from_target_feature_attr,
2524
};
@@ -182,14 +181,10 @@ fn process_builtin_attrs(
182181
if tcx.opt_item_name(did.to_def_id()).is_some() {
183182
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
184183
} else {
185-
tcx.dcx().emit_err(NoMangleNameless {
186-
span: *attr_span,
187-
definition: format!(
188-
"{} {}",
189-
tcx.def_descr_article(did.to_def_id()),
190-
tcx.def_descr(did.to_def_id())
191-
),
192-
});
184+
tcx.dcx().span_delayed_bug(
185+
*attr_span,
186+
"no_mangle should be on a named function",
187+
);
193188
}
194189
}
195190
AttributeKind::Optimize(optimize, _) => codegen_fn_attrs.optimize = *optimize,

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,14 +1284,6 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_
12841284
}
12851285
}
12861286

1287-
#[derive(Diagnostic)]
1288-
#[diag(codegen_ssa_no_mangle_nameless)]
1289-
pub(crate) struct NoMangleNameless {
1290-
#[primary_span]
1291-
pub span: Span,
1292-
pub definition: String,
1293-
}
1294-
12951287
#[derive(Diagnostic)]
12961288
#[diag(codegen_ssa_feature_not_valid)]
12971289
pub(crate) struct FeatureNotValid<'a> {

tests/ui/attributes/no-mangle-closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ pub struct S([usize; 8]);
77

88
pub fn outer_function(x: S, y: S) -> usize {
99
(#[no_mangle] || y.0[0])()
10-
//~^ ERROR `#[no_mangle]` cannot be used on a closure as it has no name
10+
//~^ ERROR `#[no_mangle]` attribute cannot be used on closures
1111
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error: `#[no_mangle]` cannot be used on a closure as it has no name
1+
error: `#[no_mangle]` attribute cannot be used on closures
22
--> $DIR/no-mangle-closure.rs:9:6
33
|
44
LL | (#[no_mangle] || y.0[0])()
55
| ^^^^^^^^^^^^
6+
|
7+
= help: `#[no_mangle]` can be applied to functions, methods, and statics
68

79
error: aborting due to 1 previous error
810

0 commit comments

Comments
 (0)