Skip to content

Commit 875d516

Browse files
authored
Unrolled build for rust-lang#136325
Rollup merge of rust-lang#136325 - compiler-errors:indirectly, r=RalfJung Delay a bug when indexing unsized slices Fixes rust-lang#136298 r? RalfJung or reassign
2 parents aa4cfd0 + d6e8c7f commit 875d516

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,12 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
634634
Rvalue::RawPtr(RawPtrKind::FakeForPtrMetadata, place) => {
635635
// These are only inserted for slice length, so the place must already be indirect.
636636
// This implies we do not have to worry about whether the borrow escapes.
637-
assert!(place.is_indirect(), "fake borrows are always indirect");
637+
if !place.is_indirect() {
638+
self.tcx.dcx().span_delayed_bug(
639+
self.body.source_info(location).span,
640+
"fake borrows are always indirect",
641+
);
642+
}
638643
}
639644

640645
Rvalue::Cast(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const ONE: [u16] = [1];
2+
//~^ ERROR the size for values of type `[u16]` cannot be known at compilation time
3+
//~| ERROR the size for values of type `[u16]` cannot be known at compilation time
4+
//~| ERROR mismatched types
5+
6+
const TWO: &'static u16 = &ONE[0];
7+
//~^ ERROR cannot move a value of type `[u16]`
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0277]: the size for values of type `[u16]` cannot be known at compilation time
2+
--> $DIR/const-slice-array-deref.rs:1:12
3+
|
4+
LL | const ONE: [u16] = [1];
5+
| ^^^^^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `[u16]`
8+
9+
error[E0308]: mismatched types
10+
--> $DIR/const-slice-array-deref.rs:1:20
11+
|
12+
LL | const ONE: [u16] = [1];
13+
| ^^^ expected `[u16]`, found `[u16; 1]`
14+
15+
error[E0277]: the size for values of type `[u16]` cannot be known at compilation time
16+
--> $DIR/const-slice-array-deref.rs:1:20
17+
|
18+
LL | const ONE: [u16] = [1];
19+
| ^^^ doesn't have a size known at compile-time
20+
|
21+
= help: the trait `Sized` is not implemented for `[u16]`
22+
= note: constant expressions must have a statically known size
23+
24+
error[E0161]: cannot move a value of type `[u16]`
25+
--> $DIR/const-slice-array-deref.rs:6:28
26+
|
27+
LL | const TWO: &'static u16 = &ONE[0];
28+
| ^^^ the size of `[u16]` cannot be statically determined
29+
30+
error: aborting due to 4 previous errors
31+
32+
Some errors have detailed explanations: E0161, E0277, E0308.
33+
For more information about an error, try `rustc --explain E0161`.

0 commit comments

Comments
 (0)