Skip to content

Commit aa642b3

Browse files
committed
addressed comments
1 parent 038aa0e commit aa642b3

File tree

8 files changed

+45
-78
lines changed

8 files changed

+45
-78
lines changed

src/librustc/middle/traits/select.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -2231,17 +2231,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
22312231
fn all_impls(&self, trait_def_id: ast::DefId) -> Vec<ast::DefId> {
22322232
ty::populate_implementations_for_trait_if_necessary(self.tcx(), trait_def_id);
22332233

2234-
let mut trait_impls = match self.tcx().trait_impls.borrow().get(&trait_def_id) {
2234+
match self.tcx().trait_impls.borrow().get(&trait_def_id) {
22352235
None => Vec::new(),
22362236
Some(impls) => impls.borrow().clone()
2237-
};
2238-
2239-
match self.tcx().trait_negative_impls.borrow().get(&trait_def_id) {
2240-
None => {},
2241-
Some(impls) => trait_impls.push_all(impls.borrow().as_slice()),
2242-
};
2243-
2244-
trait_impls
2237+
}
22452238
}
22462239

22472240
fn impl_obligations(&mut self,

src/librustc/middle/ty.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,6 @@ pub struct ctxt<'tcx> {
750750
/// Maps a trait onto a list of impls of that trait.
751751
pub trait_impls: RefCell<DefIdMap<Rc<RefCell<Vec<ast::DefId>>>>>,
752752

753-
/// Maps a trait onto a list of negative impls of that trait.
754-
pub trait_negative_impls: RefCell<DefIdMap<Rc<RefCell<Vec<ast::DefId>>>>>,
755-
756753
/// Maps a DefId of a type to a list of its inherent impls.
757754
/// Contains implementations of methods that are inherent to a type.
758755
/// Methods in these implementations don't need to be exported.
@@ -1894,7 +1891,7 @@ pub type PolyTypeOutlivesPredicate<'tcx> = PolyOutlivesPredicate<Ty<'tcx>, ty::R
18941891
/// normal trait predicate (`T : TraitRef<...>`) and one of these
18951892
/// predicates. Form #2 is a broader form in that it also permits
18961893
/// equality between arbitrary types. Processing an instance of Form
1897-
/// \#2 eventually yields one of these `ProjectionPredicate`
1894+
/// #2 eventually yields one of these `ProjectionPredicate`
18981895
/// instances to normalize the LHS.
18991896
#[derive(Clone, PartialEq, Eq, Hash, Show)]
19001897
pub struct ProjectionPredicate<'tcx> {
@@ -2415,7 +2412,6 @@ pub fn mk_ctxt<'tcx>(s: Session,
24152412
destructor_for_type: RefCell::new(DefIdMap::new()),
24162413
destructors: RefCell::new(DefIdSet::new()),
24172414
trait_impls: RefCell::new(DefIdMap::new()),
2418-
trait_negative_impls: RefCell::new(DefIdMap::new()),
24192415
inherent_impls: RefCell::new(DefIdMap::new()),
24202416
impl_items: RefCell::new(DefIdMap::new()),
24212417
used_unsafe: RefCell::new(NodeSet::new()),
@@ -6006,22 +6002,15 @@ pub fn record_trait_implementation(tcx: &ctxt,
60066002
trait_def_id: DefId,
60076003
impl_def_id: DefId) {
60086004

6009-
let trait_impls = match trait_impl_polarity(tcx, impl_def_id) {
6010-
Some(ast::ImplPolarity::Positive) => &tcx.trait_impls,
6011-
Some(ast::ImplPolarity::Negative) => &tcx.trait_negative_impls,
6012-
_ => tcx.sess.bug(&format!("tried to record a non-impl item with id {:?}",
6013-
impl_def_id)[])
6014-
};
6015-
6016-
match trait_impls.borrow().get(&trait_def_id) {
6005+
match tcx.trait_impls.borrow().get(&trait_def_id) {
60176006
Some(impls_for_trait) => {
60186007
impls_for_trait.borrow_mut().push(impl_def_id);
60196008
return;
60206009
}
60216010
None => {}
60226011
}
60236012

6024-
trait_impls.borrow_mut().insert(trait_def_id, Rc::new(RefCell::new(vec!(impl_def_id))));
6013+
tcx.trait_impls.borrow_mut().insert(trait_def_id, Rc::new(RefCell::new(vec!(impl_def_id))));
60256014
}
60266015

60276016
/// Populates the type context with all the implementations for the given type

src/librustc_typeck/coherence/overlap.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,7 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> {
3939
// check can populate this table further with impls from other
4040
// crates.
4141
let trait_def_ids: Vec<(ast::DefId, Vec<ast::DefId>)> =
42-
self.tcx.trait_impls.borrow().iter().map(|(&k, v)| {
43-
let mut impls = v.borrow().clone();
44-
if let Some(neg_impls) = self.tcx.trait_negative_impls.borrow().get(&k) {
45-
impls.push_all(neg_impls.borrow().as_slice());
46-
}
47-
(k, impls)
48-
}).collect();
42+
self.tcx.trait_impls.borrow().iter().map(|(&k, v)| (k, v.borrow().clone())).collect();
4943

5044
for &(trait_def_id, ref impls) in trait_def_ids.iter() {
5145
self.check_for_overlapping_impls_of_trait(trait_def_id, impls);

src/test/compile-fail/coherence-conflicting-negative-trait-impl.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,20 @@
1010

1111
#![feature(optin_builtin_traits)]
1212

13-
struct TestType;
13+
trait MyTrait {}
1414

15-
unsafe impl Send for TestType {}
15+
struct TestType<T>;
16+
17+
unsafe impl<T: MyTrait> Send for TestType<T> {}
18+
//~^ ERROR conflicting implementations for trait `core::marker::Send`
19+
//~^^ ERROR conflicting implementations for trait `core::marker::Send`
20+
21+
impl<T: MyTrait> !Send for TestType<T> {}
1622
//~^ ERROR conflicting implementations for trait `core::marker::Send`
1723

18-
impl !Send for TestType {}
24+
unsafe impl<T> Send for TestType<T> {}
25+
//~^ ERROR error: conflicting implementations for trait `core::marker::Send`
26+
27+
impl !Send for TestType<i32> {}
1928

2029
fn main() {}

src/test/compile-fail/coherence-orphan.rs

+6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// ignore-tidy-linelength
1112
// aux-build:coherence-orphan-lib.rs
1213

14+
#![feature(optin_builtin_traits)]
15+
1316
extern crate "coherence-orphan-lib" as lib;
1417

1518
use lib::TheTrait;
@@ -22,4 +25,7 @@ impl TheTrait<TheType> for isize { } //~ ERROR E0117
2225

2326
impl TheTrait<isize> for TheType { }
2427

28+
impl !Send for Vec<isize> { } //~ ERROR E0117
29+
//~^ ERROR conflicting
30+
2531
fn main() { }

src/test/compile-fail/marker-no-send.rs

-22
This file was deleted.

src/test/compile-fail/marker-no-share.rs

-22
This file was deleted.

src/test/compile-fail/traits-negative-impls.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// The dummy functions are used to avoid adding new cfail files.
12+
// What happens is that the compiler attempts to squash duplicates and some
13+
// errors are not reported. This way, we make sure that, for each function, different
14+
// typeck phases are involved and all errors are reported.
15+
1116
#![feature(optin_builtin_traits)]
1217

1318
use std::marker::Send;
@@ -24,13 +29,28 @@ unsafe impl<T: Send> Sync for Outer2<T> {}
2429
fn is_send<T: Send>(_: T) {}
2530
fn is_sync<T: Sync>(_: T) {}
2631

27-
fn main() {
32+
fn dummy() {
2833
Outer(TestType);
2934
//~^ ERROR the trait `core::marker::Send` is not implemented for the type `TestType`
3035

3136
is_send(TestType);
3237
//~^ ERROR the trait `core::marker::Send` is not implemented for the type `TestType`
3338

39+
is_send((8, TestType));
40+
//~^ ERROR the trait `core::marker::Send` is not implemented for the type `TestType`
41+
}
42+
43+
fn dummy2() {
44+
is_send(Box::new(TestType));
45+
//~^ ERROR the trait `core::marker::Send` is not implemented for the type `TestType`
46+
}
47+
48+
fn dummy3() {
49+
is_send(Box::new(Outer2(TestType)));
50+
//~^ ERROR the trait `core::marker::Send` is not implemented for the type `TestType`
51+
}
52+
53+
fn main() {
3454
// This will complain about a missing Send impl because `Sync` is implement *just*
3555
// for T that are `Send`. Look at #20366 and #19950
3656
is_sync(Outer2(TestType));

0 commit comments

Comments
 (0)