Skip to content

Commit 0443b99

Browse files
authored
Unrolled build for rust-lang#119888
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: * `message` which provides the text for the top level error message * `label` which provides the text for the label shown inline in the broken code in the error message * `note` which provides additional notes. 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: ```rust #[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 ```rust 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](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=05133acce8e1d163d481e97631f17536) Fixes rust-lang#111996
2 parents 9c3ad80 + d013b5a commit 0443b99

27 files changed

+93
-273
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

-8
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
206206
);
207207
}
208208
}
209-
if !attr.is_doc_comment()
210-
&& let [seg, _] = attr.get_normal_item().path.segments.as_slice()
211-
&& seg.ident.name == sym::diagnostic
212-
&& !self.features.diagnostic_namespace
213-
{
214-
let msg = "`#[diagnostic]` attribute name space is experimental";
215-
gate!(self, diagnostic_namespace, seg.ident.span, msg);
216-
}
217209

218210
// Emit errors for non-staged-api crates.
219211
if !self.features.staged_api {

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ declare_features! (
146146
(accepted, derive_default_enum, "1.62.0", Some(86985)),
147147
/// Allows the use of destructuring assignments.
148148
(accepted, destructuring_assignment, "1.59.0", Some(71126)),
149+
/// Allows using the `#[diagnostic]` attribute tool namespace
150+
(accepted, diagnostic_namespace, "CURRENT_RUSTC_VERSION", Some(111996)),
149151
/// Allows `#[doc(alias = "...")]`.
150152
(accepted, doc_alias, "1.48.0", Some(50146)),
151153
/// Allows `..` in tuple (struct) patterns.

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,6 @@ declare_features! (
436436
(unstable, deprecated_safe, "1.61.0", Some(94978)),
437437
/// Allows having using `suggestion` in the `#[deprecated]` attribute.
438438
(unstable, deprecated_suggestion, "1.61.0", Some(94785)),
439-
/// Allows using the `#[diagnostic]` attribute tool namespace
440-
(unstable, diagnostic_namespace, "1.73.0", Some(111996)),
441439
/// Controls errors in trait implementations.
442440
(unstable, do_not_recommend, "1.67.0", Some(51992)),
443441
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.

library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@
202202
//
203203
// Language features:
204204
// tidy-alphabetical-start
205+
#![cfg_attr(bootstrap, feature(diagnostic_namespace))]
205206
#![cfg_attr(bootstrap, feature(platform_intrinsics))]
206207
#![feature(abi_unadjusted)]
207208
#![feature(adt_const_params)]
@@ -223,7 +224,6 @@
223224
#![feature(const_trait_impl)]
224225
#![feature(decl_macro)]
225226
#![feature(deprecated_suggestion)]
226-
#![feature(diagnostic_namespace)]
227227
#![feature(doc_cfg)]
228228
#![feature(doc_cfg_hide)]
229229
#![feature(doc_notable_trait)]

src/doc/unstable-book/src/language-features/diagnostic-namespace.md

-84
This file was deleted.

tests/ui/diagnostic_namespace/existing_proc_macros.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(diagnostic_namespace)]
21
//@ check-pass
32
//@ aux-build:proc-macro-helper.rs
43

tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.rs

-13
This file was deleted.

tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.stderr

-37
This file was deleted.

tests/ui/diagnostic_namespace/non_existing_attributes_accepted.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(diagnostic_namespace)]
21
//@ check-pass
32
#[diagnostic::non_existing_attribute]
43
//~^WARN unknown diagnostic attribute

tests/ui/diagnostic_namespace/non_existing_attributes_accepted.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
warning: unknown diagnostic attribute
2-
--> $DIR/non_existing_attributes_accepted.rs:3:15
2+
--> $DIR/non_existing_attributes_accepted.rs:2:15
33
|
44
LL | #[diagnostic::non_existing_attribute]
55
| ^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default
88

99
warning: unknown diagnostic attribute
10-
--> $DIR/non_existing_attributes_accepted.rs:8:15
10+
--> $DIR/non_existing_attributes_accepted.rs:7:15
1111
|
1212
LL | #[diagnostic::non_existing_attribute(with_option = "foo")]
1313
| ^^^^^^^^^^^^^^^^^^^^^^

tests/ui/diagnostic_namespace/on_unimplemented/auxiliary/other.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(diagnostic_namespace)]
2-
31
#[diagnostic::on_unimplemented(
42
message = "Message",
53
note = "Note",

tests/ui/diagnostic_namespace/on_unimplemented/do_not_accept_options_of_the_internal_rustc_attribute.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(diagnostic_namespace)]
2-
31
#[diagnostic::on_unimplemented(
42
on(_Self = "&str"),
53
//~^WARN malformed `on_unimplemented` attribute

0 commit comments

Comments
 (0)