Commit Graph

879 Commits

Author SHA1 Message Date
León Orell Valerian Liehr
879f62bb3c Reword diagnostic about relaxing non-Sized bound
* The phrasing "only does something for" made sense back when this
  diagnostic was a (hard) warning. Now however, it's simply a hard
  error and thus completely rules out "doing something".
* The primary message was way too long
* The new wording more closely mirrors the wording we use for applying
  other bound modifiers (like `const` and `async`) to incompatible
  traits.
* "all other traits are not bound by default" is no longer accurate
  under Sized Hierarchy. E.g., traits and assoc tys are (currently)
  bounded by `MetaSized` by default but can't be relaxed using
  `?MetaSized` (instead, you relax it by adding `PointeeSized`).
* I've decided against adding any diagnositic notes or suggestions
  for now like "trait `Trait` can't be relaxed as it's not bound by
  default" which would be incorrect for `MetaSized` and assoc tys
  as mentioned above) or "consider changing `?MetaSized` to
  `PointeeSized`" as the Sized Hierarchy impl is still WIP)
2025-07-18 12:13:30 +02:00
Michael Goulet
216cdb7b22 Eagerly unify coroutine witness in old solver 2025-07-17 17:42:28 +00: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
Matthias Krüger
51f16b011d Rollup merge of #143914 - shepmaster:mismatched-lifetime-syntaxes-rewording, r=traviscross,jieyouxu
Reword mismatched-lifetime-syntaxes text based on feedback

Key changes include:

- Removal of the word "syntax" from the lint message. More accurately, it could have been something like "syntax group" or "syntax category", but avoiding it completely is easier.
- The primary lint message now reflects exactly which mismatch is occurring, instead of trying to be general. A new `help` line is general across the mismatch kinds.
- Suggestions have been reduced to be more minimal, no longer also changing non-idiomatic but unrelated aspects.
- Suggestion text no longer mentions changes when those changes don't occur in that specific suggestion.

r? ``@jieyouxu``
2025-07-17 10:41:47 +02:00
dianne
41e6f767b6 future-incompat lints: don't link to the nightly edition-guide version 2025-07-16 01:44:02 -07:00
Jake Goulding
5530744318 Reword mismatched-lifetime-syntaxes text based on feedback
Key changes include:

- Removal of the word "syntax" from the lint message. More accurately,
  it could have been something like "syntax group" or "syntax
  category", but avoiding it completely is easier.
- The primary lint message now reflects exactly which mismatch is
  occurring, instead of trying to be general. A new `help` line is
  general across the mismatch kinds.
- Suggestions have been reduced to be more minimal, no longer also
  changing non-idiomatic but unrelated aspects.
- Suggestion text no longer mentions changes when those changes don't
  occur in that specific suggestion.
2025-07-14 09:52:58 -04:00
Deadbeef
6b02597ed3 update issue number for const_trait_impl 2025-07-13 23:55:06 +08:00
bohan
dc6c3300fc compute all rpitit of a trait 2025-07-13 02:52:13 +08:00
Matthias Krüger
140f2fa5ae Rollup merge of #143661 - Muscraft:other-suggestion-message, r=estebank
chore: Improve how the other suggestions message gets rendered

Note: This change is part of my ongoing work to use `annotate-snippets` as `rustc`'s emitter

This change started as a way to remove some specialty code paths from `annotate-snippets`, by making the "and {} other candidates" message get rendered like a secondary message with no level, but turned into a fix for the message's Unicode output. Before this change, when using the Unicode output, the other suggestions message would get rendered outside of the main suggestion block, making it feel disconnected from what it was referring to. This change makes it so that the message is on the last line of the block, aligning its rendering with other secondary messages, and making it clear what the message is referring to.

Before:
```
error[E0433]: failed to resolve: use of undeclared type `IntoIter`
   ╭▸ $DIR/issue-82956.rs:28:24
   │
LL │         let mut iter = IntoIter::new(self);
   │                        ━━━━━━━━ use of undeclared type `IntoIter`
   ╰╴
help: consider importing one of these structs
   ╭╴
LL + use std::array::IntoIter;
   ├╴
LL + use std::collections::binary_heap::IntoIter;
   ├╴
LL + use std::collections::btree_map::IntoIter;
   ├╴
LL + use std::collections::btree_set::IntoIter;
   ╰╴
     and 9 other candidates
```

After:
```
error[E0433]: failed to resolve: use of undeclared type `IntoIter`
   ╭▸ $DIR/issue-82956.rs:28:24
   │
LL │         let mut iter = IntoIter::new(self);
   │                        ━━━━━━━━ use of undeclared type `IntoIter`
   ╰╴
help: consider importing one of these structs
   ╭╴
LL + use std::array::IntoIter;
   ├╴
LL + use std::collections::binary_heap::IntoIter;
   ├╴
LL + use std::collections::btree_map::IntoIter;
   ├╴
LL + use std::collections::btree_set::IntoIter;
   │
   ╰ and 9 other candidates
```
2025-07-11 07:35:20 +02:00
Trevor Gross
58e5c2629d Rollup merge of #143742 - estebank:borrow-suggestion, r=compiler-errors
Rework borrowing suggestions to use `Expr` instead of just `Span`

In the suggestion machinery for borrowing expressions and types, always use the available obligation `Span` to find the appropriate `Expr` to perform appropriateness checks no the `ExprKind` instead of on the textual snippet corresponding to the `Span`. (We were already doing this, but only for a subset of cases.) This now better handles situations where parentheses and `<>` are needed for correct syntax (`&(foo + bar)`, `(&foo).bar()`, `<&Foo>::bar()`, etc.).

Unify the logic for the case where `&` *and* `&mut` are appropriate with the logic for only one of those cases. (Instead of having two branches for emitting the suggestion, we now have a single one, using `Diag::multipart_suggestions` always.)

Handle the case when `S::foo()` should have been `<&S>::foo()` (instead of suggesting the prior `&S::foo()`. Fix rust-lang/rust#143393.

Make `Diag::multipart_suggestions` always verbose. CC rust-lang/rust#141973.
2025-07-10 20:20:40 -04:00
Esteban Küber
0674eca2f0 Make Diag::multipart_suggestions always verbose 2025-07-10 17:23:29 +00:00
Scott Schafer
d67bf6095a chore: Improve how the other suggestions message gets rendered 2025-07-10 08:00:20 -06:00
Oli Scherer
543c860ea6 Constify Fn* traits 2025-07-08 14:36:43 +00:00
Matthias Krüger
a4e05e1f74 Rollup merge of #143570 - bvanjoi:issue-143560, r=compiler-errors
consider nested cases for duplicate RPITIT

Fixes rust-lang/rust#143560

r? `@compiler-errors`

cc `@Zoxc`
2025-07-08 03:09:57 +02:00
bohan
e1720d7396 consider nested cases for duplicate RPITIT 2025-07-07 17:09:39 +08:00
xizheyin
796b4d1fb4 Point to correct argument in Func Call when Self type fails trait bound
When a trait bound fails due to the Self type parameter, adjust_fulfillment_errors
now correctly points to the corresponding function argument instead of incorrectly
pointing to other arguments.

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-07 16:47:15 +08:00
bohan
5bbab8967d distinguish the duplicate item of rpitit 2025-07-06 14:04:40 +08:00
bors
71e4c005ca Auto merge of #143287 - GuillaumeGomez:rollup-fdjcti9, r=GuillaumeGomez
Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#136801 (Implement `Random` for tuple)
 - rust-lang/rust#141867 (Describe Future invariants more precisely)
 - rust-lang/rust#142760 (docs(fs): Touch up grammar on lock api)
 - rust-lang/rust#143181 (Improve testing and error messages for malformed attributes)
 - rust-lang/rust#143210 (`tests/ui`: A New Order [19/N] )
 - rust-lang/rust#143212 (`tests/ui`: A New Order [20/N])
 - rust-lang/rust#143230 ([COMPILETEST-UNTANGLE 2/N] Make some compiletest errors/warnings/help more visually obvious)
 - rust-lang/rust#143240 (Port `#[rustc_object_lifetime_default]` to the new attribute parsing …)
 - rust-lang/rust#143255 (Do not enable LLD by default in the dist profile)
 - rust-lang/rust#143262 (mir: Mark `Statement` and `BasicBlockData` as `#[non_exhaustive]`)
 - rust-lang/rust#143269 (bootstrap: make comment more clear)
 - rust-lang/rust#143279 (Remove `ItemKind::descr` method)

Failed merges:

 - rust-lang/rust#143237 (Port `#[no_implicit_prelude]` to the new attribute parsing infrastructure)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-01 18:09:52 +00:00
Oli Scherer
9b5d57d0a9 Unconditionally run check_item_type on all items 2025-06-30 08:06:08 +00:00
Kivooeo
bf5910d9bb cleaned up some tests 2025-06-30 11:50:19 +05:00
Kivooeo
4b6c3d923f moved & deleted some tests 2025-06-29 22:47:01 +05:00
León Orell Valerian Liehr
f77fead002 Fix the span of trait bound modifier [const] 2025-06-29 04:56:28 +02:00
Matthias Krüger
36c2b011cb Rollup merge of #139858 - oli-obk:new-const-traits-syntax, r=fee1-dead
New const traits syntax

This PR only affects the AST and doesn't actually change anything semantically.

All occurrences of `~const` outside of libcore have been replaced by `[const]`. Within libcore we have to wait for rustfmt to be bumped in the bootstrap compiler. This will happen "automatically" (when rustfmt is run) during the bootstrap bump, as rustfmt converts `~const` into `[const]`. After this we can remove the `~const` support from the parser

Caveat discovered during impl: there is no legacy bare trait object recovery for `[const] Trait` as that snippet in type position goes down the slice /array parsing code and will error

r? ``@fee1-dead``

cc ``@nikomatsakis`` ``@traviscross`` ``@compiler-errors``
2025-06-27 22:13:00 +02:00
Oli Scherer
c51f05be30 Report infer ty errors during hir ty lowering
This centralizes the placeholder type error reporting in one location, but it also exposes the granularity at which we convert things from hir to ty more. E.g. previously infer types in where bounds were errored together with the function signature, but now they are independent.
2025-06-27 07:51:38 +00:00
bors
513999b936 Auto merge of #143057 - matthiaskrgr:rollup-bulih8o, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#124595 (Suggest cloning `Arc` moved into closure)
 - rust-lang/rust#139594 (Simplify `ObligationCauseCode::IfExpression`)
 - rust-lang/rust#141311 (make `tidy-alphabetical` use a natural sort)
 - rust-lang/rust#141648 ([rustdoc] Do not emit redundant_explicit_links lint if the doc comment comes from expansion)
 - rust-lang/rust#142285 (tests: Do not run afoul of asm.validity.non-exhaustive in input-stats)
 - rust-lang/rust#142393 (Don't  give APITs names with macro expansion placeholder fragments in it)
 - rust-lang/rust#142884 (StableMIR: Add method to retrieve body of coroutine)
 - rust-lang/rust#142981 (Make missing lifetime suggestion verbose)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-26 20:06:23 +00:00
Matthias Krüger
2f8b715f10 Rollup merge of #142981 - compiler-errors:verbose-missing-suggestion, r=estebank
Make missing lifetime suggestion verbose

I keep seeing this suggestion when working on rustc, and it's annoying that it's inline. Part of https://github.com/rust-lang/rust/issues/141973. Feel free to close this if there's another PR already doing this.

r? ``@estebank``
2025-06-26 15:47:22 +02:00
Oli Scherer
eb7245a864 Change const trait bound syntax from ~const to [const] 2025-06-26 13:46:45 +00:00
Esteban Küber
8c3a033d7f Add edition checks for some tests that had divergent output
In order to expose edition dependent divergences in some tests in the test suite, add explicit `edition` annotations. Some of these tests might require additional work to *avoid* the divergences, as they might have been unintentional. These are not exhaustive changes, purely opportunistic while looking at something else.
2025-06-25 17:02:26 +00:00
Michael Goulet
8cd3fa04e2 Don't give APITs names with macro expansion placeholder fragments in it 2025-06-25 15:42:11 +00:00
Michael Goulet
250b5d204f Make missing lifetime suggestion verbose 2025-06-24 18:59:42 +00:00
Matthias Krüger
a73954c229 Rollup merge of #142883 - mominul:impl_in_bindings, r=lcnr
Add impl_trait_in_bindings tests from #61773

This adds the [three test cases](https://github.com/rust-lang/rust/issues/61773#issuecomment-2952638727) from the rust-lang/rust#61773 as was suggested by ``@lcnr.``

I have merged the first two cases into one, named as `region-lifetimes.rs`

r? ``@lcnr``

Closes rust-lang/rust#61773
2025-06-24 20:46:06 +02:00
Muhammad Mominul Huque
2973939f7a Add impl_trait_in_bindings tests 2025-06-24 19:55:42 +06:00
mejrs
b1d18129d1 Implement DesugaringKind::FormatLiteral 2025-06-22 10:58:25 +02:00
Trevor Gross
c93fac7d64 Rollup merge of #142485 - mu001999-contrib:dead-code/adt-pattern, r=petrochenkov
Marks ADT live if it appears in pattern

Marks ADT live if it appears in pattern, it implies the construction of the ADT.
1. Then we can detect unused private ADTs impl `Default`, without special logics for `Default` and other std traits.
2. We can also remove `rustc_trivial_field_reads` on `Default`, and the logic in `should_ignore_item` (introduced by rust-lang/rust#126302).

Fixes rust-lang/rust#120770

Extracted from rust-lang/rust#128637.
r? `@petrochenkov`
2025-06-20 23:25:55 -04:00
Mara Bos
a693c52173 Bless/update tests. 2025-06-18 10:20:43 +02:00
Mu001999
52167e04e6 Marks ADT live if it appears in pattern 2025-06-14 13:44:43 +08:00
bors
6c8138de8f Auto merge of #142127 - compiler-errors:nested-goals-certainty, r=lcnr
Apply nested goals certainty to `InspectGoals` for normalizes-to

...so that normalizes-to goals don't have `Certainty::Yes` even if they have nested goals which don't hold.

r? lcnr
2025-06-12 11:29:20 +00:00
bors
e703dff8fe Auto merge of #142358 - matthiaskrgr:rollup-fxe6m7k, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#141967 (Configure bootstrap backport nominations through triagebot)
 - rust-lang/rust#142042 (Make E0621 missing lifetime suggestion verbose)
 - rust-lang/rust#142272 (tests: Change ABIs in tests to more future-resilient ones)
 - rust-lang/rust#142282 (Only run `citool` tests on the `auto` branch)
 - rust-lang/rust#142297 (Implement `//@ needs-target-std` compiletest directive)
 - rust-lang/rust#142298 (Make loongarch-none target maintainers more easily pingable)
 - rust-lang/rust#142306 (Dont unwrap and re-wrap typing envs)
 - rust-lang/rust#142324 (Remove unneeded `FunctionCx` from some codegen methods)
 - rust-lang/rust#142328 (feat: Add `bit_width` for unsigned integer types)

Failed merges:

 - rust-lang/rust#141639 (Expose discriminant values in stable_mir)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-11 17:51:57 +00:00
bors
bdb04d6c4f Auto merge of #141763 - lcnr:fixme-gamer, r=BoxyUwU
`FIXME(-Znext-solver)` triage

r? `@BoxyUwU`
2025-06-11 11:47:05 +00:00
Esteban Küber
3fce086d79 Make E0621 missing lifetime suggestion verbose
```
error[E0621]: explicit lifetime required in the type of `x`
  --> $DIR/42701_one_named_and_one_anonymous.rs:10:9
   |
LL |         &*x
   |         ^^^ lifetime `'a` required
   |
help: add explicit lifetime `'a` to the type of `x`
   |
LL | fn foo2<'a>(a: &'a Foo, x: &'a i32) -> &'a i32 {
   |                             ++
```
2025-06-09 19:55:00 +00:00
Michael Goulet
cd1d84e304 Apply nested goals certainty to InspectGoals for normalizes-to 2025-06-09 17:02:09 +00:00
bors
ccf3198de3 Auto merge of #138677 - shepmaster:consistent-elided-lifetime-syntax, r=traviscross,jieyouxu
Add a new `mismatched-lifetime-syntaxes` lint

The lang-team [discussed this](https://hackmd.io/nf4ZUYd7Rp6rq-1svJZSaQ) and I attempted to [summarize](https://github.com/rust-lang/rust/pull/120808#issuecomment-2701863833) their decision. The summary-of-the-summary is:

- Using two different kinds of syntax for elided lifetimes is confusing. In rare cases, it may even [lead to unsound code](https://github.com/rust-lang/rust/issues/48686)! Some examples:

    ```rust
    // Lint will warn about these
    fn(v: ContainsLifetime) -> ContainsLifetime<'_>;
    fn(&'static u8) -> &u8;
    ```

- Matching up references with no lifetime syntax, references with anonymous lifetime syntax, and paths with anonymous lifetime syntax is an exception to the simplest possible rule:

    ```rust
    // Lint will not warn about these
    fn(&u8) -> &'_ u8;
    fn(&'_ u8) -> &u8;
    fn(&u8) -> ContainsLifetime<'_>;
    ```

- Having a lint for consistent syntax of elided lifetimes will make the [future goal](https://github.com/rust-lang/rust/issues/91639) of warning-by-default for paths participating in elision much simpler.

---

This new lint attempts to accomplish the goal of enforcing consistent syntax. In the process, it supersedes and replaces the existing `elided-named-lifetimes` lint, which means it starts out life as warn-by-default.
2025-06-05 19:49:30 +00:00
Jake Goulding
d35ad94849 Replace elided_named_lifetimes with mismatched_lifetime_syntaxes 2025-06-04 10:40:04 -04:00
Oli Scherer
82ed50c294 Run wfcheck in one big loop instead of per module 2025-06-03 15:16:51 +00:00
lcnr
7dac755be8 FIXME(-Znext-solver) triage
Co-authored-by: Michael Goulet <michael@errs.io>
2025-06-03 14:23:56 +02:00
Oli Scherer
3fff727e87 Use more detailed spans in dyn compat errors within bodies 2025-05-27 08:18:11 +00:00
Michael Goulet
a59c86ab44 Deduplicate dyn compatibility violations due to coercion 2025-05-26 10:57:54 +00:00
Guillaume Gomez
9460f64362 Rollup merge of #141512 - Noratrieb:stop-trimming-this-much, r=compiler-errors
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-25 15:11:48 +02: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
d0413436d5 Do not try to confirm non-dyn compatible method 2025-05-23 12:20:35 +00:00