Skip to content

Commit 25b5d30

Browse files
authored
Rollup merge of #60710 - varkor:delay_span_bug-const-parent, r=matthewjasper
Use `delay_span_bug` for error cases when checking `AnonConst` parent Fixes #60704. Fixes #60650.
2 parents e952b52 + 0f792ab commit 25b5d30

5 files changed

+81
-3
lines changed

Diff for: src/librustc_typeck/collect.rs

+21-3
Original file line numberDiff line numberDiff line change
@@ -1404,15 +1404,27 @@ pub fn checked_type_of<'a, 'tcx>(
14041404
if !fail {
14051405
return None;
14061406
}
1407-
bug!("unexpected const parent path def {:?}", x);
1407+
tcx.sess.delay_span_bug(
1408+
DUMMY_SP,
1409+
&format!(
1410+
"unexpected const parent path def {:?}", x
1411+
),
1412+
);
1413+
tcx.types.err
14081414
}
14091415
}
14101416
}
14111417
x => {
14121418
if !fail {
14131419
return None;
14141420
}
1415-
bug!("unexpected const parent path {:?}", x);
1421+
tcx.sess.delay_span_bug(
1422+
DUMMY_SP,
1423+
&format!(
1424+
"unexpected const parent path {:?}", x
1425+
),
1426+
);
1427+
tcx.types.err
14161428
}
14171429
}
14181430
}
@@ -1421,7 +1433,13 @@ pub fn checked_type_of<'a, 'tcx>(
14211433
if !fail {
14221434
return None;
14231435
}
1424-
bug!("unexpected const parent in type_of_def_id(): {:?}", x);
1436+
tcx.sess.delay_span_bug(
1437+
DUMMY_SP,
1438+
&format!(
1439+
"unexpected const parent in type_of_def_id(): {:?}", x
1440+
),
1441+
);
1442+
tcx.types.err
14251443
}
14261444
}
14271445
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![feature(const_generics)]
2+
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
3+
4+
// We should probably be able to infer the types here. However, this test is checking that we don't
5+
// get an ICE in this case. It may be modified later to not be an error.
6+
7+
struct Foo<const NUM_BYTES: usize>(pub [u8; NUM_BYTES]);
8+
9+
fn main() {
10+
let _ = Foo::<3>([1, 2, 3]); //~ ERROR type annotations needed
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2+
--> $DIR/cannot-infer-type-for-const-param.rs:1:12
3+
|
4+
LL | #![feature(const_generics)]
5+
| ^^^^^^^^^^^^^^
6+
7+
error[E0282]: type annotations needed
8+
--> $DIR/cannot-infer-type-for-const-param.rs:10:19
9+
|
10+
LL | let _ = Foo::<3>([1, 2, 3]);
11+
| ^ cannot infer type for `{integer}`
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0282`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use std::convert::TryInto;
2+
3+
struct S;
4+
5+
fn main() {
6+
let _: u32 = 5i32.try_into::<32>().unwrap(); //~ ERROR wrong number of const arguments
7+
S.f::<0>(); //~ ERROR no method named `f`
8+
S::<0>; //~ ERROR wrong number of const arguments
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0107]: wrong number of const arguments: expected 0, found 1
2+
--> $DIR/invalid-const-arg-for-type-param.rs:6:34
3+
|
4+
LL | let _: u32 = 5i32.try_into::<32>().unwrap();
5+
| ^^ unexpected const argument
6+
7+
error[E0599]: no method named `f` found for type `S` in the current scope
8+
--> $DIR/invalid-const-arg-for-type-param.rs:7:7
9+
|
10+
LL | struct S;
11+
| --------- method `f` not found for this
12+
...
13+
LL | S.f::<0>();
14+
| ^
15+
16+
error[E0107]: wrong number of const arguments: expected 0, found 1
17+
--> $DIR/invalid-const-arg-for-type-param.rs:8:9
18+
|
19+
LL | S::<0>;
20+
| ^ unexpected const argument
21+
22+
error: aborting due to 3 previous errors
23+
24+
Some errors have detailed explanations: E0107, E0599.
25+
For more information about an error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)