-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
derive(SmartPointer): rewrite bounds in where and generic bounds #127681
Conversation
rustbot has assigned @compiler-errors. Use |
r? @davidtwco |
dd508f4
to
ba5b4eb
Compare
There was a problem hiding this 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
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 |
Ping. Not sure if it's too late to get the fix in? |
for (params, orig_params) in impl_generics.params[pointee_param_idx + 1..] | ||
.iter_mut() | ||
.zip(&generics.params[pointee_param_idx + 1..]) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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> { /* ... */ }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
ba5b4eb
to
00413c5
Compare
00413c5
to
b06c007
Compare
Please remove the random test files. Also there's still a question I have about why that |
This comment has been minimized.
This comment has been minimized.
b06c007
to
48421e9
Compare
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
… 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``
…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
… 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`", |
There was a problem hiding this comment.
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`"
There was a problem hiding this comment.
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
".
There was a problem hiding this comment.
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`
#[derive(SmartPointer)] | ||
#[repr(transparent)] | ||
struct NoMaybeSized<'a, #[pointee] T> { | ||
//~^ ERROR: SmartPointer` is meaningless because `T` is not `?Sized | ||
ptr: &'a T, | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
b49de3d
to
a9a3699
Compare
…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
a9a3699
to
1679c27
Compare
@bors r+ |
ah this was force pushed after I added it to the rollup, heh |
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```
Ok, thanks for the heads up @matthiaskrgr. @dingxiangfei2009, please open a new PR with the delta between 5d78d7d and the commit here. |
@bors r- |
Actually I just did it myself in #128451. |
…-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
…-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
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
@rustbot label F-derive_smart_pointer |
Fix #127647
Due to the
Unsize
bounds, we need to commute the bounds on the pointee type to the new self type.cc @Darksonn