From 48281b003ff84b230947f64aad9054113f757795 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 4 Sep 2022 22:38:12 +0000 Subject: [PATCH] Adjust spacing in suggestion, add a test --- compiler/rustc_middle/src/ty/diagnostics.rs | 4 +-- .../src/traits/error_reporting/suggestions.rs | 4 +-- .../missing-bounds.fixed | 2 +- .../missing-bounds.stderr | 4 +-- src/test/ui/suggestions/issue-97677.fixed | 2 +- src/test/ui/suggestions/issue-97677.stderr | 4 +-- .../ui/suggestions/restrict-type-not-param.rs | 12 +++++++++ .../restrict-type-not-param.stderr | 26 +++++++++++++++++++ .../traits/resolution-in-overloaded-op.stderr | 4 +-- 9 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 src/test/ui/suggestions/restrict-type-not-param.rs create mode 100644 src/test/ui/suggestions/restrict-type-not-param.stderr diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index fc6a77d400d..e4ad96b659b 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -115,9 +115,9 @@ pub fn suggest_arbitrary_trait_bound<'tcx>( // FIXME: this case overlaps with code in TyCtxt::note_and_explain_type_err. // That should be extracted into a helper function. if constraint.ends_with('>') { - constraint = format!("{}, {}={}>", &constraint[..constraint.len() - 1], name, term); + constraint = format!("{}, {} = {}>", &constraint[..constraint.len() - 1], name, term); } else { - constraint.push_str(&format!("<{}={}>", name, term)); + constraint.push_str(&format!("<{} = {}>", name, term)); } } diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 595c68166bc..ecbeb9d79b1 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -608,13 +608,13 @@ fn suggest_restricting_param_bound( // That should be extracted into a helper function. if constraint.ends_with('>') { constraint = format!( - "{}, {}={}>", + "{}, {} = {}>", &constraint[..constraint.len() - 1], name, term ); } else { - constraint.push_str(&format!("<{}={}>", name, term)); + constraint.push_str(&format!("<{} = {}>", name, term)); } } diff --git a/src/test/ui/generic-associated-types/missing-bounds.fixed b/src/test/ui/generic-associated-types/missing-bounds.fixed index 2315810a47a..ee758f19ec1 100644 --- a/src/test/ui/generic-associated-types/missing-bounds.fixed +++ b/src/test/ui/generic-associated-types/missing-bounds.fixed @@ -24,7 +24,7 @@ impl> Add for C { struct D(B); -impl> Add for D { +impl> Add for D { type Output = Self; fn add(self, rhs: Self) -> Self { diff --git a/src/test/ui/generic-associated-types/missing-bounds.stderr b/src/test/ui/generic-associated-types/missing-bounds.stderr index 138c642dd79..c913483a874 100644 --- a/src/test/ui/generic-associated-types/missing-bounds.stderr +++ b/src/test/ui/generic-associated-types/missing-bounds.stderr @@ -66,8 +66,8 @@ LL | Self(self.0 + rhs.0) | help: consider restricting type parameter `B` | -LL | impl> Add for D { - | +++++++++++++++++++++++++ +LL | impl> Add for D { + | +++++++++++++++++++++++++++ error[E0308]: mismatched types --> $DIR/missing-bounds.rs:42:14 diff --git a/src/test/ui/suggestions/issue-97677.fixed b/src/test/ui/suggestions/issue-97677.fixed index 73ca9f97b43..1e7569fa451 100644 --- a/src/test/ui/suggestions/issue-97677.fixed +++ b/src/test/ui/suggestions/issue-97677.fixed @@ -1,6 +1,6 @@ // run-rustfix -fn add_ten>(n: N) -> N { +fn add_ten>(n: N) -> N { n + 10 //~^ ERROR cannot add `{integer}` to `N` } diff --git a/src/test/ui/suggestions/issue-97677.stderr b/src/test/ui/suggestions/issue-97677.stderr index 069b184ac63..575d79267f2 100644 --- a/src/test/ui/suggestions/issue-97677.stderr +++ b/src/test/ui/suggestions/issue-97677.stderr @@ -8,8 +8,8 @@ LL | n + 10 | help: consider restricting type parameter `N` | -LL | fn add_ten>(n: N) -> N { - | ++++++++++++++++++++++++++++++ +LL | fn add_ten>(n: N) -> N { + | ++++++++++++++++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/suggestions/restrict-type-not-param.rs b/src/test/ui/suggestions/restrict-type-not-param.rs new file mode 100644 index 00000000000..60f5ba45c26 --- /dev/null +++ b/src/test/ui/suggestions/restrict-type-not-param.rs @@ -0,0 +1,12 @@ +use std::ops::Add; + +struct Wrapper(T); + +trait Foo {} + +fn qux(a: Wrapper, b: T) -> T { + a + b + //~^ ERROR cannot add `T` to `Wrapper` +} + +fn main() {} diff --git a/src/test/ui/suggestions/restrict-type-not-param.stderr b/src/test/ui/suggestions/restrict-type-not-param.stderr new file mode 100644 index 00000000000..e7d9c5ecbe4 --- /dev/null +++ b/src/test/ui/suggestions/restrict-type-not-param.stderr @@ -0,0 +1,26 @@ +error[E0369]: cannot add `T` to `Wrapper` + --> $DIR/restrict-type-not-param.rs:8:7 + | +LL | a + b + | - ^ - T + | | + | Wrapper + | +note: an implementation of `Add<_>` might be missing for `Wrapper` + --> $DIR/restrict-type-not-param.rs:3:1 + | +LL | struct Wrapper(T); + | ^^^^^^^^^^^^^^^^^ must implement `Add<_>` +note: the following trait must be implemented + --> $SRC_DIR/core/src/ops/arith.rs:LL:COL + | +LL | pub trait Add { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement + | +LL | fn qux(a: Wrapper, b: T) -> T where Wrapper: Add { + | ++++++++++++++++++++++++++++++++++++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0369`. diff --git a/src/test/ui/traits/resolution-in-overloaded-op.stderr b/src/test/ui/traits/resolution-in-overloaded-op.stderr index b67e334d40a..fe5e1d6d285 100644 --- a/src/test/ui/traits/resolution-in-overloaded-op.stderr +++ b/src/test/ui/traits/resolution-in-overloaded-op.stderr @@ -8,8 +8,8 @@ LL | a * b | help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement | -LL | fn foo>(a: &T, b: f64) -> f64 where &T: Mul { - | ++++++++++++++++++++++++++++++ +LL | fn foo>(a: &T, b: f64) -> f64 where &T: Mul { + | ++++++++++++++++++++++++++++++++ error: aborting due to previous error