Skip to content

Commit

Permalink
track_caller run-pass test, lint cleanup, PR review.
Browse files Browse the repository at this point in the history
  • Loading branch information
anp committed Oct 3, 2019
1 parent a8b2fe0 commit e9deff0
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1728,13 +1728,13 @@ attribute.
"##,

E0900: r##"
TODO: change error number
TODO: track_caller: invalid syntax
FIXME(anp): change error number
FIXME(anp): track_caller: invalid syntax
"##,

E0901: r##"
TODO: change error number
TODO: track_caller: no naked functions
FIXME(anp): change error number
FIXME(anp): track_caller: no naked functions
"##,

E0522: r##"
Expand Down
28 changes: 11 additions & 17 deletions src/librustc/hir/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::ty::TyCtxt;
use crate::ty::query::Providers;

use std::fmt::{self, Display};
use syntax::symbol::sym;
use syntax::{attr, symbol::sym};
use syntax_pos::Span;

#[derive(Copy, Clone, PartialEq)]
Expand Down Expand Up @@ -94,7 +94,6 @@ impl CheckAttrVisitor<'tcx> {
/// Checks any attribute.
fn check_attributes(&self, item: &hir::Item, target: Target) {
let mut is_valid = true;
let mut track_caller_span = None;
for attr in &item.attrs {
is_valid &= if attr.check_name(sym::inline) {
self.check_inline(attr, &item.span, target)
Expand All @@ -105,7 +104,6 @@ impl CheckAttrVisitor<'tcx> {
} else if attr.check_name(sym::target_feature) {
self.check_target_feature(attr, item, target)
} else if attr.check_name(sym::track_caller) {
track_caller_span = Some(attr.span);
self.check_track_caller(attr, &item, target)
} else {
true
Expand All @@ -122,19 +120,6 @@ impl CheckAttrVisitor<'tcx> {

self.check_repr(item, target);
self.check_used(item, target);

// Checks if `#[track_caller]` and `#[naked]` are both used.
if let Some(span) = track_caller_span {
if item.attrs.iter().any(|attr| attr.check_name(sym::naked)) {
struct_span_err!(
self.tcx.sess,
span,
E0901,
"cannot use `#[track_caller]` with `#[naked]`",
)
.emit();
}
}
}

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

/// Checks if a `#[target_feature]` can be applied.
/// Checks if a `#[track_caller]` is applied to a non-naked function. Returns `true` if valid.
fn check_track_caller(&self, attr: &hir::Attribute, item: &hir::Item, target: Target) -> bool {
if target != Target::Fn {
struct_span_err!(
Expand All @@ -164,6 +149,15 @@ impl CheckAttrVisitor<'tcx> {
.span_label(item.span, "not a function")
.emit();
false
} else if attr::contains_name(&item.attrs, sym::naked) {
struct_span_err!(
self.tcx.sess,
attr.span,
E0901,
"cannot use `#[track_caller]` with `#[naked]`",
)
.emit();
false
} else {
true
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_typeck/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4909,13 +4909,13 @@ and the pin is required to keep it in the same place in memory.
"##,

E0902: r##"
TODO: change error number
TODO: track_caller: require Rust ABI to use track_caller
FIXME(anp): change error number
FIXME(anp): track_caller: require Rust ABI to use track_caller
"##,

E0903: r##"
TODO: change error number
TODO: track_caller: can't apply in traits
FIXME(anp): change error number
FIXME(anp): track_caller: can't apply in traits
"##,

;
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/feature_gate/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ declare_features! (
(active, or_patterns, "1.38.0", Some(54883), None),

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

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
Expand Down
5 changes: 1 addition & 4 deletions src/libsyntax/feature_gate/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
),

gated!(ffi_returns_twice, Whitelisted, template!(Word), experimental!(ffi_returns_twice)),
gated!(track_caller, Whitelisted, template!(Word), experimental!(track_caller)),

// ==========================================================================
// Internal attributes: Stability, deprecation, and unsafe:
Expand Down Expand Up @@ -482,10 +483,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
cfg_fn!(no_debug)
)
),
gated!(
track_caller, Whitelisted, template!(Word),
"the `#[track_caller]` attribute is an experimental feature",
),
gated!(
// Used in resolve:
prelude_import, Whitelisted, template!(Word),
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/feature-gates/feature-gate-track_caller.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#[track_caller]
fn f() {}
//~^^ ERROR the `#[track_caller]` attribute is an experimental feature
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/feature-gates/feature-gate-track_caller.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: the `#[track_caller]` attribute is an experimental feature
--> $DIR/feature-gate-track_caller.rs:2:1
--> $DIR/feature-gate-track_caller.rs:1:1
|
LL | #[track_caller]
| ^^^^^^^^^^^^^^^
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/rfc-2091-track-caller/pass.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// run-pass
#![feature(track_caller)]

#[track_caller]
fn f() {}

fn main() {
f();
}

0 comments on commit e9deff0

Please sign in to comment.