Handle unrecognized type names in checking signature for mutable return type

This commit is contained in:
David Tolnay 2021-03-28 04:06:48 -04:00
parent e59625a9d4
commit 06ef96fa5f
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 16 additions and 6 deletions

View File

@ -521,7 +521,10 @@ fn check_mut_return_restriction(cx: &mut Check, efn: &ExternFn) {
if receiver.mutable {
return;
}
let resolve = cx.types.resolve(&receiver.ty);
let resolve = match cx.types.try_resolve(&receiver.ty) {
Some(resolve) => resolve,
None => return,
};
if !resolve.generics.lifetimes.is_empty() {
return;
}
@ -536,9 +539,11 @@ fn check_mut_return_restriction(cx: &mut Check, efn: &ExternFn) {
fn visit_type(&mut self, ty: &'t Type) {
self.found |= match ty {
Type::Ref(ty) => ty.mutable,
Type::Ident(ident) => {
let resolve = self.cx.types.resolve(ident);
!resolve.generics.lifetimes.is_empty()
Type::Ident(ident) if Atom::from(&ident.rust).is_none() => {
match self.cx.types.try_resolve(ident) {
Some(resolve) => !resolve.generics.lifetimes.is_empty(),
None => true,
}
}
_ => false,
};

View File

@ -11,11 +11,16 @@ pub struct Resolution<'a> {
impl<'a> Types<'a> {
pub fn resolve(&self, ident: &impl UnresolvedName) -> Resolution<'a> {
let ident = ident.ident();
match self.resolutions.get(ident) {
Some(resolution) => *resolution,
match self.try_resolve(ident) {
Some(resolution) => resolution,
None => panic!("Unable to resolve type `{}`", ident),
}
}
pub fn try_resolve(&self, ident: &impl UnresolvedName) -> Option<Resolution<'a>> {
let ident = ident.ident();
self.resolutions.get(ident).copied()
}
}
pub trait UnresolvedName {