Skip to content

Commit 91da0cc

Browse files
committed
Refactor tests.
Make test more focused, and clarify what the bug is. Add new ui test.
1 parent 423de71 commit 91da0cc

File tree

3 files changed

+62
-19
lines changed

3 files changed

+62
-19
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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 B<T> {
14+
fn b(&self) -> T;
15+
}
16+
17+
impl<T = X> B<T> for X
18+
where T: Default
19+
{
20+
fn b(&self) -> T {
21+
T::default()
22+
}
23+
}
24+
25+
#[derive(Copy, Clone, Default)]
26+
struct X(u8);
27+
28+
fn main() {
29+
let x = X(0);
30+
let y = x.b();
31+
foo(y);
32+
// Uncommenting the following line makes the fallback fail.
33+
// Probably we are creating a new inference var,
34+
// that is carrying over the origin but not the value of the default.
35+
// x.0;
36+
}
37+
38+
fn foo<T = X>(a: T) -> T {
39+
a
40+
}

src/test/run-pass/default-ty-param-fallback/trait_impl_with_param_in_trait.rs renamed to src/test/ui/default-ty-param-fallback/trait_impl_param_in_trait.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,31 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10+
// compile-flags: --error-format=human
1011

1112
#![feature(default_type_parameter_fallback)]
1213

13-
trait A<T = Self> {
14-
fn a(t: &T) -> Self;
15-
}
16-
17-
trait B<T = Self> {
14+
trait B<T> {
1815
fn b(&self) -> T;
1916
}
2017

2118
impl<T = X> B<T> for X
22-
where T: A<X>
19+
where T: Default
2320
{
2421
fn b(&self) -> T {
25-
T::a(self)
22+
T::default()
2623
}
2724
}
2825

26+
#[derive(Copy, Clone, Default)]
2927
struct X(u8);
3028

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;
29+
fn main() {
30+
let x = X(0);
31+
let y = x.b();
32+
foo(y);
4133
}
4234

43-
fn main() {
44-
g(&X(0));
35+
fn foo<T = u32>(a: T) -> T {
36+
a
4537
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/trait_impl_param_in_trait.rs:31:9
3+
|
4+
31 | let y = x.b();
5+
| ^
6+
| |
7+
| cannot infer type for `_`
8+
| consider giving `y` a type
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)