Skip to content

Commit bace571

Browse files
authored
Unrolled build for rust-lang#122881
Rollup merge of rust-lang#122881 - Bryanskiy:delegation-fixes-2, r=petrochenkov Delegation: fix ICE on `bound_vars` divergence Fixes rust-lang#122550. Bug was caused by divergence between lowered type and corresponding `bound_vars` in `late_bound_vars_map`. In this patch `bound_vars` calculation for delegation item is moved from `lower_fn_ty` to `resolve_bound_vars` query. r? `@petrochenkov`
2 parents cb7c636 + d1ba632 commit bace571

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -793,12 +793,20 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
793793
fd: &'tcx hir::FnDecl<'tcx>,
794794
body_id: hir::BodyId,
795795
_: Span,
796-
_: LocalDefId,
796+
def_id: LocalDefId,
797797
) {
798798
let output = match fd.output {
799799
hir::FnRetTy::DefaultReturn(_) => None,
800800
hir::FnRetTy::Return(ty) => Some(ty),
801801
};
802+
if let Some(ty) = output
803+
&& let hir::TyKind::InferDelegation(sig_id, _) = ty.kind
804+
{
805+
let bound_vars: Vec<_> =
806+
self.tcx.fn_sig(sig_id).skip_binder().bound_vars().iter().collect();
807+
let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
808+
self.map.late_bound_vars.insert(hir_id, bound_vars);
809+
}
802810
self.visit_fn_like_elision(fd.inputs, output, matches!(fk, intravisit::FnKind::Closure));
803811
intravisit::walk_fn_kind(self, fk);
804812
self.visit_nested_body(body_id)

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -2492,13 +2492,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
24922492
hir_ty: Option<&hir::Ty<'_>>,
24932493
) -> ty::PolyFnSig<'tcx> {
24942494
let tcx = self.tcx();
2495-
let bound_vars = if let hir::FnRetTy::Return(ret_ty) = decl.output
2496-
&& let hir::TyKind::InferDelegation(sig_id, _) = ret_ty.kind
2497-
{
2498-
tcx.fn_sig(sig_id).skip_binder().bound_vars()
2499-
} else {
2500-
tcx.late_bound_vars(hir_id)
2501-
};
2495+
let bound_vars = tcx.late_bound_vars(hir_id);
25022496
debug!(?bound_vars);
25032497

25042498
// We proactively collect all the inferred type params to emit a single error per fn def.
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(fn_delegation)]
2+
#![allow(incomplete_features)]
3+
4+
trait Trait {
5+
fn description(&self) -> &str {}
6+
//~^ ERROR mismatched types
7+
}
8+
9+
struct F;
10+
struct S(F);
11+
12+
impl S {
13+
reuse <S as Trait>::description { &self.0 }
14+
//~^ ERROR mismatched types
15+
//~| ERROR the trait bound `S: Trait` is not satisfied
16+
}
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/ice-issue-122550.rs:5:35
3+
|
4+
LL | fn description(&self) -> &str {}
5+
| ^^ expected `&str`, found `()`
6+
7+
error[E0308]: mismatched types
8+
--> $DIR/ice-issue-122550.rs:13:39
9+
|
10+
LL | reuse <S as Trait>::description { &self.0 }
11+
| ^^^^^^^ expected `&S`, found `&F`
12+
|
13+
= note: expected reference `&S`
14+
found reference `&F`
15+
16+
error[E0277]: the trait bound `S: Trait` is not satisfied
17+
--> $DIR/ice-issue-122550.rs:13:12
18+
|
19+
LL | reuse <S as Trait>::description { &self.0 }
20+
| ^ the trait `Trait` is not implemented for `S`
21+
|
22+
help: this trait has no implementations, consider adding one
23+
--> $DIR/ice-issue-122550.rs:4:1
24+
|
25+
LL | trait Trait {
26+
| ^^^^^^^^^^^
27+
28+
error: aborting due to 3 previous errors
29+
30+
Some errors have detailed explanations: E0277, E0308.
31+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)