Skip to content

Commit

Permalink
update suggestion ui test
Browse files Browse the repository at this point in the history
  • Loading branch information
csmoe committed Nov 12, 2019
1 parent dcc14c4 commit 9124f7a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 18 deletions.
14 changes: 12 additions & 2 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,16 @@ impl<'a> LoweringContext<'a> {
impl_trait_return_allow: bool,
make_ret_async: Option<NodeId>,
) -> P<hir::FnDecl> {
debug!("lower_fn_decl(\
fn_decl: {:?}, \
in_band_ty_params: {:?}, \
impl_trait_return_allow: {}, \
make_ret_async: {:?})",
decl,
in_band_ty_params,
impl_trait_return_allow,
make_ret_async,
);
let lt_mode = if make_ret_async.is_some() {
// In `async fn`, argument-position elided lifetimes
// must be transformed into fresh generic parameters so that
Expand Down Expand Up @@ -2416,7 +2426,7 @@ impl<'a> LoweringContext<'a> {

hir::FunctionRetTy::Return(P(hir::Ty {
kind: opaque_ty_ref,
span,
span: opaque_ty_span,
hir_id: self.next_id(),
}))
}
Expand Down Expand Up @@ -2526,7 +2536,7 @@ impl<'a> LoweringContext<'a> {
hir::Lifetime {
hir_id: self.lower_node_id(id),
span,
name: name,
name,
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
}) => name.to_string(),
_ => "'_".to_owned(),
};
if let Ok(snippet) = self.tcx().sess.source_map().span_to_snippet(return_sp) {
// only apply this suggestion onto non-async fnunctions
if !return_ty.unwrap().1 {
let fn_return_span = return_ty.unwrap().1;
if let Ok(snippet) =
self.tcx().sess.source_map().span_to_snippet(fn_return_span) {
// only apply this suggestion onto functions with
// explicit non-desugar'able return.
if fn_return_span.desugaring_kind().is_none() {
err.span_suggestion(
return_sp,
fn_return_span,
&format!(
"you can add a constraint to the return type to make it last \
less than `'static` and match {}",
Expand Down
7 changes: 3 additions & 4 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1559,7 +1559,7 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn return_type_impl_trait(
&self,
scope_def_id: DefId,
) -> Option<(Ty<'tcx>, bool)> {
) -> Option<(Ty<'tcx>, Span)> {
// HACK: `type_of_def_id()` will fail on these (#55796), so return `None`.
let hir_id = self.hir().as_local_hir_id(scope_def_id).unwrap();
match self.hir().get(hir_id) {
Expand All @@ -1579,10 +1579,9 @@ impl<'tcx> TyCtxt<'tcx> {
ty::FnDef(_, _) => {
let sig = ret_ty.fn_sig(*self);
let output = self.erase_late_bound_regions(&sig.output());
let is_async_fn =
hir::IsAsync::Async == self.asyncness(scope_def_id);
if output.is_impl_trait() {
Some((output, is_async_fn))
let fn_decl = self.hir().fn_decl_by_hir_id(hir_id).unwrap();
Some((output, fn_decl.output.span()))
} else {
None
}
Expand Down
29 changes: 29 additions & 0 deletions src/test/ui/async-await/issues/issue-62097.nll.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
error[E0373]: closure may outlive the current function, but it borrows `self`, which is owned by the current function
--> $DIR/issue-62097.rs:13:13
|
LL | foo(|| self.bar()).await;
| ^^ ---- `self` is borrowed here
| |
| may outlive borrowed value `self`
|
note: function requires argument type to outlive `'static`
--> $DIR/issue-62097.rs:13:9
|
LL | foo(|| self.bar()).await;
| ^^^^^^^^^^^^^^^^^^
help: to force the closure to take ownership of `self` (and any other referenced variables), use the `move` keyword
|
LL | foo(move || self.bar()).await;
| ^^^^^^^

error[E0521]: borrowed data escapes outside of function
--> $DIR/issue-62097.rs:13:9
|
LL | pub async fn run_dummy_fn(&self) {
| ----- `self` is a reference that is only valid in the function body
LL | foo(|| self.bar()).await;
| ^^^^^^^^^^^^^^^^^^ `self` escapes the function body here

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0373`.
16 changes: 16 additions & 0 deletions src/test/ui/async-await/issues/issue-62097.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: cannot infer an appropriate lifetime
--> $DIR/issue-62097.rs:12:31
|
LL | pub async fn run_dummy_fn(&self) {
| ^^^^^ ...but this borrow...
LL | foo(|| self.bar()).await;
| --- this return type evaluates to the `'static` lifetime...
|
note: ...can't outlive the lifetime `'_` as defined on the method body at 12:31
--> $DIR/issue-62097.rs:12:31
|
LL | pub async fn run_dummy_fn(&self) {
| ^

error: aborting due to previous error

4 changes: 0 additions & 4 deletions src/test/ui/async-await/issues/issue-63388-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ note: ...can't outlive the lifetime `'_` as defined on the method body at 11:14
|
LL | foo: &dyn Foo, bar: &'a dyn Foo
| ^
help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime `'_` as defined on the method body at 11:14
|
LL | foo + '_
|

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ note: ...can't outlive the lifetime `'_` as defined on the method body at 8:26
|
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
| ^
help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime `'_` as defined on the method body at 8:26
|
LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
| ^^^^^^^^^^^^^^^

error: aborting due to previous error

0 comments on commit 9124f7a

Please sign in to comment.