Skip to content

Commit ad1f492

Browse files
committed
Fixed crash
1 parent 25d9e08 commit ad1f492

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -799,17 +799,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
799799
/// Detect the following case
800800
///
801801
/// ```text
802-
/// fn change_object(mut a: &Ty) {
802+
/// fn change_object(mut b: &Ty) {
803803
/// let a = Ty::new();
804804
/// b = a;
805805
/// }
806806
/// ```
807807
///
808-
/// where the user likely meant to modify the value behind there reference, use `a` as an out
808+
/// where the user likely meant to modify the value behind there reference, use `b` as an out
809809
/// parameter, instead of mutating the local binding. When encountering this we suggest:
810810
///
811811
/// ```text
812-
/// fn change_object(a: &'_ mut Ty) {
812+
/// fn change_object(b: &'_ mut Ty) {
813813
/// let a = Ty::new();
814814
/// *b = a;
815815
/// }
@@ -823,6 +823,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
823823
if let Some(TypeError::Sorts(ExpectedFound { expected, found })) = error
824824
&& let ty::Ref(_, inner, hir::Mutability::Not) = expected.kind()
825825

826+
// Cannot use found in can_eq if it contains region variables that no longer exist.
827+
// Fixes #140823
828+
&& !found.has_infer_regions()
829+
826830
// The difference between the expected and found values is one level of borrowing.
827831
&& self.can_eq(self.param_env, *inner, found)
828832

0 commit comments

Comments
 (0)