Skip to content

Commit 5d18e97

Browse files
committed
---
yaml --- r: 152840 b: refs/heads/try2 c: 7da94c1 h: refs/heads/master v: v3
1 parent 741a69a commit 5d18e97

File tree

27 files changed

+240
-245
lines changed

27 files changed

+240
-245
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: b53acd5356d93ad3109a4e5d4d0ce32880dbc0e1
8+
refs/heads/try2: 7da94c1a00104e25901b6b571bca1b03990d4467
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/doc/guide-unsafe.md

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33
# Introduction
44

55
Rust aims to provide safe abstractions over the low-level details of
6-
the CPU and operating system, but sometimes one is forced to drop down
7-
and write code at that level (those abstractions have to be created
8-
somehow). This guide aims to provide an overview of the dangers and
9-
power one gets with Rust's unsafe subset.
6+
the CPU and operating system, but sometimes one needs to drop down and
7+
write code at that level. This guide aims to provide an overview of
8+
the dangers and power one gets with Rust's unsafe subset.
109

1110
Rust provides an escape hatch in the form of the `unsafe { ... }`
12-
block which allows the programmer to dodge some of the compilers
11+
block which allows the programmer to dodge some of the compiler's
1312
checks and do a wide range of operations, such as:
1413

1514
- dereferencing [raw pointers](#raw-pointers)
@@ -18,13 +17,12 @@ checks and do a wide range of operations, such as:
1817
- [inline assembly](#inline-assembly)
1918

2019
Note that an `unsafe` block does not relax the rules about lifetimes
21-
of `&` and the freezing of borrowed data, it just allows the use of
22-
additional techniques for skirting the compiler's watchful eye. Any
23-
use of `unsafe` is the programmer saying "I know more than you" to the
24-
compiler, and, as such, the programmer should be very sure that they
25-
actually do know more about why that piece of code is valid.
20+
of `&` and the freezing of borrowed data.
2621

27-
In general, one should try to minimize the amount of unsafe code in a
22+
Any use of `unsafe` is the programmer saying "I know more than you" to
23+
the compiler, and, as such, the programmer should be very sure that
24+
they actually do know more about why that piece of code is valid. In
25+
general, one should try to minimize the amount of unsafe code in a
2826
code base; preferably by using the bare minimum `unsafe` blocks to
2927
build safe interfaces.
3028

@@ -38,25 +36,25 @@ build safe interfaces.
3836

3937
## References
4038

41-
One of Rust's biggest goals as a language is ensuring memory safety,
42-
achieved in part via [the lifetime system](guide-lifetimes.html) which
43-
every `&` references has associated with it. This system is how the
39+
One of Rust's biggest features is memory safety. This is achieved in
40+
part via [the lifetime system](guide-lifetimes.html), which is how the
4441
compiler can guarantee that every `&` reference is always valid, and,
4542
for example, never pointing to freed memory.
4643

47-
These restrictions on `&` have huge advantages. However, there's no
48-
free lunch club. For example, `&` isn't a valid replacement for C's
49-
pointers, and so cannot be used for FFI, in general. Additionally,
50-
both immutable (`&`) and mutable (`&mut`) references have some
51-
aliasing and freezing guarantees, required for memory safety.
44+
These restrictions on `&` have huge advantages. However, they also
45+
constrain how we can use them. For example, `&` doesn't behave
46+
identically to C's pointers, and so cannot be used for pointers in
47+
foreign function interfaces (FFI). Additionally, both immutable (`&`)
48+
and mutable (`&mut`) references have some aliasing and freezing
49+
guarantees, required for memory safety.
5250

5351
In particular, if you have an `&T` reference, then the `T` must not be
5452
modified through that reference or any other reference. There are some
5553
standard library types, e.g. `Cell` and `RefCell`, that provide inner
5654
mutability by replacing compile time guarantees with dynamic checks at
5755
runtime.
5856

59-
An `&mut` reference has a stronger requirement: when an object has an
57+
An `&mut` reference has a different constraint: when an object has an
6058
`&mut T` pointing into it, then that `&mut` reference must be the only
6159
such usable path to that object in the whole program. That is, an
6260
`&mut` cannot alias with any other references.
@@ -106,19 +104,19 @@ offered by the Rust language and libraries. For example, they
106104

107105
Fortunately, they come with a redeeming feature: the weaker guarantees
108106
mean weaker restrictions. The missing restrictions make raw pointers
109-
appropriate as a building block for (carefully!) implementing things
110-
like smart pointers and vectors inside libraries. For example, `*`
111-
pointers are allowed to alias, allowing them to be used to write
112-
shared-ownership types like reference counted and garbage collected
113-
pointers, and even thread-safe shared memory types (`Rc` and the `Arc`
114-
types are both implemented entirely in Rust).
107+
appropriate as a building block for implementing things like smart
108+
pointers and vectors inside libraries. For example, `*` pointers are
109+
allowed to alias, allowing them to be used to write shared-ownership
110+
types like reference counted and garbage collected pointers, and even
111+
thread-safe shared memory types (`Rc` and the `Arc` types are both
112+
implemented entirely in Rust).
115113

116114
There are two things that you are required to be careful about
117115
(i.e. require an `unsafe { ... }` block) with raw pointers:
118116

119117
- dereferencing: they can have any value: so possible results include
120118
a crash, a read of uninitialised memory, a use-after-free, or
121-
reading data as normal (and one hopes happens).
119+
reading data as normal.
122120
- pointer arithmetic via the `offset` [intrinsic](#intrinsics) (or
123121
`.offset` method): this intrinsic uses so-called "in-bounds"
124122
arithmetic, that is, it is only defined behaviour if the result is
@@ -177,9 +175,10 @@ code:
177175
- store pointers privately (i.e. not in public fields of public
178176
structs), so that you can see and control all reads and writes to
179177
the pointer in one place.
180-
- use `assert!()` a lot: once you've thrown away the protection of the
181-
compiler & type-system via `unsafe { ... }` you're left with just
182-
your wits and your `assert!()`s, any bug is potentially exploitable.
178+
- use `assert!()` a lot: since you can't rely on the protection of the
179+
compiler & type-system to ensure that your `unsafe` code is correct
180+
at compile-time, use `assert!()` to verify that it is doing the
181+
right thing at run-time.
183182
- implement the `Drop` for resource clean-up via a destructor, and use
184183
RAII (Resource Acquisition Is Initialization). This reduces the need
185184
for any manual memory management by users, and automatically ensures
@@ -305,8 +304,8 @@ asm!(assembly template
305304
Any use of `asm` is feature gated (requires `#![feature(asm)]` on the
306305
crate to allow) and of course requires an `unsafe` block.
307306

308-
> **Note**: the examples here are given in x86/x86-64 assembly, but all
309-
> platforms are supported.
307+
> **Note**: the examples here are given in x86/x86-64 assembly, but
308+
> all platforms are supported.
310309
311310
## Assembly template
312311

@@ -596,7 +595,7 @@ standard library itself.
596595
> parts of the language may never be full specified and so details may
597596
> differ wildly between implementations (and even versions of `rustc`
598597
> itself).
599-
>
598+
>
600599
> Furthermore, this is just an overview; the best form of
601600
> documentation for specific instances of these features are their
602601
> definitions and uses in `std`.
@@ -689,8 +688,7 @@ fn main(argc: int, argv: **u8) -> int {
689688
```
690689

691690
Note the use of `abort`: the `exchange_malloc` lang item is assumed to
692-
return a valid pointer, and so needs to do the check
693-
internally.
691+
return a valid pointer, and so needs to do the check internally.
694692

695693
Other features provided by lang items include:
696694

branches/try2/src/doc/tutorial.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,9 +566,14 @@ tuple, introducing two variables at once: `a` and `b`.
566566
let (a, b) = get_tuple_of_two_ints();
567567
~~~~
568568

569-
Let bindings only work with _irrefutable_ patterns: that is, patterns
570-
that can never fail to match. This excludes `let` from matching
571-
literals and most `enum` variants.
569+
Let bindings only work with _irrefutable_ patterns: that is, patterns that can
570+
never fail to match. This excludes `let` from matching literals and most `enum`
571+
variants as binding patterns, since most such patterns are not irrefutable. For
572+
example, this will not compile:
573+
574+
~~~~{ignore}
575+
let (a, 2) = (1, 2);
576+
~~~~
572577

573578
## Loops
574579

branches/try2/src/libcore/intrinsics.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ pub trait TyVisitor {
9696

9797
fn visit_f32(&mut self) -> bool;
9898
fn visit_f64(&mut self) -> bool;
99-
fn visit_f128(&mut self) -> bool;
10099

101100
fn visit_char(&mut self) -> bool;
102101

branches/try2/src/libdebug/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2626
html_root_url = "http://doc.rust-lang.org/")]
2727
#![experimental]
28-
#![feature(managed_boxes, macro_rules, quad_precision_float)]
28+
#![feature(managed_boxes, macro_rules)]
2929
#![allow(experimental)]
3030

3131
pub mod fmt;

branches/try2/src/libdebug/reflect.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,6 @@ impl<V:TyVisitor + MovePtr> TyVisitor for MovePtrAdaptor<V> {
179179
true
180180
}
181181

182-
fn visit_f128(&mut self) -> bool {
183-
self.align_to::<f128>();
184-
if ! self.inner.visit_f128() { return false; }
185-
self.bump_past::<f128>();
186-
true
187-
}
188-
189182
fn visit_char(&mut self) -> bool {
190183
self.align_to::<char>();
191184
if ! self.inner.visit_char() { return false; }

branches/try2/src/libdebug/repr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ impl<'a> TyVisitor for ReprVisitor<'a> {
258258

259259
fn visit_f32(&mut self) -> bool { self.write::<f32>() }
260260
fn visit_f64(&mut self) -> bool { self.write::<f64>() }
261-
fn visit_f128(&mut self) -> bool { fail!("not implemented") }
262261

263262
fn visit_char(&mut self) -> bool {
264263
self.get::<char>(|this, &ch| {

branches/try2/src/libhexfloat/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ pub fn expand_syntax_ext(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
112112
Some(Ident{ident, span}) => match token::get_ident(ident).get() {
113113
"f32" => Some(ast::TyF32),
114114
"f64" => Some(ast::TyF64),
115-
"f128" => Some(ast::TyF128),
116115
_ => {
117116
cx.span_err(span, "invalid floating point type in hexfloat!");
118117
None

branches/try2/src/librustc/front/feature_gate.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
6464
("overloaded_calls", Active),
6565
("unboxed_closure_sugar", Active),
6666

67-
("quad_precision_float", Active),
67+
("quad_precision_float", Removed),
6868

6969
// A temporary feature gate used to enable parser extensions needed
7070
// to bootstrap fix for #5723.
@@ -91,7 +91,6 @@ enum Status {
9191
/// A set of features to be used by later passes.
9292
pub struct Features {
9393
pub default_type_params: Cell<bool>,
94-
pub quad_precision_float: Cell<bool>,
9594
pub issue_5723_bootstrap: Cell<bool>,
9695
pub overloaded_calls: Cell<bool>,
9796
}
@@ -100,7 +99,6 @@ impl Features {
10099
pub fn new() -> Features {
101100
Features {
102101
default_type_params: Cell::new(false),
103-
quad_precision_float: Cell::new(false),
104102
issue_5723_bootstrap: Cell::new(false),
105103
overloaded_calls: Cell::new(false),
106104
}
@@ -425,7 +423,6 @@ pub fn check_crate(sess: &Session, krate: &ast::Crate) {
425423
sess.abort_if_errors();
426424

427425
sess.features.default_type_params.set(cx.has_feature("default_type_params"));
428-
sess.features.quad_precision_float.set(cx.has_feature("quad_precision_float"));
429426
sess.features.issue_5723_bootstrap.set(cx.has_feature("issue_5723_bootstrap"));
430427
sess.features.overloaded_calls.set(cx.has_feature("overloaded_calls"));
431428
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,6 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
330330
'D' => return ty::mk_mach_int(ast::TyI64),
331331
'f' => return ty::mk_mach_float(ast::TyF32),
332332
'F' => return ty::mk_mach_float(ast::TyF64),
333-
'Q' => return ty::mk_mach_float(ast::TyF128),
334333
_ => fail!("parse_ty: bad numeric type")
335334
}
336335
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
221221
match t {
222222
TyF32 => mywrite!(w, "Mf"),
223223
TyF64 => mywrite!(w, "MF"),
224-
TyF128 => mywrite!(w, "MQ")
225224
}
226225
}
227226
ty::ty_enum(def, ref substs) => {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,6 @@ impl PrimitiveTypeTable {
770770
table.intern("char", TyChar);
771771
table.intern("f32", TyFloat(TyF32));
772772
table.intern("f64", TyFloat(TyF64));
773-
table.intern("f128", TyFloat(TyF128));
774773
table.intern("int", TyInt(TyI));
775774
table.intern("i8", TyInt(TyI8));
776775
table.intern("i16", TyInt(TyI16));

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,6 @@ fn basic_type_metadata(cx: &CrateContext, t: ty::t) -> DIType {
16211621
ty::ty_float(float_ty) => match float_ty {
16221622
ast::TyF32 => ("f32".to_string(), DW_ATE_float),
16231623
ast::TyF64 => ("f64".to_string(), DW_ATE_float),
1624-
ast::TyF128 => ("f128".to_string(), DW_ATE_float)
16251624
},
16261625
_ => cx.sess().bug("debuginfo::basic_type_metadata - t is invalid type")
16271626
};

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ impl<'a, 'b> Reflector<'a, 'b> {
148148
ty::ty_uint(ast::TyU64) => self.leaf("u64"),
149149
ty::ty_float(ast::TyF32) => self.leaf("f32"),
150150
ty::ty_float(ast::TyF64) => self.leaf("f64"),
151-
ty::ty_float(ast::TyF128) => self.leaf("f128"),
152151

153152
// Should rename to vec_*.
154153
ty::ty_vec(ref mt, Some(sz)) => {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ impl Type {
8888
ty!(llvm::LLVMDoubleTypeInContext(ccx.llcx))
8989
}
9090

91-
pub fn f128(ccx: &CrateContext) -> Type {
92-
ty!(llvm::LLVMFP128TypeInContext(ccx.llcx))
93-
}
94-
9591
pub fn bool(ccx: &CrateContext) -> Type {
9692
Type::i1(ccx)
9793
}
@@ -135,7 +131,6 @@ impl Type {
135131
match t {
136132
ast::TyF32 => Type::f32(ccx),
137133
ast::TyF64 => Type::f64(ccx),
138-
ast::TyF128 => Type::f128(ccx)
139134
}
140135
}
141136

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,6 @@ mod primitives {
694694
def_prim_ty!(TY_U64, super::ty_uint(ast::TyU64), 12)
695695
def_prim_ty!(TY_F32, super::ty_float(ast::TyF32), 14)
696696
def_prim_ty!(TY_F64, super::ty_float(ast::TyF64), 15)
697-
def_prim_ty!(TY_F128, super::ty_float(ast::TyF128), 16)
698697

699698
pub static TY_BOT: t_box_ = t_box_ {
700699
sty: super::ty_bot,
@@ -1272,9 +1271,6 @@ pub fn mk_f32() -> t { mk_prim_t(&primitives::TY_F32) }
12721271
#[inline]
12731272
pub fn mk_f64() -> t { mk_prim_t(&primitives::TY_F64) }
12741273

1275-
#[inline]
1276-
pub fn mk_f128() -> t { mk_prim_t(&primitives::TY_F128) }
1277-
12781274
#[inline]
12791275
pub fn mk_uint() -> t { mk_prim_t(&primitives::TY_UINT) }
12801276

@@ -1314,7 +1310,6 @@ pub fn mk_mach_float(tm: ast::FloatTy) -> t {
13141310
match tm {
13151311
ast::TyF32 => mk_f32(),
13161312
ast::TyF64 => mk_f64(),
1317-
ast::TyF128 => mk_f128()
13181313
}
13191314
}
13201315

branches/try2/src/librustc/middle/typeck/astconv.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,6 @@ pub fn ast_ty_to_prim_ty(tcx: &ty::ctxt, ast_ty: &ast::Ty) -> Option<ty::t> {
355355
Some(ty::mk_mach_uint(uit))
356356
}
357357
ast::TyFloat(ft) => {
358-
if ft == ast::TyF128 && !tcx.sess.features.quad_precision_float.get() {
359-
tcx.sess.span_err(path.span, "quadruple precision floats are \
360-
missing complete runtime support");
361-
tcx.sess.span_note(path.span, "add \
362-
#[feature(quad_precision_float)] \
363-
to the crate attributes to enable");
364-
}
365358
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
366359
Some(ty::mk_mach_float(ft))
367360
}

0 commit comments

Comments
 (0)