Skip to content

Commit 19c7885

Browse files
committed
Auto merge of #3570 - muth:master, r=phansch
panic at map_unit_fn.rs:202 for map() without args map_unit_fn.rs accessed map() arguments before type check which ensures type is Option or Result. Boiled it down to a simple test case. FWIW: Found this panic when running clippy against code which used a gtk::Window's map() fn inherited from gtk::WidgetExt http://gtk-rs.org/docs/gtk/trait.WidgetExt.html#tymethod.map
2 parents d3c747c + d395d45 commit 19c7885

File tree

3 files changed

+21
-211
lines changed

3 files changed

+21
-211
lines changed

clippy_lints/src/map_unit_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ fn suggestion_msg(function_type: &str, map_type: &str) -> String {
199199

200200
fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr, map_args: &[hir::Expr]) {
201201
let var_arg = &map_args[0];
202-
let fn_arg = &map_args[1];
203202

204203
let (map_type, variant, lint) = if match_type(cx, cx.tables.expr_ty(var_arg), &paths::OPTION) {
205204
("Option", "Some", OPTION_MAP_UNIT_FN)
@@ -208,6 +207,7 @@ fn lint_map_unit_fn(cx: &LateContext<'_, '_>, stmt: &hir::Stmt, expr: &hir::Expr
208207
} else {
209208
return;
210209
};
210+
let fn_arg = &map_args[1];
211211

212212
if is_unit_function(cx, fn_arg) {
213213
let msg = suggestion_msg("function", map_type);

tests/ui/map_unit_fn.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution.
3+
//
4+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7+
// option. This file may not be copied, modified, or distributed
8+
// except according to those terms.
9+
10+
#![allow(unused)]
11+
struct Mappable {}
12+
13+
impl Mappable {
14+
pub fn map(&self) {}
15+
}
16+
17+
fn main() {
18+
let m = Mappable {};
19+
m.map();
20+
}

tests/ui/map_unit_fn.stderr

-210
This file was deleted.

0 commit comments

Comments
 (0)