-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
ty: projections in transparent_newtype_field
#73257
ty: projections in transparent_newtype_field
#73257
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
I don't think this is the best approach here. pub trait Foo {
type Assoc: 'static;
}
impl Foo for () {
type Assoc = u32;
}
extern "C" {
pub fn lint_me(x: Bar<()>);
}
#[repr(transparent)]
pub struct Bar<T: Foo> {
value: &'static <T as Foo>::Assoc,
} Afaik extern functions must be fully monomorphic (ignoring lifetimes), in which case you should probably have relevant substs here. |
8171d28
to
3b094d3
Compare
I've force pushed over the commit to make the case you highlighted work - well spotted. I added the function being modified here in #72890. It deliberately does not apply substitutions so that it can identify the field in a transparent struct which is a non-ZST. If the non-zero-sized field were a generic parameter, and if it were substituted for Given that, I think that having this function is the appropriate approach and it being unable to handle this case is just an oversight. If you have a better approach, then I'm open to making changes though. |
Your current approach still seems somewhat unfortunate to me, I think this warns on: use std::marker::PhantomData;
trait Foo {
type Assoc;
}
impl Foo for () {
type Assoc = PhantomData<()>;
}
#[repr(transparent)]
struct Wow<T> where T: Foo<Assoc = PhantomData<T>> {
x: <T as Foo>::Assoc,
v: u32,
}
extern "C" {
fn test(v: Wow<()>);
}
I can't quite follow you here, do you explicitly not want to lint for #[repr(transparent)]
struct Foo<T> {
inner: T,
}
extern "C" {
fn foo(v: Foo<()>);
} If I understand this correctly, structs with |
It does - I've pushed a commit that fixes this and simplifies
This case does lint and it should. The previous behavior for transparent types was to skip any that were zero-sized. Consider the second example from your comment, with struct
With the new behavior for transparent types, where the non-ZST field is identified and only that field is checked, we would correctly determine that the In the previous behaviour, the There are certainly other ways I could have solved this - I don't think that identifying the non-ZST field is the only way, but it's quite explicit about what we're checking and I prefer that; I am open to better approaches, but I don't think using a I've pushed some other commits too:
|
3b094d3
to
c8c9404
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.
LGTM, the new transparent_newtype_field
now also looks good 👍
c8c9404
to
94d337d
Compare
This comment has been minimized.
This comment has been minimized.
94d337d
to
61b24fd
Compare
Pushed a minor commit re-wording to re-trigger CI as the last failure was spurious. |
r? @varkor |
@bors r=lcnr,varkor |
📌 Commit 61b24fd2561beccc4787878272c96b52d4d8a0a8 has been approved by |
@bors p=1 |
⌛ Testing commit 61b24fd2561beccc4787878272c96b52d4d8a0a8 with merge 70af37bb5fb964d44612cfb095dc2c498e8f2a6e... |
This comment has been minimized.
This comment has been minimized.
@bors r=lcnr,varkor |
📌 Commit a730d88 has been approved by |
⌛ Testing commit a730d88 with merge 3406beccc47c0d5beafc066cb3b14dbba08f1298... |
…es-projection, r=lcnr,varkor ty: projections in `transparent_newtype_field` Fixes rust-lang#73249. This PR modifies `transparent_newtype_field` so that it handles projections with generic parameters, where `normalize_erasing_regions` would ICE.
@bors retry yield |
@bors yield |
@bors retry yield |
☀️ Test successful - checks-azure |
wh...what the hell? @pietroalbini this had yielded to the rollup, but it still merged is yield implemented properly? |
I think this is how those "test timed out" locks happen, because bors will continue testing the rollup and then realize it can't merge it |
…arth Rollup of 13 pull requests Successful merges: - rust-lang#71568 (Document unsafety in slice/sort.rs) - rust-lang#72709 (`#[deny(unsafe_op_in_unsafe_fn)]` in liballoc) - rust-lang#73214 (Add asm!() support for hexagon) - rust-lang#73248 (save_analysis: improve handling of enum struct variant) - rust-lang#73257 (ty: projections in `transparent_newtype_field`) - rust-lang#73261 (Suggest `?Sized` when applicable for ADTs) - rust-lang#73300 (Implement crate-level-only lints checking.) - rust-lang#73334 (Note numeric literals that can never fit in an expected type) - rust-lang#73357 (Use `LocalDefId` for import IDs in trait map) - rust-lang#73364 (asm: Allow multiple template string arguments; interpret them as newline-separated) - rust-lang#73382 (Only display other method receiver candidates if they actually apply) - rust-lang#73465 (Add specialization of `ToString for char`) - rust-lang#73489 (Refactor hir::Place) Failed merges: r? @ghost
@Manishearth "yield" does not exist in the bors code, is just a comment saying why the PR was retried. The yield usually works because when the retry happens bors starts testing the PR with higher priority, and cancelbot kills the previous build since a new commit was pushed to |
Fixes #73249.
This PR modifies
transparent_newtype_field
so that it handlesprojections with generic parameters, where
normalize_erasing_regions
would ICE.