[6.2] Disable surprising lifetime inference of implicit initializers #82473
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.
Non-escapable struct definitions often have inicidental integer fields that are
unrelated to lifetime. Without an explicit initializer, the compiler would infer
these fields to be borrowed by the implicit intializer.
This was done because
But this was the wrong decision because it inevitabely results in lifetime
diagnostic errors elsewhere in the code that can't be tracked down at the use
site:
Instead, force the author of the data type to specify whether the type actually
depends on trivial fields or not. Such as:
This fix enables stricter diagnostics, so we need it in 6.2.
Fixes rdar://152130977 ([nonescapable] confusing diagnostic message when a
synthesized initializer generates dependence on an Int parameter)
(cherry picked from commit 8789a68)
--- CCC ---
Explanation: Disable an inference rule that was unexpected and usually undesirable. See the discussion above.
Scope: This only affects users of the experimental feature: Lifetimes.
Radar/SR Issue: rdar://152130977 ([nonescapable] confusing diagnostic message when a synthesized initializer generates
dependence on an Int parameter)
main PR: #82472
Risk: Low.
This may initially break some code that adopts Lifetimes, but only cases in which the code was not doing what the author
intended. This is a good source break. Failing to make this change now means much worse source breaking change in a
later release.
Testing: Added several source-level unit tests
Reviewer: Meghana Gupta