Skip to content

Commit 4af6020

Browse files
authored
Unrolled build for rust-lang#124037
Rollup merge of rust-lang#124037 - compiler-errors:dont-parent-body, r=michaelwoerister Don't ascend into parent bodies when collecting stmts for possible return suggestion Fixes rust-lang#124022
2 parents 00ed4ed + 8bbaeee commit 4af6020

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -2011,12 +2011,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20112011
for (span, code) in errors_causecode {
20122012
self.dcx().try_steal_modify_and_emit_err(span, StashKey::MaybeForgetReturn, |err| {
20132013
if let Some(fn_sig) = self.body_fn_sig()
2014-
&& let ExprBindingObligation(_, _, hir_id, ..) = code
2014+
&& let ExprBindingObligation(_, _, binding_hir_id, ..) = code
20152015
&& !fn_sig.output().is_unit()
20162016
{
20172017
let mut block_num = 0;
20182018
let mut found_semi = false;
2019-
for (_, node) in self.tcx.hir().parent_iter(hir_id) {
2019+
for (hir_id, node) in self.tcx.hir().parent_iter(binding_hir_id) {
2020+
// Don't proceed into parent bodies
2021+
if hir_id.owner != binding_hir_id.owner {
2022+
break;
2023+
}
20202024
match node {
20212025
hir::Node::Stmt(stmt) => {
20222026
if let hir::StmtKind::Semi(expr) = stmt.kind {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// issue: rust-lang/rust#124022
2+
3+
struct Type<T>;
4+
//~^ ERROR type parameter `T` is never used
5+
6+
fn main() {
7+
{
8+
impl<T> Type<T> {
9+
fn new() -> Type<T> {
10+
Type
11+
//~^ ERROR type annotations needed
12+
}
13+
}
14+
};
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0392]: type parameter `T` is never used
2+
--> $DIR/dont-collect-stmts-from-parent-body.rs:3:13
3+
|
4+
LL | struct Type<T>;
5+
| ^ unused type parameter
6+
|
7+
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
8+
= help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead
9+
10+
error[E0282]: type annotations needed
11+
--> $DIR/dont-collect-stmts-from-parent-body.rs:10:17
12+
|
13+
LL | Type
14+
| ^^^^ cannot infer type of the type parameter `T` declared on the struct `Type`
15+
|
16+
help: consider specifying the generic argument
17+
|
18+
LL | Type::<T>
19+
| +++++
20+
21+
error: aborting due to 2 previous errors
22+
23+
Some errors have detailed explanations: E0282, E0392.
24+
For more information about an error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)