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

E0373 examples are out of date #137962

Closed
Eclips4 opened this issue Mar 3, 2025 · 1 comment · Fixed by #137963
Closed

E0373 examples are out of date #137962

Eclips4 opened this issue Mar 3, 2025 · 1 comment · Fixed by #137963
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Eclips4
Copy link
Contributor

Eclips4 commented Mar 3, 2025

Code

fn foo(x: u32) -> Box<Fn(u32) -> u32> {
    Box::new(|y| x + y)
}

Current output

error[E0782]: expected a type, found a trait
 --> src/main.rs:1:23
  |
1 | fn foo(x: u32) -> Box<Fn(u32) -> u32> {
  |                       ^^^^^^^^^^^^^^
  |
help: you can add the `dyn` keyword if you want a trait object
  |
1 | fn foo(x: u32) -> Box<dyn Fn(u32) -> u32> {
  |                       +++

For more information about this error, try `rustc --explain E0782`.

Desired output

error[E0373]: closure may outlive the current function, but it borrows `x`, which is owned by the current function
 --> src/main.rs:2:14
  |
2 |     Box::new(|y| x + y)
  |              ^^^ - `x` is borrowed here
  |              |
  |              may outlive borrowed value `x`
  |
note: closure is returned here
 --> src/main.rs:2:5
  |
2 |     Box::new(|y| x + y)
  |     ^^^^^^^^^^^^^^^^^^^
help: to force the closure to take ownership of `x` (and any other referenced variables), use the `move` keyword
  |
2 |     Box::new(move |y| x + y)
  |              ++++

For more information about this error, try `rustc --explain E0373`.

Rationale and extra context

AFAIK, this was allowed before edition 2021, but now it is prohibited.

Rust Version

rustc 1.85.0 (4d91de4e4 2025-02-17)
binary: rustc
commit-hash: 4d91de4e48198da2e33413efdcd9cd2cc0c46688
commit-date: 2025-02-17
host: x86_64-unknown-linux-gnu
release: 1.85.0
LLVM version: 19.1.7

Anything else?

No response

@Eclips4 Eclips4 added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 3, 2025
@Eclips4
Copy link
Contributor Author

Eclips4 commented Mar 3, 2025

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 4, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 4, 2025
tgross35 added a commit to tgross35/rust that referenced this issue Mar 4, 2025
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Mar 4, 2025
@bors bors closed this as completed in 48a0d52 Mar 5, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 5, 2025
Rollup merge of rust-lang#137963 - Eclips4:fix-E0373, r=compiler-errors

Add ``dyn`` keyword to `E0373` examples

Closes rust-lang#137962
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant