struct PositionalNamedArgsLint {
positional_named_args: Vec<PositionalNamedArg>,
}Expand description
Encapsulates all the named arguments that have been used positionally
Fields
positional_named_args: Vec<PositionalNamedArg>Implementations
sourceimpl PositionalNamedArgsLint
impl PositionalNamedArgsLint
sourcefn maybe_add_positional_named_arg(
&mut self,
current_positional_arg: usize,
total_args_length: usize,
format_argument_index: usize,
ty: PositionalNamedArgType,
cur_piece: usize,
inner_span_to_replace: Option<InnerSpan>,
names: &FxHashMap<Symbol, (usize, Span)>
)
fn maybe_add_positional_named_arg(
&mut self,
current_positional_arg: usize,
total_args_length: usize,
format_argument_index: usize,
ty: PositionalNamedArgType,
cur_piece: usize,
inner_span_to_replace: Option<InnerSpan>,
names: &FxHashMap<Symbol, (usize, Span)>
)
For a given positional argument, check if the index is for a named argument.
Since positional arguments are required to come before named arguments, if the positional index is greater than or equal to the start of named arguments, we know it’s a named argument used positionally.
Example: println!(“{} {} {2}”, 0, a=1, b=2);
In this case, the first piece ({}) would be ArgumentImplicitlyIs with an index of 0. The
total number of arguments is 3 and the number of named arguments is 2, so the start of named
arguments is index 1. Therefore, the index of 0 is okay.
The second piece ({}) would be ArgumentImplicitlyIs with an index of 1, which is the start
of named arguments, and so we should add a lint to use the named argument a.
The third piece ({2}) would be ArgumentIs with an index of 2, which is greater than the
start of named arguments, and so we should add a lint to use the named argument b.
This same check also works for width and precision formatting when either or both are CountIsParam, which contains an index into the arguments.
sourcefn maybe_push(
&mut self,
format_argument_index: usize,
ty: PositionalNamedArgType,
cur_piece: usize,
inner_span_to_replace: Option<InnerSpan>,
names: &FxHashMap<Symbol, (usize, Span)>
)
fn maybe_push(
&mut self,
format_argument_index: usize,
ty: PositionalNamedArgType,
cur_piece: usize,
inner_span_to_replace: Option<InnerSpan>,
names: &FxHashMap<Symbol, (usize, Span)>
)
Try constructing a PositionalNamedArg struct and pushing it into the vec of positional
named arguments. If a named arg associated with format_argument_index cannot be found,
a new item will not be added as the lint cannot be emitted in this case.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for PositionalNamedArgsLint
impl !Send for PositionalNamedArgsLint
impl !Sync for PositionalNamedArgsLint
impl Unpin for PositionalNamedArgsLint
impl UnwindSafe for PositionalNamedArgsLint
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Layout
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference’s “Type Layout” chapter for details on type layout guarantees.
Size: 24 bytes