cxx_build/syntax/
resolve.rs

1use crate::syntax::attrs::OtherAttrs;
2use crate::syntax::{Lifetimes, NamedType, Pair, Types};
3use proc_macro2::Ident;
4
5#[derive(#[automatically_derived]
impl<'a> ::core::marker::Copy for Resolution<'a> { }Copy, #[automatically_derived]
impl<'a> ::core::clone::Clone for Resolution<'a> {
    #[inline]
    fn clone(&self) -> Resolution<'a> {
        let _: ::core::clone::AssertParamIsClone<&'a Pair>;
        let _: ::core::clone::AssertParamIsClone<&'a OtherAttrs>;
        let _: ::core::clone::AssertParamIsClone<&'a Lifetimes>;
        *self
    }
}Clone)]
6pub(crate) struct Resolution<'a> {
7    pub name: &'a Pair,
8    #[cfg_attr(not(proc_macro), expect(dead_code))]
9    pub attrs: &'a OtherAttrs,
10    pub generics: &'a Lifetimes,
11}
12
13impl<'a> Types<'a> {
14    pub(crate) fn resolve(&self, ident: &impl UnresolvedName) -> Resolution<'a> {
15        let ident = ident.ident();
16        match self.try_resolve(ident) {
17            Some(resolution) => resolution,
18            None => {
    ::core::panicking::panic_fmt(format_args!("Unable to resolve type `{0}`",
            ident));
}panic!("Unable to resolve type `{}`", ident),
19        }
20    }
21
22    pub(crate) fn try_resolve(&self, ident: &impl UnresolvedName) -> Option<Resolution<'a>> {
23        let ident = ident.ident();
24        self.resolutions.get(ident).copied()
25    }
26}
27
28pub(crate) trait UnresolvedName {
29    fn ident(&self) -> &Ident;
30}
31
32impl UnresolvedName for Ident {
33    fn ident(&self) -> &Ident {
34        self
35    }
36}
37
38impl UnresolvedName for NamedType {
39    fn ident(&self) -> &Ident {
40        &self.rust
41    }
42}