Skip to content

Commit

Permalink
sins
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Aug 9, 2024
1 parent e172dd2 commit d839703
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 21 deletions.
3 changes: 2 additions & 1 deletion compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,8 @@ pub struct QSelf {
}

/// A capture clause used in closures and `async` blocks.
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, Ord, PartialOrd)]
#[derive(Clone, Copy, PartialEq, Ord, Eq, PartialOrd, Debug)]
#[derive(Encodable, Decodable, HashStable_Generic)]
pub enum CaptureBy {
/// `move` keyword was not specified.
Ref,
Expand Down
20 changes: 16 additions & 4 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,26 @@ impl<'hir> LoweringContext<'_, 'hir> {
) = &peeled.kind
{
let coroutine_kind = match gen_kind {
GenBlockKind::Async => CoroutineKind::Async { span: *span, closure_id: peeled.node_id(), return_impl_trait_id: self.next_node_id() },
GenBlockKind::Gen => CoroutineKind::Gen { span: *span, closure_id: peeled.node_id(), return_impl_trait_id: self.next_node_id() },
GenBlockKind::AsyncGen => CoroutineKind::AsyncGen { span: *span, closure_id: peeled.node_id(), return_impl_trait_id: self.next_node_id() },
GenBlockKind::Async => CoroutineKind::Async {
span: *span,
closure_id: peeled.node_id(),
return_impl_trait_id: self.next_node_id(),
},
GenBlockKind::Gen => CoroutineKind::Gen {
span: *span,
closure_id: peeled.node_id(),
return_impl_trait_id: self.next_node_id(),
},
GenBlockKind::AsyncGen => CoroutineKind::AsyncGen {
span: *span,
closure_id: peeled.node_id(),
return_impl_trait_id: self.next_node_id(),
},
};
let id = self.next_node_id();
self.lower_expr_coroutine_closure(
binder,
capture_clause.max(*gen_capture_clause),
(*capture_clause).max(*gen_capture_clause),
e.id,
hir_id,
coroutine_kind,
Expand Down
25 changes: 11 additions & 14 deletions tests/ui/async-await/issue-69446-fnmut-capture.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
error: captured variable cannot escape `FnMut` closure body
--> $DIR/issue-69446-fnmut-capture.rs:19:17
error: async closure does not implement `FnMut` because it captures state from its environment
--> $DIR/issue-69446-fnmut-capture.rs:19:9
|
LL | let mut x = Foo;
| ----- variable defined here
LL | bar(move || async {
| _______________-_^
| | |
| | inferred to be a `FnMut` closure
LL | | x.foo();
| | - variable captured here
LL | | });
| |_____^ returns an `async` block that contains a reference to a captured variable, which then escapes the closure body
LL | bar(move || async {
| --- ^^^^^^^
| |
| required by a bound introduced by this call
|
= note: `FnMut` closures only have access to their captured variables while they are executing...
= note: ...therefore, they cannot allow references to captured variables to escape
note: required by a bound in `bar`
--> $DIR/issue-69446-fnmut-capture.rs:12:25
|
LL | async fn bar<T>(_: impl FnMut() -> T)
| ^^^^^^^^^^^^ required by this bound in `bar`

error: aborting due to 1 previous error

2 changes: 2 additions & 0 deletions tests/ui/async-await/issue-70935-complex-spans.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ note: required because it appears within the type `NotSync`
LL | struct NotSync(PhantomData<*mut ()>);
| ^^^^^^^
= note: required for `&NotSync` to implement `Send`
= note: required because it appears within the type `(&NotSync,)`
note: required because it's used within this closure
--> $DIR/issue-70935-complex-spans.rs:19:13
|
Expand Down Expand Up @@ -46,6 +47,7 @@ note: required because it appears within the type `NotSync`
LL | struct NotSync(PhantomData<*mut ()>);
| ^^^^^^^
= note: required for `&NotSync` to implement `Send`
= note: required because it appears within the type `(&NotSync,)`
note: required because it's used within this closure
--> $DIR/issue-70935-complex-spans.rs:19:13
|
Expand Down
11 changes: 9 additions & 2 deletions tests/ui/impl-trait/opaque-cast-field-access-in-future.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
error[E0282]: type annotations needed
--> $DIR/opaque-cast-field-access-in-future.rs:7:14
|
LL | &mut foo.bar;
| ^^^ cannot infer type

error[E0283]: type annotations needed
--> $DIR/opaque-cast-field-access-in-future.rs:22:17
|
Expand All @@ -6,6 +12,7 @@ LL | fn run() -> Foo<impl Future<Output = ()>> {
|
= note: cannot satisfy `_: Future`

error: aborting due to 1 previous error
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0283`.
Some errors have detailed explanations: E0282, E0283.
For more information about an error, try `rustc --explain E0282`.

0 comments on commit d839703

Please sign in to comment.