diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-02-18 19:35:20 -0500 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-02-18 16:38:17 -0800 |
| commit | 63f51ee90ccc1b7ab3a749ba7dbd4a3c76961c16 (patch) | |
| tree | 71f351d8cd5cafcda0c0474969b9a1e5c0a02eb1 | |
| parent | d6e939a2df16338e9cf63ad19d1025a15069387c (diff) | |
| download | rust-63f51ee90ccc1b7ab3a749ba7dbd4a3c76961c16.tar.gz rust-63f51ee90ccc1b7ab3a749ba7dbd4a3c76961c16.zip | |
Exempt phantom fns from the object safety check
| -rw-r--r-- | src/librustc/middle/traits/object_safety.rs | 9 | ||||
| -rw-r--r-- | src/test/compile-fail/object-safety-phantom-fn.rs | 28 |
2 files changed, 33 insertions, 4 deletions
diff --git a/src/librustc/middle/traits/object_safety.rs b/src/librustc/middle/traits/object_safety.rs index a8f8d54cba9..f10f7eb3951 100644 --- a/src/librustc/middle/traits/object_safety.rs +++ b/src/librustc/middle/traits/object_safety.rs @@ -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(..) | diff --git a/src/test/compile-fail/object-safety-phantom-fn.rs b/src/test/compile-fail/object-safety-phantom-fn.rs new file mode 100644 index 00000000000..fb30ce5c245 --- /dev/null +++ b/src/test/compile-fail/object-safety-phantom-fn.rs @@ -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 +} |
