diff --git a/compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs b/compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs index 8be782dcbf0ad..4aff127908eec 100644 --- a/compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs +++ b/compiler/rustc_mir_transform/src/check_unnecessary_transmutes.rs @@ -87,11 +87,8 @@ impl<'tcx> Visitor<'tcx> for UnnecessaryTransmuteChecker<'_, 'tcx> { && let Some((func_def_id, _)) = func.const_fn_def() && self.tcx.is_intrinsic(func_def_id, sym::transmute) && let span = self.body.source_info(location).span - && let Some(lint) = self.is_unnecessary_transmute( - func, - self.tcx.sess.source_map().span_to_snippet(arg).expect("ok"), - span, - ) + && let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(arg) + && let Some(lint) = self.is_unnecessary_transmute(func, snippet, span) && let Some(hir_id) = terminator.source_info.scope.lint_root(&self.body.source_scopes) { self.tcx.emit_node_span_lint(UNNECESSARY_TRANSMUTES, hir_id, span, lint); diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index cfc71a412bea2..7a27bc5c38738 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -680,10 +680,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } if !other_attr.has_any_name(ALLOW_LIST) { + let path = other_attr.path(); + let path: Vec<_> = path.iter().map(|s| s.as_str()).collect(); + let other_attr_name = path.join("::"); + self.dcx().emit_err(errors::NakedFunctionIncompatibleAttribute { span: other_attr.span(), naked_span: attr.span(), - attr: other_attr.name().unwrap(), + attr: other_attr_name, }); return; diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 4052264b05174..b1b4b9ee92765 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -1249,7 +1249,7 @@ pub(crate) struct NakedFunctionIncompatibleAttribute { pub span: Span, #[label(passes_naked_attribute)] pub naked_span: Span, - pub attr: Symbol, + pub attr: String, } #[derive(Diagnostic)] diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 02c164a706cd8..43955cc23a9e9 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -1650,7 +1650,7 @@ The default is {DEFAULT_EDITION} and the latest stable edition is {LATEST_STABLE static PRINT_HELP: LazyLock = LazyLock::new(|| { format!( "Compiler information to print on stdout (or to a file)\n\ - INFO may be one of ({}).", + INFO may be one of <{}>.", PRINT_KINDS.iter().map(|(name, _)| format!("{name}")).collect::>().join("|") ) }); @@ -1669,6 +1669,13 @@ static EMIT_HELP: LazyLock = LazyLock::new(|| { /// Returns all rustc command line options, including metadata for /// each option, such as whether the option is stable. +/// +/// # Option style guidelines +/// +/// - ``: Indicates a required parameter +/// - `[param]`: Indicates an optional parameter +/// - `|`: Indicates a mutually exclusive option +/// - `*`: a list element with description pub fn rustc_optgroups() -> Vec { use OptionKind::{Flag, FlagMulti, Multi, Opt}; use OptionStability::{Stable, Unstable}; @@ -1683,18 +1690,18 @@ pub fn rustc_optgroups() -> Vec { "", "cfg", "Configure the compilation environment.\n\ - SPEC supports the syntax `NAME[=\"VALUE\"]`.", - "SPEC", + SPEC supports the syntax `[=\"\"]`.", + "", ), - opt(Stable, Multi, "", "check-cfg", "Provide list of expected cfgs for checking", "SPEC"), + opt(Stable, Multi, "", "check-cfg", "Provide list of expected cfgs for checking", ""), opt( Stable, Multi, "L", "", "Add a directory to the library search path. \ - The optional KIND can be one of dependency, crate, native, framework, or all (the default).", - "[KIND=]PATH", + The optional KIND can be one of (default: all).", + "[=]", ), opt( Stable, @@ -1703,46 +1710,46 @@ pub fn rustc_optgroups() -> Vec { "", "Link the generated crate(s) to the specified native\n\ library NAME. The optional KIND can be one of\n\ - static, framework, or dylib (the default).\n\ + (default: dylib).\n\ Optional comma separated MODIFIERS\n\ - (bundle|verbatim|whole-archive|as-needed)\n\ + \n\ may be specified each with a prefix of either '+' to\n\ enable or '-' to disable.", - "[KIND[:MODIFIERS]=]NAME[:RENAME]", + "[[:]=][:]", ), make_crate_type_option(), - opt(Stable, Opt, "", "crate-name", "Specify the name of the crate being built", "NAME"), + opt(Stable, Opt, "", "crate-name", "Specify the name of the crate being built", ""), opt(Stable, Opt, "", "edition", &EDITION_STRING, EDITION_NAME_LIST), - opt(Stable, Multi, "", "emit", &EMIT_HELP, "TYPE[=FILE]"), - opt(Stable, Multi, "", "print", &PRINT_HELP, "INFO[=FILE]"), + opt(Stable, Multi, "", "emit", &EMIT_HELP, "[=]"), + opt(Stable, Multi, "", "print", &PRINT_HELP, "[=]"), opt(Stable, FlagMulti, "g", "", "Equivalent to -C debuginfo=2", ""), opt(Stable, FlagMulti, "O", "", "Equivalent to -C opt-level=3", ""), - opt(Stable, Opt, "o", "", "Write output to ", "FILENAME"), - opt(Stable, Opt, "", "out-dir", "Write output to compiler-chosen filename in ", "DIR"), + opt(Stable, Opt, "o", "", "Write output to FILENAME", ""), + opt(Stable, Opt, "", "out-dir", "Write output to compiler-chosen filename in DIR", ""), opt( Stable, Opt, "", "explain", "Provide a detailed explanation of an error message", - "OPT", + "", ), opt(Stable, Flag, "", "test", "Build a test harness", ""), - opt(Stable, Opt, "", "target", "Target triple for which the code is compiled", "TARGET"), - opt(Stable, Multi, "A", "allow", "Set lint allowed", "LINT"), - opt(Stable, Multi, "W", "warn", "Set lint warnings", "LINT"), - opt(Stable, Multi, "", "force-warn", "Set lint force-warn", "LINT"), - opt(Stable, Multi, "D", "deny", "Set lint denied", "LINT"), - opt(Stable, Multi, "F", "forbid", "Set lint forbidden", "LINT"), + opt(Stable, Opt, "", "target", "Target triple for which the code is compiled", ""), + opt(Stable, Multi, "A", "allow", "Set lint allowed", ""), + opt(Stable, Multi, "W", "warn", "Set lint warnings", ""), + opt(Stable, Multi, "", "force-warn", "Set lint force-warn", ""), + opt(Stable, Multi, "D", "deny", "Set lint denied", ""), + opt(Stable, Multi, "F", "forbid", "Set lint forbidden", ""), opt( Stable, Multi, "", "cap-lints", "Set the most restrictive lint level. More restrictive lints are capped at this level", - "LEVEL", + "", ), - opt(Stable, Multi, "C", "codegen", "Set a codegen option", "OPT[=VALUE]"), + opt(Stable, Multi, "C", "codegen", "Set a codegen option", "[=]"), opt(Stable, Flag, "V", "version", "Print version info and exit", ""), opt(Stable, Flag, "v", "verbose", "Use verbose output", ""), ]; @@ -1756,29 +1763,29 @@ pub fn rustc_optgroups() -> Vec { "", "extern", "Specify where an external rust library is located", - "NAME[=PATH]", + "[=]", ), - opt(Stable, Opt, "", "sysroot", "Override the system root", "PATH"), - opt(Unstable, Multi, "Z", "", "Set unstable / perma-unstable options", "FLAG"), + opt(Stable, Opt, "", "sysroot", "Override the system root", ""), + opt(Unstable, Multi, "Z", "", "Set unstable / perma-unstable options", ""), opt( Stable, Opt, "", "error-format", "How errors and other messages are produced", - "human|json|short", + "", ), - opt(Stable, Multi, "", "json", "Configure the JSON output of the compiler", "CONFIG"), + opt(Stable, Multi, "", "json", "Configure the JSON output of the compiler", ""), opt( Stable, Opt, "", "color", "Configure coloring of output: - auto = colorize, if output goes to a tty (default); - always = always colorize output; - never = never colorize output", - "auto|always|never", + * auto = colorize, if output goes to a tty (default); + * always = always colorize output; + * never = never colorize output", + "", ), opt( Stable, @@ -1786,7 +1793,7 @@ pub fn rustc_optgroups() -> Vec { "", "diagnostic-width", "Inform rustc of the width of the output so that diagnostics can be truncated to fit", - "WIDTH", + "", ), opt( Stable, @@ -1794,9 +1801,9 @@ pub fn rustc_optgroups() -> Vec { "", "remap-path-prefix", "Remap source names in all output (compiler messages and output files)", - "FROM=TO", + "=", ), - opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "VAR=VALUE"), + opt(Unstable, Multi, "", "env-set", "Inject an environment variable", "="), ]; options.extend(verbose_only.into_iter().map(|mut opt| { opt.is_verbose_help_only = true; @@ -2796,7 +2803,7 @@ pub fn make_crate_type_option() -> RustcOptGroup { "crate-type", "Comma separated list of types of crates for the compiler to emit", - "[bin|lib|rlib|dylib|cdylib|staticlib|proc-macro]", + "", ) } diff --git a/compiler/rustc_span/src/edition.rs b/compiler/rustc_span/src/edition.rs index da298080ed2f6..28335734f4dec 100644 --- a/compiler/rustc_span/src/edition.rs +++ b/compiler/rustc_span/src/edition.rs @@ -45,7 +45,7 @@ pub const ALL_EDITIONS: &[Edition] = &[ Edition::EditionFuture, ]; -pub const EDITION_NAME_LIST: &str = "2015|2018|2021|2024"; +pub const EDITION_NAME_LIST: &str = "<2015|2018|2021|2024|future>"; pub const DEFAULT_EDITION: Edition = Edition::Edition2015; diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 48ab9267f216c..736ffb7d0caf3 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -259,8 +259,14 @@ //! The [`is_ok`] and [`is_err`] methods return [`true`] if the [`Result`] //! is [`Ok`] or [`Err`], respectively. //! +//! The [`is_ok_and`] and [`is_err_and`] methods apply the provided function +//! to the contents of the [`Result`] to produce a boolean value. If the [`Result`] does not have the expected variant +//! then [`false`] is returned instead without executing the function. +//! //! [`is_err`]: Result::is_err //! [`is_ok`]: Result::is_ok +//! [`is_ok_and`]: Result::is_ok_and +//! [`is_err_and`]: Result::is_err_and //! //! ## Adapters for working with references //! @@ -287,6 +293,7 @@ //! (which must implement the [`Default`] trait) //! * [`unwrap_or_else`] returns the result of evaluating the provided //! function +//! * [`unwrap_unchecked`] produces *[undefined behavior]* //! //! The panicking methods [`expect`] and [`unwrap`] require `E` to //! implement the [`Debug`] trait. @@ -297,6 +304,8 @@ //! [`unwrap_or`]: Result::unwrap_or //! [`unwrap_or_default`]: Result::unwrap_or_default //! [`unwrap_or_else`]: Result::unwrap_or_else +//! [`unwrap_unchecked`]: Result::unwrap_unchecked +//! [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html //! //! These methods extract the contained value in a [`Result`] when it //! is the [`Err`] variant. They require `T` to implement the [`Debug`] @@ -304,10 +313,13 @@ //! //! * [`expect_err`] panics with a provided custom message //! * [`unwrap_err`] panics with a generic message +//! * [`unwrap_err_unchecked`] produces *[undefined behavior]* //! //! [`Debug`]: crate::fmt::Debug //! [`expect_err`]: Result::expect_err //! [`unwrap_err`]: Result::unwrap_err +//! [`unwrap_err_unchecked`]: Result::unwrap_err_unchecked +//! [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html //! //! ## Transforming contained values //! @@ -330,21 +342,29 @@ //! [`Some(v)`]: Option::Some //! [`transpose`]: Result::transpose //! -//! This method transforms the contained value of the [`Ok`] variant: +//! These methods transform the contained value of the [`Ok`] variant: //! //! * [`map`] transforms [`Result`] into [`Result`] by applying //! the provided function to the contained value of [`Ok`] and leaving //! [`Err`] values unchanged +//! * [`inspect`] takes ownership of the [`Result`], applies the +//! provided function to the contained value by reference, +//! and then returns the [`Result`] //! //! [`map`]: Result::map +//! [`inspect`]: Result::inspect //! -//! This method transforms the contained value of the [`Err`] variant: +//! These methods transform the contained value of the [`Err`] variant: //! //! * [`map_err`] transforms [`Result`] into [`Result`] by //! applying the provided function to the contained value of [`Err`] and //! leaving [`Ok`] values unchanged +//! * [`inspect_err`] takes ownership of the [`Result`], applies the +//! provided function to the contained value of [`Err`] by reference, +//! and then returns the [`Result`] //! //! [`map_err`]: Result::map_err +//! [`inspect_err`]: Result::inspect_err //! //! These methods transform a [`Result`] into a value of a possibly //! different type `U`: @@ -578,6 +598,10 @@ impl Result { /// /// let x: Result = Err("hey"); /// assert_eq!(x.is_ok_and(|x| x > 1), false); + /// + /// let x: Result = Ok("ownership".to_string()); + /// assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); + /// println!("still alive {:?}", x); /// ``` #[must_use] #[inline] @@ -623,6 +647,10 @@ impl Result { /// /// let x: Result = Ok(123); /// assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false); + /// + /// let x: Result = Err("ownership".to_string()); + /// assert_eq!(x.as_ref().is_err_and(|x| x.len() > 1), true); + /// println!("still alive {:?}", x); /// ``` #[must_use] #[inline] diff --git a/library/std/src/keyword_docs.rs b/library/std/src/keyword_docs.rs index c07c391892d80..91701576130e6 100644 --- a/library/std/src/keyword_docs.rs +++ b/library/std/src/keyword_docs.rs @@ -119,7 +119,7 @@ mod break_keyword {} #[doc(keyword = "const")] // -/// Compile-time constants, compile-time evaluable functions, and raw pointers. +/// Compile-time constants, compile-time blocks, compile-time evaluable functions, and raw pointers. /// /// ## Compile-time constants /// @@ -166,6 +166,12 @@ mod break_keyword {} /// /// For more detail on `const`, see the [Rust Book] or the [Reference]. /// +/// ## Compile-time blocks +/// +/// The `const` keyword can also be used to define a block of code that is evaluated at compile time. +/// This is useful for ensuring certain computations are completed before optimizations happen, as well as +/// before runtime. For more details, see the [Reference][const-blocks]. +/// /// ## Compile-time evaluable functions /// /// 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 {} /// [pointer primitive]: pointer /// [Rust Book]: ../book/ch03-01-variables-and-mutability.html#constants /// [Reference]: ../reference/items/constant-items.html +/// [const-blocks]: ../reference/expressions/block-expr.html#const-blocks /// [const-eval]: ../reference/const_eval.html mod const_keyword {} diff --git a/src/doc/rustdoc/src/read-documentation/search.md b/src/doc/rustdoc/src/read-documentation/search.md index bace2f5f95390..5635f68b1b398 100644 --- a/src/doc/rustdoc/src/read-documentation/search.md +++ b/src/doc/rustdoc/src/read-documentation/search.md @@ -89,7 +89,7 @@ the standard library and functions that are included in the results list: ### Non-functions in type-based search Certain items that are not functions are treated as though they -were a semantically equivelent function. +were a semantically equivalent function. For example, struct fields are treated as though they were getter methods. This means that a search for `CpuidResult -> u32` will show diff --git a/src/gcc b/src/gcc index 13cc8243226a9..0ea98a1365b81 160000 --- a/src/gcc +++ b/src/gcc @@ -1 +1 @@ -Subproject commit 13cc8243226a9028bb08ab6c5e1c5fe6d533bcdf +Subproject commit 0ea98a1365b81f7488073512c850e8ee951a4afd diff --git a/src/tools/tidy/src/gcc_submodule.rs b/src/tools/tidy/src/gcc_submodule.rs new file mode 100644 index 0000000000000..952ebe9e0cffe --- /dev/null +++ b/src/tools/tidy/src/gcc_submodule.rs @@ -0,0 +1,47 @@ +//! Tidy check to ensure that the commit SHA of the `src/gcc` submodule is the same as the +//! required GCC version of the GCC codegen backend. + +use std::path::Path; +use std::process::Command; + +pub fn check(root_path: &Path, compiler_path: &Path, bad: &mut bool) { + let cg_gcc_version_path = compiler_path.join("rustc_codegen_gcc/libgccjit.version"); + let cg_gcc_version = std::fs::read_to_string(&cg_gcc_version_path) + .expect(&format!("Cannot read GCC version from {}", cg_gcc_version_path.display())) + .trim() + .to_string(); + + let git_output = Command::new("git") + .current_dir(root_path) + .arg("submodule") + .arg("status") + // --cached asks for the version that is actually committed in the repository, not the one + // that is currently checked out. + .arg("--cached") + .arg("src/gcc") + .output() + .expect("Cannot determine git SHA of the src/gcc checkout"); + + // This can return e.g. + // -e607be166673a8de9fc07f6f02c60426e556c5f2 src/gcc + // e607be166673a8de9fc07f6f02c60426e556c5f2 src/gcc (master-e607be166673a8de9fc07f6f02c60426e556c5f2.e607be) + // +e607be166673a8de9fc07f6f02c60426e556c5f2 src/gcc (master-e607be166673a8de9fc07f6f02c60426e556c5f2.e607be) + let git_output = String::from_utf8_lossy(&git_output.stdout) + .trim() + .split_whitespace() + .next() + .unwrap_or_default() + .to_string(); + + // The SHA can start with + if the submodule is modified or - if it is not checked out. + let gcc_submodule_sha = git_output.trim_start_matches(&['+', '-']); + if gcc_submodule_sha != cg_gcc_version { + *bad = true; + eprintln!( + r#"Commit SHA of the src/gcc submodule (`{gcc_submodule_sha}`) does not match the required GCC version of the GCC codegen backend (`{cg_gcc_version}`). +Make sure to set the src/gcc submodule to commit {cg_gcc_version}. +The GCC codegen backend commit is configured at {}."#, + cg_gcc_version_path.display(), + ); + } +} diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs index 66856f5247bfd..ca45f8bb84ba9 100644 --- a/src/tools/tidy/src/lib.rs +++ b/src/tools/tidy/src/lib.rs @@ -75,6 +75,7 @@ pub mod features; pub mod fluent_alphabetical; pub mod fluent_period; mod fluent_used; +pub mod gcc_submodule; pub(crate) mod iter_header; pub mod known_bug; pub mod mir_opt_tests; diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs index 4078d462f5584..48122129b0174 100644 --- a/src/tools/tidy/src/main.rs +++ b/src/tools/tidy/src/main.rs @@ -116,6 +116,7 @@ fn main() { check!(fluent_alphabetical, &compiler_path, bless); check!(fluent_period, &compiler_path); check!(target_policy, &root_path); + check!(gcc_submodule, &root_path, &compiler_path); // Checks that only make sense for the std libs. check!(pal, &library_path); diff --git a/tests/run-make/rustc-help/help-v.diff b/tests/run-make/rustc-help/help-v.diff index 0ea79f3e55734..60a9dfbe201d9 100644 --- a/tests/run-make/rustc-help/help-v.diff +++ b/tests/run-make/rustc-help/help-v.diff @@ -1,22 +1,23 @@ -@@ -63,10 +63,27 @@ +@@ -65,10 +65,28 @@ Set a codegen option -V, --version Print version info and exit -v, --verbose Use verbose output -+ --extern NAME[=PATH] ++ --extern [=] + Specify where an external rust library is located -+ --sysroot PATH Override the system root -+ --error-format human|json|short ++ --sysroot ++ Override the system root ++ --error-format + How errors and other messages are produced -+ --json CONFIG Configure the JSON output of the compiler -+ --color auto|always|never ++ --json Configure the JSON output of the compiler ++ --color + Configure coloring of output: -+ auto = colorize, if output goes to a tty (default); -+ always = always colorize output; -+ never = never colorize output -+ --diagnostic-width WIDTH ++ * auto = colorize, if output goes to a tty (default); ++ * always = always colorize output; ++ * never = never colorize output ++ --diagnostic-width + Inform rustc of the width of the output so that + diagnostics can be truncated to fit -+ --remap-path-prefix FROM=TO ++ --remap-path-prefix = + Remap source names in all output (compiler messages + and output files) + @path Read newline separated options from `path` diff --git a/tests/run-make/rustc-help/help-v.stdout b/tests/run-make/rustc-help/help-v.stdout index 744453d6e8569..3fc297fb08e7d 100644 --- a/tests/run-make/rustc-help/help-v.stdout +++ b/tests/run-make/rustc-help/help-v.stdout @@ -2,31 +2,32 @@ Usage: rustc [OPTIONS] INPUT Options: -h, --help Display this message - --cfg SPEC Configure the compilation environment. - SPEC supports the syntax `NAME[="VALUE"]`. - --check-cfg SPEC + --cfg Configure the compilation environment. + SPEC supports the syntax `[=""]`. + --check-cfg Provide list of expected cfgs for checking - -L [KIND=]PATH Add a directory to the library search path. The - optional KIND can be one of dependency, crate, native, - framework, or all (the default). - -l [KIND[:MODIFIERS]=]NAME[:RENAME] + -L [=] Add a directory to the library search path. The + optional KIND can be one of + (default: + all). + -l [[:]=][:] Link the generated crate(s) to the specified native library NAME. The optional KIND can be one of - static, framework, or dylib (the default). + (default: dylib). Optional comma separated MODIFIERS - (bundle|verbatim|whole-archive|as-needed) + may be specified each with a prefix of either '+' to enable or '-' to disable. - --crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro] + --crate-type Comma separated list of types of crates for the compiler to emit - --crate-name NAME + --crate-name Specify the name of the crate being built - --edition 2015|2018|2021|2024 + --edition <2015|2018|2021|2024|future> Specify which edition of the compiler to use when compiling code. The default is 2015 and the latest stable edition is 2024. - --emit TYPE[=FILE] + --emit [=] Comma separated list of types of output for the compiler to emit. Each TYPE has the default FILE name: @@ -39,45 +40,47 @@ Options: * mir - CRATE_NAME.mir * obj - CRATE_NAME.o * thin-link-bitcode - CRATE_NAME.indexing.o - --print INFO[=FILE] + --print [=] Compiler information to print on stdout (or to a file) INFO may be one of - (all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|crate-root-lint-levels|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models). + . -g Equivalent to -C debuginfo=2 -O Equivalent to -C opt-level=3 - -o FILENAME Write output to - --out-dir DIR Write output to compiler-chosen filename in - --explain OPT Provide a detailed explanation of an error message + -o Write output to FILENAME + --out-dir Write output to compiler-chosen filename in DIR + --explain Provide a detailed explanation of an error message --test Build a test harness - --target TARGET Target triple for which the code is compiled - -A, --allow LINT Set lint allowed - -W, --warn LINT Set lint warnings - --force-warn LINT + --target + Target triple for which the code is compiled + -A, --allow Set lint allowed + -W, --warn Set lint warnings + --force-warn Set lint force-warn - -D, --deny LINT Set lint denied - -F, --forbid LINT Set lint forbidden - --cap-lints LEVEL + -D, --deny Set lint denied + -F, --forbid Set lint forbidden + --cap-lints Set the most restrictive lint level. More restrictive lints are capped at this level - -C, --codegen OPT[=VALUE] + -C, --codegen [=] Set a codegen option -V, --version Print version info and exit -v, --verbose Use verbose output - --extern NAME[=PATH] + --extern [=] Specify where an external rust library is located - --sysroot PATH Override the system root - --error-format human|json|short + --sysroot + Override the system root + --error-format How errors and other messages are produced - --json CONFIG Configure the JSON output of the compiler - --color auto|always|never + --json Configure the JSON output of the compiler + --color Configure coloring of output: - auto = colorize, if output goes to a tty (default); - always = always colorize output; - never = never colorize output - --diagnostic-width WIDTH + * auto = colorize, if output goes to a tty (default); + * always = always colorize output; + * never = never colorize output + --diagnostic-width Inform rustc of the width of the output so that diagnostics can be truncated to fit - --remap-path-prefix FROM=TO + --remap-path-prefix = Remap source names in all output (compiler messages and output files) @path Read newline separated options from `path` diff --git a/tests/run-make/rustc-help/help.stdout b/tests/run-make/rustc-help/help.stdout index 3043755207a64..caffe28f49899 100644 --- a/tests/run-make/rustc-help/help.stdout +++ b/tests/run-make/rustc-help/help.stdout @@ -2,31 +2,32 @@ Usage: rustc [OPTIONS] INPUT Options: -h, --help Display this message - --cfg SPEC Configure the compilation environment. - SPEC supports the syntax `NAME[="VALUE"]`. - --check-cfg SPEC + --cfg Configure the compilation environment. + SPEC supports the syntax `[=""]`. + --check-cfg Provide list of expected cfgs for checking - -L [KIND=]PATH Add a directory to the library search path. The - optional KIND can be one of dependency, crate, native, - framework, or all (the default). - -l [KIND[:MODIFIERS]=]NAME[:RENAME] + -L [=] Add a directory to the library search path. The + optional KIND can be one of + (default: + all). + -l [[:]=][:] Link the generated crate(s) to the specified native library NAME. The optional KIND can be one of - static, framework, or dylib (the default). + (default: dylib). Optional comma separated MODIFIERS - (bundle|verbatim|whole-archive|as-needed) + may be specified each with a prefix of either '+' to enable or '-' to disable. - --crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro] + --crate-type Comma separated list of types of crates for the compiler to emit - --crate-name NAME + --crate-name Specify the name of the crate being built - --edition 2015|2018|2021|2024 + --edition <2015|2018|2021|2024|future> Specify which edition of the compiler to use when compiling code. The default is 2015 and the latest stable edition is 2024. - --emit TYPE[=FILE] + --emit [=] Comma separated list of types of output for the compiler to emit. Each TYPE has the default FILE name: @@ -39,27 +40,28 @@ Options: * mir - CRATE_NAME.mir * obj - CRATE_NAME.o * thin-link-bitcode - CRATE_NAME.indexing.o - --print INFO[=FILE] + --print [=] Compiler information to print on stdout (or to a file) INFO may be one of - (all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|crate-root-lint-levels|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models). + . -g Equivalent to -C debuginfo=2 -O Equivalent to -C opt-level=3 - -o FILENAME Write output to - --out-dir DIR Write output to compiler-chosen filename in - --explain OPT Provide a detailed explanation of an error message + -o Write output to FILENAME + --out-dir Write output to compiler-chosen filename in DIR + --explain Provide a detailed explanation of an error message --test Build a test harness - --target TARGET Target triple for which the code is compiled - -A, --allow LINT Set lint allowed - -W, --warn LINT Set lint warnings - --force-warn LINT + --target + Target triple for which the code is compiled + -A, --allow Set lint allowed + -W, --warn Set lint warnings + --force-warn Set lint force-warn - -D, --deny LINT Set lint denied - -F, --forbid LINT Set lint forbidden - --cap-lints LEVEL + -D, --deny Set lint denied + -F, --forbid Set lint forbidden + --cap-lints Set the most restrictive lint level. More restrictive lints are capped at this level - -C, --codegen OPT[=VALUE] + -C, --codegen [=] Set a codegen option -V, --version Print version info and exit -v, --verbose Use verbose output diff --git a/tests/run-make/rustdoc-default-output/output-default.stdout b/tests/run-make/rustdoc-default-output/output-default.stdout index 563f8ec50cd61..78ca8c863ebab 100644 --- a/tests/run-make/rustdoc-default-output/output-default.stdout +++ b/tests/run-make/rustdoc-default-output/output-default.stdout @@ -11,7 +11,7 @@ Options: -o, --out-dir PATH which directory to place the output --crate-name NAME specify the name of this crate - --crate-type [bin|lib|rlib|dylib|cdylib|staticlib|proc-macro] + --crate-type Comma separated list of types of crates for the compiler to emit -L, --library-path DIR diff --git a/tests/ui/asm/naked-invalid-attr.rs b/tests/ui/asm/naked-invalid-attr.rs index c3a3131ee463c..6ac9cb9e3a9c5 100644 --- a/tests/ui/asm/naked-invalid-attr.rs +++ b/tests/ui/asm/naked-invalid-attr.rs @@ -51,3 +51,12 @@ fn main() { #[unsafe(naked)] //~ ERROR should be applied to a function definition || {}; } + +// Check that the path of an attribute without a name is printed correctly (issue #140082) +#[::a] +//~^ ERROR attribute incompatible with `#[unsafe(naked)]` +//~| ERROR failed to resolve: use of unresolved module or unlinked crate `a` +#[unsafe(naked)] +extern "C" fn issue_140082() { + naked_asm!("") +} diff --git a/tests/ui/asm/naked-invalid-attr.stderr b/tests/ui/asm/naked-invalid-attr.stderr index 81d30e6475d95..ef389e7d921b9 100644 --- a/tests/ui/asm/naked-invalid-attr.stderr +++ b/tests/ui/asm/naked-invalid-attr.stderr @@ -1,3 +1,9 @@ +error[E0433]: failed to resolve: use of unresolved module or unlinked crate `a` + --> $DIR/naked-invalid-attr.rs:56:5 + | +LL | #[::a] + | ^ use of unresolved module or unlinked crate `a` + error: attribute should be applied to a function definition --> $DIR/naked-invalid-attr.rs:13:1 | @@ -27,6 +33,15 @@ LL | #[unsafe(naked)] LL | || {}; | ----- not a function definition +error[E0736]: attribute incompatible with `#[unsafe(naked)]` + --> $DIR/naked-invalid-attr.rs:56:1 + | +LL | #[::a] + | ^^^^^^ the `{{root}}::a` attribute is incompatible with `#[unsafe(naked)]` +... +LL | #[unsafe(naked)] + | ---------------- function marked with `#[unsafe(naked)]` here + error: attribute should be applied to a function definition --> $DIR/naked-invalid-attr.rs:22:5 | @@ -49,5 +64,7 @@ error: attribute should be applied to a function definition LL | #![unsafe(naked)] | ^^^^^^^^^^^^^^^^^ cannot be applied to crates -error: aborting due to 6 previous errors +error: aborting due to 8 previous errors +Some errors have detailed explanations: E0433, E0736. +For more information about an error, try `rustc --explain E0433`. diff --git a/tests/ui/compiletest-self-test/compile-flags-last.stderr b/tests/ui/compiletest-self-test/compile-flags-last.stderr index 72d92206e2bb4..5a48361cfc0df 100644 --- a/tests/ui/compiletest-self-test/compile-flags-last.stderr +++ b/tests/ui/compiletest-self-test/compile-flags-last.stderr @@ -1,5 +1,5 @@ error: Argument to option 'cap-lints' missing Usage: - --cap-lints LEVEL Set the most restrictive lint level. More restrictive + --cap-lints Set the most restrictive lint level. More restrictive lints are capped at this level diff --git a/tests/ui/copy-a-resource.rs b/tests/ui/copy-a-resource.rs deleted file mode 100644 index 55f2dd4ee6dde..0000000000000 --- a/tests/ui/copy-a-resource.rs +++ /dev/null @@ -1,21 +0,0 @@ -#[derive(Debug)] -struct Foo { - i: isize, -} - -impl Drop for Foo { - fn drop(&mut self) {} -} - -fn foo(i:isize) -> Foo { - Foo { - i: i - } -} - -fn main() { - let x = foo(10); - let _y = x.clone(); - //~^ ERROR no method named `clone` found - println!("{:?}", x); -} diff --git a/tests/ui/invalid-compile-flags/emit-output-types-without-args.stderr b/tests/ui/invalid-compile-flags/emit-output-types-without-args.stderr index 669913b57653e..9e4486a272f9d 100644 --- a/tests/ui/invalid-compile-flags/emit-output-types-without-args.stderr +++ b/tests/ui/invalid-compile-flags/emit-output-types-without-args.stderr @@ -1,6 +1,7 @@ error: Argument to option 'emit' missing Usage: - --emit TYPE[=FILE] Comma separated list of types of output for the + --emit [=] + Comma separated list of types of output for the compiler to emit. Each TYPE has the default FILE name: * asm - CRATE_NAME.s diff --git a/tests/ui/invalid-compile-flags/print-without-arg.stderr b/tests/ui/invalid-compile-flags/print-without-arg.stderr index fd2a36e761bef..3048a59d0d00c 100644 --- a/tests/ui/invalid-compile-flags/print-without-arg.stderr +++ b/tests/ui/invalid-compile-flags/print-without-arg.stderr @@ -1,6 +1,7 @@ error: Argument to option 'print' missing Usage: - --print INFO[=FILE] Compiler information to print on stdout (or to a file) + --print [=] + Compiler information to print on stdout (or to a file) INFO may be one of - (all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|crate-root-lint-levels|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models). + . diff --git a/tests/ui/fail-simple.rs b/tests/ui/macros/no-matching-rule.rs similarity index 100% rename from tests/ui/fail-simple.rs rename to tests/ui/macros/no-matching-rule.rs diff --git a/tests/ui/fail-simple.stderr b/tests/ui/macros/no-matching-rule.stderr similarity index 85% rename from tests/ui/fail-simple.stderr rename to tests/ui/macros/no-matching-rule.stderr index 50c350b3ef55e..a6312a843f398 100644 --- a/tests/ui/fail-simple.stderr +++ b/tests/ui/macros/no-matching-rule.stderr @@ -1,5 +1,5 @@ error: no rules expected `@` - --> $DIR/fail-simple.rs:2:12 + --> $DIR/no-matching-rule.rs:2:12 | LL | panic!(@); | ^ no rules expected this token in macro call diff --git a/tests/ui/methods/clone-missing.rs b/tests/ui/methods/clone-missing.rs new file mode 100644 index 0000000000000..f2e4ad268c63a --- /dev/null +++ b/tests/ui/methods/clone-missing.rs @@ -0,0 +1,19 @@ +// This test checks that calling `.clone()` on a type that does not implement the `Clone` trait +// results in a compilation error. The `Foo` struct does not derive or implement `Clone`, +// so attempting to clone it should fail. + +struct Foo { + i: isize, +} + +fn foo(i:isize) -> Foo { + Foo { + i: i + } +} + +fn main() { + let x = foo(10); + let _y = x.clone(); + //~^ ERROR no method named `clone` found +} diff --git a/tests/ui/copy-a-resource.stderr b/tests/ui/methods/clone-missing.stderr similarity index 94% rename from tests/ui/copy-a-resource.stderr rename to tests/ui/methods/clone-missing.stderr index ff1e28bf9611d..4ab1aae4934bf 100644 --- a/tests/ui/copy-a-resource.stderr +++ b/tests/ui/methods/clone-missing.stderr @@ -1,5 +1,5 @@ error[E0599]: no method named `clone` found for struct `Foo` in the current scope - --> $DIR/copy-a-resource.rs:18:16 + --> $DIR/clone-missing.rs:17:16 | LL | struct Foo { | ---------- method `clone` not found for this struct diff --git a/tests/ui/modules/mod-pub-access.rs b/tests/ui/modules/mod-pub-access.rs new file mode 100644 index 0000000000000..c07e7a2ff3062 --- /dev/null +++ b/tests/ui/modules/mod-pub-access.rs @@ -0,0 +1,11 @@ +//@ run-pass +// This is a name resolution smoke test that ensures paths with more than one +// segment (e.g., `foo::bar`) resolve correctly. +// It also serves as a basic visibility test — confirming that a `pub` item +// inside a private module can still be accessed from outside that module. + +mod foo { + pub fn bar(_offset: usize) {} +} + +fn main() { foo::bar(0); } diff --git a/tests/ui/path.rs b/tests/ui/path.rs deleted file mode 100644 index bd7b99ac01ad5..0000000000000 --- a/tests/ui/path.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ run-pass - -mod foo { - pub fn bar(_offset: usize) { } -} - -pub fn main() { foo::bar(0); } diff --git a/tests/ui/capture1.rs b/tests/ui/resolve/fn-item-cant-capture-dynamic-env.rs similarity index 100% rename from tests/ui/capture1.rs rename to tests/ui/resolve/fn-item-cant-capture-dynamic-env.rs diff --git a/tests/ui/capture1.stderr b/tests/ui/resolve/fn-item-cant-capture-dynamic-env.stderr similarity index 85% rename from tests/ui/capture1.stderr rename to tests/ui/resolve/fn-item-cant-capture-dynamic-env.stderr index 8027430de522b..6b3e879201158 100644 --- a/tests/ui/capture1.stderr +++ b/tests/ui/resolve/fn-item-cant-capture-dynamic-env.stderr @@ -1,5 +1,5 @@ error[E0434]: can't capture dynamic environment in a fn item - --> $DIR/capture1.rs:3:32 + --> $DIR/fn-item-cant-capture-dynamic-env.rs:3:32 | LL | fn foo() -> isize { return bar; } | ^^^ diff --git a/tests/ui/transmute/auxiliary/unnecessary-transmute-path-remap-ice-140277-trans.rs b/tests/ui/transmute/auxiliary/unnecessary-transmute-path-remap-ice-140277-trans.rs new file mode 100644 index 0000000000000..0f273a6f536e0 --- /dev/null +++ b/tests/ui/transmute/auxiliary/unnecessary-transmute-path-remap-ice-140277-trans.rs @@ -0,0 +1,10 @@ +//@ compile-flags: --remap-path-prefix=/=/non-existent +// helper for ../unnecessary-transmute-path-remap-ice-140277.rs + +#[macro_export] +macro_rules! transmute { + ($e:expr) => {{ + let e = $e; + std::mem::transmute(e) + }}; +} diff --git a/tests/ui/transmute/unnecessary-transmute-path-remap-ice-140277.rs b/tests/ui/transmute/unnecessary-transmute-path-remap-ice-140277.rs new file mode 100644 index 0000000000000..756ce7b3d5074 --- /dev/null +++ b/tests/ui/transmute/unnecessary-transmute-path-remap-ice-140277.rs @@ -0,0 +1,10 @@ +//@ aux-crate: zerocopy=unnecessary-transmute-path-remap-ice-140277-trans.rs +//@ check-pass +// tests for a regression in linting for unnecessary transmutes +// where a span was inacessible for snippet procuring, +// when remap-path-prefix was set, causing a panic. + +fn bytes_at_home(x: [u8; 4]) -> u32 { + unsafe { zerocopy::transmute!(x) } +} +fn main() {} diff --git a/tests/ui/type-alias/type-param.rs b/tests/ui/type-alias/type-param.rs new file mode 100644 index 0000000000000..f8e73518bad6a --- /dev/null +++ b/tests/ui/type-alias/type-param.rs @@ -0,0 +1,11 @@ +//@ run-pass +// This is a smoke test to ensure that type aliases with type parameters +// are accepted by the compiler and that the parameters are correctly +// resolved in the aliased item type. + +#![allow(dead_code)] + +type Foo = extern "C" fn(T) -> bool; +type Bar = fn(T) -> bool; + +fn main() {} diff --git a/tests/ui/type-param.rs b/tests/ui/type-param.rs deleted file mode 100644 index e7cf0e5446bcf..0000000000000 --- a/tests/ui/type-param.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ run-pass - -#![allow(non_camel_case_types)] -#![allow(dead_code)] - - - -type lteq = extern "C" fn(T) -> bool; - -pub fn main() { }