(BLOCKED) Stabilize async_fn_track_caller - #161958
Conversation
| hir::CoroutineSource::Fn, | ||
| ); | ||
|
|
||
| // FIXME(async_fn_track_caller): Can this be moved above? |
There was a problem hiding this comment.
I don't understand what this is saying, so I removed it. Am I supposed to do something with it?
There was a problem hiding this comment.
This file previously tested the wrong feature gate, so I fixed that.
There was a problem hiding this comment.
This file previously tested the wrong feature gate, and it also had some unnecessary type errors, so I fixed those.
| assert_eq!(panicked_at(|| block_on(foo_closure())), 84); | ||
| assert_eq!(panicked_at(|| block_on(foo_closure())), 81); |
There was a problem hiding this comment.
#[track_caller] on async closures previously just silently didn't work (without any warnings) unless the async_fn_track_caller feature was enabled. This should be filed as an issue if the stabilization were to not go through.
(Note that, both before and after this PR, making #[track_caller] on async closures compile at all requires the closure_track_caller feature.)
|
There are a couple mentions of |
|
Any chance you could add a basic smoke test in Miri to ensure that it can run such code and it behaves correctly? |
|
@RalfJung I think I'm going to put off this stabilzation attempt until the incorrect behavior (using the call site location vs poll site location) is fixed. I could add tests in a separate PR though. |
|
The job Click to see the possible cause of the failure (guessed by this bot)Important For more information how to resolve CI failures of this job, visit this link. |
async_fn_track_callerasync_fn_track_caller
Edit: In the process of trying to stabilize this feature, I found out that the currently implemented behavior is incorrect.
#[track_caller]currently reports the location as being at the poll site, but it should report the function call site. That needs to be fixed before stabilization.Closes #110011
Stabilization report
Summary
This PR proposes stabilization of the
async_fn_track_callerfeature. This allows applying the#[track_caller]attribute toasync fn.The
#[track_caller]attribute allows a function to gain access to thecore::panic::Locationwhere it's called. This value is accessible viacore::panic::Location::caller. This attribute was previously stabilized for normal functions, but not async functions.Tracking:
#[track_caller]on async fn #110011Reference PRs:
cc @rust-lang/lang @rust-lang/lang-advisors
What is stabilized
The
#[track_caller]attribute, when applied to anasync fn, now works.Previously, this attribute was ignored and emitted a lint:
The
ungated_async_fn_track_callerlint is removed in this PR.What isn't stabilized
Applying
#[track_caller]on async blocks is not stabilized. It is instead part of theclosure_track_callerfeature, tracked at #87417.Design
Reference
RFC history
The
#[track_caller]attribute was proposed in RFC 2091, which was accepted in 2018, tracked as #47809, and stabilized in 2020 in #72445. However this only covered using the attribute on normal functions.Putting the attribute on closures was proposed in #74042, implemented in #87064, and then tracked in #87417, where it remains unstable today as
feature(closure_track_caller). This feature currently includes using the attribute on async blocks.Applying
#[track_caller]on async functions was requested as a feature in #78840, without an RFC. This was implemented unstably in #104219. Initially, using this in stable Rust would cause a hard error due to using an unstable feature, but the behavior was changed to a no-op with a lint in #104588, due to backwards-compatibility concerns.At first,
#[track_caller]on async functions was treated as part offeature(closure_track_caller). However, in #112117, it was separated into a new unstable feature:feature(async_fn_track_caller), tracked in #110011, which is where it remains today.Answers to unresolved questions
There are two possible sites that could be thought of as the "caller" for an
async fn: the site where named function is called, and the site where the returned future is polled. This stabilization of#[track_caller]uses the former interpretation.Key points
TODO
Nightly extensions
Applying
#[track_caller]on async blocks is part offeature(closure_track_caller). This feature gating is tested intests/ui/feature-gates/feature-gate-closure_track_caller.rs.Doors closed
None. We could later add something like
#[track_caller(poll)]if we want the user to be able to specify using the location where the future is polled.Feedback
Call for testing
N/A
Nightly use
#[track_caller]on async functions and suppresses the lint, in hopes of automatically getting the benefits when the feature is stabilized. https://github.com/MaterializeInc/materialize/blob/202455c7a32aa700fd23e96a3d65b7551e30f227/src/persist-client/src/lib.rs#L19Implementation
Major parts
TODO
Coverage
tests/ui/async-await/track-caller/panic-track-caller.rstests the run time behavior.async-block.rsandasync-closure-gate.rsin the same directory tests the feature gating of related features.Outstanding bugs
N/A
Outstanding FIXMEs
There's a FIXME at
rust/compiler/rustc_ast_lowering/src/lib.rs
Lines 287 to 288 in 17fd5b8
gen_blocksfeature.Tool changes
N/A
Breaking changes
This changes run time behavior of code with
#[track_caller]on async functions. I believe that this is acceptable because:ungated_async_fn_track_callerlint fire already.Type system, opsem
Compile-time checks
N/A
Type system rules
N/A
Sound by default?
Yes
Breaks the AM?
N/A
Common interactions
Temporaries
N/A
Drop order
N/A
Pre-expansion / post-expansion
N/A
Edition hygiene
N/A. Editions already decide whether
asyncis a keyword or not, but the#[track_caller]attribute doesn't affect that.SemVer implications
Libraries that wish to use
#[track_caller]on an async function, and need it to function correctly for whatever reason, would need to raise the MSRV of the crate to the version where this feature is stabilized. This can be easily missed. I'm not sure how to best mitigate this, although it might not be a big deal anyway.Exposing other features
The
closure_track_calleris adjacent to this feature, due to applying to async blocks, but is not exposed by this stabilization.History
#[track_caller]in general#[track_caller]on closures and async blocks#[track_caller]on async functionsAcknowledgments
Thanks to @bryangarza who implemented this feature.
Open items
N/A