Skip to content

Return EvaluatedToOk when type in outlives predicate is global #85090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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