Account for impl Trait { when impl Trait for Type { was intended · rust-lang/rust@e057c43 (original) (raw)

``

1

`` +

warning: trait objects without an explicit dyn are deprecated

``

``

2

`+

--> $DIR/missing-for-type-in-impl.rs:8:6

`

``

3

`+

|

`

``

4

`+

LL | impl Foo {

`

``

5

`+

| ^^^^^^^^

`

``

6

`+

|

`

``

7

`+

= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!

`

``

8

`+

= note: for more information, see https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html

`

``

9

`` +

= note: #[warn(bare_trait_objects)] on by default

``

``

10

`` +

help: if this is a dyn-compatible trait, use dyn

``

``

11

`+

|

`

``

12

`+

LL | impl dyn Foo {

`

``

13

`+

| +++

`

``

14

`+

help: you might have intended to implement this trait for a given type

`

``

15

`+

|

`

``

16

`+

LL | impl Foo for /* Type */ {

`

``

17

`+

| ++++++++++++++

`

``

18

+

``

19

`` +

warning: trait objects without an explicit dyn are deprecated

``

``

20

`+

--> $DIR/missing-for-type-in-impl.rs:8:6

`

``

21

`+

|

`

``

22

`+

LL | impl Foo {

`

``

23

`+

| ^^^^^^^^

`

``

24

`+

|

`

``

25

`+

= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!

`

``

26

`+

= note: for more information, see https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html

`

``

27

`` +

= note: duplicate diagnostic emitted due to -Z deduplicate-diagnostics=no

``

``

28

`` +

help: if this is a dyn-compatible trait, use dyn

``

``

29

`+

|

`

``

30

`+

LL | impl dyn Foo {

`

``

31

`+

| +++

`

``

32

`+

help: you might have intended to implement this trait for a given type

`

``

33

`+

|

`

``

34

`+

LL | impl Foo for /* Type */ {

`

``

35

`+

| ++++++++++++++

`

``

36

+

``

37

`` +

error[E0038]: the trait Foo cannot be made into an object

``

``

38

`+

--> $DIR/missing-for-type-in-impl.rs:8:6

`

``

39

`+

|

`

``

40

`+

LL | impl Foo {

`

``

41

`` +

| ^^^^^^^^ Foo cannot be made into an object

``

``

42

`+

|

`

``

43

`+

note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit https://doc.rust-lang.org/reference/items/traits.html#object-safety

`

``

44

`+

--> $DIR/missing-for-type-in-impl.rs:4:8

`

``

45

`+

|

`

``

46

`+

LL | trait Foo {

`

``

47

`+

| --- this trait cannot be made into an object...

`

``

48

`+

LL | fn id(me: T) -> T;

`

``

49

`` +

| ^^ ...because associated function id has no self parameter

``

``

50

`` +

help: consider turning id into a method by giving it a &self argument

``

``

51

`+

|

`

``

52

`+

LL | fn id(&self, me: T) -> T;

`

``

53

`+

| ++++++

`

``

54

`` +

help: alternatively, consider constraining id so it does not apply to trait objects

``

``

55

`+

|

`

``

56

`+

LL | fn id(me: T) -> T where Self: Sized;

`

``

57

`+

| +++++++++++++++++

`

``

58

+

``

59

`` +

error[E0277]: the trait bound i64: Foo<i64> is not satisfied

``

``

60

`+

--> $DIR/missing-for-type-in-impl.rs:19:19

`

``

61

`+

|

`

``

62

`+

LL | let x: i64 = <i64 as Foo>::id(10);

`

``

63

`` +

| ^^^ the trait Foo<i64> is not implemented for i64

``

``

64

`+

|

`

``

65

`+

help: this trait has no implementations, consider adding one

`

``

66

`+

--> $DIR/missing-for-type-in-impl.rs:3:1

`

``

67

`+

|

`

``

68

`+

LL | trait Foo {

`

``

69

`+

| ^^^^^^^^^^^^

`

``

70

+

``

71

`+

error: aborting due to 2 previous errors; 2 warnings emitted

`

``

72

+

``

73

`+

Some errors have detailed explanations: E0038, E0277.

`

``

74

`` +

For more information about an error, try rustc --explain E0038.

``