-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
forbid impl Trait
in generic param defaults
#83935
Conversation
r? @varkor (rust-highfive has picked a reviewer for you, use r? to override) |
error[E0720]: cannot resolve opaque type | ||
--> $DIR/where-allowed.rs:56:49 | ||
| | ||
LL | fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic!() } | ||
| ^^^^^^^^^^^^^^^^^^^ -------- this returned value is of `!` type | ||
| | | ||
| cannot resolve opaque type | ||
| | ||
= help: this error will resolve once the item's body returns a concrete type | ||
|
||
error[E0720]: cannot resolve opaque type | ||
--> $DIR/where-allowed.rs:62:46 | ||
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions | ||
--> $DIR/where-allowed.rs:234:7 | ||
| | ||
LL | fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { panic!() } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ -------- this returned value is of `!` type | ||
| | | ||
| cannot resolve opaque type | ||
LL | impl <T = impl Debug> T {} | ||
| ^ | ||
| | ||
= help: this error will resolve once the item's body returns a concrete type | ||
= note: `#[deny(invalid_type_param_default)]` on by default | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887> | ||
|
||
error: could not find defining uses | ||
--> $DIR/where-allowed.rs:121:16 | ||
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions | ||
--> $DIR/where-allowed.rs:240:36 | ||
| | ||
LL | type Out = impl Debug; | ||
| ^^^^^^^^^^ | ||
|
||
error: could not find defining uses | ||
--> $DIR/where-allowed.rs:157:23 | ||
LL | fn in_method_generic_param_default<T = impl Debug>(_: T) {} | ||
| ^ | ||
| | ||
LL | type InTypeAlias<R> = impl Debug; | ||
| ^^^^^^^^^^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these errors disappeared because hitting the invalid_type_param_default
future compat lint is making the compiler abort earlier.
I agree that this ought always to have been an error; it must have been an oversight. Thanks for fixing this. @bors r+ |
📌 Commit ee79f83 has been approved by |
… r=varkor forbid `impl Trait` in generic param defaults Fixes rust-lang#83929 Forbid using `impl Trait` in the default types of generic parameters, e.g. `struct Foo<T = impl Trait>`. I assume this was never supposed to be allowed - it seems no UI test used it. Note that using `impl Trait` in this position did not hit a feature gate error; however, this *shouldn't* be a breaking change as any attempt to use it should have hit the ICE in rust-lang#83929 and/or failed to provide a defining use of the `impl Trait`.
Rollup of 8 pull requests Successful merges: - rust-lang#83476 (Add strong_count mutation methods to Rc) - rust-lang#83634 (Do not emit the advanced diagnostics on macros) - rust-lang#83816 (Trigger `unused_doc_comments` on macros at once) - rust-lang#83916 (Use AnonConst for asm! constants) - rust-lang#83935 (forbid `impl Trait` in generic param defaults) - rust-lang#83936 (Disable using non-ascii identifiers in extern blocks.) - rust-lang#83945 (Add suggestion to reborrow mutable references when they're moved in a for loop) - rust-lang#83954 (Do not ICE when closure is involved in Trait Alias Impl Trait) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fixes #83929
Forbid using
impl Trait
in the default types of generic parameters, e.g.struct Foo<T = impl Trait>
. I assume this was never supposed to be allowed - it seems no UI test used it.Note that using
impl Trait
in this position did not hit a feature gate error; however, this shouldn't be a breaking change as any attempt to use it should have hit the ICE in #83929 and/or failed to provide a defining use of theimpl Trait
.