Skip to content

Commit e9deff0

Browse files
committed
track_caller run-pass test, lint cleanup, PR review.
1 parent a8b2fe0 commit e9deff0

File tree

8 files changed

+31
-32
lines changed

8 files changed

+31
-32
lines changed

src/librustc/error_codes.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1728,13 +1728,13 @@ attribute.
17281728
"##,
17291729

17301730
E0900: r##"
1731-
TODO: change error number
1732-
TODO: track_caller: invalid syntax
1731+
FIXME(anp): change error number
1732+
FIXME(anp): track_caller: invalid syntax
17331733
"##,
17341734

17351735
E0901: r##"
1736-
TODO: change error number
1737-
TODO: track_caller: no naked functions
1736+
FIXME(anp): change error number
1737+
FIXME(anp): track_caller: no naked functions
17381738
"##,
17391739

17401740
E0522: r##"

src/librustc/hir/check_attr.rs

+11-17
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::ty::TyCtxt;
1111
use crate::ty::query::Providers;
1212

1313
use std::fmt::{self, Display};
14-
use syntax::symbol::sym;
14+
use syntax::{attr, symbol::sym};
1515
use syntax_pos::Span;
1616

1717
#[derive(Copy, Clone, PartialEq)]
@@ -94,7 +94,6 @@ impl CheckAttrVisitor<'tcx> {
9494
/// Checks any attribute.
9595
fn check_attributes(&self, item: &hir::Item, target: Target) {
9696
let mut is_valid = true;
97-
let mut track_caller_span = None;
9897
for attr in &item.attrs {
9998
is_valid &= if attr.check_name(sym::inline) {
10099
self.check_inline(attr, &item.span, target)
@@ -105,7 +104,6 @@ impl CheckAttrVisitor<'tcx> {
105104
} else if attr.check_name(sym::target_feature) {
106105
self.check_target_feature(attr, item, target)
107106
} else if attr.check_name(sym::track_caller) {
108-
track_caller_span = Some(attr.span);
109107
self.check_track_caller(attr, &item, target)
110108
} else {
111109
true
@@ -122,19 +120,6 @@ impl CheckAttrVisitor<'tcx> {
122120

123121
self.check_repr(item, target);
124122
self.check_used(item, target);
125-
126-
// Checks if `#[track_caller]` and `#[naked]` are both used.
127-
if let Some(span) = track_caller_span {
128-
if item.attrs.iter().any(|attr| attr.check_name(sym::naked)) {
129-
struct_span_err!(
130-
self.tcx.sess,
131-
span,
132-
E0901,
133-
"cannot use `#[track_caller]` with `#[naked]`",
134-
)
135-
.emit();
136-
}
137-
}
138123
}
139124

140125
/// Checks if an `#[inline]` is applied to a function or a closure. Returns `true` if valid.
@@ -152,7 +137,7 @@ impl CheckAttrVisitor<'tcx> {
152137
}
153138
}
154139

155-
/// Checks if a `#[target_feature]` can be applied.
140+
/// Checks if a `#[track_caller]` is applied to a non-naked function. Returns `true` if valid.
156141
fn check_track_caller(&self, attr: &hir::Attribute, item: &hir::Item, target: Target) -> bool {
157142
if target != Target::Fn {
158143
struct_span_err!(
@@ -164,6 +149,15 @@ impl CheckAttrVisitor<'tcx> {
164149
.span_label(item.span, "not a function")
165150
.emit();
166151
false
152+
} else if attr::contains_name(&item.attrs, sym::naked) {
153+
struct_span_err!(
154+
self.tcx.sess,
155+
attr.span,
156+
E0901,
157+
"cannot use `#[track_caller]` with `#[naked]`",
158+
)
159+
.emit();
160+
false
167161
} else {
168162
true
169163
}

src/librustc_typeck/error_codes.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4909,13 +4909,13 @@ and the pin is required to keep it in the same place in memory.
49094909
"##,
49104910

49114911
E0902: r##"
4912-
TODO: change error number
4913-
TODO: track_caller: require Rust ABI to use track_caller
4912+
FIXME(anp): change error number
4913+
FIXME(anp): track_caller: require Rust ABI to use track_caller
49144914
"##,
49154915

49164916
E0903: r##"
4917-
TODO: change error number
4918-
TODO: track_caller: can't apply in traits
4917+
FIXME(anp): change error number
4918+
FIXME(anp): track_caller: can't apply in traits
49194919
"##,
49204920

49214921
;

src/libsyntax/feature_gate/active.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ declare_features! (
520520
(active, or_patterns, "1.38.0", Some(54883), None),
521521

522522
/// Enable accurate caller location reporting during panic (RFC 2091).
523-
(active, track_caller, "1.37.0", Some(47809), None),
523+
(active, track_caller, "1.39.0", Some(47809), None),
524524

525525
// -------------------------------------------------------------------------
526526
// feature-group-end: actual feature gates

src/libsyntax/feature_gate/builtin_attrs.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
307307
),
308308

309309
gated!(ffi_returns_twice, Whitelisted, template!(Word), experimental!(ffi_returns_twice)),
310+
gated!(track_caller, Whitelisted, template!(Word), experimental!(track_caller)),
310311

311312
// ==========================================================================
312313
// Internal attributes: Stability, deprecation, and unsafe:
@@ -482,10 +483,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
482483
cfg_fn!(no_debug)
483484
)
484485
),
485-
gated!(
486-
track_caller, Whitelisted, template!(Word),
487-
"the `#[track_caller]` attribute is an experimental feature",
488-
),
489486
gated!(
490487
// Used in resolve:
491488
prelude_import, Whitelisted, template!(Word),

src/test/ui/feature-gates/feature-gate-track_caller.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#[track_caller]
32
fn f() {}
43
//~^^ ERROR the `#[track_caller]` attribute is an experimental feature

src/test/ui/feature-gates/feature-gate-track_caller.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: the `#[track_caller]` attribute is an experimental feature
2-
--> $DIR/feature-gate-track_caller.rs:2:1
2+
--> $DIR/feature-gate-track_caller.rs:1:1
33
|
44
LL | #[track_caller]
55
| ^^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// run-pass
2+
#![feature(track_caller)]
3+
4+
#[track_caller]
5+
fn f() {}
6+
7+
fn main() {
8+
f();
9+
}

0 commit comments

Comments
 (0)