Skip to content

Commit 4b18085

Browse files
committed
add dyn to display of dynamic (trait) type names
The `dyn Trait` syntax was stabilized in 199ee32. Resolves #49277.
1 parent 8fb1180 commit 4b18085

File tree

57 files changed

+143
-139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+143
-139
lines changed

src/librustc/util/ppaux.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,10 +1062,14 @@ define_print! {
10621062
TyParam(ref param_ty) => write!(f, "{}", param_ty),
10631063
TyAdt(def, substs) => cx.parameterized(f, substs, def.did, &[]),
10641064
TyDynamic(data, r) => {
1065-
data.print(f, cx)?;
10661065
let r = r.print_to_string(cx);
10671066
if !r.is_empty() {
1068-
write!(f, " + {}", r)
1067+
write!(f, "(")?;
1068+
}
1069+
write!(f, "dyn ")?;
1070+
data.print(f, cx)?;
1071+
if !r.is_empty() {
1072+
write!(f, " + {})", r)
10691073
} else {
10701074
Ok(())
10711075
}

src/test/compile-fail/cross-borrow-trait.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ impl Trait for Foo {}
1818
pub fn main() {
1919
let x: Box<Trait> = Box::new(Foo);
2020
let _y: &Trait = x; //~ ERROR E0308
21-
//~| expected type `&Trait`
22-
//~| found type `std::boxed::Box<Trait>`
21+
//~| expected type `&dyn Trait`
22+
//~| found type `std::boxed::Box<dyn Trait>`
2323
}

src/test/compile-fail/destructure-trait-ref.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ fn main() {
3333
let &&x = &&(&1isize as &T);
3434

3535
// n == m
36-
let &x = &1isize as &T; //~ ERROR type `&T` cannot be dereferenced
37-
let &&x = &(&1isize as &T); //~ ERROR type `&T` cannot be dereferenced
38-
let box x = box 1isize as Box<T>; //~ ERROR type `std::boxed::Box<T>` cannot be dereferenced
36+
let &x = &1isize as &T; //~ ERROR type `&dyn T` cannot be dereferenced
37+
let &&x = &(&1isize as &T); //~ ERROR type `&dyn T` cannot be dereferenced
38+
let box x = box 1isize as Box<T>; //~ ERROR type `std::boxed::Box<dyn T>` cannot be dereferenced
3939

4040
// n > m
4141
let &&x = &1isize as &T;
4242
//~^ ERROR mismatched types
43-
//~| expected type `T`
43+
//~| expected type `dyn T`
4444
//~| found type `&_`
4545
//~| expected trait T, found reference
4646
let &&&x = &(&1isize as &T);
4747
//~^ ERROR mismatched types
48-
//~| expected type `T`
48+
//~| expected type `dyn T`
4949
//~| found type `&_`
5050
//~| expected trait T, found reference
5151
let box box x = box 1isize as Box<T>;
5252
//~^ ERROR mismatched types
53-
//~| expected type `T`
53+
//~| expected type `dyn T`
5454
//~| found type `std::boxed::Box<_>`
5555
}

src/test/compile-fail/dst-bad-assign-3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn main() {
4242
let z: Box<ToBar> = Box::new(Bar1 {f: 36});
4343
f5.2 = Bar1 {f: 36};
4444
//~^ ERROR mismatched types
45-
//~| expected type `ToBar`
45+
//~| expected type `dyn ToBar`
4646
//~| found type `Bar1`
4747
//~| expected trait ToBar, found struct `Bar1`
4848
//~| ERROR the size for value values of type

src/test/compile-fail/dst-bad-assign.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn main() {
4444
let z: Box<ToBar> = Box::new(Bar1 {f: 36});
4545
f5.ptr = Bar1 {f: 36};
4646
//~^ ERROR mismatched types
47-
//~| expected type `ToBar`
47+
//~| expected type `dyn ToBar`
4848
//~| found type `Bar1`
4949
//~| expected trait ToBar, found struct `Bar1`
5050
//~| ERROR the size for value values of type

src/test/compile-fail/fn-trait-formatting.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ fn main() {
1616
let _: () = (box |_: isize| {}) as Box<FnOnce(isize)>;
1717
//~^ ERROR mismatched types
1818
//~| expected type `()`
19-
//~| found type `std::boxed::Box<std::ops::FnOnce(isize)>`
19+
//~| found type `std::boxed::Box<dyn std::ops::FnOnce(isize)>`
2020
let _: () = (box |_: isize, isize| {}) as Box<Fn(isize, isize)>;
2121
//~^ ERROR mismatched types
2222
//~| expected type `()`
23-
//~| found type `std::boxed::Box<std::ops::Fn(isize, isize)>`
23+
//~| found type `std::boxed::Box<dyn std::ops::Fn(isize, isize)>`
2424
let _: () = (box || -> isize { unimplemented!() }) as Box<FnMut() -> isize>;
2525
//~^ ERROR mismatched types
2626
//~| expected type `()`
27-
//~| found type `std::boxed::Box<std::ops::FnMut() -> isize>`
27+
//~| found type `std::boxed::Box<dyn std::ops::FnMut() -> isize>`
2828

2929
needs_fn(1);
3030
//~^ ERROR : std::ops::Fn<(isize,)>`

src/test/compile-fail/issue-13033.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ struct Baz;
1717
impl Foo for Baz {
1818
fn bar(&mut self, other: &Foo) {}
1919
//~^ ERROR method `bar` has an incompatible type for trait
20-
//~| expected type `fn(&mut Baz, &mut Foo)`
21-
//~| found type `fn(&mut Baz, &Foo)`
20+
//~| expected type `fn(&mut Baz, &mut dyn Foo)`
21+
//~| found type `fn(&mut Baz, &dyn Foo)`
2222
}
2323

2424
fn main() {}

src/test/compile-fail/issue-20939.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
trait Foo {}
1212

1313
impl<'a> Foo for Foo+'a {}
14-
//~^ ERROR the object type `Foo + 'a` automatically implements the trait `Foo`
14+
//~^ ERROR the object type `(dyn Foo + 'a)` automatically implements the trait `Foo`
1515

1616
fn main() {}

src/test/compile-fail/issue-32963.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ fn size_of_copy<T: Copy+?Sized>() -> usize { mem::size_of::<T>() }
1717
fn main() {
1818
size_of_copy::<Misc+Copy>();
1919
//~^ ERROR only auto traits can be used as additional traits in a trait object
20-
//~| ERROR the trait bound `Misc: std::marker::Copy` is not satisfied
20+
//~| ERROR the trait bound `dyn Misc: std::marker::Copy` is not satisfied
2121
}

src/test/compile-fail/issue-41139.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ fn get_function<'a>() -> &'a Fn() -> Trait { panic!("") }
1414

1515
fn main() {
1616
let t : &Trait = &get_function()();
17-
//~^ ERROR cannot move a value of type Trait + 'static
17+
//~^ ERROR cannot move a value of type (dyn Trait + 'static)
1818
}

0 commit comments

Comments
 (0)