-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Lint #[inline(always)] closure in #[target_feature] functions #133408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
calebzulawski
wants to merge
2
commits into
rust-lang:master
from
calebzulawski:lint_inline_always_closure_in_target_feature_function
Closed
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -584,15 +584,25 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { | |
// its parent function, which effectively inherits the features anyway. Boxing this closure | ||
// would result in this closure being compiled without the inherited target features, but this | ||
// is probably a poor usage of `#[inline(always)]` and easily avoided by not using the attribute. | ||
if tcx.features().target_feature_11() | ||
&& tcx.is_closure_like(did.to_def_id()) | ||
&& codegen_fn_attrs.inline != InlineAttr::Always | ||
{ | ||
if tcx.features().target_feature_11() && tcx.is_closure_like(did.to_def_id()) { | ||
let owner_id = tcx.parent(did.to_def_id()); | ||
if tcx.def_kind(owner_id).has_codegen_attrs() { | ||
codegen_fn_attrs | ||
.target_features | ||
.extend(tcx.codegen_fn_attrs(owner_id).target_features.iter().copied()); | ||
if tcx.def_kind(owner_id).has_codegen_attrs() | ||
&& !tcx.codegen_fn_attrs(owner_id).target_features.is_empty() | ||
{ | ||
if codegen_fn_attrs.inline == InlineAttr::Always { | ||
if let Some(inline_span) = inline_span { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if we don't have the span? Something is still wrong, so we should still emit a lint -- it can point at the closure instead of the attribute, maybe? |
||
tcx.emit_node_span_lint( | ||
lint::builtin::INLINE_ALWAYS_CLOSURE_IN_TARGET_FEATURE_FUNCTION, | ||
rustc_hir::CRATE_HIR_ID, | ||
inline_span, | ||
errors::InlineAlwaysClosureInTargetFeatureFunction, | ||
); | ||
} | ||
} else { | ||
codegen_fn_attrs | ||
.target_features | ||
.extend(tcx.codegen_fn_attrs(owner_id).target_features.iter().copied()); | ||
} | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
tests/ui/rfcs/rfc-2396-target_feature-11/issue-108655-inline-always-closure.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
warning: cannot use `#[inline(always)]` with `#[target_feature]` | ||
--> $DIR/issue-108655-inline-always-closure.rs:26:9 | ||
| | ||
LL | #[inline(always)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #108655 <https://github.com/rust-lang/rust/issues/108655> | ||
= note: `#[target_feature]` will not be applied to this closure and may result in unpredictable code generation | ||
= help: consider using `#[inline]` instead | ||
= note: `#[warn(inline_always_closure_in_target_feature_function)]` on by default | ||
|
||
warning: cannot use `#[inline(always)]` with `#[target_feature]` | ||
--> $DIR/issue-108655-inline-always-closure.rs:38:17 | ||
| | ||
LL | #[inline(always)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #108655 <https://github.com/rust-lang/rust/issues/108655> | ||
= note: `#[target_feature]` will not be applied to this closure and may result in unpredictable code generation | ||
= help: consider using `#[inline]` instead | ||
|
||
warning: 2 warnings emitted | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.