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

Handle mismatched generic param kinds in trait impls betterly #96717

Merged
merged 5 commits into from
May 10, 2022

Conversation

BoxyUwU
Copy link
Member

@BoxyUwU BoxyUwU commented May 4, 2022

  • Check that generic params on a generic associated type are the same as in the trait definition
  • Check that const generics are not used in place of type generics (and the other way round too)

r? @lcnr

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 4, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 4, 2022
@BoxyUwU BoxyUwU added the A-const-generics Area: const generics (parameters and arguments) label May 4, 2022
@lcnr
Copy link
Contributor

lcnr commented May 5, 2022

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 5, 2022

📌 Commit 52916657e53bfd5f91190953708120a5be5b2641 has been approved by lcnr

@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 May 5, 2022
@BoxyUwU
Copy link
Member Author

BoxyUwU commented May 5, 2022

@bors r-

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 5, 2022
@BoxyUwU BoxyUwU force-pushed the gats_const_param_types_mismatch_err branch from 5291665 to e64b4d1 Compare May 5, 2022 12:02
@BoxyUwU BoxyUwU changed the title Check const param tys in gats in trait impls Handle mismatched generic param kinds in trait impls betterly May 5, 2022
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

can you add a test for the following? after that r=me

trait Trait {
    fn func<U, const N: usize>() {}
}
impl Trait for () {
    fn func<const N: usize, U>() {}
}

@BoxyUwU BoxyUwU force-pushed the gats_const_param_types_mismatch_err branch from 7ee1b25 to 0cf7604 Compare May 5, 2022 14:17
@BoxyUwU BoxyUwU force-pushed the gats_const_param_types_mismatch_err branch from 0cf7604 to fea1d76 Compare May 5, 2022 16:51
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

2 more nits, then r=me

compiler/rustc_typeck/src/check/compare_method.rs Outdated Show resolved Hide resolved
} {
let make_param_message = |prefix: &str, param: &ty::GenericParamDef| match param.kind {
Const { .. } => {
format!("{} const parameter with type `{}`", prefix, tcx.type_of(param.def_id))
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
format!("{} const parameter with type `{}`", prefix, tcx.type_of(param.def_id))
format!("{} const parameter of type `{}`", prefix, tcx.type_of(param.def_id))

For me "of type" seems more natural here, idk 😅

Considering that this closure doesn't capture anything, can you move it out of the loop to ty_const_params_of?

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed the error wording.

I don't think it'd be good to have the closure be by ty_const_params_of since then its really far away from the code actually calling the closure. I pushed code moving it furthur down so its closer to the call site, imo makes it easier to understand the code.

@lcnr
Copy link
Contributor

lcnr commented May 10, 2022

@bors r+ rollup

@bors
Copy link
Contributor

bors commented May 10, 2022

📌 Commit e4b8ed5 has been approved by lcnr

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 10, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request May 10, 2022
Rollup of 6 pull requests

Successful merges:

 - rust-lang#96717 (Handle mismatched generic param kinds in trait impls betterly)
 - rust-lang#96725 (Expose process windows_process_extensions_main_thread_handle on Windows)
 - rust-lang#96849 (Move some tests to more reasonable places)
 - rust-lang#96861 (Use Rust 2021 prelude in std itself.)
 - rust-lang#96879 (rustdoc: search result ranking fix)
 - rust-lang#96882 (Don't subst an AdtDef with its own substs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 77030b7 into rust-lang:master May 10, 2022
@rustbot rustbot added this to the 1.62.0 milestone May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) 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.

5 participants