Skip to content

Deriving: Include bound generic params in type parameters for where clause#89341

Merged
bors merged 4 commits into
rust-lang:masterfrom
audunhalland:derive-type-params-with-bound-generic-params
Oct 2, 2021
Merged

Deriving: Include bound generic params in type parameters for where clause#89341
bors merged 4 commits into
rust-lang:masterfrom
audunhalland:derive-type-params-with-bound-generic-params

Conversation

@audunhalland

@audunhalland audunhalland commented Sep 28, 2021

Copy link
Copy Markdown
Contributor

Fixes #89188.

The derive macro ignored the for<'s> needed with the Fn trait in that code example.

edit: I'm unsure if this might cause regressions. I'm not an experienced compiler developer so I'm not used to thinking about unwanted side effects code changes like this might have.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @matthewjasper

(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 Sep 28, 2021
@jackh726

Copy link
Copy Markdown
Member

r? @jackh726

Comment thread compiler/rustc_builtin_macros/src/deriving/generic/mod.rs Outdated
@jackh726

Copy link
Copy Markdown
Member

I think this looks correct. I was trying to come up with an example without GATs where we could run into this case, but I haven't been able to yet. We basically have to name a late-bound lifetime within the type but without also being required to name it outside. (So, <T as Trait<'a>::As wouldn't work, because we would need a T: Trait<'a> bound).

I think I'd like to see the following added to the test:

trait CallWithShim2: Sized {
    type Shim<T>;
}

struct S<'s>(&'s ());

#[derive(Clone)]
struct ShimMethod2<T: CallWithShim2 + 'static>(
    pub &'static dyn for<'s> Fn(&'s mut T::Shim<S<'s>>),
);

trait Trait<'s, 't> {}

#[derive(Clone)]
struct ShimMethod3<T: CallWithShim2 + 'static>(
    pub &'static dyn for<'s> Fn(&'s mut T::Shim<dyn for<'t> Trait<'s, 't>>),
);

trait Trait2 {
    type As;
}

#[derive(Clone)]
struct ShimMethod4<T: Trait2 + 'static>(
    pub &'static dyn for<'s> Fn(&'s mut T::As),
);

) {
let stack_len = self.bound_generic_params_stack.len();
self.bound_generic_params_stack
.extend(trait_ref.bound_generic_params.clone().into_iter());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It would probably break by HRTB variable shadowing, e.g.

for<'a> (... for<'a> ( ... ))

by outputting for<'a, 'a>? Unsure if it's important enough to address?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was trying to come up with a test case where this might happen. But I'm unsure; I couldn't find one.

@jackh726

jackh726 commented Oct 1, 2021

Copy link
Copy Markdown
Member

Okay, can you instead actually change the test case to:

trait Trait<'s, 't, 'u> {}

#[derive(Clone)]
struct ShimMethod3<T: CallWithShim2 + 'static>(
    pub &'static dyn for<'s> Fn(&'s mut T::Shim<dyn for<'t> Fn(&'s mut T::Shim<dyn for<'u> Trait<'s, 't, 'u>>)>),
);

This better tests multiple levels of binding. Made me remember that we don't allow lifetime shadowing, so we should be good.

@jackh726

jackh726 commented Oct 1, 2021

Copy link
Copy Markdown
Member

After that change, this PR LGTM to merge.

@jackh726

jackh726 commented Oct 2, 2021

Copy link
Copy Markdown
Member

@bors r+ rollup=never

Given that this effects built-in derives, I want to make sure this is easy to bisect if there are any regressions.

@bors

bors commented Oct 2, 2021

Copy link
Copy Markdown
Collaborator

📌 Commit 87241e9 has been approved by jackh726

@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 Oct 2, 2021
@bors

bors commented Oct 2, 2021

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 87241e9 with merge f03eb6b...

@bors

bors commented Oct 2, 2021

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: jackh726
Pushing f03eb6b to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Oct 2, 2021
@bors bors merged commit f03eb6b into rust-lang:master Oct 2, 2021
@rustbot rustbot added this to the 1.57.0 milestone Oct 2, 2021
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (f03eb6b): comparison url.

Summary: This benchmark run did not return any relevant changes.

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@audunhalland audunhalland deleted the derive-type-params-with-bound-generic-params branch October 3, 2021 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

derive(Clone) with HRTB and GAT

7 participants