From 42bf2af5ea1ab6e797fe2ce0abfb83e111288ded Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Thu, 19 Dec 2024 21:37:18 +0800 Subject: [PATCH 01/10] opt-dist: propagate channel info to bootstrap --- src/tools/opt-dist/src/tests.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/tools/opt-dist/src/tests.rs b/src/tools/opt-dist/src/tests.rs index 887055798e00a..06ed076a86437 100644 --- a/src/tools/opt-dist/src/tests.rs +++ b/src/tools/opt-dist/src/tests.rs @@ -25,6 +25,8 @@ pub fn run_tests(env: &Environment) -> anyhow::Result<()> { let host_triple = env.host_tuple(); let version = find_dist_version(&dist_dir)?; + let channel = version_to_channel(&version); + // Extract rustc, libstd, cargo and src archives to create the optimized sysroot let rustc_dir = extract_dist_dir(&format!("rustc-{version}-{host_triple}"))?.join("rustc"); let libstd_dir = extract_dist_dir(&format!("rust-std-{version}-{host_triple}"))? @@ -61,9 +63,13 @@ pub fn run_tests(env: &Environment) -> anyhow::Result<()> { assert!(llvm_config.is_file()); let config_content = format!( - r#"profile = "user" + r#" +profile = "user" change-id = 115898 +[rust] +channel = "{channel}" + [build] rustc = "{rustc}" cargo = "{cargo}" @@ -116,3 +122,13 @@ fn find_dist_version(directory: &Utf8Path) -> anyhow::Result { archive.strip_prefix("reproducible-artifacts-").unwrap().split_once('-').unwrap(); Ok(version.to_string()) } + +/// Roughly convert a version string (`nightly`, `beta`, or `1.XY.Z`) to channel string (`nightly`, +/// `beta` or `stable`). +fn version_to_channel(version_str: &str) -> &'static str { + match version_str { + "nightly" => "nightly", + "beta" => "beta", + _ => "stable", + } +} From d6ceae0fd89ad0f9e882aea1f9e92dff673fcfba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E6=9D=B0=E5=8F=8B=20Jieyou=20Xu=20=28Joe=29?= <39484203+jieyouxu@users.noreply.github.com> Date: Tue, 10 Dec 2024 21:02:49 +0800 Subject: [PATCH 02/10] Adjust `rustc_bootstap.rs` ui test - Fixed test name, it should've been `rustc_bootstrap.rs`, oops. - Slightly reworded test comment to make it more clear. --- ...orce_stable.stderr => rustc_bootstrap.force_stable.stderr} | 0 tests/ui/bootstrap/{rustc_bootstap.rs => rustc_bootstrap.rs} | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename tests/ui/bootstrap/{rustc_bootstap.force_stable.stderr => rustc_bootstrap.force_stable.stderr} (100%) rename tests/ui/bootstrap/{rustc_bootstap.rs => rustc_bootstrap.rs} (89%) diff --git a/tests/ui/bootstrap/rustc_bootstap.force_stable.stderr b/tests/ui/bootstrap/rustc_bootstrap.force_stable.stderr similarity index 100% rename from tests/ui/bootstrap/rustc_bootstap.force_stable.stderr rename to tests/ui/bootstrap/rustc_bootstrap.force_stable.stderr diff --git a/tests/ui/bootstrap/rustc_bootstap.rs b/tests/ui/bootstrap/rustc_bootstrap.rs similarity index 89% rename from tests/ui/bootstrap/rustc_bootstap.rs rename to tests/ui/bootstrap/rustc_bootstrap.rs index 3d792ef4be4e5..daa28e0cdf29e 100644 --- a/tests/ui/bootstrap/rustc_bootstap.rs +++ b/tests/ui/bootstrap/rustc_bootstrap.rs @@ -1,5 +1,5 @@ -//! Check `RUSTC_BOOTSTRAP`'s behavior in relation to feature stability and what rustc considers -//! itself to be (stable vs non-stable ). +//! Check the compiler's behavior when the perma-unstable env var `RUSTC_BOOTSTRAP` is set in the +//! environment in relation to feature stability and which channel rustc considers itself to be. //! //! `RUSTC_BOOTSTRAP` accepts: //! From 1f82b45b6a42eca19a9dc48402abdc02574f791d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 11 Dec 2024 01:37:17 +0000 Subject: [PATCH 03/10] Use `#[derive(Default)]` instead of manually implementing it --- compiler/rustc_ast/src/ast.rs | 19 +++---------------- .../src/pprust/state/fixup.rs | 18 +++--------------- compiler/rustc_lint/src/unused.rs | 7 +------ compiler/rustc_session/src/config.rs | 9 ++------- library/core/tests/hash/mod.rs | 15 +++------------ library/proc_macro/src/bridge/fxhash.rs | 8 +------- library/std/src/panicking.rs | 9 ++------- library/std/src/sys_common/process.rs | 8 +------- 8 files changed, 16 insertions(+), 77 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index cec868e5c8e57..31e6750a6788c 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -31,7 +31,7 @@ use rustc_data_structures::sync::Lrc; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; pub use rustc_span::AttrId; use rustc_span::source_map::{Spanned, respan}; -use rustc_span::{DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, sym}; +use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym}; use thin_vec::{ThinVec, thin_vec}; pub use crate::format::*; @@ -387,22 +387,15 @@ impl GenericParam { /// Represents lifetime, type and const parameters attached to a declaration of /// a function, enum, trait, etc. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Default)] pub struct Generics { pub params: ThinVec, pub where_clause: WhereClause, pub span: Span, } -impl Default for Generics { - /// Creates an instance of `Generics`. - fn default() -> Generics { - Generics { params: ThinVec::new(), where_clause: Default::default(), span: DUMMY_SP } - } -} - /// A where-clause in a definition. -#[derive(Clone, Encodable, Decodable, Debug)] +#[derive(Clone, Encodable, Decodable, Debug, Default)] pub struct WhereClause { /// `true` if we ate a `where` token. /// @@ -419,12 +412,6 @@ impl WhereClause { } } -impl Default for WhereClause { - fn default() -> WhereClause { - WhereClause { has_where_token: false, predicates: ThinVec::new(), span: DUMMY_SP } - } -} - /// A single predicate in a where-clause. #[derive(Clone, Encodable, Decodable, Debug)] pub struct WherePredicate { diff --git a/compiler/rustc_ast_pretty/src/pprust/state/fixup.rs b/compiler/rustc_ast_pretty/src/pprust/state/fixup.rs index 6f5382ce61d3b..ff466703f7374 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/fixup.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/fixup.rs @@ -1,7 +1,9 @@ use rustc_ast::Expr; use rustc_ast::util::{classify, parser}; -#[derive(Copy, Clone, Debug)] +// The default amount of fixing is minimal fixing, so all fixups are set to `false` by `Default`. +// Fixups should be turned on in a targeted fashion where needed. +#[derive(Copy, Clone, Debug, Default)] pub(crate) struct FixupContext { /// Print expression such that it can be parsed back as a statement /// consisting of the original expression. @@ -93,20 +95,6 @@ pub(crate) struct FixupContext { parenthesize_exterior_struct_lit: bool, } -/// The default amount of fixing is minimal fixing. Fixups should be turned on -/// in a targeted fashion where needed. -impl Default for FixupContext { - fn default() -> Self { - FixupContext { - stmt: false, - leftmost_subexpression_in_stmt: false, - match_arm: false, - leftmost_subexpression_in_match_arm: false, - parenthesize_exterior_struct_lit: false, - } - } -} - impl FixupContext { /// Create the initial fixup for printing an expression in statement /// position. diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 2b3cb14f9e904..8b1526bc747d4 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1023,6 +1023,7 @@ declare_lint! { "`if`, `match`, `while` and `return` do not need parentheses" } +#[derive(Default)] pub(crate) struct UnusedParens { with_self_ty_parens: bool, /// `1 as (i32) < 2` parses to ExprKind::Lt @@ -1030,12 +1031,6 @@ pub(crate) struct UnusedParens { parens_in_cast_in_lt: Vec, } -impl Default for UnusedParens { - fn default() -> Self { - Self { with_self_ty_parens: false, parens_in_cast_in_lt: Vec::new() } - } -} - impl_lint_pass!(UnusedParens => [UNUSED_PARENS]); impl UnusedDelimLint for UnusedParens { diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 047e920e6883b..5c36c98649020 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -168,9 +168,10 @@ pub struct CoverageOptions { } /// Controls whether branch coverage or MC/DC coverage is enabled. -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)] pub enum CoverageLevel { /// Instrument for coverage at the MIR block level. + #[default] Block, /// Also instrument branch points (includes block coverage). Branch, @@ -195,12 +196,6 @@ pub enum CoverageLevel { Mcdc, } -impl Default for CoverageLevel { - fn default() -> Self { - Self::Block - } -} - /// Settings for `-Z instrument-xray` flag. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] pub struct InstrumentXRay { diff --git a/library/core/tests/hash/mod.rs b/library/core/tests/hash/mod.rs index bf91e9e5df0e2..9f14995f73fe2 100644 --- a/library/core/tests/hash/mod.rs +++ b/library/core/tests/hash/mod.rs @@ -4,16 +4,11 @@ use std::hash::{BuildHasher, Hash, Hasher}; use std::ptr; use std::rc::Rc; +#[derive(Default)] struct MyHasher { hash: u64, } -impl Default for MyHasher { - fn default() -> MyHasher { - MyHasher { hash: 0 } - } -} - impl Hasher for MyHasher { fn write(&mut self, buf: &[u8]) { for byte in buf { @@ -107,6 +102,8 @@ fn test_writer_hasher() { struct Custom { hash: u64, } + +#[derive(Default)] struct CustomHasher { output: u64, } @@ -123,12 +120,6 @@ impl Hasher for CustomHasher { } } -impl Default for CustomHasher { - fn default() -> CustomHasher { - CustomHasher { output: 0 } - } -} - impl Hash for Custom { fn hash(&self, state: &mut H) { state.write_u64(self.hash); diff --git a/library/proc_macro/src/bridge/fxhash.rs b/library/proc_macro/src/bridge/fxhash.rs index 74a41451825ff..3345e099a3724 100644 --- a/library/proc_macro/src/bridge/fxhash.rs +++ b/library/proc_macro/src/bridge/fxhash.rs @@ -22,6 +22,7 @@ pub type FxHashMap = HashMap>; /// out-performs an FNV-based hash within rustc itself -- the collision rate is /// similar or slightly worse than FNV, but the speed of the hash function /// itself is much higher because it works on up to 8 bytes at a time. +#[derive(Default)] pub struct FxHasher { hash: usize, } @@ -31,13 +32,6 @@ const K: usize = 0x9e3779b9; #[cfg(target_pointer_width = "64")] const K: usize = 0x517cc1b727220a95; -impl Default for FxHasher { - #[inline] - fn default() -> FxHasher { - FxHasher { hash: 0 } - } -} - impl FxHasher { #[inline] fn add_to_hash(&mut self, i: usize) { diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index dca5ccca0c404..e7ce5bc61401d 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -81,7 +81,9 @@ extern "C" fn __rust_foreign_exception() -> ! { rtabort!("Rust cannot catch foreign exceptions"); } +#[derive(Default)] enum Hook { + #[default] Default, Custom(Box) + 'static + Sync + Send>), } @@ -96,13 +98,6 @@ impl Hook { } } -impl Default for Hook { - #[inline] - fn default() -> Hook { - Hook::Default - } -} - static HOOK: RwLock = RwLock::new(Hook::Default); /// Registers a custom panic hook, replacing the previously registered hook. diff --git a/library/std/src/sys_common/process.rs b/library/std/src/sys_common/process.rs index 5333ee146f7d6..9f61d69d85875 100644 --- a/library/std/src/sys_common/process.rs +++ b/library/std/src/sys_common/process.rs @@ -8,19 +8,13 @@ use crate::sys::process::{EnvKey, ExitStatus, Process, StdioPipes}; use crate::{env, fmt, io}; // Stores a set of changes to an environment -#[derive(Clone)] +#[derive(Clone, Default)] pub struct CommandEnv { clear: bool, saw_path: bool, vars: BTreeMap>, } -impl Default for CommandEnv { - fn default() -> Self { - CommandEnv { clear: false, saw_path: false, vars: Default::default() } - } -} - impl fmt::Debug for CommandEnv { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut debug_command_env = f.debug_struct("CommandEnv"); From d124ec68b37fb49d25d9849bccaf29edbb889b2c Mon Sep 17 00:00:00 2001 From: clubby789 Date: Sun, 22 Dec 2024 22:23:54 +0000 Subject: [PATCH 04/10] Link to dev guide on Docker testing --- src/ci/docker/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ci/docker/README.md b/src/ci/docker/README.md index 876787c30e537..2f35e60502622 100644 --- a/src/ci/docker/README.md +++ b/src/ci/docker/README.md @@ -26,6 +26,10 @@ DEPLOY=1 ./src/ci/docker/run.sh x86_64-gnu while locally, to the `obj/$image_name` directory. This is primarily to prevent strange linker errors when using multiple Docker images. +## Local Development + +Refer to the [dev guide](https://rustc-dev-guide.rust-lang.org/tests/docker.html) for more information on testing locally. + ## Filesystem layout - Each host architecture has its own `host-{arch}` directory, and those From d6a9ad6190eac56b2c5847541ecf6e7bbcc2565e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Mon, 23 Dec 2024 09:14:30 +0000 Subject: [PATCH 05/10] remove unused imports from rmake tests --- tests/run-make/embed-source-dwarf/rmake.rs | 2 +- tests/run-make/libstd-no-protected/rmake.rs | 2 +- tests/run-make/libtest-thread-limit/rmake.rs | 5 +---- tests/run-make/missing-unstable-trait-bound/rmake.rs | 2 +- tests/run-make/no-alloc-shim/rmake.rs | 2 +- tests/run-make/rustdoc-map-file/rmake.rs | 2 -- tests/run-make/rustdoc-output-stdout/rmake.rs | 2 -- 7 files changed, 5 insertions(+), 12 deletions(-) diff --git a/tests/run-make/embed-source-dwarf/rmake.rs b/tests/run-make/embed-source-dwarf/rmake.rs index c7106967a85eb..0aae07ff2e647 100644 --- a/tests/run-make/embed-source-dwarf/rmake.rs +++ b/tests/run-make/embed-source-dwarf/rmake.rs @@ -10,7 +10,7 @@ use std::collections::HashMap; use std::path::PathBuf; use std::rc::Rc; -use gimli::{AttributeValue, EndianRcSlice, Reader, RunTimeEndian}; +use gimli::{EndianRcSlice, Reader, RunTimeEndian}; use object::{Object, ObjectSection}; use run_make_support::{gimli, object, rfs, rustc}; diff --git a/tests/run-make/libstd-no-protected/rmake.rs b/tests/run-make/libstd-no-protected/rmake.rs index 3bba59a8f4d55..4091406d46e29 100644 --- a/tests/run-make/libstd-no-protected/rmake.rs +++ b/tests/run-make/libstd-no-protected/rmake.rs @@ -7,7 +7,7 @@ use run_make_support::object::Endianness; use run_make_support::object::read::archive::ArchiveFile; use run_make_support::object::read::elf::{FileHeader as _, SectionHeader as _}; -use run_make_support::rfs::{read, read_dir}; +use run_make_support::rfs::read; use run_make_support::{has_prefix, has_suffix, object, path, rustc, shallow_find_files, target}; type FileHeader = run_make_support::object::elf::FileHeader64; diff --git a/tests/run-make/libtest-thread-limit/rmake.rs b/tests/run-make/libtest-thread-limit/rmake.rs index fe14d2c046cca..817328cd3c3eb 100644 --- a/tests/run-make/libtest-thread-limit/rmake.rs +++ b/tests/run-make/libtest-thread-limit/rmake.rs @@ -15,10 +15,7 @@ // Reason: this should be ignored in cg_clif (Cranelift) CI and anywhere // else that uses panic=abort. -use std::ffi::{self, CStr, CString}; -use std::path::PathBuf; - -use run_make_support::{libc, run, rustc}; +use run_make_support::{libc, rustc}; fn main() { rustc().input("test.rs").arg("--test").run(); diff --git a/tests/run-make/missing-unstable-trait-bound/rmake.rs b/tests/run-make/missing-unstable-trait-bound/rmake.rs index 20f77f7c9aa0d..3f76c65247d8c 100644 --- a/tests/run-make/missing-unstable-trait-bound/rmake.rs +++ b/tests/run-make/missing-unstable-trait-bound/rmake.rs @@ -6,7 +6,7 @@ // Ensure that on stable we don't suggest restricting with an unsafe trait and we continue // mentioning the rest of the obligation chain. -use run_make_support::{diff, rust_lib_name, rustc}; +use run_make_support::{diff, rustc}; fn main() { let out = rustc() diff --git a/tests/run-make/no-alloc-shim/rmake.rs b/tests/run-make/no-alloc-shim/rmake.rs index c398a3177df63..d61ef5de8c56c 100644 --- a/tests/run-make/no-alloc-shim/rmake.rs +++ b/tests/run-make/no-alloc-shim/rmake.rs @@ -13,7 +13,7 @@ // Tracking issue: https://github.com/rust-lang/rust/issues/128602 // Discussion: https://github.com/rust-lang/rust/pull/128407#discussion_r1702439172 -use run_make_support::{cc, cwd, has_extension, has_prefix, run, rustc, shallow_find_files}; +use run_make_support::{cc, has_extension, has_prefix, run, rustc, shallow_find_files}; fn main() { rustc().input("foo.rs").crate_type("bin").emit("obj").panic("abort").run(); diff --git a/tests/run-make/rustdoc-map-file/rmake.rs b/tests/run-make/rustdoc-map-file/rmake.rs index d7e3510fe31e0..50dcc603c02f2 100644 --- a/tests/run-make/rustdoc-map-file/rmake.rs +++ b/tests/run-make/rustdoc-map-file/rmake.rs @@ -1,8 +1,6 @@ // This test ensures that all items from `foo` are correctly generated into the `redirect-map.json` // file with `--generate-redirect-map` rustdoc option. -use std::path::Path; - use run_make_support::rfs::read_to_string; use run_make_support::{path, rustdoc, serde_json}; diff --git a/tests/run-make/rustdoc-output-stdout/rmake.rs b/tests/run-make/rustdoc-output-stdout/rmake.rs index bcf5e4d97239f..d2fd045116354 100644 --- a/tests/run-make/rustdoc-output-stdout/rmake.rs +++ b/tests/run-make/rustdoc-output-stdout/rmake.rs @@ -1,8 +1,6 @@ // This test verifies that rustdoc `-o -` prints JSON on stdout and doesn't generate // a JSON file. -use std::path::PathBuf; - use run_make_support::path_helpers::{cwd, has_extension, read_dir_entries_recursive}; use run_make_support::{rustdoc, serde_json}; From 1d77a2c6772bbe8346f6e42f52f62a5a3c46908c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Mon, 23 Dec 2024 09:26:57 +0000 Subject: [PATCH 06/10] clean up `remove-dir-all-race` rmake test - removes unused variables - fixes a few typos --- tests/run-make/remove-dir-all-race/rmake.rs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/run-make/remove-dir-all-race/rmake.rs b/tests/run-make/remove-dir-all-race/rmake.rs index 03c94b76127d5..32abca92424d6 100644 --- a/tests/run-make/remove-dir-all-race/rmake.rs +++ b/tests/run-make/remove-dir-all-race/rmake.rs @@ -1,13 +1,13 @@ //@ ignore-windows // This test attempts to make sure that running `remove_dir_all` -// doesn't result in a NotFound error one of the files it +// doesn't result in a NotFound error if one of the files it // is deleting is deleted concurrently. // // The windows implementation for `remove_dir_all` is significantly // more complicated, and has not yet been brought up to par with // the implementation on other platforms, so this test is marked as -// `ignore-windows` until someone more expirenced with windows can +// `ignore-windows` until someone more experienced with windows can // sort that out. use std::fs::remove_dir_all; @@ -27,13 +27,12 @@ fn main() { write("outer/inner.txt", b"sometext"); thread::scope(|scope| { - let t1 = scope.spawn(|| { + scope.spawn(|| { thread::sleep(Duration::from_nanos(i)); remove_dir_all("outer").unwrap(); }); - let race_happened_ref = &race_happened; - let t2 = scope.spawn(|| { + scope.spawn(|| { let r1 = remove_dir_all("outer/inner"); let r2 = remove_dir_all("outer/inner.txt"); if r1.is_ok() && r2.is_err() { @@ -44,10 +43,10 @@ fn main() { assert!(!Path::new("outer").exists()); - // trying to remove a nonexistant top-level directory should + // trying to remove a nonexistent top-level directory should // still result in an error. let Err(err) = remove_dir_all("outer") else { - panic!("removing nonexistant dir did not result in an error"); + panic!("removing nonexistent dir did not result in an error"); }; assert_eq!(err.kind(), std::io::ErrorKind::NotFound); } From 9ca5df692b61db524d6a4c8e78042e9db2cc18b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Mon, 23 Dec 2024 09:31:01 +0000 Subject: [PATCH 07/10] remove unnecessary `mut` from `dump-ice-to-disk` rmake test --- tests/run-make/dump-ice-to-disk/rmake.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run-make/dump-ice-to-disk/rmake.rs b/tests/run-make/dump-ice-to-disk/rmake.rs index 15f35eb2d3d88..a7a98d31f5046 100644 --- a/tests/run-make/dump-ice-to-disk/rmake.rs +++ b/tests/run-make/dump-ice-to-disk/rmake.rs @@ -83,7 +83,7 @@ fn extract_exactly_one_ice_file>(name: &'static str, dir: P) -> I fn main() { // Establish baseline ICE message. - let mut default_ice_dump = OnceCell::new(); + let default_ice_dump = OnceCell::new(); run_in_tmpdir(|| { rustc().env("RUSTC_ICE", cwd()).input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail(); let dump = extract_exactly_one_ice_file("baseline", cwd()); From 6f19bd08b07b590ff20a2285c3dc4938d3e37447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Mon, 23 Dec 2024 09:34:52 +0000 Subject: [PATCH 08/10] fix a few typos in rmake tests' comments --- tests/run-make/import-macro-verbatim/verbatim.rs | 2 +- tests/run-make/llvm-outputs/rmake.rs | 4 ++-- tests/run-make/musl-default-linking/rmake.rs | 2 +- tests/run-make/no-builtins-lto/rmake.rs | 2 +- tests/run-make/symbol-visibility/rmake.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/run-make/import-macro-verbatim/verbatim.rs b/tests/run-make/import-macro-verbatim/verbatim.rs index 56a83673c1f57..0123a4a7e2215 100644 --- a/tests/run-make/import-macro-verbatim/verbatim.rs +++ b/tests/run-make/import-macro-verbatim/verbatim.rs @@ -1,4 +1,4 @@ -//! Include a file by concating the verbatim path using `/` instead of `\` +//! Include a file by concatenating the verbatim path using `/` instead of `\` include!(concat!(env!("VERBATIM_DIR"), "/include/include.txt")); fn main() { diff --git a/tests/run-make/llvm-outputs/rmake.rs b/tests/run-make/llvm-outputs/rmake.rs index 632e9a09ba503..2ce31b260a164 100644 --- a/tests/run-make/llvm-outputs/rmake.rs +++ b/tests/run-make/llvm-outputs/rmake.rs @@ -9,8 +9,8 @@ fn main() { let mut path_ir = PathBuf::new(); run_in_tmpdir(|| { let p = cwd(); - path_bc = p.join("nonexistant_dir_bc"); - path_ir = p.join("nonexistant_dir_ir"); + path_bc = p.join("nonexistent_dir_bc"); + path_ir = p.join("nonexistent_dir_ir"); rustc().input("-").stdin_buf("fn main() {}").out_dir(&path_bc).emit("llvm-bc").run(); rustc().input("-").stdin_buf("fn main() {}").out_dir(&path_ir).emit("llvm-ir").run(); assert!(path_bc.exists()); diff --git a/tests/run-make/musl-default-linking/rmake.rs b/tests/run-make/musl-default-linking/rmake.rs index b6d428d3f2716..d203595a44741 100644 --- a/tests/run-make/musl-default-linking/rmake.rs +++ b/tests/run-make/musl-default-linking/rmake.rs @@ -48,7 +48,7 @@ fn main() { let default = &target_spec["crt-static-default"]; // If the value is `null`, then the default to dynamically link from - // musl_base was not overriden. + // musl_base was not overridden. if default.is_null() { continue; } diff --git a/tests/run-make/no-builtins-lto/rmake.rs b/tests/run-make/no-builtins-lto/rmake.rs index 8e0c3a636490f..56fdfde42f04d 100644 --- a/tests/run-make/no-builtins-lto/rmake.rs +++ b/tests/run-make/no-builtins-lto/rmake.rs @@ -1,4 +1,4 @@ -// The rlib produced by a no_builtins crate should be explicitely linked +// The rlib produced by a no_builtins crate should be explicitly linked // during compilation, and as a result be present in the linker arguments. // See the comments inside this file for more details. // See https://github.com/rust-lang/rust/pull/35637 diff --git a/tests/run-make/symbol-visibility/rmake.rs b/tests/run-make/symbol-visibility/rmake.rs index f84e63ef74e8d..ec936bc3b07fa 100644 --- a/tests/run-make/symbol-visibility/rmake.rs +++ b/tests/run-make/symbol-visibility/rmake.rs @@ -1,7 +1,7 @@ // Dynamic libraries on Rust used to export a very high amount of symbols, // going as far as filling the output with mangled names and generic function // names. After the rework of #38117, this test checks that no mangled Rust symbols -// are exported, and that generics are only shown if explicitely requested. +// are exported, and that generics are only shown if explicitly requested. // See https://github.com/rust-lang/rust/issues/37530 use run_make_support::object::read::Object; From 0efa90f2464cad23abd371676b592d672d039057 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 19 Dec 2024 06:43:09 -0800 Subject: [PATCH 09/10] Add a test for coverage attr on trait function --- .../coverage/attr/trait-impl-inherit.cov-map | 9 +++++++ .../coverage/attr/trait-impl-inherit.coverage | 26 +++++++++++++++++++ tests/coverage/attr/trait-impl-inherit.rs | 25 ++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 tests/coverage/attr/trait-impl-inherit.cov-map create mode 100644 tests/coverage/attr/trait-impl-inherit.coverage create mode 100644 tests/coverage/attr/trait-impl-inherit.rs diff --git a/tests/coverage/attr/trait-impl-inherit.cov-map b/tests/coverage/attr/trait-impl-inherit.cov-map new file mode 100644 index 0000000000000..eab9f926bb776 --- /dev/null +++ b/tests/coverage/attr/trait-impl-inherit.cov-map @@ -0,0 +1,9 @@ +Function name: ::f +Raw bytes (9): 0x[01, 01, 00, 01, 01, 11, 05, 02, 06] +Number of files: 1 +- file 0 => global file 1 +Number of expressions: 0 +Number of file 0 mappings: 1 +- Code(Counter(0)) at (prev + 17, 5) to (start + 2, 6) +Highest counter ID seen: c0 + diff --git a/tests/coverage/attr/trait-impl-inherit.coverage b/tests/coverage/attr/trait-impl-inherit.coverage new file mode 100644 index 0000000000000..b92d82aefbc8c --- /dev/null +++ b/tests/coverage/attr/trait-impl-inherit.coverage @@ -0,0 +1,26 @@ + LL| |#![feature(coverage_attribute)] + LL| |// Checks that `#[coverage(..)]` in a trait method is not inherited in an + LL| |// implementation. + LL| |//@ edition: 2021 + LL| |//@ reference: attributes.coverage.trait-impl-inherit + LL| | + LL| |trait T { + LL| | #[coverage(off)] + LL| | fn f(&self) { + LL| | println!("default"); + LL| | } + LL| |} + LL| | + LL| |struct S; + LL| | + LL| |impl T for S { + LL| 1| fn f(&self) { + LL| 1| println!("impl S"); + LL| 1| } + LL| |} + LL| | + LL| |#[coverage(off)] + LL| |fn main() { + LL| | S.f(); + LL| |} + diff --git a/tests/coverage/attr/trait-impl-inherit.rs b/tests/coverage/attr/trait-impl-inherit.rs new file mode 100644 index 0000000000000..951fecce90a18 --- /dev/null +++ b/tests/coverage/attr/trait-impl-inherit.rs @@ -0,0 +1,25 @@ +#![feature(coverage_attribute)] +// Checks that `#[coverage(..)]` in a trait method is not inherited in an +// implementation. +//@ edition: 2021 +//@ reference: attributes.coverage.trait-impl-inherit + +trait T { + #[coverage(off)] + fn f(&self) { + println!("default"); + } +} + +struct S; + +impl T for S { + fn f(&self) { + println!("impl S"); + } +} + +#[coverage(off)] +fn main() { + S.f(); +} From 5d9f17f58c35503aeef74046d9d7d8521e265ba1 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Thu, 19 Dec 2024 06:51:07 -0800 Subject: [PATCH 10/10] Add test for coverage on a body-less trait function --- tests/ui/coverage-attr/no-coverage.rs | 9 ++++++ tests/ui/coverage-attr/no-coverage.stderr | 36 ++++++++++++++++------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/tests/ui/coverage-attr/no-coverage.rs b/tests/ui/coverage-attr/no-coverage.rs index d715ec8a3028e..c386f25816e4c 100644 --- a/tests/ui/coverage-attr/no-coverage.rs +++ b/tests/ui/coverage-attr/no-coverage.rs @@ -15,6 +15,12 @@ trait Trait { type T; type U; + + #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure + fn f(&self); + + #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure + fn g(); } #[coverage(off)] @@ -26,6 +32,9 @@ impl Trait for () { #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure type U = impl Trait; //~ ERROR unconstrained opaque type + + fn f(&self) {} + fn g() {} } extern "C" { diff --git a/tests/ui/coverage-attr/no-coverage.stderr b/tests/ui/coverage-attr/no-coverage.stderr index 1412b54b8d778..f5a44ecec747f 100644 --- a/tests/ui/coverage-attr/no-coverage.stderr +++ b/tests/ui/coverage-attr/no-coverage.stderr @@ -7,12 +7,12 @@ LL | / trait Trait { LL | | #[coverage(off)] LL | | const X: u32; ... | -LL | | type U; +LL | | fn g(); LL | | } | |_- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/no-coverage.rs:41:5 + --> $DIR/no-coverage.rs:50:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -20,7 +20,7 @@ LL | let _ = (); | ----------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/no-coverage.rs:45:9 + --> $DIR/no-coverage.rs:54:9 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -28,7 +28,7 @@ LL | () => (), | -------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/no-coverage.rs:49:5 + --> $DIR/no-coverage.rs:58:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -52,7 +52,23 @@ LL | type T; | ------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/no-coverage.rs:24:5 + --> $DIR/no-coverage.rs:19:5 + | +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ +LL | fn f(&self); + | ------------ not a function or closure + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/no-coverage.rs:22:5 + | +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ +LL | fn g(); + | ------- not a function or closure + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/no-coverage.rs:30:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -60,7 +76,7 @@ LL | type T = Self; | -------------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/no-coverage.rs:27:5 + --> $DIR/no-coverage.rs:33:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -68,7 +84,7 @@ LL | type U = impl Trait; | -------------------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/no-coverage.rs:32:5 + --> $DIR/no-coverage.rs:41:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -76,7 +92,7 @@ LL | static X: u32; | -------------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/no-coverage.rs:35:5 + --> $DIR/no-coverage.rs:44:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -84,13 +100,13 @@ LL | type T; | ------- not a function or closure error: unconstrained opaque type - --> $DIR/no-coverage.rs:28:14 + --> $DIR/no-coverage.rs:34:14 | LL | type U = impl Trait; | ^^^^^^^^^^ | = note: `U` must be used in combination with a concrete type within the same impl -error: aborting due to 11 previous errors +error: aborting due to 13 previous errors For more information about this error, try `rustc --explain E0788`.