Commit Graph

1688 Commits

Author SHA1 Message Date
bors
1984752623 Auto merge of #13255 - Jarcho:get_src_display2, r=Manishearth
Remove more `snippet_opt` calls

First commit is the same as #13244

changelog: none
2024-08-12 18:50:19 +00:00
bors
52192aa321 Auto merge of #13243 - Alexendoo:rustcversion, r=flip1995
Replace `rustc_semver` with `rustc_session::RustcVersion`

Allows dropping a dependency but there is a behaviour change here, the following versions are no longer accepted:

* `1` (would need to be `1.0` or `1.0.0`)
* `1.0.0-alpha`
* `1.0.0-alpha.2`
* `1.0.0-beta`

But this seems unlikely to effect anybody, I did some GitHub searching and found no occurrences outside our UI tests

r? `@flip1995`

changelog: none
2024-08-12 08:24:00 +00:00
Jason Newcomb
ddf2ba5886 Remove more instances of snippet_opt. 2024-08-11 18:07:53 -04:00
Jason Newcomb
f9509d3574 Refactor absolute_paths:
* Check the path length first
* Use `is_from_proc_macro`
* Use symbols instead of strings when checking crate names
2024-08-09 22:08:29 -04:00
Jason Newcomb
9afab36ca9 Rename get_source_text to get_source_range. Add new get_source_text which returns a displayable string-like type. 2024-08-09 09:27:00 -04:00
Alex Macleod
b32a0176fa Replace rustc_semver with rustc_session::RustcVersion 2024-08-09 13:00:24 +00:00
Philipp Krones
7a73a101e9
Merge remote-tracking branch 'upstream/master' into rustup 2024-08-08 18:54:43 +02: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
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