about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-10-02 18:28:11 +0000
committerbors <bors@rust-lang.org>2019-10-02 18:28:11 +0000
commit2daa404e9a151a2e8262cbd6d8c209fd067aca16 (patch)
tree555e94cb61f496a34f931489a93b895bc7b2167e /src/test
parentf2023ac599c38a59f86552089e6791c5a73412d3 (diff)
parentb961f962d0049f168bab668fff3ad903436701f4 (diff)
Auto merge of #65009 - Centril:rollup-06g05xj, r=Centril
Rollup of 13 pull requests

Successful merges:

 - #64581 (Fix unreachable_code warnings for try{} block ok-wrapped expressions)
 - #64850 (Remove inlines from DepNode code)
 - #64914 (regression test for 64453 borrow check error.)
 - #64922 (Use PlaceBuilder to avoid a lot of slice -> vec -> slice convertions)
 - #64948 (Improve sidebar styling to make its integration easier)
 - #64961 (Make comment about dummy type a bit more clear)
 - #64967 (Don't mark borrows of zero-sized arrays as indirectly mutable)
 - #64973 (Fix typo while setting `compile-flags` in test)
 - #64980 (Enable support for `IndirectlyMutableLocals` in `rustc_peek` )
 - #64989 (Fix ICE #64964)
 - #64991 ([const-prop] Correctly handle locals that can't be propagated)
 - #64995 (Remove rustdoc warning)
 - #64997 (rustc book: nitpick SLP vectorization)

Failed merges:

r? @ghost
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/async-await/issues/issue-64964.rs22
-rw-r--r--src/test/ui/borrowck/issue-64453.rs24
-rw-r--r--src/test/ui/borrowck/issue-64453.stderr34
-rw-r--r--src/test/ui/consts/const-eval/generic-slice.rs31
-rw-r--r--src/test/ui/consts/const-eval/generic-slice.stderr30
-rw-r--r--src/test/ui/consts/const-eval/issue-64970.rs15
-rw-r--r--src/test/ui/consts/const-eval/issue-64970.stderr8
-rw-r--r--src/test/ui/issues/issue-23477.rs4
-rw-r--r--src/test/ui/mir-dataflow/indirect-mutation-offset.rs42
-rw-r--r--src/test/ui/mir-dataflow/indirect-mutation-offset.stderr10
-rw-r--r--src/test/ui/try-block/try-block-unreachable-code-lint.rs76
-rw-r--r--src/test/ui/try-block/try-block-unreachable-code-lint.stderr38
12 files changed, 332 insertions, 2 deletions
diff --git a/src/test/ui/async-await/issues/issue-64964.rs b/src/test/ui/async-await/issues/issue-64964.rs
new file mode 100644
index 00000000000..11f6cb6af9c
--- /dev/null
+++ b/src/test/ui/async-await/issues/issue-64964.rs
@@ -0,0 +1,22 @@
+// check-pass
+// compile-flags: -Z query-dep-graph
+// edition:2018
+
+// Regression test for ICE related to `await`ing in a method + incr. comp. (#64964)
+
+struct Body;
+impl Body {
+    async fn next(&mut self) {
+        async {}.await
+    }
+}
+
+// Another reproduction: `await`ing with a variable from for-loop.
+
+async fn bar() {
+    for x in 0..10 {
+        async { Some(x) }.await.unwrap();
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/borrowck/issue-64453.rs b/src/test/ui/borrowck/issue-64453.rs
new file mode 100644
index 00000000000..d8ab6b6e25f
--- /dev/null
+++ b/src/test/ui/borrowck/issue-64453.rs
@@ -0,0 +1,24 @@
+struct Project;
+struct Value;
+
+static settings_dir: String = format!("");
+//~^ ERROR [E0019]
+//~| ERROR [E0015]
+//~| ERROR [E0015]
+
+fn from_string(_: String) -> Value {
+    Value
+}
+fn set_editor(_: Value) {}
+
+fn main() {
+    let settings_data = from_string(settings_dir);
+    //~^ ERROR cannot move out of static item `settings_dir` [E0507]
+    let args: i32 = 0;
+
+    match args {
+        ref x if x == &0 => set_editor(settings_data),
+        ref x if x == &1 => set_editor(settings_data),
+        _ => unimplemented!(),
+    }
+}
diff --git a/src/test/ui/borrowck/issue-64453.stderr b/src/test/ui/borrowck/issue-64453.stderr
new file mode 100644
index 00000000000..6987417fe19
--- /dev/null
+++ b/src/test/ui/borrowck/issue-64453.stderr
@@ -0,0 +1,34 @@
+error[E0507]: cannot move out of static item `settings_dir`
+  --> $DIR/issue-64453.rs:15:37
+   |
+LL |     let settings_data = from_string(settings_dir);
+   |                                     ^^^^^^^^^^^^ move occurs because `settings_dir` has type `std::string::String`, which does not implement the `Copy` trait
+
+error[E0019]: static contains unimplemented expression type
+  --> $DIR/issue-64453.rs:4:31
+   |
+LL | static settings_dir: String = format!("");
+   |                               ^^^^^^^^^^^
+   |
+   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
+
+error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
+  --> $DIR/issue-64453.rs:4:31
+   |
+LL | static settings_dir: String = format!("");
+   |                               ^^^^^^^^^^^
+   |
+   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
+
+error[E0015]: calls in statics are limited to constant functions, tuple structs and tuple variants
+  --> $DIR/issue-64453.rs:4:31
+   |
+LL | static settings_dir: String = format!("");
+   |                               ^^^^^^^^^^^
+   |
+   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
+
+error: aborting due to 4 previous errors
+
+Some errors have detailed explanations: E0015, E0019, E0507.
+For more information about an error, try `rustc --explain E0015`.
diff --git a/src/test/ui/consts/const-eval/generic-slice.rs b/src/test/ui/consts/const-eval/generic-slice.rs
new file mode 100644
index 00000000000..21360a1c471
--- /dev/null
+++ b/src/test/ui/consts/const-eval/generic-slice.rs
@@ -0,0 +1,31 @@
+// Several variants of #64945.
+
+// This struct is not important, we just use it to put `T` and `'a` in scope for our associated
+// consts.
+struct Generic<'a, T>(std::marker::PhantomData<&'a T>);
+
+impl<'a, T: 'static> Generic<'a, T> {
+    const EMPTY_SLICE: &'a [T] = {
+        let x: &'a [T] = &[];
+        x
+    };
+
+    const EMPTY_SLICE_REF: &'a &'static [T] = {
+        let x: &'static [T] = &[];
+        &x
+        //~^ ERROR `x` does not live long enough
+    };
+}
+
+static mut INTERIOR_MUT_AND_DROP: &'static [std::cell::RefCell<Vec<i32>>] = {
+    let x: &[_] = &[];
+    x
+};
+
+static mut INTERIOR_MUT_AND_DROP_REF: &'static &'static [std::cell::RefCell<Vec<i32>>] = {
+    let x: &[_] = &[];
+    &x
+    //~^ ERROR `x` does not live long enough
+};
+
+fn main() {}
diff --git a/src/test/ui/consts/const-eval/generic-slice.stderr b/src/test/ui/consts/const-eval/generic-slice.stderr
new file mode 100644
index 00000000000..c38088df4d8
--- /dev/null
+++ b/src/test/ui/consts/const-eval/generic-slice.stderr
@@ -0,0 +1,30 @@
+error[E0597]: `x` does not live long enough
+  --> $DIR/generic-slice.rs:15:9
+   |
+LL | impl<'a, T: 'static> Generic<'a, T> {
+   |      -- lifetime `'a` defined here
+...
+LL |         &x
+   |         ^^
+   |         |
+   |         borrowed value does not live long enough
+   |         using this value as a constant requires that `x` is borrowed for `'a`
+LL |
+LL |     };
+   |     - `x` dropped here while still borrowed
+
+error[E0597]: `x` does not live long enough
+  --> $DIR/generic-slice.rs:27:5
+   |
+LL |     &x
+   |     ^^
+   |     |
+   |     borrowed value does not live long enough
+   |     using this value as a static requires that `x` is borrowed for `'static`
+LL |
+LL | };
+   | - `x` dropped here while still borrowed
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0597`.
diff --git a/src/test/ui/consts/const-eval/issue-64970.rs b/src/test/ui/consts/const-eval/issue-64970.rs
new file mode 100644
index 00000000000..ede5081c8a5
--- /dev/null
+++ b/src/test/ui/consts/const-eval/issue-64970.rs
@@ -0,0 +1,15 @@
+// run-pass
+
+fn main() {
+    foo(10);
+}
+
+fn foo(mut n: i32) {
+    if false {
+        n = 0i32;
+    }
+
+    if n > 0i32 {
+        1i32 / n;
+    }
+}
diff --git a/src/test/ui/consts/const-eval/issue-64970.stderr b/src/test/ui/consts/const-eval/issue-64970.stderr
new file mode 100644
index 00000000000..2c44b68cbd1
--- /dev/null
+++ b/src/test/ui/consts/const-eval/issue-64970.stderr
@@ -0,0 +1,8 @@
+warning: unused arithmetic operation that must be used
+  --> $DIR/issue-64970.rs:13:9
+   |
+LL |         1i32 / n;
+   |         ^^^^^^^^
+   |
+   = note: `#[warn(unused_must_use)]` on by default
+
diff --git a/src/test/ui/issues/issue-23477.rs b/src/test/ui/issues/issue-23477.rs
index b10b2e49616..1ce05ba390d 100644
--- a/src/test/ui/issues/issue-23477.rs
+++ b/src/test/ui/issues/issue-23477.rs
@@ -1,5 +1,5 @@
-// build-pass (FIXME(62277): could be check-pass?)
-// compiler-flags: -g
+// build-pass
+// compile-flags: -g
 
 pub struct Dst {
     pub a: (),
diff --git a/src/test/ui/mir-dataflow/indirect-mutation-offset.rs b/src/test/ui/mir-dataflow/indirect-mutation-offset.rs
new file mode 100644
index 00000000000..804b70d2652
--- /dev/null
+++ b/src/test/ui/mir-dataflow/indirect-mutation-offset.rs
@@ -0,0 +1,42 @@
+// compile-flags: -Zunleash-the-miri-inside-of-you
+
+#![feature(core_intrinsics, rustc_attrs, const_raw_ptr_deref)]
+
+use std::cell::UnsafeCell;
+use std::intrinsics::rustc_peek;
+
+#[repr(C)]
+struct PartialInteriorMut {
+    zst: [i32; 0],
+    cell: UnsafeCell<i32>,
+}
+
+#[rustc_mir(rustc_peek_indirectly_mutable,stop_after_dataflow)]
+#[rustc_mir(borrowck_graphviz_postflow="indirect.dot")]
+const BOO: i32 = {
+    let x = PartialInteriorMut {
+        zst: [],
+        cell: UnsafeCell::new(0),
+    };
+
+    let p_zst: *const _ = &x.zst ; // Doesn't cause `x` to get marked as indirectly mutable.
+
+    let rmut_cell = unsafe {
+        // Take advantage of the fact that `zst` and `cell` are at the same location in memory.
+        // This trick would work with any size type if miri implemented `ptr::offset`.
+        let p_cell = p_zst as *const UnsafeCell<i32>;
+
+        let pmut_cell = (*p_cell).get();
+        &mut *pmut_cell
+    };
+
+    *rmut_cell = 42;  // Mutates `x` indirectly even though `x` is not marked indirectly mutable!!!
+    let val = *rmut_cell;
+    unsafe { rustc_peek(x) }; //~ ERROR rustc_peek: bit not set
+
+    val
+};
+
+fn main() {
+    println!("{}", BOO);
+}
diff --git a/src/test/ui/mir-dataflow/indirect-mutation-offset.stderr b/src/test/ui/mir-dataflow/indirect-mutation-offset.stderr
new file mode 100644
index 00000000000..16bd1781313
--- /dev/null
+++ b/src/test/ui/mir-dataflow/indirect-mutation-offset.stderr
@@ -0,0 +1,10 @@
+error: rustc_peek: bit not set
+  --> $DIR/indirect-mutation-offset.rs:35:14
+   |
+LL |     unsafe { rustc_peek(x) };
+   |              ^^^^^^^^^^^^^
+
+error: stop_after_dataflow ended compilation
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/try-block/try-block-unreachable-code-lint.rs b/src/test/ui/try-block/try-block-unreachable-code-lint.rs
new file mode 100644
index 00000000000..5a9f662d229
--- /dev/null
+++ b/src/test/ui/try-block/try-block-unreachable-code-lint.rs
@@ -0,0 +1,76 @@
+// Test unreachable_code lint for `try {}` block ok-wrapping. See issues #54165, #63324.
+
+// compile-flags: --edition 2018
+// check-pass
+#![feature(try_blocks)]
+#![warn(unreachable_code)]
+
+fn err() -> Result<u32, ()> {
+    Err(())
+}
+
+// In the following cases unreachable code is autogenerated and should not be reported.
+
+fn test_ok_wrapped_divergent_expr_1() {
+    let res: Result<u32, ()> = try {
+        loop {
+            err()?;
+        }
+    };
+    println!("res: {:?}", res);
+}
+
+fn test_ok_wrapped_divergent_expr_2() {
+    let _: Result<u32, ()> = try {
+        return
+    };
+}
+
+fn test_autogenerated_unit_after_divergent_expr() {
+    let _: Result<(), ()> = try {
+        return;
+    };
+}
+
+// In the following cases unreachable code should be reported.
+
+fn test_try_block_after_divergent_stmt() {
+    let _: Result<u32, ()> = {
+        return;
+
+        try {
+            loop {
+                err()?;
+            }
+        }
+        // ~^^^^^ WARNING unreachable expression
+    };
+}
+
+fn test_wrapped_divergent_expr() {
+    let _: Result<u32, ()> = {
+        Err(return)
+        // ~^ WARNING unreachable call
+    };
+}
+
+fn test_expr_after_divergent_stmt_in_try_block() {
+    let res: Result<u32, ()> = try {
+        loop {
+            err()?;
+        }
+
+        42
+        // ~^ WARNING unreachable expression
+    };
+    println!("res: {:?}", res);
+}
+
+fn main() {
+    test_ok_wrapped_divergent_expr_1();
+    test_ok_wrapped_divergent_expr_2();
+    test_autogenerated_unit_after_divergent_expr();
+    test_try_block_after_divergent_stmt();
+    test_wrapped_divergent_expr();
+    test_expr_after_divergent_stmt_in_try_block();
+}
diff --git a/src/test/ui/try-block/try-block-unreachable-code-lint.stderr b/src/test/ui/try-block/try-block-unreachable-code-lint.stderr
new file mode 100644
index 00000000000..54fed04d400
--- /dev/null
+++ b/src/test/ui/try-block/try-block-unreachable-code-lint.stderr
@@ -0,0 +1,38 @@
+warning: unreachable expression
+  --> $DIR/try-block-unreachable-code-lint.rs:41:9
+   |
+LL |           return;
+   |           ------ any code following this expression is unreachable
+LL | 
+LL | /         try {
+LL | |             loop {
+LL | |                 err()?;
+LL | |             }
+LL | |         }
+   | |_________^ unreachable expression
+   |
+note: lint level defined here
+  --> $DIR/try-block-unreachable-code-lint.rs:6:9
+   |
+LL | #![warn(unreachable_code)]
+   |         ^^^^^^^^^^^^^^^^
+
+warning: unreachable call
+  --> $DIR/try-block-unreachable-code-lint.rs:52:9
+   |
+LL |         Err(return)
+   |         ^^^ ------ any code following this expression is unreachable
+   |         |
+   |         unreachable call
+
+warning: unreachable expression
+  --> $DIR/try-block-unreachable-code-lint.rs:63:9
+   |
+LL | /         loop {
+LL | |             err()?;
+LL | |         }
+   | |_________- any code following this expression is unreachable
+LL | 
+LL |           42
+   |           ^^ unreachable expression
+