Skip to content

Commit 58abc44

Browse files
committed
Various small bits of cleanup.
1 parent a42950c commit 58abc44

File tree

5 files changed

+77
-73
lines changed

5 files changed

+77
-73
lines changed

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

+16-15
Original file line numberDiff line numberDiff line change
@@ -64,43 +64,45 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
6464
supplied_method_types: Vec<ty::t>)
6565
-> MethodCallee
6666
{
67-
//
67+
// Adjust the self expression the user provided and obtain the adjusted type.
6868
let self_ty = self.adjust_self_ty(unadjusted_self_ty, &pick.adjustment);
6969

70-
//
70+
// Make sure nobody calls `drop()` explicitly.
7171
self.enforce_drop_trait_limitations(&pick);
7272

73-
//
73+
// Create substitutions for the method's type parameters.
7474
let (rcvr_substs, method_origin) =
7575
self.fresh_receiver_substs(self_ty, &pick);
7676
let (method_types, method_regions) =
7777
self.instantiate_method_substs(&pick, supplied_method_types);
7878
let all_substs = rcvr_substs.with_method(method_types, method_regions);
7979
debug!("all_substs={}", all_substs.repr(self.tcx()));
8080

81-
//
81+
// Create the final signature for the method, replacing late-bound regions.
8282
let method_sig = self.instantiate_method_sig(&pick, &all_substs);
8383
let method_self_ty = method_sig.inputs[0];
8484

85-
//
85+
// Unify the (adjusted) self type with what the method expects.
8686
self.unify_receivers(self_ty, method_self_ty);
8787

88-
//
88+
// Add any trait/regions obligations specified on the method's type parameters.
8989
self.add_obligations(&pick, &all_substs);
9090

91-
//
91+
// Create the final `MethodCallee`.
9292
let fty = ty::mk_bare_fn(self.tcx(), ty::BareFnTy {
9393
sig: method_sig,
9494
fn_style: pick.method_ty.fty.fn_style,
9595
abi: pick.method_ty.fty.abi.clone(),
9696
});
97-
9897
let callee = MethodCallee {
9998
origin: method_origin,
10099
ty: fty,
101100
substs: all_substs
102101
};
103102

103+
// If this is an `&mut self` method, bias the receiver
104+
// expression towards mutability (this will switch
105+
// e.g. `Deref` to `DerefMut` in oveloaded derefs and so on).
104106
self.fixup_derefs_on_method_receiver_if_necessary(&callee);
105107

106108
callee
@@ -147,18 +149,17 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
147149
autoref: None
148150
}
149151
}
152+
probe::AutoUnsizeLength(autoderefs, len) => {
153+
ty::AutoDerefRef {
154+
autoderefs: autoderefs,
155+
autoref: Some(ty::AutoUnsize(ty::UnsizeLength(len)))
156+
}
157+
}
150158
probe::AutoRef(mutability, ref sub_adjustment) => {
151159
let deref = self.create_ty_adjustment(&**sub_adjustment);
152160
let region = self.infcx().next_region_var(infer::Autoref(self.span));
153161
wrap_autoref(deref, |base| ty::AutoPtr(region, mutability, base))
154162
}
155-
probe::AutoUnsizeLength(n, ref sub_adjustment) => {
156-
let deref = self.create_ty_adjustment(&**sub_adjustment);
157-
wrap_autoref(deref, |wrap| {
158-
assert!(wrap.is_none());
159-
ty::AutoUnsize(ty::UnsizeLength(n))
160-
})
161-
}
162163
}
163164
}
164165

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ might have two candidates:
110110
111111
Finally, to actually pick the method, we will search down the steps,
112112
trying to match the receiver type against the candidate types. At
113-
step, we also consider an auto-ref and auto-mut-ref to see whether
113+
each step, we also consider an auto-ref and auto-mut-ref to see whether
114114
that makes any of the candidates match. We pick the first step where
115115
we find a match.
116116

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

+31-40
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,12 @@ pub enum CandidateSource {
5353

5454
type MethodIndex = uint; // just for doc purposes
5555

56-
//struct CacheKey {
57-
// skol_self_ty: ty::t,
58-
// method_name: ast::Name,
59-
//}
60-
61-
pub fn exists(
62-
fcx: &FnCtxt,
63-
span: Span,
64-
method_name: ast::Name,
65-
self_ty: ty::t,
66-
call_expr_id: ast::NodeId)
67-
-> bool
56+
pub fn exists(fcx: &FnCtxt,
57+
span: Span,
58+
method_name: ast::Name,
59+
self_ty: ty::t,
60+
call_expr_id: ast::NodeId)
61+
-> bool
6862
{
6963
/*!
7064
* Determines whether the type `self_ty` supports a method name `method_name` or not.
@@ -77,15 +71,14 @@ pub fn exists(
7771
}
7872
}
7973

80-
pub fn lookup(
81-
fcx: &FnCtxt,
82-
span: Span,
83-
method_name: ast::Name,
84-
self_ty: ty::t,
85-
supplied_method_types: Vec<ty::t>,
86-
call_expr_id: ast::NodeId,
87-
self_expr: &ast::Expr)
88-
-> Result<MethodCallee, MethodError>
74+
pub fn lookup(fcx: &FnCtxt,
75+
span: Span,
76+
method_name: ast::Name,
77+
self_ty: ty::t,
78+
supplied_method_types: Vec<ty::t>,
79+
call_expr_id: ast::NodeId,
80+
self_expr: &ast::Expr)
81+
-> Result<MethodCallee, MethodError>
8982
{
9083
/*!
9184
* Performs method lookup. If lookup is successful, it will return the callee
@@ -114,31 +107,29 @@ pub fn lookup(
114107
Ok(confirm::confirm(fcx, span, self_expr, self_ty, pick, supplied_method_types))
115108
}
116109

117-
pub fn lookup_in_trait<'a, 'tcx>(
118-
fcx: &'a FnCtxt<'a, 'tcx>,
119-
span: Span,
120-
self_expr: Option<&'a ast::Expr>,
121-
m_name: ast::Name,
122-
trait_def_id: DefId,
123-
self_ty: ty::t,
124-
opt_input_types: Option<Vec<ty::t>>)
125-
-> Option<MethodCallee>
110+
pub fn lookup_in_trait<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>,
111+
span: Span,
112+
self_expr: Option<&'a ast::Expr>,
113+
m_name: ast::Name,
114+
trait_def_id: DefId,
115+
self_ty: ty::t,
116+
opt_input_types: Option<Vec<ty::t>>)
117+
-> Option<MethodCallee>
126118
{
127119
lookup_in_trait_adjusted(fcx, span, self_expr, m_name, trait_def_id,
128120
ty::AutoDerefRef { autoderefs: 0, autoref: None },
129121
self_ty, opt_input_types)
130122
}
131123

132-
pub fn lookup_in_trait_adjusted<'a, 'tcx>(
133-
fcx: &'a FnCtxt<'a, 'tcx>,
134-
span: Span,
135-
self_expr: Option<&'a ast::Expr>,
136-
m_name: ast::Name,
137-
trait_def_id: DefId,
138-
autoderefref: ty::AutoDerefRef,
139-
self_ty: ty::t,
140-
opt_input_types: Option<Vec<ty::t>>)
141-
-> Option<MethodCallee>
124+
pub fn lookup_in_trait_adjusted<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>,
125+
span: Span,
126+
self_expr: Option<&'a ast::Expr>,
127+
m_name: ast::Name,
128+
trait_def_id: DefId,
129+
autoderefref: ty::AutoDerefRef,
130+
self_ty: ty::t,
131+
opt_input_types: Option<Vec<ty::t>>)
132+
-> Option<MethodCallee>
142133
{
143134
debug!("lookup_in_trait_adjusted(self_ty={}, self_expr={}, m_name={}, trait_def_id={})",
144135
self_ty.repr(fcx.tcx()),

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

+25-13
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,30 @@ pub type PickResult = Result<Pick, MethodError>;
8484
// needed.
8585
#[deriving(Clone,Show)]
8686
pub enum PickAdjustment {
87-
AutoDeref(/* number of autoderefs */ uint), // A = expr, *expr, **expr
88-
AutoRef(ast::Mutability, Box<PickAdjustment>), // A = &A | &mut A
89-
AutoUnsizeLength(uint, Box<PickAdjustment>), // [T, ..n] => [T]
87+
// Indicates that the source expression should be autoderef'd N times
88+
//
89+
// A = expr | *expr | **expr
90+
AutoDeref(uint),
91+
92+
// Indicates that the source expression should be autoderef'd N
93+
// times and then "unsized". This should probably eventually go
94+
// away in favor of just coercing method receivers.
95+
//
96+
// A = unsize(expr | *expr | **expr)
97+
AutoUnsizeLength(/* number of autoderefs */ uint, /* length*/ uint),
98+
99+
// Indicates that an autoref is applied after some number of other adjustments
100+
//
101+
// A = &A | &mut A
102+
AutoRef(ast::Mutability, Box<PickAdjustment>),
90103
}
91104

92-
pub fn probe(
93-
fcx: &FnCtxt,
94-
span: Span,
95-
method_name: ast::Name,
96-
self_ty: ty::t,
97-
call_expr_id: ast::NodeId)
98-
-> PickResult
105+
pub fn probe(fcx: &FnCtxt,
106+
span: Span,
107+
method_name: ast::Name,
108+
self_ty: ty::t,
109+
call_expr_id: ast::NodeId)
110+
-> PickResult
99111
{
100112
debug!("probe(self_ty={}, method_name={}, call_expr_id={})",
101113
self_ty.repr(fcx.tcx()),
@@ -143,7 +155,7 @@ fn create_steps(fcx: &FnCtxt, span: Span, self_ty: ty::t) -> Vec<CandidateStep>
143155
ty::ty_vec(elem_ty, Some(len)) => {
144156
steps.push(CandidateStep {
145157
self_ty: ty::mk_vec(fcx.tcx(), elem_ty, None),
146-
adjustment: AutoUnsizeLength(len, box AutoDeref(dereferences))
158+
adjustment: AutoUnsizeLength(dereferences, len),
147159
});
148160
}
149161
_ => {
@@ -609,8 +621,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
609621
}
610622

611623
fn pick_autorefrefd_method(&mut self,
612-
step: &CandidateStep)
613-
-> Option<PickResult>
624+
step: &CandidateStep)
625+
-> Option<PickResult>
614626
{
615627
let tcx = self.tcx();
616628
self.search_mutabilities(

src/test/compile-fail/method-ambig-one-trait-coerce.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ impl foo for Box<Object+Send> {
2727
}
2828

2929
fn test1(x: Box<Object+Send+Sync>) {
30-
// FIXME -- we ought to consider this to be ambiguous, since
31-
// we could coerce to either impl. However, what actually
30+
// FIXME(#18737) -- we ought to consider this to be ambiguous,
31+
// since we could coerce to either impl. However, what actually
3232
// happens is that we consider both impls applicable because of
33-
// incorrect subtyping relation. We then decide to call this
34-
// a call to the `foo` trait, leading to the following error
33+
// incorrect subtyping relation. We then decide to call this a
34+
// call to the `foo` trait, leading to the following error
3535
// message.
3636

3737
x.foo(); //~ ERROR `foo` is not implemented

0 commit comments

Comments
 (0)