From d8047f83a95c42cfab19e3b89d24992b1722eb5c Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Mon, 2 Mar 2020 10:43:03 -0800 Subject: [PATCH 1/7] Use `is_const_fn_raw` query for HIR const-checking --- src/librustc_passes/check_const.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/librustc_passes/check_const.rs b/src/librustc_passes/check_const.rs index f68213cc9c230..f409b040c69d4 100644 --- a/src/librustc_passes/check_const.rs +++ b/src/librustc_passes/check_const.rs @@ -74,16 +74,16 @@ enum ConstKind { } impl ConstKind { - fn for_body(body: &hir::Body<'_>, hir_map: Map<'_>) -> Option { - let is_const_fn = |id| hir_map.fn_sig_by_hir_id(id).unwrap().header.is_const(); - - let owner = hir_map.body_owner(body.id()); - let const_kind = match hir_map.body_owner_kind(owner) { + fn for_body(body: &hir::Body<'_>, tcx: TyCtxt<'_>) -> Option { + let owner = tcx.hir().body_owner(body.id()); + let const_kind = match tcx.hir().body_owner_kind(owner) { hir::BodyOwnerKind::Const => Self::Const, hir::BodyOwnerKind::Static(Mutability::Mut) => Self::StaticMut, hir::BodyOwnerKind::Static(Mutability::Not) => Self::Static, - hir::BodyOwnerKind::Fn if is_const_fn(owner) => Self::ConstFn, + hir::BodyOwnerKind::Fn if tcx.is_const_fn_raw(tcx.hir().local_def_id(owner)) => { + Self::ConstFn + } hir::BodyOwnerKind::Fn | hir::BodyOwnerKind::Closure => return None, }; @@ -211,7 +211,7 @@ impl<'tcx> Visitor<'tcx> for CheckConstVisitor<'tcx> { } fn visit_body(&mut self, body: &'tcx hir::Body<'tcx>) { - let kind = ConstKind::for_body(body, self.tcx.hir()); + let kind = ConstKind::for_body(body, self.tcx); self.recurse_into(kind, |this| intravisit::walk_body(this, body)); } From e8b270a4b6d711b7dcd99b474b0866e6e3531c93 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Mon, 2 Mar 2020 10:53:58 -0800 Subject: [PATCH 2/7] Add regression test for #69615 --- .../rfc-2632-const-trait-impl/hir-const-check.rs | 16 ++++++++++++++++ .../hir-const-check.stderr | 12 ++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs create mode 100644 src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr diff --git a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs new file mode 100644 index 0000000000000..f7af1b506f0db --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.rs @@ -0,0 +1,16 @@ +// Regression test for #69615. + +#![feature(const_trait_impl, const_fn)] +#![allow(incomplete_features)] + +pub trait MyTrait { + fn method(&self); +} + +impl const MyTrait for () { + fn method(&self) { + match *self {} //~ ERROR `match` is not allowed in a `const fn` + } +} + +fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr new file mode 100644 index 0000000000000..563a9afe5bb84 --- /dev/null +++ b/src/test/ui/rfc-2632-const-trait-impl/hir-const-check.stderr @@ -0,0 +1,12 @@ +error[E0658]: `match` is not allowed in a `const fn` + --> $DIR/hir-const-check.rs:12:9 + | +LL | match *self {} + | ^^^^^^^^^^^^^^ + | + = note: see issue #49146 for more information + = help: add `#![feature(const_if_match)]` to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. From eb74096a32702e45bb9cd8d1c2c787c2067272d8 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Thu, 9 Apr 2020 14:56:19 -0700 Subject: [PATCH 3/7] Avoid calling `fn_sig` query during `is_const_fn_raw` --- src/librustc_mir/const_eval/fn_queries.rs | 27 +++++++++-------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/librustc_mir/const_eval/fn_queries.rs b/src/librustc_mir/const_eval/fn_queries.rs index 8ae4f9f4a0d6e..bf438ead84079 100644 --- a/src/librustc_mir/const_eval/fn_queries.rs +++ b/src/librustc_mir/const_eval/fn_queries.rs @@ -99,8 +99,16 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool { let node = tcx.hir().get(hir_id); - if let Some(whitelisted) = is_const_intrinsic(tcx, def_id) { - whitelisted + if let hir::Node::ForeignItem(hir::ForeignItem { kind: hir::ForeignItemKind::Fn(..), .. }) = + node + { + // Intrinsics use `rustc_const_{un,}stable` attributes to indicate constness. All other + // foreign items cannot be evaluated at compile-time. + if let Abi::RustIntrinsic | Abi::PlatformIntrinsic = tcx.hir().get_foreign_abi(hir_id) { + tcx.lookup_const_stability(def_id).is_some() + } else { + false + } } else if let Some(fn_like) = FnLikeNode::from_node(node) { if fn_like.constness() == hir::Constness::Const { return true; @@ -116,21 +124,6 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool { } } -/// Const evaluability whitelist is here to check evaluability at the -/// top level beforehand. -fn is_const_intrinsic(tcx: TyCtxt<'_>, def_id: DefId) -> Option { - if tcx.is_closure(def_id) { - return None; - } - - match tcx.fn_sig(def_id).abi() { - Abi::RustIntrinsic | Abi::PlatformIntrinsic => { - Some(tcx.lookup_const_stability(def_id).is_some()) - } - _ => None, - } -} - /// Checks whether the given item is an `impl` that has a `const` modifier. fn is_const_impl_raw(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); From af442d964de8cb9814f0e2374db34e87fb21ca73 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Fri, 17 Apr 2020 18:36:16 +0900 Subject: [PATCH 4/7] Rename `asm` test directory in favor of `llvm_asm` --- src/test/ui/{asm => llvm-asm}/issue-51431.rs | 0 .../ui/{asm => llvm-asm}/issue-51431.stderr | 0 src/test/ui/{asm => llvm-asm}/issue-54067.rs | 0 src/test/ui/{asm => llvm-asm}/issue-62046.rs | 0 .../ui/{asm => llvm-asm}/issue-62046.stderr | 0 src/test/ui/{asm => llvm-asm}/issue-69092.rs | 0 .../ui/{asm => llvm-asm}/issue-69092.stderr | 0 .../llvm-asm-bad-clobber.rs} | 0 .../llvm-asm-bad-clobber.stderr} | 2 +- .../llvm-asm-in-bad-modifier.rs} | 0 .../llvm-asm-in-bad-modifier.stderr} | 4 ++-- .../llvm-asm-literal-escaping.rs} | 0 .../llvm-asm-misplaced-option.rs} | 0 .../llvm-asm-misplaced-option.stderr} | 4 ++-- .../llvm-asm-out-assign-imm.rs} | 0 .../llvm-asm-out-assign-imm.stderr} | 2 +- .../llvm-asm-out-no-modifier.rs} | 0 .../llvm-asm-out-no-modifier.stderr} | 2 +- .../llvm-asm-out-read-uninit.rs} | 0 .../llvm-asm-out-read-uninit.stderr} | 2 +- .../llvm-asm-parse-errors.rs} | 0 .../llvm-asm-parse-errors.stderr} | 22 +++++++++---------- 22 files changed, 19 insertions(+), 19 deletions(-) rename src/test/ui/{asm => llvm-asm}/issue-51431.rs (100%) rename src/test/ui/{asm => llvm-asm}/issue-51431.stderr (100%) rename src/test/ui/{asm => llvm-asm}/issue-54067.rs (100%) rename src/test/ui/{asm => llvm-asm}/issue-62046.rs (100%) rename src/test/ui/{asm => llvm-asm}/issue-62046.stderr (100%) rename src/test/ui/{asm => llvm-asm}/issue-69092.rs (100%) rename src/test/ui/{asm => llvm-asm}/issue-69092.stderr (100%) rename src/test/ui/{asm/asm-bad-clobber.rs => llvm-asm/llvm-asm-bad-clobber.rs} (100%) rename src/test/ui/{asm/asm-bad-clobber.stderr => llvm-asm/llvm-asm-bad-clobber.stderr} (87%) rename src/test/ui/{asm/asm-in-bad-modifier.rs => llvm-asm/llvm-asm-in-bad-modifier.rs} (100%) rename src/test/ui/{asm/asm-in-bad-modifier.stderr => llvm-asm/llvm-asm-in-bad-modifier.stderr} (84%) rename src/test/ui/{asm/asm-literal-escaping.rs => llvm-asm/llvm-asm-literal-escaping.rs} (100%) rename src/test/ui/{asm/asm-misplaced-option.rs => llvm-asm/llvm-asm-misplaced-option.rs} (100%) rename src/test/ui/{asm/asm-misplaced-option.stderr => llvm-asm/llvm-asm-misplaced-option.stderr} (83%) rename src/test/ui/{asm/asm-out-assign-imm.rs => llvm-asm/llvm-asm-out-assign-imm.rs} (100%) rename src/test/ui/{asm/asm-out-assign-imm.stderr => llvm-asm/llvm-asm-out-assign-imm.stderr} (91%) rename src/test/ui/{asm/asm-out-no-modifier.rs => llvm-asm/llvm-asm-out-no-modifier.rs} (100%) rename src/test/ui/{asm/asm-out-no-modifier.stderr => llvm-asm/llvm-asm-out-no-modifier.stderr} (85%) rename src/test/ui/{asm/asm-out-read-uninit.rs => llvm-asm/llvm-asm-out-read-uninit.rs} (100%) rename src/test/ui/{asm/asm-out-read-uninit.stderr => llvm-asm/llvm-asm-out-read-uninit.stderr} (87%) rename src/test/ui/{asm/asm-parse-errors.rs => llvm-asm/llvm-asm-parse-errors.rs} (100%) rename src/test/ui/{asm/asm-parse-errors.stderr => llvm-asm/llvm-asm-parse-errors.stderr} (80%) diff --git a/src/test/ui/asm/issue-51431.rs b/src/test/ui/llvm-asm/issue-51431.rs similarity index 100% rename from src/test/ui/asm/issue-51431.rs rename to src/test/ui/llvm-asm/issue-51431.rs diff --git a/src/test/ui/asm/issue-51431.stderr b/src/test/ui/llvm-asm/issue-51431.stderr similarity index 100% rename from src/test/ui/asm/issue-51431.stderr rename to src/test/ui/llvm-asm/issue-51431.stderr diff --git a/src/test/ui/asm/issue-54067.rs b/src/test/ui/llvm-asm/issue-54067.rs similarity index 100% rename from src/test/ui/asm/issue-54067.rs rename to src/test/ui/llvm-asm/issue-54067.rs diff --git a/src/test/ui/asm/issue-62046.rs b/src/test/ui/llvm-asm/issue-62046.rs similarity index 100% rename from src/test/ui/asm/issue-62046.rs rename to src/test/ui/llvm-asm/issue-62046.rs diff --git a/src/test/ui/asm/issue-62046.stderr b/src/test/ui/llvm-asm/issue-62046.stderr similarity index 100% rename from src/test/ui/asm/issue-62046.stderr rename to src/test/ui/llvm-asm/issue-62046.stderr diff --git a/src/test/ui/asm/issue-69092.rs b/src/test/ui/llvm-asm/issue-69092.rs similarity index 100% rename from src/test/ui/asm/issue-69092.rs rename to src/test/ui/llvm-asm/issue-69092.rs diff --git a/src/test/ui/asm/issue-69092.stderr b/src/test/ui/llvm-asm/issue-69092.stderr similarity index 100% rename from src/test/ui/asm/issue-69092.stderr rename to src/test/ui/llvm-asm/issue-69092.stderr diff --git a/src/test/ui/asm/asm-bad-clobber.rs b/src/test/ui/llvm-asm/llvm-asm-bad-clobber.rs similarity index 100% rename from src/test/ui/asm/asm-bad-clobber.rs rename to src/test/ui/llvm-asm/llvm-asm-bad-clobber.rs diff --git a/src/test/ui/asm/asm-bad-clobber.stderr b/src/test/ui/llvm-asm/llvm-asm-bad-clobber.stderr similarity index 87% rename from src/test/ui/asm/asm-bad-clobber.stderr rename to src/test/ui/llvm-asm/llvm-asm-bad-clobber.stderr index 8c5d04694c497..9ecd12caa0e2a 100644 --- a/src/test/ui/asm/asm-bad-clobber.stderr +++ b/src/test/ui/llvm-asm/llvm-asm-bad-clobber.stderr @@ -1,5 +1,5 @@ error[E0664]: clobber should not be surrounded by braces - --> $DIR/asm-bad-clobber.rs:22:42 + --> $DIR/llvm-asm-bad-clobber.rs:22:42 | LL | llvm_asm!("xor %eax, %eax" : : : "{eax}"); | ^^^^^^^ diff --git a/src/test/ui/asm/asm-in-bad-modifier.rs b/src/test/ui/llvm-asm/llvm-asm-in-bad-modifier.rs similarity index 100% rename from src/test/ui/asm/asm-in-bad-modifier.rs rename to src/test/ui/llvm-asm/llvm-asm-in-bad-modifier.rs diff --git a/src/test/ui/asm/asm-in-bad-modifier.stderr b/src/test/ui/llvm-asm/llvm-asm-in-bad-modifier.stderr similarity index 84% rename from src/test/ui/asm/asm-in-bad-modifier.stderr rename to src/test/ui/llvm-asm/llvm-asm-in-bad-modifier.stderr index f1624f74a70ac..e94ac94f59f9a 100644 --- a/src/test/ui/asm/asm-in-bad-modifier.stderr +++ b/src/test/ui/llvm-asm/llvm-asm-in-bad-modifier.stderr @@ -1,11 +1,11 @@ error[E0662]: input operand constraint contains '=' - --> $DIR/asm-in-bad-modifier.rs:23:44 + --> $DIR/llvm-asm-in-bad-modifier.rs:23:44 | LL | llvm_asm!("mov $1, $0" : "=r"(x) : "=r"(5)); | ^^^^ error[E0663]: input operand constraint contains '+' - --> $DIR/asm-in-bad-modifier.rs:24:44 + --> $DIR/llvm-asm-in-bad-modifier.rs:24:44 | LL | llvm_asm!("mov $1, $0" : "=r"(y) : "+r"(5)); | ^^^^ diff --git a/src/test/ui/asm/asm-literal-escaping.rs b/src/test/ui/llvm-asm/llvm-asm-literal-escaping.rs similarity index 100% rename from src/test/ui/asm/asm-literal-escaping.rs rename to src/test/ui/llvm-asm/llvm-asm-literal-escaping.rs diff --git a/src/test/ui/asm/asm-misplaced-option.rs b/src/test/ui/llvm-asm/llvm-asm-misplaced-option.rs similarity index 100% rename from src/test/ui/asm/asm-misplaced-option.rs rename to src/test/ui/llvm-asm/llvm-asm-misplaced-option.rs diff --git a/src/test/ui/asm/asm-misplaced-option.stderr b/src/test/ui/llvm-asm/llvm-asm-misplaced-option.stderr similarity index 83% rename from src/test/ui/asm/asm-misplaced-option.stderr rename to src/test/ui/llvm-asm/llvm-asm-misplaced-option.stderr index ea155b91c5d61..21fd27825a185 100644 --- a/src/test/ui/asm/asm-misplaced-option.stderr +++ b/src/test/ui/llvm-asm/llvm-asm-misplaced-option.stderr @@ -1,11 +1,11 @@ warning: unrecognized option - --> $DIR/asm-misplaced-option.rs:24:69 + --> $DIR/llvm-asm-misplaced-option.rs:24:69 | LL | llvm_asm!("mov $1, $0" : "=r"(x) : "r"(5_usize), "0"(x) : : "cc"); | ^^^^ warning: expected a clobber, found an option - --> $DIR/asm-misplaced-option.rs:31:85 + --> $DIR/llvm-asm-misplaced-option.rs:31:85 | LL | llvm_asm!("add $2, $1; mov $1, $0" : "=r"(x) : "r"(x), "r"(8_usize) : "cc", "volatile"); | ^^^^^^^^^^ diff --git a/src/test/ui/asm/asm-out-assign-imm.rs b/src/test/ui/llvm-asm/llvm-asm-out-assign-imm.rs similarity index 100% rename from src/test/ui/asm/asm-out-assign-imm.rs rename to src/test/ui/llvm-asm/llvm-asm-out-assign-imm.rs diff --git a/src/test/ui/asm/asm-out-assign-imm.stderr b/src/test/ui/llvm-asm/llvm-asm-out-assign-imm.stderr similarity index 91% rename from src/test/ui/asm/asm-out-assign-imm.stderr rename to src/test/ui/llvm-asm/llvm-asm-out-assign-imm.stderr index feec61b4fc6ef..e110aec220936 100644 --- a/src/test/ui/asm/asm-out-assign-imm.stderr +++ b/src/test/ui/llvm-asm/llvm-asm-out-assign-imm.stderr @@ -1,5 +1,5 @@ error[E0384]: cannot assign twice to immutable variable `x` - --> $DIR/asm-out-assign-imm.rs:24:39 + --> $DIR/llvm-asm-out-assign-imm.rs:24:39 | LL | let x: isize; | - help: make this binding mutable: `mut x` diff --git a/src/test/ui/asm/asm-out-no-modifier.rs b/src/test/ui/llvm-asm/llvm-asm-out-no-modifier.rs similarity index 100% rename from src/test/ui/asm/asm-out-no-modifier.rs rename to src/test/ui/llvm-asm/llvm-asm-out-no-modifier.rs diff --git a/src/test/ui/asm/asm-out-no-modifier.stderr b/src/test/ui/llvm-asm/llvm-asm-out-no-modifier.stderr similarity index 85% rename from src/test/ui/asm/asm-out-no-modifier.stderr rename to src/test/ui/llvm-asm/llvm-asm-out-no-modifier.stderr index 1c9e108f910c6..1f2b272792435 100644 --- a/src/test/ui/asm/asm-out-no-modifier.stderr +++ b/src/test/ui/llvm-asm/llvm-asm-out-no-modifier.stderr @@ -1,5 +1,5 @@ error[E0661]: output operand constraint lacks '=' or '+' - --> $DIR/asm-out-no-modifier.rs:22:34 + --> $DIR/llvm-asm-out-no-modifier.rs:22:34 | LL | llvm_asm!("mov $1, $0" : "r"(x) : "r"(5)); | ^^^ diff --git a/src/test/ui/asm/asm-out-read-uninit.rs b/src/test/ui/llvm-asm/llvm-asm-out-read-uninit.rs similarity index 100% rename from src/test/ui/asm/asm-out-read-uninit.rs rename to src/test/ui/llvm-asm/llvm-asm-out-read-uninit.rs diff --git a/src/test/ui/asm/asm-out-read-uninit.stderr b/src/test/ui/llvm-asm/llvm-asm-out-read-uninit.stderr similarity index 87% rename from src/test/ui/asm/asm-out-read-uninit.stderr rename to src/test/ui/llvm-asm/llvm-asm-out-read-uninit.stderr index 3c3f3a6febb5a..a22ebe4e4d9db 100644 --- a/src/test/ui/asm/asm-out-read-uninit.stderr +++ b/src/test/ui/llvm-asm/llvm-asm-out-read-uninit.stderr @@ -1,5 +1,5 @@ error[E0381]: use of possibly-uninitialized variable: `x` - --> $DIR/asm-out-read-uninit.rs:22:48 + --> $DIR/llvm-asm-out-read-uninit.rs:22:48 | LL | llvm_asm!("mov $1, $0" : "=r"(x) : "r"(x)); | ^ use of possibly-uninitialized `x` diff --git a/src/test/ui/asm/asm-parse-errors.rs b/src/test/ui/llvm-asm/llvm-asm-parse-errors.rs similarity index 100% rename from src/test/ui/asm/asm-parse-errors.rs rename to src/test/ui/llvm-asm/llvm-asm-parse-errors.rs diff --git a/src/test/ui/asm/asm-parse-errors.stderr b/src/test/ui/llvm-asm/llvm-asm-parse-errors.stderr similarity index 80% rename from src/test/ui/asm/asm-parse-errors.stderr rename to src/test/ui/llvm-asm/llvm-asm-parse-errors.stderr index 64f295c3b3698..1fd46809f3eed 100644 --- a/src/test/ui/asm/asm-parse-errors.stderr +++ b/src/test/ui/llvm-asm/llvm-asm-parse-errors.stderr @@ -1,65 +1,65 @@ error: macro requires a string literal as an argument - --> $DIR/asm-parse-errors.rs:4:5 + --> $DIR/llvm-asm-parse-errors.rs:4:5 | LL | llvm_asm!(); | ^^^^^^^^^^^^ string literal required error: expected string literal - --> $DIR/asm-parse-errors.rs:5:23 + --> $DIR/llvm-asm-parse-errors.rs:5:23 | LL | llvm_asm!("nop" : struct); | ^^^^^^ not a string literal error: expected string literal - --> $DIR/asm-parse-errors.rs:6:35 + --> $DIR/llvm-asm-parse-errors.rs:6:35 | LL | llvm_asm!("mov %eax, $$0x2" : struct); | ^^^^^^ not a string literal error: expected `(`, found keyword `struct` - --> $DIR/asm-parse-errors.rs:7:44 + --> $DIR/llvm-asm-parse-errors.rs:7:44 | LL | llvm_asm!("mov %eax, $$0x2" : "={eax}" struct); | ^^^^^^ expected `(` error: expected expression, found keyword `struct` - --> $DIR/asm-parse-errors.rs:8:44 + --> $DIR/llvm-asm-parse-errors.rs:8:44 | LL | llvm_asm!("mov %eax, $$0x2" : "={eax}"(struct)); | ^^^^^^ expected expression error: expected string literal - --> $DIR/asm-parse-errors.rs:9:49 + --> $DIR/llvm-asm-parse-errors.rs:9:49 | LL | llvm_asm!("in %dx, %al" : "={al}"(result) : struct); | ^^^^^^ not a string literal error: expected `(`, found keyword `struct` - --> $DIR/asm-parse-errors.rs:10:56 + --> $DIR/llvm-asm-parse-errors.rs:10:56 | LL | llvm_asm!("in %dx, %al" : "={al}"(result) : "{dx}" struct); | ^^^^^^ expected `(` error: expected expression, found keyword `struct` - --> $DIR/asm-parse-errors.rs:11:56 + --> $DIR/llvm-asm-parse-errors.rs:11:56 | LL | llvm_asm!("in %dx, %al" : "={al}"(result) : "{dx}"(struct)); | ^^^^^^ expected expression error: expected string literal - --> $DIR/asm-parse-errors.rs:12:41 + --> $DIR/llvm-asm-parse-errors.rs:12:41 | LL | llvm_asm!("mov $$0x200, %eax" : : : struct); | ^^^^^^ not a string literal error: expected string literal - --> $DIR/asm-parse-errors.rs:13:50 + --> $DIR/llvm-asm-parse-errors.rs:13:50 | LL | llvm_asm!("mov eax, 2" : "={eax}"(foo) : : : struct); | ^^^^^^ not a string literal error: inline assembly must be a string literal - --> $DIR/asm-parse-errors.rs:14:15 + --> $DIR/llvm-asm-parse-errors.rs:14:15 | LL | llvm_asm!(123); | ^^^ From be6716f7f9b26bab52bb1879b273df515fe181e9 Mon Sep 17 00:00:00 2001 From: Donough Liu Date: Sat, 11 Apr 2020 15:53:10 +0800 Subject: [PATCH 5/7] Remove unnecessary variable intialization --- src/librustc_typeck/check/expr.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 7cb51b4d6d833..dbda735aa99c8 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -975,18 +975,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected: Expectation<'tcx>, expr: &'tcx hir::Expr<'tcx>, ) -> Ty<'tcx> { - let uty = expected.to_option(self).and_then(|uty| match uty.kind { - ty::Array(ty, _) | ty::Slice(ty) => Some(ty), - _ => None, - }); - let element_ty = if !args.is_empty() { - let coerce_to = uty.unwrap_or_else(|| { - self.next_ty_var(TypeVariableOrigin { - kind: TypeVariableOriginKind::TypeInference, - span: expr.span, + let coerce_to = expected + .to_option(self) + .and_then(|uty| match uty.kind { + ty::Array(ty, _) | ty::Slice(ty) => Some(ty), + _ => None, }) - }); + .unwrap_or_else(|| { + self.next_ty_var(TypeVariableOrigin { + kind: TypeVariableOriginKind::TypeInference, + span: expr.span, + }) + }); let mut coerce = CoerceMany::with_coercion_sites(coerce_to, args); assert_eq!(self.diverges.get(), Diverges::Maybe); for e in args { From 22e51cd78a81b5dc9be915f975c6c05721fe5797 Mon Sep 17 00:00:00 2001 From: Charles Lew Date: Fri, 17 Apr 2020 21:10:48 +0800 Subject: [PATCH 6/7] Implement `Clone` for `liballoc::collections::linked_list::Cursor`. --- src/liballoc/collections/linked_list.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/liballoc/collections/linked_list.rs b/src/liballoc/collections/linked_list.rs index 53d4f7239b76e..243ebb453d3ea 100644 --- a/src/liballoc/collections/linked_list.rs +++ b/src/liballoc/collections/linked_list.rs @@ -1197,6 +1197,14 @@ pub struct Cursor<'a, T: 'a> { list: &'a LinkedList, } +#[unstable(feature = "linked_list_cursors", issue = "58533")] +impl Clone for Cursor<'_, T> { + fn clone(&self) -> Self { + let Cursor { index, current, list } = *self; + Cursor { index, current, list } + } +} + #[unstable(feature = "linked_list_cursors", issue = "58533")] impl fmt::Debug for Cursor<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { From 5847c581d19526adca6db7a56c54eb0397a07370 Mon Sep 17 00:00:00 2001 From: JOE1994 Date: Fri, 17 Apr 2020 13:24:33 -0400 Subject: [PATCH 7/7] Minor fix and addition to doc comments 1. Fixed doc comment of struct 'rustc_middle::mir::Location' Currently, the general explanation of the struct appears at the field explanation section. I moved and changed the doc comments slightly, so that the general explanation would appear in the proper location in docs. 2. Added doc comment explaining 'rustc_mir::util::pretty::write_mir_fn' Unlike other counterparts, brief explanation for this function was missing, so I added one. Thank you for reviewing this PR :) --- src/librustc_middle/mir/mod.rs | 6 +++--- src/librustc_mir/util/pretty.rs | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/librustc_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index 212061cfd824f..4063d290993a1 100644 --- a/src/librustc_middle/mir/mod.rs +++ b/src/librustc_middle/mir/mod.rs @@ -2611,14 +2611,14 @@ impl<'a, 'b> graph::GraphSuccessors<'b> for Body<'a> { type Iter = iter::Cloned>; } +/// `Location` represents the position of the start of the statement; or, if +/// `statement_index` equals the number of statements, then the start of the +/// terminator. #[derive(Copy, Clone, PartialEq, Eq, Hash, Ord, PartialOrd, HashStable)] pub struct Location { /// The block that the location is within. pub block: BasicBlock, - /// The location is the position of the start of the statement; or, if - /// `statement_index` equals the number of statements, then the start of the - /// terminator. pub statement_index: usize, } diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index 64221c41bffe4..efb84ef35f35d 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -254,6 +254,7 @@ pub fn write_mir_pretty<'tcx>( Ok(()) } +/// Write out a human-readable textual representation for the given function. pub fn write_mir_fn<'tcx, F>( tcx: TyCtxt<'tcx>, src: MirSource<'tcx>,