Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error codes checkup and rustdoc test fix #67850

Merged
merged 2 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/librustc_error_codes/error_codes/E0445.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {}
```
4 changes: 4 additions & 0 deletions src/librustc_error_codes/error_codes/E0446.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ mod Foo {
Bar(0)
}
}

fn main() {}
```

To solve this error, please ensure that the type is also public. The type
Expand All @@ -27,4 +29,6 @@ mod Foo {
Bar(0)
}
}

fn main() {}
```
36 changes: 20 additions & 16 deletions src/librustc_error_codes/error_codes/E0491.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}
```
3 changes: 1 addition & 2 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ fn run_test(
eprint!("{}", self.0);
}
}

let out = str::from_utf8(&output.stderr).unwrap();
let _bomb = Bomb(&out);
match (output.status.success(), compile_fail) {
Expand All @@ -309,7 +308,7 @@ fn run_test(
(true, false) => {}
(false, true) => {
if !error_codes.is_empty() {
error_codes.retain(|err| !out.contains(err));
error_codes.retain(|err| !out.contains(&format!("error[{}]: ", err)));

if !error_codes.is_empty() {
return Err(TestFailure::MissingErrorCodes(error_codes));
Expand Down