Skip to content

Commit

Permalink
ty::TyKind::X -> ty::X
Browse files Browse the repository at this point in the history
  • Loading branch information
y21 committed Jun 16, 2023
1 parent 5662d71 commit 488e52b
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions clippy_lints/src/methods/read_line_without_trim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,15 @@ use rustc_hir::Expr;
use rustc_hir::QPath;
use rustc_hir::{def::Res, ExprKind};
use rustc_lint::LateContext;
use rustc_middle::ty::{Ty, TyKind};
use rustc_middle::ty::{self, Ty};
use rustc_span::sym;

use super::READ_LINE_WITHOUT_TRIM;

/// Will a `.parse::<ty>()` call fail if the input has a trailing newline?
fn parse_fails_on_trailing_newline(ty: Ty<'_>) -> bool {
// only allow a very limited set of types for now, for which we 100% know parsing will fail
matches!(
ty.kind(),
TyKind::Float(_) | TyKind::Bool | TyKind::Int(_) | TyKind::Uint(_)
)
matches!(ty.kind(), ty::Float(_) | ty::Bool | ty::Int(_) | ty::Uint(_))
}

pub fn check(cx: &LateContext<'_>, call: &Expr<'_>, recv: &Expr<'_>, arg: &Expr<'_>) {
Expand All @@ -38,7 +35,7 @@ pub fn check(cx: &LateContext<'_>, call: &Expr<'_>, recv: &Expr<'_>, arg: &Expr<
&& segment.ident.name == sym!(parse)
&& let parse_result_ty = cx.typeck_results().expr_ty(parent)
&& is_type_diagnostic_item(cx, parse_result_ty, sym::Result)
&& let TyKind::Adt(_, substs) = parse_result_ty.kind()
&& let ty::Adt(_, substs) = parse_result_ty.kind()
&& let Some(ok_ty) = substs[0].as_type()
&& parse_fails_on_trailing_newline(ok_ty)
{
Expand Down

0 comments on commit 488e52b

Please sign in to comment.