-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Use of Self::SOME_ASSOC_CONST
inside a function-local const
calls Self
a "generic parameter from outer function"
#109596
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Alternatively, perhaps this should work. |
That would require desugaring the const item into an associated const, which seems like a lot of complexity. |
Yeah, that seems like a lang decision anyway. And it's mostly irrelevant if the error message is improved (esp. to suggest a fix in the cases it's just "change Self to the type name"). |
I think it's expected that this is an error -- if the person wants to use So updating the message for extra clarity is the way to go. |
got similar weird error today struct Test {}
impl Test {
pub fn static_fn() {}
pub fn test() {
fn nested_fn() {
Self::static_fn();
}
nested_fn();
}
}
I don't think |
… r=<try> Improve 'generic param from outer item' error for `Self` and inside `static`/`const` items Fixes rust-lang#109596 Fixes rust-lang#119936
…e, r=compiler-errors Improve 'generic param from outer item' error for `Self` and inside `static`/`const` items Fixes rust-lang#109596 Fixes rust-lang#119936
…e, r=compiler-errors Improve 'generic param from outer item' error for `Self` and inside `static`/`const` items Fixes rust-lang#109596 Fixes rust-lang#119936
Rollup merge of rust-lang#119939 - clubby789:static-const-generic-note, r=compiler-errors Improve 'generic param from outer item' error for `Self` and inside `static`/`const` items Fixes rust-lang#109596 Fixes rust-lang#119936
Code
Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=01d9dd114b740509a3538ce91aa2bf6a.
A slightly more realistic (but also slightly larger) example is here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=01d9dd114b740509a3538ce91aa2bf6a (this is more or less code that I tried to emit from a macro).
Current output
Desired output
error[...]: can't use `Self` type inside function-local `const`.
Or something. I don't have strong feelings.
It should probably suggest replacing
Self::COUNT
withFoo::COUNT
though, since that's enough to fix this.Rationale and extra context
Self
here is not a generic parameter from the outer function (it's the implementing type from theimpl
block, although I'm not really sure that's a particularly clear way to refer to it either). Either way, the current message is wrong and misleading.Anything else?
Happens on nightly (
rustc 1.70.0-nightly (8be3c2bda 2023-03-24)
) and on stable (1.68.1).The text was updated successfully, but these errors were encountered: