Commit Graph

20495 Commits

Author SHA1 Message Date
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
bors
cb806113e0 Auto merge of #13236 - flip1995:rustup, r=flip1995
Rustup

r? `@ghost`

changelog: ICE fix [`uninit_vec`] through https://github.com/rust-lang/rust/pull/128720
2024-08-08 17:00:00 +00:00
Philipp Krones
e608b2fcf5
Bump nightly version -> 2024-08-08 2024-08-08 18:55:00 +02: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
bors
ffc391c766 Auto merge of #13231 - Jarcho:no_tree_walk_in_const, r=Alexendoo
Don't walk the HIR tree when checking for a const context

changelog: none
2024-08-08 13:47:18 +00:00
bors
5ccf5432ab Auto merge of #11441 - Jarcho:issue_11365, r=xFrednet
`single_match`: fix checking of explicitly matched enums

fixes #11365

This approach has false-negatives, but fixing them will require a significant amount of additional state tracking. The comment in `add_and_pats` has the explanation.

changelog: `single_match`: correct checking if the match explicitly matches all of an enum's variants.
2024-08-08 09:20:56 +00:00
bors
bfb10f431d Auto merge of #13234 - Alexendoo:lintcheck-doc-links, r=xFrednet
lintcheck: disable doc links

Removes the `help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#...` line to make the reports more concise

r? `@xFrednet`

changelog: none
2024-08-08 07:37:32 +00:00
Alex Macleod
17de8fbd06 lintcheck: disable doc links 2024-08-08 00:39:30 +00:00
bors
f2deab375c Auto merge of #13232 - Alexendoo:path-prefix, r=flip1995
Add path prefixes back when compiling `clippy_dev` and `lintcheck`

`cargo dev` and `cargo lintcheck` use `--manifest-path` to select the package to compile, with this Cargo changes the CWD to the package's containing directory meaning paths in diagnostics start from e.g. `src/` instead of `clippy_dev/src/`

Lintcheck uses a `--remap-path-prefix` trick when linting crates to re-add the directory name in diagnostics:

5ead90f13a/lintcheck/src/main.rs (L93-L94)

5ead90f13a/lintcheck/src/main.rs (L102-L103)

It works well as far as I can tell, when absolute paths appear they stay absolute and do not have the prefix added

[`profile-rustflags`](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#profile-rustflags-option) allows us to set per package `RUSTFLAGS` in order to use the same trick on the `clippy_dev` and `lintcheck` packages themselves

Now when you run into warnings/errors the filename will be correctly clickable

Before
```
error[E0425]: cannot find value `moo` in this scope
  --> src/lib.rs:41:5
   |
41 |     moo;
   |     ^^^ not found in this scope
```

After
```
error[E0425]: cannot find value `moo` in this scope
  --> clippy_dev/src/lib.rs:41:5
   |
41 |     moo;
   |     ^^^ not found in this scope
```

r? `@flip1995`

changelog: none
2024-08-07 18:53:50 +00:00
Alex Macleod
8225f2a793 Add path prefixes back when compiling clippy_dev and lintcheck 2024-08-07 16:37:05 +00:00
Jason Newcomb
8bcecfff95 Handle or patterns in single_match and single_match_else 2024-08-07 11:40:15 -04:00
Jason Newcomb
514824ff9d Refactor single_match 2024-08-07 11:32:06 -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
bors
5ead90f13a Auto merge of #12150 - ithinuel:add_misleading_use_of_ok, r=y21
Add lint for `unused_result_ok`

This PR adds a lint to capture the use of `expr.ok();` when the result is not _really_ used.

This could be interpreted as the result being checked (like it is with `unwrap()` or `expect`) but
it actually only ignores the result.

`let _ = expr;` expresses that intent better.

This was also mentionned in #8994 (although not being the main topic of that issue).

changelog: [`misleading_use_of_ok`]: Add new lint to capture `.ok();` when the result is not _really_ used.
2024-08-06 19:01:41 +00:00
bors
9d9a0dcb64 Auto merge of #13225 - Jarcho:warnings, r=flip1995
Use `-D warnings` instead of `deny-warnings` feature.

r? `@flip1995`
changelog: none
2024-08-06 14:58:50 +00:00
Jason Newcomb
4e57b2c46f Use -D warnings instead of deny-warnings feature. 2024-08-06 10:46:39 -04:00
bors
a411267453 Auto merge of #13210 - Alexendoo:lintcheck-force-warn, r=xFrednet
lintcheck: force warn all lints

It occurred to me that like `--filter` we could use `--force-warn` for normal operations, we especially want to see lints that crates decided were too annoying or were false positives

Also excludes `clippy::cargo` from the default set as nobody is really writing those and it slows things down

r? `@xFrednet`

changelog: none
2024-08-06 09:46:08 +00:00
bors
cfb38819cc Auto merge of #13145 - xFrednet:07797-restriction-and-then-why, r=Jarcho
Make restriction lint's use `span_lint_and_then` (q -> w)

This migrates a few restriction lints to use `span_lint_and_then`. This change is motivated by https://github.com/rust-lang/rust-clippy/issues/7797.

I've also cleaned up some lint message. Mostly minor stuff. For example: suggestions with a longer message than `"try"` now use `SuggestionStyle::ShowAlways`

---

cc: https://github.com/rust-lang/rust-clippy/issues/7797

sister PR of: https://github.com/rust-lang/rust-clippy/pull/13136

changelog: none
2024-08-06 04:47:27 +00:00
y21
4c6a3f4b6e pass the right ParamEnv to might_permit_raw_init_strict 2024-08-06 01:53:50 +02:00
bors
5f6d07b64e Auto merge of #13222 - dtolnay-contrib:deterministic, r=flip1995
Use a deterministic number of digits in rustc_tools_util commit hashes

Using `git rev-parse --short` in rustc_tools_util causes nondeterministic compilation of projects that use `setup_version_info!` and `get_version_info!` when built from the exact same source code and git commit. The number of digits printed by `--short` is sensitive to how many other branches and tags in the repository have been fetched so far, what other commits have been worked on in other branches, how recently you had run `git gc`, platform-specific variation in git's default configuration, and platform differences in the sequence of steps performed by the release pipeline. Someone can compile a tool from a particular commit, switch branches to work on a different commit (or simply do a git fetch), go back to the first commit and be unable to reproduce the binary that was built from it previously.

Currently, variation in short commit hashes causes Clippy version strings to be out of sync between different targets. On x86_64-unknown-linux-gnu:

```console
$ clippy-driver +1.80.0 --version
clippy 0.1.80 (0514789 2024-07-21)
```

Whereas on aarch64-apple-darwin:

```console
$ clippy-driver +1.80.0 --version
clippy 0.1.80 (05147895 2024-07-21)
```

---

changelog: none
2024-08-05 19:36:16 +00:00
David Tolnay
9f6536ce6f
Use a deterministic number of digits in rustc_tools_util commit hashes 2024-08-05 08:17:18 -07:00
bors
c082bc2cb8 Auto merge of #13136 - xFrednet:07797-restriction-and-then, r=blyxyas
Make restriction lint's use `span_lint_and_then` (a -> e)

This migrates a few restriction lints to use `span_lint_and_then`. This change is motivated by https://github.com/rust-lang/rust-clippy/issues/7797.

I'm also interested if it will have an impact on performance. With some of these lints, like [`clippy::implicit_return`](https://rust-lang.github.io/rust-clippy/master/index.html#/implicit_return) I expect an impact, as it was previously creating a suggestion **for every implicit return** which is just wild.

I've also cleaned up some lint message. Mostly minor stuff. For example: suggestions with a longer message than `"try"` now use `SuggestionStyle::ShowAlways`

---

`@blyxyas` Could you benchmark this PR? I want to get all the numbers :3

---

This also crashed our new lintcheck CI with the following message:

> Error: $GITHUB_STEP_SUMMARY upload aborted, supports content up to a size of 1024k, got 46731k. For more information see: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-markdown-summary

Which is just wild. Like, I've [tested the first 20 lints](https://github.com/xFrednet/rust-clippy/actions/runs/10027528172) and got like four changes and then this. 50 MB of changed lint messages o.O. Looks like I'll create a separate PR to fix that step ^^

---

cc: https://github.com/rust-lang/rust-clippy/issues/7797

changelog: none

r? `@blyxyas`
2024-08-05 13:33:16 +00:00
bors
e17d254e2b Auto merge of #13180 - Jarcho:deprecated_shrink, r=flip1995
Simplify lint deprecation

A couple of small changes:
* A few deprecations were changed to renames. They all had a message similar to "this lint has been replaced by ..." which is just describing a rename.
* The website and warning message are now the same. The website description was usually just a wordier version that contained no extra information. This can be worked around if needed, but I don't think that will happen.
* The legacy deprecations have been removed. rustc should handle this since it already suggests adding the `clippy::` for all lints (deprecated or not) when they're used without it. It wouldn't be a problem to add them back in.
* The website no longer has a "view source" link for deprecated lints since they're no longer read from the HIR tree. I could store the line number, but the link seems totally useless for these lints.

This came up as part of separating the internal lints into their own crate. Both the metadata collector and the lint registration code needs access to the deprecated and renamed lists. This form lets all the deprecations be a separate crate.

r? `@flip1995`

changelog: none
2024-08-05 13:23:16 +00:00
Jason Newcomb
c2186e14de Make cargo dev deprecate require a reason 2024-08-05 09:17:46 -04:00
Jason Newcomb
2c34d58159 Store deprecated lints as an array of tuples.
Remove legacy deprecations.
Remove "View Source" link for deprecated lints.
2024-08-05 09:15:55 -04:00
Jason Newcomb
1672d5d4ed Mark some lint deprecations as renames 2024-08-05 09:10:49 -04:00
bors
e611c8e1c4 Auto merge of #13217 - dtolnay-contrib:toolsutil, r=flip1995
Check exit status of subcommands spawned by rustc_tools_util

The git commands `git rev-parse --short HEAD` and `git log -1 --date=short --pretty=format:%cd` that clippy runs from its build script might fail with **"fatal: not a git repository (or any of the parent directories): .git"** if clippy is being built from a source tarball rather than a git repository. That message is written by git to stderr, and nothing is written to stdout.

For `clippy-driver --version` this PR wouldn't make a difference because it treats empty stdout and failed spawns (`git` is not installed) identically:

7ac242c3d0/rustc_tools_util/src/lib.rs (L35-L42)

But other users of `rustc_tools_util` should be able to expect that the distinction between Some and None is meaningful. They shouldn't need extra code to handle None vs Some-and-empty vs Some-and-nonempty.

---

changelog: none
2024-08-05 13:00:02 +00:00
David Tolnay
234ea1fcd9
Check exit status of subcommands spawned by rustc_tools_util 2024-08-04 11:13:06 -07:00
bors
7ac242c3d0 Auto merge of #13213 - Alexendoo:multispan-sugg, r=y21
Remove `multispan_sugg[_with_applicability]`

They're thin wrappers over the corresponding diag method so we should just use that instead

changelog: none
2024-08-04 15:05:27 +00:00
Alex Macleod
1ea7bddbdf Remove multispan_sugg[_with_applicability] 2024-08-04 13:14:23 +00:00
bors
377d72ae8b Auto merge of #13194 - sheshnath-at-knoldus:fix-typos, r=Jarcho
fix-typos

fixes some typos in lintcheck

changelog: None
2024-08-03 18:51:51 +00:00
sheshnath-at-knoldus
b9716dd32a fix-typos 2024-08-03 23:18:29 +05:30
bors
8dd459d4c7 Auto merge of #13209 - Alexendoo:nonminimal-bool-limit-ops, r=y21
Limit number of `nonminimal_bool` ops

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

changelog: none
2024-08-03 15:50:00 +00:00
bors
eb7b6769f1 Auto merge of #13208 - alex-semenyuk:fix_doc_from_iter_instead_of_collect, r=llogiq
Add clarification for from_iter_instead_of_collect

Close #13147

As mentioned at #13147 we should prefer to use collect depends on situation so clarify this at documentation and provide examples this cases.

changelog: none
2024-08-03 15:09:06 +00:00
alexey semenyuk
35dcc9bbfa Add clarification for from_iter_instead_of_collect 2024-08-03 19:28:21 +05:00
Alex Macleod
d18ce7cea0 lintcheck: force warn all lints 2024-08-03 12:28:52 +00:00
Alex Macleod
b2d0631300 Limit number of nonminimal_bool ops 2024-08-03 12:07:42 +00:00
bors
0347280d5f Auto merge of #13107 - yaxum62:i5757, r=xFrednet
Add test for `try_err` lint within try blocks.

Fixes #5757

Turns out the current `try_err` implementation already skips expressions inside of a try block.

When inside of a try block, `Err(_)?` is desugared to a `break` instead of normal `return` . This makes `find_return_type()` function at [this line](eb4d88e690/clippy_lints/src/matches/try_err.rs (L29)) always returns `None` and skips the check.

I just added a test case for try block.

changelog: none
2024-08-03 08:25:37 +00:00
xFrednet
0532104247
Migrating restriction lints to span_lint_and_then (e -> i) 2024-08-03 10:18:15 +02:00
xFrednet
a9d72c7107
Migrating restriction lints to span_lint_and_then (a -> d) 2024-08-03 10:18:05 +02: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
bors
1aa686b9c0 Auto merge of #13126 - apoisternex:issue12751, r=dswij
Fix [`redundant_slicing`] when the slice is behind a mutable reference

Fixes #12751

changelog: Fix [`redundant_slicing`] when the slice is behind a mutable reference and a immutable reference is expected.
2024-08-03 07:23:58 +00:00
Esteban Küber
5ef38a3bc7 Do not underline suggestions for code that is already there
When a suggestion part is for already present code, do not highlight it. If after that there are no highlights left, do not show the suggestion at all.

Fix clippy lint suggestion incorrectly treated as `span_help`.
2024-08-01 18:53:42 +00:00
bors
2fc74a3931 Auto merge of #13108 - tesuji:fix_redundant_closure, r=xFrednet
Fix `redundant_closure` false positive with closures has return type contains  `'static`

Fix #13073 .

Please enable "ignore white-space change" settings in github UI for easy reviewing.

HACK: The third commit contains a hack to check if a type `T: 'static` when `fn() -> U where U: 'static`.
I don't have a clean way to check for it.

changelog: [`redundant_closure`] Fix false positive with closures has return type contains  `'static`
2024-08-01 07:55:37 +00:00
bors
5542309895 Auto merge of #13195 - GuillaumeGomez:fix-false-positive-13183, r=Manishearth
Fix false positive for `missing_backticks` in footnote references

Fixes #13183.

changelog: Fix false positive for `missing_backticks` in footnote references
2024-07-31 16:06:27 +00:00
Guillaume Gomez
edca73003b Fix false positive for missing_backticks in footnote references 2024-07-31 17:27:53 +02:00