-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Code
use std::ops::ControlFlow;
fn main() {
let mut copy: Vec<U> = three_arg_diff(1, X {}, X {});
match x {
Err(r) => ControlFlow::Break(r),
2_000_000..=3_999_999 => { println!("A")}
}
}
Current output
error[E0308]: `match` arms have incompatible types
--> .\2\test.rs:8:36
|
6 | / match x {
7 | | Err(r) => ControlFlow::Break(r),
| | --------------------- this is found to be of type `ControlFlow<_, _>`
8 | | 2_000_000..=3_999_999 => { println!("A")}
| | ^^^^^^^^^^^^^ expected `ControlFlow<_, _>`, found `()`
9 | | }
| |_____- `match` arms have incompatible types
|
= note: expected enum `ControlFlow<_, _>`
found unit type `()`
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
help: try wrapping the expression in a variant of `ControlFlow`
--> C:\Users\jjl98\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\std\src\macros.rs:142
:23
|
14~ ($($arg:tt)*) => {std::ops::ControlFlow::Continue({
14| $crate::io::_print($crate::format_args_nl!($($arg)*));
14~ })};
--> C:\Users\jjl98\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\std\src\macros.rs:142
:23
|
14~ ($($arg:tt)*) => {std::ops::ControlFlow::Break({
14| $crate::io::_print($crate::format_args_nl!($($arg)*));
14~ })};
|
Desired output
error[E0308]: `match` arms have incompatible types
--> .\2\test.rs:9:36
|
6 | / match x {
7 | | //~^ ERROR cannot move out of `x` as enum variant `Some` which is behind a shared reference
8 | | Err(r) => ControlFlow::Break(r),
| | --------------------- this is found to be of type `ControlFlow<_, _>`
9 | | 2_000_000..=3_999_999 => { println!("A")}
| | ^^^^^^^^^^^^^ expected `ControlFlow<_, _>`, found `()`
10 | | }
| |_____- `match` arms have incompatible types
|
= note: expected enum `ControlFlow<_, _>`
found unit type `()`
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
Rationale and extra context
The suggestion here is incorrect — users should not be prompted to modify code in the standard library. In fact, it would be better not to show any suggestion at all, as was the case in version 1.86. The "Desired Output" shown above is exactly what rustc 1.86.0 (05f9846 2025-03-31) produces.
Other cases
Rust Version
rustc 1.89.0-nightly (1677d46cb 2025-06-10)
binary: rustc
commit-hash: 1677d46cb128cc8f285dbd32b0dc4d7a46437050
commit-date: 2025-06-10
host: x86_64-pc-windows-msvc
release: 1.89.0-nightly
LLVM version: 20.1.5
Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
xizheyin commentedon Jun 12, 2025
There are some similar issues, and it would be better to change the title to “Suggest in non-user-defined external library”. We could start a
Track Issue
to follow up on these issues.hkBst commentedon Jun 12, 2025
Which part prompts the user to modify the standard library?
jjl9807 commentedon Jun 12, 2025
The
help
sub-diagnostic in current output suggests modifyingrustlib/src/rust/library/std/src/macros.rs
by wrapping the expression in aControlFlow
variant.hkBst commentedon Jun 12, 2025
Ah, I see. It's making the suggestion to wrap something in the expansion of
println!
inControlFlow
, instead of suggesting to wrapprintln!
itself.hkBst commentedon Jun 12, 2025
@rustbot labels A-macros