Skip to content

Commit

Permalink
Stabilise attributes on statements.
Browse files Browse the repository at this point in the history
Note that attributes on expressions are still unstable and are behind the `stmt_expr_attributes` flag.

cc [Tracking issue](#15701)
  • Loading branch information
nrc committed Oct 11, 2016
1 parent 9bc6d26 commit a94f593
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 22 deletions.
3 changes: 1 addition & 2 deletions src/doc/reference.md
Expand Up @@ -2472,8 +2472,7 @@ The currently implemented features of the reference compiler are:
* - `default_type_parameter_fallback` - Allows type parameter defaults to
influence type inference.

* - `stmt_expr_attributes` - Allows attributes on expressions and
non-item statements.
* - `stmt_expr_attributes` - Allows attributes on expressions.

* - `type_ascription` - Allows type ascription expressions `expr: Type`.

Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/config.rs
Expand Up @@ -153,7 +153,7 @@ impl<'a> StripUnconfigured<'a> {
}

// Visit attributes on expression and statements (but not attributes on items in blocks).
fn visit_stmt_or_expr_attrs(&mut self, attrs: &[ast::Attribute]) {
fn visit_expr_attrs(&mut self, attrs: &[ast::Attribute]) {
// flag the offending attributes
for attr in attrs.iter() {
if !self.features.map(|features| features.stmt_expr_attributes).unwrap_or(true) {
Expand Down Expand Up @@ -227,7 +227,7 @@ impl<'a> StripUnconfigured<'a> {
}

pub fn configure_expr(&mut self, expr: P<ast::Expr>) -> P<ast::Expr> {
self.visit_stmt_or_expr_attrs(expr.attrs());
self.visit_expr_attrs(expr.attrs());

// If an expr is valid to cfg away it will have been removed by the
// outer stmt or expression folder before descending in here.
Expand All @@ -245,7 +245,6 @@ impl<'a> StripUnconfigured<'a> {
}

pub fn configure_stmt(&mut self, stmt: ast::Stmt) -> Option<ast::Stmt> {
self.visit_stmt_or_expr_attrs(stmt.attrs());
self.configure(stmt)
}
}
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/mir-dataflow/def-inits-1.rs
Expand Up @@ -11,7 +11,6 @@
// General test of maybe_uninits state computed by MIR dataflow.

#![feature(rustc_attrs)]
#![feature(stmt_expr_attributes)]

use std::intrinsics::rustc_peek;
use std::mem::{drop, replace};
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/mir-dataflow/inits-1.rs
Expand Up @@ -11,7 +11,6 @@
// General test of maybe_inits state computed by MIR dataflow.

#![feature(rustc_attrs)]
#![feature(stmt_expr_attributes)]

use std::intrinsics::rustc_peek;
use std::mem::{drop, replace};
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/mir-dataflow/uninits-1.rs
Expand Up @@ -11,7 +11,6 @@
// General test of maybe_uninits state computed by MIR dataflow.

#![feature(rustc_attrs)]
#![feature(stmt_expr_attributes)]

use std::intrinsics::rustc_peek;
use std::mem::{drop, replace};
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/mir-dataflow/uninits-2.rs
Expand Up @@ -11,7 +11,6 @@
// General test of maybe_uninits state computed by MIR dataflow.

#![feature(rustc_attrs)]
#![feature(stmt_expr_attributes)]

use std::intrinsics::rustc_peek;
use std::mem::{drop, replace};
Expand Down
16 changes: 8 additions & 8 deletions src/test/compile-fail/stmt_expr_attrs_no_feature.rs
Expand Up @@ -21,15 +21,15 @@ fn main() {
#[attr]
fn a() {}

#[attr] //~ ERROR 15701
#[attr]
{

}

#[attr] //~ ERROR 15701
#[attr]
5;

#[attr] //~ ERROR 15701
#[attr]
stmt_mac!();
}

Expand All @@ -43,7 +43,7 @@ fn c() {

#[cfg(not(unset))]
fn j() {
#[attr] //~ ERROR 15701
#[attr]
5;
}

Expand All @@ -55,7 +55,7 @@ fn d() {

#[cfg_attr(not(unset), cfg(not(unset)))]
fn i() {
#[attr] //~ ERROR 15701
#[attr]
8;
}

Expand All @@ -64,7 +64,7 @@ fn i() {
macro_rules! item_mac {
($e:ident) => {
fn $e() {
#[attr] //~ ERROR 15701
#[attr]
42;

#[cfg(unset)]
Expand All @@ -75,7 +75,7 @@ macro_rules! item_mac {

#[cfg(not(unset))]
fn k() {
#[attr] //~ ERROR 15701
#[attr]
5;
}

Expand All @@ -87,7 +87,7 @@ macro_rules! item_mac {

#[cfg_attr(not(unset), cfg(not(unset)))]
fn h() {
#[attr] //~ ERROR 15701
#[attr]
8;
}

Expand Down
2 changes: 0 additions & 2 deletions src/test/run-pass/const-negation.rs
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(stmt_expr_attributes)]

#[deny(const_err)]

fn main() {
Expand Down
2 changes: 0 additions & 2 deletions src/test/run-pass/enum-discrim-autosizing.rs
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(stmt_expr_attributes)]

use std::mem::size_of;

enum Ei8 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/issue-8460.rs
Expand Up @@ -11,7 +11,7 @@
// ignore-emscripten no threads support
// ignore-pretty : (#23623) problems when ending with // comments

#![feature(rustc_attrs, stmt_expr_attributes, zero_one)]
#![feature(rustc_attrs, zero_one)]

use std::num::Zero;
use std::thread;
Expand Down

0 comments on commit a94f593

Please sign in to comment.