Commit graph

86 commits

Author SHA1 Message Date
Esteban Küber
c95210f013 Do not suggest manual impl Copy 2026-02-01 18:30:08 +00:00
Esteban Küber
dffec20dee Tweak help to unify formatting and wording 2026-02-01 18:20:31 +00:00
Esteban Küber
8543404e8d Tweak span in E0599 2026-02-01 18:20:31 +00:00
Esteban Küber
879633f97b Change note to help 2026-02-01 18:20:31 +00:00
Esteban Küber
6c8eee8297 reword span label 2026-02-01 18:20:31 +00:00
Esteban Küber
20000ca25a Point at destructor when denying deriving Copy 2026-02-01 18:20:30 +00:00
Esteban Küber
dd8148373f Tweak span labels 2026-02-01 18:20:30 +00:00
Esteban Küber
aebf1fdcf9 Keep span of type in builtin derive macros expansions 2026-02-01 18:20:30 +00:00
Esteban Küber
b88fb8a0b0 Mention that the trait could be manually impld in E0599 2026-02-01 18:20:30 +00:00
Esteban Küber
54fe73fd6d Tweak span labels caused by trait bound coming from derive expansion
```
note: required for `B<C>` to implement `Copy`
  --> $DIR/deriving-copyclone.rs:9:10
   |
LL | #[derive(Copy, Clone)]
   |          ^^^^ unsatisfied trait bound introduced in this `derive` macro
LL | struct B<T> {
   |          - would need to be `Copy`
```
2026-02-01 18:20:30 +00:00
Esteban Küber
679f38c125 On E0277 pointing at bound in derive, suggest manual impl
When encountering a bound coming from a derive macro, suggest manual impl of the trait.

Use the span for the specific param when adding bounds in builtin derive macros, so the diagnostic will point at them as well as the derive macro itself.

```
error[E0277]: can't compare `SomeNode` with `SomeNode`
  --> f29.rs:24:15
   |
24 |     accept_eq(&node);
   |     --------- ^^^^^ no implementation for `SomeNode == SomeNode`
   |     |
   |     required by a bound introduced by this call
   |
   = note: -Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs:279:39
   = help: the trait `PartialEq` is not implemented for `SomeNode`
note: required for `Id<SomeNode>` to implement `PartialEq`
  --> f29.rs:3:10
   |
 3 | #[derive(PartialEq, Eq)]
   |          ^^^^^^^^^ unsatisfied trait bound introduced in this `derive` macro
 4 | pub struct Id<T>(PhantomData<T>);
   |               -
   = help: consider manually implementing `PartialEq` to avoid undesired bounds
note: required by a bound in `accept_eq`
  --> f29.rs:15:23
   |
15 | fn accept_eq(_: &impl PartialEq) { }
   |                       ^^^^^^^^^ required by this bound in `accept_eq`
help: consider annotating `SomeNode` with `#[derive(PartialEq)]`
   |
13 + #[derive(PartialEq)]
14 | struct SomeNode();
   |
```
2026-02-01 18:20:30 +00:00
Esteban Küber
4a27be6972 Do not mention -Zmacro-backtrace for std macros that are a wrapper around a compiler intrinsic 2026-01-26 17:34:31 +00:00
Zalathar
2df2c72d7a Ignore #[doc(hidden)] items when computing trimmed paths 2026-01-19 12:27:27 +11:00
reddevilmidzy
77b2a196fb cleaned up some tests
merge privacy/privacy-sanity-2 with privacy/privacy-sanity.rs

Add comment to generics/type-args-on-module-in-bound.rs

Add comment to array-slice-vec/closure-in-array-eln.rs

Add comment to array-slice-vec/return-in-array-len.rs

Merge for-loop-while/break-outside-loop-2.rs with
for-loop-while/break-outside-loop.rs

Add comment to macros/column-macro-collision.rs

Add comment to privacy/private-extern-fn-visibility.rs

Add comment to mismatched_types/vec-hashset-type-mismatch.rs

Merge std-sync-right-kind-impls-2.rs with std-sync-right-kind-impls.rs

Add comment to array-slice-vec/slice-of-multi-ref.rs

Add comment to mismatched_types\vec-hashset-type-mismatch.rs

Add comment to derives/derive-hygiene-struct-builder.rs

Add comment to label/undeclared-label-span.rs

Add comment to label\undeclared-label-span.rs

Add comment to mismatched_types/array-repeat-unit-struct.rs
2026-01-16 06:50:34 +09:00
reddevilmidzy
559e672489 move some tests 2026-01-16 06:50:21 +09:00
Jakub Beránek
5bcdc7c131
Rollup merge of #150384 - reddevilmidzy:t14, r=Kivooeo
Tidying up tests/ui/issues 16 tests [7/N]

> [!NOTE]
> Intermediate commits are intended to help review, but will be squashed add comment commit prior to merge.

part of rust-lang/rust#133895

r? Kivooeo
2026-01-05 15:54:13 +01:00
reddevilmidzy
93f8ad9950 cleaned up some tests
cleaned up cast-enum-const.rs

cleaned up ufcs-trait-object-format.rs

add comment to cast-to-box-arr.rs

add comment to shadow-primitives.rs

add comment to associated-type-const-nomalization.rs

add comment to fn-trait-explicit-call.rs

add comment to call-unit-struct-impl-fn-once.rs

add comment to cast-to-char-compare.rs

add comment to self-in-method-body-resolves.rs

add comment to derive-debug-newtype-unsized-slice.rs

add comment to tuple-ref-order-distinct-impls.rs

add comment to derive-debug-generic-with-lifetime.rs

add comment to recursive-trait-bound-on-type-param.rs

cleaned up const-static-ref-to-closure.rs

add comment to const-iter-no-conflict-for-loop.rs
2026-01-05 15:35:01 +09:00
reddevilmidzy
5c5c1ff6db moved some test
delete tests/ui/issues/issue-22426.rs duplicated of tests/ui/match/guards.rs
2026-01-05 10:04:46 +09:00
Tobias Bieniek
86cef2ff98
compiler/middle/lint: Suggest #[expect(dead_code)] as alternative to #[allow(dead_code)] 2025-12-26 08:38:20 +01:00
Esteban Küber
6cd44a472c Make typo in field and name suggestions verbose 2025-12-09 17:29:23 +00:00
Scott Schafer
93d16c5100
fix: Add col separator before secondary messages with no source 2025-08-26 15:15:17 -06:00
Stuart Cook
62b406d4b1
Rollup merge of #144403 - Kivooeo:issue4, r=jieyouxu
`tests/ui/issues/`: The Issues Strike Back [4/N]

Some `tests/ui/issues/` housekeeping, to trim down number of tests directly under `tests/ui/issues/`. Part of https://github.com/rust-lang/rust/issues/133895.

r? ````````@jieyouxu````````
2025-08-10 19:45:48 +10:00
Kivooeo
16765639b3 comments 2025-08-09 16:27:20 +05:00
Kivooeo
90bb5cacb5 moved 34 tests to organized locations 2025-07-25 15:34:28 +05:00
Oneirical
a924d44115 Rehome tests/ui/issues/ tests [1/?] 2025-07-24 17:01:44 -04:00
dianqk
0952f86de3
Rollup merge of #143118 - Kivooeo:tf15, r=tgross35
`tests/ui`: A New Order [15/N]

> [!NOTE]
>
> Intermediate commits are intended to help review, but will be squashed prior to merge.

Some `tests/ui/` housekeeping, to trim down number of tests directly under `tests/ui/`. Part of rust-lang/rust#133895.

r? `@jieyouxu`
2025-06-30 19:23:17 +08:00
Kivooeo
580bc12844 cleaned up some tests 2025-06-30 11:16:18 +05:00
Trevor Gross
74657a4a1a Move some UI tests to more apropriate directories
Prepare for rework done in the rest of [PR143118].

[PR143118]: https://www.github.com/rust-lang/rust/pull/143118

Co-authored-by: Kivooeo <Kivooeo123@gmail.com>
2025-06-28 19:07:29 -05:00
Jana Dönszelmann
131a2e47fb
Rollup merge of #142200 - Kivooeo:tf8, r=jieyouxu
`tests/ui`: A New Order [8/N]

Some `tests/ui/` housekeeping, to trim down number of tests directly under `tests/ui/`. Part of rust-lang/rust#133895.
2025-06-25 22:14:54 +02:00
Guillaume Gomez
0377330be4
Rollup merge of #142704 - tgross35:remove-concat_idents, r=fee1-dead
Remove the deprecated unstable `concat_idents!` macro

In [rust-lang/rust#137653], the lang and libs-API teams did a joint FCP to deprecate
and eventually remove the long-unstable `concat_idents!` macro. The
deprecation is landing in 1.88, so do the removal here (target version
1.90).

This macro has been superseded by the more recent `${concat(...)}`
metavariable expression language feature, which avoids some of the
limitations of `concat_idents!`. The metavar expression is unstably
available under the [`macro_metavar_expr_concat`] feature.

History is mildly interesting here: `concat_idents!` goes back to 2011
when it was introduced with 513276e595 ("Add #concat_idents[] and
#ident_to_str[]"). The syntax looks a bit different but it still works
about the same:

    let asdf_fdsa = "<.<";
    assert(#concat_idents[asd,f_f,dsa] == "<.<");

    assert(#ident_to_str[use_mention_distinction]
           == "use_mention_distinction");

(That test existed from introduction until its removal here.)

Closes: https://github.com/rust-lang/rust/issues/29599

[rust-lang/rust#137653]: https://github.com/rust-lang/rust/pull/137653
[`macro_metavar_expr_concat`]: https://github.com/rust-lang/rust/issues/124225
2025-06-24 15:39:38 +02:00
Trevor Gross
c978c8986f Move some issues-* tests to better homes
These tests were updated in the previous commit; while they are being
cleaned up, move them to a non-issue directory.
2025-06-24 10:55:47 +00:00
Kivooeo
793607059b cleaned up some tests 2025-06-23 18:53:56 +05:00
mejrs
b1d18129d1 Implement DesugaringKind::FormatLiteral 2025-06-22 10:58:25 +02:00
Mu001999
52167e04e6 Marks ADT live if it appears in pattern 2025-06-14 13:44:43 +08:00
Kivooeo
09940635d5 cleaned up some tests 2025-06-11 17:49:03 +05:00
Mu001999
f83ecd8270 Refactor the two-phase check for impls and impl items 2025-05-27 22:03:21 +08:00
Jana Dönszelmann
3cc172074a
collateral damage in derive tests, improves errors by not refering to implementation details 2025-05-02 18:09:31 +02:00
Esteban Küber
f0b8e13b59 Do not suggest using -Zmacro-backtrace for builtin macros
For macros that are implemented on the compiler, we do *not* mention the `-Zmacro-backtrace` flag. This includes `derive`s and standard macros.
2025-03-14 19:50:03 +00:00
Ralf Jung
4df78a07e5 make rustc_encodable_decodable feature properly unstable 2025-01-14 16:16:38 +01:00
Eric Huss
f94142b366 Update tests to use new proc-macro header 2024-11-27 07:18:25 -08:00
Jubilee
972fef232e
Rollup merge of #131153 - VulnBandit:copy_impl_vuln, r=compiler-errors
Improve duplicate derive Copy/Clone diagnostics

Improve duplicate derive Copy/Clone diagnostics.
Closes #131083
2024-11-04 20:40:44 -08:00
dianne
d7d6238b23 use backticks instead of single quotes when reporting "use of unstable library feature"
This is consistent with all other diagnostics I could find containing
features and enables the use of `DiagSymbolList` for generalizing
diagnostics for unstable library features to multiple features.
2024-11-03 13:55:52 -08:00
Esteban Küber
5b54286640 Remove detail from label/note that is already available in other note
Remove the "which is required by `{root_obligation}`" post-script in
"the trait `X` is not implemented for `Y`" explanation in E0277. This
information is already conveyed in the notes explaining requirements,
making it redundant while making the text (particularly in labels)
harder to read.

```
error[E0277]: the trait bound `NotCopy: Copy` is not satisfied
  --> $DIR/wf-static-type.rs:10:13
   |
LL | static FOO: IsCopy<Option<NotCopy>> = IsCopy { t: None };
   |             ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopy`
   |
   = note: required for `Option<NotCopy>` to implement `Copy`
note: required by a bound in `IsCopy`
  --> $DIR/wf-static-type.rs:7:17
   |
LL | struct IsCopy<T:Copy> { t: T }
   |                 ^^^^ required by this bound in `IsCopy`
```
vs the prior

```
error[E0277]: the trait bound `NotCopy: Copy` is not satisfied
  --> $DIR/wf-static-type.rs:10:13
   |
LL | static FOO: IsCopy<Option<NotCopy>> = IsCopy { t: None };
   |             ^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopy`, which is required by `Option<NotCopy>: Copy`
   |
   = note: required for `Option<NotCopy>` to implement `Copy`
note: required by a bound in `IsCopy`
  --> $DIR/wf-static-type.rs:7:17
   |
LL | struct IsCopy<T:Copy> { t: T }
   |                 ^^^^ required by this bound in `IsCopy`
```
2024-10-29 16:26:57 +00:00
VulnBandit
e3029abfae Improve duplicate derive Copy/Clone diagnostics 2024-10-16 16:49:31 +02:00
Matthias Krüger
d10f2b32f0
Rollup merge of #127907 - RalfJung:byte_slice_in_packed_struct_with_derive, r=nnethercote
built-in derive: remove BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE hack and lint

Fixes https://github.com/rust-lang/rust/issues/107457 by turning the lint into a hard error. The lint has been shown in future breakage reports since Rust 1.69 (released in April 2023).

Let's see (via crater) if enough time has passed since https://github.com/rust-lang/rust/pull/104429, and https://github.com/unicode-org/icu4x/pull/2834 has propagated far enough to let us make this a hard error.

Cc ``@nnethercote`` ``@Manishearth``
2024-08-05 05:40:19 +02:00
Ralf Jung
bda31d14f4 built-in derive: remove BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE hack and lint 2024-07-27 18:18:41 +02:00
mu001999
adf0dff10c Not lint pub structs without pub constructors if containing fields of unit, never type, PhantomData and positional ZST 2024-07-26 21:56:35 +08:00
Matthias Krüger
13314df21b
Rollup merge of #125572 - mu001999-contrib:dead/enhance, r=pnkfelix
Detect pub structs never constructed and unused associated constants

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->

Lints never constructed public structs.

If we don't provide public methods to construct public structs with private fields, and don't construct them in the local crate. They would be never constructed. So that we can detect such public structs.

---
Update:

Also lints unused associated constants in traits.
2024-06-07 20:14:28 +02:00
r0cky
35130d7233 Detect pub structs never constructed and unused associated constants in traits 2024-06-05 23:20:09 +08:00
Esteban Küber
e7ad2da7f1 When deriveing, account for HRTB on BareFn fields
When given

```rust
trait SomeTrait {
    type SomeType<'a>;
}

struct Foo<T: SomeTrait> {
    x: for<'a> fn(T::SomeType<'a>)
}
```

expand to

```rust
impl<T: ::core::clone::Clone + SomeTrait> ::core::clone::Clone for Foo<T>
    where for<'a> T::SomeType<'a>: ::core::clone::Clone {
    #[inline]
    fn clone(&self) -> Foo<T> {
        Foo { x: ::core::clone::Clone::clone(&self.x) }
    }
}
```

instead of the previous invalid

```
impl<T: ::core::clone::Clone + SomeTrait> ::core::clone::Clone for Foo<T>
    where T::SomeType<'a>: ::core::clone::Clone {
    #[inline]
    fn clone(&self) -> Foo<T> {
        Foo { x: ::core::clone::Clone::clone(&self.x) }
    }
}
```

Fix #122622.
2024-06-04 20:46:03 +00:00