about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/codegen/sanitizer/kcfi-add-kcfi-flag.rs13
-rw-r--r--tests/ui/async-await/issues/issue-66695-static-refs.rs4
-rw-r--r--tests/ui/async-await/issues/issue-67611-static-mut-refs.rs4
-rw-r--r--tests/ui/async-await/missed-capture-issue-107414.rs9
-rw-r--r--tests/ui/binding/match-beginning-vert.rs4
-rw-r--r--tests/ui/drop/dynamic-drop.rs18
-rw-r--r--tests/ui/rfcs/rfc-2294-if-let-guard/const-expr.rs26
-rw-r--r--tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.rs97
-rw-r--r--tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.stderr67
-rw-r--r--tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let.rs41
-rw-r--r--tests/ui/rfcs/rfc-2294-if-let-guard/type-inference.rs16
-rw-r--r--tests/ui/sanitize/cfg.rs21
-rw-r--r--tests/ui/unreachable-code.rs15
13 files changed, 325 insertions, 10 deletions
diff --git a/tests/codegen/sanitizer/kcfi-add-kcfi-flag.rs b/tests/codegen/sanitizer/kcfi-add-kcfi-flag.rs
index c2eb852aec3..6d466b93c40 100644
--- a/tests/codegen/sanitizer/kcfi-add-kcfi-flag.rs
+++ b/tests/codegen/sanitizer/kcfi-add-kcfi-flag.rs
@@ -1,9 +1,20 @@
 // Verifies that "kcfi" module flag is added.
 //
-// needs-sanitizer-kcfi
+// revisions: aarch64 x86_64
+// [aarch64] compile-flags: --target aarch64-unknown-none
+// [aarch64] needs-llvm-components: aarch64
+// [x86_64] compile-flags: --target x86_64-unknown-none
+// [x86_64] needs-llvm-components: x86
 // compile-flags: -Ctarget-feature=-crt-static -Zsanitizer=kcfi
 
+#![feature(no_core, lang_items)]
 #![crate_type="lib"]
+#![no_core]
+
+#[lang="sized"]
+trait Sized { }
+#[lang="copy"]
+trait Copy { }
 
 pub fn foo() {
 }
diff --git a/tests/ui/async-await/issues/issue-66695-static-refs.rs b/tests/ui/async-await/issues/issue-66695-static-refs.rs
index f0609713b4d..1b0e1c6c9e7 100644
--- a/tests/ui/async-await/issues/issue-66695-static-refs.rs
+++ b/tests/ui/async-await/issues/issue-66695-static-refs.rs
@@ -1,12 +1,15 @@
 // build-pass
 // edition:2018
 
+#![feature(if_let_guard)]
+
 static A: [i32; 5] = [1, 2, 3, 4, 5];
 
 async fn fun() {
     let u = A[async { 1 }.await];
     match A {
         i if async { true }.await => (),
+        i if let Some(1) = async { Some(1) }.await => (),
         _ => (),
     }
 }
@@ -18,6 +21,7 @@ fn main() {
     async {
         match A {
             i if async { true }.await => (),
+            i if let Some(2) = async { Some(2) }.await => (),
             _ => (),
         }
     };
diff --git a/tests/ui/async-await/issues/issue-67611-static-mut-refs.rs b/tests/ui/async-await/issues/issue-67611-static-mut-refs.rs
index c4f8f607d25..80d824d3b2e 100644
--- a/tests/ui/async-await/issues/issue-67611-static-mut-refs.rs
+++ b/tests/ui/async-await/issues/issue-67611-static-mut-refs.rs
@@ -5,6 +5,8 @@
 // [drop_tracking] compile-flags: -Zdrop-tracking
 // [drop_tracking_mir] compile-flags: -Zdrop-tracking-mir
 
+#![feature(if_let_guard)]
+
 static mut A: [i32; 5] = [1, 2, 3, 4, 5];
 
 fn is_send_sync<T: Send + Sync>(_: T) {}
@@ -14,6 +16,7 @@ async fn fun() {
     unsafe {
         match A {
             i if async { true }.await => (),
+            i if let Some(1) = async { Some(1) }.await => (),
             _ => (),
         }
     }
@@ -27,6 +30,7 @@ fn main() {
         unsafe {
             match A {
                 i if async { true }.await => (),
+                i if let Some(2) = async { Some(2) }.await => (),
                 _ => (),
             }
         }
diff --git a/tests/ui/async-await/missed-capture-issue-107414.rs b/tests/ui/async-await/missed-capture-issue-107414.rs
index 0ab4f5ade98..bb14eb74b3a 100644
--- a/tests/ui/async-await/missed-capture-issue-107414.rs
+++ b/tests/ui/async-await/missed-capture-issue-107414.rs
@@ -1,6 +1,8 @@
 // check-pass
 // edition:2018
 
+#![feature(if_let_guard)]
+
 fn main() {}
 
 struct StructA {}
@@ -22,3 +24,10 @@ async fn ice() {
         _ => {}
     }
 }
+
+async fn if_let() {
+    match Some(StructB {}) {
+        Some(struct_b) if let true = get_struct_a_async().await.fn_taking_struct_b(&struct_b) => {}
+        _ => {}
+    }
+}
diff --git a/tests/ui/binding/match-beginning-vert.rs b/tests/ui/binding/match-beginning-vert.rs
index 79267400b28..93c08f0b710 100644
--- a/tests/ui/binding/match-beginning-vert.rs
+++ b/tests/ui/binding/match-beginning-vert.rs
@@ -1,4 +1,7 @@
 // run-pass
+
+#![feature(if_let_guard)]
+
 enum Foo {
     A,
     B,
@@ -13,6 +16,7 @@ fn main() {
         match *foo {
             | A => println!("A"),
             | B | C if 1 < 2 => println!("BC!"),
+            | D if let 1 = 1 => println!("D!"),
             | _ => {},
         }
     }
diff --git a/tests/ui/drop/dynamic-drop.rs b/tests/ui/drop/dynamic-drop.rs
index 9e51d3adaaa..caef6358ea7 100644
--- a/tests/ui/drop/dynamic-drop.rs
+++ b/tests/ui/drop/dynamic-drop.rs
@@ -2,6 +2,7 @@
 // needs-unwind
 
 #![feature(generators, generator_trait)]
+#![feature(if_let_guard)]
 
 #![allow(unused_assignments)]
 #![allow(unused_variables)]
@@ -332,6 +333,16 @@ fn move_ref_pattern(a: &Allocator) {
     let (ref _a, ref mut _b, _c, mut _d) = tup;
 }
 
+fn if_let_guard(a: &Allocator, c: bool, d: i32) {
+    let foo = if c { Some(a.alloc()) } else { None };
+
+    match d == 0 {
+        false if let Some(a) = foo => { let b = a; }
+        true if let true = { drop(foo.unwrap_or_else(|| a.alloc())); d == 1 } => {}
+        _ => {}
+    }
+}
+
 fn panic_after_return(a: &Allocator) -> Ptr<'_> {
     // Panic in the drop of `p` or `q` can leak
     let exceptions = vec![8, 9];
@@ -497,6 +508,13 @@ fn main() {
 
     run_test(|a| move_ref_pattern(a));
 
+    run_test(|a| if_let_guard(a, true, 0));
+    run_test(|a| if_let_guard(a, true, 1));
+    run_test(|a| if_let_guard(a, true, 2));
+    run_test(|a| if_let_guard(a, false, 0));
+    run_test(|a| if_let_guard(a, false, 1));
+    run_test(|a| if_let_guard(a, false, 2));
+
     run_test(|a| {
         panic_after_return(a);
     });
diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/const-expr.rs b/tests/ui/rfcs/rfc-2294-if-let-guard/const-expr.rs
new file mode 100644
index 00000000000..5c42c0d8bec
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2294-if-let-guard/const-expr.rs
@@ -0,0 +1,26 @@
+// Ensure if let guards can be used in constant expressions.
+// build-pass
+
+#![feature(if_let_guard)]
+
+const fn match_if_let(x: Option<i32>, y: Option<i32>) -> i32 {
+    match x {
+        None if let Some(a @ 5) = y => a,
+        Some(z) if let (Some(_), 12) = (y, z) => 2,
+        _ => 3,
+    }
+}
+
+const ASSERTS: usize = {
+    assert!(match_if_let(None, Some(5)) == 5);
+    assert!(match_if_let(Some(12), Some(3)) == 2);
+    assert!(match_if_let(None, Some(4)) == 3);
+    assert!(match_if_let(Some(11), Some(3)) == 3);
+    assert!(match_if_let(Some(12), None) == 3);
+    assert!(match_if_let(None, None) == 3);
+    0
+};
+
+fn main() {
+    let _: [(); ASSERTS];
+}
diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.rs b/tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.rs
new file mode 100644
index 00000000000..5c333cd7795
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.rs
@@ -0,0 +1,97 @@
+#![feature(if_let_guard)]
+#![feature(let_chains)]
+#![allow(irrefutable_let_patterns)]
+
+fn same_pattern(c: bool) {
+    let x: Box<_> = Box::new(1);
+
+    let v = (1, 2);
+
+    match v {
+        (1, 2) if let y = x && c => (),
+        (1, 2) if let z = x => (), //~ ERROR use of moved value: `x`
+        _ => (),
+    }
+}
+
+fn same_pattern_ok(c: bool) {
+    let x: Box<_> = Box::new(1);
+
+    let v = (1, 2);
+
+    match v {
+        (1, 2) if c && let y = x => (),
+        (1, 2) if let z = x => (),
+        _ => (),
+    }
+}
+
+fn different_patterns(c: bool) {
+    let x: Box<_> = Box::new(1);
+
+    let v = (1, 2);
+
+    match v {
+        (1, _) if let y = x && c => (),
+        (_, 2) if let z = x => (), //~ ERROR use of moved value: `x`
+        _ => (),
+    }
+}
+
+fn different_patterns_ok(c: bool) {
+    let x: Box<_> = Box::new(1);
+
+    let v = (1, 2);
+
+    match v {
+        (1, _) if c && let y = x => (),
+        (_, 2) if let z = x => (),
+        _ => (),
+    }
+}
+
+fn or_pattern(c: bool) {
+    let x: Box<_> = Box::new(1);
+
+    let v = (1, 2);
+
+    match v {
+        (1, _) | (_, 2) if let y = x && c => (), //~ ERROR use of moved value: `x`
+        _ => (),
+    }
+}
+
+fn or_pattern_ok(c: bool) {
+    let x: Box<_> = Box::new(1);
+
+    let v = (1, 2);
+
+    match v {
+        (1, _) | (_, 2) if c && let y = x => (),
+        _ => (),
+    }
+}
+
+fn use_in_arm(c: bool) {
+    let x: Box<_> = Box::new(1);
+
+    let v = (1, 2);
+
+    match v {
+        (1, 2) if let y = x && c => false,
+        _ => { *x == 1 }, //~ ERROR use of moved value: `x`
+    };
+}
+
+fn use_in_arm_ok(c: bool) {
+    let x: Box<_> = Box::new(1);
+
+    let v = (1, 2);
+
+    match v {
+        (1, 2) if c && let y = x => false,
+        _ => { *x == 1 },
+    };
+}
+
+fn main() {}
diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.stderr b/tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.stderr
new file mode 100644
index 00000000000..d27fde58244
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let-chain.stderr
@@ -0,0 +1,67 @@
+error[E0382]: use of moved value: `x`
+  --> $DIR/move-guard-if-let-chain.rs:12:27
+   |
+LL |     let x: Box<_> = Box::new(1);
+   |         - move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
+...
+LL |         (1, 2) if let y = x && c => (),
+   |                       - value moved here
+LL |         (1, 2) if let z = x => (),
+   |                           ^ value used here after move
+   |
+help: borrow this binding in the pattern to avoid moving the value
+   |
+LL |         (1, 2) if let ref y = x && c => (),
+   |                       +++
+
+error[E0382]: use of moved value: `x`
+  --> $DIR/move-guard-if-let-chain.rs:36:27
+   |
+LL |     let x: Box<_> = Box::new(1);
+   |         - move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
+...
+LL |         (1, _) if let y = x && c => (),
+   |                       - value moved here
+LL |         (_, 2) if let z = x => (),
+   |                           ^ value used here after move
+   |
+help: borrow this binding in the pattern to avoid moving the value
+   |
+LL |         (1, _) if let ref y = x && c => (),
+   |                       +++
+
+error[E0382]: use of moved value: `x`
+  --> $DIR/move-guard-if-let-chain.rs:59:36
+   |
+LL |     let x: Box<_> = Box::new(1);
+   |         - move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
+...
+LL |         (1, _) | (_, 2) if let y = x && c => (),
+   |                                -   ^ value used here after move
+   |                                |
+   |                                value moved here
+   |
+help: borrow this binding in the pattern to avoid moving the value
+   |
+LL |         (1, _) | (_, 2) if let ref y = x && c => (),
+   |                                +++
+
+error[E0382]: use of moved value: `x`
+  --> $DIR/move-guard-if-let-chain.rs:82:16
+   |
+LL |     let x: Box<_> = Box::new(1);
+   |         - move occurs because `x` has type `Box<i32>`, which does not implement the `Copy` trait
+...
+LL |         (1, 2) if let y = x && c => false,
+   |                       - value moved here
+LL |         _ => { *x == 1 },
+   |                ^^ value used here after move
+   |
+help: borrow this binding in the pattern to avoid moving the value
+   |
+LL |         (1, 2) if let ref y = x && c => false,
+   |                       +++
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0382`.
diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let.rs b/tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let.rs
new file mode 100644
index 00000000000..071b86e2e14
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2294-if-let-guard/move-guard-if-let.rs
@@ -0,0 +1,41 @@
+// Check that borrowck knows that moves in the pattern for if-let guards
+// only happen when the pattern is matched.
+
+// build-pass
+
+#![feature(if_let_guard)]
+#![allow(irrefutable_let_patterns)]
+
+fn same_pattern() {
+    let x: Box<_> = Box::new(1);
+
+    let v = (1, 2);
+
+    match v {
+        (1, 2) if let y = x => (),
+        (1, 2) if let z = x => (),
+        _ => (),
+    }
+}
+
+fn or_pattern() {
+    let x: Box<_> = Box::new(1);
+
+    let v = (1, 2);
+
+    match v {
+        (1, _) | (_, 2) if let y = x => (),
+        _ => (),
+    }
+}
+
+fn main() {
+    let x: Box<_> = Box::new(1);
+
+    let v = (1, 2);
+
+    match v {
+        (1, 2) if let y = x => false,
+        _ => { *x == 1 },
+    };
+}
diff --git a/tests/ui/rfcs/rfc-2294-if-let-guard/type-inference.rs b/tests/ui/rfcs/rfc-2294-if-let-guard/type-inference.rs
new file mode 100644
index 00000000000..ef7a772e6c5
--- /dev/null
+++ b/tests/ui/rfcs/rfc-2294-if-let-guard/type-inference.rs
@@ -0,0 +1,16 @@
+// check-pass
+
+#![feature(if_let_guard)]
+
+struct S;
+
+fn get<T>() -> Option<T> {
+    None
+}
+
+fn main() {
+    match get() {
+        x if let Some(S) = x => {}
+        _ => {}
+    }
+}
diff --git a/tests/ui/sanitize/cfg.rs b/tests/ui/sanitize/cfg.rs
index 523de1ceaee..f8ccf3b042d 100644
--- a/tests/ui/sanitize/cfg.rs
+++ b/tests/ui/sanitize/cfg.rs
@@ -1,15 +1,15 @@
 // Verifies that when compiling with -Zsanitizer=option,
 // the `#[cfg(sanitize = "option")]` attribute is configured.
 
-// needs-sanitizer-support
 // check-pass
 // revisions: address cfi kcfi leak memory thread
 //[address]needs-sanitizer-address
 //[address]compile-flags: -Zsanitizer=address --cfg address
 //[cfi]needs-sanitizer-cfi
-//[cfi]compile-flags:     -Zsanitizer=cfi     --cfg cfi -Clto
-//[kcfi]needs-sanitizer-kcfi
-//[kcfi]compile-flags:    -Zsanitizer=kcfi    --cfg kcfi
+//[cfi]compile-flags:     -Zsanitizer=cfi     --cfg cfi
+//[cfi]compile-flags:     -Clto -Ccodegen-units=1 -Ctarget-feature=-crt-static
+//[kcfi]needs-llvm-components: x86
+//[kcfi]compile-flags:    -Zsanitizer=kcfi    --cfg kcfi --target x86_64-unknown-none
 //[leak]needs-sanitizer-leak
 //[leak]compile-flags:    -Zsanitizer=leak    --cfg leak
 //[memory]needs-sanitizer-memory
@@ -17,7 +17,14 @@
 //[thread]needs-sanitizer-thread
 //[thread]compile-flags:  -Zsanitizer=thread  --cfg thread
 
-#![feature(cfg_sanitize)]
+#![feature(cfg_sanitize, no_core, lang_items)]
+#![crate_type="lib"]
+#![no_core]
+
+#[lang="sized"]
+trait Sized { }
+#[lang="copy"]
+trait Copy { }
 
 #[cfg(all(sanitize = "address", address))]
 fn main() {}
@@ -36,3 +43,7 @@ fn main() {}
 
 #[cfg(all(sanitize = "thread", thread))]
 fn main() {}
+
+pub fn check() {
+    main();
+}
diff --git a/tests/ui/unreachable-code.rs b/tests/ui/unreachable-code.rs
index 28b938edc63..64174db7afb 100644
--- a/tests/ui/unreachable-code.rs
+++ b/tests/ui/unreachable-code.rs
@@ -2,25 +2,32 @@
 
 #![allow(unused_must_use)]
 #![allow(dead_code)]
-
 #![allow(path_statements)]
 #![allow(unreachable_code)]
 #![allow(unused_variables)]
+#![feature(if_let_guard)]
 
-fn id(x: bool) -> bool { x }
+fn id(x: bool) -> bool {
+    x
+}
 
 fn call_id() {
     let c = panic!();
     id(c);
 }
 
-fn call_id_2() { id(true) && id(return); }
+fn call_id_2() {
+    id(true) && id(return);
+}
 
-fn call_id_3() { id(return) && id(return); }
+fn call_id_3() {
+    id(return) && id(return);
+}
 
 fn ret_guard() {
     match 2 {
       x if (return) => { x; }
+      x if let true = return => { x; }
       _ => {}
     }
 }