Skip to content

Commit b4c8b0c

Browse files
committed
Auto merge of rust-lang#140298 - matthiaskrgr:rollup-5tc1gvb, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#137683 (Add a tidy check for GCC submodule version) - rust-lang#138968 (Update the index of Result to make the summary more comprehensive) - rust-lang#139572 (docs(std): mention const blocks in const keyword doc page) - rust-lang#140152 (Unify the format of rustc cli flags) - rust-lang#140193 (fix ICE in `#[naked]` attribute validation) - rust-lang#140205 (Tidying up UI tests [2/N]) - rust-lang#140284 (remove expect() in `unnecessary_transmutes`) - rust-lang#140290 (rustdoc: fix typo change from equivelent to equivalent) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e3e432d + 99dc43b commit b4c8b0c

34 files changed

+318
-169
lines changed

compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,8 @@ impl<'tcx> Visitor<'tcx> for UnnecessaryTransmuteChecker<'_, 'tcx> {
8787
&& let Some((func_def_id, _)) = func.const_fn_def()
8888
&& self.tcx.is_intrinsic(func_def_id, sym::transmute)
8989
&& let span = self.body.source_info(location).span
90-
&& let Some(lint) = self.is_unnecessary_transmute(
91-
func,
92-
self.tcx.sess.source_map().span_to_snippet(arg).expect("ok"),
93-
span,
94-
)
90+
&& let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(arg)
91+
&& let Some(lint) = self.is_unnecessary_transmute(func, snippet, span)
9592
&& let Some(hir_id) = terminator.source_info.scope.lint_root(&self.body.source_scopes)
9693
{
9794
self.tcx.emit_node_span_lint(UNNECESSARY_TRANSMUTES, hir_id, span, lint);

compiler/rustc_passes/src/check_attr.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -680,10 +680,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
680680
}
681681

682682
if !other_attr.has_any_name(ALLOW_LIST) {
683+
let path = other_attr.path();
684+
let path: Vec<_> = path.iter().map(|s| s.as_str()).collect();
685+
let other_attr_name = path.join("::");
686+
683687
self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute {
684688
span: other_attr.span(),
685689
naked_span: attr.span(),
686-
attr: other_attr.name().unwrap(),
690+
attr: other_attr_name,
687691
});
688692

689693
return;

compiler/rustc_passes/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ pub(crate) struct NakedFunctionIncompatibleAttribute {
12491249
pub span: Span,
12501250
#[label(passes_naked_attribute)]
12511251
pub naked_span: Span,
1252-
pub attr: Symbol,
1252+
pub attr: String,
12531253
}
12541254

12551255
#[derive(Diagnostic)]

compiler/rustc_session/src/config.rs

+43-36
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ The default is {DEFAULT_EDITION} and the latest stable edition is {LATEST_STABLE
16501650
static PRINT_HELP: LazyLock<String> = LazyLock::new(|| {
16511651
format!(
16521652
"Compiler information to print on stdout (or to a file)\n\
1653-
INFO may be one of ({}).",
1653+
INFO may be one of <{}>.",
16541654
PRINT_KINDS.iter().map(|(name, _)| format!("{name}")).collect::<Vec<_>>().join("|")
16551655
)
16561656
});
@@ -1669,6 +1669,13 @@ static EMIT_HELP: LazyLock<String> = LazyLock::new(|| {
16691669

16701670
/// Returns all rustc command line options, including metadata for
16711671
/// each option, such as whether the option is stable.
1672+
///
1673+
/// # Option style guidelines
1674+
///
1675+
/// - `<param>`: Indicates a required parameter
1676+
/// - `[param]`: Indicates an optional parameter
1677+
/// - `|`: Indicates a mutually exclusive option
1678+
/// - `*`: a list element with description
16721679
pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
16731680
use OptionKind::{Flag, FlagMulti, Multi, Opt};
16741681
use OptionStability::{Stable, Unstable};
@@ -1683,18 +1690,18 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
16831690
"",
16841691
"cfg",
16851692
"Configure the compilation environment.\n\
1686-
SPEC supports the syntax `NAME[=\"VALUE\"]`.",
1687-
"SPEC",
1693+
SPEC supports the syntax `<NAME>[=\"<VALUE>\"]`.",
1694+
"<SPEC>",
16881695
),
1689-
opt(Stable, Multi, "", "check-cfg", "Provide list of expected cfgs for checking", "SPEC"),
1696+
opt(Stable, Multi, "", "check-cfg", "Provide list of expected cfgs for checking", "<SPEC>"),
16901697
opt(
16911698
Stable,
16921699
Multi,
16931700
"L",
16941701
"",
16951702
"Add a directory to the library search path. \
1696-
The optional KIND can be one of dependency, crate, native, framework, or all (the default).",
1697-
"[KIND=]PATH",
1703+
The optional KIND can be one of <dependency|crate|native|framework|all> (default: all).",
1704+
"[<KIND>=]<PATH>",
16981705
),
16991706
opt(
17001707
Stable,
@@ -1703,46 +1710,46 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
17031710
"",
17041711
"Link the generated crate(s) to the specified native\n\
17051712
library NAME. The optional KIND can be one of\n\
1706-
static, framework, or dylib (the default).\n\
1713+
<static|framework|dylib> (default: dylib).\n\
17071714
Optional comma separated MODIFIERS\n\
1708-
(bundle|verbatim|whole-archive|as-needed)\n\
1715+
<bundle|verbatim|whole-archive|as-needed>\n\
17091716
may be specified each with a prefix of either '+' to\n\
17101717
enable or '-' to disable.",
1711-
"[KIND[:MODIFIERS]=]NAME[:RENAME]",
1718+
"[<KIND>[:<MODIFIERS>]=]<NAME>[:<RENAME>]",
17121719
),
17131720
make_crate_type_option(),
1714-
opt(Stable, Opt, "", "crate-name", "Specify the name of the crate being built", "NAME"),
1721+
opt(Stable, Opt, "", "crate-name", "Specify the name of the crate being built", "<NAME>"),
17151722
opt(Stable, Opt, "", "edition", &EDITION_STRING, EDITION_NAME_LIST),
1716-
opt(Stable, Multi, "", "emit", &EMIT_HELP, "TYPE[=FILE]"),
1717-
opt(Stable, Multi, "", "print", &PRINT_HELP, "INFO[=FILE]"),
1723+
opt(Stable, Multi, "", "emit", &EMIT_HELP, "<TYPE>[=<FILE>]"),
1724+
opt(Stable, Multi, "", "print", &PRINT_HELP, "<INFO>[=<FILE>]"),
17181725
opt(Stable, FlagMulti, "g", "", "Equivalent to -C debuginfo=2", ""),
17191726
opt(Stable, FlagMulti, "O", "", "Equivalent to -C opt-level=3", ""),
1720-
opt(Stable, Opt, "o", "", "Write output to <filename>", "FILENAME"),
1721-
opt(Stable, Opt, "", "out-dir", "Write output to compiler-chosen filename in <dir>", "DIR"),
1727+
opt(Stable, Opt, "o", "", "Write output to FILENAME", "<FILENAME>"),
1728+
opt(Stable, Opt, "", "out-dir", "Write output to compiler-chosen filename in DIR", "<DIR>"),
17221729
opt(
17231730
Stable,
17241731
Opt,
17251732
"",
17261733
"explain",
17271734
"Provide a detailed explanation of an error message",
1728-
"OPT",
1735+
"<OPT>",
17291736
),
17301737
opt(Stable, Flag, "", "test", "Build a test harness", ""),
1731-
opt(Stable, Opt, "", "target", "Target triple for which the code is compiled", "TARGET"),
1732-
opt(Stable, Multi, "A", "allow", "Set lint allowed", "LINT"),
1733-
opt(Stable, Multi, "W", "warn", "Set lint warnings", "LINT"),
1734-
opt(Stable, Multi, "", "force-warn", "Set lint force-warn", "LINT"),
1735-
opt(Stable, Multi, "D", "deny", "Set lint denied", "LINT"),
1736-
opt(Stable, Multi, "F", "forbid", "Set lint forbidden", "LINT"),
1738+
opt(Stable, Opt, "", "target", "Target triple for which the code is compiled", "<TARGET>"),
1739+
opt(Stable, Multi, "A", "allow", "Set lint allowed", "<LINT>"),
1740+
opt(Stable, Multi, "W", "warn", "Set lint warnings", "<LINT>"),
1741+
opt(Stable, Multi, "", "force-warn", "Set lint force-warn", "<LINT>"),
1742+
opt(Stable, Multi, "D", "deny", "Set lint denied", "<LINT>"),
1743+
opt(Stable, Multi, "F", "forbid", "Set lint forbidden", "<LINT>"),
17371744
opt(
17381745
Stable,
17391746
Multi,
17401747
"",
17411748
"cap-lints",
17421749
"Set the most restrictive lint level. More restrictive lints are capped at this level",
1743-
"LEVEL",
1750+
"<LEVEL>",
17441751
),
1745-
opt(Stable, Multi, "C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
1752+
opt(Stable, Multi, "C", "codegen", "Set a codegen option", "<OPT>[=<VALUE>]"),
17461753
opt(Stable, Flag, "V", "version", "Print version info and exit", ""),
17471754
opt(Stable, Flag, "v", "verbose", "Use verbose output", ""),
17481755
];
@@ -1756,47 +1763,47 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
17561763
"",
17571764
"extern",
17581765
"Specify where an external rust library is located",
1759-
"NAME[=PATH]",
1766+
"<NAME>[=<PATH>]",
17601767
),
1761-
opt(Stable, Opt, "", "sysroot", "Override the system root", "PATH"),
1762-
opt(Unstable, Multi, "Z", "", "Set unstable / perma-unstable options", "FLAG"),
1768+
opt(Stable, Opt, "", "sysroot", "Override the system root", "<PATH>"),
1769+
opt(Unstable, Multi, "Z", "", "Set unstable / perma-unstable options", "<FLAG>"),
17631770
opt(
17641771
Stable,
17651772
Opt,
17661773
"",
17671774
"error-format",
17681775
"How errors and other messages are produced",
1769-
"human|json|short",
1776+
"<human|json|short>",
17701777
),
1771-
opt(Stable, Multi, "", "json", "Configure the JSON output of the compiler", "CONFIG"),
1778+
opt(Stable, Multi, "", "json", "Configure the JSON output of the compiler", "<CONFIG>"),
17721779
opt(
17731780
Stable,
17741781
Opt,
17751782
"",
17761783
"color",
17771784
"Configure coloring of output:
1778-
auto = colorize, if output goes to a tty (default);
1779-
always = always colorize output;
1780-
never = never colorize output",
1781-
"auto|always|never",
1785+
* auto = colorize, if output goes to a tty (default);
1786+
* always = always colorize output;
1787+
* never = never colorize output",
1788+
"<auto|always|never>",
17821789
),
17831790
opt(
17841791
Stable,
17851792
Opt,
17861793
"",
17871794
"diagnostic-width",
17881795
"Inform rustc of the width of the output so that diagnostics can be truncated to fit",
1789-
"WIDTH",
1796+
"<WIDTH>",
17901797
),
17911798
opt(
17921799
Stable,
17931800
Multi,
17941801
"",
17951802
"remap-path-prefix",
17961803
"Remap source names in all output (compiler messages and output files)",
1797-
"FROM=TO",
1804+
"<FROM>=<TO>",
17981805
),
1799-
opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "VAR=VALUE"),
1806+
opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "<VAR>=<VALUE>"),
18001807
];
18011808
options.extend(verbose_only.into_iter().map(|mut opt| {
18021809
opt.is_verbose_help_only = true;
@@ -2796,7 +2803,7 @@ pub fn make_crate_type_option() -> RustcOptGroup {
27962803
"crate-type",
27972804
"Comma separated list of types of crates
27982805
for the compiler to emit",
2799-
"[bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]",
2806+
"<bin|lib|rlib|dylib|cdylib|staticlib|proc-macro>",
28002807
)
28012808
}
28022809

compiler/rustc_span/src/edition.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub const ALL_EDITIONS: &[Edition] = &[
4545
Edition::EditionFuture,
4646
];
4747

48-
pub const EDITION_NAME_LIST: &str = "2015|2018|2021|2024";
48+
pub const EDITION_NAME_LIST: &str = "<2015|2018|2021|2024|future>";
4949

5050
pub const DEFAULT_EDITION: Edition = Edition::Edition2015;
5151

library/core/src/result.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,14 @@
259259
//! The [`is_ok`] and [`is_err`] methods return [`true`] if the [`Result`]
260260
//! is [`Ok`] or [`Err`], respectively.
261261
//!
262+
//! The [`is_ok_and`] and [`is_err_and`] methods apply the provided function
263+
//! to the contents of the [`Result`] to produce a boolean value. If the [`Result`] does not have the expected variant
264+
//! then [`false`] is returned instead without executing the function.
265+
//!
262266
//! [`is_err`]: Result::is_err
263267
//! [`is_ok`]: Result::is_ok
268+
//! [`is_ok_and`]: Result::is_ok_and
269+
//! [`is_err_and`]: Result::is_err_and
264270
//!
265271
//! ## Adapters for working with references
266272
//!
@@ -287,6 +293,7 @@
287293
//! (which must implement the [`Default`] trait)
288294
//! * [`unwrap_or_else`] returns the result of evaluating the provided
289295
//! function
296+
//! * [`unwrap_unchecked`] produces *[undefined behavior]*
290297
//!
291298
//! The panicking methods [`expect`] and [`unwrap`] require `E` to
292299
//! implement the [`Debug`] trait.
@@ -297,17 +304,22 @@
297304
//! [`unwrap_or`]: Result::unwrap_or
298305
//! [`unwrap_or_default`]: Result::unwrap_or_default
299306
//! [`unwrap_or_else`]: Result::unwrap_or_else
307+
//! [`unwrap_unchecked`]: Result::unwrap_unchecked
308+
//! [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
300309
//!
301310
//! These methods extract the contained value in a [`Result<T, E>`] when it
302311
//! is the [`Err`] variant. They require `T` to implement the [`Debug`]
303312
//! trait. If the [`Result`] is [`Ok`]:
304313
//!
305314
//! * [`expect_err`] panics with a provided custom message
306315
//! * [`unwrap_err`] panics with a generic message
316+
//! * [`unwrap_err_unchecked`] produces *[undefined behavior]*
307317
//!
308318
//! [`Debug`]: crate::fmt::Debug
309319
//! [`expect_err`]: Result::expect_err
310320
//! [`unwrap_err`]: Result::unwrap_err
321+
//! [`unwrap_err_unchecked`]: Result::unwrap_err_unchecked
322+
//! [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
311323
//!
312324
//! ## Transforming contained values
313325
//!
@@ -330,21 +342,29 @@
330342
//! [`Some(v)`]: Option::Some
331343
//! [`transpose`]: Result::transpose
332344
//!
333-
//! This method transforms the contained value of the [`Ok`] variant:
345+
//! These methods transform the contained value of the [`Ok`] variant:
334346
//!
335347
//! * [`map`] transforms [`Result<T, E>`] into [`Result<U, E>`] by applying
336348
//! the provided function to the contained value of [`Ok`] and leaving
337349
//! [`Err`] values unchanged
350+
//! * [`inspect`] takes ownership of the [`Result`], applies the
351+
//! provided function to the contained value by reference,
352+
//! and then returns the [`Result`]
338353
//!
339354
//! [`map`]: Result::map
355+
//! [`inspect`]: Result::inspect
340356
//!
341-
//! This method transforms the contained value of the [`Err`] variant:
357+
//! These methods transform the contained value of the [`Err`] variant:
342358
//!
343359
//! * [`map_err`] transforms [`Result<T, E>`] into [`Result<T, F>`] by
344360
//! applying the provided function to the contained value of [`Err`] and
345361
//! leaving [`Ok`] values unchanged
362+
//! * [`inspect_err`] takes ownership of the [`Result`], applies the
363+
//! provided function to the contained value of [`Err`] by reference,
364+
//! and then returns the [`Result`]
346365
//!
347366
//! [`map_err`]: Result::map_err
367+
//! [`inspect_err`]: Result::inspect_err
348368
//!
349369
//! These methods transform a [`Result<T, E>`] into a value of a possibly
350370
//! different type `U`:
@@ -578,6 +598,10 @@ impl<T, E> Result<T, E> {
578598
///
579599
/// let x: Result<u32, &str> = Err("hey");
580600
/// assert_eq!(x.is_ok_and(|x| x > 1), false);
601+
///
602+
/// let x: Result<String, &str> = Ok("ownership".to_string());
603+
/// assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true);
604+
/// println!("still alive {:?}", x);
581605
/// ```
582606
#[must_use]
583607
#[inline]
@@ -623,6 +647,10 @@ impl<T, E> Result<T, E> {
623647
///
624648
/// let x: Result<u32, Error> = Ok(123);
625649
/// assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false);
650+
///
651+
/// let x: Result<u32, String> = Err("ownership".to_string());
652+
/// assert_eq!(x.as_ref().is_err_and(|x| x.len() > 1), true);
653+
/// println!("still alive {:?}", x);
626654
/// ```
627655
#[must_use]
628656
#[inline]

library/std/src/keyword_docs.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ mod break_keyword {}
119119

120120
#[doc(keyword = "const")]
121121
//
122-
/// Compile-time constants, compile-time evaluable functions, and raw pointers.
122+
/// Compile-time constants, compile-time blocks, compile-time evaluable functions, and raw pointers.
123123
///
124124
/// ## Compile-time constants
125125
///
@@ -166,6 +166,12 @@ mod break_keyword {}
166166
///
167167
/// For more detail on `const`, see the [Rust Book] or the [Reference].
168168
///
169+
/// ## Compile-time blocks
170+
///
171+
/// The `const` keyword can also be used to define a block of code that is evaluated at compile time.
172+
/// This is useful for ensuring certain computations are completed before optimizations happen, as well as
173+
/// before runtime. For more details, see the [Reference][const-blocks].
174+
///
169175
/// ## Compile-time evaluable functions
170176
///
171177
/// The other main use of the `const` keyword is in `const fn`. This marks a function as being
@@ -184,6 +190,7 @@ mod break_keyword {}
184190
/// [pointer primitive]: pointer
185191
/// [Rust Book]: ../book/ch03-01-variables-and-mutability.html#constants
186192
/// [Reference]: ../reference/items/constant-items.html
193+
/// [const-blocks]: ../reference/expressions/block-expr.html#const-blocks
187194
/// [const-eval]: ../reference/const_eval.html
188195
mod const_keyword {}
189196

src/doc/rustdoc/src/read-documentation/search.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ the standard library and functions that are included in the results list:
8989

9090
### Non-functions in type-based search
9191
Certain items that are not functions are treated as though they
92-
were a semantically equivelent function.
92+
were a semantically equivalent function.
9393

9494
For example, struct fields are treated as though they were getter methods.
9595
This means that a search for `CpuidResult -> u32` will show

src/gcc

Submodule gcc updated 29018 files

0 commit comments

Comments
 (0)