From ea79264ee422362428e5bd943a07f42ca885580c Mon Sep 17 00:00:00 2001 From: Alisdair Owens Date: Fri, 17 Jul 2015 22:20:53 +0100 Subject: [PATCH 1/3] Add diagnostics for E0392 --- src/librustc_typeck/diagnostics.rs | 36 +++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index ed04fde463c9..93f5fb4a537f 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -2109,6 +2109,41 @@ E0380: r##" Default impls are only allowed for traits with no methods or associated items. For more information see the [opt-in builtin traits RFC](https://github.com/rust -lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md). +"##, + +E0392: r##" +This error indicates that a type parameter has been declared but not actually +used. + +Here is an example that demonstrates the error: + +``` +enum Foo { + Bar +} +``` + +The first way to fix this error is by removing the type parameter, as +shown below: + +``` +enum Foo { + Bar +} +``` + +The second method is to actually make use of the type parameter: + +``` +enum Foo { + Bar(T) +} +``` + +See the 'Type Parameters' section of the reference for more details +on this topic: + +http://doc.rust-lang.org/reference.html#type-parameters-1 "## } @@ -2211,7 +2246,6 @@ register_diagnostics! { E0390, // only a single inherent implementation marked with // `#[lang = \"{}\"]` is allowed for the `{}` primitive E0391, // unsupported cyclic reference between types/traits detected - E0392, // parameter `{}` is never used E0393, // the type parameter `{}` must be explicitly specified in an object // type because its default value `{}` references the type `Self`" E0399, // trait items need to be implemented because the associated From f78333e052d0aee0387695de9e115f34802fd928 Mon Sep 17 00:00:00 2001 From: Alisdair Owens Date: Sat, 18 Jul 2015 18:42:00 +0100 Subject: [PATCH 2/3] Add details on PhantomData --- src/librustc_typeck/diagnostics.rs | 45 +++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 93f5fb4a537f..d13b8e80f02a 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -2112,10 +2112,8 @@ For more information see the [opt-in builtin traits RFC](https://github.com/rust "##, E0392: r##" -This error indicates that a type parameter has been declared but not actually -used. - -Here is an example that demonstrates the error: +This error indicates that a type or lifetime parameter has been declared +but not actually used. Here is an example that demonstrates the error: ``` enum Foo { @@ -2123,8 +2121,8 @@ enum Foo { } ``` -The first way to fix this error is by removing the type parameter, as -shown below: +If the type parameter was included by mistake, this error can be fixed +by simply removing the type parameter, as shown below: ``` enum Foo { @@ -2132,7 +2130,8 @@ enum Foo { } ``` -The second method is to actually make use of the type parameter: +Alternatively, if the type parameter was intentionally inserted, it must be +used. A simple fix is shown below: ``` enum Foo { @@ -2140,10 +2139,36 @@ enum Foo { } ``` -See the 'Type Parameters' section of the reference for more details -on this topic: +This error may also commonly be found when working with unsafe code. For +example, when using raw pointers one may wish to specify the lifetime for +which the pointed-at data is valid. An initial attempt (below) causes this +error: -http://doc.rust-lang.org/reference.html#type-parameters-1 +``` +struct Foo<'a, T> { + x: *const T +} +``` + +We want to express the constraint that Foo should not outlive `'a`, because +the data pointed to by `T` is only valid for that lifetime. The problem is +that there are no actual uses of `'a`. It's possible to work around this +by adding a PhantomData type to the struct, using it to tell the compiler +to act as if the struct contained a borrowed reference `&'a T`: + +``` +use std::marker::PhantomData; + +struct Foo<'a, T: 'a> { + x: *const T, + phantom: PhantomData<&'a T> +} +``` + +PhantomData can also be used to express information about unused type parameters. +You can read more about it in the API documentation: + +https://doc.rust-lang.org/std/marker/struct.PhantomData.html "## } From 91f0301aa521e057ab180d8d0c6b2ca98796f095 Mon Sep 17 00:00:00 2001 From: Alisdair Owens Date: Sat, 18 Jul 2015 20:34:12 +0100 Subject: [PATCH 3/3] Fix to 80 char width, change to single space after period --- src/librustc_typeck/diagnostics.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index d13b8e80f02a..a002ed311e8c 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -2139,9 +2139,9 @@ enum Foo { } ``` -This error may also commonly be found when working with unsafe code. For +This error may also commonly be found when working with unsafe code. For example, when using raw pointers one may wish to specify the lifetime for -which the pointed-at data is valid. An initial attempt (below) causes this +which the pointed-at data is valid. An initial attempt (below) causes this error: ``` @@ -2151,8 +2151,8 @@ struct Foo<'a, T> { ``` We want to express the constraint that Foo should not outlive `'a`, because -the data pointed to by `T` is only valid for that lifetime. The problem is -that there are no actual uses of `'a`. It's possible to work around this +the data pointed to by `T` is only valid for that lifetime. The problem is +that there are no actual uses of `'a`. It's possible to work around this by adding a PhantomData type to the struct, using it to tell the compiler to act as if the struct contained a borrowed reference `&'a T`: @@ -2165,8 +2165,8 @@ struct Foo<'a, T: 'a> { } ``` -PhantomData can also be used to express information about unused type parameters. -You can read more about it in the API documentation: +PhantomData can also be used to express information about unused type +parameters. You can read more about it in the API documentation: https://doc.rust-lang.org/std/marker/struct.PhantomData.html "##