From a0fe4138ed83b9c3f6e1c85ef6e6a0846b1e542d Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Wed, 3 Jan 2024 17:39:16 +0100 Subject: [PATCH 1/9] Replace visibility test with reachability test in dead code detection Fixes https://github.com/rust-lang/rust/issues/119545 --- compiler/rustc_passes/src/dead.rs | 5 +++-- tests/ui/lint/dead-code/pub-field-in-priv-mod.rs | 11 +++++++++++ .../lint/dead-code/pub-field-in-priv-mod.stderr | 16 ++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/ui/lint/dead-code/pub-field-in-priv-mod.rs create mode 100644 tests/ui/lint/dead-code/pub-field-in-priv-mod.stderr diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index cdfde2b9405..15b4df45b01 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -529,15 +529,16 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> { let tcx = self.tcx; let unconditionally_treat_fields_as_live = self.repr_unconditionally_treats_fields_as_live; let has_repr_simd = self.repr_has_repr_simd; + let effective_visibilities = &tcx.effective_visibilities(()); let live_fields = def.fields().iter().filter_map(|f| { let def_id = f.def_id; if unconditionally_treat_fields_as_live || (f.is_positional() && has_repr_simd) { return Some(def_id); } - if !tcx.visibility(f.hir_id.owner.def_id).is_public() { + if !effective_visibilities.is_reachable(f.hir_id.owner.def_id) { return None; } - if tcx.visibility(def_id).is_public() { Some(def_id) } else { None } + if effective_visibilities.is_reachable(def_id) { Some(def_id) } else { None } }); self.live_symbols.extend(live_fields); diff --git a/tests/ui/lint/dead-code/pub-field-in-priv-mod.rs b/tests/ui/lint/dead-code/pub-field-in-priv-mod.rs new file mode 100644 index 00000000000..e49a164e940 --- /dev/null +++ b/tests/ui/lint/dead-code/pub-field-in-priv-mod.rs @@ -0,0 +1,11 @@ +#![deny(dead_code)] + +fn main() { + let _ = foo::S{f: false}; +} + +mod foo { + pub struct S { + pub f: bool, //~ ERROR field `f` is never read + } +} diff --git a/tests/ui/lint/dead-code/pub-field-in-priv-mod.stderr b/tests/ui/lint/dead-code/pub-field-in-priv-mod.stderr new file mode 100644 index 00000000000..11dd387315f --- /dev/null +++ b/tests/ui/lint/dead-code/pub-field-in-priv-mod.stderr @@ -0,0 +1,16 @@ +error: field `f` is never read + --> $DIR/pub-field-in-priv-mod.rs:9:13 + | +LL | pub struct S { + | - field in this struct +LL | pub f: bool, + | ^ + | +note: the lint level is defined here + --> $DIR/pub-field-in-priv-mod.rs:1:9 + | +LL | #![deny(dead_code)] + | ^^^^^^^^^ + +error: aborting due to 1 previous error + From ccd99b384e3fcd4b1f53f471cced72647bc7c445 Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Wed, 3 Jan 2024 17:45:41 +0100 Subject: [PATCH 2/9] Remove unused fields in some structures The dead_code lint was previously eroneously missing those. Since this lint bug has been fixed, the unused fields need to be removed. --- compiler/rustc_borrowck/src/region_infer/mod.rs | 2 -- compiler/rustc_builtin_macros/src/deriving/debug.rs | 2 +- .../rustc_builtin_macros/src/deriving/encodable.rs | 2 +- .../rustc_builtin_macros/src/deriving/generic/mod.rs | 10 +++++----- compiler/rustc_codegen_llvm/src/context.rs | 6 +----- compiler/rustc_mir_transform/src/gvn.rs | 2 +- compiler/rustc_mir_transform/src/ssa.rs | 5 ++--- library/alloc/src/collections/btree/navigate.rs | 6 +++--- library/alloc/src/collections/btree/node/tests.rs | 6 +----- library/test/src/console.rs | 9 +-------- 10 files changed, 16 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index c3800a1f1f2..54c516c960c 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -2065,7 +2065,6 @@ impl<'tcx> RegionInferenceContext<'tcx> { from_closure: constraint.from_closure, cause: ObligationCause::new(constraint.span, CRATE_DEF_ID, cause_code.clone()), variance_info: constraint.variance_info, - outlives_constraint: *constraint, }) .collect(); debug!("categorized_path={:#?}", categorized_path); @@ -2294,5 +2293,4 @@ pub struct BlameConstraint<'tcx> { pub from_closure: bool, pub cause: ObligationCause<'tcx>, pub variance_info: ty::VarianceDiagInfo<'tcx>, - pub outlives_constraint: OutlivesConstraint<'tcx>, } diff --git a/compiler/rustc_builtin_macros/src/deriving/debug.rs b/compiler/rustc_builtin_macros/src/deriving/debug.rs index b11a1b6cda1..325604ee4f5 100644 --- a/compiler/rustc_builtin_macros/src/deriving/debug.rs +++ b/compiler/rustc_builtin_macros/src/deriving/debug.rs @@ -52,7 +52,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_> let (ident, vdata, fields) = match substr.fields { Struct(vdata, fields) => (substr.type_ident, *vdata, fields), - EnumMatching(_, _, v, fields) => (v.ident, &v.data, fields), + EnumMatching(_, v, fields) => (v.ident, &v.data, fields), AllFieldlessEnum(enum_def) => return show_fieldless_enum(cx, span, enum_def, substr), EnumTag(..) | StaticStruct(..) | StaticEnum(..) => { cx.dcx().span_bug(span, "nonsensical .fields in `#[derive(Debug)]`") diff --git a/compiler/rustc_builtin_macros/src/deriving/encodable.rs b/compiler/rustc_builtin_macros/src/deriving/encodable.rs index 14d93a8cc23..d939f8c7aeb 100644 --- a/compiler/rustc_builtin_macros/src/deriving/encodable.rs +++ b/compiler/rustc_builtin_macros/src/deriving/encodable.rs @@ -226,7 +226,7 @@ fn encodable_substructure( BlockOrExpr::new_expr(expr) } - EnumMatching(idx, _, variant, fields) => { + EnumMatching(idx, variant, fields) => { // We're not generating an AST that the borrow checker is expecting, // so we need to generate a unique local variable to take the // mutable loan out on, otherwise we get conflicts which don't diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index 3cb3e30daa7..afa73b672da 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -310,10 +310,10 @@ pub enum SubstructureFields<'a> { /// variants has any fields). AllFieldlessEnum(&'a ast::EnumDef), - /// Matching variants of the enum: variant index, variant count, ast::Variant, + /// Matching variants of the enum: variant index, ast::Variant, /// fields: the field name is only non-`None` in the case of a struct /// variant. - EnumMatching(usize, usize, &'a ast::Variant, Vec), + EnumMatching(usize, &'a ast::Variant, Vec), /// The tag of an enum. The first field is a `FieldInfo` for the tags, as /// if they were fields. The second field is the expression to combine the @@ -1272,7 +1272,7 @@ impl<'a> MethodDef<'a> { trait_, type_ident, nonselflike_args, - &EnumMatching(0, 1, &variants[0], Vec::new()), + &EnumMatching(0, &variants[0], Vec::new()), ); } } @@ -1318,7 +1318,7 @@ impl<'a> MethodDef<'a> { // expressions for referencing every field of every // Self arg, assuming all are instances of VariantK. // Build up code associated with such a case. - let substructure = EnumMatching(index, variants.len(), variant, fields); + let substructure = EnumMatching(index, variant, fields); let arm_expr = self .call_substructure_method( cx, @@ -1346,7 +1346,7 @@ impl<'a> MethodDef<'a> { trait_, type_ident, nonselflike_args, - &EnumMatching(0, variants.len(), v, Vec::new()), + &EnumMatching(0, v, Vec::new()), ) .into_expr(cx, span), ) diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index f89c8c9f836..3d36a146959 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -27,9 +27,7 @@ use rustc_session::config::{CrateType, DebugInfo, PAuthKey, PacRet}; use rustc_session::Session; use rustc_span::source_map::Spanned; use rustc_span::Span; -use rustc_target::abi::{ - call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx, -}; +use rustc_target::abi::{call::FnAbi, HasDataLayout, TargetDataLayout, VariantIdx}; use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel}; use smallvec::SmallVec; @@ -83,7 +81,6 @@ pub struct CodegenCx<'ll, 'tcx> { /// Mapping of scalar types to llvm types. pub scalar_lltypes: RefCell, &'ll Type>>, - pub pointee_infos: RefCell, Size), Option>>, pub isize_ty: &'ll Type, pub coverage_cx: Option>, @@ -460,7 +457,6 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { compiler_used_statics: RefCell::new(Vec::new()), type_lowering: Default::default(), scalar_lltypes: Default::default(), - pointee_infos: Default::default(), isize_ty, coverage_cx, dbg_cx, diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index a3a2108787a..2f960148ca5 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -131,7 +131,7 @@ fn propagate_ssa<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { |local, value, location| { let value = match value { // We do not know anything of this assigned value. - AssignedValue::Arg | AssignedValue::Terminator(_) => None, + AssignedValue::Arg | AssignedValue::Terminator => None, // Try to get some insight. AssignedValue::Rvalue(rvalue) => { let value = state.simplify_rvalue(rvalue, location); diff --git a/compiler/rustc_mir_transform/src/ssa.rs b/compiler/rustc_mir_transform/src/ssa.rs index e4fdbd6ae69..fddc62e6652 100644 --- a/compiler/rustc_mir_transform/src/ssa.rs +++ b/compiler/rustc_mir_transform/src/ssa.rs @@ -29,7 +29,7 @@ pub struct SsaLocals { pub enum AssignedValue<'a, 'tcx> { Arg, Rvalue(&'a mut Rvalue<'tcx>), - Terminator(&'a mut TerminatorKind<'tcx>), + Terminator, } impl SsaLocals { @@ -149,8 +149,7 @@ impl SsaLocals { Set1::One(DefLocation::CallReturn { call, .. }) => { let bb = &mut basic_blocks[call]; let loc = Location { block: call, statement_index: bb.statements.len() }; - let term = bb.terminator_mut(); - f(local, AssignedValue::Terminator(&mut term.kind), loc) + f(local, AssignedValue::Terminator, loc) } _ => {} } diff --git a/library/alloc/src/collections/btree/navigate.rs b/library/alloc/src/collections/btree/navigate.rs index a85a3162451..5e6a26f65c4 100644 --- a/library/alloc/src/collections/btree/navigate.rs +++ b/library/alloc/src/collections/btree/navigate.rs @@ -655,7 +655,7 @@ impl NodeRef { Leaf(NodeRef), Internal(NodeRef), - InternalKV(Handle, marker::KV>), + InternalKV, } impl<'a, K: 'a, V: 'a> NodeRef, K, V, marker::LeafOrInternal> { @@ -677,7 +677,7 @@ impl<'a, K: 'a, V: 'a> NodeRef, K, V, marker::LeafOrInternal> visit(Position::Leaf(leaf)); match edge.next_kv() { Ok(kv) => { - visit(Position::InternalKV(kv)); + visit(Position::InternalKV); kv.right_edge() } Err(_) => return, @@ -699,7 +699,7 @@ impl<'a, K: 'a, V: 'a> NodeRef, K, V, marker::LeafOrInternal> self.visit_nodes_in_order(|pos| match pos { Position::Leaf(node) => result += node.len(), Position::Internal(node) => result += node.len(), - Position::InternalKV(_) => (), + Position::InternalKV => (), }); result } diff --git a/library/alloc/src/collections/btree/node/tests.rs b/library/alloc/src/collections/btree/node/tests.rs index 64bce0ff8c0..d230749d712 100644 --- a/library/alloc/src/collections/btree/node/tests.rs +++ b/library/alloc/src/collections/btree/node/tests.rs @@ -32,11 +32,7 @@ impl<'a, K: 'a, V: 'a> NodeRef, K, V, marker::LeafOrInternal> result += &format!("\n{}{:?}", indent, leaf.keys()); } navigate::Position::Internal(_) => {} - navigate::Position::InternalKV(kv) => { - let depth = self.height() - kv.into_node().height(); - let indent = " ".repeat(depth); - result += &format!("\n{}{:?}", indent, kv.into_kv().0); - } + navigate::Position::InternalKV => {} }); result } diff --git a/library/test/src/console.rs b/library/test/src/console.rs index 8096e498263..f3918ba333a 100644 --- a/library/test/src/console.rs +++ b/library/test/src/console.rs @@ -46,7 +46,6 @@ pub struct ConsoleTestDiscoveryState { pub tests: usize, pub benchmarks: usize, pub ignored: usize, - pub options: Options, } impl ConsoleTestDiscoveryState { @@ -56,13 +55,7 @@ impl ConsoleTestDiscoveryState { None => None, }; - Ok(ConsoleTestDiscoveryState { - log_out, - tests: 0, - benchmarks: 0, - ignored: 0, - options: opts.options, - }) + Ok(ConsoleTestDiscoveryState { log_out, tests: 0, benchmarks: 0, ignored: 0 }) } pub fn write_log(&mut self, msg: F) -> io::Result<()> From 701dd5bc9d648f5aa2579103b9f8fae4b54f141a Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Tue, 20 Feb 2024 21:20:14 +0100 Subject: [PATCH 3/9] Allow unused fields in some tests The dead_code lint was previously eroneously missing those. Since this lint bug has been fixed, the unused fields warnings need to be fixed. Most of them are marked as `#[allow(dead_code)]`. Other warnings are fixed by changing visibility of modules. --- tests/ui/impl-not-adjacent-to-type.rs | 1 + tests/ui/privacy/suggest-making-field-public.fixed | 2 +- tests/ui/privacy/suggest-making-field-public.rs | 2 +- tests/ui/union/union-macro.rs | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/ui/impl-not-adjacent-to-type.rs b/tests/ui/impl-not-adjacent-to-type.rs index 7fc927b1d64..ccf59ed4393 100644 --- a/tests/ui/impl-not-adjacent-to-type.rs +++ b/tests/ui/impl-not-adjacent-to-type.rs @@ -3,6 +3,7 @@ mod foo { pub struct Point { pub x: i32, + #[allow(dead_code)] pub y: i32, } } diff --git a/tests/ui/privacy/suggest-making-field-public.fixed b/tests/ui/privacy/suggest-making-field-public.fixed index 29dcde88ab4..8a5686aa5e1 100644 --- a/tests/ui/privacy/suggest-making-field-public.fixed +++ b/tests/ui/privacy/suggest-making-field-public.fixed @@ -1,5 +1,5 @@ //@ run-rustfix -mod a { +pub mod a { pub struct A(pub String); } diff --git a/tests/ui/privacy/suggest-making-field-public.rs b/tests/ui/privacy/suggest-making-field-public.rs index c9f04757b2f..63fdb0bce6a 100644 --- a/tests/ui/privacy/suggest-making-field-public.rs +++ b/tests/ui/privacy/suggest-making-field-public.rs @@ -1,5 +1,5 @@ //@ run-rustfix -mod a { +pub mod a { pub struct A(pub(self)String); } diff --git a/tests/ui/union/union-macro.rs b/tests/ui/union/union-macro.rs index 01cba85deb3..729f56de7a0 100644 --- a/tests/ui/union/union-macro.rs +++ b/tests/ui/union/union-macro.rs @@ -15,6 +15,7 @@ macro_rules! duplicate { duplicate! { pub union U { + #[allow(dead_code)] pub a: u8 } } From 2b8a5480312f947b299f2d9aa682292a3cf2d952 Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Thu, 4 Jan 2024 17:45:36 +0100 Subject: [PATCH 4/9] Mark codegen_gcc fields used only on feature master as such The dead_code lint was previously eroneously missing those. Since this lint bug has been fixed, the unused fields need to be feature gated. --- compiler/rustc_codegen_gcc/src/context.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs index 8f643c7db72..9e6cf3e34df 100644 --- a/compiler/rustc_codegen_gcc/src/context.rs +++ b/compiler/rustc_codegen_gcc/src/context.rs @@ -110,6 +110,7 @@ pub struct CodegenCx<'gcc, 'tcx> { local_gen_sym_counter: Cell, eh_personality: Cell>>, + #[cfg(feature="master")] pub rust_try_fn: Cell, Function<'gcc>)>>, pub pointee_infos: RefCell, Size), Option>>, @@ -121,6 +122,7 @@ pub struct CodegenCx<'gcc, 'tcx> { /// FIXME(antoyo): fix the rustc API to avoid having this hack. pub structs_as_pointer: RefCell>>, + #[cfg(feature="master")] pub cleanup_blocks: RefCell>>, } @@ -325,9 +327,11 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { struct_types: Default::default(), local_gen_sym_counter: Cell::new(0), eh_personality: Cell::new(None), + #[cfg(feature="master")] rust_try_fn: Cell::new(None), pointee_infos: Default::default(), structs_as_pointer: Default::default(), + #[cfg(feature="master")] cleanup_blocks: Default::default(), }; // TODO(antoyo): instead of doing this, add SsizeT to libgccjit. From 9ee59f36b864e5c47ab3f806f0c1dba7548c3c8f Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Fri, 5 Jan 2024 16:13:24 +0100 Subject: [PATCH 5/9] fix: allow-one-hash-in-raw-strings option of needless_raw_string_hashes was ignored Fixes: https://github.com/rust-lang/rust-clippy/issues/11481 changelog: Fix `allow-one-hash-in-raw-strings` option of [`needless_raw_string_hashes`] was ignored --- .../clippy/clippy_lints/src/raw_strings.rs | 6 ++- .../clippy.toml | 1 + .../needless_raw_string_hashes.fixed | 9 +++++ .../needless_raw_string_hashes.rs | 9 +++++ .../needless_raw_string_hashes.stderr | 40 +++++++++++++++++++ 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/clippy.toml create mode 100644 src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.fixed create mode 100644 src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs create mode 100644 src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.stderr diff --git a/src/tools/clippy/clippy_lints/src/raw_strings.rs b/src/tools/clippy/clippy_lints/src/raw_strings.rs index ac29d27303c..7e71f48c6d9 100644 --- a/src/tools/clippy/clippy_lints/src/raw_strings.rs +++ b/src/tools/clippy/clippy_lints/src/raw_strings.rs @@ -108,7 +108,7 @@ impl EarlyLintPass for RawStrings { } } - let req = { + let mut req = { let mut following_quote = false; let mut req = 0; // `once` so a raw string ending in hashes is still checked @@ -136,7 +136,9 @@ impl EarlyLintPass for RawStrings { ControlFlow::Continue(num) | ControlFlow::Break(num) => num, } }; - + if self.allow_one_hash_in_raw_strings { + req = req.max(1); + } if req < max { span_lint_and_then( cx, diff --git a/src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/clippy.toml b/src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/clippy.toml new file mode 100644 index 00000000000..2f3d60be3a7 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/clippy.toml @@ -0,0 +1 @@ +allow-one-hash-in-raw-strings = true diff --git a/src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.fixed b/src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.fixed new file mode 100644 index 00000000000..fd20bdff6e2 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.fixed @@ -0,0 +1,9 @@ +#![allow(clippy::no_effect, unused)] +#![warn(clippy::needless_raw_string_hashes)] + +fn main() { + r#"\aaa"#; + r#"\aaa"#; + r#"Hello "world"!"#; + r####" "### "## "# "####; +} diff --git a/src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs b/src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs new file mode 100644 index 00000000000..3c6c2463700 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs @@ -0,0 +1,9 @@ +#![allow(clippy::no_effect, unused)] +#![warn(clippy::needless_raw_string_hashes)] + +fn main() { + r#"\aaa"#; + r##"\aaa"##; + r##"Hello "world"!"##; + r######" "### "## "# "######; +} diff --git a/src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.stderr b/src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.stderr new file mode 100644 index 00000000000..421ad66e4c9 --- /dev/null +++ b/src/tools/clippy/tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.stderr @@ -0,0 +1,40 @@ +error: unnecessary hashes around raw string literal + --> tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs:6:5 + | +LL | r##"\aaa"##; + | ^^^^^^^^^^^ + | + = note: `-D clippy::needless-raw-string-hashes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::needless_raw_string_hashes)]` +help: remove one hash from both sides of the string literal + | +LL - r##"\aaa"##; +LL + r#"\aaa"#; + | + +error: unnecessary hashes around raw string literal + --> tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs:7:5 + | +LL | r##"Hello "world"!"##; + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: remove one hash from both sides of the string literal + | +LL - r##"Hello "world"!"##; +LL + r#"Hello "world"!"#; + | + +error: unnecessary hashes around raw string literal + --> tests/ui-toml/needless_raw_string_hashes_one_allowed/needless_raw_string_hashes.rs:8:5 + | +LL | r######" "### "## "# "######; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: remove 2 hashes from both sides of the string literal + | +LL - r######" "### "## "# "######; +LL + r####" "### "## "# "####; + | + +error: aborting due to 3 previous errors + From 99b8ec2d6e5c8b58d51dcd842a4a9fca9a26cf89 Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Fri, 5 Jan 2024 16:23:14 +0100 Subject: [PATCH 6/9] Allow dead_code for unused struct fields that are now causing a warning --- src/tools/miri/src/shims/unix/linux/fd/epoll.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tools/miri/src/shims/unix/linux/fd/epoll.rs b/src/tools/miri/src/shims/unix/linux/fd/epoll.rs index a429caaf8f4..8c5aed6def6 100644 --- a/src/tools/miri/src/shims/unix/linux/fd/epoll.rs +++ b/src/tools/miri/src/shims/unix/linux/fd/epoll.rs @@ -21,9 +21,11 @@ pub struct Epoll { /// #[derive(Clone, Debug)] pub struct EpollEvent { + #[allow(dead_code)] pub events: u32, /// `Scalar` is used to represent the /// `epoll_data` type union. + #[allow(dead_code)] pub data: Scalar, } From e78851813eadb69b2a299ff794abbed3202e8ba8 Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Wed, 3 Jan 2024 17:45:41 +0100 Subject: [PATCH 7/9] Allow dead code in thread local dtor The dead_code lint was previously eroneously missing this dead code. Since this lint bug has been fixed, the unused field need to be removed or marked as `#[allow(dead_code)]`. Given the nature of this code, I don't feel confident removing the field so it is only marked as allow(dead_code). --- library/std/src/sys/pal/unix/thread_local_dtor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/pal/unix/thread_local_dtor.rs b/library/std/src/sys/pal/unix/thread_local_dtor.rs index 79b152cece9..e367ce5f906 100644 --- a/library/std/src/sys/pal/unix/thread_local_dtor.rs +++ b/library/std/src/sys/pal/unix/thread_local_dtor.rs @@ -35,7 +35,7 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { #[cfg(not(sanitizer_cfi_normalize_integers))] #[cfi_encoding = "i"] #[repr(transparent)] - pub struct c_int(pub libc::c_int); + pub struct c_int(#[allow(dead_code)] pub libc::c_int); extern "C" { #[linkage = "extern_weak"] From f60c4ed197ad4bc5d7390a6073b49c4c2eae3785 Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Tue, 20 Feb 2024 21:50:20 +0100 Subject: [PATCH 8/9] Allow dead code in sys/pal The dead_code lint was previously eroneously missing this dead code. Since this lint bug has been fixed, the unused field need to be removed or marked as `#[allow(dead_code)]`. These structures API is common to all platforms so the code cannot be removed and is hence marked allow(dead_code). --- library/std/src/sys/pal/sgx/net.rs | 2 ++ library/std/src/sys/pal/unsupported/net.rs | 2 ++ library/std/src/sys/pal/wasi/net.rs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/library/std/src/sys/pal/sgx/net.rs b/library/std/src/sys/pal/sgx/net.rs index c4d5da1627c..edb28e2300f 100644 --- a/library/std/src/sys/pal/sgx/net.rs +++ b/library/std/src/sys/pal/sgx/net.rs @@ -524,6 +524,7 @@ pub mod netc { #[derive(Copy, Clone)] pub struct sockaddr_in { + #[allow(dead_code)] pub sin_family: sa_family_t, pub sin_port: u16, pub sin_addr: in_addr, @@ -536,6 +537,7 @@ pub mod netc { #[derive(Copy, Clone)] pub struct sockaddr_in6 { + #[allow(dead_code)] pub sin6_family: sa_family_t, pub sin6_port: u16, pub sin6_addr: in6_addr, diff --git a/library/std/src/sys/pal/unsupported/net.rs b/library/std/src/sys/pal/unsupported/net.rs index 931fe9ba246..87e6106468f 100644 --- a/library/std/src/sys/pal/unsupported/net.rs +++ b/library/std/src/sys/pal/unsupported/net.rs @@ -346,6 +346,7 @@ pub mod netc { #[derive(Copy, Clone)] pub struct sockaddr_in { + #[allow(dead_code)] pub sin_family: sa_family_t, pub sin_port: u16, pub sin_addr: in_addr, @@ -358,6 +359,7 @@ pub mod netc { #[derive(Copy, Clone)] pub struct sockaddr_in6 { + #[allow(dead_code)] pub sin6_family: sa_family_t, pub sin6_port: u16, pub sin6_addr: in6_addr, diff --git a/library/std/src/sys/pal/wasi/net.rs b/library/std/src/sys/pal/wasi/net.rs index 2098d05db0b..b4cf94c8781 100644 --- a/library/std/src/sys/pal/wasi/net.rs +++ b/library/std/src/sys/pal/wasi/net.rs @@ -520,6 +520,7 @@ pub mod netc { #[derive(Copy, Clone)] pub struct sockaddr_in { + #[allow(dead_code)] pub sin_family: sa_family_t, pub sin_port: u16, pub sin_addr: in_addr, @@ -532,6 +533,7 @@ pub mod netc { #[derive(Copy, Clone)] pub struct sockaddr_in6 { + #[allow(dead_code)] pub sin6_family: sa_family_t, pub sin6_port: u16, pub sin6_addr: in6_addr, From 7342cc46f88bad93bfa82125a09db01bbbe92075 Mon Sep 17 00:00:00 2001 From: Arthur Carcano Date: Fri, 22 Mar 2024 10:17:16 +0100 Subject: [PATCH 9/9] Delete dead fields of deserialized cargo output The dead_code lint was previously eroneously missing this dead code. Since this lint bug has been fixed, the unused field need to be removed or marked as `#[allow(dead_code)]`. Given that this struct is deserialized without #[serde(deny_unknown_fields)] it is ok to simply delete the never read fields. --- src/bootstrap/src/core/build_steps/compile.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index 242fe3c12b9..96e0025acd2 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -2134,18 +2134,9 @@ pub struct CargoTarget<'a> { #[derive(Deserialize)] #[serde(tag = "reason", rename_all = "kebab-case")] pub enum CargoMessage<'a> { - CompilerArtifact { - package_id: Cow<'a, str>, - features: Vec>, - filenames: Vec>, - target: CargoTarget<'a>, - }, - BuildScriptExecuted { - package_id: Cow<'a, str>, - }, - BuildFinished { - success: bool, - }, + CompilerArtifact { filenames: Vec>, target: CargoTarget<'a> }, + BuildScriptExecuted, + BuildFinished, } pub fn strip_debug(builder: &Builder<'_>, target: TargetSelection, path: &Path) {