about summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2023-07-25inline format!() args from rustc_codegen_llvm to the end (4)Matthias Krüger-28/+26
r? @WaffleLapkin
2023-07-23add suggestionDeadbeef-1/+1
2023-07-23fixDeadbeef-6/+8
2023-07-23make `noop_method_call` warn by defaultDeadbeef-2/+1
2023-07-21lint/ctypes: only try normalizeDavid Wood-12/+9
Now that this lint runs on any external-ABI fn-ptr, normalization won't always succeed, so use `try_normalize_erasing_regions` instead. Signed-off-by: David Wood <david@davidtw.co>
2023-07-19lint/ctypes: allow `()` within typesDavid Wood-32/+15
Consider `()` within types to be FFI-safe, and `()` to be FFI-safe as a return type (incl. when in a transparent newtype). Signed-off-by: David Wood <david@davidtw.co>
2023-07-19lint: refactor `check_variant_for_ffi`David Wood-25/+22
Simplify this function a bit, it was quite hard to reason about. Signed-off-by: David Wood <david@davidtw.co>
2023-07-19lint/ctypes: stricter `()` return type checksDavid Wood-20/+35
`()` 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 an 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 a unit return type or a transparent wrapper around a unit is checked for directly for functions and fn-ptrs. Signed-off-by: David Wood <david@davidtw.co>
2023-07-18Rollup merge of #113832 - WaffleLapkin:track_lint_caller, r=compiler-errorsMatthias Krüger-0/+4
Add `#[track_caller]` to lint related diagnostic functions This fixes locations reported by `-Ztrack-diagnostics`.
2023-07-18Rollup merge of #113811 - jieyouxu:fix-unused-qualifications-suggestion, ↵Matthias Krüger-4/+4
r=oli-obk Fix removal span calculation of `unused_qualifications` suggestion Given a path such as `std::ops::Index<str>`, calculate the unnecessary qualification removal span by computing the beginning of the entire span until the ident span of the last path segment, which handles generic arguments and lifetime arguments in the last path segment. Previous logic only kept the ident span of the last path segment which is incorrect. Closes #113808.
2023-07-18Add `#[track_caller]` to lint related diagnostic functionsMaybe Waffle-0/+4
2023-07-18Fix removal span calculation of unused_qualifications suggestion许杰友 Jieyou Xu (Joe)-4/+4
2023-07-17Rename arg_iter to iter_instantiatedMichael Goulet-1/+1
2023-07-14refactor(rustc_middle): Substs -> GenericArgMahdi Dibaiee-93/+100
2023-07-14Rollup merge of #112729 - jieyouxu:unused-qualifications-suggestion, r=b-naberMatthias Krüger-0/+8
Add machine-applicable suggestion for `unused_qualifications` lint ``` error: unnecessary qualification --> $DIR/unused-qualifications-suggestion.rs:17:5 | LL | foo::bar(); | ^^^^^^^^ | note: the lint level is defined here --> $DIR/unused-qualifications-suggestion.rs:3:9 | LL | #![deny(unused_qualifications)] | ^^^^^^^^^^^^^^^^^^^^^ help: replace it with the unqualified path | LL | bar(); | ~~~ ``` Closes #92198.
2023-07-13Temporarily switch invalid_reference_casting lint to allow-by-defaultUrgau-1/+2
2023-07-13Rename cast_ref_to_mut lint to invalid_reference_castingUrgau-12/+12
2023-07-12Re-format let-else per rustfmt updateMark Rousskov-45/+58
2023-07-13Add machine-applicable suggestion for `unused_qualifications` lint许杰友 Jieyou Xu (Joe)-0/+8
2023-07-11Auto merge of #111717 - Urgau:uplift_fn_null_check, r=oli-obkbors-0/+121
Uplift `clippy::fn_null_check` lint This PR aims at uplifting the `clippy::fn_null_check` lint into rustc. ## `incorrect_fn_null_checks` (warn-by-default) The `incorrect_fn_null_checks` lint checks for expression that checks if a function pointer is null. ### Example ```rust let fn_ptr: fn() = /* somehow obtained nullable function pointer */ if (fn_ptr as *const ()).is_null() { /* ... */ } ``` ### Explanation Function pointers are assumed to be non-null, checking for their nullity is incorrect. ----- 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
2023-07-10Uplift `clippy::fn_null_check` to rustcUrgau-0/+121
2023-07-05Move `TyCtxt::mk_x` to `Ty::new_x` where applicableBoxy-10/+11
2023-07-04allow host param to be lowercaseDeadbeef-0/+4
2023-07-04Auto merge of #113303 - compiler-errors:yeet-chalk, r=lcnrbors-2/+1
Remove chalk support from the compiler Removes chalk (`-Ztrait-solver=chalk`) from the compiler and prunes any dead code resulting from this, mainly: * Remove the chalk compatibility layer in `compiler/rustc_traits/src/chalk` * Remove the chalk flag `-Ztrait-solver=chalk` and its `TraitEngine` implementation * Remove `TypeWellFormedFromEnv` (and its many `bug!()` match arms) * Remove the chalk migration mode from compiletest * Remove the `chalkify` UI tests (do we want to keep any of these, but migrate them to `-Ztrait-solver=next`??) Fulfills rust-lang/types-team#93. r? `@jackh726`
2023-07-03remove TypeWellFormedFromEnvMichael Goulet-2/+1
2023-07-03lint: refactor to make logic a bit cleanerDavid Wood-29/+27
Signed-off-by: David Wood <david@davidtw.co>
2023-07-03lint: stop normalizing types to avoid recur limitsDavid Wood-5/+1
This was causing compilation failures in the performance benchmarking as diesel hit recursion limits. Signed-off-by: David Wood <david@davidtw.co>
2023-07-03lint/ctypes: check other types for ext. fn-ptr tyDavid Wood-1/+63
Extend previous checks for external ABI fn-ptrs to use in internal statics, constants, type aliases and algebraic data types. Signed-off-by: David Wood <david.wood@huawei.com>
2023-07-03lint/ctypes: multiple external fn-ptrs in tyDavid Wood-18/+45
Extend previous commit's support for checking for external fn-ptrs in internal fn types to report errors for multiple found fn-ptrs. Signed-off-by: David Wood <david.wood@huawei.com>
2023-07-03lint/ctypes: ext. abi fn-ptr in internal abi fnDavid Wood-16/+59
Instead of skipping functions with internal ABIs, check that the signature doesn't contain any fn-ptr types with external ABIs that aren't FFI-safe. Signed-off-by: David Wood <david.wood@huawei.com>
2023-07-01Fix dropping_copy_types lint from linting in match-arm with side-effectsUrgau-1/+1
2023-06-29Rollup merge of #112670 - petrochenkov:typriv, r=eholkMatthias Krüger-6/+2
privacy: Type privacy lints fixes and cleanups See individual commits. Follow up to https://github.com/rust-lang/rust/pull/111801.
2023-06-26TypeWellFormedInEnvMichael Goulet-1/+2
2023-06-26Migrate predicates_of and caller_bounds to ClauseMichael Goulet-22/+12
2023-06-22migrate inferred_outlives_of to ClauseMichael Goulet-4/+4
2023-06-22Migrate item_bounds to ty::ClauseMichael Goulet-5/+4
2023-06-19s/Clause/ClauseKindMichael Goulet-18/+18
2023-06-17Move ConstEvaluatable to ClauseMichael Goulet-2/+2
2023-06-17Move WF goal to clauseMichael Goulet-1/+1
2023-06-16Add `AliasKind::Weak` for type aliases.Oli Scherer-3/+3
Only use it when the type alias contains an opaque type. Also does wf-checking on such type aliases.
2023-06-16Auto merge of #112673 - scottmcm:enough-stack, r=compiler-errorsbors-4/+7
Add an `ensure_sufficient_stack` to `LateContextAndPass::visit_expr` This is [apparently](https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/.60-alt.60-only.20failures.3F/near/365396801) where it's busting stack in #112238, and the comments for `ensure_sufficient_stack` say that > E.g. almost any call to visit_expr or equivalent can benefit from this. So this seems like a reasonable change. Hopefully it'll keep this from happening in other places too -- https://github.com/rust-lang/rust/pull/111818#issuecomment-1585023914 hit something similar when updating a lint (bors failure is https://github.com/rust-lang-ci/rust/actions/runs/5199591324/jobs/9377196369), so with any luck this will keep small permutations of things from tripping over the limit.
2023-06-15Rollup merge of #112529 - jieyouxu:block-expr-unused-must-use, r=oli-obkGuillaume Gomez-24/+123
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-32/+42
`suspicious_double_ref_op`: don't lint on `.borrow()` closes #112489
2023-06-15privacy: Do not mark items reachable farther than their nominal visibilityVadim Petrochenkov-6/+2
This commit reverts a change made in #111425. It was believed that this change was necessary for implementing type privacy lints, but #111801 showed that it was not necessary. Quite opposite, the revert fixes some issues.
2023-06-15Add an `ensure_sufficient_stack` to `LateContextAndPass::visit_expr`Scott McMurray-4/+7
This is apparently where it's busting stack, and the comments for `ensure_sufficient_stack` say that > E.g. almost any call to visit_expr or equivalent can benefit from this.
2023-06-15Rollup merge of #111212 - nicklimmm:issue-107896-fix, r=pnkfelixMatthias Krüger-4/+62
Add casting suggestion when assigning negative 2's complement bin or hex literal to a size compatible signed integer Fixes #107896 The issue stated the case for `iX::MIN` variants. This PR extends the cases for other negative values (in the 2's complement). Leveraged sign bits to detect such cases. Example cases: - <img width="845" alt="image" src="https://user-images.githubusercontent.com/65026286/236289682-19859f59-a9c5-48c5-b15f-78a935fbfcec.png"> - <img width="831" alt="image" src="https://user-images.githubusercontent.com/65026286/236289805-5b16488d-9138-4363-a1b6-a5c027c50aba.png"> - <img width="912" alt="image" src="https://user-images.githubusercontent.com/65026286/236290065-685a9777-034b-4def-83a8-cc4e20b1ed0c.png">
2023-06-15Extend `unused_must_use` to cover block exprs许杰友 Jieyou Xu (Joe)-24/+123
2023-06-13Fix explicit-outlives-requirements lint spanSam Ginnett-7/+12
2023-06-13do not use stringly typed diagnosticsDeadbeef-19/+26
2023-06-11Add subdiagnostic and suggestion for overflowing bin hex with sign bitsNicky Lim-4/+62