Skip to content

Commit c158bb4

Browse files
author
Ariel Ben-Yehuda
committed
Also store casts in metadata
This is required for it to actually work.
1 parent 4f965c8 commit c158bb4

File tree

6 files changed

+32
-3
lines changed

6 files changed

+32
-3
lines changed

src/librustc/diagnostics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ a compile-time constant.
526526

527527
register_diagnostics! {
528528
E0011,
529+
E0012,
529530
E0014,
530531
E0016,
531532
E0017,

src/librustc/metadata/common.rs

+1
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ enum_from_u32! {
148148
tag_table_capture_modes = 0x67,
149149
tag_table_object_cast_map = 0x68,
150150
tag_table_const_qualif = 0x69,
151+
tag_table_cast_kinds = 0x6a,
151152
}
152153
}
153154

src/librustc/middle/astencode.rs

+25
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use metadata::tydecode;
2323
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId, TypeParameter};
2424
use metadata::tydecode::{RegionParameter, ClosureSource};
2525
use metadata::tyencode;
26+
use middle::cast;
2627
use middle::check_const::ConstQualif;
2728
use middle::mem_categorization::Typer;
2829
use middle::privacy::{AllPublic, LastMod};
@@ -688,6 +689,10 @@ pub fn encode_closure_kind(ebml_w: &mut Encoder, kind: ty::ClosureKind) {
688689
kind.encode(ebml_w).unwrap();
689690
}
690691

692+
pub fn encode_cast_kind(ebml_w: &mut Encoder, kind: cast::CastKind) {
693+
kind.encode(ebml_w).unwrap();
694+
}
695+
691696
pub trait vtable_decoder_helpers<'tcx> {
692697
fn read_vec_per_param_space<T, F>(&mut self, f: F) -> VecPerParamSpace<T> where
693698
F: FnMut(&mut Self) -> T;
@@ -1248,6 +1253,13 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
12481253
})
12491254
}
12501255

1256+
if let Some(cast_kind) = tcx.cast_kinds.borrow().get(&id) {
1257+
rbml_w.tag(c::tag_table_cast_kinds, |rbml_w| {
1258+
rbml_w.id(id);
1259+
encode_cast_kind(rbml_w, *cast_kind)
1260+
})
1261+
}
1262+
12511263
for &qualif in tcx.const_qualif_map.borrow().get(&id).iter() {
12521264
rbml_w.tag(c::tag_table_const_qualif, |rbml_w| {
12531265
rbml_w.id(id);
@@ -1289,6 +1301,8 @@ trait rbml_decoder_decoder_helpers<'tcx> {
12891301
-> subst::Substs<'tcx>;
12901302
fn read_auto_adjustment<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
12911303
-> ty::AutoAdjustment<'tcx>;
1304+
fn read_cast_kind<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
1305+
-> cast::CastKind;
12921306
fn read_closure_kind<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
12931307
-> ty::ClosureKind;
12941308
fn read_closure_ty<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
@@ -1641,6 +1655,12 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
16411655
}).unwrap()
16421656
}
16431657

1658+
fn read_cast_kind<'b, 'c>(&mut self, _dcx: &DecodeContext<'b, 'c, 'tcx>)
1659+
-> cast::CastKind
1660+
{
1661+
Decodable::decode(self).unwrap()
1662+
}
1663+
16441664
fn read_closure_kind<'b, 'c>(&mut self, _dcx: &DecodeContext<'b, 'c, 'tcx>)
16451665
-> ty::ClosureKind
16461666
{
@@ -1801,6 +1821,11 @@ fn decode_side_tables(dcx: &DecodeContext,
18011821
dcx.tcx.closure_kinds.borrow_mut().insert(ast_util::local_def(id),
18021822
closure_kind);
18031823
}
1824+
c::tag_table_cast_kinds => {
1825+
let cast_kind =
1826+
val_dsr.read_cast_kind(dcx);
1827+
dcx.tcx.cast_kinds.borrow_mut().insert(id, cast_kind);
1828+
}
18041829
c::tag_table_const_qualif => {
18051830
let qualif: ConstQualif = Decodable::decode(val_dsr).unwrap();
18061831
dcx.tcx.const_qualif_map.borrow_mut().insert(id, qualif);

src/librustc/middle/cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub enum CastTy<'tcx> {
3636
}
3737

3838
/// Cast Kind. See RFC 401 (or librustc_typeck/check/cast.rs)
39-
#[derive(Copy, Clone, Debug)]
39+
#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)]
4040
pub enum CastKind {
4141
CoercionCast,
4242
PtrPtrCast,

src/test/compile-fail/fat-ptr-cast.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
trait Trait {}
12+
1113
fn main() {
1214
let a: &[i32] = &[1, 2, 3];
1315
let b: Box<[i32]> = Box::new([1, 2, 3]);
1416
let p = a as *const [i32];
1517
let q = a.as_ptr();
1618

1719
a as usize; //~ ERROR illegal cast
18-
b as usize; //~ ERROR illegal cast
20+
b as usize; //~ ERROR non-scalar cast
1921
p as usize; //~ ERROR illegal cast
2022

2123
// #22955

src/test/compile-fail/issue-22289.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
0 as &std::any::Any; //~ ERROR illegal cast
12+
0 as &std::any::Any; //~ ERROR non-scalar cast
1313
}

0 commit comments

Comments
 (0)