diff --git a/src/doc/rustdoc/src/documentation-tests.md b/src/doc/rustdoc/src/documentation-tests.md index fd7d1713ca574..cb233cc84cbed 100644 --- a/src/doc/rustdoc/src/documentation-tests.md +++ b/src/doc/rustdoc/src/documentation-tests.md @@ -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` and test functions -don't return anything so this will give a mismatched types error. +The problem is that `?` returns a `Result` 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`, because `Result` 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` 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: diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 40a6610c4173c..d39042ceba99f 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -240,16 +240,6 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> { ) -> Option> { 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); diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 458ed105d2650..bad5ff2596fd3 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -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); diff --git a/src/libstd/sys/redox/time.rs b/src/libstd/sys/redox/time.rs index cf798500b7fd2..5c491115c5516 100644 --- a/src/libstd/sys/redox/time.rs +++ b/src/libstd/sys/redox/time.rs @@ -144,7 +144,7 @@ impl 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") }) } diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs index 8312793590993..89786eb2a6c48 100644 --- a/src/libstd/sys/unix/time.rs +++ b/src/libstd/sys/unix/time.rs @@ -289,7 +289,7 @@ mod inner { 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") }) } diff --git a/src/test/codegen/abi-main-signature-16bit-c-int.rs b/src/test/codegen/abi-main-signature-16bit-c-int.rs index 367d509cadfe3..df5cba1c244b8 100644 --- a/src/test/codegen/abi-main-signature-16bit-c-int.rs +++ b/src/test/codegen/abi-main-signature-16bit-c-int.rs @@ -22,6 +22,7 @@ // ignore-powerpc64 // ignore-s390x // ignore-sparc +// ignore-sparc64 // ignore-wasm32 // ignore-x86 // ignore-x86_64 diff --git a/src/test/codegen/fastcall-inreg.rs b/src/test/codegen/fastcall-inreg.rs index d6dd3f356b5fe..77e3781961f4d 100644 --- a/src/test/codegen/fastcall-inreg.rs +++ b/src/test/codegen/fastcall-inreg.rs @@ -29,6 +29,7 @@ // ignore-r600 // ignore-amdgcn // ignore-sparc +// ignore-sparc64 // ignore-sparcv9 // ignore-sparcel // ignore-s390x diff --git a/src/test/codegen/repr-transparent-aggregates-2.rs b/src/test/codegen/repr-transparent-aggregates-2.rs index 9605ded569ef6..25750a6513f73 100644 --- a/src/test/codegen/repr-transparent-aggregates-2.rs +++ b/src/test/codegen/repr-transparent-aggregates-2.rs @@ -14,6 +14,8 @@ // ignore-asmjs // ignore-mips64 // ignore-s390x +// ignore-sparc +// ignore-sparc64 // ignore-wasm // ignore-x86 // ignore-x86_64 diff --git a/src/test/codegen/stack-probes.rs b/src/test/codegen/stack-probes.rs index 51ebc42a0dd6f..2c86e609e7b21 100644 --- a/src/test/codegen/stack-probes.rs +++ b/src/test/codegen/stack-probes.rs @@ -14,6 +14,8 @@ // ignore-mips64 // ignore-powerpc // ignore-s390x +// ignore-sparc +// ignore-sparc64 // ignore-wasm // ignore-emscripten // ignore-windows diff --git a/src/test/codegen/x86_mmx.rs b/src/test/codegen/x86_mmx.rs index 30777c6214ec9..ba51004a791b7 100644 --- a/src/test/codegen/x86_mmx.rs +++ b/src/test/codegen/x86_mmx.rs @@ -13,6 +13,8 @@ // ignore-emscripten // ignore-mips // ignore-mips64 +// ignore-sparc +// ignore-sparc64 // compile-flags: -O #![feature(repr_simd)] diff --git a/src/test/compile-fail/asm-bad-clobber.rs b/src/test/compile-fail/asm-bad-clobber.rs index aa77e7f46e50d..900f5cce13b26 100644 --- a/src/test/compile-fail/asm-bad-clobber.rs +++ b/src/test/compile-fail/asm-bad-clobber.rs @@ -15,6 +15,7 @@ // ignore-emscripten // ignore-powerpc // ignore-sparc +// ignore-sparc64 // ignore-mips // ignore-mips64 diff --git a/src/test/compile-fail/asm-in-bad-modifier.rs b/src/test/compile-fail/asm-in-bad-modifier.rs index 5e9278c7c35fc..3960fd50e1737 100644 --- a/src/test/compile-fail/asm-in-bad-modifier.rs +++ b/src/test/compile-fail/asm-in-bad-modifier.rs @@ -12,6 +12,7 @@ // ignore-emscripten // ignore-powerpc // ignore-sparc +// ignore-sparc64 // ignore-mips // ignore-mips64 diff --git a/src/test/compile-fail/asm-misplaced-option.rs b/src/test/compile-fail/asm-misplaced-option.rs index abd55ea101189..77798201ff341 100644 --- a/src/test/compile-fail/asm-misplaced-option.rs +++ b/src/test/compile-fail/asm-misplaced-option.rs @@ -15,6 +15,7 @@ // ignore-emscripten // ignore-powerpc // ignore-sparc +// ignore-sparc64 // ignore-mips // ignore-mips64 diff --git a/src/test/compile-fail/asm-out-no-modifier.rs b/src/test/compile-fail/asm-out-no-modifier.rs index 55d8970008f9a..e38112a256694 100644 --- a/src/test/compile-fail/asm-out-no-modifier.rs +++ b/src/test/compile-fail/asm-out-no-modifier.rs @@ -12,6 +12,7 @@ // ignore-emscripten // ignore-powerpc // ignore-sparc +// ignore-sparc64 // ignore-mips // ignore-mips64 diff --git a/src/test/compile-fail/asm-out-read-uninit.rs b/src/test/compile-fail/asm-out-read-uninit.rs index c606c5a80e58d..bd0301e6cf93b 100644 --- a/src/test/compile-fail/asm-out-read-uninit.rs +++ b/src/test/compile-fail/asm-out-read-uninit.rs @@ -12,6 +12,7 @@ // ignore-emscripten // ignore-powerpc // ignore-sparc +// ignore-sparc64 // ignore-mips // ignore-mips64 diff --git a/src/test/compile-fail/borrowck/borrowck-asm.rs b/src/test/compile-fail/borrowck/borrowck-asm.rs index 0b230be85ad97..4cd74117ef74c 100644 --- a/src/test/compile-fail/borrowck/borrowck-asm.rs +++ b/src/test/compile-fail/borrowck/borrowck-asm.rs @@ -12,6 +12,7 @@ // ignore-emscripten // ignore-powerpc // ignore-sparc +// ignore-sparc64 // revisions: ast mir //[mir]compile-flags: -Z borrowck=mir diff --git a/src/test/compile-fail/const-err-early.rs b/src/test/compile-fail/const-err-early.rs index 6caec159d019c..f8b20f6ee7933 100644 --- a/src/test/compile-fail/const-err-early.rs +++ b/src/test/compile-fail/const-err-early.rs @@ -19,8 +19,8 @@ pub const C: u8 = 200u8 * 4; //~ ERROR const_err //~^ 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; diff --git a/src/test/compile-fail/const-err2.rs b/src/test/compile-fail/const-err2.rs index 46b73371e56cf..9a5cb5a4a83fa 100644 --- a/src/test/compile-fail/const-err2.rs +++ b/src/test/compile-fail/const-err2.rs @@ -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); diff --git a/src/test/compile-fail/const-err3.rs b/src/test/compile-fail/const-err3.rs index 9656af6002442..f5e43b57e7775 100644 --- a/src/test/compile-fail/const-err3.rs +++ b/src/test/compile-fail/const-err3.rs @@ -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); diff --git a/src/test/run-fail/mir_indexing_oob_1.rs b/src/test/run-fail/mir_indexing_oob_1.rs index 41ff466f810ea..cf342ad94f990 100644 --- a/src/test/run-fail/mir_indexing_oob_1.rs +++ b/src/test/run-fail/mir_indexing_oob_1.rs @@ -12,6 +12,7 @@ const C: [u32; 5] = [0; 5]; +#[allow(const_err)] fn test() -> u32 { C[10] } diff --git a/src/test/run-fail/mir_indexing_oob_2.rs b/src/test/run-fail/mir_indexing_oob_2.rs index c5c823428bc94..3eb94682b2047 100644 --- a/src/test/run-fail/mir_indexing_oob_2.rs +++ b/src/test/run-fail/mir_indexing_oob_2.rs @@ -12,6 +12,7 @@ const C: &'static [u8; 5] = b"hello"; +#[allow(const_err)] fn test() -> u8 { C[10] } diff --git a/src/test/run-fail/mir_indexing_oob_3.rs b/src/test/run-fail/mir_indexing_oob_3.rs index 9bc4b0025e55a..06bb6d4d28713 100644 --- a/src/test/run-fail/mir_indexing_oob_3.rs +++ b/src/test/run-fail/mir_indexing_oob_3.rs @@ -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 index 0000000000000..f57a7bd7add44 --- /dev/null +++ b/src/test/run-pass/borrowck/borrowck-multiple-borrows-interior-boxes.rs @@ -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 or the MIT license +// , 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>, Option>); + +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() { +} diff --git a/src/test/run-pass/stack-probes-lto.rs b/src/test/run-pass/stack-probes-lto.rs index d1cb75909c155..3fef19c51bd28 100644 --- a/src/test/run-pass/stack-probes-lto.rs +++ b/src/test/run-pass/stack-probes-lto.rs @@ -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/run-pass/stack-probes.rs b/src/test/run-pass/stack-probes.rs index 78c5782be3833..c93dcf019397b 100644 --- a/src/test/run-pass/stack-probes.rs +++ b/src/test/run-pass/stack-probes.rs @@ -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/ui/const-eval/index_out_of_bound.rs b/src/test/rustdoc/invalid.crate.name.rs similarity index 89% rename from src/test/ui/const-eval/index_out_of_bound.rs rename to src/test/rustdoc/invalid.crate.name.rs index e7ffbe81b9ae7..4e4946a60a338 100644 --- a/src/test/ui/const-eval/index_out_of_bound.rs +++ b/src/test/rustdoc/invalid.crate.name.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -static FOO: i32 = [][0]; -//~^ ERROR E0080 +// compile-flags: --crate-name foo -fn main() {} +pub fn foo() {} diff --git a/src/test/ui/asm-out-assign-imm.rs b/src/test/ui/asm-out-assign-imm.rs index 055a169deda74..73a709b168613 100644 --- a/src/test/ui/asm-out-assign-imm.rs +++ b/src/test/ui/asm-out-assign-imm.rs @@ -12,6 +12,7 @@ // ignore-emscripten // ignore-powerpc // ignore-sparc +// ignore-sparc64 // ignore-mips #![feature(asm)] diff --git a/src/test/ui/asm-out-assign-imm.stderr b/src/test/ui/asm-out-assign-imm.stderr index d9fd4b26c3900..324dec77adcce 100644 --- a/src/test/ui/asm-out-assign-imm.stderr +++ b/src/test/ui/asm-out-assign-imm.stderr @@ -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.stderr b/src/test/ui/const-eval/index_out_of_bound.stderr deleted file mode 100644 index d16231c72b91a..0000000000000 --- a/src/test/ui/const-eval/index_out_of_bound.stderr +++ /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 index 0000000000000..f3578bcef6e41 --- /dev/null +++ b/src/test/ui/const-eval/index_out_of_bounds.rs @@ -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 or the MIT license +// , 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 index 0000000000000..96e592dc209a8 --- /dev/null +++ b/src/test/ui/const-eval/index_out_of_bounds.stderr @@ -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`. diff --git a/src/test/ui/target-feature-wrong.rs b/src/test/ui/target-feature-wrong.rs index 0edd51ba779ac..ed9bbb60dcd20 100644 --- a/src/test/ui/target-feature-wrong.rs +++ b/src/test/ui/target-feature-wrong.rs @@ -15,6 +15,8 @@ // ignore-mips // ignore-powerpc // ignore-s390x +// ignore-sparc +// ignore-sparc64 #![feature(target_feature)] diff --git a/src/test/ui/target-feature-wrong.stderr b/src/test/ui/target-feature-wrong.stderr index ed86687bb2fcc..39362f74bdd9e 100644 --- a/src/test/ui/target-feature-wrong.stderr +++ b/src/test/ui/target-feature-wrong.stderr @@ -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)] | ^^^^^^^^^^^^^^^^^