-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Add more tests for the offset_of macro #111665
Conversation
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.
Could you also add a test for privacy with Self
? There recently were some issues with it, so a test that Self
doesn't allow to refer to private fields would be nice.
Something like
mod module {
pub struct Named { v: u8 }
}
trait Trait {
fn f() -> usize {}
}
impl Trait for module::Named {
fn f() -> usize {
offset_of!(Self, v) //~ error: field is private or whatever
}
}
(and similarly for a tuple struct)
@rustbot ready |
480d06c
to
f100c3c
Compare
This comment has been minimized.
This comment has been minimized.
Hmm this is interesting. It's also interesting that I am not getting this ICE locally. Are there some checks running in CI that aren't running locally? |
@est31 do you have debug assertions enabled? this is the check: rust/compiler/rustc_hir_typeck/src/writeback.rs Lines 696 to 702 in c2ccc85
|
@WaffleLapkin I haven't. So I guess this is a bug then if you enable debug assertions in the compiler. Good that we are doing these tests 😆 |
This comment has been minimized.
This comment has been minimized.
Alright it still ICEs after having rebased this PR onto #111661 , so it means that one didn't fix it. I also can reproduce it locally if I enable debug assertions. Will remove the particular test from this PR and then file a separate issue. |
I've changed it to use Should be ready for review. |
tests/ui/offset-of/offset-of-self.rs
Outdated
} | ||
impl super::n::T { | ||
fn v_offs_self() -> usize { | ||
offset_of!(Self, v) //~ ERROR field `v` of struct |
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.
offset_of!(Self, v) //~ ERROR field `v` of struct | |
offset_of!(Self, v) //~ ERROR field `v` of struct `T` is private |
fn main() { | ||
offset_of!(Alpha, z); //~ ERROR the size for values of type | ||
offset_of!(Beta, z); //~ ERROR the size for values of type | ||
offset_of!(Gamma, z); //~ ERROR the size for values of type | ||
} | ||
|
||
fn delta() { | ||
offset_of!(Delta<u8>, z); // compiles fine |
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.
Maybe we should move fine-compiling parts to separate files, to ensure they really compile? (besides, I think there already are test that have the same compiling code, so maybe this and generic_with_sized_type
are just redundant)
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.
The only other tests with generics I could find were the one with Self that are added by this PR as well as the test added in #111661. edit: nvm, there are other tests, e.g. tests/ui/lint/dead-code/offset-of-correct-param-env.rs
or tests/ui/lint/dead-code/offset-of.rs
.
I will move the passing tests though, at least the ones in this file.
* ensuring that offset_of!(Self, ...) works iff inside an impl block * ensuring that the output type is usize and doesn't coerce. this can be changed in the future, but if it is done, it should be a conscious descision * improving the privacy checking test * ensuring that generics don't let you escape the unsized check
@rustbot ready |
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.
Thanks!
@bors r+ rollup |
Add more tests for the offset_of macro Implements what I [suggested in the tracking issue](rust-lang#106655 (comment)), plus some further improvements: * ensuring that offset_of!(Self, ...) works iff inside an impl block * ensuring that the output type is usize and doesn't coerce. this can be changed in the future, but if it is done, it should be a conscious decision * improving the privacy checking test * ensuring that generics don't let you escape the unsized check r? `@WaffleLapkin`
Add more tests for the offset_of macro Implements what I [suggested in the tracking issue](rust-lang#106655 (comment)), plus some further improvements: * ensuring that offset_of!(Self, ...) works iff inside an impl block * ensuring that the output type is usize and doesn't coerce. this can be changed in the future, but if it is done, it should be a conscious decision * improving the privacy checking test * ensuring that generics don't let you escape the unsized check r? ``@WaffleLapkin``
Add more tests for the offset_of macro Implements what I [suggested in the tracking issue](rust-lang#106655 (comment)), plus some further improvements: * ensuring that offset_of!(Self, ...) works iff inside an impl block * ensuring that the output type is usize and doesn't coerce. this can be changed in the future, but if it is done, it should be a conscious decision * improving the privacy checking test * ensuring that generics don't let you escape the unsized check r? ```@WaffleLapkin```
Add more tests for the offset_of macro Implements what I [suggested in the tracking issue](rust-lang#106655 (comment)), plus some further improvements: * ensuring that offset_of!(Self, ...) works iff inside an impl block * ensuring that the output type is usize and doesn't coerce. this can be changed in the future, but if it is done, it should be a conscious decision * improving the privacy checking test * ensuring that generics don't let you escape the unsized check r? ````@WaffleLapkin````
Rollup of 10 pull requests Successful merges: - rust-lang#111491 (Dont check `must_use` on nested `impl Future` from fn) - rust-lang#111606 (very minor cleanups) - rust-lang#111619 (Add timings for MIR passes to profiling report) - rust-lang#111652 (Better diagnostic for `use Self::..`) - rust-lang#111665 (Add more tests for the offset_of macro) - rust-lang#111708 (Give a more useful location for where a span_bug was delayed) - rust-lang#111715 (Fix doc comment for `ConstParamTy` derive) - rust-lang#111723 (style: do not overwrite obligations) - rust-lang#111743 (Improve cgu merging debug output) - rust-lang#111762 (fix: emit error when fragment is `MethodReceiverExpr` and items is empty) r? `@ghost` `@rustbot` modify labels: rollup
Implements what I suggested in the tracking issue, plus some further improvements:
r? @WaffleLapkin