don't skip inference for type in offset_of!
This commit is contained in:
parent
6d1bf733d6
commit
7cdb23b98a
@ -692,15 +692,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||||||
fcx_typeck_results.offset_of_data().items_in_stable_order()
|
fcx_typeck_results.offset_of_data().items_in_stable_order()
|
||||||
{
|
{
|
||||||
let hir_id = hir::HirId { owner: common_hir_owner, local_id };
|
let hir_id = hir::HirId { owner: common_hir_owner, local_id };
|
||||||
|
let container = self.resolve(container, &hir_id);
|
||||||
if cfg!(debug_assertions) && container.has_infer() {
|
|
||||||
span_bug!(
|
|
||||||
hir_id.to_span(self.fcx.tcx),
|
|
||||||
"writeback: `{:?}` has inference variables",
|
|
||||||
container
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
self.typeck_results.offset_of_data_mut().insert(hir_id, (container, indices.clone()));
|
self.typeck_results.offset_of_data_mut().insert(hir_id, (container, indices.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -481,10 +481,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||||||
}))))
|
}))))
|
||||||
}
|
}
|
||||||
|
|
||||||
ExprKind::OffsetOf { container, fields } => block.and(Rvalue::NullaryOp(
|
ExprKind::OffsetOf { container, fields } => {
|
||||||
NullOp::OffsetOf(fields),
|
block.and(Rvalue::NullaryOp(NullOp::OffsetOf(fields), container))
|
||||||
this.tcx.erase_regions(container),
|
}
|
||||||
)),
|
|
||||||
|
|
||||||
ExprKind::Literal { .. }
|
ExprKind::Literal { .. }
|
||||||
| ExprKind::NamedConst { .. }
|
| ExprKind::NamedConst { .. }
|
||||||
|
@ -394,6 +394,8 @@ fn offset_of() {
|
|||||||
z: T
|
z: T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trait Trait {}
|
||||||
|
|
||||||
// Ensure that this type of generics works
|
// Ensure that this type of generics works
|
||||||
fn offs_of_z<T>() -> usize {
|
fn offs_of_z<T>() -> usize {
|
||||||
offset_of!(Generic<T>, z)
|
offset_of!(Generic<T>, z)
|
||||||
@ -401,6 +403,9 @@ fn offset_of() {
|
|||||||
|
|
||||||
assert_eq!(offset_of!(Generic<u8>, z), 8);
|
assert_eq!(offset_of!(Generic<u8>, z), 8);
|
||||||
assert_eq!(offs_of_z::<u8>(), 8);
|
assert_eq!(offs_of_z::<u8>(), 8);
|
||||||
|
|
||||||
|
// Ensure that it works with the implicit lifetime in `Box<dyn Trait + '_>`.
|
||||||
|
assert_eq!(offset_of!(Generic<Box<dyn Trait>>, z), 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -13,7 +13,7 @@ fn main() {
|
|||||||
offset_of!(S, f..); //~ ERROR no rules expected the token
|
offset_of!(S, f..); //~ ERROR no rules expected the token
|
||||||
offset_of!(S, f..,); //~ ERROR no rules expected the token
|
offset_of!(S, f..,); //~ ERROR no rules expected the token
|
||||||
offset_of!(Lt<'static>, bar); // issue #111657
|
offset_of!(Lt<'static>, bar); // issue #111657
|
||||||
|
offset_of!(Lt<'_>, bar); // issue #111678
|
||||||
}
|
}
|
||||||
|
|
||||||
struct S { f: u8, }
|
struct S { f: u8, }
|
||||||
|
@ -41,6 +41,7 @@ fn main() {
|
|||||||
fn delta() {
|
fn delta() {
|
||||||
offset_of!(Delta<Alpha>, z); //~ ERROR the size for values of type
|
offset_of!(Delta<Alpha>, z); //~ ERROR the size for values of type
|
||||||
offset_of!(Delta<Extern>, z); //~ ERROR the size for values of type
|
offset_of!(Delta<Extern>, z); //~ ERROR the size for values of type
|
||||||
|
offset_of!(Delta<dyn Trait>, z); //~ ERROR the size for values of type
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generic_with_maybe_sized<T: ?Sized>() -> usize {
|
fn generic_with_maybe_sized<T: ?Sized>() -> usize {
|
||||||
|
@ -34,6 +34,15 @@ LL | offset_of!(Delta<Extern>, z);
|
|||||||
= help: the trait `Sized` is not implemented for `Extern`
|
= help: the trait `Sized` is not implemented for `Extern`
|
||||||
= note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error[E0277]: the size for values of type `dyn Trait` cannot be known at compilation time
|
||||||
|
--> $DIR/offset-of-dst-field.rs:44:5
|
||||||
|
|
|
||||||
|
LL | offset_of!(Delta<dyn Trait>, z);
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||||
|
|
|
||||||
|
= help: the trait `Sized` is not implemented for `dyn Trait`
|
||||||
|
= note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
|
error[E0277]: the size for values of type `[u8]` cannot be known at compilation time
|
||||||
--> $DIR/offset-of-dst-field.rs:42:5
|
--> $DIR/offset-of-dst-field.rs:42:5
|
||||||
|
|
|
|
||||||
@ -49,7 +58,7 @@ LL | struct Alpha {
|
|||||||
= note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
|
= note: this error originates in the macro `offset_of` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
error[E0277]: the size for values of type `T` cannot be known at compilation time
|
error[E0277]: the size for values of type `T` cannot be known at compilation time
|
||||||
--> $DIR/offset-of-dst-field.rs:47:5
|
--> $DIR/offset-of-dst-field.rs:48:5
|
||||||
|
|
|
|
||||||
LL | fn generic_with_maybe_sized<T: ?Sized>() -> usize {
|
LL | fn generic_with_maybe_sized<T: ?Sized>() -> usize {
|
||||||
| - this type parameter needs to be `std::marker::Sized`
|
| - this type parameter needs to be `std::marker::Sized`
|
||||||
@ -63,6 +72,6 @@ LL - fn generic_with_maybe_sized<T: ?Sized>() -> usize {
|
|||||||
LL + fn generic_with_maybe_sized<T>() -> usize {
|
LL + fn generic_with_maybe_sized<T>() -> usize {
|
||||||
|
|
|
|
||||||
|
|
||||||
error: aborting due to 6 previous errors
|
error: aborting due to 7 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0277`.
|
For more information about this error, try `rustc --explain E0277`.
|
||||||
|
11
tests/ui/offset-of/offset-of-inference.rs
Normal file
11
tests/ui/offset-of/offset-of-inference.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// Test that inference types in `offset_of!` don't ICE.
|
||||||
|
|
||||||
|
#![feature(offset_of)]
|
||||||
|
|
||||||
|
struct Foo<T> {
|
||||||
|
x: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _ = core::mem::offset_of!(Foo<_>, x); //~ ERROR: type annotations needed
|
||||||
|
}
|
9
tests/ui/offset-of/offset-of-inference.stderr
Normal file
9
tests/ui/offset-of/offset-of-inference.stderr
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
error[E0282]: type annotations needed
|
||||||
|
--> $DIR/offset-of-inference.rs:10:35
|
||||||
|
|
|
||||||
|
LL | let _ = core::mem::offset_of!(Foo<_>, x);
|
||||||
|
| ^^^^^^ cannot infer type
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0282`.
|
Loading…
x
Reference in New Issue
Block a user