Skip to content

Commit

Permalink
Auto merge of rust-lang#134687 - matthiaskrgr:rollup-m32tkax, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#134363 (Use `#[derive(Default)]` instead of manual `impl` when possible)
 - rust-lang#134517 (Add tests for coverage attribute on trait functions)
 - rust-lang#134528 (opt-dist: propagate channel info to bootstrap)
 - rust-lang#134669 (Document the `--dev` flag for `src/ci/docker/run.sh`)
 - rust-lang#134680 (Clean up a few rmake tests  )

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 23, 2024
2 parents 904d8f6 + a16fc10 commit addbd00
Show file tree
Hide file tree
Showing 31 changed files with 152 additions and 116 deletions.
19 changes: 3 additions & 16 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -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<GenericParam>,
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.
///
Expand All @@ -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 {
Expand Down
18 changes: 3 additions & 15 deletions compiler/rustc_ast_pretty/src/pprust/state/fixup.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,19 +1023,14 @@ 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
/// `1 as i32 < 2` parses to i32::<2[missing angle bracket]
parens_in_cast_in_lt: Vec<ast::NodeId>,
}

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 {
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
15 changes: 3 additions & 12 deletions library/core/tests/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -107,6 +102,8 @@ fn test_writer_hasher() {
struct Custom {
hash: u64,
}

#[derive(Default)]
struct CustomHasher {
output: u64,
}
Expand All @@ -123,12 +120,6 @@ impl Hasher for CustomHasher {
}
}

impl Default for CustomHasher {
fn default() -> CustomHasher {
CustomHasher { output: 0 }
}
}

impl Hash for Custom {
fn hash<H: Hasher>(&self, state: &mut H) {
state.write_u64(self.hash);
Expand Down
8 changes: 1 addition & 7 deletions library/proc_macro/src/bridge/fxhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
/// 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,
}
Expand All @@ -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) {
Expand Down
9 changes: 2 additions & 7 deletions library/std/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ extern "C" fn __rust_foreign_exception() -> ! {
rtabort!("Rust cannot catch foreign exceptions");
}

#[derive(Default)]
enum Hook {
#[default]
Default,
Custom(Box<dyn Fn(&PanicHookInfo<'_>) + 'static + Sync + Send>),
}
Expand All @@ -96,13 +98,6 @@ impl Hook {
}
}

impl Default for Hook {
#[inline]
fn default() -> Hook {
Hook::Default
}
}

static HOOK: RwLock<Hook> = RwLock::new(Hook::Default);

/// Registers a custom panic hook, replacing the previously registered hook.
Expand Down
8 changes: 1 addition & 7 deletions library/std/src/sys_common/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EnvKey, Option<OsString>>,
}

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");
Expand Down
4 changes: 4 additions & 0 deletions src/ci/docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion src/tools/opt-dist/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}"))?
Expand Down Expand Up @@ -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}"
Expand Down Expand Up @@ -116,3 +122,13 @@ fn find_dist_version(directory: &Utf8Path) -> anyhow::Result<String> {
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",
}
}
9 changes: 9 additions & 0 deletions tests/coverage/attr/trait-impl-inherit.cov-map
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Function name: <trait_impl_inherit::S as trait_impl_inherit::T>::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

26 changes: 26 additions & 0 deletions tests/coverage/attr/trait-impl-inherit.coverage
Original file line number Diff line number Diff line change
@@ -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| |}

25 changes: 25 additions & 0 deletions tests/coverage/attr/trait-impl-inherit.rs
Original file line number Diff line number Diff line change
@@ -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();
}
2 changes: 1 addition & 1 deletion tests/run-make/dump-ice-to-disk/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn extract_exactly_one_ice_file<P: AsRef<Path>>(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());
Expand Down
2 changes: 1 addition & 1 deletion tests/run-make/embed-source-dwarf/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
2 changes: 1 addition & 1 deletion tests/run-make/import-macro-verbatim/verbatim.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/run-make/libstd-no-protected/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Endianness>;
Expand Down
5 changes: 1 addition & 4 deletions tests/run-make/libtest-thread-limit/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions tests/run-make/llvm-outputs/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading

0 comments on commit addbd00

Please sign in to comment.