/// let x = vec![2, 3, 5];
/// let last_element = x.last();
/// ```
+ #[clippy::version = "1.37.0"]
pub GET_LAST_WITH_LEN,
complexity,
"Using `x.get(x.len() - 1)` when `x.last()` is correct and simpler"
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
if_chain! {
// Is a method call
- if let ExprKind::MethodCall(path, _, args, _) = expr.kind;
+ if let ExprKind::MethodCall(path, args, _) = expr.kind;
// Method name is "get"
if path.ident.name == sym!(get);
// Argument 0 (the struct we're calling the method on) is a vector
if let Some(struct_calling_on) = args.get(0);
let struct_ty = cx.typeck_results().expr_ty(struct_calling_on);
- if is_type_diagnostic_item(cx, struct_ty, sym::vec_type);
+ if is_type_diagnostic_item(cx, struct_ty, sym::Vec);
// Argument to "get" is a subtraction
if let Some(get_index_arg) = args.get(1);
) = &get_index_arg.kind;
// LHS of subtraction is "x.len()"
- if let ExprKind::MethodCall(arg_lhs_path, _, lhs_args, _) = &lhs.kind;
+ if let ExprKind::MethodCall(arg_lhs_path, lhs_args, _) = &lhs.kind;
if arg_lhs_path.ident.name == sym::len;
if let Some(arg_lhs_struct) = lhs_args.get(0);