Skip to content

Commit 1adb26b

Browse files
committed
update suggestion ui test
1 parent c000b21 commit 1adb26b

File tree

6 files changed

+38
-18
lines changed

6 files changed

+38
-18
lines changed

src/librustc/hir/lowering.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -2135,6 +2135,16 @@ impl<'a> LoweringContext<'a> {
21352135
impl_trait_return_allow: bool,
21362136
make_ret_async: Option<NodeId>,
21372137
) -> P<hir::FnDecl> {
2138+
debug!("lower_fn_decl(\
2139+
fn_decl: {:?}, \
2140+
in_band_ty_params: {:?}, \
2141+
impl_trait_return_allow: {}, \
2142+
make_ret_async: {:?})",
2143+
decl,
2144+
in_band_ty_params,
2145+
impl_trait_return_allow,
2146+
make_ret_async,
2147+
);
21382148
let lt_mode = if make_ret_async.is_some() {
21392149
// In `async fn`, argument-position elided lifetimes
21402150
// must be transformed into fresh generic parameters so that
@@ -2427,7 +2437,7 @@ impl<'a> LoweringContext<'a> {
24272437

24282438
hir::FunctionRetTy::Return(P(hir::Ty {
24292439
kind: opaque_ty_ref,
2430-
span,
2440+
span: opaque_ty_span,
24312441
hir_id: self.next_id(),
24322442
}))
24332443
}
@@ -2537,7 +2547,7 @@ impl<'a> LoweringContext<'a> {
25372547
hir::Lifetime {
25382548
hir_id: self.lower_node_id(id),
25392549
span,
2540-
name: name,
2550+
name,
25412551
}
25422552
}
25432553

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
@@ -1553,7 +1553,7 @@ impl<'tcx> TyCtxt<'tcx> {
15531553
pub fn return_type_impl_trait(
15541554
&self,
15551555
scope_def_id: DefId,
1556-
) -> Option<(Ty<'tcx>, bool)> {
1556+
) -> Option<(Ty<'tcx>, Span)> {
15571557
// HACK: `type_of_def_id()` will fail on these (#55796), so return `None`.
15581558
let hir_id = self.hir().as_local_hir_id(scope_def_id).unwrap();
15591559
match self.hir().get(hir_id) {
@@ -1573,10 +1573,9 @@ impl<'tcx> TyCtxt<'tcx> {
15731573
ty::FnDef(_, _) => {
15741574
let sig = ret_ty.fn_sig(*self);
15751575
let output = self.erase_late_bound_regions(&sig.output());
1576-
let is_async_fn =
1577-
hir::IsAsync::Async == self.asyncness(scope_def_id);
15781576
if output.is_impl_trait() {
1579-
Some((output, is_async_fn))
1577+
let fn_decl = self.hir().fn_decl_by_hir_id(hir_id).unwrap();
1578+
Some((output, fn_decl.output.span()))
15801579
} else {
15811580
None
15821581
}
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)