Rollup merge of #89963 - r00ster91:parenthesisparentheses, r=nagisa
Some "parenthesis" and "parentheses" fixes "Parenthesis" is the singular (e.g. one `(` or one `)`) and "parentheses" is the plural (multiple `(` or `)`s) and this is not hard to mix up so here are some fixes for that. Inspired by #89958
This commit is contained in:
commit
e0e2b3cc43
@ -357,13 +357,13 @@ pub fn order(self) -> i8 {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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`?
|
||||
|
@ -113,7 +113,7 @@ fn ban_let_expr(&self, expr: &'a Expr) {
|
||||
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`)")
|
||||
|
@ -1675,7 +1675,7 @@ fn print_call_post(&mut self, args: &[P<ast::Expr>]) {
|
||||
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) {}`.
|
||||
|
@ -1168,7 +1168,7 @@ fn print_let(&mut self, pat: &hir::Pat<'_>, expr: &hir::Expr<'_>) {
|
||||
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) {}`.
|
||||
|
@ -670,7 +670,7 @@ fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
|
||||
///
|
||||
/// ### 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,
|
||||
|
@ -1342,10 +1342,10 @@ pub(super) fn recover_parens_around_for_head(
|
||||
|
||||
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.
|
||||
|
@ -1258,7 +1258,7 @@ fn is_crate_vis(&self) -> bool {
|
||||
/// 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> {
|
||||
|
@ -328,7 +328,7 @@ fn check_let_else_init_bool_expr(&self, init: &ast::Expr) {
|
||||
),
|
||||
)
|
||||
.multipart_suggestion(
|
||||
"wrap the expression in parenthesis",
|
||||
"wrap the expression in parentheses",
|
||||
suggs,
|
||||
Applicability::MachineApplicable,
|
||||
)
|
||||
@ -349,7 +349,7 @@ fn check_let_else_init_trailing_brace(&self, init: &ast::Expr) {
|
||||
"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,
|
||||
)
|
||||
|
@ -430,7 +430,7 @@ fn parse_borrowed_pointee(&mut self) -> PResult<'a, TyKind> {
|
||||
}
|
||||
|
||||
// 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()?;
|
||||
|
@ -1552,7 +1552,7 @@ fn suggest_using_enum_variant(
|
||||
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)
|
||||
|
@ -300,7 +300,7 @@ fn identify_bad_closure_def_and_call(
|
||||
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,
|
||||
);
|
||||
@ -383,7 +383,7 @@ fn confirm_builtin_call(
|
||||
call_expr.span,
|
||||
&format!(
|
||||
"`{}` is a unit variant, you need to write it \
|
||||
without the parenthesis",
|
||||
without the parentheses",
|
||||
path
|
||||
),
|
||||
path.to_string(),
|
||||
|
@ -492,7 +492,7 @@ fn add_type_neq_err_label(
|
||||
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();
|
||||
|
@ -576,7 +576,7 @@ fn param_env_to_generics(
|
||||
rhs,
|
||||
});
|
||||
continue; // If something other than a Fn ends up
|
||||
// with parenthesis, leave it alone
|
||||
// with parentheses, leave it alone
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
| ~~~~~~~~~
|
||||
@ -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;
|
||||
| ~~~~~~~~~~~
|
||||
|
@ -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;
|
||||
| ~~~~~~~~
|
||||
|
@ -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 };
|
||||
| + +
|
||||
@ -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 };
|
||||
| + +
|
||||
|
@ -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 {
|
||||
| + +
|
||||
@ -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 {
|
||||
| + +
|
||||
@ -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 {
|
||||
| + +
|
||||
@ -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 {
|
||||
| + +
|
||||
|
@ -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,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 {
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
| ~~~~~~~
|
||||
@ -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;
|
||||
| ~~~~~~~~~~
|
||||
@ -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;
|
||||
| ~~~~~~~
|
||||
|
@ -16,7 +16,7 @@ LL | if &let 0 = 0 {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:33:9
|
||||
@ -25,7 +25,7 @@ LL | if !let 0 = 0 {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:34:9
|
||||
@ -34,7 +34,7 @@ LL | if *let 0 = 0 {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:36:9
|
||||
@ -43,7 +43,7 @@ LL | if -let 0 = 0 {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:44:9
|
||||
@ -52,7 +52,7 @@ LL | if (let 0 = 0)? {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:48:16
|
||||
@ -61,7 +61,7 @@ LL | if true || let 0 = 0 {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:49:17
|
||||
@ -70,7 +70,7 @@ LL | if (true || let 0 = 0) {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:50:25
|
||||
@ -79,7 +79,7 @@ LL | if true && (true || let 0 = 0) {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:51:25
|
||||
@ -88,7 +88,7 @@ LL | if true || (true && let 0 = 0) {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:54:12
|
||||
@ -97,7 +97,7 @@ LL | if x = let 0 = 0 {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:57:15
|
||||
@ -106,7 +106,7 @@ LL | if true..(let 0 = 0) {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:59:11
|
||||
@ -115,7 +115,7 @@ LL | if ..(let 0 = 0) {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:61:9
|
||||
@ -124,7 +124,7 @@ LL | if (let 0 = 0).. {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:65:8
|
||||
@ -133,7 +133,7 @@ LL | if let Range { start: _, end: _ } = true..true && false {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:69:8
|
||||
@ -142,7 +142,7 @@ LL | if let Range { start: _, end: _ } = true..true || false {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:76:8
|
||||
@ -151,7 +151,7 @@ LL | if let Range { start: F, end } = F..|| true {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:84:8
|
||||
@ -160,7 +160,7 @@ LL | if let Range { start: true, end } = t..&&false {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:90:19
|
||||
@ -169,7 +169,7 @@ LL | if let true = let true = true {}
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:94:12
|
||||
@ -178,7 +178,7 @@ LL | while &let 0 = 0 {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:97:12
|
||||
@ -187,7 +187,7 @@ LL | while !let 0 = 0 {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:98:12
|
||||
@ -196,7 +196,7 @@ LL | while *let 0 = 0 {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:100:12
|
||||
@ -205,7 +205,7 @@ LL | while -let 0 = 0 {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:108:12
|
||||
@ -214,7 +214,7 @@ LL | while (let 0 = 0)? {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:112:19
|
||||
@ -223,7 +223,7 @@ LL | while true || let 0 = 0 {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:113:20
|
||||
@ -232,7 +232,7 @@ LL | while (true || let 0 = 0) {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:114:28
|
||||
@ -241,7 +241,7 @@ LL | while true && (true || let 0 = 0) {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:115:28
|
||||
@ -250,7 +250,7 @@ LL | while true || (true && let 0 = 0) {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:118:15
|
||||
@ -259,7 +259,7 @@ LL | while x = let 0 = 0 {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:121:18
|
||||
@ -268,7 +268,7 @@ LL | while true..(let 0 = 0) {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:123:14
|
||||
@ -277,7 +277,7 @@ LL | while ..(let 0 = 0) {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:125:12
|
||||
@ -286,7 +286,7 @@ LL | while (let 0 = 0).. {}
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:129:11
|
||||
@ -295,7 +295,7 @@ LL | while let Range { start: _, end: _ } = true..true && false {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:133:11
|
||||
@ -304,7 +304,7 @@ LL | while let Range { start: _, end: _ } = true..true || false {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:140:11
|
||||
@ -313,7 +313,7 @@ LL | while let Range { start: F, end } = F..|| true {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:148:11
|
||||
@ -322,7 +322,7 @@ LL | while let Range { start: true, end } = t..&&false {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:154:22
|
||||
@ -331,7 +331,7 @@ LL | while let true = let true = true {}
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:168:6
|
||||
@ -340,7 +340,7 @@ LL | &let 0 = 0;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:170:6
|
||||
@ -349,7 +349,7 @@ LL | !let 0 = 0;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:171:6
|
||||
@ -358,7 +358,7 @@ LL | *let 0 = 0;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:173:6
|
||||
@ -367,7 +367,7 @@ LL | -let 0 = 0;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:181:6
|
||||
@ -376,7 +376,7 @@ LL | (let 0 = 0)?;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:185:13
|
||||
@ -385,7 +385,7 @@ LL | true || let 0 = 0;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:186:14
|
||||
@ -394,7 +394,7 @@ LL | (true || let 0 = 0);
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:187:22
|
||||
@ -403,7 +403,7 @@ LL | true && (true || let 0 = 0);
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:190:9
|
||||
@ -412,7 +412,7 @@ LL | x = let 0 = 0;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:192:12
|
||||
@ -421,7 +421,7 @@ LL | true..(let 0 = 0);
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:193:8
|
||||
@ -430,7 +430,7 @@ LL | ..(let 0 = 0);
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:194:6
|
||||
@ -439,7 +439,7 @@ LL | (let 0 = 0)..;
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:196:6
|
||||
@ -448,7 +448,7 @@ LL | (let Range { start: _, end: _ } = true..true || false);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:200:6
|
||||
@ -457,7 +457,7 @@ LL | (let true = let true = true);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:204:6
|
||||
@ -466,7 +466,7 @@ LL | &let 0 = 0
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:215:17
|
||||
@ -475,7 +475,7 @@ LL | true && let 1 = 1
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:219:17
|
||||
@ -484,7 +484,7 @@ LL | true && let 1 = 1
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:223:17
|
||||
@ -493,7 +493,7 @@ LL | true && let 1 = 1
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
error: `let` expressions are not supported here
|
||||
--> $DIR/disallowed-positions.rs:233:17
|
||||
@ -502,7 +502,7 @@ LL | true && let 1 = 1
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= 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
|
||||
|
||||
warning: the feature `let_chains` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/disallowed-positions.rs:20:12
|
||||
|
@ -6,7 +6,7 @@ LL | let _ = ||{}();
|
||||
| |
|
||||
| call expression requires function
|
||||
|
|
||||
help: if you meant to create this closure and immediately call it, surround the closure with parenthesis
|
||||
help: if you meant to create this closure and immediately call it, surround the closure with parentheses
|
||||
|
|
||||
LL | let _ = (||{})();
|
||||
| + +
|
||||
|
@ -27,7 +27,7 @@ LL | Alias::Unit();
|
||||
| |
|
||||
| call expression requires function
|
||||
|
|
||||
help: `Alias::Unit` is a unit variant, you need to write it without the parenthesis
|
||||
help: `Alias::Unit` is a unit variant, you need to write it without the parentheses
|
||||
|
|
||||
LL | Alias::Unit;
|
||||
| ~~~~~~~~~~~
|
||||
|
@ -98,7 +98,7 @@ fn applicable_or_arm<'a>(cx: &LateContext<'_>, arms: &'a [Arm<'a>]) -> Option<&'
|
||||
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 {
|
||||
|
@ -16,10 +16,10 @@
|
||||
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>),
|
||||
@ -283,7 +283,7 @@ pub fn range(self, end: &Self, limit: ast::RangeLimits) -> Sugg<'static> {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
|
@ -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> {
|
||||
|
@ -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> {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user