Skip to content

Conversation

SNCPlay42
Copy link
Contributor

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 the impl Trait.

@rust-highfive
Copy link
Contributor

r? @varkor

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 6, 2021
Comment on lines -258 to -288
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;
| ^^^^^^^^^^
Copy link
Contributor Author

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.

@varkor
Copy link
Contributor

varkor commented Apr 7, 2021

I agree that this ought always to have been an error; it must have been an oversight. Thanks for fixing this.

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 7, 2021

📌 Commit ee79f83 has been approved by varkor

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 7, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 7, 2021
… 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`.
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 7, 2021
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
@bors bors merged commit d554385 into rust-lang:master Apr 7, 2021
@rustbot rustbot added this to the 1.53.0 milestone Apr 7, 2021
@SNCPlay42 SNCPlay42 deleted the param-default-impl-trait branch April 18, 2021 01:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

type parameter E/#1 (E/1) out of range when substituting
5 participants