diff options
| author | bors <bors@rust-lang.org> | 2023-01-08 09:00:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-01-08 09:00:31 +0000 |
| commit | 8ea62f6c30c94778d9146ddc26c8520ed2b50a58 (patch) | |
| tree | 3d04b0d8d3e598939b6858ab2e51d06724875278 /compiler/rustc_error_codes/src | |
| parent | 2afe58571e53d48a1fc2354271abe5aff60c5c44 (diff) | |
| parent | 789ebdca4797247351ec8770d26f8e23214f1f25 (diff) | |
| download | rust-8ea62f6c30c94778d9146ddc26c8520ed2b50a58.tar.gz rust-8ea62f6c30c94778d9146ddc26c8520ed2b50a58.zip | |
Auto merge of #106588 - JohnTitor:rollup-4z80tjx, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #103104 (Stabilize `main_separator_str`) - #106410 (Suggest `mut self: &mut Self` for `?Sized` impls) - #106457 (Adjust comments about pre-push.sh hook) - #106546 (jsondoclint: Check local items in `paths` are also in `index`.) - #106557 (Add some UI tests and reword error-code docs) - #106562 (Clarify examples for `VecDeque::get/get_mut`) - #106580 (remove unreachable error code `E0313`) - #106581 (Do not emit wrong E0308 suggestion for closure mismatch) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_error_codes/src')
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_error_codes/src/error_codes/E0015.md | 23 |
2 files changed, 9 insertions, 17 deletions
diff --git a/compiler/rustc_error_codes/src/error_codes.rs b/compiler/rustc_error_codes/src/error_codes.rs index 3fba2cf5749..76d5da19399 100644 --- a/compiler/rustc_error_codes/src/error_codes.rs +++ b/compiler/rustc_error_codes/src/error_codes.rs @@ -579,8 +579,7 @@ E0791: include_str!("./error_codes/E0791.md"), // E0300, // unexpanded macro // E0304, // expected signed integer constant // E0305, // expected constant - E0313, // lifetime of borrowed pointer outlives lifetime of captured - // variable +// E0313, // removed: found unreachable // E0314, // closure outlives stack frame // E0315, // cannot invoke closure outside of its lifetime // E0319, // trait impls for defaulted traits allowed just for structs/enums diff --git a/compiler/rustc_error_codes/src/error_codes/E0015.md b/compiler/rustc_error_codes/src/error_codes/E0015.md index 021a0219d13..ac78f66adad 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0015.md +++ b/compiler/rustc_error_codes/src/error_codes/E0015.md @@ -1,5 +1,4 @@ -A constant item was initialized with something that is not a constant -expression. +A non-`const` function was called in a `const` context. Erroneous code example: @@ -8,26 +7,20 @@ fn create_some() -> Option<u8> { Some(1) } -const FOO: Option<u8> = create_some(); // error! +// error: cannot call non-const fn `create_some` in constants +const FOO: Option<u8> = create_some(); ``` -The only functions that can be called in static or constant expressions are -`const` functions, and struct/enum constructors. +All functions used in a `const` context (constant or static expression) must +be marked `const`. To fix this error, you can declare `create_some` as a constant function: ``` -const fn create_some() -> Option<u8> { // declared as a const function +// declared as a `const` function: +const fn create_some() -> Option<u8> { Some(1) } -const FOO: Option<u8> = create_some(); // ok! - -// These are also working: -struct Bar { - x: u8, -} - -const OTHER_FOO: Option<u8> = Some(1); -const BAR: Bar = Bar {x: 1}; +const FOO: Option<u8> = create_some(); // no error! ``` |
