Change:
If you pass an immutable reference through two structs, one of which is a trait, you can take an immutable reference to a variable that will be mutated later, and the compiler will compile. For a proof of concept, see , and if you want to see it in an actual use case, see (look in the main file). I don't know if this is an issue or not, it didn't cause any safety issues when I used it. Is there a rust-ier way of doing the type of thing I did in the second example (allow an immutable reference to a value that will be mutated, in order to see the new value).
The whole thing in one piece: Thanks for filing, these memory safety bugs are very important to catch, however, I think this may be a duplicate of another bug which I cannot find right now (iirc was interacting with those other bugs). I believe the underlying problem here is the function is invalid, the boxing/returning that happens should be disallowed without the having the lifetime too.
FWIW, I’ve reduced the issue a little more ():
Nominating
As I posted on IRC, this is a variance problem - is unsoundly bivariant:
Thanks for cutting it down. I still am not a good Rust programmer, so I was just copying, as close as I could, the original, accidental, version.
cc
P-backcompat-lang, 1.0.
seems to be dup of
I tested and this is indeed fixed by PR . Too bad I didn't look into this bug first rather than , since I see that other people already worked out the variance connection already.

Discussion:
variance); } <del> ty::ty_trait(box ty::TyTrait { def_id, ref substs, .. }) => { </del> <ins> ty::ty_trait(box ty::TyTrait { def_id, ref substs, bounds }) => { </ins> let trait_def = ty::lookup_trait_def(self.tcx(), def_id); let generics = &trait_def.generics;

assert!(generics.types.is_empty_in(subst::FnSpace)); assert!(generics.regions.is_empty_in(subst::FnSpace)); <ins> // The type `Foo<T+'a>` is contravariant w/r/t `'a`: let contra = self.contravariant(variance); self.add_constraints_from_region(bounds.region_bound, contra); </ins> self.add_constraints_from_substs( def_id, generics.types.get_slice(subst::TypeSpace),

<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. // Checks that regions which appear in a trait object type are // observed by the variance inference algorithm (and hence // `TOption` is contavariant w/r/t `'a` and not bivariant). // // Issue #18262. use std::mem; trait T { fn foo(); } #[rustc_variance] struct TOption<'a> { //~ ERROR regions=[[-];[];[]] v: Option<Box<T + 'a>>, } fn main() { } </ins>

} impl<'a, I, O: 'a> Parser<'a, I, O> { <del> fn compose<K: 'a>(mut self, mut rhs: Parser<O, K>) -> Parser<'a, I, K> { </del> <ins> fn compose<K: 'a>(mut self, mut rhs: Parser<'a, O, K>) -> Parser<'a, I, K> { </ins> Parser { parse: box move |&mut: x: I| { match self.parse.call_mut((x,)) {