Skip to content

Commit c45baf6

Browse files
committed
---
yaml --- r: 224224 b: refs/heads/beta c: dc556be h: refs/heads/master v: v3
1 parent 6d2fb50 commit c45baf6

File tree

2 files changed

+78
-5
lines changed

2 files changed

+78
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 8590501b31f4ab7d6cc1a818aa717afb5a3d4d96
26+
refs/heads/beta: dc556bef4313b59f082a1a0f7f2d30ef9cc88c0c
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: 938f5d7af401e2d8238522fed4a612943b6e77fd
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc/diagnostics.rs

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,8 +1359,84 @@ for v in &vs {
13591359
"##,
13601360

13611361
E0272: r##"
1362+
The `#[rustc_on_unimplemented]` attribute lets you specify a custom error
1363+
message for when a particular trait isn't implemented on a type placed in a
1364+
position that needs that trait. For example, when the following code is
1365+
compiled:
13621366
1363-
The `#[rustc_on_unimplemented]` attribute lets you specify
1367+
```
1368+
fn foo<T: Index<u8>>(x: T){}
1369+
1370+
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
1371+
trait Index<Idx> { ... }
1372+
1373+
foo(true); // `bool` does not implement `Index<u8>`
1374+
```
1375+
1376+
there will be an error about `bool` not implementing `Index<u8>`, followed by a
1377+
note saying "the type `bool` cannot be indexed by `u8`".
1378+
1379+
As you can see, you can specify type parameters in curly braces for substitution
1380+
with the actual types (using the regular format string syntax) in a given
1381+
situation. Furthermore, `{Self}` will substitute to the type (in this case,
1382+
`bool`) that we tried to use.
1383+
1384+
This error appears when the curly braces contain an identifier which doesn't
1385+
match with any of the type parameters or the string `Self`. This might happen if
1386+
you misspelled a type parameter, or if you intended to use literal curly braces.
1387+
If it is the latter, escape the curly braces with a second curly brace of the
1388+
same type; e.g. a literal `{` is `{{`
1389+
"##,
1390+
1391+
E0273: r##"
1392+
The `#[rustc_on_unimplemented]` attribute lets you specify a custom error
1393+
message for when a particular trait isn't implemented on a type placed in a
1394+
position that needs that trait. For example, when the following code is
1395+
compiled:
1396+
1397+
```
1398+
fn foo<T: Index<u8>>(x: T){}
1399+
1400+
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
1401+
trait Index<Idx> { ... }
1402+
1403+
foo(true); // `bool` does not implement `Index<u8>`
1404+
```
1405+
1406+
there will be an error about `bool` not implementing `Index<u8>`, followed by a
1407+
note saying "the type `bool` cannot be indexed by `u8`".
1408+
1409+
As you can see, you can specify type parameters in curly braces for substitution
1410+
with the actual types (using the regular format string syntax) in a given
1411+
situation. Furthermore, `{Self}` will substitute to the type (in this case,
1412+
`bool`) that we tried to use.
1413+
1414+
This error appears when the curly braces do not contain an identifier. Please
1415+
add one of the same name as a type parameter. If you intended to use literal
1416+
braces, use `{{` and `}}` to escape them.
1417+
"##,
1418+
1419+
E0273: r##"
1420+
The `#[rustc_on_unimplemented]` attribute lets you specify a custom error
1421+
message for when a particular trait isn't implemented on a type placed in a
1422+
position that needs that trait. For example, when the following code is
1423+
compiled:
1424+
1425+
```
1426+
fn foo<T: Index<u8>>(x: T){}
1427+
1428+
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
1429+
trait Index<Idx> { ... }
1430+
1431+
foo(true); // `bool` does not implement `Index<u8>`
1432+
```
1433+
1434+
there will be an error about `bool` not implementing `Index<u8>`, followed by a
1435+
note saying "the type `bool` cannot be indexed by `u8`".
1436+
1437+
For this to work, some note must be specified. An empty attribute will not do
1438+
anything, please remove the attribute or add some helpful note for users of the
1439+
trait.
13641440
"##,
13651441

13661442
E0277: r##"
@@ -1787,9 +1863,6 @@ register_diagnostics! {
17871863
// E0134,
17881864
// E0135,
17891865
E0264, // unknown external lang item
1790-
E0272, // rustc_on_unimplemented attribute refers to non-existent type parameter
1791-
E0273, // rustc_on_unimplemented must have named format arguments
1792-
E0274, // rustc_on_unimplemented must have a value
17931866
E0275, // overflow evaluating requirement
17941867
E0276, // requirement appears on impl method but not on corresponding trait method
17951868
E0278, // requirement is not satisfied

0 commit comments

Comments
 (0)