Skip to content

Commit 927a3e8

Browse files
committed
Auto merge of #62458 - Centril:rollup-j6o2sqj, r=Centril
Rollup of 4 pull requests Successful merges: - #61990 (First question mark in doctest) - #62379 (Add missing links in Option documentation) - #62438 (rustbuild: Cleanup global lint settings) - #62455 (name the trait in ambiguous-associated-items fully qualified suggestion) Failed merges: r? @ghost
2 parents 4393768 + fb01170 commit 927a3e8

File tree

5 files changed

+63
-54
lines changed

5 files changed

+63
-54
lines changed

src/bootstrap/bin/rustc.rs

+31-37
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,16 @@ fn main() {
9191
cmd.args(&args)
9292
.env(bootstrap::util::dylib_path_var(),
9393
env::join_paths(&dylib_path).unwrap());
94-
let mut maybe_crate = None;
9594

9695
// Get the name of the crate we're compiling, if any.
97-
let maybe_crate_name = args.windows(2)
98-
.find(|a| &*a[0] == "--crate-name")
99-
.map(|crate_name| &*crate_name[1]);
96+
let crate_name = args.windows(2)
97+
.find(|args| args[0] == "--crate-name")
98+
.and_then(|args| args[1].to_str());
10099

101-
if let Some(current_crate) = maybe_crate_name {
100+
if let Some(crate_name) = crate_name {
102101
if let Some(target) = env::var_os("RUSTC_TIME") {
103102
if target == "all" ||
104-
target.into_string().unwrap().split(",").any(|c| c.trim() == current_crate)
103+
target.into_string().unwrap().split(",").any(|c| c.trim() == crate_name)
105104
{
106105
cmd.arg("-Ztime");
107106
}
@@ -125,6 +124,19 @@ fn main() {
125124
cmd.arg(format!("-Cdebuginfo={}", debuginfo_level));
126125
}
127126

127+
if env::var_os("RUSTC_DENY_WARNINGS").is_some() &&
128+
env::var_os("RUSTC_EXTERNAL_TOOL").is_none() {
129+
cmd.arg("-Dwarnings");
130+
cmd.arg("-Drust_2018_idioms");
131+
// cfg(not(bootstrap)): Remove this during the next stage 0 compiler update.
132+
// `-Drustc::internal` is a new feature and `rustc_version` mis-reports the `stage`.
133+
let cfg_not_bootstrap = stage != "0" && crate_name != Some("rustc_version");
134+
if cfg_not_bootstrap && use_internal_lints(crate_name) {
135+
cmd.arg("-Zunstable-options");
136+
cmd.arg("-Drustc::internal");
137+
}
138+
}
139+
128140
if let Some(target) = target {
129141
// The stage0 compiler has a special sysroot distinct from what we
130142
// actually downloaded, so we just always pass the `--sysroot` option.
@@ -167,9 +179,6 @@ fn main() {
167179
cmd.arg(format!("-Clinker={}", target_linker));
168180
}
169181

170-
let crate_name = maybe_crate_name.unwrap();
171-
maybe_crate = Some(crate_name);
172-
173182
// If we're compiling specifically the `panic_abort` crate then we pass
174183
// the `-C panic=abort` option. Note that we do not do this for any
175184
// other crate intentionally as this is the only crate for now that we
@@ -182,8 +191,8 @@ fn main() {
182191
// `compiler_builtins` are unconditionally compiled with panic=abort to
183192
// workaround undefined references to `rust_eh_unwind_resume` generated
184193
// otherwise, see issue https://github.com/rust-lang/rust/issues/43095.
185-
if crate_name == "panic_abort" ||
186-
crate_name == "compiler_builtins" && stage != "0" {
194+
if crate_name == Some("panic_abort") ||
195+
crate_name == Some("compiler_builtins") && stage != "0" {
187196
cmd.arg("-C").arg("panic=abort");
188197
}
189198

@@ -196,7 +205,7 @@ fn main() {
196205

197206
// The compiler builtins are pretty sensitive to symbols referenced in
198207
// libcore and such, so we never compile them with debug assertions.
199-
if crate_name == "compiler_builtins" {
208+
if crate_name == Some("compiler_builtins") {
200209
cmd.arg("-C").arg("debug-assertions=no");
201210
} else {
202211
cmd.arg("-C").arg(format!("debug-assertions={}", debug_assertions));
@@ -305,22 +314,6 @@ fn main() {
305314
}
306315
}
307316

308-
// This is required for internal lints.
309-
if let Some(crate_name) = args.windows(2).find(|a| &*a[0] == "--crate-name") {
310-
let crate_name = crate_name[1].to_string_lossy();
311-
if crate_name != "rustc_version"
312-
&& (crate_name.starts_with("rustc")
313-
|| crate_name.starts_with("syntax")
314-
|| crate_name == "arena"
315-
|| crate_name == "fmt_macros")
316-
{
317-
cmd.arg("-Zunstable-options");
318-
if stage != "0" {
319-
cmd.arg("-Wrustc::internal");
320-
}
321-
}
322-
}
323-
324317
// Force all crates compiled by this compiler to (a) be unstable and (b)
325318
// allow the `rustc_private` feature to link to other unstable crates
326319
// also in the sysroot. We also do this for host crates, since those
@@ -333,13 +326,6 @@ fn main() {
333326
cmd.arg("--cfg").arg("parallel_compiler");
334327
}
335328

336-
if env::var_os("RUSTC_DENY_WARNINGS").is_some() && env::var_os("RUSTC_EXTERNAL_TOOL").is_none()
337-
{
338-
cmd.arg("-Dwarnings");
339-
cmd.arg("-Dbare_trait_objects");
340-
cmd.arg("-Drust_2018_idioms");
341-
}
342-
343329
if verbose > 1 {
344330
eprintln!(
345331
"rustc command: {:?}={:?} {:?}",
@@ -362,7 +348,7 @@ fn main() {
362348
}
363349

364350
if env::var_os("RUSTC_PRINT_STEP_TIMINGS").is_some() {
365-
if let Some(krate) = maybe_crate {
351+
if let Some(crate_name) = crate_name {
366352
let start = Instant::now();
367353
let status = cmd
368354
.status()
@@ -371,7 +357,7 @@ fn main() {
371357

372358
let is_test = args.iter().any(|a| a == "--test");
373359
eprintln!("[RUSTC-TIMING] {} test:{} {}.{:03}",
374-
krate.to_string_lossy(),
360+
crate_name,
375361
is_test,
376362
dur.as_secs(),
377363
dur.subsec_nanos() / 1_000_000);
@@ -390,6 +376,14 @@ fn main() {
390376
std::process::exit(code);
391377
}
392378

379+
// Rustc crates for which internal lints are in effect.
380+
fn use_internal_lints(crate_name: Option<&str>) -> bool {
381+
crate_name.map_or(false, |crate_name| {
382+
crate_name.starts_with("rustc") || crate_name.starts_with("syntax") ||
383+
["arena", "fmt_macros"].contains(&crate_name)
384+
})
385+
}
386+
393387
#[cfg(unix)]
394388
fn exec_cmd(cmd: &mut Command) -> io::Result<i32> {
395389
use std::os::unix::process::CommandExt;

src/libcore/macros.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,14 @@ macro_rules! r#try {
335335
/// ```
336336
/// use std::io::Write;
337337
///
338-
/// let mut w = Vec::new();
339-
/// write!(&mut w, "test").unwrap();
340-
/// write!(&mut w, "formatted {}", "arguments").unwrap();
338+
/// fn main() -> std::io::Result<()> {
339+
/// let mut w = Vec::new();
340+
/// write!(&mut w, "test")?;
341+
/// write!(&mut w, "formatted {}", "arguments")?;
341342
///
342-
/// assert_eq!(w, b"testformatted arguments");
343+
/// assert_eq!(w, b"testformatted arguments");
344+
/// Ok(())
345+
/// }
343346
/// ```
344347
///
345348
/// A module can import both `std::fmt::Write` and `std::io::Write` and call `write!` on objects

src/libcore/option.rs

+22-10
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl<T> Option<T> {
263263
}
264264

265265

266-
/// Converts from `Pin<&Option<T>>` to `Option<Pin<&T>>`
266+
/// Converts from [`Pin`]`<&Option<T>>` to `Option<`[`Pin`]`<&T>>`.
267267
#[inline]
268268
#[stable(feature = "pin", since = "1.33.0")]
269269
pub fn as_pin_ref<'a>(self: Pin<&'a Option<T>>) -> Option<Pin<&'a T>> {
@@ -272,7 +272,7 @@ impl<T> Option<T> {
272272
}
273273
}
274274

275-
/// Converts from `Pin<&mut Option<T>>` to `Option<Pin<&mut T>>`
275+
/// Converts from [`Pin`]`<&mut Option<T>>` to `Option<`[`Pin`]`<&mut T>>`.
276276
#[inline]
277277
#[stable(feature = "pin", since = "1.33.0")]
278278
pub fn as_pin_mut<'a>(self: Pin<&'a mut Option<T>>) -> Option<Pin<&'a mut T>> {
@@ -626,14 +626,14 @@ impl<T> Option<T> {
626626
}
627627
}
628628

629-
/// Returns `None` if the option is `None`, otherwise calls `predicate`
629+
/// Returns [`None`] if the option is [`None`], otherwise calls `predicate`
630630
/// with the wrapped value and returns:
631631
///
632-
/// - `Some(t)` if `predicate` returns `true` (where `t` is the wrapped
632+
/// - [`Some(t)`] if `predicate` returns `true` (where `t` is the wrapped
633633
/// value), and
634-
/// - `None` if `predicate` returns `false`.
634+
/// - [`None`] if `predicate` returns `false`.
635635
///
636-
/// This function works similar to `Iterator::filter()`. You can imagine
636+
/// This function works similar to [`Iterator::filter()`]. You can imagine
637637
/// the `Option<T>` being an iterator over one or zero elements. `filter()`
638638
/// lets you decide which elements to keep.
639639
///
@@ -648,6 +648,10 @@ impl<T> Option<T> {
648648
/// assert_eq!(Some(3).filter(is_even), None);
649649
/// assert_eq!(Some(4).filter(is_even), Some(4));
650650
/// ```
651+
///
652+
/// [`None`]: #variant.None
653+
/// [`Some(t)`]: #variant.Some
654+
/// [`Iterator::filter()`]: ../../std/iter/trait.Iterator.html#method.filter
651655
#[inline]
652656
#[stable(feature = "option_filter", since = "1.27.0")]
653657
pub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Self {
@@ -986,17 +990,25 @@ impl<T: Deref> Option<T> {
986990
/// Converts from `&Option<T>` to `Option<&T::Target>`.
987991
///
988992
/// Leaves the original Option in-place, creating a new one with a reference
989-
/// to the original one, additionally coercing the contents via `Deref`.
993+
/// to the original one, additionally coercing the contents via [`Deref`].
994+
///
995+
/// [`Deref`]: ../../std/ops/trait.Deref.html
990996
pub fn deref(&self) -> Option<&T::Target> {
991997
self.as_ref().map(|t| t.deref())
992998
}
993999
}
9941000

9951001
impl<T, E> Option<Result<T, E>> {
996-
/// Transposes an `Option` of a `Result` into a `Result` of an `Option`.
1002+
/// Transposes an `Option` of a [`Result`] into a [`Result`] of an `Option`.
9971003
///
998-
/// `None` will be mapped to `Ok(None)`.
999-
/// `Some(Ok(_))` and `Some(Err(_))` will be mapped to `Ok(Some(_))` and `Err(_)`.
1004+
/// [`None`] will be mapped to [`Ok`]`(`[`None`]`)`.
1005+
/// [`Some`]`(`[`Ok`]`(_))` and [`Some`]`(`[`Err`]`(_))` will be mapped to
1006+
/// [`Ok`]`(`[`Some`]`(_))` and [`Err`]`(_)`.
1007+
///
1008+
/// [`None`]: #variant.None
1009+
/// [`Ok`]: ../../std/result/enum.Result.html#variant.Ok
1010+
/// [`Some`]: #variant.Some
1011+
/// [`Err`]: ../../std/result/enum.Result.html#variant.Err
10001012
///
10011013
/// # Examples
10021014
///

src/librustc_typeck/astconv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1709,8 +1709,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
17091709
err.span_suggestion(
17101710
span,
17111711
"use fully-qualified syntax",
1712-
format!("<{} as {}>::{}", qself_ty, "Trait", assoc_ident),
1713-
Applicability::HasPlaceholders,
1712+
format!("<{} as {}>::{}", qself_ty, tcx.item_name(trait_did), assoc_ident),
1713+
Applicability::MachineApplicable,
17141714
).emit();
17151715
}
17161716

src/test/ui/type-alias-enum-variants/enum-variant-priority-lint-ambiguous_associated_items.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: ambiguous associated item
22
--> $DIR/enum-variant-priority-lint-ambiguous_associated_items.rs:32:15
33
|
44
LL | fn f() -> Self::V { 0 }
5-
| ^^^^^^^ help: use fully-qualified syntax: `<E as Trait>::V`
5+
| ^^^^^^^ help: use fully-qualified syntax: `<E as Tr>::V`
66
|
77
= note: #[deny(ambiguous_associated_items)] on by default
88
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!

0 commit comments

Comments
 (0)