Skip to content

Commit 54b4d06

Browse files
committed
Auto merge of rust-lang#134687 - matthiaskrgr:rollup-m32tkax, r=matthiaskrgr
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
2 parents 904d8f6 + a16fc10 commit 54b4d06

File tree

31 files changed

+152
-116
lines changed

31 files changed

+152
-116
lines changed

compiler/rustc_ast/src/ast.rs

+3-16
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use rustc_data_structures::sync::Lrc;
3131
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
3232
pub use rustc_span::AttrId;
3333
use rustc_span::source_map::{Spanned, respan};
34-
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
34+
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
3535
use thin_vec::{ThinVec, thin_vec};
3636

3737
pub use crate::format::*;
@@ -387,22 +387,15 @@ impl GenericParam {
387387

388388
/// Represents lifetime, type and const parameters attached to a declaration of
389389
/// a function, enum, trait, etc.
390-
#[derive(Clone, Encodable, Decodable, Debug)]
390+
#[derive(Clone, Encodable, Decodable, Debug, Default)]
391391
pub struct Generics {
392392
pub params: ThinVec<GenericParam>,
393393
pub where_clause: WhereClause,
394394
pub span: Span,
395395
}
396396

397-
impl Default for Generics {
398-
/// Creates an instance of `Generics`.
399-
fn default() -> Generics {
400-
Generics { params: ThinVec::new(), where_clause: Default::default(), span: DUMMY_SP }
401-
}
402-
}
403-
404397
/// A where-clause in a definition.
405-
#[derive(Clone, Encodable, Decodable, Debug)]
398+
#[derive(Clone, Encodable, Decodable, Debug, Default)]
406399
pub struct WhereClause {
407400
/// `true` if we ate a `where` token.
408401
///
@@ -419,12 +412,6 @@ impl WhereClause {
419412
}
420413
}
421414

422-
impl Default for WhereClause {
423-
fn default() -> WhereClause {
424-
WhereClause { has_where_token: false, predicates: ThinVec::new(), span: DUMMY_SP }
425-
}
426-
}
427-
428415
/// A single predicate in a where-clause.
429416
#[derive(Clone, Encodable, Decodable, Debug)]
430417
pub struct WherePredicate {

compiler/rustc_ast_pretty/src/pprust/state/fixup.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use rustc_ast::Expr;
22
use rustc_ast::util::{classify, parser};
33

4-
#[derive(Copy, Clone, Debug)]
4+
// The default amount of fixing is minimal fixing, so all fixups are set to `false` by `Default`.
5+
// Fixups should be turned on in a targeted fashion where needed.
6+
#[derive(Copy, Clone, Debug, Default)]
57
pub(crate) struct FixupContext {
68
/// Print expression such that it can be parsed back as a statement
79
/// consisting of the original expression.
@@ -93,20 +95,6 @@ pub(crate) struct FixupContext {
9395
parenthesize_exterior_struct_lit: bool,
9496
}
9597

96-
/// The default amount of fixing is minimal fixing. Fixups should be turned on
97-
/// in a targeted fashion where needed.
98-
impl Default for FixupContext {
99-
fn default() -> Self {
100-
FixupContext {
101-
stmt: false,
102-
leftmost_subexpression_in_stmt: false,
103-
match_arm: false,
104-
leftmost_subexpression_in_match_arm: false,
105-
parenthesize_exterior_struct_lit: false,
106-
}
107-
}
108-
}
109-
11098
impl FixupContext {
11199
/// Create the initial fixup for printing an expression in statement
112100
/// position.

compiler/rustc_lint/src/unused.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1023,19 +1023,14 @@ declare_lint! {
10231023
"`if`, `match`, `while` and `return` do not need parentheses"
10241024
}
10251025

1026+
#[derive(Default)]
10261027
pub(crate) struct UnusedParens {
10271028
with_self_ty_parens: bool,
10281029
/// `1 as (i32) < 2` parses to ExprKind::Lt
10291030
/// `1 as i32 < 2` parses to i32::<2[missing angle bracket]
10301031
parens_in_cast_in_lt: Vec<ast::NodeId>,
10311032
}
10321033

1033-
impl Default for UnusedParens {
1034-
fn default() -> Self {
1035-
Self { with_self_ty_parens: false, parens_in_cast_in_lt: Vec::new() }
1036-
}
1037-
}
1038-
10391034
impl_lint_pass!(UnusedParens => [UNUSED_PARENS]);
10401035

10411036
impl UnusedDelimLint for UnusedParens {

compiler/rustc_session/src/config.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,10 @@ pub struct CoverageOptions {
168168
}
169169

170170
/// Controls whether branch coverage or MC/DC coverage is enabled.
171-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
171+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
172172
pub enum CoverageLevel {
173173
/// Instrument for coverage at the MIR block level.
174+
#[default]
174175
Block,
175176
/// Also instrument branch points (includes block coverage).
176177
Branch,
@@ -195,12 +196,6 @@ pub enum CoverageLevel {
195196
Mcdc,
196197
}
197198

198-
impl Default for CoverageLevel {
199-
fn default() -> Self {
200-
Self::Block
201-
}
202-
}
203-
204199
/// Settings for `-Z instrument-xray` flag.
205200
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
206201
pub struct InstrumentXRay {

library/core/tests/hash/mod.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@ use std::hash::{BuildHasher, Hash, Hasher};
44
use std::ptr;
55
use std::rc::Rc;
66

7+
#[derive(Default)]
78
struct MyHasher {
89
hash: u64,
910
}
1011

11-
impl Default for MyHasher {
12-
fn default() -> MyHasher {
13-
MyHasher { hash: 0 }
14-
}
15-
}
16-
1712
impl Hasher for MyHasher {
1813
fn write(&mut self, buf: &[u8]) {
1914
for byte in buf {
@@ -107,6 +102,8 @@ fn test_writer_hasher() {
107102
struct Custom {
108103
hash: u64,
109104
}
105+
106+
#[derive(Default)]
110107
struct CustomHasher {
111108
output: u64,
112109
}
@@ -123,12 +120,6 @@ impl Hasher for CustomHasher {
123120
}
124121
}
125122

126-
impl Default for CustomHasher {
127-
fn default() -> CustomHasher {
128-
CustomHasher { output: 0 }
129-
}
130-
}
131-
132123
impl Hash for Custom {
133124
fn hash<H: Hasher>(&self, state: &mut H) {
134125
state.write_u64(self.hash);

library/proc_macro/src/bridge/fxhash.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
2222
/// out-performs an FNV-based hash within rustc itself -- the collision rate is
2323
/// similar or slightly worse than FNV, but the speed of the hash function
2424
/// itself is much higher because it works on up to 8 bytes at a time.
25+
#[derive(Default)]
2526
pub struct FxHasher {
2627
hash: usize,
2728
}
@@ -31,13 +32,6 @@ const K: usize = 0x9e3779b9;
3132
#[cfg(target_pointer_width = "64")]
3233
const K: usize = 0x517cc1b727220a95;
3334

34-
impl Default for FxHasher {
35-
#[inline]
36-
fn default() -> FxHasher {
37-
FxHasher { hash: 0 }
38-
}
39-
}
40-
4135
impl FxHasher {
4236
#[inline]
4337
fn add_to_hash(&mut self, i: usize) {

library/std/src/panicking.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ extern "C" fn __rust_foreign_exception() -> ! {
8181
rtabort!("Rust cannot catch foreign exceptions");
8282
}
8383

84+
#[derive(Default)]
8485
enum Hook {
86+
#[default]
8587
Default,
8688
Custom(Box<dyn Fn(&PanicHookInfo<'_>) + 'static + Sync + Send>),
8789
}
@@ -96,13 +98,6 @@ impl Hook {
9698
}
9799
}
98100

99-
impl Default for Hook {
100-
#[inline]
101-
fn default() -> Hook {
102-
Hook::Default
103-
}
104-
}
105-
106101
static HOOK: RwLock<Hook> = RwLock::new(Hook::Default);
107102

108103
/// Registers a custom panic hook, replacing the previously registered hook.

library/std/src/sys_common/process.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,13 @@ use crate::sys::process::{EnvKey, ExitStatus, Process, StdioPipes};
88
use crate::{env, fmt, io};
99

1010
// Stores a set of changes to an environment
11-
#[derive(Clone)]
11+
#[derive(Clone, Default)]
1212
pub struct CommandEnv {
1313
clear: bool,
1414
saw_path: bool,
1515
vars: BTreeMap<EnvKey, Option<OsString>>,
1616
}
1717

18-
impl Default for CommandEnv {
19-
fn default() -> Self {
20-
CommandEnv { clear: false, saw_path: false, vars: Default::default() }
21-
}
22-
}
23-
2418
impl fmt::Debug for CommandEnv {
2519
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2620
let mut debug_command_env = f.debug_struct("CommandEnv");

src/ci/docker/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ DEPLOY=1 ./src/ci/docker/run.sh x86_64-gnu
2626
while locally, to the `obj/$image_name` directory. This is primarily to prevent
2727
strange linker errors when using multiple Docker images.
2828

29+
## Local Development
30+
31+
Refer to the [dev guide](https://rustc-dev-guide.rust-lang.org/tests/docker.html) for more information on testing locally.
32+
2933
## Filesystem layout
3034

3135
- Each host architecture has its own `host-{arch}` directory, and those

src/tools/opt-dist/src/tests.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub fn run_tests(env: &Environment) -> anyhow::Result<()> {
2525
let host_triple = env.host_tuple();
2626
let version = find_dist_version(&dist_dir)?;
2727

28+
let channel = version_to_channel(&version);
29+
2830
// Extract rustc, libstd, cargo and src archives to create the optimized sysroot
2931
let rustc_dir = extract_dist_dir(&format!("rustc-{version}-{host_triple}"))?.join("rustc");
3032
let libstd_dir = extract_dist_dir(&format!("rust-std-{version}-{host_triple}"))?
@@ -61,9 +63,13 @@ pub fn run_tests(env: &Environment) -> anyhow::Result<()> {
6163
assert!(llvm_config.is_file());
6264

6365
let config_content = format!(
64-
r#"profile = "user"
66+
r#"
67+
profile = "user"
6568
change-id = 115898
6669
70+
[rust]
71+
channel = "{channel}"
72+
6773
[build]
6874
rustc = "{rustc}"
6975
cargo = "{cargo}"
@@ -116,3 +122,13 @@ fn find_dist_version(directory: &Utf8Path) -> anyhow::Result<String> {
116122
archive.strip_prefix("reproducible-artifacts-").unwrap().split_once('-').unwrap();
117123
Ok(version.to_string())
118124
}
125+
126+
/// Roughly convert a version string (`nightly`, `beta`, or `1.XY.Z`) to channel string (`nightly`,
127+
/// `beta` or `stable`).
128+
fn version_to_channel(version_str: &str) -> &'static str {
129+
match version_str {
130+
"nightly" => "nightly",
131+
"beta" => "beta",
132+
_ => "stable",
133+
}
134+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Function name: <trait_impl_inherit::S as trait_impl_inherit::T>::f
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 11, 05, 02, 06]
3+
Number of files: 1
4+
- file 0 => global file 1
5+
Number of expressions: 0
6+
Number of file 0 mappings: 1
7+
- Code(Counter(0)) at (prev + 17, 5) to (start + 2, 6)
8+
Highest counter ID seen: c0
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |// Checks that `#[coverage(..)]` in a trait method is not inherited in an
3+
LL| |// implementation.
4+
LL| |//@ edition: 2021
5+
LL| |//@ reference: attributes.coverage.trait-impl-inherit
6+
LL| |
7+
LL| |trait T {
8+
LL| | #[coverage(off)]
9+
LL| | fn f(&self) {
10+
LL| | println!("default");
11+
LL| | }
12+
LL| |}
13+
LL| |
14+
LL| |struct S;
15+
LL| |
16+
LL| |impl T for S {
17+
LL| 1| fn f(&self) {
18+
LL| 1| println!("impl S");
19+
LL| 1| }
20+
LL| |}
21+
LL| |
22+
LL| |#[coverage(off)]
23+
LL| |fn main() {
24+
LL| | S.f();
25+
LL| |}
26+
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#![feature(coverage_attribute)]
2+
// Checks that `#[coverage(..)]` in a trait method is not inherited in an
3+
// implementation.
4+
//@ edition: 2021
5+
//@ reference: attributes.coverage.trait-impl-inherit
6+
7+
trait T {
8+
#[coverage(off)]
9+
fn f(&self) {
10+
println!("default");
11+
}
12+
}
13+
14+
struct S;
15+
16+
impl T for S {
17+
fn f(&self) {
18+
println!("impl S");
19+
}
20+
}
21+
22+
#[coverage(off)]
23+
fn main() {
24+
S.f();
25+
}

tests/run-make/dump-ice-to-disk/rmake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn extract_exactly_one_ice_file<P: AsRef<Path>>(name: &'static str, dir: P) -> I
8383

8484
fn main() {
8585
// Establish baseline ICE message.
86-
let mut default_ice_dump = OnceCell::new();
86+
let default_ice_dump = OnceCell::new();
8787
run_in_tmpdir(|| {
8888
rustc().env("RUSTC_ICE", cwd()).input("lib.rs").arg("-Ztreat-err-as-bug=1").run_fail();
8989
let dump = extract_exactly_one_ice_file("baseline", cwd());

tests/run-make/embed-source-dwarf/rmake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::collections::HashMap;
1010
use std::path::PathBuf;
1111
use std::rc::Rc;
1212

13-
use gimli::{AttributeValue, EndianRcSlice, Reader, RunTimeEndian};
13+
use gimli::{EndianRcSlice, Reader, RunTimeEndian};
1414
use object::{Object, ObjectSection};
1515
use run_make_support::{gimli, object, rfs, rustc};
1616

tests/run-make/import-macro-verbatim/verbatim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Include a file by concating the verbatim path using `/` instead of `\`
1+
//! Include a file by concatenating the verbatim path using `/` instead of `\`
22
33
include!(concat!(env!("VERBATIM_DIR"), "/include/include.txt"));
44
fn main() {

tests/run-make/libstd-no-protected/rmake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use run_make_support::object::Endianness;
88
use run_make_support::object::read::archive::ArchiveFile;
99
use run_make_support::object::read::elf::{FileHeader as _, SectionHeader as _};
10-
use run_make_support::rfs::{read, read_dir};
10+
use run_make_support::rfs::read;
1111
use run_make_support::{has_prefix, has_suffix, object, path, rustc, shallow_find_files, target};
1212

1313
type FileHeader = run_make_support::object::elf::FileHeader64<Endianness>;

tests/run-make/libtest-thread-limit/rmake.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
// Reason: this should be ignored in cg_clif (Cranelift) CI and anywhere
1616
// else that uses panic=abort.
1717

18-
use std::ffi::{self, CStr, CString};
19-
use std::path::PathBuf;
20-
21-
use run_make_support::{libc, run, rustc};
18+
use run_make_support::{libc, rustc};
2219

2320
fn main() {
2421
rustc().input("test.rs").arg("--test").run();

tests/run-make/llvm-outputs/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ fn main() {
99
let mut path_ir = PathBuf::new();
1010
run_in_tmpdir(|| {
1111
let p = cwd();
12-
path_bc = p.join("nonexistant_dir_bc");
13-
path_ir = p.join("nonexistant_dir_ir");
12+
path_bc = p.join("nonexistent_dir_bc");
13+
path_ir = p.join("nonexistent_dir_ir");
1414
rustc().input("-").stdin_buf("fn main() {}").out_dir(&path_bc).emit("llvm-bc").run();
1515
rustc().input("-").stdin_buf("fn main() {}").out_dir(&path_ir).emit("llvm-ir").run();
1616
assert!(path_bc.exists());

0 commit comments

Comments
 (0)