Skip to content

Commit 605d0b4

Browse files
committed
---
yaml --- r: 235807 b: refs/heads/stable c: dc556be h: refs/heads/master i: 235805: 49b100b 235803: 9baff8a 235799: 557f71c 235791: c5b6c76 235775: 072bc97 v: v3
1 parent 8db00ad commit 605d0b4

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
@@ -29,7 +29,7 @@ refs/heads/tmp: afae2ff723393b3ab4ccffef6ac7c6d1809e2da0
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: f859507de8c410b648d934d8f5ec1c52daac971d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 8590501b31f4ab7d6cc1a818aa717afb5a3d4d96
32+
refs/heads/stable: dc556bef4313b59f082a1a0f7f2d30ef9cc88c0c
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/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)