149 Commits

Author SHA1 Message Date
Michael Goulet
c2b9a8afa9 Make sure to treat only param where clauses as inherent 2025-08-24 20:30:52 +00:00
Jacob Pratt
418bbb283f
Rollup merge of #145765 - lqd:revert-142034, r=fmease
Revert suggestions for missing methods in tuples

As requested by `@estebank` and as discussed with `@jackh726,` this reverts rust-lang/rust#142034 because of diagnostics ICEs like rust-lang/rust#142488 and its duplicates that have reached stable by now.

We will work on a proper fix to reland this cool work in the near future, but in the meantime, a revert is safer to validate and backport to beta and stable, so here it is.
2025-08-22 22:01:03 -04:00
Rémy Rakic
5a2b70b202 add regression test for issue 142488
there are a lot of MCVEs there, so this is only a few of them, not all
duplicates that were opened
2025-08-22 20:42:25 +00:00
Rémy Rakic
1f587e4d4f Revert "Detect method not being present that is present in other tuple types"
This reverts commit 585a40963ea59808e74803f8610659a505b145e0.
2025-08-22 20:26:52 +00:00
Esteban Küber
049c32797b On E0277, point at type that doesn't implement bound
When encountering an unmet trait bound, point at local type that doesn't implement the trait:

```
error[E0277]: the trait bound `Bar<T>: Foo` is not satisfied
  --> $DIR/issue-64855.rs:9:19
   |
LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ;
   |                   ^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
   |
help: the trait `Foo` is not implemented for `Bar<T>`
  --> $DIR/issue-64855.rs:9:1
   |
LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ;
   | ^^^^^^^^^^^^^^^^^
```
2025-08-22 17:55:15 +00:00
Karol Zwolak
d14b83e378 bless tests with new lint messages 2025-08-19 21:27:10 +02:00
Oneirical
75e0263af9 Rehome tests/ui/issues/ tests [5/?] 2025-08-17 13:01:02 -04:00
Esteban Küber
99196657fc Use tcx.short_string() in more diagnostics
`TyCtxt::short_string` ensures that user visible type paths aren't overwhelming on the terminal output, and properly saves the long name to disk as a side-channel. We already use these throughout the compiler and have been using them as needed when users find cases where the output is verbose. This is a proactive search of some cases to use `short_string`.

We add support for shortening the path of "trait path only".

Every manual use of `short_string` is a bright marker that that error should be using structured diagnostics instead (as they have proper handling of long types without the maintainer having to think abou tthem).

When we don't actually print out a shortened type we don't need the "use `--verbose`" note.

On E0599 show type identity to avoid expanding the receiver's generic parameters.

Unify wording on `long_ty_path` everywhere.
2025-08-07 21:18:00 +00:00
Stuart Cook
bcd50fd45f
Rollup merge of #137831 - estebank:auto-trait-err, r=compiler-errors
Tweak auto trait errors

Make suggestions to remove params and super traits verbose and make spans more accurate.

```
error[E0567]: auto traits cannot have generic parameters
  --> $DIR/auto-trait-validation.rs:6:19
   |
LL | auto trait Generic<T> {}
   |            -------^^^
   |            |
   |            auto trait cannot have generic parameters

error[E0568]: auto traits cannot have super traits or lifetime bounds
  --> $DIR/auto-trait-validation.rs:8:20
   |
LL | auto trait Bound : Copy {}
   |            -----   ^^^^
   |            |
   |            auto traits cannot have super traits or lifetime bounds
```

```
error[E0380]: auto traits cannot have associated items
  --> $DIR/issue-23080.rs:5:8
   |
LL | unsafe auto trait Trait {
   |                   ----- auto traits cannot have associated items
LL |     fn method(&self) {
   |        ^^^^^^
```
2025-08-07 20:49:36 +10:00
Oneirical
7196d8cd66 Rehome tests/ui/issues/ tests [3/?] 2025-08-04 16:43:53 -04:00
Esteban Küber
91e606b715 Tweak auto trait errors
Make suggestions to remove params and super traits tool-only, and make
the suggestion span more accurate.

```
error[E0567]: auto traits cannot have generic parameters
  --> $DIR/auto-trait-validation.rs:6:19
   |
LL | auto trait Generic<T> {}
   |            -------^^^
   |            |
   |            auto trait cannot have generic parameters

error[E0568]: auto traits cannot have super traits or lifetime bounds
  --> $DIR/auto-trait-validation.rs:8:20
   |
LL | auto trait Bound : Copy {}
   |            -----   ^^^^
   |            |
   |            auto traits cannot have super traits or lifetime bounds
```

```
error[E0380]: auto traits cannot have associated items
  --> $DIR/issue-23080.rs:5:8
   |
LL | unsafe auto trait Trait {
   |                   ----- auto traits cannot have associated items
LL |     fn method(&self) {
   |        ^^^^^^
```
2025-08-04 17:20:07 +00:00
Oneirical
a924d44115 Rehome tests/ui/issues/ tests [1/?] 2025-07-24 17:01:44 -04:00
codedump
f204801971 fix: fix issue 143740, Wrong messages from compiler confusing methods with the same name from different traits 2025-07-17 19:26:39 +08:00
Oli Scherer
28f023c751 Use predicate spans instead of whole item spans 2025-06-30 08:45:43 +00:00
Guillaume Gomez
05b209d3a2
Rollup merge of #142417 - Kivooeo:tf12, r=jieyouxu
`tests/ui`: A New Order [12/N]

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

r? `@jieyouxu`
2025-06-29 12:29:55 +02:00
Kivooeo
aac948b702 cleaned up some tests 2025-06-28 16:24:17 +05:00
Michael Goulet
250b5d204f Make missing lifetime suggestion verbose 2025-06-24 18:59:42 +00:00
mejrs
b1d18129d1 Implement DesugaringKind::FormatLiteral 2025-06-22 10:58:25 +02:00
Matthias Krüger
db23a76217
Rollup merge of #141811 - mejrs:bye_locals, r=compiler-errors
Unimplement unsized_locals

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

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

Note that this just removes the feature, not the implementation, and does not touch `unsized_fn_params`. This is because it is required to support `Box<dyn FnOnce()>: FnOnce()`.

There may be more that should be removed (possibly in follow up prs)
- the `forget_unsized` function and `forget` intrinsic.
- the `unsized_locals` test directory; I've just fixed up the tests for now
- various codegen support for unsized values and allocas

cc ``@JakobDegen`` ``@oli-obk`` ``@Noratrieb`` ``@programmerjake`` ``@bjorn3``

``@rustbot`` label F-unsized_locals

Fixes rust-lang/rust#79409
2025-06-14 11:27:10 +02:00
mejrs
c0e02e26b3 Unimplement unsized_locals 2025-06-13 01:16:36 +02:00
Matthias Krüger
c77191f46b
Rollup merge of #142034 - estebank:issue-141258, r=davidtwco
Detect method not being present that is present in other tuple types

When a method is not present because of a trait bound not being met, and that trait bound is on a tuple, we check if making the tuple have no borrowed types makes the method to be found and highlight it if it does. This is a common problem for Bevy in particular and ORMs in general.

<img width="1166" alt="Screenshot 2025-06-04 at 10 38 24 AM" src="https://github.com/user-attachments/assets/d257c9ea-c2d7-42e7-8473-8b93aa54b8e0" />

Address rust-lang/rust#141258. I believe that more combination of cases in the tuple types should be handled (like adding borrows and checking when a specific type needs to not be a borrow while the rest stay the same), but for now this handles the most common case.
2025-06-12 22:09:43 +02:00
Kivooeo
c6c55cc0cb cleaned up some tests 2025-06-11 20:51:49 +05:00
Esteban Küber
585a40963e Detect method not being present that is present in other tuple types
When a method is not present because of a trait bound not being met, and that trait bound is on a tuple, we check if making the tuple have no borrowed types makes the method to be found and highlight it if it does. This is a common problem for Bevy in particular and ORMs in general.
2025-06-04 18:18:06 +00:00
Kivooeo
afc64242b6 cleaned up some tests 2025-05-31 19:49:19 +05:00
Noratrieb
01503d0c1e Avoid extra path trimming in method not found error
Method errors have an extra check that force trim paths whenever the
normal string is longer than 10 characters, which can be quite unhelpful
when multiple items have the same name (for example an `Error`).

A user reported this force trimming as being quite unhelpful when they
had a method error where the precise path of the `Error` mattered.

The code uses `tcx.short_string` already to get the normal path, which
tries to be clever around trimming paths if necessary, so there is no
reason for this extra force trimming.
2025-05-24 23:31:07 +02:00
Michael Goulet
45598de704 Do not gather local all together at the beginning of typeck 2025-05-05 14:27:09 +00:00
bors
7188f45311 Auto merge of #140503 - matthiaskrgr:rollup-n7zigts, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #136160 (Remove backticks from `ShouldPanic::YesWithMessage`'s `TrFailedMsg`)
 - #139059 (uses_power_alignment: wording tweaks)
 - #139192 (mention provenance in the pointer::wrapping_offset docs)
 - #140312 (Improve pretty-printing of braces)
 - #140404 (rm `TypeVistable` impls for `Canonical`)
 - #140437 (enable msa feature for mips in codegen tests)
 - #140438 (Add `rust.debug-assertions-tools` option)
 - #140439 (miri: algebraic intrinsics: bring back float non-determinism)
 - #140445 (Treat ManuallyDrop as ~const Destruct)
 - #140446 (chore: fix some tests)
 - #140448 (Rename `rustc_query_append!` to `rustc_with_all_queries!`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-30 12:09:10 +00:00
Vadim Petrochenkov
20faf8532b compiletest: Make diagnostic kind mandatory on line annotations 2025-04-30 10:44:24 +03:00
mejrs
a4ce307c01 Coalesce duplicate missing clone tests 2025-04-29 12:46:26 +02:00
reddevilmidzy
db2a73e284 Cleaned up 5 tests in tests/ui 2025-04-25 20:50:57 +09:00
Vadim Petrochenkov
b3f75353a2 UI tests: add missing diagnostic kinds where possible 2025-04-08 23:06:31 +03:00
Oli Scherer
cb4751d4b8 Implement #[define_opaque] attribute for functions. 2025-03-11 12:05:02 +00:00
Michael Goulet
aab7b145d0
Rollup merge of #137565 - compiler-errors:macro-ex, r=estebank
Try to point of macro expansion from resolver and method errors if it involves macro var

In the case that a macro caller passes an identifier into a macro generating a path or method expression, point out that identifier in the context of the *macro* so it's a bit more clear how the macro is involved in causing the error.

r? ``````````@estebank`````````` or reassign
2025-03-06 12:22:13 -05:00
Michael Goulet
ab31129956 Point of macro expansion from call expr if it involves macro var 2025-03-03 23:53:42 +00:00
许杰友 Jieyou Xu (Joe)
83429144fc tests: remove explicit long type filename hash normalization from some ui tests 2025-03-04 00:21:02 +08:00
Michael Goulet
0a7ab1d6df More sophisticated span trimming 2025-02-21 00:41:17 +00:00
Michael Goulet
6d71251cf9 Trim suggestion parts to the subset that is purely additive 2025-02-14 00:44:10 -08:00
Michael Goulet
b480a9214a Use underline suggestions for purely 'additive' replacements 2025-02-14 00:27:13 -08:00
lcnr
83a02619d5 fallout :skull_emoji: 2025-02-14 00:37:23 +01:00
Michael Goulet
72b4df3772 Implement lint for definition site item shadowing too 2025-02-13 05:45:53 +00:00
Michael Goulet
2189908170 Add more tests 2025-02-13 05:45:53 +00:00
Michael Goulet
18a3cc5c2c Rework collapse method to work correctly with more complex supertrait graphs 2025-02-13 05:45:53 +00:00
Michael Goulet
f8c51d3002 Implement shadowing lint 2025-02-13 05:45:53 +00:00
Esteban Küber
f0845adb0c Show diff suggestion format on verbose replacement
```
error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields
  --> $DIR/attempted-access-non-fatal.rs:7:15
   |
LL |     let _ = 2.l;
   |               ^
   |
help: if intended to be a floating point literal, consider adding a `0` after the period and a `f64` suffix
   |
LL -     let _ = 2.l;
LL +     let _ = 2.0f64;
   |
```
2025-02-10 20:21:39 +00:00
Jason Newcomb
4718cb40ec When displaying a parameter mismatch error, only highlight the mismatched parameters when showing the definition. 2025-02-05 10:36:32 -05:00
Jason Newcomb
6378fbc366 Check for generic parameter mismatches on trait functions. 2025-02-03 12:54:53 -05:00
Michael Goulet
e4193e2de8 Do not ICE when encountering predicates from other items in method error reporting 2025-01-03 19:39:39 +00:00
Zalathar
835fbcbcab Remove the -test suffix from normalize directives 2024-12-27 19:58:16 +11:00
Adrian Taylor
e75660dad3 Arbitrary self types v2: use Receiver trait
In this new version of Arbitrary Self Types, we no longer use the Deref trait
exclusively when working out which self types are valid. Instead, we follow a
chain of Receiver traits. This enables methods to be called on smart pointer
types which fundamentally cannot support Deref (for instance because they are
wrappers for pointers that don't follow Rust's aliasing rules).

This includes:
* Changes to tests appropriately
* New tests for:
  * The basics of the feature
  * Ensuring lifetime elision works properly
  * Generic Receivers
  * A copy of the method subst test enhanced with Receiver

This is really the heart of the 'arbitrary self types v2' feature, and
is the most critical commit in the current PR.

Subsequent commits are focused on:
* Detecting "shadowing" problems, where a smart pointer type can hide
  methods in the pointee.
* Diagnostics and cleanup.

Naming: in this commit, the "Autoderef" type is modified so that it no
longer solely focuses on the "Deref" trait, but can now consider the
"Receiver" trait instead. Should it be renamed, to something like
"TraitFollower"? This was considered, but rejected, because
* even in the Receiver case, it still considers built-in derefs
* the name Autoderef is short and snappy.
2024-12-11 11:59:12 +00:00
Esteban Küber
d860e5b088 Mention type parameter in more cases and don't suggest ~const bound already there 2024-12-07 21:37:13 +00:00