-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Account for associated type, const and static when using type argument #62004
Conversation
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
495a620
to
7932b04
Compare
@@ -1691,6 +1745,9 @@ pub struct Resolver<'a> { | |||
current_type_ascription: Vec<Span>, | |||
|
|||
injected_crate: Option<Module<'a>>, | |||
|
|||
/// Used for more accurate error when using type parameters in a associated items. | |||
scope: CurrentScope, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use some other terminology than "scope", it's incredibly overloaded in resolve.
Also, could you move enum CurrentScope
and its impls into diagnostics.rs
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be a better name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BodyOwner
/ DefOwner
maybe? (though Def
is similarly unfortunately overloaded)
When using a type argument from the enclosing scope in an associated type, const or static item provide a more targetted E0401 error, instead of blaming the "outer function" blindly.
7932b04
to
7515e71
Compare
☔ The latest upstream changes (presumably #62467) made this pull request unmergeable. Please resolve the merge conflicts. |
//~^ ERROR can't use generic parameters in a `const` | ||
//~| ERROR can't use generic parameters in a `const` | ||
type Type = T; | ||
//~^ ERROR can't use generic parameters in associated type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here Type
is not an associated type alias but rather a free type alias.
if let Some((sugg_span, new_snippet)) = cm.generate_local_type_param_snippet(span) { | ||
if !resolver.scope.is_other() { | ||
err.help(&format!( | ||
"{} need a type instead of a generic parameter", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"{} need a type instead of a generic parameter", | |
"{} needs a type instead of a generic parameter", |
ping from triage @estebank any updates on this? |
ping from triage @cramertj this PR is waiting for your review? |
I have some WIP code in my local branch to address some of the comments and will need a rebase. I won't be getting to it until at least the weekend. |
Closing, I'll reopen when I get back to this. |
When using a type argument from the enclosing scope in an associated type,
const or static item provide a more targetted E0401 error, instead of
blaming the "outer function" blindly.
Fix #45447.