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

derive(SmartPointer): rewrite bounds in where and generic bounds #127681

Closed

Conversation

dingxiangfei2009
Copy link
Contributor

@dingxiangfei2009 dingxiangfei2009 commented Jul 13, 2024

Fix #127647

Due to the Unsize bounds, we need to commute the bounds on the pointee type to the new self type.

cc @Darksonn

@rustbot
Copy link
Collaborator

rustbot commented Jul 13, 2024

r? @compiler-errors

rustbot has assigned @compiler-errors.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 13, 2024
@dingxiangfei2009
Copy link
Contributor Author

r? @davidtwco

@rustbot rustbot assigned davidtwco and unassigned compiler-errors Jul 13, 2024
@dingxiangfei2009 dingxiangfei2009 force-pushed the smart-ptr-bounds branch 3 times, most recently from dd508f4 to ba5b4eb Compare July 13, 2024 20:04
Copy link
Member

@davidtwco davidtwco left a comment

Choose a reason for hiding this comment

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

One nit, r=me other than that

compiler/rustc_builtin_macros/src/deriving/smart_ptr.rs Outdated Show resolved Hide resolved
@Darksonn
Copy link
Contributor

What needs to happen here? Can we merge it now so that the fix will be available in the same version of rustc that initially adds #[derive(SmartPointer)]?

@Darksonn
Copy link
Contributor

Ping. Not sure if it's too late to get the fix in?

Comment on lines 168 to 171
for (params, orig_params) in impl_generics.params[pointee_param_idx + 1..]
.iter_mut()
.zip(&generics.params[pointee_param_idx + 1..])
Copy link
Member

Choose a reason for hiding this comment

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

Why do we only care about pointee_param_idx + 1 ..? Is there some restriction about the placement of #[pointee] that this is implicitly relying on?

Copy link
Contributor Author

@dingxiangfei2009 dingxiangfei2009 Jul 29, 2024

Choose a reason for hiding this comment

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

It has to do with those generic types that come after the annotated #[pointee] type parameter that may contain bounds "involving" the #[pointee] type, such as the X in this example.

#[derive(core::marker::SmartPointer)]
#[repr(transparent)]
pub struct Ptr6<'a, #[pointee] T: ?Sized, X: MyTrait<T>> {
    data: &'a mut T,
    x: core::marker::PhantomData<X>,
}

The macro needs to write down a new bound X: MyTrait<T> from X: MyTrait<__S> as well.

Copy link
Member

Choose a reason for hiding this comment

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

But bounds can reference the #[pointee] parameter before the parameter is declared:

trait Foo<S>{}

struct Test<S: Foo<T>, #[pointee] T> { /* ... */ }

Copy link
Member

Choose a reason for hiding this comment

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

^?

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 always thought this was not possible. I will update this part.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied. pointee_param_idx is skipped because that bound will be written separately.

@compiler-errors
Copy link
Member

Please remove the random test files. Also there's still a question I have about why that [i + 1...] exists, that you still have not answered.

@rust-log-analyzer

This comment has been minimized.

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 31, 2024
Rollup of 8 pull requests

Successful merges:

 - rust-lang#125048 (PinCoerceUnsized trait into core)
 - rust-lang#127681 (derive(SmartPointer): rewrite bounds in where and generic bounds)
 - rust-lang#127830 (When an archive fails to build, print the path)
 - rust-lang#128147 (migrate fmt-write-bloat to rmake)
 - rust-lang#128356 (Migrate `cross-lang-lto-clang` and `cross-lang-lto-pgo-smoketest` `run-make` tests to rmake)
 - rust-lang#128387 (More detailed note to deprecate ONCE_INIT)
 - rust-lang#128388 (Match LLVM ABI in `extern "C"` functions for `f128` on Windows)
 - rust-lang#128412 (Remove `crate_level_only` from `ELIDED_LIFETIMES_IN_PATHS`)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 31, 2024
… r=compiler-errors

derive(SmartPointer): rewrite bounds in where and generic bounds

Fix rust-lang#127647

Due to the `Unsize` bounds, we need to commute the bounds on the pointee type to the new self type.

cc ``@Darksonn``
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 31, 2024
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#127681 (derive(SmartPointer): rewrite bounds in where and generic bounds)
 - rust-lang#127830 (When an archive fails to build, print the path)
 - rust-lang#128356 (Migrate `cross-lang-lto-clang` and `cross-lang-lto-pgo-smoketest` `run-make` tests to rmake)
 - rust-lang#128387 (More detailed note to deprecate ONCE_INIT)
 - rust-lang#128388 (Match LLVM ABI in `extern "C"` functions for `f128` on Windows)
 - rust-lang#128412 (Remove `crate_level_only` from `ELIDED_LIFETIMES_IN_PATHS`)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 31, 2024
… r=compiler-errors

derive(SmartPointer): rewrite bounds in where and generic bounds

Fix rust-lang#127647

Due to the `Unsize` bounds, we need to commute the bounds on the pointee type to the new self type.

cc ```@Darksonn```
.struct_span_err(
pointee_ty_ident.span,
format!(
"`SmartPointer` is meaningless because `{}` is not `?Sized`",
Copy link
Contributor

Choose a reason for hiding this comment

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

I would probably phrase this as

"`derive(SmartPointer)` requires the use of `{}: ?Sized`"

Copy link
Member

Choose a reason for hiding this comment

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

Or "derive(SmartPointer) requires {} is marked ?Sized".

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 elected

`derive(SmartPointer)` requires {} to be marked `?Sized`

Comment on lines 38 to 44
#[derive(SmartPointer)]
#[repr(transparent)]
struct NoMaybeSized<'a, #[pointee] T> {
//~^ ERROR: SmartPointer` is meaningless because `T` is not `?Sized
ptr: &'a T,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have a test that ?std::marker::Sized succeeds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops I somehow pushed this commit. 😓 I intend to open another PR.

It is working. To verify it, the test has updated with sensible ways that Sized marker can be used in.

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 31, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#126454 (bump-stage0: use IndexMap for determinism)
 - rust-lang#127681 (derive(SmartPointer): rewrite bounds in where and generic bounds)
 - rust-lang#127830 (When an archive fails to build, print the path)
 - rust-lang#128151 (Structured suggestion for `extern crate foo` when `foo` isn't resolved in import)
 - rust-lang#128387 (More detailed note to deprecate ONCE_INIT)
 - rust-lang#128388 (Match LLVM ABI in `extern "C"` functions for `f128` on Windows)
 - rust-lang#128402 (Attribute checking simplifications)
 - rust-lang#128412 (Remove `crate_level_only` from `ELIDED_LIFETIMES_IN_PATHS`)
 - rust-lang#128430 (Use a separate pattern type for `rustc_pattern_analysis` diagnostics )

r? `@ghost`
`@rustbot` modify labels: rollup
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jul 31, 2024

📌 Commit 1679c27 has been approved by compiler-errors

It is now in the queue for this repository.

@matthiaskrgr
Copy link
Member

ah this was force pushed after I added it to the rollup, heh

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jul 31, 2024
Rollup merge of rust-lang#127681 - dingxiangfei2009:smart-ptr-bounds, r=compiler-errors

derive(SmartPointer): rewrite bounds in where and generic bounds

Fix rust-lang#127647

Due to the `Unsize` bounds, we need to commute the bounds on the pointee type to the new self type.

cc ```@Darksonn```
@compiler-errors
Copy link
Member

Ok, thanks for the heads up @matthiaskrgr. @dingxiangfei2009, please open a new PR with the delta between 5d78d7d and the commit here.

@compiler-errors
Copy link
Member

@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 Jul 31, 2024
@compiler-errors
Copy link
Member

Actually I just did it myself in #128451.

tgross35 added a commit to tgross35/rust that referenced this pull request Jul 31, 2024
…-maybe-sized, r=compiler-errors

derive(SmartPointer): require pointee to be maybe sized

cc `@Darksonn`

So `#[pointee]` has to be `?Sized` in order for deriving `SmartPointer` to be meaningful.

cc `@compiler-errors` for suggestions in rust-lang#127681
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 31, 2024
…-maybe-sized, r=compiler-errors

derive(SmartPointer): require pointee to be maybe sized

cc ``@Darksonn``

So `#[pointee]` has to be `?Sized` in order for deriving `SmartPointer` to be meaningful.

cc ``@compiler-errors`` for suggestions in rust-lang#127681
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 1, 2024
Rollup merge of rust-lang#128452 - dingxiangfei2009:smart-ptr-require-maybe-sized, r=compiler-errors

derive(SmartPointer): require pointee to be maybe sized

cc ``@Darksonn``

So `#[pointee]` has to be `?Sized` in order for deriving `SmartPointer` to be meaningful.

cc ``@compiler-errors`` for suggestions in rust-lang#127681
@Darksonn
Copy link
Contributor

Darksonn commented Aug 6, 2024

@rustbot label F-derive_smart_pointer

@rustbot rustbot added the F-derive_smart_pointer `#![feature(derive_smart_pointer)]` label Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-derive_smart_pointer `#![feature(derive_smart_pointer)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

Trait bounds not properly propagated in #[derive(SmartPointer)]
8 participants