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.
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
```
Improve cross-namespace name diagnostics
Closerust-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.
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.
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".
Use #[panic_handler] rather than #[lang = "panic_impl"]
As preparation for turning #[panic_handler] from a weak lang item into an EII.
r? @jdonszelmann
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
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.
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
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`
```
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.