Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize 'attr_literals' feature. #53044

Merged
merged 1 commit into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions src/doc/unstable-book/src/language-features/attr-literals.md

This file was deleted.

1 change: 0 additions & 1 deletion src/liballoc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#![feature(allocator_api)]
#![feature(alloc_system)]
#![feature(attr_literals)]
#![feature(box_syntax)]
#![feature(const_fn)]
#![feature(drain_filter)]
Expand Down
1 change: 0 additions & 1 deletion src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
#![feature(arbitrary_self_types)]
#![feature(asm)]
#![feature(associated_type_defaults)]
#![feature(attr_literals)]
#![feature(cfg_target_has_atomic)]
#![feature(concat_idents)]
#![feature(const_fn)]
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4630,7 +4630,7 @@ field that requires non-trivial alignment.
Erroneous code example:

```compile_fail,E0691
#![feature(repr_align, attr_literals)]
#![feature(repr_align)]

#[repr(align(32))]
struct ForceAlign32;
Expand All @@ -4657,7 +4657,7 @@ Alternatively, `PhantomData<T>` has alignment 1 for all `T`, so you can use it
if you need to keep the field for some reason:

```
#![feature(repr_align, attr_literals)]
#![feature(repr_align)]

use std::marker::PhantomData;

Expand Down
1 change: 0 additions & 1 deletion src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@
#![feature(arbitrary_self_types)]
#![feature(array_error_internals)]
#![feature(asm)]
#![feature(attr_literals)]
#![feature(box_syntax)]
#![feature(cfg_target_has_atomic)]
#![feature(cfg_target_thread_local)]
Expand Down
9 changes: 4 additions & 5 deletions src/libsyntax/diagnostic_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,18 @@ Delete the offending feature attribute.
"##,

E0565: r##"
A literal was used in an attribute that doesn't support literals.
A literal was used in a built-in attribute that doesn't support literals.

Erroneous code example:

```ignore (compile_fail not working here; see Issue #43707)
#![feature(attr_literals)]

#[inline("always")] // error: unsupported literal
pub fn something() {}
```

Literals in attributes are new and largely unsupported. Work to support literals
where appropriate is ongoing. Try using an unquoted name instead:
Literals in attributes are new and largely unsupported in built-in attributes.
Work to support literals where appropriate is ongoing. Try using an unquoted
name instead:

```
#[inline(always)]
Expand Down
48 changes: 7 additions & 41 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,6 @@ declare_features! (
// Allows exhaustive pattern matching on types that contain uninhabited types
(active, exhaustive_patterns, "1.13.0", Some(51085), None),

// Allows all literals in attribute lists and values of key-value pairs
(active, attr_literals, "1.13.0", Some(34981), None),

// Allows untagged unions `union U { ... }`
(active, untagged_unions, "1.13.0", Some(32836), None),

Expand Down Expand Up @@ -654,6 +651,8 @@ declare_features! (
(accepted, tool_attributes, "1.30.0", Some(44690), None),
// Allows multi-segment paths in attributes and derives
(accepted, proc_macro_path_invoc, "1.30.0", Some(38356), None),
// Allows all literals in attribute lists and values of key-value pairs.
(accepted, attr_literals, "1.30.0", Some(34981), None),
);

// If you change this, please modify src/doc/unstable-book as well. You must
Expand Down Expand Up @@ -1451,22 +1450,6 @@ impl<'a> PostExpansionVisitor<'a> {
}
}

fn contains_novel_literal(item: &ast::MetaItem) -> bool {
use ast::MetaItemKind::*;
use ast::NestedMetaItemKind::*;

match item.node {
Word => false,
NameValue(ref lit) => !lit.node.is_str(),
List(ref list) => list.iter().any(|li| {
match li.node {
MetaItem(ref mi) => contains_novel_literal(mi),
Literal(_) => true,
}
}),
}
}

impl<'a> PostExpansionVisitor<'a> {
fn whole_crate_feature_gates(&mut self, _krate: &ast::Crate) {
for &(ident, span) in &*self.context.parse_sess.non_modrs_mods.borrow() {
Expand Down Expand Up @@ -1526,28 +1509,11 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}

if !self.context.features.unrestricted_attribute_tokens {
// Unfortunately, `parse_meta` cannot be called speculatively because it can report
// errors by itself, so we have to call it only if the feature is disabled.
match attr.parse_meta(self.context.parse_sess) {
Ok(meta) => {
// allow attr_literals in #[repr(align(x))] and #[repr(packed(n))]
let mut allow_attr_literal = false;
if attr.path == "repr" {
if let Some(content) = meta.meta_item_list() {
allow_attr_literal = content.iter().any(
|c| c.check_name("align") || c.check_name("packed"));
}
}

if !allow_attr_literal && contains_novel_literal(&meta) {
gate_feature_post!(&self, attr_literals, attr.span,
"non-string literals in attributes, or string \
literals in top-level positions, are experimental");
}
}
Err(mut err) => {
err.help("try enabling `#![feature(unrestricted_attribute_tokens)]`").emit()
}
// Unfortunately, `parse_meta` cannot be called speculatively
// because it can report errors by itself, so we have to call it
// only if the feature is disabled.
if let Err(mut err) = attr.parse_meta(self.context.parse_sess) {
err.help("try enabling `#![feature(unrestricted_attribute_tokens)]`").emit()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/pretty/attr-literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// pp-exact
// Tests literals in attributes.

#![feature(custom_attribute, attr_literals)]
#![feature(custom_attribute)]

fn main() {
#![hello("hi", 1, 2, 1.012, pi = 3.14, bye, name("John"))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// aux-build:macro_crate_test.rs
// ignore-stage1

#![feature(plugin, rustc_attrs, attr_literals)]
#![feature(plugin, rustc_attrs)]
#![plugin(macro_crate_test)]

#[macro_use]
Expand Down
1 change: 0 additions & 1 deletion src/test/run-pass/align-with-extern-c-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
// #45662

#![feature(repr_align)]
#![feature(attr_literals)]

#[repr(align(16))]
pub struct A(i64);
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/attr-usage-repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(attr_literals)]
#![feature(repr_simd)]

#[repr(C)] //~ ERROR: attribute should be applied to struct, enum or union
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/attr-usage-repr.stderr
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
error[E0517]: attribute should be applied to struct, enum or union
--> $DIR/attr-usage-repr.rs:14:8
--> $DIR/attr-usage-repr.rs:13:8
|
LL | #[repr(C)] //~ ERROR: attribute should be applied to struct, enum or union
| ^
LL | fn f() {}
| --------- not a struct, enum or union

error[E0517]: attribute should be applied to enum
--> $DIR/attr-usage-repr.rs:26:8
--> $DIR/attr-usage-repr.rs:25:8
|
LL | #[repr(i8)] //~ ERROR: attribute should be applied to enum
| ^^
LL | struct SInt(f64, f64);
| ---------------------- not an enum

error[E0517]: attribute should be applied to struct or union
--> $DIR/attr-usage-repr.rs:32:8
--> $DIR/attr-usage-repr.rs:31:8
|
LL | #[repr(align(8))] //~ ERROR: attribute should be applied to struct
| ^^^^^^^^
LL | enum EAlign { A, B }
| -------------------- not a struct or union

error[E0517]: attribute should be applied to struct or union
--> $DIR/attr-usage-repr.rs:35:8
--> $DIR/attr-usage-repr.rs:34:8
|
LL | #[repr(packed)] //~ ERROR: attribute should be applied to struct
| ^^^^^^
LL | enum EPacked { A, B }
| --------------------- not a struct or union

error[E0517]: attribute should be applied to struct
--> $DIR/attr-usage-repr.rs:38:8
--> $DIR/attr-usage-repr.rs:37:8
|
LL | #[repr(simd)] //~ ERROR: attribute should be applied to struct
| ^^^^
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/error-codes/E0565-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(attr_literals)]

// deprecated doesn't currently support literals
#[deprecated("since")] //~ ERROR E0565
fn f() { }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0565-1.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0565]: unsupported literal
--> $DIR/E0565-1.rs:14:14
--> $DIR/E0565-1.rs:12:14
|
LL | #[deprecated("since")] //~ ERROR E0565
| ^^^^^^^
Expand Down
2 changes: 0 additions & 2 deletions src/test/ui/error-codes/E0565.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(attr_literals)]

// repr currently doesn't support literals
#[repr("C")] //~ ERROR E0565
struct A { }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0565.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0565]: unsupported literal
--> $DIR/E0565.rs:14:8
--> $DIR/E0565.rs:12:8
|
LL | #[repr("C")] //~ ERROR E0565
| ^^^
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/feature-gates/feature-gate-custom_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

// Check that literals in attributes parse just fine.

#![feature(rustc_attrs, attr_literals)]
#![feature(rustc_attrs)]
#![allow(dead_code)]
#![allow(unused_variables)]

Expand Down
43 changes: 0 additions & 43 deletions src/test/ui/gated-attr-literals.rs

This file was deleted.

Loading