Comprehence cycle detection in collect. In some cases, the cycles we

report are not *necessary* cycles, but we'll work on refactoring them
over time. This overlaps with the cycle detection that astconv already
does: I left that code in because it gives a more targeted error
message, though perhaps less helpful in that it doesn't give the full
details of the cycle.
This commit is contained in:
Niko Matsakis 2015-02-17 17:11:01 -05:00
parent 15ef2c2e6b
commit 0d9e473be9
8 changed files with 280 additions and 66 deletions

View file

@ -0,0 +1,19 @@
// Copyright 2015 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 #15477. This test should pass, vs reporting an
// error as it does now, but at least this test shows it doesn't
// segfault.
trait Chromosome<X: Chromosome> {
//~^ ERROR cyclic reference detected
}
fn main() { }

View file

@ -0,0 +1,17 @@
// Copyright 2015 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.
// Test a supertrait cycle where a trait extends itself.
trait Chromosome: Chromosome {
//~^ ERROR cyclic reference detected
}
fn main() { }

View file

@ -0,0 +1,22 @@
// Copyright 2015 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.
// Test a supertrait cycle where the first trait we find (`A`) is not
// a direct participant in the cycle.
trait A: B {
}
trait B: C { }
//~^ ERROR cyclic reference detected
trait C: B { }
fn main() { }

View file

@ -0,0 +1,23 @@
// Copyright 2015 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.
// Test a supertrait cycle where a trait extends itself.
trait Chromosome: Get<Struct> {
//~^ ERROR cyclic reference detected
}
trait Get<A> {
fn get(&self) -> A;
}
struct Struct<C:Chromosome> { c: C }
fn main() { }