Skip to content

Commit

Permalink
Don't use main; improve example
Browse files Browse the repository at this point in the history
  • Loading branch information
aticu committed Jul 19, 2022
1 parent 1cbacc0 commit 38ea235
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
14 changes: 5 additions & 9 deletions compiler/rustc_error_codes/src/error_codes/E0283.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ impl Into<u32> for Foo {
fn into(self) -> u32 { 1 }
}
fn main() {
let foo = Foo;
let bar: u32 = foo.into() * 1u32;
}
let foo = Foo;
let bar: u32 = foo.into() * 1u32;
```

This error can be solved by adding type annotations that provide the missing
information to the compiler. In this case, the solution is to specify the
fully-qualified method:
trait's type parameter:

```
struct Foo;
Expand All @@ -26,8 +24,6 @@ impl Into<u32> for Foo {
fn into(self) -> u32 { 1 }
}
fn main() {
let foo = Foo;
let bar: u32 = <Foo as Into<u32>>::into(foo) * 1u32;
}
let foo = Foo;
let bar: u32 = Into::<u32>::into(foo) * 1u32;
```
16 changes: 6 additions & 10 deletions compiler/rustc_error_codes/src/error_codes/E0790.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ impl Generator for AnotherImpl {
fn create() -> u32 { 2 }
}
fn main() {
let cont: u32 = Generator::create();
// error, impossible to choose one of Generator trait implementation
// Should it be Impl or AnotherImpl, maybe something else?
}
let cont: u32 = Generator::create();
// error, impossible to choose one of Generator trait implementation
// Should it be Impl or AnotherImpl, maybe something else?
```

This error can be solved by adding type annotations that provide the missing
Expand All @@ -42,10 +40,8 @@ impl Generator for AnotherImpl {
fn create() -> u32 { 2 }
}
fn main() {
let gen1 = AnotherImpl::create();
let gen1 = AnotherImpl::create();
// if there are multiple methods with same name (different traits)
let gen2 = <AnotherImpl as Generator>::create();
}
// if there are multiple methods with same name (different traits)
let gen2 = <AnotherImpl as Generator>::create();
```

0 comments on commit 38ea235

Please sign in to comment.