Stabilize the #[diagnostic] namespace and #[diagnostic::on_unimplemented] attribute by weiznich · Pull Request #119888 · rust-lang/rust (original) (raw)

@weiznich

@rustbot rustbot added S-waiting-on-review

Status: Awaiting review from the assignee but also interested parties.

T-compiler

Relevant to the compiler team, which will review and decide on the PR/issue.

T-libs

Relevant to the library team, which will review and decide on the PR/issue.

labels

Jan 12, 2024

Noratrieb

bors added a commit to rust-lang-ci/rust that referenced this pull request

Mar 6, 2024

@bors

…iaskrgr

Rollup of 9 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Mar 6, 2024

@matthiaskrgr

…pace, r=compiler-errors

Stabilize the #[diagnostic] namespace and #[diagnostic::on_unimplemented] attribute

This PR stabilizes the #[diagnostic] attribute namespace and a minimal option of the #[diagnostic::on_unimplemented] attribute.

The #[diagnostic] attribute namespace is meant to provide a home for attributes that allow users to influence error messages emitted by the compiler. The compiler is not guaranteed to use any of this hints, however it should accept any (non-)existing attribute in this namespace and potentially emit lint-warnings for unused attributes and options. This is meant to allow discarding certain attributes/options in the future to allow fundamental changes to the compiler without the need to keep then non-meaningful options working.

The #[diagnostic::on_unimplemented] attribute is allowed to appear on a trait definition. This allows crate authors to hint the compiler to emit a specific error message if a certain trait is not implemented. For the #[diagnostic::on_unimplemented] attribute the following options are implemented:

The note option can appear several times, which results in several note messages being emitted. If any of the other options appears several times the first occurrence of the relevant option specifies the actually used value. Any other occurrence generates an lint warning. For any other non-existing option a lint-warning is generated.

All three options accept a text as argument. This text is allowed to contain format parameters referring to generic argument or Self by name via the {Self} or {NameOfGenericArgument} syntax. For any non-existing argument a lint warning is generated.

This allows to have a trait definition like:

#[diagnostic::on_unimplemented(
    message = "My Message for `ImportantTrait<{A}>` is not implemented for `{Self}`",
    label = "My Label",
    note = "Note 1",
    note = "Note 2"
)]
trait ImportantTrait<A> {}

which then generates for the following code

fn use_my_trait(_: impl ImportantTrait<i32>) {}

fn main() {
    use_my_trait(String::new());
}

this error message:

error[E0277]: My Message for `ImportantTrait<i32>` is not implemented for `String`
  --> src/main.rs:14:18
   |
14 |     use_my_trait(String::new());
   |     ------------ ^^^^^^^^^^^^^ My Label
   |     |
   |     required by a bound introduced by this call
   |
   = help: the trait `ImportantTrait<i32>` is not implemented for `String`
   = note: Note 1
   = note: Note 2

Playground with the unstable feature

Fixes rust-lang#111996

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request

Mar 6, 2024

@matthiaskrgr

…pace, r=compiler-errors

Stabilize the #[diagnostic] namespace and #[diagnostic::on_unimplemented] attribute

This PR stabilizes the #[diagnostic] attribute namespace and a minimal option of the #[diagnostic::on_unimplemented] attribute.

The #[diagnostic] attribute namespace is meant to provide a home for attributes that allow users to influence error messages emitted by the compiler. The compiler is not guaranteed to use any of this hints, however it should accept any (non-)existing attribute in this namespace and potentially emit lint-warnings for unused attributes and options. This is meant to allow discarding certain attributes/options in the future to allow fundamental changes to the compiler without the need to keep then non-meaningful options working.

The #[diagnostic::on_unimplemented] attribute is allowed to appear on a trait definition. This allows crate authors to hint the compiler to emit a specific error message if a certain trait is not implemented. For the #[diagnostic::on_unimplemented] attribute the following options are implemented:

The note option can appear several times, which results in several note messages being emitted. If any of the other options appears several times the first occurrence of the relevant option specifies the actually used value. Any other occurrence generates an lint warning. For any other non-existing option a lint-warning is generated.

All three options accept a text as argument. This text is allowed to contain format parameters referring to generic argument or Self by name via the {Self} or {NameOfGenericArgument} syntax. For any non-existing argument a lint warning is generated.

This allows to have a trait definition like:

#[diagnostic::on_unimplemented(
    message = "My Message for `ImportantTrait<{A}>` is not implemented for `{Self}`",
    label = "My Label",
    note = "Note 1",
    note = "Note 2"
)]
trait ImportantTrait<A> {}

which then generates for the following code

fn use_my_trait(_: impl ImportantTrait<i32>) {}

fn main() {
    use_my_trait(String::new());
}

this error message:

error[E0277]: My Message for `ImportantTrait<i32>` is not implemented for `String`
  --> src/main.rs:14:18
   |
14 |     use_my_trait(String::new());
   |     ------------ ^^^^^^^^^^^^^ My Label
   |     |
   |     required by a bound introduced by this call
   |
   = help: the trait `ImportantTrait<i32>` is not implemented for `String`
   = note: Note 1
   = note: Note 2

Playground with the unstable feature

Fixes rust-lang#111996

bors added a commit to rust-lang-ci/rust that referenced this pull request

Mar 6, 2024

@bors

…iaskrgr

Rollup of 8 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

bors added a commit to rust-lang-ci/rust that referenced this pull request

Mar 7, 2024

@bors

…llaumeGomez

Rollup of 10 pull requests

Successful merges:

r? @ghost @rustbot modify labels: rollup

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request

Mar 8, 2024

@rust-timer

Rollup merge of rust-lang#119888 - weiznich:stablize_diagnostic_namespace, r=compiler-errors

Stabilize the #[diagnostic] namespace and #[diagnostic::on_unimplemented] attribute

This PR stabilizes the #[diagnostic] attribute namespace and a minimal option of the #[diagnostic::on_unimplemented] attribute.

The #[diagnostic] attribute namespace is meant to provide a home for attributes that allow users to influence error messages emitted by the compiler. The compiler is not guaranteed to use any of this hints, however it should accept any (non-)existing attribute in this namespace and potentially emit lint-warnings for unused attributes and options. This is meant to allow discarding certain attributes/options in the future to allow fundamental changes to the compiler without the need to keep then non-meaningful options working.

The #[diagnostic::on_unimplemented] attribute is allowed to appear on a trait definition. This allows crate authors to hint the compiler to emit a specific error message if a certain trait is not implemented. For the #[diagnostic::on_unimplemented] attribute the following options are implemented:

The note option can appear several times, which results in several note messages being emitted. If any of the other options appears several times the first occurrence of the relevant option specifies the actually used value. Any other occurrence generates an lint warning. For any other non-existing option a lint-warning is generated.

All three options accept a text as argument. This text is allowed to contain format parameters referring to generic argument or Self by name via the {Self} or {NameOfGenericArgument} syntax. For any non-existing argument a lint warning is generated.

This allows to have a trait definition like:

#[diagnostic::on_unimplemented(
    message = "My Message for `ImportantTrait<{A}>` is not implemented for `{Self}`",
    label = "My Label",
    note = "Note 1",
    note = "Note 2"
)]
trait ImportantTrait<A> {}

which then generates for the following code

fn use_my_trait(_: impl ImportantTrait<i32>) {}

fn main() {
    use_my_trait(String::new());
}

this error message:

error[E0277]: My Message for `ImportantTrait<i32>` is not implemented for `String`
  --> src/main.rs:14:18
   |
14 |     use_my_trait(String::new());
   |     ------------ ^^^^^^^^^^^^^ My Label
   |     |
   |     required by a bound introduced by this call
   |
   = help: the trait `ImportantTrait<i32>` is not implemented for `String`
   = note: Note 1
   = note: Note 2

Playground with the unstable feature

Fixes rust-lang#111996

@fmease fmease added the relnotes

Marks issues that should be documented in the release notes of the next release.

label

Mar 8, 2024

This was referenced

Mar 8, 2024

@clux clux mentioned this pull request

Mar 10, 2024

wcampbell0x2a added a commit to sharksforarms/deku that referenced this pull request

May 2, 2024

@wcampbell0x2a

error[E0277]: the trait bound FieldF: deku::DekuReader<'_, _> is not satisfied --> examples/example.rs:37:14 | 37 | field_f: FieldF, | ^^^^^^ the trait deku::DekuReader<'_, _> is not implemented for FieldF | = note: implement by adding #[derive(DekuRead)] to FieldF = note: make sure the ctx sent into the function matches FieldF's ctx = help: the following other types implement trait deku::DekuReader<'a, Ctx>: <() as deku::DekuReader<'_, Ctx>> <(A, B) as deku::DekuReader<'a, Ctx>> <(A, B, C) as deku::DekuReader<'a, Ctx>> <(A, B, C, D) as deku::DekuReader<'a, Ctx>> <(A, B, C, D, E) as deku::DekuReader<'a, Ctx>> <(A, B, C, D, E, F) as deku::DekuReader<'a, Ctx>> <(A, B, C, D, E, F, G) as deku::DekuReader<'a, Ctx>> <(A, B, C, D, E, F, G, H) as deku::DekuReader<'a, Ctx>> and 152 others

wip-sync pushed a commit to NetBSD/pkgsrc-wip that referenced this pull request

May 4, 2024

@he32

Pkgsrc changes:

Upstream chnages:

Version 1.78.0 (2024-05-02)

Language

Compiler

Target changes:

Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support.

Libraries

Stabilized APIs

These APIs are now stable in const contexts:

Cargo

Misc

Compatibility Notes

Internal Changes

These changes do not affect any public interfaces of Rust, but they represent significant improvements to the performance or internals of rustc and related tools.

wcampbell0x2a added a commit to sharksforarms/deku that referenced this pull request

May 14, 2024

@wcampbell0x2a

error[E0277]: the trait bound FieldF: deku::DekuReader<'_, _> is not satisfied --> examples/example.rs:37:14 | 37 | field_f: FieldF, | ^^^^^^ the trait deku::DekuReader<'_, _> is not implemented for FieldF | = note: implement by adding #[derive(DekuRead)] to FieldF = note: make sure the ctx sent into the function matches FieldF's ctx = help: the following other types implement trait deku::DekuReader<'a, Ctx>: <() as deku::DekuReader<'_, Ctx>> <(A, B) as deku::DekuReader<'a, Ctx>> <(A, B, C) as deku::DekuReader<'a, Ctx>> <(A, B, C, D) as deku::DekuReader<'a, Ctx>> <(A, B, C, D, E) as deku::DekuReader<'a, Ctx>> <(A, B, C, D, E, F) as deku::DekuReader<'a, Ctx>> <(A, B, C, D, E, F, G) as deku::DekuReader<'a, Ctx>> <(A, B, C, D, E, F, G, H) as deku::DekuReader<'a, Ctx>> and 152 others

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request

Oct 13, 2024

@he32

This is based on the pkgsrc-wip rust180 package, retaining the main pkgsrc changes as best as I could.

Pkgsrc changes:

Upstream chnages:

Version 1.80.1 (2024-08-08)

Version 1.80.0 (2024-07-25)

Language

Compiler

Libraries

Stabilized APIs

These APIs are now stable in const contexts:

Cargo

Rustdoc

Compatibility Notes

Internal Changes

These changes do not affect any public interfaces of Rust, but they represent significant improvements to the performance or internals of rustc and related tools.

Version 1.79.0 (2024-06-13)

Language

Compiler

Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support.

Libraries

Stabilized APIs

These APIs are now stable in const contexts:

Cargo

Rustdoc

Misc

Compatibility Notes

Version 1.78.0 (2024-05-02)

Language

Compiler

Target changes:

Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support.

Libraries

Stabilized APIs

These APIs are now stable in const contexts:

Cargo

Misc

Compatibility Notes

Internal Changes

These changes do not affect any public interfaces of Rust, but they represent significant improvements to the performance or internals of rustc and related tools.

Version 1.77.0 (2024-03-21)

Compiler

Refer to Rust's [platform support page][platform-support-doc] for more information on Rust's tiered platform support.

Libraries

Stabilized APIs

Cargo

Rustdoc

Misc

Internal Changes

These changes do not affect any public interfaces of Rust, but they represent significant improvements to the performance or internals of rustc and related tools.