Skip to content

Commit 8004247

Browse files
author
Alfie John
committed
---
yaml --- r: 236565 b: refs/heads/tmp c: 29048c3 h: refs/heads/master i: 236563: ffc68e3 v: v3
1 parent 82ff6d5 commit 8004247

File tree

9 files changed

+39
-55
lines changed

9 files changed

+39
-55
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2626
refs/heads/beta: d2e13e822a73e0ea46ae9e21afdd3155fc997f6d
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
28-
refs/heads/tmp: 8b85b57ccb9a8bf837971d22dc268698f203356e
28+
refs/heads/tmp: 29048c3a803d085eb814c4410f9258dde81af59d
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: f859507de8c410b648d934d8f5ec1c52daac971d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828

branches/tmp/src/doc/trpl/closures.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,8 @@ fn factory() -> &(Fn(i32) -> i32) {
411411
```
412412

413413
Right. Because we have a reference, we need to give it a lifetime. But
414-
our `factory()` function takes no arguments, so
415-
[elision](lifetimes.html#lifetime-elision) doesn’t kick in here. Then what
416-
choices do we have? Try `'static`:
414+
our `factory()` function takes no arguments, so elision doesn’t kick in
415+
here. What lifetime can we choose? `'static`:
417416

418417
```rust,ignore
419418
fn factory() -> &'static (Fn(i32) -> i32) {
@@ -433,7 +432,7 @@ But we get another error:
433432
```text
434433
error: mismatched types:
435434
expected `&'static core::ops::Fn(i32) -> i32`,
436-
found `[closure@<anon>:7:9: 7:20]`
435+
found `[closure <anon>:7:9: 7:20]`
437436
(expected &-ptr,
438437
found closure) [E0308]
439438
|x| x + num
@@ -442,17 +441,21 @@ error: mismatched types:
442441
```
443442

444443
This error is letting us know that we don’t have a `&'static Fn(i32) -> i32`,
445-
we have a `[closure@<anon>:7:9: 7:20]`. Wait, what?
444+
we have a `[closure <anon>:7:9: 7:20]`. Wait, what?
446445

447446
Because each closure generates its own environment `struct` and implementation
448447
of `Fn` and friends, these types are anonymous. They exist just solely for
449-
this closure. So Rust shows them as `closure@<anon>`, rather than some
448+
this closure. So Rust shows them as `closure <anon>`, rather than some
450449
autogenerated name.
451450

452-
The error also points out that the return type is expected to be a reference,
453-
but what we are trying to return is not. Further, we cannot directly assign a
454-
`'static` lifetime to an object. So we'll take a different approach and return
455-
a "trait object" by `Box`ing up the `Fn`. This _almost_ works:
451+
But why doesn’t our closure implement `&'static Fn`? Well, as we discussed before,
452+
closures borrow their environment. And in this case, our environment is based
453+
on a stack-allocated `5`, the `num` variable binding. So the borrow has a lifetime
454+
of the stack frame. So if we returned this closure, the function call would be
455+
over, the stack frame would go away, and our closure is capturing an environment
456+
of garbage memory!
457+
458+
So what to do? This _almost_ works:
456459

457460
```rust,ignore
458461
fn factory() -> Box<Fn(i32) -> i32> {
@@ -468,7 +471,7 @@ assert_eq!(6, answer);
468471
# }
469472
```
470473

471-
There’s just one last problem:
474+
We use a trait object, by `Box`ing up the `Fn`. There’s just one last problem:
472475

473476
```text
474477
error: closure may outlive the current function, but it borrows `num`,
@@ -477,12 +480,8 @@ Box::new(|x| x + num)
477480
^~~~~~~~~~~
478481
```
479482

480-
Well, as we discussed before, closures borrow their environment. And in this
481-
case, our environment is based on a stack-allocated `5`, the `num` variable
482-
binding. So the borrow has a lifetime of the stack frame. So if we returned
483-
this closure, the function call would be over, the stack frame would go away,
484-
and our closure is capturing an environment of garbage memory! With one last
485-
fix, we can make this work:
483+
We still have a reference to the parent stack frame. With one last fix, we can
484+
make this work:
486485

487486
```rust
488487
fn factory() -> Box<Fn(i32) -> i32> {

branches/tmp/src/doc/trpl/lifetimes.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ fn frob<'a, 'b>(s: &'a str, t: &'b str) -> &str; // Expanded: Output lifetime is
349349
fn get_mut(&mut self) -> &mut T; // elided
350350
fn get_mut<'a>(&'a mut self) -> &'a mut T; // expanded
351351
352-
fn args<T:ToCStr>(&mut self, args: &[T]) -> &mut Command // elided
353-
fn args<'a, 'b, T:ToCStr>(&'a mut self, args: &'b [T]) -> &'a mut Command // expanded
352+
fn args<T:ToCStr>(&mut self, args: &[T]) -> &mut Command; // elided
353+
fn args<'a, 'b, T:ToCStr>(&'a mut self, args: &'b [T]) -> &'a mut Command; // expanded
354354
355355
fn new(buf: &mut [u8]) -> BufWriter; // elided
356-
fn new<'a>(buf: &'a mut [u8]) -> BufWriter<'a> // expanded
356+
fn new<'a>(buf: &'a mut [u8]) -> BufWriter<'a>; // expanded
357357
```

branches/tmp/src/libcore/mem.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -434,11 +434,6 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
434434
/// While this does call the argument's implementation of `Drop`, it will not
435435
/// release any borrows, as borrows are based on lexical scope.
436436
///
437-
/// This effectively does nothing for
438-
/// [types which implement `Copy`](../../book/ownership.html#copy-types),
439-
/// e.g. integers. Such values are copied and _then_ moved into the function,
440-
/// so the value persists after this function call.
441-
///
442437
/// # Examples
443438
///
444439
/// Basic usage:
@@ -491,21 +486,6 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
491486
/// let borrow = x.borrow();
492487
/// println!("{}", *borrow);
493488
/// ```
494-
///
495-
/// Integers and other types implementing `Copy` are unaffected by `drop()`
496-
///
497-
/// ```
498-
/// #[derive(Copy, Clone)]
499-
/// struct Foo(u8);
500-
///
501-
/// let x = 1;
502-
/// let y = Foo(2);
503-
/// drop(x); // a copy of `x` is moved and dropped
504-
/// drop(y); // a copy of `y` is moved and dropped
505-
///
506-
/// println!("x: {}, y: {}", x, y.0); // still available
507-
/// ```
508-
///
509489
#[inline]
510490
#[stable(feature = "rust1", since = "1.0.0")]
511491
pub fn drop<T>(_x: T) { }

branches/tmp/src/libcore/slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,15 +1410,15 @@ impl<'a, T> ExactSizeIterator for ChunksMut<'a, T> {}
14101410
// Free functions
14111411
//
14121412

1413-
/// Converts a reference to A into a slice of length 1 (without copying).
1413+
/// Converts a pointer to A into a slice of length 1 (without copying).
14141414
#[unstable(feature = "ref_slice", issue = "27774")]
14151415
pub fn ref_slice<A>(s: &A) -> &[A] {
14161416
unsafe {
14171417
from_raw_parts(s, 1)
14181418
}
14191419
}
14201420

1421-
/// Converts a reference to A into a slice of length 1 (without copying).
1421+
/// Converts a pointer to A into a slice of length 1 (without copying).
14221422
#[unstable(feature = "ref_slice", issue = "27774")]
14231423
pub fn mut_ref_slice<A>(s: &mut A) -> &mut [A] {
14241424
unsafe {

branches/tmp/src/libcore/str/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ impl Utf8Error {
115115
/// Returns the index in the given string up to which valid UTF-8 was
116116
/// verified.
117117
///
118-
/// It is the maximum index such that `from_utf8(input[..index])`
119-
/// would return `Some(_)`.
118+
/// Starting at the index provided, but not necessarily at it precisely, an
119+
/// invalid UTF-8 encoding sequence was found.
120120
#[unstable(feature = "utf8_error", reason = "method just added",
121121
issue = "27734")]
122122
pub fn valid_up_to(&self) -> usize { self.valid_up_to }

branches/tmp/src/librustc_trans/back/linker.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use back::archive;
1919
use metadata::csearch;
2020
use middle::dependency_format::Linkage;
2121
use session::Session;
22+
use session::config::DebugInfoLevel::{NoDebugInfo, LimitedDebugInfo, FullDebugInfo};
2223
use session::config::CrateTypeDylib;
2324
use session::config;
2425
use syntax::ast;
@@ -280,9 +281,17 @@ impl<'a> Linker for MsvcLinker<'a> {
280281
}
281282

282283
fn debuginfo(&mut self) {
283-
// This will cause the Microsoft linker to generate a PDB file
284-
// from the CodeView line tables in the object files.
285-
self.cmd.arg("/DEBUG");
284+
match self.sess.opts.debuginfo {
285+
NoDebugInfo => {
286+
// Do nothing if debuginfo is disabled
287+
},
288+
LimitedDebugInfo |
289+
FullDebugInfo => {
290+
// This will cause the Microsoft linker to generate a PDB file
291+
// from the CodeView line tables in the object files.
292+
self.cmd.arg("/DEBUG");
293+
}
294+
}
286295
}
287296

288297
fn whole_archives(&mut self) {

branches/tmp/src/libstd/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ macro_rules! print {
9898
($($arg:tt)*) => ($crate::io::_print(format_args!($($arg)*)));
9999
}
100100

101-
/// Macro for printing to the standard output, with a newline.
101+
/// Macro for printing to the standard output.
102102
///
103103
/// Use the `format!` syntax to write data to the standard output.
104104
/// See `std::fmt` for more information.

branches/tmp/src/test/run-make/output-type-permutations/Makefile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ all:
55
$(call REMOVE_RLIBS,bar)
66
$(call REMOVE_DYLIBS,bar)
77
rm $(TMPDIR)/libbar.a
8-
rm -f $(TMPDIR)/bar.{exp,lib,pdb}
8+
rm -f $(TMPDIR)/bar.{exp,lib}
99
# Check that $(TMPDIR) is empty.
1010
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
1111

1212
$(RUSTC) foo.rs --crate-type=bin
1313
rm $(TMPDIR)/$(call BIN,bar)
14-
rm -f $(TMPDIR)/bar.pdb
1514
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
1615

1716
$(RUSTC) foo.rs --emit=asm,llvm-ir,llvm-bc,obj,link
@@ -20,7 +19,6 @@ all:
2019
rm $(TMPDIR)/bar.s
2120
rm $(TMPDIR)/bar.o
2221
rm $(TMPDIR)/$(call BIN,bar)
23-
rm -f $(TMPDIR)/bar.pdb
2422
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
2523

2624
$(RUSTC) foo.rs --emit=asm -o $(TMPDIR)/foo
@@ -41,7 +39,6 @@ all:
4139

4240
$(RUSTC) foo.rs --emit=link -o $(TMPDIR)/$(call BIN,foo)
4341
rm $(TMPDIR)/$(call BIN,foo)
44-
rm -f $(TMPDIR)/foo.pdb
4542
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
4643

4744
$(RUSTC) foo.rs --crate-type=rlib -o $(TMPDIR)/foo
@@ -50,7 +47,7 @@ all:
5047

5148
$(RUSTC) foo.rs --crate-type=dylib -o $(TMPDIR)/$(call BIN,foo)
5249
rm $(TMPDIR)/$(call BIN,foo)
53-
rm -f $(TMPDIR)/foo.{exp,lib,pdb}
50+
rm -f $(TMPDIR)/foo.{exp,lib}
5451
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
5552

5653
$(RUSTC) foo.rs --crate-type=staticlib -o $(TMPDIR)/foo
@@ -59,7 +56,6 @@ all:
5956

6057
$(RUSTC) foo.rs --crate-type=bin -o $(TMPDIR)/$(call BIN,foo)
6158
rm $(TMPDIR)/$(call BIN,foo)
62-
rm -f $(TMPDIR)/foo.pdb
6359
[ "$$(ls -1 $(TMPDIR) | wc -l)" -eq "0" ]
6460

6561
$(RUSTC) foo.rs --emit=asm,llvm-ir,llvm-bc,obj,link --crate-type=staticlib

0 commit comments

Comments
 (0)