about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2023-08-13Auto merge of #114757 - Urgau:transmute-with-invalid_reference_casting, r=est31bors-24/+48
Also consider `mem::transmute` with the `invalid_reference_casting` lint This PR extend the `invalid_reference_casting` lint with regard to the `std::mem::transmute` function. ``` error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell` --> $DIR/reference_casting.rs:27:16 | LL | let _num = &mut *std::mem::transmute::<_, *mut i32>(&num); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` *I encourage anyone reviewing this PR to do so [without whitespaces](https://github.blog/2011-10-21-github-secrets/#whitespace).*
2023-08-13Auto merge of #114723 - petrochenkov:noplugin2, r=davidtwcobors-3/+19
rustc: Move `features` from `Session` to `GlobalCtxt` Removes one more piece of mutable state. Follow up to #114622. The rule I used for passing feature in function signatures: - if a crate already depends on `rustc_middle`, then `Session` is replaced with `TyCtxt` - otherwise session and features are passed as a pair `sess: &Session, features: &Features` The code in `rustc_lint` is ultimately used for implementing a trait from `rustc_expand`, so it also doesn't use tcx despite the dependency on `rustc_middle`.
2023-08-12Also consider `transmute` with the `invalid_reference_casting` lintUrgau-24/+48
2023-08-11rustc: Move `features` from `Session` to `GlobalCtxt`Vadim Petrochenkov-3/+19
Removes two pieces of mutable state. Follow up to #114622.
2023-08-10downgrade internal_features to warnlcnr-2/+2
2023-08-06Improve diagnostics and add tests for function callsest31-23/+31
2023-08-06Rollup merge of #114486 - Urgau:const-context-nan-suggestion-114471, ↵Matthias Krüger-6/+10
r=compiler-errors Avoid invalid NaN lint machine-applicable suggestion in const context This PR removes the machine-applicable suggestion in const context for the `invalid_nan_comparision` lint ~~and replace it with a simple help~~. Fixes https://github.com/rust-lang/rust/issues/114471
2023-08-05Add FIXME as reminder to restore suggestion laterMichael Goulet-0/+1
2023-08-05Avoid invalid NaN lint machine-applicable suggestion in const contextUrgau-6/+9
2023-08-05Rollup merge of #114248 - fmease:neg-copy-rules-out-missing-copy-impl, r=b-naberMatthias Krüger-0/+23
Make lint missing-copy-implementations honor negative `Copy` impls Fixes #101980. ``@rustbot`` label A-lint F-negative_impls
2023-08-05Auto merge of #113734 - cjgillot:no-crate-lint, r=petrochenkovbors-512/+494
Convert builtin "global" late lints to run per module The compiler currently has 4 non-incremental lints: 1. `clashing_extern_declarations`; 2. `missing_debug_implementations`; 3. ~`unnameable_test_items`;~ changed by https://github.com/rust-lang/rust/pull/114414 4. `missing_docs`. Non-incremental lints get reexecuted for each compilation, which is slow. Moreover, those lints are allow-by-default, so run for nothing most of the time. This PR attempts to make them more incremental-friendly. `clashing_extern_declarations` is moved to a standalone query. `missing_debug_implementation` can use `non_blanket_impls_for_ty` instead of recomputing it. `missing_docs` is harder as it needs to track if there is a `doc(hidden)` module surrounding. I hack around this using the lint level engine. That's easy to implement and allows to re-enable the lint for a re-exported module, while a more proper solution would reuse the same device as `unnameable_test_items`.
2023-08-05Add #[rustc_never_returns_null_ptr]est31-1/+1
And look for it in the useless_ptr_null_checks lint
2023-08-04Auto merge of #112117 - bryangarza:track-caller-feature-gate, r=compiler-errorsbors-7/+7
Add separate feature gate for async fn track caller 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-04Rollup merge of #114472 - estebank:issue-76140, r=compiler-errorsMatthias Krüger-1/+4
Reword `confusable_idents` lint Fix #76140.
2023-08-04Rollup merge of #114434 - Nilstrieb:indexing-spans, r=est31Matthias Krüger-2/+2
Improve spans for indexing expressions fixes #114388 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. r? compiler-errors
2023-08-04Reword confusable idents lintEsteban Küber-1/+4
Fix #76140.
2023-08-04Fetch diagnostic item later.Camille GILLOT-2/+2
2023-08-04Make rustc internal lints per module.Camille GILLOT-7/+7
2023-08-04Make MissingDoc a module lint.Camille GILLOT-71/+38
2023-08-04Make MissingDebugImplementation a module lint.Camille GILLOT-22/+14
2023-08-04Simplify clashing_extern_declarations.Camille GILLOT-270/+263
2023-08-04Querify clashing_extern_declarations lint.Camille GILLOT-410/+440
2023-08-04Auto merge of #114414 - cjgillot:early-unnameable-test, r=petrochenkovbors-83/+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/+59
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-119/+165
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-83/+1
2023-08-03Add `internal_features` lintNilstrieb-16/+59
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/+6
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-31/+98
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-24/+24
2023-08-01Expand incorrect_fn_null_check lint with reference null checkingUrgau-13/+35
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-8/+27
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/+67
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-13/+14
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-9/+10
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-44/+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.