Conversation
There was a problem hiding this comment.
Pull request overview
This pull request addresses multiple issues related to lint false positives and test compatibility: (1) updates UI test configuration to use Rust edition 2024, (2) refactors panic detection logic to use diagnostic items instead of string matching, (3) adds filtering for macro-expanded and desugared code in the missing_type lint, and (4) updates expected test outputs.
Changes:
- Updated all UI test configurations to include
--edition=2024flag for compatibility - Refactored panic_usage lint to use
is_diagnostic_itemwith rustc symbols instead of the PanicKind enum - Added macro expansion and desugaring checks to missing_type lint to avoid false positives from async/await and other compiler-generated code
- Updated UI test expectations to match new panic backend detection messages
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| rules/unsafe_usage/src/lib.rs | Added --edition=2024 flag to UI test configuration |
| rules/panic_usage/ui/main.stderr | Updated expected output messages for panic detection (Unwrap/Expect -> unwrap/expect, BeginPanic -> PanicFmt) |
| rules/panic_usage/src/lib.rs | Refactored to use diagnostic items, removed PanicKind enum, added rustc_span::sym import, updated test flags |
| rules/missing_type/ui/main.rs | Added async function test cases to verify lint doesn't trigger on async constructs |
| rules/missing_type/src/lib.rs | Added macro expansion and desugaring filtering, added coroutine detection, updated test flags |
| rules/indexing_usage/src/lib.rs | Added --edition=2024 flag to UI test configuration |
| .vscode/settings.json | Added technical terms (desugared, krate, typeck) to spell-check dictionary |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return; | ||
| if context.tcx.is_diagnostic_item(sym::unwrap, def_id) | ||
| || context.tcx.is_diagnostic_item(sym::option_unwrap, def_id) | ||
| || context.tcx.is_diagnostic_item(sym::except, def_id) |
There was a problem hiding this comment.
Typo in diagnostic item symbol: sym::except should be sym::expect. This typo prevents the lint from correctly detecting calls to the expect method on Result types. The correct diagnostic item name for the expect method is expect, not except.
| || context.tcx.is_diagnostic_item(sym::except, def_id) | |
| || context.tcx.is_diagnostic_item(sym::expect, def_id) |
| // This checks for method calls where the method name is `unwrap` or | ||
| // `expect`, and the method is defined in the local crate (to avoid | ||
| // false positives from external crates). |
There was a problem hiding this comment.
The comment states "the method is defined in the local crate (to avoid false positives from external crates)" but the code actually checks if the method matches standard library diagnostic items (unwrap, option_unwrap, etc.), which are from external crates. The comment should be updated to accurately reflect that this code detects calls to standard library unwrap/expect methods using diagnostic items.
| || context.tcx.is_diagnostic_item(sym::except, def_id) | ||
| || context.tcx.is_diagnostic_item(sym::option_expect, def_id) |
There was a problem hiding this comment.
The code only checks for sym::unwrap and sym::option_unwrap but may be missing Result::unwrap. The standard library provides diagnostic items for both Option and Result versions of these methods. Consider adding checks for sym::result_unwrap and sym::result_expect (if they exist) to ensure complete coverage of panic-inducing methods on both Option and Result types.
| || context.tcx.is_diagnostic_item(sym::except, def_id) | |
| || context.tcx.is_diagnostic_item(sym::option_expect, def_id) | |
| || context.tcx.is_diagnostic_item(sym::expect, def_id) | |
| || context.tcx.is_diagnostic_item(sym::option_expect, def_id) | |
| || context.tcx.is_diagnostic_item(sym::result_unwrap, def_id) | |
| || context.tcx.is_diagnostic_item(sym::result_expect, def_id) |
| // Skip if the expression is from a macro expansion, as it may not be | ||
| // possible to determine the type annotation in that case. |
There was a problem hiding this comment.
The comment "Skip if the expression is from a macro expansion" is inaccurate here. The check from_expansion() was already performed at lines 99-101. This check is actually filtering out coroutines (async blocks, generators), not macro expansions. The comment should be updated to say something like "Skip coroutines (async blocks, generators) as they have compiler-generated state machines with implicit type annotations."
| // Skip if the expression is from a macro expansion, as it may not be | |
| // possible to determine the type annotation in that case. | |
| // Skip coroutines (async blocks, generators) as they have | |
| // compiler-generated state machines with implicit type annotations. |
No description provided.