Skip to content

Commit 08e0266

Browse files
committed
deduplication
1 parent f1021bf commit 08e0266

File tree

7 files changed

+62
-71
lines changed

7 files changed

+62
-71
lines changed

compiler/rustc_typeck/src/check/generator_interior.rs

+17-12
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct InteriorVisitor<'a, 'tcx> {
3333
/// that they may succeed the said yield point in the post-order.
3434
guard_bindings: SmallVec<[SmallVec<[HirId; 4]>; 1]>,
3535
guard_bindings_set: HirIdSet,
36+
linted_values: HirIdSet,
3637
}
3738

3839
impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
@@ -122,18 +123,21 @@ impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
122123
// Insert the type into the ordered set.
123124
let scope_span = scope.map(|s| s.span(self.fcx.tcx, self.region_scope_tree));
124125

125-
check_must_not_suspend_ty(
126-
self.fcx,
127-
ty,
128-
hir_id,
129-
SuspendCheckData {
130-
expr,
131-
source_span,
132-
yield_span: yield_data.span,
133-
plural_len: 1,
134-
..Default::default()
135-
},
136-
);
126+
if !self.linted_values.contains(&hir_id) {
127+
check_must_not_suspend_ty(
128+
self.fcx,
129+
ty,
130+
hir_id,
131+
SuspendCheckData {
132+
expr,
133+
source_span,
134+
yield_span: yield_data.span,
135+
plural_len: 1,
136+
..Default::default()
137+
},
138+
);
139+
self.linted_values.insert(hir_id);
140+
}
137141

138142
self.types.insert(ty::GeneratorInteriorTypeCause {
139143
span: source_span,
@@ -181,6 +185,7 @@ pub fn resolve_interior<'a, 'tcx>(
181185
prev_unresolved_span: None,
182186
guard_bindings: <_>::default(),
183187
guard_bindings_set: <_>::default(),
188+
linted_values: <_>::default(),
184189
};
185190
intravisit::walk_body(&mut visitor, body);
186191

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// edition:2018
2+
#![feature(must_not_suspend)]
3+
#![deny(must_not_suspend)]
4+
5+
#[must_not_suspend]
6+
struct No {}
7+
8+
async fn shushspend() {}
9+
10+
async fn wheeee<T>(t: T) {
11+
shushspend().await;
12+
drop(t);
13+
}
14+
15+
async fn yes() {
16+
wheeee(No {}).await; //~ ERROR `No` held across
17+
}
18+
19+
fn main() {
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error: `No` held across a suspend point, but should not be
2+
--> $DIR/dedup.rs:16:12
3+
|
4+
LL | wheeee(No {}).await;
5+
| -------^^^^^------- the value is held across this suspend point
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/dedup.rs:3:9
9+
|
10+
LL | #![deny(must_not_suspend)]
11+
| ^^^^^^^^^^^^^^^^
12+
help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
13+
--> $DIR/dedup.rs:16:12
14+
|
15+
LL | wheeee(No {}).await;
16+
| ^^^^^
17+
18+
error: aborting due to previous error
19+

src/test/ui/lint/must_not_suspend/generic.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
// edition:2018
2+
// run-pass
3+
//
4+
// this test shows a case where the lint doesn't fire in generic code
25
#![feature(must_not_suspend)]
36
#![deny(must_not_suspend)]
47

@@ -12,10 +15,6 @@ async fn wheeee<T>(t: T) {
1215
drop(t);
1316
}
1417

15-
async fn yes() {
16-
wheeee(No {}).await; //~ ERROR `No` held across
17-
//~^ ERROR `No` held across
18-
}
19-
2018
fn main() {
19+
let _fut = wheeee(No {});
2120
}

src/test/ui/lint/must_not_suspend/generic.stderr

-31
This file was deleted.

src/test/ui/lint/must_not_suspend/ref.rs

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ async fn other() {}
1616
impl Bar {
1717
async fn uhoh(&mut self) {
1818
let guard = &mut self.u; //~ ERROR `Umm` held across
19-
//~^ ERROR `Umm` held across
2019

2120
other().await;
2221

src/test/ui/lint/must_not_suspend/ref.stderr

+2-22
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ error: `Umm` held across a suspend point, but should not be
33
|
44
LL | let guard = &mut self.u;
55
| ^^^^^^
6-
...
6+
LL |
77
LL | other().await;
88
| ------------- the value is held across this suspend point
99
|
@@ -23,25 +23,5 @@ help: consider using a block (`{ ... }`) to shrink the value's scope, ending bef
2323
LL | let guard = &mut self.u;
2424
| ^^^^^^
2525

26-
error: `Umm` held across a suspend point, but should not be
27-
--> $DIR/ref.rs:18:26
28-
|
29-
LL | let guard = &mut self.u;
30-
| ^^^^^^
31-
...
32-
LL | other().await;
33-
| ------------- the value is held across this suspend point
34-
|
35-
note: You gotta use Umm's, ya know?
36-
--> $DIR/ref.rs:18:26
37-
|
38-
LL | let guard = &mut self.u;
39-
| ^^^^^^
40-
help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
41-
--> $DIR/ref.rs:18:26
42-
|
43-
LL | let guard = &mut self.u;
44-
| ^^^^^^
45-
46-
error: aborting due to 2 previous errors
26+
error: aborting due to previous error
4727

0 commit comments

Comments
 (0)