about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSimonas Kazlauskas <git@kazlauskas.me>2019-01-19 00:37:52 +0200
committerSimonas Kazlauskas <git@kazlauskas.me>2019-01-25 19:20:38 +0200
commitce289c6c9911c7ea55b7f30b125d3c38ed359da4 (patch)
treef69e5e7e9233b1afb5cd865009d14ff62a4ab9ed
parent89e34d3e32bcb8bc52f3b9deeae7034d7f045388 (diff)
downloadrust-ce289c6c9911c7ea55b7f30b125d3c38ed359da4.tar.gz
rust-ce289c6c9911c7ea55b7f30b125d3c38ed359da4.zip
Resolve breakage
-rw-r--r--src/librustc_codegen_llvm/attributes.rs41
-rw-r--r--src/librustc_codegen_llvm/declare.rs24
-rw-r--r--src/librustc_typeck/collect.rs2
-rw-r--r--src/librustc_typeck/diagnostics.rs2
-rw-r--r--src/libsyntax/feature_gate.rs2
-rw-r--r--src/test/ui/feature-gate-optimize_attribute.rs13
-rw-r--r--src/test/ui/feature-gate-optimize_attribute.stderr23
7 files changed, 46 insertions, 61 deletions
diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs
index a7d4f910f7a..e6bc7bca46b 100644
--- a/src/librustc_codegen_llvm/attributes.rs
+++ b/src/librustc_codegen_llvm/attributes.rs
@@ -144,6 +144,28 @@ pub fn non_lazy_bind(sess: &Session, llfn: &'ll Value) {
     }
 }
 
+pub(crate) fn default_optimisation_attrs(sess: &Session, llfn: &'ll Value) {
+    match sess.opts.optimize {
+        OptLevel::Size => {
+            llvm::Attribute::MinSize.unapply_llfn(Function, llfn);
+            llvm::Attribute::OptimizeForSize.apply_llfn(Function, llfn);
+            llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
+        },
+        OptLevel::SizeMin => {
+            llvm::Attribute::MinSize.apply_llfn(Function, llfn);
+            llvm::Attribute::OptimizeForSize.apply_llfn(Function, llfn);
+            llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
+        }
+        OptLevel::No => {
+            llvm::Attribute::MinSize.unapply_llfn(Function, llfn);
+            llvm::Attribute::OptimizeForSize.unapply_llfn(Function, llfn);
+            llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
+        }
+        _ => {}
+    }
+}
+
+
 /// Composite function which sets LLVM attributes for function depending on its AST (`#[attribute]`)
 /// attributes.
 pub fn from_fn_attrs(
@@ -157,24 +179,7 @@ pub fn from_fn_attrs(
 
     match codegen_fn_attrs.optimize {
         OptimizeAttr::None => {
-            match cx.tcx.sess.opts.optimize {
-                OptLevel::Size => {
-                    llvm::Attribute::MinSize.unapply_llfn(Function, llfn);
-                    llvm::Attribute::OptimizeForSize.apply_llfn(Function, llfn);
-                    llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
-                },
-                OptLevel::SizeMin => {
-                    llvm::Attribute::MinSize.apply_llfn(Function, llfn);
-                    llvm::Attribute::OptimizeForSize.apply_llfn(Function, llfn);
-                    llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
-                }
-                OptLevel::No => {
-                    llvm::Attribute::MinSize.unapply_llfn(Function, llfn);
-                    llvm::Attribute::OptimizeForSize.unapply_llfn(Function, llfn);
-                    llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
-                }
-                _ => {}
-            }
+            default_optimisation_attrs(cx.tcx.sess, llfn);
         }
         OptimizeAttr::Speed => {
             llvm::Attribute::MinSize.unapply_llfn(Function, llfn);
diff --git a/src/librustc_codegen_llvm/declare.rs b/src/librustc_codegen_llvm/declare.rs
index da45e0200d8..6b7ee16cb71 100644
--- a/src/librustc_codegen_llvm/declare.rs
+++ b/src/librustc_codegen_llvm/declare.rs
@@ -15,7 +15,7 @@ use llvm;
 use llvm::AttributePlace::Function;
 use rustc::ty::{self, PolyFnSig};
 use rustc::ty::layout::LayoutOf;
-use rustc::session::config::{Sanitizer, OptLevel};
+use rustc::session::config::Sanitizer;
 use rustc_data_structures::small_c_str::SmallCStr;
 use abi::{FnType, FnTypeExt};
 use attributes;
@@ -65,28 +65,8 @@ fn declare_raw_fn(
         }
     }
 
-    // FIXME(opt): this is kinda duplicated with similar code in attributes::from_fn_attrs…
-    match cx.tcx.sess.opts.optimize {
-        OptLevel::Size => {
-            llvm::Attribute::MinSize.unapply_llfn(Function, llfn);
-            llvm::Attribute::OptimizeForSize.apply_llfn(Function, llfn);
-            llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
-        },
-        OptLevel::SizeMin => {
-            llvm::Attribute::MinSize.apply_llfn(Function, llfn);
-            llvm::Attribute::OptimizeForSize.apply_llfn(Function, llfn);
-            llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
-        }
-        OptLevel::No => {
-            llvm::Attribute::MinSize.unapply_llfn(Function, llfn);
-            llvm::Attribute::OptimizeForSize.unapply_llfn(Function, llfn);
-            llvm::Attribute::OptimizeNone.unapply_llfn(Function, llfn);
-        }
-        _ => {}
-    }
-
+    attributes::default_optimisation_attrs(cx.tcx.sess, llfn);
     attributes::non_lazy_bind(cx.sess(), llfn);
-
     llfn
 }
 
diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs
index 2256dbcec00..ade84faae8d 100644
--- a/src/librustc_typeck/collect.rs
+++ b/src/librustc_typeck/collect.rs
@@ -2379,7 +2379,7 @@ fn codegen_fn_attrs<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: DefId) -> Codegen
         if attr.path != "optimize" {
             return ia;
         }
-        let err = |sp, s| span_err!(tcx.sess.diagnostic(), sp, E0720, "{}", s);
+        let err = |sp, s| span_err!(tcx.sess.diagnostic(), sp, E0722, "{}", s);
         match attr.meta().map(|i| i.node) {
             Some(MetaItemKind::Word) => {
                 err(attr.span, "expected one argument");
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs
index 21dcdaf4fa0..e02111bf2bf 100644
--- a/src/librustc_typeck/diagnostics.rs
+++ b/src/librustc_typeck/diagnostics.rs
@@ -4719,5 +4719,5 @@ register_diagnostics! {
     E0645, // trait aliases not finished
     E0698, // type inside generator must be known in this context
     E0719, // duplicate values for associated type binding
-    E0720, // Malformed #[optimize] attribute
+    E0722, // Malformed #[optimize] attribute
 }
diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs
index abbcf24fca5..adc5affedc8 100644
--- a/src/libsyntax/feature_gate.rs
+++ b/src/libsyntax/feature_gate.rs
@@ -1219,7 +1219,7 @@ pub const BUILTIN_ATTRIBUTES: &[(&str, AttributeType, AttributeTemplate, Attribu
                            cfg_fn!(alloc_error_handler))),
 
     // RFC 2412
-    ("optimize", Whitelisted, Gated(Stability::Unstable,
+    ("optimize", Whitelisted, template!(List: "size|speed"), Gated(Stability::Unstable,
                                "optimize_attribute",
                                "#[optimize] attribute is an unstable feature",
                                cfg_fn!(optimize_attribute))),
diff --git a/src/test/ui/feature-gate-optimize_attribute.rs b/src/test/ui/feature-gate-optimize_attribute.rs
index 4c3126f534e..c1f75100141 100644
--- a/src/test/ui/feature-gate-optimize_attribute.rs
+++ b/src/test/ui/feature-gate-optimize_attribute.rs
@@ -1,12 +1,3 @@
-// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
 #![crate_type="rlib"]
 #![optimize(speed)] //~ ERROR #54882
 
@@ -19,7 +10,9 @@ fn size() {}
 #[optimize(speed)] //~ ERROR #54882
 fn speed() {}
 
-#[optimize(banana)] //~ ERROR #54882
+#[optimize(banana)]
+//~^ ERROR #54882
+//~| ERROR E0722
 fn not_known() {}
 
 }
diff --git a/src/test/ui/feature-gate-optimize_attribute.stderr b/src/test/ui/feature-gate-optimize_attribute.stderr
index cd790a0bb6a..ddd4c457d73 100644
--- a/src/test/ui/feature-gate-optimize_attribute.stderr
+++ b/src/test/ui/feature-gate-optimize_attribute.stderr
@@ -1,5 +1,5 @@
 error[E0658]: #[optimize] attribute is an unstable feature (see issue #54882)
-  --> $DIR/feature-gate-optimize_attribute.rs:16:1
+  --> $DIR/feature-gate-optimize_attribute.rs:7:1
    |
 LL | #[optimize(size)] //~ ERROR #54882
    | ^^^^^^^^^^^^^^^^^
@@ -7,7 +7,7 @@ LL | #[optimize(size)] //~ ERROR #54882
    = help: add #![feature(optimize_attribute)] to the crate attributes to enable
 
 error[E0658]: #[optimize] attribute is an unstable feature (see issue #54882)
-  --> $DIR/feature-gate-optimize_attribute.rs:19:1
+  --> $DIR/feature-gate-optimize_attribute.rs:10:1
    |
 LL | #[optimize(speed)] //~ ERROR #54882
    | ^^^^^^^^^^^^^^^^^^
@@ -15,15 +15,15 @@ LL | #[optimize(speed)] //~ ERROR #54882
    = help: add #![feature(optimize_attribute)] to the crate attributes to enable
 
 error[E0658]: #[optimize] attribute is an unstable feature (see issue #54882)
-  --> $DIR/feature-gate-optimize_attribute.rs:22:1
+  --> $DIR/feature-gate-optimize_attribute.rs:13:1
    |
-LL | #[optimize(banana)] //~ ERROR #54882
+LL | #[optimize(banana)]
    | ^^^^^^^^^^^^^^^^^^^
    |
    = help: add #![feature(optimize_attribute)] to the crate attributes to enable
 
 error[E0658]: #[optimize] attribute is an unstable feature (see issue #54882)
-  --> $DIR/feature-gate-optimize_attribute.rs:13:1
+  --> $DIR/feature-gate-optimize_attribute.rs:4:1
    |
 LL | #[optimize(size)] //~ ERROR #54882
    | ^^^^^^^^^^^^^^^^^
@@ -31,13 +31,20 @@ LL | #[optimize(size)] //~ ERROR #54882
    = help: add #![feature(optimize_attribute)] to the crate attributes to enable
 
 error[E0658]: #[optimize] attribute is an unstable feature (see issue #54882)
-  --> $DIR/feature-gate-optimize_attribute.rs:11:1
+  --> $DIR/feature-gate-optimize_attribute.rs:2:1
    |
 LL | #![optimize(speed)] //~ ERROR #54882
    | ^^^^^^^^^^^^^^^^^^^
    |
    = help: add #![feature(optimize_attribute)] to the crate attributes to enable
 
-error: aborting due to 5 previous errors
+error[E0722]: invalid argument
+  --> $DIR/feature-gate-optimize_attribute.rs:13:12
+   |
+LL | #[optimize(banana)]
+   |            ^^^^^^
+
+error: aborting due to 6 previous errors
 
-For more information about this error, try `rustc --explain E0658`.
+Some errors occurred: E0658, E0722.
+For more information about an error, try `rustc --explain E0658`.