Skip to content

Commit 9deb747

Browse files
authored
Rollup merge of rust-lang#92256 - fee1-dead:improve-selection-err, r=oli-obk
Improve selection errors for `~const` trait bounds
2 parents 0d5c738 + 21b3baa commit 9deb747

File tree

2 files changed

+58
-11
lines changed

2 files changed

+58
-11
lines changed

core/src/cmp.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,20 @@ use self::Ordering::*;
199199
#[stable(feature = "rust1", since = "1.0.0")]
200200
#[doc(alias = "==")]
201201
#[doc(alias = "!=")]
202-
#[rustc_on_unimplemented(
203-
message = "can't compare `{Self}` with `{Rhs}`",
204-
label = "no implementation for `{Self} == {Rhs}`"
202+
#[cfg_attr(
203+
bootstrap,
204+
rustc_on_unimplemented(
205+
message = "can't compare `{Self}` with `{Rhs}`",
206+
label = "no implementation for `{Self} == {Rhs}`"
207+
)
208+
)]
209+
#[cfg_attr(
210+
not(bootstrap),
211+
rustc_on_unimplemented(
212+
message = "can't compare `{Self}` with `{Rhs}`",
213+
label = "no implementation for `{Self} == {Rhs}`",
214+
append_const_msg,
215+
)
205216
)]
206217
#[rustc_diagnostic_item = "PartialEq"]
207218
pub trait PartialEq<Rhs: ?Sized = Self> {
@@ -1031,9 +1042,20 @@ impl PartialOrd for Ordering {
10311042
#[doc(alias = "<")]
10321043
#[doc(alias = "<=")]
10331044
#[doc(alias = ">=")]
1034-
#[rustc_on_unimplemented(
1035-
message = "can't compare `{Self}` with `{Rhs}`",
1036-
label = "no implementation for `{Self} < {Rhs}` and `{Self} > {Rhs}`"
1045+
#[cfg_attr(
1046+
bootstrap,
1047+
rustc_on_unimplemented(
1048+
message = "can't compare `{Self}` with `{Rhs}`",
1049+
label = "no implementation for `{Self} < {Rhs}` and `{Self} > {Rhs}`",
1050+
)
1051+
)]
1052+
#[cfg_attr(
1053+
not(bootstrap),
1054+
rustc_on_unimplemented(
1055+
message = "can't compare `{Self}` with `{Rhs}`",
1056+
label = "no implementation for `{Self} < {Rhs}` and `{Self} > {Rhs}`",
1057+
append_const_msg,
1058+
)
10371059
)]
10381060
#[rustc_diagnostic_item = "PartialOrd"]
10391061
pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {

core/src/ops/arith.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,36 @@
6565
/// ```
6666
#[lang = "add"]
6767
#[stable(feature = "rust1", since = "1.0.0")]
68-
#[rustc_on_unimplemented(
69-
on(all(_Self = "{integer}", Rhs = "{float}"), message = "cannot add a float to an integer",),
70-
on(all(_Self = "{float}", Rhs = "{integer}"), message = "cannot add an integer to a float",),
71-
message = "cannot add `{Rhs}` to `{Self}`",
72-
label = "no implementation for `{Self} + {Rhs}`"
68+
#[cfg_attr(
69+
bootstrap,
70+
rustc_on_unimplemented(
71+
on(
72+
all(_Self = "{integer}", Rhs = "{float}"),
73+
message = "cannot add a float to an integer",
74+
),
75+
on(
76+
all(_Self = "{float}", Rhs = "{integer}"),
77+
message = "cannot add an integer to a float",
78+
),
79+
message = "cannot add `{Rhs}` to `{Self}`",
80+
label = "no implementation for `{Self} + {Rhs}`"
81+
)
82+
)]
83+
#[cfg_attr(
84+
not(bootstrap),
85+
rustc_on_unimplemented(
86+
on(
87+
all(_Self = "{integer}", Rhs = "{float}"),
88+
message = "cannot add a float to an integer",
89+
),
90+
on(
91+
all(_Self = "{float}", Rhs = "{integer}"),
92+
message = "cannot add an integer to a float",
93+
),
94+
message = "cannot add `{Rhs}` to `{Self}`",
95+
label = "no implementation for `{Self} + {Rhs}`",
96+
append_const_msg,
97+
)
7398
)]
7499
#[doc(alias = "+")]
75100
pub trait Add<Rhs = Self> {

0 commit comments

Comments
 (0)