From afa35e90ef4e813f83052e0e66fde893b9a29722 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 9 Dec 2023 17:55:07 +0000 Subject: [PATCH] Print constness in TraitPredPrintModifiersAndPath --- compiler/rustc_middle/src/ty/print/pretty.rs | 9 ++++++--- .../call-const-trait-method-fail.stderr | 2 +- .../call-generic-method-nonconst.stderr | 2 +- .../const-default-method-bodies.stderr | 2 +- .../rfc-2632-const-trait-impl/cross-crate.gatednc.stderr | 2 +- .../default-method-body-is-const-same-trait-ck.stderr | 2 +- 6 files changed, 11 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 2179d6e9c3c9..fd53111001b7 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2880,11 +2880,15 @@ define_print_and_forward_display! { } TraitPredPrintModifiersAndPath<'tcx> { - // FIXME(effects) print `~const` here + if let Some(idx) = cx.tcx().generics_of(self.0.trait_ref.def_id).host_effect_index + { + if self.0.trait_ref.args.const_at(idx) != cx.tcx().consts.true_ { + p!("~const "); + } + } if let ty::ImplPolarity::Negative = self.0.polarity { p!("!") } - p!(print(self.0.trait_ref.print_only_trait_path())); } @@ -2919,7 +2923,6 @@ define_print_and_forward_display! { p!("~const "); } } - // FIXME(effects) print `~const` here if let ty::ImplPolarity::Negative = self.polarity { p!("!"); } diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr index 8d809907a535..93d520f29ef2 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr @@ -2,7 +2,7 @@ error[E0277]: the trait bound `u32: ~const Plus` is not satisfied --> $DIR/call-const-trait-method-fail.rs:25:5 | LL | a.plus(b) - | ^ the trait `Plus` is not implemented for `u32` + | ^ the trait `~const Plus` is not implemented for `u32` | = help: the trait `Plus` is implemented for `u32` diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr index a2ff4dd6e77b..aea9a39b2610 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr @@ -2,7 +2,7 @@ error[E0277]: the trait bound `S: ~const Foo` is not satisfied --> $DIR/call-generic-method-nonconst.rs:23:34 | LL | pub const EQ: bool = equals_self(&S); - | ----------- ^^ the trait `Foo` is not implemented for `S` + | ----------- ^^ the trait `~const Foo` is not implemented for `S` | | | required by a bound introduced by this call | diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-default-method-bodies.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-default-method-bodies.stderr index 111a6a3fc7f8..f39e6dcadbaa 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/const-default-method-bodies.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/const-default-method-bodies.stderr @@ -2,7 +2,7 @@ error[E0277]: the trait bound `NonConstImpl: ~const ConstDefaultFn` is not satis --> $DIR/const-default-method-bodies.rs:24:18 | LL | NonConstImpl.a(); - | ^ the trait `ConstDefaultFn` is not implemented for `NonConstImpl` + | ^ the trait `~const ConstDefaultFn` is not implemented for `NonConstImpl` | = help: the trait `ConstDefaultFn` is implemented for `NonConstImpl` diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr index ed647aee8c37..f0ac953fd5d2 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/cross-crate.gatednc.stderr @@ -2,7 +2,7 @@ error[E0277]: the trait bound `cross_crate::NonConst: ~const cross_crate::MyTrai --> $DIR/cross-crate.rs:17:14 | LL | NonConst.func(); - | ^^^^ the trait `cross_crate::MyTrait` is not implemented for `cross_crate::NonConst` + | ^^^^ the trait `~const cross_crate::MyTrait` is not implemented for `cross_crate::NonConst` | = help: the trait `cross_crate::MyTrait` is implemented for `cross_crate::NonConst` diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr index d8e2c0ffb813..29db6109a98c 100644 --- a/tests/ui/rfcs/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/default-method-body-is-const-same-trait-ck.stderr @@ -2,7 +2,7 @@ error[E0277]: the trait bound `(): ~const Tr` is not satisfied --> $DIR/default-method-body-is-const-same-trait-ck.rs:8:12 | LL | ().a() - | ^ the trait `Tr` is not implemented for `()` + | ^ the trait `~const Tr` is not implemented for `()` | = help: the trait `Tr` is implemented for `()`