Rollup merge of #85393 - Aaron1011:async-type-err, r=varkor
Suppress spurious errors inside `async fn` Fixes #73741
This commit is contained in:
commit
5f544bcf70
3 changed files with 46 additions and 9 deletions
|
@ -89,19 +89,31 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
|
||||||
if let Some((unresolved_type, unresolved_type_span)) =
|
if let Some((unresolved_type, unresolved_type_span)) =
|
||||||
self.fcx.unresolved_type_vars(&ty)
|
self.fcx.unresolved_type_vars(&ty)
|
||||||
{
|
{
|
||||||
let note = format!(
|
|
||||||
"the type is part of the {} because of this {}",
|
|
||||||
self.kind, yield_data.source
|
|
||||||
);
|
|
||||||
|
|
||||||
// If unresolved type isn't a ty_var then unresolved_type_span is None
|
// If unresolved type isn't a ty_var then unresolved_type_span is None
|
||||||
let span = self
|
let span = self
|
||||||
.prev_unresolved_span
|
.prev_unresolved_span
|
||||||
.unwrap_or_else(|| unresolved_type_span.unwrap_or(source_span));
|
.unwrap_or_else(|| unresolved_type_span.unwrap_or(source_span));
|
||||||
self.fcx
|
|
||||||
.need_type_info_err_in_generator(self.kind, span, unresolved_type)
|
// If we encounter an int/float variable, then inference fallback didn't
|
||||||
.span_note(yield_data.span, &*note)
|
// finish due to some other error. Don't emit spurious additional errors.
|
||||||
.emit();
|
if let ty::Infer(ty::InferTy::IntVar(_) | ty::InferTy::FloatVar(_)) =
|
||||||
|
unresolved_type.kind()
|
||||||
|
{
|
||||||
|
self.fcx
|
||||||
|
.tcx
|
||||||
|
.sess
|
||||||
|
.delay_span_bug(span, &format!("Encountered var {:?}", unresolved_type));
|
||||||
|
} else {
|
||||||
|
let note = format!(
|
||||||
|
"the type is part of the {} because of this {}",
|
||||||
|
self.kind, yield_data.source
|
||||||
|
);
|
||||||
|
|
||||||
|
self.fcx
|
||||||
|
.need_type_info_err_in_generator(self.kind, span, unresolved_type)
|
||||||
|
.span_note(yield_data.span, &*note)
|
||||||
|
.emit();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Insert the type into the ordered set.
|
// Insert the type into the ordered set.
|
||||||
let scope_span = scope.map(|s| s.span(self.fcx.tcx, self.region_scope_tree));
|
let scope_span = scope.map(|s| s.span(self.fcx.tcx, self.region_scope_tree));
|
||||||
|
|
14
src/test/ui/async-await/issue-73741-type-err.rs
Normal file
14
src/test/ui/async-await/issue-73741-type-err.rs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
// edition:2018
|
||||||
|
//
|
||||||
|
// Regression test for issue #73741
|
||||||
|
// Ensures that we don't emit spurious errors when
|
||||||
|
// a type error ocurrs in an `async fn`
|
||||||
|
|
||||||
|
async fn weird() {
|
||||||
|
1 = 2; //~ ERROR invalid left-hand side
|
||||||
|
|
||||||
|
let mut loop_count = 0;
|
||||||
|
async {}.await
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
11
src/test/ui/async-await/issue-73741-type-err.stderr
Normal file
11
src/test/ui/async-await/issue-73741-type-err.stderr
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
error[E0070]: invalid left-hand side of assignment
|
||||||
|
--> $DIR/issue-73741-type-err.rs:8:7
|
||||||
|
|
|
||||||
|
LL | 1 = 2;
|
||||||
|
| - ^
|
||||||
|
| |
|
||||||
|
| cannot assign to this expression
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0070`.
|
Loading…
Add table
Add a link
Reference in a new issue