Merge remote-tracking branch 'upstream/master' into rustup
This commit is contained in:
commit
bbcde66685
323 changed files with 3669 additions and 1716 deletions
|
|
@ -739,7 +739,7 @@ fn path_to_string(path: &QPath<'_>) -> String {
|
|||
*s += ", ";
|
||||
write!(s, "{:?}", segment.ident.as_str()).unwrap();
|
||||
},
|
||||
other => write!(s, "/* unimplemented: {:?}*/", other).unwrap(),
|
||||
other => write!(s, "/* unimplemented: {other:?}*/").unwrap(),
|
||||
},
|
||||
QPath::LangItem(..) => panic!("path_to_string: called for lang item qpath"),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ define_Conf! {
|
|||
///
|
||||
/// Suppress lints whenever the suggested change would cause breakage for other crates.
|
||||
(avoid_breaking_exported_api: bool = true),
|
||||
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED.
|
||||
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS.
|
||||
///
|
||||
/// The minimum rust version that the project supports
|
||||
(msrv: Option<String> = None),
|
||||
|
|
@ -482,16 +482,13 @@ pub fn format_error(error: Box<dyn Error>) -> String {
|
|||
let field = fields.get(index).copied().unwrap_or_default();
|
||||
write!(
|
||||
msg,
|
||||
"{:separator_width$}{:field_width$}",
|
||||
" ",
|
||||
field,
|
||||
separator_width = SEPARATOR_WIDTH,
|
||||
field_width = column_width
|
||||
"{:SEPARATOR_WIDTH$}{field:column_width$}",
|
||||
" "
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
write!(msg, "\n{}", suffix).unwrap();
|
||||
write!(msg, "\n{suffix}").unwrap();
|
||||
msg
|
||||
} else {
|
||||
s
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ use rustc_hir::{
|
|||
BinOpKind, Block, Closure, Expr, ExprKind, HirId, Item, Local, MutTy, Mutability, Node, Path, Stmt, StmtKind, Ty,
|
||||
TyKind, UnOp,
|
||||
};
|
||||
use rustc_hir_analysis::hir_ty_to_ty;
|
||||
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::mir::interpret::ConstValue;
|
||||
|
|
@ -32,7 +33,6 @@ use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
|
|||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::{sym, BytePos, Span};
|
||||
use rustc_hir_analysis::hir_ty_to_ty;
|
||||
|
||||
use std::borrow::{Borrow, Cow};
|
||||
|
||||
|
|
@ -530,7 +530,7 @@ impl<'tcx> LateLintPass<'tcx> for LintWithoutLintPass {
|
|||
cx,
|
||||
LINT_WITHOUT_LINT_PASS,
|
||||
lint_span,
|
||||
&format!("the lint `{}` is not added to any `LintPass`", lint_name),
|
||||
&format!("the lint `{lint_name}` is not added to any `LintPass`"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -666,7 +666,7 @@ impl<'tcx> LateLintPass<'tcx> for CompilerLintFunctions {
|
|||
path.ident.span,
|
||||
"usage of a compiler lint function",
|
||||
None,
|
||||
&format!("please use the Clippy variant of this function: `{}`", sugg),
|
||||
&format!("please use the Clippy variant of this function: `{sugg}`"),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -854,13 +854,8 @@ fn suggest_help(
|
|||
"this call is collapsible",
|
||||
"collapse into",
|
||||
format!(
|
||||
"span_lint_and_help({}, {}, {}, {}, {}, {})",
|
||||
and_then_snippets.cx,
|
||||
and_then_snippets.lint,
|
||||
and_then_snippets.span,
|
||||
and_then_snippets.msg,
|
||||
&option_span,
|
||||
help
|
||||
"span_lint_and_help({}, {}, {}, {}, {}, {help})",
|
||||
and_then_snippets.cx, and_then_snippets.lint, and_then_snippets.span, and_then_snippets.msg, &option_span,
|
||||
),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
|
|
@ -886,13 +881,8 @@ fn suggest_note(
|
|||
"this call is collapsible",
|
||||
"collapse into",
|
||||
format!(
|
||||
"span_lint_and_note({}, {}, {}, {}, {}, {})",
|
||||
and_then_snippets.cx,
|
||||
and_then_snippets.lint,
|
||||
and_then_snippets.span,
|
||||
and_then_snippets.msg,
|
||||
note_span,
|
||||
note
|
||||
"span_lint_and_note({}, {}, {}, {}, {note_span}, {note})",
|
||||
and_then_snippets.cx, and_then_snippets.lint, and_then_snippets.span, and_then_snippets.msg,
|
||||
),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
|
|
@ -927,7 +917,7 @@ impl<'tcx> LateLintPass<'tcx> for MatchTypeOnDiagItem {
|
|||
expr.span,
|
||||
"usage of `clippy_utils::ty::match_type()` on a type diagnostic item",
|
||||
"try",
|
||||
format!("clippy_utils::ty::is_type_diagnostic_item({}, {}, sym::{})", cx_snippet, ty_snippet, item_name),
|
||||
format!("clippy_utils::ty::is_type_diagnostic_item({cx_snippet}, {ty_snippet}, sym::{item_name})"),
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,46 +64,6 @@ const DEFAULT_LINT_LEVELS: &[(&str, &str)] = &[
|
|||
/// This prefix is in front of the lint groups in the lint store. The prefix will be trimmed
|
||||
/// to only keep the actual lint group in the output.
|
||||
const CLIPPY_LINT_GROUP_PREFIX: &str = "clippy::";
|
||||
|
||||
/// This template will be used to format the configuration section in the lint documentation.
|
||||
/// The `configurations` parameter will be replaced with one or multiple formatted
|
||||
/// `ClippyConfiguration` instances. See `CONFIGURATION_VALUE_TEMPLATE` for further customizations
|
||||
macro_rules! CONFIGURATION_SECTION_TEMPLATE {
|
||||
() => {
|
||||
r#"
|
||||
### Configuration
|
||||
This lint has the following configuration variables:
|
||||
|
||||
{configurations}
|
||||
"#
|
||||
};
|
||||
}
|
||||
/// This template will be used to format an individual `ClippyConfiguration` instance in the
|
||||
/// lint documentation.
|
||||
///
|
||||
/// The format function will provide strings for the following parameters: `name`, `ty`, `doc` and
|
||||
/// `default`
|
||||
macro_rules! CONFIGURATION_VALUE_TEMPLATE {
|
||||
() => {
|
||||
"* `{name}`: `{ty}`: {doc} (defaults to `{default}`)\n"
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! RENAMES_SECTION_TEMPLATE {
|
||||
() => {
|
||||
r#"
|
||||
### Past names
|
||||
|
||||
{names}
|
||||
"#
|
||||
};
|
||||
}
|
||||
macro_rules! RENAME_VALUE_TEMPLATE {
|
||||
() => {
|
||||
"* `{name}`\n"
|
||||
};
|
||||
}
|
||||
|
||||
const LINT_EMISSION_FUNCTIONS: [&[&str]; 7] = [
|
||||
&["clippy_utils", "diagnostics", "span_lint"],
|
||||
&["clippy_utils", "diagnostics", "span_lint_and_help"],
|
||||
|
|
@ -205,7 +165,16 @@ impl MetadataCollector {
|
|||
.filter(|config| config.lints.iter().any(|lint| lint == lint_name))
|
||||
.map(ToString::to_string)
|
||||
.reduce(|acc, x| acc + &x)
|
||||
.map(|configurations| format!(CONFIGURATION_SECTION_TEMPLATE!(), configurations = configurations))
|
||||
.map(|configurations| {
|
||||
format!(
|
||||
r#"
|
||||
### Configuration
|
||||
This lint has the following configuration variables:
|
||||
|
||||
{configurations}
|
||||
"#
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -291,16 +260,13 @@ fn replace_produces(lint_name: &str, docs: &mut String, clippy_project_root: &Pa
|
|||
continue;
|
||||
}
|
||||
|
||||
panic!("lint `{}` has an unterminated code block", lint_name)
|
||||
panic!("lint `{lint_name}` has an unterminated code block")
|
||||
}
|
||||
|
||||
break;
|
||||
},
|
||||
Some(line) if line.trim_start() == "{{produces}}" => {
|
||||
panic!(
|
||||
"lint `{}` has marker {{{{produces}}}} with an ignored or missing code block",
|
||||
lint_name
|
||||
)
|
||||
panic!("lint `{lint_name}` has marker {{{{produces}}}} with an ignored or missing code block")
|
||||
},
|
||||
Some(line) => {
|
||||
let line = line.trim();
|
||||
|
|
@ -319,7 +285,7 @@ fn replace_produces(lint_name: &str, docs: &mut String, clippy_project_root: &Pa
|
|||
match lines.next() {
|
||||
Some(line) if line.trim_start() == "```" => break,
|
||||
Some(line) => example.push(line),
|
||||
None => panic!("lint `{}` has an unterminated code block", lint_name),
|
||||
None => panic!("lint `{lint_name}` has an unterminated code block"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -336,10 +302,9 @@ fn replace_produces(lint_name: &str, docs: &mut String, clippy_project_root: &Pa
|
|||
<summary>Produces</summary>\n\
|
||||
\n\
|
||||
```text\n\
|
||||
{}\n\
|
||||
{output}\n\
|
||||
```\n\
|
||||
</details>",
|
||||
output
|
||||
</details>"
|
||||
),
|
||||
);
|
||||
|
||||
|
|
@ -394,7 +359,7 @@ fn get_lint_output(lint_name: &str, example: &[&mut String], clippy_project_root
|
|||
panic!("failed to write to `{}`: {e}", file.as_path().to_string_lossy());
|
||||
}
|
||||
|
||||
let prefixed_name = format!("{}{lint_name}", CLIPPY_LINT_GROUP_PREFIX);
|
||||
let prefixed_name = format!("{CLIPPY_LINT_GROUP_PREFIX}{lint_name}");
|
||||
|
||||
let mut cmd = Command::new("cargo");
|
||||
|
||||
|
|
@ -417,7 +382,7 @@ fn get_lint_output(lint_name: &str, example: &[&mut String], clippy_project_root
|
|||
let output = cmd
|
||||
.arg(file.as_path())
|
||||
.output()
|
||||
.unwrap_or_else(|e| panic!("failed to run `{:?}`: {e}", cmd));
|
||||
.unwrap_or_else(|e| panic!("failed to run `{cmd:?}`: {e}"));
|
||||
|
||||
let tmp_file_path = file.to_string_lossy();
|
||||
let stderr = std::str::from_utf8(&output.stderr).unwrap();
|
||||
|
|
@ -441,8 +406,7 @@ fn get_lint_output(lint_name: &str, example: &[&mut String], clippy_project_root
|
|||
let rendered: Vec<&str> = msgs.iter().filter_map(|msg| msg["rendered"].as_str()).collect();
|
||||
let non_json: Vec<&str> = stderr.lines().filter(|line| !line.starts_with('{')).collect();
|
||||
panic!(
|
||||
"did not find lint `{}` in output of example, got:\n{}\n{}",
|
||||
lint_name,
|
||||
"did not find lint `{lint_name}` in output of example, got:\n{}\n{}",
|
||||
non_json.join("\n"),
|
||||
rendered.join("\n")
|
||||
);
|
||||
|
|
@ -588,13 +552,10 @@ fn to_kebab(config_name: &str) -> String {
|
|||
|
||||
impl fmt::Display for ClippyConfiguration {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
writeln!(
|
||||
f,
|
||||
CONFIGURATION_VALUE_TEMPLATE!(),
|
||||
name = self.name,
|
||||
ty = self.config_type,
|
||||
doc = self.doc,
|
||||
default = self.default
|
||||
"* `{}`: `{}`: {} (defaults to `{}`)",
|
||||
self.name, self.config_type, self.doc, self.default
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -811,7 +772,7 @@ fn get_lint_group_and_level_or_lint(
|
|||
lint_collection_error_item(
|
||||
cx,
|
||||
item,
|
||||
&format!("Unable to determine lint level for found group `{}`", group),
|
||||
&format!("Unable to determine lint level for found group `{group}`"),
|
||||
);
|
||||
None
|
||||
}
|
||||
|
|
@ -869,7 +830,7 @@ fn collect_renames(lints: &mut Vec<LintMetadata>) {
|
|||
if name == lint_name;
|
||||
if let Some(past_name) = k.strip_prefix(CLIPPY_LINT_GROUP_PREFIX);
|
||||
then {
|
||||
write!(collected, RENAME_VALUE_TEMPLATE!(), name = past_name).unwrap();
|
||||
writeln!(collected, "* `{past_name}`").unwrap();
|
||||
names.push(past_name.to_string());
|
||||
}
|
||||
}
|
||||
|
|
@ -882,7 +843,15 @@ fn collect_renames(lints: &mut Vec<LintMetadata>) {
|
|||
}
|
||||
|
||||
if !collected.is_empty() {
|
||||
write!(&mut lint.docs, RENAMES_SECTION_TEMPLATE!(), names = collected).unwrap();
|
||||
write!(
|
||||
&mut lint.docs,
|
||||
r#"
|
||||
### Past names
|
||||
|
||||
{collected}
|
||||
"#
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -895,7 +864,7 @@ fn lint_collection_error_item(cx: &LateContext<'_>, item: &Item<'_>, message: &s
|
|||
cx,
|
||||
INTERNAL_METADATA_COLLECTOR,
|
||||
item.ident.span,
|
||||
&format!("metadata collection error for `{}`: {}", item.ident.name, message),
|
||||
&format!("metadata collection error for `{}`: {message}", item.ident.name),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue