Skip to content

Commit 37686ed

Browse files
Add comments and assertions to tests
1 parent a549bbd commit 37686ed

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

src/test/ui/associated-types/issue-54182-1.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
// run-pass
22

3+
// Tests that the return type of trait methods is correctly normalized when
4+
// checking that a method in an impl matches the trait definition when the
5+
// return type involves a defaulted associated type.
6+
// ie. the trait has a method with return type `-> Self::R`, and `type R = ()`,
7+
// but the impl leaves out the return type (resulting in `()`).
8+
// Note that specialization is not involved in this test; no items in
9+
// implementations may be overridden. If they were, the normalization wouldn't
10+
// happen.
11+
312
#![feature(associated_type_defaults)]
413

514
macro_rules! overload {
@@ -12,20 +21,20 @@ macro_rules! overload {
1221
}
1322

1423
fn main() {
15-
let r = overload!(42, true);
16-
println!("-> {:?}", r);
24+
let r: () = overload!(42, true);
1725

18-
let r = overload!("Hello world", 13.0);
19-
println!("-> {:?}", r);
26+
let r: f32 = overload!("Hello world", 13.0);
27+
assert_eq!(r, 13.0);
2028

21-
let r = overload!(42, true, 42.5);
22-
println!("-> {:?}", r);
29+
let r: () = overload!(42, true, 42.5);
2330

24-
let r = overload!("Hello world", 13.0, 42);
25-
println!("-> {:?}", r);
31+
let r: i32 = overload!("Hello world", 13.0, 42);
32+
assert_eq!(r, 42);
2633
}
2734

2835
mod overload {
36+
/// This trait has an assoc. type defaulting to `()`, and a required method returning a value
37+
/// of that assoc. type.
2938
pub trait Overload {
3039
// type R;
3140
type R = ();
@@ -35,6 +44,10 @@ mod overload {
3544
// overloads for 2 args
3645
impl Overload for (i32, bool) {
3746
// type R = ();
47+
48+
/// This function has no return type specified, and so defaults to `()`.
49+
///
50+
/// This should work, but didn't, until RFC 2532 was implemented.
3851
fn overload(self) /*-> Self::R*/ {
3952
let (a, b) = self; // destructure args
4053
println!("i32 and bool {:?}", (a, b));

src/test/ui/associated-types/issue-54182-2.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
// compile-pass
22

3+
// Before RFC 2532, normalizing a defaulted assoc. type didn't work at all,
4+
// unless the impl in question overrides that type, which makes the default
5+
// pointless.
6+
37
#![feature(associated_type_defaults)]
48

59
trait Tr {

0 commit comments

Comments
 (0)