/src/test/compile-fail/issue-22638.rs

https://gitlab.com/jianglu/rust · Rust · 69 lines · 48 code · 11 blank · 10 comment · 1 complexity · 4ab2f3e492163b50cf05f055013ce85c MD5 · raw file

  1. // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
  2. // file at the top-level directory of this distribution and at
  3. // http://rust-lang.org/COPYRIGHT.
  4. //
  5. // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  6. // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  7. // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
  8. // option. This file may not be copied, modified, or distributed
  9. // except according to those terms.
  10. #![allow(unused)]
  11. #![recursion_limit = "20"]
  12. #![type_length_limit = "20000000"]
  13. #![crate_type = "rlib"]
  14. #[derive(Clone)]
  15. struct A (B);
  16. impl A {
  17. pub fn matches<F: Fn()>(&self, f: &F) {
  18. let &A(ref term) = self;
  19. term.matches(f);
  20. }
  21. }
  22. #[derive(Clone)]
  23. enum B {
  24. Variant1,
  25. Variant2(C),
  26. }
  27. impl B {
  28. pub fn matches<F: Fn()>(&self, f: &F) {
  29. match self {
  30. &B::Variant2(ref factor) => {
  31. factor.matches(&|| ())
  32. }
  33. _ => unreachable!("")
  34. }
  35. }
  36. }
  37. #[derive(Clone)]
  38. struct C (D);
  39. impl C {
  40. pub fn matches<F: Fn()>(&self, f: &F) {
  41. let &C(ref base) = self;
  42. base.matches(&|| {
  43. C(base.clone()).matches(f)
  44. })
  45. }
  46. }
  47. #[derive(Clone)]
  48. struct D (Box<A>);
  49. impl D {
  50. pub fn matches<F: Fn()>(&self, f: &F) {
  51. //~^ ERROR reached the type-length limit while instantiating `D::matches::<[closure
  52. let &D(ref a) = self;
  53. a.matches(f)
  54. }
  55. }
  56. pub fn matches() {
  57. A(B::Variant1).matches(&(|| ()))
  58. }