Commit Graph

537 Commits

Author SHA1 Message Date
Matthias Krüger
5cdf870502
Rollup merge of #121961 - surechen:add_test_20240304, r=petrochenkov
add test for #78894 #71450

fixes #78894
fixes #71450
2024-03-05 19:53:21 +01:00
Alex Macleod
6120de99f7 Fix linting paths with qself in unused_qualifications 2024-03-05 18:31:32 +00:00
surechen
523ab25418 add test for #71450 2024-03-05 10:45:09 +08:00
surechen
6e9f59f967 add test for #78894 2024-03-04 12:34:11 +08:00
Matthias Krüger
10234fc246
Rollup merge of #121749 - jieyouxu:issue-45127-fix, r=petrochenkov
Don't lint on executable crates with `non_snake_case` names

Revives #111130, cc `@GilShoshan94.`
Closes #45127.
2024-03-03 22:56:13 +01:00
Matthias Krüger
ed6d17523a
Rollup merge of #121528 - Alexendoo:unused_qualifications, r=petrochenkov
Consider middle segments of paths in `unused_qualifications`

Currently `unused_qualifications` looks at the last segment of a path to see if it can be trimmed, this PR extends the check to the middle segments also

```rust
// currently linted
use std::env::args();
std::env::args(); // Removes `std::env::`
```
```rust
// newly linted
use std::env;
std::env::args(); // Removes `std::`
```

Paths with generics in them are now linted as long as the part being trimmed is before any generic args, e.g. it will now suggest trimming `std::vec::` from `std::vec::Vec<usize>`

Paths with any segments that are from an expansion are no longer linted

Fixes #100979
Fixes #96698
2024-03-03 22:56:13 +01:00
Alex Macleod
4ea9f72c72 Consider middle segments of paths in unused_qualifications 2024-03-03 19:14:28 +00:00
许杰友 Jieyou Xu (Joe)
d0111cb57a
Only run lint tests on x86_64-unknown-linux-gnu
We're trying to test lint behavior, not per-target crate-type support.
2024-03-03 13:58:35 +00:00
许杰友 Jieyou Xu (Joe)
82ceec9d1d
Ignore cdylib test for i686-unknown-linux-musl 2024-03-03 13:05:15 +00:00
许杰友 Jieyou Xu (Joe)
6e355ae44c
Ignore wasm in dylib/proc-macro crate type tests 2024-03-02 11:49:36 +00:00
clubby789
367126d49a If suggestion would leave an empty line, delete it 2024-03-01 13:48:20 +00:00
Gil Shoshan
bf8756d2dd
Don't lint snake-case on executable crate name
Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
2024-02-28 16:55:00 +00:00
Matthias Krüger
218be2771d
Rollup merge of #121628 - gurry:121534-ice-asymm-binop, r=oli-obk
Do not const prop unions

Unions can produce values whose types don't match their underlying layout types which can lead to ICEs on eval.

Fixes #121534
2024-02-26 16:06:04 +01:00
Gurinder Singh
633c92cd6d Do not const pop unions
as they can made to produce values whose types don't
match their underlying layout types which can lead to
ICEs on eval
2024-02-26 15:22:22 +05:30
Guillaume Gomez
91d337dfa8
Rollup merge of #120840 - HTGAzureX1212:HTGAzureX1212/unicode-identifier-types, r=fmease,Manishearth
Split Diagnostics for Uncommon Codepoints: Add Individual Identifier Types

This pull request further modifies the `uncommon_codepoints` lint, adding the individual identifier types of `Technical`, `Not_NFKC`, `Exclusion` and `Limited_Use` to the diagnostic message.

Example rendered diagnostic:
```
error: identifier contains a Unicode codepoint that is not used in normalized strings: 'ij'
  --> $DIR/lint-uncommon-codepoints.rs:6:4
   |
LL | fn dijkstra() {}
   |    ^^^^^^^
   = note: this character is included in the Not_NFKC Unicode general security profile
```

Second step of #120228.
2024-02-26 10:27:41 +01:00
HTGAzureX1212.
8bccceb8fc separate messages for individual categories 2024-02-26 10:09:03 +08:00
bors
0250ef2571 Auto merge of #121461 - reitermarkus:generic-nonzero-tests, r=dtolnay
Use generic `NonZero` in tests.

Tracking issue: https://github.com/rust-lang/rust/issues/120257

r? `@dtolnay`
2024-02-26 01:16:16 +00:00
bors
b0d3e04ca9 Auto merge of #120393 - Urgau:rfc3373-non-local-defs, r=WaffleLapkin
Implement RFC 3373: Avoid non-local definitions in functions

This PR implements [RFC 3373: Avoid non-local definitions in functions](https://github.com/rust-lang/rust/issues/120363).
2024-02-25 19:11:06 +00:00
Gurinder Singh
fa7557181f Don't use unwrap() in ArrayIntoIter lint when typeck fails 2024-02-25 17:51:56 +05:30
Markus Reiter
b2fbb8a053
Use generic NonZero in tests. 2024-02-25 12:03:48 +01:00
Ralf Jung
f32095cd8d promotion: don't promote int::MIN / -1 2024-02-24 12:17:37 +01:00
Matthias Krüger
06e54f8d49
Rollup merge of #121510 - RalfJung:lint-overflowing-ops, r=oli-obk
lint-overflowing-ops: unify cases and remove redundancy

Follow-up to https://github.com/rust-lang/rust/pull/121432
r? `@oli-obk`
2024-02-23 17:02:06 +01:00
Ralf Jung
9a2d550050 lint-overflowing-ops: unify cases and remove redundancy 2024-02-23 15:29:33 +01:00
Matthias Krüger
86727df4ed
Rollup merge of #121471 - estebank:lint-clone, r=TaKO8Ki
When encountering `<&T as Clone>::clone(x)` because `T: Clone`, suggest `#[derive(Clone)]`

CC #40699.

```
warning: call to `.clone()` on a reference in this situation does nothing
  --> $DIR/noop-method-call.rs:23:71
   |
LL |     let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone();
   |                                                                       ^^^^^^^^
   |
   = note: the type `PlainType<u32>` does not implement `Clone`, so calling `clone` on `&PlainType<u32>` copies the reference, which does not do anything and can be removed
help: remove this redundant call
   |
LL -     let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref.clone();
LL +     let non_clone_type_ref_clone: &PlainType<u32> = non_clone_type_ref;
   |
help: if you meant to clone `PlainType<u32>`, implement `Clone` for it
   |
LL + #[derive(Clone)]
LL | struct PlainType<T>(T);
   |
```
2024-02-23 09:42:11 +01:00
Esteban Küber
6017de46f7 When encountering <&T as Clone>::clone(x) because T: Clone, suggest #[derive(Clone)]
CC #40699.
2024-02-22 18:01:20 +00:00
James Dietz
669f891845 remove exception 2024-02-22 10:04:20 -05:00
James Dietz
03f095f9f2 consolidate tests 2024-02-21 22:41:47 -05:00
Dylan DPC
e10b3b88b4
Rollup merge of #121338 - jieyouxu:ambiguous_wide_pointer_comparisons_suggestion, r=Nadrieril
Downgrade ambiguous_wide_pointer_comparisons suggestions to MaybeIncorrect

In certain cases like #121330, it is possible to have more than one suggestion from the `ambiguous_wide_pointer_comparisons` lint (which before this PR are `MachineApplicable`). When this gets passed to rustfix, rustfix makes *multiple* changes according to the suggestions which result in incorrect code.

This is a temporary workaround. The real long term solution to problems like these is to address <https://github.com/rust-lang/rust/issues/53934>.

This PR also includes a drive-by edit to the panic message emitted by compiletest because "ui" test suite now uses `//`@`` directives.

Fixes #121330.
2024-02-21 08:55:58 +00:00
Peter Jaszkowiak
4913ab8f77
Stabilize LazyCell and LazyLock (lazy_cell) 2024-02-20 20:55:13 -07:00
León Orell Valerian Liehr
c99b3f24c2
Rollup merge of #122382 - mu001999:dead_code/enhance, r=petrochenkov
Detect unused structs which implement private traits

Fixes #122361
2024-05-23 20:09:07 +02:00
Matthias Krüger
e713b2a00c
Rollup merge of #125416 - compiler-errors:param-env-missing-copy, r=lcnr
Use correct param-env in `MissingCopyImplementations`

We shouldn't assume the param-env is empty for this lint, since although we check the struct has no parameters, there still may be trivial where-clauses.

fixes #125394
2024-05-23 14:09:25 +02:00
Matthias Krüger
4af1c31fcf
Rollup merge of #125156 - zachs18:for_loops_over_fallibles_behind_refs, r=Nilstrieb
Expand `for_loops_over_fallibles` lint to lint on fallibles behind references.

Extends the scope of the (warn-by-default) lint `for_loops_over_fallibles` from just `for _ in x` where `x: Option<_>/Result<_, _>` to also cover `x: &(mut) Option<_>/Result<_>`

```rs
fn main() {
    // Current lints
    for _ in Some(42) {}
    for _ in Ok::<_, i32>(42) {}

    // New lints
    for _ in &Some(42) {}
    for _ in &mut Some(42) {}
    for _ in &Ok::<_, i32>(42) {}
    for _ in &mut Ok::<_, i32>(42) {}

    // Should not lint
    for _ in Some(42).into_iter() {}
    for _ in Some(42).iter() {}
    for _ in Some(42).iter_mut() {}
    for _ in Ok::<_, i32>(42).into_iter() {}
    for _ in Ok::<_, i32>(42).iter() {}
    for _ in Ok::<_, i32>(42).iter_mut() {}
}
```

<details><summary><code>cargo build</code> diff</summary>

```diff
diff --git a/old.out b/new.out
index 84215aa..ca195a7 100644
--- a/old.out
+++ b/new.out
`@@` -1,33 +1,93 `@@`
 warning: for loop over an `Option`. This is more readably written as an `if let` statement
  --> src/main.rs:3:14
   |
 3 |     for _ in Some(42) {}
   |              ^^^^^^^^
   |
   = note: `#[warn(for_loops_over_fallibles)]` on by default
 help: to check pattern in a loop use `while let`
   |
 3 |     while let Some(_) = Some(42) {}
   |     ~~~~~~~~~~~~~~~ ~~~
 help: consider using `if let` to clear intent
   |
 3 |     if let Some(_) = Some(42) {}
   |     ~~~~~~~~~~~~ ~~~

 warning: for loop over a `Result`. This is more readably written as an `if let` statement
  --> src/main.rs:4:14
   |
 4 |     for _ in Ok::<_, i32>(42) {}
   |              ^^^^^^^^^^^^^^^^
   |
 help: to check pattern in a loop use `while let`
   |
 4 |     while let Ok(_) = Ok::<_, i32>(42) {}
   |     ~~~~~~~~~~~~~ ~~~
 help: consider using `if let` to clear intent
   |
 4 |     if let Ok(_) = Ok::<_, i32>(42) {}
   |     ~~~~~~~~~~ ~~~

-warning: `for-loops-over-fallibles` (bin "for-loops-over-fallibles") generated 2 warnings
-    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s
+warning: for loop over a `&Option`. This is more readably written as an `if let` statement
+ --> src/main.rs:7:14
+  |
+7 |     for _ in &Some(42) {}
+  |              ^^^^^^^^^
+  |
+help: to check pattern in a loop use `while let`
+  |
+7 |     while let Some(_) = &Some(42) {}
+  |     ~~~~~~~~~~~~~~~ ~~~
+help: consider using `if let` to clear intent
+  |
+7 |     if let Some(_) = &Some(42) {}
+  |     ~~~~~~~~~~~~ ~~~
+
+warning: for loop over a `&mut Option`. This is more readably written as an `if let` statement
+ --> src/main.rs:8:14
+  |
+8 |     for _ in &mut Some(42) {}
+  |              ^^^^^^^^^^^^^
+  |
+help: to check pattern in a loop use `while let`
+  |
+8 |     while let Some(_) = &mut Some(42) {}
+  |     ~~~~~~~~~~~~~~~ ~~~
+help: consider using `if let` to clear intent
+  |
+8 |     if let Some(_) = &mut Some(42) {}
+  |     ~~~~~~~~~~~~ ~~~
+
+warning: for loop over a `&Result`. This is more readably written as an `if let` statement
+ --> src/main.rs:9:14
+  |
+9 |     for _ in &Ok::<_, i32>(42) {}
+  |              ^^^^^^^^^^^^^^^^^
+  |
+help: to check pattern in a loop use `while let`
+  |
+9 |     while let Ok(_) = &Ok::<_, i32>(42) {}
+  |     ~~~~~~~~~~~~~ ~~~
+help: consider using `if let` to clear intent
+  |
+9 |     if let Ok(_) = &Ok::<_, i32>(42) {}
+  |     ~~~~~~~~~~ ~~~
+
+warning: for loop over a `&mut Result`. This is more readably written as an `if let` statement
+  --> src/main.rs:10:14
+   |
+10 |     for _ in &mut Ok::<_, i32>(42) {}
+   |              ^^^^^^^^^^^^^^^^^^^^^
+   |
+help: to check pattern in a loop use `while let`
+   |
+10 |     while let Ok(_) = &mut Ok::<_, i32>(42) {}
+   |     ~~~~~~~~~~~~~ ~~~
+help: consider using `if let` to clear intent
+   |
+10 |     if let Ok(_) = &mut Ok::<_, i32>(42) {}
+   |     ~~~~~~~~~~ ~~~
+
+warning: `for-loops-over-fallibles` (bin "for-loops-over-fallibles") generated 6 warnings
+    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s

```

</details>

-----

Question:

* ~~Currently, the article `an` is used for `&Option`, and `&mut Option` in the lint diagnostic, since that's what `Option` uses. Is this okay or should it be changed? (likewise, `a` is used for `&Result` and `&mut Result`)~~ The article `a` is used for `&Option`, `&mut Option`, `&Result`, `&mut Result` and (as before) `Result`. Only `Option` uses `an` (as before).

`@rustbot` label +A-lint
2024-05-23 07:41:17 +02:00
r0cky
96968350e1 Detect unused structs which implement private traits 2024-05-23 09:07:59 +08:00
Michael Goulet
8369dbba43 Use correct param-env in MissingCopyImplementations 2024-05-22 12:46:08 -04:00
bors
791adf759c Auto merge of #124417 - Xiretza:translate-early-lints, r=fmease
Make early lints translatable

<del>Requires https://github.com/projectfluent/fluent-rs/pull/353.</del> 5134a04eaa

r? diagnostics
2024-05-21 21:36:09 +00:00
Xiretza
8004e6a379 Make early lints translatable 2024-05-21 20:16:39 +00:00
Jubilee Young
d89500843c Move 100 entries from tests/ui into subdirs
- Move super-fast-paren-parsing test into ui/parser
- Move stmt_expr_attrs test into ui/feature-gates
- Move macro tests into ui/macros
- Move global_asm tests into ui/asm
- Move env tests into ui/process
- Move xcrate tests into ui/cross-crate
- Move unop tests into ui/unop
- Move backtrace tests into ui/backtrace
- Move check-static tests into ui/statics
- Move expr tests into ui/expr
- Move optimization fuel tests into ui/fuel
- Move ffi attribute tests into ui/ffi-attrs
- Move suggestion tests into ui/suggestions
- Move main tests into ui/fn-main
- Move lint tests into ui/lint
- Move repr tests into ui/repr
- Move intrinsics tests into ui/intrinsics
- Move tool lint tests into ui/tool-attributes
- Move return tests into ui/return
- Move pattern tests into ui/patttern
- Move range tests into ui/range
- Move foreign-fn tests into ui/foreign
- Move orphan-check tests into ui/coherence
- Move inference tests into ui/inference
- Reduce ROOT_ENTRY_LIMIT
2024-05-20 19:55:59 -07:00
Ben Kimock
18b0a07d49 Handle a few more simple tests 2024-05-20 11:13:10 -04:00
bors
36c0a6d40f Auto merge of #125105 - nnethercote:rustc_resolve-cleanups, r=estebank
`rustc_resolve` cleanups

Some improvements I found while looking through this code.

r? `@estebank`
2024-05-18 06:36:44 +00:00
Matthias Krüger
e62688eb96
Rollup merge of #123694 - Xiretza:expand-diagnostics, r=compiler-errors
expand: fix minor diagnostics bug

The error mentions `///`, when it's actually `//!`:

```
error[E0658]: attributes on expressions are experimental
 --> test.rs:4:9
  |
4 |         //! wah
  |         ^^^^^^^
  |
  = note: see issue https://github.com/rust-lang/rust/issues/15701 <https://github.com/rust-lang/rust/issues/15701> for more information
  = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
  = help: `///` is for documentation comments. For a plain comment, use `//`.
```
2024-05-17 07:20:56 +02:00
Zachary S
6b818ddac6 Fix article in test 2024-05-15 13:17:11 -05:00
Zachary S
ea549fd176 Add tests for 'Also apply warn(for_loops_over_fallibles) to &T and &mut T, not just T = Result/Option.' 2024-05-15 11:53:40 -05:00
David Tolnay
0ca322c774
Add test of unused_parens lint involving macro calls 2024-05-11 15:49:03 -07:00
Ben Kimock
2bb25d3f4a Handle Deref expressions in invalid_reference_casting 2024-05-10 12:33:07 -04:00
Nicholas Nethercote
5134a04eaa Remove ordinalize.
Some minor (English only) heroics are performed to print error messages
like "5th rule of macro `m` is never used". The form "rule #5 of macro
`m` is never used" is just as good and much simpler to implement.
2024-05-10 16:42:09 +10:00
Ben Kimock
0ca1a94b2b Handle field projections like slice indexing in invalid_reference_casting 2024-05-08 17:21:06 -04:00
Matthias Krüger
9fce3dc685
Rollup merge of #124761 - Urgau:ref-casting_bigger_slice_index, r=jieyouxu
Fix insufficient logic when searching for the underlying allocation

This PR fixes the logic inside the `invalid_reference_casting` lint, when trying to lint on bigger memory layout casts.

More specifically when looking for the "underlying allocation" we were wrongly assuming that when we got `&mut slice[index]` that `slice[index]` was the allocation, but it's not.

Fixes https://github.com/rust-lang/rust/issues/124685
2024-05-08 17:03:09 +02:00
bors
80420a693f Auto merge of #124747 - MasterAwesome:master, r=davidtwco
Support Result<T, E> across FFI when niche optimization can be used (v2)

This PR is identical to #122253, which was approved and merged but then removed from master by a force-push due to a [CI bug](https://rust-lang.zulipchat.com/#narrow/stream/242791-t-infra/topic/ci.20broken.3F).

r? ghost

Original PR description:

---

Allow allow enums like `Result<T, E>` to be used across FFI if the T/E can be niche optimized and the non-niche-optimized type is FFI safe.

Implementation of https://github.com/rust-lang/rfcs/pull/3391
Tracking issue: https://github.com/rust-lang/rust/issues/110503

Additional ABI and codegen tests were added in https://github.com/rust-lang/rust/pull/115372
2024-05-06 00:55:49 +00:00
Urgau
cd6a0c8c77 Fix insufficient logic when searching for the underlying allocation
in the `invalid_reference_casting` lint, when trying to lint on
bigger memory layout casts.
2024-05-05 19:14:20 +02:00
bors
378a43a065 Auto merge of #124539 - Urgau:non-local-defs_modulo_modules, r=lcnr
Consider inner modules to be local in the `non_local_definitions` lint

This PR implements the [proposed fix](https://github.com/rust-lang/rust/issues/124396#issuecomment-2079553642) for #124396, that is to consider inner modules to be local in the `non_local_definitions` lint.

This PR is voluntarily kept as minimal as possible so it can be backported easily.

T-lang [nomination](https://github.com/rust-lang/rust/issues/124396#issuecomment-2079692820) will need to be removed before this can be merged.

Fixes *(nearly, needs backport)* https://github.com/rust-lang/rust/issues/124396
2024-05-01 06:21:31 +00:00
Urgau
21c688af86 Consider inner modules to be local in the non_local_definitions lint 2024-04-29 22:54:04 +02:00
Arvind Mukund
ed532cc186 Put the RFC behind a feature gate result_ffi_guarantees 2024-04-23 21:30:59 -07:00
Arvind Mukund
b3f6511755 Add a test against Result<(), ()> 2024-04-23 21:27:45 -07:00
Arvind Mukund
014ddac9c9 Disallow single-variant enums
Couldn't find documentation supporting that single-variant
`#[repr(Rust)]` enums with RHS assigned work as expected with this
change.

```rust
enum Variants {
  A = 17,
} // Would this be zero sized optimized guaranteed?
```
2024-04-23 21:27:44 -07:00
Arvind Mukund
223d5eb64f Add tests
Tests both `T` and `E` for niche variant optimization lints
2024-04-23 21:26:04 -07:00
Xiretza
bfacfe2510 expand: fix minor diagnostics bug
The error mentions `///`, when it's actually `//!`:

error[E0658]: attributes on expressions are experimental
 --> test.rs:4:9
  |
4 |         //! wah
  |         ^^^^^^^
  |
  = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information
  = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable
  = help: `///` is for documentation comments. For a plain comment, use `//`.
2024-04-22 16:28:20 +00:00
许杰友 Jieyou Xu (Joe)
4d386d9f04
Downgrade ambiguous_wide_pointer_comparisons suggestions to MaybeIncorrect
It is possible to have more than one valid suggestion, which when
applied together via rustfix causes the code to no longer compile.

This is a temporary workaround; the real long term solution to these
issues is to solve <https://github.com/rust-lang/rust/issues/53934>.
2024-02-20 17:21:01 +00:00
Kalle Wachsmuth
dc7a01610f
trigger unsafe_code on global_asm! invocations 2024-02-20 00:14:53 +01:00
bors
2bf78d12d3 Auto merge of #119673 - petrochenkov:dialoc5, r=compiler-errors,cjgillot
macro_rules: Preserve all metavariable spans in a global side table

This PR preserves spans of `tt` metavariables used to pass tokens to declarative macros.
Such metavariable spans can then be used in span combination operations like `Span::to` to improve all kinds of diagnostics.

Spans of non-`tt` metavariables are currently kept in nonterminal tokens, but the long term plan is remove all nonterminal tokens from rustc parser and rely on the proc macro model with invisible delimiters (#114647, #67062).
In particular, `NtIdent` nonterminal (corresponding to `ident` metavariables) becomes easy to remove when this PR lands (#119412 does it).

The metavariable spans are kept in a global side table keyed by `Span`s of original tokens.
The alternative to the side table is keeping them in `SpanData` instead, but the performance regressions would be large because any spans from tokens passed to declarative macros would stop being inline and would work through span interner instead, and the penalty would be paid even if we never use the metavar span for the given original span.
(But also see the comment on `fn maybe_use_metavar_location` describing the map collision issues with the side table approach.)

There are also other alternatives - keeping the metavar span in `Token` or `TokenTree`, but associating it with `Span` itsel is the most natural choice because metavar spans are used in span combining operations, and those operations are not necessarily tied to tokens.
2024-02-18 20:51:16 +00:00
surechen
a61126cef6 By tracking import use types to check whether it is scope uses or the other situations like module-relative uses, we can do more accurate redundant import checking.
fixes #117448

For example unnecessary imports in std::prelude that can be eliminated:

```rust
use std::option::Option::Some;//~ WARNING the item `Some` is imported redundantly
use std::option::Option::None; //~ WARNING the item `None` is imported redundantly
```
2024-02-18 16:38:11 +08:00
Vadim Petrochenkov
9f8d05f29f macro_rules: Preserve all metavariable spans in a global side table 2024-02-18 11:19:24 +03:00
Urgau
63469ab762 Add cargo update suggestion for non local defs 2024-02-17 14:00:08 +01:00
Urgau
85e3a2ee04 Add const-anon suggestion for non local impl 2024-02-17 13:59:46 +01:00
Urgau
6170394313 Implement RFC3373 non local definitions lint 2024-02-17 13:59:45 +01:00
Gurinder Singh
5010ca001c Enable ConstPropLint for promoteds
This fixes the issue wherein the lint didn't fire for promoteds
in the case of SHL/SHR operators in non-optimized builds
and all arithmetic operators in optimized builds
2024-02-17 10:44:46 +05:30
许杰友 Jieyou Xu (Joe)
ec2cc761bc
[AUTO-GENERATED] Migrate ui tests from // to //@ directives 2024-02-16 20:02:50 +00:00
Urgau
ddec8c5edc Ignore unsized types when trying to determine the size of a type 2024-02-14 19:23:20 +01:00
Guillaume Gomez
18c935d000
Rollup merge of #121075 - chenyukang:yukang-fix-121070-lint-range, r=oli-obk
Fix false positive with if let and ranges

Fixes #121070
2024-02-14 15:41:28 +01:00
Guillaume Gomez
b36e094802
Rollup merge of #120893 - c410-f3r:testsssssss, r=petrochenkov
Move some tests

r? `@petrochenkov`
2024-02-14 15:41:26 +01:00
Oli Scherer
9e31121985
Rollup merge of #121049 - estebank:issue-121009, r=fmease
Do not point at `#[allow(_)]` as the reason for compat lint triggering

Fix #121009.
2024-02-14 11:53:42 +01:00
Oli Scherer
c4371a79de
Rollup merge of #120530 - trevyn:issue-116434, r=compiler-errors
Be less confident when `dyn` suggestion is not checked for object safety

#120275 no longer checks bare traits for object safety when making a `dyn` suggestion on Rust < 2021. In this case, qualify the suggestion with a note that the trait must be object safe, to prevent user confusion as seen in #116434

r? ```@fmease```
2024-02-14 11:53:39 +01:00
yukang
2fe73cea5e Fix false positive with if let and ranges 2024-02-14 15:15:22 +08:00
Caio
0e9aa75bcd Move tests 2024-02-13 18:08:25 -03:00
Esteban Küber
24b52fd9df Do not point at #[allow(_)] as the reason for compat lint triggering
Fix #121009.
2024-02-13 20:27:43 +00:00
Urgau
915200fbe0 Lint on reference casting to bigger underlying allocation 2024-02-12 19:40:17 +01:00
Matthias Krüger
fd287d2e88
Rollup merge of #120773 - Enselic:copy-vs-move, r=oli-obk
large_assignments: Allow moves into functions

Moves into functions are typically implemented with pointer passing
rather than memcpy's at the llvm-ir level, so allow moves into
functions.

Part of the "Differentiate between Operand::Move and Operand::Copy" step of https://github.com/rust-lang/rust/issues/83518.

r? `@oli-obk` (who I think is still E-mentor?)
2024-02-11 01:37:55 +01:00
Martin Nordholts
a4fbd01af2 tests/ui/lint/large_assignments: only-x86_64 -> only-64bit
So that devs on aarch64 can also bless tests.
2024-02-10 16:17:00 +01:00
Martin Nordholts
e2979a8b8c large_assignments: Allow moves into functions
Moves into functions are typically implemented with pointer passing
rather than memcpy's at the llvm-ir level, so allow moves into
functions.
2024-02-10 16:17:00 +01:00
trevyn
29fd82b24e Be less confident when dyn suggestion is not checked for object safety 2024-02-09 20:47:50 -08:00
Matthias Krüger
f41d0d90c2
Rollup merge of #113671 - oli-obk:normalize_weak_tys, r=petrochenkov
Make privacy visitor use types more (instead of HIR)

r? ``@petrochenkov``

This is a prerequisite to normalizing projections, as otherwise we have too many invalid bound vars (hir_ty_to_ty is creating types that have bound vars, but no binder).

The commits are still chaotic, I'm gonna clean them up, but I just wanted to let you know about the general direction and wondering if we could land this before adding normalization, as normalization is where behavioral changes happen, and I'd like to keep that part as minimal as possible.

[context can be found on zulip](https://rust-lang.zulipchat.com/#narrow/stream/315482-t-compiler.2Fetc.2Fopaque-types/topic/weak.20type.20aliases.20and.20privacy)
2024-02-09 14:41:48 +01:00
Martin Nordholts
1a0200ebc0 large_assignments: Add copy variant of Box, Rc, Arc check 2024-02-08 10:42:39 +01:00
Guillaume Boisseau
f5a36cbd73
Rollup merge of #120470 - estebank:issue-54196, r=compiler-errors
Mark "unused binding" suggestion as maybe incorrect

Ignoring unused bindings should be a determination made by a human, `rustfix` shouldn't auto-apply the suggested change.

Fix #54196.
2024-02-07 18:24:42 +01:00
Oli Scherer
4389a1cc42 Stop using hir_ty_to_ty in rustc_privacy 2024-02-07 14:59:26 +00:00
r0cky
c7519d42c2 Update tests 2024-02-07 10:42:01 +08:00
r0cky
40878ca6ea Make traits / trait methods detected by the dead code lint! 2024-02-07 10:22:16 +08:00
Esteban Küber
aef18c9bfb Mark "unused binding" suggestion as maybe incorrect
Ignoring unused bindings should be a determination made by a human, `rustfix` shouldn't auto-apply the suggested change.

Fix #54196.
2024-02-06 17:13:58 +00:00
Matthias Krüger
ed27148812
Rollup merge of #116284 - RalfJung:no-nan-match, r=cjgillot
make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern

These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error.

This is part of implementing https://github.com/rust-lang/rfcs/pull/3535.

Closes https://github.com/rust-lang/rust/issues/41620 by removing the lint.

https://github.com/rust-lang/reference/pull/1456 updates the reference to match.
2024-02-05 11:07:26 +01:00
Matthew Jasper
4feec41e05 #![feature(inline_const_pat)] is no longer incomplete 2024-02-01 10:27:54 +00:00
Markus Reiter
021739c840
Update tests. 2024-01-27 16:38:57 +01:00
Ralf Jung
1254ee48c4 remove illegal_floating_point_literal_pattern lint 2024-01-26 17:25:02 +01: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
72dddeaeb7
Rollup merge of #119710 - Nilstrieb:let-_-=-oops, r=TaKO8Ki
Improve `let_underscore_lock`

- lint if the lock was in a nested pattern
- lint if the lock is inside a `Result<Lock, _>`

addresses https://github.com/rust-lang/rust/pull/119704#discussion_r1444044745
2024-01-22 07:56:41 +01:00
George Bateman
615946db4f
Stabilize simple offset_of 2024-01-19 20:38:51 +00:00
Jake Goulding
d95d6ceecb dead_code treats #[repr(transparent)] the same as #[repr(C)]
Fixes #119659
2024-01-18 13:04:31 -05:00
Martin Nordholts
8f440f06c6 large_assignments: Lint on specific large args passed to functions 2024-01-15 19:07:12 +01:00
George-lewis
d56cdd48cb Bless tests
Update tests
2024-01-13 12:46:58 -05: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
bors
3071aefdb2 Auto merge of #117321 - chenyukang:yukang-fix-117142, r=petrochenkov
Fix unused_parens issue when cast is followed LT

Fixes #117142

The original check only checks `a as (i32) < 0`, this fix extends it to handle `b + a as (i32) < 0`.

A better way is maybe we suggest `(a as i32) < 0` instead of suppressing the warning, maybe following PR could improve it.
2024-01-12 22:15:55 +00:00
Matthias Krüger
5efa69d979
Rollup merge of #119704 - chenyukang:yukang-fix-let_underscore, r=Nilstrieb
Fix two variable binding issues in lint let_underscore

Fixes #119696
Fixes #119697
2024-01-09 00:19:35 +01:00
yukang
75df38e816 Fix 2 variable binding issues in let_underscore 2024-01-08 16:50:14 +08:00
Matthias Krüger
1d6ab69ab1
Rollup merge of #119624 - petrochenkov:dialoc4, r=compiler-errors
rustc_span: More consistent span combination operations

Also add more tests for using `tt` in addition to `ident`, and some other minor tweaks, see individual commits.

This is a part of https://github.com/rust-lang/rust/pull/119412 that doesn't yet add side tables for metavariable spans.
2024-01-06 16:07:48 +01:00
Matthias Krüger
958417fba1
Rollup merge of #119554 - matthewjasper:remove-guard-distinction, r=compiler-errors
Fix scoping for let chains in match guards

If let guards were previously represented as a different type of guard in HIR and THIR. This meant that let chains in match guards were not handled correctly because they were treated exactly like normal guards.

- Remove `hir::Guard` and `thir::Guard`.
- Make the scoping different between normal guards and if let guards also check for let chains.

closes #118593
2024-01-05 20:39:52 +01:00
Vadim Petrochenkov
c586fe40f1 macro_rules: Add more tests for using tt in addition to ident
Generally, `tt` and `ident` should behave identically, modulo the latter accepting only a subset of token trees.
2024-01-05 19:13:52 +03:00
Michael Goulet
da700b39df
Rollup merge of #119601 - nnethercote:Emitter-cleanups, r=oli-obk
`Emitter` cleanups

Some improvements I found while looking at this code.

r? `@oli-obk`
2024-01-05 10:57:24 -05:00
Matthew Jasper
407cb24142 Remove hir::Guard
Use Expr instead. Use `ExprKind::Let` to represent if let guards.
2024-01-05 10:56:59 +00:00
bors
5113ed28ea Auto merge of #118297 - shepmaster:warn-dead-tuple-fields, r=WaffleLapkin
Merge `unused_tuple_struct_fields` into `dead_code`

This implicitly upgrades the lint from `allow` to `warn` and places it into the `unused` lint group.

[Discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Moving.20.60unused_tuple_struct_fields.60.20from.20allow.20to.20warn)
2024-01-05 04:51:55 +00:00
Nicholas Nethercote
f5a09a9e1d Unbreak tests/ui/lint/use_suggestion_json.rs.
PR #82639 changed UI tests so `-Z unstable-options` aren't passed to UI
tests by default. This completely broke `use_suggestion_json.rs`, which
uses the unstable `--error-format=pretty-json` option. The expected
output went from 400 lines of pretty JSON error messages to a single
JSON error saying "`--error-format=pretty-json` is unstable"!

This commit adds `-Z unstable-options` back and reinstates the old
expected output, with some minor changes to account for shifted spans
and slightly JSON output changes since then.
2024-01-05 14:24:06 +11:00
Matthias Krüger
9fa0c8e1c7
Rollup merge of #119184 - Rajveer100:branch-for-issue-118752, r=davidtwco
Switch from using `//~ERROR` annotations with `--error-format` to `error-pattern`

Fixes #118752

As noticed by ```@jyn514``` while working on a patch, tests failed due to `//~ERROR` annotations used in combination with the older `--error-format` which is now `error-pattern`.
2024-01-04 15:33:57 +01:00
Jake Goulding
53eca9fa87 Adjust compiler tests for unused_tuple_struct_fields -> dead_code 2024-01-02 15:34:37 -05:00
Matthias Krüger
bfc1643071
Rollup merge of #119410 - est31:fix_if_guard_unused, r=Nilstrieb
Rename test to be more descriptive

As suggested in https://github.com/rust-lang/rust/pull/119402#discussion_r1438171079

r? ``@Nilstrieb``
2023-12-29 21:40:24 +01:00
Matthias Krüger
c8d42740c5
Rollup merge of #119388 - Enselic:prevent-lint-triplication, r=cjgillot
rustc_lint: Prevent triplication of various lints

Prevent triplication of various lints. The triplication happens because we run the same lint three times (or less in some cases):
* In `BuiltinCombinedPreExpansionLintPass`
* In `BuiltinCombinedEarlyLintPass`
* In `shallow_lint_levels_on()`

Only run the lints one time by checking the `lint_added_lints` bool.

Set your GitHub diff setting to ignore whitespaces changes when reviewing this PR, since I had to enclose a block inside an if.

Closes #73301

(I found this while exploring the code related to [this](https://github.com/rust-lang/rust/pull/119251#discussion_r1435677330) comment.)
2023-12-29 21:40:23 +01:00
est31
740378cdde Rename test 2023-12-29 13:49:23 +01:00
est31
ab60a7df64 Also walk bindings created by if-let guards 2023-12-29 03:38:09 +01:00
Martin Nordholts
7ca4e9fcb2 rustc_lint: Prevent triplication of 'unknown lint' lint 2023-12-28 19:46:51 +01:00
Martin Nordholts
741884dab2 rustc_lint: Prevent multiple 'incompatible with previous forbid' lints 2023-12-28 19:46:40 +01:00
Martin Nordholts
e0c626fbbc rustc_lint: Prevent multiple 'lint ignored' lints
Prevent multiple 'ignored unless specified at crate level' lints. The
multiplication happens because we run the same lint three times:
* In BuiltinCombinedEarlyLintPass
* In BuiltinCombinedPreExpansionLintPass
* In shallow_lint_levels_on

Only run the lint one time by checking the `lint_added_lints` bool.
2023-12-28 19:46:40 +01:00
Michael Goulet
65aaece6c0
Rollup merge of #119297 - cjgillot:issue-119267, r=petrochenkov
Pass DeadItem and lint as consistent group in dead-code.

Fixes https://github.com/rust-lang/rust/issues/119267
2023-12-26 13:29:13 -05:00
bors
f8fe517144 Auto merge of #116274 - RalfJung:soft_unstable, r=cjgillot
make soft_unstable show up in future breakage reports

If we want to break these in the future, let's warn users of affected crates.
2023-12-25 16:26:15 +00:00
Camille GILLOT
8bb74c0187 Pass DeadItem and lint as consistent group in dead-code. 2023-12-25 13:15:28 +00:00
Rajveer
af44e719fa Switch from using //~ERROR annotations with --error-format to error-pattern
Resolves Issue #118752
2023-12-21 16:45:29 +05:30
Maybe Waffle
b863e9ba57
Stabilize ptr::{from_ref, from_mut} 2023-12-15 08:34:59 -08:00
Urgau
4839cca9aa Recurse into let bindings if possible in ref casting lint 2023-12-14 17:27:14 +01:00
bors
8a3765582c Auto merge of #117758 - Urgau:lint_pointer_trait_comparisons, r=davidtwco
Add lint against ambiguous wide pointer comparisons

This PR is the resolution of https://github.com/rust-lang/rust/issues/106447 decided in https://github.com/rust-lang/rust/issues/117717 by T-lang.

## `ambiguous_wide_pointer_comparisons`

*warn-by-default*

The `ambiguous_wide_pointer_comparisons` lint checks comparison of `*const/*mut ?Sized` as the operands.

### Example

```rust
let ab = (A, B);
let a = &ab.0 as *const dyn T;
let b = &ab.1 as *const dyn T;

let _ = a == b;
```

### Explanation

The comparison includes metadata which may not be expected.

-------

This PR also drops `clippy::vtable_address_comparisons` which is superseded by this one.

~~One thing: is the current naming right? `invalid` seems a bit too much.~~

Fixes https://github.com/rust-lang/rust/issues/117717
2023-12-11 14:33:16 +00:00
Matthias Krüger
1b391d4ae4
Rollup merge of #118504 - compiler-errors:must-use, r=WaffleLapkin
Enforce `must_use` on associated types and RPITITs that have a must-use trait in bounds

Warn when an RPITIT or (un-normalized) associated type with a `#[must_use]` trait in its bounds is unused.

This is pending T-lang approval, since it changes the semantics of the `#[must_use]` attribute slightly, but I think it strictly catches more strange errors.

I could also limit this to just RPITITs, but that seems less useful.

Fixes #118444
2023-12-06 21:52:32 +01:00
Urgau
5630540ac0 Add warn-by-default lint against ambiguous wide pointer comparisons 2023-12-06 09:03:48 +01:00
Michael Goulet
19bf749560
Rollup merge of #118123 - RalfJung:internal-lib-features, r=compiler-errors
Add support for making lib features internal

We have the notion of an "internal" lang feature: a feature that is never intended to be stabilized, and using which can cause ICEs and other issues without that being considered a bug.

This extends that idea to lib features as well. It is an alternative to https://github.com/rust-lang/rust/pull/115623: instead of using an attribute to declare lib features internal, we simply do this based on the name. Everything ending in `_internals` or `_internal` is considered internal.

Then we rename `core_intrinsics` to `core_intrinsics_internal`, which fixes https://github.com/rust-lang/rust/issues/115597.
2023-12-05 14:52:41 -05:00
Michael Goulet
d1009a42d8 Enforce must_use on associated types and RPITITs 2023-11-30 02:24:52 +00:00
Esteban Küber
0ff331bc78 Change how for (x in foo) {} is handled
Use the same approach used for match arm patterns.
2023-11-29 18:47:32 +00:00
Esteban Küber
1994abed74 Bubble parse error when expecting ) 2023-11-29 18:47:31 +00:00
yukang
eef4e653f2 Fix unused_parens when cast is followed LT 2023-11-28 22:54:45 +08:00
Nilstrieb
41e8d152dc Show number in error message even for one error
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-24 19:15:52 +01:00
Ralf Jung
d1583eba66 lib features ending in '_internals?' are internal 2023-11-21 08:00:26 +01:00
bors
85c42b751e Auto merge of #115691 - jsgf:typed-json-diags, r=est31,dtolnay
Add `$message_type` field to distinguish json diagnostic outputs

Currently the json-formatted outputs have no way to unambiguously determine which kind of message is being output. A consumer can look for specific fields in the json object (eg "message"), but there's no guarantee that in future some other kind of output will have a field of the same name.

This PR adds a `"type"` field to add json outputs which can be used to unambiguously determine which kind of output it is. The mapping is:

`diagnostic`: regular compiler diagnostics
`artifact`: artifact notifications
`future_incompat`: Future incompatibility report
`unused_extern`: Unused crate warnings/errors

This matches the "internally tagged" representation for serde enums.
2023-11-21 06:30:14 +00:00
Max Niederman
c5ed7b0ead
add test for pinned must_use pointers 2023-11-18 21:01:02 -08:00
Guillaume Gomez
9e4ab9f111
Rollup merge of #117395 - gurry:117380-wrong-parent-sugg, r=Nilstrieb
Fix missing leading space in suggestion

For a local pattern with no space between `let` and `(` e.g.:
```rust
  let(_a) = 3;
```
we were previously suggesting this illegal code:
```rust
  let_a = 3;
```
After this change the suggestion will instead be:
```rust
  let _a = 3;
```
Fixes #117380
2023-10-30 17:33:19 +01:00
yukang
82f34fdd23 Fix #117284, Fix unused variables lint issue for args in macro 2023-10-30 21:35:18 +08:00
Gurinder Singh
a2486dba3b Fix missing leading space in suggestion
For a local pattern with no space between `let` and `(` e.g.:

  let(_a) = 3;

we were previously suggesting this illegal code:

  let_a =3;

After this change the suggestion will instead be:

  let _a =3;

(Note the space after `let`)
2023-10-30 19:04:55 +05:30
bohan
482275b194 use visibility to check unused imports and delete some stmts 2023-10-22 21:27:46 +08:00
Oli Scherer
e96ce20b34 s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
Oli Scherer
60956837cf s/Generator/Coroutine/ 2023-10-20 21:10:38 +00:00
Ali MJ Al-Nasrawy
0653d7eebf
Rollup merge of #116812 - rmehri01:missing_copy_implementations_non_exhaustive, r=petrochenkov
Disable missing_copy_implementations lint on non_exhaustive types

Fixes #116766
2023-10-18 14:24:50 +03:00
Esteban Küber
890e92feed Unify suggestion wording 2023-10-17 17:33:55 +00:00
Ryan Mehri
a8e7e79101 disable missing_copy_implementations lint on non_exhaustive types
use is_variant_list_non_exhaustive/is_field_list_non_exhaustive

remove unused tcx

inline non_exhaustive def/variant check
2023-10-17 08:33:37 -07:00
Jeremy Fitzhardinge
8f0845862c Use $message_type as the tag
`type` turned out to be controversial.
2023-10-13 15:50:01 -07:00
bors
71704c4f84 Auto merge of #116623 - Nadrieril:validate-range-endpoints, r=oli-obk
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-11 10:07:19 +00:00
Nadrieril
dcdddb7a60 Fix span of overflow lint for negated literals 2023-10-11 04:55:55 +02:00
bors
48e24629e9 Auto merge of #115583 - RalfJung:packed-unsized, r=lcnr
fix detecting references to packed unsized fields

Fixes https://github.com/rust-lang/rust/issues/115396

This is a breaking change, but permitted as a soundness fix.
2023-10-07 10:57: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
Matthias Krüger
c1c5ab717e
Rollup merge of #116428 - Alexendoo:note-duplicate-diagnostics, r=compiler-errors,estebank
Add a note to duplicate diagnostics

Helps explain why there may be a difference between manual testing and the test suite output and highlights them as something to potentially look into

For existing duplicate diagnostics I just blessed them other than a few files that had other `NOTE` annotations in
2023-10-05 19:24:35 +02:00
Alex Macleod
5453a9f34d Add a note to duplicate diagnostics 2023-10-05 01:04:41 +00:00
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
Urgau
e46236cceb Clarify invalid_reference_casting lint around interior mutable types 2023-10-04 22:06:16 +02:00
Chinedu Francis Nwafili
67379c4006
Address misc feedback 2023-10-02 08:59:31 -04:00
Ralf Jung
b9acee2d29 make soft_unstable show up in future breakage reports 2023-09-29 21:56:57 +02: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
Jeremy Fitzhardinge
da3df9c201 Add test for future-incompat diagnostics with json output 2023-09-19 14:17:02 -07:00
Jeremy Fitzhardinge
5c8170656b Add type field to json diagnostic outputs
Currently the json-formatted outputs have no way to unambiguously
determine which kind of message is being output. A consumer can look for
specific fields in the json object (eg "message"), but there's no
guarantee that in future some other kind of output will have a field of
the same name.

This PR adds a `"type"` field to add json outputs which can be used to
unambiguously determine which kind of output it is. The mapping is:

diagnostic: regular compiler diagnostics
artifact: artifact notifications
future_incompat: Report of future incompatibility
unused_extern: Unused crate warnings/errors

This matches the "internally tagged" representation for serde enums.
2023-09-19 14:17:02 -07: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
Ralf Jung
ad7045e160 still accept references to u8 slices and str in packed fields 2023-09-06 08:32:30 +02:00
Ralf Jung
8b3435c10f fix detecting references to packed unsized fields 2023-09-05 22:29:51 +02: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