Skip to content

E0121 suggestion just causes another problem "non-defining opaque type use in defining scope" with no good suggestion #106858

Open
@matthiaskrgr

Description

@matthiaskrgr

Given the following code:

#![feature(type_alias_impl_trait)]

type Pointer<T> = impl std::ops::Deref<Target=T>;

fn test() -> Pointer<_> {
    //~^ ERROR: the placeholder `_` is not allowed within types
    Box::new(1)
}

fn main() {
    test();
}

The current output is:

error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
 --> src/main.rs:5:22
  |
5 | fn test() -> Pointer<_> {
  |              --------^-
  |              |       |
  |              |       not allowed in type signatures
  |              help: replace with the correct return type: `Pointer<i32>`

For more information about this error, try `rustc --explain E0121`.

Applying this gives us

#![feature(type_alias_impl_trait)]

type Pointer<T> = impl std::ops::Deref<Target=T>;

fn test() -> Pointer<i32> {
    //~^ ERROR: the placeholder `_` is not allowed within types
    Box::new(1)
}

fn main() {
    test();
}

Which has a even more vague description and no error index to look up details :/

error: non-defining opaque type use in defining scope
 --> src/main.rs:7:5
  |
7 |     Box::new(1)
  |     ^^^^^^^^^^^
  |
note: used non-generic type `i32` for generic parameter
 --> src/main.rs:3:14
  |
3 | type Pointer<T> = impl std::ops::Deref<Target=T>;
  |              ^

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

Status

Can do after stabilization

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions