Skip to content

Commit e367400

Browse files
committed
Emit lint even if span for inline attribute isn't found. Fix lint docs.
1 parent 119ebd4 commit e367400

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -590,14 +590,13 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
590590
&& !tcx.codegen_fn_attrs(owner_id).target_features.is_empty()
591591
{
592592
if codegen_fn_attrs.inline == InlineAttr::Always {
593-
if let Some(inline_span) = inline_span {
594-
tcx.emit_node_span_lint(
595-
lint::builtin::INLINE_ALWAYS_CLOSURE_IN_TARGET_FEATURE_FUNCTION,
596-
rustc_hir::CRATE_HIR_ID,
597-
inline_span,
598-
errors::InlineAlwaysClosureInTargetFeatureFunction,
599-
);
600-
}
593+
// Do *not* inherit target features here, that could be unsound.
594+
tcx.emit_node_span_lint(
595+
lint::builtin::INLINE_ALWAYS_CLOSURE_IN_TARGET_FEATURE_FUNCTION,
596+
rustc_hir::CRATE_HIR_ID,
597+
inline_span.unwrap_or(tcx.def_span(did)),
598+
errors::InlineAlwaysClosureInTargetFeatureFunction,
599+
);
601600
} else {
602601
codegen_fn_attrs
603602
.target_features

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5188,10 +5188,14 @@ declare_lint! {
51885188
///
51895189
/// ```rust,edition2021,compile_fail
51905190
/// #![deny(inline_always_closure_in_target_feature_function)]
5191+
/// #![feature(target_feature_11)]
51915192
///
51925193
/// #[target_feature(enable = "avx")]
51935194
/// fn example() {
5194-
/// let closure = #[inline(always)] || {};
5195+
/// let closure = {
5196+
/// #[inline(always)] move || {}
5197+
/// };
5198+
/// closure()
51955199
/// }
51965200
///
51975201
/// ```

0 commit comments

Comments
 (0)