-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #53580 - nikomatsakis:nll-issue-53568, r=pnkfelix
fix NLL ICEs Custom type-ops reuse some of the query machinery -- but while query results are canonicalized after they are constructed, custom type ops are not, and hence we have to resolve the type variables to avoid an ICE here. Also, use the type-op machinery for implied outlives bounds. Fixes #53568 Fixes #52992 Fixes #53680
- Loading branch information
Showing
8 changed files
with
211 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/librustc/traits/query/type_op/implied_outlives_bounds.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use infer::canonical::{Canonical, Canonicalized, CanonicalizedQueryResult, QueryResult}; | ||
use traits::query::outlives_bounds::OutlivesBound; | ||
use traits::query::Fallible; | ||
use ty::{ParamEnvAnd, Ty, TyCtxt}; | ||
|
||
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] | ||
pub struct ImpliedOutlivesBounds<'tcx> { | ||
pub ty: Ty<'tcx>, | ||
} | ||
|
||
impl<'tcx> ImpliedOutlivesBounds<'tcx> { | ||
pub fn new(ty: Ty<'tcx>) -> Self { | ||
ImpliedOutlivesBounds { ty } | ||
} | ||
} | ||
|
||
impl<'gcx: 'tcx, 'tcx> super::QueryTypeOp<'gcx, 'tcx> for ImpliedOutlivesBounds<'tcx> { | ||
type QueryResult = Vec<OutlivesBound<'tcx>>; | ||
|
||
fn try_fast_path( | ||
_tcx: TyCtxt<'_, 'gcx, 'tcx>, | ||
_key: &ParamEnvAnd<'tcx, Self>, | ||
) -> Option<Self::QueryResult> { | ||
None | ||
} | ||
|
||
fn perform_query( | ||
tcx: TyCtxt<'_, 'gcx, 'tcx>, | ||
canonicalized: Canonicalized<'gcx, ParamEnvAnd<'tcx, Self>>, | ||
) -> Fallible<CanonicalizedQueryResult<'gcx, Self::QueryResult>> { | ||
// FIXME the query should take a `ImpliedOutlivesBounds` | ||
let Canonical { | ||
variables, | ||
value: | ||
ParamEnvAnd { | ||
param_env, | ||
value: ImpliedOutlivesBounds { ty }, | ||
}, | ||
} = canonicalized; | ||
let canonicalized = Canonical { | ||
variables, | ||
value: param_env.and(ty), | ||
}; | ||
|
||
tcx.implied_outlives_bounds(canonicalized) | ||
} | ||
|
||
fn shrink_to_tcx_lifetime( | ||
v: &'a CanonicalizedQueryResult<'gcx, Self::QueryResult>, | ||
) -> &'a Canonical<'tcx, QueryResult<'tcx, Self::QueryResult>> { | ||
v | ||
} | ||
} | ||
|
||
BraceStructTypeFoldableImpl! { | ||
impl<'tcx> TypeFoldable<'tcx> for ImpliedOutlivesBounds<'tcx> { | ||
ty, | ||
} | ||
} | ||
|
||
BraceStructLiftImpl! { | ||
impl<'a, 'tcx> Lift<'tcx> for ImpliedOutlivesBounds<'a> { | ||
type Lifted = ImpliedOutlivesBounds<'tcx>; | ||
ty, | ||
} | ||
} | ||
|
||
impl_stable_hash_for! { | ||
struct ImpliedOutlivesBounds<'tcx> { ty } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Regression test for an NLL-related ICE (#52992) -- computing | ||
// implied bounds was causing outlives relations that were not | ||
// properly handled. | ||
// | ||
// compile-pass | ||
|
||
#![feature(nll)] | ||
|
||
fn main() {} | ||
|
||
fn fail<'a>() -> Struct<'a, Generic<()>> { | ||
Struct(&Generic(())) | ||
} | ||
|
||
struct Struct<'a, T>(&'a T) where | ||
T: Trait + 'a, | ||
T::AT: 'a; // only fails with this bound | ||
|
||
struct Generic<T>(T); | ||
|
||
trait Trait { | ||
type AT; | ||
} | ||
|
||
impl<T> Trait for Generic<T> { | ||
type AT = T; // only fails with a generic AT | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Regression test for an NLL-related ICE (#53568) -- we failed to | ||
// resolve inference variables in "custom type-ops". | ||
// | ||
// compile-pass | ||
|
||
#![feature(nll)] | ||
#![allow(dead_code)] | ||
|
||
trait Future { | ||
type Item; | ||
} | ||
|
||
impl<F, T> Future for F | ||
where F: Fn() -> T | ||
{ | ||
type Item = T; | ||
} | ||
|
||
trait Connect {} | ||
|
||
struct Connector<H> { | ||
handler: H, | ||
} | ||
|
||
impl<H, T> Connect for Connector<H> | ||
where | ||
T: 'static, | ||
H: Future<Item = T> | ||
{ | ||
} | ||
|
||
struct Client<C> { | ||
connector: C, | ||
} | ||
|
||
fn build<C>(_connector: C) -> Client<C> { | ||
unimplemented!() | ||
} | ||
|
||
fn client<H>(handler: H) -> Client<impl Connect> | ||
where H: Fn() + Copy | ||
{ | ||
let connector = Connector { | ||
handler, | ||
}; | ||
let client = build(connector); | ||
client | ||
} | ||
|
||
fn main() { } | ||
|