Skip to content

Clippy subtree update #122149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 107 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
4d93edf
Allow newly added non_local_definitions lint in clippy
Urgau Jan 26, 2024
b8fb890
Auto merge of #120393 - Urgau:rfc3373-non-local-defs, r=WaffleLapkin
bors Feb 25, 2024
66e4757
Add `ast::ExprKind::Dummy`
ShE3py Feb 25, 2024
ef2039e
Add `ErrorGuaranteed` to `ast::ExprKind::Err`
ShE3py Feb 25, 2024
5931794
Auto merge of #120586 - ShE3py:exprkind-err, r=fmease
bors Feb 26, 2024
d85642e
Alphabetize configuration options and lints in Clippy doc
CBSpeir Feb 25, 2024
03bb790
[`map_entry`]: Check insert expression for map use
Ethiraric Feb 27, 2024
9f4a58f
Add new `mixed_attributes_style` lint
GuillaumeGomez Feb 26, 2024
2873823
Add ui test for `mixed_attributes_style`
GuillaumeGomez Feb 26, 2024
f301386
Update ui tests
GuillaumeGomez Feb 27, 2024
7be6e21
Merge commit '10136170fe9ed01e46aeb4f4479175b79eb0e3c7' into clippy-s…
flip1995 Feb 27, 2024
c6cb0e9
[`unnecessary_cast`]: Avoid breaking precedence
Ethiraric Feb 27, 2024
4155bec
Auto merge of #12365 - Ethiraric:fix-11968, r=Alexendoo
bors Feb 27, 2024
dfedadc
fix: manual_memcpy wrong suggestion for multi dimensional arrays
granddaifuku Dec 25, 2023
4c1d05c
Auto merge of #12362 - Ethiraric:fix-11935, r=llogiq
bors Feb 27, 2024
2a2b0b7
Rename `DiagnosticBuilder` as `Diag`.
nnethercote Feb 22, 2024
0671d78
check for try blocks in `LintPass` methods
y21 Feb 23, 2024
7a7224e
Remove the `UntranslatableDiagnosticTrivial` lint.
nnethercote Feb 5, 2024
1430623
move methods out of impl and remove unused `&self` param
y21 Feb 23, 2024
1ba47ea
Use `LitKind::Err` for floats with empty exponents.
nnethercote Feb 28, 2024
ebf2095
Fix invalid condition in `nonminimal_bool` lint
GuillaumeGomez Feb 28, 2024
8473716
Add ui regression test for #12371
GuillaumeGomez Feb 28, 2024
733e1d4
Show duplicate diagnostics in UI tests by default
Alexendoo Feb 28, 2024
41a3516
Improve `is_lint_level` code
GuillaumeGomez Feb 28, 2024
b4021ee
Auto merge of #12375 - GuillaumeGomez:improve-code, r=flip1995
bors Feb 28, 2024
e450a27
Auto merge of #12372 - GuillaumeGomez:fix-nonminimal_bool-regression,…
bors Feb 28, 2024
af91e6e
Auto merge of #12374 - Alexendoo:duplicate-diagnostics, r=Manishearth
bors Feb 28, 2024
17930c9
Add stubs for `f16` and `f128` to clippy
tgross35 Feb 28, 2024
0d59345
[`redundant_closure_call`]: Don't lint if closure origins from a macro
Ethiraric Feb 28, 2024
139191b
Auto merge of #12380 - Ethiraric:fix-12358, r=llogiq
bors Feb 28, 2024
e3b8b52
Auto merge of #121489 - nnethercote:diag-renaming, r=davidtwco
bors Feb 28, 2024
f055f2a
Rollup merge of #121724 - nnethercote:LitKind-Err-for-floats, r=fmease
matthiaskrgr Feb 28, 2024
81783fb
Overhaul how stashed diagnostics work, again.
nnethercote Feb 26, 2024
81100bd
Rename `DiagCtxt::with_emitter` as `DiagCtxt::new`.
nnethercote Feb 29, 2024
04b74ee
Auto merge of #12344 - CBSpeir:alphabetize-affected-lints, r=flip1995
bors Feb 29, 2024
00ff8c9
Auto merge of #12354 - GuillaumeGomez:mixed_attributes_style, r=llogiq
bors Feb 29, 2024
ce4b81d
Bump macOS CI version to 13
Alexendoo Feb 28, 2024
7cfe7d6
Rollup merge of #121669 - nnethercote:count-stashed-errs-again, r=est…
GuillaumeGomez Feb 29, 2024
14b7251
Rollup merge of #121783 - nnethercote:emitter-cleanups, r=oli-obk
GuillaumeGomez Feb 29, 2024
3b8da4a
Auto merge of #12382 - Alexendoo:macos-ci, r=flip1995
bors Feb 29, 2024
bb1ee87
Fixed FP for `thread_local_initializer_can_be_made_const` for `os_local`
PartiallyUntyped Jan 21, 2024
225d377
Auto merge of #12276 - PartiallyTyped:hide-thread-local, r=blyxyas
bors Mar 1, 2024
fb18033
Auto merge of #121728 - tgross35:f16-f128-step1-ty-updates, r=compile…
bors Mar 1, 2024
c5f8198
Document manifest options
Jan 30, 2024
e865dca
Auto merge of #12010 - granddaifuku:fix/manual-memcpy-indexing-for-mu…
bors Mar 1, 2024
346b094
Auto merge of #12218 - jhpratt:manifest-options-doc, r=blyxyas
bors Mar 1, 2024
aa1c9a5
If suggestion would leave an empty line, delete it
clubby789 Jan 26, 2024
0656d28
Add `assigning_clones` lint
Kobzol Jan 1, 2024
e3cda2a
Update lints
Kobzol Jan 2, 2024
0fcc33e
Fix tests
Kobzol Jan 3, 2024
41f5ee1
React to review
Kobzol Jan 22, 2024
f7356f2
Fix lint errors
Kobzol Jan 23, 2024
bc551b9
Do not run the lint on macro-generated code
Kobzol Jan 23, 2024
24de0be
Fix tests
Kobzol Jan 23, 2024
1a97d14
fix [`derive_partial_eq_without_eq`] FP on trait projection
J-ZhengLi Mar 1, 2024
dde2552
add test cases for #9319
J-ZhengLi Mar 1, 2024
2c8f471
Propegate HIR and AST `f16` and `f128` types to clippy
tgross35 Mar 1, 2024
1580af6
Refactor lints in clippy_lints::attrs into separate submodules/files
CBSpeir Mar 1, 2024
5e0afee
Auto merge of #12394 - CBSpeir:issue-12390-refactor, r=Alexendoo
bors Mar 2, 2024
550b276
Rollup merge of #121841 - tgross35:f16-f128-step2-intrinsics, r=compi…
Nadrieril Mar 2, 2024
8e3ad2e
Remove double expr lint
MarcusGrass Mar 3, 2024
1df2854
[`let_underscore_untyped`]: fix false positive on async function
samueltardieu Mar 3, 2024
28e11b3
Auto merge of #12400 - samueltardieu:issue-12395, r=Alexendoo
bors Mar 3, 2024
74cba63
Dedup std_instead_of_core by using first segment span for uniqueness
MarcusGrass Mar 3, 2024
08459b4
Added msrv to threadlocal initializer
PartiallyUntyped Mar 3, 2024
a2e4ef2
dump bugged fix
MarcusGrass Mar 3, 2024
3735bf9
Working but not with mixed imports
MarcusGrass Mar 3, 2024
a6fc64b
Trait checking and type construction
PartiallyUntyped Feb 13, 2024
58d9c47
formatting
PartiallyUntyped Feb 13, 2024
ca8f03f
Update trait_checking.md
PartiallyUntyped Feb 13, 2024
8c5afd4
address review comments
PartiallyUntyped Feb 13, 2024
19c2aba
address review comments
PartiallyUntyped Mar 3, 2024
3064211
Auto merge of #12406 - MarcusGrass:fix-duplicate-std-instead-of-core,…
bors Mar 3, 2024
6e5332c
Pointers cannot be converted to integers at compile time
samueltardieu Mar 3, 2024
aceeb54
Auto merge of #12405 - PartiallyTyped:12404, r=blyxyas
bors Mar 3, 2024
c2dd413
Auto merge of #12403 - samueltardieu:issue-12402, r=blyxyas
bors Mar 3, 2024
3b9939e
[`identity_op`]: Fix duplicate errors
cookie-s Mar 4, 2024
f75d8c7
Auto merge of #12393 - J-ZhengLi:issue9413, r=dswij
bors Mar 4, 2024
e970fa5
Auto merge of #12341 - y21:issue12337, r=dswij
bors Mar 4, 2024
c0939b1
Auto merge of #12409 - cookie-s:fix-identityop-duplicate-errors, r=Al…
bors Mar 4, 2024
c5c1477
Add missing header for `manual_c_str_literals`
Veykril Mar 4, 2024
7322fa0
Add missing header for `manual_is_variant_and`
Veykril Mar 4, 2024
ea92548
Add `is_intrinsic` helper
oli-obk Feb 19, 2024
1cb3905
Auto merge of #12415 - Veykril:patch-1, r=blyxyas
bors Mar 4, 2024
5214ab5
Auto merge of #12416 - Veykril:patch-2, r=blyxyas
bors Mar 4, 2024
b74b4b0
Rename all `ParseSess` variables/fields/lifetimes as `psess`.
nnethercote Mar 4, 2024
cc4c8db
Handle plural acronyms in `doc_markdown`
smoelius Mar 4, 2024
415b1f1
Auto merge of #120675 - oli-obk:intrinsics3.0, r=pnkfelix
bors Mar 5, 2024
dc37ddd
Rename `DiagnosticMessage` as `DiagMessage`.
nnethercote Feb 29, 2024
ec920ce
Rename `DiagnosticExt` as `DiagExt`.
nnethercote Feb 29, 2024
ae710de
Auto merge of #121780 - nnethercote:diag-renaming2, r=davidtwco
bors Mar 5, 2024
193456e
Auto merge of #12288 - PartiallyTyped:trait-type-checking-documentati…
bors Mar 5, 2024
eb4a441
Auto merge of #12419 - smoelius:plural-acronyms, r=dswij
bors Mar 5, 2024
ee375e4
Don't emit "missing backticks" lint if the element is wrapped in `<co…
GuillaumeGomez Mar 5, 2024
bd9b9ff
Add regression test for #9473
GuillaumeGomez Mar 5, 2024
3c5008e
[misrefactored_assign_op]: Fix duplicate diagnostics
high-cloud Mar 4, 2024
21efd39
Auto merge of #12423 - GuillaumeGomez:code-wrapped-element, r=Alexendoo
bors Mar 5, 2024
2d9d404
Auto merge of #12413 - high-cloud:fix_assign_ops2, r=flip1995
bors Mar 5, 2024
e485a02
Auto merge of #12077 - Kobzol:assigning-clones, r=blyxyas
bors Mar 5, 2024
0901b9f
Convert `TypeVisitor` and `DefIdVisitor` to use `VisitorResult`
Jarcho Feb 24, 2024
a79db2a
Auto merge of #12401 - MarcusGrass:dedup-nonminimal-bool, r=blyxyas
bors Mar 6, 2024
ac643a2
Don't lint `redundant_field_names` across macro boundaries
Alexendoo Mar 7, 2024
ba80e06
Auto merge of #12429 - Alexendoo:redundant-field-names-macro-ctxt, r=…
bors Mar 7, 2024
a6df027
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Mar 7, 2024
1d65642
Bump nightly version -> 2024-03-07
flip1995 Mar 7, 2024
93f0a9a
Auto merge of #12431 - flip1995:rustup, r=flip1995
bors Mar 7, 2024
73f7e79
Merge commit '93f0a9a91f58c9b2153868f458402155fb6265bb' into clippy-s…
flip1995 Mar 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/tools/clippy/.github/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ diff -u normalized.stderr tests/ui/double_neg.stderr

# make sure "clippy-driver --rustc --arg" and "rustc --arg" behave the same
SYSROOT=$(rustc --print sysroot)
diff -u <(LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver --rustc --version --verbose) <(rustc --version --verbose)
diff -u <(./target/debug/clippy-driver --rustc --version --verbose) <(rustc --version --verbose)

echo "fn main() {}" >target/driver_test.rs
# we can't run 2 rustcs on the same file at the same time
CLIPPY=$(LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver ./target/driver_test.rs --rustc)
CLIPPY=$(./target/debug/clippy-driver ./target/driver_test.rs --rustc)
RUSTC=$(rustc ./target/driver_test.rs)
diff -u <($CLIPPY) <($RUSTC)

Expand Down
11 changes: 3 additions & 8 deletions src/tools/clippy/.github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ jobs:
run: rustup show active-toolchain

# Run
- name: Set LD_LIBRARY_PATH (Linux)
run: |
SYSROOT=$(rustc --print sysroot)
echo "LD_LIBRARY_PATH=${SYSROOT}/lib${LD_LIBRARY_PATH+:${LD_LIBRARY_PATH}}" >> $GITHUB_ENV

- name: Build
run: cargo build --tests --features deny-warnings,internal

Expand All @@ -72,6 +67,6 @@ jobs:
working-directory: clippy_dev

- name: Test clippy-driver
run: bash .github/driver.sh
env:
OS: ${{ runner.os }}
run: |
TOOLCHAIN=$(rustup show active-toolchain | cut -f1 -d' ')
rustup run $TOOLCHAIN bash .github/driver.sh
32 changes: 6 additions & 26 deletions src/tools/clippy/.github/workflows/clippy_bors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
host: i686-unknown-linux-gnu
- os: windows-latest
host: x86_64-pc-windows-msvc
- os: macos-latest
- os: macos-13
host: x86_64-apple-darwin

runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -87,23 +87,6 @@ jobs:
rustup show active-toolchain

# Run
- name: Set LD_LIBRARY_PATH (Linux)
if: runner.os == 'Linux'
run: |
SYSROOT=$(rustc --print sysroot)
echo "LD_LIBRARY_PATH=${SYSROOT}/lib${LD_LIBRARY_PATH+:${LD_LIBRARY_PATH}}" >> $GITHUB_ENV
- name: Link rustc dylib (MacOS)
if: runner.os == 'macOS'
run: |
SYSROOT=$(rustc --print sysroot)
sudo mkdir -p /usr/local/lib
sudo find "${SYSROOT}/lib" -maxdepth 1 -name '*dylib' -exec ln -s {} /usr/local/lib \;
- name: Set PATH (Windows)
if: runner.os == 'Windows'
run: |
SYSROOT=$(rustc --print sysroot)
echo "$SYSROOT/bin" >> $GITHUB_PATH

- name: Build
run: cargo build --tests --features deny-warnings,internal

Expand Down Expand Up @@ -136,7 +119,9 @@ jobs:
working-directory: clippy_dev

- name: Test clippy-driver
run: bash .github/driver.sh
run: |
TOOLCHAIN=$(rustup show active-toolchain | cut -f1 -d' ')
rustup run $TOOLCHAIN bash .github/driver.sh
env:
OS: ${{ runner.os }}

Expand Down Expand Up @@ -236,11 +221,6 @@ jobs:
- name: Install toolchain
run: rustup show active-toolchain

- name: Set LD_LIBRARY_PATH
run: |
SYSROOT=$(rustc --print sysroot)
echo "LD_LIBRARY_PATH=${SYSROOT}/lib${LD_LIBRARY_PATH+:${LD_LIBRARY_PATH}}" >> $GITHUB_ENV

# Download
- name: Download target dir
uses: actions/download-artifact@v3
Expand All @@ -254,8 +234,8 @@ jobs:
# Run
- name: Test ${{ matrix.integration }}
run: |
RUSTUP_TOOLCHAIN="$(rustup show active-toolchain | grep -o -E "nightly-[0-9]{4}-[0-9]{2}-[0-9]{2}")" \
$CARGO_TARGET_DIR/debug/integration --show-output
TOOLCHAIN=$(rustup show active-toolchain | cut -f1 -d' ')
rustup run $TOOLCHAIN $CARGO_TARGET_DIR/debug/integration --show-output
env:
INTEGRATION: ${{ matrix.integration }}

Expand Down
112 changes: 57 additions & 55 deletions src/tools/clippy/CHANGELOG.md

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions src/tools/clippy/book/src/development/trait_checking.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,53 @@ impl LateLintPass<'_> for CheckTokioAsyncReadExtTrait {
}
```

## Creating Types Programmatically

Traits are often generic over a type parameter, e.g. `Borrow<T>` is generic
over `T`. Rust allows us to implement a trait for a specific type. For example,
we can implement `Borrow<[u8]>` for a hypothetical type `Foo`. Let's suppose
that we would like to find whether our type actually implements `Borrow<[u8]>`.

To do so, we can use the same `implements_trait` function as above, and supply
a type parameter that represents `[u8]`. Since `[u8]` is a specialization of
`[T]`, we can use the [`Ty::new_slice`][new_slice] method to create a type
that represents `[T]` and supply `u8` as a type parameter.
To create a `ty::Ty` programmatically, we rely on `Ty::new_*` methods. These
methods create a `TyKind` and then wrap it in a `Ty` struct. This means we
have access to all the primitive types, such as `Ty::new_char`,
`Ty::new_bool`, `Ty::new_int`, etc. We can also create more complex types,
such as slices, tuples, and references out of these basic building blocks.

For trait checking, it is not enough to create the types, we need to convert
them into [GenericArg]. In rustc, a generic is an entity that the compiler
understands and has three kinds, type, const and lifetime. By calling
`.into()` on a constructed [Ty], we wrap the type into a generic which can
then be used by the query system to decide whether the specialized trait
is implemented.

The following code demonstrates how to do this:

```rust

use rustc_middle::ty::Ty;
use clippy_utils::ty::implements_trait;
use rustc_span::symbol::sym;

let ty = todo!("Get the `Foo` type to check for a trait implementation");
let borrow_id = cx.tcx.get_diagnostic_item(sym::Borrow).unwrap(); // avoid unwrap in real code
let slice_of_bytes_t = Ty::new_slice(cx.tcx, cx.tcx.types.u8);
let generic_param = slice_of_bytes_t.into();
if implements_trait(cx, ty, borrow_id, &[generic_param]) {
todo!("Rest of lint implementation")
}
```

In essence, the [Ty] struct allows us to create types programmatically in a
representation that can be used by the compiler and the query engine. We then
use the `rustc_middle::Ty` of the type we are interested in, and query the
compiler to see if it indeed implements the trait we are interested in.


[DefId]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.DefId.html
[diagnostic_items]: https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-items.html
[lang_items]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/lang_items/struct.LanguageItems.html
Expand All @@ -102,4 +149,7 @@ impl LateLintPass<'_> for CheckTokioAsyncReadExtTrait {
[symbol]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/symbol/struct.Symbol.html
[symbol_index]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_span/symbol/sym/index.html
[TyCtxt]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html
[Ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html
[rust]: https://github.com/rust-lang/rust
[new_slice]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html#method.new_slice
[GenericArg]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.GenericArg.html
16 changes: 16 additions & 0 deletions src/tools/clippy/book/src/development/type_checking.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ the [`TypeckResults::node_type()`][node_type] method inside of bodies.

> **Warning**: Don't use `hir_ty_to_ty` inside of bodies, because this can cause ICEs.

## Creating Types programmatically

A common usecase for creating types programmatically is when we want to check if a type implements a trait (see
[Trait Checking](trait_checking.md)).

Here's an example of how to create a `Ty` for a slice of `u8`, i.e. `[u8]`

```rust
use rustc_middle::ty::Ty;
// assume we have access to a LateContext
let ty = Ty::new_slice(cx.tcx, Ty::new_u8());
```

In general, we rely on `Ty::new_*` methods. These methods define the basic building-blocks that the
type-system and trait-system use to define and understand the written code.

## Useful Links

Below are some useful links to further explore the concepts covered
Expand Down
Loading