From 6dc824257ad36ce44cd41340a1b0cd87b78dfaf7 Mon Sep 17 00:00:00 2001 From: mandeep Date: Thu, 17 May 2018 21:15:32 -0500 Subject: [PATCH 01/12] Add doc comment to hiding portions of code example Refactor hiding example to be more complete --- src/doc/rustdoc/src/documentation-tests.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/doc/rustdoc/src/documentation-tests.md b/src/doc/rustdoc/src/documentation-tests.md index 3098587a8a4cc..eb5c53f899bab 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: From 8d74cf870557b42902274f5b898f8aa3117eb47c Mon Sep 17 00:00:00 2001 From: mandeep Date: Fri, 18 May 2018 10:06:20 -0500 Subject: [PATCH 02/12] Add println statement to rendered code block example --- src/doc/rustdoc/src/documentation-tests.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/doc/rustdoc/src/documentation-tests.md b/src/doc/rustdoc/src/documentation-tests.md index eb5c53f899bab..2941ae16a58e1 100644 --- a/src/doc/rustdoc/src/documentation-tests.md +++ b/src/doc/rustdoc/src/documentation-tests.md @@ -89,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 From 95e2bf253d864c5e14ad000ffa2040ce85916056 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Thu, 31 May 2018 22:05:36 +0200 Subject: [PATCH 03/12] Fix confusing error message for sub_instant When subtracting an Instant from another, the function will panick when `RHS > self`, but the error message confusingly displays a different error: ```rust let i = Instant::now(); let other = Instant::now(); if other > i { println!("{:?}", i - other); } ``` This results in a panic: ``` thread 'test_instant' panicked at 'other was less than the current instant', libstd/sys/unix/time.rs:292:17 ``` --- src/libstd/sys/unix/time.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs index 8312793590993..f7459cb55d5ca 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!("other was greater than the current instant") }) } From 33c4b37d00985f8f12796ef1b0b8ff97a4f3db99 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Mon, 4 Jun 2018 08:58:55 +0200 Subject: [PATCH 04/12] Clarify error phrase in `sub_instant` function Uses the same wording as [`src/libstd/sys/windows/time.rs`][1]. 1: https://github.com/avdv/rust/blob/95e2bf253d864c5e14ad000ffa2040ce85916056/src/libstd/sys/windows/time.rs#L65 --- src/libstd/sys/redox/time.rs | 2 +- src/libstd/sys/unix/time.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 f7459cb55d5ca..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 greater than the current instant") + panic!("specified instant was later than self") }) } From 3cbcc5a22d8eaeed4b33fcb5b066e154b35bd98f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 31 May 2018 22:08:31 +0200 Subject: [PATCH 05/12] Fix crate-name option in rustdoc --- src/librustdoc/core.rs | 5 ++++- src/test/rustdoc/invalid.crate.name.rs | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc/invalid.crate.name.rs 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/test/rustdoc/invalid.crate.name.rs b/src/test/rustdoc/invalid.crate.name.rs new file mode 100644 index 0000000000000..4e4946a60a338 --- /dev/null +++ b/src/test/rustdoc/invalid.crate.name.rs @@ -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 or the MIT license +// , 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() {} From 690240994f0c1cd299e35f7b1db2538515ba5910 Mon Sep 17 00:00:00 2001 From: John Paul Adrian Glaubitz Date: Mon, 4 Jun 2018 13:27:32 +0200 Subject: [PATCH 06/12] test: Ignore some problematic tests on sparc and sparc64 --- src/test/codegen/abi-main-signature-16bit-c-int.rs | 1 + src/test/codegen/fastcall-inreg.rs | 1 + src/test/codegen/repr-transparent-aggregates-2.rs | 2 ++ src/test/codegen/stack-probes.rs | 2 ++ src/test/codegen/x86_mmx.rs | 2 ++ src/test/compile-fail/asm-bad-clobber.rs | 1 + src/test/compile-fail/asm-in-bad-modifier.rs | 1 + src/test/compile-fail/asm-misplaced-option.rs | 1 + src/test/compile-fail/asm-out-no-modifier.rs | 1 + src/test/compile-fail/asm-out-read-uninit.rs | 1 + src/test/compile-fail/borrowck/borrowck-asm.rs | 1 + src/test/run-pass/stack-probes-lto.rs | 2 ++ src/test/run-pass/stack-probes.rs | 2 ++ src/test/ui/asm-out-assign-imm.rs | 1 + src/test/ui/asm-out-assign-imm.stderr | 2 +- src/test/ui/target-feature-wrong.rs | 2 ++ src/test/ui/target-feature-wrong.stderr | 14 +++++++------- 17 files changed, 29 insertions(+), 8 deletions(-) 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/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/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/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)] | ^^^^^^^^^^^^^^^^^ From c2825e134db01e2537d7c3ba7acb60f0c983e740 Mon Sep 17 00:00:00 2001 From: Erin Moon Date: Mon, 4 Jun 2018 18:14:33 -0500 Subject: [PATCH 07/12] tests that #39963 is fixed on MIR borrowck --- ...orrowck-multiple-borrows-interior-boxes.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/test/run-pass/borrowck/borrowck-multiple-borrows-interior-boxes.rs 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() { +} From 589f9a87a87c2f444e83a1e4d25de0ac8c0ca7a4 Mon Sep 17 00:00:00 2001 From: Fabian Zaiser Date: Sun, 3 Jun 2018 20:57:45 +0200 Subject: [PATCH 08/12] Propagate uses of constants correctly so that array index checks work --- src/librustc_mir/transform/const_prop.rs | 10 ---------- .../ui/const-eval/index_out_of_bound.stderr | 9 --------- ...x_out_of_bound.rs => index_out_of_bounds.rs} | 5 ++++- .../ui/const-eval/index_out_of_bounds.stderr | 17 +++++++++++++++++ 4 files changed, 21 insertions(+), 20 deletions(-) delete mode 100644 src/test/ui/const-eval/index_out_of_bound.stderr rename src/test/ui/const-eval/{index_out_of_bound.rs => index_out_of_bounds.rs} (83%) create mode 100644 src/test/ui/const-eval/index_out_of_bounds.stderr 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/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_bound.rs b/src/test/ui/const-eval/index_out_of_bounds.rs similarity index 83% rename from src/test/ui/const-eval/index_out_of_bound.rs rename to src/test/ui/const-eval/index_out_of_bounds.rs index e7ffbe81b9ae7..9624b2924baa5 100644 --- a/src/test/ui/const-eval/index_out_of_bound.rs +++ b/src/test/ui/const-eval/index_out_of_bounds.rs @@ -11,4 +11,7 @@ static FOO: i32 = [][0]; //~^ ERROR E0080 -fn main() {} +fn main() { + let array = [std::env::args().len()]; + array[1]; //~ ERROR index out of bounds +} \ No newline at end of file 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`. From 29c43fea376624d62a8466e9304312f70c19d558 Mon Sep 17 00:00:00 2001 From: Fabian Zaiser Date: Sun, 3 Jun 2018 21:05:22 +0200 Subject: [PATCH 09/12] Fix tidy --- src/test/ui/const-eval/index_out_of_bounds.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/const-eval/index_out_of_bounds.rs b/src/test/ui/const-eval/index_out_of_bounds.rs index 9624b2924baa5..f3578bcef6e41 100644 --- a/src/test/ui/const-eval/index_out_of_bounds.rs +++ b/src/test/ui/const-eval/index_out_of_bounds.rs @@ -14,4 +14,4 @@ static FOO: i32 = [][0]; fn main() { let array = [std::env::args().len()]; array[1]; //~ ERROR index out of bounds -} \ No newline at end of file +} From 96004899bec1d63a8f54bea461f2d2a2965d4636 Mon Sep 17 00:00:00 2001 From: Fabian Zaiser Date: Sun, 3 Jun 2018 23:39:02 +0200 Subject: [PATCH 10/12] Fix tests --- src/test/compile-fail/const-err-early.rs | 4 ++-- src/test/compile-fail/const-err2.rs | 1 + src/test/compile-fail/const-err3.rs | 1 + src/test/run-fail/mir_indexing_oob_1.rs | 1 + src/test/run-fail/mir_indexing_oob_2.rs | 1 + src/test/run-fail/mir_indexing_oob_3.rs | 1 + 6 files changed, 7 insertions(+), 2 deletions(-) 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] } From 63885f7f72974f71d08d21bf79676ef4dc1ccaf8 Mon Sep 17 00:00:00 2001 From: Tobias Stolzmann Date: Tue, 29 May 2018 21:43:10 +0200 Subject: [PATCH 11/12] =?UTF-8?q?Update=20rustdoc=20book=20to=20suggest=20?= =?UTF-8?q?using=20Termination=20trait=20instead=20of=20hidden=20=E2=80=98?= =?UTF-8?q?foo=E2=80=99=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/doc/rustdoc/src/documentation-tests.md | 40 ++++++++++++++++------ 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/doc/rustdoc/src/documentation-tests.md b/src/doc/rustdoc/src/documentation-tests.md index fd7d1713ca574..1fa385d652fd6 100644 --- a/src/doc/rustdoc/src/documentation-tests.md +++ b/src/doc/rustdoc/src/documentation-tests.md @@ -168,37 +168,55 @@ 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 + +A complete error handling is often not useful in your example, 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: From 089da06cc437aa4764f958ff441e79d7fca6b148 Mon Sep 17 00:00:00 2001 From: Tobias Stolzmann Date: Thu, 31 May 2018 20:01:03 +0200 Subject: [PATCH 12/12] Improve wording --- src/doc/rustdoc/src/documentation-tests.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/doc/rustdoc/src/documentation-tests.md b/src/doc/rustdoc/src/documentation-tests.md index 1fa385d652fd6..2de69924b74dd 100644 --- a/src/doc/rustdoc/src/documentation-tests.md +++ b/src/doc/rustdoc/src/documentation-tests.md @@ -171,8 +171,9 @@ explanation. ## Using `?` in doc tests -A complete error handling is often not useful in your example, as it would add -significant amounts of boilerplate code. Instead, you may want the following: +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 /// ```