Merge remote-tracking branch 'upstream/master' into rustup
This commit is contained in:
commit
ab7e525929
377 changed files with 6426 additions and 3724 deletions
|
|
@ -107,48 +107,48 @@ impl<'tcx> LateLintPass<'tcx> for InterningDefinedSymbol {
|
|||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
if let ExprKind::Binary(op, left, right) = expr.kind {
|
||||
if matches!(op.node, BinOpKind::Eq | BinOpKind::Ne) {
|
||||
let data = [
|
||||
(left, self.symbol_str_expr(left, cx)),
|
||||
(right, self.symbol_str_expr(right, cx)),
|
||||
];
|
||||
match data {
|
||||
// both operands are a symbol string
|
||||
[(_, Some(left)), (_, Some(right))] => {
|
||||
if let ExprKind::Binary(op, left, right) = expr.kind
|
||||
&& matches!(op.node, BinOpKind::Eq | BinOpKind::Ne)
|
||||
{
|
||||
let data = [
|
||||
(left, self.symbol_str_expr(left, cx)),
|
||||
(right, self.symbol_str_expr(right, cx)),
|
||||
];
|
||||
match data {
|
||||
// both operands are a symbol string
|
||||
[(_, Some(left)), (_, Some(right))] => {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
UNNECESSARY_SYMBOL_STR,
|
||||
expr.span,
|
||||
"unnecessary `Symbol` to string conversion",
|
||||
"try",
|
||||
format!(
|
||||
"{} {} {}",
|
||||
left.as_symbol_snippet(cx),
|
||||
op.node.as_str(),
|
||||
right.as_symbol_snippet(cx),
|
||||
),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
},
|
||||
// one of the operands is a symbol string
|
||||
[(expr, Some(symbol)), _] | [_, (expr, Some(symbol))] => {
|
||||
// creating an owned string for comparison
|
||||
if matches!(symbol, SymbolStrExpr::Expr { is_to_owned: true, .. }) {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
UNNECESSARY_SYMBOL_STR,
|
||||
expr.span,
|
||||
"unnecessary `Symbol` to string conversion",
|
||||
"unnecessary string allocation",
|
||||
"try",
|
||||
format!(
|
||||
"{} {} {}",
|
||||
left.as_symbol_snippet(cx),
|
||||
op.node.as_str(),
|
||||
right.as_symbol_snippet(cx),
|
||||
),
|
||||
format!("{}.as_str()", symbol.as_symbol_snippet(cx)),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
},
|
||||
// one of the operands is a symbol string
|
||||
[(expr, Some(symbol)), _] | [_, (expr, Some(symbol))] => {
|
||||
// creating an owned string for comparison
|
||||
if matches!(symbol, SymbolStrExpr::Expr { is_to_owned: true, .. }) {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
UNNECESSARY_SYMBOL_STR,
|
||||
expr.span,
|
||||
"unnecessary string allocation",
|
||||
"try",
|
||||
format!("{}.as_str()", symbol.as_symbol_snippet(cx)),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
},
|
||||
// nothing found
|
||||
[(_, None), (_, None)] => {},
|
||||
}
|
||||
}
|
||||
},
|
||||
// nothing found
|
||||
[(_, None), (_, None)] => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -80,22 +80,22 @@ pub fn check_path(cx: &LateContext<'_>, path: &[&str]) -> bool {
|
|||
.copied();
|
||||
for item_def_id in lang_items.iter().map(|(_, def_id)| def_id).chain(incoherent_impls) {
|
||||
let lang_item_path = cx.get_def_path(item_def_id);
|
||||
if path_syms.starts_with(&lang_item_path) {
|
||||
if let [item] = &path_syms[lang_item_path.len()..] {
|
||||
if matches!(
|
||||
cx.tcx.def_kind(item_def_id),
|
||||
DefKind::Mod | DefKind::Enum | DefKind::Trait
|
||||
) {
|
||||
for child in cx.tcx.module_children(item_def_id) {
|
||||
if child.ident.name == *item {
|
||||
return true;
|
||||
}
|
||||
if path_syms.starts_with(&lang_item_path)
|
||||
&& let [item] = &path_syms[lang_item_path.len()..]
|
||||
{
|
||||
if matches!(
|
||||
cx.tcx.def_kind(item_def_id),
|
||||
DefKind::Mod | DefKind::Enum | DefKind::Trait
|
||||
) {
|
||||
for child in cx.tcx.module_children(item_def_id) {
|
||||
if child.ident.name == *item {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
for child in cx.tcx.associated_item_def_ids(item_def_id) {
|
||||
if cx.tcx.item_name(*child) == *item {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for child in cx.tcx.associated_item_def_ids(item_def_id) {
|
||||
if cx.tcx.item_name(*child) == *item {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -205,12 +205,10 @@ pub(super) fn is_lint_ref_type(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
|
|||
mutbl: Mutability::Not,
|
||||
},
|
||||
) = ty.kind
|
||||
&& let TyKind::Path(ref path) = inner.kind
|
||||
&& let Res::Def(DefKind::Struct, def_id) = cx.qpath_res(path, inner.hir_id)
|
||||
{
|
||||
if let TyKind::Path(ref path) = inner.kind {
|
||||
if let Res::Def(DefKind::Struct, def_id) = cx.qpath_res(path, inner.hir_id) {
|
||||
return match_def_path(cx, def_id, &paths::LINT);
|
||||
}
|
||||
}
|
||||
return match_def_path(cx, def_id, &paths::LINT);
|
||||
}
|
||||
|
||||
false
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ impl EarlyLintPass for ProduceIce {
|
|||
|
||||
fn is_trigger_fn(fn_kind: FnKind<'_>) -> bool {
|
||||
match fn_kind {
|
||||
FnKind::Fn(_, ident, ..) => ident.name.as_str() == "it_looks_like_you_are_trying_to_kill_clippy",
|
||||
FnKind::Fn(_, _, func) => func.ident.name.as_str() == "it_looks_like_you_are_trying_to_kill_clippy",
|
||||
FnKind::Closure(..) => false,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -281,10 +281,10 @@ fn path_from_array(exprs: &[Expr<'_>]) -> Option<Vec<String>> {
|
|||
exprs
|
||||
.iter()
|
||||
.map(|expr| {
|
||||
if let ExprKind::Lit(lit) = &expr.kind {
|
||||
if let LitKind::Str(sym, _) = lit.node {
|
||||
return Some((*sym.as_str()).to_owned());
|
||||
}
|
||||
if let ExprKind::Lit(lit) = &expr.kind
|
||||
&& let LitKind::Str(sym, _) = lit.node
|
||||
{
|
||||
return Some((*sym.as_str()).to_owned());
|
||||
}
|
||||
|
||||
None
|
||||
|
|
|
|||
|
|
@ -21,28 +21,31 @@ declare_lint_pass!(UnsortedClippyUtilsPaths => [UNSORTED_CLIPPY_UTILS_PATHS]);
|
|||
|
||||
impl EarlyLintPass for UnsortedClippyUtilsPaths {
|
||||
fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &Crate) {
|
||||
if let Some(utils) = krate.items.iter().find(|item| item.ident.name.as_str() == "utils") {
|
||||
if let ItemKind::Mod(_, ModKind::Loaded(ref items, ..)) = utils.kind {
|
||||
if let Some(paths) = items.iter().find(|item| item.ident.name.as_str() == "paths") {
|
||||
if let ItemKind::Mod(_, ModKind::Loaded(ref items, ..)) = paths.kind {
|
||||
let mut last_name: Option<&str> = None;
|
||||
for item in items {
|
||||
let name = item.ident.as_str();
|
||||
if let Some(last_name) = last_name {
|
||||
if *last_name > *name {
|
||||
span_lint(
|
||||
cx,
|
||||
UNSORTED_CLIPPY_UTILS_PATHS,
|
||||
item.span,
|
||||
"this constant should be before the previous constant due to lexical \
|
||||
if let Some(utils) = krate
|
||||
.items
|
||||
.iter()
|
||||
.find(|item| item.kind.ident().is_some_and(|i| i.name.as_str() == "utils"))
|
||||
&& let ItemKind::Mod(_, _, ModKind::Loaded(ref items, ..)) = utils.kind
|
||||
&& let Some(paths) = items
|
||||
.iter()
|
||||
.find(|item| item.kind.ident().is_some_and(|i| i.name.as_str() == "paths"))
|
||||
&& let ItemKind::Mod(_, _, ModKind::Loaded(ref items, ..)) = paths.kind
|
||||
{
|
||||
let mut last_name: Option<String> = None;
|
||||
for item in items {
|
||||
let name = item.kind.ident().expect("const items have idents").to_string();
|
||||
if let Some(last_name) = last_name
|
||||
&& *last_name > *name
|
||||
{
|
||||
span_lint(
|
||||
cx,
|
||||
UNSORTED_CLIPPY_UTILS_PATHS,
|
||||
item.span,
|
||||
"this constant should be before the previous constant due to lexical \
|
||||
ordering",
|
||||
);
|
||||
}
|
||||
}
|
||||
last_name = Some(name);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
last_name = Some(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue