about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/coercion/struct-coerce-vec-to-slice.rs20
-rw-r--r--tests/ui/coercion/struct-literal-field-type-coercion-to-expected-type.rs16
-rw-r--r--tests/ui/issues/issue-28777.rs22
-rw-r--r--tests/ui/issues/issue-31260.rs15
-rw-r--r--tests/ui/issues/issue-9382.rs37
-rw-r--r--tests/ui/lint/inert-attr-macro.rs7
-rw-r--r--tests/ui/lint/inert-attr-macro.stderr14
-rw-r--r--tests/ui/parser/operator-precedence-braces-exprs.rs28
-rw-r--r--tests/ui/suggestions/tuple-struct-where-clause-suggestion-91520.rs17
-rw-r--r--tests/ui/suggestions/tuple-struct-where-clause-suggestion-91520.stderr21
10 files changed, 116 insertions, 81 deletions
diff --git a/tests/ui/coercion/struct-coerce-vec-to-slice.rs b/tests/ui/coercion/struct-coerce-vec-to-slice.rs
new file mode 100644
index 00000000000..9ef20ac4ea6
--- /dev/null
+++ b/tests/ui/coercion/struct-coerce-vec-to-slice.rs
@@ -0,0 +1,20 @@
+//! Regression test that ensures struct field literals can be coerced into slice and `Box` types
+
+//@ check-pass
+
+struct Thing1<'a> {
+    baz: &'a [Box<isize>],
+    bar: Box<u64>,
+}
+
+struct Thing2<'a> {
+    baz: &'a [Box<isize>],
+    bar: u64,
+}
+
+pub fn main() {
+    let _a = Thing1 { baz: &[], bar: Box::new(32) };
+    let _b = Thing1 { baz: &Vec::new(), bar: Box::new(32) };
+    let _c = Thing2 { baz: &[], bar: 32 };
+    let _d = Thing2 { baz: &Vec::new(), bar: 32 };
+}
diff --git a/tests/ui/coercion/struct-literal-field-type-coercion-to-expected-type.rs b/tests/ui/coercion/struct-literal-field-type-coercion-to-expected-type.rs
new file mode 100644
index 00000000000..0b8ec7dc07a
--- /dev/null
+++ b/tests/ui/coercion/struct-literal-field-type-coercion-to-expected-type.rs
@@ -0,0 +1,16 @@
+//! Regression test to check that literal expressions in a struct field can be coerced to the
+//! expected field type, including block expressions.
+//!
+//! Issue: <https://github.com/rust-lang/rust/issues/31260>
+
+//@ check-pass
+
+pub struct Struct<K: 'static> {
+    pub field: K,
+}
+
+static STRUCT: Struct<&'static [u8]> = Struct { field: { &[1] } };
+
+static STRUCT2: Struct<&'static [u8]> = Struct { field: &[1] };
+
+fn main() {}
diff --git a/tests/ui/issues/issue-28777.rs b/tests/ui/issues/issue-28777.rs
deleted file mode 100644
index f67e11e3694..00000000000
--- a/tests/ui/issues/issue-28777.rs
+++ /dev/null
@@ -1,22 +0,0 @@
-//@ run-pass
-#![allow(unused_braces)]
-fn main() {
-    let v1 = { 1 + {2} * {3} };
-    let v2 =   1 + {2} * {3}  ;
-
-    assert_eq!(7, v1);
-    assert_eq!(7, v2);
-
-    let v3;
-    v3 = { 1 + {2} * {3} };
-    let v4;
-    v4 = 1 + {2} * {3};
-    assert_eq!(7, v3);
-    assert_eq!(7, v4);
-
-    let v5 = { 1 + {2} * 3 };
-    assert_eq!(7, v5);
-
-    let v9 = { 1 + if 1 > 2 {1} else {2} * {3} };
-    assert_eq!(7, v9);
-}
diff --git a/tests/ui/issues/issue-31260.rs b/tests/ui/issues/issue-31260.rs
deleted file mode 100644
index 5e9fffb195c..00000000000
--- a/tests/ui/issues/issue-31260.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-//@ check-pass
-#![allow(dead_code)]
-pub struct Struct<K: 'static> {
-    pub field: K,
-}
-
-static STRUCT: Struct<&'static [u8]> = Struct {
-    field: {&[1]}
-};
-
-static STRUCT2: Struct<&'static [u8]> = Struct {
-    field: &[1]
-};
-
-fn main() {}
diff --git a/tests/ui/issues/issue-9382.rs b/tests/ui/issues/issue-9382.rs
deleted file mode 100644
index 27f9ab57743..00000000000
--- a/tests/ui/issues/issue-9382.rs
+++ /dev/null
@@ -1,37 +0,0 @@
-//@ run-pass
-#![allow(dead_code)]
-
-// Tests for a previous bug that occurred due to an interaction
-// between struct field initialization and the auto-coercion
-// from a vector to a slice. The drop glue was being invoked on
-// the temporary slice with a wrong type, triggering an LLVM assert.
-
-
-struct Thing1<'a> {
-    baz: &'a [Box<isize>],
-    bar: Box<u64>,
-}
-
-struct Thing2<'a> {
-    baz: &'a [Box<isize>],
-    bar: u64,
-}
-
-pub fn main() {
-    let _t1_fixed = Thing1 {
-        baz: &[],
-        bar: Box::new(32),
-    };
-    Thing1 {
-        baz: &Vec::new(),
-        bar: Box::new(32),
-    };
-    let _t2_fixed = Thing2 {
-        baz: &[],
-        bar: 32,
-    };
-    Thing2 {
-        baz: &Vec::new(),
-        bar: 32,
-    };
-}
diff --git a/tests/ui/lint/inert-attr-macro.rs b/tests/ui/lint/inert-attr-macro.rs
index 90303a1fc3d..5d4133d6c77 100644
--- a/tests/ui/lint/inert-attr-macro.rs
+++ b/tests/ui/lint/inert-attr-macro.rs
@@ -1,5 +1,6 @@
 //@ check-pass
 
+#![feature(cfg_boolean_literals)]
 #![warn(unused)]
 
 macro_rules! foo {
@@ -17,4 +18,10 @@ fn main() {
     // This does work, since the attribute is on a parent
     // of the macro invocation.
     #[allow(warnings)] { #[inline] foo!(); }
+
+    // Ok, `cfg` and `cfg_attr` are expanded eagerly and do not warn.
+    #[cfg(true)] foo!();
+    #[cfg(false)] foo!();
+    #[cfg_attr(true, cfg(true))] foo!();
+    #[cfg_attr(false, nonexistent)] foo!();
 }
diff --git a/tests/ui/lint/inert-attr-macro.stderr b/tests/ui/lint/inert-attr-macro.stderr
index 5ccb4ffe792..b85b0319e71 100644
--- a/tests/ui/lint/inert-attr-macro.stderr
+++ b/tests/ui/lint/inert-attr-macro.stderr
@@ -1,41 +1,41 @@
 warning: unused attribute `inline`
-  --> $DIR/inert-attr-macro.rs:10:5
+  --> $DIR/inert-attr-macro.rs:11:5
    |
 LL |     #[inline] foo!();
    |     ^^^^^^^^^
    |
 note: the built-in attribute `inline` will be ignored, since it's applied to the macro invocation `foo`
-  --> $DIR/inert-attr-macro.rs:10:15
+  --> $DIR/inert-attr-macro.rs:11:15
    |
 LL |     #[inline] foo!();
    |               ^^^
 note: the lint level is defined here
-  --> $DIR/inert-attr-macro.rs:3:9
+  --> $DIR/inert-attr-macro.rs:4:9
    |
 LL | #![warn(unused)]
    |         ^^^^^^
    = note: `#[warn(unused_attributes)]` implied by `#[warn(unused)]`
 
 warning: unused attribute `allow`
-  --> $DIR/inert-attr-macro.rs:14:5
+  --> $DIR/inert-attr-macro.rs:15:5
    |
 LL |     #[allow(warnings)] #[inline] foo!();
    |     ^^^^^^^^^^^^^^^^^^
    |
 note: the built-in attribute `allow` will be ignored, since it's applied to the macro invocation `foo`
-  --> $DIR/inert-attr-macro.rs:14:34
+  --> $DIR/inert-attr-macro.rs:15:34
    |
 LL |     #[allow(warnings)] #[inline] foo!();
    |                                  ^^^
 
 warning: unused attribute `inline`
-  --> $DIR/inert-attr-macro.rs:14:24
+  --> $DIR/inert-attr-macro.rs:15:24
    |
 LL |     #[allow(warnings)] #[inline] foo!();
    |                        ^^^^^^^^^
    |
 note: the built-in attribute `inline` will be ignored, since it's applied to the macro invocation `foo`
-  --> $DIR/inert-attr-macro.rs:14:34
+  --> $DIR/inert-attr-macro.rs:15:34
    |
 LL |     #[allow(warnings)] #[inline] foo!();
    |                                  ^^^
diff --git a/tests/ui/parser/operator-precedence-braces-exprs.rs b/tests/ui/parser/operator-precedence-braces-exprs.rs
new file mode 100644
index 00000000000..d6f44ef879c
--- /dev/null
+++ b/tests/ui/parser/operator-precedence-braces-exprs.rs
@@ -0,0 +1,28 @@
+//! Regression test for ensuring that operator precedence is correctly handled in the presence of
+//! braces
+//!
+//! Issue: <https://github.com/rust-lang/rust/issues/28777>
+
+//@ run-pass
+
+#[allow(unused_braces)]
+fn main() {
+    let v1 = { 1 + { 2 } * { 3 } };
+    let v2 = 1 + { 2 } * { 3 };
+
+    assert_eq!(7, v1);
+    assert_eq!(7, v2);
+
+    let v3;
+    v3 = { 1 + { 2 } * { 3 } };
+    let v4;
+    v4 = 1 + { 2 } * { 3 };
+    assert_eq!(7, v3);
+    assert_eq!(7, v4);
+
+    let v5 = { 1 + { 2 } * 3 };
+    assert_eq!(7, v5);
+
+    let v9 = { 1 + if 1 > 2 { 1 } else { 2 } * { 3 } };
+    assert_eq!(7, v9);
+}
diff --git a/tests/ui/suggestions/tuple-struct-where-clause-suggestion-91520.rs b/tests/ui/suggestions/tuple-struct-where-clause-suggestion-91520.rs
new file mode 100644
index 00000000000..b7086325d5f
--- /dev/null
+++ b/tests/ui/suggestions/tuple-struct-where-clause-suggestion-91520.rs
@@ -0,0 +1,17 @@
+// Verify that the `where` clause suggestion is in the correct place
+// Previously, the suggestion to add `where` clause was placed inside the derive
+// like `#[derive(Clone where Inner<T>: Clone)]`
+// instead of `struct Outer<T>(Inner<T>) where Inner<T>: Clone`
+
+#![crate_type = "lib"]
+
+struct Inner<T>(T);
+//~^ HELP consider annotating `Inner<T>` with `#[derive(Clone)]`
+impl Clone for Inner<()> {
+    fn clone(&self) -> Self { todo!() }
+}
+
+#[derive(Clone)]
+struct Outer<T>(Inner<T>);
+//~^ ERROR the trait bound `Inner<T>: Clone` is not satisfied [E0277]
+//~| HELP consider introducing a `where` clause
diff --git a/tests/ui/suggestions/tuple-struct-where-clause-suggestion-91520.stderr b/tests/ui/suggestions/tuple-struct-where-clause-suggestion-91520.stderr
new file mode 100644
index 00000000000..577b090ce1b
--- /dev/null
+++ b/tests/ui/suggestions/tuple-struct-where-clause-suggestion-91520.stderr
@@ -0,0 +1,21 @@
+error[E0277]: the trait bound `Inner<T>: Clone` is not satisfied
+  --> $DIR/tuple-struct-where-clause-suggestion-91520.rs:15:17
+   |
+LL | #[derive(Clone)]
+   |          ----- in this derive macro expansion
+LL | struct Outer<T>(Inner<T>);
+   |                 ^^^^^^^^ the trait `Clone` is not implemented for `Inner<T>`
+   |
+help: consider annotating `Inner<T>` with `#[derive(Clone)]`
+   |
+LL + #[derive(Clone)]
+LL | struct Inner<T>(T);
+   |
+help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
+   |
+LL | struct Outer<T>(Inner<T>) where Inner<T>: Clone;
+   |                           +++++++++++++++++++++
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0277`.