Commit Graph

422 Commits

Author SHA1 Message Date
Nicholas Nethercote
b982472b92 Make attribute template suggestions work at the level of attr items
Attribute templated mismatch suggestions come in two forms:
- for a normal attribute, something like `#[inline(always)]`;
- for an attribute embedded in `cfg_attr`, something like
  `inline(always)`.

This commit replaces the former with the latter, and removes the need
for the fragile span-based test for detecting embedded attributes in
`template_suggestions`, and also `AttributeParseError::attr_span`. It
takes advantage of the newly added (and accurate) `AttrItem::span`
field.

This change has a minor effect on error messages: when there are
multiple suggestions their order can change because the `#[`/`]` are
no longer included. This actually improves things, because e.g. if you
write the invalid `#[inline(please)]`, the simpler `#[inline]` will be
suggested ahead of the longer `#[inline(always)]` and `#[inline(never)`]
alternatives.
2026-07-26 18:18:15 +10:00
Nicholas Nethercote
c4621ddc66 Improve consistency of "malformed foo attribute input" error messages
Similar to the previous three commits.
2026-07-24 13:01:21 +10:00
Nicholas Nethercote
35b1187a65 Improve consistency of InvalidTarget attribute error messages
Mostly in a fashion similar to the previous commit.

There is one exceptional case: for errors involving `repr` the argument
is significant. For these, the argument is included in the error line
and the caret highlighting, e.g.
```
error: the `repr(C)` attribute cannot be used on functions
  --> $DIR/naked-with-invalid-repr-attr.rs:10:3
   |
LL | #[repr(C)]
   |   ^^^^^^^
   |
   = help: the `repr(C)` attribute can only be applied to data types
```

Contrast this with a more typical argument-excluding case used
everywhere else:
```
error: the `rustc_abi` attribute cannot be used on associated consts
  --> $DIR/debug.rs:46:7
   |
LL |     #[rustc_abi(debug)]
   |       ^^^^^^^^^
   |
   = help: the `rustc_abi` attribute can be applied to functions and type aliases
```
2026-07-24 12:58:31 +10:00
Jacob Pratt
e1d8ba6e3b Rollup merge of #159307 - TorinAsakura:fix/builtin-attribute-value-diagnostics, r=petrochenkov
Improve cross-namespace name diagnostics

Close rust-lang/rust#86290

Cross-namespace name matches now use the ordinary missing-name diagnostic while preserving its error code and suggestions. The diagnostic adds a note identifying the item found in another namespace, while same-namespace wrong-kind diagnostics remain unchanged.

The UI expectations cover cross-namespace combinations across the resolver suite, including preservation of existing suggestions.
2026-07-20 23:38:00 -04:00
Andrew Ghostuhin
30bc6d2f06 fix: improve missing value diagnostics for built-in attributes 2026-07-21 01:03:16 +03:00
Esteban Küber
5f35fc8b8f Replace shortened type with _ instead of ... as placeholder 2026-07-13 22:48:25 +00:00
Jonathan Brouwer
9ad6dbf24f Use AllowedTargets::ManuallyChecked for LangParser 2026-06-22 17:09:37 +02:00
Jonathan Brouwer
f99e8948be Move target checking for #[lang] to the attribute parser 2026-06-22 17:09:32 +02:00
qaijuang
98c932aba7 add missing test 2026-06-17 09:39:00 -04:00
qaijuang
d1bc1b4631 suggest named lifetimes in assoc type bindings 2026-06-17 09:38:57 -04:00
qaijuang
5c7a657e99 add red test 2026-06-17 09:06:33 -04:00
Kivooeo
c1f6331d13 add suggestion for mgca to add assoc type 2026-06-15 12:02:46 +00:00
Jonathan Brouwer
0c2ef16d32 Rollup merge of #157826 - tshepang:some-lack-a-personality, r=oli-obk
make test succeed on targets lacking a personality

Not all targets have `eh_personality` lang item set (see library/std/src/sys/personality/mod.rs), so change test to use a more available lang item.
2026-06-14 22:26:22 +02:00
León Orell Valerian Liehr
2fda23312d Slightly tweak the diagnostic for uncovered type parameters
The diagnostic is generally very noisy.
This commit tries to make it slightly less cluttered and more legible by

1. stopping to reuse the lengthy primary message as the primary label.
   This duplication didn't increase the information content and only
   turned the diagnostic into a letter and symbol soup.
   Instead, we now pick a succinct label ("uncovered type parameter")
   that immediately(!) signals to the users in red what is wrong with
   the highlighted type parameter.
2. breaking some information-dense notes into multiple lines.

Finally, this rephrases the slightly awkward and confusing
"type parameter […] must be used as a type parameter for […] type" to
"type parameter […] must be used as an argument to […] type".
2026-06-14 11:44:15 +02:00
Tshepang Mbambo
53ed8517b4 make test succeed on targets lacking a personality 2026-06-12 18:33:35 +02:00
Jonathan Brouwer
87a08b15cb Integrate target checking for #[repr] into its attribute parser 2026-06-02 21:12:15 +02:00
bjorn3
ee1536314f Remove unused import from a test
I forgot to remove this import when I changed this test.
2026-06-02 12:47:32 +02:00
Jonathan Brouwer
1bd288dd23 Rollup merge of #156924 - bjorn3:less_panic_impl, r=jdonszelmann
Use #[panic_handler] rather than #[lang = "panic_impl"]

As preparation for turning #[panic_handler] from a weak lang item into an EII.

r? @jdonszelmann
2026-06-01 19:35:49 +02:00
Jonathan Brouwer
737cb2d142 Rollup merge of #157125 - JonathanBrouwer:repr-target-checking2, r=mejrs
Rewrite the `#[repr]` attribute parser

The `#[repr]` attribute parser was one of the first attribute parsers we made, and didn't use a lot of the awesome infra we have nowadays yet, so in preparation for a new approach I'm trying for https://github.com/rust-lang/rust/pull/156569 I decided to clean it up.

This PR should have no observable effect other than improved diagnostic messages.

r? @mejrs
2026-05-30 18:01:56 +02:00
Jonathan Brouwer
c72dc2be5b Clean up extend function of ReprParser 2026-05-30 11:33:50 +02:00
Aria Givens
a1d4ad104f Suggest using NameValue syntax for malformed deprecated attribute 2026-05-28 23:03:44 -04:00
bjorn3
b8813df6cb Use #[panic_handler] rather than #[lang = "panic_impl"]
As preparation for turning #[panic_handler] from a weak lang item into
an EII.
2026-05-25 16:59:11 +02:00
janwi_mac
d02b4c8e77 Improve suggestions for unconstrained parameters in impl blocks
When an unconstrained type or lifetime parameter is detected in an
`impl`, provide more specific help based on its usage:
- If the parameter is entirely unused, suggest removing it.
- If it is used in the `impl` body but not the `Self` type, suggest
  including it in the `Self` type and the struct definition.

This also adds a comprehensive UI test for these cases.
2026-05-09 17:50:35 +12:00
mu001999
d5a26d811b Support trailing self in import paths 2026-04-27 10:58:30 +08:00
Jacob Pratt
ca34f771c0 Rollup merge of #154827 - scrabsha:push-zuosxmmnzkrq, r=jdonszelmann
distinguish "expected a single argument" and "expected an argument" on attribute parsing
2026-04-11 04:50:15 -04:00
Jonathan Brouwer
65745a1b95 Revert #152369 because of multiple regressions
The regressions are documented in the PR comments.
This reverts commit 2972b5e, reversing changes made to f908263.
2026-04-09 18:53:59 +02:00
Sasha Pourcelot
362e0f9160 special case expected_single_argument when no argument is provided 2026-04-09 16:39:58 +00:00
yukang
ef9b7c2b8f replace span_look_ahead with span_followed_by 2026-04-08 09:34:24 +08:00
Edvin Bryntesson
bd864efa70 bless tests and tidy
also removes E0452 and splits
`tests/rustdoc-ui/lints/renamed-lint-still-applies` into 2 tests

this is because of delayed warn lint being lost on compiler aborting on
error
2026-04-03 11:08:11 +02:00
Yuki Okushi
531631c7ad Make messages more generic 2026-03-28 16:18:11 +09:00
cyrgani
9b0be7857a allow incomplete_features in most UI tests 2026-03-21 20:10:07 +00:00
León Orell Valerian Liehr
6bb6b11d9d Rename #[rustc_variance] to #[rustc_dump_variances] 2026-03-02 19:31:15 +01:00
mu001999
58e5475683 Rewrite build_reduced_graph_for_use_tree 2026-02-20 10:58:58 +08:00
Esteban Küber
37684bdfc5 Make all multipart suggestions verbose
The ShowAlways style of suggestions is usually easier to understand than the inline style.
2026-02-18 18:33:35 +00:00
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
Ralf Jung
5e65109f21 add write_box_via_move intrinsic and use it for vec!
This allows us to get rid of box_new entirely
2026-02-16 17:27:40 +01:00
Jonathan Brouwer
c61c2603cf Port #[lang] to the new attribute parsers 2026-02-13 16:04:19 +00:00
xizheyin
ed90b35669 Add note when inherent impl for a alias type defined outside of the crate 2026-02-09 15:10:01 +08:00
Jonathan Brouwer
c1091da34c Fix existing messages in stderrs 2026-02-07 09:13:42 +01:00
Esteban Küber
dffec20dee Tweak help to unify formatting and wording 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
20000ca25a Point at destructor when denying deriving Copy 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
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
León Orell Valerian Liehr
233a45c41a Fix handling of const params defaults that ref Self & generalize diag
We used to lower such bad defaulted const args in trait object types to
`{type error}`; now correctly lower them to `{const error}`.

The added tests used to ICE prior to this change.
2026-01-21 12:53:47 +01:00
León Orell Valerian Liehr
9b861ace46 Generalize diag for missing assoc types to account for assoc consts 2026-01-21 12:53:46 +01:00
Jonathan Brouwer
f5a1fc75ad Update uitests 2026-01-18 22:41:00 +01:00
Jonathan Brouwer
cbcd1c3eef Rollup merge of #151036 - issue-151026, r=mati865
Better handle when trying to iterate on a `Range` of a type that isn't `Step`

Mention when a trait bound corresponds to an unstable trait.

Mention `Range` when `Step` bound is unment, and explain that only some std types impl `Iterator` for `Range`.

CC rust-lang/rust#151026
2026-01-14 11:05:40 +01:00
Guillaume Gomez
6c700ecd6a Rollup merge of #150737 - smithdb3/fix-150576, r=chenyukang
diagnostics: make implicit Sized bounds explicit in E0277

When a trait parameter depends upon Sized, the error message only referred to the full trait itself and didn't mention Sized. This makes the failure to implement Sized explicit. It also notes when the Sized trait bound is explicit or implicit.

Fixes rust-lang/rust#150576
2026-01-13 23:39:08 +01:00
Esteban Küber
cafe91749f On unmet trait bound, mention if trait is unstable 2026-01-13 01:16:58 +00:00