Commit graph

92 commits

Author SHA1 Message Date
Esteban Küber
c73b3d20c6 Unify wording of resolve error
Remove "failed to resolve" and use the same format we use in other resolution errors "cannot find `name`".

```
error[E0433]: cannot find `nonexistent` in `existent`
  --> $DIR/custom_attr_multisegment_error.rs:5:13
   |
LL | #[existent::nonexistent]
   |             ^^^^^^^^^^^ could not find `nonexistent` in `existent`
```
2026-02-17 16:51:44 +00:00
Alan Egerton
c43a33eec7
Feed ErrorGuaranteed from late lifetime resolution to RBV
If late lifetime resolution fails for whatever reason, forward to RBV
the guarantee that an error was emitted - thereby eliminating the need
for a "hack" to suppress subsequent/superfluous error diagnostics.
2026-02-13 16:24:39 +00:00
Vadim Petrochenkov
7b5a4d8653 privacy: Synchronize PrivateItemsInPublicInterfacesChecker and EmbargoVisitor 2026-01-29 16:34:17 +03: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
joboet
ee24f22b7c
update UI tests 2026-01-21 19:20:04 +01:00
aerooneqq
f483cb2587 Generate error delegation when delegation is not resolved 2026-01-20 11:32:23 +03:00
Asuna
e555d2c44b Use updated indexes to build reverse map for delegation generics 2026-01-12 00:11:55 +01:00
aerooneqq
3f477dd710 Recursive delegation improvements 2025-12-25 14:49:01 +03:00
Jonathan Brouwer
e156286fa5
Rollup merge of #150130 - aerooneqq:delegation-one-line-trait-impl, r=petrochenkov
Support syntax for one-line trait reuse

This PR adds support for reusing the whole trait with a one-line reuse syntax and is part of the delegation feature rust-lang/rust#118212:
```rust
trait T {
  fn foo(&self);
}

struct S;
impl T for S { ... }

struct Wrapper(S);
reuse impl T for Wrapper { self.0 }
```

The core idea is that we already have support for glob reuse, so in this scenario we want to transform one-line reuse into a trait impl block with a glob reuse in the following way:
```rust
//Before
reuse impl T for Wrapper { self.0 }

//After
impl T for Wrapper {
  reuse T::* { self.0 }
}
```

It seems like this task can be solved during parsing stage, when we encountered a one-line trait reuse, we can expand into this impl block right away, and the code which was already written to expand glob delegations will take care about the rest. We will copy trait path into glob reuse path.

The implementation of the transformation reuses already existing methods for `impl` parsing, however, we do not parse inner `impl` items, instead we parse "inner items" as delegation body. Thus, we do not have to deal with generics, consts, unsafe and other `impl` related features.

Other syntax possibility is trying to shorten one-line reuse by replacing `impl` keyword with `reuse` keyword:
```rust
reuse T for Wrapper { self.0 }
```
In this case implementation may become more complicated, and the syntax more confusing, as keywords such as `const` or `unsafe` will precede `reuse`, and there are also generics:
```rust
unsafe reuse<T1, T2> T for Wrapper { self.0 }
```

In the first (currently implemented) version reuse is placed in the beginning of the item, and it is clear that we will reuse trait implementation, while in the second, shorter version, the `reuse` keyword may be lost in generics and keywords that may precede `impl`.

r? ``@petrochenkov``
2025-12-23 12:01:01 +01:00
aerooneqq
1de1885a63 Support syntax for one-line trait reuse 2025-12-23 10:34:23 +03:00
Jonathan Brouwer
1e496bc9e6
Rollup merge of #150024 - aerooneqq:recursive-delegation-2, r=petrochenkov
Support recursive delegation

This PR adds support for recursive delegations and is a part of the delegation feature rust-lang/rust#118212.

r? ``@petrochenkov``
2025-12-18 18:37:17 +01:00
aerooneqq
ae5e0d5492 Support recursive delegation 2025-12-18 10:42:47 +03:00
Kivooeo
84f2854bc3 remove fixme & update stderr files 2025-12-16 13:23:48 +00:00
Esteban Küber
6cd44a472c Make typo in field and name suggestions verbose 2025-12-09 17:29:23 +00:00
Matthias Krüger
c42ce16c7b
Rollup merge of #149548 - aerooneqq:ice-issue-144594, r=petrochenkov
Generate delegation error body when delegation is not resolved

This PR relates to the delegation feature rust-lang/rust#118212, it fixes rust-lang/rust#144594 ICE.
r? `@petrochenkov`
2025-12-05 16:17:10 +01:00
aerooneqq
3e717121a1 Generate error delegation body when delegation is not resolved 2025-12-05 15:22:26 +03:00
aerooneqq
62fe6a0143 Rename added test 2025-12-01 15:30:53 +03:00
aerooneqq
968376d507 Add label rib when visiting delegation body, add test 2025-12-01 12:38:12 +03:00
Christian Poveda
b2ab7cf980
Gate 2015 UI tests 2025-11-27 11:19:00 -05:00
Stuart Cook
06b18db01b
Rollup merge of #148735 - chenyukang:yukang-fix-ice-148732, r=nnethercote
Fix ICE caused by invalid spans for shrink_file

Fixes rust-lang/rust#148732

There are two issues in this function:
1. the original issue is caused by a typo error, which is fixed in the first commit
2. another different ice(Patch span `7..7` is beyond the end of buffer `0`) will be reported after fixing the first one, is caused by spans cross file boundaries due to macro expansion. It is fixed in the second commit.

r? `@nnethercote`

edited: also fixes rust-lang/rust#148684, added a new testcase for it in the last commit.
2025-11-13 11:57:07 +11:00
yukang
4a2c9a11d5 skip invalid span in error emitter 2025-11-12 17:47:15 +08:00
yukang
8573ee6478 Fix ICE caused by span boundaries due to macro expansion 2025-11-09 16:32:22 +08:00
León Orell Valerian Liehr
c262920059
Remove #[const_trait] 2025-11-08 07:37:15 +01:00
Esteban Küber
14646ec374 Add note to E0401 2025-11-03 16:24:36 +00:00
Esteban Küber
48dde00f10 Use more accurate span in resolve_ident_in_lexical_scope 2025-11-03 16:24:35 +00:00
Stuart Cook
c10e1e4122
Rollup merge of #148370 - estebank:outer-param, r=JonathanBrouwer
Point at inner item when it uses generic type param from outer item or `Self`

Partially address rust-lang/rust#37892.

In E0401 generated in resolve:
```
error[E0401]: can't use generic parameters from outer item
  --> $DIR/E0401.rs:4:39
   |
LL | fn foo<T>(x: T) {
   |        - type parameter from outer item
LL |     fn bfnr<U, V: Baz<U>, W: Fn()>(y: T) {
   |        ----                           ^ use of generic parameter from outer item
   |        |
   |        generic parameter used in this inner function
   |
help: try introducing a local generic parameter here
   |
LL |     fn bfnr<T, U, V: Baz<U>, W: Fn()>(y: T) {
   |             ++
```
In E0401 generated in hir_typeck:
```
error[E0401]: can't reference `Self` constructor from outer item
  --> $DIR/do-not-ice-on-note_and_explain.rs:6:13
   |
LL | impl<B> A<B> {
   | ------------ the inner item doesn't inherit generics from this impl, so `Self` is invalid to reference
LL |     fn d() {
LL |         fn d() {
   |            - `Self` used in this inner item
LL |             Self(1)
   |             ^^^^ help: replace `Self` with the actual type: `A`
```
2025-11-03 11:52:41 +11:00
Esteban Küber
f171c41a83 Do not suggest adding type param to fn delegation 2025-11-02 20:05:48 +00:00
Esteban Küber
f6938709c8 Point at inner item when using outer item type param
```
error[E0401]: can't use generic parameters from outer item
  --> $DIR/E0401.rs:4:39
   |
LL | fn foo<T>(x: T) {
   |        - type parameter from outer item
LL |     fn bfnr<U, V: Baz<U>, W: Fn()>(y: T) {
   |        ----                           ^ use of generic parameter from outer item
   |        |
   |        generic parameter used in this inner function
   |
help: try introducing a local generic parameter here
   |
LL |     fn bfnr<T, U, V: Baz<U>, W: Fn()>(y: T) {
   |             ++
```
2025-11-01 18:29:46 +00:00
Esteban Küber
973ab7d08f Make "add param to inner item" suggestion verbose
```
error[E0401]: can't use generic parameters from outer item
  --> $DIR/enum-definition-with-outer-generic-parameter-5997.rs:3:16
   |
LL | fn f<Z>() -> bool {
   |      - type parameter from outer item
LL |     enum E { V(Z) }
   |                ^ use of generic parameter from outer item
   |
help: try introducing a local generic parameter here
   |
LL |     enum E<Z> { V(Z) }
   |           +++
```
2025-11-01 18:23:19 +00:00
Esteban Küber
eeadffd926 When more than a single impl and less than 4 could apply, point at them
```
error[E0277]: the trait bound `[[u16; 3]; 2]: Bar` is not satisfied
  --> $DIR/issue-67185-2.rs:21:6
   |
LL | impl Foo for FooImpl {}
   |      ^^^ the trait `Bar` is not implemented for `[[u16; 3]; 2]`
   |
help: the following other types implement trait `Bar`
  --> $DIR/issue-67185-2.rs:9:1
   |
LL | impl Bar for [u16; 4] {}
   | ^^^^^^^^^^^^^^^^^^^^^ `[u16; 4]`
LL | impl Bar for [[u16; 3]; 3] {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^ `[[u16; 3]; 3]`
note: required by a bound in `Foo`
  --> $DIR/issue-67185-2.rs:14:30
   |
LL | trait Foo
   |       --- required by a bound in this trait
LL | where
LL |     [<u8 as Baz>::Quaks; 2]: Bar,
   |                              ^^^ required by this bound in `Foo`
```
2025-10-31 20:44:01 +00:00
Matthias Krüger
dade9fe04b
Rollup merge of #147251 - jackh726:global-cache-non-concurrent-change, r=lcnr
Do not assert that a change in global cache only happens when concurrent

Fixes rust-lang/trait-system-refactor-initiative#234

I think it should just be safe to remove this assert (rather than delaying a bug). If the previous and current result are the same, I wouldn't expect issues.

r? lcnr
2025-10-04 17:11:12 +02:00
jackh726
55aeb1747d Do not assert that a change in global cache only happens when concurrent 2025-10-03 16:21:15 -04:00
Guillaume Gomez
a535c7be54 Ignore more failing ui tests for GCC backend 2025-09-26 15:33:48 +02: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
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
Guillaume Gomez
de93fb13fe Add ignore-backends annotations in failing GCC backend ui tests 2025-07-23 13:48:04 +02:00
Oli Scherer
9b5d57d0a9 Unconditionally run check_item_type on all items 2025-06-30 08:06:08 +00:00
Guillaume Gomez
cd0adc9d7b
Rollup merge of #140370 - WaffleLapkin:unqualified, r=jdonszelmann
Improve diagnostics for usage of qualified paths within tuple struct exprs/pats

For patterns the old diagnostic was just incorrect, but I also added machine applicable suggestions.

For context, this special cases errors for `<T as Trait>::Assoc(..)` patterns and expressions (latter is just a call). Tuple struct patterns and expressions both live in the value namespace, so they are not forwarded through associated *types*.

r? ``@jdonszelmann``

cc ``@petrochenkov`` in https://github.com/rust-lang/rust/pull/80080#issuecomment-800630582 you were wondering why it doesn't work for types, that's why — tuple patterns are resolved in the value namespace.
2025-06-01 19:35:41 +02:00
John Kåre Alsaker
e561ec0e03 Remove global next_disambiguator state and handle it with a DisambiguatorState type 2025-04-29 13:22:38 +02:00
Waffle Lapkin
8f765fc7a1
bless tests 2025-04-27 18:14:55 +02:00
Matthias Krüger
0de803c38d
Rollup merge of #138632 - clubby789:stabilize-cfg-boolean-lit, r=davidtwco,Urgau,traviscross
Stabilize `cfg_boolean_literals`

Closes #131204
`@rustbot` labels +T-lang +I-lang-nominated
This will end up conflicting with the test in #138293 so whichever doesn't land first will need updating

--

# Stabilization Report

## General design

### What is the RFC for this feature and what changes have occurred to the user-facing design since the RFC was finalized?

[RFC 3695](https://github.com/rust-lang/rfcs/pull/3695), none.

### What behavior are we committing to that has been controversial? Summarize the major arguments pro/con.

None

### Are there extensions to this feature that remain unstable? How do we know that we are not accidentally committing to those?

None

## Has a call-for-testing period been conducted? If so, what feedback was received?

Yes; only positive feedback was received.

## Implementation quality

### Summarize the major parts of the implementation and provide links into the code (or to PRs)

Implemented in [#131034](https://github.com/rust-lang/rust/pull/131034).

### Summarize existing test coverage of this feature

- [Basic usage, including `#[cfg()]`, `cfg!()` and `#[cfg_attr()]`](6d71251cf9/tests/ui/cfg/true-false.rs)
- [`--cfg=true/false` on the command line being accessible via `r#true/r#false`](6d71251cf9/tests/ui/cfg/raw-true-false.rs)
- [Interaction with the unstable `#[doc(cfg(..))]` feature](6d71251/tests/rustdoc-ui/cfg-boolean-literal.rs)
- [Denying `--check-cfg=cfg(true/false)`](6d71251/tests/ui/check-cfg/invalid-arguments.rs)
- Ensuring `--cfg false` on the command line doesn't change the meaning of `cfg(false)`: `tests/ui/cfg/cmdline-false.rs`
- Ensuring both `cfg(true)` and `cfg(false)` on the same item result in it being disabled: `tests/ui/cfg/both-true-false.rs`

### What outstanding bugs in the issue tracker involve this feature? Are they stabilization-blocking?

The above mentioned issue; it should not block as it interacts with another unstable feature.

### What FIXMEs are still in the code for that feature and why is it ok to leave them there?

None

### Summarize contributors to the feature by name for recognition and assuredness that people involved in the feature agree with stabilization
- `@clubby789` (RFC)
- `@Urgau` (Implementation in rustc)

### Which tools need to be adjusted to support this feature. Has this work been done?

`rustdoc`'s  unstable`#[doc(cfg(..)]` has been updated to respect it. `cargo` has been updated with a forward compatibility lint to enable supporting it in cargo once stabilized.

## Type system and execution rules

### What updates are needed to the reference/specification? (link to PRs when they exist)

A few lines to be added to the reference for configuration predicates, specified in the RFC.
2025-04-17 06:25:15 +02:00
Nicholas Nethercote
cdf5b8d4e7 Change how anonymous associated types are printed.
Give them their own symbol `anon_assoc`, as is done for all the other
anonymous `DefPathData` variants.
2025-04-11 20:13:16 +10:00
Bennet Bleßmann
7dd57f085c
update/bless tests 2025-04-06 21:41:47 +02:00
clubby789
303c1b45c2 Use cfg(false) in UI tests 2025-04-03 21:41:58 +00:00
Bryanskiy
63447f2095 Delegation: allow foreign fns reuse 2025-03-13 14:13:07 +03:00
Manish Goregaokar
9d1b62c109
Rollup merge of #138407 - Bryanskiy:delegation-variadic, r=petrochenkov
Delegation: reject C-variadics

The explanation is contained in attached issues.

Fixes https://github.com/rust-lang/rust/issues/127443
Fixes https://github.com/rust-lang/rust/issues/127413

r? `@petrochenkov`
2025-03-12 10:19:34 -07:00
Bryanskiy
ccdba16f42 Delegation: reject C-variadics 2025-03-12 17:14:51 +03:00
Bryanskiy
7bfe2136e4 Delegation: one more ICE fix for MethodCall generation 2025-03-12 15:59:37 +03:00
Bryanskiy
61122d1829 Delegation: fix ICE with invalid MethodCall generation 2025-03-10 17:08:29 +03:00