Skip to content

Commit

Permalink
Rollup merge of #34547 - sanxiyn:pretty-lifetime, r=pnkfelix
Browse files Browse the repository at this point in the history
Fix pretty-printing of lifetime bound

Fix #34527.
  • Loading branch information
jseyfried committed Jun 30, 2016
2 parents bd7a363 + 3c29fc5 commit a8751e0
Show file tree
Hide file tree
Showing 20 changed files with 233 additions and 122 deletions.
14 changes: 13 additions & 1 deletion mk/llvm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@ endif

define DEF_LLVM_RULES

ifeq ($(1),$$(CFG_BUILD))
LLVM_DEPS_TARGET_$(1) := $$(LLVM_DEPS)
else
LLVM_DEPS_TARGET_$(1) := $$(LLVM_DEPS) $$(LLVM_CONFIG_$$(CFG_BUILD))
endif

# If CFG_LLVM_ROOT is defined then we don't build LLVM ourselves
ifeq ($(CFG_LLVM_ROOT),)

LLVM_STAMP_$(1) = $$(CFG_LLVM_BUILD_DIR_$(1))/llvm-auto-clean-stamp

$$(LLVM_CONFIG_$(1)): $$(LLVM_DEPS) $$(LLVM_STAMP_$(1))
$$(LLVM_CONFIG_$(1)): $$(LLVM_DEPS_TARGET_$(1)) $$(LLVM_STAMP_$(1))
@$$(call E, cmake: llvm)
ifeq ($$(findstring msvc,$(1)),msvc)
$$(Q)$$(CFG_CMAKE) --build $$(CFG_LLVM_BUILD_DIR_$(1)) \
Expand All @@ -42,7 +48,13 @@ else
endif
$$(Q)touch $$(LLVM_CONFIG_$(1))

ifeq ($$(findstring msvc,$(1)),msvc)
clean-llvm$(1):
else
clean-llvm$(1):
@$$(call E, clean: llvm)
$$(Q)$$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1)) clean
endif

else
clean-llvm$(1):
Expand Down
69 changes: 46 additions & 23 deletions src/bootstrap/build/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,27 +135,64 @@ pub fn compiler_rt(build: &Build, target: &str) {
let dst = build.compiler_rt_out(target);
let arch = target.split('-').next().unwrap();
let mode = if build.config.rust_optimize {"Release"} else {"Debug"};

let build_llvm_config = build.llvm_config(&build.config.build);
let mut cfg = cmake::Config::new(build.src.join("src/compiler-rt"));
cfg.target(target)
.host(&build.config.build)
.out_dir(&dst)
.profile(mode)
.define("LLVM_CONFIG_PATH", build_llvm_config)
.define("COMPILER_RT_DEFAULT_TARGET_TRIPLE", target)
.define("COMPILER_RT_BUILD_SANITIZERS", "OFF")
.define("COMPILER_RT_BUILD_EMUTLS", "OFF")
// inform about c/c++ compilers, the c++ compiler isn't actually used but
// it's needed to get the initial configure to work on all platforms.
.define("CMAKE_C_COMPILER", build.cc(target))
.define("CMAKE_CXX_COMPILER", build.cc(target));

let (dir, build_target, libname) = if target.contains("linux") ||
target.contains("freebsd") ||
target.contains("netbsd") {
let os = if target.contains("android") {"-android"} else {""};
let arch = if arch.starts_with("arm") && target.contains("eabihf") {
"armhf"
let os_extra = if target.contains("android") && target.contains("arm") {
"-android"
} else {
arch
""
};
let target = format!("clang_rt.builtins-{}{}", arch, os);
let builtins_arch = match arch {
"i586" => "i386",
"arm" | "armv7" if target.contains("android") => "armhf",
"arm" if target.contains("eabihf") => "armhf",
_ => arch,
};
let target = format!("clang_rt.builtins-{}{}", builtins_arch, os_extra);
("linux".to_string(), target.clone(), target)
} else if target.contains("darwin") {
let target = format!("clang_rt.builtins_{}_osx", arch);
} else if target.contains("apple-darwin") {
let builtins_arch = match arch {
"i686" => "i386",
_ => arch,
};
let target = format!("clang_rt.builtins_{}_osx", builtins_arch);
("builtins".to_string(), target.clone(), target)
} else if target.contains("apple-ios") {
cfg.define("COMPILER_RT_ENABLE_IOS", "ON");
let target = match arch {
"armv7s" => "hard_pic_armv7em_macho_embedded".to_string(),
"aarch64" => "builtins_arm64_ios".to_string(),
_ => format!("hard_pic_{}_macho_embedded", arch),
};
("builtins".to_string(), target.clone(), target)
} else if target.contains("windows-gnu") {
let target = format!("clang_rt.builtins-{}", arch);
("windows".to_string(), target.clone(), target)
} else if target.contains("windows-msvc") {
let builtins_arch = match arch {
"i586" | "i686" => "i386",
_ => arch,
};
(format!("windows/{}", mode),
"lib/builtins/builtins".to_string(),
format!("clang_rt.builtins-{}", arch.replace("i686", "i386")))
format!("clang_rt.builtins-{}", builtins_arch))
} else {
panic!("can't get os from target: {}", target)
};
Expand All @@ -168,21 +205,7 @@ pub fn compiler_rt(build: &Build, target: &str) {
}
let _ = fs::remove_dir_all(&dst);
t!(fs::create_dir_all(&dst));
let build_llvm_config = build.llvm_config(&build.config.build);
let mut cfg = cmake::Config::new(build.src.join("src/compiler-rt"));
cfg.target(target)
.host(&build.config.build)
.out_dir(&dst)
.profile(mode)
.define("LLVM_CONFIG_PATH", build_llvm_config)
.define("COMPILER_RT_DEFAULT_TARGET_TRIPLE", target)
.define("COMPILER_RT_BUILD_SANITIZERS", "OFF")
.define("COMPILER_RT_BUILD_EMUTLS", "OFF")
// inform about c/c++ compilers, the c++ compiler isn't actually used but
// it's needed to get the initial configure to work on all platforms.
.define("CMAKE_C_COMPILER", build.cc(target))
.define("CMAKE_CXX_COMPILER", build.cc(target))
.build_target(&build_target);
cfg.build_target(&build_target);
cfg.build();
}

Expand Down
10 changes: 5 additions & 5 deletions src/doc/book/closures.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ to our closure when we pass it to `call_with_one`, so we use `&||`.
A quick note about closures that use explicit lifetimes. Sometimes you might have a closure
that takes a reference like so:

```
```rust
fn call_with_ref<F>(some_closure:F) -> i32
where F: Fn(&i32) -> i32 {

Expand All @@ -334,8 +334,8 @@ fn call_with_ref<F>(some_closure:F) -> i32
Normally you can specify the lifetime of the parameter to our closure. We
could annotate it on the function declaration:

```ignore
fn call_with_ref<'a, F>(some_closure:F) -> i32
```rust,ignore
fn call_with_ref<'a, F>(some_closure:F) -> i32
where F: Fn(&'a 32) -> i32 {
```

Expand All @@ -353,11 +353,11 @@ fn call_with_ref<F>(some_closure:F) -> i32
where F: for<'a> Fn(&'a 32) -> i32 {
```

This lets the Rust compiler find the minimum lifetime to invoke our closure and
This lets the Rust compiler find the minimum lifetime to invoke our closure and
satisfy the borrow checker's rules. Our function then compiles and excutes as we
expect.

```
```rust
fn call_with_ref<F>(some_closure:F) -> i32
where F: for<'a> Fn(&'a i32) -> i32 {

Expand Down
7 changes: 2 additions & 5 deletions src/doc/book/crates-and-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ As an example, let’s make a *phrases* crate, which will give us various phrase
in different languages. To keep things simple, we’ll stick to ‘greetings’ and
‘farewells’ as two kinds of phrases, and use English and Japanese (日本語) as
two languages for those phrases to be in. We’ll use this module layout:

```text
+-----------+
+---| greetings |
| +-----------+
+---------+ |
+---------+ | +-----------+
+---| english |---+
| +---------+ | +-----------+
| +---| farewells |
Expand All @@ -37,8 +35,7 @@ two languages for those phrases to be in. We’ll use this module layout:
| +---| greetings |
| +----------+ | +-----------+
+---| japanese |--+
+----------+ |
| +-----------+
+----------+ | +-----------+
+---| farewells |
+-----------+
```
Expand Down
4 changes: 3 additions & 1 deletion src/doc/book/ownership.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Vectors have a [generic type][generics] `Vec<T>`, so in this example `v` will ha

[arrays]: primitive-types.html#arrays
[vectors]: vectors.html
[heap]: the-stack-and-the-heap.html
[heap]: the-stack-and-the-heap.html#the-heap
[stack]: the-stack-and-the-heap.html#the-stack
[bindings]: variable-bindings.html
[generics]: generics.html
Expand Down Expand Up @@ -136,6 +136,8 @@ Rust allocates memory for an integer [i32] on the [stack][sh], copies the bit
pattern representing the value of 10 to the allocated memory and binds the
variable name x to this memory region for future reference.

[i32]: primitive-types.html#numeric-types

Now consider the following code fragment:

```rust
Expand Down
4 changes: 2 additions & 2 deletions src/doc/book/traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,10 @@ fn normal<T: ConvertTo<i64>>(x: &T) -> i64 {
}

// can be called with T == i64
fn inverse<T>() -> T
fn inverse<T>(x: i32) -> T
// this is using ConvertTo as if it were "ConvertTo<i64>"
where i32: ConvertTo<T> {
42.convert()
x.convert()
}
```

Expand Down
18 changes: 13 additions & 5 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,20 @@ Non-doc comments are interpreted as a form of whitespace.

## Whitespace

Whitespace is any non-empty string containing only the following characters:

Whitespace is any non-empty string containing only characters that have the
`Pattern_White_Space` Unicode property, namely:

- `U+0009` (horizontal tab, `'\t'`)
- `U+000A` (line feed, `'\n'`)
- `U+000B` (vertical tab)
- `U+000C` (form feed)
- `U+000D` (carriage return, `'\r'`)
- `U+0020` (space, `' '`)
- `U+0009` (tab, `'\t'`)
- `U+000A` (LF, `'\n'`)
- `U+000D` (CR, `'\r'`)
- `U+0085` (next line)
- `U+200E` (left-to-right mark)
- `U+200F` (right-to-left mark)
- `U+2028` (line separator)
- `U+2029` (paragraph separator)

Rust is a "free-form" language, meaning that all forms of whitespace serve only
to separate _tokens_ in the grammar, and have no semantic significance.
Expand Down
1 change: 1 addition & 0 deletions src/libcollections/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
//! format!("{:?}", (3, 4)); // => "(3, 4)"
//! format!("{value}", value=4); // => "4"
//! format!("{} {}", 1, 2); // => "1 2"
//! format!("{:04}", 42); // => "0042" with leading zeros
//! ```
//!
//! From these, you can see that the first argument is a format string. It is
Expand Down
40 changes: 15 additions & 25 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,45 +673,35 @@ extern "C" {
"##,

E0269: r##"
Functions must eventually return a value of their return type. For example, in
the following function:
A returned value was expected but not all control paths return one.
Erroneous code example:
```compile_fail,E0269
fn abracada_FAIL() -> String {
"this won't work".to_string();
// error: not all control paths return a value
}
```
If the condition is true, the value `x` is returned, but if the condition is
false, control exits the `if` block and reaches a place where nothing is being
returned. All possible control paths must eventually return a `u8`, which is not
happening here.
An easy fix for this in a complicated function is to specify a default return
value, if possible:
In the previous code, the function is supposed to return a `String`, however,
the code returns nothing (because of the ';'). Another erroneous code would be:
```ignore
fn foo(x: u8) -> u8 {
if x > 0 {
x // alternatively, `return x`
```compile_fail
fn abracada_FAIL(b: bool) -> u32 {
if b {
0
} else {
"a" // It fails because an `u32` was expected and something else is
// returned.
}
// lots of other if branches
0 // return 0 if all else fails
}
```
It is advisable to find out what the unhandled cases are and check for them,
returning an appropriate value or panicking if necessary. Check if you need
to remove a semicolon from the last expression, like in this case:
```ignore
fn foo(x: u8) -> u8 {
inner(2*x + 1);
}
```
The semicolon discards the return value of `inner`, instead of returning
it from `foo`.
to remove a semicolon from the last expression, like in the first erroneous
code example.
"##,

E0270: r##"
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
}
hir::ViewPathList(p, paths) => {
let mine = paths.into_iter().filter(|path| {
!self.maybe_inline_local(path.node.id(), None, false, om,
please_inline)
!self.maybe_inline_local(path.node.id(), path.node.rename(),
false, om, please_inline)
}).collect::<hir::HirVec<hir::PathListItem>>();

if mine.is_empty() {
Expand Down
29 changes: 23 additions & 6 deletions src/libstd/io/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,11 @@ pub struct Empty { _priv: () }
/// A slightly sad example of not reading anything into a buffer:
///
/// ```
/// use std::io;
/// use std::io::Read;
/// use std::io::{self, Read};
///
/// # fn foo() -> io::Result<String> {
/// let mut buffer = String::new();
/// try!(io::empty().read_to_string(&mut buffer));
/// # Ok(buffer)
/// # }
/// io::empty().read_to_string(&mut buffer).unwrap();
/// assert!(buffer.is_empty());
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn empty() -> Empty { Empty { _priv: () } }
Expand Down Expand Up @@ -113,6 +110,16 @@ pub struct Repeat { byte: u8 }
///
/// All reads from this reader will succeed by filling the specified buffer with
/// the given byte.
///
/// # Examples
///
/// ```
/// use std::io::{self, Read};
///
/// let mut buffer = [0; 3];
/// io::repeat(0b101).read_exact(&mut buffer).unwrap();
/// assert_eq!(buffer, [0b101, 0b101, 0b101]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } }

Expand All @@ -139,6 +146,16 @@ pub struct Sink { _priv: () }
///
/// All calls to `write` on the returned instance will return `Ok(buf.len())`
/// and the contents of the buffer will not be inspected.
///
/// # Examples
///
/// ```rust
/// use std::io::{self, Write};
///
/// let mut buffer = vec![1, 2, 3, 5, 8];
/// let num_bytes = io::sink().write(&mut buffer).unwrap();
/// assert_eq!(num_bytes, 5);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn sink() -> Sink { Sink { _priv: () } }

Expand Down
Loading

0 comments on commit a8751e0

Please sign in to comment.