Skip to content

Commit 9248500

Browse files
authored
Unrolled build for rust-lang#121743
Rollup merge of rust-lang#121743 - compiler-errors:opportunistically-resolve-regions, r=jackh726 Opportunistically resolve regions when processing region outlives obligations Due to the matching in `TypeOutlives` being structural, we should attempt to opportunistically resolve regions before processing region obligations. Thanks ``@lcnr`` for finding this. r? lcnr
2 parents c475e23 + 5cdbe83 commit 9248500

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

compiler/rustc_infer/src/infer/outlives/obligations.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,17 @@
6262
use crate::infer::outlives::components::{push_outlives_components, Component};
6363
use crate::infer::outlives::env::RegionBoundPairs;
6464
use crate::infer::outlives::verify::VerifyBoundCx;
65+
use crate::infer::resolve::OpportunisticRegionResolver;
6566
use crate::infer::{
6667
self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, UndoLog, VerifyBound,
6768
};
6869
use crate::traits::{ObligationCause, ObligationCauseCode};
6970
use rustc_data_structures::undo_log::UndoLogs;
7071
use rustc_middle::mir::ConstraintCategory;
7172
use rustc_middle::traits::query::NoSolution;
72-
use rustc_middle::ty::{self, GenericArgsRef, Region, Ty, TyCtxt, TypeVisitableExt};
73+
use rustc_middle::ty::{
74+
self, GenericArgsRef, Region, Ty, TyCtxt, TypeFoldable as _, TypeVisitableExt,
75+
};
7376
use rustc_middle::ty::{GenericArgKind, PolyTypeOutlivesPredicate};
7477
use rustc_span::DUMMY_SP;
7578
use smallvec::smallvec;
@@ -176,6 +179,11 @@ impl<'tcx> InferCtxt<'tcx> {
176179
.map_err(|NoSolution| (outlives, origin.clone()))?
177180
.no_bound_vars()
178181
.expect("started with no bound vars, should end with no bound vars");
182+
// `TypeOutlives` is structural, so we should try to opportunistically resolve all
183+
// region vids before processing regions, so we have a better chance to match clauses
184+
// in our param-env.
185+
let (sup_type, sub_region) =
186+
(sup_type, sub_region).fold_with(&mut OpportunisticRegionResolver::new(self));
179187

180188
debug!(?sup_type, ?sub_region, ?origin);
181189

tests/ui/implied-bounds/impl-implied-bounds-compatibility.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub trait MessageListenersInterface {
1010

1111
impl<'a> MessageListenersInterface for MessageListeners<'a> {
1212
fn listeners<'b>(&'b self) -> &'a MessageListeners<'b> {
13-
//~^ ERROR cannot infer an appropriate lifetime for lifetime parameter 'b in generic type due to conflicting requirements
13+
//~^ ERROR in type `&'a MessageListeners<'_>`, reference has a longer lifetime than the data it references
1414
self
1515
}
1616
}
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,20 @@
1-
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter 'b in generic type due to conflicting requirements
1+
error[E0491]: in type `&'a MessageListeners<'_>`, reference has a longer lifetime than the data it references
22
--> $DIR/impl-implied-bounds-compatibility.rs:12:5
33
|
44
LL | fn listeners<'b>(&'b self) -> &'a MessageListeners<'b> {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
note: first, the lifetime cannot outlive the lifetime `'c` as defined here...
8-
--> $DIR/impl-implied-bounds-compatibility.rs:12:5
9-
|
10-
LL | fn listeners<'b>(&'b self) -> &'a MessageListeners<'b> {
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
note: ...so that the method type is compatible with trait
13-
--> $DIR/impl-implied-bounds-compatibility.rs:12:5
14-
|
15-
LL | fn listeners<'b>(&'b self) -> &'a MessageListeners<'b> {
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17-
= note: expected `fn(&'c MessageListeners<'_>) -> &'c MessageListeners<'c>`
18-
found `fn(&MessageListeners<'_>) -> &'a MessageListeners<'_>`
19-
note: but, the lifetime must be valid for the lifetime `'a` as defined here...
7+
note: the pointer is valid for the lifetime `'a` as defined here
208
--> $DIR/impl-implied-bounds-compatibility.rs:11:6
219
|
2210
LL | impl<'a> MessageListenersInterface for MessageListeners<'a> {
2311
| ^^
24-
note: ...so that the reference type `&'a MessageListeners<'_>` does not outlive the data it points at
12+
note: but the referenced data is only valid for the lifetime `'c` as defined here
2513
--> $DIR/impl-implied-bounds-compatibility.rs:12:5
2614
|
2715
LL | fn listeners<'b>(&'b self) -> &'a MessageListeners<'b> {
2816
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2917

3018
error: aborting due to 1 previous error
3119

32-
For more information about this error, try `rustc --explain E0495`.
20+
For more information about this error, try `rustc --explain E0491`.

0 commit comments

Comments
 (0)