Skip to content
8 changes: 8 additions & 0 deletions compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
parent_id = self.tcx.parent_hir_id(*hir_id);
parent
}
hir::Node::Stmt(hir::Stmt { hir_id, kind: hir::StmtKind::Let(_), .. }) => {
parent_id = self.tcx.parent_hir_id(*hir_id);
parent
}
hir::Node::LetStmt(hir::LetStmt { hir_id, .. }) => {
parent_id = self.tcx.parent_hir_id(*hir_id);
parent
}
hir::Node::Block(_) => {
parent_id = self.tcx.parent_hir_id(parent_id);
parent
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_middle/src/query/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use rustc_query_system::query::{QueryCache, QueryMode, try_get_cached};
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};

use crate::dep_graph;
use crate::query::IntoQueryParam;
use crate::query::erase::{self, Erasable, Erased};
use crate::ty::TyCtxt;

Expand All @@ -27,7 +26,6 @@ pub(crate) fn query_get_at<'tcx, Cache>(
where
Cache: QueryCache,
{
let key = key.into_query_param();
match try_get_cached(tcx, query_cache, &key) {
Some(value) => value,
None => execute_query(tcx, span, key, QueryMode::Get).unwrap(),
Expand All @@ -46,7 +44,6 @@ pub(crate) fn query_ensure<'tcx, Cache>(
) where
Cache: QueryCache,
{
let key = key.into_query_param();
if try_get_cached(tcx, query_cache, &key).is_none() {
execute_query(tcx, DUMMY_SP, key, QueryMode::Ensure { check_cache });
}
Expand All @@ -66,7 +63,6 @@ where
Cache: QueryCache<Value = Erased<Result<T, ErrorGuaranteed>>>,
Result<T, ErrorGuaranteed>: Erasable,
{
let key = key.into_query_param();
if let Some(res) = try_get_cached(tcx, query_cache, &key) {
erase::restore_val(res).map(drop)
} else {
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_mir_transform/src/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,11 +1086,6 @@ impl<'a, 'tcx> AssignmentResult<'a, 'tcx> {

let Some((name, decl_span)) = self.checked_places.names[index] else { continue };

// By convention, underscore-prefixed bindings are explicitly allowed to be unused.
if name.as_str().starts_with('_') {
continue;
}

let is_maybe_drop_guard = maybe_drop_guard(
tcx,
self.typing_env,
Expand Down Expand Up @@ -1118,6 +1113,11 @@ impl<'a, 'tcx> AssignmentResult<'a, 'tcx> {
continue;
};

// By convention, underscore-prefixed bindings are allowed to be unused explicitly
if name.as_str().starts_with('_') {
break;
}

match kind {
AccessKind::Assign => {
let suggestion = annotate_mut_binding_to_immutable_binding(
Expand Down
1 change: 1 addition & 0 deletions tests/codegen-llvm/lib-optimizations/append-elements.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ compile-flags: -O -Zmerge-functions=disabled
//@ needs-deterministic-layouts
//@ min-llvm-version: 21
//@ ignore-std-debug-assertions (causes different value naming)
#![crate_type = "lib"]

//! Check that a temporary intermediate allocations can eliminated and replaced
Expand Down
23 changes: 23 additions & 0 deletions tests/ui/let-else/let-else-break-help-issue-142602.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// testcase from https://github.com/rust-lang/rust/issues/142602

pub fn main() {
// Case 1: break before let-else
let _a = loop {
if true {
break;
}
let Some(_) = Some(5) else {
break 3; //~ ERROR mismatched types
};
};

// Case 2: two let-else statements
let _b = loop {
let Some(_) = Some(5) else {
break;
};
let Some(_) = Some(4) else {
break 3; //~ ERROR mismatched types
};
};
}
21 changes: 21 additions & 0 deletions tests/ui/let-else/let-else-break-help-issue-142602.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0308]: mismatched types
--> $DIR/let-else-break-help-issue-142602.rs:10:19
|
LL | break;
| ----- expected because of this `break`
...
LL | break 3;
| ^ expected `()`, found integer

error[E0308]: mismatched types
--> $DIR/let-else-break-help-issue-142602.rs:20:19
|
LL | break;
| ----- expected because of this `break`
...
LL | break 3;
| ^ expected `()`, found integer

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
Loading