summary refs log tree commit diff
path: root/compiler/rustc_lint/src/lints.rs
AgeCommit message (Collapse)AuthorLines
2023-09-16Auto merge of #114494 - est31:extend_useless_ptr_null_checks, r=jackh726bors-0/+2
Make useless_ptr_null_checks smarter about some std functions This teaches the `useless_ptr_null_checks` lint that some std functions can't ever return null pointers, because they need to point to valid data, get references as input, etc. This is achieved by introducing an `#[rustc_never_returns_null_ptr]` attribute and adding it to these std functions (gated behind bootstrap `cfg_attr`). Later on, the attribute could maybe be used to tell LLVM that the returned pointer is never null. I don't expect much impact of that though, as the functions are pretty shallow and usually the input data is already never null. Follow-up of PR #113657 Fixes #114442
2023-08-30feat(rustc_lint): make `CheckLintName` respect lint levelWeihang Lo-10/+58
2023-08-24lint: translate `RenamedOrRemovedLint`Weihang Lo-6/+12
2023-08-23Improve note for the invalid_reference_casting lintUrgau-0/+2
Add link to the book interior mutability chapter, https://doc.rust-lang.org/book/ch15-05-interior-mutability.html.
2023-08-06Improve diagnostics and add tests for function callsest31-0/+2
2023-08-06Rollup merge of #114486 - Urgau:const-context-nan-suggestion-114471, ↵Matthias Krüger-1/+1
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-05Avoid invalid NaN lint machine-applicable suggestion in const contextUrgau-1/+1
2023-08-04Auto merge of #112117 - bryangarza:track-caller-feature-gate, r=compiler-errorsbors-1/+1
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/+3
Reword `confusable_idents` lint Fix #76140.
2023-08-04Reword confusable idents lintEsteban Küber-1/+3
Fix #76140.
2023-08-04Auto merge of #114414 - cjgillot:early-unnameable-test, r=petrochenkovbors-4/+0
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-03Auto merge of #108955 - Nilstrieb:dont-use-me-pls, r=oli-obkbors-2/+11
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-4/+16
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-4/+0
2023-08-03Add `internal_features` lintNilstrieb-2/+11
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-1/+5
2023-08-02Add separate feature gate for async fn track callerBryan Garza-1/+1
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-01Rename incorrect_fn_null_checks to useless_ptr_null_checksUrgau-4/+4
2023-08-01Expand incorrect_fn_null_check lint with reference null checkingUrgau-3/+11
2023-07-29Improve diagnostics of the invalid_reference_casting lintUrgau-4/+11
2023-07-29Add support for deferred casting for the invalid_reference_casting lintUrgau-1/+4
2023-07-29Auto merge of #113422 - Urgau:cast_ref_to_mut-pre-beta, r=Nilstriebbors-3/+3
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 #111916 - fee1-dead-contrib:noop-method-call-warn, ↵bors-2/+3
r=compiler-errors make `noop_method_call` warn by default r? `@compiler-errors`
2023-07-25inline format!() args from rustc_codegen_llvm to the end (4)Matthias Krüger-3/+3
r? @WaffleLapkin
2023-07-23add suggestionDeadbeef-1/+1
2023-07-23fixDeadbeef-1/+2
2023-07-13Rename cast_ref_to_mut lint to invalid_reference_castingUrgau-3/+3
2023-07-10Uplift `clippy::fn_null_check` to rustcUrgau-0/+6
2023-06-26Migrate predicates_of and caller_bounds to ClauseMichael Goulet-3/+3
2023-06-15Rollup merge of #112529 - jieyouxu:block-expr-unused-must-use, r=oli-obkGuillaume Gomez-11/+42
Extend `unused_must_use` to cover block exprs Given code like ```rust #[must_use] fn foo() -> i32 { 42 } fn warns() { { foo(); } } fn does_not_warn() { { foo() }; } fn main() { warns(); does_not_warn(); } ``` ### Before This PR ``` warning: unused return value of `foo` that must be used --> test.rs:8:9 | 8 | foo(); | ^^^^^ | = note: `#[warn(unused_must_use)]` on by default help: use `let _ = ...` to ignore the resulting value | 8 | let _ = foo(); | +++++++ warning: 1 warning emitted ``` ### After This PR ``` warning: unused return value of `foo` that must be used --> test.rs:8:9 | 8 | foo(); | ^^^^^ | = note: `#[warn(unused_must_use)]` on by default help: use `let _ = ...` to ignore the resulting value | 8 | let _ = foo(); | +++++++ warning: unused return value of `foo` that must be used --> test.rs:14:9 | 14 | foo() | ^^^^^ | help: use `let _ = ...` to ignore the resulting value | 14 | let _ = foo(); | +++++++ + warning: 2 warnings emitted ``` Fixes #104253.
2023-06-15Rollup merge of #112517 - fee1-dead-contrib:sus-op-no-borrow, r=compiler-errorsGuillaume Gomez-4/+8
`suspicious_double_ref_op`: don't lint on `.borrow()` closes #112489
2023-06-15Extend `unused_must_use` to cover block exprs许杰友 Jieyou Xu (Joe)-11/+42
2023-06-13do not use stringly typed diagnosticsDeadbeef-4/+8
2023-06-11Add subdiagnostic and suggestion for overflowing bin hex with sign bitsNicky Lim-0/+17
2023-06-10Uplift improved version of `clippy::cmp_nan` to rustcUrgau-0/+30
2023-06-08Uplift clippy::undropped_manually_drops to rustcUrgau-0/+19
2023-05-31Uplift clippy::cast_ref_to_mut to rustcUrgau-0/+5
2023-05-30Rollup merge of #111543 - Urgau:uplift_invalid_utf8_in_unchecked, r=WaffleLapkinNilstrieb-0/+19
Uplift `clippy::invalid_utf8_in_unchecked` lint This PR aims at uplifting the `clippy::invalid_utf8_in_unchecked` lint into two lints. ## `invalid_from_utf8_unchecked` (deny-by-default) The `invalid_from_utf8_unchecked` lint checks for calls to `std::str::from_utf8_unchecked` and `std::str::from_utf8_unchecked_mut` with an invalid UTF-8 literal. ### Example ```rust unsafe { std::str::from_utf8_unchecked(b"cl\x82ippy"); } ``` ### Explanation Creating such a `str` would result in undefined behavior as per documentation for `std::str::from_utf8_unchecked` and `std::str::from_utf8_unchecked_mut`. ## `invalid_from_utf8` (warn-by-default) The `invalid_from_utf8` lint checks for calls to `std::str::from_utf8` and `std::str::from_utf8_mut` with an invalid UTF-8 literal. ### Example ```rust std::str::from_utf8(b"ru\x82st"); ``` ### Explanation Trying to create such a `str` would always return an error as per documentation for `std::str::from_utf8` and `std::str::from_utf8_mut`. ----- 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 ----- For Clippy: changelog: Moves: Uplifted `clippy::invalid_utf8_in_unchecked` into rustc
2023-05-29Use `Cow` in `{D,Subd}iagnosticMessage`.Nicholas Nethercote-1/+1
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment: ``` // FIXME(davidtwco): can a `Cow<'static, str>` be used here? ``` This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging. This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths. Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile.
2023-05-27Add invalid_from_utf8 analogous to invalid_from_utf8_uncheckedUrgau-6/+15
2023-05-27Uplift clippy::invalid_utf8_in_unchecked as invalid_from_utf8_uncheckedUrgau-0/+10
2023-05-21Rename `forget_ref` lint to `forgetting_references`Urgau-1/+1
2023-05-21Rename `drop_ref` lint to `dropping_references`Urgau-2/+2
2023-05-21Rename `forget_copy` lint to `forgetting_copy_types`Urgau-1/+1
2023-05-21Rename `drop_copy` lint to `dropping_copy_types`Urgau-1/+1
2023-05-10Add note to suggest using `let _ = x` to ignore the valueUrgau-0/+4
2023-05-10Use label instead of note to be more consistent with other lintsUrgau-8/+8
2023-05-10Uplift clippy::forget_copy to rustcUrgau-0/+8
2023-05-10Uplift clippy::forget_ref to rustcUrgau-0/+8
2023-05-10Uplift clippy::drop_copy to rustcUrgau-0/+8