Skip to content

Commit d2f5122

Browse files
committed
Auto merge of #4155 - phansch:rustup_trait_obj, r=oli-obk
Rustup to #61203 See #61203 Migrates all trait objects to use `dyn` in our ui tests changelog: none
2 parents 018fa30 + 2c72026 commit d2f5122

16 files changed

+38
-38
lines changed

tests/ui/borrow_box.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -27,55 +27,55 @@ impl<'a> Test4 for Test3<'a> {
2727

2828
use std::any::Any;
2929

30-
pub fn test5(foo: &mut Box<Any>) {
30+
pub fn test5(foo: &mut Box<dyn Any>) {
3131
println!("{:?}", foo)
3232
}
3333

3434
pub fn test6() {
35-
let foo: &Box<Any>;
35+
let foo: &Box<dyn Any>;
3636
}
3737

3838
struct Test7<'a> {
39-
foo: &'a Box<Any>,
39+
foo: &'a Box<dyn Any>,
4040
}
4141

4242
trait Test8 {
43-
fn test8(a: &Box<Any>);
43+
fn test8(a: &Box<dyn Any>);
4444
}
4545

4646
impl<'a> Test8 for Test7<'a> {
47-
fn test8(a: &Box<Any>) {
47+
fn test8(a: &Box<dyn Any>) {
4848
unimplemented!();
4949
}
5050
}
5151

52-
pub fn test9(foo: &mut Box<Any + Send + Sync>) {
52+
pub fn test9(foo: &mut Box<dyn Any + Send + Sync>) {
5353
let _ = foo;
5454
}
5555

5656
pub fn test10() {
57-
let foo: &Box<Any + Send + 'static>;
57+
let foo: &Box<dyn Any + Send + 'static>;
5858
}
5959

6060
struct Test11<'a> {
61-
foo: &'a Box<Any + Send>,
61+
foo: &'a Box<dyn Any + Send>,
6262
}
6363

6464
trait Test12 {
65-
fn test4(a: &Box<Any + 'static>);
65+
fn test4(a: &Box<dyn Any + 'static>);
6666
}
6767

6868
impl<'a> Test12 for Test11<'a> {
69-
fn test4(a: &Box<Any + 'static>) {
69+
fn test4(a: &Box<dyn Any + 'static>) {
7070
unimplemented!();
7171
}
7272
}
7373

7474
fn main() {
7575
test1(&mut Box::new(false));
7676
test2();
77-
test5(&mut (Box::new(false) as Box<Any>));
77+
test5(&mut (Box::new(false) as Box<dyn Any>));
7878
test6();
79-
test9(&mut (Box::new(false) as Box<Any + Send + Sync>));
79+
test9(&mut (Box::new(false) as Box<dyn Any + Send + Sync>));
8080
test10();
8181
}

tests/ui/box_vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn test(foo: Box<Vec<bool>>) {
1515
println!("{:?}", foo.get(0))
1616
}
1717

18-
pub fn test2(foo: Box<Fn(Vec<u32>)>) {
18+
pub fn test2(foo: Box<dyn Fn(Vec<u32>)>) {
1919
// pass if #31 is fixed
2020
foo(vec![1, 2, 3])
2121
}

tests/ui/escape_analysis.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Z for A {
2121

2222
fn main() {}
2323

24-
fn ok_box_trait(boxed_trait: &Box<Z>) {
24+
fn ok_box_trait(boxed_trait: &Box<dyn Z>) {
2525
let boxed_local = boxed_trait;
2626
// done
2727
}

tests/ui/eta.fixed

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ fn main() {
3232
let e = Some(1u8).map(generic);
3333
let e = Some(1u8).map(generic);
3434
// See #515
35-
let a: Option<Box<::std::ops::Deref<Target = [i32]>>> =
36-
Some(vec![1i32, 2]).map(|v| -> Box<::std::ops::Deref<Target = [i32]>> { Box::new(v) });
35+
let a: Option<Box<dyn (::std::ops::Deref<Target = [i32]>)>> =
36+
Some(vec![1i32, 2]).map(|v| -> Box<dyn (::std::ops::Deref<Target = [i32]>)> { Box::new(v) });
3737
}
3838

3939
trait TestTrait {
@@ -108,7 +108,7 @@ fn test_redundant_closures_containing_method_calls() {
108108
let _: Vec<_> = arr.iter().map(|x| x.map_err(some.take().unwrap())).collect();
109109
}
110110

111-
struct Thunk<T>(Box<FnMut() -> T>);
111+
struct Thunk<T>(Box<dyn FnMut() -> T>);
112112

113113
impl<T> Thunk<T> {
114114
fn new<F: 'static + FnOnce() -> T>(f: F) -> Thunk<T> {

tests/ui/eta.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ fn main() {
3232
let e = Some(1u8).map(|a| generic(a));
3333
let e = Some(1u8).map(generic);
3434
// See #515
35-
let a: Option<Box<::std::ops::Deref<Target = [i32]>>> =
36-
Some(vec![1i32, 2]).map(|v| -> Box<::std::ops::Deref<Target = [i32]>> { Box::new(v) });
35+
let a: Option<Box<dyn (::std::ops::Deref<Target = [i32]>)>> =
36+
Some(vec![1i32, 2]).map(|v| -> Box<dyn (::std::ops::Deref<Target = [i32]>)> { Box::new(v) });
3737
}
3838

3939
trait TestTrait {
@@ -108,7 +108,7 @@ fn test_redundant_closures_containing_method_calls() {
108108
let _: Vec<_> = arr.iter().map(|x| x.map_err(|e| some.take().unwrap()(e))).collect();
109109
}
110110

111-
struct Thunk<T>(Box<FnMut() -> T>);
111+
struct Thunk<T>(Box<dyn FnMut() -> T>);
112112

113113
impl<T> Thunk<T> {
114114
fn new<F: 'static + FnOnce() -> T>(f: F) -> Thunk<T> {

tests/ui/extra_unused_lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn lt_return_only<'a>() -> &'a u8 {
2525
panic!()
2626
}
2727

28-
fn unused_lt_blergh<'a>(x: Option<Box<Send + 'a>>) {}
28+
fn unused_lt_blergh<'a>(x: Option<Box<dyn Send + 'a>>) {}
2929

3030
trait Foo<'a> {
3131
fn x(&self, a: &'a u8);

tests/ui/len_zero.fixed

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn main() {
7070
println!("This should not happen either!");
7171
}
7272

73-
let z: &TraitsToo = &y;
73+
let z: &dyn TraitsToo = &y;
7474
if z.len() > 0 {
7575
// No error; `TraitsToo` has no `.is_empty()` method.
7676
println!("Nor should this!");
@@ -125,7 +125,7 @@ fn main() {
125125
}
126126
assert!(!has_is_empty.is_empty());
127127

128-
let with_is_empty: &WithIsEmpty = &Wither;
128+
let with_is_empty: &dyn WithIsEmpty = &Wither;
129129
if with_is_empty.is_empty() {
130130
println!("Or this!");
131131
}

tests/ui/len_zero.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn main() {
7070
println!("This should not happen either!");
7171
}
7272

73-
let z: &TraitsToo = &y;
73+
let z: &dyn TraitsToo = &y;
7474
if z.len() > 0 {
7575
// No error; `TraitsToo` has no `.is_empty()` method.
7676
println!("Nor should this!");
@@ -125,7 +125,7 @@ fn main() {
125125
}
126126
assert!(!has_is_empty.is_empty());
127127

128-
let with_is_empty: &WithIsEmpty = &Wither;
128+
let with_is_empty: &dyn WithIsEmpty = &Wither;
129129
if with_is_empty.len() == 0 {
130130
println!("Or this!");
131131
}

tests/ui/needless_borrow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ trait Trait {}
4141

4242
impl<'a> Trait for &'a str {}
4343

44-
fn h(_: &Trait) {}
44+
fn h(_: &dyn Trait) {}
4545
#[warn(clippy::needless_borrow)]
4646
#[allow(dead_code)]
4747
fn issue_1432() {

tests/ui/needless_lifetimes.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,16 @@ fn struct_with_lt4<'a, 'b>(_foo: &'a Foo<'b>) -> &'a str {
166166

167167
trait WithLifetime<'a> {}
168168

169-
type WithLifetimeAlias<'a> = WithLifetime<'a>;
169+
type WithLifetimeAlias<'a> = dyn WithLifetime<'a>;
170170

171171
// Should not warn because it won't build without the lifetime.
172-
fn trait_obj_elided<'a>(_arg: &'a WithLifetime) -> &'a str {
172+
fn trait_obj_elided<'a>(_arg: &'a dyn WithLifetime) -> &'a str {
173173
unimplemented!()
174174
}
175175

176176
// Should warn because there is no lifetime on `Drop`, so this would be
177177
// unambiguous if we elided the lifetime.
178-
fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str {
178+
fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str {
179179
unimplemented!()
180180
}
181181

@@ -226,7 +226,7 @@ struct Test {
226226
}
227227

228228
impl Test {
229-
fn iter<'a>(&'a self) -> Box<Iterator<Item = usize> + 'a> {
229+
fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = usize> + 'a> {
230230
unimplemented!()
231231
}
232232
}

tests/ui/needless_lifetimes.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ LL | | }
8181
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
8282
--> $DIR/needless_lifetimes.rs:178:1
8383
|
84-
LL | / fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str {
84+
LL | / fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str {
8585
LL | | unimplemented!()
8686
LL | | }
8787
| |_^

tests/ui/non_copy_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const STR: &str = "012345";
2727
const COW: Cow<str> = Cow::Borrowed("abcdef");
2828
//^ note: a const item of Cow is used in the `postgres` package.
2929

30-
const NO_ANN: &Display = &70;
30+
const NO_ANN: &dyn Display = &70;
3131

3232
static STATIC_TUPLE: (AtomicUsize, String) = (ATOMIC, STRING);
3333
//^ there should be no lints on this line

tests/ui/unnecessary_clone.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn clone_on_ref_ptr() {
4444
sync::Weak::clone(&arc_weak);
4545

4646
let x = Arc::new(SomeImpl);
47-
let _: Arc<SomeTrait> = x.clone();
47+
let _: Arc<dyn SomeTrait> = x.clone();
4848
}
4949

5050
fn clone_on_copy_generic<T: Copy>(t: T) {

tests/ui/unnecessary_clone.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ LL | arc_weak.clone();
4545
| ^^^^^^^^^^^^^^^^ help: try this: `Weak::<bool>::clone(&arc_weak)`
4646

4747
error: using '.clone()' on a ref-counted pointer
48-
--> $DIR/unnecessary_clone.rs:47:29
48+
--> $DIR/unnecessary_clone.rs:47:33
4949
|
50-
LL | let _: Arc<SomeTrait> = x.clone();
51-
| ^^^^^^^^^ help: try this: `Arc::<SomeImpl>::clone(&x)`
50+
LL | let _: Arc<dyn SomeTrait> = x.clone();
51+
| ^^^^^^^^^ help: try this: `Arc::<SomeImpl>::clone(&x)`
5252

5353
error: using `clone` on a `Copy` type
5454
--> $DIR/unnecessary_clone.rs:51:5

tests/ui/unused_unit.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl Unitter {
1717
#[allow(clippy::no_effect)]
1818
pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G)
1919
where G: Fn() -> () {
20-
let _y: &Fn() -> () = &f;
20+
let _y: &dyn Fn() -> () = &f;
2121
(); // this should not lint, as it's not in return type position
2222
}
2323
}

tests/ui/unused_unit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl Unitter {
1818
pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) ->
1919
()
2020
where G: Fn() -> () {
21-
let _y: &Fn() -> () = &f;
21+
let _y: &dyn Fn() -> () = &f;
2222
(); // this should not lint, as it's not in return type position
2323
}
2424
}

0 commit comments

Comments
 (0)