提交 adcdd605 编写于 作者: S Sean Griffin 提交者: Corey Farwell

Put overlapping impls behind feature gate, add tests

I've added some explicit tests that negative impls are allowed to
overlap, and also to make sure that the feature doesn't interfere with
specialization. I've not added an explicit test for positive overlapping
with negative, as that's already tested elsewhere.
上级 c81c958e
......@@ -2230,6 +2230,9 @@ pub fn impl_trait_ref(self, id: DefId) -> Option<TraitRef<'gcx>> {
/// Returns true if the impls are the same polarity and are implementing
/// a trait which contains no items
pub fn impls_are_allowed_to_overlap(self, def_id1: DefId, def_id2: DefId) -> bool {
if !self.sess.features.borrow().overlapping_marker_traits {
return false;
}
let trait1_is_empty = self.impl_trait_ref(def_id1)
.map_or(false, |trait_ref| {
self.associated_item_def_ids(trait_ref.def_id).is_empty()
......
......@@ -349,6 +349,9 @@ pub fn new() -> Features {
// Allows module-level inline assembly by way of global_asm!()
(active, global_asm, "1.18.0", Some(35119)),
// Allows overlapping impls of marker traits
(active, overlapping_marker_traits, "1.18.0", Some(29864)),
);
declare_features! (
......
......@@ -9,6 +9,7 @@
// except according to those terms.
#![feature(optin_builtin_traits)]
#![feature(overlapping_marker_traits)]
trait MyTrait {}
......
......@@ -9,6 +9,7 @@
// except according to those terms.
#![feature(optin_builtin_traits)]
#![feature(overlapping_marker_traits)]
use std::marker::Copy;
......
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait MyMarker {}
impl<T> MyMarker for T {}
impl<T> MyMarker for Vec<T> {}
//~^ ERROR E0119
fn main() {}
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(overlapping_marker_traits)]
#![feature(specialization)]
trait MyMarker {}
impl<T> MyMarker for T {}
impl<T> MyMarker for Vec<T> {}
fn foo<T: MyMarker>(t: T) -> T {
t
}
fn main() {
assert_eq!(1, foo(1));
assert_eq!(2.0, foo(2.0));
assert_eq!(vec![1], foo(vec![1]));
}
......@@ -8,11 +8,18 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(overlapping_marker_traits)]
#![feature(optin_builtin_traits)]
trait MyMarker {}
impl<T: Copy> MyMarker for T {}
impl<T: Eq> MyMarker for T {}
struct MyStruct;
impl !Send for MyStruct {}
impl !Send for MyStruct {}
fn foo<T: MyMarker>(t: T) -> T {
t
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册