lint: port ty diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
8139542598
commit
0996a7ab5c
2 changed files with 21 additions and 11 deletions
|
@ -34,3 +34,12 @@ lint-default-hash-types = prefer `{$preferred}` over `{$used}`, it has better pe
|
||||||
|
|
||||||
lint-query-instability = using `{$query}` can result in unstable query results
|
lint-query-instability = using `{$query}` can result in unstable query results
|
||||||
.note = if you believe this case to be fine, allow this lint and add a comment explaining your rationale
|
.note = if you believe this case to be fine, allow this lint and add a comment explaining your rationale
|
||||||
|
|
||||||
|
lint-tykind-kind = usage of `ty::TyKind::<kind>`
|
||||||
|
.suggestion = try using `ty::<kind>` directly
|
||||||
|
|
||||||
|
lint-tykind = usage of `ty::TyKind`
|
||||||
|
.help = try using `Ty` instead
|
||||||
|
|
||||||
|
lint-ty-qualified = usage of qualified `ty::{$ty}`
|
||||||
|
.suggestion = try importing it and using it unqualified
|
||||||
|
|
|
@ -140,10 +140,10 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
|
||||||
segment.args.map_or(segment.ident.span, |a| a.span_ext).hi()
|
segment.args.map_or(segment.ident.span, |a| a.span_ext).hi()
|
||||||
);
|
);
|
||||||
cx.struct_span_lint(USAGE_OF_TY_TYKIND, path.span, |lint| {
|
cx.struct_span_lint(USAGE_OF_TY_TYKIND, path.span, |lint| {
|
||||||
lint.build("usage of `ty::TyKind::<kind>`")
|
lint.build(fluent::lint::tykind_kind)
|
||||||
.span_suggestion(
|
.span_suggestion(
|
||||||
span,
|
span,
|
||||||
"try using `ty::<kind>` directly",
|
fluent::lint::suggestion,
|
||||||
"ty",
|
"ty",
|
||||||
Applicability::MaybeIncorrect, // ty maybe needs an import
|
Applicability::MaybeIncorrect, // ty maybe needs an import
|
||||||
)
|
)
|
||||||
|
@ -169,10 +169,10 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
|
||||||
if let QPath::TypeRelative(qpath_ty, ..) = qpath
|
if let QPath::TypeRelative(qpath_ty, ..) = qpath
|
||||||
&& qpath_ty.hir_id == ty.hir_id
|
&& qpath_ty.hir_id == ty.hir_id
|
||||||
{
|
{
|
||||||
lint.build("usage of `ty::TyKind::<kind>`")
|
lint.build(fluent::lint::tykind_kind)
|
||||||
.span_suggestion(
|
.span_suggestion(
|
||||||
path.span,
|
path.span,
|
||||||
"try using `ty::<kind>` directly",
|
fluent::lint::suggestion,
|
||||||
"ty",
|
"ty",
|
||||||
Applicability::MaybeIncorrect, // ty maybe needs an import
|
Applicability::MaybeIncorrect, // ty maybe needs an import
|
||||||
)
|
)
|
||||||
|
@ -187,10 +187,10 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
|
||||||
if let QPath::TypeRelative(qpath_ty, ..) = qpath
|
if let QPath::TypeRelative(qpath_ty, ..) = qpath
|
||||||
&& qpath_ty.hir_id == ty.hir_id
|
&& qpath_ty.hir_id == ty.hir_id
|
||||||
{
|
{
|
||||||
lint.build("usage of `ty::TyKind::<kind>`")
|
lint.build(fluent::lint::tykind_kind)
|
||||||
.span_suggestion(
|
.span_suggestion(
|
||||||
path.span,
|
path.span,
|
||||||
"try using `ty::<kind>` directly",
|
fluent::lint::suggestion,
|
||||||
"ty",
|
"ty",
|
||||||
Applicability::MaybeIncorrect, // ty maybe needs an import
|
Applicability::MaybeIncorrect, // ty maybe needs an import
|
||||||
)
|
)
|
||||||
|
@ -207,10 +207,10 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
|
||||||
if let QPath::TypeRelative(qpath_ty, ..) = qpath
|
if let QPath::TypeRelative(qpath_ty, ..) = qpath
|
||||||
&& qpath_ty.hir_id == ty.hir_id
|
&& qpath_ty.hir_id == ty.hir_id
|
||||||
{
|
{
|
||||||
lint.build("usage of `ty::TyKind::<kind>`")
|
lint.build(fluent::lint::tykind_kind)
|
||||||
.span_suggestion(
|
.span_suggestion(
|
||||||
path.span,
|
path.span,
|
||||||
"try using `ty::<kind>` directly",
|
fluent::lint::suggestion,
|
||||||
"ty",
|
"ty",
|
||||||
Applicability::MaybeIncorrect, // ty maybe needs an import
|
Applicability::MaybeIncorrect, // ty maybe needs an import
|
||||||
)
|
)
|
||||||
|
@ -220,15 +220,16 @@ impl<'tcx> LateLintPass<'tcx> for TyTyKind {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
lint.build("usage of `ty::TyKind`").help("try using `Ty` instead").emit();
|
lint.build(fluent::lint::tykind).help(fluent::lint::help).emit();
|
||||||
})
|
})
|
||||||
} else if !ty.span.from_expansion() && let Some(t) = is_ty_or_ty_ctxt(cx, &path) {
|
} else if !ty.span.from_expansion() && let Some(t) = is_ty_or_ty_ctxt(cx, &path) {
|
||||||
if path.segments.len() > 1 {
|
if path.segments.len() > 1 {
|
||||||
cx.struct_span_lint(USAGE_OF_QUALIFIED_TY, path.span, |lint| {
|
cx.struct_span_lint(USAGE_OF_QUALIFIED_TY, path.span, |lint| {
|
||||||
lint.build(&format!("usage of qualified `ty::{}`", t))
|
lint.build(fluent::lint::ty_qualified)
|
||||||
|
.set_arg("ty", t.clone())
|
||||||
.span_suggestion(
|
.span_suggestion(
|
||||||
path.span,
|
path.span,
|
||||||
"try importing it and using it unqualified",
|
fluent::lint::suggestion,
|
||||||
t,
|
t,
|
||||||
// The import probably needs to be changed
|
// The import probably needs to be changed
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue