Skip to content

Commit 6ffe6dd

Browse files
Check sig for errors before checking for unconstrained anonymous lifetime
1 parent 8c61cd4 commit 6ffe6dd

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

Diff for: compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+23-21
Original file line numberDiff line numberDiff line change
@@ -2557,27 +2557,29 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
25572557
// reject function types that violate cmse ABI requirements
25582558
cmse::validate_cmse_abi(self.tcx(), self.dcx(), hir_id, abi, bare_fn_ty);
25592559

2560-
// Find any late-bound regions declared in return type that do
2561-
// not appear in the arguments. These are not well-formed.
2562-
//
2563-
// Example:
2564-
// for<'a> fn() -> &'a str <-- 'a is bad
2565-
// for<'a> fn(&'a String) -> &'a str <-- 'a is ok
2566-
let inputs = bare_fn_ty.inputs();
2567-
let late_bound_in_args =
2568-
tcx.collect_constrained_late_bound_regions(inputs.map_bound(|i| i.to_owned()));
2569-
let output = bare_fn_ty.output();
2570-
let late_bound_in_ret = tcx.collect_referenced_late_bound_regions(output);
2571-
2572-
self.validate_late_bound_regions(late_bound_in_args, late_bound_in_ret, |br_name| {
2573-
struct_span_code_err!(
2574-
self.dcx(),
2575-
decl.output.span(),
2576-
E0581,
2577-
"return type references {}, which is not constrained by the fn input types",
2578-
br_name
2579-
)
2580-
});
2560+
if !bare_fn_ty.references_error() {
2561+
// Find any late-bound regions declared in return type that do
2562+
// not appear in the arguments. These are not well-formed.
2563+
//
2564+
// Example:
2565+
// for<'a> fn() -> &'a str <-- 'a is bad
2566+
// for<'a> fn(&'a String) -> &'a str <-- 'a is ok
2567+
let inputs = bare_fn_ty.inputs();
2568+
let late_bound_in_args =
2569+
tcx.collect_constrained_late_bound_regions(inputs.map_bound(|i| i.to_owned()));
2570+
let output = bare_fn_ty.output();
2571+
let late_bound_in_ret = tcx.collect_referenced_late_bound_regions(output);
2572+
2573+
self.validate_late_bound_regions(late_bound_in_args, late_bound_in_ret, |br_name| {
2574+
struct_span_code_err!(
2575+
self.dcx(),
2576+
decl.output.span(),
2577+
E0581,
2578+
"return type references {}, which is not constrained by the fn input types",
2579+
br_name
2580+
)
2581+
});
2582+
}
25812583

25822584
bare_fn_ty
25832585
}

Diff for: tests/ui/async-await/unconstrained-lifetimes.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ edition: 2021
2+
3+
// Make sure we don't complain about the implicit `-> impl Future` capturing an
4+
// unconstrained anonymous lifetime.
5+
6+
async fn foo(_: Missing<'_>) {}
7+
//~^ ERROR cannot find type `Missing` in this scope
8+
9+
fn main() {}

Diff for: tests/ui/async-await/unconstrained-lifetimes.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0412]: cannot find type `Missing` in this scope
2+
--> $DIR/unconstrained-lifetimes.rs:6:17
3+
|
4+
LL | async fn foo(_: Missing<'_>) {}
5+
| ^^^^^^^ not found in this scope
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)