Rollup merge of #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``
This commit is contained in:
Matthias Krüger 2025-03-01 11:34:00 +01:00 committed by GitHub
commit b7853ef3cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 1 deletions

View File

@ -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<");

View File

@ -9,3 +9,6 @@ struct Foo {
struct Bar(unsafe<'a> &'a ());
impl Trait for unsafe<'a> &'a () {}
fn empty()
-> unsafe<> () {}

View File

@ -7,3 +7,5 @@ struct Foo {
struct Bar(unsafe<'a> &'a ());
impl Trait for unsafe<'a> &'a () {}
fn empty() -> unsafe<> () {}