Skip to content

Commit ccb2add

Browse files
committed
---
yaml --- r: 67316 b: refs/heads/master c: b1f5b1b h: refs/heads/master v: v3
1 parent d795e70 commit ccb2add

28 files changed

+474
-919
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: af7b87f69d9c4633d7e0c7dd77f34c23bbd433d8
2+
refs/heads/master: b1f5b1ba5fd12a058d153e9da8f11cd1bc597bf0
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 18e3db7392d2d0697b7e27d6d986139960144d85
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9

trunk/src/librustc/metadata/tydecode.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fn parse_trait_store(st: &mut PState) -> ty::TraitStore {
186186
}
187187

188188
fn parse_substs(st: &mut PState, conv: conv_did) -> ty::substs {
189-
let self_r = parse_opt(st, |st| parse_region(st) );
189+
let regions = parse_region_substs(st, |x,y| conv(x,y));
190190

191191
let self_ty = parse_opt(st, |st| parse_ty(st, |x,y| conv(x,y)) );
192192

@@ -196,12 +196,28 @@ fn parse_substs(st: &mut PState, conv: conv_did) -> ty::substs {
196196
st.pos = st.pos + 1u;
197197

198198
return ty::substs {
199-
self_r: self_r,
199+
regions: regions,
200200
self_ty: self_ty,
201201
tps: params
202202
};
203203
}
204204

205+
fn parse_region_substs(st: &mut PState, conv: conv_did) -> ty::RegionSubsts {
206+
match next(st) {
207+
'e' => ty::ErasedRegions,
208+
'n' => {
209+
let mut regions = opt_vec::Empty;
210+
while peek(st) != '.' {
211+
let r = parse_region(st);
212+
regions.push(r);
213+
}
214+
assert_eq!(next(st), '.');
215+
ty::NonerasedRegions(regions)
216+
}
217+
_ => fail!("parse_bound_region: bad input")
218+
}
219+
}
220+
205221
fn parse_bound_region(st: &mut PState) -> ty::bound_region {
206222
match next(st) {
207223
's' => ty::br_self,

trunk/src/librustc/metadata/tyencode.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,28 @@ fn enc_opt<T>(w: @io::Writer, t: Option<T>, enc_f: &fn(T)) {
120120
}
121121

122122
fn enc_substs(w: @io::Writer, cx: @ctxt, substs: &ty::substs) {
123-
do enc_opt(w, substs.self_r) |r| { enc_region(w, cx, r) }
123+
enc_region_substs(w, cx, &substs.regions);
124124
do enc_opt(w, substs.self_ty) |t| { enc_ty(w, cx, t) }
125125
w.write_char('[');
126126
for substs.tps.iter().advance |t| { enc_ty(w, cx, *t); }
127127
w.write_char(']');
128128
}
129129

130+
fn enc_region_substs(w: @io::Writer, cx: @ctxt, substs: &ty::RegionSubsts) {
131+
match *substs {
132+
ty::ErasedRegions => {
133+
w.write_char('e');
134+
}
135+
ty::NonerasedRegions(ref regions) => {
136+
w.write_char('n');
137+
for regions.iter().advance |&r| {
138+
enc_region(w, cx, r);
139+
}
140+
w.write_char('.');
141+
}
142+
}
143+
}
144+
130145
fn enc_region(w: @io::Writer, cx: @ctxt, r: ty::Region) {
131146
match r {
132147
ty::re_bound(br) => {

trunk/src/librustc/middle/check_match.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
use middle::const_eval::{compare_const_vals, lookup_const_by_id};
13-
use middle::const_eval::{eval_const_expr, const_val, const_bool};
13+
use middle::const_eval::{eval_const_expr, const_val, const_bool, const_float};
1414
use middle::pat_util::*;
1515
use middle::ty::*;
1616
use middle::ty;
@@ -102,6 +102,27 @@ pub fn check_arms(cx: &MatchCheckCtxt, arms: &[arm]) {
102102
let mut seen = ~[];
103103
for arms.iter().advance |arm| {
104104
for arm.pats.iter().advance |pat| {
105+
106+
// Check that we do not match against a static NaN (#6804)
107+
let pat_matches_nan: &fn(@pat) -> bool = |p| {
108+
match cx.tcx.def_map.find(&p.id) {
109+
Some(&def_static(did, false)) => {
110+
let const_expr = lookup_const_by_id(cx.tcx, did).get();
111+
match eval_const_expr(cx.tcx, const_expr) {
112+
const_float(f) if f.is_NaN() => true,
113+
_ => false
114+
}
115+
}
116+
_ => false
117+
}
118+
};
119+
for walk_pat(*pat) |p| {
120+
if pat_matches_nan(p) {
121+
cx.tcx.sess.span_warn(p.span, "unmatchable NaN in pattern, \
122+
use the is_NaN method in a guard instead");
123+
}
124+
}
125+
105126
let v = ~[*pat];
106127
match is_useful(cx, &seen, v) {
107128
not_useful => {

trunk/src/librustc/middle/kind.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use util::ppaux::UserString;
1919
use syntax::ast::*;
2020
use syntax::attr;
2121
use syntax::codemap::span;
22+
use syntax::opt_vec;
2223
use syntax::print::pprust::expr_to_str;
2324
use syntax::{visit, ast_util};
2425

@@ -83,7 +84,7 @@ fn check_struct_safe_for_destructor(cx: Context,
8384
let struct_tpt = ty::lookup_item_type(cx.tcx, struct_did);
8485
if !struct_tpt.generics.has_type_params() {
8586
let struct_ty = ty::mk_struct(cx.tcx, struct_did, ty::substs {
86-
self_r: None,
87+
regions: ty::NonerasedRegions(opt_vec::Empty),
8788
self_ty: None,
8889
tps: ~[]
8990
});

trunk/src/librustc/middle/subst.rs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
use middle::ty;
15+
use syntax::opt_vec::OptVec;
1516
use util::ppaux::Repr;
1617

1718
///////////////////////////////////////////////////////////////////////////
@@ -79,6 +80,12 @@ impl<T:Subst> Subst for ~[T] {
7980
}
8081
}
8182

83+
impl<T:Subst> Subst for OptVec<T> {
84+
fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> OptVec<T> {
85+
self.map(|t| t.subst(tcx, substs))
86+
}
87+
}
88+
8289
impl<T:Subst + 'static> Subst for @T {
8390
fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> @T {
8491
match self {
@@ -105,13 +112,26 @@ impl Subst for ty::TraitRef {
105112
impl Subst for ty::substs {
106113
fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> ty::substs {
107114
ty::substs {
108-
self_r: self.self_r.subst(tcx, substs),
115+
regions: self.regions.subst(tcx, substs),
109116
self_ty: self.self_ty.map(|typ| typ.subst(tcx, substs)),
110117
tps: self.tps.map(|typ| typ.subst(tcx, substs))
111118
}
112119
}
113120
}
114121

122+
impl Subst for ty::RegionSubsts {
123+
fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> ty::RegionSubsts {
124+
match *self {
125+
ty::ErasedRegions => {
126+
ty::ErasedRegions
127+
}
128+
ty::NonerasedRegions(ref regions) => {
129+
ty::NonerasedRegions(regions.subst(tcx, substs))
130+
}
131+
}
132+
}
133+
}
134+
115135
impl Subst for ty::BareFnTy {
116136
fn subst(&self, tcx: ty::ctxt, substs: &ty::substs) -> ty::BareFnTy {
117137
ty::fold_bare_fn_ty(self, |t| t.subst(tcx, substs))
@@ -158,15 +178,18 @@ impl Subst for ty::Region {
158178
// will most likely disappear.
159179
match self {
160180
&ty::re_bound(ty::br_self) => {
161-
match substs.self_r {
162-
None => {
163-
tcx.sess.bug(
164-
fmt!("ty::Region#subst(): \
165-
Reference to self region when \
166-
given substs with no self region: %s",
167-
substs.repr(tcx)));
181+
match substs.regions {
182+
ty::ErasedRegions => ty::re_static,
183+
ty::NonerasedRegions(ref regions) => {
184+
if regions.len() != 1 {
185+
tcx.sess.bug(
186+
fmt!("ty::Region#subst(): \
187+
Reference to self region when \
188+
given substs with no self region: %s",
189+
substs.repr(tcx)));
190+
}
191+
*regions.get(0)
168192
}
169-
Some(self_r) => self_r
170193
}
171194
}
172195
_ => *self

trunk/src/librustc/middle/trans/base.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,8 @@ pub fn get_res_dtor(ccx: @mut CrateContext,
515515
did
516516
};
517517
assert_eq!(did.crate, ast::local_crate);
518-
let tsubsts = ty::substs { self_r: None, self_ty: None,
518+
let tsubsts = ty::substs {regions: ty::ErasedRegions,
519+
self_ty: None,
519520
tps: /*bad*/ substs.to_owned() };
520521
let (val, _) = monomorphize::monomorphic_fn(ccx,
521522
did,

trunk/src/librustc/middle/trans/callee.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,10 @@ pub fn trans_fn_ref_with_vtables(
274274
// Polytype of the function item (may have type params)
275275
let fn_tpt = ty::lookup_item_type(tcx, def_id);
276276

277-
// For simplicity, we want to use the Subst trait when composing
278-
// substitutions for default methods. The subst trait does
279-
// substitutions with regions, though, so we put a dummy self
280-
// region parameter in to keep it from failing. This is a hack.
281-
let substs = ty::substs { self_r: Some(ty::re_empty),
277+
let substs = ty::substs { regions: ty::ErasedRegions,
282278
self_ty: None,
283279
tps: /*bad*/ type_params.to_owned() };
284280

285-
286281
// We need to do a bunch of special handling for default methods.
287282
// We need to modify the def_id and our substs in order to monomorphize
288283
// the function.

trunk/src/librustc/middle/trans/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ pub fn find_vtable(tcx: ty::ctxt,
11031103

11041104
pub fn dummy_substs(tps: ~[ty::t]) -> ty::substs {
11051105
substs {
1106-
self_r: Some(ty::re_bound(ty::br_self)),
1106+
regions: ty::ErasedRegions,
11071107
self_ty: None,
11081108
tps: tps
11091109
}

0 commit comments

Comments
 (0)