Skip to content

Commit

Permalink
Rollup merge of rust-lang#71350 - GuillaumeGomez:error-code-explanati…
Browse files Browse the repository at this point in the history
…on-extra-check, r=oli-obk

Error code explanation extra check

r? @Mark-Simulacrum
  • Loading branch information
Dylan-DPC authored Apr 22, 2020
2 parents 10e47f5 + 5cdea2d commit d3e24bd
Show file tree
Hide file tree
Showing 25 changed files with 231 additions and 84 deletions.
4 changes: 3 additions & 1 deletion src/librustc_error_codes/error_codes/E0060.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ External C functions are allowed to be variadic. However, a variadic function
takes a minimum number of arguments. For example, consider C's variadic `printf`
function:

```
```compile_fail,E0060
use std::os::raw::{c_char, c_int};
extern "C" {
fn printf(_: *const c_char, ...) -> c_int;
}
unsafe { printf(); } // error!
```

Using this declaration, it must be called with at least one argument, so
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0130.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ A pattern was declared as an argument in a foreign function declaration.

Erroneous code example:

```compile_fail
```compile_fail,E0130
extern {
fn foo((a, b): (u32, u32)); // error: patterns aren't allowed in foreign
// function declarations
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0198.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ A negative implementation was marked as unsafe.

Erroneous code example:

```compile_fail
```compile_fail,E0198
struct Foo;
unsafe impl !Clone for Foo { } // error!
Expand Down
10 changes: 10 additions & 0 deletions src/librustc_error_codes/error_codes/E0202.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
Inherent associated types were part of [RFC 195] but are not yet implemented.
See [the tracking issue][iss8995] for the status of this implementation.

Erroneous code example:

```compile_fail,E0202
struct Foo;
impl Foo {
type Bar = isize; // error!
}
```

[RFC 195]: https://github.com/rust-lang/rfcs/blob/master/text/0195-associated-items.md
[iss8995]: https://github.com/rust-lang/rust/issues/8995
10 changes: 3 additions & 7 deletions src/librustc_error_codes/error_codes/E0230.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ message for when a particular trait isn't implemented on a type placed in a
position that needs that trait. For example, when the following code is
compiled:

```compile_fail
```compile_fail,E0230
#![feature(rustc_attrs)]
fn foo<T: Index<u8>>(x: T){}
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
trait Index<Idx> { /* ... */ }
foo(true); // `bool` does not implement `Index<u8>`
#[rustc_on_unimplemented = "error on `{Self}` with params `<{A},{B}>`"] // error
trait BadAnnotation<A> {}
```

There will be an error about `bool` not implementing `Index<u8>`, followed by a
Expand Down
10 changes: 3 additions & 7 deletions src/librustc_error_codes/error_codes/E0231.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ message for when a particular trait isn't implemented on a type placed in a
position that needs that trait. For example, when the following code is
compiled:

```compile_fail
```compile_fail,E0231
#![feature(rustc_attrs)]
fn foo<T: Index<u8>>(x: T){}
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
trait Index<Idx> { /* ... */ }
foo(true); // `bool` does not implement `Index<u8>`
#[rustc_on_unimplemented = "error on `{Self}` with params `<{A},{}>`"] // error!
trait BadAnnotation<A> {}
```

there will be an error about `bool` not implementing `Index<u8>`, followed by a
Expand Down
10 changes: 3 additions & 7 deletions src/librustc_error_codes/error_codes/E0232.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ message for when a particular trait isn't implemented on a type placed in a
position that needs that trait. For example, when the following code is
compiled:

```compile_fail
```compile_fail,E0232
#![feature(rustc_attrs)]
fn foo<T: Index<u8>>(x: T){}
#[rustc_on_unimplemented = "the type `{Self}` cannot be indexed by `{Idx}`"]
trait Index<Idx> { /* ... */ }
foo(true); // `bool` does not implement `Index<u8>`
#[rustc_on_unimplemented(lorem="")] // error!
trait BadAnnotation {}
```

there will be an error about `bool` not implementing `Index<u8>`, followed by a
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0281.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ You tried to supply a type which doesn't implement some trait in a location
which expected that trait. This error typically occurs when working with
`Fn`-based types. Erroneous code example:

```compile-fail
```compile_fail
fn foo<F: Fn(usize)>(x: F) { }
fn main() {
Expand Down
26 changes: 13 additions & 13 deletions src/librustc_error_codes/error_codes/E0364.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ attempted to `pub use` a type or value that was not itself public.

Erroneous code example:

```compile_fail
mod foo {
const X: u32 = 1;
}
pub use foo::X;
```compile_fail,E0364
mod a {
fn foo() {}
fn main() {}
mod a {
pub use super::foo; // error!
}
}
```

The solution to this problem is to ensure that the items that you are
re-exporting are themselves marked with `pub`:

```
mod foo {
pub const X: u32 = 1;
}
pub use foo::X;
mod a {
pub fn foo() {} // ok!
fn main() {}
mod a {
pub use super::foo;
}
}
```

See the [Use Declarations][use-declarations] section of the reference for
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0378.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ or a newtype wrapper around a pointer.

Erroneous code example:

```compile-fail,E0378
```compile_fail,E0378
#![feature(dispatch_from_dyn)]
use std::ops::DispatchFromDyn;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0590.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Example of erroneous code:

```compile_fail
```compile_fail,E0590
while break {}
```

Expand Down
12 changes: 12 additions & 0 deletions src/librustc_error_codes/error_codes/E0639.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,17 @@ instantiated from outside of the defining crate as it has been marked
as `non_exhaustive` and as such more fields/variants may be added in
future that could cause adverse side effects for this code.

Erroneous code example:

```ignore (it only works cross-crate)
#[non_exhaustive]
pub struct NormalStruct {
pub first_field: u16,
pub second_field: u16,
}
let ns = NormalStruct { first_field: 640, second_field: 480 }; // error!
```

It is recommended that you look for a `new` function or equivalent in the
crate's documentation.
10 changes: 5 additions & 5 deletions src/librustc_error_codes/error_codes/E0644.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ A closure or generator was constructed that references its own type.

Erroneous example:

```compile-fail,E0644
```compile_fail,E0644
fn fix<F>(f: &F)
where F: Fn(&F)
{
f(&f);
f(&f);
}
fn main() {
fix(&|y| {
// Here, when `x` is called, the parameter `y` is equal to `x`.
});
fix(&|y| {
// Here, when `x` is called, the parameter `y` is equal to `x`.
});
}
```

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0658.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ An unstable feature was used.

Erroneous code example:

```compile_fail,E658
```compile_fail,E0658
#[repr(u128)] // error: use of unstable library feature 'repr128'
enum Foo {
Bar(u64),
Expand Down
12 changes: 12 additions & 0 deletions src/librustc_error_codes/error_codes/E0669.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
Cannot convert inline assembly operand to a single LLVM value.

Erroneous code example:

```compile_fail,E0669
#![feature(llvm_asm)]
fn main() {
unsafe {
llvm_asm!("" :: "r"("")); // error!
}
}
```

This error usually happens when trying to pass in a value to an input inline
assembly operand that is actually a pair of values. In particular, this can
happen when trying to pass in a slice, for instance a `&str`. In Rust, these
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0698.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ generator can be constructed.

Erroneous code example:

```edition2018,compile-fail,E0698
```edition2018,compile_fail,E0698
async fn bar<T>() -> () {}
async fn foo() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0700.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ appear within the `impl Trait` itself.

Erroneous code example:

```compile-fail,E0700
```compile_fail,E0700
use std::cell::Cell;
trait Trait<'a> { }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0708.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Erroneous code example:

```compile_fail,edition2018
```compile_fail,edition2018,E0708
#![feature(async_closure)]
fn main() {
Expand Down
14 changes: 14 additions & 0 deletions src/librustc_error_codes/error_codes/E0714.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
A `#[marker]` trait contained an associated item.

Erroneous code example:

```compile_fail,E0714
#![feature(marker_trait_attr)]
#![feature(associated_type_defaults)]
#[marker]
trait MarkerConst {
const N: usize; // error!
}
fn main() {}
```

The items of marker traits cannot be overridden, so there's no need to have them
when they cannot be changed per-type anyway. If you wanted them for ergonomic
reasons, consider making an extension trait instead.
19 changes: 19 additions & 0 deletions src/librustc_error_codes/error_codes/E0715.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
An `impl` for a `#[marker]` trait tried to override an associated item.

Erroneous code example:

```compile_fail,E0715
#![feature(marker_trait_attr)]
#[marker]
trait Marker {
const N: usize = 0;
fn do_something() {}
}
struct OverrideConst;
impl Marker for OverrideConst { // error!
const N: usize = 1;
}
fn main() {}
```

Because marker traits are allowed to have multiple implementations for the same
type, it's not allowed to override anything in those implementations, as it
would be ambiguous which override should actually be used.
24 changes: 14 additions & 10 deletions src/librustc_error_codes/error_codes/E0727.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,29 @@ A `yield` clause was used in an `async` context.

Example of erroneous code:

```compile_fail
```compile_fail,E0727,edition2018
#![feature(generators)]
let generator = || {
async {
yield;
}
};
fn main() {
let generator = || {
async {
yield;
}
};
}
```

Here, the `yield` keyword is used in an `async` block,
which is not yet supported.

To fix this error, you have to move `yield` out of the `async` block:

```
```edition2018
#![feature(generators)]
let generator = || {
yield;
};
fn main() {
let generator = || {
yield;
};
}
```
21 changes: 18 additions & 3 deletions src/librustc_error_codes/error_codes/E0732.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
An `enum` with a discriminant must specify a `#[repr(inttype)]`.

Erroneous code example:

```compile_fail,E0732
#![feature(arbitrary_enum_discriminant)]
enum Enum { // error!
Unit = 1,
Tuple() = 2,
Struct{} = 3,
}
# fn main() {}
```

A `#[repr(inttype)]` must be provided on an `enum` if it has a non-unit
variant with a discriminant, or where there are both unit variants with
discriminants and non-unit variants. This restriction ensures that there
Expand All @@ -23,7 +36,9 @@ fn discriminant(v : &Enum) -> u8 {
unsafe { *(v as *const Enum as *const u8) }
}
assert_eq!(3, discriminant(&Enum::Unit));
assert_eq!(2, discriminant(&Enum::Tuple(5)));
assert_eq!(1, discriminant(&Enum::Struct{a: 7, b: 11}));
fn main() {
assert_eq!(3, discriminant(&Enum::Unit));
assert_eq!(2, discriminant(&Enum::Tuple(5)));
assert_eq!(1, discriminant(&Enum::Struct{a: 7, b: 11}));
}
```
Loading

0 comments on commit d3e24bd

Please sign in to comment.