Skip to content

Commit

Permalink
Run rustfmt on librustc_typeck/check/ folder
Browse files Browse the repository at this point in the history
  • Loading branch information
srinivasreddy committed Oct 7, 2016
1 parent 75c155b commit 4ef3f59
Show file tree
Hide file tree
Showing 7 changed files with 633 additions and 603 deletions.
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/assoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
// except according to those terms.

use rustc::infer::InferCtxt;
use rustc::traits::{self, FulfillmentContext, Normalized, MiscObligation,
SelectionContext, ObligationCause};
use rustc::traits::{self, FulfillmentContext, Normalized, MiscObligation, SelectionContext,
ObligationCause};
use rustc::ty::fold::TypeFoldable;
use syntax::ast;
use syntax_pos::Span;

//FIXME(@jroesch): Ideally we should be able to drop the fulfillment_cx argument.
// FIXME(@jroesch): Ideally we should be able to drop the fulfillment_cx argument.
pub fn normalize_associated_types_in<'a, 'gcx, 'tcx, T>(
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
fulfillment_cx: &mut FulfillmentContext<'tcx>,
Expand Down
109 changes: 61 additions & 48 deletions src/librustc_typeck/check/autoderef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use syntax::parse::token;
#[derive(Copy, Clone, Debug)]
enum AutoderefKind {
Builtin,
Overloaded
Overloaded,
}

pub struct Autoderef<'a, 'gcx: 'tcx, 'tcx: 'a> {
Expand All @@ -35,7 +35,7 @@ pub struct Autoderef<'a, 'gcx: 'tcx, 'tcx: 'a> {
cur_ty: Ty<'tcx>,
obligations: Vec<traits::PredicateObligation<'tcx>>,
at_start: bool,
span: Span
span: Span,
}

impl<'a, 'gcx, 'tcx> Iterator for Autoderef<'a, 'gcx, 'tcx> {
Expand All @@ -45,7 +45,8 @@ impl<'a, 'gcx, 'tcx> Iterator for Autoderef<'a, 'gcx, 'tcx> {
let tcx = self.fcx.tcx;

debug!("autoderef: steps={:?}, cur_ty={:?}",
self.steps, self.cur_ty);
self.steps,
self.cur_ty);
if self.at_start {
self.at_start = false;
debug!("autoderef stage #0 is {:?}", self.cur_ty);
Expand All @@ -54,11 +55,13 @@ impl<'a, 'gcx, 'tcx> Iterator for Autoderef<'a, 'gcx, 'tcx> {

if self.steps.len() == tcx.sess.recursion_limit.get() {
// We've reached the recursion limit, error gracefully.
struct_span_err!(tcx.sess, self.span, E0055,
"reached the recursion limit while auto-dereferencing {:?}",
self.cur_ty)
.span_label(self.span, &format!("deref recursion limit reached"))
.emit();
struct_span_err!(tcx.sess,
self.span,
E0055,
"reached the recursion limit while auto-dereferencing {:?}",
self.cur_ty)
.span_label(self.span, &format!("deref recursion limit reached"))
.emit();
return None;
}

Expand All @@ -72,7 +75,7 @@ impl<'a, 'gcx, 'tcx> Iterator for Autoderef<'a, 'gcx, 'tcx> {
} else {
match self.overloaded_deref_ty(self.cur_ty) {
Some(ty) => (AutoderefKind::Overloaded, ty),
_ => return None
_ => return None,
}
};

Expand All @@ -81,8 +84,10 @@ impl<'a, 'gcx, 'tcx> Iterator for Autoderef<'a, 'gcx, 'tcx> {
}

self.steps.push((self.cur_ty, kind));
debug!("autoderef stage #{:?} is {:?} from {:?}", self.steps.len(),
new_ty, (self.cur_ty, kind));
debug!("autoderef stage #{:?} is {:?} from {:?}",
self.steps.len(),
new_ty,
(self.cur_ty, kind));
self.cur_ty = new_ty;

Some((self.cur_ty, self.steps.len()))
Expand All @@ -99,9 +104,9 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
let trait_ref = TraitRef {
def_id: match tcx.lang_items.deref_trait() {
Some(f) => f,
None => return None
None => return None,
},
substs: Substs::new_trait(tcx, self.cur_ty, &[])
substs: Substs::new_trait(tcx, self.cur_ty, &[]),
};

let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
Expand All @@ -113,15 +118,13 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
return None;
}

let normalized = traits::normalize_projection_type(
&mut selcx,
ty::ProjectionTy {
trait_ref: trait_ref,
item_name: token::intern("Target")
},
cause,
0
);
let normalized = traits::normalize_projection_type(&mut selcx,
ty::ProjectionTy {
trait_ref: trait_ref,
item_name: token::intern("Target"),
},
cause,
0);

debug!("overloaded_deref_ty({:?}) = {:?}", ty, normalized);
self.obligations.extend(normalized.obligations);
Expand All @@ -134,17 +137,23 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
}

pub fn finalize<'b, I>(self, pref: LvaluePreference, exprs: I)
where I: IntoIterator<Item=&'b hir::Expr>
where I: IntoIterator<Item = &'b hir::Expr>
{
let methods : Vec<_> = self.steps.iter().map(|&(ty, kind)| {
if let AutoderefKind::Overloaded = kind {
self.fcx.try_overloaded_deref(self.span, None, ty, pref)
} else {
None
}
}).collect();
let methods: Vec<_> = self.steps
.iter()
.map(|&(ty, kind)| {
if let AutoderefKind::Overloaded = kind {
self.fcx.try_overloaded_deref(self.span, None, ty, pref)
} else {
None
}
})
.collect();

debug!("finalize({:?}) - {:?},{:?}", pref, methods, self.obligations);
debug!("finalize({:?}) - {:?},{:?}",
pref,
methods,
self.obligations);

for expr in exprs {
debug!("finalize - finalizing #{} - {:?}", expr.id, expr);
Expand All @@ -163,18 +172,14 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
}

impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
pub fn autoderef(&'a self,
span: Span,
base_ty: Ty<'tcx>)
-> Autoderef<'a, 'gcx, 'tcx>
{
pub fn autoderef(&'a self, span: Span, base_ty: Ty<'tcx>) -> Autoderef<'a, 'gcx, 'tcx> {
Autoderef {
fcx: self,
steps: vec![],
cur_ty: self.resolve_type_vars_if_possible(&base_ty),
obligations: vec![],
at_start: true,
span: span
span: span,
}
}

Expand All @@ -183,28 +188,36 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
base_expr: Option<&hir::Expr>,
base_ty: Ty<'tcx>,
lvalue_pref: LvaluePreference)
-> Option<MethodCallee<'tcx>>
{
-> Option<MethodCallee<'tcx>> {
debug!("try_overloaded_deref({:?},{:?},{:?},{:?})",
span, base_expr, base_ty, lvalue_pref);
span,
base_expr,
base_ty,
lvalue_pref);
// Try DerefMut first, if preferred.
let method = match (lvalue_pref, self.tcx.lang_items.deref_mut_trait()) {
(PreferMutLvalue, Some(trait_did)) => {
self.lookup_method_in_trait(span, base_expr,
token::intern("deref_mut"), trait_did,
base_ty, None)
self.lookup_method_in_trait(span,
base_expr,
token::intern("deref_mut"),
trait_did,
base_ty,
None)
}
_ => None
_ => None,
};

// Otherwise, fall back to Deref.
let method = match (method, self.tcx.lang_items.deref_trait()) {
(None, Some(trait_did)) => {
self.lookup_method_in_trait(span, base_expr,
token::intern("deref"), trait_did,
base_ty, None)
self.lookup_method_in_trait(span,
base_expr,
token::intern("deref"),
trait_did,
base_ty,
None)
}
(method, _) => method
(method, _) => method,
};

method
Expand Down
Loading

0 comments on commit 4ef3f59

Please sign in to comment.