From 74e9db11625a4b9226ec0a1f84a8a6804e98d72a Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 21 Jan 2020 09:55:43 -0800 Subject: [PATCH 1/6] Update cargo, books --- Cargo.lock | 14 ++++++++++---- src/doc/book | 2 +- src/doc/embedded-book | 2 +- src/doc/reference | 2 +- src/doc/rust-by-example | 2 +- src/tools/cargo | 2 +- 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cbb40f4e2a25e..0a76aabc3a312 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -307,7 +307,7 @@ dependencies = [ "glob", "hex 0.4.0", "home", - "humantime", + "humantime 2.0.0", "ignore", "im-rc", "jobserver", @@ -1013,7 +1013,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3" dependencies = [ "atty", - "humantime", + "humantime 1.3.0", "log", "regex", "termcolor", @@ -1026,7 +1026,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" dependencies = [ "atty", - "humantime", + "humantime 1.3.0", "log", "regex", "termcolor", @@ -1454,6 +1454,12 @@ dependencies = [ "quick-error", ] +[[package]] +name = "humantime" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9b6c53306532d3c8e8087b44e6580e10db51a023cf9b433cea2ac38066b92da" + [[package]] name = "hyper" version = "0.12.31" @@ -2647,7 +2653,7 @@ dependencies = [ "clap", "derive_more", "env_logger 0.6.2", - "humantime", + "humantime 1.3.0", "lazy_static 1.3.0", "log", "rls-span", diff --git a/src/doc/book b/src/doc/book index 5c5cfd2e94cd4..87dd684367857 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 5c5cfd2e94cd42632798d9bd3d1116133e128ac9 +Subproject commit 87dd6843678575f8dda962f239d14ef4be14b352 diff --git a/src/doc/embedded-book b/src/doc/embedded-book index 9493b7d4dc97e..4d78994915af1 160000 --- a/src/doc/embedded-book +++ b/src/doc/embedded-book @@ -1 +1 @@ -Subproject commit 9493b7d4dc97eda439bd8780f05ad7b234cd1cd7 +Subproject commit 4d78994915af1bde9a95c04a8c27d8dca066232a diff --git a/src/doc/reference b/src/doc/reference index e1157538e86d8..11e893fc1357b 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit e1157538e86d83df0cf95d5e33bd943f80d0248f +Subproject commit 11e893fc1357bc688418ddf1087c2b7aa25d154d diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index 1d59403cb5269..1c2bd024d13f8 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit 1d59403cb5269c190cc52a95584ecc280345495a +Subproject commit 1c2bd024d13f8011307e13386cf1fea2180352b5 diff --git a/src/tools/cargo b/src/tools/cargo index ad3dbe10e1e65..f6449ba236db3 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit ad3dbe10e1e654fb1f032a5dd9481d7cbaa00d65 +Subproject commit f6449ba236db31995255ac5e4cad4ab88296a7c6 From f0be351d26009768f2e27e5887e051daca84ff30 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 21 Jan 2020 17:37:11 +0100 Subject: [PATCH 2/6] typeck: use diverges.replace(..) --- src/librustc_typeck/check/_match.rs | 6 ++---- src/librustc_typeck/check/expr.rs | 6 ++---- src/librustc_typeck/check/mod.rs | 7 ++----- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index bd84547d45f9e..a6f8a82a480f2 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -50,10 +50,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.warn_arms_when_scrutinee_diverges(arms, match_src); - // Otherwise, we have to union together the types that the - // arms produce and so forth. - let scrut_diverges = self.diverges.get(); - self.diverges.set(Diverges::Maybe); + // Otherwise, we have to union together the types that the arms produce and so forth. + let scrut_diverges = self.diverges.replace(Diverges::Maybe); // rust-lang/rust#55810: Typecheck patterns first (via eager // collection into `Vec`), so we get types for all bindings. diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 201a09fdc63fa..b4c2b85241f96 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -165,10 +165,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } // Hide the outer diverging and has_errors flags. - let old_diverges = self.diverges.get(); - let old_has_errors = self.has_errors.get(); - self.diverges.set(Diverges::Maybe); - self.has_errors.set(false); + let old_diverges = self.diverges.replace(Diverges::Maybe); + let old_has_errors = self.has_errors.replace(false); let ty = self.check_expr_kind(expr, expected, needs); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 3818750e920ce..2dc198b6d9695 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4429,10 +4429,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.warn_if_unreachable(stmt.hir_id, stmt.span, "statement"); // Hide the outer diverging and `has_errors` flags. - let old_diverges = self.diverges.get(); - let old_has_errors = self.has_errors.get(); - self.diverges.set(Diverges::Maybe); - self.has_errors.set(false); + let old_diverges = self.diverges.replace(Diverges::Maybe); + let old_has_errors = self.has_errors.replace(false); match stmt.kind { hir::StmtKind::Local(ref l) => { @@ -4442,7 +4440,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { hir::StmtKind::Item(_) => {} hir::StmtKind::Expr(ref expr) => { // Check with expected type of `()`. - self.check_expr_has_type_or_error(&expr, self.tcx.mk_unit(), |err| { self.suggest_semicolon_at_end(expr.span, err); }); From 4b3f3ed9d9ff17eced067428e65f5219827a3d38 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 21 Jan 2020 18:24:25 +0100 Subject: [PATCH 3/6] typeck: remove redundant diverges code --- src/librustc_typeck/check/_match.rs | 31 ++++++++--------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index a6f8a82a480f2..d339e3dbf5d68 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -53,25 +53,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Otherwise, we have to union together the types that the arms produce and so forth. let scrut_diverges = self.diverges.replace(Diverges::Maybe); - // rust-lang/rust#55810: Typecheck patterns first (via eager - // collection into `Vec`), so we get types for all bindings. - let all_arm_pats_diverge: Vec<_> = arms - .iter() - .map(|arm| { - let mut all_pats_diverge = Diverges::WarnedAlways; - self.diverges.set(Diverges::Maybe); - self.check_pat_top(&arm.pat, scrut_ty, Some(scrut.span), true); - all_pats_diverge &= self.diverges.get(); - - // As discussed with @eddyb, this is for disabling unreachable_code - // warnings on patterns (they're now subsumed by unreachable_patterns - // warnings). - match all_pats_diverge { - Diverges::Maybe => Diverges::Maybe, - Diverges::Always { .. } | Diverges::WarnedAlways => Diverges::WarnedAlways, - } - }) - .collect(); + // #55810: Type check patterns first so we get types for all bindings. + for arm in arms { + self.check_pat_top(&arm.pat, scrut_ty, Some(scrut.span), true); + } // Now typecheck the blocks. // @@ -102,11 +87,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { CoerceMany::with_coercion_sites(coerce_first, arms) }; - let mut other_arms = vec![]; // used only for diagnostics + let mut other_arms = vec![]; // Used only for diagnostics. let mut prior_arm_ty = None; - for (i, (arm, pats_diverge)) in arms.iter().zip(all_arm_pats_diverge).enumerate() { + for (i, arm) in arms.iter().enumerate() { if let Some(g) = &arm.guard { - self.diverges.set(pats_diverge); + self.diverges.set(Diverges::Maybe); match g { hir::Guard::If(e) => { self.check_expr_has_type_or_error(e, tcx.types.bool, |_| {}) @@ -114,7 +99,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; } - self.diverges.set(pats_diverge); + self.diverges.set(Diverges::Maybe); let arm_ty = if source_if && if_no_else && i != 0 From 95c2f3807502d9c87b92c233c3d19617b81766e3 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 21 Jan 2020 18:47:58 +0100 Subject: [PATCH 4/6] typeck: remove redundant diverges check --- src/librustc_typeck/check/_match.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index d339e3dbf5d68..686cdfbc089b4 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -183,16 +183,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { arms: &'tcx [hir::Arm<'tcx>], source: hir::MatchSource, ) { - if self.diverges.get().is_always() { - use hir::MatchSource::*; - let msg = match source { - IfDesugar { .. } | IfLetDesugar { .. } => "block in `if` expression", - WhileDesugar { .. } | WhileLetDesugar { .. } => "block in `while` expression", - _ => "arm", - }; - for arm in arms { - self.warn_if_unreachable(arm.body.hir_id, arm.body.span, msg); - } + use hir::MatchSource::*; + let msg = match source { + IfDesugar { .. } | IfLetDesugar { .. } => "block in `if` expression", + WhileDesugar { .. } | WhileLetDesugar { .. } => "block in `while` expression", + _ => "arm", + }; + for arm in arms { + self.warn_if_unreachable(arm.body.hir_id, arm.body.span, msg); } } From f899771a7f4d8c6c34f3e61488ba077051a20c4d Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 22 Jan 2020 08:53:31 +0900 Subject: [PATCH 5/6] Update Clippy --- src/tools/clippy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/clippy b/src/tools/clippy index fd0428f622fee..3e74853d1f989 160000 --- a/src/tools/clippy +++ b/src/tools/clippy @@ -1 +1 @@ -Subproject commit fd0428f622feee209e6014b802f5717d48d9e978 +Subproject commit 3e74853d1f9893cf2a47f28b658711d8f9f97b6b From c9eb9453a14afe8667176c16fdd3a77ab5f482f8 Mon Sep 17 00:00:00 2001 From: Tyler Lanphear Date: Wed, 22 Jan 2020 22:25:43 -0500 Subject: [PATCH 6/6] unused-parens: implement for block return values --- src/librustc/ty/mod.rs | 2 +- src/librustc/ty/sty.rs | 2 +- src/librustc_data_structures/sorted_map.rs | 2 +- src/librustc_lint/unused.rs | 16 ++++++--- src/librustc_mir_build/hair/pattern/_match.rs | 2 +- src/librustc_span/source_map.rs | 4 +-- src/libsyntax/print/pprust.rs | 6 +--- src/test/ui/lint/lint-unnecessary-parens.rs | 7 ++++ .../ui/lint/lint-unnecessary-parens.stderr | 36 ++++++++++++------- 9 files changed, 50 insertions(+), 27 deletions(-) diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 0470ab20dc464..e67131b916413 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -2410,7 +2410,7 @@ impl<'tcx> AdtDef { #[inline] pub fn variant_range(&self) -> Range { - (VariantIdx::new(0)..VariantIdx::new(self.variants.len())) + VariantIdx::new(0)..VariantIdx::new(self.variants.len()) } /// Computes the discriminant value used by a specific variant. diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 13f623aadb1a3..837b2fcc50068 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -529,7 +529,7 @@ impl<'tcx> GeneratorSubsts<'tcx> { pub fn variant_range(&self, def_id: DefId, tcx: TyCtxt<'tcx>) -> Range { // FIXME requires optimized MIR let num_variants = tcx.generator_layout(def_id).variant_fields.len(); - (VariantIdx::new(0)..VariantIdx::new(num_variants)) + VariantIdx::new(0)..VariantIdx::new(num_variants) } /// The discriminant for the given variant. Panics if the `variant_index` is diff --git a/src/librustc_data_structures/sorted_map.rs b/src/librustc_data_structures/sorted_map.rs index b29ffd7594008..08706aac11e41 100644 --- a/src/librustc_data_structures/sorted_map.rs +++ b/src/librustc_data_structures/sorted_map.rs @@ -132,7 +132,7 @@ impl SortedMap { R: RangeBounds, { let (start, end) = self.range_slice_indices(range); - (&self.data[start..end]) + &self.data[start..end] } #[inline] diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 15158c09af074..bb2c4fa1aaff6 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -544,12 +544,20 @@ impl EarlyLintPass for UnusedParens { } fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &ast::Stmt) { - if let ast::StmtKind::Local(ref local) = s.kind { - self.check_unused_parens_pat(cx, &local.pat, false, false); + use ast::StmtKind::*; - if let Some(ref value) = local.init { - self.check_unused_parens_expr(cx, &value, "assigned value", false, None, None); + match s.kind { + Local(ref local) => { + self.check_unused_parens_pat(cx, &local.pat, false, false); + + if let Some(ref value) = local.init { + self.check_unused_parens_expr(cx, &value, "assigned value", false, None, None); + } } + Expr(ref expr) => { + self.check_unused_parens_expr(cx, &expr, "block return value", false, None, None); + } + _ => {} } } diff --git a/src/librustc_mir_build/hair/pattern/_match.rs b/src/librustc_mir_build/hair/pattern/_match.rs index 20183fd55c871..a2ce224904b29 100644 --- a/src/librustc_mir_build/hair/pattern/_match.rs +++ b/src/librustc_mir_build/hair/pattern/_match.rs @@ -1530,7 +1530,7 @@ impl<'tcx> IntRange<'tcx> { // 2 -------- // 2 ------- let (lo, hi) = self.boundaries(); let (other_lo, other_hi) = other.boundaries(); - (lo == other_hi || hi == other_lo) + lo == other_hi || hi == other_lo } fn to_pat(&self, tcx: TyCtxt<'tcx>) -> Pat<'tcx> { diff --git a/src/librustc_span/source_map.rs b/src/librustc_span/source_map.rs index 9c7c0f0c8b0ec..e0b93b9ce2555 100644 --- a/src/librustc_span/source_map.rs +++ b/src/librustc_span/source_map.rs @@ -774,10 +774,10 @@ impl SourceMap { // searching forwards for boundaries we've got somewhere to search. let snippet = if let Some(ref src) = local_begin.sf.src { let len = src.len(); - (&src[start_index..len]) + &src[start_index..len] } else if let Some(src) = src.get_source() { let len = src.len(); - (&src[start_index..len]) + &src[start_index..len] } else { return 1; }; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 3927e4f903011..f441712b165cb 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -548,11 +548,7 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::Dere let st = match style { ast::StrStyle::Cooked => (format!("\"{}\"", st.escape_debug())), ast::StrStyle::Raw(n) => { - (format!( - "r{delim}\"{string}\"{delim}", - delim = "#".repeat(n as usize), - string = st - )) + format!("r{delim}\"{string}\"{delim}", delim = "#".repeat(n as usize), string = st) } }; self.word(st) diff --git a/src/test/ui/lint/lint-unnecessary-parens.rs b/src/test/ui/lint/lint-unnecessary-parens.rs index 12ffb6d3c6655..4e8339a8e6bf1 100644 --- a/src/test/ui/lint/lint-unnecessary-parens.rs +++ b/src/test/ui/lint/lint-unnecessary-parens.rs @@ -17,6 +17,13 @@ fn unused_parens_around_return_type() -> (u32) { //~ ERROR unnecessary parenthes panic!() } +fn unused_parens_around_block_return() -> u32 { + let foo = { + (5) //~ ERROR unnecessary parentheses around block return value + }; + (5) //~ ERROR unnecessary parentheses around block return value +} + trait Trait { fn test(&self); } diff --git a/src/test/ui/lint/lint-unnecessary-parens.stderr b/src/test/ui/lint/lint-unnecessary-parens.stderr index 541ae7aa4b54a..ea58220d20c9f 100644 --- a/src/test/ui/lint/lint-unnecessary-parens.stderr +++ b/src/test/ui/lint/lint-unnecessary-parens.stderr @@ -22,26 +22,38 @@ error: unnecessary parentheses around type LL | fn unused_parens_around_return_type() -> (u32) { | ^^^^^ help: remove these parentheses +error: unnecessary parentheses around block return value + --> $DIR/lint-unnecessary-parens.rs:22:9 + | +LL | (5) + | ^^^ help: remove these parentheses + +error: unnecessary parentheses around block return value + --> $DIR/lint-unnecessary-parens.rs:24:5 + | +LL | (5) + | ^^^ help: remove these parentheses + error: unnecessary parentheses around function argument - --> $DIR/lint-unnecessary-parens.rs:36:9 + --> $DIR/lint-unnecessary-parens.rs:43:9 | LL | bar((true)); | ^^^^^^ help: remove these parentheses error: unnecessary parentheses around `if` condition - --> $DIR/lint-unnecessary-parens.rs:38:8 + --> $DIR/lint-unnecessary-parens.rs:45:8 | LL | if (true) {} | ^^^^^^ help: remove these parentheses error: unnecessary parentheses around `while` condition - --> $DIR/lint-unnecessary-parens.rs:39:11 + --> $DIR/lint-unnecessary-parens.rs:46:11 | LL | while (true) {} | ^^^^^^ help: remove these parentheses warning: denote infinite loops with `loop { ... }` - --> $DIR/lint-unnecessary-parens.rs:39:5 + --> $DIR/lint-unnecessary-parens.rs:46:5 | LL | while (true) {} | ^^^^^^^^^^^^ help: use `loop` @@ -49,46 +61,46 @@ LL | while (true) {} = note: `#[warn(while_true)]` on by default error: unnecessary parentheses around `match` head expression - --> $DIR/lint-unnecessary-parens.rs:41:11 + --> $DIR/lint-unnecessary-parens.rs:48:11 | LL | match (true) { | ^^^^^^ help: remove these parentheses error: unnecessary parentheses around `let` head expression - --> $DIR/lint-unnecessary-parens.rs:44:16 + --> $DIR/lint-unnecessary-parens.rs:51:16 | LL | if let 1 = (1) {} | ^^^ help: remove these parentheses error: unnecessary parentheses around `let` head expression - --> $DIR/lint-unnecessary-parens.rs:45:19 + --> $DIR/lint-unnecessary-parens.rs:52:19 | LL | while let 1 = (2) {} | ^^^ help: remove these parentheses error: unnecessary parentheses around method argument - --> $DIR/lint-unnecessary-parens.rs:59:24 + --> $DIR/lint-unnecessary-parens.rs:66:24 | LL | X { y: false }.foo((true)); | ^^^^^^ help: remove these parentheses error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:61:18 + --> $DIR/lint-unnecessary-parens.rs:68:18 | LL | let mut _a = (0); | ^^^ help: remove these parentheses error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:62:10 + --> $DIR/lint-unnecessary-parens.rs:69:10 | LL | _a = (0); | ^^^ help: remove these parentheses error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:63:11 + --> $DIR/lint-unnecessary-parens.rs:70:11 | LL | _a += (1); | ^^^ help: remove these parentheses -error: aborting due to 13 previous errors +error: aborting due to 15 previous errors