forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#116621 - aliemjay:rollup-0e2of3c, r=aliemjay
Rollup of 4 pull requests Successful merges: - rust-lang#95967 (Add explicit-endian String::from_utf16 variants) - rust-lang#116530 (delay a bug when encountering an ambiguity in MIR typeck) - rust-lang#116611 (Document `diagnostic_namespace` feature) - rust-lang#116612 (Remove unused dominator iterator) r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
6 changed files
with
275 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/doc/unstable-book/src/language-features/diagnostic-namespace.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# `diagnostic_namespace` | ||
|
||
The tracking issue for this feature is: [#111996] | ||
|
||
[#111996]: https://github.com/rust-lang/rust/issues/111996 | ||
|
||
------------------------ | ||
|
||
The `diagnostic_namespace` feature permits customization of compilation errors. | ||
|
||
## diagnostic::on_unimplemented | ||
|
||
With [#114452] support for `diagnostic::on_unimplemented` was added. | ||
|
||
When used on a trait declaration, the following options are available: | ||
|
||
* `message` to customize the primary error message | ||
* `note` to add a customized note message to an error message | ||
* `label` to customize the label part of the error message | ||
|
||
The attribute will hint to the compiler to use these in error messages: | ||
```rust | ||
// some library | ||
#![feature(diagnostic_namespace)] | ||
|
||
#[diagnostic::on_unimplemented( | ||
message = "cannot insert element", | ||
label = "cannot be put into a table", | ||
note = "see <link> for more information about the Table api" | ||
)] | ||
pub trait Element { | ||
// ... | ||
} | ||
``` | ||
|
||
```rust,compile_fail,E0277 | ||
# #![feature(diagnostic_namespace)] | ||
# | ||
# #[diagnostic::on_unimplemented( | ||
# message = "cannot insert element", | ||
# label = "cannot be put into a table", | ||
# note = "see <link> for more information about the Table api" | ||
# )] | ||
# pub trait Element { | ||
# // ... | ||
# } | ||
# struct Table; | ||
# impl Table { | ||
# fn insert<T: Element>(&self, element: T) { | ||
# // .. | ||
# } | ||
# } | ||
# fn main() { | ||
# let table = Table; | ||
# let element = (); | ||
// user code | ||
table.insert(element); | ||
# } | ||
``` | ||
|
||
```text | ||
error[E0277]: cannot insert element | ||
--> src/main.rs:24:18 | ||
| | ||
24 | table.insert(element); | ||
| ------ ^^^^^^^ cannot be put into a table | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: the trait `Element` is not implemented for `<type>` | ||
= note: see <link> for more information about the Table api | ||
note: required by a bound in `Table::insert` | ||
--> src/main.rs:15:18 | ||
| | ||
15 | fn insert<T: Element>(&self, element: T) { | ||
| ^^^^^^^ required by this bound in `Table::insert` | ||
For more information about this error, try `rustc --explain E0277`. | ||
``` | ||
|
||
See [RFC 3368] for more information. | ||
|
||
[#114452]: https://github.com/rust-lang/rust/pull/114452 | ||
[RFC 3368]: https://github.com/rust-lang/rfcs/blob/master/text/3368-diagnostic-attribute-namespace.md |
20 changes: 20 additions & 0 deletions
20
tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.current.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: internal compiler error: no errors encountered even though `delay_span_bug` issued | ||
|
||
error: internal compiler error: ambiguity performing ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: ProvePredicate { predicate: Binder { value: ProjectionPredicate(AliasTy { args: [FnDef(DefId(get_rpit), []), ()], def_id: DefId(ops::function::FnOnce::Output) }, Term::Ty(Alias(Opaque, AliasTy { args: [], def_id: DefId(Opaque::{opaque#0}) }))), bound_vars: [] } } } | ||
--> $DIR/rpit_tait_equality_in_canonical_query.rs:28:5 | ||
| | ||
LL | query(get_rpit); | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
--> $DIR/rpit_tait_equality_in_canonical_query.rs:28:5 | ||
| | ||
LL | query(get_rpit); | ||
| ^^^^^^^^^^^^^^^ | ||
|
||
|
||
|
||
|
||
query stack during panic: | ||
end of query stack | ||
error: aborting due to 2 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters