Skip to main content

rustc_hir/attrs/
diagnostic.rs

1//! Contains the data structures used by the diagnostic attribute family.
2use std::fmt;
3use std::fmt::Debug;
4
5pub use rustc_ast::attr::data_structures::*;
6use rustc_macros::{Decodable, Encodable, PrintAttribute, StableHash};
7use rustc_span::{DesugaringKind, Span, Symbol, kw};
8use thin_vec::ThinVec;
9use tracing::debug;
10
11use crate::attrs::PrintAttribute;
12
13#[derive(#[automatically_derived]
impl ::core::clone::Clone for Directive {
    #[inline]
    fn clone(&self) -> Directive {
        Directive {
            is_rustc_attr: ::core::clone::Clone::clone(&self.is_rustc_attr),
            filters: ::core::clone::Clone::clone(&self.filters),
            message: ::core::clone::Clone::clone(&self.message),
            label: ::core::clone::Clone::clone(&self.label),
            notes: ::core::clone::Clone::clone(&self.notes),
            parent_label: ::core::clone::Clone::clone(&self.parent_label),
        }
    }
}Clone, #[automatically_derived]
impl ::core::default::Default for Directive {
    #[inline]
    fn default() -> Directive {
        Directive {
            is_rustc_attr: ::core::default::Default::default(),
            filters: ::core::default::Default::default(),
            message: ::core::default::Default::default(),
            label: ::core::default::Default::default(),
            notes: ::core::default::Default::default(),
            parent_label: ::core::default::Default::default(),
        }
    }
}Default, #[automatically_derived]
impl ::core::fmt::Debug for Directive {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        let names: &'static _ =
            &["is_rustc_attr", "filters", "message", "label", "notes",
                        "parent_label"];
        let values: &[&dyn ::core::fmt::Debug] =
            &[&self.is_rustc_attr, &self.filters, &self.message, &self.label,
                        &self.notes, &&self.parent_label];
        ::core::fmt::Formatter::debug_struct_fields_finish(f, "Directive",
            names, values)
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for Directive {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    Directive {
                        is_rustc_attr: ref __binding_0,
                        filters: ref __binding_1,
                        message: ref __binding_2,
                        label: ref __binding_3,
                        notes: ref __binding_4,
                        parent_label: ref __binding_5 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                        { __binding_3.stable_hash(__hcx, __hasher); }
                        { __binding_4.stable_hash(__hcx, __hasher); }
                        { __binding_5.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for Directive {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    Directive {
                        is_rustc_attr: ref __binding_0,
                        filters: ref __binding_1,
                        message: ref __binding_2,
                        label: ref __binding_3,
                        notes: ref __binding_4,
                        parent_label: ref __binding_5 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_3,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_4,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_5,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for Directive {
            fn decode(__decoder: &mut __D) -> Self {
                Directive {
                    is_rustc_attr: ::rustc_serialize::Decodable::decode(__decoder),
                    filters: ::rustc_serialize::Decodable::decode(__decoder),
                    message: ::rustc_serialize::Decodable::decode(__decoder),
                    label: ::rustc_serialize::Decodable::decode(__decoder),
                    notes: ::rustc_serialize::Decodable::decode(__decoder),
                    parent_label: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable, const _: () =
    {
        #[allow(unused)]
        impl PrintAttribute for Directive {
            fn should_render(&self) -> bool { true }
            fn print_attribute(&self,
                __p: &mut rustc_ast_pretty::pp::Printer) {
                let Self {
                        is_rustc_attr, filters, message, label, notes, parent_label
                        } = self;
                __p.word("Directive");
                if true && !is_rustc_attr.should_render() &&
                                        !filters.should_render() && !message.should_render() &&
                                !label.should_render() && !notes.should_render() &&
                        !parent_label.should_render() {
                    return;
                }
                __p.nbsp();
                __p.word("{");
                let mut __printed_anything = false;
                if is_rustc_attr.should_render() {
                    if __printed_anything { __p.word_space(","); }
                    __p.word("is_rustc_attr");
                    __p.word(":");
                    __p.nbsp();
                    __printed_anything = true;
                }
                is_rustc_attr.print_attribute(__p);
                if filters.should_render() {
                    if __printed_anything { __p.word_space(","); }
                    __p.word("filters");
                    __p.word(":");
                    __p.nbsp();
                    __printed_anything = true;
                }
                filters.print_attribute(__p);
                if message.should_render() {
                    if __printed_anything { __p.word_space(","); }
                    __p.word("message");
                    __p.word(":");
                    __p.nbsp();
                    __printed_anything = true;
                }
                message.print_attribute(__p);
                if label.should_render() {
                    if __printed_anything { __p.word_space(","); }
                    __p.word("label");
                    __p.word(":");
                    __p.nbsp();
                    __printed_anything = true;
                }
                label.print_attribute(__p);
                if notes.should_render() {
                    if __printed_anything { __p.word_space(","); }
                    __p.word("notes");
                    __p.word(":");
                    __p.nbsp();
                    __printed_anything = true;
                }
                notes.print_attribute(__p);
                if parent_label.should_render() {
                    if __printed_anything { __p.word_space(","); }
                    __p.word("parent_label");
                    __p.word(":");
                    __p.nbsp();
                    __printed_anything = true;
                }
                parent_label.print_attribute(__p);
                __p.word("}");
            }
        }
    };PrintAttribute)]
14pub struct Directive {
15    pub is_rustc_attr: bool,
16    /// This is never nested more than once, i.e. the directives in this
17    /// thinvec have no filters of their own.
18    pub filters: ThinVec<(Filter, Directive)>,
19    pub message: Option<(Span, FormatString)>,
20    pub label: Option<(Span, FormatString)>,
21    pub notes: ThinVec<FormatString>,
22    pub parent_label: Option<FormatString>,
23}
24
25impl Directive {
26    /// Visit all the generic arguments used in the attribute, to see whether they are actually a
27    /// generic of the item. If not then `visit` must issue a diagnostic.
28    ///
29    /// We can't check this while parsing the attribute because `rustc_attr_parsing` doesn't have
30    /// access to the item an attribute is on. Instead we later call this function in `check_attr`.
31    pub fn visit_params(&self, visit: &mut impl FnMut(Symbol, Span)) {
32        for (filter, subcommand) in &self.filters {
33            filter.visit_params(visit);
34            subcommand.visit_params(visit);
35        }
36
37        if let Some((_, message)) = &self.message {
38            message.visit_params(visit);
39        }
40        if let Some((_, label)) = &self.label {
41            label.visit_params(visit);
42        }
43
44        for note in &self.notes {
45            note.visit_params(visit);
46        }
47
48        if let Some(parent_label) = &self.parent_label {
49            parent_label.visit_params(visit);
50        }
51    }
52
53    pub fn eval(
54        &self,
55        filter_options: Option<&FilterOptions>,
56        args: &FormatArgs,
57    ) -> CustomDiagnostic {
58        let this = &args.this;
59        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir/src/attrs/diagnostic.rs:59",
                        "rustc_hir::attrs::diagnostic", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir/src/attrs/diagnostic.rs"),
                        ::tracing_core::__macro_support::Option::Some(59u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir::attrs::diagnostic"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("Directive::eval({0:?}, this={1}, options={2:?}, args ={3:?})",
                                                    self, this, filter_options, args) as &dyn Value))])
            });
    } else { ; }
};debug!(
60            "Directive::eval({self:?}, this={this}, options={filter_options:?}, args ={args:?})"
61        );
62
63        let mut ret = CustomDiagnostic::default();
64
65        if let Some(filter_options) = filter_options {
66            for (filter, directive) in &self.filters {
67                if filter.matches_predicate(filter_options) {
68                    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir/src/attrs/diagnostic.rs:68",
                        "rustc_hir::attrs::diagnostic", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir/src/attrs/diagnostic.rs"),
                        ::tracing_core::__macro_support::Option::Some(68u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir::attrs::diagnostic"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("eval: {0:?} succeeded",
                                                    filter) as &dyn Value))])
            });
    } else { ; }
};debug!("eval: {filter:?} succeeded");
69                    ret.update(directive, args);
70                } else {
71                    {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir/src/attrs/diagnostic.rs:71",
                        "rustc_hir::attrs::diagnostic", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir/src/attrs/diagnostic.rs"),
                        ::tracing_core::__macro_support::Option::Some(71u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir::attrs::diagnostic"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("eval: skipping {0:?} due to {1:?}",
                                                    filter, filter_options) as &dyn Value))])
            });
    } else { ; }
};debug!("eval: skipping {filter:?} due to {filter_options:?}");
72                }
73            }
74        } else {
75            if true {
    if !!self.is_rustc_attr {
        {
            ::core::panicking::panic_fmt(format_args!("Directive::eval called for `rustc_on_unimplemented` without `filter_options`"));
        }
    };
};debug_assert!(
76                !self.is_rustc_attr,
77                "Directive::eval called for `rustc_on_unimplemented` without `filter_options`"
78            );
79        };
80        ret.update(self, args);
81        ret
82    }
83}
84
85/// A custom diagnostic, created from a diagnostic attribute.
86#[derive(#[automatically_derived]
impl ::core::default::Default for CustomDiagnostic {
    #[inline]
    fn default() -> CustomDiagnostic {
        CustomDiagnostic {
            message: ::core::default::Default::default(),
            label: ::core::default::Default::default(),
            notes: ::core::default::Default::default(),
            parent_label: ::core::default::Default::default(),
        }
    }
}Default, #[automatically_derived]
impl ::core::fmt::Debug for CustomDiagnostic {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field4_finish(f,
            "CustomDiagnostic", "message", &self.message, "label",
            &self.label, "notes", &self.notes, "parent_label",
            &&self.parent_label)
    }
}Debug)]
87pub struct CustomDiagnostic {
88    pub message: Option<String>,
89    pub label: Option<String>,
90    pub notes: Vec<String>,
91    pub parent_label: Option<String>,
92}
93
94impl CustomDiagnostic {
95    fn update(&mut self, di: &Directive, args: &FormatArgs) {
96        if self.message.is_none() {
97            self.message = di.message.as_ref().map(|m| m.1.format(args));
98        }
99        if self.label.is_none() {
100            self.label = di.label.as_ref().map(|l| l.1.format(args));
101        }
102        if self.parent_label.is_none() {
103            self.parent_label = di.parent_label.as_ref().map(|p| p.format(args));
104        }
105
106        self.notes.extend(di.notes.iter().map(|n| n.format(args)))
107    }
108}
109
110/// Like [std::fmt::Arguments] this is a string that has been parsed into "pieces",
111/// either as string pieces or dynamic arguments.
112#[derive(#[automatically_derived]
impl ::core::clone::Clone for FormatString {
    #[inline]
    fn clone(&self) -> FormatString {
        FormatString {
            input: ::core::clone::Clone::clone(&self.input),
            span: ::core::clone::Clone::clone(&self.span),
            pieces: ::core::clone::Clone::clone(&self.pieces),
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for FormatString {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f, "FormatString",
            "input", &self.input, "span", &self.span, "pieces", &&self.pieces)
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for FormatString
            {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    FormatString {
                        input: ref __binding_0,
                        span: ref __binding_1,
                        pieces: ref __binding_2 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for FormatString {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    FormatString {
                        input: ref __binding_0,
                        span: ref __binding_1,
                        pieces: ref __binding_2 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_2,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for FormatString {
            fn decode(__decoder: &mut __D) -> Self {
                FormatString {
                    input: ::rustc_serialize::Decodable::decode(__decoder),
                    span: ::rustc_serialize::Decodable::decode(__decoder),
                    pieces: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable, const _: () =
    {
        #[allow(unused)]
        impl PrintAttribute for FormatString {
            fn should_render(&self) -> bool { true }
            fn print_attribute(&self,
                __p: &mut rustc_ast_pretty::pp::Printer) {
                let Self { input, span, pieces } = self;
                __p.word("FormatString");
                if true && !input.should_render() && !span.should_render() &&
                        !pieces.should_render() {
                    return;
                }
                __p.nbsp();
                __p.word("{");
                let mut __printed_anything = false;
                if input.should_render() {
                    if __printed_anything { __p.word_space(","); }
                    __p.word("input");
                    __p.word(":");
                    __p.nbsp();
                    __printed_anything = true;
                }
                input.print_attribute(__p);
                if span.should_render() {
                    if __printed_anything { __p.word_space(","); }
                    __p.word("span");
                    __p.word(":");
                    __p.nbsp();
                    __printed_anything = true;
                }
                span.print_attribute(__p);
                if pieces.should_render() {
                    if __printed_anything { __p.word_space(","); }
                    __p.word("pieces");
                    __p.word(":");
                    __p.nbsp();
                    __printed_anything = true;
                }
                pieces.print_attribute(__p);
                __p.word("}");
            }
        }
    };PrintAttribute)]
113pub struct FormatString {
114    pub input: Symbol,
115    pub span: Span,
116    pub pieces: ThinVec<Piece>,
117}
118
119impl FormatString {
120    /// Formats the format string.
121    ///
122    /// This is a private method, use `Directive::eval` instead. A diagnostic attribute being used
123    /// should issue a `tracing` event, which `Directive::eval` does.
124    fn format(&self, args: &FormatArgs) -> String {
125        let mut ret = String::new();
126        for piece in &self.pieces {
127            match piece {
128                Piece::Lit(s) | Piece::Arg(FormatArg::AsIs(s)) => ret.push_str(s.as_str()),
129
130                // `A` if we have `trait Trait<A> {}` and `note = "i'm the actual type of {A}"`
131                Piece::Arg(FormatArg::GenericParam { generic_param, .. }) => {
132                    match args.generic_args.iter().find(|(p, _)| p == generic_param) {
133                        Some((_, val)) => ret.push_str(val.as_str()),
134
135                        None => {
136                            // Apparently this was not actually a generic parameter, so lets write
137                            // what the user wrote.
138                            let _ = fmt::write(&mut ret, format_args!("{{{0}}}", generic_param)format_args!("{{{generic_param}}}"));
139                        }
140                    }
141                }
142                // `{Self}`
143                Piece::Arg(FormatArg::SelfUpper) => {
144                    let slf = match args.generic_args.iter().find(|(p, _)| *p == kw::SelfUpper) {
145                        Some((_, val)) => val.to_string(),
146                        None => "Self".to_string(),
147                    };
148                    ret.push_str(&slf);
149                }
150                Piece::Arg(FormatArg::This) => ret.push_str(&args.this),
151
152                // It's only `rustc_onunimplemented` from here
153                Piece::Arg(FormatArg::ThisPath) => ret.push_str(&args.this_path),
154                Piece::Arg(FormatArg::ThisResolved) => {
155                    let _ = fmt::write(&mut ret, format_args!("{0}", &args.this_resolved)format_args!("{}", &args.this_resolved));
156                }
157                Piece::Arg(FormatArg::ItemContext) => ret.push_str(args.item_context),
158            }
159        }
160        ret
161    }
162
163    fn visit_params(&self, visit: &mut impl FnMut(Symbol, Span)) {
164        for piece in &self.pieces {
165            if let Piece::Arg(FormatArg::GenericParam { generic_param, span }) = piece {
166                visit(*generic_param, *span);
167            }
168        }
169    }
170}
171
172/// Arguments to fill a [FormatString] with.
173///
174/// For example, given a
175/// ```rust,ignore (just an example)
176///
177/// #[rustc_on_unimplemented(
178///     on(all(from_desugaring = "QuestionMark"),
179///         message = "the `?` operator can only be used in {ItemContext} \
180///                     that returns `Result` or `Option` \
181///                     (or another type that implements `{FromResidual}`)",
182///         label = "cannot use the `?` operator in {ItemContext} that returns `{Self}`",
183///         parent_label = "this function should return `Result` or `Option` to accept `?`"
184///     ),
185/// )]
186/// pub trait FromResidual<R = <Self as Try>::Residual> {
187///    ...
188/// }
189///
190/// async fn an_async_function() -> u32 {
191///     let x: Option<u32> = None;
192///     x?; //~ ERROR the `?` operator
193///     22
194/// }
195///  ```
196/// it will look like this:
197///
198/// ```rust,ignore (just an example)
199/// FormatArgs {
200///     this: "FromResidual",
201///     this_resolved: "FromResidual<Option<Infallible>>",
202///     item_context: "an async function",
203///     generic_args: [("Self", "u32"), ("R", "Option<Infallible>")],
204/// }
205/// ```
206#[derive(#[automatically_derived]
impl ::core::fmt::Debug for FormatArgs {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field5_finish(f, "FormatArgs",
            "this", &self.this, "this_resolved", &self.this_resolved,
            "this_path", &self.this_path, "item_context", &self.item_context,
            "generic_args", &&self.generic_args)
    }
}Debug)]
207pub struct FormatArgs {
208    /// The name of the item the attribute is on.
209    pub this: String,
210    pub this_resolved: String = String::new(),
211    pub this_path: String = String::new(),
212    pub item_context: &'static str = "",
213    pub generic_args: Vec<(Symbol, String)> = Vec::new(),
214}
215
216#[derive(#[automatically_derived]
impl ::core::clone::Clone for Piece {
    #[inline]
    fn clone(&self) -> Piece {
        match self {
            Piece::Lit(__self_0) =>
                Piece::Lit(::core::clone::Clone::clone(__self_0)),
            Piece::Arg(__self_0) =>
                Piece::Arg(::core::clone::Clone::clone(__self_0)),
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Piece {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Piece::Lit(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Lit",
                    &__self_0),
            Piece::Arg(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Arg",
                    &__self_0),
        }
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for Piece {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    Piece::Lit(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    Piece::Arg(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for Piece {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        Piece::Lit(ref __binding_0) => { 0usize }
                        Piece::Arg(ref __binding_0) => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    Piece::Lit(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    Piece::Arg(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for Piece {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        Piece::Lit(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => {
                        Piece::Arg(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Piece`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, const _: () =
    {
        #[allow(unused)]
        impl PrintAttribute for Piece {
            fn should_render(&self) -> bool { true }
            fn print_attribute(&self,
                __p: &mut rustc_ast_pretty::pp::Printer) {
                match self {
                    Self::Lit(f0) => {
                        __p.word("Lit");
                        if true && !f0.should_render() { return; }
                        __p.popen();
                        let mut __printed_anything = false;
                        if f0.should_render() {
                            if __printed_anything { __p.word_space(","); }
                            __printed_anything = true;
                        }
                        f0.print_attribute(__p);
                        __p.pclose();
                    }
                    Self::Arg(f0) => {
                        __p.word("Arg");
                        if true && !f0.should_render() { return; }
                        __p.popen();
                        let mut __printed_anything = false;
                        if f0.should_render() {
                            if __printed_anything { __p.word_space(","); }
                            __printed_anything = true;
                        }
                        f0.print_attribute(__p);
                        __p.pclose();
                    }
                }
            }
        }
    };PrintAttribute)]
217pub enum Piece {
218    Lit(Symbol),
219    Arg(FormatArg),
220}
221
222#[derive(#[automatically_derived]
impl ::core::clone::Clone for FormatArg {
    #[inline]
    fn clone(&self) -> FormatArg {
        match self {
            FormatArg::GenericParam { generic_param: __self_0, span: __self_1
                } =>
                FormatArg::GenericParam {
                    generic_param: ::core::clone::Clone::clone(__self_0),
                    span: ::core::clone::Clone::clone(__self_1),
                },
            FormatArg::SelfUpper => FormatArg::SelfUpper,
            FormatArg::This => FormatArg::This,
            FormatArg::ThisResolved => FormatArg::ThisResolved,
            FormatArg::ThisPath => FormatArg::ThisPath,
            FormatArg::ItemContext => FormatArg::ItemContext,
            FormatArg::AsIs(__self_0) =>
                FormatArg::AsIs(::core::clone::Clone::clone(__self_0)),
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for FormatArg {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            FormatArg::GenericParam { generic_param: __self_0, span: __self_1
                } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "GenericParam", "generic_param", __self_0, "span",
                    &__self_1),
            FormatArg::SelfUpper =>
                ::core::fmt::Formatter::write_str(f, "SelfUpper"),
            FormatArg::This => ::core::fmt::Formatter::write_str(f, "This"),
            FormatArg::ThisResolved =>
                ::core::fmt::Formatter::write_str(f, "ThisResolved"),
            FormatArg::ThisPath =>
                ::core::fmt::Formatter::write_str(f, "ThisPath"),
            FormatArg::ItemContext =>
                ::core::fmt::Formatter::write_str(f, "ItemContext"),
            FormatArg::AsIs(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "AsIs",
                    &__self_0),
        }
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for FormatArg {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    FormatArg::GenericParam {
                        generic_param: ref __binding_0, span: ref __binding_1 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                    FormatArg::SelfUpper => {}
                    FormatArg::This => {}
                    FormatArg::ThisResolved => {}
                    FormatArg::ThisPath => {}
                    FormatArg::ItemContext => {}
                    FormatArg::AsIs(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for FormatArg {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        FormatArg::GenericParam {
                            generic_param: ref __binding_0, span: ref __binding_1 } => {
                            0usize
                        }
                        FormatArg::SelfUpper => { 1usize }
                        FormatArg::This => { 2usize }
                        FormatArg::ThisResolved => { 3usize }
                        FormatArg::ThisPath => { 4usize }
                        FormatArg::ItemContext => { 5usize }
                        FormatArg::AsIs(ref __binding_0) => { 6usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    FormatArg::GenericParam {
                        generic_param: ref __binding_0, span: ref __binding_1 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                    FormatArg::SelfUpper => {}
                    FormatArg::This => {}
                    FormatArg::ThisResolved => {}
                    FormatArg::ThisPath => {}
                    FormatArg::ItemContext => {}
                    FormatArg::AsIs(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for FormatArg {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        FormatArg::GenericParam {
                            generic_param: ::rustc_serialize::Decodable::decode(__decoder),
                            span: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    1usize => { FormatArg::SelfUpper }
                    2usize => { FormatArg::This }
                    3usize => { FormatArg::ThisResolved }
                    4usize => { FormatArg::ThisPath }
                    5usize => { FormatArg::ItemContext }
                    6usize => {
                        FormatArg::AsIs(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `FormatArg`, expected 0..7, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, const _: () =
    {
        #[allow(unused)]
        impl PrintAttribute for FormatArg {
            fn should_render(&self) -> bool { true }
            fn print_attribute(&self,
                __p: &mut rustc_ast_pretty::pp::Printer) {
                match self {
                    Self::GenericParam { generic_param, span } => {
                        __p.word("GenericParam");
                        if true && !generic_param.should_render() &&
                                !span.should_render() {
                            return;
                        }
                        __p.nbsp();
                        __p.word("{");
                        let mut __printed_anything = false;
                        if generic_param.should_render() {
                            if __printed_anything { __p.word_space(","); }
                            __p.word("generic_param");
                            __p.word(":");
                            __p.nbsp();
                            __printed_anything = true;
                        }
                        generic_param.print_attribute(__p);
                        if span.should_render() {
                            if __printed_anything { __p.word_space(","); }
                            __p.word("span");
                            __p.word(":");
                            __p.nbsp();
                            __printed_anything = true;
                        }
                        span.print_attribute(__p);
                        __p.word("}");
                    }
                    Self::SelfUpper => { __p.word("SelfUpper") }
                    Self::This => { __p.word("This") }
                    Self::ThisResolved => { __p.word("ThisResolved") }
                    Self::ThisPath => { __p.word("ThisPath") }
                    Self::ItemContext => { __p.word("ItemContext") }
                    Self::AsIs(f0) => {
                        __p.word("AsIs");
                        if true && !f0.should_render() { return; }
                        __p.popen();
                        let mut __printed_anything = false;
                        if f0.should_render() {
                            if __printed_anything { __p.word_space(","); }
                            __printed_anything = true;
                        }
                        f0.print_attribute(__p);
                        __p.pclose();
                    }
                }
            }
        }
    };PrintAttribute)]
223pub enum FormatArg {
224    // A generic parameter, like `{T}` if we're on the `From<T>` trait.
225    GenericParam {
226        generic_param: Symbol,
227        span: Span,
228    },
229    // `{Self}`
230    SelfUpper,
231    /// `{This}` and `{This:name}`.
232    This,
233    /// The sugared form: `{This:sugared}`.
234    ThisResolved,
235    /// The full path: `{This:path}`.
236    ThisPath,
237    /// what we're in, like a function, method, closure etc.
238    ItemContext,
239    /// What the user typed, if it doesn't match anything we can use.
240    AsIs(Symbol),
241}
242
243/// Represents the `on` filter in `#[rustc_on_unimplemented]`.
244#[derive(#[automatically_derived]
impl ::core::clone::Clone for Filter {
    #[inline]
    fn clone(&self) -> Filter {
        Filter {
            span: ::core::clone::Clone::clone(&self.span),
            pred: ::core::clone::Clone::clone(&self.pred),
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Filter {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "Filter",
            "span", &self.span, "pred", &&self.pred)
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for Filter {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    Filter { span: ref __binding_0, pred: ref __binding_1 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for Filter {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    Filter { span: ref __binding_0, pred: ref __binding_1 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for Filter {
            fn decode(__decoder: &mut __D) -> Self {
                Filter {
                    span: ::rustc_serialize::Decodable::decode(__decoder),
                    pred: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable, const _: () =
    {
        #[allow(unused)]
        impl PrintAttribute for Filter {
            fn should_render(&self) -> bool { true }
            fn print_attribute(&self,
                __p: &mut rustc_ast_pretty::pp::Printer) {
                let Self { span, pred } = self;
                __p.word("Filter");
                if true && !span.should_render() && !pred.should_render() {
                    return;
                }
                __p.nbsp();
                __p.word("{");
                let mut __printed_anything = false;
                if span.should_render() {
                    if __printed_anything { __p.word_space(","); }
                    __p.word("span");
                    __p.word(":");
                    __p.nbsp();
                    __printed_anything = true;
                }
                span.print_attribute(__p);
                if pred.should_render() {
                    if __printed_anything { __p.word_space(","); }
                    __p.word("pred");
                    __p.word(":");
                    __p.nbsp();
                    __printed_anything = true;
                }
                pred.print_attribute(__p);
                __p.word("}");
            }
        }
    };PrintAttribute)]
245pub struct Filter {
246    pub span: Span,
247    pub pred: Predicate,
248}
249impl Filter {
250    pub fn matches_predicate(&self, options: &FilterOptions) -> bool {
251        self.pred.eval(&mut |p| match p {
252            FlagOrNv::Flag(b) => options.has_flag(*b),
253            FlagOrNv::NameValue(NameValue { name, value }) => {
254                let value = value.format(&options.generic_args);
255                options.contains(*name, value)
256            }
257        })
258    }
259
260    pub fn visit_params(&self, visit: &mut impl FnMut(Symbol, Span)) {
261        self.pred.visit_params(self.span, visit);
262    }
263}
264
265/// Predicate(s) in `#[rustc_on_unimplemented]`'s `on` filter. See [`Filter`].
266///
267/// It is similar to the predicate in the `cfg` attribute,
268/// and may contain nested predicates.
269#[derive(#[automatically_derived]
impl ::core::clone::Clone for Predicate {
    #[inline]
    fn clone(&self) -> Predicate {
        match self {
            Predicate::Flag(__self_0) =>
                Predicate::Flag(::core::clone::Clone::clone(__self_0)),
            Predicate::Match(__self_0) =>
                Predicate::Match(::core::clone::Clone::clone(__self_0)),
            Predicate::Not(__self_0) =>
                Predicate::Not(::core::clone::Clone::clone(__self_0)),
            Predicate::All(__self_0) =>
                Predicate::All(::core::clone::Clone::clone(__self_0)),
            Predicate::Any(__self_0) =>
                Predicate::Any(::core::clone::Clone::clone(__self_0)),
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Predicate {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Predicate::Flag(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Flag",
                    &__self_0),
            Predicate::Match(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Match",
                    &__self_0),
            Predicate::Not(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Not",
                    &__self_0),
            Predicate::All(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "All",
                    &__self_0),
            Predicate::Any(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Any",
                    &__self_0),
        }
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for Predicate {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    Predicate::Flag(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    Predicate::Match(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    Predicate::Not(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    Predicate::All(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    Predicate::Any(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for Predicate {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        Predicate::Flag(ref __binding_0) => { 0usize }
                        Predicate::Match(ref __binding_0) => { 1usize }
                        Predicate::Not(ref __binding_0) => { 2usize }
                        Predicate::All(ref __binding_0) => { 3usize }
                        Predicate::Any(ref __binding_0) => { 4usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    Predicate::Flag(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    Predicate::Match(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    Predicate::Not(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    Predicate::All(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    Predicate::Any(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for Predicate {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        Predicate::Flag(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => {
                        Predicate::Match(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    2usize => {
                        Predicate::Not(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    3usize => {
                        Predicate::All(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    4usize => {
                        Predicate::Any(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Predicate`, expected 0..5, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, const _: () =
    {
        #[allow(unused)]
        impl PrintAttribute for Predicate {
            fn should_render(&self) -> bool { true }
            fn print_attribute(&self,
                __p: &mut rustc_ast_pretty::pp::Printer) {
                match self {
                    Self::Flag(f0) => {
                        __p.word("Flag");
                        if true && !f0.should_render() { return; }
                        __p.popen();
                        let mut __printed_anything = false;
                        if f0.should_render() {
                            if __printed_anything { __p.word_space(","); }
                            __printed_anything = true;
                        }
                        f0.print_attribute(__p);
                        __p.pclose();
                    }
                    Self::Match(f0) => {
                        __p.word("Match");
                        if true && !f0.should_render() { return; }
                        __p.popen();
                        let mut __printed_anything = false;
                        if f0.should_render() {
                            if __printed_anything { __p.word_space(","); }
                            __printed_anything = true;
                        }
                        f0.print_attribute(__p);
                        __p.pclose();
                    }
                    Self::Not(f0) => {
                        __p.word("Not");
                        if true && !f0.should_render() { return; }
                        __p.popen();
                        let mut __printed_anything = false;
                        if f0.should_render() {
                            if __printed_anything { __p.word_space(","); }
                            __printed_anything = true;
                        }
                        f0.print_attribute(__p);
                        __p.pclose();
                    }
                    Self::All(f0) => {
                        __p.word("All");
                        if true && !f0.should_render() { return; }
                        __p.popen();
                        let mut __printed_anything = false;
                        if f0.should_render() {
                            if __printed_anything { __p.word_space(","); }
                            __printed_anything = true;
                        }
                        f0.print_attribute(__p);
                        __p.pclose();
                    }
                    Self::Any(f0) => {
                        __p.word("Any");
                        if true && !f0.should_render() { return; }
                        __p.popen();
                        let mut __printed_anything = false;
                        if f0.should_render() {
                            if __printed_anything { __p.word_space(","); }
                            __printed_anything = true;
                        }
                        f0.print_attribute(__p);
                        __p.pclose();
                    }
                }
            }
        }
    };PrintAttribute)]
270pub enum Predicate {
271    /// A condition like `on(crate_local)`.
272    Flag(Flag),
273    /// A match, like `on(Rhs = "Whatever")`.
274    Match(NameValue),
275    /// Negation, like `on(not($pred))`.
276    Not(Box<Predicate>),
277    /// True if all predicates are true, like `on(all($a, $b, $c))`.
278    All(ThinVec<Predicate>),
279    /// True if any predicate is true, like `on(any($a, $b, $c))`.
280    Any(ThinVec<Predicate>),
281}
282
283impl Predicate {
284    pub fn eval(&self, eval: &mut impl FnMut(FlagOrNv<'_>) -> bool) -> bool {
285        match self {
286            Predicate::Flag(flag) => eval(FlagOrNv::Flag(flag)),
287            Predicate::Match(nv) => eval(FlagOrNv::NameValue(nv)),
288            Predicate::Not(not) => !not.eval(eval),
289            Predicate::All(preds) => preds.into_iter().all(|pred| pred.eval(eval)),
290            Predicate::Any(preds) => preds.into_iter().any(|pred| pred.eval(eval)),
291        }
292    }
293
294    pub fn visit_params(&self, span: Span, visit: &mut impl FnMut(Symbol, Span)) {
295        match self {
296            Predicate::Flag(_) => {}
297            Predicate::Match(nv) => nv.visit_params(span, visit),
298            Predicate::Not(not) => not.visit_params(span, visit),
299            Predicate::All(preds) | Predicate::Any(preds) => {
300                preds.iter().for_each(|pred| pred.visit_params(span, visit))
301            }
302        }
303    }
304}
305
306/// Represents a `MetaWord` in an `on`-filter.
307#[derive(#[automatically_derived]
impl ::core::clone::Clone for Flag {
    #[inline]
    fn clone(&self) -> Flag { *self }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Flag { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for Flag {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                Flag::CrateLocal => "CrateLocal",
                Flag::Direct => "Direct",
                Flag::FromDesugaring => "FromDesugaring",
            })
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for Flag {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    Flag::CrateLocal => {}
                    Flag::Direct => {}
                    Flag::FromDesugaring => {}
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for Flag {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        Flag::CrateLocal => { 0usize }
                        Flag::Direct => { 1usize }
                        Flag::FromDesugaring => { 2usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    Flag::CrateLocal => {}
                    Flag::Direct => {}
                    Flag::FromDesugaring => {}
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for Flag {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { Flag::CrateLocal }
                    1usize => { Flag::Direct }
                    2usize => { Flag::FromDesugaring }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Flag`, expected 0..3, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, const _: () =
    {
        #[allow(unused)]
        impl PrintAttribute for Flag {
            fn should_render(&self) -> bool { true }
            fn print_attribute(&self,
                __p: &mut rustc_ast_pretty::pp::Printer) {
                match self {
                    Self::CrateLocal => { __p.word("CrateLocal") }
                    Self::Direct => { __p.word("Direct") }
                    Self::FromDesugaring => { __p.word("FromDesugaring") }
                }
            }
        }
    };PrintAttribute)]
308pub enum Flag {
309    /// Whether the code causing the trait bound to not be fulfilled
310    /// is part of the user's crate.
311    CrateLocal,
312    /// Whether the obligation is user-specified rather than derived.
313    Direct,
314    /// Whether we are in some kind of desugaring like
315    /// `?` or `try { .. }`.
316    FromDesugaring,
317}
318
319/// A `MetaNameValueStr` in an `on`-filter.
320///
321/// For example, `#[rustc_on_unimplemented(on(name = "value", message = "hello"))]`.
322#[derive(#[automatically_derived]
impl ::core::clone::Clone for NameValue {
    #[inline]
    fn clone(&self) -> NameValue {
        NameValue {
            name: ::core::clone::Clone::clone(&self.name),
            value: ::core::clone::Clone::clone(&self.value),
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for NameValue {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "NameValue",
            "name", &self.name, "value", &&self.value)
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for NameValue {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    NameValue { name: ref __binding_0, value: ref __binding_1 }
                        => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for NameValue {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    NameValue { name: ref __binding_0, value: ref __binding_1 }
                        => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_1,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for NameValue {
            fn decode(__decoder: &mut __D) -> Self {
                NameValue {
                    name: ::rustc_serialize::Decodable::decode(__decoder),
                    value: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable, const _: () =
    {
        #[allow(unused)]
        impl PrintAttribute for NameValue {
            fn should_render(&self) -> bool { true }
            fn print_attribute(&self,
                __p: &mut rustc_ast_pretty::pp::Printer) {
                let Self { name, value } = self;
                __p.word("NameValue");
                if true && !name.should_render() && !value.should_render() {
                    return;
                }
                __p.nbsp();
                __p.word("{");
                let mut __printed_anything = false;
                if name.should_render() {
                    if __printed_anything { __p.word_space(","); }
                    __p.word("name");
                    __p.word(":");
                    __p.nbsp();
                    __printed_anything = true;
                }
                name.print_attribute(__p);
                if value.should_render() {
                    if __printed_anything { __p.word_space(","); }
                    __p.word("value");
                    __p.word(":");
                    __p.nbsp();
                    __printed_anything = true;
                }
                value.print_attribute(__p);
                __p.word("}");
            }
        }
    };PrintAttribute)]
323pub struct NameValue {
324    pub name: Name,
325    /// Something like `"&str"` or `"alloc::string::String"`,
326    /// in which case it just contains a single string piece.
327    /// But if it is something like `"&[{A}]"` then it must be formatted later.
328    pub value: FilterFormatString,
329}
330
331impl NameValue {
332    pub fn visit_params(&self, span: Span, visit: &mut impl FnMut(Symbol, Span)) {
333        if let Name::GenericArg(arg) = self.name {
334            visit(arg, span);
335        }
336        self.value.visit_params(span, visit);
337    }
338}
339
340/// The valid names of the `on` filter.
341#[derive(#[automatically_derived]
impl ::core::clone::Clone for Name {
    #[inline]
    fn clone(&self) -> Name {
        let _: ::core::clone::AssertParamIsClone<Symbol>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for Name { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for Name {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Name::Cause => ::core::fmt::Formatter::write_str(f, "Cause"),
            Name::FromDesugaring =>
                ::core::fmt::Formatter::write_str(f, "FromDesugaring"),
            Name::SelfUpper =>
                ::core::fmt::Formatter::write_str(f, "SelfUpper"),
            Name::GenericArg(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "GenericArg", &__self_0),
        }
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for Name {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    Name::Cause => {}
                    Name::FromDesugaring => {}
                    Name::SelfUpper => {}
                    Name::GenericArg(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for Name {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        Name::Cause => { 0usize }
                        Name::FromDesugaring => { 1usize }
                        Name::SelfUpper => { 2usize }
                        Name::GenericArg(ref __binding_0) => { 3usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    Name::Cause => {}
                    Name::FromDesugaring => {}
                    Name::SelfUpper => {}
                    Name::GenericArg(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for Name {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { Name::Cause }
                    1usize => { Name::FromDesugaring }
                    2usize => { Name::SelfUpper }
                    3usize => {
                        Name::GenericArg(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Name`, expected 0..4, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, const _: () =
    {
        #[allow(unused)]
        impl PrintAttribute for Name {
            fn should_render(&self) -> bool { true }
            fn print_attribute(&self,
                __p: &mut rustc_ast_pretty::pp::Printer) {
                match self {
                    Self::Cause => { __p.word("Cause") }
                    Self::FromDesugaring => { __p.word("FromDesugaring") }
                    Self::SelfUpper => { __p.word("SelfUpper") }
                    Self::GenericArg(f0) => {
                        __p.word("GenericArg");
                        if true && !f0.should_render() { return; }
                        __p.popen();
                        let mut __printed_anything = false;
                        if f0.should_render() {
                            if __printed_anything { __p.word_space(","); }
                            __printed_anything = true;
                        }
                        f0.print_attribute(__p);
                        __p.pclose();
                    }
                }
            }
        }
    };PrintAttribute)]
342pub enum Name {
343    Cause,
344    FromDesugaring,
345    SelfUpper,
346    GenericArg(Symbol),
347}
348
349#[derive(#[automatically_derived]
impl<'p> ::core::fmt::Debug for FlagOrNv<'p> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            FlagOrNv::Flag(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Flag",
                    &__self_0),
            FlagOrNv::NameValue(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "NameValue", &__self_0),
        }
    }
}Debug, #[automatically_derived]
impl<'p> ::core::clone::Clone for FlagOrNv<'p> {
    #[inline]
    fn clone(&self) -> FlagOrNv<'p> {
        match self {
            FlagOrNv::Flag(__self_0) =>
                FlagOrNv::Flag(::core::clone::Clone::clone(__self_0)),
            FlagOrNv::NameValue(__self_0) =>
                FlagOrNv::NameValue(::core::clone::Clone::clone(__self_0)),
        }
    }
}Clone)]
350pub enum FlagOrNv<'p> {
351    Flag(&'p Flag),
352    NameValue(&'p NameValue),
353}
354
355/// Represents a value inside an `on` filter.
356///
357/// For example, `#[rustc_on_unimplemented(on(name = "value", message = "hello"))]`.
358/// If it is a simple literal like this then `pieces` will be `[LitOrArg::Lit("value")]`.
359/// The `Arg` variant is used when it contains formatting like
360/// `#[rustc_on_unimplemented(on(Self = "&[{A}]", message = "hello"))]`.
361#[derive(#[automatically_derived]
impl ::core::clone::Clone for FilterFormatString {
    #[inline]
    fn clone(&self) -> FilterFormatString {
        FilterFormatString {
            pieces: ::core::clone::Clone::clone(&self.pieces),
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for FilterFormatString {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f,
            "FilterFormatString", "pieces", &&self.pieces)
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            FilterFormatString {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                match *self {
                    FilterFormatString { pieces: ref __binding_0 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for FilterFormatString {
            fn encode(&self, __encoder: &mut __E) {
                match *self {
                    FilterFormatString { pieces: ref __binding_0 } => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for FilterFormatString {
            fn decode(__decoder: &mut __D) -> Self {
                FilterFormatString {
                    pieces: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable, const _: () =
    {
        #[allow(unused)]
        impl PrintAttribute for FilterFormatString {
            fn should_render(&self) -> bool { true }
            fn print_attribute(&self,
                __p: &mut rustc_ast_pretty::pp::Printer) {
                let Self { pieces } = self;
                __p.word("FilterFormatString");
                if true && !pieces.should_render() { return; }
                __p.nbsp();
                __p.word("{");
                let mut __printed_anything = false;
                if pieces.should_render() {
                    if __printed_anything { __p.word_space(","); }
                    __p.word("pieces");
                    __p.word(":");
                    __p.nbsp();
                    __printed_anything = true;
                }
                pieces.print_attribute(__p);
                __p.word("}");
            }
        }
    };PrintAttribute)]
362pub struct FilterFormatString {
363    pub pieces: ThinVec<LitOrArg>,
364}
365
366impl FilterFormatString {
367    fn format(&self, generic_args: &[(Symbol, String)]) -> String {
368        let mut ret = String::new();
369
370        for piece in &self.pieces {
371            match piece {
372                LitOrArg::Lit(s) => ret.push_str(s.as_str()),
373                LitOrArg::Arg(s) => match generic_args.iter().find(|(k, _)| k == s) {
374                    Some((_, val)) => ret.push_str(val),
375                    None => {
376                        let _ = std::fmt::write(&mut ret, format_args!("{{{0}}}", s)format_args!("{{{s}}}"));
377                    }
378                },
379            }
380        }
381
382        ret
383    }
384    pub fn visit_params(&self, span: Span, visit: &mut impl FnMut(Symbol, Span)) {
385        for piece in &self.pieces {
386            if let LitOrArg::Arg(arg) = piece {
387                visit(*arg, span);
388            }
389        }
390    }
391}
392
393#[derive(#[automatically_derived]
impl ::core::clone::Clone for LitOrArg {
    #[inline]
    fn clone(&self) -> LitOrArg {
        match self {
            LitOrArg::Lit(__self_0) =>
                LitOrArg::Lit(::core::clone::Clone::clone(__self_0)),
            LitOrArg::Arg(__self_0) =>
                LitOrArg::Arg(::core::clone::Clone::clone(__self_0)),
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for LitOrArg {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            LitOrArg::Lit(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Lit",
                    &__self_0),
            LitOrArg::Arg(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Arg",
                    &__self_0),
        }
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for LitOrArg {
            #[inline]
            fn stable_hash<__Hcx: ::rustc_data_structures::stable_hash::StableHashCtxt>(&self,
                __hcx: &mut __Hcx,
                __hasher:
                    &mut ::rustc_data_structures::stable_hash::StableHasher) {
                ::std::mem::discriminant(self).stable_hash(__hcx, __hasher);
                match *self {
                    LitOrArg::Lit(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                    LitOrArg::Arg(ref __binding_0) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for LitOrArg {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        LitOrArg::Lit(ref __binding_0) => { 0usize }
                        LitOrArg::Arg(ref __binding_0) => { 1usize }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    LitOrArg::Lit(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                    LitOrArg::Arg(ref __binding_0) => {
                        ::rustc_serialize::Encodable::<__E>::encode(__binding_0,
                            __encoder);
                    }
                }
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for LitOrArg {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => {
                        LitOrArg::Lit(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    1usize => {
                        LitOrArg::Arg(::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `LitOrArg`, expected 0..2, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, const _: () =
    {
        #[allow(unused)]
        impl PrintAttribute for LitOrArg {
            fn should_render(&self) -> bool { true }
            fn print_attribute(&self,
                __p: &mut rustc_ast_pretty::pp::Printer) {
                match self {
                    Self::Lit(f0) => {
                        __p.word("Lit");
                        if true && !f0.should_render() { return; }
                        __p.popen();
                        let mut __printed_anything = false;
                        if f0.should_render() {
                            if __printed_anything { __p.word_space(","); }
                            __printed_anything = true;
                        }
                        f0.print_attribute(__p);
                        __p.pclose();
                    }
                    Self::Arg(f0) => {
                        __p.word("Arg");
                        if true && !f0.should_render() { return; }
                        __p.popen();
                        let mut __printed_anything = false;
                        if f0.should_render() {
                            if __printed_anything { __p.word_space(","); }
                            __printed_anything = true;
                        }
                        f0.print_attribute(__p);
                        __p.pclose();
                    }
                }
            }
        }
    };PrintAttribute)]
394pub enum LitOrArg {
395    Lit(Symbol),
396    Arg(Symbol),
397}
398
399/// Used with `Filter::matches_predicate` to evaluate the [`Filter`].
400///
401/// For example, given a
402/// ```rust,ignore (just an example)
403/// #[rustc_on_unimplemented(
404///     on(all(from_desugaring = "QuestionMark"),
405///         message = "the `?` operator can only be used in {ItemContext} \
406///                     that returns `Result` or `Option` \
407///                     (or another type that implements `{FromResidual}`)",
408///         label = "cannot use the `?` operator in {ItemContext} that returns `{Self}`",
409///         parent_label = "this function should return `Result` or `Option` to accept `?`"
410///     ),
411/// )]
412/// pub trait FromResidual<R = <Self as Try>::Residual> {
413///    ...
414/// }
415///
416/// async fn an_async_function() -> u32 {
417///     let x: Option<u32> = None;
418///     x?; //~ ERROR the `?` operator
419///     22
420/// }
421///  ```
422/// it will look like this:
423///
424/// ```rust,ignore (just an example)
425/// FilterOptions {
426///     self_types: ["u32", "{integral}"],
427///     from_desugaring: Some("QuestionMark"),
428///     cause: None,
429///     crate_local: false,
430///     direct: true,
431///     generic_args: [("Self","u32"),
432///         ("R", "core::option::Option<core::convert::Infallible>"),
433///         ("R", "core::option::Option<T>" ),
434///     ],
435/// }
436/// ```
437#[derive(#[automatically_derived]
impl ::core::fmt::Debug for FilterOptions {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        let names: &'static _ =
            &["self_types", "from_desugaring", "cause", "crate_local",
                        "direct", "generic_args"];
        let values: &[&dyn ::core::fmt::Debug] =
            &[&self.self_types, &self.from_desugaring, &self.cause,
                        &self.crate_local, &self.direct, &&self.generic_args];
        ::core::fmt::Formatter::debug_struct_fields_finish(f, "FilterOptions",
            names, values)
    }
}Debug)]
438pub struct FilterOptions {
439    /// All the self types that may apply.
440    pub self_types: Vec<String>,
441    // The kind of compiler desugaring.
442    pub from_desugaring: Option<DesugaringKind>,
443    /// Match on a variant of rustc_infer's `ObligationCauseCode`.
444    pub cause: Option<String>,
445    pub crate_local: bool,
446    /// Is the obligation "directly" user-specified, rather than derived?
447    pub direct: bool,
448    // A list of the generic arguments and their reified types.
449    pub generic_args: Vec<(Symbol, String)>,
450}
451
452impl FilterOptions {
453    pub fn has_flag(&self, name: Flag) -> bool {
454        match name {
455            Flag::CrateLocal => self.crate_local,
456            Flag::Direct => self.direct,
457            Flag::FromDesugaring => self.from_desugaring.is_some(),
458        }
459    }
460    pub fn contains(&self, name: Name, value: String) -> bool {
461        match name {
462            Name::SelfUpper => self.self_types.contains(&value),
463            Name::FromDesugaring => self.from_desugaring.is_some_and(|ds| ds.matches(&value)),
464            Name::Cause => self.cause == Some(value),
465            Name::GenericArg(arg) => self.generic_args.contains(&(arg, value)),
466        }
467    }
468}