Commit Graph

230 Commits

Author SHA1 Message Date
bors
2bbb619893 Auto merge of #114417 - chinedufn:fix-expect-unused-in-impl-block-rust-issue-114416, r=cjgillot
Fix multiple `expect` attribs in impl block

Closes #114416
2023-10-04 20:44:38 +00:00
Chinedu Francis Nwafili
67379c4006
Address misc feedback 2023-10-02 08:59:31 -04:00
Matthias Krüger
e814f1e3c0
Rollup merge of #116201 - Jarcho:noop_fix, r=fee1-dead
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-29 10:11:12 +02:00
Jason Newcomb
66bc682cab Fix noop_method_call detection for new diagnostic items 2023-09-28 08:22:59 -04:00
Urgau
1b2c1a8583 Fix ICE by introducing an expr_or_init variant for outside bodies 2023-09-27 18:59:24 +02:00
Urgau
bd360472b1 Simplify casting logic of the invalid_reference_casting lint 2023-09-27 18:50:26 +02:00
Urgau
e577dcdd4d Prefer expr_or_init over manual init detection 2023-09-27 15:09:30 +02:00
Camille GILLOT
211d2ed07b Bless tests. 2023-09-23 13:47:30 +00:00
Camille GILLOT
a626caaad9 Revert duplication of tests. 2023-09-23 13:34:07 +00:00
bors
959b2c703d Auto merge of #115696 - RalfJung:closure-ty-print, r=oli-obk
adjust how closure/generator types are printed

I saw `&[closure@$DIR/issue-20862.rs:2:5]` and I thought it is a slice type, because that's usually what `&[_]` is... it took me a while to realize that this is just a confusing printer and actually there's no slice. Let's use something that cannot be mistaken for a regular type.
2023-09-22 15:19:38 +00:00
Ralf Jung
c4ec12f4b7 adjust how closure/generator types and rvalues are printed 2023-09-21 22:20:58 +02:00
Martin Nordholts
d016e9a686 tests/ui: Split large_moves.rs and move to lint/large_assignments
To make failing tests easier to debug with --emit=mir, etc.
2023-09-21 21:00:11 +02:00
Guillaume Gomez
9ce64bae94
Rollup merge of #115257 - Urgau:invalid-utf8-walk-up-hir, r=Nilstrieb
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-21 13:25:38 +02:00
Urgau
f156d3bc57 Improve invalid UTF-8 lint by finding the expression initializer 2023-09-21 10:16:29 +02:00
bors
635c4a5e61 Auto merge of #114494 - est31:extend_useless_ptr_null_checks, r=jackh726
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-16 03:40:20 +00:00
bors
e17235105c Auto merge of #115825 - cjgillot:expr-field-lint, r=compiler-errors
Visit ExprField for lint levels.

Fixes https://github.com/rust-lang/rust/issues/115823
2023-09-14 06:29:23 +00:00
bors
c728bf3963 Auto merge of #114656 - bossmc:rework-no-coverage-attr, r=oli-obk
Rework `no_coverage` to `coverage(off)`

As discussed at the tail of https://github.com/rust-lang/rust/issues/84605 this replaces the `no_coverage` attribute with a `coverage` attribute that takes sub-parameters (currently `off` and `on`) to control the coverage instrumentation.

Allows future-proofing for things like `coverage(off, reason="Tested live", issue="#12345")` or similar.
2023-09-14 01:05:18 +00:00
Camille GILLOT
01d7bf09f3 Visit ExprField for lint levels. 2023-09-13 19:47:20 +00:00
Chinedu Francis Nwafili
7db9c3c1a6
Tests passing 2023-09-12 03:11:11 -04:00
Matthias Krüger
5a2b589ac7
Rollup merge of #115631 - compiler-errors:ctypes-unsized, r=davidtwco
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-11 21:16:21 +02:00
bors
5d62ab8981 Auto merge of #115387 - weihanglo:merge-check-and-lint, r=oli-obk
Make unknown/renamed/removed lints passed via command line respect lint levels
2023-09-11 08:56:29 +00:00
Gurinder Singh
e7c51320db Fix ICE in improper_ctypes_definitions lint
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-09 12:30:25 +05:30
Andy Caldwell
679267f2ac
Rename the feature, but not the attribute, to coverage_attribute 2023-09-08 12:46:09 +01:00
Andy Caldwell
8e03371fc3
Rework no_coverage to coverage(off) 2023-09-08 12:46:06 +01:00
Michael Goulet
086cf34634 Don't ICE when computing ctype's repr_nullable_ptr for possibly-unsized ty 2023-09-07 06:04:37 +00:00
bors
4e5b31c2b0 Auto merge of #115166 - Urgau:invalid_ref_casting-invalid-unsafecell-usage, 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-07 00:24:45 +00:00
Urgau
efbe445ba7 Add help to allow lint for the implied by suggestion 2023-09-04 14:21:38 +02:00
Gurinder Singh
10f4917568 Emit unused doc comment warnings for pat and expr fields 2023-09-03 08:21:18 +05:30
Matthias Krüger
888dc2e3b0
Rollup merge of #115424 - notriddle:notriddle/issue-106413, r=oli-obk
diagnostics: avoid wrong `unused_parens` on `x as (T) < y`

Fixes #106413
Fixes #80636
2023-09-01 21:41:39 +02:00
bors
1accf068d8 Auto merge of #113126 - Bryanskiy:delete_old, r=petrochenkov
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-09-01 12:40:01 +00:00
Michael Howell
62835c9531 diagnostics: avoid wrong unused_parens on x as (T) < y 2023-08-31 20:14:49 -07:00
Weihang Lo
a11805ae46
feat(rustc_lint): make CheckLintName respect lint level 2023-08-30 19:24:44 +01:00
Weihang Lo
ecff1c012e
test(ui/lint): demonstrate the current cmdline lint behavior
This demonstrates the current behavior of adding lint form the command
line. generally the lint levels are ignored as the current implementation
unconditionally emit errors for those lints.
2023-08-30 15:10:35 +01:00
Urgau
89800a27fc Lint on invalid UnsafeCell::raw_get with invalid_reference_casting lint 2023-08-24 15:00:21 +02:00
Urgau
aa7730003e Improve note for the invalid_reference_casting lint
Add link to the book interior mutability chapter,
https://doc.rust-lang.org/book/ch15-05-interior-mutability.html.
2023-08-23 11:27:33 +02:00
Urgau
7ee77b5d1b Add support for ptr::write for the invalid_reference_casting lint 2023-08-22 15:47:29 +02:00
Matthias Krüger
2667d853a6
Rollup merge of #114784 - Urgau:many-improve-invalid_reference_casting-lint, r=est31
Improve `invalid_reference_casting` lint

This PR improves the `invalid_reference_casting` lint:
 - by considering an unlimited number of casts instead only const to mut ptr
 - by also considering ptr-to-integer and integer-to-ptr casts
 - by also taking into account [`ptr::cast`](https://doc.rust-lang.org/std/primitive.pointer.html#method.cast), [`ptr::cast`](https://doc.rust-lang.org/std/primitive.pointer.html#method.cast-1) and [`ptr::cast_const`](https://doc.rust-lang.org/std/primitive.pointer.html#method.cast_const)

Most of this improvements comes from skimming Github Code Search result for [`&mut \*.*as \*const`](https://github.com/search?q=lang%3Arust+%2F%26mut+%5C*.*as+%5C*const%2F&type=code)

r? ``@est31`` (maybe)
2023-08-16 20:10:37 +02:00
Chinedu Francis Nwafili
8ad46b49a2
Misc progress 2023-08-15 09:41:43 -04:00
Guillaume Gomez
dd76268ac5
Rollup merge of #114820 - ehuss:unknown-lint-mod-warning, r=compiler-errors
Add test for unknown_lints from another file.

This adds a test for #84936 which was incidentally fixed via #97266. It is a strange issue where `#![allow(unknown_lints)]` at the crate root was not applying to unknown lints that fired in a non-inline-module. I did not dig further into how #97266 fixed it, but I did verify it. I couldn't find any existing tests which did anything similar.

Closes #84936
2023-08-15 14:29:47 +02:00
Urgau
91b05f8e09 Improve invalid_reference_casting lint 2023-08-15 10:14:45 +02:00
Eric Huss
9dda6b5d35 Add test for unknown_lints from another file. 2023-08-14 12:05:53 -07:00
yukang
c44b35e1c3 match scrutinee need necessary parentheses for structs 2023-08-14 18:05:13 +08:00
bors
570601f0aa Auto merge of #114757 - Urgau:transmute-with-invalid_reference_casting, r=est31
Also consider `mem::transmute` with the `invalid_reference_casting` lint

This PR extend the `invalid_reference_casting` lint with regard to the `std::mem::transmute` function.

```
error: casting `&T` to `&mut T` is undefined behavior, even if the reference is unused, consider instead using an `UnsafeCell`
  --> $DIR/reference_casting.rs:27:16
   |
LL |     let _num = &mut *std::mem::transmute::<_, *mut i32>(&num);
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```

*I encourage anyone reviewing this PR to do so [without whitespaces](https://github.blog/2011-10-21-github-secrets/#whitespace).*
2023-08-13 12:46:00 +00:00
bors
1e836d12d3 Auto merge of #114710 - Urgau:fix-expect-dead_code-114557, r=cjgillot
Respect `#[expect]` the same way `#[allow]` is with the `dead_code` lint

This PR makes the `#[expect]` attribute being respected in the same way the `#[allow]` attribute is with the `dead_code` lint.

The fix is much more involved than I would have liked (and it's not because I didn't tried!), because the implementation took advantage of the fact that firing a lint in a allow context is a nop (for the user, as the lint is suppressed) to not fire-it at all.

And will it's fine for `#[allow]`, it definitively isn't for `#[expect]`, as the presence and absence of the lint is significant. So a big part of the PR is just adding the context information of whenever an item is on the worklist because of an `[allow]`/`#[expect]` or not.

Fixes https://github.com/rust-lang/rust/issues/114557
2023-08-12 15:14:42 +00:00
Urgau
b517dd5bc9 Also consider transmute with the invalid_reference_casting lint 2023-08-12 13:05:44 +02:00
Urgau
d801a2ff15 Respect #[expect] the same way #[allow] is with the dead_code lint 2023-08-10 22:57:48 +02:00
Chinedu Francis Nwafili
b56a04975c
Fix multiple expect attribs in impl block
Closes #114416
2023-08-08 08:34:09 -04:00
bors
84ec2633de Auto merge of #113902 - Enselic:lint-recursive-drop, r=oli-obk
Make `unconditional_recursion` warning detect recursive drops

Closes #55388

Also closes #50049 unless we want to keep it for the second example which this PR does not solve, but I think it is better to track that work in #57965.

r? `@oli-obk` since you are the mentor for #55388

Unresolved questions:
- [x] There are two false positives that must be fixed before merging (see diff). I suspect the best way to solve them is to perform analysis after drop elaboration instead of before, as now, but I have not explored that any further yet. Could that be an option? **Answer:** Yes, that solved the problem.

`@rustbot` label +T-compiler +C-enhancement +A-lint
2023-08-07 13:39:28 +00:00
est31
4b1bc27010 Improve diagnostics and add tests for function calls 2023-08-06 19:08:14 +02:00
Matthias Krüger
1305a43d0a
Rollup merge of #114486 - Urgau:const-context-nan-suggestion-114471, r=compiler-errors
Avoid invalid NaN lint machine-applicable suggestion in const context

This PR removes the machine-applicable suggestion in const context for the `invalid_nan_comparision` lint ~~and replace it with a simple help~~.

Fixes https://github.com/rust-lang/rust/issues/114471
2023-08-06 03:56:09 +02:00