mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 16:54:01 +00:00
final clippy changes
This commit is contained in:
parent
b1da2a53b4
commit
968affc3e0
@ -48,7 +48,7 @@ fn is_derive(attr: &ast::Attribute) -> bool {
|
||||
}
|
||||
|
||||
/// Returns the arguments of `#[derive(...)]`.
|
||||
fn get_derive_spans<'a>(attr: &ast::Attribute) -> Option<Vec<Span>> {
|
||||
fn get_derive_spans(attr: &ast::Attribute) -> Option<Vec<Span>> {
|
||||
attr.meta_item_list().map(|meta_item_list| {
|
||||
meta_item_list
|
||||
.iter()
|
||||
|
@ -172,19 +172,19 @@ fn execute(opts: &Options) -> Result<i32, failure::Error> {
|
||||
match determine_operation(&matches)? {
|
||||
Operation::Help(HelpOp::None) => {
|
||||
print_usage_to_stdout(opts, "");
|
||||
return Ok(0);
|
||||
Ok(0)
|
||||
}
|
||||
Operation::Help(HelpOp::Config) => {
|
||||
Config::print_docs(&mut stdout(), options.unstable_features);
|
||||
return Ok(0);
|
||||
Ok(0)
|
||||
}
|
||||
Operation::Help(HelpOp::FileLines) => {
|
||||
print_help_file_lines();
|
||||
return Ok(0);
|
||||
Ok(0)
|
||||
}
|
||||
Operation::Version => {
|
||||
print_version();
|
||||
return Ok(0);
|
||||
Ok(0)
|
||||
}
|
||||
Operation::ConfigOutputDefault { path } => {
|
||||
let toml = Config::default().all_options().to_toml().map_err(err_msg)?;
|
||||
@ -194,13 +194,13 @@ fn execute(opts: &Options) -> Result<i32, failure::Error> {
|
||||
} else {
|
||||
io::stdout().write_all(toml.as_bytes())?;
|
||||
}
|
||||
return Ok(0);
|
||||
Ok(0)
|
||||
}
|
||||
Operation::Stdin { input } => format_string(input, options),
|
||||
Operation::Format {
|
||||
files,
|
||||
minimal_config_path,
|
||||
} => format(files, minimal_config_path, options),
|
||||
} => format(files, minimal_config_path, &options),
|
||||
}
|
||||
}
|
||||
|
||||
@ -236,7 +236,7 @@ fn format_string(input: String, options: GetOptsOptions) -> Result<i32, failure:
|
||||
fn format(
|
||||
files: Vec<PathBuf>,
|
||||
minimal_config_path: Option<String>,
|
||||
options: GetOptsOptions,
|
||||
options: &GetOptsOptions,
|
||||
) -> Result<i32, failure::Error> {
|
||||
options.verify_file_lines(&files);
|
||||
let (config, config_path) = load_config(None, Some(options.clone()))?;
|
||||
|
@ -47,7 +47,7 @@ fn custom_opener(s: &str) -> &str {
|
||||
s.lines().next().map_or("", |first_line| {
|
||||
first_line
|
||||
.find(' ')
|
||||
.map_or(first_line, |space_index| &first_line[0..space_index + 1])
|
||||
.map_or(first_line, |space_index| &first_line[0..=space_index])
|
||||
})
|
||||
}
|
||||
|
||||
@ -1151,7 +1151,7 @@ pub fn recover_comment_removed(
|
||||
context.report.append(
|
||||
context.source_map.span_to_filename(span).into(),
|
||||
vec![FormattingError::from_span(
|
||||
&span,
|
||||
span,
|
||||
&context.source_map,
|
||||
ErrorKind::LostComment,
|
||||
)],
|
||||
@ -1428,7 +1428,7 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_remove_trailing_white_spaces() {
|
||||
let s = format!(" r#\"\n test\n \"#");
|
||||
let s = " r#\"\n test\n \"#";
|
||||
assert_eq!(remove_trailing_white_spaces(&s), s);
|
||||
}
|
||||
|
||||
|
@ -264,7 +264,7 @@ configuration_option_enum! { Color:
|
||||
|
||||
impl Color {
|
||||
/// Whether we should use a coloured terminal.
|
||||
pub fn use_colored_tty(&self) -> bool {
|
||||
pub fn use_colored_tty(self) -> bool {
|
||||
match self {
|
||||
Color::Always => true,
|
||||
Color::Never => false,
|
||||
@ -417,7 +417,7 @@ configuration_option_enum!{ Edition:
|
||||
}
|
||||
|
||||
impl Edition {
|
||||
pub(crate) fn to_libsyntax_pos_edition(&self) -> syntax_pos::edition::Edition {
|
||||
pub(crate) fn to_libsyntax_pos_edition(self) -> syntax_pos::edition::Edition {
|
||||
match self {
|
||||
Edition::Edition2015 => syntax_pos::edition::Edition::Edition2015,
|
||||
Edition::Edition2018 => syntax_pos::edition::Edition::Edition2018,
|
||||
|
14
src/expr.rs
14
src/expr.rs
@ -100,7 +100,7 @@ pub fn format_expr(
|
||||
)
|
||||
})
|
||||
}
|
||||
ast::ExprKind::Unary(ref op, ref subexpr) => rewrite_unary_op(context, op, subexpr, shape),
|
||||
ast::ExprKind::Unary(op, ref subexpr) => rewrite_unary_op(context, op, subexpr, shape),
|
||||
ast::ExprKind::Struct(ref path, ref fields, ref base) => rewrite_struct_lit(
|
||||
context,
|
||||
path,
|
||||
@ -1519,7 +1519,7 @@ fn rewrite_index(
|
||||
}
|
||||
}
|
||||
|
||||
fn struct_lit_can_be_aligned(fields: &[ast::Field], base: &Option<&ast::Expr>) -> bool {
|
||||
fn struct_lit_can_be_aligned(fields: &[ast::Field], base: Option<&ast::Expr>) -> bool {
|
||||
if base.is_some() {
|
||||
return false;
|
||||
}
|
||||
@ -1555,7 +1555,7 @@ fn rewrite_struct_lit<'a>(
|
||||
|
||||
let one_line_width = h_shape.map_or(0, |shape| shape.width);
|
||||
let body_lo = context.snippet_provider.span_after(span, "{");
|
||||
let fields_str = if struct_lit_can_be_aligned(fields, &base)
|
||||
let fields_str = if struct_lit_can_be_aligned(fields, base)
|
||||
&& context.config.struct_field_align_threshold() > 0
|
||||
{
|
||||
rewrite_with_alignment(
|
||||
@ -1676,7 +1676,7 @@ pub fn rewrite_field(
|
||||
};
|
||||
let name = context.snippet(field.ident.span);
|
||||
if field.is_shorthand {
|
||||
Some(attrs_str + &name)
|
||||
Some(attrs_str + name)
|
||||
} else {
|
||||
let mut separator = String::from(struct_lit_field_separator(context.config));
|
||||
for _ in 0..prefix_max_width.saturating_sub(name.len()) {
|
||||
@ -1688,7 +1688,7 @@ pub fn rewrite_field(
|
||||
|
||||
match expr {
|
||||
Some(ref e) if e.as_str() == name && context.config.use_field_init_shorthand() => {
|
||||
Some(attrs_str + &name)
|
||||
Some(attrs_str + name)
|
||||
}
|
||||
Some(e) => Some(format!("{}{}{}{}", attrs_str, name, separator, e)),
|
||||
None => {
|
||||
@ -1827,12 +1827,12 @@ pub fn rewrite_unary_suffix<R: Rewrite>(
|
||||
|
||||
fn rewrite_unary_op(
|
||||
context: &RewriteContext,
|
||||
op: &ast::UnOp,
|
||||
op: ast::UnOp,
|
||||
expr: &ast::Expr,
|
||||
shape: Shape,
|
||||
) -> Option<String> {
|
||||
// For some reason, an UnOp is not spanned like BinOp!
|
||||
let operator_str = match *op {
|
||||
let operator_str = match op {
|
||||
ast::UnOp::Deref => "*",
|
||||
ast::UnOp::Not => "!",
|
||||
ast::UnOp::Neg => "-",
|
||||
|
@ -214,7 +214,7 @@ where
|
||||
|
||||
#[test]
|
||||
fn scan_simple_git_diff() {
|
||||
const DIFF: &'static str = include_str!("test/bindgen.diff");
|
||||
const DIFF: &str = include_str!("test/bindgen.diff");
|
||||
let (files, ranges) = scan_diff(DIFF.as_bytes(), 1, r".*\.rs").expect("scan_diff failed?");
|
||||
|
||||
assert!(
|
||||
|
@ -194,11 +194,11 @@ impl<'b, T: Write + 'b> FormatHandler for Session<'b, T> {
|
||||
fn handle_formatted_file(
|
||||
&mut self,
|
||||
path: FileName,
|
||||
mut result: String,
|
||||
result: String,
|
||||
report: &mut FormatReport,
|
||||
) -> Result<(), ErrorKind> {
|
||||
if let Some(ref mut out) = self.out {
|
||||
match source_file::write_file(&mut result, &path, out, &self.config) {
|
||||
match source_file::write_file(&result, &path, out, &self.config) {
|
||||
Ok(b) if b => report.add_diff(),
|
||||
Err(e) => {
|
||||
// Create a new error with path_str to help users see which files failed
|
||||
@ -224,7 +224,7 @@ pub(crate) struct FormattingError {
|
||||
|
||||
impl FormattingError {
|
||||
pub(crate) fn from_span(
|
||||
span: &Span,
|
||||
span: Span,
|
||||
source_map: &SourceMap,
|
||||
kind: ErrorKind,
|
||||
) -> FormattingError {
|
||||
@ -234,13 +234,13 @@ impl FormattingError {
|
||||
kind,
|
||||
is_string: false,
|
||||
line_buffer: source_map
|
||||
.span_to_lines(*span)
|
||||
.span_to_lines(span)
|
||||
.ok()
|
||||
.and_then(|fl| {
|
||||
fl.file
|
||||
.get_line(fl.lines[0].line_index)
|
||||
.map(|l| l.into_owned())
|
||||
}).unwrap_or_else(|| String::new()),
|
||||
}).unwrap_or_else(String::new),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ pub fn merge_use_trees(use_trees: Vec<UseTree>) -> Vec<UseTree> {
|
||||
fn merge_use_trees_inner(trees: &mut Vec<UseTree>, use_tree: UseTree) {
|
||||
for tree in trees.iter_mut() {
|
||||
if tree.share_prefix(&use_tree) {
|
||||
tree.merge(use_tree);
|
||||
tree.merge(&use_tree);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -536,7 +536,7 @@ impl UseTree {
|
||||
}
|
||||
}
|
||||
|
||||
fn merge(&mut self, other: UseTree) {
|
||||
fn merge(&mut self, other: &UseTree) {
|
||||
let mut new_path = vec![];
|
||||
for (a, b) in self
|
||||
.path
|
||||
|
@ -475,7 +475,7 @@ where
|
||||
formatted_comment = rewrite_post_comment(&mut item_max_width)?;
|
||||
comment_alignment = post_comment_alignment(item_max_width, inner_item.len());
|
||||
}
|
||||
for _ in 0..(comment_alignment + 1) {
|
||||
for _ in 0..=comment_alignment {
|
||||
result.push(' ');
|
||||
}
|
||||
// An additional space for the missing trailing separator.
|
||||
|
@ -524,12 +524,12 @@ enum MacroArgKind {
|
||||
|
||||
fn delim_token_to_str(
|
||||
context: &RewriteContext,
|
||||
delim_token: &DelimToken,
|
||||
delim_token: DelimToken,
|
||||
shape: Shape,
|
||||
use_multiple_lines: bool,
|
||||
inner_is_empty: bool,
|
||||
) -> (String, String) {
|
||||
let (lhs, rhs) = match *delim_token {
|
||||
let (lhs, rhs) = match delim_token {
|
||||
DelimToken::Paren => ("(", ")"),
|
||||
DelimToken::Bracket => ("[", "]"),
|
||||
DelimToken::Brace => {
|
||||
@ -612,7 +612,7 @@ impl MacroArgKind {
|
||||
MacroArgKind::MetaVariable(ty, ref name) => {
|
||||
Some(format!("${}:{}", name, ty.name.as_str()))
|
||||
}
|
||||
MacroArgKind::Repeat(ref delim_tok, ref args, ref another, ref tok) => {
|
||||
MacroArgKind::Repeat(delim_tok, ref args, ref another, ref tok) => {
|
||||
let (lhs, inner, rhs) = rewrite_delimited_inner(delim_tok, args)?;
|
||||
let another = another
|
||||
.as_ref()
|
||||
@ -622,7 +622,7 @@ impl MacroArgKind {
|
||||
|
||||
Some(format!("${}{}{}{}{}", lhs, inner, rhs, another, repeat_tok))
|
||||
}
|
||||
MacroArgKind::Delimited(ref delim_tok, ref args) => {
|
||||
MacroArgKind::Delimited(delim_tok, ref args) => {
|
||||
rewrite_delimited_inner(delim_tok, args)
|
||||
.map(|(lhs, inner, rhs)| format!("{}{}{}", lhs, inner, rhs))
|
||||
}
|
||||
@ -755,8 +755,8 @@ impl MacroArgParser {
|
||||
let mut hi = span.hi();
|
||||
|
||||
// Parse '*', '+' or '?.
|
||||
for ref tok in iter {
|
||||
self.set_last_tok(tok);
|
||||
for tok in iter {
|
||||
self.set_last_tok(&tok);
|
||||
if first {
|
||||
first = false;
|
||||
lo = tok.span().lo();
|
||||
@ -977,7 +977,7 @@ enum SpaceState {
|
||||
fn force_space_before(tok: &Token) -> bool {
|
||||
debug!("tok: force_space_before {:?}", tok);
|
||||
|
||||
match *tok {
|
||||
match tok {
|
||||
Token::Eq
|
||||
| Token::Lt
|
||||
| Token::Le
|
||||
@ -1002,7 +1002,7 @@ fn force_space_before(tok: &Token) -> bool {
|
||||
}
|
||||
|
||||
fn ident_like(tok: &Token) -> bool {
|
||||
match *tok {
|
||||
match tok {
|
||||
Token::Ident(..) | Token::Literal(..) | Token::Lifetime(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
@ -1011,7 +1011,7 @@ fn ident_like(tok: &Token) -> bool {
|
||||
fn next_space(tok: &Token) -> SpaceState {
|
||||
debug!("next_space: {:?}", tok);
|
||||
|
||||
match *tok {
|
||||
match tok {
|
||||
Token::Not
|
||||
| Token::BinOp(BinOpToken::And)
|
||||
| Token::Tilde
|
||||
|
@ -315,7 +315,7 @@ impl<'a> FmtVisitor<'a> {
|
||||
self.push_str("\n");
|
||||
status.last_wspace = None;
|
||||
} else {
|
||||
self.push_str(&snippet[status.line_start..i + 1]);
|
||||
self.push_str(&snippet[status.line_start..=i]);
|
||||
}
|
||||
|
||||
status.cur_line += 1;
|
||||
|
@ -193,12 +193,12 @@ impl ReorderableItemKind {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_same_item_kind(&self, item: &ast::Item) -> bool {
|
||||
ReorderableItemKind::from(item) == *self
|
||||
fn is_same_item_kind(self, item: &ast::Item) -> bool {
|
||||
ReorderableItemKind::from(item) == self
|
||||
}
|
||||
|
||||
fn is_reorderable(&self, config: &Config) -> bool {
|
||||
match *self {
|
||||
fn is_reorderable(self, config: &Config) -> bool {
|
||||
match self {
|
||||
ReorderableItemKind::ExternCrate => config.reorder_imports(),
|
||||
ReorderableItemKind::Mod => config.reorder_modules(),
|
||||
ReorderableItemKind::Use => config.reorder_imports(),
|
||||
@ -206,8 +206,8 @@ impl ReorderableItemKind {
|
||||
}
|
||||
}
|
||||
|
||||
fn in_group(&self) -> bool {
|
||||
match *self {
|
||||
fn in_group(self) -> bool {
|
||||
match self {
|
||||
ReorderableItemKind::ExternCrate
|
||||
| ReorderableItemKind::Mod
|
||||
| ReorderableItemKind::Use => true,
|
||||
|
@ -91,7 +91,7 @@ impl Indent {
|
||||
};
|
||||
let num_chars = num_tabs + num_spaces;
|
||||
if num_tabs == 0 && num_chars + offset <= INDENT_BUFFER_LEN {
|
||||
Cow::from(&INDENT_BUFFER[offset..num_chars + 1])
|
||||
Cow::from(&INDENT_BUFFER[offset..=num_chars])
|
||||
} else {
|
||||
let mut indent = String::with_capacity(num_chars + if offset == 0 { 1 } else { 0 });
|
||||
if offset == 0 {
|
||||
|
@ -102,7 +102,7 @@ fn verify_config_test_names() {
|
||||
// `print_diff` selects the approach not used.
|
||||
fn write_message(msg: &str) {
|
||||
let mut writer = OutputWriter::new(Color::Auto);
|
||||
writer.writeln(&format!("{}", msg), None);
|
||||
writer.writeln(msg, None);
|
||||
}
|
||||
|
||||
// Integration tests. The files in the tests/source are formatted and compared
|
||||
@ -949,7 +949,7 @@ fn rustfmt() -> PathBuf {
|
||||
me.is_file() || me.with_extension("exe").is_file(),
|
||||
"no rustfmt bin, try running `cargo build` before testing"
|
||||
);
|
||||
return me;
|
||||
me
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -126,7 +126,7 @@ pub fn rewrite_with_alignment<T: AlignedItem>(
|
||||
} else {
|
||||
("", fields.len() - 1)
|
||||
};
|
||||
let init = &fields[0..group_index + 1];
|
||||
let init = &fields[0..=group_index];
|
||||
let rest = &fields[group_index + 1..];
|
||||
let init_last_pos = if rest.is_empty() {
|
||||
span.hi()
|
||||
|
@ -621,24 +621,25 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
|
||||
self.report.append(
|
||||
file_name,
|
||||
vec![FormattingError::from_span(
|
||||
&attr.span,
|
||||
attr.span,
|
||||
&self.source_map,
|
||||
ErrorKind::DeprecatedAttr,
|
||||
)],
|
||||
);
|
||||
} else if attr.path.segments[0].ident.to_string() == "rustfmt"
|
||||
&& (attr.path.segments.len() == 1
|
||||
|| attr.path.segments[1].ident.to_string() != "skip")
|
||||
{
|
||||
let file_name = self.source_map.span_to_filename(attr.span).into();
|
||||
self.report.append(
|
||||
file_name,
|
||||
vec![FormattingError::from_span(
|
||||
&attr.span,
|
||||
&self.source_map,
|
||||
ErrorKind::BadAttr,
|
||||
)],
|
||||
);
|
||||
} else if attr.path.segments[0].ident.to_string() == "rustfmt" {
|
||||
if attr.path.segments.len() == 1
|
||||
|| attr.path.segments[1].ident.to_string() != "skip"
|
||||
{
|
||||
let file_name = self.source_map.span_to_filename(attr.span).into();
|
||||
self.report.append(
|
||||
file_name,
|
||||
vec![FormattingError::from_span(
|
||||
attr.span,
|
||||
&self.source_map,
|
||||
ErrorKind::BadAttr,
|
||||
)],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if contains_skip(attrs) {
|
||||
|
Loading…
Reference in New Issue
Block a user