Commit Graph

2414 Commits

Author SHA1 Message Date
bors
fda6892747 Auto merge of #133234 - jhpratt:rollup-42dmg4p, r=jhpratt
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-20 09:27:56 +00:00
Jacob Pratt
a175db1424
Rollup merge of #133108 - RalfJung:future-compat-needs-to-run, r=lcnr
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-20 01:54:25 -05:00
Jacob Pratt
25dc4d0394
Rollup merge of #132732 - gavincrawford:as_ptr_attribute, r=Urgau
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-20 01:54:24 -05:00
Ralf Jung
df94818366 lints_that_dont_need_to_run: never skip future-compat-reported lints 2024-11-19 22:04:10 +01:00
lcnr
ffd7a50314 impl trait overcaptures, yeet TypingMode::from_param_env 2024-11-19 18:06:20 +01:00
lcnr
948cec0fad move fn is_item_raw to TypingEnv 2024-11-19 18:06:20 +01:00
gavincrawford
01fd384d58
Correct comments concerning updated dangling pointer lint 2024-11-19 10:05:24 -07:00
lcnr
9cba14b95b use TypingEnv when no infcx is available
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-18 10:38:56 +01:00
Guillaume Gomez
325bc6c201
Rollup merge of #132956 - maxcabrajac:coroutine_kind, r=petrochenkov
Add visit_coroutine_kind to ast::Visitor

r? ``@petrochenkov``

related to #128974
2024-11-15 23:38:10 +01:00
Guillaume Gomez
1f83a4de1f
Rollup merge of #132936 - surechen:fix_131989, r=Nadrieril
For expr `return (_ = 42);` unused_paren lint should not be triggered

fixes #131989
2024-11-15 23:38:09 +01:00
surechen
3a74bce72e Adding BreakValue to UnusedDelimsCtx to make UnusedParens and UnusedBraces checking break 2024-11-14 09:08:56 +08:00
maxcabrajac
71786ee619 Change rustc_lint 2024-11-12 13:50:03 -03:00
surechen
33d3c27d38 For expr return (_ = 42); unused_paren lint should not be triggered
fixes #131989
2024-11-12 10:17:41 +08:00
Michael Goulet
8e068b989b Recurse into APITs in impl_trait_overcaptures 2024-11-11 20:53:08 +00:00
gavincrawford
8ec94d30e5
Update dangling pointer tests 2024-11-11 13:36:43 -07:00
gavincrawford
37c30aeb45
Check for #[rustc_as_ptr] attribute instead of searching for function names
Co-authored-by: Urgau <3616612+Urgau@users.noreply.github.com>
2024-11-11 13:36:24 -07:00
Matthias Krüger
54cb1f7fe6
Rollup merge of #132426 - Urgau:unreach_pub-super, r=petrochenkov
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-10 22:20:35 +01:00
Michael Goulet
a1f9d5bfba Dont suggest use<APIT> 2024-11-09 19:41:53 +00:00
Michael Goulet
ad20906065 Suggest turning APITs into generics in opaque overcaptures 2024-11-09 19:18:22 +00:00
Jubilee
6c0e8ef86a
Rollup merge of #132095 - gechelberger:fix-131977, r=wesleywiser
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-07 18:48:21 -08:00
clubby789
b480f0f224 Remove unused intercrate dependencies 2024-11-07 14:17:16 +00:00
Matthias Krüger
560248f4f7
Rollup merge of #132637 - blyxyas:lint-less-passes, r=flip1995
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-05 20:10:53 +01:00
blyxyas
2eac3c0e53 Do not filter empty passes & Make CTFE Clippy into lintless pass 2024-11-05 15:27:09 +01:00
Urgau
0bc622d251 Prefer pub(super) in unreachable_pub lint suggestion 2024-11-04 19:09:40 +01:00
Michael Goulet
d458f850aa ty::BrK -> ty::BoundRegionKind::K 2024-11-04 04:45:52 +00:00
Michael Goulet
be4b0261c2 ty::KContainer -> ty::AssocItemContainer::K 2024-11-04 04:45:52 +00:00
Jubilee Young
586e141be7 compiler: Directly use rustc_abi in lints 2024-11-03 13:38:47 -08:00
Matthias Krüger
fa69b671a9
Rollup merge of #132453 - Urgau:non_local_defs-impl-mod-transparent, r=jieyouxu
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-02 08:33:13 +01:00
Guillaume Gomez
2896483320
Rollup merge of #132439 - tgross35:f16-f128-nan-lint, r=jieyouxu
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-02 03:08:52 +08:00
Urgau
37db365948 Also treat impl definition parent as transparent regarding modules 2024-11-01 16:07:02 +01:00
Trevor Gross
3afbe4f9c7 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-10-31 21:26:36 -05:00
Jubilee
6b0c8cfedc
Rollup merge of #132357 - m-ou-se:explicit-abi, r=compiler-errors
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-31 17:50:41 -07:00
bors
9ccfedf186 Auto merge of #132301 - compiler-errors:adjust, r=lcnr
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-31 10:17:49 +00:00
Mara Bos
cb26fa07bb Improve the missing_abi lint. 2024-10-31 10:55:45 +01:00
Jubilee
847b6fe6b0
Rollup merge of #132246 - workingjubilee:campaign-on-irform, r=compiler-errors
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-30 14:01:37 -07:00
Camille GILLOT
b6e1214ac0 Remap impl-trait lifetimes on HIR instead of AST lowering. 2024-10-30 16:18:50 +00:00
Matthias Krüger
305508f969
Rollup merge of #131856 - lcnr:typing-mode, r=compiler-errors
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-30 06:40:34 +01:00
Jubilee Young
7086dd83cc compiler: rustc_abi::Abi => BackendRepr
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-29 14:56:00 -07:00
Matthias Krüger
5d6c49938e
Rollup merge of #131984 - dingxiangfei2009:stabilize-if-let-rescope, r=traviscross,lcnr
Stabilize if_let_rescope

Close #131154
Tracked by #124085
2024-10-29 18:38:57 +01:00
lcnr
f51ec110a7 TypingMode 🤔 2024-10-29 17:01:24 +01:00
bors
2df8dbb1b3 Auto merge of #132277 - workingjubilee:rollup-5e6q6e4, r=workingjubilee
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-29 07:32:45 +00:00
Michael Goulet
599ffab6cd Remove region from adjustments 2024-10-29 01:34:06 +00:00
bors
a9d17627d2 Auto merge of #128985 - GrigorenkoPV:instantly-dangling-pointer, r=Urgau
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-29 00:24:07 +00:00
Jubilee
d6be363400
Rollup merge of #132249 - workingjubilee:add-rustc-abi, r=compiler-errors
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-28 10:18:50 -07:00
Pavel Grigorenko
c69894eaec New lint: dangling_pointers_from_temporaries 2024-10-28 14:16:05 +03:00
Jubilee Young
3f73fe7db4 compiler: Depend on rustc_abi in rustc_lint 2024-10-27 23:59:31 -07:00
Eric Huss
924ded6b72 Clean up some comments on lint implementation 2024-10-27 04:30:51 -07:00
bors
9b18a122f7 Auto merge of #132190 - matthiaskrgr:rollup-rsocfiz, r=matthiaskrgr
Rollup of 3 pull requests

Successful merges:

 - #131875 (Add WASM | WASI | Emscripten groups to triagebot.toml)
 - #132019 (Document `PartialEq` impl for `OnceLock`)
 - #132182 (Downgrade `untranslatable_diagnostic` and `diagnostic_outside_of_impl` to `allow`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-10-26 19:00:57 +00:00
bors
4d88de2acd Auto merge of #125116 - blyxyas:ignore-allowed-lints-final, r=cjgillot
(Big performance change) Do not run lints that cannot emit

Before this change, adding a lint was a difficult matter because it always had some overhead involved. This was because all lints would run, no matter their default level, or if the user had `#![allow]`ed them. This PR changes that. This change would improve both the Rust lint infrastructure and Clippy, but Clippy will see the most benefit, as it has about 900 registered lints (and growing!)

So yeah, with this little patch we filter all lints pre-linting, and remove any lint that is either:
- Manually `#![allow]`ed in the whole crate,
- Allowed in the command line, or
- Not manually enabled with `#[warn]` or similar, and its default level is `Allow`

As some lints **need** to run, this PR also adds **loadbearing lints**. On a lint declaration, you can use the ``@eval_always` = true` marker to label it as loadbearing. A loadbearing lint will never be filtered (it will always run)

Fixes #106983
2024-10-26 16:37:43 +00:00
Jieyou Xu
5f4739157a Downgrade untranslatable_diagnostic and diagnostic_outside_of_impl to allow
See <https://github.com/rust-lang/rust/issues/132181> for more context.
2024-10-26 14:11:59 +00:00