Skip to content

Commit 36973f7

Browse files
committed
consider closures/ty-fn-defs when making trait selection keys
Fixes #42602.
1 parent f61bee3 commit 36973f7

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/librustc/ty/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,9 @@ impl<'tcx> TraitPredicate<'tcx> {
944944
self.input_types()
945945
.flat_map(|t| t.walk())
946946
.filter_map(|t| match t.sty {
947-
ty::TyAdt(adt_def, _) => Some(adt_def.did),
947+
ty::TyAdt(adt_def, ..) => Some(adt_def.did),
948+
ty::TyClosure(def_id, ..) => Some(def_id),
949+
ty::TyFnDef(def_id, ..) => Some(def_id),
948950
_ => None
949951
})
950952
.next()

src/test/incremental/issue-42602.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Regression test for #42602. It used to be that we had
12+
// a dep-graph like
13+
//
14+
// typeck(foo) -> FnOnce -> typeck(bar)
15+
//
16+
// This was fixed by improving the resolution of the `FnOnce` trait
17+
// selection node.
18+
19+
// revisions:cfail1
20+
// compile-flags:-Zquery-dep-graph
21+
22+
#![feature(rustc_attrs)]
23+
24+
fn main() {
25+
a::foo();
26+
b::bar();
27+
}
28+
29+
mod a {
30+
#[rustc_if_this_changed(HirBody)]
31+
pub fn foo() {
32+
let x = vec![1, 2, 3];
33+
let v = || ::std::mem::drop(x);
34+
v();
35+
}
36+
}
37+
38+
mod b {
39+
#[rustc_then_this_would_need(TypeckTables)] //[cfail1]~ ERROR no path
40+
pub fn bar() {
41+
let x = vec![1, 2, 3];
42+
let v = || ::std::mem::drop(x);
43+
v();
44+
}
45+
}

0 commit comments

Comments
 (0)