Skip to content

Commit 5f544bc

Browse files
Rollup merge of #85393 - Aaron1011:async-type-err, r=varkor
Suppress spurious errors inside `async fn` Fixes #73741
2 parents fad04ff + 500503b commit 5f544bc

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

compiler/rustc_typeck/src/check/generator_interior.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,31 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
8989
if let Some((unresolved_type, unresolved_type_span)) =
9090
self.fcx.unresolved_type_vars(&ty)
9191
{
92-
let note = format!(
93-
"the type is part of the {} because of this {}",
94-
self.kind, yield_data.source
95-
);
96-
9792
// If unresolved type isn't a ty_var then unresolved_type_span is None
9893
let span = self
9994
.prev_unresolved_span
10095
.unwrap_or_else(|| unresolved_type_span.unwrap_or(source_span));
101-
self.fcx
102-
.need_type_info_err_in_generator(self.kind, span, unresolved_type)
103-
.span_note(yield_data.span, &*note)
104-
.emit();
96+
97+
// If we encounter an int/float variable, then inference fallback didn't
98+
// finish due to some other error. Don't emit spurious additional errors.
99+
if let ty::Infer(ty::InferTy::IntVar(_) | ty::InferTy::FloatVar(_)) =
100+
unresolved_type.kind()
101+
{
102+
self.fcx
103+
.tcx
104+
.sess
105+
.delay_span_bug(span, &format!("Encountered var {:?}", unresolved_type));
106+
} else {
107+
let note = format!(
108+
"the type is part of the {} because of this {}",
109+
self.kind, yield_data.source
110+
);
111+
112+
self.fcx
113+
.need_type_info_err_in_generator(self.kind, span, unresolved_type)
114+
.span_note(yield_data.span, &*note)
115+
.emit();
116+
}
105117
} else {
106118
// Insert the type into the ordered set.
107119
let scope_span = scope.map(|s| s.span(self.fcx.tcx, self.region_scope_tree));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// edition:2018
2+
//
3+
// Regression test for issue #73741
4+
// Ensures that we don't emit spurious errors when
5+
// a type error ocurrs in an `async fn`
6+
7+
async fn weird() {
8+
1 = 2; //~ ERROR invalid left-hand side
9+
10+
let mut loop_count = 0;
11+
async {}.await
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0070]: invalid left-hand side of assignment
2+
--> $DIR/issue-73741-type-err.rs:8:7
3+
|
4+
LL | 1 = 2;
5+
| - ^
6+
| |
7+
| cannot assign to this expression
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0070`.

0 commit comments

Comments
 (0)