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

Account for associated type, const and static when using type argument #62004

Closed
wants to merge 2 commits into from

Conversation

estebank
Copy link
Contributor

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.

@rust-highfive
Copy link
Contributor

r? @cramertj

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 20, 2019
@estebank estebank force-pushed the type-param-in-const branch from 495a620 to 7932b04 Compare June 20, 2019 19:37
@@ -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,
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Member

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)

estebank added 2 commits July 6, 2019 09:34
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.
@estebank estebank force-pushed the type-param-in-const branch from 7932b04 to 7515e71 Compare July 6, 2019 17:13
@bors
Copy link
Collaborator

bors commented Jul 7, 2019

☔ 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
Copy link
Contributor

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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"{} need a type instead of a generic parameter",
"{} needs a type instead of a generic parameter",

@totsteps
Copy link
Member

ping from triage @estebank any updates on this?

@totsteps
Copy link
Member

ping from triage @cramertj this PR is waiting for your review?

@estebank
Copy link
Contributor Author

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.

@Alexendoo Alexendoo added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 7, 2019
@estebank
Copy link
Contributor Author

estebank commented Aug 7, 2019

Closing, I'll reopen when I get back to this.

@estebank estebank closed this Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad error message using associated type
8 participants