From 673ab17c7f2b23ead8190df2514be52f81973573 Mon Sep 17 00:00:00 2001 From: Bryan Garza <1396101+bryangarza@users.noreply.github.com> Date: Tue, 30 May 2023 14:32:29 -0700 Subject: [PATCH] Add separate feature gate for async fn track caller This patch adds a feature gate `async_fn_track_caller` that is separate from `closure_track_caller`. This is to allow enabling `async_fn_track_caller` separately. Fixes #110009 --- compiler/rustc_ast_lowering/src/expr.rs | 4 +- compiler/rustc_ast_lowering/src/item.rs | 7 ++- .../rustc_codegen_ssa/src/codegen_attrs.rs | 9 ++- compiler/rustc_feature/src/active.rs | 2 + compiler/rustc_lint/src/builtin.rs | 12 ++-- compiler/rustc_lint/src/lints.rs | 2 +- compiler/rustc_span/src/symbol.rs | 1 + .../track-caller/async-block.afn.stderr | 30 ++++++++++ .../track-caller/async-block.nofeat.stderr | 30 ++++++++++ .../async-await/track-caller/async-block.rs | 18 ++++++ .../track-caller/async-block.stderr | 12 ---- .../async-closure-gate.afn.stderr | 57 +++++++++++++++++++ .../async-closure-gate.nofeat.stderr | 57 +++++++++++++++++++ .../track-caller/async-closure-gate.rs | 41 +++++++++++++ .../track-caller/async-closure-gate.stderr | 12 ---- .../panic-track-caller.cls.stderr | 31 ++++++++++ .../panic-track-caller.nofeat.stderr | 14 +++-- .../track-caller/panic-track-caller.rs | 46 ++++++++------- tests/ui/proc-macro/meta-macro-hygiene.stdout | 2 +- .../nonterminal-token-hygiene.stdout | 2 +- 20 files changed, 326 insertions(+), 63 deletions(-) create mode 100644 tests/ui/async-await/track-caller/async-block.afn.stderr create mode 100644 tests/ui/async-await/track-caller/async-block.nofeat.stderr delete mode 100644 tests/ui/async-await/track-caller/async-block.stderr create mode 100644 tests/ui/async-await/track-caller/async-closure-gate.afn.stderr create mode 100644 tests/ui/async-await/track-caller/async-closure-gate.nofeat.stderr delete mode 100644 tests/ui/async-await/track-caller/async-closure-gate.stderr create mode 100644 tests/ui/async-await/track-caller/panic-track-caller.cls.stderr diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index 0954cf03da9a8..6bbf59b7fd30c 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -657,14 +657,14 @@ impl<'hir> LoweringContext<'_, 'hir> { } /// Forwards a possible `#[track_caller]` annotation from `outer_hir_id` to - /// `inner_hir_id` in case the `closure_track_caller` feature is enabled. + /// `inner_hir_id` in case the `async_fn_track_caller` feature is enabled. pub(super) fn maybe_forward_track_caller( &mut self, span: Span, outer_hir_id: hir::HirId, inner_hir_id: hir::HirId, ) { - if self.tcx.features().closure_track_caller + if self.tcx.features().async_fn_track_caller && let Some(attrs) = self.attrs.get(&outer_hir_id.local_id) && attrs.into_iter().any(|attr| attr.has_name(sym::track_caller)) { diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 5a0474dbc01d1..df73c721ade23 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -56,6 +56,11 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> { owner: NodeId, f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>, ) { + let allow_gen_future = Some(if self.tcx.features().async_fn_track_caller { + [sym::gen_future, sym::closure_track_caller][..].into() + } else { + [sym::gen_future][..].into() + }); let mut lctx = LoweringContext { // Pseudo-globals. tcx: self.tcx, @@ -83,7 +88,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> { impl_trait_defs: Vec::new(), impl_trait_bounds: Vec::new(), allow_try_trait: Some([sym::try_trait_v2, sym::yeet_desugar_details][..].into()), - allow_gen_future: Some([sym::gen_future, sym::closure_track_caller][..].into()), + allow_gen_future, generics_def_id_map: Default::default(), }; lctx.with_hir_id_owner(owner, |lctx| f(lctx)); diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 92792ab6477d2..f6936c80b7758 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -215,14 +215,19 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { } sym::thread_local => codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL, sym::track_caller => { - if !tcx.is_closure(did.to_def_id()) + let is_closure = tcx.is_closure(did.to_def_id()); + + if !is_closure && let Some(fn_sig) = fn_sig() && fn_sig.skip_binder().abi() != abi::Abi::Rust { struct_span_err!(tcx.sess, attr.span, E0737, "`#[track_caller]` requires Rust ABI") .emit(); } - if tcx.is_closure(did.to_def_id()) && !tcx.features().closure_track_caller { + if is_closure + && !tcx.features().closure_track_caller + && !attr.span.allows_unstable(sym::closure_track_caller) + { feature_err( &tcx.sess.parse_sess, sym::closure_track_caller, diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index bbc3d291e2007..92085b4ef9af2 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -313,6 +313,8 @@ declare_features! ( (active, async_closure, "1.37.0", Some(62290), None), /// Allows async functions to be declared, implemented, and used in traits. (active, async_fn_in_trait, "1.66.0", Some(91611), None), + /// Allows `#[track_caller]` on async functions. + (active, async_fn_track_caller, "CURRENT_RUSTC_VERSION", Some(110011), None), /// Allows builtin # foo() syntax (active, builtin_syntax, "1.71.0", Some(110680), None), /// Allows `c"foo"` literals. diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index e6917f4b2d3b7..70621eba6af3e 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1259,8 +1259,8 @@ impl<'tcx> LateLintPass<'tcx> for UnstableFeatures { declare_lint! { /// The `ungated_async_fn_track_caller` lint warns when the - /// `#[track_caller]` attribute is used on an async function, method, or - /// closure, without enabling the corresponding unstable feature flag. + /// `#[track_caller]` attribute is used on an async function + /// without enabling the corresponding unstable feature flag. /// /// ### Example /// @@ -1274,13 +1274,13 @@ declare_lint! { /// ### Explanation /// /// The attribute must be used in conjunction with the - /// [`closure_track_caller` feature flag]. Otherwise, the `#[track_caller]` + /// [`async_fn_track_caller` feature flag]. Otherwise, the `#[track_caller]` /// annotation will function as a no-op. /// - /// [`closure_track_caller` feature flag]: https://doc.rust-lang.org/beta/unstable-book/language-features/closure-track-caller.html + /// [`async_fn_track_caller` feature flag]: https://doc.rust-lang.org/beta/unstable-book/language-features/async-fn-track-caller.html UNGATED_ASYNC_FN_TRACK_CALLER, Warn, - "enabling track_caller on an async fn is a no-op unless the closure_track_caller feature is enabled" + "enabling track_caller on an async fn is a no-op unless the async_fn_track_caller feature is enabled" } declare_lint_pass!( @@ -1300,7 +1300,7 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller { def_id: LocalDefId, ) { if fn_kind.asyncness() == IsAsync::Async - && !cx.tcx.features().closure_track_caller + && !cx.tcx.features().async_fn_track_caller // Now, check if the function has the `#[track_caller]` attribute && let Some(attr) = cx.tcx.get_attr(def_id, sym::track_caller) { diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index a6a48bf4ffa74..bf955086393ea 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -250,7 +250,7 @@ impl<'a> DecorateLint<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> { rustc_session::parse::add_feature_diagnostics( diag, &self.parse_sess, - sym::closure_track_caller, + sym::async_fn_track_caller, ); diag } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index d3739733c1d10..0d6d425a1748d 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -400,6 +400,7 @@ symbols! { async_await, async_closure, async_fn_in_trait, + async_fn_track_caller, atomic, atomic_mod, atomics, diff --git a/tests/ui/async-await/track-caller/async-block.afn.stderr b/tests/ui/async-await/track-caller/async-block.afn.stderr new file mode 100644 index 0000000000000..2302722eecc4b --- /dev/null +++ b/tests/ui/async-await/track-caller/async-block.afn.stderr @@ -0,0 +1,30 @@ +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-block.rs:8:13 + | +LL | let _ = #[track_caller] async { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-block.rs:15:13 + | +LL | let _ = #[track_caller] async { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-block.rs:23:17 + | +LL | let _ = #[track_caller] async { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/async-await/track-caller/async-block.nofeat.stderr b/tests/ui/async-await/track-caller/async-block.nofeat.stderr new file mode 100644 index 0000000000000..2302722eecc4b --- /dev/null +++ b/tests/ui/async-await/track-caller/async-block.nofeat.stderr @@ -0,0 +1,30 @@ +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-block.rs:8:13 + | +LL | let _ = #[track_caller] async { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-block.rs:15:13 + | +LL | let _ = #[track_caller] async { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-block.rs:23:17 + | +LL | let _ = #[track_caller] async { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/async-await/track-caller/async-block.rs b/tests/ui/async-await/track-caller/async-block.rs index 8ddd4ab118615..24711b966b5d8 100644 --- a/tests/ui/async-await/track-caller/async-block.rs +++ b/tests/ui/async-await/track-caller/async-block.rs @@ -1,9 +1,27 @@ // edition:2021 +// revisions: afn nofeat #![feature(stmt_expr_attributes)] +#![cfg_attr(afn, feature(async_fn_track_caller))] fn main() { let _ = #[track_caller] async { //~^ ERROR `#[track_caller]` on closures is currently unstable [E0658] }; } + +#[track_caller] +async fn foo() { + let _ = #[track_caller] async { + //~^ ERROR `#[track_caller]` on closures is currently unstable [E0658] + }; +} + +#[track_caller] +async fn foo2() { + let _ = async { + let _ = #[track_caller] async { + //~^ ERROR `#[track_caller]` on closures is currently unstable [E0658] + }; + }; +} diff --git a/tests/ui/async-await/track-caller/async-block.stderr b/tests/ui/async-await/track-caller/async-block.stderr deleted file mode 100644 index 21d1054d22066..0000000000000 --- a/tests/ui/async-await/track-caller/async-block.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0658]: `#[track_caller]` on closures is currently unstable - --> $DIR/async-block.rs:6:13 - | -LL | let _ = #[track_caller] async { - | ^^^^^^^^^^^^^^^ - | - = note: see issue #87417 for more information - = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/async-await/track-caller/async-closure-gate.afn.stderr b/tests/ui/async-await/track-caller/async-closure-gate.afn.stderr new file mode 100644 index 0000000000000..739c04a767305 --- /dev/null +++ b/tests/ui/async-await/track-caller/async-closure-gate.afn.stderr @@ -0,0 +1,57 @@ +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-closure-gate.rs:8:13 + | +LL | let _ = #[track_caller] async || { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-closure-gate.rs:15:13 + | +LL | let _ = #[track_caller] async || { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-closure-gate.rs:21:13 + | +LL | let _ = #[track_caller] || { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-closure-gate.rs:28:17 + | +LL | let _ = #[track_caller] || { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-closure-gate.rs:36:9 + | +LL | #[track_caller] || { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-closure-gate.rs:45:13 + | +LL | #[track_caller] || { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/async-await/track-caller/async-closure-gate.nofeat.stderr b/tests/ui/async-await/track-caller/async-closure-gate.nofeat.stderr new file mode 100644 index 0000000000000..739c04a767305 --- /dev/null +++ b/tests/ui/async-await/track-caller/async-closure-gate.nofeat.stderr @@ -0,0 +1,57 @@ +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-closure-gate.rs:8:13 + | +LL | let _ = #[track_caller] async || { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-closure-gate.rs:15:13 + | +LL | let _ = #[track_caller] async || { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-closure-gate.rs:21:13 + | +LL | let _ = #[track_caller] || { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-closure-gate.rs:28:17 + | +LL | let _ = #[track_caller] || { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-closure-gate.rs:36:9 + | +LL | #[track_caller] || { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error[E0658]: `#[track_caller]` on closures is currently unstable + --> $DIR/async-closure-gate.rs:45:13 + | +LL | #[track_caller] || { + | ^^^^^^^^^^^^^^^ + | + = note: see issue #87417 for more information + = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/async-await/track-caller/async-closure-gate.rs b/tests/ui/async-await/track-caller/async-closure-gate.rs index d9d556855991b..8d8d081aa90b2 100644 --- a/tests/ui/async-await/track-caller/async-closure-gate.rs +++ b/tests/ui/async-await/track-caller/async-closure-gate.rs @@ -1,9 +1,50 @@ // edition:2021 +// revisions: afn nofeat #![feature(async_closure, stmt_expr_attributes)] +#![cfg_attr(afn, feature(async_fn_track_caller))] fn main() { let _ = #[track_caller] async || { //~^ ERROR `#[track_caller]` on closures is currently unstable [E0658] }; } + +#[track_caller] +async fn foo() { + let _ = #[track_caller] async || { + //~^ ERROR `#[track_caller]` on closures is currently unstable [E0658] + }; +} + +async fn foo2() { + let _ = #[track_caller] || { + //~^ ERROR `#[track_caller]` on closures is currently unstable [E0658] + }; +} + +fn foo3() { + async { + let _ = #[track_caller] || { + //~^ ERROR `#[track_caller]` on closures is currently unstable [E0658] + }; + } +} + +async fn foo4() { + let _ = || { + #[track_caller] || { + //~^ ERROR `#[track_caller]` on closures is currently unstable [E0658] + }; + }; +} + +fn foo5() { + async { + let _ = || { + #[track_caller] || { + //~^ ERROR `#[track_caller]` on closures is currently unstable [E0658] + }; + }; + } +} diff --git a/tests/ui/async-await/track-caller/async-closure-gate.stderr b/tests/ui/async-await/track-caller/async-closure-gate.stderr deleted file mode 100644 index 498f1b43b9bca..0000000000000 --- a/tests/ui/async-await/track-caller/async-closure-gate.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0658]: `#[track_caller]` on closures is currently unstable - --> $DIR/async-closure-gate.rs:6:13 - | -LL | let _ = #[track_caller] async || { - | ^^^^^^^^^^^^^^^ - | - = note: see issue #87417 for more information - = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/async-await/track-caller/panic-track-caller.cls.stderr b/tests/ui/async-await/track-caller/panic-track-caller.cls.stderr new file mode 100644 index 0000000000000..f3090e3b9a68f --- /dev/null +++ b/tests/ui/async-await/track-caller/panic-track-caller.cls.stderr @@ -0,0 +1,31 @@ +warning: `#[track_caller]` on async functions is a no-op + --> $DIR/panic-track-caller.rs:53:1 + | +LL | #[track_caller] + | ^^^^^^^^^^^^^^^ +... +LL | / async fn bar_track_caller() { +LL | | panic!() +LL | | } + | |_- this function will not propagate the caller location + | + = note: see issue #110011 for more information + = help: add `#![feature(async_fn_track_caller)]` to the crate attributes to enable + = note: `#[warn(ungated_async_fn_track_caller)]` on by default + +warning: `#[track_caller]` on async functions is a no-op + --> $DIR/panic-track-caller.rs:67:5 + | +LL | #[track_caller] + | ^^^^^^^^^^^^^^^ +... +LL | / async fn bar_assoc() { +LL | | panic!(); +LL | | } + | |_____- this function will not propagate the caller location + | + = note: see issue #110011 for more information + = help: add `#![feature(async_fn_track_caller)]` to the crate attributes to enable + +warning: 2 warnings emitted + diff --git a/tests/ui/async-await/track-caller/panic-track-caller.nofeat.stderr b/tests/ui/async-await/track-caller/panic-track-caller.nofeat.stderr index 51ea225f4cbd4..f3090e3b9a68f 100644 --- a/tests/ui/async-await/track-caller/panic-track-caller.nofeat.stderr +++ b/tests/ui/async-await/track-caller/panic-track-caller.nofeat.stderr @@ -1,29 +1,31 @@ warning: `#[track_caller]` on async functions is a no-op - --> $DIR/panic-track-caller.rs:50:1 + --> $DIR/panic-track-caller.rs:53:1 | LL | #[track_caller] | ^^^^^^^^^^^^^^^ +... LL | / async fn bar_track_caller() { LL | | panic!() LL | | } | |_- this function will not propagate the caller location | - = note: see issue #87417 for more information - = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + = note: see issue #110011 for more information + = help: add `#![feature(async_fn_track_caller)]` to the crate attributes to enable = note: `#[warn(ungated_async_fn_track_caller)]` on by default warning: `#[track_caller]` on async functions is a no-op - --> $DIR/panic-track-caller.rs:62:5 + --> $DIR/panic-track-caller.rs:67:5 | LL | #[track_caller] | ^^^^^^^^^^^^^^^ +... LL | / async fn bar_assoc() { LL | | panic!(); LL | | } | |_____- this function will not propagate the caller location | - = note: see issue #87417 for more information - = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable + = note: see issue #110011 for more information + = help: add `#![feature(async_fn_track_caller)]` to the crate attributes to enable warning: 2 warnings emitted diff --git a/tests/ui/async-await/track-caller/panic-track-caller.rs b/tests/ui/async-await/track-caller/panic-track-caller.rs index 65bb23e0b4b9e..df8290e5fffc7 100644 --- a/tests/ui/async-await/track-caller/panic-track-caller.rs +++ b/tests/ui/async-await/track-caller/panic-track-caller.rs @@ -1,9 +1,12 @@ // run-pass // edition:2021 -// revisions: feat nofeat +// revisions: afn cls nofeat // needs-unwind +// gate-test-async_fn_track_caller #![feature(async_closure, stmt_expr_attributes)] -#![cfg_attr(feat, feature(closure_track_caller))] +#![cfg_attr(afn, feature(async_fn_track_caller))] +#![cfg_attr(cls, feature(closure_track_caller))] +#![allow(unused)] use std::future::Future; use std::panic; @@ -47,7 +50,9 @@ async fn foo() { bar().await } -#[track_caller] //[nofeat]~ WARN `#[track_caller]` on async functions is a no-op +#[track_caller] +//[cls]~^ WARN `#[track_caller]` on async functions is a no-op +//[nofeat]~^^ WARN `#[track_caller]` on async functions is a no-op async fn bar_track_caller() { panic!() } @@ -59,7 +64,9 @@ async fn foo_track_caller() { struct Foo; impl Foo { - #[track_caller] //[nofeat]~ WARN `#[track_caller]` on async functions is a no-op + #[track_caller] + //[cls]~^ WARN `#[track_caller]` on async functions is a no-op + //[nofeat]~^^ WARN `#[track_caller]` on async functions is a no-op async fn bar_assoc() { panic!(); } @@ -71,7 +78,7 @@ async fn foo_assoc() { // Since compilation is expected to fail for this fn when using // `nofeat`, we test that separately in `async-closure-gate.rs` -#[cfg(feat)] +#[cfg(cls)] async fn foo_closure() { let c = #[track_caller] async || { panic!(); @@ -81,7 +88,7 @@ async fn foo_closure() { // Since compilation is expected to fail for this fn when using // `nofeat`, we test that separately in `async-block.rs` -#[cfg(feat)] +#[cfg(cls)] async fn foo_block() { let a = #[track_caller] async { panic!(); @@ -106,21 +113,22 @@ fn panicked_at(f: impl FnOnce() + panic::UnwindSafe) -> u32 { } fn main() { - assert_eq!(panicked_at(|| block_on(foo())), 43); + assert_eq!(panicked_at(|| block_on(foo())), 46 +); - #[cfg(feat)] - assert_eq!(panicked_at(|| block_on(foo_track_caller())), 56); - #[cfg(nofeat)] - assert_eq!(panicked_at(|| block_on(foo_track_caller())), 52); + #[cfg(afn)] + assert_eq!(panicked_at(|| block_on(foo_track_caller())), 61); + #[cfg(any(cls, nofeat))] + assert_eq!(panicked_at(|| block_on(foo_track_caller())), 57); - #[cfg(feat)] - assert_eq!(panicked_at(|| block_on(foo_assoc())), 69); - #[cfg(nofeat)] - assert_eq!(panicked_at(|| block_on(foo_assoc())), 64); + #[cfg(afn)] + assert_eq!(panicked_at(|| block_on(foo_assoc())), 76); + #[cfg(any(cls, nofeat))] + assert_eq!(panicked_at(|| block_on(foo_assoc())), 71); - #[cfg(feat)] - assert_eq!(panicked_at(|| block_on(foo_closure())), 79); + #[cfg(cls)] + assert_eq!(panicked_at(|| block_on(foo_closure())), 84); - #[cfg(feat)] - assert_eq!(panicked_at(|| block_on(foo_block())), 89); + #[cfg(cls)] + assert_eq!(panicked_at(|| block_on(foo_block())), 96); } diff --git a/tests/ui/proc-macro/meta-macro-hygiene.stdout b/tests/ui/proc-macro/meta-macro-hygiene.stdout index 4a2200091b27e..e476a8024fd77 100644 --- a/tests/ui/proc-macro/meta-macro-hygiene.stdout +++ b/tests/ui/proc-macro/meta-macro-hygiene.stdout @@ -18,7 +18,7 @@ Respanned: TokenStream [Ident { ident: "$crate", span: $DIR/auxiliary/make-macro use core /* 0#1 */::prelude /* 0#1 */::rust_2018 /* 0#1 */::*; #[macro_use /* 0#1 */] extern crate core /* 0#1 */; -extern crate compiler_builtins /* 443 */ as _ /* 0#1 */; +extern crate compiler_builtins /* 444 */ as _ /* 0#1 */; // Don't load unnecessary hygiene information from std extern crate std /* 0#0 */; diff --git a/tests/ui/proc-macro/nonterminal-token-hygiene.stdout b/tests/ui/proc-macro/nonterminal-token-hygiene.stdout index 077a728a7a6ba..23a2100423821 100644 --- a/tests/ui/proc-macro/nonterminal-token-hygiene.stdout +++ b/tests/ui/proc-macro/nonterminal-token-hygiene.stdout @@ -39,7 +39,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [ use ::core /* 0#1 */::prelude /* 0#1 */::rust_2015 /* 0#1 */::*; #[macro_use /* 0#1 */] extern crate core /* 0#2 */; -extern crate compiler_builtins /* 443 */ as _ /* 0#2 */; +extern crate compiler_builtins /* 444 */ as _ /* 0#2 */; // Don't load unnecessary hygiene information from std extern crate std /* 0#0 */;