Skip to content

Commit 56bf28d

Browse files
Expand const-if-const trait bounds correctly
1 parent e1eaa2d commit 56bf28d

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,8 +1567,18 @@ impl<'a> State<'a> {
15671567

15681568
match bound {
15691569
GenericBound::Trait(tref, modifier) => {
1570-
if modifier == &TraitBoundModifier::Maybe {
1571-
self.word("?");
1570+
match modifier {
1571+
TraitBoundModifier::None => {}
1572+
TraitBoundModifier::Maybe => {
1573+
self.word("?");
1574+
}
1575+
TraitBoundModifier::MaybeConst => {
1576+
self.word_space("~const");
1577+
}
1578+
TraitBoundModifier::MaybeConstMaybe => {
1579+
self.word_space("~const");
1580+
self.word("?");
1581+
}
15721582
}
15731583
self.print_poly_trait_ref(tref);
15741584
}

tests/ui/macros/stringify.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ fn test_item() {
626626
stringify_item!(
627627
impl ~const Struct {}
628628
),
629-
"impl Struct {}", // FIXME
629+
"impl ~const Struct {}",
630630
);
631631

632632
// ItemKind::MacCall
@@ -838,15 +838,15 @@ fn test_ty() {
838838
assert_eq!(stringify_ty!(dyn Send + 'a), "dyn Send + 'a");
839839
assert_eq!(stringify_ty!(dyn 'a + Send), "dyn 'a + Send");
840840
assert_eq!(stringify_ty!(dyn ?Sized), "dyn ?Sized");
841-
assert_eq!(stringify_ty!(dyn ~const Clone), "dyn Clone"); // FIXME
841+
assert_eq!(stringify_ty!(dyn ~const Clone), "dyn ~const Clone");
842842
assert_eq!(stringify_ty!(dyn for<'a> Send), "dyn for<'a> Send");
843843

844844
// TyKind::ImplTrait
845845
assert_eq!(stringify_ty!(impl Send), "impl Send");
846846
assert_eq!(stringify_ty!(impl Send + 'a), "impl Send + 'a");
847847
assert_eq!(stringify_ty!(impl 'a + Send), "impl 'a + Send");
848848
assert_eq!(stringify_ty!(impl ?Sized), "impl ?Sized");
849-
assert_eq!(stringify_ty!(impl ~const Clone), "impl Clone"); // FIXME
849+
assert_eq!(stringify_ty!(impl ~const Clone), "impl ~const Clone");
850850
assert_eq!(stringify_ty!(impl for<'a> Send), "impl for<'a> Send");
851851

852852
// TyKind::Paren
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// compile-flags: -Zunpretty=normal
2+
// check-pass
3+
4+
fn foo() where T: ~const Bar {}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// compile-flags: -Zunpretty=normal
2+
// check-pass
3+
4+
fn foo() where T: ~const Bar {}

0 commit comments

Comments
 (0)