Commit Graph

20535 Commits

Author SHA1 Message Date
Guillaume Gomez
e845366c82 Add MSRV check for saturating_sub lints in const contexts 2024-08-31 16:24:17 +02:00
Guillaume Gomez
d20fc38f0a Create new inverted_saturating_sub lint 2024-08-29 20:20:13 +02:00
Guillaume Gomez
27c6343365 Add ui test to ensure that if 0 is returned from both if and else, it will not break clippy 2024-08-29 20:20:13 +02:00
Guillaume Gomez
2622a87587 Add ui regression tests for implicit_saturation_sub lint extension 2024-08-29 20:20:13 +02:00
Guillaume Gomez
74a2344dc1 Extend implicit_saturation_sub lint 2024-08-29 20:20:13 +02:00
bors
73819440ea Auto merge of #13193 - alex-semenyuk:fix_doc_unused_io_amount, r=xFrednet
Fix doc example for UNUSED_IO_AMOUNT

Cosmetic changes. Unify example for UNUSED_IO_AMOUNT

changelog: none
2024-08-14 08:17:18 +00:00
bors
70457f637d Auto merge of #13253 - alex-semenyuk:fix_message_unnecessary_unwrap, r=llogiq
Clarify suggestion message for unwrap lint

Close #10217
As mentioned at #10217 message for `unwrap` uses `..` like `Some(..)` which can confuse with slice and other places mostly use `<item>` like `for (i, <item>) in target_groups_json.iter().enumerate().skip(1) {` So replace  `..` to `<item>`

changelog: [`unnecessary_unwrap`] clarify suggestion message
2024-08-13 23:50:05 +00:00
bors
84e98eb9da Auto merge of #13265 - antonilol:lint-source-location, r=Alexendoo
Fix lint source location github link (missing a letter 'L')

Links to github ('View Source') were broken by [pull request 13221](https://github.com/rust-lang/rust-clippy/pull/13221/files#diff-dcd0f8da3873f35e9777182474a9d0f287f478c0c02650a1d3fefffe1c8c1d30R159).

also fixed some indentation in docs

changelog: none
2024-08-13 12:01:12 +00:00
Antoni Spaanderman
819fa6f180
fix source location github link 2024-08-13 13:13:31 +02:00
Antoni Spaanderman
5fee840875
fix indentation in docs 2024-08-13 13:13:02 +02:00
bors
61a252f182 Auto merge of #13221 - Alexendoo:farewell-metadata-collector, r=xFrednet
Replace the metadata collector with tests

The metadata collector handles 3 files: [`CHANGELOG.md`](c082bc2cb8/CHANGELOG.md (L6050)), [`lint_configuration.md`](c082bc2cb8/book/src/lint_configuration.md) and `util/gh-pages/lints.json`

- `CHANGELOG.md` and `lint_configuration.md` are now checked by `tests/config-metadata.rs`, when they are outdated `cargo test` will fail with a message to run `cargo bless --test config-metadata` in order to update them

   A plain `cargo bless` will run all the tests, blessing both this and the UI tests

- `util/gh-pages/lints.json` is now generated when running `cargo uitest` with `COLLECT_METADATA=1` (still aliased to `cargo collect-metadata`)

   It uses a `ui_test` [post test action](https://docs.rs/ui_test/latest/ui_test/custom_flags/trait.Flag.html#method.post_test_action) to retrieve the applicability from the actual diagnostics emitted during UI tests

   Example change from the current to new JSON:

   ```diff
      {
        "id": "chars_next_cmp",
   -    "id_span": {
   -      "path": "src/methods/mod.rs",
   -      "line": 891
   -    },
   +    "id_location": "clippy_lints/src/methods/mod.rs#891",
        "group": "style",
        "level": "warn",
   -    "docs": "\n### What it does ... ```",
   +    "docs": "### What it does ... ```\n",
        "version": "pre 1.29.0",
   -    "applicability": {
   -      "is_multi_part_suggestion": false,
   -      "applicability": "Unresolved"
   -    }
   +    "applicability": "MachineApplicable"
      },
   ```

   `Hide whitespace` makes the `compile-test.rs` changes much easier to see

r? `@flip1995`

changelog: none
2024-08-13 09:36:58 +00:00
Alex Macleod
a22ce2d005 Remove HashSets from Conf 2024-08-12 20:24:47 +00:00
Alex Macleod
182cd5f278 Replace the metadata collector with tests 2024-08-12 20:24:46 +00:00
bors
8827107526 Auto merge of #13230 - kyoto7250:fix_issue_13099, r=flip1995
Add a test for ice-3717.rs

this PR is a part of https://github.com/rust-lang/rust-clippy/issues/13099.

Based on the changes introduced in #13098 for introduce ui_test, we will update the uitest output.
This is a fix for `ice-3717.rs`.

Although fixes have already been made in #13216, it seems that he is a first-time contributor.
I thought it might be better for him to refer to my PR, so I created it accordingly.

Since this is my first contribution in a while, please let me know if there are any issues or required changes.

changelog: none

r! `@flip1995`
2024-08-12 19:49:45 +00:00
bors
e07078482b Auto merge of #13261 - antonilol:fix-doc-code-blocks, r=xFrednet
fix code blocks in doc comments inconsistently using 3 or 4 spaces of indentation

The metadata collector script was treating the space lines all start with as indentation. This caused code block's triple backticks to get a space in front of it, like this:
```
 ```rust
^ this space
```
Code after that that is indented with 4 spaces will only have 3 of those rendered.
Example (taken from [here](https://rust-lang.github.io/rust-clippy/master/index.html#/missing_panics_doc)):
```rust
...
pub fn divide_by(x: i32, y: i32) -> i32 {
   if y == 0 {                      // 3 spaces
       panic!("Cannot divide by 0") // 7 spaces
...
```

Also added 'compile_fail' alongside the other rustdoc directives (second code block [here](https://rust-lang.github.io/rust-clippy/master/index.html#/macro_metavars_in_unsafe) had no highlighting), fixed a doc comment using 'rs' instead of 'rust' and removed some spaces causing an extra missing space of indentation (see second code block [here](https://rust-lang.github.io/rust-clippy/master/index.html#/map_err_ignore)).

changelog: none
2024-08-12 19:14:50 +00:00
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
Antoni Spaanderman
d7f1252ddf
fix code blocks in doc comments inconsistently using 3 or 4 spaces of indentation 2024-08-12 18:42:13 +02: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
bors
c7c8724897 Auto merge of #13187 - GuillaumeGomez:settings-menu, r=Alexendoo
Add settings menu on clippy lints page

It looks like this (when the menu is expanded):

![Screenshot from 2024-08-06 21-36-41](https://github.com/user-attachments/assets/c464aef3-b21e-48cc-8e3a-c32a134f995e)

Follow-up of https://github.com/rust-lang/rust-clippy/pull/13178.

Someone pointed out that they should be able to disable the shortcuts on this page like it's the case for rustdoc and docs.rs. So here we go.

The first commit moves the style into its own file: it's much better for a web browser because it can then cache it.

The second one actually adds the new settings menu you can see above.

r? `@Alexendoo`

changelog: Add settings menu on clippy lints page
2024-08-11 18:42:37 +00:00
Guillaume Gomez
2ae6a4954b Move themes directly into HTML 2024-08-11 19:44:18 +02:00
Guillaume Gomez
934e98d591 Unify theme and settings menus 2024-08-11 19:39:19 +02:00
Alexey Semenyuk
f93fb9a417 Clarify message for unwrap lint 2024-08-11 20:33:28 +05:00
bors
94099f48c9 Auto merge of #13250 - Alexendoo:lintcheck-diff-key, r=xFrednet
lintcheck: key lints on line start rather than byte start/end

Before: https://github.com/rust-lang/rust-clippy/actions/runs/10305798317
After: https://github.com/Alexendoo/rust-clippy/actions/runs/10333749860

If a single lint emits e.g. twice on the same line and the messages change for both there would still be two changed entries

Also slightly changes the output, the URL is no longer visible

r? `@xFrednet`

changelog: none
2024-08-11 09:00:46 +00:00
Alex Macleod
6de27a0272 lintcheck: key lints on line start rather than byte start/end 2024-08-10 19:08:30 +00:00
bors
c8b0923a73 Auto merge of #13163 - GuillaumeGomez:fix-13097, r=Alexendoo
Fix case where doc_markdown is triggered on words ending with "ified"

Fixes #13097.

r? `@Alexendoo`

changelog: Fix case where doc_markdown is triggered on words ending with "ified"
2024-08-10 17:51:56 +00:00
bors
37f98fffe7 Auto merge of #13220 - y21:issue13219, r=dswij
[`macro_metavars_in_unsafe`]: recognize metavariables in tail expressions

Fixes #13219

`macro_metavars_in_unsafe` keeps track of the current "expansion depth" (incremented/decremented when entering/leaving a macro span) to tell if an expression from the root context is contained within a macro (see the doc comment I added for a hopefully better explanation)

Before this PR, we didn't increment said `expn_depth` for `unsafe` blocks within macros, because we already do that in `visit_stmt` anyway, so it would work fine for statements, but that's not enough for tail expressions of an unsafe block.

So we now also increment it for macro unsafe blocks.
Also updated the comment for `expn_depth` while I'm at it because "This is not necessary for correctness" isn't correct now that I think about it

------

changelog: none
2024-08-10 12:43:43 +00:00
bors
780c61f1ee Auto merge of #13041 - Jarcho:path, r=y21
Refactor `absolute_paths`

Checks are rearranged to do the more expensive checks later. Since the most likely path length will be one (locals and imported/local items) this will exclude such paths on the first check.

Tests were rewritten as they were hard to follow (annotations would have helped), spammy (lots of tests for the same thing) and insufficient.

One thing thing that came up and should be decided on now is what to do about the difference between `path::to::Trait::item` (4 segments) and `path::to::Type::item` (3 segments). The current behaviour treats these as different lengths which is terrible. I personally think these should both be three segments since the item can't actually be imported. Only the type or the trait could be. This makes `crate_name::Trait::item` the shortest absolute path which is shorter than the lint allows by default.

changelog: None
2024-08-10 02:10:12 +00: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
bors
1c81105b43 Auto merge of #13211 - rzvxa:respect_allow_inconsistent_struct_constructor_on_adt, r=Alexendoo
Respect allow `inconsistent_struct_constructor` on the struct definition

Closes #13203

Now we check if the target type is marked with `#[allow(clippy:inconsistent_struct_constructor)]` before lining.
As a side-effect of this change, The rule in the subject no longer runs on non-local `AdtDef`s. However, as suggested by `@Jarcho` it shouldn't be a big deal since most of the time we didn't have access to this information anyway.

> You can't get lint attributes from other crates. I would probably just restrict the lint to only work with types from the current crate while you're at it. Upstream crates don't have a definition order from the point of view of the current crate (with the exception of #[repr(C)] structs).

changelog: Respect allow `inconsistent_struct_constructor` on the struct definition.
2024-08-09 12:23:53 +00:00
rzvxa
d85cf0bacd use fulfill_or_allowed over is_lint_allowed. 2024-08-09 12:18:56 +03:30
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
kyoto7250
5e25e7c370 add a test for ice-3717.rs
https://github.com/rust-lang/rust-clippy/issues/13099
2024-08-07 21:48:47 +09:00