Skip to content

Commit b01a101

Browse files
committed
---
yaml --- r: 272823 b: refs/heads/beta c: a331278 h: refs/heads/master i: 272821: e405ba8 272819: 2141e73 272815: a7c7dbb
1 parent af5fc79 commit b01a101

File tree

3 files changed

+90
-6
lines changed

3 files changed

+90
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 5daf13cae371ce4ee90450a1d3006b53395a40d7
26+
refs/heads/beta: a3312784518b9fa95e43f9a2d773acb0c083147a
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/librustc_front/hir.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -777,8 +777,6 @@ pub enum Expr_ {
777777
ExprTupField(P<Expr>, Spanned<usize>),
778778
/// An indexing operation (`foo[2]`)
779779
ExprIndex(P<Expr>, P<Expr>),
780-
/// A range (`1..2`, `1..`, or `..2`)
781-
ExprRange(Option<P<Expr>>, Option<P<Expr>>),
782780

783781
/// Variable reference, possibly containing `::` and/or type
784782
/// parameters, e.g. foo::bar::<baz>.

branches/beta/src/librustc_front/lowering.rs

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ use hir;
6565

6666
use std::collections::BTreeMap;
6767
use std::collections::HashMap;
68+
use std::iter;
6869
use syntax::ast::*;
6970
use syntax::attr::{ThinAttributes, ThinAttributesExt};
7071
use syntax::ext::mtwt;
@@ -1213,9 +1214,74 @@ pub fn lower_expr(lctx: &LoweringContext, e: &Expr) -> P<hir::Expr> {
12131214
ExprKind::Index(ref el, ref er) => {
12141215
hir::ExprIndex(lower_expr(lctx, el), lower_expr(lctx, er))
12151216
}
1216-
ExprKind::Range(ref e1, ref e2) => {
1217-
hir::ExprRange(e1.as_ref().map(|x| lower_expr(lctx, x)),
1218-
e2.as_ref().map(|x| lower_expr(lctx, x)))
1217+
ExprKind::Range(ref e1, ref e2, lims) => {
1218+
fn make_struct(lctx: &LoweringContext,
1219+
ast_expr: &Expr,
1220+
path: &[&str],
1221+
fields: &[(&str, &P<Expr>)]) -> P<hir::Expr> {
1222+
let strs = std_path(lctx, &iter::once(&"ops")
1223+
.chain(path)
1224+
.map(|s| *s)
1225+
.collect::<Vec<_>>());
1226+
1227+
let structpath = path_global(ast_expr.span, strs);
1228+
1229+
let hir_expr = if fields.len() == 0 {
1230+
expr_path(lctx,
1231+
structpath,
1232+
ast_expr.attrs.clone())
1233+
} else {
1234+
expr_struct(lctx,
1235+
ast_expr.span,
1236+
structpath,
1237+
fields.into_iter().map(|&(s, e)| {
1238+
field(token::intern(s),
1239+
lower_expr(lctx, &**e),
1240+
ast_expr.span)
1241+
}).collect(),
1242+
None,
1243+
ast_expr.attrs.clone())
1244+
};
1245+
1246+
signal_block_expr(lctx,
1247+
hir_vec![],
1248+
hir_expr,
1249+
ast_expr.span,
1250+
hir::PushUnstableBlock,
1251+
None)
1252+
}
1253+
1254+
return cache_ids(lctx, e.id, |lctx| {
1255+
use syntax::ast::RangeLimits::*;
1256+
1257+
match (e1, e2, lims) {
1258+
(&None, &None, HalfOpen) =>
1259+
make_struct(lctx, e, &["RangeFull"],
1260+
&[]),
1261+
1262+
(&Some(ref e1), &None, HalfOpen) =>
1263+
make_struct(lctx, e, &["RangeFrom"],
1264+
&[("start", e1)]),
1265+
1266+
(&None, &Some(ref e2), HalfOpen) =>
1267+
make_struct(lctx, e, &["RangeTo"],
1268+
&[("end", e2)]),
1269+
1270+
(&Some(ref e1), &Some(ref e2), HalfOpen) =>
1271+
make_struct(lctx, e, &["Range"],
1272+
&[("start", e1), ("end", e2)]),
1273+
1274+
(&None, &Some(ref e2), Closed) =>
1275+
make_struct(lctx, e, &["RangeToInclusive"],
1276+
&[("end", e2)]),
1277+
1278+
(&Some(ref e1), &Some(ref e2), Closed) =>
1279+
make_struct(lctx, e, &["RangeInclusive", "NonEmpty"],
1280+
&[("start", e1), ("end", e2)]),
1281+
1282+
_ => panic!("impossible range in AST"),
1283+
}
1284+
});
12191285
}
12201286
ExprKind::Path(ref qself, ref path) => {
12211287
let hir_qself = qself.as_ref().map(|&QSelf { ref ty, position }| {
@@ -1632,6 +1698,17 @@ fn arm(pats: hir::HirVec<P<hir::Pat>>, expr: P<hir::Expr>) -> hir::Arm {
16321698
}
16331699
}
16341700

1701+
fn field(name: Name, expr: P<hir::Expr>, span: Span) -> hir::Field {
1702+
hir::Field {
1703+
name: Spanned {
1704+
node: name,
1705+
span: span,
1706+
},
1707+
span: span,
1708+
expr: expr,
1709+
}
1710+
}
1711+
16351712
fn expr_break(lctx: &LoweringContext, span: Span,
16361713
attrs: ThinAttributes) -> P<hir::Expr> {
16371714
expr(lctx, span, hir::ExprBreak(None), attrs)
@@ -1681,6 +1758,15 @@ fn expr_tuple(lctx: &LoweringContext, sp: Span, exprs: hir::HirVec<P<hir::Expr>>
16811758
expr(lctx, sp, hir::ExprTup(exprs), attrs)
16821759
}
16831760

1761+
fn expr_struct(lctx: &LoweringContext,
1762+
sp: Span,
1763+
path: hir::Path,
1764+
fields: hir::HirVec<hir::Field>,
1765+
e: Option<P<hir::Expr>>,
1766+
attrs: ThinAttributes) -> P<hir::Expr> {
1767+
expr(lctx, sp, hir::ExprStruct(path, fields, e), attrs)
1768+
}
1769+
16841770
fn expr(lctx: &LoweringContext, span: Span, node: hir::Expr_,
16851771
attrs: ThinAttributes) -> P<hir::Expr> {
16861772
P(hir::Expr {

0 commit comments

Comments
 (0)