Fix clippy::needless_borrow
in the compiler
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
This commit is contained in:
parent
0ff8610964
commit
21a870515b
304 changed files with 1101 additions and 1174 deletions
|
@ -263,7 +263,7 @@ impl<'tcx> LateLintPass<'tcx> for NonShorthandFieldPatterns {
|
|||
continue;
|
||||
}
|
||||
if let PatKind::Binding(binding_annot, _, ident, None) = fieldpat.pat.kind {
|
||||
if cx.tcx.find_field_index(ident, &variant)
|
||||
if cx.tcx.find_field_index(ident, variant)
|
||||
== Some(cx.typeck_results().field_index(fieldpat.hir_id))
|
||||
{
|
||||
cx.emit_spanned_lint(
|
||||
|
@ -633,21 +633,21 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
|
|||
return;
|
||||
}
|
||||
let (def, ty) = match item.kind {
|
||||
hir::ItemKind::Struct(_, ref ast_generics) => {
|
||||
hir::ItemKind::Struct(_, ast_generics) => {
|
||||
if !ast_generics.params.is_empty() {
|
||||
return;
|
||||
}
|
||||
let def = cx.tcx.adt_def(item.owner_id);
|
||||
(def, Ty::new_adt(cx.tcx, def, ty::List::empty()))
|
||||
}
|
||||
hir::ItemKind::Union(_, ref ast_generics) => {
|
||||
hir::ItemKind::Union(_, ast_generics) => {
|
||||
if !ast_generics.params.is_empty() {
|
||||
return;
|
||||
}
|
||||
let def = cx.tcx.adt_def(item.owner_id);
|
||||
(def, Ty::new_adt(cx.tcx, def, ty::List::empty()))
|
||||
}
|
||||
hir::ItemKind::Enum(_, ref ast_generics) => {
|
||||
hir::ItemKind::Enum(_, ast_generics) => {
|
||||
if !ast_generics.params.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
@ -1027,7 +1027,7 @@ impl EarlyLintPass for UnusedDocComment {
|
|||
}
|
||||
|
||||
fn check_block(&mut self, cx: &EarlyContext<'_>, block: &ast::Block) {
|
||||
warn_if_doc(cx, block.span, "blocks", &block.attrs());
|
||||
warn_if_doc(cx, block.span, "blocks", block.attrs());
|
||||
}
|
||||
|
||||
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
|
||||
|
@ -1117,7 +1117,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
|
|||
}
|
||||
};
|
||||
match it.kind {
|
||||
hir::ItemKind::Fn(.., ref generics, _) => {
|
||||
hir::ItemKind::Fn(.., generics, _) => {
|
||||
if let Some(no_mangle_attr) = attr::find_by_name(attrs, sym::no_mangle) {
|
||||
check_no_mangle_on_generic_fn(no_mangle_attr, None, generics, it.span);
|
||||
}
|
||||
|
@ -1444,10 +1444,10 @@ declare_lint_pass!(
|
|||
impl TypeAliasBounds {
|
||||
pub(crate) fn is_type_variable_assoc(qpath: &hir::QPath<'_>) -> bool {
|
||||
match *qpath {
|
||||
hir::QPath::TypeRelative(ref ty, _) => {
|
||||
hir::QPath::TypeRelative(ty, _) => {
|
||||
// If this is a type variable, we found a `T::Assoc`.
|
||||
match ty.kind {
|
||||
hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) => {
|
||||
hir::TyKind::Path(hir::QPath::Resolved(None, path)) => {
|
||||
matches!(path.res, Res::Def(DefKind::TyParam, _))
|
||||
}
|
||||
_ => false,
|
||||
|
@ -1714,16 +1714,16 @@ impl EarlyLintPass for EllipsisInclusiveRangePatterns {
|
|||
}
|
||||
|
||||
let (parentheses, endpoints) = match &pat.kind {
|
||||
PatKind::Ref(subpat, _) => (true, matches_ellipsis_pat(&subpat)),
|
||||
PatKind::Ref(subpat, _) => (true, matches_ellipsis_pat(subpat)),
|
||||
_ => (false, matches_ellipsis_pat(pat)),
|
||||
};
|
||||
|
||||
if let Some((start, end, join)) = endpoints {
|
||||
if parentheses {
|
||||
self.node_id = Some(pat.id);
|
||||
let end = expr_to_string(&end);
|
||||
let end = expr_to_string(end);
|
||||
let replace = match start {
|
||||
Some(start) => format!("&({}..={})", expr_to_string(&start), end),
|
||||
Some(start) => format!("&({}..={})", expr_to_string(start), end),
|
||||
None => format!("&(..={end})"),
|
||||
};
|
||||
if join.edition() >= Edition::Edition2021 {
|
||||
|
@ -2381,7 +2381,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
|
|||
|
||||
/// Determine if this expression is a "dangerous initialization".
|
||||
fn is_dangerous_init(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<InitKind> {
|
||||
if let hir::ExprKind::Call(ref path_expr, ref args) = expr.kind {
|
||||
if let hir::ExprKind::Call(path_expr, args) = expr.kind {
|
||||
// Find calls to `mem::{uninitialized,zeroed}` methods.
|
||||
if let hir::ExprKind::Path(ref qpath) = path_expr.kind {
|
||||
let def_id = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id()?;
|
||||
|
@ -2398,7 +2398,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
|
|||
if cx.tcx.is_diagnostic_item(sym::assume_init, def_id) {
|
||||
// This is a call to *some* method named `assume_init`.
|
||||
// See if the `self` parameter is one of the dangerous constructors.
|
||||
if let hir::ExprKind::Call(ref path_expr, _) = receiver.kind {
|
||||
if let hir::ExprKind::Call(path_expr, _) = receiver.kind {
|
||||
if let hir::ExprKind::Path(ref qpath) = path_expr.kind {
|
||||
let def_id = cx.qpath_res(qpath, path_expr.hir_id).opt_def_id()?;
|
||||
match cx.tcx.get_diagnostic_name(def_id) {
|
||||
|
@ -2540,7 +2540,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
|
|||
return variant_find_init_error(
|
||||
cx,
|
||||
ty,
|
||||
&first_variant.0,
|
||||
first_variant.0,
|
||||
args,
|
||||
"field of the only potentially inhabited enum variant",
|
||||
init,
|
||||
|
@ -2646,13 +2646,13 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr {
|
|||
/// test if expression is a null ptr
|
||||
fn is_null_ptr(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
|
||||
match &expr.kind {
|
||||
rustc_hir::ExprKind::Cast(ref expr, ref ty) => {
|
||||
rustc_hir::ExprKind::Cast(expr, ty) => {
|
||||
if let rustc_hir::TyKind::Ptr(_) = ty.kind {
|
||||
return is_zero(expr) || is_null_ptr(cx, expr);
|
||||
}
|
||||
}
|
||||
// check for call to `core::ptr::null` or `core::ptr::null_mut`
|
||||
rustc_hir::ExprKind::Call(ref path, _) => {
|
||||
rustc_hir::ExprKind::Call(path, _) => {
|
||||
if let rustc_hir::ExprKind::Path(ref qpath) = path.kind {
|
||||
if let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id() {
|
||||
return matches!(
|
||||
|
@ -2670,7 +2670,7 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr {
|
|||
/// test if expression is the literal `0`
|
||||
fn is_zero(expr: &hir::Expr<'_>) -> bool {
|
||||
match &expr.kind {
|
||||
rustc_hir::ExprKind::Lit(ref lit) => {
|
||||
rustc_hir::ExprKind::Lit(lit) => {
|
||||
if let LitKind::Int(a, _) = lit.node {
|
||||
return a == 0;
|
||||
}
|
||||
|
|
|
@ -385,7 +385,7 @@ impl LintStore {
|
|||
};
|
||||
}
|
||||
Some(LintGroup { lint_ids, .. }) => {
|
||||
return CheckLintNameResult::Tool(Ok(&lint_ids));
|
||||
return CheckLintNameResult::Tool(Ok(lint_ids));
|
||||
}
|
||||
},
|
||||
Some(Id(id)) => return CheckLintNameResult::Tool(Ok(slice::from_ref(id))),
|
||||
|
@ -406,12 +406,12 @@ impl LintStore {
|
|||
if let Some(LintAlias { name, silent }) = depr {
|
||||
let LintGroup { lint_ids, .. } = self.lint_groups.get(name).unwrap();
|
||||
return if *silent {
|
||||
CheckLintNameResult::Ok(&lint_ids)
|
||||
CheckLintNameResult::Ok(lint_ids)
|
||||
} else {
|
||||
CheckLintNameResult::Tool(Err((Some(&lint_ids), (*name).to_string())))
|
||||
CheckLintNameResult::Tool(Err((Some(lint_ids), (*name).to_string())))
|
||||
};
|
||||
}
|
||||
CheckLintNameResult::Ok(&lint_ids)
|
||||
CheckLintNameResult::Ok(lint_ids)
|
||||
}
|
||||
},
|
||||
Some(Id(id)) => CheckLintNameResult::Ok(slice::from_ref(id)),
|
||||
|
@ -458,12 +458,12 @@ impl LintStore {
|
|||
if let Some(LintAlias { name, silent }) = depr {
|
||||
let LintGroup { lint_ids, .. } = self.lint_groups.get(name).unwrap();
|
||||
return if *silent {
|
||||
CheckLintNameResult::Tool(Err((Some(&lint_ids), complete_name)))
|
||||
CheckLintNameResult::Tool(Err((Some(lint_ids), complete_name)))
|
||||
} else {
|
||||
CheckLintNameResult::Tool(Err((Some(&lint_ids), (*name).to_string())))
|
||||
CheckLintNameResult::Tool(Err((Some(lint_ids), (*name).to_string())))
|
||||
};
|
||||
}
|
||||
CheckLintNameResult::Tool(Err((Some(&lint_ids), complete_name)))
|
||||
CheckLintNameResult::Tool(Err((Some(lint_ids), complete_name)))
|
||||
}
|
||||
},
|
||||
Some(Id(id)) => {
|
||||
|
@ -1051,7 +1051,7 @@ impl<'a> EarlyContext<'a> {
|
|||
impl<'tcx> LintContext for LateContext<'tcx> {
|
||||
/// Gets the overall compiler `Session` object.
|
||||
fn sess(&self) -> &Session {
|
||||
&self.tcx.sess
|
||||
self.tcx.sess
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
|
@ -1080,7 +1080,7 @@ impl<'tcx> LintContext for LateContext<'tcx> {
|
|||
impl LintContext for EarlyContext<'_> {
|
||||
/// Gets the overall compiler `Session` object.
|
||||
fn sess(&self) -> &Session {
|
||||
&self.builder.sess()
|
||||
self.builder.sess()
|
||||
}
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
|
@ -1127,7 +1127,7 @@ impl<'tcx> LateContext<'tcx> {
|
|||
/// bodies (e.g. for paths in `hir::Ty`), without any risk of ICE-ing.
|
||||
pub fn qpath_res(&self, qpath: &hir::QPath<'_>, id: hir::HirId) -> Res {
|
||||
match *qpath {
|
||||
hir::QPath::Resolved(_, ref path) => path.res,
|
||||
hir::QPath::Resolved(_, path) => path.res,
|
||||
hir::QPath::TypeRelative(..) | hir::QPath::LangItem(..) => self
|
||||
.maybe_typeck_results()
|
||||
.filter(|typeck_results| typeck_results.hir_owner == id.owner)
|
||||
|
|
|
@ -350,7 +350,7 @@ impl<'a> EarlyCheckNode<'a> for (&'a ast::Crate, &'a [ast::Attribute]) {
|
|||
where
|
||||
'a: 'b,
|
||||
{
|
||||
&self.1
|
||||
self.1
|
||||
}
|
||||
fn check<'b, T: EarlyLintPass>(self, cx: &mut EarlyContextAndPass<'b, T>)
|
||||
where
|
||||
|
|
|
@ -24,7 +24,7 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
|
|||
// This check will always be true, since `lint_expectations` only
|
||||
// holds stable ids
|
||||
if let LintExpectationId::Stable { hir_id, .. } = id {
|
||||
if !fulfilled_expectations.contains(&id)
|
||||
if !fulfilled_expectations.contains(id)
|
||||
&& tool_filter.map_or(true, |filter| expectation.lint_tool == Some(filter))
|
||||
{
|
||||
let rationale = expectation.reason.map(|rationale| ExpectationNote { rationale });
|
||||
|
|
|
@ -137,7 +137,7 @@ fn suggest_question_mark<'tcx>(
|
|||
// Check that the function/closure/constant we are in has a `Result` type.
|
||||
// Otherwise suggesting using `?` may not be a good idea.
|
||||
{
|
||||
let ty = cx.typeck_results().expr_ty(&cx.tcx.hir().body(body_id).value);
|
||||
let ty = cx.typeck_results().expr_ty(cx.tcx.hir().body(body_id).value);
|
||||
let ty::Adt(ret_adt, ..) = ty.kind() else { return false };
|
||||
if !cx.tcx.is_diagnostic_item(sym::Result, ret_adt.did()) {
|
||||
return false;
|
||||
|
|
|
@ -196,7 +196,7 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
|
|||
}
|
||||
} else if !ty.span.from_expansion()
|
||||
&& path.segments.len() > 1
|
||||
&& let Some(ty) = is_ty_or_ty_ctxt(cx, &path)
|
||||
&& let Some(ty) = is_ty_or_ty_ctxt(cx, path)
|
||||
{
|
||||
cx.emit_spanned_lint(
|
||||
USAGE_OF_QUALIFIED_TY,
|
||||
|
|
|
@ -279,7 +279,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
|
||||
fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem<'tcx>) {
|
||||
let generics = self.context.generics.take();
|
||||
self.context.generics = Some(&trait_item.generics);
|
||||
self.context.generics = Some(trait_item.generics);
|
||||
self.with_lint_attrs(trait_item.hir_id(), |cx| {
|
||||
cx.with_param_env(trait_item.owner_id, |cx| {
|
||||
lint_callback!(cx, check_trait_item, trait_item);
|
||||
|
@ -291,7 +291,7 @@ impl<'tcx, T: LateLintPass<'tcx>> hir_visit::Visitor<'tcx> for LateContextAndPas
|
|||
|
||||
fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem<'tcx>) {
|
||||
let generics = self.context.generics.take();
|
||||
self.context.generics = Some(&impl_item.generics);
|
||||
self.context.generics = Some(impl_item.generics);
|
||||
self.with_lint_attrs(impl_item.hir_id(), |cx| {
|
||||
cx.with_param_env(impl_item.owner_id, |cx| {
|
||||
lint_callback!(cx, check_impl_item, impl_item);
|
||||
|
@ -355,7 +355,7 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
|
|||
enclosing_body: None,
|
||||
cached_typeck_results: Cell::new(None),
|
||||
param_env: ty::ParamEnv::empty(),
|
||||
effective_visibilities: &tcx.effective_visibilities(()),
|
||||
effective_visibilities: tcx.effective_visibilities(()),
|
||||
last_node_with_lint_attrs: tcx.hir().local_def_id_to_hir_id(module_def_id),
|
||||
generics: None,
|
||||
only_module: true,
|
||||
|
@ -364,7 +364,7 @@ pub fn late_lint_mod<'tcx, T: LateLintPass<'tcx> + 'tcx>(
|
|||
// Note: `passes` is often empty. In that case, it's faster to run
|
||||
// `builtin_lints` directly rather than bundling it up into the
|
||||
// `RuntimeCombinedLateLintPass`.
|
||||
let mut passes: Vec<_> = unerased_lint_store(&tcx.sess)
|
||||
let mut passes: Vec<_> = unerased_lint_store(tcx.sess)
|
||||
.late_module_passes
|
||||
.iter()
|
||||
.map(|mk_pass| (mk_pass)(tcx))
|
||||
|
@ -405,7 +405,7 @@ fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>(
|
|||
fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
|
||||
// Note: `passes` is often empty.
|
||||
let mut passes: Vec<_> =
|
||||
unerased_lint_store(&tcx.sess).late_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
|
||||
unerased_lint_store(tcx.sess).late_passes.iter().map(|mk_pass| (mk_pass)(tcx)).collect();
|
||||
|
||||
if passes.is_empty() {
|
||||
return;
|
||||
|
@ -416,7 +416,7 @@ fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) {
|
|||
enclosing_body: None,
|
||||
cached_typeck_results: Cell::new(None),
|
||||
param_env: ty::ParamEnv::empty(),
|
||||
effective_visibilities: &tcx.effective_visibilities(()),
|
||||
effective_visibilities: tcx.effective_visibilities(()),
|
||||
last_node_with_lint_attrs: hir::CRATE_HIR_ID,
|
||||
generics: None,
|
||||
only_module: false,
|
||||
|
|
|
@ -123,7 +123,7 @@ impl LintLevelSets {
|
|||
}
|
||||
|
||||
fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExpectation)> {
|
||||
let store = unerased_lint_store(&tcx.sess);
|
||||
let store = unerased_lint_store(tcx.sess);
|
||||
|
||||
let mut builder = LintLevelsBuilder {
|
||||
sess: tcx.sess,
|
||||
|
@ -138,7 +138,7 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
|
|||
},
|
||||
warn_about_weird_lints: false,
|
||||
store,
|
||||
registered_tools: &tcx.registered_tools(()),
|
||||
registered_tools: tcx.registered_tools(()),
|
||||
};
|
||||
|
||||
builder.add_command_line();
|
||||
|
@ -152,7 +152,7 @@ fn lint_expectations(tcx: TyCtxt<'_>, (): ()) -> Vec<(LintExpectationId, LintExp
|
|||
|
||||
#[instrument(level = "trace", skip(tcx), ret)]
|
||||
fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLevelMap {
|
||||
let store = unerased_lint_store(&tcx.sess);
|
||||
let store = unerased_lint_store(tcx.sess);
|
||||
let attrs = tcx.hir_attrs(owner);
|
||||
|
||||
let mut levels = LintLevelsBuilder {
|
||||
|
@ -167,7 +167,7 @@ fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLe
|
|||
},
|
||||
warn_about_weird_lints: false,
|
||||
store,
|
||||
registered_tools: &tcx.registered_tools(()),
|
||||
registered_tools: tcx.registered_tools(()),
|
||||
};
|
||||
|
||||
if owner == hir::CRATE_OWNER_ID {
|
||||
|
@ -605,7 +605,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
|||
let orig_level = level;
|
||||
let lint_flag_val = Symbol::intern(lint_name);
|
||||
|
||||
let Ok(ids) = self.store.find_lints(&lint_name) else {
|
||||
let Ok(ids) = self.store.find_lints(lint_name) else {
|
||||
// errors already handled above
|
||||
continue;
|
||||
};
|
||||
|
@ -629,7 +629,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
|||
/// (e.g. if a forbid was already inserted on the same scope), then emits a
|
||||
/// diagnostic with no change to `specs`.
|
||||
fn insert_spec(&mut self, id: LintId, (mut level, src): LevelAndSource) {
|
||||
let (old_level, old_src) = self.provider.get_lint_level(id.lint, &self.sess);
|
||||
let (old_level, old_src) = self.provider.get_lint_level(id.lint, self.sess);
|
||||
if let Level::Expect(id) = &mut level
|
||||
&& let LintExpectationId::Stable { .. } = id
|
||||
{
|
||||
|
@ -929,12 +929,12 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
|||
DeprecatedLintName {
|
||||
name,
|
||||
suggestion: sp,
|
||||
replace: &new_lint_name,
|
||||
replace: new_lint_name,
|
||||
},
|
||||
);
|
||||
|
||||
let src = LintLevelSource::Node {
|
||||
name: Symbol::intern(&new_lint_name),
|
||||
name: Symbol::intern(new_lint_name),
|
||||
span: sp,
|
||||
reason,
|
||||
};
|
||||
|
|
|
@ -250,7 +250,7 @@ impl<'a> DecorateLint<'a, ()> for BuiltinUngatedAsyncFnTrackCaller<'_> {
|
|||
diag.span_label(self.label, fluent::lint_label);
|
||||
rustc_session::parse::add_feature_diagnostics(
|
||||
diag,
|
||||
&self.parse_sess,
|
||||
self.parse_sess,
|
||||
sym::async_fn_track_caller,
|
||||
);
|
||||
diag
|
||||
|
|
|
@ -204,7 +204,7 @@ impl EarlyLintPass for NonAsciiIdents {
|
|||
|
||||
// Get the skeleton as a `Symbol`.
|
||||
skeleton_buf.clear();
|
||||
skeleton_buf.extend(skeleton(&symbol_str));
|
||||
skeleton_buf.extend(skeleton(symbol_str));
|
||||
let skeleton_sym = if *symbol_str == *skeleton_buf {
|
||||
symbol
|
||||
} else {
|
||||
|
|
|
@ -334,7 +334,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase {
|
|||
let crate_ident = if let Some(name) = &cx.tcx.sess.opts.crate_name {
|
||||
Some(Ident::from_str(name))
|
||||
} else {
|
||||
attr::find_by_name(&cx.tcx.hir().attrs(hir::CRATE_HIR_ID), sym::crate_name)
|
||||
attr::find_by_name(cx.tcx.hir().attrs(hir::CRATE_HIR_ID), sym::crate_name)
|
||||
.and_then(|attr| attr.meta())
|
||||
.and_then(|meta| {
|
||||
meta.name_value_literal().and_then(|lit| {
|
||||
|
@ -473,7 +473,7 @@ impl NonUpperCaseGlobals {
|
|||
fn check_upper_case(cx: &LateContext<'_>, sort: &str, ident: &Ident) {
|
||||
let name = ident.name.as_str();
|
||||
if name.chars().any(|c| c.is_lowercase()) {
|
||||
let uc = NonSnakeCase::to_snake_case(&name).to_uppercase();
|
||||
let uc = NonSnakeCase::to_snake_case(name).to_uppercase();
|
||||
// We cannot provide meaningful suggestions
|
||||
// if the characters are in the category of "Lowercase Letter".
|
||||
let sub = if *name != uc {
|
||||
|
@ -520,7 +520,7 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
|
|||
|
||||
fn check_pat(&mut self, cx: &LateContext<'_>, p: &hir::Pat<'_>) {
|
||||
// Lint for constants that look like binding identifiers (#7526)
|
||||
if let PatKind::Path(hir::QPath::Resolved(None, ref path)) = p.kind {
|
||||
if let PatKind::Path(hir::QPath::Resolved(None, path)) = p.kind {
|
||||
if let Res::Def(DefKind::Const, _) = path.res {
|
||||
if path.segments.len() == 1 {
|
||||
NonUpperCaseGlobals::check_upper_case(
|
||||
|
|
|
@ -113,7 +113,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
|
|||
for (assoc_pred, assoc_pred_span) in cx
|
||||
.tcx
|
||||
.explicit_item_bounds(proj.projection_ty.def_id)
|
||||
.iter_instantiated_copied(cx.tcx, &proj.projection_ty.args)
|
||||
.iter_instantiated_copied(cx.tcx, proj.projection_ty.args)
|
||||
{
|
||||
let assoc_pred = assoc_pred.fold_with(proj_replacer);
|
||||
let Ok(assoc_pred) = traits::fully_normalize(
|
||||
|
|
|
@ -28,7 +28,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByValue {
|
|||
return;
|
||||
}
|
||||
}
|
||||
if let Some(t) = path_for_pass_by_value(cx, &inner_ty) {
|
||||
if let Some(t) = path_for_pass_by_value(cx, inner_ty) {
|
||||
cx.emit_spanned_lint(
|
||||
PASS_BY_VALUE,
|
||||
ty.span,
|
||||
|
|
|
@ -623,7 +623,7 @@ fn lint_nan<'tcx>(
|
|||
impl<'tcx> LateLintPass<'tcx> for TypeLimits {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx hir::Expr<'tcx>) {
|
||||
match e.kind {
|
||||
hir::ExprKind::Unary(hir::UnOp::Neg, ref expr) => {
|
||||
hir::ExprKind::Unary(hir::UnOp::Neg, expr) => {
|
||||
// Propagate negation, if the negation itself isn't negated
|
||||
if self.negated_expr_id != Some(e.hir_id) {
|
||||
self.negated_expr_id = Some(expr.hir_id);
|
||||
|
@ -632,14 +632,14 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
|
|||
}
|
||||
hir::ExprKind::Binary(binop, ref l, ref r) => {
|
||||
if is_comparison(binop) {
|
||||
if !check_limits(cx, binop, &l, &r) {
|
||||
if !check_limits(cx, binop, l, r) {
|
||||
cx.emit_spanned_lint(UNUSED_COMPARISONS, e.span, UnusedComparisons);
|
||||
} else {
|
||||
lint_nan(cx, e, binop, l, r);
|
||||
}
|
||||
}
|
||||
}
|
||||
hir::ExprKind::Lit(ref lit) => lint_literal(cx, self, e, lit),
|
||||
hir::ExprKind::Lit(lit) => lint_literal(cx, self, e, lit),
|
||||
_ => {}
|
||||
};
|
||||
|
||||
|
@ -685,7 +685,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
|
|||
ty::Int(int_ty) => {
|
||||
let (min, max) = int_ty_range(int_ty);
|
||||
let lit_val: i128 = match lit.kind {
|
||||
hir::ExprKind::Lit(ref li) => match li.node {
|
||||
hir::ExprKind::Lit(li) => match li.node {
|
||||
ast::LitKind::Int(
|
||||
v,
|
||||
ast::LitIntType::Signed(_) | ast::LitIntType::Unsuffixed,
|
||||
|
@ -699,7 +699,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
|
|||
ty::Uint(uint_ty) => {
|
||||
let (min, max): (u128, u128) = uint_ty_range(uint_ty);
|
||||
let lit_val: u128 = match lit.kind {
|
||||
hir::ExprKind::Lit(ref li) => match li.node {
|
||||
hir::ExprKind::Lit(li) => match li.node {
|
||||
ast::LitKind::Int(v, _) => v,
|
||||
_ => return true,
|
||||
},
|
||||
|
@ -1015,7 +1015,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
|||
// We can't completely trust `repr(C)` markings, so make sure the fields are actually safe.
|
||||
let mut all_phantom = !variant.fields.is_empty();
|
||||
for field in &variant.fields {
|
||||
all_phantom &= match self.check_field_type_for_ffi(cache, &field, args) {
|
||||
all_phantom &= match self.check_field_type_for_ffi(cache, field, args) {
|
||||
FfiSafe => false,
|
||||
// `()` fields are FFI-safe!
|
||||
FfiUnsafe { ty, .. } if ty.is_unit() => false,
|
||||
|
@ -1399,7 +1399,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
if let hir::FnRetTy::Return(ref ret_hir) = decl.output {
|
||||
if let hir::FnRetTy::Return(ret_hir) = decl.output {
|
||||
for (fn_ptr_ty, span) in self.find_fn_ptr_ty_with_external_abi(ret_hir, sig.output()) {
|
||||
self.check_type_for_ffi_and_report_errors(span, fn_ptr_ty, false, true);
|
||||
}
|
||||
|
@ -1415,7 +1415,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
|||
self.check_type_for_ffi_and_report_errors(input_hir.span, *input_ty, false, false);
|
||||
}
|
||||
|
||||
if let hir::FnRetTy::Return(ref ret_hir) = decl.output {
|
||||
if let hir::FnRetTy::Return(ret_hir) = decl.output {
|
||||
self.check_type_for_ffi_and_report_errors(ret_hir.span, sig.output(), false, true);
|
||||
}
|
||||
}
|
||||
|
@ -1487,13 +1487,13 @@ impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDeclarations {
|
|||
let abi = cx.tcx.hir().get_foreign_abi(it.hir_id());
|
||||
|
||||
match it.kind {
|
||||
hir::ForeignItemKind::Fn(ref decl, _, _) if !vis.is_internal_abi(abi) => {
|
||||
hir::ForeignItemKind::Fn(decl, _, _) if !vis.is_internal_abi(abi) => {
|
||||
vis.check_foreign_fn(it.owner_id.def_id, decl);
|
||||
}
|
||||
hir::ForeignItemKind::Static(ref ty, _) if !vis.is_internal_abi(abi) => {
|
||||
hir::ForeignItemKind::Static(ty, _) if !vis.is_internal_abi(abi) => {
|
||||
vis.check_foreign_static(it.owner_id, ty.span);
|
||||
}
|
||||
hir::ForeignItemKind::Fn(ref decl, _, _) => vis.check_fn(it.owner_id.def_id, decl),
|
||||
hir::ForeignItemKind::Fn(decl, _, _) => vis.check_fn(it.owner_id.def_id, decl),
|
||||
hir::ForeignItemKind::Static(..) | hir::ForeignItemKind::Type => (),
|
||||
}
|
||||
}
|
||||
|
@ -1705,7 +1705,7 @@ impl InvalidAtomicOrdering {
|
|||
sym::AtomicI64,
|
||||
sym::AtomicI128,
|
||||
];
|
||||
if let ExprKind::MethodCall(ref method_path, _, args, _) = &expr.kind
|
||||
if let ExprKind::MethodCall(method_path, _, args, _) = &expr.kind
|
||||
&& recognized_names.contains(&method_path.ident.name)
|
||||
&& let Some(m_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
|
||||
&& let Some(impl_did) = cx.tcx.impl_of_method(m_def_id)
|
||||
|
@ -1766,7 +1766,7 @@ impl InvalidAtomicOrdering {
|
|||
}
|
||||
|
||||
fn check_memory_fence(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
||||
if let ExprKind::Call(ref func, ref args) = expr.kind
|
||||
if let ExprKind::Call(func, args) = expr.kind
|
||||
&& let ExprKind::Path(ref func_qpath) = func.kind
|
||||
&& let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id()
|
||||
&& matches!(cx.tcx.get_diagnostic_name(def_id), Some(sym::fence | sym::compiler_fence))
|
||||
|
|
|
@ -111,7 +111,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
|||
}
|
||||
|
||||
if let hir::ExprKind::Match(await_expr, _arms, hir::MatchSource::AwaitDesugar) = expr.kind
|
||||
&& let ty = cx.typeck_results().expr_ty(&await_expr)
|
||||
&& let ty = cx.typeck_results().expr_ty(await_expr)
|
||||
&& let ty::Alias(ty::Opaque, ty::AliasTy { def_id: future_def_id, .. }) = ty.kind()
|
||||
&& cx.tcx.ty_is_opaque_future(ty)
|
||||
&& let async_fn_def_id = cx.tcx.parent(*future_def_id)
|
||||
|
@ -132,9 +132,9 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
|||
return;
|
||||
}
|
||||
|
||||
let ty = cx.typeck_results().expr_ty(&expr);
|
||||
let ty = cx.typeck_results().expr_ty(expr);
|
||||
|
||||
let must_use_result = is_ty_must_use(cx, ty, &expr, expr.span);
|
||||
let must_use_result = is_ty_must_use(cx, ty, expr, expr.span);
|
||||
let type_lint_emitted_or_suppressed = match must_use_result {
|
||||
Some(path) => {
|
||||
emit_must_use_untranslated(cx, &path, "", "", 1, false, expr_is_from_block);
|
||||
|
@ -211,7 +211,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
|
|||
expr_is_from_block: bool,
|
||||
) -> bool {
|
||||
let maybe_def_id = match expr.kind {
|
||||
hir::ExprKind::Call(ref callee, _) => {
|
||||
hir::ExprKind::Call(callee, _) => {
|
||||
match callee.kind {
|
||||
hir::ExprKind::Path(ref qpath) => {
|
||||
match cx.qpath_res(qpath, callee.hir_id) {
|
||||
|
@ -692,7 +692,7 @@ trait UnusedDelimLint {
|
|||
innermost = match &innermost.kind {
|
||||
ExprKind::AddrOf(_, _, expr) => expr,
|
||||
_ => {
|
||||
if parser::contains_exterior_struct_lit(&innermost) {
|
||||
if parser::contains_exterior_struct_lit(innermost) {
|
||||
return true;
|
||||
} else {
|
||||
break;
|
||||
|
@ -721,7 +721,7 @@ trait UnusedDelimLint {
|
|||
return matches!(rhs.kind, ExprKind::Block(..));
|
||||
}
|
||||
|
||||
_ => return parser::contains_exterior_struct_lit(&inner),
|
||||
_ => return parser::contains_exterior_struct_lit(inner),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -896,7 +896,7 @@ trait UnusedDelimLint {
|
|||
};
|
||||
self.check_unused_delims_expr(
|
||||
cx,
|
||||
&value,
|
||||
value,
|
||||
ctx,
|
||||
followed_by_block,
|
||||
left_pos,
|
||||
|
@ -919,7 +919,7 @@ trait UnusedDelimLint {
|
|||
StmtKind::Expr(ref expr) => {
|
||||
self.check_unused_delims_expr(
|
||||
cx,
|
||||
&expr,
|
||||
expr,
|
||||
UnusedDelimsCtx::BlockRetValue,
|
||||
false,
|
||||
None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue