Skip to content

Commit 3adb755

Browse files
committed
Rebasing fixes
1 parent 5dd1bc3 commit 3adb755

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

src/librustc/middle/typeck/check/method.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -619,14 +619,11 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
619619

620620
let tcx = self.tcx();
621621

622-
// It is illegal to create a trait object with methods which includes
623-
// the Self type. An error will be reported when we coerce to a trait
624-
// object if the method refers to the `Self` type. Substituting ty_err
625-
// here allows compiler to soldier on.
626-
//
627-
// `confirm_candidate()` also relies upon this substitution
628-
// for Self. (fix)
629-
let rcvr_substs = substs.with_self_ty(ty::mk_err());
622+
// It is illegal to invoke a method on a trait instance that refers to
623+
// the `Self` type. Here, we use a substitution that replaces `Self`
624+
// with the object type itself. Hence, a `&self` method will wind up
625+
// with an argument type like `&Trait`.
626+
let rcvr_substs = substs.with_self_ty(self_ty);
630627

631628
let trait_ref = Rc::new(TraitRef {
632629
def_id: did,
@@ -1337,6 +1334,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
13371334
self.ty_to_string(rcvr_ty),
13381335
candidate.repr(self.tcx()));
13391336

1337+
let rcvr_substs = candidate.rcvr_substs.clone();
13401338
self.enforce_drop_trait_limitations(candidate);
13411339

13421340
// Determine the values for the generic parameters of the method.

src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16871687
self.register_unsize_obligations(span, &**u)
16881688
}
16891689
ty::UnsizeVtable(ref ty_trait, self_ty) => {
1690-
vtable2::check_object_safety(self.tcx(), ty_trait, span);
1690+
vtable::check_object_safety(self.tcx(), ty_trait, span);
16911691
// If the type is `Foo+'a`, ensures that the type
16921692
// being cast to `Foo+'a` implements `Foo`:
16931693
vtable::register_object_cast_obligations(self,

src/librustc/middle/typeck/check/vtable.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub fn check_object_safety(tcx: &ty::ctxt, object_trait: &ty::TyTrait, span: Spa
179179
*/
180180
let mut msgs = Vec::new();
181181

182-
let method_name = method.ident.repr(tcx);
182+
let method_name = method.name.repr(tcx);
183183

184184
match method.explicit_self {
185185
ty::ByValueExplicitSelfCategory => { // reason (a) above
@@ -204,12 +204,18 @@ pub fn check_object_safety(tcx: &ty::ctxt, object_trait: &ty::TyTrait, span: Spa
204204
}
205205
};
206206
let ref sig = method.fty.sig;
207-
for &input_ty in sig.inputs.tail().iter().chain([sig.output].iter()) {
207+
for &input_ty in sig.inputs[1..].iter() {
208208
match check_for_self_ty(input_ty) {
209209
Some(msg) => msgs.push(msg),
210210
_ => {}
211211
}
212212
}
213+
if let ty::FnConverging(result_type) = sig.output {
214+
match check_for_self_ty(result_type) {
215+
Some(msg) => msgs.push(msg),
216+
_ => {}
217+
}
218+
}
213219

214220
if method.generics.has_type_params(FnSpace) {
215221
// reason (b) above

src/test/compile-fail/region-object-lifetime-in-coercion.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,27 @@
1111
// Test that attempts to implicitly coerce a value into an
1212
// object respect the lifetime bound on the object type.
1313

14-
fn a(v: &[u8]) -> Box<Clone + 'static> {
15-
let x: Box<Clone + 'static> = box v; //~ ERROR does not outlive
14+
trait Foo {}
15+
impl<'a> Foo for &'a [u8] {}
16+
17+
fn a(v: &[u8]) -> Box<Foo + 'static> {
18+
let x: Box<Foo + 'static> = box v; //~ ERROR does not outlive
1619
x
1720
}
1821

19-
fn b(v: &[u8]) -> Box<Clone + 'static> {
22+
fn b(v: &[u8]) -> Box<Foo + 'static> {
2023
box v //~ ERROR does not outlive
2124
}
2225

23-
fn c(v: &[u8]) -> Box<Clone> {
26+
fn c(v: &[u8]) -> Box<Foo> {
2427
box v // OK thanks to lifetime elision
2528
}
2629

27-
fn d<'a,'b>(v: &'a [u8]) -> Box<Clone+'b> {
30+
fn d<'a,'b>(v: &'a [u8]) -> Box<Foo+'b> {
2831
box v //~ ERROR does not outlive
2932
}
3033

31-
fn e<'a:'b,'b>(v: &'a [u8]) -> Box<Clone+'b> {
34+
fn e<'a:'b,'b>(v: &'a [u8]) -> Box<Foo+'b> {
3235
box v // OK, thanks to 'a:'b
3336
}
3437

0 commit comments

Comments
 (0)