diff options
| author | bors <bors@rust-lang.org> | 2020-04-17 04:15:18 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2020-04-17 04:15:18 +0000 |
| commit | 861996e13820a2e401df60756a373606b50948e5 (patch) | |
| tree | 7b70bbcac40629669a01366657b05d910289c77b /src/librustc_error_codes/error_codes | |
| parent | 318726b301db2a0718d05f166d3d6c578273189c (diff) | |
| parent | 65243a8f7c03425c399d990d0802e4506bbcd754 (diff) | |
Auto merge of #71230 - Dylan-DPC:rollup-rofigbv, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - #70578 (Add long error explanation for E0657) - #70910 (Hides default fns inside Fuse impl to avoid exposing it to any crate) - #71164 (reword Miri validity errors: undefined -> uninitialized) - #71182 (Add some regression tests) - #71206 (Miri error messages: avoid try terminology) - #71220 (Dogfood or_patterns in the standard library) - #71225 (Fix typo in Default trait docs: Provides -> Provide) Failed merges: r? @ghost
Diffstat (limited to 'src/librustc_error_codes/error_codes')
| -rw-r--r-- | src/librustc_error_codes/error_codes/E0657.md | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/librustc_error_codes/error_codes/E0657.md b/src/librustc_error_codes/error_codes/E0657.md new file mode 100644 index 00000000000..7fe48c51147 --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0657.md @@ -0,0 +1,57 @@ +A lifetime bound on a trait implementation was captured at an incorrect place. + +Erroneous code example: + +```compile_fail,E0657 +trait Id<T> {} +trait Lt<'a> {} + +impl<'a> Lt<'a> for () {} +impl<T> Id<T> for T {} + +fn free_fn_capture_hrtb_in_impl_trait() + -> Box<for<'a> Id<impl Lt<'a>>> // error! +{ + Box::new(()) +} + +struct Foo; +impl Foo { + fn impl_fn_capture_hrtb_in_impl_trait() + -> Box<for<'a> Id<impl Lt<'a>>> // error! + { + Box::new(()) + } +} +``` + +Here, you have used the inappropriate lifetime in the `impl Trait`, +The `impl Trait` can only capture lifetimes bound at the fn or impl +level. + +To fix this we have to define the lifetime at the function or impl +level and use that lifetime in the `impl Trait`. For example you can +define the lifetime at the function: + +``` +trait Id<T> {} +trait Lt<'a> {} + +impl<'a> Lt<'a> for () {} +impl<T> Id<T> for T {} + +fn free_fn_capture_hrtb_in_impl_trait<'b>() + -> Box<for<'a> Id<impl Lt<'b>>> // ok! +{ + Box::new(()) +} + +struct Foo; +impl Foo { + fn impl_fn_capture_hrtb_in_impl_trait<'b>() + -> Box<for<'a> Id<impl Lt<'b>>> // ok! + { + Box::new(()) + } +} +``` |
