Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pretty-printing dyn* trait objects #134601

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 0 additions & 4 deletions tests/ui-fulldeps/pprust-parenthesis-insertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ help: consider adding an explicit lifetime bound
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
|
LL | Box::new(executor)
| ^^^^^^^^^^^^^^^^^^
| |
| the parameter type `impl FnOnce(T) -> Future<Output = ()>` must be valid for the static lifetime...
| ...so that the type `impl FnOnce(T) -> Future<Output = ()>` will meet its required lifetime bounds
| the parameter type `impl FnOnce(T) -> dyn* Future<Output = ()>` must be valid for the static lifetime...
| ...so that the type `impl FnOnce(T) -> dyn* Future<Output = ()>` will meet its required lifetime bounds
|
help: consider adding an explicit lifetime bound
|
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/unpretty/expanded-exhaustive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -800,6 +801,7 @@ mod types {
let _: dyn Send + 'static;
let _: dyn 'static + Send;
let _: dyn for<'a> Send;
let _: dyn* Send;
}

/// TyKind::ImplTrait
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/unpretty/expanded-exhaustive.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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() {
Expand Down
Loading