Skip to content

Commit 2dd1c8f

Browse files
authored
Rollup merge of #116663 - compiler-errors:resolve-regions, r=lcnr
Don't ICE when encountering unresolved regions in `fully_resolve` We can encounter unresolved regions due to unconstrained impl lifetime arguments because `collect_return_position_impl_trait_in_trait_tys` runs before WF actually checks that the impl is well-formed. Fixes #116525
2 parents 89432aa + ea73f10 commit 2dd1c8f

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

compiler/rustc_infer/src/infer/mod.rs

+20-7
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_middle::ty::{self, GenericParamDefKind, InferConst, InferTy, Ty, TyCtx
3636
use rustc_middle::ty::{ConstVid, EffectVid, FloatVid, IntVid, TyVid};
3737
use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgs, GenericArgsRef};
3838
use rustc_span::symbol::Symbol;
39-
use rustc_span::Span;
39+
use rustc_span::{Span, DUMMY_SP};
4040

4141
use std::cell::{Cell, RefCell};
4242
use std::fmt;
@@ -1422,12 +1422,25 @@ impl<'tcx> InferCtxt<'tcx> {
14221422
/// This method is idempotent, but it not typically not invoked
14231423
/// except during the writeback phase.
14241424
pub fn fully_resolve<T: TypeFoldable<TyCtxt<'tcx>>>(&self, value: T) -> FixupResult<'tcx, T> {
1425-
let value = resolve::fully_resolve(self, value);
1426-
assert!(
1427-
value.as_ref().map_or(true, |value| !value.has_infer()),
1428-
"`{value:?}` is not fully resolved"
1429-
);
1430-
value
1425+
match resolve::fully_resolve(self, value) {
1426+
Ok(value) => {
1427+
if value.has_non_region_infer() {
1428+
bug!("`{value:?}` is not fully resolved");
1429+
}
1430+
if value.has_infer_regions() {
1431+
let guar = self
1432+
.tcx
1433+
.sess
1434+
.delay_span_bug(DUMMY_SP, format!("`{value:?}` is not fully resolved"));
1435+
Ok(self.tcx.fold_regions(value, |re, _| {
1436+
if re.is_var() { ty::Region::new_error(self.tcx, guar) } else { re }
1437+
}))
1438+
} else {
1439+
Ok(value)
1440+
}
1441+
}
1442+
Err(e) => Err(e),
1443+
}
14311444
}
14321445

14331446
// Instantiates the bound variables in a given binder with fresh inference

compiler/rustc_lint/src/async_fn_in_trait.rs

-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ declare_lint! {
5858
///
5959
///
6060
/// ```rust
61-
/// # #![feature(return_position_impl_trait_in_trait)]
6261
/// use core::future::Future;
6362
/// pub trait Trait {
6463
/// fn method(&self) -> impl Future<Output = ()> + Send { async {} }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// edition: 2021
2+
3+
pub(crate) trait Inbox<M> {
4+
async fn next(self) -> M;
5+
}
6+
7+
pub(crate) trait Actor: Sized {
8+
type Message;
9+
10+
async fn on_mount(self, _: impl Inbox<Self::Message>);
11+
}
12+
13+
impl<'a> Actor for () {
14+
//~^ ERROR the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
15+
type Message = &'a ();
16+
async fn on_mount(self, _: impl Inbox<&'a ()>) {}
17+
}
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
2+
--> $DIR/unconstrained-impl-region.rs:13:6
3+
|
4+
LL | impl<'a> Actor for () {
5+
| ^^ unconstrained lifetime parameter
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0207`.

0 commit comments

Comments
 (0)