about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2023-10-13Format all the let chains in compilerMichael Goulet-189/+270
2023-10-12check-cfg: only print the list of expected names onceUrgau-1/+5
2023-10-12check-cfg: adjust expected names and values when usefulUrgau-1/+12
2023-10-12Auto merge of #116628 - gurry:116293-dup-note.rs, r=petrochenkovbors-10/+4
Fix duplicate note on internal feature gates with associated issues Fixes #116293 Note sure if I should add tests because the issue occurs only for feature gates having associated issues and that set of feature gates will change unpredictably leading to an unnecessary churn in tests.
2023-10-12Fix duplicate note on internal feature gateGurinder Singh-10/+4
The BuiltinInternalFeatures gate already has a struct level #[note] attribute. The additional note field in it caused a duplicate to be displayed when it was set to Some(...) which happened when the feature had an associated issue
2023-10-11Auto merge of #116623 - Nadrieril:validate-range-endpoints, r=oli-obkbors-8/+9
Fix overflow checking in range patterns When a range pattern contains an overflowing literal, if we're not careful we might not notice the overflow and use the wrapped value. This makes for confusing error messages because linting against overflowing literals is only done in a later pass. So when a range is invalid we check for overflows to provide a better error. This check didn't use to handle negative types; this PR fixes that. First commit adds tests, second cleans up without changing behavior, third does the fix. EDIT: while I was at it, I fixed a small annoyance about the span of the overflow lint on negated literals. Fixes https://github.com/rust-lang/rust/issues/94239
2023-10-11Fix span of overflow lint for negated literalsNadrieril-8/+9
2023-10-08rustdoc: remove rust logo from non-Rust cratesMichael Howell-0/+2
2023-10-06Rollup merge of #116421 - Urgau:inter-mut-invalid_ref_casting, r=oli-obkMatthias Krüger-11/+19
Clarify `invalid_reference_casting` lint around interior mutable types This is PR intends to clarify the `invalid_reference_casting` lint around interior mutable types by adding a note for them saying that they should go through `UnsafeCell::get`. So for this code: ```rust let cell = &std::cell::UnsafeCell::new(0); let _num = &mut *(cell as *const _ as *mut i32); ``` the following note will be added to the lint output: ```diff error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell` --> $DIR/reference_casting.rs:68:16 | LL | let _num = &mut *(cell as *const _ as *mut i32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, visit <https://doc.rust-lang.org/book/ch15-05-interior-mutability.html> + = note: even for types with interior mutability, the only legal way to obtain a mutable pointer from a shared reference is through `UnsafeCell::get` ``` Suggestion are welcome around the note contents. Fixes https://github.com/rust-lang/rust/issues/116410 cc `@RalfJung`
2023-10-05Auto merge of #116184 - compiler-errors:afit-lint, r=tmandrybors-0/+152
Add `async_fn_in_trait` lint cc https://github.com/rust-lang/rust/pull/115822#issuecomment-1731168465 Mostly unsure what the messaging should be. Feedback required. r? `@tmandry`
2023-10-04Apply suggestions from code reviewTyler Mandry-2/+7
Co-authored-by: Travis Cross <tc@traviscross.com>
2023-10-04Clarify `invalid_reference_casting` lint around interior mutable typesUrgau-11/+19
2023-10-03Rollup merge of #116379 - fmease:opaq-hid-inf-bnds-non-lt-bndrs, ↵Matthias Krüger-7/+3
r=compiler-errors non_lifetime_binders: fix ICE in lint opaque-hidden-inferred-bound Opaque types like `impl for<T> Trait<T>` would previously lead to an ICE. r? `@compiler-errors`
2023-10-03non_lifetime_binders: fix ICE in lint opaque-hidden-inferred-boundLeón Orell Valerian Liehr-7/+3
2023-10-03Address review nitsMichael Goulet-7/+6
2023-10-03Only reachable traitsMichael Goulet-0/+6
2023-10-03Fill in prose to describe the `async_fn_in_trait` lintTravis Cross-5/+65
We're stabilizing `async fn` in trait (AFIT), but we have some reservations about how people might use this in the definitions of publicly-visible traits, so we're going to lint about that. This is a bit of an odd lint for `rustc`. We normally don't lint just to have people confirm that they understand how Rust works. But in this one exceptional case, this seems like the right thing to do as compared to the other plausible alternatives. In this commit, we describe the nature of this odd lint.
2023-10-03Add async_fn_in_trait lintMichael Goulet-0/+82
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-26const-eval: make misalignment a hard errorRalf Jung-0/+5
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