From 1cc8289791570b6d06e5f12dea385d886378089a Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 20 Dec 2024 20:33:59 -0800 Subject: [PATCH 1/2] Support pretty-printing dyn* trait objects --- compiler/rustc_ast_pretty/src/pprust/state.rs | 6 ++++-- compiler/rustc_hir_pretty/src/lib.rs | 6 ++++-- tests/ui-fulldeps/pprust-parenthesis-insertion.rs | 3 --- .../suggestions/wrap-dyn-in-suggestion-issue-120223.stderr | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 24c1c0f221ee3..172df10292920 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1204,8 +1204,10 @@ impl<'a> State<'a> { } ast::TyKind::Path(Some(qself), path) => self.print_qpath(path, qself, false), ast::TyKind::TraitObject(bounds, syntax) => { - if *syntax == ast::TraitObjectSyntax::Dyn { - self.word_nbsp("dyn"); + match syntax { + ast::TraitObjectSyntax::Dyn => self.word_nbsp("dyn"), + ast::TraitObjectSyntax::DynStar => self.word_nbsp("dyn*"), + ast::TraitObjectSyntax::None => {} } self.print_type_bounds(bounds); } diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index de2a7726e9b9e..5c1c58921907e 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -402,8 +402,10 @@ impl<'a> State<'a> { } hir::TyKind::Path(ref qpath) => self.print_qpath(qpath, false), hir::TyKind::TraitObject(bounds, lifetime, syntax) => { - if syntax == ast::TraitObjectSyntax::Dyn { - self.word_space("dyn"); + match syntax { + ast::TraitObjectSyntax::Dyn => self.word_nbsp("dyn"), + ast::TraitObjectSyntax::DynStar => self.word_nbsp("dyn*"), + ast::TraitObjectSyntax::None => {} } let mut first = true; for bound in bounds { diff --git a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs index 184458bad5551..54a8fdf9cd5c8 100644 --- a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs +++ b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs @@ -129,10 +129,7 @@ static EXPRS: &[&str] = &[ "(0.).to_string()", "0. .. 1.", */ - /* - // FIXME: pretty-printer loses the dyn*. `i as Trait` "i as dyn* Trait", - */ ]; // Flatten the content of parenthesis nodes into their parent node. For example diff --git a/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr b/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr index f7fc17ea24f18..1fb3e7d211edb 100644 --- a/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr +++ b/tests/ui/suggestions/wrap-dyn-in-suggestion-issue-120223.stderr @@ -58,14 +58,14 @@ help: consider adding an explicit lifetime bound LL | executor: impl FnOnce(T) -> (dyn Future) + 'static, | + +++++++++++ -error[E0310]: the parameter type `impl FnOnce(T) -> Future` may not live long enough +error[E0310]: the parameter type `impl FnOnce(T) -> dyn* Future` may not live long enough --> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:14:5 | LL | Box::new(executor) | ^^^^^^^^^^^^^^^^^^ | | - | the parameter type `impl FnOnce(T) -> Future` must be valid for the static lifetime... - | ...so that the type `impl FnOnce(T) -> Future` will meet its required lifetime bounds + | the parameter type `impl FnOnce(T) -> dyn* Future` must be valid for the static lifetime... + | ...so that the type `impl FnOnce(T) -> dyn* Future` will meet its required lifetime bounds | help: consider adding an explicit lifetime bound | From 23a250738b6dbba043a4722d18561c0629cfa453 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 20 Dec 2024 20:41:34 -0800 Subject: [PATCH 2/2] Relocate dyn* test out of parenthesis insertion test --- tests/ui-fulldeps/pprust-parenthesis-insertion.rs | 1 - tests/ui/unpretty/expanded-exhaustive.rs | 2 ++ tests/ui/unpretty/expanded-exhaustive.stdout | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs index 54a8fdf9cd5c8..60904c7afec14 100644 --- a/tests/ui-fulldeps/pprust-parenthesis-insertion.rs +++ b/tests/ui-fulldeps/pprust-parenthesis-insertion.rs @@ -129,7 +129,6 @@ static EXPRS: &[&str] = &[ "(0.).to_string()", "0. .. 1.", */ - "i as dyn* Trait", ]; // Flatten the content of parenthesis nodes into their parent node. For example diff --git a/tests/ui/unpretty/expanded-exhaustive.rs b/tests/ui/unpretty/expanded-exhaustive.rs index 98fe05cf7c8b4..e052627e71cfe 100644 --- a/tests/ui/unpretty/expanded-exhaustive.rs +++ b/tests/ui/unpretty/expanded-exhaustive.rs @@ -9,6 +9,7 @@ #![feature(const_trait_impl)] #![feature(decl_macro)] #![feature(deref_patterns)] +#![feature(dyn_star)] #![feature(explicit_tail_calls)] #![feature(gen_blocks)] #![feature(let_chains)] @@ -800,6 +801,7 @@ mod types { let _: dyn Send + 'static; let _: dyn 'static + Send; let _: dyn for<'a> Send; + let _: dyn* Send; } /// TyKind::ImplTrait diff --git a/tests/ui/unpretty/expanded-exhaustive.stdout b/tests/ui/unpretty/expanded-exhaustive.stdout index 452c06dd7e4e7..132d00cd8edd5 100644 --- a/tests/ui/unpretty/expanded-exhaustive.stdout +++ b/tests/ui/unpretty/expanded-exhaustive.stdout @@ -10,6 +10,7 @@ #![feature(const_trait_impl)] #![feature(decl_macro)] #![feature(deref_patterns)] +#![feature(dyn_star)] #![feature(explicit_tail_calls)] #![feature(gen_blocks)] #![feature(let_chains)] @@ -647,6 +648,7 @@ mod types { let _: dyn Send + 'static; let _: dyn 'static + Send; let _: dyn for<'a> Send; + let _: dyn* Send; } /// TyKind::ImplTrait const fn ty_impl_trait() {