diff options
| author | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2018-10-13 11:32:49 +0200 |
|---|---|---|
| committer | Oliver Scherer <github35764891676564198441@oli-obk.de> | 2018-10-13 11:32:49 +0200 |
| commit | 78aaa3e5468f7e23267659b99b20f9ef33cdad44 (patch) | |
| tree | e4d6a050aa415464cc47a30c33076c6b3071cf6c /src/librustc/ty | |
| parent | 849a0e9c40ef79efec0802334fe10406ea3e7256 (diff) | |
| download | rust-78aaa3e5468f7e23267659b99b20f9ef33cdad44.tar.gz rust-78aaa3e5468f7e23267659b99b20f9ef33cdad44.zip | |
Check the invariant for `principal` inside the method
Diffstat (limited to 'src/librustc/ty')
| -rw-r--r-- | src/librustc/ty/error.rs | 3 | ||||
| -rw-r--r-- | src/librustc/ty/fast_reject.rs | 2 | ||||
| -rw-r--r-- | src/librustc/ty/item_path.rs | 2 | ||||
| -rw-r--r-- | src/librustc/ty/sty.rs | 16 | ||||
| -rw-r--r-- | src/librustc/ty/wf.rs | 2 |
5 files changed, 11 insertions, 14 deletions
diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index 3123f0fbe31..d886d5ed204 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -208,8 +208,7 @@ impl<'a, 'gcx, 'lcx, 'tcx> ty::TyS<'tcx> { ty::FnDef(..) => "fn item".into(), ty::FnPtr(_) => "fn pointer".into(), ty::Dynamic(ref inner, ..) => { - inner.principal().map_or_else(|| "trait".into(), - |p| format!("trait {}", tcx.item_path_str(p.def_id())).into()) + format!("trait {}", tcx.item_path_str(inner.principal().def_id())).into() } ty::Closure(..) => "closure".into(), ty::Generator(..) => "generator".into(), diff --git a/src/librustc/ty/fast_reject.rs b/src/librustc/ty/fast_reject.rs index 0f68e7aba4d..e6aaf8b1bb2 100644 --- a/src/librustc/ty/fast_reject.rs +++ b/src/librustc/ty/fast_reject.rs @@ -78,7 +78,7 @@ pub fn simplify_type<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, ty::Array(..) | ty::Slice(_) => Some(ArraySimplifiedType), ty::RawPtr(_) => Some(PtrSimplifiedType), ty::Dynamic(ref trait_info, ..) => { - trait_info.principal().map(|p| TraitSimplifiedType(p.def_id())) + Some(TraitSimplifiedType(trait_info.principal().def_id())) } ty::Ref(_, ty, _) => { // since we introduce auto-refs during method lookup, we diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index ab081324036..c4a25971da3 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -436,7 +436,7 @@ pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> { match ty.sty { ty::Adt(adt_def, _) => Some(adt_def.did), - ty::Dynamic(data, ..) => data.principal().map(|p| p.def_id()), + ty::Dynamic(data, ..) => Some(data.principal().def_id()), ty::Array(subty, _) | ty::Slice(subty) => characteristic_def_id_of_type(subty), diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 145c122e75d..cc6e6b2861e 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -559,10 +559,10 @@ impl<'a, 'gcx, 'tcx> Binder<ExistentialPredicate<'tcx>> { impl<'tcx> serialize::UseSpecializedDecodable for &'tcx List<ExistentialPredicate<'tcx>> {} impl<'tcx> List<ExistentialPredicate<'tcx>> { - pub fn principal(&self) -> Option<ExistentialTraitRef<'tcx>> { - match self.get(0) { - Some(&ExistentialPredicate::Trait(tr)) => Some(tr), - _ => None, + pub fn principal(&self) -> ExistentialTraitRef<'tcx> { + match self[0] { + ExistentialPredicate::Trait(tr) => tr, + other => bug!("first predicate is {:?}", other), } } @@ -589,8 +589,8 @@ impl<'tcx> List<ExistentialPredicate<'tcx>> { } impl<'tcx> Binder<&'tcx List<ExistentialPredicate<'tcx>>> { - pub fn principal(&self) -> Option<PolyExistentialTraitRef<'tcx>> { - self.skip_binder().principal().map(Binder::bind) + pub fn principal(&self) -> PolyExistentialTraitRef<'tcx> { + Binder::bind(self.skip_binder().principal()) } #[inline] @@ -1825,9 +1825,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> { } Dynamic(ref obj, region) => { let mut v = vec![region]; - if let Some(p) = obj.principal() { - v.extend(p.skip_binder().substs.regions()); - } + v.extend(obj.principal().skip_binder().substs.regions()); v } Adt(_, substs) | Opaque(_, substs) => { diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index 7af838845cd..27747970f76 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -387,7 +387,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { let cause = self.cause(traits::MiscObligation); let component_traits = - data.auto_traits().chain(data.principal().map(|p| p.def_id())); + data.auto_traits().chain(once(data.principal().def_id())); self.out.extend( component_traits.map(|did| traits::Obligation::new( cause.clone(), |
