diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 242074fec7795..a9225f2870f55 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,19 @@ 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"); + // 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"); + } + } + 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 +179,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 +191,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 +205,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 +314,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 +326,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 +348,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 +357,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 +376,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; diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 33ffd84e521f2..58ea0207c5609 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 diff --git a/src/libcore/option.rs b/src/libcore/option.rs index b27fd4098e167..a6bdd5a906306 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 { @@ -986,17 +990,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 /// 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!