Skip to content

Commit d3cba9b

Browse files
committed
Auto merge of #54270 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - #53941 (rustdoc: Sort implementors) - #54181 (Suggest && and || instead of 'and' and 'or') - #54209 (Partially revert 674a5db "Fix undesirable fallout [from macro modularization]") - #54213 (De-overlap the lifetimes of `flow_inits` and `flow_{un,ever_}inits`.) - #54244 (Add a small search box to seach Rust's standary library) Failed merges: r? @ghost
2 parents 32dc5a0 + 8b1e5e1 commit d3cba9b

File tree

8 files changed

+285
-73
lines changed

8 files changed

+285
-73
lines changed

src/doc/index.md

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ Rust's standard library has [extensive API documentation](std/index.html),
4343
with explanations of how to use various things, as well as example code for
4444
accomplishing various tasks.
4545

46+
<div>
47+
<form action="std/index.html" method="get">
48+
<input type="search" name="search"/>
49+
<button>Search</button>
50+
</form>
51+
</div>
52+
4653
## The Rustc Book
4754

4855
[The Rustc Book](rustc/index.html) describes the Rust compiler, `rustc`.

src/librustc_mir/borrow_check/mod.rs

+24-18
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,6 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
177177
MaybeInitializedPlaces::new(tcx, mir, &mdpe),
178178
|bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]),
179179
));
180-
let flow_uninits = FlowAtLocation::new(do_dataflow(
181-
tcx,
182-
mir,
183-
id,
184-
&attributes,
185-
&dead_unwinds,
186-
MaybeUninitializedPlaces::new(tcx, mir, &mdpe),
187-
|bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]),
188-
));
189-
let flow_ever_inits = FlowAtLocation::new(do_dataflow(
190-
tcx,
191-
mir,
192-
id,
193-
&attributes,
194-
&dead_unwinds,
195-
EverInitializedPlaces::new(tcx, mir, &mdpe),
196-
|bd, i| DebugFormatted::new(&bd.move_data().inits[i]),
197-
));
198180

199181
let locals_are_invalidated_at_exit = match tcx.hir.body_owner_kind(id) {
200182
hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => false,
@@ -216,6 +198,12 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
216198
&borrow_set,
217199
&mut errors_buffer,
218200
);
201+
202+
// The various `flow_*` structures can be large. We drop `flow_inits` here
203+
// so it doesn't overlap with the others below. This reduces peak memory
204+
// usage significantly on some benchmarks.
205+
drop(flow_inits);
206+
219207
let regioncx = Rc::new(regioncx);
220208

221209
let flow_borrows = FlowAtLocation::new(do_dataflow(
@@ -227,6 +215,24 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
227215
Borrows::new(tcx, mir, regioncx.clone(), def_id, body_id, &borrow_set),
228216
|rs, i| DebugFormatted::new(&rs.location(i)),
229217
));
218+
let flow_uninits = FlowAtLocation::new(do_dataflow(
219+
tcx,
220+
mir,
221+
id,
222+
&attributes,
223+
&dead_unwinds,
224+
MaybeUninitializedPlaces::new(tcx, mir, &mdpe),
225+
|bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]),
226+
));
227+
let flow_ever_inits = FlowAtLocation::new(do_dataflow(
228+
tcx,
229+
mir,
230+
id,
231+
&attributes,
232+
&dead_unwinds,
233+
EverInitializedPlaces::new(tcx, mir, &mdpe),
234+
|bd, i| DebugFormatted::new(&bd.move_data().inits[i]),
235+
));
230236

231237
let movable_generator = match tcx.hir.get(id) {
232238
Node::Expr(&hir::Expr {

src/librustdoc/html/render.rs

+20-4
Original file line numberDiff line numberDiff line change
@@ -2301,17 +2301,21 @@ fn document_non_exhaustive(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::R
23012301
}
23022302

23032303
fn name_key(name: &str) -> (&str, u64, usize) {
2304+
let end = name.bytes()
2305+
.rposition(|b| b.is_ascii_digit()).map_or(name.len(), |i| i + 1);
2306+
23042307
// find number at end
2305-
let split = name.bytes().rposition(|b| b < b'0' || b'9' < b).map_or(0, |s| s + 1);
2308+
let split = name[0..end].bytes()
2309+
.rposition(|b| !b.is_ascii_digit()).map_or(0, |i| i + 1);
23062310

23072311
// count leading zeroes
23082312
let after_zeroes =
2309-
name[split..].bytes().position(|b| b != b'0').map_or(name.len(), |extra| split + extra);
2313+
name[split..end].bytes().position(|b| b != b'0').map_or(name.len(), |extra| split + extra);
23102314

23112315
// sort leading zeroes last
23122316
let num_zeroes = after_zeroes - split;
23132317

2314-
match name[split..].parse() {
2318+
match name[split..end].parse() {
23152319
Ok(n) => (&name[..split], n, num_zeroes),
23162320
Err(_) => (name, 0, num_zeroes),
23172321
}
@@ -2702,6 +2706,14 @@ fn bounds(t_bounds: &[clean::GenericBound]) -> String {
27022706
bounds
27032707
}
27042708

2709+
fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl) -> Ordering {
2710+
let lhs = format!("{}", lhs.inner_impl());
2711+
let rhs = format!("{}", rhs.inner_impl());
2712+
2713+
// lhs and rhs are formatted as HTML, which may be unnecessary
2714+
name_key(&lhs).cmp(&name_key(&rhs))
2715+
}
2716+
27052717
fn item_trait(
27062718
w: &mut fmt::Formatter,
27072719
cx: &Context,
@@ -2905,9 +2917,12 @@ fn item_trait(
29052917
.map_or(true, |d| cache.paths.contains_key(&d)));
29062918

29072919

2908-
let (synthetic, concrete): (Vec<&&Impl>, Vec<&&Impl>) = local.iter()
2920+
let (mut synthetic, mut concrete): (Vec<&&Impl>, Vec<&&Impl>) = local.iter()
29092921
.partition(|i| i.inner_impl().synthetic);
29102922

2923+
synthetic.sort_by(compare_impl);
2924+
concrete.sort_by(compare_impl);
2925+
29112926
if !foreign.is_empty() {
29122927
write!(w, "
29132928
<h2 id='foreign-impls' class='small-section-header'>
@@ -4716,6 +4731,7 @@ fn test_name_sorting() {
47164731
"Fruit1", "Fruit01",
47174732
"Fruit2", "Fruit02",
47184733
"Fruit20",
4734+
"Fruit30x",
47194735
"Fruit100",
47204736
"Pear"];
47214737
let mut sorted = names.to_owned();

src/libsyntax/parse/parser.rs

+33
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,22 @@ impl<'a> Parser<'a> {
732732
format!("expected {} here", expect)))
733733
};
734734
let mut err = self.fatal(&msg_exp);
735+
if self.token.is_ident_named("and") {
736+
err.span_suggestion_short_with_applicability(
737+
self.span,
738+
"use `&&` instead of `and` for the boolean operator",
739+
"&&".to_string(),
740+
Applicability::MaybeIncorrect,
741+
);
742+
}
743+
if self.token.is_ident_named("or") {
744+
err.span_suggestion_short_with_applicability(
745+
self.span,
746+
"use `||` instead of `or` for the boolean operator",
747+
"||".to_string(),
748+
Applicability::MaybeIncorrect,
749+
);
750+
}
735751
let sp = if self.token == token::Token::Eof {
736752
// This is EOF, don't want to point at the following char, but rather the last token
737753
self.prev_span
@@ -4751,6 +4767,23 @@ impl<'a> Parser<'a> {
47514767
e.span_label(sp, "expected `{`");
47524768
}
47534769

4770+
if self.token.is_ident_named("and") {
4771+
e.span_suggestion_short_with_applicability(
4772+
self.span,
4773+
"use `&&` instead of `and` for the boolean operator",
4774+
"&&".to_string(),
4775+
Applicability::MaybeIncorrect,
4776+
);
4777+
}
4778+
if self.token.is_ident_named("or") {
4779+
e.span_suggestion_short_with_applicability(
4780+
self.span,
4781+
"use `||` instead of `or` for the boolean operator",
4782+
"||".to_string(),
4783+
Applicability::MaybeIncorrect,
4784+
);
4785+
}
4786+
47544787
// Check to see if the user has written something like
47554788
//
47564789
// if (cond)

src/test/rustdoc/issue-53812.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub trait MyIterator {
12+
}
13+
14+
pub struct MyStruct<T>(T);
15+
16+
macro_rules! array_impls {
17+
($($N:expr)+) => {
18+
$(
19+
impl<'a, T> MyIterator for &'a MyStruct<[T; $N]> {
20+
}
21+
)+
22+
}
23+
}
24+
25+
// @has issue_53812/trait.MyIterator.html '//*[@id="implementors-list"]//h3[1]' 'MyStruct<[T; 0]>'
26+
// @has - '//*[@id="implementors-list"]//h3[2]' 'MyStruct<[T; 1]>'
27+
// @has - '//*[@id="implementors-list"]//h3[3]' 'MyStruct<[T; 2]>'
28+
// @has - '//*[@id="implementors-list"]//h3[4]' 'MyStruct<[T; 3]>'
29+
// @has - '//*[@id="implementors-list"]//h3[5]' 'MyStruct<[T; 10]>'
30+
array_impls! { 10 3 2 1 0 }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn test_and() {
12+
let a = true;
13+
let b = false;
14+
if a and b {
15+
//~^ ERROR expected `{`, found `and`
16+
println!("both");
17+
}
18+
}
19+
20+
fn test_or() {
21+
let a = true;
22+
let b = false;
23+
if a or b {
24+
//~^ ERROR expected `{`, found `or`
25+
println!("both");
26+
}
27+
}
28+
29+
fn test_and_par() {
30+
let a = true;
31+
let b = false;
32+
if (a and b) {
33+
//~^ ERROR expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `and`
34+
println!("both");
35+
}
36+
}
37+
38+
fn test_or_par() {
39+
let a = true;
40+
let b = false;
41+
if (a or b) {
42+
//~^ ERROR expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `or`
43+
println!("both");
44+
}
45+
}
46+
47+
fn test_while_and() {
48+
let a = true;
49+
let b = false;
50+
while a and b {
51+
//~^ ERROR expected one of `!`, `.`, `::`, `?`, `{`, or an operator, found `and`
52+
println!("both");
53+
}
54+
}
55+
56+
fn test_while_or() {
57+
let a = true;
58+
let b = false;
59+
while a or b {
60+
//~^ ERROR expected one of `!`, `.`, `::`, `?`, `{`, or an operator, found `or`
61+
println!("both");
62+
}
63+
}
64+
65+
fn main() {
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error: expected `{`, found `and`
2+
--> $DIR/issue-54109-and_instead_of_ampersands.rs:14:10
3+
|
4+
LL | if a and b {
5+
| -- ^^^ help: use `&&` instead of `and` for the boolean operator
6+
| |
7+
| this `if` statement has a condition, but no block
8+
9+
error: expected `{`, found `or`
10+
--> $DIR/issue-54109-and_instead_of_ampersands.rs:23:10
11+
|
12+
LL | if a or b {
13+
| -- ^^ help: use `||` instead of `or` for the boolean operator
14+
| |
15+
| this `if` statement has a condition, but no block
16+
17+
error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `and`
18+
--> $DIR/issue-54109-and_instead_of_ampersands.rs:32:11
19+
|
20+
LL | if (a and b) {
21+
| ^^^
22+
| |
23+
| expected one of 8 possible tokens here
24+
| help: use `&&` instead of `and` for the boolean operator
25+
26+
error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `or`
27+
--> $DIR/issue-54109-and_instead_of_ampersands.rs:41:11
28+
|
29+
LL | if (a or b) {
30+
| ^^
31+
| |
32+
| expected one of 8 possible tokens here
33+
| help: use `||` instead of `or` for the boolean operator
34+
35+
error: expected one of `!`, `.`, `::`, `?`, `{`, or an operator, found `and`
36+
--> $DIR/issue-54109-and_instead_of_ampersands.rs:50:13
37+
|
38+
LL | while a and b {
39+
| ^^^
40+
| |
41+
| expected one of `!`, `.`, `::`, `?`, `{`, or an operator here
42+
| help: use `&&` instead of `and` for the boolean operator
43+
44+
error: expected one of `!`, `.`, `::`, `?`, `{`, or an operator, found `or`
45+
--> $DIR/issue-54109-and_instead_of_ampersands.rs:59:13
46+
|
47+
LL | while a or b {
48+
| ^^
49+
| |
50+
| expected one of `!`, `.`, `::`, `?`, `{`, or an operator here
51+
| help: use `||` instead of `or` for the boolean operator
52+
53+
error: aborting due to 6 previous errors
54+

0 commit comments

Comments
 (0)