Skip to content

Commit 48281b0

Browse files
Adjust spacing in suggestion, add a test
1 parent 30e3673 commit 48281b0

File tree

9 files changed

+50
-12
lines changed

9 files changed

+50
-12
lines changed

compiler/rustc_middle/src/ty/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ pub fn suggest_arbitrary_trait_bound<'tcx>(
115115
// FIXME: this case overlaps with code in TyCtxt::note_and_explain_type_err.
116116
// That should be extracted into a helper function.
117117
if constraint.ends_with('>') {
118-
constraint = format!("{}, {}={}>", &constraint[..constraint.len() - 1], name, term);
118+
constraint = format!("{}, {} = {}>", &constraint[..constraint.len() - 1], name, term);
119119
} else {
120-
constraint.push_str(&format!("<{}={}>", name, term));
120+
constraint.push_str(&format!("<{} = {}>", name, term));
121121
}
122122
}
123123

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,13 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
608608
// That should be extracted into a helper function.
609609
if constraint.ends_with('>') {
610610
constraint = format!(
611-
"{}, {}={}>",
611+
"{}, {} = {}>",
612612
&constraint[..constraint.len() - 1],
613613
name,
614614
term
615615
);
616616
} else {
617-
constraint.push_str(&format!("<{}={}>", name, term));
617+
constraint.push_str(&format!("<{} = {}>", name, term));
618618
}
619619
}
620620

src/test/ui/generic-associated-types/missing-bounds.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<B: Add + Add<Output = B>> Add for C<B> {
2424

2525
struct D<B>(B);
2626

27-
impl<B: std::ops::Add<Output=B>> Add for D<B> {
27+
impl<B: std::ops::Add<Output = B>> Add for D<B> {
2828
type Output = Self;
2929

3030
fn add(self, rhs: Self) -> Self {

src/test/ui/generic-associated-types/missing-bounds.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ LL | Self(self.0 + rhs.0)
6666
|
6767
help: consider restricting type parameter `B`
6868
|
69-
LL | impl<B: std::ops::Add<Output=B>> Add for D<B> {
70-
| +++++++++++++++++++++++++
69+
LL | impl<B: std::ops::Add<Output = B>> Add for D<B> {
70+
| +++++++++++++++++++++++++++
7171

7272
error[E0308]: mismatched types
7373
--> $DIR/missing-bounds.rs:42:14

src/test/ui/suggestions/issue-97677.fixed

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-rustfix
22

3-
fn add_ten<N: std::ops::Add<i32, Output=N>>(n: N) -> N {
3+
fn add_ten<N: std::ops::Add<i32, Output = N>>(n: N) -> N {
44
n + 10
55
//~^ ERROR cannot add `{integer}` to `N`
66
}

src/test/ui/suggestions/issue-97677.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | n + 10
88
|
99
help: consider restricting type parameter `N`
1010
|
11-
LL | fn add_ten<N: std::ops::Add<i32, Output=N>>(n: N) -> N {
12-
| ++++++++++++++++++++++++++++++
11+
LL | fn add_ten<N: std::ops::Add<i32, Output = N>>(n: N) -> N {
12+
| ++++++++++++++++++++++++++++++++
1313

1414
error: aborting due to previous error
1515

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use std::ops::Add;
2+
3+
struct Wrapper<T>(T);
4+
5+
trait Foo {}
6+
7+
fn qux<T>(a: Wrapper<T>, b: T) -> T {
8+
a + b
9+
//~^ ERROR cannot add `T` to `Wrapper<T>`
10+
}
11+
12+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0369]: cannot add `T` to `Wrapper<T>`
2+
--> $DIR/restrict-type-not-param.rs:8:7
3+
|
4+
LL | a + b
5+
| - ^ - T
6+
| |
7+
| Wrapper<T>
8+
|
9+
note: an implementation of `Add<_>` might be missing for `Wrapper<T>`
10+
--> $DIR/restrict-type-not-param.rs:3:1
11+
|
12+
LL | struct Wrapper<T>(T);
13+
| ^^^^^^^^^^^^^^^^^ must implement `Add<_>`
14+
note: the following trait must be implemented
15+
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
16+
|
17+
LL | pub trait Add<Rhs = Self> {
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
19+
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
20+
|
21+
LL | fn qux<T>(a: Wrapper<T>, b: T) -> T where Wrapper<T>: Add<T, Output = T> {
22+
| ++++++++++++++++++++++++++++++++++++
23+
24+
error: aborting due to previous error
25+
26+
For more information about this error, try `rustc --explain E0369`.

src/test/ui/traits/resolution-in-overloaded-op.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | a * b
88
|
99
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
1010
|
11-
LL | fn foo<T: MyMul<f64, f64>>(a: &T, b: f64) -> f64 where &T: Mul<f64, Output=f64> {
12-
| ++++++++++++++++++++++++++++++
11+
LL | fn foo<T: MyMul<f64, f64>>(a: &T, b: f64) -> f64 where &T: Mul<f64, Output = f64> {
12+
| ++++++++++++++++++++++++++++++++
1313

1414
error: aborting due to previous error
1515

0 commit comments

Comments
 (0)