From 3dbb741a4b54516e6979f85f4847361413a1b4a3 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Tue, 4 Sep 2018 01:44:19 -0700 Subject: [PATCH 01/11] rustdoc: Sort implementors Fixes #53812 --- src/librustdoc/html/render.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 867b2a329057b..54c746cae410f 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2300,17 +2300,21 @@ fn document_non_exhaustive(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::R } fn name_key(name: &str) -> (&str, u64, usize) { + let end = name.bytes() + .rposition(|b| b.is_ascii_digit()).map_or(name.len(), |i| i + 1); + // find number at end - let split = name.bytes().rposition(|b| b < b'0' || b'9' < b).map_or(0, |s| s + 1); + let split = name[0..end].bytes() + .rposition(|b| !b.is_ascii_digit()).map_or(0, |i| i + 1); // count leading zeroes let after_zeroes = - name[split..].bytes().position(|b| b != b'0').map_or(name.len(), |extra| split + extra); + name[split..end].bytes().position(|b| b != b'0').map_or(name.len(), |extra| split + extra); // sort leading zeroes last let num_zeroes = after_zeroes - split; - match name[split..].parse() { + match name[split..end].parse() { Ok(n) => (&name[..split], n, num_zeroes), Err(_) => (name, 0, num_zeroes), } @@ -2701,6 +2705,14 @@ fn bounds(t_bounds: &[clean::GenericBound]) -> String { bounds } +fn compare_impl<'a, 'b>(lhs: &'a &&Impl, rhs: &'b &&Impl) -> Ordering { + let lhs = format!("{}", lhs.inner_impl()); + let rhs = format!("{}", rhs.inner_impl()); + + // lhs and rhs are formatted as HTML, which may be unnecessary + name_key(&lhs).cmp(&name_key(&rhs)) +} + fn item_trait( w: &mut fmt::Formatter, cx: &Context, @@ -2904,9 +2916,12 @@ fn item_trait( .map_or(true, |d| cache.paths.contains_key(&d))); - let (synthetic, concrete): (Vec<&&Impl>, Vec<&&Impl>) = local.iter() + let (mut synthetic, mut concrete): (Vec<&&Impl>, Vec<&&Impl>) = local.iter() .partition(|i| i.inner_impl().synthetic); + synthetic.sort_by(compare_impl); + concrete.sort_by(compare_impl); + if !foreign.is_empty() { write!(w, "

@@ -4715,6 +4730,7 @@ fn test_name_sorting() { "Fruit1", "Fruit01", "Fruit2", "Fruit02", "Fruit20", + "Fruit30x", "Fruit100", "Pear"]; let mut sorted = names.to_owned(); From 636f518aac7430406dcb410cd7e46b4a217c265c Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Thu, 13 Sep 2018 15:54:12 +0300 Subject: [PATCH 02/11] Suggest && and || instead of 'and' and 'or' Closes #54109. --- src/libsyntax/parse/parser.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f57fca2cfcf60..a28157106ba7d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -732,6 +732,12 @@ impl<'a> Parser<'a> { format!("expected {} here", expect))) }; let mut err = self.fatal(&msg_exp); + if self.token.is_ident_named("and") { + err.help("Use `&&` instead of `and` for the boolean operator"); + } + if self.token.is_ident_named("or") { + err.help("Use `||` instead of `or` for the boolean operator"); + } let sp = if self.token == token::Token::Eof { // This is EOF, don't want to point at the following char, but rather the last token self.prev_span @@ -4751,6 +4757,13 @@ impl<'a> Parser<'a> { e.span_label(sp, "expected `{`"); } + if self.token.is_ident_named("and") { + e.help("Use `&&` instead of `and` for the boolean operator"); + } + if self.token.is_ident_named("or") { + e.help("Use `||` instead of `or` for the boolean operator"); + } + // Check to see if the user has written something like // // if (cond) From 888b8c9451a41cccc8bdceee6423ee9d9e66bb43 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Thu, 13 Sep 2018 15:54:25 +0300 Subject: [PATCH 03/11] Add tests for issue 54109 --- .../issue-54109-and_instead_of_ampersands.rs | 48 +++++++++++++++++++ ...sue-54109-and_instead_of_ampersands.stderr | 38 +++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.rs create mode 100644 src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr diff --git a/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.rs b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.rs new file mode 100644 index 0000000000000..cb37845529407 --- /dev/null +++ b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.rs @@ -0,0 +1,48 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn test_and() { + let a = true; + let b = false; + if a and b { + //~^ ERROR expected `{`, found `and` + println!("both"); + } +} + +fn test_or() { + let a = true; + let b = false; + if a or b { + //~^ ERROR expected `{`, found `or` + println!("both"); + } +} + +fn test_and_par() { + let a = true; + let b = false; + if (a and b) { + //~^ ERROR expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `and` + println!("both"); + } +} + +fn test_or_par() { + let a = true; + let b = false; + if (a or b) { + //~^ ERROR expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `or` + println!("both"); + } +} + +fn main() { +} diff --git a/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr new file mode 100644 index 0000000000000..9d53cc237e291 --- /dev/null +++ b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr @@ -0,0 +1,38 @@ +error: expected `{`, found `and` + --> $DIR/issue-54109-and_instead_of_ampersands.rs:14:10 + | +LL | if a and b { + | -- ^^^ + | | + | this `if` statement has a condition, but no block + | + = help: Use `&&` instead of `and` for the boolean operator + +error: expected `{`, found `or` + --> $DIR/issue-54109-and_instead_of_ampersands.rs:23:10 + | +LL | if a or b { + | -- ^^ + | | + | this `if` statement has a condition, but no block + | + = help: Use `||` instead of `or` for the boolean operator + +error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `and` + --> $DIR/issue-54109-and_instead_of_ampersands.rs:32:11 + | +LL | if (a and b) { + | ^^^ expected one of 8 possible tokens here + | + = help: Use `&&` instead of `and` for the boolean operator + +error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `or` + --> $DIR/issue-54109-and_instead_of_ampersands.rs:41:11 + | +LL | if (a or b) { + | ^^ expected one of 8 possible tokens here + | + = help: Use `||` instead of `or` for the boolean operator + +error: aborting due to 4 previous errors + From acc44e40ccd860a3cae54c7b56956c3c1340182e Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Thu, 13 Sep 2018 20:40:39 +0300 Subject: [PATCH 04/11] Use span_suggestion_with_applicability for "and/or" hinter Advised by @estebank. --- src/libsyntax/parse/parser.rs | 28 ++++++++++++++++--- ...sue-54109-and_instead_of_ampersands.stderr | 23 +++++++-------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index a28157106ba7d..429d1b6bf5e8f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -733,10 +733,20 @@ impl<'a> Parser<'a> { }; let mut err = self.fatal(&msg_exp); if self.token.is_ident_named("and") { - err.help("Use `&&` instead of `and` for the boolean operator"); + err.span_suggestion_with_applicability( + self.span, + "use `&&` instead of `and` for the boolean operator", + "&&".to_string(), + Applicability::MaybeIncorrect, + ); } if self.token.is_ident_named("or") { - err.help("Use `||` instead of `or` for the boolean operator"); + err.span_suggestion_with_applicability( + self.span, + "use `||` instead of `or` for the boolean operator", + "||".to_string(), + Applicability::MaybeIncorrect, + ); } let sp = if self.token == token::Token::Eof { // This is EOF, don't want to point at the following char, but rather the last token @@ -4758,10 +4768,20 @@ impl<'a> Parser<'a> { } if self.token.is_ident_named("and") { - e.help("Use `&&` instead of `and` for the boolean operator"); + e.span_suggestion_with_applicability( + self.span, + "use `&&` instead of `and` for the boolean operator", + "&&".to_string(), + Applicability::MaybeIncorrect, + ); } if self.token.is_ident_named("or") { - e.help("Use `||` instead of `or` for the boolean operator"); + e.span_suggestion_with_applicability( + self.span, + "use `||` instead of `or` for the boolean operator", + "||".to_string(), + Applicability::MaybeIncorrect, + ); } // Check to see if the user has written something like diff --git a/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr index 9d53cc237e291..74ebb1e757c96 100644 --- a/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr +++ b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr @@ -2,37 +2,34 @@ error: expected `{`, found `and` --> $DIR/issue-54109-and_instead_of_ampersands.rs:14:10 | LL | if a and b { - | -- ^^^ + | -- ^^^ help: use `&&` instead of `and` for the boolean operator: `&&` | | | this `if` statement has a condition, but no block - | - = help: Use `&&` instead of `and` for the boolean operator error: expected `{`, found `or` --> $DIR/issue-54109-and_instead_of_ampersands.rs:23:10 | LL | if a or b { - | -- ^^ + | -- ^^ help: use `||` instead of `or` for the boolean operator: `||` | | | this `if` statement has a condition, but no block - | - = help: Use `||` instead of `or` for the boolean operator error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `and` --> $DIR/issue-54109-and_instead_of_ampersands.rs:32:11 | LL | if (a and b) { - | ^^^ expected one of 8 possible tokens here - | - = help: Use `&&` instead of `and` for the boolean operator + | ^^^ + | | + | expected one of 8 possible tokens here + | help: use `&&` instead of `and` for the boolean operator: `&&` error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `or` --> $DIR/issue-54109-and_instead_of_ampersands.rs:41:11 | LL | if (a or b) { - | ^^ expected one of 8 possible tokens here - | - = help: Use `||` instead of `or` for the boolean operator + | ^^ + | | + | expected one of 8 possible tokens here + | help: use `||` instead of `or` for the boolean operator: `||` error: aborting due to 4 previous errors - From 79919a7ed672fc77d0c6b8e5836b33af4598e280 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Thu, 13 Sep 2018 20:51:29 +0300 Subject: [PATCH 05/11] Add "while" tests for issue 54109 --- .../issue-54109-and_instead_of_ampersands.rs | 18 ++++++++++++++++ ...sue-54109-and_instead_of_ampersands.stderr | 21 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.rs b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.rs index cb37845529407..d053b11772cd0 100644 --- a/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.rs +++ b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.rs @@ -44,5 +44,23 @@ fn test_or_par() { } } +fn test_while_and() { + let a = true; + let b = false; + while a and b { + //~^ ERROR expected one of `!`, `.`, `::`, `?`, `{`, or an operator, found `and` + println!("both"); + } +} + +fn test_while_or() { + let a = true; + let b = false; + while a or b { + //~^ ERROR expected one of `!`, `.`, `::`, `?`, `{`, or an operator, found `or` + println!("both"); + } +} + fn main() { } diff --git a/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr index 74ebb1e757c96..552619dd4beec 100644 --- a/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr +++ b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr @@ -32,4 +32,23 @@ LL | if (a or b) { | expected one of 8 possible tokens here | help: use `||` instead of `or` for the boolean operator: `||` -error: aborting due to 4 previous errors +error: expected one of `!`, `.`, `::`, `?`, `{`, or an operator, found `and` + --> $DIR/issue-54109-and_instead_of_ampersands.rs:50:13 + | +LL | while a and b { + | ^^^ + | | + | expected one of `!`, `.`, `::`, `?`, `{`, or an operator here + | help: use `&&` instead of `and` for the boolean operator: `&&` + +error: expected one of `!`, `.`, `::`, `?`, `{`, or an operator, found `or` + --> $DIR/issue-54109-and_instead_of_ampersands.rs:59:13 + | +LL | while a or b { + | ^^ + | | + | expected one of `!`, `.`, `::`, `?`, `{`, or an operator here + | help: use `||` instead of `or` for the boolean operator: `||` + +error: aborting due to 6 previous errors + From 0a0d642f38f8e4f69997dd48dd96e364471d90bf Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Fri, 14 Sep 2018 02:37:12 +0300 Subject: [PATCH 06/11] Partially revert 674a5db "Fix undesirable fallout [from macro modularization]" --- .../ui/run-pass/macros/macro-comma-support.rs | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/test/ui/run-pass/macros/macro-comma-support.rs b/src/test/ui/run-pass/macros/macro-comma-support.rs index 9186974f0a378..f674123aac7a2 100644 --- a/src/test/ui/run-pass/macros/macro-comma-support.rs +++ b/src/test/ui/run-pass/macros/macro-comma-support.rs @@ -62,30 +62,30 @@ fn assert_ne() { #[test] fn cfg() { - cfg!(pants); - cfg!(pants,); - cfg!(pants = "pants"); - cfg!(pants = "pants",); - cfg!(all(pants)); - cfg!(all(pants),); - cfg!(all(pants,)); - cfg!(all(pants,),); + let _ = cfg!(pants); + let _ = cfg!(pants,); + let _ = cfg!(pants = "pants"); + let _ = cfg!(pants = "pants",); + let _ = cfg!(all(pants)); + let _ = cfg!(all(pants),); + let _ = cfg!(all(pants,)); + let _ = cfg!(all(pants,),); } #[test] fn column() { - column!(); + let _ = column!(); } // compile_error! is in a companion to this test in compile-fail #[test] fn concat() { - concat!(); - concat!("hello"); - concat!("hello",); - concat!("hello", " world"); - concat!("hello", " world",); + let _ = concat!(); + let _ = concat!("hello"); + let _ = concat!("hello",); + let _ = concat!("hello", " world"); + let _ = concat!("hello", " world",); } #[test] @@ -131,10 +131,10 @@ fn debug_assert_ne() { #[test] fn env() { - env!("PATH"); - env!("PATH",); - env!("PATH", "not found"); - env!("PATH", "not found",); + let _ = env!("PATH"); + let _ = env!("PATH",); + let _ = env!("PATH", "not found"); + let _ = env!("PATH", "not found",); } #[cfg(std)] @@ -158,58 +158,58 @@ fn eprintln() { #[test] fn file() { - file!(); + let _ = file!(); } #[cfg(std)] #[test] fn format() { - format!("hello"); - format!("hello",); - format!("hello {}", "world"); - format!("hello {}", "world",); + let _ = format!("hello"); + let _ = format!("hello",); + let _ = format!("hello {}", "world"); + let _ = format!("hello {}", "world",); } #[test] fn format_args() { - format_args!("hello"); - format_args!("hello",); - format_args!("hello {}", "world"); - format_args!("hello {}", "world",); + let _ = format_args!("hello"); + let _ = format_args!("hello",); + let _ = format_args!("hello {}", "world"); + let _ = format_args!("hello {}", "world",); } #[test] fn include() { - include!("auxiliary/macro-comma-support.rs"); - include!("auxiliary/macro-comma-support.rs",); + let _ = include!("auxiliary/macro-comma-support.rs"); + let _ = include!("auxiliary/macro-comma-support.rs",); } #[test] fn include_bytes() { - include_bytes!("auxiliary/macro-comma-support.rs"); - include_bytes!("auxiliary/macro-comma-support.rs",); + let _ = include_bytes!("auxiliary/macro-comma-support.rs"); + let _ = include_bytes!("auxiliary/macro-comma-support.rs",); } #[test] fn include_str() { - include_str!("auxiliary/macro-comma-support.rs"); - include_str!("auxiliary/macro-comma-support.rs",); + let _ = include_str!("auxiliary/macro-comma-support.rs"); + let _ = include_str!("auxiliary/macro-comma-support.rs",); } #[test] fn line() { - line!(); + let _ = line!(); } #[test] fn module_path() { - module_path!(); + let _ = module_path!(); } #[test] fn option_env() { - option_env!("PATH"); - option_env!("PATH",); + let _ = option_env!("PATH"); + let _ = option_env!("PATH",); } #[test] @@ -309,10 +309,10 @@ fn unreachable() { #[test] fn vec() { let _: Vec<()> = vec![]; - vec![0]; - vec![0,]; - vec![0, 1]; - vec![0, 1,]; + let _ = vec![0]; + let _ = vec![0,]; + let _ = vec![0, 1]; + let _ = vec![0, 1,]; } // give a test body access to a fmt::Formatter, which seems @@ -340,21 +340,21 @@ macro_rules! test_with_formatter { test_with_formatter! { #[test] fn write(f: &mut fmt::Formatter) { - write!(f, "hello"); - write!(f, "hello",); - write!(f, "hello {}", "world"); - write!(f, "hello {}", "world",); + let _ = write!(f, "hello"); + let _ = write!(f, "hello",); + let _ = write!(f, "hello {}", "world"); + let _ = write!(f, "hello {}", "world",); } } test_with_formatter! { #[test] fn writeln(f: &mut fmt::Formatter) { - writeln!(f); - writeln!(f,); - writeln!(f, "hello"); - writeln!(f, "hello",); - writeln!(f, "hello {}", "world"); - writeln!(f, "hello {}", "world",); + let _ = writeln!(f); + let _ = writeln!(f,); + let _ = writeln!(f, "hello"); + let _ = writeln!(f, "hello",); + let _ = writeln!(f, "hello {}", "world"); + let _ = writeln!(f, "hello {}", "world",); } } From aa9aca0d3d6aa371691d226bd41b4dd4af083a46 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 14 Sep 2018 14:55:21 +1000 Subject: [PATCH 07/11] De-overlap the lifetimes of `flow_inits` and `flow_{un,ever_}inits`. This reduces `max-rss` for an `nll-check` build by 27% for `keccak`, and by 8% for `inflate`. --- src/librustc_mir/borrow_check/mod.rs | 42 ++++++++++++++++------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 76f6bcb5e566d..8b379c5ce6970 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -177,24 +177,6 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( MaybeInitializedPlaces::new(tcx, mir, &mdpe), |bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]), )); - let flow_uninits = FlowAtLocation::new(do_dataflow( - tcx, - mir, - id, - &attributes, - &dead_unwinds, - MaybeUninitializedPlaces::new(tcx, mir, &mdpe), - |bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]), - )); - let flow_ever_inits = FlowAtLocation::new(do_dataflow( - tcx, - mir, - id, - &attributes, - &dead_unwinds, - EverInitializedPlaces::new(tcx, mir, &mdpe), - |bd, i| DebugFormatted::new(&bd.move_data().inits[i]), - )); let locals_are_invalidated_at_exit = match tcx.hir.body_owner_kind(id) { hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => false, @@ -216,6 +198,12 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( &borrow_set, &mut errors_buffer, ); + + // The various `flow_*` structures can be large. We drop `flow_inits` here + // so it doesn't overlap with the others below. This reduces peak memory + // usage significantly on some benchmarks. + drop(flow_inits); + let regioncx = Rc::new(regioncx); let flow_borrows = FlowAtLocation::new(do_dataflow( @@ -227,6 +215,24 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( Borrows::new(tcx, mir, regioncx.clone(), def_id, body_id, &borrow_set), |rs, i| DebugFormatted::new(&rs.location(i)), )); + let flow_uninits = FlowAtLocation::new(do_dataflow( + tcx, + mir, + id, + &attributes, + &dead_unwinds, + MaybeUninitializedPlaces::new(tcx, mir, &mdpe), + |bd, i| DebugFormatted::new(&bd.move_data().move_paths[i]), + )); + let flow_ever_inits = FlowAtLocation::new(do_dataflow( + tcx, + mir, + id, + &attributes, + &dead_unwinds, + EverInitializedPlaces::new(tcx, mir, &mdpe), + |bd, i| DebugFormatted::new(&bd.move_data().inits[i]), + )); let movable_generator = match tcx.hir.get(id) { Node::Expr(&hir::Expr { From bc63a4a13a442e1844bb5577adcc464c2a6bfd21 Mon Sep 17 00:00:00 2001 From: Vitaly _Vi Shukela Date: Sat, 15 Sep 2018 02:05:32 +0300 Subject: [PATCH 08/11] issue 54109: use short suggestions --- src/libsyntax/parse/parser.rs | 8 ++++---- .../issue-54109-and_instead_of_ampersands.stderr | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 429d1b6bf5e8f..48e034b117f18 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -733,7 +733,7 @@ impl<'a> Parser<'a> { }; let mut err = self.fatal(&msg_exp); if self.token.is_ident_named("and") { - err.span_suggestion_with_applicability( + err.span_suggestion_short_with_applicability( self.span, "use `&&` instead of `and` for the boolean operator", "&&".to_string(), @@ -741,7 +741,7 @@ impl<'a> Parser<'a> { ); } if self.token.is_ident_named("or") { - err.span_suggestion_with_applicability( + err.span_suggestion_short_with_applicability( self.span, "use `||` instead of `or` for the boolean operator", "||".to_string(), @@ -4768,7 +4768,7 @@ impl<'a> Parser<'a> { } if self.token.is_ident_named("and") { - e.span_suggestion_with_applicability( + e.span_suggestion_short_with_applicability( self.span, "use `&&` instead of `and` for the boolean operator", "&&".to_string(), @@ -4776,7 +4776,7 @@ impl<'a> Parser<'a> { ); } if self.token.is_ident_named("or") { - e.span_suggestion_with_applicability( + e.span_suggestion_short_with_applicability( self.span, "use `||` instead of `or` for the boolean operator", "||".to_string(), diff --git a/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr index 552619dd4beec..22845775aed13 100644 --- a/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr +++ b/src/test/ui/did_you_mean/issue-54109-and_instead_of_ampersands.stderr @@ -2,7 +2,7 @@ error: expected `{`, found `and` --> $DIR/issue-54109-and_instead_of_ampersands.rs:14:10 | LL | if a and b { - | -- ^^^ help: use `&&` instead of `and` for the boolean operator: `&&` + | -- ^^^ help: use `&&` instead of `and` for the boolean operator | | | this `if` statement has a condition, but no block @@ -10,7 +10,7 @@ error: expected `{`, found `or` --> $DIR/issue-54109-and_instead_of_ampersands.rs:23:10 | LL | if a or b { - | -- ^^ help: use `||` instead of `or` for the boolean operator: `||` + | -- ^^ help: use `||` instead of `or` for the boolean operator | | | this `if` statement has a condition, but no block @@ -21,7 +21,7 @@ LL | if (a and b) { | ^^^ | | | expected one of 8 possible tokens here - | help: use `&&` instead of `and` for the boolean operator: `&&` + | help: use `&&` instead of `and` for the boolean operator error: expected one of `!`, `)`, `,`, `.`, `::`, `?`, `{`, or an operator, found `or` --> $DIR/issue-54109-and_instead_of_ampersands.rs:41:11 @@ -30,7 +30,7 @@ LL | if (a or b) { | ^^ | | | expected one of 8 possible tokens here - | help: use `||` instead of `or` for the boolean operator: `||` + | help: use `||` instead of `or` for the boolean operator error: expected one of `!`, `.`, `::`, `?`, `{`, or an operator, found `and` --> $DIR/issue-54109-and_instead_of_ampersands.rs:50:13 @@ -39,7 +39,7 @@ LL | while a and b { | ^^^ | | | expected one of `!`, `.`, `::`, `?`, `{`, or an operator here - | help: use `&&` instead of `and` for the boolean operator: `&&` + | help: use `&&` instead of `and` for the boolean operator error: expected one of `!`, `.`, `::`, `?`, `{`, or an operator, found `or` --> $DIR/issue-54109-and_instead_of_ampersands.rs:59:13 @@ -48,7 +48,7 @@ LL | while a or b { | ^^ | | | expected one of `!`, `.`, `::`, `?`, `{`, or an operator here - | help: use `||` instead of `or` for the boolean operator: `||` + | help: use `||` instead of `or` for the boolean operator error: aborting due to 6 previous errors From bbcb6339aa6f1062a220ce5d16fea3b645c32281 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Fri, 14 Sep 2018 22:42:44 -0700 Subject: [PATCH 09/11] Add a test to prevent regression The way it defines implementations is unrealistic though. --- src/test/rustdoc/issue-53812.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/test/rustdoc/issue-53812.rs diff --git a/src/test/rustdoc/issue-53812.rs b/src/test/rustdoc/issue-53812.rs new file mode 100644 index 0000000000000..f0113d13bb4f4 --- /dev/null +++ b/src/test/rustdoc/issue-53812.rs @@ -0,0 +1,26 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +pub trait MyIterator { +} + +pub struct MyStruct(T); + +macro_rules! array_impls { + ($($N:expr)+) => { + $( + impl<'a, T> MyIterator for &'a MyStruct<[T; $N]> { + } + )+ + } +} + +// @has issue_53812/trait.MyIterator.html '//*[@id="implementors-list"]//h3[1]' 'MyStruct<[T; 0]>' +array_impls! { 10 3 2 1 0 } From d63fd469291cc7285b47a3f03c6ed99954c4bbe1 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Fri, 14 Sep 2018 23:28:32 -0700 Subject: [PATCH 10/11] Add a small search box to seach Rust's standary library This change partially addresses #14572. No CSS doesn't look fancy but at least it is functional. --- src/doc/index.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/doc/index.md b/src/doc/index.md index 11313ba99e1a6..b1788d8c32f02 100644 --- a/src/doc/index.md +++ b/src/doc/index.md @@ -43,6 +43,13 @@ Rust's standard library has [extensive API documentation](std/index.html), with explanations of how to use various things, as well as example code for accomplishing various tasks. +
+
+ + +
+
+ ## The Rustc Book [The Rustc Book](rustc/index.html) describes the Rust compiler, `rustc`. From 2fe450370319c30756a716e0525cc6d23046f104 Mon Sep 17 00:00:00 2001 From: Kazuyoshi Kato Date: Sun, 16 Sep 2018 00:39:12 -0700 Subject: [PATCH 11/11] Check the remaining nodes --- src/test/rustdoc/issue-53812.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/test/rustdoc/issue-53812.rs b/src/test/rustdoc/issue-53812.rs index f0113d13bb4f4..60d19fbcd1a20 100644 --- a/src/test/rustdoc/issue-53812.rs +++ b/src/test/rustdoc/issue-53812.rs @@ -23,4 +23,8 @@ macro_rules! array_impls { } // @has issue_53812/trait.MyIterator.html '//*[@id="implementors-list"]//h3[1]' 'MyStruct<[T; 0]>' +// @has - '//*[@id="implementors-list"]//h3[2]' 'MyStruct<[T; 1]>' +// @has - '//*[@id="implementors-list"]//h3[3]' 'MyStruct<[T; 2]>' +// @has - '//*[@id="implementors-list"]//h3[4]' 'MyStruct<[T; 3]>' +// @has - '//*[@id="implementors-list"]//h3[5]' 'MyStruct<[T; 10]>' array_impls! { 10 3 2 1 0 }