about summary refs log tree commit diff
path: root/src/librustc_error_codes/error_codes
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-01-13 12:49:12 +0000
committerbors <bors@rust-lang.org>2020-01-13 12:49:12 +0000
commitbf84eb538fd16743240434b3e837b36c35719fee (patch)
treeb9bdb0082e4b4341905a42c9d3cef95e126f5d78 /src/librustc_error_codes/error_codes
parentaf958046e5855a4254831102b502f57dafa40f69 (diff)
parent5b7d64e9473216dc8650ca5f910100389ab91726 (diff)
downloadrust-bf84eb538fd16743240434b3e837b36c35719fee.tar.gz
rust-bf84eb538fd16743240434b3e837b36c35719fee.zip
Auto merge of #67850 - GuillaumeGomez:err-codes-checkup, r=Mark-Simulacrum
Error codes checkup and rustdoc test fix

This PR does a few things:

 * fix how rustdoc checks that an error code has been thrown (it only checked for "E0XXX" so if it appeared in the output because the file has it in its name or wherever, it passed the test, which was incorrect)
 * fix the failing code examples that weren't throwing the expected error code
Diffstat (limited to 'src/librustc_error_codes/error_codes')
-rw-r--r--src/librustc_error_codes/error_codes/E0445.md4
-rw-r--r--src/librustc_error_codes/error_codes/E0446.md4
-rw-r--r--src/librustc_error_codes/error_codes/E0491.md36
3 files changed, 28 insertions, 16 deletions
diff --git a/src/librustc_error_codes/error_codes/E0445.md b/src/librustc_error_codes/error_codes/E0445.md
index 9cc62b2ba6d..e6a28a9c2c4 100644
--- a/src/librustc_error_codes/error_codes/E0445.md
+++ b/src/librustc_error_codes/error_codes/E0445.md
@@ -12,6 +12,8 @@ trait Foo {
 pub trait Bar : Foo {} // error: private trait in public interface
 pub struct Bar2<T: Foo>(pub T); // same error
 pub fn foo<T: Foo> (t: T) {} // same error
+
+fn main() {}
 ```
 
 To solve this error, please ensure that the trait is also public. The trait
@@ -26,4 +28,6 @@ pub trait Foo { // we set the Foo trait public
 pub trait Bar : Foo {} // ok!
 pub struct Bar2<T: Foo>(pub T); // ok!
 pub fn foo<T: Foo> (t: T) {} // ok!
+
+fn main() {}
 ```
diff --git a/src/librustc_error_codes/error_codes/E0446.md b/src/librustc_error_codes/error_codes/E0446.md
index d0144478dbf..77a1834ece4 100644
--- a/src/librustc_error_codes/error_codes/E0446.md
+++ b/src/librustc_error_codes/error_codes/E0446.md
@@ -12,6 +12,8 @@ mod Foo {
         Bar(0)
     }
 }
+
+fn main() {}
 ```
 
 To solve this error, please ensure that the type is also public. The type
@@ -27,4 +29,6 @@ mod Foo {
         Bar(0)
     }
 }
+
+fn main() {}
 ```
diff --git a/src/librustc_error_codes/error_codes/E0491.md b/src/librustc_error_codes/error_codes/E0491.md
index 1ccaf71257b..d45663f3a53 100644
--- a/src/librustc_error_codes/error_codes/E0491.md
+++ b/src/librustc_error_codes/error_codes/E0491.md
@@ -3,30 +3,34 @@ A reference has a longer lifetime than the data it references.
 Erroneous code example:
 
 ```compile_fail,E0491
-trait SomeTrait<'a> {
-    type Output;
+struct Foo<'a> {
+    x: fn(&'a i32),
 }
 
-impl<'a, T> SomeTrait<'a> for T {
-    type Output = &'a T; // compile error E0491
+trait Trait<'a, 'b> {
+    type Out;
+}
+
+impl<'a, 'b> Trait<'a, 'b> for usize {
+    type Out = &'a Foo<'b>; // error!
 }
 ```
 
-Here, the problem is that a reference type like `&'a T` is only valid
-if all the data in T outlives the lifetime `'a`. But this impl as written
-is applicable to any lifetime `'a` and any type `T` -- we have no guarantee
-that `T` outlives `'a`. To fix this, you can add a where clause like
-`where T: 'a`.
+Here, the problem is that the compiler cannot be sure that the `'b` lifetime
+will live longer than `'a`, which should be mandatory in order to be sure that
+`Trait::Out` will always have a reference pointing to an existing type. So in
+this case, we just need to tell the compiler than `'b` must outlive `'a`:
 
 ```
-trait SomeTrait<'a> {
-    type Output;
+struct Foo<'a> {
+    x: fn(&'a i32),
+}
+
+trait Trait<'a, 'b> {
+    type Out;
 }
 
-impl<'a, T> SomeTrait<'a> for T
-where
-    T: 'a,
-{
-    type Output = &'a T; // compile error E0491
+impl<'a, 'b: 'a> Trait<'a, 'b> for usize { // we added the lifetime enforcement
+    type Out = &'a Foo<'b>; // it now works!
 }
 ```