Skip to content

Commit 1ac9eb6

Browse files
committed
---
yaml --- r: 173871 b: refs/heads/auto c: de7b3cf h: refs/heads/master i: 173869: d8462f1 173867: cf1c2fb 173863: 6948b35 173855: 590703b v: v3
1 parent 1dfbe28 commit 1ac9eb6

File tree

4 files changed

+91
-1
lines changed

4 files changed

+91
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: a7025582cc9c89ee37e38bcdf94482b75cf37cd8
13+
refs/heads/auto: de7b3cf02e01be08863b712a666e24e7bfe8fca3
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2015 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+
//! Implementations checker: builtin traits and default impls are allowed just
12+
//! for structs and enums.
13+
14+
use middle::def;
15+
use middle::ty;
16+
use syntax::ast::{Item, ItemImpl};
17+
use syntax::ast;
18+
use syntax::ast_util;
19+
use syntax::visit;
20+
use util::ppaux::UserString;
21+
22+
pub fn check(tcx: &ty::ctxt) {
23+
let mut impls = ImplsChecker { tcx: tcx };
24+
visit::walk_crate(&mut impls, tcx.map.krate());
25+
}
26+
27+
struct ImplsChecker<'cx, 'tcx:'cx> {
28+
tcx: &'cx ty::ctxt<'tcx>
29+
}
30+
31+
impl<'cx, 'tcx,'v> visit::Visitor<'v> for ImplsChecker<'cx, 'tcx> {
32+
fn visit_item(&mut self, item: &'v ast::Item) {
33+
match item.node {
34+
ast::ItemImpl(_, _, _, Some(ref opt_trait), _, _) => {
35+
let trait_ref = ty::node_id_to_trait_ref(self.tcx, opt_trait.ref_id);
36+
if let Some(_) = self.tcx.lang_items.to_builtin_kind(trait_ref.def_id) {
37+
match trait_ref.self_ty().sty {
38+
ty::ty_struct(..) | ty::ty_enum(..) => {}
39+
_ => {
40+
self.tcx.sess.span_err(
41+
item.span,
42+
&format!("builtin traits can only be \
43+
implemented on structs or enums")[]);
44+
}
45+
}
46+
}
47+
}
48+
_ => {}
49+
}
50+
}
51+
}

branches/auto/src/librustc_typeck/coherence/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use syntax::visit;
4949
use util::nodemap::{DefIdMap, FnvHashMap};
5050
use util::ppaux::Repr;
5151

52+
mod impls;
5253
mod orphan;
5354
mod overlap;
5455
mod unsafety;
@@ -596,6 +597,7 @@ pub fn check_coherence(crate_context: &CrateCtxt) {
596597
inference_context: new_infer_ctxt(crate_context.tcx),
597598
inherent_impls: RefCell::new(FnvHashMap::new()),
598599
}.check(crate_context.tcx.map.krate());
600+
impls::check(crate_context.tcx);
599601
unsafety::check(crate_context.tcx);
600602
orphan::check(crate_context.tcx);
601603
overlap::check(crate_context.tcx);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2015 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+
use std::marker::Send;
12+
13+
enum TestE {
14+
A
15+
}
16+
17+
struct MyType;
18+
19+
unsafe impl Send for TestE {}
20+
unsafe impl Send for MyType {}
21+
unsafe impl Send for (MyType, MyType) {}
22+
//~^ ERROR builtin traits can only be implemented on structs or enums
23+
24+
unsafe impl Send for &'static MyType {}
25+
//~^ ERROR builtin traits can only be implemented on structs or enums
26+
27+
unsafe impl Send for [MyType] {}
28+
//~^ ERROR builtin traits can only be implemented on structs or enums
29+
30+
unsafe impl Send for &'static [MyType] {}
31+
//~^ ERROR builtin traits can only be implemented on structs or enums
32+
33+
fn is_send<T: Send>() {}
34+
35+
fn main() {
36+
is_send::<(MyType, TestE)>();
37+
}

0 commit comments

Comments
 (0)