diff options
| author | Jubilee Young <workingjubilee@gmail.com> | 2024-05-19 16:11:46 -0700 |
|---|---|---|
| committer | Jubilee Young <workingjubilee@gmail.com> | 2024-05-20 19:55:59 -0700 |
| commit | d89500843caf666998619bbc0c88d5857726963d (patch) | |
| tree | a004fb459e4d686f805a5f22882fc10ed743b87c /tests/ui/pattern | |
| parent | 8e7517d99a8aaab02b512483ae91f8b79553fa3d (diff) | |
| download | rust-d89500843caf666998619bbc0c88d5857726963d.tar.gz rust-d89500843caf666998619bbc0c88d5857726963d.zip | |
Move 100 entries from tests/ui into subdirs
- Move super-fast-paren-parsing test into ui/parser - Move stmt_expr_attrs test into ui/feature-gates - Move macro tests into ui/macros - Move global_asm tests into ui/asm - Move env tests into ui/process - Move xcrate tests into ui/cross-crate - Move unop tests into ui/unop - Move backtrace tests into ui/backtrace - Move check-static tests into ui/statics - Move expr tests into ui/expr - Move optimization fuel tests into ui/fuel - Move ffi attribute tests into ui/ffi-attrs - Move suggestion tests into ui/suggestions - Move main tests into ui/fn-main - Move lint tests into ui/lint - Move repr tests into ui/repr - Move intrinsics tests into ui/intrinsics - Move tool lint tests into ui/tool-attributes - Move return tests into ui/return - Move pattern tests into ui/patttern - Move range tests into ui/range - Move foreign-fn tests into ui/foreign - Move orphan-check tests into ui/coherence - Move inference tests into ui/inference - Reduce ROOT_ENTRY_LIMIT
Diffstat (limited to 'tests/ui/pattern')
| -rw-r--r-- | tests/ui/pattern/by-move-pattern-binding.rs | 29 | ||||
| -rw-r--r-- | tests/ui/pattern/by-move-pattern-binding.stderr | 51 | ||||
| -rw-r--r-- | tests/ui/pattern/fn-in-pat.rs | 16 | ||||
| -rw-r--r-- | tests/ui/pattern/fn-in-pat.stderr | 11 | ||||
| -rw-r--r-- | tests/ui/pattern/inc-range-pat.rs | 12 | ||||
| -rw-r--r-- | tests/ui/pattern/no-patterns-in-args-2.rs | 13 | ||||
| -rw-r--r-- | tests/ui/pattern/no-patterns-in-args-2.stderr | 23 | ||||
| -rw-r--r-- | tests/ui/pattern/no-patterns-in-args.rs | 16 | ||||
| -rw-r--r-- | tests/ui/pattern/no-patterns-in-args.stderr | 34 |
9 files changed, 205 insertions, 0 deletions
diff --git a/tests/ui/pattern/by-move-pattern-binding.rs b/tests/ui/pattern/by-move-pattern-binding.rs new file mode 100644 index 00000000000..f68d181291d --- /dev/null +++ b/tests/ui/pattern/by-move-pattern-binding.rs @@ -0,0 +1,29 @@ +enum E { + Foo, + Bar(String) +} + +struct S { + x: E +} + +fn f(x: String) {} + +fn main() { + let s = S { x: E::Bar("hello".to_string()) }; + match &s.x { //~ ERROR cannot move + &E::Foo => {} + &E::Bar(identifier) => f(identifier.clone()) + }; + match &s.x { + &E::Foo => {} + &E::Bar(ref identifier) => println!("{}", *identifier) + }; + if let &E::Bar(identifier) = &s.x { //~ ERROR cannot move + f(identifier.clone()); + }; + let &E::Bar(identifier) = &s.x else { //~ ERROR cannot move + return; + }; + f(identifier.clone()); +} diff --git a/tests/ui/pattern/by-move-pattern-binding.stderr b/tests/ui/pattern/by-move-pattern-binding.stderr new file mode 100644 index 00000000000..203e37dc387 --- /dev/null +++ b/tests/ui/pattern/by-move-pattern-binding.stderr @@ -0,0 +1,51 @@ +error[E0507]: cannot move out of a shared reference + --> $DIR/by-move-pattern-binding.rs:14:11 + | +LL | match &s.x { + | ^^^^ +LL | &E::Foo => {} +LL | &E::Bar(identifier) => f(identifier.clone()) + | ---------- + | | + | data moved here + | move occurs because `identifier` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - &E::Bar(identifier) => f(identifier.clone()) +LL + E::Bar(identifier) => f(identifier.clone()) + | + +error[E0507]: cannot move out of a shared reference + --> $DIR/by-move-pattern-binding.rs:22:34 + | +LL | if let &E::Bar(identifier) = &s.x { + | ---------- ^^^^ + | | + | data moved here + | move occurs because `identifier` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - if let &E::Bar(identifier) = &s.x { +LL + if let E::Bar(identifier) = &s.x { + | + +error[E0507]: cannot move out of a shared reference + --> $DIR/by-move-pattern-binding.rs:25:31 + | +LL | let &E::Bar(identifier) = &s.x else { + | ---------- ^^^^ + | | + | data moved here + | move occurs because `identifier` has type `String`, which does not implement the `Copy` trait + | +help: consider removing the borrow + | +LL - let &E::Bar(identifier) = &s.x else { +LL + let E::Bar(identifier) = &s.x else { + | + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0507`. diff --git a/tests/ui/pattern/fn-in-pat.rs b/tests/ui/pattern/fn-in-pat.rs new file mode 100644 index 00000000000..2d7c86b8666 --- /dev/null +++ b/tests/ui/pattern/fn-in-pat.rs @@ -0,0 +1,16 @@ +struct A {} + +impl A { + fn new() {} +} + +fn hof<F>(_: F) where F: FnMut(()) {} + +fn ice() { + hof(|c| match c { + A::new() => (), //~ ERROR expected tuple struct or tuple variant, found associated function + _ => () + }) +} + +fn main() {} diff --git a/tests/ui/pattern/fn-in-pat.stderr b/tests/ui/pattern/fn-in-pat.stderr new file mode 100644 index 00000000000..41ea4df72a2 --- /dev/null +++ b/tests/ui/pattern/fn-in-pat.stderr @@ -0,0 +1,11 @@ +error[E0164]: expected tuple struct or tuple variant, found associated function `A::new` + --> $DIR/fn-in-pat.rs:11:9 + | +LL | A::new() => (), + | ^^^^^^^^ `fn` calls are not allowed in patterns + | + = help: for more information, visit https://doc.rust-lang.org/book/ch18-00-patterns.html + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0164`. diff --git a/tests/ui/pattern/inc-range-pat.rs b/tests/ui/pattern/inc-range-pat.rs new file mode 100644 index 00000000000..189dac4feed --- /dev/null +++ b/tests/ui/pattern/inc-range-pat.rs @@ -0,0 +1,12 @@ +//@ run-pass +// Test old and new syntax for inclusive range patterns. + +#![allow(ellipsis_inclusive_range_patterns)] + +fn main() { + assert!(match 42 { 0 ... 100 => true, _ => false }); + assert!(match 42 { 0 ..= 100 => true, _ => false }); + + assert!(match 'x' { 'a' ... 'z' => true, _ => false }); + assert!(match 'x' { 'a' ..= 'z' => true, _ => false }); +} diff --git a/tests/ui/pattern/no-patterns-in-args-2.rs b/tests/ui/pattern/no-patterns-in-args-2.rs new file mode 100644 index 00000000000..85b7fc5cdba --- /dev/null +++ b/tests/ui/pattern/no-patterns-in-args-2.rs @@ -0,0 +1,13 @@ +#![deny(patterns_in_fns_without_body)] + +trait Tr { + fn f1(mut arg: u8); //~ ERROR patterns aren't allowed in functions without bodies + //~^ WARN was previously accepted + fn f2(&arg: u8); //~ ERROR patterns aren't allowed in functions without bodies + fn g1(arg: u8); // OK + fn g2(_: u8); // OK + #[allow(anonymous_parameters)] + fn g3(u8); // OK +} + +fn main() {} diff --git a/tests/ui/pattern/no-patterns-in-args-2.stderr b/tests/ui/pattern/no-patterns-in-args-2.stderr new file mode 100644 index 00000000000..6adcbb9dccd --- /dev/null +++ b/tests/ui/pattern/no-patterns-in-args-2.stderr @@ -0,0 +1,23 @@ +error[E0642]: patterns aren't allowed in functions without bodies + --> $DIR/no-patterns-in-args-2.rs:6:11 + | +LL | fn f2(&arg: u8); + | ^^^^ pattern not allowed in function without body + +error: patterns aren't allowed in functions without bodies + --> $DIR/no-patterns-in-args-2.rs:4:11 + | +LL | fn f1(mut arg: u8); + | ^^^^^^^ help: remove `mut` from the parameter: `arg` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #35203 <https://github.com/rust-lang/rust/issues/35203> +note: the lint level is defined here + --> $DIR/no-patterns-in-args-2.rs:1:9 + | +LL | #![deny(patterns_in_fns_without_body)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0642`. diff --git a/tests/ui/pattern/no-patterns-in-args.rs b/tests/ui/pattern/no-patterns-in-args.rs new file mode 100644 index 00000000000..54836b0a3f5 --- /dev/null +++ b/tests/ui/pattern/no-patterns-in-args.rs @@ -0,0 +1,16 @@ +extern "C" { + fn f1(mut arg: u8); //~ ERROR patterns aren't allowed in foreign function declarations + fn f2(&arg: u8); //~ ERROR patterns aren't allowed in foreign function declarations + fn f3(arg @ _: u8); //~ ERROR patterns aren't allowed in foreign function declarations + fn g1(arg: u8); // OK + fn g2(_: u8); // OK +// fn g3(u8); // Not yet +} + +type A1 = fn(mut arg: u8); //~ ERROR patterns aren't allowed in function pointer types +type A2 = fn(&arg: u8); //~ ERROR patterns aren't allowed in function pointer types +type B1 = fn(arg: u8); // OK +type B2 = fn(_: u8); // OK +type B3 = fn(u8); // OK + +fn main() {} diff --git a/tests/ui/pattern/no-patterns-in-args.stderr b/tests/ui/pattern/no-patterns-in-args.stderr new file mode 100644 index 00000000000..1c2ce866467 --- /dev/null +++ b/tests/ui/pattern/no-patterns-in-args.stderr @@ -0,0 +1,34 @@ +error[E0130]: patterns aren't allowed in foreign function declarations + --> $DIR/no-patterns-in-args.rs:2:11 + | +LL | fn f1(mut arg: u8); + | ^^^^^^^ pattern not allowed in foreign function + +error[E0130]: patterns aren't allowed in foreign function declarations + --> $DIR/no-patterns-in-args.rs:3:11 + | +LL | fn f2(&arg: u8); + | ^^^^ pattern not allowed in foreign function + +error[E0130]: patterns aren't allowed in foreign function declarations + --> $DIR/no-patterns-in-args.rs:4:11 + | +LL | fn f3(arg @ _: u8); + | ^^^^^^^ pattern not allowed in foreign function + +error[E0561]: patterns aren't allowed in function pointer types + --> $DIR/no-patterns-in-args.rs:10:14 + | +LL | type A1 = fn(mut arg: u8); + | ^^^^^^^ + +error[E0561]: patterns aren't allowed in function pointer types + --> $DIR/no-patterns-in-args.rs:11:14 + | +LL | type A2 = fn(&arg: u8); + | ^^^^ + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0130, E0561. +For more information about an error, try `rustc --explain E0130`. |
