Skip to content

Commit a8751e0

Browse files
committed
Rollup merge of #34547 - sanxiyn:pretty-lifetime, r=pnkfelix
Fix pretty-printing of lifetime bound Fix #34527.
2 parents bd7a363 + 3c29fc5 commit a8751e0

File tree

20 files changed

+233
-122
lines changed

20 files changed

+233
-122
lines changed

mk/llvm.mk

+13-1
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,18 @@ endif
2727

2828
define DEF_LLVM_RULES
2929

30+
ifeq ($(1),$$(CFG_BUILD))
31+
LLVM_DEPS_TARGET_$(1) := $$(LLVM_DEPS)
32+
else
33+
LLVM_DEPS_TARGET_$(1) := $$(LLVM_DEPS) $$(LLVM_CONFIG_$$(CFG_BUILD))
34+
endif
35+
3036
# If CFG_LLVM_ROOT is defined then we don't build LLVM ourselves
3137
ifeq ($(CFG_LLVM_ROOT),)
3238

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

35-
$$(LLVM_CONFIG_$(1)): $$(LLVM_DEPS) $$(LLVM_STAMP_$(1))
41+
$$(LLVM_CONFIG_$(1)): $$(LLVM_DEPS_TARGET_$(1)) $$(LLVM_STAMP_$(1))
3642
@$$(call E, cmake: llvm)
3743
ifeq ($$(findstring msvc,$(1)),msvc)
3844
$$(Q)$$(CFG_CMAKE) --build $$(CFG_LLVM_BUILD_DIR_$(1)) \
@@ -42,7 +48,13 @@ else
4248
endif
4349
$$(Q)touch $$(LLVM_CONFIG_$(1))
4450

51+
ifeq ($$(findstring msvc,$(1)),msvc)
4552
clean-llvm$(1):
53+
else
54+
clean-llvm$(1):
55+
@$$(call E, clean: llvm)
56+
$$(Q)$$(MAKE) -C $$(CFG_LLVM_BUILD_DIR_$(1)) clean
57+
endif
4658

4759
else
4860
clean-llvm$(1):

src/bootstrap/build/native.rs

+46-23
Original file line numberDiff line numberDiff line change
@@ -135,27 +135,64 @@ pub fn compiler_rt(build: &Build, target: &str) {
135135
let dst = build.compiler_rt_out(target);
136136
let arch = target.split('-').next().unwrap();
137137
let mode = if build.config.rust_optimize {"Release"} else {"Debug"};
138+
139+
let build_llvm_config = build.llvm_config(&build.config.build);
140+
let mut cfg = cmake::Config::new(build.src.join("src/compiler-rt"));
141+
cfg.target(target)
142+
.host(&build.config.build)
143+
.out_dir(&dst)
144+
.profile(mode)
145+
.define("LLVM_CONFIG_PATH", build_llvm_config)
146+
.define("COMPILER_RT_DEFAULT_TARGET_TRIPLE", target)
147+
.define("COMPILER_RT_BUILD_SANITIZERS", "OFF")
148+
.define("COMPILER_RT_BUILD_EMUTLS", "OFF")
149+
// inform about c/c++ compilers, the c++ compiler isn't actually used but
150+
// it's needed to get the initial configure to work on all platforms.
151+
.define("CMAKE_C_COMPILER", build.cc(target))
152+
.define("CMAKE_CXX_COMPILER", build.cc(target));
153+
138154
let (dir, build_target, libname) = if target.contains("linux") ||
139155
target.contains("freebsd") ||
140156
target.contains("netbsd") {
141-
let os = if target.contains("android") {"-android"} else {""};
142-
let arch = if arch.starts_with("arm") && target.contains("eabihf") {
143-
"armhf"
157+
let os_extra = if target.contains("android") && target.contains("arm") {
158+
"-android"
144159
} else {
145-
arch
160+
""
146161
};
147-
let target = format!("clang_rt.builtins-{}{}", arch, os);
162+
let builtins_arch = match arch {
163+
"i586" => "i386",
164+
"arm" | "armv7" if target.contains("android") => "armhf",
165+
"arm" if target.contains("eabihf") => "armhf",
166+
_ => arch,
167+
};
168+
let target = format!("clang_rt.builtins-{}{}", builtins_arch, os_extra);
148169
("linux".to_string(), target.clone(), target)
149-
} else if target.contains("darwin") {
150-
let target = format!("clang_rt.builtins_{}_osx", arch);
170+
} else if target.contains("apple-darwin") {
171+
let builtins_arch = match arch {
172+
"i686" => "i386",
173+
_ => arch,
174+
};
175+
let target = format!("clang_rt.builtins_{}_osx", builtins_arch);
176+
("builtins".to_string(), target.clone(), target)
177+
} else if target.contains("apple-ios") {
178+
cfg.define("COMPILER_RT_ENABLE_IOS", "ON");
179+
let target = match arch {
180+
"armv7s" => "hard_pic_armv7em_macho_embedded".to_string(),
181+
"aarch64" => "builtins_arm64_ios".to_string(),
182+
_ => format!("hard_pic_{}_macho_embedded", arch),
183+
};
151184
("builtins".to_string(), target.clone(), target)
152185
} else if target.contains("windows-gnu") {
153186
let target = format!("clang_rt.builtins-{}", arch);
154187
("windows".to_string(), target.clone(), target)
155188
} else if target.contains("windows-msvc") {
189+
let builtins_arch = match arch {
190+
"i586" | "i686" => "i386",
191+
_ => arch,
192+
};
156193
(format!("windows/{}", mode),
157194
"lib/builtins/builtins".to_string(),
158-
format!("clang_rt.builtins-{}", arch.replace("i686", "i386")))
195+
format!("clang_rt.builtins-{}", builtins_arch))
159196
} else {
160197
panic!("can't get os from target: {}", target)
161198
};
@@ -168,21 +205,7 @@ pub fn compiler_rt(build: &Build, target: &str) {
168205
}
169206
let _ = fs::remove_dir_all(&dst);
170207
t!(fs::create_dir_all(&dst));
171-
let build_llvm_config = build.llvm_config(&build.config.build);
172-
let mut cfg = cmake::Config::new(build.src.join("src/compiler-rt"));
173-
cfg.target(target)
174-
.host(&build.config.build)
175-
.out_dir(&dst)
176-
.profile(mode)
177-
.define("LLVM_CONFIG_PATH", build_llvm_config)
178-
.define("COMPILER_RT_DEFAULT_TARGET_TRIPLE", target)
179-
.define("COMPILER_RT_BUILD_SANITIZERS", "OFF")
180-
.define("COMPILER_RT_BUILD_EMUTLS", "OFF")
181-
// inform about c/c++ compilers, the c++ compiler isn't actually used but
182-
// it's needed to get the initial configure to work on all platforms.
183-
.define("CMAKE_C_COMPILER", build.cc(target))
184-
.define("CMAKE_CXX_COMPILER", build.cc(target))
185-
.build_target(&build_target);
208+
cfg.build_target(&build_target);
186209
cfg.build();
187210
}
188211

src/doc/book/closures.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ to our closure when we pass it to `call_with_one`, so we use `&||`.
322322
A quick note about closures that use explicit lifetimes. Sometimes you might have a closure
323323
that takes a reference like so:
324324

325-
```
325+
```rust
326326
fn call_with_ref<F>(some_closure:F) -> i32
327327
where F: Fn(&i32) -> i32 {
328328

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

337-
```ignore
338-
fn call_with_ref<'a, F>(some_closure:F) -> i32
337+
```rust,ignore
338+
fn call_with_ref<'a, F>(some_closure:F) -> i32
339339
where F: Fn(&'a 32) -> i32 {
340340
```
341341

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

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

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

src/doc/book/crates-and-modules.md

+2-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ As an example, let’s make a *phrases* crate, which will give us various phrase
2222
in different languages. To keep things simple, we’ll stick to ‘greetings’ and
2323
‘farewells’ as two kinds of phrases, and use English and Japanese (日本語) as
2424
two languages for those phrases to be in. We’ll use this module layout:
25-
2625
```text
2726
+-----------+
2827
+---| greetings |
29-
| +-----------+
30-
+---------+ |
28+
+---------+ | +-----------+
3129
+---| english |---+
3230
| +---------+ | +-----------+
3331
| +---| farewells |
@@ -37,8 +35,7 @@ two languages for those phrases to be in. We’ll use this module layout:
3735
| +---| greetings |
3836
| +----------+ | +-----------+
3937
+---| japanese |--+
40-
+----------+ |
41-
| +-----------+
38+
+----------+ | +-----------+
4239
+---| farewells |
4340
+-----------+
4441
```

src/doc/book/ownership.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Vectors have a [generic type][generics] `Vec<T>`, so in this example `v` will ha
6767

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

139+
[i32]: primitive-types.html#numeric-types
140+
139141
Now consider the following code fragment:
140142

141143
```rust

src/doc/book/traits.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,10 @@ fn normal<T: ConvertTo<i64>>(x: &T) -> i64 {
397397
}
398398

399399
// can be called with T == i64
400-
fn inverse<T>() -> T
400+
fn inverse<T>(x: i32) -> T
401401
// this is using ConvertTo as if it were "ConvertTo<i64>"
402402
where i32: ConvertTo<T> {
403-
42.convert()
403+
x.convert()
404404
}
405405
```
406406

src/doc/reference.md

+13-5
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,20 @@ Non-doc comments are interpreted as a form of whitespace.
114114

115115
## Whitespace
116116

117-
Whitespace is any non-empty string containing only the following characters:
118-
117+
Whitespace is any non-empty string containing only characters that have the
118+
`Pattern_White_Space` Unicode property, namely:
119+
120+
- `U+0009` (horizontal tab, `'\t'`)
121+
- `U+000A` (line feed, `'\n'`)
122+
- `U+000B` (vertical tab)
123+
- `U+000C` (form feed)
124+
- `U+000D` (carriage return, `'\r'`)
119125
- `U+0020` (space, `' '`)
120-
- `U+0009` (tab, `'\t'`)
121-
- `U+000A` (LF, `'\n'`)
122-
- `U+000D` (CR, `'\r'`)
126+
- `U+0085` (next line)
127+
- `U+200E` (left-to-right mark)
128+
- `U+200F` (right-to-left mark)
129+
- `U+2028` (line separator)
130+
- `U+2029` (paragraph separator)
123131

124132
Rust is a "free-form" language, meaning that all forms of whitespace serve only
125133
to separate _tokens_ in the grammar, and have no semantic significance.

src/libcollections/fmt.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
//! format!("{:?}", (3, 4)); // => "(3, 4)"
2929
//! format!("{value}", value=4); // => "4"
3030
//! format!("{} {}", 1, 2); // => "1 2"
31+
//! format!("{:04}", 42); // => "0042" with leading zeros
3132
//! ```
3233
//!
3334
//! From these, you can see that the first argument is a format string. It is

src/librustc/diagnostics.rs

+15-25
Original file line numberDiff line numberDiff line change
@@ -673,45 +673,35 @@ extern "C" {
673673
"##,
674674

675675
E0269: r##"
676-
Functions must eventually return a value of their return type. For example, in
677-
the following function:
676+
A returned value was expected but not all control paths return one.
677+
678+
Erroneous code example:
678679
679680
```compile_fail,E0269
680681
fn abracada_FAIL() -> String {
681682
"this won't work".to_string();
683+
// error: not all control paths return a value
682684
}
683685
```
684686
685-
If the condition is true, the value `x` is returned, but if the condition is
686-
false, control exits the `if` block and reaches a place where nothing is being
687-
returned. All possible control paths must eventually return a `u8`, which is not
688-
happening here.
689-
690-
An easy fix for this in a complicated function is to specify a default return
691-
value, if possible:
687+
In the previous code, the function is supposed to return a `String`, however,
688+
the code returns nothing (because of the ';'). Another erroneous code would be:
692689
693-
```ignore
694-
fn foo(x: u8) -> u8 {
695-
if x > 0 {
696-
x // alternatively, `return x`
690+
```compile_fail
691+
fn abracada_FAIL(b: bool) -> u32 {
692+
if b {
693+
0
694+
} else {
695+
"a" // It fails because an `u32` was expected and something else is
696+
// returned.
697697
}
698-
// lots of other if branches
699-
0 // return 0 if all else fails
700698
}
701699
```
702700
703701
It is advisable to find out what the unhandled cases are and check for them,
704702
returning an appropriate value or panicking if necessary. Check if you need
705-
to remove a semicolon from the last expression, like in this case:
706-
707-
```ignore
708-
fn foo(x: u8) -> u8 {
709-
inner(2*x + 1);
710-
}
711-
```
712-
713-
The semicolon discards the return value of `inner`, instead of returning
714-
it from `foo`.
703+
to remove a semicolon from the last expression, like in the first erroneous
704+
code example.
715705
"##,
716706

717707
E0270: r##"

src/librustdoc/visit_ast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
189189
}
190190
hir::ViewPathList(p, paths) => {
191191
let mine = paths.into_iter().filter(|path| {
192-
!self.maybe_inline_local(path.node.id(), None, false, om,
193-
please_inline)
192+
!self.maybe_inline_local(path.node.id(), path.node.rename(),
193+
false, om, please_inline)
194194
}).collect::<hir::HirVec<hir::PathListItem>>();
195195

196196
if mine.is_empty() {

src/libstd/io/util.rs

+23-6
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,11 @@ pub struct Empty { _priv: () }
7878
/// A slightly sad example of not reading anything into a buffer:
7979
///
8080
/// ```
81-
/// use std::io;
82-
/// use std::io::Read;
81+
/// use std::io::{self, Read};
8382
///
84-
/// # fn foo() -> io::Result<String> {
8583
/// let mut buffer = String::new();
86-
/// try!(io::empty().read_to_string(&mut buffer));
87-
/// # Ok(buffer)
88-
/// # }
84+
/// io::empty().read_to_string(&mut buffer).unwrap();
85+
/// assert!(buffer.is_empty());
8986
/// ```
9087
#[stable(feature = "rust1", since = "1.0.0")]
9188
pub fn empty() -> Empty { Empty { _priv: () } }
@@ -113,6 +110,16 @@ pub struct Repeat { byte: u8 }
113110
///
114111
/// All reads from this reader will succeed by filling the specified buffer with
115112
/// the given byte.
113+
///
114+
/// # Examples
115+
///
116+
/// ```
117+
/// use std::io::{self, Read};
118+
///
119+
/// let mut buffer = [0; 3];
120+
/// io::repeat(0b101).read_exact(&mut buffer).unwrap();
121+
/// assert_eq!(buffer, [0b101, 0b101, 0b101]);
122+
/// ```
116123
#[stable(feature = "rust1", since = "1.0.0")]
117124
pub fn repeat(byte: u8) -> Repeat { Repeat { byte: byte } }
118125

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

0 commit comments

Comments
 (0)