Skip to content

Commit

Permalink
Unrolled build for rust-lang#137769
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#137769 - compiler-errors:empty-unsafe-fmt, r=ytmimi

Do not yeet `unsafe<>` from type when formatting unsafe binder

Unsafe binders are types like `unsafe<'a, 'b> Ty<'a, 'b>`. However, users can also specify unsafe binder types with no bound vars, like `unsafe<> Ty`.

When I added nightly formatting for unsafe binders, I didn't consider this, so on nightly we are stripping the `unsafe<>` part, which gives us back `Ty` which is a different type!

This PR fixes that.

r? ``@ytmimi``
  • Loading branch information
rust-timer authored Mar 1, 2025
2 parents 0c72c0d + 5bf2237 commit bd18f38
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/tools/rustfmt/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,11 @@ impl Rewrite for ast::Ty {
}
ast::TyKind::UnsafeBinder(ref binder) => {
let mut result = String::new();
if let Some(ref lifetime_str) =
if binder.generic_params.is_empty() {
// We always want to write `unsafe<>` since `unsafe<> Ty`
// and `Ty` are distinct types.
result.push_str("unsafe<> ")
} else if let Some(ref lifetime_str) =
rewrite_bound_params(context, shape, &binder.generic_params)
{
result.push_str("unsafe<");
Expand Down
3 changes: 3 additions & 0 deletions src/tools/rustfmt/tests/source/unsafe-binders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ struct Foo {
struct Bar(unsafe<'a> &'a ());

impl Trait for unsafe<'a> &'a () {}

fn empty()
-> unsafe<> () {}
2 changes: 2 additions & 0 deletions src/tools/rustfmt/tests/target/unsafe-binders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ struct Foo {
struct Bar(unsafe<'a> &'a ());

impl Trait for unsafe<'a> &'a () {}

fn empty() -> unsafe<> () {}

0 comments on commit bd18f38

Please sign in to comment.