about summary refs log tree commit diff
path: root/tests/ui
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui')
-rw-r--r--tests/ui/associated-types/projection-dyn-associated-type.rs28
-rw-r--r--tests/ui/associated-types/projection-dyn-associated-type.stderr52
-rw-r--r--tests/ui/did_you_mean/issue-48492-tuple-destructure-missing-parens.stderr4
-rw-r--r--tests/ui/feature-gates/feature-gate-never_patterns.stderr2
-rw-r--r--tests/ui/parser/match-arm-without-body.rs4
-rw-r--r--tests/ui/parser/match-arm-without-body.stderr11
-rw-r--r--tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.fixed18
-rw-r--r--tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.rs18
-rw-r--r--tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.stderr18
9 files changed, 143 insertions, 12 deletions
diff --git a/tests/ui/associated-types/projection-dyn-associated-type.rs b/tests/ui/associated-types/projection-dyn-associated-type.rs
new file mode 100644
index 00000000000..3b981e7987e
--- /dev/null
+++ b/tests/ui/associated-types/projection-dyn-associated-type.rs
@@ -0,0 +1,28 @@
+// Regression test for the projection bug in <https://github.com/rust-lang/rust/issues/123953>
+//
+//@ compile-flags: -Zincremental-verify-ich=yes
+//@ incremental
+
+pub trait A {}
+pub trait B: A {}
+
+pub trait Mirror {
+    type Assoc: ?Sized;
+}
+
+impl<T: ?Sized> Mirror for A {
+    //~^ ERROR the type parameter `T` is not constrained by the impl trait, self type, or predicates [E0207]
+    //~| WARN trait objects without an explicit `dyn` are deprecated [bare_trait_objects]
+    //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
+    type Assoc = T;
+}
+
+pub fn foo<'a>(
+    x: &'a <dyn A + 'static as Mirror>::Assoc
+) -> &'a <dyn B + 'static as Mirror>::Assoc {
+    //~^ ERROR the trait bound `(dyn B + 'static): Mirror` is not satisfied [E0277]
+    //~| ERROR the trait bound `(dyn B + 'static): Mirror` is not satisfied [E0277]
+    static
+} //~ ERROR expected identifier, found `}`
+
+pub fn main() {}
diff --git a/tests/ui/associated-types/projection-dyn-associated-type.stderr b/tests/ui/associated-types/projection-dyn-associated-type.stderr
new file mode 100644
index 00000000000..1ac2beb0414
--- /dev/null
+++ b/tests/ui/associated-types/projection-dyn-associated-type.stderr
@@ -0,0 +1,52 @@
+error: expected identifier, found `}`
+  --> $DIR/projection-dyn-associated-type.rs:26:1
+   |
+LL | }
+   | ^ expected identifier
+
+warning: trait objects without an explicit `dyn` are deprecated
+  --> $DIR/projection-dyn-associated-type.rs:13:28
+   |
+LL | impl<T: ?Sized> Mirror for A {
+   |                            ^
+   |
+   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
+   = note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2021/warnings-promoted-to-error.html>
+   = note: `#[warn(bare_trait_objects)]` (part of `#[warn(rust_2021_compatibility)]`) on by default
+help: if this is a dyn-compatible trait, use `dyn`
+   |
+LL | impl<T: ?Sized> Mirror for dyn A {
+   |                            +++
+help: alternatively use a blanket implementation to implement `Mirror` for all types that also implement `A`
+   |
+LL - impl<T: ?Sized> Mirror for A {
+LL + impl<T: ?Sized, U: A> Mirror for U {
+   |
+
+error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
+  --> $DIR/projection-dyn-associated-type.rs:13:6
+   |
+LL | impl<T: ?Sized> Mirror for A {
+   |      ^ unconstrained type parameter
+
+error[E0277]: the trait bound `(dyn B + 'static): Mirror` is not satisfied
+  --> $DIR/projection-dyn-associated-type.rs:22:6
+   |
+LL | ) -> &'a <dyn B + 'static as Mirror>::Assoc {
+   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Mirror` is not implemented for `(dyn B + 'static)`
+   |
+   = help: the trait `Mirror` is implemented for `dyn A`
+
+error[E0277]: the trait bound `(dyn B + 'static): Mirror` is not satisfied
+  --> $DIR/projection-dyn-associated-type.rs:22:6
+   |
+LL | ) -> &'a <dyn B + 'static as Mirror>::Assoc {
+   |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Mirror` is not implemented for `(dyn B + 'static)`
+   |
+   = help: the trait `Mirror` is implemented for `dyn A`
+   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+
+error: aborting due to 4 previous errors; 1 warning emitted
+
+Some errors have detailed explanations: E0207, E0277.
+For more information about an error, try `rustc --explain E0207`.
diff --git a/tests/ui/did_you_mean/issue-48492-tuple-destructure-missing-parens.stderr b/tests/ui/did_you_mean/issue-48492-tuple-destructure-missing-parens.stderr
index c74cb89f85c..286d6021396 100644
--- a/tests/ui/did_you_mean/issue-48492-tuple-destructure-missing-parens.stderr
+++ b/tests/ui/did_you_mean/issue-48492-tuple-destructure-missing-parens.stderr
@@ -32,10 +32,10 @@ help: try adding parentheses to match on a tuple...
    |
 LL |         (Nucleotide::Adenine, Nucleotide::Cytosine, _) => true
    |         +                                            +
-help: ...or a vertical bar to match on multiple alternatives
+help: ...or a vertical bar to match on alternatives
    |
 LL -         Nucleotide::Adenine, Nucleotide::Cytosine, _ => true
-LL +         Nucleotide::Adenine | Nucleotide::Cytosine | _ => true
+LL +         Nucleotide::Adenine | Nucleotide::Cytosine, _ => true
    |
 
 error: unexpected `,` in pattern
diff --git a/tests/ui/feature-gates/feature-gate-never_patterns.stderr b/tests/ui/feature-gates/feature-gate-never_patterns.stderr
index 473e263c796..e655209924a 100644
--- a/tests/ui/feature-gates/feature-gate-never_patterns.stderr
+++ b/tests/ui/feature-gates/feature-gate-never_patterns.stderr
@@ -8,7 +8,7 @@ help: try adding parentheses to match on a tuple...
    |
 LL |         (Some(_),)
    |         +        +
-help: ...or a vertical bar to match on multiple alternatives
+help: ...or a vertical bar to match on alternatives
    |
 LL -         Some(_),
 LL +         Some(_) |
diff --git a/tests/ui/parser/match-arm-without-body.rs b/tests/ui/parser/match-arm-without-body.rs
index 4723abff8b6..7fe5b6d2539 100644
--- a/tests/ui/parser/match-arm-without-body.rs
+++ b/tests/ui/parser/match-arm-without-body.rs
@@ -17,13 +17,13 @@ fn main() {
         Some(_),
         //~^ ERROR unexpected `,` in pattern
         //~| HELP try adding parentheses to match on a tuple
-        //~| HELP or a vertical bar to match on multiple alternatives
+        //~| HELP or a vertical bar to match on alternative
     }
     match Some(false) {
         Some(_),
         //~^ ERROR unexpected `,` in pattern
         //~| HELP try adding parentheses to match on a tuple
-        //~| HELP or a vertical bar to match on multiple alternatives
+        //~| HELP or a vertical bar to match on alternative
         _ => {}
     }
     match Some(false) {
diff --git a/tests/ui/parser/match-arm-without-body.stderr b/tests/ui/parser/match-arm-without-body.stderr
index a65875b787a..59a323f2cc1 100644
--- a/tests/ui/parser/match-arm-without-body.stderr
+++ b/tests/ui/parser/match-arm-without-body.stderr
@@ -16,7 +16,7 @@ help: try adding parentheses to match on a tuple...
    |
 LL |         (Some(_),)
    |         +        +
-help: ...or a vertical bar to match on multiple alternatives
+help: ...or a vertical bar to match on alternatives
    |
 LL -         Some(_),
 LL +         Some(_) |
@@ -36,13 +36,10 @@ LL |
 LL |
 LL ~         _) => {}
    |
-help: ...or a vertical bar to match on multiple alternatives
+help: ...or a vertical bar to match on alternatives
    |
-LL ~         Some(_) |
-LL +
-LL +
-LL +
-LL ~         _ => {}
+LL -         Some(_),
+LL +         Some(_) |
    |
 
 error: expected one of `.`, `=>`, `?`, or an operator, found reserved identifier `_`
diff --git a/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.fixed b/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.fixed
new file mode 100644
index 00000000000..0258f868f00
--- /dev/null
+++ b/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.fixed
@@ -0,0 +1,18 @@
+//@ run-rustfix
+
+// Regression test for issue #143330.
+// Ensure we suggest to replace only the intended coma with a bar, not all commas in the pattern.
+
+fn main() {
+    struct Foo { x: i32, ch: char }
+    let pos = Foo { x: 2, ch: 'x' };
+    match pos {
+        // All commas here were replaced with bars.
+        // Foo { x: 2 | ch: ' |' } | Foo { x: 3 | ch: '@' } => (),
+        (Foo { x: 2, ch: ',' } | Foo { x: 3, ch: '@' }) => (),
+        //~^ ERROR unexpected `,` in pattern
+        //~| HELP try adding parentheses to match on a tuple...
+        //~| HELP ...or a vertical bar to match on alternative
+        _ => todo!(),
+    }
+}
diff --git a/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.rs b/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.rs
new file mode 100644
index 00000000000..7d5087fa0ff
--- /dev/null
+++ b/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.rs
@@ -0,0 +1,18 @@
+//@ run-rustfix
+
+// Regression test for issue #143330.
+// Ensure we suggest to replace only the intended coma with a bar, not all commas in the pattern.
+
+fn main() {
+    struct Foo { x: i32, ch: char }
+    let pos = Foo { x: 2, ch: 'x' };
+    match pos {
+        // All commas here were replaced with bars.
+        // Foo { x: 2 | ch: ' |' } | Foo { x: 3 | ch: '@' } => (),
+        Foo { x: 2, ch: ',' }, Foo { x: 3, ch: '@' } => (),
+        //~^ ERROR unexpected `,` in pattern
+        //~| HELP try adding parentheses to match on a tuple...
+        //~| HELP ...or a vertical bar to match on alternative
+        _ => todo!(),
+    }
+}
diff --git a/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.stderr b/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.stderr
new file mode 100644
index 00000000000..ee75e2db133
--- /dev/null
+++ b/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.stderr
@@ -0,0 +1,18 @@
+error: unexpected `,` in pattern
+  --> $DIR/only-replace-intended-coma-not-all-in-pattern.rs:12:30
+   |
+LL |         Foo { x: 2, ch: ',' }, Foo { x: 3, ch: '@' } => (),
+   |                              ^
+   |
+help: try adding parentheses to match on a tuple...
+   |
+LL |         (Foo { x: 2, ch: ',' }, Foo { x: 3, ch: '@' }) => (),
+   |         +                                            +
+help: ...or a vertical bar to match on alternatives
+   |
+LL -         Foo { x: 2, ch: ',' }, Foo { x: 3, ch: '@' } => (),
+LL +         Foo { x: 2, ch: ',' } | Foo { x: 3, ch: '@' } => (),
+   |
+
+error: aborting due to 1 previous error
+