summary refs log tree commit diff
path: root/compiler/rustc_lint/src/lints.rs
AgeCommit message (Collapse)AuthorLines
2023-08-11Rename cast_ref_to_mut lint to invalid_reference_castingUrgau-3/+3
(cherry picked from commit 3dbbf23e29516218863bda29d2983bd503e6b7fd)
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
2023-05-10Uplift clippy::drop_ref to rustcUrgau-0/+9
2023-04-28uplift `clippy::clone_double_ref` as `suspicious_double_ref_op`Deadbeef-0/+8
2023-04-25Add deny lint to prevent untranslatable diagnostics using static stringsclubby789-0/+4
2023-04-10Fix typos in compilerDaniPopes-7/+7
2023-03-25Emits suggestions for expressions with parentheses or not separatelyMu001999-6/+27
2023-03-24Use independent suggestionsMu42-3/+4
2023-03-22Move useless_anynous_reexport lint into unused_importsGuillaume Gomez-8/+0
2023-03-19Rollup merge of #109003 - GuillaumeGomez:useless-anonymous-reexport-lint, ↵Dylan DPC-0/+8
r=cjgillot Add `useless_anonymous_reexport` lint This is a follow-up of https://github.com/rust-lang/rust/pull/108936. We once again show all anonymous re-exports in rustdoc, however we also wanted to add a lint to let users know that it very likely doesn't have the effect they think it has.
2023-03-15error-msg: expand suggestion for unused lintEzra Shaw-12/+10
2023-03-12Add test for useless_anonymous_reexport lintGuillaume Gomez-0/+1
2023-03-12Add lint for useless anonymous reexportsGuillaume Gomez-0/+7
2023-02-23Add lint against `Iterator::map` receiving a callable that returns `()`Obei Sideg-0/+16
2023-02-22errors: generate typed identifiers in each crateDavid Wood-58/+62
Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter. Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-18lint: don't suggest assume_init for uninhabited typesy21-2/+11
2023-02-17Don't eagerly convert principal to stringclubby789-3/+2
2023-02-04Fix #103320, add explanatory message for [#must_use]yukang-0/+18
2023-01-28Reintroduce multiple_supertrait_upcastable lintGary Guo-0/+7
2023-01-17Remove double spaces after dots in commentsMaybe Waffle-1/+1
2023-01-09migrate: `deref_into_dyn_supertrait.rs`Rejyr-0/+18
2023-01-09add: allow lints in `lints.rs`Rejyr-0/+2
2023-01-09migrate: rest of `builtin.rs` without `builtin_asm_labels`Rejyr-8/+233
2023-01-09migrate: `UnsafeCode` in `builtin.rs`Rejyr-1/+41
2023-01-09migrate: `hidden_unicode_codepoints.rs`Rejyr-1/+89
2023-01-09refactor: refactor to derive for some lints.Rejyr-112/+62
2023-01-09migrate: `for_loops_over_fallibles.rs`Rejyr-0/+49
2023-01-09migrate: `expect.rs`Rejyr-1/+30
2023-01-09migrate(wip): `builtin.rs`Rejyr-1/+256