Skip to content

Commit 8ba6151

Browse files
committed
auto merge of #11246 : ktt3ja/rust/issue-11224, r=alexcrichton
Close #11224
2 parents a969510 + 576a851 commit 8ba6151

File tree

2 files changed

+60
-23
lines changed

2 files changed

+60
-23
lines changed

src/librustc/middle/dead.rs

+44-23
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ impl MarkSymbolVisitor {
6262
}
6363
}
6464

65+
fn check_def_id(&mut self, def_id: ast::DefId) {
66+
if should_explore(self.tcx, def_id) {
67+
self.worklist.push(def_id.node);
68+
}
69+
self.live_symbols.insert(def_id.node);
70+
}
71+
6572
fn lookup_and_handle_definition(&mut self, id: &ast::NodeId) {
6673
let def_map = self.tcx.def_map.borrow();
6774
let def = match def_map.get().find(id) {
@@ -74,13 +81,44 @@ impl MarkSymbolVisitor {
7481
_ => Some(def_id_of_def(def)),
7582
};
7683
match def_id {
77-
Some(def_id) => {
78-
if should_explore(self.tcx, def_id) {
79-
self.worklist.push(def_id.node);
84+
Some(def_id) => self.check_def_id(def_id),
85+
None => (),
86+
}
87+
}
88+
89+
fn lookup_and_handle_method(&mut self, id: &ast::NodeId,
90+
span: codemap::Span) {
91+
let method_map = self.method_map.borrow();
92+
match method_map.get().find(id) {
93+
Some(&typeck::method_map_entry { origin, .. }) => {
94+
match origin {
95+
typeck::method_static(def_id) => {
96+
match ty::provided_source(self.tcx, def_id) {
97+
Some(p_did) => self.check_def_id(p_did),
98+
None => self.check_def_id(def_id)
99+
}
100+
}
101+
typeck::method_param(typeck::method_param {
102+
trait_id: trait_id,
103+
method_num: index,
104+
..
105+
})
106+
| typeck::method_object(typeck::method_object {
107+
trait_id: trait_id,
108+
method_num: index,
109+
..
110+
}) => {
111+
let def_id = ty::trait_method(self.tcx,
112+
trait_id, index).def_id;
113+
self.check_def_id(def_id);
114+
}
80115
}
81-
self.live_symbols.insert(def_id.node);
82116
}
83-
None => (),
117+
None => {
118+
self.tcx.sess.span_bug(span,
119+
"method call expression not \
120+
in method map?!")
121+
}
84122
}
85123
}
86124

@@ -135,24 +173,7 @@ impl Visitor<()> for MarkSymbolVisitor {
135173
fn visit_expr(&mut self, expr: @ast::Expr, _: ()) {
136174
match expr.node {
137175
ast::ExprMethodCall(..) => {
138-
let method_map = self.method_map.borrow();
139-
match method_map.get().find(&expr.id) {
140-
Some(&typeck::method_map_entry {
141-
origin: typeck::method_static(def_id),
142-
..
143-
}) => {
144-
if should_explore(self.tcx, def_id) {
145-
self.worklist.push(def_id.node);
146-
}
147-
self.live_symbols.insert(def_id.node);
148-
}
149-
Some(_) => (),
150-
None => {
151-
self.tcx.sess.span_bug(expr.span,
152-
"method call expression not \
153-
in method map?!")
154-
}
155-
}
176+
self.lookup_and_handle_method(&expr.id, expr.span);
156177
}
157178
_ => ()
158179
}

src/test/compile-fail/lint-dead-code-3.rs

+16
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,19 @@ enum c_void {} //~ ERROR: code is never used
6464
extern {
6565
fn free(p: *c_void); //~ ERROR: code is never used
6666
}
67+
68+
// Check provided method
69+
mod inner {
70+
pub trait Trait {
71+
fn f(&self) { f(); }
72+
}
73+
74+
impl Trait for int {}
75+
76+
fn f() {}
77+
}
78+
79+
pub fn foo() {
80+
let a = &1 as &inner::Trait;
81+
a.f();
82+
}

0 commit comments

Comments
 (0)