about summary refs log tree commit diff
path: root/compiler/rustc_lint
AgeCommit message (Collapse)AuthorLines
2023-08-04Querify clashing_extern_declarations lint.Camille GILLOT-410/+440
2023-08-04Auto merge of #114414 - cjgillot:early-unnameable-test, r=petrochenkovbors-85/+1
Make test harness lint about unnnameable tests. Implementation of https://github.com/rust-lang/rust/pull/113734#discussion_r1283073418 About the options suggested in https://github.com/rust-lang/rust/issues/36629#issuecomment-404753945: adding this case to unused_attribute was just more complicated. I'll try to understand a bit more what you had in mind in https://github.com/rust-lang/rfcs/pull/2471#issuecomment-397241123 This was just simpler to do in a standalone PR. I'll remove the corresponding changes from https://github.com/rust-lang/rust/pull/113734 later. r? `@petrochenkov`
2023-08-04Improve spans for indexing expressionsNilstrieb-2/+2
Indexing is similar to method calls in having an arbitrary left-hand-side and then something on the right, which is the main part of the expression. Method calls already have a span for that right part, but indexing does not. This means that long method chains that use indexing have really bad spans, especially when the indexing panics and that span in coverted into a panic location. This does the same thing as method calls for the AST and HIR, storing an extra span which is then put into the `fn_span` field in THIR.
2023-08-03Auto merge of #108955 - Nilstrieb:dont-use-me-pls, r=oli-obkbors-16/+62
Add `internal_features` lint Implements https://github.com/rust-lang/compiler-team/issues/596 Also requires some more test blessing for codegen tests etc `@jyn514` had the idea of just `allow`ing the lint by default in the test suite. I'm not sure whether this is a good idea, but it's definitely one worth considering. Additional input encouraged.
2023-08-03Rollup merge of #113657 - Urgau:expand-incorrect_fn_null_check-lint, r=cjgillotMatthias Krüger-122/+172
Expand, rename and improve `incorrect_fn_null_checks` lint This PR, - firstly, expand the lint by now linting on references - secondly, it renames the lint `incorrect_fn_null_checks` -> `useless_ptr_null_checks` - and thirdly it improves the lint by catching `ptr::from_mut`, `ptr::from_ref`, as well as `<*mut _>::cast` and `<*const _>::cast_mut` Fixes https://github.com/rust-lang/rust/issues/113601 cc ```@est31```
2023-08-03Make test harness lint about unnnameable tests.Camille GILLOT-85/+1
2023-08-03Add `internal_features` lintNilstrieb-16/+62
It lints against features that are inteded to be internal to the compiler and standard library. Implements MCP #596. We allow `internal_features` in the standard library and compiler as those use many features and this _is_ the standard library from the "internal to the compiler and standard library" after all. Marking some features as internal wasn't exactly the most scientific approach, I just marked some mostly obvious features. While there is a categorization in the macro, it's not very well upheld (should probably be fixed in another PR). We always pass `-Ainternal_features` in the testsuite About 400 UI tests and several other tests use internal features. Instead of throwing the attribute on each one, just always allow them. There's nothing wrong with testing internal features^^
2023-08-03Also add label with original type for function pointersUrgau-2/+7
2023-08-03Also lint on cast/cast_mut and ptr::from_mut/ptr::from_refUrgau-16/+36
2023-08-03Make lint missing-copy-implementations honor negative Copy implsLeón Orell Valerian Liehr-0/+23
2023-08-02Add separate feature gate for async fn track callerBryan Garza-7/+7
This patch adds a feature gate `async_fn_track_caller` that is separate from `closure_track_caller`. This is to allow enabling `async_fn_track_caller` separately. Fixes #110009
2023-08-02Auto merge of #112431 - Urgau:cast_ref_to_mut_improvments, r=Nilstriebbors-32/+103
Improve `invalid_reference_casting` lint This PR is a follow-up to https://github.com/rust-lang/rust/pull/111567 and https://github.com/rust-lang/rust/pull/113422. This PR does multiple things: - First it adds support for deferred de-reference, the goal is to support code like this, where the casting and de-reference are not done on the same expression ```rust let myself = self as *const Self as *mut Self; *myself = Self::Ready(value); ``` - Second it does not lint anymore on SB/TB UB code by only checking assignments (`=`, `+=`, ...) and creation of mutable references `&mut *` - Thirdly it greatly improves the diagnostics in particular for cast from `&mut` to `&mut` or assignments - ~~And lastly it renames the lint from `cast_ref_to_mut` to `invalid_reference_casting` which is more consistent with the ["rules"](https://github.com/rust-lang/rust-clippy/issues/2845) and also more consistent with what the lint checks~~ *https://github.com/rust-lang/rust/pull/113422* This PR is best reviewed commit by commit. r? compiler
2023-08-02Replace old private-in-public diagnostic with type privacy lintsBryanskiy-0/+5
2023-08-01Rename incorrect_fn_null_checks to useless_ptr_null_checksUrgau-30/+30
2023-08-01Expand incorrect_fn_null_check lint with reference null checkingUrgau-14/+39
2023-07-31Rollup merge of #114286 - nbdd0121:upcast, r=compiler-errorsMatthias Krüger-0/+1
Add missing feature gate in multiple_supertrait_upcastable doc Fix #112424
2023-07-31Add missing feature gate in multiple_supertrait_upcastable docGary Guo-0/+1
2023-07-30Check lazy type aliases for well-formednessLeón Orell Valerian Liehr-7/+12
2023-07-29Improve diagnostics of the invalid_reference_casting lintUrgau-9/+31
2023-07-29Avoid linting on expression that are only UB with SB/TBUrgau-2/+15
2023-07-29Add support for deferred casting for the invalid_reference_casting lintUrgau-31/+68
2023-07-29Revert "Temporarily switch invalid_reference_casting lint to allow-by-default"Urgau-2/+1
This reverts commit f25ad54a4d0febbcb2b7e951835228b7b2320b49.
2023-07-29Auto merge of #113422 - Urgau:cast_ref_to_mut-pre-beta, r=Nilstriebbors-15/+16
Rename and allow `cast_ref_to_mut` lint This PR is a small subset of https://github.com/rust-lang/rust/pull/112431, that is the renaming of the lint (`cast_ref_to_mut` -> `invalid_reference_casting`). BUT also temporarily change the default level of the lint from deny-by-default to allow-by-default until https://github.com/rust-lang/rust/pull/112431 is merged. r? `@Nilstrieb`
2023-07-29Auto merge of #113099 - bvanjoi:fix-112713-2, r=petrochenkovbors-0/+3
fix(resolve): update the ambiguity glob binding as warning recursively Fixes #47525 Fixes #56593, but `issue-56593-2.rs` is not fixed to ensure backward compatibility. Fixes #98467 Fixes #105235 Fixes #112713 This PR had added a field called `warn_ambiguous` in `NameBinding` which is only for back compatibly reason and used for lint. More details: https://github.com/rust-lang/rust/pull/112743 r? `@petrochenkov`
2023-07-29Auto merge of #111916 - fee1-dead-contrib:noop-method-call-warn, ↵bors-11/+12
r=compiler-errors make `noop_method_call` warn by default r? `@compiler-errors`
2023-07-28Lower generic const items to HIRLeón Orell Valerian Liehr-1/+2
2023-07-29fix(resolve): update the ambiguity glob binding as warning recursivelybohan-0/+3
2023-07-27Rollup merge of #114075 - matthiaskrgr:fmt_args_rustc_3, r=wesleywiserMatthias Krüger-28/+26
inline format!() args from rustc_codegen_llvm to the end (4) r? `@WaffleLapkin`
2023-07-26Auto merge of #113457 - davidtwco:lint-ctypes-issue-113436, r=oli-obkbors-46/+39
lint/ctypes: fix `()` return type checks Fixes #113436. `()` is normally FFI-unsafe, but is FFI-safe when used as a return type. It is also desirable that a transparent newtype for `()` is FFI-safe when used as a return type. In order to support this, when a type was deemed FFI-unsafe, because of a `()` type, and was used in return type - then the type was considered FFI-safe. However, this was the wrong approach - it didn't check that the `()` was part of a transparent newtype! The consequence of this is that the presence of a `()` type in a more complex return type would make it the entire type be considered safe (as long as the `()` type was the first that the lint found) - which is obviously incorrect. Instead, this logic is removed, and after [consultation with t-lang](https://github.com/rust-lang/rust/issues/113436#issuecomment-1640756721), I've fixed the bugs and inconsistencies and made `()` FFI-safe within types. I also refactor a function, but that's not too exciting.
2023-07-25inline format!() args from rustc_codegen_llvm to the end (4)Matthias Krüger-28/+26
r? @WaffleLapkin
2023-07-23add suggestionDeadbeef-2/+2
2023-07-23fixDeadbeef-7/+9
2023-07-23make `noop_method_call` warn by defaultDeadbeef-2/+1
2023-07-21lint/ctypes: only try normalizeDavid Wood-12/+9
Now that this lint runs on any external-ABI fn-ptr, normalization won't always succeed, so use `try_normalize_erasing_regions` instead. Signed-off-by: David Wood <david@davidtw.co>
2023-07-19lint/ctypes: allow `()` within typesDavid Wood-32/+15
Consider `()` within types to be FFI-safe, and `()` to be FFI-safe as a return type (incl. when in a transparent newtype). Signed-off-by: David Wood <david@davidtw.co>
2023-07-19lint: refactor `check_variant_for_ffi`David Wood-27/+22
Simplify this function a bit, it was quite hard to reason about. Signed-off-by: David Wood <david@davidtw.co>
2023-07-19lint/ctypes: stricter `()` return type checksDavid Wood-20/+35
`()` is normally FFI-unsafe, but is FFI-safe when used as a return type. It is also desirable that a transparent newtype for `()` is FFI-safe when used as a return type. In order to support this, when an type was deemed FFI-unsafe, because of a `()` type, and was used in return type - then the type was considered FFI-safe. However, this was the wrong approach - it didn't check that the `()` was part of a transparent newtype! The consequence of this is that the presence of a `()` type in a more complex return type would make it the entire type be considered safe (as long as the `()` type was the first that the lint found) - which is obviously incorrect. Instead, this logic is removed, and a unit return type or a transparent wrapper around a unit is checked for directly for functions and fn-ptrs. Signed-off-by: David Wood <david@davidtw.co>
2023-07-18Rollup merge of #113832 - WaffleLapkin:track_lint_caller, r=compiler-errorsMatthias Krüger-0/+4
Add `#[track_caller]` to lint related diagnostic functions This fixes locations reported by `-Ztrack-diagnostics`.
2023-07-18Rollup merge of #113811 - jieyouxu:fix-unused-qualifications-suggestion, ↵Matthias Krüger-4/+4
r=oli-obk Fix removal span calculation of `unused_qualifications` suggestion Given a path such as `std::ops::Index<str>`, calculate the unnecessary qualification removal span by computing the beginning of the entire span until the ident span of the last path segment, which handles generic arguments and lifetime arguments in the last path segment. Previous logic only kept the ident span of the last path segment which is incorrect. Closes #113808.
2023-07-18Add `#[track_caller]` to lint related diagnostic functionsMaybe Waffle-0/+4
2023-07-18Fix removal span calculation of unused_qualifications suggestion许杰友 Jieyou Xu (Joe)-4/+4
2023-07-17Rename arg_iter to iter_instantiatedMichael Goulet-1/+1
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-93/+100
2023-07-14Rollup merge of #112729 - jieyouxu:unused-qualifications-suggestion, r=b-naberMatthias Krüger-0/+8
Add machine-applicable suggestion for `unused_qualifications` lint ``` error: unnecessary qualification --> $DIR/unused-qualifications-suggestion.rs:17:5 | LL | foo::bar(); | ^^^^^^^^ | note: the lint level is defined here --> $DIR/unused-qualifications-suggestion.rs:3:9 | LL | #![deny(unused_qualifications)] | ^^^^^^^^^^^^^^^^^^^^^ help: replace it with the unqualified path | LL | bar(); | ~~~ ``` Closes #92198.
2023-07-13Temporarily switch invalid_reference_casting lint to allow-by-defaultUrgau-1/+2
2023-07-13Rename cast_ref_to_mut lint to invalid_reference_castingUrgau-14/+14
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-45/+58
2023-07-13Add machine-applicable suggestion for `unused_qualifications` lint许杰友 Jieyou Xu (Joe)-0/+8
2023-07-11Auto merge of #111717 - Urgau:uplift_fn_null_check, r=oli-obkbors-0/+124
Uplift `clippy::fn_null_check` lint This PR aims at uplifting the `clippy::fn_null_check` lint into rustc. ## `incorrect_fn_null_checks` (warn-by-default) The `incorrect_fn_null_checks` lint checks for expression that checks if a function pointer is null. ### Example ```rust let fn_ptr: fn() = /* somehow obtained nullable function pointer */ if (fn_ptr as *const ()).is_null() { /* ... */ } ``` ### Explanation Function pointers are assumed to be non-null, checking for their nullity is incorrect. ----- Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 `@rustbot` label: +I-lang-nominated r? compiler
2023-07-10Uplift `clippy::fn_null_check` to rustcUrgau-0/+124