Skip to content

Weird error message when returning an &'r T #12187

Closed
@TethysSvensson

Description

@TethysSvensson

This program causes an internal compiler error:

fn new<T>() -> &'static T {
  fail!("placeholder")
}

fn main() {
  let &v = new();
}

I get this error, when compiling it:

error: internal compiler error: ty_region() invoked on in appropriate ty: &ty_err
  • The problem disappears, if I force the type of v.
  • A more reasonable error message appears if I write let v = new(); instead.
  • It remains, if I replace the signature with fn new<'r, T>() -> &'r T.
  • It also remain if I replace the type signature with fn new<T>() -> Option<&'static T> and alter main accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions