From 56bf28d4f4236f19f962868f181b15b174d041c4 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 7 Feb 2023 20:22:42 +0000 Subject: [PATCH] Expand const-if-const trait bounds correctly --- compiler/rustc_ast_pretty/src/pprust/state.rs | 14 ++++++++++++-- tests/ui/macros/stringify.rs | 6 +++--- tests/ui/unpretty/ast-const-trait-bound.rs | 4 ++++ tests/ui/unpretty/ast-const-trait-bound.stdout | 4 ++++ 4 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 tests/ui/unpretty/ast-const-trait-bound.rs create mode 100644 tests/ui/unpretty/ast-const-trait-bound.stdout diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index d7767efa984..cd621bc67a1 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1567,8 +1567,18 @@ pub fn print_type_bounds(&mut self, bounds: &[ast::GenericBound]) { match bound { GenericBound::Trait(tref, modifier) => { - if modifier == &TraitBoundModifier::Maybe { - self.word("?"); + match modifier { + TraitBoundModifier::None => {} + TraitBoundModifier::Maybe => { + self.word("?"); + } + TraitBoundModifier::MaybeConst => { + self.word_space("~const"); + } + TraitBoundModifier::MaybeConstMaybe => { + self.word_space("~const"); + self.word("?"); + } } self.print_poly_trait_ref(tref); } diff --git a/tests/ui/macros/stringify.rs b/tests/ui/macros/stringify.rs index 5cd217df6fc..fdc2a7666d6 100644 --- a/tests/ui/macros/stringify.rs +++ b/tests/ui/macros/stringify.rs @@ -626,7 +626,7 @@ impl const Trait for T {} stringify_item!( impl ~const Struct {} ), - "impl Struct {}", // FIXME + "impl ~const Struct {}", ); // ItemKind::MacCall @@ -838,7 +838,7 @@ fn test_ty() { assert_eq!(stringify_ty!(dyn Send + 'a), "dyn Send + 'a"); assert_eq!(stringify_ty!(dyn 'a + Send), "dyn 'a + Send"); assert_eq!(stringify_ty!(dyn ?Sized), "dyn ?Sized"); - assert_eq!(stringify_ty!(dyn ~const Clone), "dyn Clone"); // FIXME + assert_eq!(stringify_ty!(dyn ~const Clone), "dyn ~const Clone"); assert_eq!(stringify_ty!(dyn for<'a> Send), "dyn for<'a> Send"); // TyKind::ImplTrait @@ -846,7 +846,7 @@ fn test_ty() { assert_eq!(stringify_ty!(impl Send + 'a), "impl Send + 'a"); assert_eq!(stringify_ty!(impl 'a + Send), "impl 'a + Send"); assert_eq!(stringify_ty!(impl ?Sized), "impl ?Sized"); - assert_eq!(stringify_ty!(impl ~const Clone), "impl Clone"); // FIXME + assert_eq!(stringify_ty!(impl ~const Clone), "impl ~const Clone"); assert_eq!(stringify_ty!(impl for<'a> Send), "impl for<'a> Send"); // TyKind::Paren diff --git a/tests/ui/unpretty/ast-const-trait-bound.rs b/tests/ui/unpretty/ast-const-trait-bound.rs new file mode 100644 index 00000000000..dbcba7871ec --- /dev/null +++ b/tests/ui/unpretty/ast-const-trait-bound.rs @@ -0,0 +1,4 @@ +// compile-flags: -Zunpretty=normal +// check-pass + +fn foo() where T: ~const Bar {} diff --git a/tests/ui/unpretty/ast-const-trait-bound.stdout b/tests/ui/unpretty/ast-const-trait-bound.stdout new file mode 100644 index 00000000000..dbcba7871ec --- /dev/null +++ b/tests/ui/unpretty/ast-const-trait-bound.stdout @@ -0,0 +1,4 @@ +// compile-flags: -Zunpretty=normal +// check-pass + +fn foo() where T: ~const Bar {} -- 2.44.0