Skip to content

Commit 3857826

Browse files
committed
Run pass tests.
The happy kind of test.
1 parent bdda07b commit 3857826

16 files changed

+102
-187
lines changed

src/test/run-pass/default-ty-param-fallback/default_ty_param_fallback_trait_impl.rs

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/test/run-pass/default-ty-param-fallback/default_ty_param_fallback_trait_impl_simple.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/test/run-pass/default-ty-param-fallback/default_ty_param_fallback_type_alias.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/test/run-pass/default_ty_param_fallback_default_dependent_associated_type.rs renamed to src/test/run-pass/default-ty-param-fallback/dependent_associated_type.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ impl<A> Id for A {
2121
type This = A;
2222
}
2323

24-
struct Foo<X: Default = usize, Y = <X as Id>::This> {
24+
struct Foo<X, Y> {
2525
data: PhantomData<(X, Y)>
2626
}
2727

28-
impl<X: Default, Y> Foo<X, Y> {
28+
impl<X: Default = usize, Y = <X as Id>::This> Foo<X, Y> {
2929
fn new() -> Foo<X, Y> {
3030
Foo { data: PhantomData }
3131
}
3232
}
3333

3434
fn main() {
35-
let foo = Foo::new();
35+
let _ = Foo::new();
3636
}

src/test/run-pass/default_ty_param_fallback_dependent_defaults.rs renamed to src/test/run-pass/default-ty-param-fallback/dependent_defaults.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@
1212
#![feature(default_type_parameter_fallback)]
1313
use std::marker::PhantomData;
1414

15+
#[allow(dead_code)]
1516
struct Foo<T,U=T> { t: T, data: PhantomData<U> }
1617

18+
impl<T,U=T> Foo<T,U> {
19+
fn new(t: T) -> Foo<T,U> {
20+
Foo { t, data: PhantomData }
21+
}
22+
}
23+
1724
fn main() {
18-
let foo = Foo { t: 'a', data: PhantomData };
25+
let _ = Foo::new('a');
1926
}

src/test/run-pass/default_ty_param_fallback_trait_impl_simple.rs renamed to src/test/run-pass/default-ty-param-fallback/enum.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,22 @@
1010

1111
#![feature(default_type_parameter_fallback)]
1212

13-
// An example from the RFC
14-
trait Foo { fn takes_foo(&self); }
15-
trait Bar { }
13+
use std::path::Path;
1614

17-
impl<T:Bar=usize> Foo for Vec<T> {
18-
fn takes_foo(&self) {}
15+
enum Opt<T=String> {
16+
Som(T),
17+
Non,
1918
}
2019

21-
impl Bar for usize {}
22-
2320
fn main() {
24-
let x = Vec::new(); // x: Vec<$0>
25-
x.takes_foo(); // adds oblig Vec<$0> : Foo
21+
// Defaults on the type definiton work, as long no other params are interfering.
22+
let _ = Opt::Non;
23+
let _: Opt<_> = Opt::Non;
24+
25+
func1(None);
26+
func2(Opt::Non);
2627
}
28+
29+
// Defaults on fns take precedence.
30+
fn func1<P: AsRef<Path> = String>(p: Option<P>) { }
31+
fn func2<P: AsRef<Path> = String>(p: Opt<P>) { }

src/test/run-pass/default_ty_param_fallback_method_call_test.rs renamed to src/test/run-pass/default-ty-param-fallback/method_call.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ impl Foo {
1919
}
2020

2121
fn main() {
22-
let f = Foo.method();
23-
println!("{}", f);
22+
// Bug: Replacing with Foo.method::<_>() fails.
23+
// Suspicion: astconv and tycheck are considering this a "A provided type parameter.",
24+
// resulting in type_var_for_def not being called and a TypeInference var being created
25+
// rather than a TypeParameterDefinition var.
26+
let _ = Foo.method();
2427
}

src/test/run-pass/default_ty_param_fallback_struct.rs renamed to src/test/run-pass/default-ty-param-fallback/struct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ impl<A:Default=i32> Foo<A> {
1919
}
2020

2121
fn main() {
22-
let foo = Foo::new();
22+
let _ = Foo::new();
2323
}

src/test/run-pass/default_ty_param_fallback_trait_impl.rs renamed to src/test/run-pass/default-ty-param-fallback/trait_impl.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,30 @@
1010

1111
#![feature(default_type_parameter_fallback)]
1212

13-
// Another example from the RFC
13+
struct Vac<T>(Vec<T>);
14+
15+
impl<T=usize> Vac<T> {
16+
fn new() -> Self {
17+
Vac(Vec::new())
18+
}
19+
}
20+
1421
trait Foo { }
1522
trait Bar { }
1623

17-
impl<T:Bar=usize> Foo for Vec<T> {}
24+
impl<T:Bar=usize> Foo for Vac<T> {}
1825
impl Bar for usize {}
1926

20-
fn takes_foo<F:Foo>(f: F) {}
27+
fn takes_foo<F:Foo>(_: F) {}
2128

2229
fn main() {
23-
let x = Vec::new(); // x: Vec<$0>
24-
takes_foo(x); // adds oblig Vec<$0> : Foo
30+
let x = Vac::new(); // x: Vac<$0>
31+
// adds oblig Vac<$0> : Foo,
32+
// and applies the default of `impl<T> Vac<T>` and
33+
// `impl<T:Bar> Foo for Vac<T>`, which must agree.
34+
//
35+
// The default of F in takes_foo<F> makes no difference here,
36+
// because the corresponding inference var will be generalized
37+
// to Vac<_>.
38+
takes_foo(x);
2539
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
11+
#![feature(default_type_parameter_fallback)]
12+
13+
trait A<T = Self> {
14+
fn a(t: &T) -> Self;
15+
}
16+
17+
trait B<T = Self> {
18+
fn b(&self) -> T;
19+
}
20+
21+
impl<T = X> B<T> for X
22+
where T: A<X>
23+
{
24+
fn b(&self) -> T {
25+
T::a(self)
26+
}
27+
}
28+
29+
struct X(u8);
30+
31+
impl A for X {
32+
fn a(x: &X) -> X {
33+
X(x.0)
34+
}
35+
}
36+
37+
fn g(x: &X) {
38+
// Bug: replacing with `let x = X::b(x)` will cause `x` to be unknown in `x.0`.
39+
let x = <X as B>::b(x);
40+
x.0;
41+
}
42+
43+
fn main() {
44+
g(&X(0));
45+
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010

1111
#![feature(default_type_parameter_fallback)]
1212

13-
struct Foo;
13+
struct HeshMep<K, V, S=String>(Vec<K>, Vec<V>, S);
1414

15-
impl Foo {
16-
fn method<A:Default=String>(&self) -> A {
17-
A::default()
15+
impl<V, K=usize, S:Default=String> HeshMep<K, V, S> {
16+
fn new() -> HeshMep<K, V, S> {
17+
HeshMep(Vec::new(), Vec::new(), S::default())
1818
}
1919
}
2020

21+
type IntMap<K> = HeshMep<K, usize>;
22+
2123
fn main() {
22-
let f = Foo.method();
23-
println!("{}", f);
24+
let _ = IntMap::new();
2425
}

src/test/run-pass/default_ty_param_fallback_default_over_literal.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/test/run-pass/default_ty_param_fallback_ensure_normalization.rs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/test/run-pass/default_ty_param_fallback_struct_and_type_alias.rs

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/test/run-pass/default_ty_param_fallback_type_alias.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)