From 5db17335a15e5e290bd7505cc37b2177c86b51c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Fri, 11 Oct 2019 00:00:00 +0000 Subject: [PATCH 1/9] rustdoc: forward -Z options to rustc Currently rustdoc does not forward `-Z` options to rustc when building test executables. This makes impossible to use rustdoc to run test samples when crate under test is instrumented with one of sanitizers `-Zsanitizer=...`, since the final linking step will not include sanitizer runtime library. Forward `-Z` options to rustc to solve the issue. Helps with #43031. --- src/librustdoc/config.rs | 4 ++++ src/librustdoc/test.rs | 3 +++ .../failed-doctest-missing-codes.stdout | 14 +++++++------- .../rustdoc-ui/failed-doctest-output.stdout | 8 ++++---- src/test/rustdoc-ui/unparseable-doc-test.stdout | 8 ++++---- src/test/rustdoc/sanitizer-option.rs | 17 +++++++++++++++++ 6 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 src/test/rustdoc/sanitizer-option.rs diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index fe4e2bd091519..3bfc25e5115cb 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -53,6 +53,8 @@ pub struct Options { pub codegen_options_strs: Vec, /// Debugging (`-Z`) options to pass to the compiler. pub debugging_options: DebuggingOptions, + /// Debugging (`-Z`) options strings to pass to the compiler. + pub debugging_options_strs: Vec, /// The target used to compile the crate against. pub target: TargetTriple, /// Edition used when reading the crate. Defaults to "2015". Also used by default when @@ -481,6 +483,7 @@ impl Options { let generate_redirect_pages = matches.opt_present("generate-redirect-pages"); let test_builder = matches.opt_str("test-builder").map(PathBuf::from); let codegen_options_strs = matches.opt_strs("C"); + let debugging_options_strs = matches.opt_strs("Z"); let lib_strs = matches.opt_strs("L"); let extern_strs = matches.opt_strs("extern"); let runtool = matches.opt_str("runtool"); @@ -502,6 +505,7 @@ impl Options { codegen_options, codegen_options_strs, debugging_options, + debugging_options_strs, target, edition, maybe_sysroot, diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 3e77ca47e8a6a..f1d1694ca940e 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -279,6 +279,9 @@ fn run_test( for codegen_options_str in &options.codegen_options_strs { compiler.arg("-C").arg(&codegen_options_str); } + for debugging_option_str in &options.debugging_options_strs { + compiler.arg("-Z").arg(&debugging_option_str); + } if no_run { compiler.arg("--emit=metadata"); } diff --git a/src/test/rustdoc-ui/failed-doctest-missing-codes.stdout b/src/test/rustdoc-ui/failed-doctest-missing-codes.stdout index d206b721765b2..a8753d14de22f 100644 --- a/src/test/rustdoc-ui/failed-doctest-missing-codes.stdout +++ b/src/test/rustdoc-ui/failed-doctest-missing-codes.stdout @@ -6,13 +6,13 @@ failures: ---- $DIR/failed-doctest-missing-codes.rs - Foo (line 8) stdout ---- error[E0308]: mismatched types - --> $DIR/failed-doctest-missing-codes.rs:9:13 - | -3 | let x: () = 5i32; - | ^^^^ expected (), found i32 - | - = note: expected type `()` - found type `i32` + --> $DIR/failed-doctest-missing-codes.rs:9:13 + | +LL | let x: () = 5i32; + | ^^^^ expected (), found i32 + | + = note: expected type `()` + found type `i32` error: aborting due to previous error diff --git a/src/test/rustdoc-ui/failed-doctest-output.stdout b/src/test/rustdoc-ui/failed-doctest-output.stdout index ef1b419f52895..9887d07a3eb6e 100644 --- a/src/test/rustdoc-ui/failed-doctest-output.stdout +++ b/src/test/rustdoc-ui/failed-doctest-output.stdout @@ -7,10 +7,10 @@ failures: ---- $DIR/failed-doctest-output.rs - OtherStruct (line 21) stdout ---- error[E0425]: cannot find value `no` in this scope - --> $DIR/failed-doctest-output.rs:22:1 - | -3 | no - | ^^ not found in this scope + --> $DIR/failed-doctest-output.rs:22:1 + | +LL | no + | ^^ not found in this scope error: aborting due to previous error diff --git a/src/test/rustdoc-ui/unparseable-doc-test.stdout b/src/test/rustdoc-ui/unparseable-doc-test.stdout index 0350c01643607..4ea6455d3aa4c 100644 --- a/src/test/rustdoc-ui/unparseable-doc-test.stdout +++ b/src/test/rustdoc-ui/unparseable-doc-test.stdout @@ -6,10 +6,10 @@ failures: ---- $DIR/unparseable-doc-test.rs - foo (line 6) stdout ---- error: unterminated double quote string - --> $DIR/unparseable-doc-test.rs:8:1 - | -2 | "unterminated - | ^^^^^^^^^^^^^ + --> $DIR/unparseable-doc-test.rs:8:1 + | +LL | "unterminated + | ^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/rustdoc/sanitizer-option.rs b/src/test/rustdoc/sanitizer-option.rs new file mode 100644 index 0000000000000..6af9ed3e33f66 --- /dev/null +++ b/src/test/rustdoc/sanitizer-option.rs @@ -0,0 +1,17 @@ +// needs-sanitizer-support +// compile-flags: --test -Z sanitizer=address +// +// #43031: Verify that rustdoc passes `-Z` options to rustc. Use an extern +// function that is provided by the sanitizer runtime, if flag is not passed +// correctly, then linking will fail. + +/// ``` +/// extern { +/// fn __sanitizer_print_stack_trace(); +/// } +/// +/// fn main() { +/// unsafe { __sanitizer_print_stack_trace() }; +/// } +/// ``` +pub fn z_flag_is_passed_to_rustc() {} From 282403e6bd0f858474c47fe2b9efd50645023c7c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 19 Oct 2019 11:46:56 +0200 Subject: [PATCH 2/9] clarify const_prop ICE protection comment --- src/librustc_mir/transform/const_prop.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index f0c0e57344388..223330a3ecb44 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -518,12 +518,13 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } } - // Work around: avoid ICE in miri. - // FIXME(wesleywiser) we don't currently handle the case where we try to make a ref - // from a function argument that hasn't been assigned to in this function. The main - // issue is if an arg is a fat-pointer, miri `expects()` to be able to read the value - // of that pointer to get size info. However, since this is `ConstProp`, that argument - // doesn't actually have a backing value and so this causes an ICE. + // Work around: avoid ICE in miri. FIXME(wesleywiser) + // The Miri engine ICEs when taking a reference to an uninitialized unsized + // local. There's nothing it can do here: taking a reference needs an allocation + // which needs to know the size. Normally that's okay as during execution + // (e.g. for CTFE) it can never happen. But here in const_prop + // we leave function arguments uninitialized, so if one of these is unsized + // and has a reference taken, we get an ICE. Rvalue::Ref(_, _, Place { base: PlaceBase::Local(local), projection: box [] }) => { trace!("checking Ref({:?})", place); let alive = @@ -531,14 +532,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { true } else { false }; + // local 0 is the return place; locals 1..=arg_count are the arguments. if local.as_usize() <= self.ecx.frame().body.arg_count && !alive { trace!("skipping Ref({:?})", place); return None; } } - // Work around: avoid extra unnecessary locals. - // FIXME(wesleywiser): const eval will turn this into a `const Scalar()` that + // Work around: avoid extra unnecessary locals. FIXME(wesleywiser) + // Const eval will turn this into a `const Scalar()` that // `SimplifyLocals` doesn't know it can remove. Rvalue::Aggregate(_, operands) if operands.len() == 0 => { return None; From 9be0bd8aa110bc580fb5d0f59e4f4fc96068c616 Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Sat, 19 Oct 2019 13:05:46 -0400 Subject: [PATCH 3/9] Avoid ICE when include! is used by stdin crate This should also eliminate the ICE when using `include_bytes!`, `include_str!` and `#[doc(include = "...")]`. Fixes #63900 --- src/libsyntax_expand/base.rs | 15 +++++++++++---- src/libsyntax_expand/expand.rs | 9 ++++++++- src/libsyntax_ext/source_util.rs | 24 +++++++++++++++++++++--- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/libsyntax_expand/base.rs b/src/libsyntax_expand/base.rs index c222e7357ac7e..58edf23a5b1e2 100644 --- a/src/libsyntax_expand/base.rs +++ b/src/libsyntax_expand/base.rs @@ -1072,7 +1072,11 @@ impl<'a> ExtCtxt<'a> { /// This unifies the logic used for resolving `include_X!`, and `#[doc(include)]` file paths. /// /// Returns an absolute path to the file that `path` refers to. - pub fn resolve_path(&self, path: impl Into, span: Span) -> PathBuf { + pub fn resolve_path( + &self, + path: impl Into, + span: Span, + ) -> Result> { let path = path.into(); // Relative paths are resolved relative to the file in which they are found @@ -1082,13 +1086,16 @@ impl<'a> ExtCtxt<'a> { let mut result = match self.source_map().span_to_unmapped_path(callsite) { FileName::Real(path) => path, FileName::DocTest(path, _) => path, - other => panic!("cannot resolve relative path in non-file source `{}`", other), + other => return Err(self.struct_span_err( + span, + &format!("cannot resolve relative path in non-file source `{}`", other), + )), }; result.pop(); result.push(path); - result + Ok(result) } else { - path + Ok(path) } } } diff --git a/src/libsyntax_expand/expand.rs b/src/libsyntax_expand/expand.rs index f03d464eafb90..fc521e5edc06b 100644 --- a/src/libsyntax_expand/expand.rs +++ b/src/libsyntax_expand/expand.rs @@ -1418,7 +1418,14 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { return noop_visit_attribute(at, self); } - let filename = self.cx.resolve_path(&*file.as_str(), it.span()); + let filename = match self.cx.resolve_path(&*file.as_str(), it.span()) { + Ok(filename) => filename, + Err(mut err) => { + err.emit(); + continue; + } + }; + match self.cx.source_map().load_file(&filename) { Ok(source_file) => { let src = source_file.src.as_ref() diff --git a/src/libsyntax_ext/source_util.rs b/src/libsyntax_ext/source_util.rs index 438e199ebdb8f..f6c58fcdfa1cb 100644 --- a/src/libsyntax_ext/source_util.rs +++ b/src/libsyntax_ext/source_util.rs @@ -76,7 +76,13 @@ pub fn expand_include<'cx>(cx: &'cx mut ExtCtxt<'_>, sp: Span, tts: TokenStream) None => return DummyResult::any(sp), }; // The file will be added to the code map by the parser - let file = cx.resolve_path(file, sp); + let file = match cx.resolve_path(file, sp) { + Ok(f) => f, + Err(mut err) => { + err.emit(); + return DummyResult::any(sp); + }, + }; let directory_ownership = DirectoryOwnership::Owned { relative: None }; let p = parse::new_sub_parser_from_file(cx.parse_sess(), &file, directory_ownership, None, sp); @@ -122,7 +128,13 @@ pub fn expand_include_str(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) Some(f) => f, None => return DummyResult::any(sp) }; - let file = cx.resolve_path(file, sp); + let file = match cx.resolve_path(file, sp) { + Ok(f) => f, + Err(mut err) => { + err.emit(); + return DummyResult::any(sp); + }, + }; match cx.source_map().load_binary_file(&file) { Ok(bytes) => match std::str::from_utf8(&bytes) { Ok(src) => { @@ -147,7 +159,13 @@ pub fn expand_include_bytes(cx: &mut ExtCtxt<'_>, sp: Span, tts: TokenStream) Some(f) => f, None => return DummyResult::any(sp) }; - let file = cx.resolve_path(file, sp); + let file = match cx.resolve_path(file, sp) { + Ok(f) => f, + Err(mut err) => { + err.emit(); + return DummyResult::any(sp); + }, + }; match cx.source_map().load_binary_file(&file) { Ok(bytes) => { base::MacEager::expr(cx.expr_lit(sp, ast::LitKind::ByteStr(Lrc::new(bytes)))) From 2f7c9a28964f8ddb1fca675bbc567144c893d6e6 Mon Sep 17 00:00:00 2001 From: varkor Date: Sun, 20 Oct 2019 01:11:56 +0100 Subject: [PATCH 4/9] Improve error message for APIT with explicit generic parameters This is disallowed with type or const generics. --- src/librustc_typeck/astconv.rs | 4 ++-- src/librustc_typeck/error_codes.rs | 4 ++-- src/test/ui/impl-trait/issues/universal-issue-48703.rs | 2 +- src/test/ui/impl-trait/issues/universal-issue-48703.stderr | 2 +- .../issues/universal-turbofish-in-method-issue-50950.rs | 2 +- .../issues/universal-turbofish-in-method-issue-50950.stderr | 2 +- src/test/ui/synthetic-param.rs | 6 +++--- src/test/ui/synthetic-param.stderr | 6 +++--- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 7e0a9bc4011c0..8eab9c4e67e33 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -232,8 +232,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { tcx.sess, span, E0632, - "cannot provide explicit type parameters when `impl Trait` is \ - used in argument position." + "cannot provide explicit generic arguments when `impl Trait` is \ + used in argument position" }; err.emit(); diff --git a/src/librustc_typeck/error_codes.rs b/src/librustc_typeck/error_codes.rs index ef08e8d4f0b7a..8321fdd400fec 100644 --- a/src/librustc_typeck/error_codes.rs +++ b/src/librustc_typeck/error_codes.rs @@ -5048,8 +5048,8 @@ the future, [RFC 2091] prohibits their implementation without a follow-up RFC. // E0612, // merged into E0609 // E0613, // Removed (merged with E0609) E0627, // yield statement outside of generator literal - E0632, // cannot provide explicit type parameters when `impl Trait` is used - // in argument position. + E0632, // cannot provide explicit generic arguments when `impl Trait` is + // used in argument position E0634, // type has conflicting packed representaton hints E0640, // infer outlives requirements E0641, // cannot cast to/from a pointer with an unknown kind diff --git a/src/test/ui/impl-trait/issues/universal-issue-48703.rs b/src/test/ui/impl-trait/issues/universal-issue-48703.rs index e434e10bf89d7..f661c62c9e440 100644 --- a/src/test/ui/impl-trait/issues/universal-issue-48703.rs +++ b/src/test/ui/impl-trait/issues/universal-issue-48703.rs @@ -5,5 +5,5 @@ use std::fmt::Debug; fn foo(x: impl Debug) { } fn main() { - foo::('a'); //~ ERROR cannot provide explicit type parameters + foo::('a'); //~ ERROR cannot provide explicit generic arguments } diff --git a/src/test/ui/impl-trait/issues/universal-issue-48703.stderr b/src/test/ui/impl-trait/issues/universal-issue-48703.stderr index 527bbd5f30fef..a51302dce2966 100644 --- a/src/test/ui/impl-trait/issues/universal-issue-48703.stderr +++ b/src/test/ui/impl-trait/issues/universal-issue-48703.stderr @@ -1,4 +1,4 @@ -error[E0632]: cannot provide explicit type parameters when `impl Trait` is used in argument position. +error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position --> $DIR/universal-issue-48703.rs:8:5 | LL | foo::('a'); diff --git a/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.rs b/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.rs index d3d561621fc2d..4ac0a694cb148 100644 --- a/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.rs +++ b/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.rs @@ -12,6 +12,6 @@ struct TestEvent(i32); fn main() { let mut evt = EventHandler {}; evt.handle_event::(|_evt| { - //~^ ERROR cannot provide explicit type parameters + //~^ ERROR cannot provide explicit generic arguments }); } diff --git a/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr b/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr index e2e6581fcf915..f09aa166ef508 100644 --- a/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr +++ b/src/test/ui/impl-trait/issues/universal-turbofish-in-method-issue-50950.stderr @@ -1,4 +1,4 @@ -error[E0632]: cannot provide explicit type parameters when `impl Trait` is used in argument position. +error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position --> $DIR/universal-turbofish-in-method-issue-50950.rs:14:9 | LL | evt.handle_event::(|_evt| { diff --git a/src/test/ui/synthetic-param.rs b/src/test/ui/synthetic-param.rs index e53e3ba06e0d1..e14697f5c3e97 100644 --- a/src/test/ui/synthetic-param.rs +++ b/src/test/ui/synthetic-param.rs @@ -17,12 +17,12 @@ impl Bar { } fn main() { - func::(42); //~ ERROR cannot provide explicit type parameters + func::(42); //~ ERROR cannot provide explicit generic arguments func(42); // Ok - Foo::func::(42); //~ ERROR cannot provide explicit type parameters + Foo::func::(42); //~ ERROR cannot provide explicit generic arguments Foo::func(42); // Ok - Bar::::func::(42); //~ ERROR cannot provide explicit type parameters + Bar::::func::(42); //~ ERROR cannot provide explicit generic arguments Bar::::func(42); // Ok } diff --git a/src/test/ui/synthetic-param.stderr b/src/test/ui/synthetic-param.stderr index bfafd8cbd72ec..f8d14f26f32de 100644 --- a/src/test/ui/synthetic-param.stderr +++ b/src/test/ui/synthetic-param.stderr @@ -1,16 +1,16 @@ -error[E0632]: cannot provide explicit type parameters when `impl Trait` is used in argument position. +error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position --> $DIR/synthetic-param.rs:20:5 | LL | func::(42); | ^^^^^^^^^^ -error[E0632]: cannot provide explicit type parameters when `impl Trait` is used in argument position. +error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position --> $DIR/synthetic-param.rs:23:5 | LL | Foo::func::(42); | ^^^^^^^^^^^^^^^ -error[E0632]: cannot provide explicit type parameters when `impl Trait` is used in argument position. +error[E0632]: cannot provide explicit generic arguments when `impl Trait` is used in argument position --> $DIR/synthetic-param.rs:26:5 | LL | Bar::::func::(42); From f907fbe1a6676a26cfc893b78f0fffb4285f1e6c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 19 Oct 2019 18:16:22 +0200 Subject: [PATCH 5/9] skip all refs-to-uninit-local, not just arguments --- src/librustc_mir/transform/const_prop.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 223330a3ecb44..780b49cd9db0d 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -523,18 +523,19 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { // local. There's nothing it can do here: taking a reference needs an allocation // which needs to know the size. Normally that's okay as during execution // (e.g. for CTFE) it can never happen. But here in const_prop - // we leave function arguments uninitialized, so if one of these is unsized + // unknown data is uninitialized, so if e.g. a function argument is unsized // and has a reference taken, we get an ICE. Rvalue::Ref(_, _, Place { base: PlaceBase::Local(local), projection: box [] }) => { trace!("checking Ref({:?})", place); let alive = if let LocalValue::Live(_) = self.ecx.frame().locals[*local].value { true - } else { false }; + } else { + false + }; - // local 0 is the return place; locals 1..=arg_count are the arguments. - if local.as_usize() <= self.ecx.frame().body.arg_count && !alive { - trace!("skipping Ref({:?})", place); + if !alive { + trace!("skipping Ref({:?}) to uninitialized local", place); return None; } } From 51a5b49bdafe24cd59d1f38b54e82b181b37aae8 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Sun, 20 Oct 2019 09:36:04 -0700 Subject: [PATCH 6/9] Remove `borrowck_graphviz_postflow` from test --- src/test/ui/consts/const-eval/issue-65394.rs | 3 --- src/test/ui/consts/const-eval/issue-65394.stderr | 6 +++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/test/ui/consts/const-eval/issue-65394.rs b/src/test/ui/consts/const-eval/issue-65394.rs index 978e227bcc817..8cf527f0429f0 100644 --- a/src/test/ui/consts/const-eval/issue-65394.rs +++ b/src/test/ui/consts/const-eval/issue-65394.rs @@ -1,8 +1,5 @@ // Test for absence of validation mismatch ICE in #65394 -#![feature(rustc_attrs)] - -#[rustc_mir(borrowck_graphviz_postflow="hello.dot")] const _: Vec = { let mut x = Vec::::new(); let r = &mut x; //~ ERROR references in constants may only refer to immutable values diff --git a/src/test/ui/consts/const-eval/issue-65394.stderr b/src/test/ui/consts/const-eval/issue-65394.stderr index f48c551cb50f5..15df813836e5b 100644 --- a/src/test/ui/consts/const-eval/issue-65394.stderr +++ b/src/test/ui/consts/const-eval/issue-65394.stderr @@ -1,11 +1,11 @@ error[E0017]: references in constants may only refer to immutable values - --> $DIR/issue-65394.rs:8:13 + --> $DIR/issue-65394.rs:5:13 | LL | let r = &mut x; | ^^^^^^ constants require immutable values -[ERROR rustc_mir::transform::qualify_consts] old validator: [($DIR/issue-65394.rs:8:13: 8:19, "MutBorrow(Mut { allow_two_phase_borrow: false })")] -[ERROR rustc_mir::transform::qualify_consts] new validator: [($DIR/issue-65394.rs:8:13: 8:19, "MutBorrow(Mut { allow_two_phase_borrow: false })"), ($DIR/issue-65394.rs:7:9: 7:14, "LiveDrop")] +[ERROR rustc_mir::transform::qualify_consts] old validator: [($DIR/issue-65394.rs:5:13: 5:19, "MutBorrow(Mut { allow_two_phase_borrow: false })")] +[ERROR rustc_mir::transform::qualify_consts] new validator: [($DIR/issue-65394.rs:5:13: 5:19, "MutBorrow(Mut { allow_two_phase_borrow: false })"), ($DIR/issue-65394.rs:4:9: 4:14, "LiveDrop")] error: aborting due to previous error For more information about this error, try `rustc --explain E0017`. From 040d88dda1c65d6cb3cd5df5e81075a281f90da4 Mon Sep 17 00:00:00 2001 From: Mikko Rantanen Date: Sun, 20 Oct 2019 21:13:47 +0300 Subject: [PATCH 7/9] Remove leading :: from paths in doc examples --- src/libcore/iter/traits/collect.rs | 2 +- src/libcore/ops/unsize.rs | 2 +- src/libcore/str/mod.rs | 4 ++-- src/libstd/net/udp.rs | 2 +- src/libstd/process.rs | 12 ++++++------ 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libcore/iter/traits/collect.rs b/src/libcore/iter/traits/collect.rs index 25439136b8538..00a864170583e 100644 --- a/src/libcore/iter/traits/collect.rs +++ b/src/libcore/iter/traits/collect.rs @@ -167,7 +167,7 @@ pub trait FromIterator: Sized { /// // and we'll implement IntoIterator /// impl IntoIterator for MyCollection { /// type Item = i32; -/// type IntoIter = ::std::vec::IntoIter; +/// type IntoIter = std::vec::IntoIter; /// /// fn into_iter(self) -> Self::IntoIter { /// self.0.into_iter() diff --git a/src/libcore/ops/unsize.rs b/src/libcore/ops/unsize.rs index 8e46830084642..d29147645f7ef 100644 --- a/src/libcore/ops/unsize.rs +++ b/src/libcore/ops/unsize.rs @@ -76,7 +76,7 @@ impl, U: ?Sized> CoerceUnsized<*const U> for *const T {} /// ``` /// # #![feature(dispatch_from_dyn, unsize)] /// # use std::{ops::DispatchFromDyn, marker::Unsize}; -/// # struct Rc(::std::rc::Rc); +/// # struct Rc(std::rc::Rc); /// impl DispatchFromDyn> for Rc /// where /// T: Unsize, diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index 885696e5acf49..f67012d8f2fce 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -176,7 +176,7 @@ Section: Creating a string /// ``` /// fn from_utf8_lossy(mut input: &[u8], mut push: F) where F: FnMut(&str) { /// loop { -/// match ::std::str::from_utf8(input) { +/// match std::str::from_utf8(input) { /// Ok(valid) => { /// push(valid); /// break @@ -184,7 +184,7 @@ Section: Creating a string /// Err(error) => { /// let (valid, after_valid) = input.split_at(error.valid_up_to()); /// unsafe { -/// push(::std::str::from_utf8_unchecked(valid)) +/// push(std::str::from_utf8_unchecked(valid)) /// } /// push("\u{FFFD}"); /// diff --git a/src/libstd/net/udp.rs b/src/libstd/net/udp.rs index 46bbd8855deda..a9e4457f42374 100644 --- a/src/libstd/net/udp.rs +++ b/src/libstd/net/udp.rs @@ -202,7 +202,7 @@ impl UdpSocket { /// /// let socket = UdpSocket::bind("127.0.0.1:34254").expect("couldn't bind to address"); /// assert_eq!(socket.peer_addr().unwrap_err().kind(), - /// ::std::io::ErrorKind::NotConnected); + /// std::io::ErrorKind::NotConnected); /// ``` #[stable(feature = "udp_peer_addr", since = "1.40.0")] pub fn peer_addr(&self) -> io::Result { diff --git a/src/libstd/process.rs b/src/libstd/process.rs index da136ca6bf68d..4b0cf8312f189 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -1488,12 +1488,12 @@ impl Child { /// } /// /// fn main() { -/// ::std::process::exit(match run_app() { -/// Ok(_) => 0, -/// Err(err) => { -/// eprintln!("error: {:?}", err); -/// 1 -/// } +/// std::process::exit(match run_app() { +/// Ok(_) => 0, +/// Err(err) => { +/// eprintln!("error: {:?}", err); +/// 1 +/// } /// }); /// } /// ``` From 2a5c31ca51a5d7c1c3d580e1214094dc2ef5d8fe Mon Sep 17 00:00:00 2001 From: David Sinclair Date: Sun, 20 Oct 2019 22:22:33 +0200 Subject: [PATCH 8/9] Rename the default argument 'def' to 'default' Fixes: #65492 --- src/libcore/option.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 09d4076c7fbc7..9eb29eae7f75a 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -395,10 +395,10 @@ impl Option { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn unwrap_or(self, def: T) -> T { + pub fn unwrap_or(self, default: T) -> T { match self { Some(x) => x, - None => def, + None => default, } } From e697ffbbcb41559c8de3ca3b94f3b9467e662a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Heine=20n=C3=A9=20Lang?= Date: Sun, 20 Oct 2019 23:13:41 +0200 Subject: [PATCH 9/9] Fix parameter name in documentation --- src/libstd/io/stdio.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs index c798ee0e2209a..6574ef13db953 100644 --- a/src/libstd/io/stdio.rs +++ b/src/libstd/io/stdio.rs @@ -762,7 +762,7 @@ pub fn set_print(sink: Option>) -> Option