2019-05-01 12:10:01 -05:00
|
|
|
// Test that we properly detect the cycle amongst the traits
|
|
|
|
// here and report an error.
|
|
|
|
|
|
|
|
use std::panic::RefUnwindSafe;
|
|
|
|
|
|
|
|
trait Database {
|
|
|
|
type Storage;
|
|
|
|
}
|
|
|
|
trait HasQueryGroup {}
|
|
|
|
trait Query<DB> {
|
|
|
|
type Data;
|
|
|
|
}
|
|
|
|
trait SourceDatabase {
|
|
|
|
fn parse(&self) {
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ParseQuery;
|
|
|
|
struct RootDatabase {
|
|
|
|
_runtime: Runtime<RootDatabase>,
|
|
|
|
}
|
|
|
|
struct Runtime<DB: Database> {
|
|
|
|
_storage: Box<DB::Storage>,
|
|
|
|
}
|
|
|
|
struct SalsaStorage {
|
2020-07-24 15:59:43 -05:00
|
|
|
_parse: <ParseQuery as Query<RootDatabase>>::Data,
|
2021-08-27 17:34:48 -05:00
|
|
|
//~^ ERROR overflow
|
2019-05-01 12:10:01 -05:00
|
|
|
}
|
|
|
|
|
2019-10-10 18:20:42 -05:00
|
|
|
impl Database for RootDatabase {
|
2020-06-27 15:36:35 -05:00
|
|
|
// This would also be an error if we didn't abort compilation on the error
|
|
|
|
// above.
|
|
|
|
type Storage = SalsaStorage;
|
2019-05-01 12:10:01 -05:00
|
|
|
}
|
|
|
|
impl HasQueryGroup for RootDatabase {}
|
|
|
|
impl<DB> Query<DB> for ParseQuery
|
|
|
|
where
|
|
|
|
DB: SourceDatabase,
|
|
|
|
DB: Database,
|
|
|
|
{
|
|
|
|
type Data = RootDatabase;
|
|
|
|
}
|
|
|
|
impl<T> SourceDatabase for T
|
|
|
|
where
|
|
|
|
T: RefUnwindSafe,
|
|
|
|
T: HasQueryGroup,
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn goto_implementation(db: &RootDatabase) -> u32 {
|
|
|
|
// This is not satisfied:
|
|
|
|
//
|
|
|
|
// - `RootDatabase: SourceDatabase`
|
|
|
|
// - requires `RootDatabase: RefUnwindSafe` + `RootDatabase: HasQueryGroup`
|
|
|
|
// - `RootDatabase: RefUnwindSafe`
|
|
|
|
// - requires `Runtime<RootDatabase>: RefUnwindSafe`
|
|
|
|
// - `Runtime<RootDatabase>: RefUnwindSafe`
|
|
|
|
// - requires `DB::Storage: RefUnwindSafe` (`SalsaStorage: RefUnwindSafe`)
|
|
|
|
// - `SalsaStorage: RefUnwindSafe`
|
|
|
|
// - requires `<ParseQuery as Query<RootDatabase>>::Data: RefUnwindSafe`,
|
|
|
|
// which means `ParseQuery: Query<RootDatabase>`
|
|
|
|
// - `ParseQuery: Query<RootDatabase>`
|
|
|
|
// - requires `RootDatabase: SourceDatabase`,
|
|
|
|
// - `RootDatabase: SourceDatabase` is already on the stack, so we have a
|
|
|
|
// cycle with non-coinductive participants
|
|
|
|
//
|
|
|
|
// we used to fail to report an error here because we got the
|
|
|
|
// caching wrong.
|
|
|
|
SourceDatabase::parse(db);
|
|
|
|
22
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {}
|