Support pretty-printing dyn* trait objects

This commit is contained in:
David Tolnay 2024-12-20 20:33:59 -08:00
parent 13170cd787
commit 1cc8289791
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
4 changed files with 11 additions and 10 deletions

View file

@ -1204,8 +1204,10 @@ impl<'a> State<'a> {
} }
ast::TyKind::Path(Some(qself), path) => self.print_qpath(path, qself, false), ast::TyKind::Path(Some(qself), path) => self.print_qpath(path, qself, false),
ast::TyKind::TraitObject(bounds, syntax) => { ast::TyKind::TraitObject(bounds, syntax) => {
if *syntax == ast::TraitObjectSyntax::Dyn { match syntax {
self.word_nbsp("dyn"); ast::TraitObjectSyntax::Dyn => self.word_nbsp("dyn"),
ast::TraitObjectSyntax::DynStar => self.word_nbsp("dyn*"),
ast::TraitObjectSyntax::None => {}
} }
self.print_type_bounds(bounds); self.print_type_bounds(bounds);
} }

View file

@ -402,8 +402,10 @@ impl<'a> State<'a> {
} }
hir::TyKind::Path(ref qpath) => self.print_qpath(qpath, false), hir::TyKind::Path(ref qpath) => self.print_qpath(qpath, false),
hir::TyKind::TraitObject(bounds, lifetime, syntax) => { hir::TyKind::TraitObject(bounds, lifetime, syntax) => {
if syntax == ast::TraitObjectSyntax::Dyn { match syntax {
self.word_space("dyn"); ast::TraitObjectSyntax::Dyn => self.word_nbsp("dyn"),
ast::TraitObjectSyntax::DynStar => self.word_nbsp("dyn*"),
ast::TraitObjectSyntax::None => {}
} }
let mut first = true; let mut first = true;
for bound in bounds { for bound in bounds {

View file

@ -129,10 +129,7 @@ static EXPRS: &[&str] = &[
"(0.).to_string()", "(0.).to_string()",
"0. .. 1.", "0. .. 1.",
*/ */
/*
// FIXME: pretty-printer loses the dyn*. `i as Trait`
"i as dyn* Trait", "i as dyn* Trait",
*/
]; ];
// Flatten the content of parenthesis nodes into their parent node. For example // Flatten the content of parenthesis nodes into their parent node. For example

View file

@ -58,14 +58,14 @@ help: consider adding an explicit lifetime bound
LL | executor: impl FnOnce(T) -> (dyn Future<Output = ()>) + 'static, LL | executor: impl FnOnce(T) -> (dyn Future<Output = ()>) + 'static,
| + +++++++++++ | + +++++++++++
error[E0310]: the parameter type `impl FnOnce(T) -> Future<Output = ()>` may not live long enough error[E0310]: the parameter type `impl FnOnce(T) -> dyn* Future<Output = ()>` may not live long enough
--> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:14:5 --> $DIR/wrap-dyn-in-suggestion-issue-120223.rs:14:5
| |
LL | Box::new(executor) LL | Box::new(executor)
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
| | | |
| the parameter type `impl FnOnce(T) -> Future<Output = ()>` must be valid for the static lifetime... | the parameter type `impl FnOnce(T) -> dyn* Future<Output = ()>` must be valid for the static lifetime...
| ...so that the type `impl FnOnce(T) -> Future<Output = ()>` will meet its required lifetime bounds | ...so that the type `impl FnOnce(T) -> dyn* Future<Output = ()>` will meet its required lifetime bounds
| |
help: consider adding an explicit lifetime bound help: consider adding an explicit lifetime bound
| |