about summary refs log tree commit diff
path: root/compiler/rustc_lint
AgeCommit message (Collapse)AuthorLines
2024-12-06compiler: Tighten up ImproperCTypesLayer recursionJubilee Young-21/+12
2024-12-06lint ImproperCTypes: message tweaks and refactoring from code reviewniacdoial-28/+31
2024-12-06lint ImproperCTypes: confirm that Box<FfiSafeType> and ↵niacdoial-1/+1
Option<Box<FfiSafeType>> are FFI-safe in function declarations too
2024-12-06lint: polish code from the last few commitsniacdoial-25/+60
2024-12-06lint: fix ImproperCTypes edge case for unsized structs due to foreign typesniacdoial-2/+65
2024-12-06lint: rework some ImproperCTypes messages (especially around indirections to ↵niacdoial-23/+126
!Sized)
2024-12-06lint: revamp ImproperCTypes diagnostic architecture for nested notes and ↵niacdoial-45/+146
help messages
2024-12-05Update compiler/rustc_lint/messages.ftlAnthony Eid-3/+2
Co-authored-by: Urgau <3616612+Urgau@users.noreply.github.com>
2024-12-05Update compiler/rustc_lint/src/lints.rsAnthony Eid-2/+3
Co-authored-by: Urgau <3616612+Urgau@users.noreply.github.com>
2024-12-05Start work on dangling pointers lintAnthony Eid-1/+5
2024-12-05Rollup merge of #118833 - Urgau:lint_function_pointer_comparisons, r=cjgillotLeón Orell Valerian Liehr-4/+176
Add lint against function pointer comparisons This is kind of a follow-up to https://github.com/rust-lang/rust/pull/117758 where we added a lint against wide pointer comparisons for being ambiguous and unreliable; well function pointer comparisons are also unreliable. We should IMO follow a similar logic and warn people about it. ----- ## `unpredictable_function_pointer_comparisons` *warn-by-default* The `unpredictable_function_pointer_comparisons` lint checks comparison of function pointer as the operands. ### Example ```rust fn foo() {} let a = foo as fn(); let _ = a == foo; ``` ### Explanation Function pointers comparisons do not produce meaningful result since they are never guaranteed to be unique and could vary between different code generation units. Furthermore different function could have the same address after being merged together. ---- This PR also uplift the very similar `clippy::fn_address_comparisons` lint, which only linted on if one of the operand was an `ty::FnDef` while this PR lints proposes to lint on all `ty::FnPtr` and `ty::FnDef`. ```@rustbot``` labels +I-lang-nominated ~~Edit: Blocked on https://github.com/rust-lang/libs-team/issues/323 being accepted and it's follow-up pr~~
2024-12-03Rollup merge of #133753 - ↵Matthias Krüger-2/+5
dingxiangfei2009:reduce-false-positive-if-let-rescope, r=jieyouxu Reduce false positives on some common cases from if-let-rescope lint r? `@jieyouxu` We would like to identify a very common case in the ecosystem in which we do not need to apply the lint suggestion for the new Edition 2024 `if let` semantics. In this patch we excluded linting from `if let`s in statements and block tail expressions. In these simple cases, new Edition 2024 drop orders are identical to those of Edition 2021 and prior. However, conservatively we should still lint for the other cases, because [this example](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=2113df5ce78f161d32a1190faf5c7469) shows that the drop order changes are very pronounced, some of which are even sensitive to runtime data.
2024-12-03Rollup merge of #133545 - clubby789:symbol-intern-lit, r=jieyouxuMatthias Krüger-3/+44
Lint against Symbol::intern on a string literal Disabled in tests where this doesn't make much sense
2024-12-02Add warn-by-default lint against unpredictable fn pointer comparisonsUrgau-4/+176
2024-12-02remove `Ty::is_copy_modulo_regions`lcnr-2/+6
2024-12-02remove outdated commentlcnr-11/+4
2024-12-02reduce false positives on some common cases from if-let-rescopeDing Xiang Fei-2/+5
2024-12-01Fixed typos by changing `happend` to `happened`HomelikeBrick42-3/+3
2024-11-28Replace `Symbol::intern` calls with preinterned symbolsclubby789-1/+1
2024-11-28Implement lint against `Symbol::intern` on a string literalclubby789-2/+43
2024-11-28Rollup merge of #133487 - pitaj:reserve-guarded-strings, r=fee1-deadGuillaume Gomez-2/+16
fix confusing diagnostic for reserved `##` Closes #131615
2024-11-27Avoid even more decoding if not absolutely necessaryUrgau-2/+2
2024-11-26Avoid decoding from metadata if not necessaryUrgau-1/+1
2024-11-25fix confusing diagnostic for reserved `##`Peter Jaszkowiak-2/+16
2024-11-25Refactor `where` predicates, and reserve for attributes supportFrank King-19/+19
2024-11-24add guard pattern AST nodeMax Niederman-1/+1
2024-11-23no more Reveal :(lcnr-2/+0
2024-11-21Rollup merge of #133153 - maxcabrajac:flat_maps, r=petrochenkovMatthias Krüger-8/+9
Add visits to nodes that already have flat_maps in ast::MutVisitor This PR aims to add `visit_` methods for every node that has a `flat_map_` in MutVisitor, giving implementers free choice over overriding `flat_map` for 1-to-n conversions or `visit` for a 1-to-1. There is one major problem: `flat_map_stmt`. While all other default implementations of `flat_map`s are 1-to-1 conversion, as they either only call visits or a internal 1-to-many conversions are natural, `flat_map_stmt` doesn't follow this pattern. `flat_map_stmt`'s default implementation is a 1-to-n conversion that panics if n > 1 (effectively being a 1-to-[0;1]). This means that it cannot be used as is for a default `visit_stmt`, which would be required to be a 1-to-1. Implementing `visit_stmt` without runtime checks would require it to reach over a potential `flat_map_item` or `filter_map_expr` overrides and call for their `visit` counterparts directly. Other than that, if we want to keep the behavior of `flat_map_stmt` it cannot call `visit_stmt` internally. To me, it seems reasonable to make all default implementations 1-to-1 conversions and let implementers handle `visit_stmt` if they need it, but I don't know if calling `visit` directly when a 1-to-1 is required is ok or not. related to #128974 & #127615 r? ``@petrochenkov``
2024-11-20Itemsmaxcabrajac-8/+9
2024-11-20Auto merge of #131326 - dingxiangfei2009:issue-130836-attempt-2, r=nikomatsakisbors-314/+0
Reduce false positives of tail-expr-drop-order from consumed values (attempt #2) r? `@nikomatsakis` Tracked by #123739. Related to #129864 but not replacing, yet. Related to #130836. This is an implementation of the approach suggested in the [Zulip stream](https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/temporary.20drop.20order.20changes). A new MIR statement `BackwardsIncompatibleDrop` is added to the MIR syntax. The lint now works by inspecting possibly live move paths before at the `BackwardsIncompatibleDrop` location and the actual drop under the current edition, which should be one before Edition 2024 in practice.
2024-11-20reduce false positives of tail-expr-drop-order from consumed valuesDing Xiang Fei-314/+0
take 2 open up coroutines tweak the wordings the lint works up until 2021 We were missing one case, for ADTs, which was causing `Result` to yield incorrect results. only include field spans with significant types deduplicate and eliminate field spans switch to emit spans to impl Drops Co-authored-by: Niko Matsakis <nikomat@amazon.com> collect drops instead of taking liveness diff apply some suggestions and add explantory notes small fix on the cache let the query recurse through coroutine new suggestion format with extracted variable name fine-tune the drop span and messages bugfix on runtime borrows tweak message wording filter out ecosystem types earlier apply suggestions clippy check lint level at session level further restrict applicability of the lint translate bid into nop for stable mir detect cycle in type structure
2024-11-20Auto merge of #133234 - jhpratt:rollup-42dmg4p, r=jhprattbors-24/+25
Rollup of 5 pull requests Successful merges: - #132732 (Use attributes for `dangling_pointers_from_temporaries` lint) - #133108 (lints_that_dont_need_to_run: never skip future-compat-reported lints) - #133190 (CI: use free runner in dist-aarch64-msvc) - #133196 (Make rustc --explain compatible with BusyBox less) - #133216 (Implement `~const Fn` trait goal in the new solver) r? `@ghost` `@rustbot` modify labels: rollup
2024-11-20Rollup merge of #133108 - RalfJung:future-compat-needs-to-run, r=lcnrJacob Pratt-10/+12
lints_that_dont_need_to_run: never skip future-compat-reported lints Follow-up to https://github.com/rust-lang/rust/pull/125116: future-compat lints show up with `--json=future-incompat` even if they are otherwise allowed in the crate. So let's ensure we do not skip those as part of the `lints_that_dont_need_to_run` logic. I could not find a current future compat lint that is emitted by a lint pass, so there's no clear way to add a test for this. Cc `@blyxyas` `@cjgillot`
2024-11-20Rollup merge of #132732 - gavincrawford:as_ptr_attribute, r=UrgauJacob Pratt-14/+13
Use attributes for `dangling_pointers_from_temporaries` lint Checking for dangling pointers by function name isn't ideal, and leaves out certain pointer-returning methods that don't follow the `as_ptr` naming convention. Using an attribute for this lint cleans things up and allows more thorough coverage of other methods, such as `UnsafeCell::get()`.
2024-11-19Add external macro specific diagnostic to check-cfgUrgau-12/+93
2024-11-19Disable most Cargo check-cfg help in external macrosUrgau-3/+10
2024-11-19lints_that_dont_need_to_run: never skip future-compat-reported lintsRalf Jung-10/+12
2024-11-19impl trait overcaptures, yeet ` TypingMode::from_param_env`lcnr-3/+3
2024-11-19move `fn is_item_raw` to `TypingEnv`lcnr-13/+11
2024-11-19Correct comments concerning updated dangling pointer lintgavincrawford-8/+5
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-66/+77
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-15Rollup merge of #132956 - maxcabrajac:coroutine_kind, r=petrochenkovGuillaume Gomez-19/+4
Add visit_coroutine_kind to ast::Visitor r? ``@petrochenkov`` related to #128974
2024-11-15Rollup merge of #132936 - surechen:fix_131989, r=NadrierilGuillaume Gomez-0/+9
For expr `return (_ = 42);` unused_paren lint should not be triggered fixes #131989
2024-11-14Adding `BreakValue` to UnusedDelimsCtx to make `UnusedParens` and ↵surechen-1/+8
`UnusedBraces` checking `break`
2024-11-12Change rustc_lintmaxcabrajac-19/+4
2024-11-12For expr `return (_ = 42);` unused_paren lint should not be triggeredsurechen-0/+2
fixes #131989
2024-11-11Recurse into APITs in impl_trait_overcapturesMichael Goulet-1/+5
2024-11-11Update dangling pointer testsgavincrawford-3/+4
2024-11-11Check for #[rustc_as_ptr] attribute instead of searching for function namesgavincrawford-4/+5
Co-authored-by: Urgau <3616612+Urgau@users.noreply.github.com>
2024-11-10Rollup merge of #132426 - Urgau:unreach_pub-super, r=petrochenkovMatthias Krüger-1/+20
Prefer `pub(super)` in `unreachable_pub` lint suggestion This PR updates the `unreachable_pub` lint suggestion to prefer `pub(super)` instead of `pub(crate)` when possible. cc `@petrochenkov` r? `@nnethercote`