diff options
| author | bors <bors@rust-lang.org> | 2022-07-19 13:49:56 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-07-19 13:49:56 +0000 |
| commit | a289cfcfb32593c63d75f113547f63ffe2dde285 (patch) | |
| tree | a54aeb4086ab0399fd43dcb0724f0eb26deb91c9 /compiler/rustc_error_codes | |
| parent | 8bd12e8cca3f28f302b9cc0f1f47bb64bd1f98fd (diff) | |
| parent | e6904fc5b24a10e97d0a32908f49886e52e73990 (diff) | |
| download | rust-a289cfcfb32593c63d75f113547f63ffe2dde285.tar.gz rust-a289cfcfb32593c63d75f113547f63ffe2dde285.zip | |
Auto merge of #99462 - matthiaskrgr:rollup-ihhwaru, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - #98028 (Add E0790 as more specific variant of E0283) - #99384 (use body's param-env when checking if type needs drop) - #99401 (Avoid `Symbol` to `&str` conversions) - #99419 (Stabilize `core::task::ready!`) - #99435 (Revert "Stabilize $$ in Rust 1.63.0") - #99438 (Improve suggestions for `NonZeroT` <- `T` coercion error) - #99441 (Update mdbook) - #99453 (:arrow_up: rust-analyzer) - #99457 (use `par_for_each_in` in `par_body_owners` and `collect_crate_mono_items`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_error_codes')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0283.md | 45 | ||||
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0790.md | 47 |
3 files changed, 60 insertions, 33 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index 977318b8589..97766b8368a 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -492,6 +492,7 @@ E0785: include_str!("./error_codes/E0785.md"), E0786: include_str!("./error_codes/E0786.md"), E0787: include_str!("./error_codes/E0787.md"), E0788: include_str!("./error_codes/E0788.md"), +E0790: include_str!("./error_codes/E0790.md"), ; // E0006, // merged with E0005 // E0008, // cannot bind by-move into a pattern guard diff --git a/compiler/rustc_error_codes/src/error_codes/E0283.md b/compiler/rustc_error_codes/src/error_codes/E0283.md index 6885f9a486d..79d2c8204f9 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0283.md +++ b/compiler/rustc_error_codes/src/error_codes/E0283.md @@ -3,48 +3,27 @@ An implementation cannot be chosen unambiguously because of lack of information. Erroneous code example: ```compile_fail,E0283 -trait Generator { - fn create() -> u32; -} - -struct Impl; - -impl Generator for Impl { - fn create() -> u32 { 1 } -} - -struct AnotherImpl; +struct Foo; -impl Generator for AnotherImpl { - fn create() -> u32 { 2 } +impl Into<u32> for Foo { + fn into(self) -> u32 { 1 } } -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 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 use a concrete -type: +information to the compiler. In this case, the solution is to specify the +trait's type parameter: ``` -trait Generator { - fn create() -> u32; -} - -struct AnotherImpl; +struct Foo; -impl Generator for AnotherImpl { - fn create() -> u32 { 2 } +impl Into<u32> for Foo { + fn into(self) -> u32 { 1 } } -fn main() { - let gen1 = AnotherImpl::create(); - - // if there are multiple methods with same name (different traits) - let gen2 = <AnotherImpl as Generator>::create(); -} +let foo = Foo; +let bar: u32 = Into::<u32>::into(foo) * 1u32; ``` diff --git a/compiler/rustc_error_codes/src/error_codes/E0790.md b/compiler/rustc_error_codes/src/error_codes/E0790.md new file mode 100644 index 00000000000..2aee9dfbdbd --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0790.md @@ -0,0 +1,47 @@ +You need to specify a specific implementation of the trait in order to call the +method. + +Erroneous code example: + +```compile_fail,E0790 +trait Generator { + fn create() -> u32; +} + +struct Impl; + +impl Generator for Impl { + fn create() -> u32 { 1 } +} + +struct AnotherImpl; + +impl Generator for AnotherImpl { + fn create() -> u32 { 2 } +} + +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 +information to the compiler. In this case, the solution is to use a concrete +type: + +``` +trait Generator { + fn create() -> u32; +} + +struct AnotherImpl; + +impl Generator for AnotherImpl { + fn create() -> u32 { 2 } +} + +let gen1 = AnotherImpl::create(); + +// if there are multiple methods with same name (different traits) +let gen2 = <AnotherImpl as Generator>::create(); +``` |
