diff options
| author | Ömer Sinan Ağacan <omeragacan@gmail.com> | 2021-01-26 13:10:54 +0300 |
|---|---|---|
| committer | Ömer Sinan Ağacan <omeragacan@gmail.com> | 2021-01-26 13:23:30 +0300 |
| commit | 8ddc1c83f2fe56c2087bd5ee743720ec607b76df (patch) | |
| tree | a8c3a42c8a3519969002923e289aa751f5b598f8 /src/test | |
| parent | a8f707553276a15565860af3d415aae18428aa96 (diff) | |
Refine "remove semicolon" suggestion in trait selection
Don't suggest it if the last statement doesn't have a semicolon Fixes #81098 See also #54771 for why this suggestion was added
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/suggestions/issue-81098.rs | 13 | ||||
| -rw-r--r-- | src/test/ui/suggestions/issue-81098.stderr | 23 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/issue-81098.rs b/src/test/ui/suggestions/issue-81098.rs new file mode 100644 index 00000000000..a601b5866f4 --- /dev/null +++ b/src/test/ui/suggestions/issue-81098.rs @@ -0,0 +1,13 @@ +// Don't suggest removing a semicolon if the last statement isn't an expression with semicolon +// (#81098) +fn wat() -> impl core::fmt::Display { //~ ERROR: `()` doesn't implement `std::fmt::Display` + fn why() {} +} + +// Do it if the last statement is an expression with semicolon +// (#54771) +fn ok() -> impl core::fmt::Display { //~ ERROR: `()` doesn't implement `std::fmt::Display` + 1; +} + +fn main() {} diff --git a/src/test/ui/suggestions/issue-81098.stderr b/src/test/ui/suggestions/issue-81098.stderr new file mode 100644 index 00000000000..2a72159e577 --- /dev/null +++ b/src/test/ui/suggestions/issue-81098.stderr @@ -0,0 +1,23 @@ +error[E0277]: `()` doesn't implement `std::fmt::Display` + --> $DIR/issue-81098.rs:3:13 + | +LL | fn wat() -> impl core::fmt::Display { + | ^^^^^^^^^^^^^^^^^^^^^^^ `()` cannot be formatted with the default formatter + | + = help: the trait `std::fmt::Display` is not implemented for `()` + = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead + +error[E0277]: `()` doesn't implement `std::fmt::Display` + --> $DIR/issue-81098.rs:9:12 + | +LL | fn ok() -> impl core::fmt::Display { + | ^^^^^^^^^^^^^^^^^^^^^^^ `()` cannot be formatted with the default formatter +LL | 1; + | - consider removing this semicolon + | + = help: the trait `std::fmt::Display` is not implemented for `()` + = note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. |
