From 4f542f9e4fd3a78018194cd3438a14da6f90a9d2 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Sun, 25 Dec 2016 19:38:45 +0200 Subject: [PATCH] traits with self-containing supertraits are not object safe This should be the last time I fix this function. Fixes #38404. --- src/librustc/traits/object_safety.rs | 6 ++++-- src/test/compile-fail/issue-38404.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/issue-38404.rs diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index 0d5c9b98941..df87d624e3a 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -81,8 +81,10 @@ pub fn astconv_object_safety_violations(self, trait_def_id: DefId) { let mut violations = vec![]; - if self.supertraits_reference_self(trait_def_id) { - violations.push(ObjectSafetyViolation::SupertraitSelf); + for def_id in traits::supertrait_def_ids(self, trait_def_id) { + if self.supertraits_reference_self(def_id) { + violations.push(ObjectSafetyViolation::SupertraitSelf); + } } debug!("astconv_object_safety_violations(trait_def_id={:?}) = {:?}", diff --git a/src/test/compile-fail/issue-38404.rs b/src/test/compile-fail/issue-38404.rs new file mode 100644 index 00000000000..a2b0d0a60c0 --- /dev/null +++ b/src/test/compile-fail/issue-38404.rs @@ -0,0 +1,16 @@ +// Copyright 2016 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait A: std::ops::Add + Sized {} +trait B: A {} +trait C: A> {} +//~^ ERROR the trait `B` cannot be made into an object + +fn main() {} -- GitLab