From d47673d3d7351c16aa8528edabfc886d2228fbb0 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 21 Jan 2020 17:37:11 +0100 Subject: [PATCH 1/5] 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 f7df630fb90b1..7c0500c1c7425 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -4418,10 +4418,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) => { @@ -4431,7 +4429,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 1240a3180d474f064791686602e324fe683a0645 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 21 Jan 2020 18:24:25 +0100 Subject: [PATCH 2/5] 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 7dceff9b5b2e41855ff3ba2fab3a2ae41e965df5 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 21 Jan 2020 18:47:58 +0100 Subject: [PATCH 3/5] 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 d45d8b1c7b6b725ab9d4f1d987a45a76c7510a47 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 21 Jan 2020 09:55:43 -0800 Subject: [PATCH 4/5] 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 48bc269ebb654..741f2c532cd20 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 c7b23e275284cf88fd71df57b4fc203979299d97 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Wed, 22 Jan 2020 08:53:31 +0900 Subject: [PATCH 5/5] 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