Rollup merge of #139091 - mejrs:format, r=compiler-errors

Rewrite on_unimplemented format string parser.

This PR rewrites the format string parser for `rustc_on_unimplemented` and `diagnostic::on_unimplemented`. I plan on moving this code (and more) into the new attribute parsing system soon and wanted to PR it separately.

This PR introduces some minor differences though:
- `rustc_on_unimplemented` on trait *implementations* is no longer checked/used - this is actually never used (outside of some tests) so I plan on removing it in the future.
- for `rustc_on_unimplemented`, it introduces the `{This}` argument in favor of `{ThisTraitname}` (to be removed later). It'll be easier to parse.
- for `rustc_on_unimplemented`, `Self` can now consistently be used as a filter, rather than just `_Self`. It used to not match correctly on for example `Self = "[{integer}]"`
- Some error messages now have better spans.

Fixes https://github.com/rust-lang/rust/issues/130627
This commit is contained in:
Chris Denton 2025-04-19 15:09:33 +00:00 committed by GitHub
commit aad59a30de
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 965 additions and 688 deletions

View file

@ -1,20 +0,0 @@
//@ known-bug: #130627
#![feature(trait_alias)]
trait Test {}
#[diagnostic::on_unimplemented(
message="message",
label="label",
note="note"
)]
trait Alias = Test;
// Use trait alias as bound on type parameter.
fn foo<T: Alias>(v: &T) {
}
pub fn main() {
foo(&1);
}

View file

@ -0,0 +1,17 @@
// used to ICE, see <https://github.com/rust-lang/rust/issues/130627>
// Instead it should just ignore the diagnostic attribute
#![feature(trait_alias)]
trait Test {}
#[diagnostic::on_unimplemented(message = "blah", label = "blah", note = "blah")]
//~^ WARN `#[diagnostic::on_unimplemented]` can only be applied to trait definitions
trait Alias = Test;
// Use trait alias as bound on type parameter.
fn foo<T: Alias>(v: &T) {}
pub fn main() {
foo(&1);
//~^ ERROR the trait bound `{integer}: Alias` is not satisfied
}

View file

@ -0,0 +1,31 @@
warning: `#[diagnostic::on_unimplemented]` can only be applied to trait definitions
--> $DIR/on_impl_trait.rs:7:1
|
LL | #[diagnostic::on_unimplemented(message = "blah", label = "blah", note = "blah")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default
error[E0277]: the trait bound `{integer}: Alias` is not satisfied
--> $DIR/on_impl_trait.rs:15:9
|
LL | foo(&1);
| --- ^^ the trait `Test` is not implemented for `{integer}`
| |
| required by a bound introduced by this call
|
help: this trait has no implementations, consider adding one
--> $DIR/on_impl_trait.rs:5:1
|
LL | trait Test {}
| ^^^^^^^^^^
= note: required for `{integer}` to implement `Alias`
note: required by a bound in `foo`
--> $DIR/on_impl_trait.rs:12:11
|
LL | fn foo<T: Alias>(v: &T) {}
| ^^^^^ required by this bound in `foo`
error: aborting due to 1 previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0277`.

View file

@ -1,52 +1,52 @@
warning: unmatched `}` found
--> $DIR/broken_format.rs:2:32
--> $DIR/broken_format.rs:2:42
|
LL | #[diagnostic::on_unimplemented(message = "{{Test } thing")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^
|
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default
warning: positional format arguments are not allowed here
--> $DIR/broken_format.rs:7:32
--> $DIR/broken_format.rs:7:49
|
LL | #[diagnostic::on_unimplemented(message = "Test {}")]
| ^^^^^^^^^^^^^^^^^^^
| ^
|
= help: only named format arguments with the name of one of the generic types are allowed in this context
warning: positional format arguments are not allowed here
--> $DIR/broken_format.rs:12:32
--> $DIR/broken_format.rs:12:49
|
LL | #[diagnostic::on_unimplemented(message = "Test {1:}")]
| ^^^^^^^^^^^^^^^^^^^^^
| ^
|
= help: only named format arguments with the name of one of the generic types are allowed in this context
warning: invalid format specifier
--> $DIR/broken_format.rs:17:32
--> $DIR/broken_format.rs:17:42
|
LL | #[diagnostic::on_unimplemented(message = "Test {Self:123}")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^
|
= help: no format specifier are supported in this position
warning: expected `}`, found `!`
--> $DIR/broken_format.rs:22:32
--> $DIR/broken_format.rs:22:42
|
LL | #[diagnostic::on_unimplemented(message = "Test {Self:!}")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^
warning: unmatched `}` found
--> $DIR/broken_format.rs:22:32
--> $DIR/broken_format.rs:22:42
|
LL | #[diagnostic::on_unimplemented(message = "Test {Self:!}")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^
warning: unmatched `}` found
--> $DIR/broken_format.rs:2:32
--> $DIR/broken_format.rs:2:42
|
LL | #[diagnostic::on_unimplemented(message = "{{Test } thing")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
@ -70,10 +70,10 @@ LL | fn check_1(_: impl ImportantTrait1) {}
| ^^^^^^^^^^^^^^^ required by this bound in `check_1`
warning: positional format arguments are not allowed here
--> $DIR/broken_format.rs:7:32
--> $DIR/broken_format.rs:7:49
|
LL | #[diagnostic::on_unimplemented(message = "Test {}")]
| ^^^^^^^^^^^^^^^^^^^
| ^
|
= help: only named format arguments with the name of one of the generic types are allowed in this context
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
@ -98,10 +98,10 @@ LL | fn check_2(_: impl ImportantTrait2) {}
| ^^^^^^^^^^^^^^^ required by this bound in `check_2`
warning: positional format arguments are not allowed here
--> $DIR/broken_format.rs:12:32
--> $DIR/broken_format.rs:12:49
|
LL | #[diagnostic::on_unimplemented(message = "Test {1:}")]
| ^^^^^^^^^^^^^^^^^^^^^
| ^
|
= help: only named format arguments with the name of one of the generic types are allowed in this context
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
@ -126,10 +126,10 @@ LL | fn check_3(_: impl ImportantTrait3) {}
| ^^^^^^^^^^^^^^^ required by this bound in `check_3`
warning: invalid format specifier
--> $DIR/broken_format.rs:17:32
--> $DIR/broken_format.rs:17:42
|
LL | #[diagnostic::on_unimplemented(message = "Test {Self:123}")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^
|
= help: no format specifier are supported in this position
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
@ -154,18 +154,18 @@ LL | fn check_4(_: impl ImportantTrait4) {}
| ^^^^^^^^^^^^^^^ required by this bound in `check_4`
warning: expected `}`, found `!`
--> $DIR/broken_format.rs:22:32
--> $DIR/broken_format.rs:22:42
|
LL | #[diagnostic::on_unimplemented(message = "Test {Self:!}")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
warning: unmatched `}` found
--> $DIR/broken_format.rs:22:32
--> $DIR/broken_format.rs:22:42
|
LL | #[diagnostic::on_unimplemented(message = "Test {Self:!}")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

View file

@ -39,82 +39,82 @@ LL | #[diagnostic::on_unimplemented = "Message"]
= help: only `message`, `note` and `label` are allowed as options
warning: there is no parameter `from_desugaring` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:17
|
LL | message = "{from_desugaring}{direct}{cause}{integral}{integer}",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
warning: there is no parameter `direct` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:34
|
LL | message = "{from_desugaring}{direct}{cause}{integral}{integer}",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
warning: there is no parameter `cause` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:42
|
LL | message = "{from_desugaring}{direct}{cause}{integral}{integer}",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
warning: there is no parameter `integral` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:49
|
LL | message = "{from_desugaring}{direct}{cause}{integral}{integer}",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
warning: there is no parameter `integer` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:59
|
LL | message = "{from_desugaring}{direct}{cause}{integral}{integer}",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
warning: there is no parameter `float` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:15
|
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
warning: there is no parameter `_Self` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:22
|
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
warning: there is no parameter `crate_local` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:29
|
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
warning: there is no parameter `Trait` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:42
|
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
warning: there is no parameter `ItemContext` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:49
|
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
@ -191,91 +191,91 @@ LL | fn takes_bar(_: impl Bar) {}
| ^^^ required by this bound in `takes_bar`
warning: there is no parameter `from_desugaring` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:17
|
LL | message = "{from_desugaring}{direct}{cause}{integral}{integer}",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
warning: there is no parameter `direct` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:34
|
LL | message = "{from_desugaring}{direct}{cause}{integral}{integer}",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
warning: there is no parameter `cause` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:42
|
LL | message = "{from_desugaring}{direct}{cause}{integral}{integer}",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
warning: there is no parameter `integral` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:49
|
LL | message = "{from_desugaring}{direct}{cause}{integral}{integer}",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
warning: there is no parameter `integer` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:33:59
|
LL | message = "{from_desugaring}{direct}{cause}{integral}{integer}",
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
warning: there is no parameter `float` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:15
|
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
warning: there is no parameter `_Self` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:22
|
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
warning: there is no parameter `crate_local` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:29
|
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
warning: there is no parameter `Trait` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:42
|
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
warning: there is no parameter `ItemContext` on trait `Baz`
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:5
--> $DIR/do_not_accept_options_of_the_internal_rustc_attribute.rs:44:49
|
LL | label = "{float}{_Self}{crate_local}{Trait}{ItemContext}"
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

View file

@ -47,10 +47,10 @@ LL | #[diagnostic::on_unimplemented]
= help: at least one of the `message`, `note` and `label` options are expected
warning: there is no parameter `DoesNotExist` on trait `Test`
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:31:32
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:31:44
|
LL | #[diagnostic::on_unimplemented(message = "{DoesNotExist}")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
@ -167,10 +167,10 @@ LL | fn take_whatever(_: impl Whatever) {}
| ^^^^^^^^ required by this bound in `take_whatever`
warning: there is no parameter `DoesNotExist` on trait `Test`
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:31:32
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:31:44
|
LL | #[diagnostic::on_unimplemented(message = "{DoesNotExist}")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^
|
= help: expect either a generic argument name or `{Self}` as format argument
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

View file

@ -20,12 +20,12 @@ trait BadAnnotation1
{}
#[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{C}>`"]
//~^ ERROR there is no parameter `C` on trait `BadAnnotation2`
//~^ ERROR cannot find parameter C on this trait
trait BadAnnotation2<A,B>
{}
#[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{}>`"]
//~^ ERROR only named generic parameters are allowed
//~^ ERROR positional format arguments are not allowed here
trait BadAnnotation3<A,B>
{}

View file

@ -11,17 +11,17 @@ LL | #[rustc_on_unimplemented = "message"]
LL | #[rustc_on_unimplemented(/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...")]
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
error[E0230]: there is no parameter `C` on trait `BadAnnotation2`
--> $DIR/bad-annotation.rs:22:1
error[E0230]: cannot find parameter C on this trait
--> $DIR/bad-annotation.rs:22:90
|
LL | #[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{C}>`"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^
error[E0231]: only named generic parameters are allowed
--> $DIR/bad-annotation.rs:27:1
error[E0231]: positional format arguments are not allowed here
--> $DIR/bad-annotation.rs:27:90
|
LL | #[rustc_on_unimplemented = "Unimplemented trait error on `{Self}` with params `<{A},{B},{}>`"]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ^
error[E0232]: this attribute must have a valid value
--> $DIR/bad-annotation.rs:32:26

View file

@ -1,15 +0,0 @@
#![feature(rustc_attrs)]
trait Foo<A> {
fn foo(self);
}
#[rustc_on_unimplemented = "an impl did not match: {A} {B} {C}"]
impl<A, B, C> Foo<A> for (A, B, C) {
fn foo(self) {}
}
fn main() {
Foo::<usize>::foo((1i32, 1i32, 1i32));
//~^ ERROR the trait bound `(i32, i32, i32): Foo<usize>` is not satisfied
}

View file

@ -1,15 +0,0 @@
error[E0277]: the trait bound `(i32, i32, i32): Foo<usize>` is not satisfied
--> $DIR/impl-substs.rs:13:23
|
LL | Foo::<usize>::foo((1i32, 1i32, 1i32));
| ----------------- ^^^^^^^^^^^^^^^^^^ an impl did not match: usize _ _
| |
| required by a bound introduced by this call
|
= help: the trait `Foo<usize>` is not implemented for `(i32, i32, i32)`
but trait `Foo<i32>` is implemented for it
= help: for that trait implementation, expected `i32`, found `usize`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -1,8 +0,0 @@
#![feature(rustc_attrs)]
trait Foo {}
#[rustc_on_unimplemented] //~ ERROR malformed `rustc_on_unimplemented` attribute input
impl Foo for u32 {}
fn main() {}

View file

@ -1,15 +0,0 @@
error: malformed `rustc_on_unimplemented` attribute input
--> $DIR/issue-104140.rs:5:1
|
LL | #[rustc_on_unimplemented]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[rustc_on_unimplemented = "message"]
| +++++++++++
LL | #[rustc_on_unimplemented(/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...")]
| ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
error: aborting due to 1 previous error

View file

@ -1,42 +0,0 @@
// Test if the on_unimplemented message override works
#![feature(rustc_attrs)]
struct Foo<T>(T);
struct Bar<T>(T);
#[rustc_on_unimplemented = "trait message"]
trait Index<Idx: ?Sized> {
type Output: ?Sized;
fn index(&self, index: Idx) -> &Self::Output;
}
#[rustc_on_unimplemented = "on impl for Foo"]
impl Index<Foo<usize>> for [i32] {
type Output = i32;
fn index(&self, _index: Foo<usize>) -> &i32 {
loop {}
}
}
#[rustc_on_unimplemented = "on impl for Bar"]
impl Index<Bar<usize>> for [i32] {
type Output = i32;
fn index(&self, _index: Bar<usize>) -> &i32 {
loop {}
}
}
fn main() {
Index::index(&[] as &[i32], 2u32);
//~^ ERROR E0277
//~| ERROR E0277
Index::index(&[] as &[i32], Foo(2u32));
//~^ ERROR E0277
//~| ERROR E0277
Index::index(&[] as &[i32], Bar(2u32));
//~^ ERROR E0277
//~| ERROR E0277
}

View file

@ -1,75 +0,0 @@
error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied
--> $DIR/multiple-impls.rs:33:33
|
LL | Index::index(&[] as &[i32], 2u32);
| ------------ ^^^^ trait message
| |
| required by a bound introduced by this call
|
= help: the trait `Index<u32>` is not implemented for `[i32]`
= help: the following other types implement trait `Index<Idx>`:
`[i32]` implements `Index<Bar<usize>>`
`[i32]` implements `Index<Foo<usize>>`
error[E0277]: the trait bound `[i32]: Index<Foo<u32>>` is not satisfied
--> $DIR/multiple-impls.rs:36:33
|
LL | Index::index(&[] as &[i32], Foo(2u32));
| ------------ ^^^^^^^^^ on impl for Foo
| |
| required by a bound introduced by this call
|
= help: the trait `Index<Foo<u32>>` is not implemented for `[i32]`
= help: the following other types implement trait `Index<Idx>`:
`[i32]` implements `Index<Bar<usize>>`
`[i32]` implements `Index<Foo<usize>>`
error[E0277]: the trait bound `[i32]: Index<Bar<u32>>` is not satisfied
--> $DIR/multiple-impls.rs:39:33
|
LL | Index::index(&[] as &[i32], Bar(2u32));
| ------------ ^^^^^^^^^ on impl for Bar
| |
| required by a bound introduced by this call
|
= help: the trait `Index<Bar<u32>>` is not implemented for `[i32]`
= help: the following other types implement trait `Index<Idx>`:
`[i32]` implements `Index<Bar<usize>>`
`[i32]` implements `Index<Foo<usize>>`
error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied
--> $DIR/multiple-impls.rs:33:5
|
LL | Index::index(&[] as &[i32], 2u32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ trait message
|
= help: the trait `Index<u32>` is not implemented for `[i32]`
= help: the following other types implement trait `Index<Idx>`:
`[i32]` implements `Index<Bar<usize>>`
`[i32]` implements `Index<Foo<usize>>`
error[E0277]: the trait bound `[i32]: Index<Foo<u32>>` is not satisfied
--> $DIR/multiple-impls.rs:36:5
|
LL | Index::index(&[] as &[i32], Foo(2u32));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ on impl for Foo
|
= help: the trait `Index<Foo<u32>>` is not implemented for `[i32]`
= help: the following other types implement trait `Index<Idx>`:
`[i32]` implements `Index<Bar<usize>>`
`[i32]` implements `Index<Foo<usize>>`
error[E0277]: the trait bound `[i32]: Index<Bar<u32>>` is not satisfied
--> $DIR/multiple-impls.rs:39:5
|
LL | Index::index(&[] as &[i32], Bar(2u32));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ on impl for Bar
|
= help: the trait `Index<Bar<u32>>` is not implemented for `[i32]`
= help: the following other types implement trait `Index<Idx>`:
`[i32]` implements `Index<Bar<usize>>`
`[i32]` implements `Index<Foo<usize>>`
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0277`.

View file

@ -1,25 +0,0 @@
// Test if the on_unimplemented message override works
#![feature(rustc_attrs)]
#[rustc_on_unimplemented = "invalid"]
trait Index<Idx: ?Sized> {
type Output: ?Sized;
fn index(&self, index: Idx) -> &Self::Output;
}
#[rustc_on_unimplemented = "a usize is required to index into a slice"]
impl Index<usize> for [i32] {
type Output = i32;
fn index(&self, index: usize) -> &i32 {
&self[index]
}
}
fn main() {
Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
//~^ ERROR E0277
//~| ERROR E0277
}

View file

@ -1,25 +0,0 @@
error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied
--> $DIR/on-impl.rs:22:47
|
LL | Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
| ------------------- ^^^^ a usize is required to index into a slice
| |
| required by a bound introduced by this call
|
= help: the trait `Index<u32>` is not implemented for `[i32]`
but trait `Index<usize>` is implemented for it
= help: for that trait implementation, expected `usize`, found `u32`
error[E0277]: the trait bound `[i32]: Index<u32>` is not satisfied
--> $DIR/on-impl.rs:22:5
|
LL | Index::<u32>::index(&[1, 2, 3] as &[i32], 2u32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ a usize is required to index into a slice
|
= help: the trait `Index<u32>` is not implemented for `[i32]`
but trait `Index<usize>` is implemented for it
= help: for that trait implementation, expected `usize`, found `u32`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.

View file

@ -0,0 +1,14 @@
#![feature(rustc_attrs)]
#[rustc_on_unimplemented(on(
all(A = "{integer}", any(Self = "[{integral}; _]",)),
message = "an array of type `{Self}` cannot be built directly from an iterator",
))]
pub trait FromIterator<A>: Sized {
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self;
}
fn main() {
let iter = 0..42_8;
let x: [u8; 8] = FromIterator::from_iter(iter);
//~^ ERROR an array of type `[u8; 8]` cannot be built directly from an iterator
}

View file

@ -0,0 +1,15 @@
error[E0277]: an array of type `[u8; 8]` cannot be built directly from an iterator
--> $DIR/use_self_no_underscore.rs:12:22
|
LL | let x: [u8; 8] = FromIterator::from_iter(iter);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `FromIterator<{integer}>` is not implemented for `[u8; 8]`
|
help: this trait has no implementations, consider adding one
--> $DIR/use_self_no_underscore.rs:7:1
|
LL | pub trait FromIterator<A>: Sized {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.