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 7fbd4ce commit 3c1d554
Show file tree
Hide file tree
Showing 30 changed files with 100 additions and 100 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/util/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,13 @@ impl ExprPrecedence {
}
}

/// In `let p = e`, operators with precedence `<=` this one requires parenthesis in `e`.
/// In `let p = e`, operators with precedence `<=` this one requires parentheses in `e`.
pub fn prec_let_scrutinee_needs_par() -> usize {
AssocOp::LAnd.precedence()
}

/// Suppose we have `let _ = e` and the `order` of `e`.
/// Is the `order` such that `e` in `let _ = e` needs parenthesis when it is on the RHS?
/// Is the `order` such that `e` in `let _ = e` needs parentheses when it is on the RHS?
///
/// Conversely, suppose that we have `(let _ = a) OP b` and `order` is that of `OP`.
/// Can we print this as `let _ = a OP b`?
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<'a> AstValidator<'a> {
if sess.opts.unstable_features.is_nightly_build() {
sess.struct_span_err(expr.span, "`let` expressions are not supported here")
.note("only supported directly in conditions of `if`- and `while`-expressions")
.note("as well as when nested within `&&` and parenthesis in those conditions")
.note("as well as when nested within `&&` and parentheses in those conditions")
.emit();
} else {
sess.struct_span_err(expr.span, "expected expression, found statement (`let`)")
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ impl<'a> State<'a> {
self.print_expr_cond_paren(expr, Self::cond_needs_par(expr))
}

// Does `expr` need parenthesis when printed in a condition position?
// Does `expr` need parentheses when printed in a condition position?
//
// These cases need parens due to the parse error observed in #26461: `if return {}`
// parses as the erroneous construct `if (return {})`, not `if (return) {}`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,7 @@ impl<'a> State<'a> {
self.print_expr_cond_paren(expr, Self::cond_needs_par(expr) || npals())
}

// Does `expr` need parenthesis when printed in a condition position?
// Does `expr` need parentheses when printed in a condition position?
//
// These cases need parens due to the parse error observed in #26461: `if return {}`
// parses as the erroneous construct `if (return {})`, not `if (return) {}`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ declare_lint! {
///
/// ### Explanation
///
/// The parenthesis are not needed, and should be removed. This is the
/// The parentheses are not needed, and should be removed. This is the
/// preferred style for writing these expressions.
pub(super) UNUSED_PARENS,
Warn,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,10 +1342,10 @@ impl<'a> Parser<'a> {

self.struct_span_err(
MultiSpan::from_spans(vec![begin_par_sp, self.prev_token.span]),
"unexpected parenthesis surrounding `for` loop head",
"unexpected parentheses surrounding `for` loop head",
)
.multipart_suggestion(
"remove parenthesis in `for` loop",
"remove parentheses in `for` loop",
vec![(begin_par_sp, String::new()), (self.prev_token.span, String::new())],
// With e.g. `for (x) in y)` this would replace `(x) in y)`
// with `x) in y)` which is syntactically invalid.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ impl<'a> Parser<'a> {
/// Parses `pub`, `pub(crate)` and `pub(in path)` plus shortcuts `crate` for `pub(crate)`,
/// `pub(self)` for `pub(in self)` and `pub(super)` for `pub(in super)`.
/// If the following element can't be a tuple (i.e., it's a function definition), then
/// it's not a tuple struct field), and the contents within the parentheses isn't valid,
/// it's not a tuple struct field), and the contents within the parentheses aren't valid,
/// so emit a proper diagnostic.
// Public for rustfmt usage.
pub fn parse_visibility(&mut self, fbt: FollowedByType) -> PResult<'a, Visibility> {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_parse/src/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ impl<'a> Parser<'a> {
),
)
.multipart_suggestion(
"wrap the expression in parenthesis",
"wrap the expression in parentheses",
suggs,
Applicability::MachineApplicable,
)
Expand All @@ -349,7 +349,7 @@ impl<'a> Parser<'a> {
"right curly brace `}` before `else` in a `let...else` statement not allowed",
)
.multipart_suggestion(
"try wrapping the expression in parenthesis",
"try wrapping the expression in parentheses",
suggs,
Applicability::MachineApplicable,
)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ impl<'a> Parser<'a> {
}

// Parses the `typeof(EXPR)`.
// To avoid ambiguity, the type is surrounded by parenthesis.
// To avoid ambiguity, the type is surrounded by parentheses.
fn parse_typeof_ty(&mut self) -> PResult<'a, TyKind> {
self.expect(&token::OpenDelim(token::Paren))?;
let expr = self.parse_anon_const_expr()?;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
matches!(source, PathSource::TupleStruct(..)) || source.is_call();
if suggest_only_tuple_variants {
// Suggest only tuple variants regardless of whether they have fields and do not
// suggest path with added parenthesis.
// suggest path with added parentheses.
let mut suggestable_variants = variants
.iter()
.filter(|(.., kind)| *kind == CtorKind::Fn)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/check/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let end = callee_span.shrink_to_hi();
err.multipart_suggestion(
"if you meant to create this closure and immediately call it, surround the \
closure with parenthesis",
closure with parentheses",
vec![(start, "(".to_string()), (end, ")".to_string())],
Applicability::MaybeIncorrect,
);
Expand Down Expand Up @@ -383,7 +383,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
call_expr.span,
&format!(
"`{}` is a unit variant, you need to write it \
without the parenthesis",
without the parentheses",
path
),
path.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
other_ty: Ty<'tcx>,
op: hir::BinOp,
is_assign: IsAssign,
) -> bool /* did we suggest to call a function because of missing parenthesis? */ {
) -> bool /* did we suggest to call a function because of missing parentheses? */ {
err.span_label(span, ty.to_string());
if let FnDef(def_id, _) = *ty.kind() {
let source_map = self.tcx.sess.source_map();
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
rhs,
});
continue; // If something other than a Fn ends up
// with parenthesis, leave it alone
// with parentheses, leave it alone
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/empty/empty-struct-unit-expr.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LL | let e4 = E::Empty4();
| |
| call expression requires function
|
help: `E::Empty4` is a unit variant, you need to write it without the parenthesis
help: `E::Empty4` is a unit variant, you need to write it without the parentheses
|
LL | let e4 = E::Empty4;
| ~~~~~~~~~
Expand All @@ -41,7 +41,7 @@ LL | let xe4 = XE::XEmpty4();
| |
| call expression requires function
|
help: `XE::XEmpty4` is a unit variant, you need to write it without the parenthesis
help: `XE::XEmpty4` is a unit variant, you need to write it without the parentheses
|
LL | let xe4 = XE::XEmpty4;
| ~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0618.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LL | X::Entry();
| |
| call expression requires function
|
help: `X::Entry` is a unit variant, you need to write it without the parenthesis
help: `X::Entry` is a unit variant, you need to write it without the parentheses
|
LL | X::Entry;
| ~~~~~~~~
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/let-else/let-else-bool-binop-init.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: a `&&` expression cannot be directly assigned in `let...else`
LL | let true = true && false else { return };
| ^^^^^^^^^^^^^
|
help: wrap the expression in parenthesis
help: wrap the expression in parentheses
|
LL | let true = (true && false) else { return };
| + +
Expand All @@ -15,7 +15,7 @@ error: a `||` expression cannot be directly assigned in `let...else`
LL | let true = true || false else { return };
| ^^^^^^^^^^^^^
|
help: wrap the expression in parenthesis
help: wrap the expression in parentheses
|
LL | let true = (true || false) else { return };
| + +
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/let-else/let-else-brace-before-else.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: right curly brace `}` before `else` in a `let...else` statement not allow
LL | let Some(1) = { Some(1) } else {
| ^
|
help: try wrapping the expression in parenthesis
help: try wrapping the expression in parentheses
|
LL | let Some(1) = ({ Some(1) }) else {
| + +
Expand All @@ -15,7 +15,7 @@ error: right curly brace `}` before `else` in a `let...else` statement not allow
LL | let Some(1) = loop { break Some(1) } else {
| ^
|
help: try wrapping the expression in parenthesis
help: try wrapping the expression in parentheses
|
LL | let Some(1) = (loop { break Some(1) }) else {
| + +
Expand All @@ -26,7 +26,7 @@ error: right curly brace `}` before `else` in a `let...else` statement not allow
LL | let 2 = 1 + match 1 { n => n } else {
| ^
|
help: try wrapping the expression in parenthesis
help: try wrapping the expression in parentheses
|
LL | let 2 = 1 + (match 1 { n => n }) else {
| + +
Expand All @@ -37,7 +37,7 @@ error: right curly brace `}` before `else` in a `let...else` statement not allow
LL | let Some(1) = unsafe { unsafe_fn() } else {
| ^
|
help: try wrapping the expression in parenthesis
help: try wrapping the expression in parentheses
|
LL | let Some(1) = (unsafe { unsafe_fn() }) else {
| + +
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/parser/recover-for-loop-parens-around-head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn main() {

for ( elem in vec ) {
//~^ ERROR expected one of `)`, `,`, `@`, or `|`, found keyword `in`
//~| ERROR unexpected parenthesis surrounding `for` loop head
//~| ERROR unexpected parentheses surrounding `for` loop head
const RECOVERY_WITNESS: () = 0; //~ ERROR mismatched types
}
}
4 changes: 2 additions & 2 deletions src/test/ui/parser/recover-for-loop-parens-around-head.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ error: expected one of `)`, `,`, `@`, or `|`, found keyword `in`
LL | for ( elem in vec ) {
| ^^ expected one of `)`, `,`, `@`, or `|`

error: unexpected parenthesis surrounding `for` loop head
error: unexpected parentheses surrounding `for` loop head
--> $DIR/recover-for-loop-parens-around-head.rs:10:9
|
LL | for ( elem in vec ) {
| ^ ^
|
help: remove parenthesis in `for` loop
help: remove parentheses in `for` loop
|
LL - for ( elem in vec ) {
LL + for elem in vec {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// the tuple struct pattern, has 0 fields, but requires 1 field.
//
// In emitting E0023, we try to see if this is a case of e.g., `Some(a, b, c)` but where
// the scrutinee was of type `Some((a, b, c))`, and suggest that parenthesis be added.
// the scrutinee was of type `Some((a, b, c))`, and suggest that parentheses be added.
//
// However, we did not account for the expected type being different than the tuple pattern type.
// This caused an issue when the tuple pattern type (`P<T>`) was generic.
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/resolve/privacy-enum-ctor.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ LL | let _ = Z::Unit();
| |
| call expression requires function
|
help: `Z::Unit` is a unit variant, you need to write it without the parenthesis
help: `Z::Unit` is a unit variant, you need to write it without the parentheses
|
LL | let _ = Z::Unit;
| ~~~~~~~
Expand Down Expand Up @@ -372,7 +372,7 @@ LL | let _: E = m::E::Unit();
| |
| call expression requires function
|
help: `m::E::Unit` is a unit variant, you need to write it without the parenthesis
help: `m::E::Unit` is a unit variant, you need to write it without the parentheses
|
LL | let _: E = m::E::Unit;
| ~~~~~~~~~~
Expand Down Expand Up @@ -406,7 +406,7 @@ LL | let _: E = E::Unit();
| |
| call expression requires function
|
help: `E::Unit` is a unit variant, you need to write it without the parenthesis
help: `E::Unit` is a unit variant, you need to write it without the parentheses
|
LL | let _: E = E::Unit;
| ~~~~~~~
Expand Down
Loading

0 comments on commit 3c1d554

Please sign in to comment.