From 4e8199b572f2035b7749cba276ece3a26630d23e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:21 +0200 Subject: Adding upstream version 1.67.1+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_error_codes/src/error_codes.rs | 1 + .../rustc_error_codes/src/error_codes/E0207.md | 75 ++++++++++++++++++++-- .../rustc_error_codes/src/error_codes/E0322.md | 3 +- .../rustc_error_codes/src/error_codes/E0382.md | 2 +- .../rustc_error_codes/src/error_codes/E0706.md | 2 +- .../rustc_error_codes/src/error_codes/E0760.md | 4 +- .../rustc_error_codes/src/error_codes/E0791.md | 41 ++++++++++++ 7 files changed, 120 insertions(+), 8 deletions(-) create mode 100644 compiler/rustc_error_codes/src/error_codes/E0791.md (limited to 'compiler/rustc_error_codes') diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index 1e86d1596..31a709c36 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -494,6 +494,7 @@ E0786: include_str!("./error_codes/E0786.md"), E0787: include_str!("./error_codes/E0787.md"), E0788: include_str!("./error_codes/E0788.md"), E0790: include_str!("./error_codes/E0790.md"), +E0791: include_str!("./error_codes/E0791.md"), ; // E0006, // merged with E0005 // E0008, // cannot bind by-move into a pattern guard diff --git a/compiler/rustc_error_codes/src/error_codes/E0207.md b/compiler/rustc_error_codes/src/error_codes/E0207.md index 8a7923ac9..95e7c9fc7 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0207.md +++ b/compiler/rustc_error_codes/src/error_codes/E0207.md @@ -1,4 +1,5 @@ -A type parameter that is specified for `impl` is not constrained. +A type, const or lifetime parameter that is specified for `impl` is not +constrained. Erroneous code example: @@ -14,8 +15,8 @@ impl Foo { } ``` -Any type parameter of an `impl` must meet at least one of -the following criteria: +Any type or const parameter of an `impl` must meet at least one of the +following criteria: - it appears in the _implementing type_ of the impl, e.g. `impl Foo` - for a trait impl, it appears in the _implemented trait_, e.g. @@ -23,6 +24,9 @@ the following criteria: - it is bound as an associated type, e.g. `impl SomeTrait for T where T: AnotherTrait` +Any unconstrained lifetime parameter of an `impl` is not supported if the +lifetime parameter is used by an associated type. + ### Error example 1 Suppose we have a struct `Foo` and we would like to define some methods for it. @@ -32,7 +36,6 @@ The problem is that the parameter `T` does not appear in the implementing type (`Foo`) of the impl. In this case, we can fix the error by moving the type parameter from the `impl` to the method `get`: - ``` struct Foo; @@ -128,6 +131,70 @@ impl Maker> for FooMaker { } ``` +### Error example 3 + +Suppose we have a struct `Foo` and we would like to define some methods for it. +The following code example has a definition which leads to a compiler error: + +```compile_fail,E0207 +struct Foo; + +impl Foo { + // error: the const parameter `T` is not constrained by the impl trait, self + // type, or predicates [E0207] + fn get(&self) -> i32 { + i32::default() + } +} +``` + +The problem is that the const parameter `T` does not appear in the implementing +type (`Foo`) of the impl. In this case, we can fix the error by moving the type +parameter from the `impl` to the method `get`: + + +``` +struct Foo; + +// Move the const parameter from the impl to the method +impl Foo { + fn get(&self) -> i32 { + i32::default() + } +} +``` + +### Error example 4 + +Suppose we have a struct `Foo` and a struct `Bar` that uses lifetime `'a`. We +would like to implement trait `Contains` for `Foo`. The trait `Contains` have +the associated type `B`. The following code example has a definition which +leads to a compiler error: + +```compile_fail,E0207 +struct Foo; +struct Bar<'a>; + +trait Contains { + type B; + + fn get(&self) -> i32; +} + +impl<'a> Contains for Foo { + type B = Bar<'a>; + + // error: the lifetime parameter `'a` is not constrained by the impl trait, + // self type, or predicates [E0207] + fn get(&self) -> i32 { + i32::default() + } +} +``` + +Please note that unconstrained lifetime parameters are not supported if they are +being used by an associated type. + ### Additional information For more information, please see [RFC 447]. diff --git a/compiler/rustc_error_codes/src/error_codes/E0322.md b/compiler/rustc_error_codes/src/error_codes/E0322.md index ccef8681d..194bbd83b 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0322.md +++ b/compiler/rustc_error_codes/src/error_codes/E0322.md @@ -1,4 +1,5 @@ -The `Sized` trait was implemented explicitly. +A built-in trait was implemented explicitly. All implementations of the trait +are provided automatically by the compiler. Erroneous code example: diff --git a/compiler/rustc_error_codes/src/error_codes/E0382.md b/compiler/rustc_error_codes/src/error_codes/E0382.md index d1408a062..cbc4980f8 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0382.md +++ b/compiler/rustc_error_codes/src/error_codes/E0382.md @@ -61,7 +61,7 @@ with `#[derive(Clone)]`. Some types have no ownership semantics at all and are trivial to duplicate. An example is `i32` and the other number types. We don't have to call `.clone()` to -clone them, because they are marked `Copy` in addition to `Clone`. Implicit +clone them, because they are marked `Copy` in addition to `Clone`. Implicit cloning is more convenient in this case. We can mark our own types `Copy` if all their members also are marked `Copy`. diff --git a/compiler/rustc_error_codes/src/error_codes/E0706.md b/compiler/rustc_error_codes/src/error_codes/E0706.md index d379b8a23..fabd855a2 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0706.md +++ b/compiler/rustc_error_codes/src/error_codes/E0706.md @@ -56,4 +56,4 @@ You might be interested in visiting the [async book] for further information. [`async-trait` crate]: https://crates.io/crates/async-trait [async-is-hard]: https://smallcultfollowing.com/babysteps/blog/2019/10/26/async-fn-in-traits-are-hard/ [Generic Associated Types]: https://github.com/rust-lang/rust/issues/44265 -[async book]: https://rust-lang.github.io/async-book/07_workarounds/06_async_in_traits.html +[async book]: https://rust-lang.github.io/async-book/07_workarounds/05_async_in_traits.html diff --git a/compiler/rustc_error_codes/src/error_codes/E0760.md b/compiler/rustc_error_codes/src/error_codes/E0760.md index e1dcfefeb..85e5faada 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0760.md +++ b/compiler/rustc_error_codes/src/error_codes/E0760.md @@ -1,9 +1,11 @@ +#### Note: this error code is no longer emitted by the compiler. + `async fn`/`impl trait` return type cannot contain a projection or `Self` that references lifetimes from a parent scope. Erroneous code example: -```compile_fail,E0760,edition2018 +```compile_fail,edition2018 struct S<'a>(&'a i32); impl<'a> S<'a> { diff --git a/compiler/rustc_error_codes/src/error_codes/E0791.md b/compiler/rustc_error_codes/src/error_codes/E0791.md new file mode 100644 index 000000000..61d2f511a --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0791.md @@ -0,0 +1,41 @@ +Static variables with the `#[linkage]` attribute within external blocks +must have one of the following types, which are equivalent to a nullable +pointer in C: + +* `*mut T` or `*const T`, where `T` may be any type. + +* An enumerator type with no `#[repr]` attribute and with two variants, where + one of the variants has no fields, and the other has a single field of one of + the following non-nullable types: + * Reference type + * Function pointer type + + The variants can appear in either order. + +For example, the following declaration is invalid: + +```compile_fail,E0791 +#![feature(linkage)] + +extern "C" { + #[linkage = "extern_weak"] + static foo: i8; +} +``` + +The following declarations are valid: + +``` +#![feature(linkage)] + +extern "C" { + #[linkage = "extern_weak"] + static foo: Option; + + #[linkage = "extern_weak"] + static bar: Option<&'static i8>; + + #[linkage = "extern_weak"] + static baz: *mut i8; +} +``` -- cgit v1.2.3