suggest to add move keyword for generator
This commit is contained in:
parent
dd2356fe7d
commit
d1d256592b
5 changed files with 47 additions and 5 deletions
|
@ -750,6 +750,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
let kind_place = kind.filter(|_| place_desc.is_some()).map(|k| (k, place_span.0));
|
let kind_place = kind.filter(|_| place_desc.is_some()).map(|k| (k, place_span.0));
|
||||||
let explanation = self.explain_why_borrow_contains_point(location, &borrow, kind_place);
|
let explanation = self.explain_why_borrow_contains_point(location, &borrow, kind_place);
|
||||||
|
|
||||||
|
debug!(
|
||||||
|
"report_borrowed_value_does_not_live_long_enough(place_desc: {:?}, explanation: {:?})",
|
||||||
|
place_desc,
|
||||||
|
explanation
|
||||||
|
);
|
||||||
let err = match (place_desc, explanation) {
|
let err = match (place_desc, explanation) {
|
||||||
(Some(_), _) if self.is_place_thread_local(root_place) => {
|
(Some(_), _) if self.is_place_thread_local(root_place) => {
|
||||||
self.report_thread_local_value_does_not_live_long_enough(drop_span, borrow_span)
|
self.report_thread_local_value_does_not_live_long_enough(drop_span, borrow_span)
|
||||||
|
@ -790,6 +795,24 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
span,
|
span,
|
||||||
&format!("`{}`", name),
|
&format!("`{}`", name),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
Some(ref name),
|
||||||
|
BorrowExplanation::MustBeValidFor {
|
||||||
|
category: category @ ConstraintCategory::OpaqueType,
|
||||||
|
from_closure: false,
|
||||||
|
ref region_name,
|
||||||
|
span,
|
||||||
|
..
|
||||||
|
},
|
||||||
|
|
||||||
|
) if borrow_spans.for_generator() => self.report_escaping_closure_capture(
|
||||||
|
borrow_spans.args_or_use(),
|
||||||
|
borrow_span,
|
||||||
|
region_name,
|
||||||
|
category,
|
||||||
|
span,
|
||||||
|
&format!("`{}`", name),
|
||||||
|
),
|
||||||
(
|
(
|
||||||
ref name,
|
ref name,
|
||||||
BorrowExplanation::MustBeValidFor {
|
BorrowExplanation::MustBeValidFor {
|
||||||
|
@ -1214,6 +1237,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
ConstraintCategory::Return => {
|
ConstraintCategory::Return => {
|
||||||
err.span_note(constraint_span, "closure is returned here");
|
err.span_note(constraint_span, "closure is returned here");
|
||||||
}
|
}
|
||||||
|
ConstraintCategory::OpaqueType => {
|
||||||
|
err.span_note(constraint_span, "generator is returned here");
|
||||||
|
}
|
||||||
ConstraintCategory::CallArgument => {
|
ConstraintCategory::CallArgument => {
|
||||||
fr_name.highlight_region_name(&mut err);
|
fr_name.highlight_region_name(&mut err);
|
||||||
err.span_note(
|
err.span_note(
|
||||||
|
|
|
@ -17,6 +17,7 @@ use syntax_pos::Span;
|
||||||
|
|
||||||
mod find_use;
|
mod find_use;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub(in crate::borrow_check) enum BorrowExplanation {
|
pub(in crate::borrow_check) enum BorrowExplanation {
|
||||||
UsedLater(LaterUseKind, Span),
|
UsedLater(LaterUseKind, Span),
|
||||||
UsedLaterInLoop(LaterUseKind, Span),
|
UsedLaterInLoop(LaterUseKind, Span),
|
||||||
|
@ -35,7 +36,7 @@ pub(in crate::borrow_check) enum BorrowExplanation {
|
||||||
Unexplained,
|
Unexplained,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub(in crate::borrow_check) enum LaterUseKind {
|
pub(in crate::borrow_check) enum LaterUseKind {
|
||||||
TraitCapture,
|
TraitCapture,
|
||||||
ClosureCapture,
|
ClosureCapture,
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
// edition:2018
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
fn foo() -> Box<impl std::future::Future<Output = u32>> {
|
||||||
|
let x = 0u32;
|
||||||
|
Box::new(async move { x } )
|
||||||
|
//~^ ERROR E0373
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _foo = foo();
|
||||||
|
}
|
|
@ -1,9 +1,12 @@
|
||||||
// edition:2018
|
// edition:2018
|
||||||
#![feature(async_closure,async_await)]
|
// run-rustfix
|
||||||
|
|
||||||
fn foo() -> Box<impl std::future::Future<Output = u32>> {
|
fn foo() -> Box<impl std::future::Future<Output = u32>> {
|
||||||
let x = 0u32;
|
let x = 0u32;
|
||||||
Box::new(async { x } )
|
Box::new(async { x } )
|
||||||
//~^ ERROR E0373
|
//~^ ERROR E0373
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {
|
||||||
|
let _foo = foo();
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
|
error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
|
||||||
--> $DIR/async-borrowck-escaping-block-error.rs:5:20
|
--> $DIR/async-borrowck-escaping-block-error.rs:6:20
|
||||||
|
|
|
|
||||||
LL | Box::new(async { x } )
|
LL | Box::new(async { x } )
|
||||||
| ^^-^^
|
| ^^-^^
|
||||||
|
@ -8,7 +8,7 @@ LL | Box::new(async { x } )
|
||||||
| may outlive borrowed value `x`
|
| may outlive borrowed value `x`
|
||||||
|
|
|
|
||||||
note: generator is returned here
|
note: generator is returned here
|
||||||
--> $DIR/async-borrowck-escaping-block-error.rs:3:13
|
--> $DIR/async-borrowck-escaping-block-error.rs:4:13
|
||||||
|
|
|
|
||||||
LL | fn foo() -> Box<impl std::future::Future<Output = u32>> {
|
LL | fn foo() -> Box<impl std::future::Future<Output = u32>> {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue