Skip to content

Commit

Permalink
Some "parenthesis" and "parentheses" fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wooster0 committed Oct 17, 2021
1 parent 049ab82 commit 599d912
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/manual_unwrap_or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
reindent_multiline(or_body_snippet.into(), true, Some(indent));

let suggestion = if scrutinee.span.from_expansion() {
// we don't want parenthesis around macro, e.g. `(some_macro!()).unwrap_or(0)`
// we don't want parentheses around macro, e.g. `(some_macro!()).unwrap_or(0)`
sugg::Sugg::hir_with_macro_callsite(cx, scrutinee, "..")
}
else {
Expand Down
6 changes: 3 additions & 3 deletions clippy_utils/src/sugg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use std::convert::TryInto;
use std::fmt::Display;
use std::ops::{Add, Neg, Not, Sub};

/// A helper type to build suggestion correctly handling parenthesis.
/// A helper type to build suggestion correctly handling parentheses.
#[derive(Clone, PartialEq)]
pub enum Sugg<'a> {
/// An expression that never needs parenthesis such as `1337` or `[0; 42]`.
/// An expression that never needs parentheses such as `1337` or `[0; 42]`.
NonParen(Cow<'a, str>),
/// An expression that does not fit in other variants.
MaybeParen(Cow<'a, str>),
Expand Down Expand Up @@ -283,7 +283,7 @@ impl<'a> Sugg<'a> {
}
}

/// Adds parenthesis to any expression that might need them. Suitable to the
/// Adds parentheses to any expression that might need them. Suitable to the
/// `self` argument of a method call
/// (e.g., to build `bar.foo()` or `(1 + 2).foo()`).
pub fn maybe_par(self) -> Self {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/manual_unwrap_or.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ fn result_unwrap_or() {
let a = Ok::<i32, &str>(1);
a.unwrap_or(42);

// int case, suggestion must surround Result expr with parenthesis
// int case, suggestion must surround Result expr with parentheses
(Ok(1) as Result<i32, &str>).unwrap_or(42);

// method call case, suggestion must not surround Result expr `s.method()` with parenthesis
// method call case, suggestion must not surround Result expr `s.method()` with parentheses
struct S {}
impl S {
fn method(self) -> Option<i32> {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/manual_unwrap_or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ fn result_unwrap_or() {
Err(_) => 42,
};

// int case, suggestion must surround Result expr with parenthesis
// int case, suggestion must surround Result expr with parentheses
match Ok(1) as Result<i32, &str> {
Ok(i) => i,
Err(_) => 42,
};

// method call case, suggestion must not surround Result expr `s.method()` with parenthesis
// method call case, suggestion must not surround Result expr `s.method()` with parentheses
struct S {}
impl S {
fn method(self) -> Option<i32> {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/useless_conversion.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn main() {
let _ = vec![1, 2, 3].into_iter();
let _: String = format!("Hello {}", "world");

// keep parenthesis around `a + b` for suggestion (see #4750)
// keep parentheses around `a + b` for suggestion (see #4750)
let a: i32 = 1;
let b: i32 = 1;
let _ = (a + b) * 3;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/useless_conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn main() {
let _ = vec![1, 2, 3].into_iter().into_iter();
let _: String = format!("Hello {}", "world").into();

// keep parenthesis around `a + b` for suggestion (see #4750)
// keep parentheses around `a + b` for suggestion (see #4750)
let a: i32 = 1;
let b: i32 = 1;
let _ = i32::from(a + b) * 3;
Expand Down

0 comments on commit 599d912

Please sign in to comment.