Skip to content

Commit 77d536b

Browse files
committed
---
yaml --- r: 225004 b: refs/heads/stable c: 2520277 h: refs/heads/master v: v3
1 parent 8e471f8 commit 77d536b

File tree

20 files changed

+65
-27
lines changed

20 files changed

+65
-27
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ refs/heads/tmp: e5d90d98402475b6e154ce216f9efcb80da1a747
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: 1fe32ca12c51afcd761d9962f51a74ff0d07a591
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 82447cf5006b0ebdbcf47b796cc521ee0d88f3fa
32+
refs/heads/stable: 252027768eac85cfd98427ba2cbf1d51bfc77d53
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b

branches/stable/src/doc/trpl/references-and-borrowing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ We can’t modify `v` because it’s borrowed by the loop.
297297
References must live as long as the resource they refer to. Rust will check the
298298
scopes of your references to ensure that this is true.
299299

300-
If Rust didn’t check that this property, we could accidentally use a reference
300+
If Rust didn’t check this property, we could accidentally use a reference
301301
which was invalid. For example:
302302

303303
```rust,ignore

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -34,7 +34,7 @@ use std::borrow::{Cow, IntoCow};
3434
use std::num::wrapping::OverflowingOps;
3535
use std::cmp::Ordering;
3636
use std::collections::hash_map::Entry::Vacant;
37-
use std::{i8, i16, i32, i64};
37+
use std::{i8, i16, i32, i64, u8, u16, u32, u64};
3838
use std::rc::Rc;
3939

4040
fn lookup_const<'a>(tcx: &'a ty::ctxt, e: &Expr) -> Option<&'a Expr> {
@@ -461,6 +461,16 @@ pub fn const_uint_checked_neg<'a>(
461461
Ok(const_uint((!a).wrapping_add(1)))
462462
}
463463

464+
fn const_uint_not(a: u64, opt_ety: Option<UintTy>) -> const_val {
465+
let mask = match opt_ety {
466+
Some(UintTy::U8) => u8::MAX as u64,
467+
Some(UintTy::U16) => u16::MAX as u64,
468+
Some(UintTy::U32) => u32::MAX as u64,
469+
None | Some(UintTy::U64) => u64::MAX,
470+
};
471+
const_uint(!a & mask)
472+
}
473+
464474
macro_rules! overflow_checking_body {
465475
($a:ident, $b:ident, $ety:ident, $overflowing_op:ident,
466476
lhs: $to_8_lhs:ident $to_16_lhs:ident $to_32_lhs:ident,
@@ -677,7 +687,7 @@ pub fn eval_const_expr_partial<'tcx>(tcx: &ty::ctxt<'tcx>,
677687
ast::ExprUnary(ast::UnNot, ref inner) => {
678688
match try!(eval_const_expr_partial(tcx, &**inner, ety)) {
679689
const_int(i) => const_int(!i),
680-
const_uint(i) => const_uint(!i),
690+
const_uint(i) => const_uint_not(i, expr_uint_type),
681691
const_bool(b) => const_bool(!b),
682692
const_str(_) => signal!(e, NotOnString),
683693
const_float(_) => signal!(e, NotOnFloat),

branches/stable/src/librustc_typeck/check/mod.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3153,26 +3153,10 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
31533153
Some(&**oprnd), oprnd_t, lvalue_pref) {
31543154
Some(mt) => mt.ty,
31553155
None => {
3156-
let is_newtype = match oprnd_t.sty {
3157-
ty::ty_struct(did, substs) => {
3158-
let fields = ty::struct_fields(fcx.tcx(), did, substs);
3159-
fields.len() == 1
3160-
&& fields[0].name ==
3161-
token::special_idents::unnamed_field.name
3162-
}
3163-
_ => false
3164-
};
3165-
if is_newtype {
3166-
// This is an obsolete struct deref
3167-
span_err!(tcx.sess, expr.span, E0068,
3168-
"single-field tuple-structs can \
3169-
no longer be dereferenced");
3170-
} else {
3171-
fcx.type_error_message(expr.span, |actual| {
3172-
format!("type `{}` cannot be \
3173-
dereferenced", actual)
3174-
}, oprnd_t, None);
3175-
}
3156+
fcx.type_error_message(expr.span, |actual| {
3157+
format!("type `{}` cannot be \
3158+
dereferenced", actual)
3159+
}, oprnd_t, None);
31763160
tcx.types.err
31773161
}
31783162
}

branches/stable/src/libsyntax/ext/deriving/clone.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt,
3939
args: Vec::new(),
4040
ret_ty: Self_,
4141
attributes: attrs,
42+
is_unsafe: false,
4243
combine_substructure: combine_substructure(Box::new(|c, s, sub| {
4344
cs_clone("Clone", c, s, sub)
4445
})),

branches/stable/src/libsyntax/ext/deriving/cmp/eq.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt,
5959
args: vec!(),
6060
ret_ty: nil_ty(),
6161
attributes: attrs,
62+
is_unsafe: false,
6263
combine_substructure: combine_substructure(Box::new(|a, b, c| {
6364
cs_total_eq_assert(a, b, c)
6465
}))

branches/stable/src/libsyntax/ext/deriving/cmp/ord.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt,
4040
args: vec!(borrowed_self()),
4141
ret_ty: Literal(path_std!(cx, core::cmp::Ordering)),
4242
attributes: attrs,
43+
is_unsafe: false,
4344
combine_substructure: combine_substructure(Box::new(|a, b, c| {
4445
cs_cmp(a, b, c)
4546
})),

branches/stable/src/libsyntax/ext/deriving/cmp/partial_eq.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub fn expand_deriving_partial_eq(cx: &mut ExtCtxt,
7171
args: vec!(borrowed_self()),
7272
ret_ty: Literal(path_local!(bool)),
7373
attributes: attrs,
74+
is_unsafe: false,
7475
combine_substructure: combine_substructure(Box::new(|a, b, c| {
7576
$f(a, b, c)
7677
}))

branches/stable/src/libsyntax/ext/deriving/cmp/partial_ord.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
3737
args: vec!(borrowed_self()),
3838
ret_ty: Literal(path_local!(bool)),
3939
attributes: attrs,
40+
is_unsafe: false,
4041
combine_substructure: combine_substructure(Box::new(|cx, span, substr| {
4142
cs_op($op, $equal, cx, span, substr)
4243
}))
@@ -60,6 +61,7 @@ pub fn expand_deriving_partial_ord(cx: &mut ExtCtxt,
6061
args: vec![borrowed_self()],
6162
ret_ty: ret_ty,
6263
attributes: attrs,
64+
is_unsafe: false,
6365
combine_substructure: combine_substructure(Box::new(|cx, span, substr| {
6466
cs_partial_cmp(cx, span, substr)
6567
}))

branches/stable/src/libsyntax/ext/deriving/decodable.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ fn expand_deriving_decodable_imp(cx: &mut ExtCtxt,
7979
true
8080
)),
8181
attributes: Vec::new(),
82+
is_unsafe: false,
8283
combine_substructure: combine_substructure(Box::new(|a, b, c| {
8384
decodable_substructure(a, b, c, krate)
8485
})),

branches/stable/src/libsyntax/ext/deriving/default.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt,
3939
args: Vec::new(),
4040
ret_ty: Self_,
4141
attributes: attrs,
42+
is_unsafe: false,
4243
combine_substructure: combine_substructure(Box::new(|a, b, c| {
4344
default_substructure(a, b, c)
4445
}))

branches/stable/src/libsyntax/ext/deriving/encodable.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ fn expand_deriving_encodable_imp(cx: &mut ExtCtxt,
155155
true
156156
)),
157157
attributes: Vec::new(),
158+
is_unsafe: false,
158159
combine_substructure: combine_substructure(Box::new(|a, b, c| {
159160
encodable_substructure(a, b, c)
160161
})),

branches/stable/src/libsyntax/ext/deriving/generic/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ pub struct MethodDef<'a> {
253253

254254
pub attributes: Vec<ast::Attribute>,
255255

256+
// Is it an `unsafe fn`?
257+
pub is_unsafe: bool,
258+
256259
pub combine_substructure: RefCell<CombineSubstructureFunc<'a>>,
257260
}
258261

@@ -859,6 +862,12 @@ impl<'a> MethodDef<'a> {
859862
let fn_decl = cx.fn_decl(args, ret_type);
860863
let body_block = cx.block_expr(body);
861864

865+
let unsafety = if self.is_unsafe {
866+
ast::Unsafety::Unsafe
867+
} else {
868+
ast::Unsafety::Normal
869+
};
870+
862871
// Create the method.
863872
P(ast::ImplItem {
864873
id: ast::DUMMY_NODE_ID,
@@ -870,7 +879,7 @@ impl<'a> MethodDef<'a> {
870879
generics: fn_generics,
871880
abi: abi,
872881
explicit_self: explicit_self,
873-
unsafety: ast::Unsafety::Normal,
882+
unsafety: unsafety,
874883
decl: fn_decl
875884
}, body_block)
876885
})

branches/stable/src/libsyntax/ext/deriving/hash.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt,
4444
args: vec!(Ptr(Box::new(Literal(arg)), Borrowed(None, MutMutable))),
4545
ret_ty: nil_ty(),
4646
attributes: vec![],
47+
is_unsafe: false,
4748
combine_substructure: combine_substructure(Box::new(|a, b, c| {
4849
hash_substructure(a, b, c)
4950
}))

branches/stable/src/libsyntax/ext/deriving/primitive.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
4444
true)),
4545
// #[inline] liable to cause code-bloat
4646
attributes: attrs.clone(),
47+
is_unsafe: false,
4748
combine_substructure: combine_substructure(Box::new(|c, s, sub| {
4849
cs_from("i64", c, s, sub)
4950
})),
@@ -59,6 +60,7 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt,
5960
true)),
6061
// #[inline] liable to cause code-bloat
6162
attributes: attrs,
63+
is_unsafe: false,
6264
combine_substructure: combine_substructure(Box::new(|c, s, sub| {
6365
cs_from("u64", c, s, sub)
6466
})),

branches/stable/src/libsyntax/ext/deriving/show.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub fn expand_deriving_show(cx: &mut ExtCtxt,
4242
args: vec!(fmtr),
4343
ret_ty: Literal(path_std!(cx, core::fmt::Result)),
4444
attributes: Vec::new(),
45+
is_unsafe: false,
4546
combine_substructure: combine_substructure(Box::new(|a, b, c| {
4647
show_substructure(a, b, c)
4748
}))

branches/stable/src/libsyntax/feature_gate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
258258
("no_builtins", Whitelisted),
259259
("no_mangle", Whitelisted),
260260
("no_stack_check", Whitelisted),
261-
("packed", Whitelisted),
262261
("static_assert", Gated("static_assert",
263262
"`#[static_assert]` is an experimental feature, and has a poor API")),
264263
("no_debug", Whitelisted),

branches/stable/src/test/auxiliary/custom_derive_plugin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ fn expand(cx: &mut ExtCtxt,
5454
args: vec![],
5555
ret_ty: Literal(Path::new_local("isize")),
5656
attributes: vec![],
57+
is_unsafe: false,
5758
combine_substructure: combine_substructure(box |cx, span, substr| {
5859
let zero = cx.expr_isize(span, 0);
5960
cs_fold(false,

branches/stable/src/test/auxiliary/custom_derive_plugin_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ fn expand(cx: &mut ExtCtxt,
5656
args: vec![],
5757
ret_ty: Literal(Path::new_local("isize")),
5858
attributes: vec![],
59+
is_unsafe: false,
5960
combine_substructure: combine_substructure(Box::new(totalsum_substructure)),
6061
},
6162
],
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
const U8_MAX_HALF: u8 = !0u8 / 2;
12+
const U16_MAX_HALF: u16 = !0u16 / 2;
13+
const U32_MAX_HALF: u32 = !0u32 / 2;
14+
const U64_MAX_HALF: u64 = !0u64 / 2;
15+
16+
fn main() {
17+
assert_eq!(U8_MAX_HALF, 0x7f);
18+
assert_eq!(U16_MAX_HALF, 0x7fff);
19+
assert_eq!(U32_MAX_HALF, 0x7fff_ffff);
20+
assert_eq!(U64_MAX_HALF, 0x7fff_ffff_ffff_ffff);
21+
}

0 commit comments

Comments
 (0)