Skip to content

Commit e793982

Browse files
committed
---
yaml --- r: 152619 b: refs/heads/try2 c: 410d70b h: refs/heads/master i: 152617: 82090d2 152615: e9e56e8 v: v3
1 parent 1fe2351 commit e793982

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+921
-473
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: feceb1276e3f7848fb6bee0a130065f6b1c56daf
8+
refs/heads/try2: 410d70b5af30a4e5d566b981c9bf1b10b12b796b
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/rust.md

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ rule. A literal is a form of constant expression, so is evaluated (primarily)
234234
at compile time.
235235

236236
~~~~ {.ebnf .gram}
237-
literal : string_lit | char_lit | num_lit ;
237+
literal : string_lit | char_lit | byte_string_lit | byte_lit | num_lit ;
238238
~~~~
239239

240240
#### Character and string literals
@@ -244,17 +244,17 @@ char_lit : '\x27' char_body '\x27' ;
244244
string_lit : '"' string_body * '"' | 'r' raw_string ;
245245
246246
char_body : non_single_quote
247-
| '\x5c' [ '\x27' | common_escape ] ;
247+
| '\x5c' [ '\x27' | common_escape | unicode_escape ] ;
248248
249249
string_body : non_double_quote
250-
| '\x5c' [ '\x22' | common_escape ] ;
250+
| '\x5c' [ '\x22' | common_escape | unicode_escape ] ;
251251
raw_string : '"' raw_string_body '"' | '#' raw_string '#' ;
252252
253253
common_escape : '\x5c'
254254
| 'n' | 'r' | 't' | '0'
255255
| 'x' hex_digit 2
256-
| 'u' hex_digit 4
257-
| 'U' hex_digit 8 ;
256+
unicode_escape : 'u' hex_digit 4
257+
| 'U' hex_digit 8 ;
258258
259259
hex_digit : 'a' | 'b' | 'c' | 'd' | 'e' | 'f'
260260
| 'A' | 'B' | 'C' | 'D' | 'E' | 'F'
@@ -294,7 +294,7 @@ the following forms:
294294
escaped in order to denote *itself*.
295295

296296
Raw string literals do not process any escapes. They start with the character
297-
`U+0072` (`r`), followed zero or more of the character `U+0023` (`#`) and a
297+
`U+0072` (`r`), followed by zero or more of the character `U+0023` (`#`) and a
298298
`U+0022` (double-quote) character. The _raw string body_ is not defined in the
299299
EBNF grammar above: it can contain any sequence of Unicode characters and is
300300
terminated only by another `U+0022` (double-quote) character, followed by the
@@ -319,6 +319,65 @@ r##"foo #"# bar"##; // foo #"# bar
319319
"\\x52"; r"\x52"; // \x52
320320
~~~~
321321

322+
#### Byte and byte string literals
323+
324+
~~~~ {.ebnf .gram}
325+
byte_lit : 'b' '\x27' byte_body '\x27' ;
326+
byte_string_lit : 'b' '"' string_body * '"' | 'b' 'r' raw_byte_string ;
327+
328+
byte_body : ascii_non_single_quote
329+
| '\x5c' [ '\x27' | common_escape ] ;
330+
331+
byte_string_body : ascii_non_double_quote
332+
| '\x5c' [ '\x22' | common_escape ] ;
333+
raw_byte_string : '"' raw_byte_string_body '"' | '#' raw_byte_string '#' ;
334+
335+
~~~~
336+
337+
A _byte literal_ is a single ASCII character (in the `U+0000` to `U+007F` range)
338+
enclosed within two `U+0027` (single-quote) characters,
339+
with the exception of `U+0027` itself,
340+
which must be _escaped_ by a preceding U+005C character (`\`),
341+
or a single _escape_.
342+
It is equivalent to a `u8` unsigned 8-bit integer _number literal_.
343+
344+
A _byte string literal_ is a sequence of ASCII characters and _escapes_
345+
enclosed within two `U+0022` (double-quote) characters,
346+
with the exception of `U+0022` itself,
347+
which must be _escaped_ by a preceding `U+005C` character (`\`),
348+
or a _raw byte string literal_.
349+
It is equivalent to a `&'static [u8]` borrowed vectior unsigned 8-bit integers.
350+
351+
Some additional _escapes_ are available in either byte or non-raw byte string
352+
literals. An escape starts with a `U+005C` (`\`) and continues with one of
353+
the following forms:
354+
355+
* An _byte escape_ escape starts with `U+0078` (`x`) and is
356+
followed by exactly two _hex digits_. It denotes the byte
357+
equal to the provided hex value.
358+
* A _whitespace escape_ is one of the characters `U+006E` (`n`), `U+0072`
359+
(`r`), or `U+0074` (`t`), denoting the bytes values `0x0A` (ASCII LF),
360+
`0x0D` (ASCII CR) or `0x09` (ASCII HT) respectively.
361+
* The _backslash escape_ is the character `U+005C` (`\`) which must be
362+
escaped in order to denote its ASCII encoding `0x5C`.
363+
364+
Raw byte string literals do not process any escapes.
365+
They start with the character `U+0072` (`r`),
366+
followed by `U+0062` (`b`),
367+
followed by zero or more of the character `U+0023` (`#`),
368+
and a `U+0022` (double-quote) character.
369+
The _raw string body_ is not defined in the EBNF grammar above:
370+
it can contain any sequence of ASCII characters and is
371+
terminated only by another `U+0022` (double-quote) character, followed by the
372+
same number of `U+0023` (`#`) characters that preceded the opening `U+0022`
373+
(double-quote) character.
374+
A raw byte string literal can not contain any non-ASCII byte.
375+
376+
All characters contained in the raw string body represent their ASCII encoding,
377+
the characters `U+0022` (double-quote) (except when followed by at least as
378+
many `U+0023` (`#`) characters as were used to start the raw string literal) or
379+
`U+005C` (`\`) do not have any special meaning.
380+
322381
#### Number literals
323382

324383
~~~~ {.ebnf .gram}

branches/try2/src/libcore/str.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ Section: Comparing strings
560560

561561
// share the implementation of the lang-item vs. non-lang-item
562562
// eq_slice.
563+
/// NOTE: This function is (ab)used in rustc::middle::trans::_match
564+
/// to compare &[u8] byte slices that are not necessarily valid UTF-8.
563565
#[inline]
564566
fn eq_slice_(a: &str, b: &str) -> bool {
565567
#[allow(ctypes)]
@@ -572,6 +574,8 @@ fn eq_slice_(a: &str, b: &str) -> bool {
572574
}
573575

574576
/// Bytewise slice equality
577+
/// NOTE: This function is (ab)used in rustc::middle::trans::_match
578+
/// to compare &[u8] byte slices that are not necessarily valid UTF-8.
575579
#[cfg(not(test))]
576580
#[lang="str_eq"]
577581
#[inline]

branches/try2/src/libregex_macros/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,
182182
#[allow(unused_variable)]
183183
fn run(&mut self, start: uint, end: uint) -> Vec<Option<uint>> {
184184
let mut matched = false;
185-
let prefix_bytes: &[u8] = &$prefix_bytes;
185+
let prefix_bytes: &[u8] = $prefix_bytes;
186186
let mut clist = &mut Threads::new(self.which);
187187
let mut nlist = &mut Threads::new(self.which);
188188

branches/try2/src/librustc/metadata/tydecode.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,9 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
346346
assert_eq!(next(st), '[');
347347
let def = parse_def(st, NominalType, |x,y| conv(x,y));
348348
let substs = parse_substs(st, |x,y| conv(x,y));
349-
let store = parse_trait_store(st, |x,y| conv(x,y));
350349
let bounds = parse_bounds(st, |x,y| conv(x,y));
351350
assert_eq!(next(st), ']');
352-
return ty::mk_trait(st.tcx, def, substs, store, bounds.builtin_bounds);
351+
return ty::mk_trait(st.tcx, def, substs, bounds.builtin_bounds);
353352
}
354353
'p' => {
355354
let did = parse_def(st, TypeParameter, |x,y| conv(x,y));

branches/try2/src/librustc/metadata/tyencode.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,10 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
232232
ty::ty_trait(box ty::TyTrait {
233233
def_id,
234234
ref substs,
235-
store,
236235
bounds
237236
}) => {
238237
mywrite!(w, "x[{}|", (cx.ds)(def_id));
239238
enc_substs(w, cx, substs);
240-
enc_trait_store(w, cx, store);
241239
let bounds = ty::ParamBounds {builtin_bounds: bounds,
242240
trait_bounds: Vec::new()};
243241
enc_bounds(w, cx, &bounds);

branches/try2/src/librustc/middle/const_eval.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,7 @@ pub fn lit_to_const(lit: &Lit) -> const_val {
506506
LitBinary(ref data) => {
507507
const_binary(Rc::new(data.iter().map(|x| *x).collect()))
508508
}
509+
LitByte(n) => const_uint(n as u64),
509510
LitChar(n) => const_uint(n as u64),
510511
LitInt(n, _) => const_int(n),
511512
LitUint(n, _) => const_uint(n),
@@ -528,6 +529,7 @@ pub fn compare_const_vals(a: &const_val, b: &const_val) -> Option<int> {
528529
(&const_float(a), &const_float(b)) => compare_vals(a, b),
529530
(&const_str(ref a), &const_str(ref b)) => compare_vals(a, b),
530531
(&const_bool(a), &const_bool(b)) => compare_vals(a, b),
532+
(&const_binary(ref a), &const_binary(ref b)) => compare_vals(a, b),
531533
_ => None
532534
}
533535
}

branches/try2/src/librustc/middle/kind.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,12 @@ fn check_bounds_on_type_parameters(cx: &mut Context, e: &Expr) {
361361
fn check_trait_cast(cx: &mut Context, source_ty: ty::t, target_ty: ty::t, span: Span) {
362362
check_cast_for_escaping_regions(cx, source_ty, target_ty, span);
363363
match ty::get(target_ty).sty {
364-
ty::ty_trait(box ty::TyTrait { bounds, .. }) => {
365-
check_trait_cast_bounds(cx, span, source_ty, bounds);
366-
}
364+
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ ty, .. }) => match ty::get(ty).sty {
365+
ty::ty_trait(box ty::TyTrait { bounds, .. }) => {
366+
check_trait_cast_bounds(cx, span, source_ty, bounds);
367+
}
368+
_ => {}
369+
},
367370
_ => {}
368371
}
369372
}
@@ -530,9 +533,8 @@ pub fn check_cast_for_escaping_regions(
530533
{
531534
// Determine what type we are casting to; if it is not a trait, then no
532535
// worries.
533-
match ty::get(target_ty).sty {
534-
ty::ty_trait(..) => {}
535-
_ => { return; }
536+
if !ty::type_is_trait(target_ty) {
537+
return;
536538
}
537539

538540
// Collect up the regions that appear in the target type. We want to

branches/try2/src/librustc/middle/lint.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ fn check_type_limits(cx: &Context, e: &ast::Expr) {
805805
} else { t };
806806
let (min, max) = uint_ty_range(uint_type);
807807
let lit_val: u64 = match lit.node {
808+
ast::LitByte(_v) => return, // _v is u8, within range by definition
808809
ast::LitInt(v, _) => v as u64,
809810
ast::LitUint(v, _) => v,
810811
ast::LitIntUnsuffixed(v) => v as u64,
@@ -980,9 +981,6 @@ fn check_heap_type(cx: &Context, span: Span, ty: ty::t) {
980981
n_box += 1;
981982
}
982983
ty::ty_uniq(_) |
983-
ty::ty_trait(box ty::TyTrait {
984-
store: ty::UniqTraitStore, ..
985-
}) |
986984
ty::ty_closure(box ty::ClosureTy {
987985
store: ty::UniqTraitStore,
988986
..

branches/try2/src/librustc/middle/mem_categorization.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ pub enum deref_kind {
174174
pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
175175
match ty::get(t).sty {
176176
ty::ty_uniq(_) |
177-
ty::ty_trait(box ty::TyTrait { store: ty::UniqTraitStore, .. }) |
178177
ty::ty_closure(box ty::ClosureTy {store: ty::UniqTraitStore, ..}) => {
179178
Some(deref_ptr(OwnedPtr))
180179
}
@@ -183,13 +182,6 @@ pub fn opt_deref_kind(t: ty::t) -> Option<deref_kind> {
183182
let kind = ty::BorrowKind::from_mutbl(mt.mutbl);
184183
Some(deref_ptr(BorrowedPtr(kind, r)))
185184
}
186-
ty::ty_trait(box ty::TyTrait {
187-
store: ty::RegionTraitStore(r, mutbl),
188-
..
189-
}) => {
190-
let kind = ty::BorrowKind::from_mutbl(mutbl);
191-
Some(deref_ptr(BorrowedPtr(kind, r)))
192-
}
193185

194186
ty::ty_closure(box ty::ClosureTy {
195187
store: ty::RegionTraitStore(r, _),

branches/try2/src/librustc/middle/trans/_match.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,13 +1273,24 @@ fn compare_values<'a>(
12731273
val: bool_to_i1(result.bcx, result.val)
12741274
}
12751275
}
1276-
_ => cx.sess().bug("only scalars and strings supported in compare_values"),
1276+
_ => cx.sess().bug("only strings supported in compare_values"),
12771277
},
12781278
ty::ty_rptr(_, mt) => match ty::get(mt.ty).sty {
12791279
ty::ty_str => compare_str(cx, lhs, rhs, rhs_t),
1280-
_ => cx.sess().bug("only scalars and strings supported in compare_values"),
1280+
ty::ty_vec(mt, _) => match ty::get(mt.ty).sty {
1281+
ty::ty_uint(ast::TyU8) => {
1282+
// NOTE: cast &[u8] to &str and abuse the str_eq lang item,
1283+
// which calls memcmp().
1284+
let t = ty::mk_str_slice(cx.tcx(), ty::ReStatic, ast::MutImmutable);
1285+
let lhs = BitCast(cx, lhs, type_of::type_of(cx.ccx(), t).ptr_to());
1286+
let rhs = BitCast(cx, rhs, type_of::type_of(cx.ccx(), t).ptr_to());
1287+
compare_str(cx, lhs, rhs, rhs_t)
1288+
},
1289+
_ => cx.sess().bug("only byte strings supported in compare_values"),
1290+
},
1291+
_ => cx.sess().bug("on string and byte strings supported in compare_values"),
12811292
},
1282-
_ => cx.sess().bug("only scalars and strings supported in compare_values"),
1293+
_ => cx.sess().bug("only scalars, byte strings, and strings supported in compare_values"),
12831294
}
12841295
}
12851296

branches/try2/src/librustc/middle/trans/adt.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,11 @@ impl Case {
292292
fn find_ptr(&self) -> Option<uint> {
293293
self.tys.iter().position(|&ty| {
294294
match ty::get(ty).sty {
295-
ty::ty_rptr(_, mt) => match ty::get(mt.ty).sty {
296-
ty::ty_vec(_, None) | ty::ty_str => false,
295+
ty::ty_uniq(ty) | ty::ty_rptr(_, ty::mt{ty, ..}) => match ty::get(ty).sty {
296+
ty::ty_vec(_, None) | ty::ty_str| ty::ty_trait(..) => false,
297297
_ => true,
298298
},
299-
ty::ty_uniq(..) | ty::ty_box(..) |
300-
ty::ty_bare_fn(..) => true,
299+
ty::ty_box(..) | ty::ty_bare_fn(..) => true,
301300
// Is that everything? Would closures or slices qualify?
302301
_ => false
303302
}

branches/try2/src/librustc/middle/trans/base.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,9 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6
17941794
match ty::get(ret_ty).sty {
17951795
// `~` pointer return values never alias because ownership
17961796
// is transferred
1797+
ty::ty_uniq(it) if match ty::get(it).sty {
1798+
ty::ty_str | ty::ty_vec(..) | ty::ty_trait(..) => true, _ => false
1799+
} => {}
17971800
ty::ty_uniq(_) => {
17981801
attrs.push((lib::llvm::ReturnIndex as uint, lib::llvm::NoAliasAttribute as u64));
17991802
}
@@ -1803,9 +1806,9 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6
18031806
// We can also mark the return value as `nonnull` in certain cases
18041807
match ty::get(ret_ty).sty {
18051808
// These are not really pointers but pairs, (pointer, len)
1806-
ty::ty_rptr(_, ty::mt { ty: it, .. }) |
1809+
ty::ty_uniq(it) |
18071810
ty::ty_rptr(_, ty::mt { ty: it, .. }) if match ty::get(it).sty {
1808-
ty::ty_str | ty::ty_vec(..) => true, _ => false
1811+
ty::ty_str | ty::ty_vec(..) | ty::ty_trait(..) => true, _ => false
18091812
} => {}
18101813
ty::ty_uniq(_) | ty::ty_rptr(_, _) => {
18111814
attrs.push((lib::llvm::ReturnIndex as uint, lib::llvm::NonNullAttribute as u64));

branches/try2/src/librustc/middle/trans/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn type_is_immediate(ccx: &CrateContext, ty: ty::t) -> bool {
6767
ty::type_is_unique(ty) || ty::type_is_region_ptr(ty) ||
6868
type_is_newtype_immediate(ccx, ty) || ty::type_is_bot(ty) ||
6969
ty::type_is_simd(tcx, ty);
70-
if simple {
70+
if simple && !ty::type_is_trait(ty) {
7171
return true;
7272
}
7373
match ty::get(ty).sty {

branches/try2/src/librustc/middle/trans/consts.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: ast::Lit)
4343
-> ValueRef {
4444
let _icx = push_ctxt("trans_lit");
4545
match lit.node {
46+
ast::LitByte(b) => C_integral(Type::uint_from_ty(cx, ast::TyU8), b as u64, false),
4647
ast::LitChar(i) => C_integral(Type::char(cx), i as u64, false),
4748
ast::LitInt(i, t) => C_integral(Type::int_from_ty(cx, t), i as u64, true),
4849
ast::LitUint(u, t) => C_integral(Type::uint_from_ty(cx, t), u, false),
@@ -143,7 +144,9 @@ fn const_deref(cx: &CrateContext, v: ValueRef, t: ty::t, explicit: bool)
143144
let dv = match ty::get(t).sty {
144145
ty::ty_ptr(mt) | ty::ty_rptr(_, mt) => {
145146
match ty::get(mt.ty).sty {
146-
ty::ty_vec(_, None) | ty::ty_str => cx.sess().bug("unexpected slice"),
147+
ty::ty_vec(_, None) | ty::ty_str | ty::ty_trait(..) => {
148+
cx.sess().bug("unexpected unsized type")
149+
}
147150
_ => const_deref_ptr(cx, v),
148151
}
149152
}

branches/try2/src/librustc/middle/trans/datum.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,7 @@ pub fn appropriate_rvalue_mode(ccx: &CrateContext, ty: ty::t) -> RvalueMode {
157157
* on whether type is immediate or not.
158158
*/
159159

160-
if type_is_zero_size(ccx, ty) {
161-
ByValue
162-
} else if type_is_immediate(ccx, ty) {
160+
if type_is_immediate(ccx, ty) {
163161
ByValue
164162
} else {
165163
ByRef

0 commit comments

Comments
 (0)