diff options
| author | bors <bors@rust-lang.org> | 2024-06-05 18:40:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-06-05 18:40:07 +0000 |
| commit | 7ebd2bdbf6d798e6e711a0100981b0ff029abf5f (patch) | |
| tree | 88186c3530c163795b396dd63e3293f3d7307456 /compiler/rustc_error_codes/src | |
| parent | c1dba09f263cbff6170f130aa418e28bdf22bd96 (diff) | |
| parent | dd2e1a3b34f1ebc54f5f3507d7642b2e886d9662 (diff) | |
| download | rust-7ebd2bdbf6d798e6e711a0100981b0ff029abf5f.tar.gz rust-7ebd2bdbf6d798e6e711a0100981b0ff029abf5f.zip | |
Auto merge of #126037 - matthiaskrgr:rollup-7pz1nhr, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #124746 (`rustc --explain E0582` additional example) - #125407 (Detect when user is trying to create a lending `Iterator` and give a custom explanation) - #125505 (Add intra-doc-links to rustc_middle crate-level docs.) - #125792 (Don't drop `Unsize` candidate in intercrate mode) - #125819 (Various `HirTyLowerer` cleanups) - #125861 (rustc_codegen_ssa: fix `get_rpath_relative_to_output` panic when lib only contains file name) - #125911 (delete bootstrap build before switching to bumped rustc) - #125921 (coverage: Carve out hole spans in a separate early pass) - #125940 (std::unix::fs::get_path: using fcntl codepath for netbsd instead.) - #126022 (set `has_unconstrained_ty_var` when generalizing aliases in bivariant contexts) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_error_codes/src')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0582.md | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes/E0582.md b/compiler/rustc_error_codes/src/error_codes/E0582.md index e50cc60ea33..b2cdb509c95 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0582.md +++ b/compiler/rustc_error_codes/src/error_codes/E0582.md @@ -27,6 +27,40 @@ fn bar<F, G>(t: F, u: G) fn main() { } ``` +This error also includes the use of associated types with lifetime parameters. +```compile_fail,E0582 +trait Foo { + type Assoc<'a>; +} + +struct Bar<X, F> +where + X: Foo, + F: for<'a> Fn(X::Assoc<'a>) -> &'a i32 +{ + x: X, + f: F +} +``` +The latter scenario encounters this error because `Foo::Assoc<'a>` could be +implemented by a type that does not use the `'a` parameter, so there is no +guarentee that `X::Assoc<'a>` actually uses `'a`. + +To fix this we can pass a dummy parameter: +``` +# trait Foo { +# type Assoc<'a>; +# } +struct Bar<X, F> +where + X: Foo, + F: for<'a> Fn(X::Assoc<'a>, /* dummy */ &'a ()) -> &'a i32 +{ + x: X, + f: F +} +``` + Note: The examples above used to be (erroneously) accepted by the compiler, but this was since corrected. See [issue #33685] for more details. |
