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

Function-local types are not resolved #1559

Closed
lnicola opened this issue Jul 20, 2019 · 13 comments
Closed

Function-local types are not resolved #1559

lnicola opened this issue Jul 20, 2019 · 13 comments
Labels
S-actionable Someone could pick this issue up and work on it right now

Comments

@lnicola
Copy link
Member

lnicola commented Jul 20, 2019

fn main() {
    struct S;
    let _s = S;
}

Same for type aliases. Found in #1549.

@matklad
Copy link
Member

matklad commented Jul 20, 2019

Yeah, we just don't support local items at all yet :(

@flodiebold
Copy link
Member

See #1165.

@crumblingstatue
Copy link

Funny, the original example now seems to resolve, but not if it's a record struct.

@lnicola
Copy link
Member Author

lnicola commented Jul 20, 2020

Hmm, maybe #2600 partially implemented this.

Actually, record structs work too, but not e.g. arrays of them. Actually nope.

@crumblingstatue
Copy link

It doesn't work, at least for me.
I did the array thing because if I just do let foo = Bar{};, it shows nothing instead of {unknown}. But if you hover over it, it will still say {unknown}.
image

@ice1000
Copy link
Contributor

ice1000 commented Jul 21, 2020

It doesn't work, at least for me.
I did the array thing because if I just do let foo = Bar{};, it shows nothing instead of {unknown}. But if you hover over it, it will still say {unknown}.
image

Can you fix this?

@lnicola
Copy link
Member Author

lnicola commented Jul 24, 2020

It doesn't work, at least for me.

I think you're right. I wonder why unit and tuple structs work but not record ones.

Can you fix this?

I wish :-).

@pksunkara
Copy link
Contributor

I am not sure if this is the same issue or not, but my gut says it is. Please correct me if I am wrong and I will create a new one. In the below working code, a.foo() doesn't resolve to a type. As you can see impl A { fn foo() } is actually inside a dummy mod. (This is one of pattern some derives use to reduce share some common stuff without exposing it to the user).

main_rs_—_nested

@lnicola
Copy link
Member Author

lnicola commented Nov 10, 2020

Yeah, it looks like the same issue.

@flodiebold
Copy link
Member

flodiebold commented Nov 11, 2020

That (a local impl used outside that block) is actually a special case that might never be supported by RA, and IMO should be deprecated in the language. We don't want to have to parse all function (or constant) bodies just because they might contain an impl that we need; this would have a bad impact on lazyness.

This is one of pattern some derives use to reduce share some common stuff without exposing it to the user

If the impl is only used in that block, that's fine, but I don't see the point otherwise.

@pksunkara
Copy link
Contributor

pksunkara commented Nov 11, 2020

I agree about the impact but I think we should partially support this, i.e. only if we encounter them in const items.

I don't think there's another way to solve the issue of scoping restrictions in expanded proc-macros.

@flodiebold
Copy link
Member

I don't think there's another way to solve the issue of scoping restrictions in expanded proc-macros.

Again, I don't see the point. Note that we certainly want to support using impls defined in the same block. But if you're relying on the fact that impls in blocks are available outside of that block, I don't see how that's solving any scoping issue.

@jonas-schievink
Copy link
Contributor

Fixed by #7614 / #7627

The issue with const _: () = { ... }; that @pksunkara mentioned is now tracked in #7550

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-actionable Someone could pick this issue up and work on it right now
Projects
None yet
Development

No branches or pull requests

7 participants