Skip to content

Commit fdac78b

Browse files
committed
Rebasing fixes
1 parent f16acf8 commit fdac78b

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

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

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

600600
let tcx = self.tcx();
601601

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

611608
let trait_ref = Rc::new(TraitRef {
612609
def_id: did,
@@ -1317,6 +1314,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> {
13171314
self.ty_to_string(rcvr_ty),
13181315
candidate.repr(self.tcx()));
13191316

1317+
let rcvr_substs = candidate.rcvr_substs.clone();
13201318
self.enforce_drop_trait_limitations(candidate);
13211319

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

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

Lines changed: 1 addition & 1 deletion
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

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)