Skip to content

Commit 9124f7a

Browse files
committedNov 12, 2019
update suggestion ui test
1 parent dcc14c4 commit 9124f7a

File tree

7 files changed

+67
-18
lines changed

7 files changed

+67
-18
lines changed
 

‎src/librustc/hir/lowering.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -2124,6 +2124,16 @@ impl<'a> LoweringContext<'a> {
21242124
impl_trait_return_allow: bool,
21252125
make_ret_async: Option<NodeId>,
21262126
) -> P<hir::FnDecl> {
2127+
debug!("lower_fn_decl(\
2128+
fn_decl: {:?}, \
2129+
in_band_ty_params: {:?}, \
2130+
impl_trait_return_allow: {}, \
2131+
make_ret_async: {:?})",
2132+
decl,
2133+
in_band_ty_params,
2134+
impl_trait_return_allow,
2135+
make_ret_async,
2136+
);
21272137
let lt_mode = if make_ret_async.is_some() {
21282138
// In `async fn`, argument-position elided lifetimes
21292139
// must be transformed into fresh generic parameters so that
@@ -2416,7 +2426,7 @@ impl<'a> LoweringContext<'a> {
24162426

24172427
hir::FunctionRetTy::Return(P(hir::Ty {
24182428
kind: opaque_ty_ref,
2419-
span,
2429+
span: opaque_ty_span,
24202430
hir_id: self.next_id(),
24212431
}))
24222432
}
@@ -2526,7 +2536,7 @@ impl<'a> LoweringContext<'a> {
25262536
hir::Lifetime {
25272537
hir_id: self.lower_node_id(id),
25282538
span,
2529-
name: name,
2539+
name,
25302540
}
25312541
}
25322542

‎src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
5353
}) => name.to_string(),
5454
_ => "'_".to_owned(),
5555
};
56-
if let Ok(snippet) = self.tcx().sess.source_map().span_to_snippet(return_sp) {
57-
// only apply this suggestion onto non-async fnunctions
58-
if !return_ty.unwrap().1 {
56+
let fn_return_span = return_ty.unwrap().1;
57+
if let Ok(snippet) =
58+
self.tcx().sess.source_map().span_to_snippet(fn_return_span) {
59+
// only apply this suggestion onto functions with
60+
// explicit non-desugar'able return.
61+
if fn_return_span.desugaring_kind().is_none() {
5962
err.span_suggestion(
60-
return_sp,
63+
fn_return_span,
6164
&format!(
6265
"you can add a constraint to the return type to make it last \
6366
less than `'static` and match {}",

‎src/librustc/ty/context.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ impl<'tcx> TyCtxt<'tcx> {
15591559
pub fn return_type_impl_trait(
15601560
&self,
15611561
scope_def_id: DefId,
1562-
) -> Option<(Ty<'tcx>, bool)> {
1562+
) -> Option<(Ty<'tcx>, Span)> {
15631563
// HACK: `type_of_def_id()` will fail on these (#55796), so return `None`.
15641564
let hir_id = self.hir().as_local_hir_id(scope_def_id).unwrap();
15651565
match self.hir().get(hir_id) {
@@ -1579,10 +1579,9 @@ impl<'tcx> TyCtxt<'tcx> {
15791579
ty::FnDef(_, _) => {
15801580
let sig = ret_ty.fn_sig(*self);
15811581
let output = self.erase_late_bound_regions(&sig.output());
1582-
let is_async_fn =
1583-
hir::IsAsync::Async == self.asyncness(scope_def_id);
15841582
if output.is_impl_trait() {
1585-
Some((output, is_async_fn))
1583+
let fn_decl = self.hir().fn_decl_by_hir_id(hir_id).unwrap();
1584+
Some((output, fn_decl.output.span()))
15861585
} else {
15871586
None
15881587
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0373]: closure may outlive the current function, but it borrows `self`, which is owned by the current function
2+
--> $DIR/issue-62097.rs:13:13
3+
|
4+
LL | foo(|| self.bar()).await;
5+
| ^^ ---- `self` is borrowed here
6+
| |
7+
| may outlive borrowed value `self`
8+
|
9+
note: function requires argument type to outlive `'static`
10+
--> $DIR/issue-62097.rs:13:9
11+
|
12+
LL | foo(|| self.bar()).await;
13+
| ^^^^^^^^^^^^^^^^^^
14+
help: to force the closure to take ownership of `self` (and any other referenced variables), use the `move` keyword
15+
|
16+
LL | foo(move || self.bar()).await;
17+
| ^^^^^^^
18+
19+
error[E0521]: borrowed data escapes outside of function
20+
--> $DIR/issue-62097.rs:13:9
21+
|
22+
LL | pub async fn run_dummy_fn(&self) {
23+
| ----- `self` is a reference that is only valid in the function body
24+
LL | foo(|| self.bar()).await;
25+
| ^^^^^^^^^^^^^^^^^^ `self` escapes the function body here
26+
27+
error: aborting due to 2 previous errors
28+
29+
For more information about this error, try `rustc --explain E0373`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: cannot infer an appropriate lifetime
2+
--> $DIR/issue-62097.rs:12:31
3+
|
4+
LL | pub async fn run_dummy_fn(&self) {
5+
| ^^^^^ ...but this borrow...
6+
LL | foo(|| self.bar()).await;
7+
| --- this return type evaluates to the `'static` lifetime...
8+
|
9+
note: ...can't outlive the lifetime `'_` as defined on the method body at 12:31
10+
--> $DIR/issue-62097.rs:12:31
11+
|
12+
LL | pub async fn run_dummy_fn(&self) {
13+
| ^
14+
15+
error: aborting due to previous error
16+

‎src/test/ui/async-await/issues/issue-63388-2.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ note: ...can't outlive the lifetime `'_` as defined on the method body at 11:14
2020
|
2121
LL | foo: &dyn Foo, bar: &'a dyn Foo
2222
| ^
23-
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
24-
|
25-
LL | foo + '_
26-
|
2723

2824
error: aborting due to 2 previous errors
2925

‎src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait-async.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ note: ...can't outlive the lifetime `'_` as defined on the method body at 8:26
1111
|
1212
LL | async fn f(self: Pin<&Self>) -> impl Clone { self }
1313
| ^
14-
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
15-
|
16-
LL | async fn f(self: Pin<&Self>) -> impl Clone + '_ { self }
17-
| ^^^^^^^^^^^^^^^
1814

1915
error: aborting due to previous error
2016

0 commit comments

Comments
 (0)
Please sign in to comment.