summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2023-09-29Rollup merge of #116231 - DaniPopes:simpler-lint-array, r=NilstriebMatthias Krüger-7/+6
Remove `rustc_lint_defs::lint_array`
2023-09-29Rollup merge of #116201 - Jarcho:noop_fix, r=fee1-deadMatthias Krüger-0/+6
Fix `noop_method_call` detection This needs to be merged before #116198 can compile. The error occurs before the compiler is built so this needs to be a separate PR.
2023-09-28Remove `rustc_lint_defs::lint_array`DaniPopes-7/+6
2023-09-28Auto merge of #116199 - Urgau:simplify-invalid_ref_casting, r=cjgillotbors-112/+80
Simplify some of the logic in the `invalid_reference_casting` lint This PR simplifies 2 areas of the logic for the `invalid_reference_casting` lint: - The init detection: we now use the newly added `expr_or_init` function instead of a manual detection - The ref-to-mut-ptr casting detection logic: I simplified this logic by caring less hardly about the order of the casting operations Those two simplifications permits us to detect more cases, as can be seen in the test output changes.
2023-09-28Fix `noop_method_call` detection for new diagnostic itemsJason Newcomb-0/+6
2023-09-28Auto merge of #116204 - Alexendoo:rustc-lint-macro-paths, r=cjgillotbors-84/+78
Use absolute paths in rustc_lint::passes macros A cosmetic change, so the callsite doesn't have to import things. Makes nicer for us to try in clippy
2023-09-27Fix ICE by introducing an expr_or_init variant for outside bodiesUrgau-3/+40
2023-09-27Simplify casting logic of the invalid_reference_casting lintUrgau-80/+32
2023-09-27Use absolute paths in rustc_lint::passes macrosAlex Macleod-84/+78
A cosmetic change, so the callsite doesn't have to import things
2023-09-27Prefer expr_or_init over manual init detectionUrgau-29/+8
2023-09-26Don't store lazyness in DefKindMichael Goulet-3/+3
2023-09-23Remove GeneratorWitness and rename GeneratorWitnessMIR.Camille GILLOT-1/+0
2023-09-22make the reason: field mandatory for @future_incompatible lintsRalf Jung-4/+6
2023-09-21Record asyncness span in HIRMichael Goulet-2/+1
2023-09-21Rollup merge of #115257 - Urgau:invalid-utf8-walk-up-hir, r=NilstriebGuillaume Gomez-11/+62
Improve invalid UTF-8 lint by finding the expression initializer This PR introduce a small mechanism to walk up the HIR through bindings, if/else, consts, ... when trying lint on invalid UTF-8. Fixes https://github.com/rust-lang/rust/issues/115208
2023-09-21Improve invalid UTF-8 lint by finding the expression initializerUrgau-11/+14
2023-09-18Add clippy like expr_or_init fn to rustc LateContextUrgau-0/+48
2023-09-16Auto merge of #114494 - est31:extend_useless_ptr_null_checks, r=jackh726bors-23/+31
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-09-14Auto merge of #115677 - matthewjasper:let-expr-recovery, r=b-naberbors-7/+5
Improve invalid let expression handling - Move all of the checks for valid let expression positions to parsing. - Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location. - Suppress some later errors and MIR construction for invalid let expressions. - Fix a (drop) scope issue that was also responsible for #104172. Fixes #104172 Fixes #104868
2023-09-14Auto merge of #115825 - cjgillot:expr-field-lint, r=compiler-errorsbors-0/+9
Visit ExprField for lint levels. Fixes https://github.com/rust-lang/rust/issues/115823
2023-09-13Visit ExprField for lint levels.Camille GILLOT-0/+9
2023-09-11Rollup merge of #115631 - compiler-errors:ctypes-unsized, r=davidtwcoMatthias Krüger-1/+6
Don't ICE when computing ctype's `repr_nullable_ptr` for possibly-unsized ty We may not always be able to compute the layout of a type like `&T` when `T: ?Sized`, even if we're able to estimate its size skeleton. r? davidtwco Fixes #115628
2023-09-11Move let expression checking to parsingMatthew Jasper-7/+5
There was an incomplete version of the check in parsing and a second version in AST validation. This meant that some, but not all, invalid uses were allowed inside macros/disabled cfgs. It also means that later passes have a hard time knowing when the let expression is in a valid location, sometimes causing ICEs. - Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location. - Suppress later errors and MIR construction for invalid let expressions.
2023-09-11Rollup merge of #115739 - Alexendoo:lint-pass-check-attribute, r=oli-obkMatthias Krüger-13/+12
Call `LateLintPass::check_attribute` from `with_lint_attrs` Fixes #115571 For regular `register_late_pass` lints also means that `last_node_with_lint_attrs` is correct when in `check_attribute`, I've added a test that previously failed for `clippy::allow_attributes` As far as I can see the only late lint in rustc that uses `check_attribute` is `unstable_features` which is allow by default and deprecated so this is mostly for clippy (or future rustc lints)
2023-09-11Auto merge of #115387 - weihanglo:merge-check-and-lint, r=oli-obkbors-153/+133
Make unknown/renamed/removed lints passed via command line respect lint levels
2023-09-10Call `LateLintPass::check_attribute` from `with_lint_attrs`Alex Macleod-13/+12
2023-09-09Fix ICE in improper_ctypes_definitions lintGurinder Singh-2/+2
The lint panicked for an input like 'extern "C" fn(Option<&<T as FooTrait>::FooType>)' because the type T therein cannot be normalized. The normalization failure caused SizeSkeleton::compute() to return an error and trigger a panic in the unwrap().
2023-09-07Don't ICE when computing ctype's repr_nullable_ptr for possibly-unsized tyMichael Goulet-1/+6
2023-09-07Auto merge of #115166 - Urgau:invalid_ref_casting-invalid-unsafecell-usage, ↵bors-5/+39
r=est31 Lint on invalid usage of `UnsafeCell::raw_get` in reference casting This PR proposes to take into account `UnsafeCell::raw_get` method call for non-Freeze types for the `invalid_reference_casting` lint. The goal of this is to catch those kind of invalid reference casting: ```rust fn as_mut<T>(x: &T) -> &mut T { unsafe { &mut *std::cell::UnsafeCell::raw_get(x as *const _ as *const _) } //~^ ERROR casting `&T` to `&mut T` is undefined behavior } ``` r? `@est31`
2023-09-06Rollup merge of #115578 - ouz-a:rustc_clarify, r=oli-obkMatthias Krüger-1/+1
Clarify cryptic comments Clarifies some unclear comments that lurked in the compiler. r? ``@oli-obk``
2023-09-06make comments less crypticouz-a-1/+1
2023-09-03Emit unused doc comment warnings for pat and expr fieldsGurinder Singh-0/+14
2023-09-01Rollup merge of #115424 - notriddle:notriddle/issue-106413, r=oli-obkMatthias Krüger-1/+30
diagnostics: avoid wrong `unused_parens` on `x as (T) < y` Fixes #106413 Fixes #80636
2023-09-01Auto merge of #113126 - Bryanskiy:delete_old, r=petrochenkovbors-0/+5
Replace old private-in-public diagnostic with type privacy lints Next part of RFC https://github.com/rust-lang/rust/issues/48054. r? `@petrochenkov`
2023-08-31Use terminology more sensiblyMichael Howell-1/+1
2023-08-31diagnostics: avoid wrong `unused_parens` on `x as (T) < y`Michael Howell-1/+30
2023-08-30feat(rustc_lint): make `CheckLintName` respect lint levelWeihang Lo-109/+97
2023-08-30refactor(rustc_lint): inline `check_lint_name_cmdline`Weihang Lo-70/+62
2023-08-29some more is_zst that should be is_1zstRalf Jung-3/+3
2023-08-24Rollup merge of #115152 - weihanglo:lint-refactor, r=compiler-errorsWeihang Lo-51/+77
refactor(lint): translate `RenamedOrRemovedLint` I was trying to address <https://github.com/rust-lang/cargo/issues/12495> and found that maybe I should refactor relevant lints a bit. This PR translates `RenamedOrRemovedLint` into fluent file. To make diagnostic types clearer and easier to organize, this PR splits it into two structs. The second commit adds lifetime annotations for removing unnecessary clones. If people feel too noisy, we can revert such change. ### Possibly relevant UI tests: * `tests/ui/lint-removed*` * `tests/ui/lint-renamed*` * `tests/ui/rustdoc-renamed.rs` * `tests/rustdoc-ui/lints/unknown-renamed-lints.rs`
2023-08-24Lint on invalid UnsafeCell::raw_get with invalid_reference_casting lintUrgau-5/+39
2023-08-24Auto merge of #115094 - Mark-Simulacrum:bootstrap-update, r=ozkanonurbors-1/+1
Update bootstrap compiler to 1.73.0 beta
2023-08-24refactor: use references to reduce unnecessary clonesWeihang Lo-28/+27
2023-08-24lint: translate `RenamedOrRemovedLint`Weihang Lo-34/+61
2023-08-23Bump cfg(bootstrap)Mark Rousskov-1/+1
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-23Rollup merge of #115100 - Urgau:invalid_ref_casting-ptr-writes, r=est31Dylan DPC-17/+47
Add support for `ptr::write`s for the `invalid_reference_casting` lint This PR adds support for `ptr::write` and others for the `invalid_reference_casting` lint. Detecting instances where instead of using the deref (`*`) operator to assign someone uses `ptr::write`, `ptr::write_unaligned` or `ptr::write_volatile`. ```rust let data_len = 5u64; std::ptr::write( std::mem::transmute::<*const u64, *mut u64>(&data_len), new_data_len, ); ``` r? ``@est31``
2023-08-22Rollup merge of #115011 - compiler-errors:warn-on-elided-assoc-ct-lt, r=cjgillotMichael Goulet-0/+8
Warn on elided lifetimes in associated constants (`ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT`) Elided lifetimes in associated constants (in impls) erroneously resolve to fresh lifetime parameters on the impl since #97313. This is not correct behavior (see #38831). I originally opened #114716 to fix this, but given the time that has passed, the crater results seem pretty bad: https://github.com/rust-lang/rust/pull/114716#issuecomment-1682091952 This PR alternatively implements a lint against this behavior, and I'm hoping to bump this to deny in a few versions.
2023-08-22Add support for ptr::write for the invalid_reference_casting lintUrgau-17/+47
2023-08-22unknown unstable lint command linemojave2-10/+18
fix ##113702 fix #113702 unknown unstable lint command lint improve impelementation