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

Provide more context when denying invalid type params #97471

Merged
merged 7 commits into from
Jun 3, 2022

Conversation

estebank
Copy link
Contributor

No description provided.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 28, 2022
@rust-highfive
Copy link
Collaborator

r? @cjgillot

(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 May 28, 2022
@rust-log-analyzer

This comment was marked as resolved.

Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

The logic does not seem straightforward, so I have a lot of questions.

compiler/rustc_typeck/src/astconv/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_typeck/src/astconv/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_typeck/src/astconv/mod.rs Show resolved Hide resolved
compiler/rustc_typeck/src/astconv/mod.rs Show resolved Hide resolved
compiler/rustc_typeck/src/astconv/mod.rs Show resolved Hide resolved
let suggestion = vec![
if is_self {
// Account for people writing `Self::Variant::<Args>`, where
// `Self` is the enum.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand the relation between this comment and the match above which defines is_self.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Expanded the comment

@@ -2017,69 +2017,79 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.normalize_ty(span, tcx.mk_projection(item_def_id, item_substs))
}

pub fn prohibit_generics<'a, T: IntoIterator<Item = &'a hir::PathSegment<'a>>>(
pub fn prohibit_generics<'a, T: Iterator<Item = &'a hir::PathSegment<'a>> + Clone>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't T always a slice &[&hir::PathSegment<'_>]? Can't we just take this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried doing that. It isn't, there are a couple of callers that pass in an Iterator after skipping a few things. I think at least one uses filter_map, which isn't amenable to a direct subslicing approach.

@@ -681,7 +681,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
trait_ref: &hir::TraitRef<'_>,
self_ty: Ty<'tcx>,
) -> ty::TraitRef<'tcx> {
self.prohibit_generics(trait_ref.path.segments.split_last().unwrap().1);
self.prohibit_generics(trait_ref.path.segments.split_last().unwrap().1.iter());
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit (pre-existing): an explicit slice may be easier to read.

@@ -784,7 +784,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let args = trait_segment.args();
let infer_args = trait_segment.infer_args;

self.prohibit_generics(trait_ref.path.segments.split_last().unwrap().1);
self.prohibit_generics(trait_ref.path.segments.split_last().unwrap().1.iter());
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise.

compiler/rustc_typeck/src/astconv/mod.rs Show resolved Hide resolved
@rust-log-analyzer

This comment was marked as resolved.

* Confirm the path segment being modified is an `enum`
* Check whether type has type param before suggesting changing `Self`
* Wording changes
* Add clarifying comments
* Suggest removing args from `Self` if the type doesn't have type params
@rust-log-analyzer

This comment was marked as resolved.

@cjgillot
Copy link
Contributor

cjgillot commented Jun 3, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jun 3, 2022

📌 Commit cd8cfbf has been approved by cjgillot

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 3, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 3, 2022
Provide more context when denying invalid type params
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 3, 2022
Rollup of 3 pull requests

Successful merges:

 - rust-lang#97415 (Compute `is_late_bound_map` query separately from lifetime resolution)
 - rust-lang#97471 (Provide more context when denying invalid type params )
 - rust-lang#97681 (Add more eslint checks)

Failed merges:

 - rust-lang#97446 (Make hir().get_generics and generics_of consistent.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6b80b15 into rust-lang:master Jun 3, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 3, 2022
@estebank estebank deleted the prohibit-generics branch November 9, 2023 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants