]> git.lizzy.rs Git - rust.git/commitdiff
deduplication
authorGus Wynn <guswynn@gmail.com>
Sat, 18 Sep 2021 20:00:36 +0000 (13:00 -0700)
committerGus Wynn <guswynn@gmail.com>
Sat, 18 Sep 2021 20:00:36 +0000 (13:00 -0700)
compiler/rustc_typeck/src/check/generator_interior.rs
src/test/ui/lint/must_not_suspend/dedup.rs [new file with mode: 0644]
src/test/ui/lint/must_not_suspend/dedup.stderr [new file with mode: 0644]
src/test/ui/lint/must_not_suspend/generic.rs
src/test/ui/lint/must_not_suspend/generic.stderr [deleted file]
src/test/ui/lint/must_not_suspend/ref.rs
src/test/ui/lint/must_not_suspend/ref.stderr

index ac67d2b93c57bc36a41a1cfd223ef51cf91f5a45..5ad9bdbe68db051570891bd6af992b2d32d0535e 100644 (file)
@@ -33,6 +33,7 @@ struct InteriorVisitor<'a, 'tcx> {
     /// that they may succeed the said yield point in the post-order.
     guard_bindings: SmallVec<[SmallVec<[HirId; 4]>; 1]>,
     guard_bindings_set: HirIdSet,
+    linted_values: HirIdSet,
 }
 
 impl<'a, 'tcx> InteriorVisitor<'a, 'tcx> {
@@ -122,18 +123,21 @@ fn record(
                 // Insert the type into the ordered set.
                 let scope_span = scope.map(|s| s.span(self.fcx.tcx, self.region_scope_tree));
 
-                check_must_not_suspend_ty(
-                    self.fcx,
-                    ty,
-                    hir_id,
-                    SuspendCheckData {
-                        expr,
-                        source_span,
-                        yield_span: yield_data.span,
-                        plural_len: 1,
-                        ..Default::default()
-                    },
-                );
+                if !self.linted_values.contains(&hir_id) {
+                    check_must_not_suspend_ty(
+                        self.fcx,
+                        ty,
+                        hir_id,
+                        SuspendCheckData {
+                            expr,
+                            source_span,
+                            yield_span: yield_data.span,
+                            plural_len: 1,
+                            ..Default::default()
+                        },
+                    );
+                    self.linted_values.insert(hir_id);
+                }
 
                 self.types.insert(ty::GeneratorInteriorTypeCause {
                     span: source_span,
@@ -181,6 +185,7 @@ pub fn resolve_interior<'a, 'tcx>(
         prev_unresolved_span: None,
         guard_bindings: <_>::default(),
         guard_bindings_set: <_>::default(),
+        linted_values: <_>::default(),
     };
     intravisit::walk_body(&mut visitor, body);
 
diff --git a/src/test/ui/lint/must_not_suspend/dedup.rs b/src/test/ui/lint/must_not_suspend/dedup.rs
new file mode 100644 (file)
index 0000000..040fff5
--- /dev/null
@@ -0,0 +1,20 @@
+// edition:2018
+#![feature(must_not_suspend)]
+#![deny(must_not_suspend)]
+
+#[must_not_suspend]
+struct No {}
+
+async fn shushspend() {}
+
+async fn wheeee<T>(t: T) {
+    shushspend().await;
+    drop(t);
+}
+
+async fn yes() {
+    wheeee(No {}).await; //~ ERROR `No` held across
+}
+
+fn main() {
+}
diff --git a/src/test/ui/lint/must_not_suspend/dedup.stderr b/src/test/ui/lint/must_not_suspend/dedup.stderr
new file mode 100644 (file)
index 0000000..542b7a3
--- /dev/null
@@ -0,0 +1,19 @@
+error: `No` held across a suspend point, but should not be
+  --> $DIR/dedup.rs:16:12
+   |
+LL |     wheeee(No {}).await;
+   |     -------^^^^^------- the value is held across this suspend point
+   |
+note: the lint level is defined here
+  --> $DIR/dedup.rs:3:9
+   |
+LL | #![deny(must_not_suspend)]
+   |         ^^^^^^^^^^^^^^^^
+help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
+  --> $DIR/dedup.rs:16:12
+   |
+LL |     wheeee(No {}).await;
+   |            ^^^^^
+
+error: aborting due to previous error
+
index 94457e375400e69572c041dfca450be13f8d17af..b3effa020c48fa9b2e1ee1cc98a06869199d5773 100644 (file)
@@ -1,4 +1,7 @@
 // edition:2018
+// run-pass
+//
+// this test shows a case where the lint doesn't fire in generic code
 #![feature(must_not_suspend)]
 #![deny(must_not_suspend)]
 
@@ -12,10 +15,6 @@ async fn wheeee<T>(t: T) {
     drop(t);
 }
 
-async fn yes() {
-    wheeee(No {}).await; //~ ERROR `No` held across
-    //~^ ERROR `No` held across
-}
-
 fn main() {
+    let _fut = wheeee(No {});
 }
diff --git a/src/test/ui/lint/must_not_suspend/generic.stderr b/src/test/ui/lint/must_not_suspend/generic.stderr
deleted file mode 100644 (file)
index d853ba7..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-error: `No` held across a suspend point, but should not be
-  --> $DIR/generic.rs:16:12
-   |
-LL |     wheeee(No {}).await;
-   |     -------^^^^^------- the value is held across this suspend point
-   |
-note: the lint level is defined here
-  --> $DIR/generic.rs:3:9
-   |
-LL | #![deny(must_not_suspend)]
-   |         ^^^^^^^^^^^^^^^^
-help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
-  --> $DIR/generic.rs:16:12
-   |
-LL |     wheeee(No {}).await;
-   |            ^^^^^
-
-error: `No` held across a suspend point, but should not be
-  --> $DIR/generic.rs:16:12
-   |
-LL |     wheeee(No {}).await;
-   |     -------^^^^^------- the value is held across this suspend point
-   |
-help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
-  --> $DIR/generic.rs:16:12
-   |
-LL |     wheeee(No {}).await;
-   |            ^^^^^
-
-error: aborting due to 2 previous errors
-
index 89fd73c187e901fc7f4645cb70c2648186f66230..738dd9e04655ced2a1a106d30ebaadb9c9f80d15 100644 (file)
@@ -16,7 +16,6 @@ async fn other() {}
 impl Bar {
     async fn uhoh(&mut self) {
         let guard = &mut self.u; //~ ERROR `Umm` held across
-        //~^ ERROR `Umm` held across
 
         other().await;
 
index d4c58bcbcd280a3339792b621b86dbae6347f9d3..78b44b00625d1cdf2809fc0628e3b78eb4e40cde 100644 (file)
@@ -3,7 +3,7 @@ error: `Umm` held across a suspend point, but should not be
    |
 LL |         let guard = &mut self.u;
    |                          ^^^^^^
-...
+LL | 
 LL |         other().await;
    |         ------------- the value is held across this suspend point
    |
@@ -23,25 +23,5 @@ help: consider using a block (`{ ... }`) to shrink the value's scope, ending bef
 LL |         let guard = &mut self.u;
    |                          ^^^^^^
 
-error: `Umm` held across a suspend point, but should not be
-  --> $DIR/ref.rs:18:26
-   |
-LL |         let guard = &mut self.u;
-   |                          ^^^^^^
-...
-LL |         other().await;
-   |         ------------- the value is held across this suspend point
-   |
-note: You gotta use Umm's, ya know?
-  --> $DIR/ref.rs:18:26
-   |
-LL |         let guard = &mut self.u;
-   |                          ^^^^^^
-help: consider using a block (`{ ... }`) to shrink the value's scope, ending before the suspend point
-  --> $DIR/ref.rs:18:26
-   |
-LL |         let guard = &mut self.u;
-   |                          ^^^^^^
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error