PageRenderTime 57ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/compile-fail/regions-early-bound-error.rs

https://github.com/paulstansifer/rust
Rust | 38 lines | 16 code | 6 blank | 16 comment | 1 complexity | f51233d1fc27fdfc0e06fbd8c93c9852 MD5 | raw file
Possible License(s): 0BSD, Apache-2.0, MIT, AGPL-1.0
  1. // Copyright 2012 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. // Tests that you can use a fn lifetime parameter as part of
  11. // the value for a type parameter in a bound.
  12. trait GetRef<'a, T> {
  13. fn get(&self) -> &'a T;
  14. }
  15. struct Box<'a, T:'a> {
  16. t: &'a T
  17. }
  18. impl<'a,T:Clone> GetRef<'a,T> for Box<'a,T> {
  19. fn get(&self) -> &'a T {
  20. self.t
  21. }
  22. }
  23. fn get<'a,'b,G:GetRef<'a, isize>>(g1: G, b: &'b isize) -> &'b isize {
  24. g1.get()
  25. //~^ ERROR cannot infer an appropriate lifetime for automatic coercion due to
  26. //~| ERROR mismatched types
  27. //~| expected `&'b isize`
  28. //~| found `&'a isize`
  29. //~| lifetime mismatch
  30. }
  31. fn main() {
  32. }