]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #51369 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
authorbors <bors@rust-lang.org>
Tue, 5 Jun 2018 15:26:26 +0000 (15:26 +0000)
committerbors <bors@rust-lang.org>
Tue, 5 Jun 2018 15:26:26 +0000 (15:26 +0000)
Rollup of 7 pull requests

Successful merges:

 - #50852 (Add doc comment to hiding portions of code example)
 - #51183 (Update rustdoc book to suggest using Termination trait instead of hidden ‘foo’ function)
 - #51255 (Fix confusing error message for sub_instant)
 - #51256 (Fix crate-name option in rustdoc)
 - #51308 (Check array indices in constant propagation)
 - #51343 (test: Ignore some problematic tests on sparc and sparc64)
 - #51358 (Tests that #39963 is fixed on MIR borrowck)

Failed merges:

34 files changed:
src/doc/rustdoc/src/documentation-tests.md
src/librustc_mir/transform/const_prop.rs
src/librustdoc/core.rs
src/libstd/sys/redox/time.rs
src/libstd/sys/unix/time.rs
src/test/codegen/abi-main-signature-16bit-c-int.rs
src/test/codegen/fastcall-inreg.rs
src/test/codegen/repr-transparent-aggregates-2.rs
src/test/codegen/stack-probes.rs
src/test/codegen/x86_mmx.rs
src/test/compile-fail/asm-bad-clobber.rs
src/test/compile-fail/asm-in-bad-modifier.rs
src/test/compile-fail/asm-misplaced-option.rs
src/test/compile-fail/asm-out-no-modifier.rs
src/test/compile-fail/asm-out-read-uninit.rs
src/test/compile-fail/borrowck/borrowck-asm.rs
src/test/compile-fail/const-err-early.rs
src/test/compile-fail/const-err2.rs
src/test/compile-fail/const-err3.rs
src/test/run-fail/mir_indexing_oob_1.rs
src/test/run-fail/mir_indexing_oob_2.rs
src/test/run-fail/mir_indexing_oob_3.rs
src/test/run-pass/borrowck/borrowck-multiple-borrows-interior-boxes.rs [new file with mode: 0644]
src/test/run-pass/stack-probes-lto.rs
src/test/run-pass/stack-probes.rs
src/test/rustdoc/invalid.crate.name.rs [new file with mode: 0644]
src/test/ui/asm-out-assign-imm.rs
src/test/ui/asm-out-assign-imm.stderr
src/test/ui/const-eval/index_out_of_bound.rs [deleted file]
src/test/ui/const-eval/index_out_of_bound.stderr [deleted file]
src/test/ui/const-eval/index_out_of_bounds.rs [new file with mode: 0644]
src/test/ui/const-eval/index_out_of_bounds.stderr [new file with mode: 0644]
src/test/ui/target-feature-wrong.rs
src/test/ui/target-feature-wrong.stderr

index fd7d1713ca574eefeebff662b3f1f3d07088c064..cb233cc84cbed8fd95ddbce645dcabfe35a0cd45 100644 (file)
@@ -79,8 +79,9 @@ from your example, but are important to make the tests work. Consider
 an example block that looks like this:
 
 ```text
-/// Some documentation.
-# fn foo() {}
+/// /// Some documentation.
+/// # fn foo() {} // this function will be hidden
+/// println!("Hello, World!");
 ```
 
 It will render like this:
@@ -88,6 +89,7 @@ It will render like this:
 ```rust
 /// Some documentation.
 # fn foo() {}
+println!("Hello, World!");
 ```
 
 Yes, that's right: you can add lines that start with `# `, and they will
@@ -168,37 +170,56 @@ By repeating all parts of the example, you can ensure that your example still
 compiles, while only showing the parts that are relevant to that part of your
 explanation.
 
-Another case where the use of `#` is handy is when you want to ignore
-error handling. Lets say you want the following,
+
+## Using `?` in doc tests
+
+When writing an example, it is rarely useful to include a complete error
+handling, as it would add significant amounts of boilerplate code. Instead, you
+may want the following:
 
 ```ignore
+/// ```
 /// use std::io;
 /// let mut input = String::new();
 /// io::stdin().read_line(&mut input)?;
+/// ```
 ```
 
-The problem is that `?` returns a `Result<T, E>` and test functions
-don't return anything so this will give a mismatched types error.
+The problem is that `?` returns a `Result<T, E>` and test functions don't
+return anything, so this will give a mismatched types error.
+
+You can get around this limitation by manually adding a `main` that returns
+`Result<T, E>`, because `Result<T, E>` implements the `Termination` trait:
 
 ```ignore
 /// A doc test using ?
 ///
 /// ```
 /// use std::io;
-/// # fn foo() -> io::Result<()> {
+///
+/// fn main() -> io::Result<()> {
+///     let mut input = String::new();
+///     io::stdin().read_line(&mut input)?;
+///     Ok(())
+/// }
+/// ```
+```
+
+Together with the `# ` from the section above, you arrive at a solution that
+appears to the reader as the initial idea but works with doc tests:
+
+```ignore
+/// ```
+/// use std::io;
+/// # fn main() -> io::Result<()> {
 /// let mut input = String::new();
 /// io::stdin().read_line(&mut input)?;
 /// # Ok(())
 /// # }
 /// ```
-# fn foo() {}
 ```
 
-You can get around this by wrapping the code in a function. This catches
-and swallows the `Result<T, E>` when running tests on the docs. This
-pattern appears regularly in the standard library.
-
-### Documenting macros
+## Documenting macros
 
 Here’s an example of documenting a macro:
 
index 40a6610c4173caab16c2f96816f9e4e68748640a..d39042ceba99fc6162c5d4aa6d246084d6ad3f26 100644 (file)
@@ -240,16 +240,6 @@ fn const_prop(
     ) -> Option<Const<'tcx>> {
         let span = source_info.span;
         match *rvalue {
-            // No need to overwrite an already evaluated constant
-            Rvalue::Use(Operand::Constant(box Constant {
-                literal: Literal::Value {
-                    value: &ty::Const {
-                        val: ConstVal::Value(_),
-                        ..
-                    },
-                },
-                ..
-            })) => None,
             // This branch exists for the sanity type check
             Rvalue::Use(Operand::Constant(ref c)) => {
                 assert_eq!(c.ty, place_ty);
index 458ed105d2650b04c54cc56658c94988f06cf2b8..bad5ff2596fd3496f2086729a34ffd2288106577 100644 (file)
@@ -230,7 +230,10 @@ pub fn run_core(search_paths: SearchPaths,
 
         let krate = panictry!(driver::phase_1_parse_input(control, &sess, &input));
 
-        let name = ::rustc_codegen_utils::link::find_crate_name(Some(&sess), &krate.attrs, &input);
+        let name = match crate_name {
+            Some(ref crate_name) => crate_name.clone(),
+            None => ::rustc_codegen_utils::link::find_crate_name(Some(&sess), &krate.attrs, &input),
+        };
 
         let mut crate_loader = CrateLoader::new(&sess, &cstore, &name);
 
index cf798500b7fd2d716dcccaaa7adb62250b879a88..5c491115c55160dafcc356c2082699454b9b29f4 100644 (file)
@@ -144,7 +144,7 @@ pub fn now() -> Instant {
 
     pub fn sub_instant(&self, other: &Instant) -> Duration {
         self.t.sub_timespec(&other.t).unwrap_or_else(|_| {
-            panic!("other was less than the current instant")
+            panic!("specified instant was later than self")
         })
     }
 
index 83127935909931211957d8df0e34e7c599e92ceb..89786eb2a6c486005c27ba46da3375fa3fd79aa7 100644 (file)
@@ -289,7 +289,7 @@ pub fn now() -> Instant {
 
         pub fn sub_instant(&self, other: &Instant) -> Duration {
             self.t.sub_timespec(&other.t).unwrap_or_else(|_| {
-                panic!("other was less than the current instant")
+                panic!("specified instant was later than self")
             })
         }
 
index 367d509cadfe3755e38ad0f17a79bbe3dfc80b3f..df5cba1c244b8fbcc4961503b6b9590ec4389241 100644 (file)
@@ -22,6 +22,7 @@
 // ignore-powerpc64
 // ignore-s390x
 // ignore-sparc
+// ignore-sparc64
 // ignore-wasm32
 // ignore-x86
 // ignore-x86_64
index d6dd3f356b5fe7b363d4799ab2f6c7eb75f45fb8..77e3781961f4d8cc30b5050c8ecc3fd9f08732c0 100644 (file)
@@ -29,6 +29,7 @@
 // ignore-r600
 // ignore-amdgcn
 // ignore-sparc
+// ignore-sparc64
 // ignore-sparcv9
 // ignore-sparcel
 // ignore-s390x
index 9605ded569ef6128bebd7f196be5072a28dd4673..25750a6513f73662cb370279da6487118d01fe31 100644 (file)
@@ -14,6 +14,8 @@
 // ignore-asmjs
 // ignore-mips64
 // ignore-s390x
+// ignore-sparc
+// ignore-sparc64
 // ignore-wasm
 // ignore-x86
 // ignore-x86_64
index 51ebc42a0dd6f53b241abaf20188c62c75e1a6b5..2c86e609e7b21d24e39b0a51f69a365822caccd8 100644 (file)
@@ -14,6 +14,8 @@
 // ignore-mips64
 // ignore-powerpc
 // ignore-s390x
+// ignore-sparc
+// ignore-sparc64
 // ignore-wasm
 // ignore-emscripten
 // ignore-windows
index 30777c6214ec94848cc11dcdfb732f295b4b183f..ba51004a791b7b7c7e68c6e685829355e4354e84 100644 (file)
@@ -13,6 +13,8 @@
 // ignore-emscripten
 // ignore-mips
 // ignore-mips64
+// ignore-sparc
+// ignore-sparc64
 // compile-flags: -O
 
 #![feature(repr_simd)]
index aa77e7f46e50da720f26235b17ef4d6effc4cfe4..900f5cce13b2611ba5c228165dc399b62740a14a 100644 (file)
@@ -15,6 +15,7 @@
 // ignore-emscripten
 // ignore-powerpc
 // ignore-sparc
+// ignore-sparc64
 // ignore-mips
 // ignore-mips64
 
index 5e9278c7c35fc63e19537b3967fd5e1d4d53f446..3960fd50e1737faeb5bd136acf111e0ade469550 100644 (file)
@@ -12,6 +12,7 @@
 // ignore-emscripten
 // ignore-powerpc
 // ignore-sparc
+// ignore-sparc64
 // ignore-mips
 // ignore-mips64
 
index abd55ea101189ab7d039e94b37dc43f43e6fee55..77798201ff341cd23d689600ca968d66586aa7f8 100644 (file)
@@ -15,6 +15,7 @@
 // ignore-emscripten
 // ignore-powerpc
 // ignore-sparc
+// ignore-sparc64
 // ignore-mips
 // ignore-mips64
 
index 55d8970008f9a94eaa069d9d68d2541de6d641f2..e38112a256694117726fc6bc228c08a1197fb397 100644 (file)
@@ -12,6 +12,7 @@
 // ignore-emscripten
 // ignore-powerpc
 // ignore-sparc
+// ignore-sparc64
 // ignore-mips
 // ignore-mips64
 
index c606c5a80e58dbd35ffec4c8086a2a2ea63cef07..bd0301e6cf93b6f4cf8ae249c69369a9a8f7d75c 100644 (file)
@@ -12,6 +12,7 @@
 // ignore-emscripten
 // ignore-powerpc
 // ignore-sparc
+// ignore-sparc64
 // ignore-mips
 // ignore-mips64
 
index 0b230be85ad97c2ab68d97220eb720159c6172d2..4cd74117ef74cad59c590950f91f635fef5ac02e 100644 (file)
@@ -12,6 +12,7 @@
 // ignore-emscripten
 // ignore-powerpc
 // ignore-sparc
+// ignore-sparc64
 
 // revisions: ast mir
 //[mir]compile-flags: -Z borrowck=mir
index 6caec159d019ce39ce7f9bd1d65f64a561aa9b53..f8b20f6ee7933f4efac8699f741efe23c6b56491 100644 (file)
@@ -19,8 +19,8 @@
 //~^ ERROR this constant cannot be used
 pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR const_err
 //~^ ERROR this constant cannot be used
-pub const E: u8 = [5u8][1];
-//~^ ERROR const_err
+pub const E: u8 = [5u8][1]; //~ ERROR const_err
+//~| ERROR this constant cannot be used
 
 fn main() {
     let _a = A;
index 46b73371e56cf554ee652cb136a67b9d28132877..9a5cb5a4a83fac6fdd10a4ba4930688ff7531609 100644 (file)
@@ -31,6 +31,7 @@ fn main() {
     let d = 42u8 - (42u8 + 1);
     //~^ ERROR const_err
     let _e = [5u8][1];
+    //~^ ERROR const_err
     black_box(a);
     black_box(b);
     black_box(c);
index 9656af6002442c6369dd86120e9cb3008cb96b6f..f5e43b57e7775082022d99b3291b3765c03da23b 100644 (file)
@@ -23,6 +23,7 @@ fn main() {
     let d = 42u8 - (42u8 + 1);
     //~^ ERROR const_err
     let _e = [5u8][1];
+    //~^ ERROR const_err
     black_box(b);
     black_box(c);
     black_box(d);
index 41ff466f810ea262d8cd9237e50b0f7172c4e9ac..cf342ad94f990271e34c8f0eedfd5fac33727c2f 100644 (file)
@@ -12,6 +12,7 @@
 
 const C: [u32; 5] = [0; 5];
 
+#[allow(const_err)]
 fn test() -> u32 {
     C[10]
 }
index c5c823428bc94edfcf26095d60614c990252e7f1..3eb94682b20471d05a05eead80d74f9ef0009573 100644 (file)
@@ -12,6 +12,7 @@
 
 const C: &'static [u8; 5] = b"hello";
 
+#[allow(const_err)]
 fn test() -> u8 {
     C[10]
 }
index 9bc4b0025e55ad46f604fddd34a0438430a48d85..06bb6d4d2871378cc173b75cd81f49f8d26235be 100644 (file)
@@ -12,6 +12,7 @@
 
 const C: &'static [u8; 5] = b"hello";
 
+#[allow(const_err)]
 fn mir() -> u8 {
     C[10]
 }
diff --git a/src/test/run-pass/borrowck/borrowck-multiple-borrows-interior-boxes.rs b/src/test/run-pass/borrowck/borrowck-multiple-borrows-interior-boxes.rs
new file mode 100644 (file)
index 0000000..f57a7bd
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Test case from #39963.
+
+#![feature(nll)]
+
+#[derive(Clone)]
+struct Foo(Option<Box<Foo>>, Option<Box<Foo>>);
+
+fn test(f: &mut Foo) {
+  match *f {
+    Foo(Some(ref mut left), Some(ref mut right)) => match **left {
+      Foo(Some(ref mut left), Some(ref mut right)) => panic!(),
+      _ => panic!(),
+    },
+    _ => panic!(),
+  }
+}
+
+fn main() {
+}
index d1cb75909c155c81ef2f1fe0b16f6ca934de85e1..3fef19c51bd288722bb95fb8ec7a3cb765102f99 100644 (file)
@@ -14,6 +14,8 @@
 // ignore-mips64
 // ignore-powerpc
 // ignore-s390x
+// ignore-sparc
+// ignore-sparc64
 // ignore-wasm
 // ignore-cloudabi no processes
 // ignore-emscripten no processes
index 78c5782be383368b2116a9d5323826a5fd8cee53..c93dcf019397b34eef0a91adc26ec9a92f805dd2 100644 (file)
@@ -14,6 +14,8 @@
 // ignore-mips64
 // ignore-powerpc
 // ignore-s390x
+// ignore-sparc
+// ignore-sparc64
 // ignore-wasm
 // ignore-cloudabi no processes
 // ignore-emscripten no processes
diff --git a/src/test/rustdoc/invalid.crate.name.rs b/src/test/rustdoc/invalid.crate.name.rs
new file mode 100644 (file)
index 0000000..4e4946a
--- /dev/null
@@ -0,0 +1,13 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// compile-flags: --crate-name foo
+
+pub fn foo() {}
index 055a169deda74da9b934a2fd8a7a030a2f49b6a6..73a709b168613a35a361c8097ac6aabaa5885ef6 100644 (file)
@@ -12,6 +12,7 @@
 // ignore-emscripten
 // ignore-powerpc
 // ignore-sparc
+// ignore-sparc64
 // ignore-mips
 
 #![feature(asm)]
index d9fd4b26c390015f2e284ac87a94f140743c70e7..324dec77adcce8dbaa016c4dfeab71dd8233f81f 100644 (file)
@@ -1,5 +1,5 @@
 error[E0384]: cannot assign twice to immutable variable `x`
-  --> $DIR/asm-out-assign-imm.rs:30:9
+  --> $DIR/asm-out-assign-imm.rs:31:9
    |
 LL |     x = 1;
    |     ----- first assignment to `x`
diff --git a/src/test/ui/const-eval/index_out_of_bound.rs b/src/test/ui/const-eval/index_out_of_bound.rs
deleted file mode 100644 (file)
index e7ffbe8..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-static FOO: i32 = [][0];
-//~^ ERROR E0080
-
-fn main() {}
diff --git a/src/test/ui/const-eval/index_out_of_bound.stderr b/src/test/ui/const-eval/index_out_of_bound.stderr
deleted file mode 100644 (file)
index d16231c..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-error[E0080]: constant evaluation error
-  --> $DIR/index_out_of_bound.rs:11:19
-   |
-LL | static FOO: i32 = [][0];
-   |                   ^^^^^ index out of bounds: the len is 0 but the index is 0
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0080`.
diff --git a/src/test/ui/const-eval/index_out_of_bounds.rs b/src/test/ui/const-eval/index_out_of_bounds.rs
new file mode 100644 (file)
index 0000000..f3578bc
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+static FOO: i32 = [][0];
+//~^ ERROR E0080
+
+fn main() {
+    let array = [std::env::args().len()];
+    array[1]; //~ ERROR index out of bounds
+}
diff --git a/src/test/ui/const-eval/index_out_of_bounds.stderr b/src/test/ui/const-eval/index_out_of_bounds.stderr
new file mode 100644 (file)
index 0000000..96e592d
--- /dev/null
@@ -0,0 +1,17 @@
+error[E0080]: constant evaluation error
+  --> $DIR/index_out_of_bounds.rs:11:19
+   |
+LL | static FOO: i32 = [][0];
+   |                   ^^^^^ index out of bounds: the len is 0 but the index is 0
+
+error: index out of bounds: the len is 1 but the index is 1
+  --> $DIR/index_out_of_bounds.rs:16:5
+   |
+LL |     array[1]; //~ ERROR index out of bounds
+   |     ^^^^^^^^
+   |
+   = note: #[deny(const_err)] on by default
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0080`.
index 0edd51ba779ac4eb0009a15ac3f3aa3a58f654fb..ed9bbb60dcd20d773f949f02470b0c7ac23b6303 100644 (file)
@@ -15,6 +15,8 @@
 // ignore-mips
 // ignore-powerpc
 // ignore-s390x
+// ignore-sparc
+// ignore-sparc64
 
 #![feature(target_feature)]
 
index ed86687bb2fccbec23171b60c6a03989041a6a84..39362f74bdd9e7d8ce44adfe76f6ebe3e47777ce 100644 (file)
@@ -1,35 +1,35 @@
 error: #[target_feature] attribute must be of the form #[target_feature(..)]
-  --> $DIR/target-feature-wrong.rs:21:1
+  --> $DIR/target-feature-wrong.rs:23:1
    |
 LL | #[target_feature = "+sse2"]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: the feature named `foo` is not valid for this target
-  --> $DIR/target-feature-wrong.rs:23:18
+  --> $DIR/target-feature-wrong.rs:25:18
    |
 LL | #[target_feature(enable = "foo")]
    |                  ^^^^^^^^^^^^^^
 
 error: #[target_feature(..)] only accepts sub-keys of `enable` currently
-  --> $DIR/target-feature-wrong.rs:25:18
+  --> $DIR/target-feature-wrong.rs:27:18
    |
 LL | #[target_feature(bar)]
    |                  ^^^
 
 error: #[target_feature(..)] only accepts sub-keys of `enable` currently
-  --> $DIR/target-feature-wrong.rs:27:18
+  --> $DIR/target-feature-wrong.rs:29:18
    |
 LL | #[target_feature(disable = "baz")]
    |                  ^^^^^^^^^^^^^^^
 
 error: #[target_feature(..)] can only be applied to `unsafe` function
-  --> $DIR/target-feature-wrong.rs:31:1
+  --> $DIR/target-feature-wrong.rs:33:1
    |
 LL | #[target_feature(enable = "sse2")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: attribute should be applied to a function
-  --> $DIR/target-feature-wrong.rs:35:1
+  --> $DIR/target-feature-wrong.rs:37:1
    |
 LL | #[target_feature(enable = "sse2")]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -38,7 +38,7 @@ LL | mod another {}
    | -------------- not a function
 
 error: cannot use #[inline(always)] with #[target_feature]
-  --> $DIR/target-feature-wrong.rs:39:1
+  --> $DIR/target-feature-wrong.rs:41:1
    |
 LL | #[inline(always)]
    | ^^^^^^^^^^^^^^^^^