Skip to content

Commit 5eea7d6

Browse files
committed
don't infer region paramaterization for ids in a bound context
1 parent 8922264 commit 5eea7d6

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

src/rustc/middle/region.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,21 @@ impl determine_rp_ctxt {
518518
}
519519
}
520520

521+
// For named types like Foo, if there is no explicit region
522+
// parameter, then we will add the anonymous region, so there is
523+
// a dependency if the anonymous region implies rp.
524+
//
525+
// If the region is explicitly specified, then we follows the
526+
// normal rules.
527+
fn opt_region_is_relevant(opt_r: option<@ast::region>) -> bool {
528+
debug!("opt_region_is_relevant: %? (anon_implies_rp=%b)",
529+
opt_r, self.anon_implies_rp);
530+
match opt_r {
531+
none => self.anon_implies_rp,
532+
some(r) => self.region_is_relevant(r)
533+
}
534+
}
535+
521536
fn with(item_id: ast::node_id,
522537
anon_implies_rp: bool,
523538
f: fn()) {
@@ -613,19 +628,23 @@ fn determine_rp_in_ty(ty: @ast::ty,
613628
// then check whether it is region-parameterized and consider
614629
// that as a direct dependency.
615630
match ty.node {
616-
ast::ty_path(_, id) => {
631+
ast::ty_path(path, id) => {
617632
match cx.def_map.get(id) {
618633
ast::def_ty(did) | ast::def_class(did, _) => {
619634
if did.crate == ast::local_crate {
620-
cx.add_dep(did.node);
635+
if cx.opt_region_is_relevant(path.rp) {
636+
cx.add_dep(did.node);
637+
}
621638
} else {
622639
let cstore = cx.sess.cstore;
623640
match csearch::get_region_param(cstore, did) {
624641
none => {}
625642
some(variance) => {
626643
debug!("reference to external, rp'd type %s",
627644
pprust::ty_to_str(ty, cx.sess.intr()));
628-
cx.add_rp(cx.item_id, cx.add_variance(variance))
645+
if cx.opt_region_is_relevant(path.rp) {
646+
cx.add_rp(cx.item_id, cx.add_variance(variance))
647+
}
629648
}
630649
}
631650
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
struct direct {
2+
f: &int;
3+
}
4+
5+
struct indirect1 {
6+
g: fn@(direct);
7+
}
8+
9+
struct indirect2 {
10+
g: fn@(direct/&);
11+
}
12+
13+
struct indirect3 {
14+
g: fn@(direct/&self);
15+
}
16+
17+
fn take_direct(p: direct) -> direct { p } //~ ERROR mismatched types
18+
fn take_indirect1(p: indirect1) -> indirect1 { p }
19+
fn take_indirect2(p: indirect2) -> indirect2 { p }
20+
fn take_indirect3(p: indirect3) -> indirect3 { p } //~ ERROR mismatched types
21+
fn main() {}

0 commit comments

Comments
 (0)