summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
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-311/+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-311/+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-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`
2024-11-09Dont suggest use<APIT>Michael Goulet-1/+3
2024-11-09Suggest turning APITs into generics in opaque overcapturesMichael Goulet-35/+11
2024-11-07Rollup merge of #132095 - gechelberger:fix-131977, r=wesleywiserJubilee-8/+19
Fix #131977 parens mangled in shared mut static lint suggestion Resolves #131977 for static mut references after discussion with Esteban & Jieyou on [t-compiler/help](https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/linting.20with.20parens.20in.20the.20HIR). This doesn't do anything to change the underlying issue if there are other expressions that generate lint suggestions which need to be applied within parentheses.
2024-11-05Rollup merge of #132637 - blyxyas:lint-less-passes, r=flip1995Matthias Krüger-0/+3
Do not filter empty lint passes & re-do CTFE pass Some structs implement `LintPass` without having a `Lint` associated with them #125116 broke that behaviour by filtering them out. This PR ensures that lintless passes are not filtered out.
2024-11-05Do not filter empty passes & Make CTFE Clippy into lintless passblyxyas-0/+3
2024-11-04Prefer `pub(super)` in `unreachable_pub` lint suggestionUrgau-1/+20
2024-11-04ty::BrK -> ty::BoundRegionKind::KMichael Goulet-7/+7
2024-11-04ty::KContainer -> ty::AssocItemContainer::KMichael Goulet-2/+2
2024-11-03compiler: Directly use rustc_abi in lintsJubilee Young-7/+6
2024-11-02Rollup merge of #132453 - Urgau:non_local_defs-impl-mod-transparent, r=jieyouxuMatthias Krüger-2/+8
Also treat `impl` definition parent as transparent regarding modules This PR changes the `non_local_definitions` lint logic to also consider `impl` definition parent as transparent regarding modules. See tests and explanation in the changes. ``````@rustbot`````` label +L-non_local_definitions Fixes *(after beta-backport)* #132427 cc ``````@leighmcculloch`````` r? ``````@jieyouxu``````
2024-11-02Rollup merge of #132439 - tgross35:f16-f128-nan-lint, r=jieyouxuGuillaume Gomez-1/+4
Add `f16` and `f128` to `invalid_nan_comparison` Currently `f32_nan` and `f64_nan` are used to provide the `invalid_nan_comparison` lint. Since we have `f16_nan` and `f128_nan`, hook these up so the new float types get the same lints.
2024-11-01Also treat `impl` definition parent as transparent regarding modulesUrgau-2/+8
2024-10-31Add `f16` and `f128` to `invalid_nan_comparison`Trevor Gross-1/+4
Currently `f32_nan` and `f64_nan` are used to provide the `invalid_nan_comparison` lint. Since we have `f16_nan` and `f128_nan`, hook these up so the new float types get the same lints.
2024-10-31Rollup merge of #132357 - m-ou-se:explicit-abi, r=compiler-errorsJubilee-3/+1
Improve missing_abi lint This is for the migration lint for https://github.com/rust-lang/rfcs/pull/3722 It is not yet marked as an edition migration lint, because `Edition2027` doesn't exist yet. The lint now includes a machine applicable suggestion: ``` warning: extern declarations without an explicit ABI are deprecated --> src/main.rs:3:1 | 3 | extern fn a() {} | ^^^^^^ help: explicitly specify the C ABI: `extern "C"` | ```
2024-10-31Auto merge of #132301 - compiler-errors:adjust, r=lcnrbors-1/+1
Remove region from adjustments It's not necessary to store this region, because it's only used in THIR and MemCat/ExprUse, both of which already basically only deal with erased regions anyways.
2024-10-31Improve the missing_abi lint.Mara Bos-3/+1
2024-10-30Rollup merge of #132246 - workingjubilee:campaign-on-irform, r=compiler-errorsJubilee-6/+8
Rename `rustc_abi::Abi` to `BackendRepr` Remove the confabulation of `rustc_abi::Abi` with what "ABI" actually means by renaming it to `BackendRepr`, and rename `Abi::Aggregate` to `BackendRepr::Memory`. The type never actually represented how things are passed, as that has to have `PassMode` considered, at minimum, but rather it just is how we represented some things to the backend. This conflation arose because LLVM, the primary backend at the time, would lower certain IR forms using certain ABIs. Even that only somewhat was true, as it broke down when one ventured significantly afield of what is described by the System V AMD64 ABI either by using different architectures, ABI-modifying IR annotations, the same architecture **with different ISA extensions enabled**, or other... unexpected delights. Unfortunately both names are still somewhat of a misnomer right now, as people have written code for years based on this misunderstanding. Still, their original names are even moreso, and for better or worse, this backend code hasn't received as much maintenance as the rest of the compiler, lately. Actually arriving at a correct end-state will simply require us to disentangle a lot of code in order to fix, much of it pointlessly repeated in several places. Thus this is not an "actual fix", just a way to deflect further misunderstandings.
2024-10-30Remap impl-trait lifetimes on HIR instead of AST lowering.Camille GILLOT-1/+1
2024-10-30Rollup merge of #131856 - lcnr:typing-mode, r=compiler-errorsMatthias Krüger-9/+21
TypingMode: merge intercrate, reveal, and defining_opaque_types This adds `TypingMode` and uses it in most places. We do not yet remove `Reveal` from `param_env`s. This and other future work as tracked in #132279 and via `FIXME`s. Fetching the `TypingMode` of the `InferCtxt` asserts that the `TypingMode` agrees with `ParamEnv::reveal` to make sure we don't introduce any subtle bugs here. This will be unnecessary once `ParamEnv::reveal` no longer exists. As the `TypingMode` is now a part of the query input, I've merged the coherence and non-coherence caches for the new solver. I've also enabled the local `infcx` cache during coherence by clearing the cache when forking it with a different `TypingMode`. #### `TypingMode::from_param_env` I am using this even in cases where I know that the `param_env` will always be `Reveal::UserFacing`. This is to make it easier to correctly refactor this code in the future, any time we use `Reveal::UserFacing` in a body while not defining its opaque types is incorrect and should use a `TypingMode` which only reveals opaques defined by that body instead, cc #124598 r? ``@compiler-errors``
2024-10-29compiler: `rustc_abi::Abi` => `BackendRepr`Jubilee Young-6/+8
The initial naming of "Abi" was an awful mistake, conveying wrong ideas about how psABIs worked and even more about what the enum meant. It was only meant to represent the way the value would be described to a codegen backend as it was lowered to that intermediate representation. It was never meant to mean anything about the actual psABI handling! The conflation is because LLVM typically will associate a certain form with a certain ABI, but even that does not hold when the special cases that actually exist arise, plus the IR annotations that modify the ABI. Reframe `rustc_abi::Abi` as the `BackendRepr` of the type, and rename `BackendRepr::Aggregate` as `BackendRepr::Memory`. Unfortunately, due to the persistent misunderstandings, this too is now incorrect: - Scattered ABI-relevant code is entangled with BackendRepr - We do not always pre-compute a correct BackendRepr that reflects how we "actually" want this value to be handled, so we leave the backend interface to also inject various special-cases here - In some cases `BackendRepr::Memory` is a "real" aggregate, but in others it is in fact using memory, and in some cases it is a scalar! Our rustc-to-backend lowering code handles this sort of thing right now. That will eventually be addressed by lifting duplicated lowering code to either rustc_codegen_ssa or rustc_target as appropriate.
2024-10-29Rollup merge of #131984 - dingxiangfei2009:stabilize-if-let-rescope, ↵Matthias Krüger-2/+1
r=traviscross,lcnr Stabilize if_let_rescope Close #131154 Tracked by #124085
2024-10-29TypingMode :thinking:lcnr-9/+21
2024-10-29Auto merge of #132277 - workingjubilee:rollup-5e6q6e4, r=workingjubileebors-4/+3
Rollup of 9 pull requests Successful merges: - #130259 (Lower AST node id only once) - #131441 (Add a new trait `proc_macro::ToTokens`) - #132247 (stable_mir: Directly use types from rustc_abi) - #132249 (compiler: Add rustc_abi dependence to the compiler) - #132255 (Add `LayoutData::is_uninhabited` and use it) - #132258 ([rustdoc] Unify variant struct fields margins with struct fields) - #132260 (cg_llvm: Use a type-safe helper to cast `&str` and `&[u8]` to `*const c_char`) - #132261 (refactor: cleaner check to return None) - #132271 (Updating Fuchsia platform-support documentation) r? `@ghost` `@rustbot` modify labels: rollup
2024-10-29Remove region from adjustmentsMichael Goulet-1/+1
2024-10-29Auto merge of #128985 - GrigorenkoPV:instantly-dangling-pointer, r=Urgaubors-79/+237
Lint against getting pointers from immediately dropped temporaries Fixes #123613 ## Changes: 1. New lint: `dangling_pointers_from_temporaries`. Is a generalization of `temporary_cstring_as_ptr` for more types and more ways to get a temporary. 2. `temporary_cstring_as_ptr` is removed and marked as renamed to `dangling_pointers_from_temporaries`. 3. `clippy::temporary_cstring_as_ptr` is marked as renamed to `dangling_pointers_from_temporaries`. 4. Fixed a false positive[^fp] for when the pointer is not actually dangling because of lifetime extension for function/method call arguments. 5. `core::cell::Cell` is now `rustc_diagnostic_item = "Cell"` ## Questions: - [ ] Instead of manually checking for a list of known methods and diagnostic items, maybe add some sort of annotation to those methods in library and check for the presence of that annotation? https://github.com/rust-lang/rust/pull/128985#issuecomment-2318714312 ## Known limitations: ### False negatives[^fn]: See the comments in `compiler/rustc_lint/src/dangling.rs` 1. Method calls that are not checked for: - `temporary_unsafe_cell.get()` - `temporary_sync_unsafe_cell.get()` 2. Ways to get a temporary that are not recognized: - `owning_temporary.field` - `owning_temporary[index]` 3. No checks for ref-to-ptr conversions: - `&raw [mut] temporary` - `&temporary as *(const|mut) _` - `ptr::from_ref(&temporary)` and friends [^fn]: lint **should** be emitted, but **is not** [^fp]: lint **should not** be emitted, but **is**
2024-10-28Rollup merge of #132249 - workingjubilee:add-rustc-abi, r=compiler-errorsJubilee-4/+3
compiler: Add rustc_abi dependence to the compiler Depend on rustc_abi in compiler crates that use it indirectly but have not yet taken on that dependency, and are not *significantly* entangled in my other PRs. This leaves an "excise rustc_target" step after the dust settles.
2024-10-28New lint: `dangling_pointers_from_temporaries`Pavel Grigorenko-79/+237
2024-10-27compiler: Depend on rustc_abi in rustc_lintJubilee Young-4/+3
2024-10-27Clean up some comments on lint implementationEric Huss-66/+18