trait UnusedDelimLint {
const DELIM_STR: &'static str;
const LINT_EXPR_IN_PATTERN_MATCHING_CTX: bool;
// Required methods
fn lint(&self) -> &'static Lint;
fn check_unused_delims_expr(
&self,
cx: &EarlyContext<'_>,
value: &Expr,
ctx: UnusedDelimsCtx,
followed_by_block: bool,
left_pos: Option<BytePos>,
right_pos: Option<BytePos>,
is_kw: bool,
);
// Provided methods
fn expr_allows_remove_arg_block(expr: &Expr) -> bool { ... }
fn needs_arg_block_to_preserve_temporaries(
ctx: UnusedDelimsCtx,
arg_block: &Expr,
expr: &Expr,
) -> bool { ... }
fn is_expr_delims_necessary(
inner: &Expr,
ctx: UnusedDelimsCtx,
followed_by_block: bool,
) -> bool { ... }
fn emit_unused_delims_expr(
&self,
cx: &EarlyContext<'_>,
value: &Expr,
ctx: UnusedDelimsCtx,
left_pos: Option<BytePos>,
right_pos: Option<BytePos>,
is_kw: bool,
) { ... }
fn emit_unused_delims(
&self,
cx: &EarlyContext<'_>,
value_span: Span,
spans: Option<(Span, Span)>,
msg: &str,
keep_space: (bool, bool),
is_kw: bool,
) { ... }
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr) { ... }
fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &Stmt) { ... }
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item) { ... }
fn block_wraps_expanded_expr(value: &Expr) -> bool { ... }
}Expand description
Used by both UnusedParens and UnusedBraces to prevent code duplication.
Required Associated Constants§
const DELIM_STR: &'static str
Sourceconst LINT_EXPR_IN_PATTERN_MATCHING_CTX: bool
const LINT_EXPR_IN_PATTERN_MATCHING_CTX: bool
Due to ref pattern, there can be a difference between using
{ expr } and expr in pattern-matching contexts. This means
that we should only lint unused_parens and not unused_braces
in this case.
let mut a = 7;
let ref b = { a }; // We actually borrow a copy of `a` here.
a += 1; // By mutating `a` we invalidate any borrows of `a`.
assert_eq!(b + 1, a); // `b` does not borrow `a`, so we can still use it here.Required Methods§
fn lint(&self) -> &'static Lint
fn check_unused_delims_expr( &self, cx: &EarlyContext<'_>, value: &Expr, ctx: UnusedDelimsCtx, followed_by_block: bool, left_pos: Option<BytePos>, right_pos: Option<BytePos>, is_kw: bool, )
Provided Methods§
Sourcefn expr_allows_remove_arg_block(expr: &Expr) -> bool
fn expr_allows_remove_arg_block(expr: &Expr) -> bool
Returns whether the outer braces of a single-expression function/method argument block can be removed.
In Rust 2024, { expr } can drop tail-expression temporaries before the
call starts. Removing the block may extend those temporaries, so lint only
expression forms that are harmless here.
Sourcefn needs_arg_block_to_preserve_temporaries(
ctx: UnusedDelimsCtx,
arg_block: &Expr,
expr: &Expr,
) -> bool
fn needs_arg_block_to_preserve_temporaries( ctx: UnusedDelimsCtx, arg_block: &Expr, expr: &Expr, ) -> bool
Returns whether { expr } must be kept in function/method argument
position to avoid changing temporary lifetime semantics.
fn is_expr_delims_necessary( inner: &Expr, ctx: UnusedDelimsCtx, followed_by_block: bool, ) -> bool
fn emit_unused_delims_expr( &self, cx: &EarlyContext<'_>, value: &Expr, ctx: UnusedDelimsCtx, left_pos: Option<BytePos>, right_pos: Option<BytePos>, is_kw: bool, )
fn emit_unused_delims( &self, cx: &EarlyContext<'_>, value_span: Span, spans: Option<(Span, Span)>, msg: &str, keep_space: (bool, bool), is_kw: bool, )
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &Expr)
fn check_stmt(&mut self, cx: &EarlyContext<'_>, s: &Stmt)
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &Item)
fn block_wraps_expanded_expr(value: &Expr) -> bool
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".