diff options
Diffstat (limited to 'compiler/rustc_lint/src')
| -rw-r--r-- | compiler/rustc_lint/src/internal.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_lint/src/unused.rs | 18 |
2 files changed, 14 insertions, 14 deletions
diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 3a8c8e79b4f..e8fcf4132ea 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -379,13 +379,15 @@ impl LateLintPass<'_> for Diagnostics { _ => return, // occurs for fns passed as args } } - ExprKind::MethodCall(segment, _recv, args, _span) => { - let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap(); - let fn_gen_args = cx.typeck_results().node_args(expr.hir_id); + ExprKind::MethodCall(_segment, _recv, args, _span) => { + let Some((span, def_id, fn_gen_args)) = typeck_results_of_method_fn(cx, expr) + else { + return; + }; let mut call_tys: Vec<_> = args.iter().map(|arg| cx.typeck_results().expr_ty(arg)).collect(); call_tys.insert(0, cx.tcx.types.self_param); // dummy inserted for `self` - (segment.ident.span, def_id, fn_gen_args, call_tys) + (span, def_id, fn_gen_args, call_tys) } _ => return, }; diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 3481c66da70..f84d1c6c2d0 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -20,6 +20,7 @@ use rustc_span::symbol::Symbol; use rustc_span::symbol::{kw, sym}; use rustc_span::{BytePos, Span}; use std::iter; +use std::ops::ControlFlow; declare_lint! { /// The `unused_must_use` lint detects unused result of a type flagged as @@ -753,21 +754,18 @@ trait UnusedDelimLint { // fn f(){(print!(รก // ``` use rustc_ast::visit::{walk_expr, Visitor}; - struct ErrExprVisitor { - has_error: bool, - } + struct ErrExprVisitor; impl<'ast> Visitor<'ast> for ErrExprVisitor { - fn visit_expr(&mut self, expr: &'ast ast::Expr) { + type Result = ControlFlow<()>; + fn visit_expr(&mut self, expr: &'ast ast::Expr) -> ControlFlow<()> { if let ExprKind::Err(_) = expr.kind { - self.has_error = true; - return; + ControlFlow::Break(()) + } else { + walk_expr(self, expr) } - walk_expr(self, expr) } } - let mut visitor = ErrExprVisitor { has_error: false }; - visitor.visit_expr(value); - if visitor.has_error { + if ErrExprVisitor.visit_expr(value).is_break() { return; } let spans = match value.kind { |
