Skip to content

Commit aeba2cc

Browse files
committed
Adjust orphan rules to consider all input types, not just self type.
Fixes #18222.
1 parent 3d2cf60 commit aeba2cc

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

src/librustc/middle/traits/coherence.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ pub fn impl_is_local(tcx: &ty::ctxt,
6767
return true;
6868
}
6969

70-
// Otherwise, self type must be local to the crate.
71-
let self_ty = ty::lookup_item_type(tcx, impl_def_id).ty;
72-
return ty_is_local(tcx, self_ty);
70+
// Otherwise, at least one of the input types must be local to the
71+
// crate.
72+
trait_ref.input_types().iter().any(|&t| ty_is_local(tcx, t))
7373
}
7474

7575
pub fn ty_is_local(tcx: &ty::ctxt,
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2014 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+
pub trait TheTrait<T> {
12+
fn the_fn(&self);
13+
}
14+
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2014 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+
// aux-build:coherence-orphan-lib.rs
12+
13+
extern crate "coherence-orphan-lib" as lib;
14+
15+
use lib::TheTrait;
16+
17+
struct TheType;
18+
19+
impl TheTrait<uint> for int { } //~ ERROR E0117
20+
21+
impl TheTrait<TheType> for int { }
22+
23+
impl TheTrait<int> for TheType { }
24+
25+
fn main() { }

0 commit comments

Comments
 (0)