self.associated_item can return none

self.associated_item can return none, replace unwrap with '?' and bubble up None value instead of panicking
This commit is contained in:
jsirs 2018-11-05 14:37:36 +02:00 committed by GitHub
parent 2a1dc1eff6
commit 4a08333c4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -290,7 +290,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// type parameters or early-bound regions.
let tcx = self.tcx;
let method_item =
self.associated_item(trait_def_id, m_name, Namespace::Value).unwrap();
self.associated_item(trait_def_id, m_name, Namespace::Value)?;
let def_id = method_item.def_id;
let generics = tcx.generics_of(def_id);
assert_eq!(generics.params.len(), 0);