Change:
The following code either aborts or segfaults for me, depending on if I'm in gdb or not, on Linux: With optimizations, becomes Which means we're doing something very bad when translating this code.
Still reducing...
FWIW, I can confirm that behaviour on Windows.
cc me
Reduced: And that makes it clear the issue is not broken codegen, but rather that is mistakenly treated as object-safe (while it inherits from the non-object-safe ).
nice. cc
P-backcompat-lang, 1.0.
Hint: iterate with
takes/creates s but needs a . I'm not sure how to make these agree.
checkobjectsafety should use to enumerate the trait_ref, I think. Annoyingly this does require a right now (harder to fix than you might think).
On I get , which is an unwrap in in the supertraits iterator.

Discussion:
self.register_unsize_obligations(span, &**u) } ty::UnsizeVtable(ref ty_trait, self_ty) => { <del> vtable::check_object_safety(self.tcx(), ty_trait, span); </del> <ins> vtable::check_object_safety(self.tcx(), &ty_trait.principal, span); </ins> // If the type is `Foo+'a`, ensures that the type // being cast to `Foo+'a` implements `Foo`: vtable::register_object_cast_obligations(self,

// Ensure that if ~T is cast to ~Trait, then T : Trait push_cast_obligation(fcx, cast_expr, object_trait, referent_ty); <del> check_object_safety(fcx.tcx(), object_trait, source_expr.span); </del> <ins> check_object_safety(fcx.tcx(), &object_trait.principal, source_expr.span); </ins> } (&ty::ty_rptr(referent_region, ty::mt { ty: referent_ty,

target_region, referent_region); <del> check_object_safety(fcx.tcx(), object_trait, source_expr.span); </del> <ins> check_object_safety(fcx.tcx(), &object_trait.principal, source_expr.span); </ins> } }

// self by value, has no type parameters and does not use the `Self` type, except // in self position. pub fn check_object_safety<'tcx>(tcx: &ty::ctxt<'tcx>, <del> object_trait: &ty::TyTrait<'tcx>, </del> <ins> object_trait: &ty::TraitRef<'tcx>, span: Span) { let mut object = object_trait.clone(); if object.substs.types.len(SelfSpace) == 0 { object.substs.types.push(SelfSpace, ty::mk_err()); } let object = Rc::new(object); for tr in traits::supertraits(tcx, object) { check_object_safety_inner(tcx, &*tr, span); } } fn check_object_safety_inner<'tcx>(tcx: &ty::ctxt<'tcx>, object_trait: &ty::TraitRef<'tcx>, </ins> span: Span) { // Skip the fn_once lang item trait since only the compiler should call // `call_once` which is the method which takes self by value. What could go // wrong? match tcx.lang_items.fn_once_trait() { <del> Some(def_id) if def_id == object_trait.principal.def_id => return, </del> <ins> Some(def_id) if def_id == object_trait.def_id => return, </ins> _ => {} } <del> let trait_items = ty::trait_items(tcx, object_trait.principal.def_id); </del> <ins> let trait_items = ty::trait_items(tcx, object_trait.def_id); </ins> let mut errors = Vec::new(); for item in trait_items.iter() {

let mut errors = errors.iter().flat_map(|x| x.iter()).peekable(); if errors.peek().is_some() { <del> let trait_name = ty::item_path_str(tcx, object_trait.principal.def_id); </del> <ins> let trait_name = ty::item_path_str(tcx, object_trait.def_id); </ins> span_err!(tcx.sess, span, E0038, "cannot convert to a trait object because trait `{}` is not object-safe", trait_name);

<ins> // 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. pub trait Foo for Sized? { fn foo<T>(&self, ext_thing: &T); } pub trait Bar for Sized?: Foo { } impl<T: Foo> Bar for T { } pub struct Thing; impl Foo for Thing { fn foo<T>(&self, _: &T) {} } #[inline(never)] fn foo(b: &Bar) { b.foo(&0u) } fn main() { let mut thing = Thing; let test: &Bar = &mut thing; //~ ERROR cannot convert to a trait object because trait `Foo` foo(test); } </ins>