From ee05fc8104e5e2fecf8f67fc3d4259d5d576a20f Mon Sep 17 00:00:00 2001 From: Andre Bogus Date: Thu, 20 Jun 2019 14:36:53 +0200 Subject: [PATCH 1/5] First question mark in doctest --- src/libcore/macros.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 8b44025f91f5e..4648f1a006eca 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -335,11 +335,14 @@ macro_rules! r#try { /// ``` /// use std::io::Write; /// -/// let mut w = Vec::new(); -/// write!(&mut w, "test").unwrap(); -/// write!(&mut w, "formatted {}", "arguments").unwrap(); +/// fn main() -> std::io::Result<()> { +/// let mut w = Vec::new(); +/// write!(&mut w, "test")?; +/// write!(&mut w, "formatted {}", "arguments")?; /// -/// assert_eq!(w, b"testformatted arguments"); +/// assert_eq!(w, b"testformatted arguments"); +/// Ok(()) +/// } /// ``` /// /// A module can import both `std::fmt::Write` and `std::io::Write` and call `write!` on objects From 02886e2c51ba0fe244bf4526de2559a7e192cab6 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 4 Jul 2019 18:11:52 +0200 Subject: [PATCH 2/5] Add missing links in Option documentation --- src/libcore/option.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index eec4b149ddc78..8eadc4abaae82 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -263,7 +263,7 @@ impl Option { } - /// Converts from `Pin<&Option>` to `Option>` + /// Converts from [`Pin`]`<&Option>` to `Option<`[`Pin`]`<&T>>`. #[inline] #[stable(feature = "pin", since = "1.33.0")] pub fn as_pin_ref<'a>(self: Pin<&'a Option>) -> Option> { @@ -272,7 +272,7 @@ impl Option { } } - /// Converts from `Pin<&mut Option>` to `Option>` + /// Converts from [`Pin`]`<&mut Option>` to `Option<`[`Pin`]`<&mut T>>`. #[inline] #[stable(feature = "pin", since = "1.33.0")] pub fn as_pin_mut<'a>(self: Pin<&'a mut Option>) -> Option> { @@ -626,14 +626,14 @@ impl Option { } } - /// Returns `None` if the option is `None`, otherwise calls `predicate` + /// Returns [`None`] if the option is [`None`], otherwise calls `predicate` /// with the wrapped value and returns: /// - /// - `Some(t)` if `predicate` returns `true` (where `t` is the wrapped + /// - [`Some(t)`] if `predicate` returns `true` (where `t` is the wrapped /// value), and - /// - `None` if `predicate` returns `false`. + /// - [`None`] if `predicate` returns `false`. /// - /// This function works similar to `Iterator::filter()`. You can imagine + /// This function works similar to [`Iterator::filter()`]. You can imagine /// the `Option` being an iterator over one or zero elements. `filter()` /// lets you decide which elements to keep. /// @@ -648,6 +648,10 @@ impl Option { /// assert_eq!(Some(3).filter(is_even), None); /// assert_eq!(Some(4).filter(is_even), Some(4)); /// ``` + /// + /// [`None`]: #variant.None + /// [`Some(t)`]: #variant.Some + /// [`Iterator::filter()`]: ../../std/iter/trait.Iterator.html#method.filter #[inline] #[stable(feature = "option_filter", since = "1.27.0")] pub fn filter bool>(self, predicate: P) -> Self { @@ -994,17 +998,25 @@ impl Option { /// Converts from `&Option` to `Option<&T::Target>`. /// /// Leaves the original Option in-place, creating a new one with a reference - /// to the original one, additionally coercing the contents via `Deref`. + /// to the original one, additionally coercing the contents via [`Deref`]. + /// + /// [`Deref`]: ../../std/ops/trait.Deref.html pub fn deref(&self) -> Option<&T::Target> { self.as_ref().map(|t| t.deref()) } } impl Option> { - /// Transposes an `Option` of a `Result` into a `Result` of an `Option`. + /// Transposes an `Option` of a [`Result`] into a [`Result`] of an `Option`. /// - /// `None` will be mapped to `Ok(None)`. - /// `Some(Ok(_))` and `Some(Err(_))` will be mapped to `Ok(Some(_))` and `Err(_)`. + /// [`None`] will be mapped to [`Ok`]`(`[`None`]`)`. + /// [`Some`]`(`[`Ok`]`(_))` and [`Some`]`(`[`Err`]`(_))` will be mapped to + /// [`Ok`]`(`[`Some`]`(_))` and [`Err`]`(_)`. + /// + /// [`None`]: #variant.None + /// [`Ok`]: ../../std/result/enum.Result.html#variant.Ok + /// [`Some`]: #variant.Some + /// [`Err`]: ../../std/result/enum.Result.html#variant.Err /// /// # Examples /// From b11757e0d55a53934b27ecbefa1a89b7b092f7d3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 6 Jul 2019 03:15:04 +0300 Subject: [PATCH 3/5] rustbuild: Cleanup global lint settings --- src/bootstrap/bin/rustc.rs | 66 +++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 37 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 242074fec7795..2d403038c215a 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -91,17 +91,16 @@ fn main() { cmd.args(&args) .env(bootstrap::util::dylib_path_var(), env::join_paths(&dylib_path).unwrap()); - let mut maybe_crate = None; // Get the name of the crate we're compiling, if any. - let maybe_crate_name = args.windows(2) - .find(|a| &*a[0] == "--crate-name") - .map(|crate_name| &*crate_name[1]); + let crate_name = args.windows(2) + .find(|args| args[0] == "--crate-name") + .and_then(|args| args[1].to_str()); - if let Some(current_crate) = maybe_crate_name { + if let Some(crate_name) = crate_name { if let Some(target) = env::var_os("RUSTC_TIME") { if target == "all" || - target.into_string().unwrap().split(",").any(|c| c.trim() == current_crate) + target.into_string().unwrap().split(",").any(|c| c.trim() == crate_name) { cmd.arg("-Ztime"); } @@ -125,6 +124,17 @@ fn main() { cmd.arg(format!("-Cdebuginfo={}", debuginfo_level)); } + if env::var_os("RUSTC_DENY_WARNINGS").is_some() && + env::var_os("RUSTC_EXTERNAL_TOOL").is_none() { + cmd.arg("-Dwarnings"); + cmd.arg("-Drust_2018_idioms"); + if stage != "0" && crate_name != Some("rustc_version") && // cfg(not(bootstrap)) + use_internal_lints(crate_name) { + cmd.arg("-Zunstable-options"); + cmd.arg("-Drustc::internal"); + } + } + if let Some(target) = target { // The stage0 compiler has a special sysroot distinct from what we // actually downloaded, so we just always pass the `--sysroot` option. @@ -167,9 +177,6 @@ fn main() { cmd.arg(format!("-Clinker={}", target_linker)); } - let crate_name = maybe_crate_name.unwrap(); - maybe_crate = Some(crate_name); - // If we're compiling specifically the `panic_abort` crate then we pass // the `-C panic=abort` option. Note that we do not do this for any // other crate intentionally as this is the only crate for now that we @@ -182,8 +189,8 @@ fn main() { // `compiler_builtins` are unconditionally compiled with panic=abort to // workaround undefined references to `rust_eh_unwind_resume` generated // otherwise, see issue https://github.com/rust-lang/rust/issues/43095. - if crate_name == "panic_abort" || - crate_name == "compiler_builtins" && stage != "0" { + if crate_name == Some("panic_abort") || + crate_name == Some("compiler_builtins") && stage != "0" { cmd.arg("-C").arg("panic=abort"); } @@ -196,7 +203,7 @@ fn main() { // The compiler builtins are pretty sensitive to symbols referenced in // libcore and such, so we never compile them with debug assertions. - if crate_name == "compiler_builtins" { + if crate_name == Some("compiler_builtins") { cmd.arg("-C").arg("debug-assertions=no"); } else { cmd.arg("-C").arg(format!("debug-assertions={}", debug_assertions)); @@ -305,22 +312,6 @@ fn main() { } } - // This is required for internal lints. - if let Some(crate_name) = args.windows(2).find(|a| &*a[0] == "--crate-name") { - let crate_name = crate_name[1].to_string_lossy(); - if crate_name != "rustc_version" - && (crate_name.starts_with("rustc") - || crate_name.starts_with("syntax") - || crate_name == "arena" - || crate_name == "fmt_macros") - { - cmd.arg("-Zunstable-options"); - if stage != "0" { - cmd.arg("-Wrustc::internal"); - } - } - } - // Force all crates compiled by this compiler to (a) be unstable and (b) // allow the `rustc_private` feature to link to other unstable crates // also in the sysroot. We also do this for host crates, since those @@ -333,13 +324,6 @@ fn main() { cmd.arg("--cfg").arg("parallel_compiler"); } - if env::var_os("RUSTC_DENY_WARNINGS").is_some() && env::var_os("RUSTC_EXTERNAL_TOOL").is_none() - { - cmd.arg("-Dwarnings"); - cmd.arg("-Dbare_trait_objects"); - cmd.arg("-Drust_2018_idioms"); - } - if verbose > 1 { eprintln!( "rustc command: {:?}={:?} {:?}", @@ -362,7 +346,7 @@ fn main() { } if env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some() { - if let Some(krate) = maybe_crate { + if let Some(crate_name) = crate_name { let start = Instant::now(); let status = cmd .status() @@ -371,7 +355,7 @@ fn main() { let is_test = args.iter().any(|a| a == "--test"); eprintln!("[RUSTC-TIMING] {} test:{} {}.{:03}", - krate.to_string_lossy(), + crate_name, is_test, dur.as_secs(), dur.subsec_nanos() / 1_000_000); @@ -390,6 +374,14 @@ fn main() { std::process::exit(code); } +// Rustc crates for which internal lints are in effect. +fn use_internal_lints(crate_name: Option<&str>) -> bool { + crate_name.map_or(false, |crate_name| { + crate_name.starts_with("rustc") || crate_name.starts_with("syntax") || + ["arena", "fmt_macros"].contains(&crate_name) + }) +} + #[cfg(unix)] fn exec_cmd(cmd: &mut Command) -> io::Result { use std::os::unix::process::CommandExt; From 36a5aa832503a2fb6ab2eb80e1873711807430a5 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 7 Jul 2019 01:18:29 +0300 Subject: [PATCH 4/5] Address review comments --- src/bootstrap/bin/rustc.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 2d403038c215a..a9225f2870f55 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -128,8 +128,10 @@ fn main() { env::var_os("RUSTC_EXTERNAL_TOOL").is_none() { cmd.arg("-Dwarnings"); cmd.arg("-Drust_2018_idioms"); - if stage != "0" && crate_name != Some("rustc_version") && // cfg(not(bootstrap)) - use_internal_lints(crate_name) { + // cfg(not(bootstrap)): Remove this during the next stage 0 compiler update. + // `-Drustc::internal` is a new feature and `rustc_version` mis-reports the `stage`. + let cfg_not_bootstrap = stage != "0" && crate_name != Some("rustc_version"); + if cfg_not_bootstrap && use_internal_lints(crate_name) { cmd.arg("-Zunstable-options"); cmd.arg("-Drustc::internal"); } From 6bb60ef6f2392b029c0bb5e2042f0f5743ae6763 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sat, 6 Jul 2019 16:47:43 -0700 Subject: [PATCH 5/5] name the trait in ambiguous-associated-items fully qualified suggestion We have the trait at this point, so we can name it in the error message, rather than using "Trait" as a (potentially confusing) placeholder. Thanks to Yuki "@JohnTitor" Okushi for pointing out where to look (in the same file) for a closely related issue for ambiguous associated types (as opposed to items; that was #59225, except that one won't be quite as easy to resolve, because we actually don't have the trait `DefId` at that point). --- src/librustc_typeck/astconv.rs | 4 ++-- ...um-variant-priority-lint-ambiguous_associated_items.stderr | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 7154b7958b932..d314228a232c9 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1709,8 +1709,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { err.span_suggestion( span, "use fully-qualified syntax", - format!("<{} as {}>::{}", qself_ty, "Trait", assoc_ident), - Applicability::HasPlaceholders, + format!("<{} as {}>::{}", qself_ty, tcx.item_name(trait_did), assoc_ident), + Applicability::MachineApplicable, ).emit(); } diff --git a/src/test/ui/type-alias-enum-variants/enum-variant-priority-lint-ambiguous_associated_items.stderr b/src/test/ui/type-alias-enum-variants/enum-variant-priority-lint-ambiguous_associated_items.stderr index f0dd689934f83..ef025e0e1467f 100644 --- a/src/test/ui/type-alias-enum-variants/enum-variant-priority-lint-ambiguous_associated_items.stderr +++ b/src/test/ui/type-alias-enum-variants/enum-variant-priority-lint-ambiguous_associated_items.stderr @@ -2,7 +2,7 @@ error: ambiguous associated item --> $DIR/enum-variant-priority-lint-ambiguous_associated_items.rs:32:15 | LL | fn f() -> Self::V { 0 } - | ^^^^^^^ help: use fully-qualified syntax: `::V` + | ^^^^^^^ help: use fully-qualified syntax: `::V` | = note: #[deny(ambiguous_associated_items)] on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!