Update track_caller logic/lint after rebase
This commit is contained in:
parent
e28a07a0a1
commit
2d060034f0
5 changed files with 52 additions and 37 deletions
|
@ -656,34 +656,35 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
||||||
hir::ExprKind::Closure(c)
|
hir::ExprKind::Closure(c)
|
||||||
};
|
};
|
||||||
|
|
||||||
let track_caller = self
|
|
||||||
.attrs
|
|
||||||
.get(&outer_hir_id.local_id)
|
|
||||||
.map_or(false, |attrs| attrs.into_iter().any(|attr| attr.has_name(sym::track_caller)));
|
|
||||||
|
|
||||||
let hir_id = self.lower_node_id(closure_node_id);
|
let hir_id = self.lower_node_id(closure_node_id);
|
||||||
if track_caller {
|
let unstable_span = self.mark_span_with_reason(
|
||||||
let unstable_span = self.mark_span_with_reason(
|
DesugaringKind::Async,
|
||||||
DesugaringKind::Async,
|
span,
|
||||||
span,
|
self.allow_gen_future.clone(),
|
||||||
self.allow_gen_future.clone(),
|
);
|
||||||
);
|
if self.tcx.features().closure_track_caller {
|
||||||
self.lower_attrs(
|
let track_caller = self
|
||||||
hir_id,
|
.attrs
|
||||||
&[Attribute {
|
.get(&outer_hir_id.local_id)
|
||||||
kind: AttrKind::Normal(ptr::P(NormalAttr {
|
.map_or(false, |attrs| attrs.into_iter().any(|attr| attr.has_name(sym::track_caller)));
|
||||||
item: AttrItem {
|
if track_caller {
|
||||||
path: Path::from_ident(Ident::new(sym::track_caller, span)),
|
self.lower_attrs(
|
||||||
args: AttrArgs::Empty,
|
hir_id,
|
||||||
|
&[Attribute {
|
||||||
|
kind: AttrKind::Normal(ptr::P(NormalAttr {
|
||||||
|
item: AttrItem {
|
||||||
|
path: Path::from_ident(Ident::new(sym::track_caller, span)),
|
||||||
|
args: AttrArgs::Empty,
|
||||||
|
tokens: None,
|
||||||
|
},
|
||||||
tokens: None,
|
tokens: None,
|
||||||
},
|
})),
|
||||||
tokens: None,
|
id: self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id(),
|
||||||
})),
|
style: AttrStyle::Outer,
|
||||||
id: self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id(),
|
span: unstable_span,
|
||||||
style: AttrStyle::Outer,
|
}],
|
||||||
span: unstable_span,
|
);
|
||||||
}],
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let generator = hir::Expr { hir_id, kind: generator_kind, span: self.lower_span(span) };
|
let generator = hir::Expr { hir_id, kind: generator_kind, span: self.lower_span(span) };
|
||||||
|
|
|
@ -1397,7 +1397,7 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
|
||||||
span: Span,
|
span: Span,
|
||||||
hir_id: HirId,
|
hir_id: HirId,
|
||||||
) {
|
) {
|
||||||
if let HirFnKind::ItemFn(_, _, _) = fn_kind && fn_kind.asyncness() == IsAsync::Async && !cx.tcx.features().closure_track_caller {
|
if fn_kind.asyncness() == IsAsync::Async && !cx.tcx.features().closure_track_caller {
|
||||||
// Now, check if the function has the `#[track_caller]` attribute
|
// Now, check if the function has the `#[track_caller]` attribute
|
||||||
let attrs = cx.tcx.hir().attrs(hir_id);
|
let attrs = cx.tcx.hir().attrs(hir_id);
|
||||||
let maybe_track_caller = attrs.iter().find(|attr| attr.has_name(sym::track_caller));
|
let maybe_track_caller = attrs.iter().find(|attr| attr.has_name(sym::track_caller));
|
||||||
|
@ -1407,12 +1407,20 @@ impl<'tcx> LateLintPass<'tcx> for UngatedAsyncFnTrackCaller {
|
||||||
attr.span,
|
attr.span,
|
||||||
fluent::lint_ungated_async_fn_track_caller,
|
fluent::lint_ungated_async_fn_track_caller,
|
||||||
|lint| {
|
|lint| {
|
||||||
lint.span_label(span, "this function will not propagate the caller location");
|
lint.span_label(
|
||||||
|
span,
|
||||||
|
"this function will not propagate the caller location",
|
||||||
|
);
|
||||||
if cx.tcx.sess.is_nightly_build() {
|
if cx.tcx.sess.is_nightly_build() {
|
||||||
lint.span_suggestion(attr.span, fluent::suggestion, "closure_track_caller", Applicability::MachineApplicable);
|
lint.span_suggestion(
|
||||||
|
attr.span,
|
||||||
|
fluent::suggestion,
|
||||||
|
"closure_track_caller",
|
||||||
|
Applicability::MachineApplicable,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
lint
|
lint
|
||||||
}
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -219,6 +219,7 @@ late_lint_methods!(
|
||||||
// May Depend on constants elsewhere
|
// May Depend on constants elsewhere
|
||||||
UnusedBrokenConst: UnusedBrokenConst,
|
UnusedBrokenConst: UnusedBrokenConst,
|
||||||
UnstableFeatures: UnstableFeatures,
|
UnstableFeatures: UnstableFeatures,
|
||||||
|
UngatedAsyncFnTrackCaller: UngatedAsyncFnTrackCaller,
|
||||||
ArrayIntoIter: ArrayIntoIter::default(),
|
ArrayIntoIter: ArrayIntoIter::default(),
|
||||||
DropTraitConstraints: DropTraitConstraints,
|
DropTraitConstraints: DropTraitConstraints,
|
||||||
TemporaryCStringAsPtr: TemporaryCStringAsPtr,
|
TemporaryCStringAsPtr: TemporaryCStringAsPtr,
|
||||||
|
|
|
@ -10,5 +10,15 @@ LL | | }
|
||||||
|
|
|
|
||||||
= note: `#[warn(ungated_async_fn_track_caller)]` on by default
|
= note: `#[warn(ungated_async_fn_track_caller)]` on by default
|
||||||
|
|
||||||
warning: 1 warning emitted
|
warning: `#[track_caller]` on async functions is a no-op
|
||||||
|
--> $DIR/panic-track-caller.rs:62:5
|
||||||
|
|
|
||||||
|
LL | #[track_caller]
|
||||||
|
| ^^^^^^^^^^^^^^^ help: enable this unstable feature: `closure_track_caller`
|
||||||
|
LL | / async fn bar_assoc() {
|
||||||
|
LL | | panic!();
|
||||||
|
LL | | }
|
||||||
|
| |_____- this function will not propagate the caller location
|
||||||
|
|
||||||
|
warning: 2 warnings emitted
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ async fn foo_track_caller() {
|
||||||
struct Foo;
|
struct Foo;
|
||||||
|
|
||||||
impl Foo {
|
impl Foo {
|
||||||
#[track_caller]
|
#[track_caller] //[nofeat]~ WARN `#[track_caller]` on async functions is a no-op
|
||||||
async fn bar_assoc() {
|
async fn bar_assoc() {
|
||||||
panic!();
|
panic!();
|
||||||
}
|
}
|
||||||
|
@ -104,9 +104,4 @@ fn main() {
|
||||||
assert_eq!(panicked_at(|| block_on(foo_assoc())), 69);
|
assert_eq!(panicked_at(|| block_on(foo_assoc())), 69);
|
||||||
#[cfg(nofeat)]
|
#[cfg(nofeat)]
|
||||||
assert_eq!(panicked_at(|| block_on(foo_assoc())), 64);
|
assert_eq!(panicked_at(|| block_on(foo_assoc())), 64);
|
||||||
|
|
||||||
#[cfg(feat)]
|
|
||||||
assert_eq!(panicked_at(|| block_on(foo_closure())), 76);
|
|
||||||
#[cfg(feat)]
|
|
||||||
assert_eq!(panicked_at(|| block_on(foo_closure())), 74);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue