Skip to content

Commit ed22606

Browse files
committed
auto merge of #20285 : FlaPer87/rust/oibit-send-and-friends, r=nikomatsakis
This commit introduces the syntax for negative implementations of traits as shown below: `impl !Trait for Type {}` cc #13231 Part of RFC rust-lang/rfcs#127 r? @nikomatsakis
2 parents ad9e759 + c062fac commit ed22606

File tree

35 files changed

+215
-39
lines changed

35 files changed

+215
-39
lines changed

src/librustc/lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1762,7 +1762,7 @@ impl LintPass for Stability {
17621762
}
17631763
}
17641764
}
1765-
ast::ItemImpl(_, _, Some(ref t), _, _) => {
1765+
ast::ItemImpl(_, _, _, Some(ref t), _, _) => {
17661766
let id = ty::trait_ref_to_def_id(cx.tcx, t);
17671767
self.lint(cx, id, t.path.span);
17681768
}

src/librustc/metadata/common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,3 +259,5 @@ pub const tag_unsafety: uint = 0xb1;
259259

260260
pub const tag_associated_type_names: uint = 0xb2;
261261
pub const tag_associated_type_name: uint = 0xb3;
262+
263+
pub const tag_polarity: uint = 0xb4;

src/librustc/metadata/encoder.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
12071207
None => {}
12081208
}
12091209
}
1210-
ast::ItemImpl(unsafety, _, ref opt_trait, ref ty, ref ast_items) => {
1210+
ast::ItemImpl(unsafety, polarity, _, ref opt_trait, ref ty, ref ast_items) => {
12111211
// We need to encode information about the default methods we
12121212
// have inherited, so we drive this based on the impl structure.
12131213
let impl_items = tcx.impl_items.borrow();
@@ -1221,6 +1221,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
12211221
encode_name(rbml_w, item.ident.name);
12221222
encode_attributes(rbml_w, item.attrs[]);
12231223
encode_unsafety(rbml_w, unsafety);
1224+
encode_polarity(rbml_w, polarity);
12241225
match ty.node {
12251226
ast::TyPath(ref path, _) if path.segments.len() == 1 => {
12261227
let ident = path.segments.last().unwrap().identifier;
@@ -1704,6 +1705,14 @@ fn encode_associated_type_names(rbml_w: &mut Encoder, names: &[ast::Name]) {
17041705
rbml_w.end_tag();
17051706
}
17061707

1708+
fn encode_polarity(rbml_w: &mut Encoder, polarity: ast::ImplPolarity) {
1709+
let byte: u8 = match polarity {
1710+
ast::ImplPolarity::Positive => 0,
1711+
ast::ImplPolarity::Negative => 1,
1712+
};
1713+
rbml_w.wr_tagged_u8(tag_polarity, byte);
1714+
}
1715+
17071716
fn encode_crate_deps(rbml_w: &mut Encoder, cstore: &cstore::CStore) {
17081717
fn get_ordered_deps(cstore: &cstore::CStore) -> Vec<decoder::CrateDep> {
17091718
// Pull the cnums and name,vers,hash out of cstore
@@ -1885,7 +1894,7 @@ struct ImplVisitor<'a, 'b:'a, 'c:'a, 'tcx:'b> {
18851894

18861895
impl<'a, 'b, 'c, 'tcx, 'v> Visitor<'v> for ImplVisitor<'a, 'b, 'c, 'tcx> {
18871896
fn visit_item(&mut self, item: &ast::Item) {
1888-
if let ast::ItemImpl(_, _, Some(ref trait_ref), _, _) = item.node {
1897+
if let ast::ItemImpl(_, _, _, Some(ref trait_ref), _, _) = item.node {
18891898
let def_map = &self.ecx.tcx.def_map;
18901899
let trait_def = def_map.borrow()[trait_ref.ref_id].clone();
18911900
let def_id = trait_def.def_id();

src/librustc/middle/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl<'v> Visitor<'v> for LifeSeeder {
355355
ast::ItemEnum(ref enum_def, _) if allow_dead_code => {
356356
self.worklist.extend(enum_def.variants.iter().map(|variant| variant.node.id));
357357
}
358-
ast::ItemImpl(_, _, Some(ref _trait_ref), _, ref impl_items) => {
358+
ast::ItemImpl(_, _, _, Some(ref _trait_ref), _, ref impl_items) => {
359359
for impl_item in impl_items.iter() {
360360
match *impl_item {
361361
ast::MethodImplItem(ref method) => {

src/librustc/middle/infer/error_reporting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,7 @@ fn lifetimes_in_scope(tcx: &ty::ctxt,
17121712
match tcx.map.find(parent) {
17131713
Some(node) => match node {
17141714
ast_map::NodeItem(item) => match item.node {
1715-
ast::ItemImpl(_, ref gen, _, _, _) => {
1715+
ast::ItemImpl(_, _, ref gen, _, _, _) => {
17161716
taken.push_all(gen.lifetimes.as_slice());
17171717
}
17181718
_ => ()

src/librustc/middle/privacy.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for EmbargoVisitor<'a, 'tcx> {
287287
// undefined symbols at linkage time if this case is not handled.
288288
//
289289
// * Private trait impls for private types can be completely ignored
290-
ast::ItemImpl(_, _, _, ref ty, ref impl_items) => {
290+
ast::ItemImpl(_, _, _, _, ref ty, ref impl_items) => {
291291
let public_ty = match ty.node {
292292
ast::TyPath(_, id) => {
293293
match self.tcx.def_map.borrow()[id].clone() {
@@ -657,7 +657,7 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
657657
// invoked, and the struct/enum itself is private. Crawl
658658
// back up the chains to find the relevant struct/enum that
659659
// was private.
660-
ast::ItemImpl(_, _, _, ref ty, _) => {
660+
ast::ItemImpl(_, _, _, _, ref ty, _) => {
661661
let id = match ty.node {
662662
ast::TyPath(_, id) => id,
663663
_ => return Some((err_span, err_msg, None)),
@@ -1137,7 +1137,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
11371137
match item.node {
11381138
// implementations of traits don't need visibility qualifiers because
11391139
// that's controlled by having the trait in scope.
1140-
ast::ItemImpl(_, _, Some(..), _, ref impl_items) => {
1140+
ast::ItemImpl(_, _, _, Some(..), _, ref impl_items) => {
11411141
check_inherited(item.span, item.vis,
11421142
"visibility qualifiers have no effect on trait \
11431143
impls");
@@ -1216,7 +1216,7 @@ impl<'a, 'tcx> SanePrivacyVisitor<'a, 'tcx> {
12161216
};
12171217
check_inherited(tcx, item.span, item.vis);
12181218
match item.node {
1219-
ast::ItemImpl(_, _, _, _, ref impl_items) => {
1219+
ast::ItemImpl(_, _, _, _, _, ref impl_items) => {
12201220
for impl_item in impl_items.iter() {
12211221
match *impl_item {
12221222
ast::MethodImplItem(ref m) => {
@@ -1361,7 +1361,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> {
13611361
// (i.e. we could just return here to not check them at
13621362
// all, or some worse estimation of whether an impl is
13631363
// publicly visible.
1364-
ast::ItemImpl(_, ref g, ref trait_ref, ref self_, ref impl_items) => {
1364+
ast::ItemImpl(_, _, ref g, ref trait_ref, ref self_, ref impl_items) => {
13651365
// `impl [... for] Private` is never visible.
13661366
let self_contains_private;
13671367
// impl [... for] Public<...>, but not `impl [... for]

src/librustc/middle/reachable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn item_might_be_inlined(item: &ast::Item) -> bool {
5555
}
5656

5757
match item.node {
58-
ast::ItemImpl(_, ref generics, _, _, _) |
58+
ast::ItemImpl(_, _, ref generics, _, _, _) |
5959
ast::ItemFn(_, _, _, ref generics, _) => {
6060
generics_require_inlining(generics)
6161
}
@@ -216,7 +216,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> {
216216
.map
217217
.expect_item(impl_did.node)
218218
.node {
219-
ast::ItemImpl(_, ref generics, _, _, _) => {
219+
ast::ItemImpl(_, _, ref generics, _, _, _) => {
220220
generics_require_inlining(generics)
221221
}
222222
_ => false

src/librustc/middle/resolve_lifetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<'a, 'v> Visitor<'v> for LifetimeContext<'a> {
106106
ast::ItemEnum(_, ref generics) |
107107
ast::ItemStruct(_, ref generics) |
108108
ast::ItemTrait(_, ref generics, _, _) |
109-
ast::ItemImpl(_, ref generics, _, _, _) => {
109+
ast::ItemImpl(_, _, ref generics, _, _, _) => {
110110
// These kinds of items have only early bound lifetime parameters.
111111
let lifetimes = &generics.lifetimes;
112112
let early_scope = EarlyScope(subst::TypeSpace, lifetimes, &ROOT_SCOPE);

src/librustc/middle/stability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'v> Visitor<'v> for Annotator {
8282
// stability of the trait. This is WRONG, but expedient to get
8383
// libstd stabilized for the 1.0 release.
8484
let use_parent = match i.node {
85-
ast::ItemImpl(_, _, Some(_), _, _) => false,
85+
ast::ItemImpl(_, _, _, Some(_), _, _) => false,
8686
_ => true,
8787
};
8888

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5127,7 +5127,7 @@ pub fn impl_trait_ref<'tcx>(cx: &ctxt<'tcx>, id: ast::DefId)
51275127
match cx.map.find(id.node) {
51285128
Some(ast_map::NodeItem(item)) => {
51295129
match item.node {
5130-
ast::ItemImpl(_, _, ref opt_trait, _, _) => {
5130+
ast::ItemImpl(_, _, _, ref opt_trait, _, _) => {
51315131
match opt_trait {
51325132
&Some(ref t) => {
51335133
let trait_ref = ty::node_id_to_trait_ref(cx, t.ref_id);

0 commit comments

Comments
 (0)