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

Wrong error message when using Self in some places #24968

Closed
bombless opened this issue Apr 29, 2015 · 7 comments · Fixed by #25485
Closed

Wrong error message when using Self in some places #24968

bombless opened this issue Apr 29, 2015 · 7 comments · Fixed by #25485
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@bombless
Copy link
Contributor

fn foo(_: Self) {}

fn main() {}
<anon>:1:11: 1:15 error: use of undeclared type name `Self`
<anon>:1 fn foo(_: Self) {}
                   ^~~~

Self is a keyword, this error message indicates that it can be used to define type, which is misleading.

@XuefengWu
Copy link
Contributor

There is a similar issue: #12796 file.

@bombless
Copy link
Contributor Author

bombless commented May 1, 2015

No, that's a different issue.
At the time that issue was filed, Self was not a keyword, just a confusing type. That said, at the time that issue was reported, it's fine to say the compiler was implemented properly.
But my issue is about wrong error message, not bad(confusing) error message.

@XuefengWu
Copy link
Contributor

Do you mean Self is not a special ident now?
I found the example code can be compiled,

pub trait Square {
    fn square(x: Self) -> Self;
}

and there is excluding self type code。

pub fn parse_ident_or_self_type(&mut self) -> PResult<ast::Ident> {
        if self.is_self_type_ident() {
            self.expect_self_type_ident()
        } else {
            self.parse_ident()
        }
    }

https://github.com/XuefengWu/rust/blob/master/src/libsyntax/parse/parser.rs#L558-L564

@bombless
Copy link
Contributor Author

bombless commented May 3, 2015

My point is that we are in different situation now.
See #22158 and notice that it happened after the time the issue we discuss was filed.

@Manishearth
Copy link
Member

Actually, IIRC we're moving towards a direction where Self can be used everywhere in a trait or impl context. I'm not sure though. @pnkfelix any idea?

@bombless
Copy link
Contributor Author

bombless commented May 5, 2015

Yes we can use it in traits or impls.

trait T where Self: Sized {}

is totally legal for instance.

But Self inside global functions can not be explained if I understand correctly.

@Manishearth
Copy link
Member

Oh, sorry, this was a global fn. Makes sense.

bors added a commit that referenced this issue May 16, 2015
fix #24968
report more friendly error message for Self when fn args
copy from #25096
r? @nrc  @arielb1
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
Projects
None yet
4 participants