Skip to content

Commit 5dd79ce

Browse files
dotdashthestinger
authored andcommitted
---
yaml --- r: 157460 b: refs/heads/snap-stage3 c: 6c18e50 h: refs/heads/master v: v3
1 parent c07f491 commit 5dd79ce

32 files changed

+765
-551
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 065caf34f5ff29e04605f95d9c5d511af219439a
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 80e5fe1a56bb95e8e89d5f8f0ff5122583bb5336
4+
refs/heads/snap-stage3: 6c18e508f10aa5bf42dc80691654b9cde2a661cd
55
refs/heads/try: 0ee4d8b0b112c608646fa75463ab4dc59132efd9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/doc/guide.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3466,14 +3466,13 @@ for destroying that resource as well. Given that we're discussing pointers
34663466
right now, let's discuss this in the context of memory allocation, though
34673467
it applies to other resources as well.
34683468

3469-
When you allocate heap memory, you need a mechanism to free that memory. Many
3470-
languages use a garbage collector to handle deallocation. This is a valid,
3471-
time-tested strategy, but it's not without its drawbacks: it adds overhead, and
3472-
can lead to unpredictable pauses in execution. Because the programmer does not
3473-
have to think as much about deallocation, allocation becomes something
3474-
commonplace, leading to more memory usage. And if you need precise control
3475-
over when something is deallocated, leaving it up to your runtime can make this
3476-
difficult.
3469+
When you allocate heap memory, you need a mechanism to free that memory. Many
3470+
languages let the programmer control the allocation, and then use a garbage
3471+
collector to handle the deallocation. This is a valid, time-tested strategy,
3472+
but it's not without its drawbacks. Because the programmer does not have to
3473+
think as much about deallocation, allocation becomes something commonplace,
3474+
because it's easy. And if you need precise control over when something is
3475+
deallocated, leaving it up to your runtime can make this difficult.
34773476

34783477
Rust chooses a different path, and that path is called **ownership**. Any
34793478
binding that creates a resource is the **owner** of that resource.
@@ -3499,19 +3498,17 @@ memory. The length of time that the borrower is borrowing the pointer
34993498
from you is called a **lifetime**.
35003499

35013500
If two distinct bindings share a pointer, and the memory that pointer points to
3502-
is immutable, then there are no problems. But if it's mutable, the result of
3503-
changing it can vary unpredictably depending on who happens to access it first,
3504-
which is called a **race condition**. To avoid this, if someone wants to mutate
3505-
something that they've borrowed from you, you must not have lent out that
3506-
pointer to anyone else.
3501+
is immutable, then there are no problems. But if it's mutable, both pointers
3502+
can attempt to write to the memory at the same time, causing a **race
3503+
condition**. Therefore, if someone wants to mutate something that they've
3504+
borrowed from you, you must not have lent out that pointer to anyone else.
35073505

35083506
Rust has a sophisticated system called the **borrow checker** to make sure that
35093507
everyone plays by these rules. At compile time, it verifies that none of these
3510-
rules are broken. If our program compiles successfully, Rust can guarantee it
3511-
is free of data races and other memory errors, and there is no runtime overhead
3512-
for any of this. The borrow checker works only at compile time. If the borrow
3513-
checker did find a problem, it will report a **lifetime error**, and your
3514-
program will refuse to compile.
3508+
rules are broken. If there's no problem, our program compiles successfully, and
3509+
there is no runtime overhead for any of this. The borrow checker works only at
3510+
compile time. If the borrow checker did find a problem, it will report a
3511+
**lifetime error**, and your program will refuse to compile.
35153512

35163513
That's a lot to take in. It's also one of the _most_ important concepts in
35173514
all of Rust. Let's see this syntax in action:

branches/snap-stage3/src/liballoc/heap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ unsafe fn exchange_free(ptr: *mut u8, size: uint, align: uint) {
112112
#[cfg(any(target_arch = "arm",
113113
target_arch = "mips",
114114
target_arch = "mipsel"))]
115-
static MIN_ALIGN: uint = 8;
115+
const MIN_ALIGN: uint = 8;
116116
#[cfg(any(target_arch = "x86",
117117
target_arch = "x86_64"))]
118-
static MIN_ALIGN: uint = 16;
118+
const MIN_ALIGN: uint = 16;
119119

120120
#[cfg(jemalloc)]
121121
mod imp {

branches/snap-stage3/src/libcore/intrinsics.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -260,17 +260,6 @@ extern "rust-intrinsic" {
260260
/// NB: This is very different from the `unreachable!()` macro!
261261
pub fn unreachable() -> !;
262262

263-
/// Inform the optimizer that a condition is always true.
264-
/// If the condition is false, the behavior is undefined.
265-
///
266-
/// No code is generated for this intrinsic, but the optimizer will try
267-
/// to preserve it (and its condition) between passes, which may interfere
268-
/// with optimization of surrounding code and reduce performance. It should
269-
/// not be used if the invariant can be discovered by the optimizer on its
270-
/// own, or if it does not enable any significant optimizations.
271-
#[cfg(not(stage0))]
272-
pub fn assume(b: bool);
273-
274263
/// Execute a breakpoint trap, for inspection by a debugger.
275264
pub fn breakpoint();
276265

branches/snap-stage3/src/librustc/diagnostics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ register_diagnostics!(
4444
E0025,
4545
E0026,
4646
E0027,
47+
E0028,
4748
E0029,
4849
E0030,
4950
E0031,
51+
E0032,
5052
E0033,
5153
E0034,
5254
E0035,

branches/snap-stage3/src/librustc/metadata/decoder.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -673,14 +673,9 @@ pub fn get_enum_variants(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
673673
let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id},
674674
item, tcx, cdata);
675675
let name = item_name(&*intr, item);
676-
let (ctor_ty, arg_tys) = match ty::get(ctor_ty).sty {
677-
ty::ty_bare_fn(ref f) =>
678-
(Some(ctor_ty), f.sig.inputs.clone()),
679-
_ => // Nullary or struct enum variant.
680-
(None, get_struct_fields(intr.clone(), cdata, did.node)
681-
.iter()
682-
.map(|field_ty| get_type(cdata, field_ty.id.node, tcx).ty)
683-
.collect())
676+
let arg_tys = match ty::get(ctor_ty).sty {
677+
ty::ty_bare_fn(ref f) => f.sig.inputs.clone(),
678+
_ => Vec::new(), // Nullary enum variant.
684679
};
685680
match variant_disr_val(item) {
686681
Some(val) => { disr_val = val; }

branches/snap-stage3/src/librustc/middle/privacy.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -667,12 +667,21 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
667667

668668
let struct_type = ty::lookup_item_type(self.tcx, id).ty;
669669
let struct_desc = match ty::get(struct_type).sty {
670-
ty::ty_struct(_, _) =>
671-
format!("struct `{}`", ty::item_path_str(self.tcx, id)),
672-
ty::ty_enum(enum_id, _) =>
670+
ty::ty_struct(_, _) => format!("struct `{}`", ty::item_path_str(self.tcx, id)),
671+
ty::ty_bare_fn(ty::BareFnTy { sig: ty::FnSig { output, .. }, .. }) => {
672+
// Struct `id` is really a struct variant of an enum,
673+
// and we're really looking at the variant's constructor
674+
// function. So get the return type for a detailed error
675+
// message.
676+
let enum_id = match ty::get(output).sty {
677+
ty::ty_enum(id, _) => id,
678+
_ => self.tcx.sess.span_bug(span, "enum variant doesn't \
679+
belong to an enum")
680+
};
673681
format!("variant `{}` of enum `{}`",
674682
ty::with_path(self.tcx, id, |mut p| p.last().unwrap()),
675-
ty::item_path_str(self.tcx, enum_id)),
683+
ty::item_path_str(self.tcx, enum_id))
684+
}
676685
_ => self.tcx.sess.span_bug(span, "can't find struct for field")
677686
};
678687
let msg = match name {

branches/snap-stage3/src/librustc/middle/resolve.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5077,6 +5077,7 @@ impl<'a> Resolver<'a> {
50775077
PatEnum(ref path, _) => {
50785078
// This must be an enum variant, struct or const.
50795079
match self.resolve_path(pat_id, path, ValueNS, false) {
5080+
Some(def @ (DefFn(..), _)) |
50805081
Some(def @ (DefVariant(..), _)) |
50815082
Some(def @ (DefStruct(..), _)) |
50825083
Some(def @ (DefConst(..), _)) => {

branches/snap-stage3/src/librustc/middle/trans/context.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,6 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option<ValueRef
860860
ifn!("llvm.lifetime.end" fn(t_i64, i8p) -> void);
861861

862862
ifn!("llvm.expect.i1" fn(i1, i1) -> i1);
863-
ifn!("llvm.assume" fn(i1) -> void);
864863

865864
// Some intrinsics were introduced in later versions of LLVM, but they have
866865
// fallbacks in libc or libm and such. Currently, all of these intrinsics

branches/snap-stage3/src/librustc/middle/trans/intrinsic.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ pub fn get_simple_intrinsic(ccx: &CrateContext, item: &ast::ForeignItem) -> Opti
8181
"bswap16" => "llvm.bswap.i16",
8282
"bswap32" => "llvm.bswap.i32",
8383
"bswap64" => "llvm.bswap.i64",
84-
"assume" => "llvm.assume",
8584
_ => return None
8685
};
8786
Some(ccx.get_intrinsic(&name))

branches/snap-stage3/src/librustc/middle/ty.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use syntax::ast::{CrateNum, DefId, FnStyle, Ident, ItemTrait, LOCAL_CRATE};
5050
use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId};
5151
use syntax::ast::{Onceness, StmtExpr, StmtSemi, StructField, UnnamedField};
5252
use syntax::ast::{Visibility};
53-
use syntax::ast_util::{mod, is_local, lit_is_str, local_def, PostExpansionMethod};
53+
use syntax::ast_util::{mod, PostExpansionMethod, is_local, lit_is_str};
5454
use syntax::attr::{mod, AttrMetaMethods};
5555
use syntax::codemap::Span;
5656
use syntax::parse::token::{mod, InternedString};
@@ -4221,7 +4221,7 @@ pub fn ty_to_def_id(ty: t) -> Option<ast::DefId> {
42214221
pub struct VariantInfo {
42224222
pub args: Vec<t>,
42234223
pub arg_names: Option<Vec<ast::Ident> >,
4224-
pub ctor_ty: Option<t>,
4224+
pub ctor_ty: t,
42254225
pub name: ast::Name,
42264226
pub id: ast::DefId,
42274227
pub disr_val: Disr,
@@ -4249,7 +4249,7 @@ impl VariantInfo {
42494249
return VariantInfo {
42504250
args: arg_tys,
42514251
arg_names: None,
4252-
ctor_ty: Some(ctor_ty),
4252+
ctor_ty: ctor_ty,
42534253
name: ast_variant.node.name.name,
42544254
id: ast_util::local_def(ast_variant.node.id),
42554255
disr_val: discriminant,
@@ -4262,8 +4262,7 @@ impl VariantInfo {
42624262

42634263
assert!(fields.len() > 0);
42644264

4265-
let arg_tys = struct_def.fields.iter()
4266-
.map(|field| node_id_to_type(cx, field.node.id)).collect();
4265+
let arg_tys = ty_fn_args(ctor_ty).iter().map(|a| *a).collect();
42674266
let arg_names = fields.iter().map(|field| {
42684267
match field.node.kind {
42694268
NamedField(ident, _) => ident,
@@ -4275,7 +4274,7 @@ impl VariantInfo {
42754274
return VariantInfo {
42764275
args: arg_tys,
42774276
arg_names: Some(arg_names),
4278-
ctor_ty: None,
4277+
ctor_ty: ctor_ty,
42794278
name: ast_variant.node.name.name,
42804279
id: ast_util::local_def(ast_variant.node.id),
42814280
disr_val: discriminant,

0 commit comments

Comments
 (0)