Skip to content

Commit

Permalink
adding fixes for compile-fail test
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurikholkar committed Oct 9, 2017
1 parent 00504f2 commit cb0d746
Showing 1 changed file with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ use std::marker::PhantomData;

struct Type<'a> {
// Invariant
data: PhantomData<fn(&'a u32) -> &'a u32>
data: PhantomData<fn(&'a u32) -> &'a u32>,
}

fn foo<'a>() -> Type<'a> { loop { } }
fn foo<'a>() -> Type<'a> {
loop {}
}

fn bar<T>(t: T, x: T::Output) -> T::Output
where T: FnOnce<()>
Expand All @@ -36,36 +38,36 @@ fn bar<T>(t: T, x: T::Output) -> T::Output
}

#[cfg(ok)] // two instantiations: OK
fn baz<'a,'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
fn baz<'a, 'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
let a = bar(foo, x);
let b = bar(foo, y);
(a, b)
}

#[cfg(oneuse)] // one instantiation: BAD
fn baz<'a,'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
let f = foo; // <-- No consistent type can be inferred for `f` here.
let a = bar(f, x);
let b = bar(f, y);
(a, b)
//[oneuse]~^ ERROR 50:5: 50:6: lifetime mismatch [E0623]
fn baz<'a, 'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
let f = foo; // <-- No consistent type can be inferred for `f` here.
let a = bar(f, x);
let b = bar(f, y);
(a, b)
//[oneuse]~^ ERROR E0623
}

#[cfg(transmute)] // one instantiations: BAD
fn baz<'a,'b>(x: Type<'a>) -> Type<'static> {
// Cannot instantiate `foo` with any lifetime other than `'a`,
// since it is provided as input.
fn baz<'a, 'b>(x: Type<'a>) -> Type<'static> {
// Cannot instantiate `foo` with any lifetime other than `'a`,
// since it is provided as input.

bar(foo, x) //[transmute]~ ERROR E0495
bar(foo, x) //[transmute]~ ERROR E0495
}

#[cfg(krisskross)] // two instantiations, mixing and matching: BAD
fn transmute<'a,'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
let a = bar(foo, y); //[krisskross]~ ERROR 64:21: 64:22: lifetime mismatch [E0623]
let b = bar(foo, x);
(a, b) //[krisskross]~ ERROR 66:8: 66:9: lifetime mismatch [E0623]
fn transmute<'a, 'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
let a = bar(foo, y);
let b = bar(foo, x);
(a, b) //[krisskross]~ ERROR E0623
}

#[rustc_error]
fn main() { }
fn main() {}
//[ok]~^ ERROR compilation successful

0 comments on commit cb0d746

Please sign in to comment.