Rollup merge of #122881 - Bryanskiy:delegation-fixes-2, r=petrochenkov
Delegation: fix ICE on `bound_vars` divergence Fixes https://github.com/rust-lang/rust/issues/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`
This commit is contained in:
commit
ccc5310922
@ -793,12 +793,20 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
|||||||
fd: &'tcx hir::FnDecl<'tcx>,
|
fd: &'tcx hir::FnDecl<'tcx>,
|
||||||
body_id: hir::BodyId,
|
body_id: hir::BodyId,
|
||||||
_: Span,
|
_: Span,
|
||||||
_: LocalDefId,
|
def_id: LocalDefId,
|
||||||
) {
|
) {
|
||||||
let output = match fd.output {
|
let output = match fd.output {
|
||||||
hir::FnRetTy::DefaultReturn(_) => None,
|
hir::FnRetTy::DefaultReturn(_) => None,
|
||||||
hir::FnRetTy::Return(ty) => Some(ty),
|
hir::FnRetTy::Return(ty) => Some(ty),
|
||||||
};
|
};
|
||||||
|
if let Some(ty) = output
|
||||||
|
&& let hir::TyKind::InferDelegation(sig_id, _) = ty.kind
|
||||||
|
{
|
||||||
|
let bound_vars: Vec<_> =
|
||||||
|
self.tcx.fn_sig(sig_id).skip_binder().bound_vars().iter().collect();
|
||||||
|
let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
|
||||||
|
self.map.late_bound_vars.insert(hir_id, bound_vars);
|
||||||
|
}
|
||||||
self.visit_fn_like_elision(fd.inputs, output, matches!(fk, intravisit::FnKind::Closure));
|
self.visit_fn_like_elision(fd.inputs, output, matches!(fk, intravisit::FnKind::Closure));
|
||||||
intravisit::walk_fn_kind(self, fk);
|
intravisit::walk_fn_kind(self, fk);
|
||||||
self.visit_nested_body(body_id)
|
self.visit_nested_body(body_id)
|
||||||
|
@ -2492,13 +2492,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
hir_ty: Option<&hir::Ty<'_>>,
|
hir_ty: Option<&hir::Ty<'_>>,
|
||||||
) -> ty::PolyFnSig<'tcx> {
|
) -> ty::PolyFnSig<'tcx> {
|
||||||
let tcx = self.tcx();
|
let tcx = self.tcx();
|
||||||
let bound_vars = if let hir::FnRetTy::Return(ret_ty) = decl.output
|
let bound_vars = tcx.late_bound_vars(hir_id);
|
||||||
&& let hir::TyKind::InferDelegation(sig_id, _) = ret_ty.kind
|
|
||||||
{
|
|
||||||
tcx.fn_sig(sig_id).skip_binder().bound_vars()
|
|
||||||
} else {
|
|
||||||
tcx.late_bound_vars(hir_id)
|
|
||||||
};
|
|
||||||
debug!(?bound_vars);
|
debug!(?bound_vars);
|
||||||
|
|
||||||
// We proactively collect all the inferred type params to emit a single error per fn def.
|
// We proactively collect all the inferred type params to emit a single error per fn def.
|
||||||
|
18
tests/ui/delegation/ice-issue-122550.rs
Normal file
18
tests/ui/delegation/ice-issue-122550.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#![feature(fn_delegation)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
trait Trait {
|
||||||
|
fn description(&self) -> &str {}
|
||||||
|
//~^ ERROR mismatched types
|
||||||
|
}
|
||||||
|
|
||||||
|
struct F;
|
||||||
|
struct S(F);
|
||||||
|
|
||||||
|
impl S {
|
||||||
|
reuse <S as Trait>::description { &self.0 }
|
||||||
|
//~^ ERROR mismatched types
|
||||||
|
//~| ERROR the trait bound `S: Trait` is not satisfied
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
31
tests/ui/delegation/ice-issue-122550.stderr
Normal file
31
tests/ui/delegation/ice-issue-122550.stderr
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/ice-issue-122550.rs:5:35
|
||||||
|
|
|
||||||
|
LL | fn description(&self) -> &str {}
|
||||||
|
| ^^ expected `&str`, found `()`
|
||||||
|
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/ice-issue-122550.rs:13:39
|
||||||
|
|
|
||||||
|
LL | reuse <S as Trait>::description { &self.0 }
|
||||||
|
| ^^^^^^^ expected `&S`, found `&F`
|
||||||
|
|
|
||||||
|
= note: expected reference `&S`
|
||||||
|
found reference `&F`
|
||||||
|
|
||||||
|
error[E0277]: the trait bound `S: Trait` is not satisfied
|
||||||
|
--> $DIR/ice-issue-122550.rs:13:12
|
||||||
|
|
|
||||||
|
LL | reuse <S as Trait>::description { &self.0 }
|
||||||
|
| ^ the trait `Trait` is not implemented for `S`
|
||||||
|
|
|
||||||
|
help: this trait has no implementations, consider adding one
|
||||||
|
--> $DIR/ice-issue-122550.rs:4:1
|
||||||
|
|
|
||||||
|
LL | trait Trait {
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
Some errors have detailed explanations: E0277, E0308.
|
||||||
|
For more information about an error, try `rustc --explain E0277`.
|
Loading…
x
Reference in New Issue
Block a user