track_caller run-pass test, lint cleanup, PR review.

This commit is contained in:
Adam Perry 2019-10-02 18:24:10 -07:00
parent 543449d4fd
commit 6c04c8eb8e
8 changed files with 31 additions and 32 deletions

View File

@ -1641,13 +1641,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##"

View File

@ -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)]
@ -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)
@ -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
@ -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.
@ -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!(
@ -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
}

View File

@ -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
"##,
;

View File

@ -526,7 +526,7 @@ declare_features! (
(active, raw_dylib, "1.40.0", Some(58713), 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

View File

@ -324,6 +324,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:
@ -499,10 +500,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),

View File

@ -1,4 +1,3 @@
#[track_caller]
fn f() {}
//~^^ ERROR the `#[track_caller]` attribute is an experimental feature

View File

@ -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]
| ^^^^^^^^^^^^^^^

View File

@ -0,0 +1,9 @@
// run-pass
#![feature(track_caller)]
#[track_caller]
fn f() {}
fn main() {
f();
}