summary refs log tree commit diff
path: root/compiler/rustc_lint/src
AgeCommit message (Collapse)AuthorLines
2023-08-11lint/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> (cherry picked from commit 09434a2575cee12b241c516ad91f21d4b4f9c3fd)
2023-08-11lint/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> (cherry picked from commit 24f90fdd2654e9c5437a684d3a72a4e70826a985)
2023-08-11lint: 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> (cherry picked from commit 99b1897cf640d5f6dac74416761c9b3c75e1ef7a)
2023-08-11lint/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> (cherry picked from commit f53cef31f5ea41c9a5ab8e5335637a6873b9f0b5)
2023-08-11Temporarily switch invalid_reference_casting lint to allow-by-defaultUrgau-1/+2
(cherry picked from commit f25ad54a4d0febbcb2b7e951835228b7b2320b49)
2023-08-11Rename cast_ref_to_mut lint to invalid_reference_castingUrgau-12/+12
(cherry picked from commit 3dbbf23e29516218863bda29d2983bd503e6b7fd)
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
2023-06-11`suspicious_double_ref_op`: don't lint on `.borrow()`Deadbeef-15/+18
2023-06-10Auto merge of #112494 - matthiaskrgr:rollup-xdf3om8, r=matthiaskrgrbors-2/+2
Rollup of 5 pull requests Successful merges: - #112297 (bootstrap: Disallow `--exclude test::std`) - #112298 (Update field-offset and enable unstable_offset_of) - #112335 (ci: Upgrade loongarch64-linux-gnu GCC to 13.1.0) - #112413 (Adjust span labels for `HIDDEN_GLOB_REEXPORTS`) - #112483 (Add deprecation warning to python versions <3.6 in x.py) r? `@ghost` `@rustbot` modify labels: rollup
2023-06-10Auto merge of #111818 - Urgau:uplift_cmp_nan, r=cjgillotbors-7/+125
Uplift `clippy::cmp_nan` lint This PR aims at uplifting the `clippy::cmp_nan` lint into rustc. ## `invalid_nan_comparisons` ~~(deny-by-default)~~ (warn-by-default) The `invalid_nan_comparisons` lint checks comparison with `f32::NAN` or `f64::NAN` as one of the operand. ### Example ```rust,compile_fail let a = 2.3f32; if a == f32::NAN {} ``` ### Explanation NaN does not compare meaningfully to anything – not even itself – so those comparisons are always false. ----- 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-06-10Uplift improved version of `clippy::cmp_nan` to rustcUrgau-7/+125
2023-06-10Adjust span labels for `HIDDEN_GLOB_REEXPORTS`许杰友 Jieyou Xu (Joe)-2/+2
2023-06-09Auto merge of #112465 - GuillaumeGomez:rollup-gyh5buc, r=GuillaumeGomezbors-4/+18
Rollup of 3 pull requests Successful merges: - #112260 (Improve document of `unsafe_code` lint) - #112429 ([rustdoc] List matching impls on type aliases) - #112442 (Deduplicate identical region constraints in new solver) r? `@ghost` `@rustbot` modify labels: rollup
2023-06-09Auto merge of #111530 - Urgau:uplift_undropped_manually_drops, r=compiler-errorsbors-2/+61
Uplift `clippy::undropped_manually_drops` lint This PR aims at uplifting the `clippy::undropped_manually_drops` lint. ## `undropped_manually_drops` (warn-by-default) The `undropped_manually_drops` lint check for calls to `std::mem::drop` with a value of `std::mem::ManuallyDrop` which doesn't drop. ### Example ```rust struct S; drop(std::mem::ManuallyDrop::new(S)); ``` ### Explanation `ManuallyDrop` does not drop it's inner value so calling `std::mem::drop` will not drop the inner value of the `ManuallyDrop` either. ----- Mostly followed the instructions for uplifting an 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::undropped_manually_drops` into rustc
2023-06-09Improve document of `unsafe_code` lintEval EXEC-4/+18
Signed-off-by: Eval EXEC <execvy@gmail.com>
2023-06-08Uplift clippy::undropped_manually_drops to rustcUrgau-2/+61
2023-06-06Rollup merge of #112343 - GuillaumeGomez:extern-crate-missing-docs, r=notriddleMatthias Krüger-2/+6
Prevent emitting `missing_docs` for `pub extern crate` Fixes #112308. r? `@notriddle`
2023-06-06Prevent emitting `missing_docs` for `pub extern crate`Guillaume Gomez-2/+6
2023-06-05Ensure space is inserted after keyword in `unused_delims`clubby789-17/+42
2023-06-01Rollup merge of #111496 - mpalmer:unreachable-pub-docs, r=pnkfelixMatthias Krüger-4/+8
Extra context for unreachable_pub lint While experienced Rustaceans no doubt know this sort of thing already, as more of a newbie I had trouble understanding why I was triggering the lint. Hopefully this expanded explanation saves someone else some head-scratching. Fixes #110922
2023-05-31Uplift clippy::cast_ref_to_mut to rustcUrgau-0/+80
2023-05-30Rollup merge of #111543 - Urgau:uplift_invalid_utf8_in_unchecked, r=WaffleLapkinNilstrieb-0/+140
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