提交 63f51ee9 编写于 作者: N Niko Matsakis 提交者: Alex Crichton

Exempt phantom fns from the object safety check

上级 d6e939a2
......@@ -138,10 +138,11 @@ fn supertraits_reference_self<'tcx>(tcx: &ty::ctxt<'tcx>,
match predicate {
ty::Predicate::Trait(ref data) => {
// In the case of a trait predicate, we can skip the "self" type.
data.0.trait_ref.substs.types.get_slice(TypeSpace)
.iter()
.cloned()
.any(is_self)
Some(data.def_id()) != tcx.lang_items.phantom_fn() &&
data.0.trait_ref.substs.types.get_slice(TypeSpace)
.iter()
.cloned()
.any(is_self)
}
ty::Predicate::Projection(..) |
ty::Predicate::TypeOutlives(..) |
......
// Copyright 2014 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.
// Check that `Self` appearing in a phantom fn does not make a trait not object safe.
#![feature(rustc_attrs)]
trait Baz : PhantomFn<Self> {
}
fn make_bar<T:Bar<u32>>(t: &T) -> &Bar<u32> {
t
}
fn make_baz<T:Baz>(t: &T) -> &Baz {
t
}
#[rustc_error]
fn main() { //~ ERROR compilation successful
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册