1
Fork 0
This commit is contained in:
bjorn3 2025-02-08 22:12:13 +00:00
parent 3183b44a1e
commit 1fcae03369
287 changed files with 5888 additions and 4608 deletions

View file

@ -102,10 +102,11 @@ impl EarlyLintPass for WhileTrue {
"{}loop",
label.map_or_else(String::new, |label| format!("{}: ", label.ident,))
);
cx.emit_span_lint(WHILE_TRUE, condition_span, BuiltinWhileTrue {
suggestion: condition_span,
replace,
});
cx.emit_span_lint(
WHILE_TRUE,
condition_span,
BuiltinWhileTrue { suggestion: condition_span, replace },
);
}
}
}
@ -421,10 +422,11 @@ impl MissingDoc {
let attrs = cx.tcx.hir().attrs(cx.tcx.local_def_id_to_hir_id(def_id));
let has_doc = attrs.iter().any(has_doc);
if !has_doc {
cx.emit_span_lint(MISSING_DOCS, cx.tcx.def_span(def_id), BuiltinMissingDoc {
article,
desc,
});
cx.emit_span_lint(
MISSING_DOCS,
cx.tcx.def_span(def_id),
BuiltinMissingDoc { article, desc },
);
}
}
}
@ -706,10 +708,11 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
.next()
.is_some();
if !has_impl {
cx.emit_span_lint(MISSING_DEBUG_IMPLEMENTATIONS, item.span, BuiltinMissingDebugImpl {
tcx: cx.tcx,
def_id: debug,
});
cx.emit_span_lint(
MISSING_DEBUG_IMPLEMENTATIONS,
item.span,
BuiltinMissingDebugImpl { tcx: cx.tcx, def_id: debug },
);
}
}
}
@ -831,12 +834,11 @@ impl EarlyLintPass for DeprecatedAttr {
BuiltinDeprecatedAttrLinkSuggestion::Default { suggestion: attr.span }
}
};
cx.emit_span_lint(DEPRECATED, attr.span, BuiltinDeprecatedAttrLink {
name,
reason,
link,
suggestion,
});
cx.emit_span_lint(
DEPRECATED,
attr.span,
BuiltinDeprecatedAttrLink { name, reason, link, suggestion },
);
}
return;
}
@ -874,11 +876,11 @@ fn warn_if_doc(cx: &EarlyContext<'_>, node_span: Span, node_kind: &str, attrs: &
BuiltinUnusedDocCommentSub::BlockHelp
}
};
cx.emit_span_lint(UNUSED_DOC_COMMENTS, span, BuiltinUnusedDocComment {
kind: node_kind,
label: node_span,
sub,
});
cx.emit_span_lint(
UNUSED_DOC_COMMENTS,
span,
BuiltinUnusedDocComment { kind: node_kind, label: node_span, sub },
);
}
}
}
@ -1008,9 +1010,11 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
match param.kind {
GenericParamKind::Lifetime { .. } => {}
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
cx.emit_span_lint(NO_MANGLE_GENERIC_ITEMS, span, BuiltinNoMangleGeneric {
suggestion: no_mangle_attr.span,
});
cx.emit_span_lint(
NO_MANGLE_GENERIC_ITEMS,
span,
BuiltinNoMangleGeneric { suggestion: no_mangle_attr.span },
);
break;
}
}
@ -1037,9 +1041,11 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
// Const items do not refer to a particular location in memory, and therefore
// don't have anything to attach a symbol to
cx.emit_span_lint(NO_MANGLE_CONST_ITEMS, it.span, BuiltinConstNoMangle {
suggestion,
});
cx.emit_span_lint(
NO_MANGLE_CONST_ITEMS,
it.span,
BuiltinConstNoMangle { suggestion },
);
}
}
hir::ItemKind::Impl(hir::Impl { generics, items, .. }) => {
@ -1305,12 +1311,16 @@ impl UnreachablePub {
applicability = Applicability::MaybeIncorrect;
}
let def_span = cx.tcx.def_span(def_id);
cx.emit_span_lint(UNREACHABLE_PUB, def_span, BuiltinUnreachablePub {
what,
new_vis,
suggestion: (vis_span, applicability),
help: exportable,
});
cx.emit_span_lint(
UNREACHABLE_PUB,
def_span,
BuiltinUnreachablePub {
what,
new_vis,
suggestion: (vis_span, applicability),
help: exportable,
},
);
}
}
}
@ -1454,24 +1464,32 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
let enable_feat_help = cx.tcx.sess.is_nightly_build();
if let [.., label_sp] = *where_spans {
cx.emit_span_lint(TYPE_ALIAS_BOUNDS, where_spans, BuiltinTypeAliasBounds {
in_where_clause: true,
label: label_sp,
enable_feat_help,
suggestions: vec![(generics.where_clause_span, String::new())],
preds: generics.predicates,
ty: ty.take(),
});
cx.emit_span_lint(
TYPE_ALIAS_BOUNDS,
where_spans,
BuiltinTypeAliasBounds {
in_where_clause: true,
label: label_sp,
enable_feat_help,
suggestions: vec![(generics.where_clause_span, String::new())],
preds: generics.predicates,
ty: ty.take(),
},
);
}
if let [.., label_sp] = *inline_spans {
cx.emit_span_lint(TYPE_ALIAS_BOUNDS, inline_spans, BuiltinTypeAliasBounds {
in_where_clause: false,
label: label_sp,
enable_feat_help,
suggestions: inline_sugg,
preds: generics.predicates,
ty,
});
cx.emit_span_lint(
TYPE_ALIAS_BOUNDS,
inline_spans,
BuiltinTypeAliasBounds {
in_where_clause: false,
label: label_sp,
enable_feat_help,
suggestions: inline_sugg,
preds: generics.predicates,
ty,
},
);
}
}
}
@ -1559,10 +1577,11 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
| ty::ClauseKind::HostEffect(..) => continue,
};
if predicate.is_global() {
cx.emit_span_lint(TRIVIAL_BOUNDS, span, BuiltinTrivialBounds {
predicate_kind_name,
predicate,
});
cx.emit_span_lint(
TRIVIAL_BOUNDS,
span,
BuiltinTrivialBounds { predicate_kind_name, predicate },
);
}
}
}
@ -1611,12 +1630,16 @@ impl EarlyLintPass for DoubleNegations {
&& let ExprKind::Unary(UnOp::Neg, ref inner2) = inner.kind
&& !matches!(inner2.kind, ExprKind::Unary(UnOp::Neg, _))
{
cx.emit_span_lint(DOUBLE_NEGATIONS, expr.span, BuiltinDoubleNegations {
add_parens: BuiltinDoubleNegationsAddParens {
start_span: inner.span.shrink_to_lo(),
end_span: inner.span.shrink_to_hi(),
cx.emit_span_lint(
DOUBLE_NEGATIONS,
expr.span,
BuiltinDoubleNegations {
add_parens: BuiltinDoubleNegationsAddParens {
start_span: inner.span.shrink_to_lo(),
end_span: inner.span.shrink_to_hi(),
},
},
});
);
}
}
}
@ -1931,12 +1954,11 @@ impl KeywordIdents {
return;
}
cx.emit_span_lint(lint, ident.span, BuiltinKeywordIdents {
kw: ident,
next: edition,
suggestion: ident.span,
prefix,
});
cx.emit_span_lint(
lint,
ident.span,
BuiltinKeywordIdents { kw: ident, next: edition, suggestion: ident.span, prefix },
);
}
}
@ -2357,11 +2379,11 @@ impl EarlyLintPass for IncompleteInternalFeatures {
let help =
HAS_MIN_FEATURES.contains(&name).then_some(BuiltinIncompleteFeaturesHelp);
cx.emit_span_lint(INCOMPLETE_FEATURES, span, BuiltinIncompleteFeatures {
name,
note,
help,
});
cx.emit_span_lint(
INCOMPLETE_FEATURES,
span,
BuiltinIncompleteFeatures { name, note, help },
);
} else {
cx.emit_span_lint(INTERNAL_FEATURES, span, BuiltinInternalFeatures { name });
}
@ -2684,13 +2706,17 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
InitKind::Uninit => fluent::lint_builtin_unpermitted_type_init_uninit,
};
let sub = BuiltinUnpermittedTypeInitSub { err };
cx.emit_span_lint(INVALID_VALUE, expr.span, BuiltinUnpermittedTypeInit {
msg,
ty: conjured_ty,
label: expr.span,
sub,
tcx: cx.tcx,
});
cx.emit_span_lint(
INVALID_VALUE,
expr.span,
BuiltinUnpermittedTypeInit {
msg,
ty: conjured_ty,
label: expr.span,
sub,
tcx: cx.tcx,
},
);
}
}
}
@ -2776,9 +2802,11 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr {
{
// `&raw *NULL` is ok.
} else {
cx.emit_span_lint(DEREF_NULLPTR, expr.span, BuiltinDerefNullptr {
label: expr.span,
});
cx.emit_span_lint(
DEREF_NULLPTR,
expr.span,
BuiltinDerefNullptr { label: expr.span },
);
}
}
}
@ -2995,14 +3023,18 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels {
let span = span.unwrap_or(*template_span);
match label_kind {
AsmLabelKind::Named => {
cx.emit_span_lint(NAMED_ASM_LABELS, span, InvalidAsmLabel::Named {
missing_precise_span,
});
cx.emit_span_lint(
NAMED_ASM_LABELS,
span,
InvalidAsmLabel::Named { missing_precise_span },
);
}
AsmLabelKind::FormatArg => {
cx.emit_span_lint(NAMED_ASM_LABELS, span, InvalidAsmLabel::FormatArg {
missing_precise_span,
});
cx.emit_span_lint(
NAMED_ASM_LABELS,
span,
InvalidAsmLabel::FormatArg { missing_precise_span },
);
}
// the binary asm issue only occurs when using intel syntax on x86 targets
AsmLabelKind::Binary
@ -3012,10 +3044,11 @@ impl<'tcx> LateLintPass<'tcx> for AsmLabels {
Some(InlineAsmArch::X86 | InlineAsmArch::X86_64) | None
) =>
{
cx.emit_span_lint(BINARY_ASM_LABELS, span, InvalidAsmLabel::Binary {
missing_precise_span,
cx.emit_span_lint(
BINARY_ASM_LABELS,
span,
})
InvalidAsmLabel::Binary { missing_precise_span, span },
)
}
// No lint on anything other than x86
AsmLabelKind::Binary => (),

View file

@ -233,11 +233,14 @@ impl LintStore {
}
pub fn register_group_alias(&mut self, lint_name: &'static str, alias: &'static str) {
self.lint_groups.insert(alias, LintGroup {
lint_ids: vec![],
is_externally_loaded: false,
depr: Some(LintAlias { name: lint_name, silent: true }),
});
self.lint_groups.insert(
alias,
LintGroup {
lint_ids: vec![],
is_externally_loaded: false,
depr: Some(LintAlias { name: lint_name, silent: true }),
},
);
}
pub fn register_group(
@ -252,11 +255,14 @@ impl LintStore {
.insert(name, LintGroup { lint_ids: to, is_externally_loaded, depr: None })
.is_none();
if let Some(deprecated) = deprecated_name {
self.lint_groups.insert(deprecated, LintGroup {
lint_ids: vec![],
is_externally_loaded,
depr: Some(LintAlias { name, silent: false }),
});
self.lint_groups.insert(
deprecated,
LintGroup {
lint_ids: vec![],
is_externally_loaded,
depr: Some(LintAlias { name, silent: false }),
},
);
}
if !new {

View file

@ -85,14 +85,19 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait {
.find_map(|i| (i.ident.name == sym::Target).then_some(i.span))
.map(|label| SupertraitAsDerefTargetLabel { label });
let span = tcx.def_span(item.owner_id.def_id);
cx.emit_span_lint(DEREF_INTO_DYN_SUPERTRAIT, span, SupertraitAsDerefTarget {
self_ty,
supertrait_principal: supertrait_principal
.map_bound(|trait_ref| ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)),
target_principal,
label: span,
label2,
});
cx.emit_span_lint(
DEREF_INTO_DYN_SUPERTRAIT,
span,
SupertraitAsDerefTarget {
self_ty,
supertrait_principal: supertrait_principal.map_bound(|trait_ref| {
ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
}),
target_principal,
label: span,
label2,
},
);
}
}
}

View file

@ -163,32 +163,44 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
};
match fn_name {
sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => {
cx.emit_span_lint(DROPPING_REFERENCES, expr.span, DropRefDiag {
arg_ty,
label: arg.span,
sugg: let_underscore_ignore_sugg(),
});
cx.emit_span_lint(
DROPPING_REFERENCES,
expr.span,
DropRefDiag { arg_ty, label: arg.span, sugg: let_underscore_ignore_sugg() },
);
}
sym::mem_forget if arg_ty.is_ref() => {
cx.emit_span_lint(FORGETTING_REFERENCES, expr.span, ForgetRefDiag {
arg_ty,
label: arg.span,
sugg: let_underscore_ignore_sugg(),
});
cx.emit_span_lint(
FORGETTING_REFERENCES,
expr.span,
ForgetRefDiag {
arg_ty,
label: arg.span,
sugg: let_underscore_ignore_sugg(),
},
);
}
sym::mem_drop if is_copy && !drop_is_single_call_in_arm => {
cx.emit_span_lint(DROPPING_COPY_TYPES, expr.span, DropCopyDiag {
arg_ty,
label: arg.span,
sugg: let_underscore_ignore_sugg(),
});
cx.emit_span_lint(
DROPPING_COPY_TYPES,
expr.span,
DropCopyDiag {
arg_ty,
label: arg.span,
sugg: let_underscore_ignore_sugg(),
},
);
}
sym::mem_forget if is_copy => {
cx.emit_span_lint(FORGETTING_COPY_TYPES, expr.span, ForgetCopyDiag {
arg_ty,
label: arg.span,
sugg: let_underscore_ignore_sugg(),
});
cx.emit_span_lint(
FORGETTING_COPY_TYPES,
expr.span,
ForgetCopyDiag {
arg_ty,
label: arg.span,
sugg: let_underscore_ignore_sugg(),
},
);
}
sym::mem_drop
if let ty::Adt(adt, _) = arg_ty.kind()

View file

@ -54,10 +54,11 @@ fn enforce_mem_discriminant(
) {
let ty_param = cx.typeck_results().node_args(func_expr.hir_id).type_at(0);
if is_non_enum(ty_param) {
cx.emit_span_lint(ENUM_INTRINSICS_NON_ENUMS, expr_span, EnumIntrinsicsMemDiscriminate {
ty_param,
note: args_span,
});
cx.emit_span_lint(
ENUM_INTRINSICS_NON_ENUMS,
expr_span,
EnumIntrinsicsMemDiscriminate { ty_param, note: args_span },
);
}
}

View file

@ -96,14 +96,11 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles {
end_span: pat.span.between(arg.span),
};
cx.emit_span_lint(FOR_LOOPS_OVER_FALLIBLES, arg.span, ForLoopsOverFalliblesDiag {
article,
ref_prefix,
ty,
sub,
question_mark,
suggestion,
});
cx.emit_span_lint(
FOR_LOOPS_OVER_FALLIBLES,
arg.span,
ForLoopsOverFalliblesDiag { article, ref_prefix, ty, sub, question_mark, suggestion },
);
}
}

View file

@ -74,13 +74,11 @@ impl HiddenUnicodeCodepoints {
HiddenUnicodeCodepointsDiagSub::NoEscape { spans }
};
cx.emit_span_lint(TEXT_DIRECTION_CODEPOINT_IN_LITERAL, span, HiddenUnicodeCodepointsDiag {
label,
count,
span_label: span,
labels,
sub,
});
cx.emit_span_lint(
TEXT_DIRECTION_CODEPOINT_IN_LITERAL,
span,
HiddenUnicodeCodepointsDiag { label, count, span_label: span, labels, sub },
);
}
fn check_literal(

View file

@ -221,20 +221,25 @@ impl IfLetRescope {
}
}
if let Some((span, hir_id)) = first_if_to_lint {
tcx.emit_node_span_lint(IF_LET_RESCOPE, hir_id, span, IfLetRescopeLint {
significant_droppers,
lifetime_ends,
rewrite: first_if_to_rewrite.then_some(IfLetRescopeRewrite {
match_heads,
consequent_heads,
closing_brackets: ClosingBrackets {
span: expr_end,
count: closing_brackets,
empty_alt,
},
alt_heads,
}),
});
tcx.emit_node_span_lint(
IF_LET_RESCOPE,
hir_id,
span,
IfLetRescopeLint {
significant_droppers,
lifetime_ends,
rewrite: first_if_to_rewrite.then_some(IfLetRescopeRewrite {
match_heads,
consequent_heads,
closing_brackets: ClosingBrackets {
span: expr_end,
count: closing_brackets,
empty_alt,
},
alt_heads,
}),
},
);
}
}
}

View file

@ -314,12 +314,10 @@ where
// We only computed variance of lifetimes...
debug_assert_matches!(self.tcx.def_kind(def_id), DefKind::LifetimeParam);
let uncaptured = match *kind {
ParamKind::Early(name, index) => {
ty::Region::new_early_param(self.tcx, ty::EarlyParamRegion {
name,
index,
})
}
ParamKind::Early(name, index) => ty::Region::new_early_param(
self.tcx,
ty::EarlyParamRegion { name, index },
),
ParamKind::Free(def_id, name) => ty::Region::new_late_param(
self.tcx,
self.parent_def_id.to_def_id(),

View file

@ -48,10 +48,11 @@ impl LateLintPass<'_> for DefaultHashTypes {
Some(sym::HashSet) => "FxHashSet",
_ => return,
};
cx.emit_span_lint(DEFAULT_HASH_TYPES, path.span, DefaultHashTypesDiag {
preferred,
used: cx.tcx.item_name(def_id),
});
cx.emit_span_lint(
DEFAULT_HASH_TYPES,
path.span,
DefaultHashTypesDiag { preferred, used: cx.tcx.item_name(def_id) },
);
}
}
@ -107,14 +108,18 @@ impl LateLintPass<'_> for QueryStability {
{
let def_id = instance.def_id();
if cx.tcx.has_attr(def_id, sym::rustc_lint_query_instability) {
cx.emit_span_lint(POTENTIAL_QUERY_INSTABILITY, span, QueryInstability {
query: cx.tcx.item_name(def_id),
});
cx.emit_span_lint(
POTENTIAL_QUERY_INSTABILITY,
span,
QueryInstability { query: cx.tcx.item_name(def_id) },
);
}
if cx.tcx.has_attr(def_id, sym::rustc_lint_untracked_query_information) {
cx.emit_span_lint(UNTRACKED_QUERY_INFORMATION, span, QueryUntracked {
method: cx.tcx.item_name(def_id),
});
cx.emit_span_lint(
UNTRACKED_QUERY_INFORMATION,
span,
QueryUntracked { method: cx.tcx.item_name(def_id) },
);
}
}
}
@ -186,9 +191,11 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
match span {
Some(span) => {
cx.emit_span_lint(USAGE_OF_TY_TYKIND, path.span, TykindKind {
suggestion: span,
});
cx.emit_span_lint(
USAGE_OF_TY_TYKIND,
path.span,
TykindKind { suggestion: span },
);
}
None => cx.emit_span_lint(USAGE_OF_TY_TYKIND, path.span, TykindDiag),
}
@ -196,10 +203,11 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
&& path.segments.len() > 1
&& let Some(ty) = is_ty_or_ty_ctxt(cx, path)
{
cx.emit_span_lint(USAGE_OF_QUALIFIED_TY, path.span, TyQualified {
ty,
suggestion: path.span,
});
cx.emit_span_lint(
USAGE_OF_QUALIFIED_TY,
path.span,
TyQualified { ty, suggestion: path.span },
);
}
}
_ => {}
@ -553,9 +561,11 @@ impl LateLintPass<'_> for BadOptAccess {
&& let Some(lit) = item.lit()
&& let ast::LitKind::Str(val, _) = lit.kind
{
cx.emit_span_lint(BAD_OPT_ACCESS, expr.span, BadOptAccessDiag {
msg: val.as_str(),
});
cx.emit_span_lint(
BAD_OPT_ACCESS,
expr.span,
BadOptAccessDiag { msg: val.as_str() },
);
}
}
}

View file

@ -156,10 +156,11 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
};
if is_sync_lock {
let span = MultiSpan::from_span(pat.span);
cx.emit_span_lint(LET_UNDERSCORE_LOCK, span, NonBindingLet::SyncLock {
sub,
pat: pat.span,
});
cx.emit_span_lint(
LET_UNDERSCORE_LOCK,
span,
NonBindingLet::SyncLock { sub, pat: pat.span },
);
// Only emit let_underscore_drop for top-level `_` patterns.
} else if can_use_init.is_some() {
cx.emit_span_lint(LET_UNDERSCORE_DROP, local.span, NonBindingLet::DropType { sub });

View file

@ -627,18 +627,23 @@ fn register_internals(store: &mut LintStore) {
// `DIAGNOSTIC_OUTSIDE_OF_IMPL` here because `-Wrustc::internal` is provided to every crate and
// these lints will trigger all of the time - change this once migration to diagnostic structs
// and translation is completed
store.register_group(false, "rustc::internal", None, vec![
LintId::of(DEFAULT_HASH_TYPES),
LintId::of(POTENTIAL_QUERY_INSTABILITY),
LintId::of(UNTRACKED_QUERY_INFORMATION),
LintId::of(USAGE_OF_TY_TYKIND),
LintId::of(PASS_BY_VALUE),
LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO),
LintId::of(USAGE_OF_QUALIFIED_TY),
LintId::of(NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT),
LintId::of(BAD_OPT_ACCESS),
LintId::of(SPAN_USE_EQ_CTXT),
]);
store.register_group(
false,
"rustc::internal",
None,
vec![
LintId::of(DEFAULT_HASH_TYPES),
LintId::of(POTENTIAL_QUERY_INSTABILITY),
LintId::of(UNTRACKED_QUERY_INFORMATION),
LintId::of(USAGE_OF_TY_TYKIND),
LintId::of(PASS_BY_VALUE),
LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO),
LintId::of(USAGE_OF_QUALIFIED_TY),
LintId::of(NON_GLOB_IMPORT_OF_TYPE_IR_INHERENT),
LintId::of(BAD_OPT_ACCESS),
LintId::of(SPAN_USE_EQ_CTXT),
],
);
}
#[cfg(test)]

View file

@ -60,25 +60,39 @@ impl<'tcx> LateLintPass<'tcx> for MapUnitFn {
let fn_ty = cx.tcx.fn_sig(id).skip_binder();
let ret_ty = fn_ty.output().skip_binder();
if is_unit_type(ret_ty) {
cx.emit_span_lint(MAP_UNIT_FN, span, MappingToUnit {
function_label: cx.tcx.span_of_impl(*id).unwrap_or(default_span),
argument_label: args[0].span,
map_label: arg_ty.default_span(cx.tcx),
suggestion: path.ident.span,
replace: "for_each".to_string(),
})
cx.emit_span_lint(
MAP_UNIT_FN,
span,
MappingToUnit {
function_label: cx
.tcx
.span_of_impl(*id)
.unwrap_or(default_span),
argument_label: args[0].span,
map_label: arg_ty.default_span(cx.tcx),
suggestion: path.ident.span,
replace: "for_each".to_string(),
},
)
}
} else if let ty::Closure(id, subs) = arg_ty.kind() {
let cl_ty = subs.as_closure().sig();
let ret_ty = cl_ty.output().skip_binder();
if is_unit_type(ret_ty) {
cx.emit_span_lint(MAP_UNIT_FN, span, MappingToUnit {
function_label: cx.tcx.span_of_impl(*id).unwrap_or(default_span),
argument_label: args[0].span,
map_label: arg_ty.default_span(cx.tcx),
suggestion: path.ident.span,
replace: "for_each".to_string(),
})
cx.emit_span_lint(
MAP_UNIT_FN,
span,
MappingToUnit {
function_label: cx
.tcx
.span_of_impl(*id)
.unwrap_or(default_span),
argument_label: args[0].span,
map_label: arg_ty.default_span(cx.tcx),
suggestion: path.ident.span,
replace: "for_each".to_string(),
},
)
}
}
}

View file

@ -209,22 +209,30 @@ impl EarlyLintPass for NonAsciiIdents {
if codepoints.is_empty() {
continue;
}
cx.emit_span_lint(UNCOMMON_CODEPOINTS, sp, IdentifierUncommonCodepoints {
codepoints_len: codepoints.len(),
codepoints: codepoints.into_iter().map(|(c, _)| c).collect(),
identifier_type: id_ty_descr,
});
cx.emit_span_lint(
UNCOMMON_CODEPOINTS,
sp,
IdentifierUncommonCodepoints {
codepoints_len: codepoints.len(),
codepoints: codepoints.into_iter().map(|(c, _)| c).collect(),
identifier_type: id_ty_descr,
},
);
}
let remaining = chars
.extract_if(.., |(c, _)| !GeneralSecurityProfile::identifier_allowed(*c))
.collect::<Vec<_>>();
if !remaining.is_empty() {
cx.emit_span_lint(UNCOMMON_CODEPOINTS, sp, IdentifierUncommonCodepoints {
codepoints_len: remaining.len(),
codepoints: remaining.into_iter().map(|(c, _)| c).collect(),
identifier_type: "Restricted",
});
cx.emit_span_lint(
UNCOMMON_CODEPOINTS,
sp,
IdentifierUncommonCodepoints {
codepoints_len: remaining.len(),
codepoints: remaining.into_iter().map(|(c, _)| c).collect(),
identifier_type: "Restricted",
},
);
}
}
}
@ -253,12 +261,16 @@ impl EarlyLintPass for NonAsciiIdents {
.entry(skeleton_sym)
.and_modify(|(existing_symbol, existing_span, existing_is_ascii)| {
if !*existing_is_ascii || !is_ascii {
cx.emit_span_lint(CONFUSABLE_IDENTS, sp, ConfusableIdentifierPair {
existing_sym: *existing_symbol,
sym: symbol,
label: *existing_span,
main_label: sp,
});
cx.emit_span_lint(
CONFUSABLE_IDENTS,
sp,
ConfusableIdentifierPair {
existing_sym: *existing_symbol,
sym: symbol,
label: *existing_span,
main_label: sp,
},
);
}
if *existing_is_ascii && !is_ascii {
*existing_symbol = symbol;
@ -370,10 +382,11 @@ impl EarlyLintPass for NonAsciiIdents {
let char_info = format!("'{}' (U+{:04X})", ch, ch as u32);
includes += &char_info;
}
cx.emit_span_lint(MIXED_SCRIPT_CONFUSABLES, sp, MixedScriptConfusables {
set: script_set.to_string(),
includes,
});
cx.emit_span_lint(
MIXED_SCRIPT_CONFUSABLES,
sp,
MixedScriptConfusables { set: script_set.to_string(), includes },
);
}
}
}

View file

@ -256,10 +256,14 @@ fn check_panic_str<'tcx>(
.map(|span| fmt_span.from_inner(InnerSpan::new(span.start, span.end)))
.collect(),
};
cx.emit_span_lint(NON_FMT_PANICS, arg_spans, NonFmtPanicUnused {
count: n_arguments,
suggestion: is_arg_inside_call(arg.span, span).then_some(arg.span),
});
cx.emit_span_lint(
NON_FMT_PANICS,
arg_spans,
NonFmtPanicUnused {
count: n_arguments,
suggestion: is_arg_inside_call(arg.span, span).then_some(arg.span),
},
);
} else {
let brace_spans: Option<Vec<_>> =
snippet.filter(|s| s.starts_with('"') || s.starts_with("r#")).map(|s| {

View file

@ -222,17 +222,21 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
None
};
cx.emit_span_lint(NON_LOCAL_DEFINITIONS, ms, NonLocalDefinitionsDiag::Impl {
depth: self.body_depth,
body_kind_descr: cx.tcx.def_kind_descr(parent_def_kind, parent),
body_name: parent_opt_item_name
.map(|s| s.to_ident_string())
.unwrap_or_else(|| "<unnameable>".to_string()),
cargo_update: cargo_update(),
const_anon,
doctest,
macro_to_change,
})
cx.emit_span_lint(
NON_LOCAL_DEFINITIONS,
ms,
NonLocalDefinitionsDiag::Impl {
depth: self.body_depth,
body_kind_descr: cx.tcx.def_kind_descr(parent_def_kind, parent),
body_name: parent_opt_item_name
.map(|s| s.to_ident_string())
.unwrap_or_else(|| "<unnameable>".to_string()),
cargo_update: cargo_update(),
const_anon,
doctest,
macro_to_change,
},
)
}
ItemKind::Macro(_macro, MacroKind::Bang)
if cx.tcx.has_attr(item.owner_id.def_id, sym::macro_export) =>

View file

@ -150,11 +150,11 @@ impl NonCamelCaseTypes {
} else {
NonCamelCaseTypeSub::Label { span: ident.span }
};
cx.emit_span_lint(NON_CAMEL_CASE_TYPES, ident.span, NonCamelCaseType {
sort,
name,
sub,
});
cx.emit_span_lint(
NON_CAMEL_CASE_TYPES,
ident.span,
NonCamelCaseType { sort, name, sub },
);
}
}
}
@ -488,11 +488,11 @@ impl NonUpperCaseGlobals {
} else {
NonUpperCaseGlobalSub::Label { span: ident.span }
};
cx.emit_span_lint(NON_UPPER_CASE_GLOBALS, ident.span, NonUpperCaseGlobal {
sort,
name,
sub,
});
cx.emit_span_lint(
NON_UPPER_CASE_GLOBALS,
ident.span,
NonUpperCaseGlobal { sort, name, sub },
);
}
}
}

View file

@ -128,13 +128,17 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
ty::Adt(def, _) => Some(cx.tcx.def_span(def.did()).shrink_to_lo()),
_ => None,
};
cx.emit_span_lint(NOOP_METHOD_CALL, span, NoopMethodCallDiag {
method: call.ident,
orig_ty,
trait_,
label: span,
suggest_derive,
});
cx.emit_span_lint(
NOOP_METHOD_CALL,
span,
NoopMethodCallDiag {
method: call.ident,
orig_ty,
trait_,
label: span,
suggest_derive,
},
);
} else {
match name {
// If `type_of(x) == T` and `x.borrow()` is used to get `&T`,

View file

@ -113,10 +113,13 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
// return type is well-formed in traits even when `Self` isn't sized.
if let ty::Param(param_ty) = *proj_term.kind()
&& param_ty.name == kw::SelfUpper
&& matches!(opaque.origin, hir::OpaqueTyOrigin::AsyncFn {
in_trait_or_impl: Some(hir::RpitContext::Trait),
..
})
&& matches!(
opaque.origin,
hir::OpaqueTyOrigin::AsyncFn {
in_trait_or_impl: Some(hir::RpitContext::Trait),
..
}
)
{
return;
}

View file

@ -30,10 +30,11 @@ impl<'tcx> LateLintPass<'tcx> for PassByValue {
}
}
if let Some(t) = path_for_pass_by_value(cx, inner_ty) {
cx.emit_span_lint(PASS_BY_VALUE, ty.span, PassByValueDiag {
ty: t,
suggestion: ty.span,
});
cx.emit_span_lint(
PASS_BY_VALUE,
ty.span,
PassByValueDiag { ty: t, suggestion: ty.span },
);
}
}
_ => {}

View file

@ -50,9 +50,10 @@ fn maybe_lint_redundant_semis(cx: &EarlyContext<'_>, seq: &mut Option<(Span, boo
return;
}
cx.emit_span_lint(REDUNDANT_SEMICOLONS, span, RedundantSemicolonsDiag {
multiple,
suggestion: span,
});
cx.emit_span_lint(
REDUNDANT_SEMICOLONS,
span,
RedundantSemicolonsDiag { multiple, suggestion: span },
);
}
}

View file

@ -147,11 +147,10 @@ impl<'tcx> LateLintPass<'tcx> for ShadowedIntoIter {
None
};
cx.emit_span_lint(lint, call.ident.span, ShadowedIntoIterDiag {
target,
edition,
suggestion: call.ident.span,
sub,
});
cx.emit_span_lint(
lint,
call.ident.span,
ShadowedIntoIterDiag { target, edition, suggestion: call.ident.span, sub },
);
}
}

View file

@ -157,11 +157,9 @@ fn emit_static_mut_refs(
}
};
cx.emit_span_lint(STATIC_MUT_REFS, span, RefOfMutStatic {
cx.emit_span_lint(
STATIC_MUT_REFS,
span,
sugg,
shared_label,
shared_note,
mut_note,
});
RefOfMutStatic { span, sugg, shared_label, shared_note, mut_note },
);
}

View file

@ -101,11 +101,11 @@ impl<'tcx> LateLintPass<'tcx> for DropTraitConstraints {
continue;
}
let Some(def_id) = cx.tcx.get_diagnostic_item(sym::needs_drop) else { return };
cx.emit_span_lint(DROP_BOUNDS, span, DropTraitConstraintsDiag {
predicate,
tcx: cx.tcx,
def_id,
});
cx.emit_span_lint(
DROP_BOUNDS,
span,
DropTraitConstraintsDiag { predicate, tcx: cx.tcx, def_id },
);
}
}
}

View file

@ -599,13 +599,16 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
}
fn rev_binop(binop: hir::BinOp) -> hir::BinOp {
source_map::respan(binop.span, match binop.node {
hir::BinOpKind::Lt => hir::BinOpKind::Gt,
hir::BinOpKind::Le => hir::BinOpKind::Ge,
hir::BinOpKind::Gt => hir::BinOpKind::Lt,
hir::BinOpKind::Ge => hir::BinOpKind::Le,
_ => return binop,
})
source_map::respan(
binop.span,
match binop.node {
hir::BinOpKind::Lt => hir::BinOpKind::Gt,
hir::BinOpKind::Le => hir::BinOpKind::Ge,
hir::BinOpKind::Gt => hir::BinOpKind::Lt,
hir::BinOpKind::Ge => hir::BinOpKind::Le,
_ => return binop,
},
)
}
fn check_limits(
@ -1386,14 +1389,11 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
} else {
None
};
self.cx.emit_span_lint(lint, sp, ImproperCTypes {
ty,
desc,
label: sp,
help,
note,
span_note,
});
self.cx.emit_span_lint(
lint,
sp,
ImproperCTypes { ty, desc, label: sp, help, note, span_note },
);
}
fn check_for_opaque_ty(&mut self, sp: Span, ty: Ty<'tcx>) -> bool {
@ -1930,11 +1930,11 @@ impl InvalidAtomicOrdering {
}
fn check_atomic_compare_exchange(cx: &LateContext<'_>, expr: &Expr<'_>) {
let Some((method, args)) = Self::inherent_atomic_method_call(cx, expr, &[
sym::fetch_update,
sym::compare_exchange,
sym::compare_exchange_weak,
]) else {
let Some((method, args)) = Self::inherent_atomic_method_call(
cx,
expr,
&[sym::fetch_update, sym::compare_exchange, sym::compare_exchange_weak],
) else {
return;
};

View file

@ -77,10 +77,11 @@ fn lint_overflowing_range_endpoint<'tcx>(
}
};
cx.emit_span_lint(OVERFLOWING_LITERALS, struct_expr.span, RangeEndpointOutOfRange {
ty,
sub: sub_sugg,
});
cx.emit_span_lint(
OVERFLOWING_LITERALS,
struct_expr.span,
RangeEndpointOutOfRange { ty, sub: sub_sugg },
);
// We've just emitted a lint, special cased for `(...)..MAX+1` ranges,
// return `true` so the callers don't also emit a lint
@ -190,15 +191,19 @@ fn report_bin_hex_error(
})
.flatten();
cx.emit_span_lint(OVERFLOWING_LITERALS, span, OverflowingBinHex {
ty: t,
lit: repr_str.clone(),
dec: val,
actually,
sign,
sub,
sign_bit_sub,
})
cx.emit_span_lint(
OVERFLOWING_LITERALS,
span,
OverflowingBinHex {
ty: t,
lit: repr_str.clone(),
dec: val,
actually,
sign,
sub,
sign_bit_sub,
},
)
}
// Find the "next" fitting integer and return a suggestion string
@ -283,13 +288,11 @@ fn lint_int_literal<'tcx>(
let help = get_type_suggestion(cx.typeck_results().node_type(hir_id), v, negative)
.map(|suggestion_ty| OverflowingIntHelp { suggestion_ty });
cx.emit_span_lint(OVERFLOWING_LITERALS, span, OverflowingInt {
ty: t.name_str(),
lit,
min,
max,
help,
});
cx.emit_span_lint(
OVERFLOWING_LITERALS,
span,
OverflowingInt { ty: t.name_str(), lit, min, max, help },
);
}
}
@ -314,10 +317,11 @@ fn lint_uint_literal<'tcx>(
match par_e.kind {
hir::ExprKind::Cast(..) => {
if let ty::Char = cx.typeck_results().expr_ty(par_e).kind() {
cx.emit_span_lint(OVERFLOWING_LITERALS, par_e.span, OnlyCastu8ToChar {
span: par_e.span,
literal: lit_val,
});
cx.emit_span_lint(
OVERFLOWING_LITERALS,
par_e.span,
OnlyCastu8ToChar { span: par_e.span, literal: lit_val },
);
return;
}
}
@ -341,16 +345,20 @@ fn lint_uint_literal<'tcx>(
);
return;
}
cx.emit_span_lint(OVERFLOWING_LITERALS, span, OverflowingUInt {
ty: t.name_str(),
lit: cx
.sess()
.source_map()
.span_to_snippet(lit.span)
.unwrap_or_else(|_| lit_val.to_string()),
min,
max,
});
cx.emit_span_lint(
OVERFLOWING_LITERALS,
span,
OverflowingUInt {
ty: t.name_str(),
lit: cx
.sess()
.source_map()
.span_to_snippet(lit.span)
.unwrap_or_else(|_| lit_val.to_string()),
min,
max,
},
);
}
}
@ -388,14 +396,18 @@ pub(crate) fn lint_literal<'tcx>(
_ => bug!(),
};
if is_infinite == Ok(true) {
cx.emit_span_lint(OVERFLOWING_LITERALS, span, OverflowingLiteral {
ty: t.name_str(),
lit: cx
.sess()
.source_map()
.span_to_snippet(lit.span)
.unwrap_or_else(|_| sym.to_string()),
});
cx.emit_span_lint(
OVERFLOWING_LITERALS,
span,
OverflowingLiteral {
ty: t.name_str(),
lit: cx
.sess()
.source_map()
.span_to_snippet(lit.span)
.unwrap_or_else(|_| sym.to_string()),
},
);
}
}
_ => {}

View file

@ -63,9 +63,11 @@ impl<'tcx> LateLintPass<'tcx> for UnitBindings {
&& !matches!(init.kind, hir::ExprKind::Tup([]))
&& !matches!(local.pat.kind, hir::PatKind::Tuple([], ..))
{
cx.emit_span_lint(UNIT_BINDINGS, local.span, UnitBindingsDiag {
label: local.pat.span,
});
cx.emit_span_lint(
UNIT_BINDINGS,
local.span,
UnitBindingsDiag { label: local.pat.span },
);
}
}
}

View file

@ -184,18 +184,22 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
let mut op_warned = false;
if let Some(must_use_op) = must_use_op {
cx.emit_span_lint(UNUSED_MUST_USE, expr.span, UnusedOp {
op: must_use_op,
label: expr.span,
suggestion: if expr_is_from_block {
UnusedOpSuggestion::BlockTailExpr {
before_span: expr.span.shrink_to_lo(),
after_span: expr.span.shrink_to_hi(),
}
} else {
UnusedOpSuggestion::NormalExpr { span: expr.span.shrink_to_lo() }
cx.emit_span_lint(
UNUSED_MUST_USE,
expr.span,
UnusedOp {
op: must_use_op,
label: expr.span,
suggestion: if expr_is_from_block {
UnusedOpSuggestion::BlockTailExpr {
before_span: expr.span.shrink_to_lo(),
after_span: expr.span.shrink_to_hi(),
}
} else {
UnusedOpSuggestion::NormalExpr { span: expr.span.shrink_to_lo() }
},
},
});
);
op_warned = true;
}
@ -489,35 +493,39 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
);
}
MustUsePath::Closure(span) => {
cx.emit_span_lint(UNUSED_MUST_USE, *span, UnusedClosure {
count: plural_len,
pre: descr_pre,
post: descr_post,
});
cx.emit_span_lint(
UNUSED_MUST_USE,
*span,
UnusedClosure { count: plural_len, pre: descr_pre, post: descr_post },
);
}
MustUsePath::Coroutine(span) => {
cx.emit_span_lint(UNUSED_MUST_USE, *span, UnusedCoroutine {
count: plural_len,
pre: descr_pre,
post: descr_post,
});
cx.emit_span_lint(
UNUSED_MUST_USE,
*span,
UnusedCoroutine { count: plural_len, pre: descr_pre, post: descr_post },
);
}
MustUsePath::Def(span, def_id, reason) => {
cx.emit_span_lint(UNUSED_MUST_USE, *span, UnusedDef {
pre: descr_pre,
post: descr_post,
cx,
def_id: *def_id,
note: *reason,
suggestion: (!is_inner).then_some(if expr_is_from_block {
UnusedDefSuggestion::BlockTailExpr {
before_span: span.shrink_to_lo(),
after_span: span.shrink_to_hi(),
}
} else {
UnusedDefSuggestion::NormalExpr { span: span.shrink_to_lo() }
}),
});
cx.emit_span_lint(
UNUSED_MUST_USE,
*span,
UnusedDef {
pre: descr_pre,
post: descr_post,
cx,
def_id: *def_id,
note: *reason,
suggestion: (!is_inner).then_some(if expr_is_from_block {
UnusedDefSuggestion::BlockTailExpr {
before_span: span.shrink_to_lo(),
after_span: span.shrink_to_hi(),
}
} else {
UnusedDefSuggestion::NormalExpr { span: span.shrink_to_lo() }
}),
},
);
}
}
}
@ -867,11 +875,11 @@ trait UnusedDelimLint {
end_replace: hi_replace,
}
});
cx.emit_span_lint(self.lint(), primary_span, UnusedDelim {
delim: Self::DELIM_STR,
item: msg,
suggestion,
});
cx.emit_span_lint(
self.lint(),
primary_span,
UnusedDelim { delim: Self::DELIM_STR, item: msg, suggestion },
);
}
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
@ -1558,9 +1566,11 @@ impl UnusedImportBraces {
ast::UseTreeKind::Nested { .. } => return,
};
cx.emit_span_lint(UNUSED_IMPORT_BRACES, item.span, UnusedImportBracesDiag {
node: node_name,
});
cx.emit_span_lint(
UNUSED_IMPORT_BRACES,
item.span,
UnusedImportBracesDiag { node: node_name },
);
}
}
}