Skip to content

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

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

Open
matthiaskrgr opened this issue Jan 14, 2023 · 1 comment
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

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>;
  |              ^
@matthiaskrgr matthiaskrgr added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 14, 2023
@compiler-errors
Copy link
Member

Unrelated to this diagnostic "bug", @oli-obk I think "non-defining opaque type use in defining scope" could use an error code and an explain since TAIT is being stabilized.

@oli-obk oli-obk self-assigned this Jan 16, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 16, 2023
Improve a TAIT error and add an error code plus documentation

cc rust-lang#106858
@oli-obk oli-obk moved this from In Progress to Todo in type alias impl trait stabilization Aug 4, 2023
@oli-obk oli-obk moved this from Todo to Can do after stabilization in type alias impl trait stabilization Aug 11, 2023
@inquisitivecrystal inquisitivecrystal moved this from Can do after stabilization to Todo in type alias impl trait stabilization Aug 27, 2023
@inquisitivecrystal inquisitivecrystal moved this from Todo to Can do after stabilization in type alias impl trait stabilization Aug 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
Status: Can do after stabilization
Development

No branches or pull requests

3 participants