about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAli MJ Al-Nasrawy <alimjalnasrawy@gmail.com>2023-12-17 06:08:24 +0000
committerAli MJ Al-Nasrawy <alimjalnasrawy@gmail.com>2023-12-17 07:31:07 +0000
commit8c215e7841c486f5f460d541bbc1773933266475 (patch)
tree926d6d1eafbf197f4e0726b8cab885d73645ebf1
parent9f7d0e91b528a19a9516df0f647a0191808e7227 (diff)
downloadrust-8c215e7841c486f5f460d541bbc1773933266475.tar.gz
rust-8c215e7841c486f5f460d541bbc1773933266475.zip
fix diagnostic regresssion
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs19
-rw-r--r--tests/ui/higher-ranked/trait-bounds/hrtb-perfect-forwarding.rs2
-rw-r--r--tests/ui/higher-ranked/trait-bounds/hrtb-perfect-forwarding.stderr14
-rw-r--r--tests/ui/lifetimes/issue-79187-2.stderr18
4 files changed, 21 insertions, 32 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs
index 924e68fa91d..60dbf7dc055 100644
--- a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs
@@ -408,13 +408,18 @@ fn try_extract_error_from_region_constraints<'tcx>(
     mut region_var_origin: impl FnMut(RegionVid) -> RegionVariableOrigin,
     mut universe_of_region: impl FnMut(RegionVid) -> UniverseIndex,
 ) -> Option<DiagnosticBuilder<'tcx, ErrorGuaranteed>> {
+    let placeholder_universe = match placeholder_region.kind() {
+        ty::RePlaceholder(p) => p.universe,
+        ty::ReVar(vid) => universe_of_region(vid),
+        _ => ty::UniverseIndex::ROOT,
+    };
     let matches =
         |a_region: Region<'tcx>, b_region: Region<'tcx>| match (a_region.kind(), b_region.kind()) {
             (RePlaceholder(a_p), RePlaceholder(b_p)) => a_p.bound == b_p.bound,
             _ => a_region == b_region,
         };
-    let check = |constraint: &Constraint<'tcx>, cause: &SubregionOrigin<'tcx>, exact| {
-        match *constraint {
+    let mut check =
+        |constraint: &Constraint<'tcx>, cause: &SubregionOrigin<'tcx>, exact| match *constraint {
             Constraint::RegSubReg(sub, sup)
                 if ((exact && sup == placeholder_region)
                     || (!exact && matches(sup, placeholder_region)))
@@ -422,16 +427,16 @@ fn try_extract_error_from_region_constraints<'tcx>(
             {
                 Some((sub, cause.clone()))
             }
-            // FIXME: Should this check the universe of the var?
             Constraint::VarSubReg(vid, sup)
-                if ((exact && sup == placeholder_region)
-                    || (!exact && matches(sup, placeholder_region))) =>
+                if (exact
+                    && sup == placeholder_region
+                    && !universe_of_region(vid).can_name(placeholder_universe))
+                    || (!exact && matches(sup, placeholder_region)) =>
             {
                 Some((ty::Region::new_var(infcx.tcx, vid), cause.clone()))
             }
             _ => None,
-        }
-    };
+        };
     let mut info = region_constraints
         .constraints
         .iter()
diff --git a/tests/ui/higher-ranked/trait-bounds/hrtb-perfect-forwarding.rs b/tests/ui/higher-ranked/trait-bounds/hrtb-perfect-forwarding.rs
index 07befeff43c..d45fa183c0c 100644
--- a/tests/ui/higher-ranked/trait-bounds/hrtb-perfect-forwarding.rs
+++ b/tests/ui/higher-ranked/trait-bounds/hrtb-perfect-forwarding.rs
@@ -41,7 +41,7 @@ where
     // isize>`, we require `T : for<'a> Bar<&'a isize>`, but the where
     // clause only specifies `T : Bar<&'b isize>`.
     foo_hrtb_bar_not(&mut t);
-    //~^ ERROR mismatched types
+    //~^ ERROR implementation of `Bar` is not general enough
     //~^^ ERROR lifetime may not live long enough
 }
 
diff --git a/tests/ui/higher-ranked/trait-bounds/hrtb-perfect-forwarding.stderr b/tests/ui/higher-ranked/trait-bounds/hrtb-perfect-forwarding.stderr
index 14a80630f40..727b9e6bec8 100644
--- a/tests/ui/higher-ranked/trait-bounds/hrtb-perfect-forwarding.stderr
+++ b/tests/ui/higher-ranked/trait-bounds/hrtb-perfect-forwarding.stderr
@@ -53,19 +53,14 @@ note: due to current limitations in the borrow checker, this implies a `'static`
 LL |     T: for<'a> Foo<&'a isize> + Bar<&'b isize>,
    |        ^^^^^^^^^^^^^^^^^^^^^^
 
-error[E0308]: mismatched types
+error: implementation of `Bar` is not general enough
   --> $DIR/hrtb-perfect-forwarding.rs:43:5
    |
 LL |     foo_hrtb_bar_not(&mut t);
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Bar` is not general enough
    |
-   = note: expected trait `for<'a> <T as Foo<&'a isize>>`
-              found trait `for<'a> <T as Foo<&'a isize>>`
-note: the lifetime requirement is introduced here
-  --> $DIR/hrtb-perfect-forwarding.rs:37:8
-   |
-LL |     T: for<'a> Foo<&'a isize> + Bar<&'b isize>,
-   |        ^^^^^^^^^^^^^^^^^^^^^^
+   = note: `T` must implement `Bar<&'0 isize>`, for any lifetime `'0`...
+   = note: ...but it actually implements `Bar<&'1 isize>`, for some specific lifetime `'1`
 
 warning: function cannot return without recursing
   --> $DIR/hrtb-perfect-forwarding.rs:48:1
@@ -82,4 +77,3 @@ LL |       foo_hrtb_bar_hrtb(&mut t);
 
 error: aborting due to 2 previous errors; 4 warnings emitted
 
-For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/lifetimes/issue-79187-2.stderr b/tests/ui/lifetimes/issue-79187-2.stderr
index 0b7593f01c6..e8115bb6b06 100644
--- a/tests/ui/lifetimes/issue-79187-2.stderr
+++ b/tests/ui/lifetimes/issue-79187-2.stderr
@@ -54,13 +54,8 @@ error[E0308]: mismatched types
 LL |     take_foo(|a: &i32| a);
    |     ^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
    |
-   = note: expected trait `for<'a> <{closure@$DIR/issue-79187-2.rs:11:14: 11:23} as FnOnce<(&'a i32,)>>`
-              found trait `for<'a> <{closure@$DIR/issue-79187-2.rs:11:14: 11:23} as FnOnce<(&'a i32,)>>`
-note: this closure does not fulfill the lifetime requirements
-  --> $DIR/issue-79187-2.rs:11:14
-   |
-LL |     take_foo(|a: &i32| a);
-   |              ^^^^^^^^^
+   = note: expected reference `&_`
+              found reference `&_`
 note: the lifetime requirement is introduced here
   --> $DIR/issue-79187-2.rs:5:21
    |
@@ -73,13 +68,8 @@ error[E0308]: mismatched types
 LL |     take_foo(|a: &i32| -> &i32 { a });
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
    |
-   = note: expected trait `for<'a> <{closure@$DIR/issue-79187-2.rs:14:14: 14:31} as FnOnce<(&'a i32,)>>`
-              found trait `for<'a> <{closure@$DIR/issue-79187-2.rs:14:14: 14:31} as FnOnce<(&'a i32,)>>`
-note: this closure does not fulfill the lifetime requirements
-  --> $DIR/issue-79187-2.rs:14:14
-   |
-LL |     take_foo(|a: &i32| -> &i32 { a });
-   |              ^^^^^^^^^^^^^^^^^
+   = note: expected reference `&_`
+              found reference `&_`
 note: the lifetime requirement is introduced here
   --> $DIR/issue-79187-2.rs:5:21
    |