Rollup merge of #136325 - compiler-errors:indirectly, r=RalfJung
Delay a bug when indexing unsized slices Fixes #136298 r? RalfJung or reassign
This commit is contained in:
commit
f1daf9e2c4
3 changed files with 48 additions and 1 deletions
|
@ -634,7 +634,12 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
|||
Rvalue::RawPtr(RawPtrKind::FakeForPtrMetadata, place) => {
|
||||
// These are only inserted for slice length, so the place must already be indirect.
|
||||
// This implies we do not have to worry about whether the borrow escapes.
|
||||
assert!(place.is_indirect(), "fake borrows are always indirect");
|
||||
if !place.is_indirect() {
|
||||
self.tcx.dcx().span_delayed_bug(
|
||||
self.body.source_info(location).span,
|
||||
"fake borrows are always indirect",
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Rvalue::Cast(
|
||||
|
|
9
tests/ui/consts/const-slice-array-deref.rs
Normal file
9
tests/ui/consts/const-slice-array-deref.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
const ONE: [u16] = [1];
|
||||
//~^ ERROR the size for values of type `[u16]` cannot be known at compilation time
|
||||
//~| ERROR the size for values of type `[u16]` cannot be known at compilation time
|
||||
//~| ERROR mismatched types
|
||||
|
||||
const TWO: &'static u16 = &ONE[0];
|
||||
//~^ ERROR cannot move a value of type `[u16]`
|
||||
|
||||
fn main() {}
|
33
tests/ui/consts/const-slice-array-deref.stderr
Normal file
33
tests/ui/consts/const-slice-array-deref.stderr
Normal file
|
@ -0,0 +1,33 @@
|
|||
error[E0277]: the size for values of type `[u16]` cannot be known at compilation time
|
||||
--> $DIR/const-slice-array-deref.rs:1:12
|
||||
|
|
||||
LL | const ONE: [u16] = [1];
|
||||
| ^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `[u16]`
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/const-slice-array-deref.rs:1:20
|
||||
|
|
||||
LL | const ONE: [u16] = [1];
|
||||
| ^^^ expected `[u16]`, found `[u16; 1]`
|
||||
|
||||
error[E0277]: the size for values of type `[u16]` cannot be known at compilation time
|
||||
--> $DIR/const-slice-array-deref.rs:1:20
|
||||
|
|
||||
LL | const ONE: [u16] = [1];
|
||||
| ^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
= help: the trait `Sized` is not implemented for `[u16]`
|
||||
= note: constant expressions must have a statically known size
|
||||
|
||||
error[E0161]: cannot move a value of type `[u16]`
|
||||
--> $DIR/const-slice-array-deref.rs:6:28
|
||||
|
|
||||
LL | const TWO: &'static u16 = &ONE[0];
|
||||
| ^^^ the size of `[u16]` cannot be statically determined
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0161, E0277, E0308.
|
||||
For more information about an error, try `rustc --explain E0161`.
|
Loading…
Add table
Add a link
Reference in a new issue