Skip to content

Commit

Permalink
Auto merge of rust-lang#85090 - Aaron1011:type-outlives-global, r=mat…
Browse files Browse the repository at this point in the history
…thewjasper,jackh726

Return `EvaluatedToOk` when type in outlives predicate is global

A global type doesn't reference any local regions or types, so it's
guaranteed to outlive any region.
  • Loading branch information
bors committed Jul 3, 2021
2 parents 71b8742 + 1f7cb16 commit d34a3a4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
10 changes: 9 additions & 1 deletion compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,15 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
None => Ok(EvaluatedToAmbig),
},

ty::PredicateKind::TypeOutlives(..) | ty::PredicateKind::RegionOutlives(..) => {
ty::PredicateKind::TypeOutlives(pred) => {
if pred.0.is_global() {
Ok(EvaluatedToOk)
} else {
Ok(EvaluatedToOkModuloRegions)
}
}

ty::PredicateKind::RegionOutlives(..) => {
// We do not consider region relationships when evaluating trait matches.
Ok(EvaluatedToOkModuloRegions)
}
Expand Down
18 changes: 9 additions & 9 deletions src/test/ui/traits/issue-83538-tainted-cache-after-cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub struct Second {
d: Vec<First>,
}

struct Third<f> {
g: Vec<f>,
struct Third<'a, f> {
g: Vec<(f, &'a f)>,
}

enum Ty {
Expand All @@ -38,29 +38,29 @@ struct Sixth {
}

#[rustc_evaluate_where_clauses]
fn forward()
fn forward<'a>()
where
Vec<First>: Unpin,
Third<Ty>: Unpin,
Third<'a, Ty>: Unpin,
{
}

#[rustc_evaluate_where_clauses]
fn reverse()
fn reverse<'a>()
where
Third<Ty>: Unpin,
Third<'a, Ty>: Unpin,
Vec<First>: Unpin,
{
}

fn main() {
// Key is that Vec<First> is "ok" and Third<Ty> is "ok modulo regions":
// Key is that Vec<First> is "ok" and Third<'_, Ty> is "ok modulo regions":

forward();
//~^ ERROR evaluate(Binder(TraitPredicate(<std::vec::Vec<First> as std::marker::Unpin>), [])) = Ok(EvaluatedToOk)
//~| ERROR evaluate(Binder(TraitPredicate(<Third<Ty> as std::marker::Unpin>), [])) = Ok(EvaluatedToOkModuloRegions)
//~| ERROR evaluate(Binder(TraitPredicate(<Third<'_, Ty> as std::marker::Unpin>), [])) = Ok(EvaluatedToOkModuloRegions)

reverse();
//~^ ERROR evaluate(Binder(TraitPredicate(<std::vec::Vec<First> as std::marker::Unpin>), [])) = Ok(EvaluatedToOk)
//~| ERROR evaluate(Binder(TraitPredicate(<Third<Ty> as std::marker::Unpin>), [])) = Ok(EvaluatedToOkModuloRegions)
//~| ERROR evaluate(Binder(TraitPredicate(<Third<'_, Ty> as std::marker::Unpin>), [])) = Ok(EvaluatedToOkModuloRegions)
}
12 changes: 6 additions & 6 deletions src/test/ui/traits/issue-83538-tainted-cache-after-cycle.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ LL | Vec<First>: Unpin,
LL | forward();
| ^^^^^^^

error: evaluate(Binder(TraitPredicate(<Third<Ty> as std::marker::Unpin>), [])) = Ok(EvaluatedToOkModuloRegions)
error: evaluate(Binder(TraitPredicate(<Third<'_, Ty> as std::marker::Unpin>), [])) = Ok(EvaluatedToOkModuloRegions)
--> $DIR/issue-83538-tainted-cache-after-cycle.rs:59:5
|
LL | Third<Ty>: Unpin,
| ----- predicate
LL | Third<'a, Ty>: Unpin,
| ----- predicate
...
LL | forward();
| ^^^^^^^

error: evaluate(Binder(TraitPredicate(<Third<Ty> as std::marker::Unpin>), [])) = Ok(EvaluatedToOkModuloRegions)
error: evaluate(Binder(TraitPredicate(<Third<'_, Ty> as std::marker::Unpin>), [])) = Ok(EvaluatedToOkModuloRegions)
--> $DIR/issue-83538-tainted-cache-after-cycle.rs:63:5
|
LL | Third<Ty>: Unpin,
| ----- predicate
LL | Third<'a, Ty>: Unpin,
| ----- predicate
...
LL | reverse();
| ^^^^^^^
Expand Down

0 comments on commit d34a3a4

Please sign in to comment.