-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[6.2] Fix diagnostics for missing or invalid @_lifetime annotations on inout params #82511
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
Merged
+62
−11
Conversation
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
@swift-ci test |
tbkka
approved these changes
Jun 26, 2025
@swift-ci test macOS |
|
@swift-ci test macOS |
1 similar comment
@swift-ci test macOS |
CI still fails for unknown reasons after four tries.
I'll rebase and start from scratch to see if that helps. |
Remove incorrectly nested single quotes from the suggested fix. (cherry picked from commit 465d6a8)
This comes up often when passing a MutableSpan as an 'inout' argument. The vague diagnostic was causing developers to attempt incorrect @_lifetime annotations. Be clear about why the annotation is needed and which annotation should be used. (cherry picked from commit df0b81c)
Correctly diagnose this as: "invalid use of inout dependence on the same inout parameter @_lifetime(a: &a) func f_inout_useless(a: inout MutableRawSpan) {} Correctly diagnose this as: "lifetime-dependent parameter must be 'inout'": @_lifetime(a: borrow a) func f_inout_useless(a: borrowing MutableRawSpan) {} (cherry picked from commit 05fa82b)
This is a common mistake made more common be suggestions of existing diagnostic that tell users not to use a 'copy' dependency. Report a diagnostic error rather than crashing the compiler. Fix the diagnostic output to make sense relative to the source location. Fixes rdar://154136015 ([nonescapable] compiler assertion with @_lifetime(x: inout x)) (cherry picked from commit 080b682)
Users commonly try to write a lifetime dependency on an 'inout' parameters as: @_lifetime(a: &a) func f_inout_useless(a: inout MutableRawSpan) {} This is useless. Guide them toward what they really wanted: @_lifetime(a: copy a) Fixes rdar://151618856 (@Lifetime(..) gives inconsistent error messages) (cherry picked from commit 87f2510)
@swift-ci test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fix LifetimeDependence diagnostic formatting
Remove incorrectly nested single quotes from the suggested fix.
(cherry picked from commit 465d6a8)
Lifetime diagnostics: clarify @_lifetime usage for inout parameters
This comes up often when passing a MutableSpan as an 'inout' argument. The
vague diagnostic was causing developers to attempt incorrect @_lifetime
annotations. Be clear about why the annotation is needed and which annotation
should be used.
(cherry picked from commit df0b81c)
Fix misleading Lifetime diagnostics for inout parameters
Correctly diagnose this as:
"invalid use of inout dependence on the same inout parameter
Correctly diagnose this as:
"lifetime-dependent parameter must be 'inout'":
(cherry picked from commit 05fa82b)
Fix a compiler crash with '@'_lifetime(inout x), add diagnostic
This is a common mistake made more common be suggestions of existing diagnostic
that tell users not to use a 'copy' dependency.
Report a diagnostic error rather than crashing the compiler. Fix the diagnostic
output to make sense relative to the source location.
Fixes rdar://154136015 ([nonescapable] compiler assertion with @_lifetime(x: inout x))
(cherry picked from commit 080b682)
Diagnostic note for invalid @_lifetime annotations on inout params
Users commonly try to write a lifetime dependency on an 'inout' parameters as:
This is useless. Guide them toward what they really wanted:
Fixes rdar://151618856 (@Lifetime(..) gives inconsistent error messages)
(cherry picked from commit 87f2510)
--- CCC ---
Explanation: Fix diagnostics for missing or invalid @_lifetime annotations on inout params
Scope: This primarily affects adopters of the supported experimental Lifetimes feature but also improves diagnostic for regular non-experimental uses of MutableSpan.
Radar/SR Issue:
rdar://151618856 (@Lifetime(...) gives inconsistent error messages)
rdar://154136015 ([nonescapable] compiler assertion with @_lifetime(x: inout x))
main PR: #82505
Risk: Low. This eliminates a compiler crash and improves the quality of the diagnostic messages.
Testing: Added source-level unit tests.
Reviewer: Meghana Gupta