Skip to content

Commit 5e04567

Browse files
authored
Rollup merge of rust-lang#102187 - b-naber:inline-const-source-info, r=eholk
Use correct location for type tests in promoted constants Previously we forgot to remap the location in a type test collected when visiting the body of a promoted constant back to the usage location, causing an ICE when trying to get span information for that type test. Fixes rust-lang#102117
2 parents 32471a7 + 29cc36f commit 5e04567

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

+9
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
584584
// modify their locations.
585585
let all_facts = &mut None;
586586
let mut constraints = Default::default();
587+
let mut type_tests = Default::default();
587588
let mut closure_bounds = Default::default();
588589
let mut liveness_constraints =
589590
LivenessValues::new(Rc::new(RegionValueElements::new(&promoted_body)));
@@ -595,6 +596,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
595596
&mut this.cx.borrowck_context.constraints.outlives_constraints,
596597
&mut constraints,
597598
);
599+
mem::swap(&mut this.cx.borrowck_context.constraints.type_tests, &mut type_tests);
598600
mem::swap(
599601
&mut this.cx.borrowck_context.constraints.closure_bounds_mapping,
600602
&mut closure_bounds,
@@ -619,6 +621,13 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
619621
swap_constraints(self);
620622

621623
let locations = location.to_locations();
624+
625+
// Use location of promoted const in collected constraints
626+
for type_test in type_tests.iter() {
627+
let mut type_test = type_test.clone();
628+
type_test.locations = locations;
629+
self.cx.borrowck_context.constraints.type_tests.push(type_test)
630+
}
622631
for constraint in constraints.outlives().iter() {
623632
let mut constraint = constraint.clone();
624633
constraint.locations = locations;

src/test/ui/consts/issue-102117.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#![feature(inline_const, const_type_id)]
2+
3+
use std::alloc::Layout;
4+
use std::any::TypeId;
5+
use std::mem::transmute;
6+
use std::ptr::drop_in_place;
7+
8+
pub struct VTable {
9+
layout: Layout,
10+
type_id: TypeId,
11+
drop_in_place: unsafe fn(*mut ()),
12+
}
13+
14+
impl VTable {
15+
pub fn new<T>() -> &'static Self {
16+
const {
17+
//~^ ERROR the parameter type `T` may not live long enough
18+
//~| ERROR the parameter type `T` may not live long enough
19+
&VTable {
20+
layout: Layout::new::<T>(),
21+
type_id: TypeId::of::<T>(),
22+
drop_in_place: unsafe {
23+
transmute::<unsafe fn(*mut T), unsafe fn(*mut ())>(drop_in_place::<T>)
24+
},
25+
}
26+
}
27+
}
28+
}
29+
30+
fn main() {}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error[E0310]: the parameter type `T` may not live long enough
2+
--> $DIR/issue-102117.rs:16:9
3+
|
4+
LL | / const {
5+
LL | |
6+
LL | |
7+
LL | | &VTable {
8+
... |
9+
LL | | }
10+
LL | | }
11+
| |_________^ ...so that the type `T` will meet its required lifetime bounds
12+
|
13+
help: consider adding an explicit lifetime bound...
14+
|
15+
LL | pub fn new<T: 'static>() -> &'static Self {
16+
| +++++++++
17+
18+
error[E0310]: the parameter type `T` may not live long enough
19+
--> $DIR/issue-102117.rs:16:9
20+
|
21+
LL | / const {
22+
LL | |
23+
LL | |
24+
LL | | &VTable {
25+
... |
26+
LL | | }
27+
LL | | }
28+
| |_________^ ...so that the type `T` will meet its required lifetime bounds
29+
|
30+
help: consider adding an explicit lifetime bound...
31+
|
32+
LL | pub fn new<T: 'static>() -> &'static Self {
33+
| +++++++++
34+
35+
error: aborting due to 2 previous errors
36+
37+
For more information about this error, try `rustc --explain E0310`.

0 commit comments

Comments
 (0)