Skip to content
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

Confusing error message with conservative impl trait #39722

Closed
iopq opened this issue Feb 10, 2017 · 2 comments
Closed

Confusing error message with conservative impl trait #39722

iopq opened this issue Feb 10, 2017 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@iopq
Copy link

iopq commented Feb 10, 2017

#![feature(conservative_impl_trait)]

fn main() {
    let mut x = &mut 1i32;
    let closure = return_closure(x);
    closure();
}


fn return_closure(x: &mut i32) -> impl Fn() {
    move || println!("{}", x)
}

this gives the error message

error[E0564]: only named lifetimes are allowed in `impl Trait`, but `` was found in the type `[closure@<anon>:11:5: 11:30 x:&mut i32]`
  --> <anon>:10:35
   |
10 | fn return_closure(x: &mut i32) -> impl Fn() {
   |                                   ^^^^^^^^^

but that's wrong, if we amend the code to

#![feature(conservative_impl_trait)]

fn main() {
    let mut x = &mut 1i32;
    let closure = return_closure(x);
    closure();
}


fn return_closure<'a>(x: &'a mut i32) -> impl Fn() {
    move || println!("{}", x)
}

it compiles and runs just fine, so the previous error message is incorrect

@frewsxcv frewsxcv added the A-diagnostics Area: Messages for errors, warnings, and lints label Feb 11, 2017
@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@gnzlbg
Copy link
Contributor

gnzlbg commented Aug 30, 2017

Duplicate of #38615

@cramertj
Copy link
Member

cramertj commented Jan 5, 2018

This is fixed.

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 C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants