diff options
| author | Michael Goulet <michael@errs.io> | 2025-02-28 02:59:37 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-02-28 02:59:40 +0000 |
| commit | 5bf22375cf14d31a81362fe4230e4756e01483a0 (patch) | |
| tree | fa4371419fc4c78117a50e6953b1b9a0b3bd9523 | |
| parent | f45d4acf1bb635aa010f19f8a749eed8293203b3 (diff) | |
| download | rust-5bf22375cf14d31a81362fe4230e4756e01483a0.tar.gz rust-5bf22375cf14d31a81362fe4230e4756e01483a0.zip | |
Do not yeet unsafe<> from type
| -rw-r--r-- | src/tools/rustfmt/src/types.rs | 6 | ||||
| -rw-r--r-- | src/tools/rustfmt/tests/source/unsafe-binders.rs | 3 | ||||
| -rw-r--r-- | src/tools/rustfmt/tests/target/unsafe-binders.rs | 2 |
3 files changed, 10 insertions, 1 deletions
diff --git a/src/tools/rustfmt/src/types.rs b/src/tools/rustfmt/src/types.rs index 0009490e86f..7b44b47c719 100644 --- a/src/tools/rustfmt/src/types.rs +++ b/src/tools/rustfmt/src/types.rs @@ -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<"); diff --git a/src/tools/rustfmt/tests/source/unsafe-binders.rs b/src/tools/rustfmt/tests/source/unsafe-binders.rs index ccf7c8bb9af..2f43af54d20 100644 --- a/src/tools/rustfmt/tests/source/unsafe-binders.rs +++ b/src/tools/rustfmt/tests/source/unsafe-binders.rs @@ -9,3 +9,6 @@ struct Foo { struct Bar(unsafe<'a> &'a ()); impl Trait for unsafe<'a> &'a () {} + +fn empty() +-> unsafe<> () {} diff --git a/src/tools/rustfmt/tests/target/unsafe-binders.rs b/src/tools/rustfmt/tests/target/unsafe-binders.rs index 9d308f4a894..d52dc559519 100644 --- a/src/tools/rustfmt/tests/target/unsafe-binders.rs +++ b/src/tools/rustfmt/tests/target/unsafe-binders.rs @@ -7,3 +7,5 @@ struct Foo { struct Bar(unsafe<'a> &'a ()); impl Trait for unsafe<'a> &'a () {} + +fn empty() -> unsafe<> () {} |
