| Age | Commit message (Collapse) | Author | Lines |
|
|
|
Check assoc consts and tys later like assoc fns
This PR
1. checks assoc consts and tys later like assoc fns
2. marks assoc consts appear in poly-trait-ref live
For assoc consts, considering
```rust
#![deny(dead_code)]
trait Tr { // ERROR trait `Tr` is never used
const I: Self;
}
struct Foo; //~ ERROR struct `Foo` is never constructed
impl Tr for Foo {
const I: Self = Foo;
}
fn main() {}
```
Current this will produce unused `I` instead of unused `Tr` and `Foo` ([play](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=e0490d4a2d522cb70437b26e514a3d9c)), because `const I: Self = Foo;` will be added into the worklist at first:
```
error: associated constant `I` is never used
--> src/main.rs:4:11
|
3 | trait Tr { // ERROR trait `Tr` is never used
| -- associated constant in this trait
4 | const I: Self;
| ^
|
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![deny(dead_code)]
| ^^^^^^^^^
error: could not compile `playground` (bin "playground") due to 1 previous error
```
This also happens to assoc tys, see the [new test](https://github.com/rust-lang/rust/compare/master...mu001999-contrib:rust:dead-code/impl-items?expand=1#diff-bf45fa403934a31c9d610a073ed2603d885e7e81572e8edf38b7f4e08a1f3531)
Fixes rust-lang/rust#126729
r? `````@petrochenkov`````
|
|
|
|
Full list of `impl const Default` types:
- ()
- bool
- char
- Cell
- std::ascii::Char
- usize
- u8
- u16
- u32
- u64
- u128
- i8
- i16
- i32
- i64
- i128
- f16
- f32
- f64
- f128
- std::marker::PhantomData<T>
- Option<T>
- std::iter::Empty<T>
- std::ptr::Alignment
- &[T]
- &mut [T]
- &str
- &mut str
- String
- Vec<T>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Signed-off-by: tcpdumppy <847462026@qq.com>
|
|
```
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
--> $DIR/attempted-access-non-fatal.rs:7:15
|
LL | let _ = 2.l;
| ^
|
help: if intended to be a floating point literal, consider adding a `0` after the period and a `f64` suffix
|
LL - let _ = 2.l;
LL + let _ = 2.0f64;
|
```
|
|
|
|
|
|
Done with
```bash
sd '//@ pretty-expanded.*\n' '' tests/ui/**/*.rs
```
and
```
sd '//@pretty-expanded.*\n' '' tests/ui/**/*.rs
```
|
|
|
|
This reverts commit 13314df21b0bb0cdd02c6760581d1b9f1052fa7e, reversing
changes made to 6e534c73c35f569492ed5fb5f349075d58ed8b7e.
|
|
This reverts commit 977c5fd419ade52467f7de79d5bfc25c0c893275, reversing
changes made to 24c94f0e4f5aa333c665fbbba423172c30176624.
|
|
This reverts commit 2724aeaaeb127a8073e39461caacbe21a128ce7b, reversing
changes made to d929a42a664c026167800801b26d734db925314f.
|
|
This reverts commit 31fe9628cf830a08e7194a446f66c668aaea86e9, reversing
changes made to f20307851ead9fbbb9fa88bbffb3258a069230a6.
|
|
This reverts commit a70dc297a899b76793a14c5705f6ec78fd7a57a7, reversing
changes made to ceae37188b9f1be527bb16c9d657a161be7dbbe3.
|
|
This reverts commit 91b18a058c4661f82e420b633dc0a3e1ccd14b88, reversing
changes made to 9aedec9313dc8ecf9bdcb5f09c4eb0ad8b9a4875.
|
|
Stabilize offset_of_nested
Tracking issue #120140. Closes #120140.
As the FCP is now nearing its end I have opened a stabilization PR. I have done this separately to the offset_of_enum feature, since that FCP has not started.
`@rustbot` label F-offset_of_nested T-lang T-libs-api
|
|
|
|
never type, PhantomData and positional ZST
|
|
Extend rules of dead code analysis for impls for adts to impls for types refer to adts
The rules of dead code analysis for impl blocks can be extended to self types which refer to adts.
So that we can lint the following unused struct and trait:
```rust
struct Foo; //~ ERROR struct `Foo` is never constructed
trait Trait { //~ ERROR trait `Trait` is never used
fn foo(&self) {}
}
impl Trait for &Foo {}
```
r? `@pnkfelix`
|
|
Improve dead code analysis
Fixes #120770
1. check impl items later if self ty is private although the trait method is public, cause we must use the ty firstly if it's private
2. mark the adt live if it appears in pattern, like generic argument, this implies the use of the adt
3. based on the above, we can handle the case that private adts impl Default, so that we don't need adding rustc_trivial_field_reads on Default, and the logic in should_ignore_item
r? ``@pnkfelix``
|
|
|
|
refer to adts
|
|
Let's `#[expect]` some lints: Stabilize `lint_reasons` (RFC 2383)
Let's give this another try! The [previous stabilization attempt](https://github.com/rust-lang/rust/pull/99063) was stalled by some unresolved questions. These have been discussed in a [lang team](https://github.com/rust-lang/lang-team/issues/191) meeting. The last open question, regarding the semantics of the `#[expect]` attribute was decided on in https://github.com/rust-lang/rust/issues/115980
I've just updated the [stabilization report](https://github.com/rust-lang/rust/issues/54503#issuecomment-1179563964) with the discussed questions and decisions. Luckily, the decision is inline with the current implementation.
This hopefully covers everything. Let's hope that the CI will be green like the spring.
fixes #115980
fixes #54503
---
r? `@wesleywiser`
Tacking Issue: https://github.com/rust-lang/rust/issues/54503
Stabilization Report: https://github.com/rust-lang/rust/issues/54503#issuecomment-1179563964
Documentation Update: https://github.com/rust-lang/reference/pull/1237
<!--
For Clippy:
changelog: [`allow_attributes`]: Is now available on stable, since the `lint_reasons` feature was stabilized
changelog: [`allow_attributes_without_reason`]: Is now available on stable, since the `lint_reasons` feature was stabilized
-->
---
Roses are red,
Violets are blue,
Let's expect lints,
With reason clues
|
|
Rollup of 7 pull requests
Successful merges:
- #126618 (Mark assoc tys live only if the corresponding trait is live)
- #126746 (Deny `use<>` for RPITITs)
- #126868 (not use offset when there is not ends with brace)
- #126884 (Do not ICE when suggesting dereferencing closure arg)
- #126893 (Eliminate the distinction between PREC_POSTFIX and PREC_PAREN precedence level)
- #126915 (Don't suggest awaiting in closure patterns)
- #126943 (De-duplicate all consecutive native libs regardless of their options)
r? `@ghost`
`@rustbot` modify labels: rollup
|
|
Detect unused structs which derived Default
<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.
This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using
r? <reviewer name>
-->
Fixes #98871
|
|
Mark assoc tys live only if the corresponding trait is live
r? ````@pnkfelix````
|
|
|
|
|
|
r=pnkfelix
Show notice about "never used" of Debug for enum
Close #123068
If an ADT implements `Debug` trait and it is not used, the compiler says a note that indicates intentionally ignored during dead code analysis as [this note](https://github.com/rust-lang/rust/blob/2207179a591f5f252885a94ab014dafeb6e8e9e8/tests/ui/lint/dead-code/unused-variant.stderr#L9).
However this node is not shown for variants that have fields in enum. This PR fixes to show the note.
|
|
Suggest removing unused tuple fields if they are the last fields
Fixes #124556
We now check if dead/unused fields are the last fields of the tuple and suggest their removal instead of suggesting them to be changed to `()`.
|
|
|
|
|
|
Add pub struct with allow(dead_code) into worklist
<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.
This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using
r? <reviewer name>
-->
Fixes #126289
|
|
assoc constants
|
|
|
|
|
|
|
|
|
|
Fixes https://github.com/rust-lang/rust/issues/119545
|
|
|
|
|
|
|