Fix double error for #[no_mangle] on closures

This commit is contained in:
Jonathan Brouwer 2025-10-08 09:39:11 +02:00
parent 82224f6891
commit 730221e654
No known key found for this signature in database
GPG key ID: F13E55D38C971DEF
6 changed files with 9 additions and 21 deletions

View file

@ -362,6 +362,7 @@ impl<S: Stage> NoArgsAttributeParser<S> for NoMangleParser {
Allow(Target::Static),
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Method(MethodKind::TraitImpl)),
Error(Target::Closure),
]);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoMangle;
}

View file

@ -223,8 +223,6 @@ codegen_ssa_multiple_main_functions = entry symbol `main` declared multiple time
codegen_ssa_no_field = no field `{$name}`
codegen_ssa_no_mangle_nameless = `#[no_mangle]` cannot be used on {$definition} as it has no name
codegen_ssa_no_module_named =
no module named `{$user_path}` (mangled: {$cgu_name}). available modules: {$cgu_names}

View file

@ -19,7 +19,6 @@ use rustc_span::{Ident, Span, sym};
use rustc_target::spec::SanitizerSet;
use crate::errors;
use crate::errors::NoMangleNameless;
use crate::target_features::{
check_target_feature_trait_unsafe, check_tied_features, from_target_feature_attr,
};
@ -182,14 +181,10 @@ fn process_builtin_attrs(
if tcx.opt_item_name(did.to_def_id()).is_some() {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
} else {
tcx.dcx().emit_err(NoMangleNameless {
span: *attr_span,
definition: format!(
"{} {}",
tcx.def_descr_article(did.to_def_id()),
tcx.def_descr(did.to_def_id())
),
});
tcx.dcx().span_delayed_bug(
*attr_span,
"no_mangle should be on a named function",
);
}
}
AttributeKind::Optimize(optimize, _) => codegen_fn_attrs.optimize = *optimize,

View file

@ -1284,14 +1284,6 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetFeatureDisableOrEnable<'_
}
}
#[derive(Diagnostic)]
#[diag(codegen_ssa_no_mangle_nameless)]
pub(crate) struct NoMangleNameless {
#[primary_span]
pub span: Span,
pub definition: String,
}
#[derive(Diagnostic)]
#[diag(codegen_ssa_feature_not_valid)]
pub(crate) struct FeatureNotValid<'a> {

View file

@ -7,5 +7,5 @@ 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
//~^ ERROR `#[no_mangle]` attribute cannot be used on closures
}

View file

@ -1,8 +1,10 @@
error: `#[no_mangle]` cannot be used on a closure as it has no name
error: `#[no_mangle]` attribute cannot be used on closures
--> $DIR/no-mangle-closure.rs:9:6
|
LL | (#[no_mangle] || y.0[0])()
| ^^^^^^^^^^^^
|
= help: `#[no_mangle]` can be applied to functions, methods, and statics
error: aborting due to 1 previous error