Skip to content

Commit 5ad8b9e

Browse files
committed
update async-await send/sync test
1 parent b975601 commit 5ad8b9e

File tree

5 files changed

+32
-28
lines changed

5 files changed

+32
-28
lines changed

src/librustc/traits/error_reporting.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -2456,7 +2456,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
24562456
let target_span = tables
24572457
.generator_interior_types
24582458
.iter()
2459-
.zip(tables.generator_interior_exprs.iter())
24602459
.find(|(ty::GeneratorInteriorTypeCause { ty, .. }, _)| {
24612460
// Careful: the regions for types that appear in the
24622461
// generator interior are not generally known, so we
@@ -2578,37 +2577,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
25782577
};
25792578

25802579
span.push_span_label(original_span, message);
2581-
err.set_span(span.clone());
2580+
err.set_span(span);
25822581

25832582
format!("is not {}", trait_name)
25842583
} else {
25852584
format!("does not implement `{}`", trait_ref.print_only_trait_path())
25862585
};
25872586

25882587
// Look at the last interior type to get a span for the `.await`.
2589-
let await_span = tables.generator_interior_types.iter().map(|i| i.span).last().unwrap();
2588+
let await_span =
2589+
tables.generator_interior_types.iter().map(|(i, _)| i.span).last().unwrap();
25902590
let mut span = MultiSpan::from_span(await_span);
25912591
span.push_span_label(
25922592
await_span,
25932593
format!("{} occurs here, with `{}` maybe used later", await_or_yield, snippet),
25942594
);
25952595

2596-
if let Some(expr_id) = expr {
2597-
let expr = hir.expect_expr(expr_id);
2598-
let is_ref = tables.expr_adjustments(expr).iter().any(|adj| adj.is_region_borrow());
2599-
let parent = hir.get_parent_node(expr_id);
2600-
if let Some(hir::Node::Expr(e)) = hir.find(parent) {
2601-
let method_span = hir.span(parent);
2602-
if tables.is_method_call(e) && is_ref {
2603-
err.span_help(
2604-
method_span,
2605-
"consider moving this method call into a `let` \
2606-
binding to create a shorter lived borrow"
2607-
);
2608-
}
2609-
}
2610-
}
2611-
26122596
span.push_span_label(target_span, format!("has type `{}`", target_ty));
26132597

26142598
// If available, use the scope span to annotate the drop location.
@@ -2627,6 +2611,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
26272611
),
26282612
);
26292613

2614+
if let Some(expr_id) = expr {
2615+
let expr = hir.expect_expr(expr_id);
2616+
let is_ref = tables.expr_adjustments(expr).iter().any(|adj| adj.is_region_borrow());
2617+
let parent = hir.get_parent_node(expr_id);
2618+
if let Some(hir::Node::Expr(e)) = hir.find(parent) {
2619+
let method_span = hir.span(parent);
2620+
if tables.is_method_call(e) && is_ref {
2621+
err.span_help(
2622+
method_span,
2623+
"consider moving this method call into a `let` \
2624+
binding to create a shorter lived borrow",
2625+
);
2626+
}
2627+
}
2628+
}
2629+
26302630
// Add a note for the item obligation that remains - normally a note pointing to the
26312631
// bound that introduced the obligation (e.g. `T: Send`).
26322632
debug!("note_obligation_cause_for_async_await: next_code={:?}", next_code);

src/librustc/ty/adjustment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl Adjustment<'tcx> {
8585
pub fn is_region_borrow(&self) -> bool {
8686
match self.kind {
8787
Adjust::Borrow(AutoBorrow::Ref(..)) => true,
88-
_ => false
88+
_ => false,
8989
}
9090
}
9191
}

src/librustc/ty/context.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,9 @@ pub struct TypeckTables<'tcx> {
436436
/// entire variable.
437437
pub upvar_list: ty::UpvarListMap,
438438

439-
/// Stores the type, span and optional scope span of all types
439+
/// Stores the type, expression, span and optional scope span of all types
440440
/// that are live across the yield of this generator (if a generator).
441-
pub generator_interior_types: Vec<GeneratorInteriorTypeCause<'tcx>>,
442-
443-
pub generator_interior_exprs: Vec<Option<hir::HirId>>,
441+
pub generator_interior_types: Vec<(GeneratorInteriorTypeCause<'tcx>, Option<hir::HirId>)>,
444442
}
445443

446444
impl<'tcx> TypeckTables<'tcx> {
@@ -467,7 +465,6 @@ impl<'tcx> TypeckTables<'tcx> {
467465
concrete_opaque_types: Default::default(),
468466
upvar_list: Default::default(),
469467
generator_interior_types: Default::default(),
470-
generator_interior_exprs: Default::default(),
471468
}
472469
}
473470

@@ -731,7 +728,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckTables<'tcx> {
731728
ref concrete_opaque_types,
732729
ref upvar_list,
733730
ref generator_interior_types,
734-
ref generator_interior_exprs,
735731
} = *self;
736732

737733
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
@@ -770,7 +766,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckTables<'tcx> {
770766
concrete_opaque_types.hash_stable(hcx, hasher);
771767
upvar_list.hash_stable(hcx, hasher);
772768
generator_interior_types.hash_stable(hcx, hasher);
773-
generator_interior_exprs.hash_stable(hcx, hasher);
774769
})
775770
}
776771
}

src/librustc_typeck/check/generator_interior.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use rustc_span::Span;
1818
struct InteriorVisitor<'a, 'tcx> {
1919
fcx: &'a FnCtxt<'a, 'tcx>,
2020
types: FxHashMap<ty::GeneratorInteriorTypeCause<'tcx>, usize>,
21+
exprs: Vec<Option<hir::HirId>>,
2122
region_scope_tree: &'tcx region::ScopeTree,
2223
expr_count: usize,
2324
kind: hir::GeneratorKind,
@@ -99,6 +100,7 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
99100
scope_span,
100101
})
101102
.or_insert(entries);
103+
self.exprs.push(expr.map(|e| e.hir_id));
102104
}
103105
} else {
104106
debug!(
@@ -136,6 +138,7 @@ pub fn resolve_interior<'a, 'tcx>(
136138
expr_count: 0,
137139
kind,
138140
prev_unresolved_span: None,
141+
exprs: vec![],
139142
};
140143
intravisit::walk_body(&mut visitor, body);
141144

@@ -170,7 +173,8 @@ pub fn resolve_interior<'a, 'tcx>(
170173
});
171174

172175
// Store the generator types and spans into the tables for this generator.
173-
let interior_types = types.iter().map(|t| t.0.clone()).collect::<Vec<_>>();
176+
let interior_types =
177+
types.iter().zip(visitor.exprs).map(|(t, e)| (t.0.clone(), e)).collect::<Vec<_>>();
174178
visitor.fcx.inh.tables.borrow_mut().generator_interior_types = interior_types;
175179

176180
// Extract type components

src/test/ui/async-await/issue-64130-4-async-move.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ LL | let _x = get().await;
1616
...
1717
LL | }
1818
| - `client` is later dropped here
19+
help: consider moving this method call into a `let` binding to create a shorter lived borrow
20+
--> $DIR/issue-64130-4-async-move.rs:19:15
21+
|
22+
LL | match client.status() {
23+
| ^^^^^^^^^^^^^^^
1924
= note: the return type of a function must have a statically known size
2025

2126
error: aborting due to previous error

0 commit comments

Comments
 (0)