Commit Graph

80 Commits

Author SHA1 Message Date
Urgau
915200fbe0 Lint on reference casting to bigger underlying allocation 2024-02-12 19:40:17 +01:00
HTGAzureX1212.
da1d0c4a69
tidy 2024-01-23 21:17:06 +08:00
HTGAzureX1212.
3a07333a8a
address requested changes 2024-01-23 21:16:24 +08:00
HTGAzureX1212.
f3682a1304
add list of characters to uncommon codepoints lint 2024-01-23 10:56:33 +08:00
Matthias Krüger
a54c295665
Rollup merge of #118639 - fmease:deny-features-in-stable-rustc-crates, r=WaffleLapkin
Undeprecate lint `unstable_features` and make use of it in the compiler

See also #117937.

r? compiler
2024-01-22 16:54:56 +01:00
Nilstrieb
a04ac4952c Improve let_underscore_lock
- lint if the lock was in a nested pattern
- lint if the lock is inside a `Result<Lock, _>`
2024-01-12 23:18:58 +01:00
yukang
ca421fe1d3 check rust lints when an unknown lint is detected 2024-01-12 18:50:36 +08:00
León Orell Valerian Liehr
c0a9f722c4
Undeprecate and use lint unstable_features 2023-12-20 18:16:28 +01:00
Urgau
5630540ac0 Add warn-by-default lint against ambiguous wide pointer comparisons 2023-12-06 09:03:48 +01:00
Michael Goulet
15fbcc3636 Rework supertrait lint once again 2023-11-22 21:51:39 +00:00
bors
6d2b84b3ed Auto merge of #118133 - Urgau:stabilize_trait_upcasting, r=WaffleLapkin
Stabilize RFC3324 dyn upcasting coercion

This PR stabilize the `trait_upcasting` feature, aka https://github.com/rust-lang/rfcs/pull/3324.

The FCP was completed here: https://github.com/rust-lang/rust/issues/65991#issuecomment-1817552398.

~~And also remove the `deref_into_dyn_supertrait` lint which is now handled by dyn upcasting coercion.~~

Heavily inspired by https://github.com/rust-lang/rust/pull/101718
Fixes https://github.com/rust-lang/rust/issues/65991
2023-11-22 16:15:34 +00:00
bors
73bc12199e Auto merge of #112380 - jieyouxu:useless-bindings-lint, r=WaffleLapkin
Add allow-by-default lint for unit bindings

### Example

```rust
#![warn(unit_bindings)]

macro_rules! owo {
    () => {
        let whats_this = ();
    }
}

fn main() {
    // No warning if user explicitly wrote `()` on either side.
    let expr = ();
    let () = expr;
    let _ = ();

    let _ = expr; //~ WARN binding has unit type
    let pat = expr; //~ WARN binding has unit type
    let _pat = expr; //~ WARN binding has unit type

    // No warning for let bindings with unit type in macro expansions.
    owo!();

    // No warning if user explicitly annotates the unit type on the binding.
    let pat: () = expr;
}
```

outputs

```
warning: binding has unit type `()`
  --> $DIR/unit-bindings.rs:17:5
   |
LL |     let _ = expr;
   |     ^^^^-^^^^^^^^
   |         |
   |         this pattern is inferred to be the unit type `()`
   |
note: the lint level is defined here
  --> $DIR/unit-bindings.rs:3:9
   |
LL | #![warn(unit_bindings)]
   |         ^^^^^^^^^^^^^

warning: binding has unit type `()`
  --> $DIR/unit-bindings.rs:18:5
   |
LL |     let pat = expr;
   |     ^^^^---^^^^^^^^
   |         |
   |         this pattern is inferred to be the unit type `()`

warning: binding has unit type `()`
  --> $DIR/unit-bindings.rs:19:5
   |
LL |     let _pat = expr;
   |     ^^^^----^^^^^^^^
   |         |
   |         this pattern is inferred to be the unit type `()`

warning: 3 warnings emitted
```

This lint is not triggered if any of the following conditions are met:

- The user explicitly annotates the binding with the `()` type.
- The binding is from a macro expansion.
- The user explicitly wrote `let () = init;`
- The user explicitly wrote `let pat = ();`. This is allowed for local lifetimes.

### Known Issue

It is known that this lint can trigger on some proc-macro generated code whose span returns false for `Span::from_expansion` because e.g. the proc-macro simply forwards user code spans, and otherwise don't have distinguishing syntax context compared to non-macro-generated code. For those kind of proc-macros, I believe the correct way to fix them is to instead emit identifers with span like `Span::mixed_site().located_at(user_span)`.

Closes #71432.
2023-11-22 14:03:16 +00:00
Urgau
4c2d6de70e Stabilize RFC3324 dyn upcasting coercion
Aka trait_upcasting feature.

And also adjust the `deref_into_dyn_supertrait` lint.
2023-11-22 13:56:36 +01:00
许杰友 Jieyou Xu (Joe)
8da09aed94
Add allow-by-default lint for unit bindings
This lint is not triggered if any of the following conditions are met:

- The user explicitly annotates the binding with the `()` type.
- The binding is from a macro expansion.
- The user explicitly wrote `let () = init;`
- The user explicitly wrote `let pat = ();`. This is allowed for local
  lifetimes.
2023-11-20 11:45:44 +08:00
Urgau
f5023e4c76 Remove --check-cfg checking of --cfg args 2023-11-18 12:21:58 +01:00
Oli Scherer
e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Arthur Lafrance
5895102c4d debug Span::ctxt() call detection 2023-10-16 19:50:29 -07:00
Arthur Lafrance
f77dea89e1 basic lint v2 implemented 2023-10-16 19:47:33 -07:00
Michael Goulet
362b75badf Fix AFIT lint message to mention pitfall 2023-10-13 19:13:18 +00:00
Matthias Krüger
7d7004d3e6
Rollup merge of #116421 - Urgau:inter-mut-invalid_ref_casting, r=oli-obk
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-06 06:23:48 +02:00
Urgau
e46236cceb Clarify invalid_reference_casting lint around interior mutable types 2023-10-04 22:06:16 +02:00
Michael Goulet
c373d206cd Address review nits 2023-10-03 00:51:13 +00:00
Travis Cross
afea0b4eab Fill in prose to describe the async_fn_in_trait lint
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-03 00:37:18 +00:00
Michael Goulet
ec79720c1e Add async_fn_in_trait lint 2023-10-03 00:37:18 +00: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
Weihang Lo
a11805ae46
feat(rustc_lint): make CheckLintName respect lint level 2023-08-30 19:24:44 +01:00
Weihang Lo
81a24922e7
lint: translate RenamedOrRemovedLint 2023-08-24 01:09:46 +01: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
est31
4b1bc27010 Improve diagnostics and add tests for function calls 2023-08-06 19:08:14 +02:00
Matthias Krüger
cd5317a000
Rollup merge of #114472 - estebank:issue-76140, r=compiler-errors
Reword `confusable_idents` lint

Fix #76140.
2023-08-04 21:31:59 +02:00
Esteban Küber
553508c22e Reword confusable idents lint
Fix #76140.
2023-08-04 16:46:08 +00:00
bors
ec5b882c2f Auto merge of #114414 - cjgillot:early-unnameable-test, r=petrochenkov
Make test harness lint about unnnameable tests.

Implementation of https://github.com/rust-lang/rust/pull/113734#discussion_r1283073418

About the options suggested in https://github.com/rust-lang/rust/issues/36629#issuecomment-404753945: adding this case to unused_attribute was just more complicated. I'll try to understand a bit more what you had in mind in https://github.com/rust-lang/rfcs/pull/2471#issuecomment-397241123

This was just simpler to do in a standalone PR. I'll remove the corresponding changes from https://github.com/rust-lang/rust/pull/113734 later.

r? `@petrochenkov`
2023-08-04 14:13:11 +00:00
bors
1fe384649a Auto merge of #108955 - Nilstrieb:dont-use-me-pls, r=oli-obk
Add `internal_features` lint

Implements https://github.com/rust-lang/compiler-team/issues/596

Also requires some more test blessing for codegen tests etc

`@jyn514` had the idea of just `allow`ing the lint by default in the test suite. I'm not sure whether this is a good idea, but it's definitely one worth considering. Additional input encouraged.
2023-08-03 22:58:02 +00:00
Matthias Krüger
7518ae566e
Rollup merge of #113657 - Urgau:expand-incorrect_fn_null_check-lint, r=cjgillot
Expand, rename and improve `incorrect_fn_null_checks` lint

This PR,

 - firstly, expand the lint by now linting on references
 - secondly, it renames the lint `incorrect_fn_null_checks` -> `useless_ptr_null_checks`
 - and thirdly it improves the lint by catching `ptr::from_mut`, `ptr::from_ref`, as well as `<*mut _>::cast` and `<*const _>::cast_mut`

Fixes https://github.com/rust-lang/rust/issues/113601
cc ```@est31```
2023-08-03 17:29:06 +02:00
Camille GILLOT
2a0a1f918d Make test harness lint about unnnameable tests. 2023-08-03 13:07:30 +00:00
Nilstrieb
5830ca216d Add internal_features lint
It lints against features that are inteded to be internal to the
compiler and standard library. Implements MCP #596.

We allow `internal_features` in the standard library and compiler as those
use many features and this _is_ the standard library from the "internal to the compiler and
standard library" after all.

Marking some features as internal wasn't exactly the most scientific approach, I just marked some
mostly obvious features. While there is a categorization in the macro,
it's not very well upheld (should probably be fixed in another PR).

We always pass `-Ainternal_features` in the testsuite
About 400 UI tests and several other tests use internal features.
Instead of throwing the attribute on each one, just always allow them.
There's nothing wrong with testing internal features^^
2023-08-03 14:50:50 +02:00
Urgau
ee519532f6 Also add label with original type for function pointers 2023-08-03 10:57:11 +02:00
Urgau
d2b7c8028f Rename incorrect_fn_null_checks to useless_ptr_null_checks 2023-08-01 19:35:31 +02:00
Urgau
743ae5a2eb Expand incorrect_fn_null_check lint with reference null checking 2023-08-01 19:35:31 +02:00
Urgau
20a6b57106 Improve diagnostics of the invalid_reference_casting lint 2023-07-29 12:20:59 +02:00
Urgau
f3dafe91ff Add support for deferred casting for the invalid_reference_casting lint 2023-07-29 12:20:59 +02:00
bors
04411507be Auto merge of #113422 - Urgau:cast_ref_to_mut-pre-beta, r=Nilstrieb
Rename and allow `cast_ref_to_mut` lint

This PR is a small subset of https://github.com/rust-lang/rust/pull/112431, that is the renaming of the lint (`cast_ref_to_mut` -> `invalid_reference_casting`).

BUT also temporarily change the default level of the lint from deny-by-default to allow-by-default until https://github.com/rust-lang/rust/pull/112431 is merged.

r? `@Nilstrieb`
2023-07-29 07:48:44 +00:00
bors
4734ac0943 Auto merge of #111916 - fee1-dead-contrib:noop-method-call-warn, r=compiler-errors
make `noop_method_call` warn by default

r? `@compiler-errors`
2023-07-29 01:40:50 +00:00
Deadbeef
2a76c570d6 add suggestion 2023-07-23 09:58:31 +00:00
Deadbeef
626efab67f fix 2023-07-23 09:58:31 +00:00
David Wood
99b1897cf6
lint: refactor check_variant_for_ffi
Simplify this function a bit, it was quite hard to reason about.

Signed-off-by: David Wood <david@davidtw.co>
2023-07-19 09:55:10 +01:00
Urgau
3dbbf23e29 Rename cast_ref_to_mut lint to invalid_reference_casting 2023-07-13 23:01:24 +02:00
Urgau
f6d2bf63d3 Uplift clippy::fn_null_check to rustc 2023-07-10 18:12:41 +02:00
Guillaume Gomez
db7d8374c1
Rollup merge of #112517 - fee1-dead-contrib:sus-op-no-borrow, r=compiler-errors
`suspicious_double_ref_op`: don't lint on `.borrow()`

closes #112489
2023-06-15 22:04:55 +02:00
Deadbeef
1caed51673 do not use stringly typed diagnostics 2023-06-13 13:53:56 +00:00