Commit Graph

1788 Commits

Author SHA1 Message Date
Alex Macleod b32a0176fa Replace `rustc_semver` with `rustc_session::RustcVersion` 2024-08-09 13:00:24 +00:00
bors 7591ec4e88 Auto merge of #128703 - compiler-errors:normalizing-tails, r=lcnr
Miscellaneous improvements to struct tail normalization

1. Make checks for foreign tails more accurate by normalizing the struct tail. I didn't write a test for this one.
2. Normalize when computing struct tail for `offset_of` for slice/str. This fixes the new solver only.
3. Normalizing when computing tails for disaligned reference check. This fixes both solvers.

r? lcnr
2024-08-09 11:36:01 +00:00
Nicholas Nethercote e785219238 Shrink `TyKind::FnPtr`.
By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and
`FnHeader`, which can be packed more efficiently. This reduces the size
of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms.
This reduces peak memory usage by a few percent on some benchmarks. It
also reduces cache misses and page faults similarly, though this doesn't
translate to clear cycles or wall-time improvements on CI.
2024-08-09 14:33:25 +10:00
Philipp Krones 1ac76a2062 Merge commit 'cb806113e0f83a8f9b47d35b453b676543bcc40e' into clippy-subtree-update 2024-08-08 19:13:50 +02:00
Philipp Krones 7a73a101e9
Merge remote-tracking branch 'upstream/master' into rustup 2024-08-08 18:54:43 +02:00
Michael Goulet 6ce7e6d99f Rename struct_tail_erasing_lifetimes to struct_tail_for_codegen 2024-08-08 12:15:16 -04:00
bors b1e87922c1 Auto merge of #13200 - Jarcho:constant_no_typeck, r=Alexendoo
Don't use `LateContext` in the constant evaluator

This also changes the interface to require explicitly creating the context. `constant` could be added back in, but the others are probably not worth it.

A couple of bugs have been fixed. The wrong `TypeckResults` was used once when evaluating a constant, and the wrong `ParamEnv` was used by some callers (there wasn't a way to use the correct one).

changelog: none
2024-08-08 14:42:42 +00:00
Jason Newcomb e4ad36d6a8 Require `ConstEvalCtxt` to be constructed. 2024-08-08 10:37:10 -04:00
Jason Newcomb d2cb227eb4 Don't store `LateContext` in `ConstEvalLateContext` 2024-08-08 10:34:53 -04:00
Jason Newcomb 3779062955 Add `HasSession` trait 2024-08-08 10:31:45 -04:00
Jason Newcomb 16633a2d7b Replace `in_constant` with `is_in_const_context`. Use only the state in `LateContext` to avoid walking the HIR tree. 2024-08-07 09:57:27 -04:00
Jason Newcomb 4e57b2c46f Use `-D warnings` instead of `deny-warnings` feature. 2024-08-06 10:46:39 -04:00
Alex Macleod 1ea7bddbdf Remove `multispan_sugg[_with_applicability]` 2024-08-04 13:14:23 +00:00
bors 1ea827fa03 Auto merge of #13115 - tesuji:rm-dup-peels, r=dswij
Remove duplicated `peel_middle_ty_refs`

TODO: Should we move `ty::peel_mid_ty_refs_is_mutable` to super module too?

changelog: none
2024-08-03 07:32:30 +00:00
Alex Macleod 943a8e0646 Remove some miscellaneous `#[allow]`s 2024-07-29 19:57:39 +00:00
shenyifu 38a3462037 Fix fix under loop may dropping loop label when applying fix. 2024-07-29 17:43:03 +08:00
Mark Rousskov 5faea65d4d step cfg(bootstrap) 2024-07-28 14:46:29 -04:00
bors d20be39c7f Auto merge of #13149 - jusexton:issue-13123, r=dswij
Fix while_let_on_iterator dropping loop label when applying fix.

Loop label was not persisted when displaying help and was therefore producing broken rust code when applying fixes.

Solution was to store the `ast::Label` when creating a `higher::WhileLet` from an expression and add the label name to the lint suggestion and diagnostics.

---

Fixes: https://github.com/rust-lang/rust-clippy/issues/13123

changelog: [`while_let_on_iterator`]: Fix issue dropping loop label when displaying help and applying fixes.
2024-07-27 15:23:21 +00:00
Guillaume Gomez 4969960a9c Fix dogfood lints 2024-07-26 11:21:32 +02:00
bors c7cfe7f5e2 Auto merge of #13156 - y21:for_each_expr_visitor_refactor, r=xFrednet
Remove unnecessary `res` field in `for_each_expr` visitors

Small refactor in the `for_each_expr*` visitors. This should not change anything functionally.

Instead of storing the final value `Option<B>` in the visitor and setting it to `Some` when we get a `ControlFlow::Break(B)` from the closure, we can just directly return it from the visitor itself now that visitors support that.

cc #12829 and https://github.com/rust-lang/rust-clippy/pull/12830#discussion_r1627882827

changelog: none
2024-07-25 17:51:02 +00:00
Philipp Krones 4e6851e50b Merge commit '37f4fbb92913586b73a35772efd00eccd1cbbe13' into clippy-subtree-update 2024-07-25 18:29:17 +02:00
Philipp Krones 71b0f0fcac
Bump Clippy version -> 0.1.82 2024-07-25 18:23:37 +02:00
Philipp Krones 9f53fc32cf
Merge remote-tracking branch 'upstream/master' into rustup 2024-07-25 18:23:27 +02:00
y21 de1e163779 get rid of unnecessary `res` field in `for_each_expr` visitors 2024-07-25 15:02:31 +02:00
bors 5e6540f049 Auto merge of #13146 - Alexendoo:cast-lossless-128, r=y21
Lint casts to `u128` in `cast_lossless`

Reverts #12496 per https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Should.20.60as.20u128.60.20trigger.20cast_lossless

Also changes the lint messages and refactors the suggestion production - Fixes #12695

changelog: [`cast_lossless`]: lint casts to `u128`
2024-07-24 21:00:05 +00:00
Alex Macleod 6d28e1a954 Lint casts to `u128` in `cast_lossless` 2024-07-24 14:32:41 +00:00
blyxyas b21a91ae3a Replace local variables signifying "done" or "loop break", use ControlFlow #12830 2024-07-24 01:40:58 +02:00
jusexton 0cdf6e172c Fix while_let_on_iterator dropping loop label when applying fix. 2024-07-23 02:55:58 -05:00
Jason Newcomb e34c6dbae5 Refactor for using config values:
* Construct lint passes by taking `Conf` by reference.
* Use `HashSet` configs in less places
* Move some `check_crate` code into the pass constructor when possible.
2024-07-17 14:05:49 -04:00
Lzu Tao a5fd2c98bd Remove duplicated peel_middle_ty_refs
TODO: Should we move `ty::peel_mid_ty_refs_is_mutable` to super module too?
2024-07-17 12:51:08 +07:00
Noah Lev f2c1265483 Add `ConstArgKind::Path` and make `ConstArg` its own HIR node
This is a very large commit since a lot needs to be changed in order to
make the tests pass. The salient changes are:

- `ConstArgKind` gets a new `Path` variant, and all const params are now
  represented using it. Non-param paths still use `ConstArgKind::Anon`
  to prevent this change from getting too large, but they will soon use
  the `Path` variant too.

- `ConstArg` gets a distinct `hir_id` field and its own variant in
  `hir::Node`. This affected many parts of the compiler that expected
  the parent of an `AnonConst` to be the containing context (e.g., an
  array repeat expression). They have been changed to check the
  "grandparent" where necessary.

- Some `ast::AnonConst`s now have their `DefId`s created in
  rustc_ast_lowering rather than `DefCollector`. This is because in some
  cases they will end up becoming a `ConstArgKind::Path` instead, which
  has no `DefId`. We have to solve this in a hacky way where we guess
  whether the `AnonConst` could end up as a path const since we can't
  know for sure until after name resolution (`N` could refer to a free
  const or a nullary struct). If it has no chance as being a const
  param, then we create a `DefId` in `DefCollector` -- otherwise we
  decide during ast_lowering. This will have to be updated once all path
  consts use `ConstArgKind::Path`.

- We explicitly use `ConstArgHasType` for array lengths, rather than
  implicitly relying on anon const type feeding -- this is due to the
  addition of `ConstArgKind::Path`.

- Some tests have their outputs changed, but the changes are for the
  most part minor (including removing duplicate or almost-duplicate
  errors). One test now ICEs, but it is for an incomplete, unstable
  feature and is now tracked at #127009.
2024-07-16 19:27:28 -07:00
Noah Lev 6e99e2d748 Use `ConstArg` for array lengths 2024-07-16 19:27:28 -07:00
Noah Lev 620a056a33 hir: Create `hir::ConstArgKind` enum
This will allow lowering const params to a dedicated enum variant, rather
than to an `AnonConst` that is later examined during `ty` lowering.
2024-07-16 19:27:28 -07:00
apoisternex 489a77831c fix [`excessive_precision`] suggestions on float literal written in scientific notation
fixes: #12954

changelog: fix [`excessive_precision`] suggestions on float literal written in scientific notation
2024-07-15 18:52:18 -03:00
bors eb4d88e690 Auto merge of #13102 - tesuji:fix-needless_option_as_deref, r=Alexendoo
Fix `needless_option_as_deref` false-positive on struct literals

changelog: [`needless_option_as_deref`] Fix false-positive on struct literals.

Fixes #13077 .

r?  Alexendoo
2024-07-15 16:23:41 +00:00
Lzu Tao dcee2e8a0f Dont stop find loop node at struct field node 2024-07-15 15:56:17 +00:00
Philipp Krones c1fd25d0aa Merge commit 'b794b8e08c16517a941dc598bb1483e8e12a8592' into clippy-subtree-update 2024-07-11 15:44:03 +02:00
Philipp Krones 1ced73e66a
Merge remote-tracking branch 'upstream/master' into rustup 2024-07-11 15:29:08 +02:00
bors e82cfdc559 Auto merge of #127476 - jieyouxu:rollup-16wyb0b, r=jieyouxu
Rollup of 10 pull requests

Successful merges:

 - #126841 ([`macro_metavar_expr_concat`] Add support for literals)
 - #126881 (Make `NEVER_TYPE_FALLBACK_FLOWING_INTO_UNSAFE` a deny-by-default lint in edition 2024)
 - #126921 (Give VaList its own home)
 - #127367 (Run alloc sync tests)
 - #127431 (Use field ident spans directly instead of the full field span in diagnostics on local fields)
 - #127437 (Uplift trait ref is knowable into `rustc_next_trait_solver`)
 - #127439 (Uplift elaboration into `rustc_type_ir`)
 - #127451 (Improve `run-make/output-type-permutations` code and improve `filename_not_in_denylist` API)
 - #127452 (Fix intrinsic const parameter counting with `effects`)
 - #127459 (rustdoc-json: add type/trait alias tests)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-07-08 06:47:12 +00:00
Maybe Waffle 791ff40337 Add support for `mir::TerminatorKind::TailCall` in clippy 2024-07-07 17:11:05 +02:00
Michael Goulet 7ce4a49911 iter_identity is a better name 2024-07-07 00:12:35 -04:00
Jason Newcomb d8fb164a7c Rename `any_parent_is_automatically_derived` to `in_automatically_derived`. Only check for the attribute on an impl block. 2024-07-06 00:24:48 -04:00
bors 3ef366705b Auto merge of #13049 - Jarcho:is_in_test, r=Alexendoo
Remove `is_in_test_module_or_function`

Uses are replaced with `is_in_test` for consistency with other lints and to simplify the implementation of the lints. This means the module name is no longer checked, but that was a horrible hack from a time when late passes couldn't see `#[cfg(..)]` attributes.

changelog: none
2024-07-05 11:33:46 +00:00
Jason Newcomb 6d61bdabea Use `is_in_test` in more places. 2024-07-05 02:42:58 -04:00
bors 885f97e2ce Auto merge of #11656 - y21:unnecessary_string_from_utf8, r=Jarcho
[`unnecessary_to_owned`]: catch `to_owned` on byte slice to create temporary `&str`

Closes #11648

Detects the pattern `&String::from_utf8(bytes.to_vec()).unwrap()` and suggests `core::str::from_utf8(bytes).unwrap()`, which avoids the unnecessary intermediate allocation.

I decided to put this in the existing `unnecessary_to_owned` lint (rather than creating a new lint) for a few reasons:
- we get to use some of its logic (for example, recognizing any of the functions in the `to_owned` family, e.g. `to_vec`)
- the actual inefficient operation that can be avoided here is the call to `.to_vec()`, so this is in a way similar to the other cases caught by `unnecessary_to_owned`, just through a bunch of type conversions
- we can make this more "generic" later and catch other cases, so imo it's best not to tie this lint specifically to the `String` type

changelog: [`unnecessary_to_owned`]: catch `&String::from_utf8(bytes.to_vec()).unwrap()` and suggest `core::str::from_utf8(bytes).unwrap()`
2024-07-05 02:04:06 +00:00
bors 0f4035fde3 Auto merge of #12976 - tesuji:fix-explicit_auto_deref, r=xFrednet
Fix some false-positive cases of `explicit_auto_deref`

changelog: [`explicit_auto_deref`] Fix some false-positive cases

Fix part of #9841
Fix  #12969

r? xFrednet
2024-07-03 18:24:23 +00:00
Lzu Tao c4c41d1352 Fix 12969 and fix 9841 2024-07-03 21:25:43 +07:00
Astra Tsai 0dd8b27b6b Fix formatting 2024-07-01 19:10:10 -07:00
Astra Tsai 567bea29b1 Fix `into_iter_without_iter` false positive when the implementation is not within the first `impl` block 2024-07-01 18:57:24 -07:00
bors c4125286ce Auto merge of #12840 - tesuji:const-asserts, r=llogiq
Don't lint `assertions_on_constants` on any const assertions

close #12816
close #12847
cc #12817

----

changelog: Fix false positives in consts for `assertions_on_constants` and `unnecessary_operation`.
2024-07-01 22:06:06 +00:00
Matthias Krüger fb95df70a7 Rollup merge of #127058 - compiler-errors:tighten-async-spans, r=oli-obk
Tighten `fn_decl_span` for async blocks

Tightens the span of `async {}` blocks in diagnostics, and subsequently async closures and async fns, by actually setting the `fn_decl_span` correctly. This is kinda a follow-up on #125078, but it fixes the problem in a more general way.

I think the diagnostics are significantly improved, since we no longer have a bunch of overlapping spans. I'll point out one caveat where I think the diagnostic may get a bit more confusing, but where I don't think it matters.

r? ````@estebank```` or ````@oli-obk```` or someone else on wg-diag or compiler i dont really care lol
2024-06-28 08:34:10 +02:00
Michael Goulet 39a215531c Tighten spans for async blocks 2024-06-27 15:19:08 -04:00
Philipp Krones abdd057163 Merge commit '68a799aea9b65e2444fbecfe32217ce7d5a3604f' into clippy-subtree-update 2024-06-27 18:56:04 +02:00
Philipp Krones e9e7a815a7
Merge remote-tracking branch 'upstream/master' into rustup 2024-06-27 18:49:59 +02:00
xFrednet 1b4c281fe7 RFC 2383: Stabilize `lint_reasons` in Clippy 🖇️ 2024-06-25 17:50:48 +02:00
Michael Goulet a155c38989 Split out IntoIterator and non-Iterator constructors for AliasTy/AliasTerm/TraitRef/projection 2024-06-24 11:28:21 -04:00
bors 26c556dd63 Auto merge of #12965 - KisaragiEffective:resolve-invalid-paths-on-bool-then, r=blyxyas
resolve `clippy::invalid_paths` on `bool::then`

*Please write a short comment explaining your change (or "none" for internal only changes)*

changelog: none
2024-06-22 22:47:21 +00:00
Jason Newcomb 4baae5d8b3 Add new `Span` utils to avoid both allocating and
compressing/decompressing spans.
2024-06-21 03:23:06 -04:00
Michael Goulet f6661f5b9b StaticForeignItem and StaticItem are the same 2024-06-20 19:51:09 -04:00
vohoanglong0107 2f9f204123 feat: unnecessary_min_max lint 2024-06-20 13:57:16 +00:00
Kisaragi Marine 9749d990ed
resolve `clippy::invalid_paths` on `bool::then` 2024-06-20 11:45:45 +09:00
y21 ed9ccf66e9 [`unnecessary_to_owned`]: catch to_owned from byte slice to string 2024-06-20 00:09:31 +02:00
Trevor Gross 8cde354f0b Resolve Clippy `f16` and `f128` `unimplemented!`/`FIXME`s
This removes the ICE codepaths for `f16` and `f128` in Clippy.
`rustc_apfloat` is used as a dependency for the parsing of these types,
since their `FromStr` implementation will not be available in the
standard library for a while.
2024-06-19 13:30:21 -04:00
bors 29cc5c691c Auto merge of #12942 - Jarcho:ex_proc_macro, r=Manishearth
Add more types to `is_from_proc_macro`

I've been running through going through all the lint implementations to clean them up. I'll be separating out the changes into small PRs to make reviewing easier.

changelog: none
2024-06-18 23:45:47 +00:00
Michael Goulet 7218fdd2db Fix other tools 2024-06-17 22:35:25 -04:00
bors 2ad53f4e38 Auto merge of #12943 - Jarcho:range_sym, r=llogiq
Use symbols when raising range expressions.

----

changelog: none
2024-06-17 12:15:18 +00:00
Jason Newcomb f09650b347 Use symbols when raising range expressions. 2024-06-16 20:24:43 -04:00
Jason Newcomb e18b310874 Add more types to `is_from_proc_macro` 2024-06-16 20:15:09 -04:00
Jason Newcomb 22710f33a8 Add lint `manual_inspect` 2024-06-16 18:33:43 -04:00
Jason Newcomb a002f93e51 `expr_use_ctxt` changes:
* Delay the parsing of the use node
* Mark when the `SyntaxContext` changes rather than return `None`
* Return a default value if the HIR tree is broken rather than `None`
2024-06-16 18:00:21 -04:00
bors 0dc265ff82 Auto merge of #12756 - y21:assigning_clones_lifetimes, r=Alexendoo
Avoid emitting `assigning_clones` when cloned data borrows from the place to clone into

Fixes #12444
Fixes #12460
Fixes #12749
Fixes #12757
Fixes #12929

I think the documentation for the function should describe what- and how this is fixing the issues well.
It avoids emitting a warning when the data being cloned borrows from the place to clone into, which is information that we can get from `PossibleBorrowerMap`. Unfortunately, it is a tiny bit tedious to match on the MIR like that and I'm not sure if this is possibly relying a bit too much on the exact MIR lowering for assignments.

Things left to do:
- [x] Handle place projections (or verify that they work as expected)
- [x] Handle non-`Drop` types

changelog: [`assigning_clones`]: avoid warning when the suggestion would lead to a borrow-check error
2024-06-15 18:25:42 +00:00
Philipp Krones 3bff119f63 Merge commit '3e5a02b13b1244545454752c6629b767522a44b1' into clippy-subtree-update 2024-06-13 12:30:48 +02:00
Philipp Krones 614966b0c3
Bump Clippy version -> 0.1.81 2024-06-13 12:24:14 +02:00
Philipp Krones cc63143bbf
Merge remote-tracking branch 'upstream/master' into rustup 2024-06-13 12:24:08 +02:00
bors 38d12a9bc0 Auto merge of #12681 - y21:issue12677, r=Jarcho
Let `qualify_min_const_fn` deal with drop terminators

Fixes #12677

The `method_accepts_droppable` check that was there seemed overly conservative.
> Returns true if any of the method parameters is a type that implements `Drop`.
> The method can't be made const then, because `drop` can't be const-evaluated.

Accepting parameters that implement `Drop` should still be fine as long as the parameter isn't actually dropped, as is the case in the linked issue where the droppable is moved into the return place. This more accurate analysis ("is there a `drop` terminator") is already done by `qualify_min_const_fn` [here](f5e250180c/clippy_utils/src/qualify_min_const_fn.rs (L298)), so I don't think this additional check is really necessary?

Fixing the other, second case in the linked issue was only slightly more involved, since `Vec::new()` is a function call that has the ability to panic, so there must be a `drop()` terminator for cleanup, however we should be able to freely ignore that. [Const checking ignores cleanup blocks](https://github.com/rust-lang/rust/blob/master/compiler/rustc_const_eval/src/transform/check_consts/check.rs#L382-L388), so we should, too?

r? `@Jarcho`

----

changelog: [`missing_const_for_fn`]: continue linting on fns with parameters implementing `Drop` if they're not actually dropped
2024-06-11 22:38:52 +00:00
AurelienFT c86b19f1ef Add lint to check manual pattern char comparison and merge its code with single_char_pattern lint 2024-06-11 21:56:14 +02:00
Ralf Jung 8c1f953772 ScalarInt: size mismatches are a bug, do not delay the panic 2024-06-10 13:43:16 +02:00
Lzu Tao b161dc659c add utils is_inside_always_const_context 2024-06-08 16:50:25 +07:00
bors d553ebef57 Auto merge of #12851 - samueltardieu:issue12846, r=y21
Add required parentheses around method receiver

Fix #12846

changelog: [`needless_bool`]: Add missing parentheses around method receiver
2024-06-07 21:27:46 +00:00
y21 973f318514 qualify_min_const_fn: ignore cleanup bbs 2024-06-07 20:56:22 +02:00
bors 0f87a81882 Auto merge of #12822 - Alexendoo:for-each-expr, r=dswij
Make `for_each_expr` visit closures by default, rename the old version `for_each_expr_without_closures`

A lot of the time `for_each_expr` is picked when closures should be visited so I think it makes sense for this to be the default with the alternative available for when you don't need to visit them.

The first commit renames `for_each_expr` to `for_each_expr_without_closures` and `for_each_expr_with_closures` to `for_each_expr`

The second commit switches a few uses that I caught over to include closures to fix a few bugs

changelog: none
2024-06-07 09:42:37 +00:00
bors 0b441d5ac5 Auto merge of #12877 - y21:const_host_ice, r=dswij
Handle const effects inherited from parent correctly in `type_certainty`

This fixes a (debug) ICE in `type_certainty` that happened in the [k256 crate]. (I'm sure you can also specifically construct an edge test case that will run into type_certainty false positives visible outside of debug builds from this bug)

<details>
<summary>Minimal ICE repro</summary>

```rs
use std::ops::Add;
Add::add(1_i32, 1).add(i32::MIN);
```
</details>

The subtraction here overflowed:
436675b477/clippy_utils/src/ty/type_certainty/mod.rs (L209)

... when we have something like `Add::add` where `add` fn has 0 generic params but the `host_effect_index` is `Some(2)` (inherited from the parent generics, the const trait `Add`), and we end up executing `0 - 1`.

(Even if the own generics weren't empty and we didn't overflow, this would still be wrong because it would assume that a trait method with 1 generic parameter didn't have any generics).

So, *only* exclude the "host" generic parameter if it's actually bound by the own generics

changelog: none

[k256 crate]: https://github.com/RustCrypto/elliptic-curves/tree/master/k256
2024-06-07 09:33:48 +00:00
Oli Scherer abd011638d Revert "Create const block DefIds in typeck instead of ast lowering"
This reverts commit ddc5f9b6c1f21da5d4596bf7980185a00984ac42.
2024-06-07 08:33:58 +00:00
bors 16fcbd21e5 Auto merge of #126068 - lqd:revert-124976, r=petrochenkov
Revert "use `tcx.used_crates(())` more" before it reaches beta

There are more open issues caused by #124976 than will be fixed by #125493 alone. The beta cut is soon, so let's revert it and buy some time to analyze and fix these issues in our own time.

fixes https://github.com/rust-lang/rust/issues/125474
fixes https://github.com/rust-lang/rust/issues/125484
fixes https://github.com/rust-lang/rust/issues/125646
fixes https://github.com/rust-lang/rust/issues/125707
fixes #126066
fixes #125934
fixes https://github.com/rust-lang/rust/issues/126021

r? `@petrochenkov`
`@bors` p=1
2024-06-06 20:18:43 +00:00
Samuel Tardieu 1e23449678 Move `is_receiver_of_method_call` to `clippy_utils` for reuse 2024-06-06 20:09:21 +02:00
Rémy Rakic c245cde61c Revert "Rollup merge of #124976 - petrochenkov:usedcrates, r=oli-obk"
This reverts commit eda4a35f365535af72118118a3597edf5a13c12d, reversing
changes made to eb6b35b5bcb3c2a594cb29cd478aeb2893f49d30.
2024-06-06 10:06:28 +00:00
bors ea13653f6f Auto merge of #124482 - spastorino:unsafe-extern-blocks, r=oli-obk
Unsafe extern blocks

This implements RFC 3484.

Tracking issue #123743 and RFC https://github.com/rust-lang/rfcs/pull/3484

This is better reviewed commit by commit.
2024-06-06 08:14:58 +00:00
Boxy 38de6e1f3a Misc fixes to cranelift/clippy/miri 2024-06-05 22:25:42 +01:00
Santiago Pastorino bd0f908242 Add safe/unsafe to static inside extern blocks 2024-06-04 14:19:43 -03:00
Santiago Pastorino 537ce5c8c6 Handle safety keyword for extern block inner items 2024-06-04 14:19:42 -03:00
Michael Goulet 9f4a2dd147 Align Term methods with GenericArg methods 2024-06-03 20:36:27 -04:00
y21 708ef7955d only run flop lints on inherent method calls 2024-06-03 21:42:00 +02:00
y21 25d40c9f6b handle parent const effects correctly in type_certainty 2024-06-01 20:10:48 +02:00
Matthias Krüger febfa5157c Rollup merge of #125635 - fmease:mv-type-binding-assoc-item-constraint, r=compiler-errors
Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanup

Rename `hir::TypeBinding` and `ast::AssocConstraint` to `AssocItemConstraint` and update all items and locals using the old terminology.

Motivation: The terminology *type binding* is extremely outdated. "Type bindings" not only include constraints on associated *types* but also on associated *constants* (feature `associated_const_equality`) and on RPITITs of associated *functions* (feature `return_type_notation`). Hence the word *item* in the new name. Furthermore, the word *binding* commonly refers to a mapping from a binder/identifier to a "value" for some definition of "value". Its use in "type binding" made sense when equality constraints (e.g., `AssocTy = Ty`) were the only kind of associated item constraint. Nowadays however, we also have *associated type bounds* (e.g., `AssocTy: Bound`) for which the term *binding* doesn't make sense.

---

Old terminology (HIR, rustdoc):

```
`TypeBinding`: (associated) type binding
├── `Constraint`: associated type bound
└── `Equality`: (associated) equality constraint (?)
    ├── `Ty`: (associated) type binding
    └── `Const`: associated const equality (constraint)
```

Old terminology (AST, abbrev.):

```
`AssocConstraint`
├── `Bound`
└── `Equality`
    ├── `Ty`
    └── `Const`
```

New terminology (AST, HIR, rustdoc):

```
`AssocItemConstraint`: associated item constraint
├── `Bound`: associated type bound
└── `Equality`: associated item equality constraint OR associated item binding (for short)
    ├── `Ty`: associated type equality constraint OR associated type binding (for short)
    └── `Const`: associated const equality constraint OR associated const binding (for short)
```

r? compiler-errors
2024-05-31 08:50:22 +02:00
León Orell Valerian Liehr 040edea332 Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanup 2024-05-30 22:52:33 +02:00
Jacher 1c117f12ea ignore generics in handling 2024-05-30 13:15:25 +00:00
Jacherr e186ed2ad1 check return type of get and indexing 2024-05-30 11:45:57 +00:00
Jacherr 46b3264131 add backticks to doc comments 2024-05-30 11:45:43 +00:00
Jacherr 93b39d8910 disable indexing_slicing for custom Index impls 2024-05-30 11:45:43 +00:00
Philipp Krones f67f72695a Merge commit 'c9139bd546d9cd69df817faeab62c5f9b1a51337' into clippy-subtree-update 2024-05-30 10:49:05 +02:00
Philipp Krones 89037ea18f
Merge remote-tracking branch 'upstream/master' into rustup 2024-05-30 09:44:14 +02:00
Oli Scherer e3e27ba3dd Create const block DefIds in typeck instead of ast lowering 2024-05-28 13:38:43 +00:00
bors 4dd07f4e4e Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercote
[perf] Delay the construction of early lint diag structs

Attacks some of the perf regressions from https://github.com/rust-lang/rust/pull/124417#issuecomment-2123700666.

See individual commits for details. The first three commits are not strictly necessary.
However, the 2nd one (06bc4fc67145e3a7be9b5a2cf2b5968cef36e587, *Remove `LintDiagnostic::msg`*) makes the main change way nicer to implement.
It's also pretty sweet on its own if I may say so myself.
2024-05-27 08:44:12 +00:00
J-ZhengLi 03306b6ab6 suggest adding parentheses when linting [`let_and_return`] and [`needless_return`] 2024-05-27 11:49:10 +08:00
León Orell Valerian Liehr 0c653d9f91 Remove `LintDiagnostic::msg`
* instead simply set the primary message inside the lint decorator functions
* it used to be this way before [#]101986 which introduced `msg` to prevent
  good path delayed bugs (which no longer exist) from firing under certain
  circumstances when lints were suppressed / silenced
* this is no longer necessary for various reasons I presume
* it shaves off complexity and makes further changes easier to implement
2024-05-23 04:08:35 +02:00
Philipp Krones 4363278c73 Merge commit '2efebd2f0c03dabbe5c3ad7b4ebfbd99238d1fb2' into clippy-subtree-update 2024-05-21 10:39:30 -07:00
Matthias Krüger acf38f8466 Rollup merge of #125173 - scottmcm:never-checked, r=davidtwco
Remove `Rvalue::CheckedBinaryOp`

Zulip conversation: <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/intrinsics.20vs.20binop.2Funop/near/438729996>
cc `@RalfJung`

While it's a draft,
r? ghost
2024-05-20 18:13:48 +02:00
Alex Macleod e6040437ef Swap `for_each_expr` and `for_each_expr_with_closures` 2024-05-19 16:47:02 +00:00
Santiago Pastorino 23e8b03f00 Add and use generics.is_empty() and generics.is_own_empty, rather than using generics' attributes 2024-05-19 11:10:56 -03:00
bors 37dfd973b7 Auto merge of #125077 - spastorino:add-new-fnsafety-enum2, r=jackh726
Rename Unsafe to Safety

Alternative to #124455, which is to just have one Safety enum to use everywhere, this opens the posibility of adding `ast::Safety::Safe` that's useful for unsafe extern blocks.

This leaves us today with:

```rust
enum ast::Safety {
    Unsafe(Span),
    Default,
    // Safe (going to be added for unsafe extern blocks)
}

enum hir::Safety {
    Unsafe,
    Safe,
}
```

We would convert from `ast::Safety::Default` into the right Safety level according the context.
2024-05-18 19:35:24 +00:00
Scott McMurray 0cd64b5756 Fix clippy 2024-05-17 20:33:02 -07:00
Santiago Pastorino 0590d71ce2 Rename Unsafe to Safety 2024-05-17 18:33:37 -03:00
Philipp Krones c200dad300
Merge remote-tracking branch 'upstream/master' into rustup 2024-05-16 14:20:56 -07:00
Michael Goulet 4f589e322d Remove trivial Binder::dummy calls 2024-05-16 14:24:23 -04:00
Michael Goulet 6b371469bf Fix tools 2024-05-16 14:24:23 -04:00
bors caad063933 Auto merge of #12713 - J-ZhengLi:issue8864, r=y21
make sure the msrv for `const_raw_ptr_deref` is met when linting [`missing_const_for_fn`]

fixes: #8864

---

changelog: make sure the msrv for `const_ptr_deref` is met when linting [`missing_const_for_fn`]
2024-05-15 21:29:34 +00:00
J-ZhengLi 1b7fc5f5aa add some msrv checks in `is_min_const_fn` 2024-05-15 16:38:57 +08:00
Michael Goulet 760fbdf64e split out AliasTy -> AliasTerm 2024-05-13 11:59:42 -04:00
Michael Goulet e65cefcf6f Propagate errors rather than using return_if_err 2024-05-12 12:50:18 -04:00
Michael Goulet db193c1c9d Make LateCtxt be a type info delegate for EUV for clippy 2024-05-12 12:11:25 -04:00
Michael Goulet 2baeb9be54 Lift `TraitRef` into `rustc_type_ir` 2024-05-10 15:44:03 -04:00
Matthias Krüger 44c29bd7d1 Rollup merge of #124957 - compiler-errors:builtin-deref, r=michaelwoerister
Make `Ty::builtin_deref` just return a `Ty`

Nowhere in the compiler are we using the mutability part of the `TyAndMut` that we used to return.
2024-05-10 16:10:47 +02:00
bors ff931a7af8 Auto merge of #124961 - matthiaskrgr:rollup-1jj65p6, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #124551 (Add benchmarks for `impl Debug for str`)
 - #124915 (`rustc_target` cleanups)
 - #124918 (Eliminate some `FIXME(lcnr)` comments)
 - #124927 (opt-dist: use xz2 instead of xz crate)
 - #124936 (analyse visitor: build proof tree in probe)
 - #124943 (always use `GenericArgsRef`)
 - #124955 (Use fewer origins when creating type variables.)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-05-10 06:50:46 +00:00
Matthias Krüger b8997e30f0 Rollup merge of #124955 - nnethercote:next_ty_var, r=lcnr
Use fewer origins when creating type variables.

To reduce lots of repetitive boilerplate code. Details in the individual commit messages.

r? ``@lcnr``
2024-05-10 07:30:22 +02:00
Michael Goulet 51145a20bf Make builtin_deref just return a Ty 2024-05-09 22:55:00 -04:00
Michael Goulet 9523b3fbf0 Rename Generics::params to Generics::own_params 2024-05-09 20:58:46 -04:00
Nicholas Nethercote dbeae8da78 Use fewer origins when creating type variables.
`InferCtxt::next_{ty,const}_var*` all take an origin, but the
`param_def_id` is almost always `None`. This commit changes them to just
take a `Span` and build the origin within the method, and adds new
methods for the rare cases where `param_def_id` might not be `None`.
This avoids a lot of tedious origin building.

Specifically:
- next_ty_var{,_id_in_universe,_in_universe}: now take `Span` instead of
  `TypeVariableOrigin`
- next_ty_var_with_origin: added

- next_const_var{,_in_universe}: takes Span instead of ConstVariableOrigin
- next_const_var_with_origin: added

- next_region_var, next_region_var_in_universe: these are unchanged,
  still take RegionVariableOrigin

The API inconsistency (ty/const vs region) seems worth it for the
large conciseness improvements.
2024-05-10 09:47:46 +10:00
y21 dff9164ac5 consider `copy_deref` a possible borrower 2024-05-10 00:33:29 +02:00
lcnr 9b4ad016ec always use `GenericArgsRef` 2024-05-09 19:52:02 +00:00
Matthias Krüger eef082899d Rollup merge of #123344 - pietroalbini:pa-unused-imports, r=Nilstrieb
Remove braces when fixing a nested use tree into a single item

[Back in 2019](https://github.com/rust-lang/rust/pull/56645) I added rustfix support for the `unused_imports` lint, to automatically remove them when running `cargo fix`. For the most part this worked great, but when removing all but one childs of a nested use tree it turned `use foo::{Unused, Used}` into `use foo::{Used}`. This is slightly annoying, because it then requires you to run `rustfmt` to get `use foo::Used`.

This PR automatically removes braces and the surrouding whitespace when all but one child of a nested use tree are unused. To get it done I had to add the span of the nested use tree to the AST, and refactor a bit the code I wrote back then.

A thing I noticed is, there doesn't seem to be any `//@ run-rustfix` test for fixing the `unused_imports` lint. I created a test in `tests/suggestions` (is that the right directory?) that for now tests just what I added in the PR. I can followup in a separate PR to add more tests for fixing `unused_lints`.

This PR is best reviewed commit-by-commit.
2024-05-08 23:33:24 +02:00
Michael Howell afedaf6a26 Update doc comments to avoid lazy continuations 2024-05-06 16:31:23 -07:00
bors 28002514d5 Auto merge of #12742 - Alexendoo:assigning-clones-nested-late-init, r=dswij
Don't lint assigning_clones on nested late init locals

Fixes #12741

changelog: none
2024-05-04 19:36:06 +00:00
bors 3cdc951b0b Auto merge of #124401 - oli-obk:some_hir_cleanups, r=cjgillot
Some hir cleanups

It seemed odd to not put `AnonConst` in the arena, compared with the other types that we did put into an arena. This way we can also give it a `Span` without growing a lot of other HIR data structures because of the extra field.

r? compiler
2024-05-04 00:32:27 +00:00
bors 993d8ae2a7 Auto merge of #12567 - Alexendoo:format-args-storage, r=flip1995
Fix `FormatArgs` storage when `-Zthreads` > 1

Fixes #11886

The initial way I thought of was a little gross so I never opened a PR for it, I thought of a nicer way today that no longer involves any `thread_local`s or `static`s

`rustc_data_strucutres::sync::{Lrc, OnceLock}` implement `DynSend` + `DynSync` so we can pass them to the lint passes that need the storage

changelog: none

r? `@flip1995`
2024-05-03 09:21:22 +00:00
Philipp Krones 80c6f8ff7b Merge commit '20b085d500dfba5afe0869707bf357af3afe20be' into clippy-subtree-update 2024-05-02 17:26:44 +02:00
bors c36918329f Auto merge of #12743 - CBSpeir:remove-paths-vec_resize, r=y21
Remove `dead_code` paths

The following paths are `dead_code` and can be removed:

### `clippy_utils::paths::VEC_RESIZE`
* Introduced when `vec_resize_to_zero` lint added in PR https://github.com/rust-lang/rust-clippy/pull/5637
* No longer used after commit 8acc4d2f1e
### `clippy_utils::paths::SLICE_GET`
* Introduced when `get_first` lint added in PR https://github.com/rust-lang/rust-clippy/pull/8882
* No longer used after commit a8d80d531f
### `clippy_utils::paths::STR_BYTES`
* Introduced when `bytes_count_to_len` lint added in PR https://github.com/rust-lang/rust-clippy/pull/8711
* No longer used after commit ba6a459528

When the lints were moved into the `Methods` lint pass, they switched from using paths to diagnostic items.  However, the paths were never removed.  This occurred in PR https://github.com/rust-lang/rust-clippy/pull/8957.

This relates to issue https://github.com/rust-lang/rust-clippy/issues/5393

changelog: none
2024-05-02 12:47:40 +00:00
Philipp Krones 76b95fd249
Bump Clippy version -> 0.1.80 2024-05-02 14:21:19 +02:00
Philipp Krones e8492355a3
Merge remote-tracking branch 'upstream/master' into rustup 2024-05-02 14:21:00 +02:00
Christopher B. Speir 5e05821af3 Remove clippy_utils::paths::{SLICE_GET, STR_BYTES}
Both clippy_utils::paths::SLICE_GET and clippy_utils::paths::STR_BYTES
are dead_code and can therefore be removed.
2024-05-01 22:23:31 -05:00
Christopher B. Speir fed9940e57 Remove clippy_utils::paths::VEC_RESIZE
This path is no longer used and can be removed.
2024-05-01 08:45:45 -05:00
Alex Macleod c313ef51df Don't lint assigning_clones on nested late init locals 2024-05-01 12:22:50 +00:00
Alex Macleod c187bff864 Fix `FormatArgs` storage when `-Zthreads` > 1 2024-05-01 11:35:04 +00:00
Santiago Pastorino 9276ce1cf3 Add StaticForeignItem and use it on ForeignItemKind 2024-04-29 13:15:51 -03:00
Andre Bogus 87efce4fa2 configurably allow `useless_vec` in tests
This adds a `àllow-useless-vec-in-test` configuration which, when set
to `true` will allow the `useless_vec` lint in `#[test]` functions and
code within `#[cfg(test)]`. It also moves a `is_in_test` helper to
`clippy_utils`.
2024-04-28 22:07:56 +02:00
bors c6bf9548d5 Auto merge of #12624 - J-ZhengLi:issue12586, r=xFrednet
fix [`large_stack_arrays`] linting in `vec` macro

fixes: #12586

this PR also adds a wrapper function `matching_root_macro_call` to `clippy_utils::macros`, considering how often that same pattern appears in the codebase.

(I'm always very indecisive towards naming, so, if anyone have better idea of how that function should be named, feel free to suggest it)

---

changelog: fix [`large_stack_arrays`] linting in `vec` macro; add `matching_root_macro_call` to clippy_utils
2024-04-27 09:30:20 +00:00
Oli Scherer b1a4f87257 put `hir::AnonConst` on the hir arena 2024-04-26 12:57:02 +00:00
bors c642d0cab6 Auto merge of #12696 - smoelius:fix-is_test_module_or_function, r=Alexendoo
Fix `is_test_module_or_function`

The rustdoc comment for `is_test_module_or_function` states: 2795a60189/clippy_utils/src/lib.rs (L2561-L2566)

Given `item`, the function calls `is_in_test_function` with `item.hir_id()`. However, `is_in_test_function` considers only `item`'s parents, not `item` itself. This PR fixes the problem.

The `test_with_disallowed_name` test fails without the fix, but passes once applied.

changelog: none
2024-04-20 15:06:02 +00:00
Samuel Moelius de258cc6be Fix `is_test_module_or_function` 2024-04-20 01:20:03 +00:00
Alex Macleod f7aef635c1 Rework interior mutability detection 2024-04-18 17:33:39 +00:00
Philipp Krones a5aaf33422 Merge commit 'ca3b393750ee8d870bf3215dcf6509cafa5c0445' into clippy-subtree-update 2024-04-18 17:48:52 +02:00