about summary refs log tree commit diff
path: root/src/test/ui/lint/dead-code
AgeCommit message (Collapse)AuthorLines
2023-01-11Move /src/test to /testsAlbert Larsan-1735/+0
2022-10-24Port `dead_code` lints to be translatable.Charles Lew-4/+4
2022-10-01bless ui testsMaybe Waffle-11/+11
2022-08-03Warn about dead tuple struct fieldsFabian Wolff-6/+64
2022-06-22Rewrite dead-code pass to avoid fetching HIR.Camille GILLOT-30/+53
2022-06-22Uniform spans in dead code lint.Camille GILLOT-40/+36
2022-06-19collapse dead code warnings into a single diagnosticTakayuki Maeda-166/+252
add comments in `store_dead_field_or_variant` support multiple log level add a item ident label fix ui tests fix a ui test fix a rustdoc ui test use let chain refactor: remove `store_dead_field_or_variant` fix a tiny bug
2022-06-02don't use a `span_note` for ignored implslcnr-6/+1
2022-05-21Remove `crate` visibility modifier in libs, testsJacob Pratt-15/+14
2022-05-10Add regression test for #68408Yuki Okushi-0/+22
2022-02-01Make dead code check a query.Camille GILLOT-10/+10
2022-01-15Use span of ignored impls for explanatory noteFabian Wolff-4/+5
2022-01-11Annotate dead code lint with notes about ignored derived implsFabian Wolff-0/+5
2021-11-22Split inline const to two feature gatesGary Guo-1/+1
2021-08-24Auto merge of #85556 - FabianWolff:issue-85071, r=estebank,jackh726bors-0/+109
Warn about unreachable code following an expression with an uninhabited type This pull request fixes #85071. The issue is that liveness analysis currently is "smarter" than reachability analysis when it comes to detecting uninhabited types: Unreachable code is detected during type checking, where full type information is not yet available. Therefore, the check for type inhabitedness is quite crude: https://github.com/rust-lang/rust/blob/fc81ad22c453776de16acf9938976930cf8c9401/compiler/rustc_typeck/src/check/expr.rs#L202-L205 i.e. it only checks for `!`, but not other, non-trivially uninhabited types, such as empty enums, structs containing an uninhabited type, etc. By contrast, liveness analysis, which runs after type checking, can benefit from the more sophisticated `tcx.is_ty_uninhabited_from()`: https://github.com/rust-lang/rust/blob/fc81ad22c453776de16acf9938976930cf8c9401/compiler/rustc_passes/src/liveness.rs#L981 https://github.com/rust-lang/rust/blob/fc81ad22c453776de16acf9938976930cf8c9401/compiler/rustc_passes/src/liveness.rs#L996 This can lead to confusing warnings when a variable is reported as unused, but the use of the variable is not reported as unreachable. For instance: ```rust enum Foo {} fn f() -> Foo {todo!()} fn main() { let x = f(); let _ = x; } ``` currently leads to ``` warning: unused variable: `x` --> t1.rs:5:9 | 5 | let x = f(); | ^ help: if this is intentional, prefix it with an underscore: `_x` | = note: `#[warn(unused_variables)]` on by default warning: 1 warning emitted ``` which is confusing, because `x` _appears_ to be used in line 6. With my changes, I get: ``` warning: unreachable expression --> t1.rs:6:13 | 5 | let x = f(); | --- any code following this expression is unreachable 6 | let _ = x; | ^ unreachable expression | = note: `#[warn(unreachable_code)]` on by default note: this expression has type `Foo`, which is uninhabited --> t1.rs:5:13 | 5 | let x = f(); | ^^^ warning: unused variable: `x` --> t1.rs:5:9 | 5 | let x = f(); | ^ help: if this is intentional, prefix it with an underscore: `_x` | = note: `#[warn(unused_variables)]` on by default warning: 2 warnings emitted ``` My implementation is slightly inelegant because unreachable code warnings can now be issued in two different places (during type checking and during liveness analysis), but I think it is the solution with the least amount of unnecessary code duplication, given that the new warning integrates nicely with liveness analysis, where unreachable code is already implicitly detected for the purpose of finding unused variables.
2021-08-15Add a dead code test for using anon const in patternGary Guo-0/+45
2021-07-21temporarily ignore a test until we reland PR 83171.Felix S. Klock II-0/+2
2021-07-21Revert PR 81473 to resolve (on mainline) issues 81626 and 81658.Felix S. Klock II-113/+0
Revert "Add missing brace" This reverts commit 85ad773049536d7fed9a94ae0ac74f97135c8655. Revert "Simplify base_expr" This reverts commit 899aae465eb4ef295dc1eeb2603f744568e0768c. Revert "Warn write-only fields" This reverts commit d3c69a4c0dd98af2611b7553d1a65afef6a6ccb0.
2021-07-14Warn about useless assignments of variables/fields to themselvesFabian Wolff-0/+94
2021-05-21Warn about unreachable code following an expression with an uninhabited typeFabian Wolff-0/+109
2021-05-16More tests for issue-85255hi-rustin-5/+82
2021-05-15Warn about unused pub fields in non-pub structsFabian Wolff-0/+54
2021-04-16Remove #[main] attribute.Charles Lew-2/+2
2021-02-19Consider auto derefs before warning about write only fieldsTomasz Miąsko-1/+68
Changes from 81473 extended the dead code lint with an ability to detect fields that are written to but never read from. The implementation skips over fields on the left hand side of an assignment, without marking them as live. A field access might involve an automatic dereference and de-facto read the field. Conservatively mark expressions with deref adjustments as live to avoid generating false positive warnings.
2021-01-28Warn write-only fieldsSeo Sanghyeon-0/+46
2021-01-23Do not mark unit variants as used when in path patternTomasz Miąsko-1/+40
Record that we are processing a pattern so that code responsible for handling path resolution can correctly decide whether to mark it as used or not.
2021-01-13Update tests for extern block lintingMark Rousskov-5/+5
2020-12-08Visit ForeignItems when marking dead code.Camille GILLOT-0/+19
2020-09-22dead_code: look at trait impls even if they don't contain itemsBastian Kauschke-0/+19
2020-06-28Rename the lint to clashing_extern_declarations.jumbatm-1/+1
Also, run RustFmt on the clashing_extern_fn test case and update stderrs.
2020-06-20Update existing test cases.jumbatm-6/+7
- Allow ClashingExternDecl for lint-dead-code-3 - Update test case for #5791 - Update test case for #1866 - Update extern-abi-from-macro test case
2020-05-06Dead-code pass highlights too much of impl functionsmibac138-2/+54
2020-04-24Remove redundant `descr`/`descriptive_variant` methods from HIR.Eduard-Mihai Burtescu-8/+8
2020-04-19test for false "never constructed" warnings for `Self::` variant pathsjakubadamw-1/+21
2020-01-31Auto merge of #68080 - varkor:declared-here, r=petrochenkovbors-14/+14
Address inconsistency in using "is" with "declared here" "is" was generally used for NLL diagnostics, but not other diagnostics. Using "is" makes the diagnostics sound more natural and readable, so it seems sensible to commit to them throughout. r? @Centril
2020-01-24Normalise notes with the/isvarkor-14/+14
2020-01-23Use check-pass mode for lint testsTomasz Miąsko-1/+1
2019-11-16Use "field is never read" instead of "field is never used"cosine-10/+10
2019-10-26Use ident instead of def_span in dead-code passPi Lanningham-42/+87
According to @estebank, def_span scans forward on the line until it finds a {, and if it can't find one, fallse back to the span for the whole item. This was apparently written before the identifier span was explicitly tracked on each node. This means that if an unused function signature spans multiple lines, the entire function (potentially hundreds of lines) gets flagged as dead code. This could, for example, cause IDEs to add error squiggly's to the whole function. By using the span from the ident instead, we narrow the scope of this in most cases. In a wider sense, it's probably safe to use ident.span instead of def_span in most locations throughout the whole code base, but since this is my first contribution, I kept it small. Some interesting points that came up while I was working on this: - I reorganized the tests a bit to bring some of the dead code ones all into the same location - A few tests were for things unrelated to dead code (like the path-lookahead for parens), so I added #![allow(dead_code)] and cleaned up the stderr file to reduce noise in the future - The same fix doesn't apply to const and static declarations. I tried adding these cases to the match expression, but that created a much wider change to tests and error messages, so I left it off until I could get some code review to validate the approach.
2019-10-26Move dead_code related tests to test/ui/dead-codePi Lanningham-0/+974
This helps organize the tests better. I also renamed several of the tests to remove redundant dead-code in the path, and better match what they're testing