diff options
| author | Cameron Hart <cameron.hart@gmail.com> | 2017-03-25 19:00:49 +1100 |
|---|---|---|
| committer | Cameron Hart <cameron.hart@gmail.com> | 2017-04-21 07:37:10 +1000 |
| commit | 7971a47eff4b178ffe7c38c67b1926dacea4c0dd (patch) | |
| tree | e13abfbdef80aa9a36dd5f58dc0d12f2985cedfb /src/libsyntax | |
| parent | 4358e35fda66ab7a00215c7f9d50e7c6dc9b801b (diff) | |
| download | rust-7971a47eff4b178ffe7c38c67b1926dacea4c0dd.tar.gz rust-7971a47eff4b178ffe7c38c67b1926dacea4c0dd.zip | |
Added feature gate, updated error messages and tests.
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/attr.rs | 13 | ||||
| -rw-r--r-- | src/libsyntax/diagnostic_list.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/feature_gate.rs | 8 |
3 files changed, 18 insertions, 5 deletions
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 442345ceb3c..82492d97627 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -972,19 +972,24 @@ pub fn find_repr_attrs(diagnostic: &Handler, attr: &Attribute) -> Vec<ReprAttr> } else if let Some((name, value)) = item.name_value_literal() { if name == "align" { recognised = true; - let mut valid_align = false; + let mut align_error = None; if let ast::LitKind::Int(align, ast::LitIntType::Unsuffixed) = value.node { if align.is_power_of_two() { // rustc::ty::layout::Align restricts align to <= 32768 if align <= 32768 { acc.push(ReprAlign(align as u16)); - valid_align = true; + } else { + align_error = Some("larger than 32768"); } + } else { + align_error = Some("not a power of two"); } + } else { + align_error = Some("not an unsuffixed integer"); } - if !valid_align { + if let Some(align_error) = align_error { span_err!(diagnostic, item.span, E0589, - "align representation must be a u16 power of two"); + "invalid `repr(align)` attribute: {}", align_error); } } } diff --git a/src/libsyntax/diagnostic_list.rs b/src/libsyntax/diagnostic_list.rs index 775775875a4..01d1277ea62 100644 --- a/src/libsyntax/diagnostic_list.rs +++ b/src/libsyntax/diagnostic_list.rs @@ -292,5 +292,5 @@ register_diagnostics! { E0556, // malformed feature, expected just one word E0557, // feature has been removed E0584, // file for module `..` found at both .. and .. - E0589, // align representation must be a u16 power of two + E0589, // invalid `repr(align)` attribute } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 175447e1112..9b55a860b35 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -338,6 +338,9 @@ declare_features! ( // Allows the `catch {...}` expression (active, catch_expr, "1.17.0", Some(31436)), + // Allows `repr(align(u16))` struct attribute (RFC 1358) + (active, repr_align, "1.17.0", Some(33626)), + // See rust-lang/rfcs#1414. Allows code like `let x: &'static u32 = &42` to work. (active, rvalue_static_promotion, "1.15.1", Some(38865)), @@ -1189,6 +1192,11 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { and possibly buggy"); } + if item.check_name("align") { + gate_feature_post!(&self, repr_align, i.span, + "the struct `#[repr(align(u16))]` attribute \ + is experimental"); + } } } } |
