Skip to content

Commit ada4d0d

Browse files
authored
Rollup merge of rust-lang#120381 - fee1-dead-contrib:reconstify-add, r=compiler-errors
Reconstify `Add` r? project-const-traits I'm not happy with the ui test changes (or failures because I did not bless them and include the diffs in this PR). There is at least some bugs I need to look and try fix: 1. A third duplicated diagnostic when a consumer crate that does not have `effects` enabled has a trait selection error for an upstream const_trait trait. See tests/ui/ufcs/ufcs-qpath-self-mismatch.rs. 2. For some reason, making `Add` a const trait would stop us from suggesting `T: Add` when we try to add two `T`s without that bound. See tests/ui/suggestions/issue-97677.rs
2 parents 2efd952 + 2e1e574 commit ada4d0d

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

Diff for: compiler/rustc_middle/src/ty/diagnostics.rs

+4
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ impl<'tcx, T> IsSuggestable<'tcx> for T
9898
where
9999
T: TypeVisitable<TyCtxt<'tcx>> + TypeFoldable<TyCtxt<'tcx>>,
100100
{
101+
#[tracing::instrument(level = "debug", skip(tcx))]
101102
fn is_suggestable(self, tcx: TyCtxt<'tcx>, infer_suggestable: bool) -> bool {
102103
self.visit_with(&mut IsSuggestableVisitor { tcx, infer_suggestable }).is_continue()
103104
}
@@ -533,6 +534,9 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for IsSuggestableVisitor<'tcx> {
533534
match c.kind() {
534535
ConstKind::Infer(InferConst::Var(_)) if self.infer_suggestable => {}
535536

537+
// effect variables are always suggestable, because they are not visible
538+
ConstKind::Infer(InferConst::EffectVar(_)) => {}
539+
536540
ConstKind::Infer(..)
537541
| ConstKind::Bound(..)
538542
| ConstKind::Placeholder(..)

Diff for: library/core/src/ops/arith.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
append_const_msg
7474
)]
7575
#[doc(alias = "+")]
76+
#[const_trait]
7677
pub trait Add<Rhs = Self> {
7778
/// The resulting type after applying the `+` operator.
7879
#[stable(feature = "rust1", since = "1.0.0")]
@@ -94,7 +95,8 @@ pub trait Add<Rhs = Self> {
9495
macro_rules! add_impl {
9596
($($t:ty)*) => ($(
9697
#[stable(feature = "rust1", since = "1.0.0")]
97-
impl Add for $t {
98+
#[rustc_const_unstable(feature = "const_ops", issue = "90080")]
99+
impl const Add for $t {
98100
type Output = $t;
99101

100102
#[inline]

Diff for: tests/ui/suggestions/invalid-bin-op.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ help: consider annotating `S<T>` with `#[derive(PartialEq)]`
1616
LL + #[derive(PartialEq)]
1717
LL | struct S<T>(T);
1818
|
19+
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
20+
|
21+
LL | pub fn foo<T>(s: S<T>, t: S<T>) where S<T>: PartialEq {
22+
| +++++++++++++++++++++
1923

2024
error: aborting due to 1 previous error
2125

Diff for: tests/ui/ufcs/ufcs-qpath-self-mismatch.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ fn main() {
44
<i32 as Add<u32>>::add(1, 2);
55
//~^ ERROR cannot add `u32` to `i32`
66
//~| ERROR cannot add `u32` to `i32`
7+
//~| ERROR cannot add `u32` to `i32`
78
<i32 as Add<i32>>::add(1u32, 2);
89
//~^ ERROR mismatched types
910
<i32 as Add<i32>>::add(1, 2u32);

Diff for: tests/ui/ufcs/ufcs-qpath-self-mismatch.stderr

+18-5
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,29 @@ LL | <i32 as Add<u32>>::add(1, 2);
1111
<&'a i32 as Add<i32>>
1212
<&i32 as Add<&i32>>
1313

14+
error[E0277]: cannot add `u32` to `i32`
15+
--> $DIR/ufcs-qpath-self-mismatch.rs:4:5
16+
|
17+
LL | <i32 as Add<u32>>::add(1, 2);
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `i32 + u32`
19+
|
20+
= help: the trait `Add<u32>` is not implemented for `i32`
21+
= help: the following other types implement trait `Add<Rhs>`:
22+
<i32 as Add>
23+
<i32 as Add<&i32>>
24+
<&'a i32 as Add<i32>>
25+
<&i32 as Add<&i32>>
26+
1427
error[E0308]: mismatched types
15-
--> $DIR/ufcs-qpath-self-mismatch.rs:7:28
28+
--> $DIR/ufcs-qpath-self-mismatch.rs:8:28
1629
|
1730
LL | <i32 as Add<i32>>::add(1u32, 2);
1831
| ---------------------- ^^^^ expected `i32`, found `u32`
1932
| |
2033
| arguments to this function are incorrect
2134
|
2235
help: the return type of this call is `u32` due to the type of the argument passed
23-
--> $DIR/ufcs-qpath-self-mismatch.rs:7:5
36+
--> $DIR/ufcs-qpath-self-mismatch.rs:8:5
2437
|
2538
LL | <i32 as Add<i32>>::add(1u32, 2);
2639
| ^^^^^^^^^^^^^^^^^^^^^^^----^^^^
@@ -34,15 +47,15 @@ LL | <i32 as Add<i32>>::add(1i32, 2);
3447
| ~~~
3548

3649
error[E0308]: mismatched types
37-
--> $DIR/ufcs-qpath-self-mismatch.rs:9:31
50+
--> $DIR/ufcs-qpath-self-mismatch.rs:10:31
3851
|
3952
LL | <i32 as Add<i32>>::add(1, 2u32);
4053
| ---------------------- ^^^^ expected `i32`, found `u32`
4154
| |
4255
| arguments to this function are incorrect
4356
|
4457
help: the return type of this call is `u32` due to the type of the argument passed
45-
--> $DIR/ufcs-qpath-self-mismatch.rs:9:5
58+
--> $DIR/ufcs-qpath-self-mismatch.rs:10:5
4659
|
4760
LL | <i32 as Add<i32>>::add(1, 2u32);
4861
| ^^^^^^^^^^^^^^^^^^^^^^^^^^----^
@@ -68,7 +81,7 @@ LL | <i32 as Add<u32>>::add(1, 2);
6881
<&'a i32 as Add<i32>>
6982
<&i32 as Add<&i32>>
7083

71-
error: aborting due to 4 previous errors
84+
error: aborting due to 5 previous errors
7285

7386
Some errors have detailed explanations: E0277, E0308.
7487
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)