Skip to content

Commit aa0df3d

Browse files
committed
get the old error messages back
- added some old code that used ExplicitSelf::determine to check for eqtype with the expected self type in the simple cases - this fixes problems with error messages being worse in those cases, which caused some compile-fail tests to fail
1 parent d03eb2c commit aa0df3d

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/librustc_typeck/check/wfcheck.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,17 +491,40 @@ impl<'a, 'gcx> CheckTypeWellFormedVisitor<'a, 'gcx> {
491491
.help("consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`")
492492
.code("E0307".into())
493493
.emit();
494-
return
494+
break
495495
}
496496
}
497497

498-
if let ExplicitSelf::Other = ExplicitSelf::determine(fcx, fcx.param_env, self_ty, self_arg_ty) {
498+
let self_kind = ExplicitSelf::determine(fcx, fcx.param_env, self_ty, self_arg_ty);
499+
500+
if let ExplicitSelf::Other = self_kind {
499501
if !fcx.tcx.sess.features.borrow().arbitrary_self_types {
500502
feature_gate::feature_err(&fcx.tcx.sess.parse_sess, "arbitrary_self_types", span,
501503
GateIssue::Language, "arbitrary `self` types are unstable")
502504
.help("consider changing to `self`, `&self`, `&mut self`, or `self: Box<Self>`")
503505
.emit();
504-
return
506+
}
507+
} else {
508+
let rcvr_ty = match self_kind {
509+
ExplicitSelf::ByValue => self_ty,
510+
ExplicitSelf::ByReference(region, mutbl) => {
511+
fcx.tcx.mk_ref(region, ty::TypeAndMut {
512+
ty: self_ty,
513+
mutbl,
514+
})
515+
}
516+
ExplicitSelf::ByBox => fcx.tcx.mk_box(self_ty),
517+
ExplicitSelf::Other => unreachable!(),
518+
};
519+
let rcvr_ty = fcx.normalize_associated_types_in(span, &rcvr_ty);
520+
let rcvr_ty = fcx.liberate_late_bound_regions(method.def_id,
521+
&ty::Binder(rcvr_ty));
522+
523+
debug!("check_method_receiver: receiver ty = {:?}", rcvr_ty);
524+
525+
let cause = fcx.cause(span, ObligationCauseCode::MethodReceiver);
526+
if let Some(mut err) = fcx.demand_eqtype_with_origin(&cause, rcvr_ty, self_arg_ty) {
527+
err.emit();
505528
}
506529
}
507530
}

0 commit comments

Comments
 (0)