Skip to content

Commit 77a1d6b

Browse files
authored
Rollup merge of rust-lang#136891 - compiler-errors:unconstrained-anon-lt, r=lqd
Check sig for errors before checking for unconstrained anonymous lifetime Fixes rust-lang#136841
2 parents 86ebf42 + 6ffe6dd commit 77a1d6b

File tree

3 files changed

+41
-21
lines changed

3 files changed

+41
-21
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

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

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

25862588
bare_fn_ty
25872589
}
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() {}
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)