Skip to content

Commit 88d5b2f

Browse files
committed
Refactor mod/check (part vi)
1 parent c9941a8 commit 88d5b2f

File tree

1 file changed

+7
-49
lines changed
  • src/librustc_typeck/check

1 file changed

+7
-49
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4937,46 +4937,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
49374937
_ => {}
49384938
}
49394939

4940-
let mut type_segment = None;
4941-
let mut fn_segment = None;
4942-
match def {
4943-
// Case 1. Reference to a struct/variant constructor.
4944-
Def::StructCtor(def_id, ..) |
4945-
Def::VariantCtor(def_id, ..) => {
4946-
// Everything but the final segment should have no
4947-
// parameters at all.
4948-
let mut generics = self.tcx.generics_of(def_id);
4949-
if let Some(def_id) = generics.parent {
4950-
// Variant and struct constructors use the
4951-
// generics of their parent type definition.
4952-
generics = self.tcx.generics_of(def_id);
4953-
}
4954-
type_segment = Some((segments.last().unwrap(), generics));
4955-
}
4956-
4957-
// Case 2. Reference to a top-level value.
4958-
Def::Fn(def_id) |
4959-
Def::Const(def_id) |
4960-
Def::Static(def_id, _) => {
4961-
fn_segment = Some((segments.last().unwrap(), self.tcx.generics_of(def_id)));
4962-
}
4963-
4964-
// Case 3. Reference to a method or associated const.
4965-
Def::Method(def_id) |
4966-
Def::AssociatedConst(def_id) => {
4967-
let generics = self.tcx.generics_of(def_id);
4968-
if segments.len() >= 2 {
4969-
let parent_generics = self.tcx.generics_of(generics.parent.unwrap());
4970-
type_segment = Some((&segments[segments.len() - 2], parent_generics));
4971-
}
4972-
fn_segment = Some((segments.last().unwrap(), generics));
4973-
}
4974-
4975-
_ => {}
4976-
}
4977-
4978-
debug!("type_segment={:?} fn_segment={:?}", type_segment, fn_segment);
4979-
49804940
// Now we have to compare the types that the user *actually*
49814941
// provided against the types that were *expected*. If the user
49824942
// did not provide any types, then we want to substitute inference
@@ -5004,14 +4964,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
50044964
}).unwrap_or(false);
50054965

50064966
let def_id = def.def_id();
5007-
let defs = self.tcx.generics_of(def_id);
5008-
let count = defs.count();
4967+
let mut parent_defs = self.tcx.generics_of(def_id);
4968+
let count = parent_defs.count();
50094969
let mut substs = if count <= 8 {
50104970
AccumulateVec::Array(ArrayVec::new())
50114971
} else {
50124972
AccumulateVec::Heap(Vec::with_capacity(count))
50134973
};
5014-
let mut parent_defs = defs;
50154974
let mut stack = vec![(def_id, parent_defs)];
50164975
while let Some(def_id) = parent_defs.parent {
50174976
parent_defs = self.tcx.generics_of(def_id);
@@ -5030,7 +4989,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
50304989

50314990
let infer_types = if let Some(&PathSeg(_, index)) = path_segs
50324991
.iter()
5033-
.find(|&PathSeg(di, _)| *di == def_id) {
4992+
.find(|&PathSeg(did, _)| *did == def_id) {
50344993

50354994
if let Some(ref data) = segments[index].args {
50364995
let lifetime_offset = if infer_lifetimes[&index] {
@@ -5048,7 +5007,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
50485007
_ => bug!("expected a lifetime arg"),
50495008
}
50505009
GenericParamDefKind::Type { .. } => match arg {
5051-
// A provided type parameter.
50525010
GenericArg::Type(ty) => self.to_ty(ty).into(),
50535011
_ => bug!("expected a type arg"),
50545012
}
@@ -5088,15 +5046,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
50885046

50895047
// The things we are substituting into the type should not contain
50905048
// escaping late-bound regions, and nor should the base type scheme.
5091-
let ty = self.tcx.type_of(def.def_id());
5049+
let ty = self.tcx.type_of(def_id);
50925050
assert!(!substs.has_escaping_regions());
50935051
assert!(!ty.has_escaping_regions());
50945052

50955053
// Add all the obligations that are required, substituting and
50965054
// normalized appropriately.
5097-
let bounds = self.instantiate_bounds(span, def.def_id(), &substs);
5055+
let bounds = self.instantiate_bounds(span, def_id, &substs);
50985056
self.add_obligations_for_parameters(
5099-
traits::ObligationCause::new(span, self.body_id, traits::ItemObligation(def.def_id())),
5057+
traits::ObligationCause::new(span, self.body_id, traits::ItemObligation(def_id)),
51005058
&bounds);
51015059

51025060
// Substitute the values for the type parameters into the type of
@@ -5122,7 +5080,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
51225080
}
51235081
}
51245082

5125-
self.check_rustc_args_require_const(def.def_id(), node_id, span);
5083+
self.check_rustc_args_require_const(def_id, node_id, span);
51265084

51275085
debug!("instantiate_value_path: type of {:?} is {:?}",
51285086
node_id,

0 commit comments

Comments
 (0)