Exempt phantom fns from the object safety check
This commit is contained in:
parent
d6e939a2df
commit
63f51ee90c
@ -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(..) |
|
||||
|
28
src/test/compile-fail/object-safety-phantom-fn.rs
Normal file
28
src/test/compile-fail/object-safety-phantom-fn.rs
Normal file
@ -0,0 +1,28 @@
|
||||
// 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
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user