Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ pub(crate) struct AutoTraitItems {
#[primary_span]
pub spans: Vec<Span>,
#[suggestion(
"remove the super traits or lifetime bounds",
"remove the associated items",
code = "",
applicability = "machine-applicable",
style = "tool-only"
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) struct CallToDeprecatedSafeFnRequiresUnsafe {

#[derive(Subdiagnostic)]
#[multipart_suggestion(
"you can wrap the call in an `unsafe` block if you can guarantee that the environment access only happens in single-threaded code",
"you can wrap the call in an `unsafe` block if you can guarantee {$guarantee}",
Copy link
Member

@lqd lqd Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, is this correct? guarantee is in the parent diagnostic. If it is, it seems quite error-prone e.g. with respect to refactoring (or complicates checking the syntax at compile time I guess).

Copy link
Contributor Author

@JonathanBrouwer JonathanBrouwer Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is correct, subdiagnostics can use variables from their parent diagnostic, and this message (and quite a few others) do!
This was already the case, I also don't like it, and want to fix it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also why subdiagnostics are currently exempted from the compile-time "do variables exist" check, again, was also already the case before my refactoring

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great to hear, it'll help reduce this magic flexibility for the better, surely.

applicability = "machine-applicable"
)]
pub(crate) struct CallToDeprecatedSafeFnRequiresUnsafeSub {
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,9 @@ pub(crate) enum AmbiguousMissingKwForItemSub {
span: Span,
snippet: String,
},
#[help("you likely meant to define an item, e.g., `{$vis} fn foo() {\"{}\"}`")]
#[help(
"if you meant to call a macro, remove the `pub` and add a trailing `!` after the identifier"
)]
HelpMacro,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this one I can't find a way to trigger this help message (though I didn't try very hard)
At least I added an assertion for the message above :)

}

Expand Down
9 changes: 5 additions & 4 deletions tests/ui/auto-traits/assoc-ty.current.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
error[E0380]: auto traits cannot have associated items
--> $DIR/assoc-ty.rs:10:10
--> $DIR/assoc-ty.rs:11:10
|
LL | auto trait Trait {
| ----- auto traits cannot have associated items
LL |
...
LL | type Output;
| ^^^^^^

Expand All @@ -12,8 +12,9 @@ error[E0658]: auto traits are experimental and possibly buggy
|
LL | / auto trait Trait {
LL | |
LL | | type Output;
LL | |
LL | | type Output;
... |
LL | | }
| |_^
|
Expand All @@ -22,7 +23,7 @@ LL | | }
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0308]: mismatched types
--> $DIR/assoc-ty.rs:15:36
--> $DIR/assoc-ty.rs:17:36
|
LL | let _: <() as Trait>::Output = ();
| --------------------- ^^ expected associated type, found `()`
Expand Down
11 changes: 6 additions & 5 deletions tests/ui/auto-traits/assoc-ty.next.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
error[E0380]: auto traits cannot have associated items
--> $DIR/assoc-ty.rs:10:10
--> $DIR/assoc-ty.rs:11:10
|
LL | auto trait Trait {
| ----- auto traits cannot have associated items
LL |
...
LL | type Output;
| ^^^^^^

Expand All @@ -12,8 +12,9 @@ error[E0658]: auto traits are experimental and possibly buggy
|
LL | / auto trait Trait {
LL | |
LL | | type Output;
LL | |
LL | | type Output;
... |
LL | | }
| |_^
|
Expand All @@ -22,13 +23,13 @@ LL | | }
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error[E0271]: type mismatch resolving `<() as Trait>::Output normalizes-to _`
--> $DIR/assoc-ty.rs:15:12
--> $DIR/assoc-ty.rs:17:12
|
LL | let _: <() as Trait>::Output = ();
| ^^^^^^^^^^^^^^^^^^^^^ types differ

error[E0271]: type mismatch resolving `<() as Trait>::Output normalizes-to _`
--> $DIR/assoc-ty.rs:15:12
--> $DIR/assoc-ty.rs:17:12
|
LL | let _: <() as Trait>::Output = ();
| ^^^^^^^^^^^^^^^^^^^^^ types differ
Expand Down
5 changes: 4 additions & 1 deletion tests/ui/auto-traits/assoc-ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

auto trait Trait {
//~^ ERROR auto traits are experimental and possibly buggy
//~| HELP add `#![feature(auto_traits)]` to the crate attributes to enable
type Output;
//~^ ERROR auto traits cannot have associated items
//~| HELP remove the associated items
}

fn main() {
let _: <() as Trait>::Output = ();
//[current]~^ ERROR mismatched types
//[next]~^^ ERROR type mismatch resolving `<() as Trait>::Output normalizes-to _`
//[current]~| HELP consider constraining the associated type `<() as Trait>::Output` to `()` or calling a method that returns `<() as Trait>::Output`
//[next]~^^^ ERROR type mismatch resolving `<() as Trait>::Output normalizes-to _`
//[next]~| ERROR type mismatch resolving `<() as Trait>::Output normalizes-to _`
}
2 changes: 2 additions & 0 deletions tests/ui/macros/metavar-expressions/usage-errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ curly__rhs_dollar__no_round !(a);
macro_rules! no_curly__no_rhs_dollar__round {
( $( $i:ident ),* ) => { count(i) };
//~^ ERROR missing `fn` or `struct` for function or struct definition
//~| HELP if you meant to call a macro, try
}
no_curly__no_rhs_dollar__round !(a, b, c);

#[rustfmt::skip] // autoformatters can break a few of the error traces
macro_rules! no_curly__no_rhs_dollar__no_round {
( $i:ident ) => { count(i) };
//~^ ERROR missing `fn` or `struct` for function or struct definition
//~| HELP if you meant to call a macro, try
}
no_curly__no_rhs_dollar__no_round !(a);

Expand Down
8 changes: 4 additions & 4 deletions tests/ui/macros/metavar-expressions/usage-errors.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ LL | ( $( $i:ident ),* ) => { count!(i) };
| +

error: missing `fn` or `struct` for function or struct definition
--> $DIR/usage-errors.rs:35:23
--> $DIR/usage-errors.rs:36:23
|
LL | ( $i:ident ) => { count(i) };
| ^^^^^
Expand All @@ -41,13 +41,13 @@ LL | ( $i:ident ) => { count!(i) };
| +

error: variable `i` is still repeating at this depth
--> $DIR/usage-errors.rs:42:36
--> $DIR/usage-errors.rs:44:36
|
LL | ( $( $i:ident ),* ) => { count($i) };
| ^^

error[E0425]: cannot find value `a` in this scope
--> $DIR/usage-errors.rs:52:49
--> $DIR/usage-errors.rs:54:49
|
LL | ( $i:ident ) => { count($i) };
| -- due to this macro variable
Expand All @@ -56,7 +56,7 @@ LL | const _: u32 = no_curly__rhs_dollar__no_round! (a);
| ^ not found in this scope

error[E0425]: cannot find function `count` in this scope
--> $DIR/usage-errors.rs:49:23
--> $DIR/usage-errors.rs:51:23
|
LL | ( $i:ident ) => { count($i) };
| ^^^^^ not found in this scope
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/rust-2024/unsafe-before_exec-suggestion.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ edition:2015
//@ only-unix
//@ run-rustfix

#![deny(deprecated_safe_2024)]

use std::process::Command;
use std::os::unix::process::CommandExt;

#[allow(deprecated)]
fn main() {
let mut cmd = Command::new("sleep");
// TODO: Audit that the closure is async-signal-safe.
unsafe { cmd.before_exec(|| Ok(())) };
//~^ ERROR call to deprecated safe function
//~| WARN this is accepted in the current edition
drop(cmd);
}
17 changes: 17 additions & 0 deletions tests/ui/rust-2024/unsafe-before_exec-suggestion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@ edition:2015
//@ only-unix
//@ run-rustfix

#![deny(deprecated_safe_2024)]

use std::process::Command;
use std::os::unix::process::CommandExt;

#[allow(deprecated)]
fn main() {
let mut cmd = Command::new("sleep");
cmd.before_exec(|| Ok(()));
//~^ ERROR call to deprecated safe function
//~| WARN this is accepted in the current edition
drop(cmd);
}
21 changes: 21 additions & 0 deletions tests/ui/rust-2024/unsafe-before_exec-suggestion.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error: call to deprecated safe function `std::os::unix::process::CommandExt::before_exec` is unsafe and requires unsafe block
--> $DIR/unsafe-before_exec-suggestion.rs:13:5
|
LL | cmd.before_exec(|| Ok(()));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
= note: for more information, see <https://doc.rust-lang.org/edition-guide/rust-2024/newly-unsafe-functions.html>
note: the lint level is defined here
--> $DIR/unsafe-before_exec-suggestion.rs:5:9
|
LL | #![deny(deprecated_safe_2024)]
| ^^^^^^^^^^^^^^^^^^^^
help: you can wrap the call in an `unsafe` block if you can guarantee that the closure is async-signal-safe
|
LL + // TODO: Audit that the closure is async-signal-safe.
LL ~ unsafe { cmd.before_exec(|| Ok(())) };
|

error: aborting due to 1 previous error

Loading