Skip to main content

rustc_middle/
lint.rs

1use std::cmp::min;
2
3use rustc_data_structures::fx::FxIndexMap;
4use rustc_data_structures::sorted_map::SortedMap;
5use rustc_errors::{Diag, DiagLocation, Diagnostic, MultiSpan};
6use rustc_hir::{HirId, ItemLocalId};
7use rustc_lint_defs::{
8    EditionFcw, FutureIncompatibilityReason, Level, Lint, LintExpectationId, LintId,
9    StableLintExpectationId, UnstableLintExpectationId, builtin,
10};
11use rustc_macros::{Decodable, Encodable, StableHash};
12use rustc_session::Session;
13use rustc_span::{DUMMY_SP, ExpnKind, Span, Symbol, kw};
14use tracing::instrument;
15
16use crate::ty::TyCtxt;
17
18/// How a lint level was set.
19#[derive(#[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for LintLevelSource { }
#[automatically_derived]
impl ::core::clone::Clone for LintLevelSource {
    #[inline]
    fn clone(&self) -> LintLevelSource {
        let _: ::core::clone::AssertParamIsClone<Symbol>;
        let _: ::core::clone::AssertParamIsClone<Span>;
        let _: ::core::clone::AssertParamIsClone<Option<Symbol>>;
        let _: ::core::clone::AssertParamIsClone<Level>;
        *self
    }
}Clone, #[automatically_derived]
impl ::core::marker::Copy for LintLevelSource { }Copy, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for LintLevelSource { }
#[automatically_derived]
impl ::core::cmp::PartialEq for LintLevelSource {
    #[inline]
    fn eq(&self, other: &LintLevelSource) -> bool {
        let __self_discr = ::core::intrinsics::discriminant_value(self);
        let __arg1_discr = ::core::intrinsics::discriminant_value(other);
        __self_discr == __arg1_discr &&
            match (self, other) {
                (LintLevelSource::Node {
                    name: __self_0, span: __self_1, reason: __self_2 },
                    LintLevelSource::Node {
                    name: __arg1_0, span: __arg1_1, reason: __arg1_2 }) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1 &&
                        __self_2 == __arg1_2,
                (LintLevelSource::CommandLine(__self_0, __self_1),
                    LintLevelSource::CommandLine(__arg1_0, __arg1_1)) =>
                    __self_0 == __arg1_0 && __self_1 == __arg1_1,
                _ => true,
            }
    }
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for LintLevelSource {
    #[inline]
    #[doc(hidden)]
    #[coverage(off)]
    fn assert_fields_are_eq(&self) {
        let _: ::core::cmp::AssertParamIsEq<Symbol>;
        let _: ::core::cmp::AssertParamIsEq<Span>;
        let _: ::core::cmp::AssertParamIsEq<Option<Symbol>>;
        let _: ::core::cmp::AssertParamIsEq<Level>;
    }
}Eq, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for LintLevelSource {
            fn encode(&self, __encoder: &mut __E) {
                let disc =
                    match *self {
                        LintLevelSource::Default => { 0usize }
                        LintLevelSource::Node {
                            name: ref __binding_0,
                            span: ref __binding_1,
                            reason: ref __binding_2 } => {
                            1usize
                        }
                        LintLevelSource::CommandLine(ref __binding_0,
                            ref __binding_1) => {
                            2usize
                        }
                    };
                ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
                match *self {
                    LintLevelSource::Default => {}
                    LintLevelSource::Node {
                        name: ref __binding_0,
                        span: ref __binding_1,
                        reason: 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);
                    }
                    LintLevelSource::CommandLine(ref __binding_0,
                        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 LintLevelSource {
            fn decode(__decoder: &mut __D) -> Self {
                match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
                    {
                    0usize => { LintLevelSource::Default }
                    1usize => {
                        LintLevelSource::Node {
                            name: ::rustc_serialize::Decodable::decode(__decoder),
                            span: ::rustc_serialize::Decodable::decode(__decoder),
                            reason: ::rustc_serialize::Decodable::decode(__decoder),
                        }
                    }
                    2usize => {
                        LintLevelSource::CommandLine(::rustc_serialize::Decodable::decode(__decoder),
                            ::rustc_serialize::Decodable::decode(__decoder))
                    }
                    n => {
                        ::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `LintLevelSource`, expected 0..3, actual {0}",
                                n));
                    }
                }
            }
        }
    };Decodable, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            LintLevelSource {
            #[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 {
                    LintLevelSource::Default => {}
                    LintLevelSource::Node {
                        name: ref __binding_0,
                        span: ref __binding_1,
                        reason: ref __binding_2 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                    }
                    LintLevelSource::CommandLine(ref __binding_0,
                        ref __binding_1) => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, #[automatically_derived]
impl ::core::fmt::Debug for LintLevelSource {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            LintLevelSource::Default =>
                ::core::fmt::Formatter::write_str(f, "Default"),
            LintLevelSource::Node {
                name: __self_0, span: __self_1, reason: __self_2 } =>
                ::core::fmt::Formatter::debug_struct_field3_finish(f, "Node",
                    "name", __self_0, "span", __self_1, "reason", &__self_2),
            LintLevelSource::CommandLine(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f,
                    "CommandLine", __self_0, &__self_1),
        }
    }
}Debug)]
20pub enum LintLevelSource {
21    /// Lint is at the default level as declared in rustc.
22    Default,
23
24    /// Lint level was set by an attribute.
25    Node {
26        name: Symbol,
27        span: Span,
28        /// RFC 2383 reason
29        reason: Option<Symbol>,
30    },
31
32    /// Lint level was set by a command-line flag.
33    /// The provided `Level` is the level specified on the command line.
34    /// (The actual level may be lower due to `--cap-lints`.)
35    CommandLine(Symbol, Level),
36}
37
38impl LintLevelSource {
39    pub fn name(&self) -> Symbol {
40        match *self {
41            LintLevelSource::Default => kw::Default,
42            LintLevelSource::Node { name, .. } => name,
43            LintLevelSource::CommandLine(name, _) => name,
44        }
45    }
46
47    pub fn span(&self) -> Span {
48        match *self {
49            LintLevelSource::Default => DUMMY_SP,
50            LintLevelSource::Node { span, .. } => span,
51            LintLevelSource::CommandLine(_, _) => DUMMY_SP,
52        }
53    }
54}
55
56/// Convenience helper for things that are frequently used together.
57#[derive(#[automatically_derived]
impl<Id: ::core::marker::Copy> ::core::marker::Copy for LevelSpec<Id> { }Copy, #[automatically_derived]
impl<Id: ::core::clone::Clone> ::core::clone::Clone for LevelSpec<Id> {
    #[inline]
    fn clone(&self) -> LevelSpec<Id> {
        LevelSpec {
            level: ::core::clone::Clone::clone(&self.level),
            lint_id: ::core::clone::Clone::clone(&self.lint_id),
            src: ::core::clone::Clone::clone(&self.src),
        }
    }
}Clone, #[automatically_derived]
impl<Id: ::core::fmt::Debug> ::core::fmt::Debug for LevelSpec<Id> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f, "LevelSpec",
            "level", &self.level, "lint_id", &self.lint_id, "src", &&self.src)
    }
}Debug, const _: () =
    {
        impl<Id> ::rustc_data_structures::stable_hash::StableHash for
            LevelSpec<Id> where
            Id: ::rustc_data_structures::stable_hash::StableHash {
            #[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 {
                    LevelSpec {
                        level: ref __binding_0,
                        lint_id: ref __binding_1,
                        src: ref __binding_2 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash, const _: () =
    {
        impl<Id, __E: ::rustc_span::SpanEncoder>
            ::rustc_serialize::Encodable<__E> for LevelSpec<Id> where
            Id: ::rustc_serialize::Encodable<__E> {
            fn encode(&self, __encoder: &mut __E) {
                let LevelSpec {
                        level: ref __binding_0,
                        lint_id: ref __binding_1,
                        src: ref __binding_2 } = *self;
                ::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<Id, __D: ::rustc_span::SpanDecoder>
            ::rustc_serialize::Decodable<__D> for LevelSpec<Id> where
            Id: ::rustc_serialize::Decodable<__D> {
            fn decode(__decoder: &mut __D) -> Self {
                LevelSpec {
                    level: ::rustc_serialize::Decodable::decode(__decoder),
                    lint_id: ::rustc_serialize::Decodable::decode(__decoder),
                    src: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable)]
58pub struct LevelSpec<Id = LintExpectationId> {
59    // This field *must* be private. It must be set in tandem with `lint_id`, only in
60    // `LevelSpec::new`, because only certain `level`/`lint_id` combinations are valid. See
61    // `LevelSpec::new` for those combinations.
62    //
63    // If you are thinking right now that `level` and `lint_id` should be combined into a single
64    // type that excludes the invalid combinations, that's a reasonable thought, but in practice
65    // it's painful because `level` needs to be used by itself, without `lint_id`, in many places.
66    // Making the fields private prevents invalid combinations while retaining the flexibility of
67    // two separate fields.
68    level: Level,
69
70    // This field *must* be private. See the comment on `level`.
71    lint_id: Option<Id>,
72
73    pub src: LintLevelSource,
74}
75
76pub type UnstableLevelSpec = LevelSpec<UnstableLintExpectationId>;
77pub type StableLevelSpec = LevelSpec<StableLintExpectationId>;
78
79impl<Id: Copy> LevelSpec<Id> {
80    // Panics if an invalid `level`/`lint_id` combination is given.
81    pub fn new(level: Level, lint_id: Option<Id>, src: LintLevelSource) -> LevelSpec<Id> {
82        match (level, lint_id) {
83            (Level::Allow | Level::Warn | Level::Deny | Level::Forbid, None) => {}
84            (Level::Expect, Some(_)) => {}
85            (Level::ForceWarn, _) => {}
86            _ => {
    ::core::panicking::panic_fmt(format_args!("invalid level/lint_id combination"));
}panic!("invalid level/lint_id combination"),
87        }
88        LevelSpec { level, lint_id, src }
89    }
90
91    pub fn level(self) -> Level {
92        self.level
93    }
94
95    pub fn is_allow(self) -> bool {
96        self.level == Level::Allow
97    }
98
99    pub fn is_expect(self) -> bool {
100        self.level == Level::Expect
101    }
102
103    pub fn lint_id(self) -> Option<Id> {
104        self.lint_id
105    }
106}
107
108impl From<UnstableLevelSpec> for LevelSpec {
109    fn from(level: UnstableLevelSpec) -> LevelSpec {
110        let LevelSpec { level, lint_id, src } = level;
111        let lint_id = lint_id.map(LintExpectationId::Unstable);
112        LevelSpec { level, lint_id, src }
113    }
114}
115
116impl From<StableLevelSpec> for LevelSpec {
117    fn from(level: StableLevelSpec) -> LevelSpec {
118        let LevelSpec { level, lint_id, src } = level;
119        let lint_id = lint_id.map(LintExpectationId::Stable);
120        LevelSpec { level, lint_id, src }
121    }
122}
123
124/// Return type for the `shallow_lint_levels_on` query.
125///
126/// This map represents lints levels given by the attributes for *a single HirId*.
127#[derive(#[automatically_derived]
impl ::core::default::Default for ShallowLintLevelMap {
    #[inline]
    fn default() -> ShallowLintLevelMap {
        ShallowLintLevelMap {
            specs: ::core::default::Default::default(),
            expectations: ::core::default::Default::default(),
        }
    }
}Default, #[automatically_derived]
impl ::core::fmt::Debug for ShallowLintLevelMap {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f,
            "ShallowLintLevelMap", "specs", &self.specs, "expectations",
            &&self.expectations)
    }
}Debug, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            ShallowLintLevelMap {
            #[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 {
                    ShallowLintLevelMap {
                        specs: ref __binding_0, expectations: ref __binding_1 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
128pub struct ShallowLintLevelMap {
129    // All the specs for this HirId. This is accessed frequently, e.g. for every lint emitted.
130    pub specs: SortedMap<ItemLocalId, FxIndexMap<LintId, StableLevelSpec>>,
131
132    // Additional information about the `expect` specs for this HirId. This is consulted only once
133    // per compilation session, in `check_expectations`/`lint_expectations`.
134    pub expectations: Vec<(StableLintExpectationId, LintExpectation)>,
135}
136
137/// Verify the effect of special annotations: `warnings` lint level and lint caps.
138///
139/// The return of this function is suitable for diagnostics.
140pub fn reveal_actual_level_spec<Id: Copy>(
141    sess: &Session,
142    lint: LintId,
143    probe_for_lint_level_spec: impl Fn(LintId) -> Option<LevelSpec<Id>>,
144) -> LevelSpec<Id> {
145    let level_spec = probe_for_lint_level_spec(lint);
146
147    // If `level` is none then we actually assume the default level for this lint.
148    let mut level_spec = level_spec.unwrap_or_else(|| {
149        LevelSpec::new(lint.lint.default_level(sess.edition()), None, LintLevelSource::Default)
150    });
151
152    // If we're about to issue a warning, check at the last minute for any
153    // directives against the `warnings` lint group. If, for example, there's an
154    // `allow(warnings)` in scope then we want to respect that instead.
155    if level_spec.level == Level::Warn {
156        if let Some(configured_level_spec) =
157            probe_for_lint_level_spec(LintId::of(builtin::WARNINGS))
158        {
159            let respect_warnings_lint_group = match configured_level_spec.level {
160                // -Wwarnings is a no-op.
161                Level::Warn => false,
162                // Some warnings cannot be denied from the `warnings` lint group, only individually.
163                Level::Deny | Level::Forbid => !lint.lint.ignore_deny_warnings,
164                // All warnings respect -Awarnings.
165                Level::Allow => true,
166                // Not sure what the right behavior is here, but, sure, why not.
167                // See tests/ui/lint/rfc-2383-lint-reason/expect_warnings.rs.
168                Level::Expect => true,
169                Level::ForceWarn => {
170                    sess.dcx().span_delayed_bug(
171                        configured_level_spec.src.span(),
172                        "cannot --force-warn the `warnings` lint group",
173                    );
174                    false
175                }
176            };
177            if respect_warnings_lint_group {
178                level_spec = configured_level_spec;
179            }
180        }
181    }
182
183    // Ensure that we never exceed the `--cap-lints` argument unless the source is a --force-warn
184    if !#[allow(non_exhaustive_omitted_patterns)] match level_spec.src {
    LintLevelSource::CommandLine(_, Level::ForceWarn) => true,
    _ => false,
}matches!(level_spec.src, LintLevelSource::CommandLine(_, Level::ForceWarn)) {
185        level_spec.level = min(level_spec.level, sess.opts.lint_cap.unwrap_or(Level::Forbid));
186    };
187
188    // Ensure that we never exceed driver level.
189    if let Some(driver_level) = sess.driver_lint_caps.get(&lint) {
190        level_spec.level = min(level_spec.level, *driver_level);
191    }
192
193    level_spec
194}
195
196impl ShallowLintLevelMap {
197    /// Perform a deep probe in the HIR tree looking for the actual level spec for the lint.
198    /// This lint level spec is not usable for diagnostics, it needs to be corrected by
199    /// `reveal_actual_level` beforehand.
200    {}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::TRACE <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("probe_for_lint_level_spec",
                                "rustc_middle::lint", ::tracing::Level::TRACE,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/lint.rs"),
                                ::tracing_core::__macro_support::Option::Some(200u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_middle::lint"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("id")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("id");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("start")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("start");
                                                    NAME.as_str()
                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::TRACE <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::TRACE <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&start)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return: Option<StableLevelSpec> =
                            loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        if let Some(map) = self.specs.get(&start.local_id) &&
                                let Some(level_spec) = map.get(&id) {
                            return Some(*level_spec);
                        }
                        let mut owner = start.owner;
                        let mut specs = &self.specs;
                        for parent in tcx.hir_parent_id_iter(start) {
                            if parent.owner != owner {
                                owner = parent.owner;
                                specs = &tcx.shallow_lint_levels_on(owner).specs;
                            }
                            if let Some(map) = specs.get(&parent.local_id) &&
                                    let Some(level_spec) = map.get(&id) {
                                return Some(*level_spec);
                            }
                        }
                        None
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/lint.rs:200",
                        "rustc_middle::lint", ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/lint.rs"),
                        ::tracing_core::__macro_support::Option::Some(200u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_middle::lint"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "trace", skip(self, tcx), ret)]
201    fn probe_for_lint_level_spec(
202        &self,
203        tcx: TyCtxt<'_>,
204        id: LintId,
205        start: HirId,
206    ) -> Option<StableLevelSpec> {
207        if let Some(map) = self.specs.get(&start.local_id)
208            && let Some(level_spec) = map.get(&id)
209        {
210            return Some(*level_spec);
211        }
212
213        let mut owner = start.owner;
214        let mut specs = &self.specs;
215
216        for parent in tcx.hir_parent_id_iter(start) {
217            if parent.owner != owner {
218                owner = parent.owner;
219                specs = &tcx.shallow_lint_levels_on(owner).specs;
220            }
221            if let Some(map) = specs.get(&parent.local_id)
222                && let Some(level_spec) = map.get(&id)
223            {
224                return Some(*level_spec);
225            }
226        }
227
228        None
229    }
230
231    /// Fetch and return the user-visible lint level spec for the given lint at the given HirId.
232    {}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::TRACE <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("lint_level_spec_at_node",
                                "rustc_middle::lint", ::tracing::Level::TRACE,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/lint.rs"),
                                ::tracing_core::__macro_support::Option::Some(232u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_middle::lint"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("lint")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("lint");
                                                    NAME.as_str()
                                                },
                                                {
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("cur")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("cur");
                                                    NAME.as_str()
                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::TRACE <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::TRACE <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&lint)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&cur)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return: StableLevelSpec = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        reveal_actual_level_spec(tcx.sess, lint,
                            |lint| { self.probe_for_lint_level_spec(tcx, lint, cur) })
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/lint.rs:232",
                        "rustc_middle::lint", ::tracing::Level::TRACE,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/cea272fa356e94bd2ee2cadf376630aa0683867a/compiler/rustc_middle/src/lint.rs"),
                        ::tracing_core::__macro_support::Option::Some(232u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_middle::lint"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "trace", skip(self, tcx), ret)]
233    pub fn lint_level_spec_at_node(
234        &self,
235        tcx: TyCtxt<'_>,
236        lint: LintId,
237        cur: HirId,
238    ) -> StableLevelSpec {
239        reveal_actual_level_spec(tcx.sess, lint, |lint| {
240            self.probe_for_lint_level_spec(tcx, lint, cur)
241        })
242    }
243}
244
245impl TyCtxt<'_> {
246    /// Fetch and return the user-visible lint level spec for the given lint at the given HirId.
247    pub fn lint_level_spec_at_node(self, lint: &'static Lint, id: HirId) -> StableLevelSpec {
248        self.shallow_lint_levels_on(id.owner).lint_level_spec_at_node(self, LintId::of(lint), id)
249    }
250}
251
252/// This struct represents a lint expectation and holds all required information
253/// to emit the `unfulfilled_lint_expectations` lint if it is unfulfilled after
254/// the `LateLintPass` has completed.
255#[derive(#[automatically_derived]
impl ::core::clone::Clone for LintExpectation {
    #[inline]
    fn clone(&self) -> LintExpectation {
        LintExpectation {
            reason: ::core::clone::Clone::clone(&self.reason),
            emission_span: ::core::clone::Clone::clone(&self.emission_span),
            is_unfulfilled_lint_expectations: ::core::clone::Clone::clone(&self.is_unfulfilled_lint_expectations),
            lint_tool: ::core::clone::Clone::clone(&self.lint_tool),
        }
    }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for LintExpectation {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field4_finish(f,
            "LintExpectation", "reason", &self.reason, "emission_span",
            &self.emission_span, "is_unfulfilled_lint_expectations",
            &self.is_unfulfilled_lint_expectations, "lint_tool",
            &&self.lint_tool)
    }
}Debug, const _: () =
    {
        impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
            for LintExpectation {
            fn encode(&self, __encoder: &mut __E) {
                let LintExpectation {
                        reason: ref __binding_0,
                        emission_span: ref __binding_1,
                        is_unfulfilled_lint_expectations: ref __binding_2,
                        lint_tool: ref __binding_3 } = *self;
                ::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);
            }
        }
    };Encodable, const _: () =
    {
        impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
            for LintExpectation {
            fn decode(__decoder: &mut __D) -> Self {
                LintExpectation {
                    reason: ::rustc_serialize::Decodable::decode(__decoder),
                    emission_span: ::rustc_serialize::Decodable::decode(__decoder),
                    is_unfulfilled_lint_expectations: ::rustc_serialize::Decodable::decode(__decoder),
                    lint_tool: ::rustc_serialize::Decodable::decode(__decoder),
                }
            }
        }
    };Decodable, const _: () =
    {
        impl ::rustc_data_structures::stable_hash::StableHash for
            LintExpectation {
            #[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 {
                    LintExpectation {
                        reason: ref __binding_0,
                        emission_span: ref __binding_1,
                        is_unfulfilled_lint_expectations: ref __binding_2,
                        lint_tool: ref __binding_3 } => {
                        { __binding_0.stable_hash(__hcx, __hasher); }
                        { __binding_1.stable_hash(__hcx, __hasher); }
                        { __binding_2.stable_hash(__hcx, __hasher); }
                        { __binding_3.stable_hash(__hcx, __hasher); }
                    }
                }
            }
        }
    };StableHash)]
256pub struct LintExpectation {
257    /// The reason for this expectation that can optionally be added as part of
258    /// the attribute. It will be displayed as part of the lint message.
259    pub reason: Option<Symbol>,
260    /// The [`Span`] of the attribute that this expectation originated from.
261    pub emission_span: Span,
262    /// Lint messages for the `unfulfilled_lint_expectations` lint will be
263    /// adjusted to include an additional note. Therefore, we have to track if
264    /// the expectation is for the lint.
265    pub is_unfulfilled_lint_expectations: bool,
266    /// This will hold the name of the tool that this lint belongs to. For
267    /// the lint `clippy::some_lint` the tool would be `clippy`, the same
268    /// goes for `rustdoc`. This will be `None` for rustc lints
269    pub lint_tool: Option<Symbol>,
270}
271
272impl LintExpectation {
273    pub fn new(
274        reason: Option<Symbol>,
275        emission_span: Span,
276        is_unfulfilled_lint_expectations: bool,
277        lint_tool: Option<Symbol>,
278    ) -> Self {
279        Self { reason, emission_span, is_unfulfilled_lint_expectations, lint_tool }
280    }
281}
282
283fn explain_lint_level_source(
284    sess: &Session,
285    lint: &'static Lint,
286    level: Level,
287    src: LintLevelSource,
288    err: &mut Diag<'_, ()>,
289) {
290    // Find the name of the lint group that contains the given lint.
291    // Assumes the lint only belongs to one group.
292    let lint_group_name = |lint| {
293        let lint_groups_iter = sess.lint_groups_iter();
294        let lint_id = LintId::of(lint);
295        lint_groups_iter
296            .filter(|lint_group| !lint_group.is_externally_loaded)
297            .find(|lint_group| {
298                lint_group
299                    .lints
300                    .iter()
301                    .find(|lint_group_lint| **lint_group_lint == lint_id)
302                    .is_some()
303            })
304            .map(|lint_group| lint_group.name)
305    };
306    let name = lint.name_lower();
307    if let Level::Allow = level {
308        // Do not point at `#[allow(compat_lint)]` as the reason for a compatibility lint
309        // triggering. (#121009)
310        return;
311    }
312    match src {
313        LintLevelSource::Default => {
314            let level_str = level.as_str();
315            match lint_group_name(lint) {
316                Some(group_name) => {
317                    err.note_once(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("`#[{0}({1})]` (part of `#[{0}({2})]`) on by default",
                level_str, name, group_name))
    })format!("`#[{level_str}({name})]` (part of `#[{level_str}({group_name})]`) on by default"));
318                }
319                None => {
320                    err.note_once(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("`#[{0}({1})]` on by default",
                level_str, name))
    })format!("`#[{level_str}({name})]` on by default"));
321                }
322            }
323        }
324        LintLevelSource::CommandLine(lint_flag_val, orig_level) => {
325            let flag = orig_level.to_cmd_flag();
326            let hyphen_case_lint_name = name.replace('_', "-");
327            if lint_flag_val.as_str() == name {
328                err.note_once(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("requested on the command line with `{0} {1}`",
                flag, hyphen_case_lint_name))
    })format!(
329                    "requested on the command line with `{flag} {hyphen_case_lint_name}`"
330                ));
331            } else {
332                let hyphen_case_flag_val = lint_flag_val.as_str().replace('_', "-");
333                err.note_once(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("`{0} {1}` implied by `{0} {2}`",
                flag, hyphen_case_lint_name, hyphen_case_flag_val))
    })format!(
334                    "`{flag} {hyphen_case_lint_name}` implied by `{flag} {hyphen_case_flag_val}`"
335                ));
336                if #[allow(non_exhaustive_omitted_patterns)] match orig_level {
    Level::Warn | Level::Deny => true,
    _ => false,
}matches!(orig_level, Level::Warn | Level::Deny) {
337                    let help = if name == "dead_code" {
338                        ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("to override `{0} {1}` add `#[expect({2})]` or `#[allow({2})]`",
                flag, hyphen_case_flag_val, name))
    })format!(
339                            "to override `{flag} {hyphen_case_flag_val}` add `#[expect({name})]` or `#[allow({name})]`"
340                        )
341                    } else {
342                        ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("to override `{0} {1}` add `#[allow({2})]`",
                flag, hyphen_case_flag_val, name))
    })format!(
343                            "to override `{flag} {hyphen_case_flag_val}` add `#[allow({name})]`"
344                        )
345                    };
346                    err.help_once(help);
347                }
348            }
349        }
350        LintLevelSource::Node { name: lint_attr_name, span, reason, .. } => {
351            if let Some(rationale) = reason {
352                err.note(rationale.to_string());
353            }
354            err.span_note_once(span, "the lint level is defined here");
355            if lint_attr_name.as_str() != name {
356                let level_str = level.as_str();
357                err.note_once(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("`#[{0}({1})]` implied by `#[{0}({2})]`",
                level_str, name, lint_attr_name))
    })format!(
358                    "`#[{level_str}({name})]` implied by `#[{level_str}({lint_attr_name})]`"
359                ));
360            }
361        }
362    }
363
364    if let Some(warnings_group) = sess
365        .opts
366        .lint_opts
367        .iter()
368        .find_map(|(opt, level)| (opt == "warnings").then_some(level))
369        .copied()
370        && warnings_group >= Level::Deny
371        && level < warnings_group
372    {
373        err.note_once(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("the `{0}` lint ignores `-D warnings`",
                name))
    })format!("the `{name}` lint ignores `-D warnings`"));
374    }
375}
376
377/// The innermost function for emitting lints implementing the [`trait@Diagnostic`] trait.
378///
379/// If you are looking to implement a lint, look for higher level functions,
380/// for example:
381///
382/// - [`TyCtxt::emit_node_span_lint`]
383/// - `LintContext::opt_span_lint`
384#[track_caller]
385pub fn emit_lint_base<'a, D: Diagnostic<'a, ()> + 'a>(
386    sess: &'a Session,
387    lint: &'static Lint,
388    level_spec: impl Into<LevelSpec>,
389    span: Option<MultiSpan>,
390    decorate: D,
391) {
392    // Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to
393    // the "real" work.
394    #[track_caller]
395    fn emit_lint_base_impl<'a>(
396        sess: &'a Session,
397        lint: &'static Lint,
398        level_spec: LevelSpec,
399        span: Option<MultiSpan>,
400        decorate: Box<
401            dyn FnOnce(rustc_errors::DiagCtxtHandle<'a>, rustc_errors::Level) -> Diag<'a, ()> + 'a,
402        >,
403    ) {
404        let LevelSpec { level, lint_id, src } = level_spec;
405
406        // Check for future incompatibility lints and issue a stronger warning.
407        let future_incompatible = lint.future_incompatible;
408
409        let has_future_breakage = future_incompatible.map_or(
410            // Default allow lints trigger too often for testing.
411            sess.opts.unstable_opts.future_incompat_test && lint.default_level != Level::Allow,
412            |incompat| incompat.report_in_deps,
413        );
414
415        // Convert lint level to error level.
416        let err_level = match level {
417            Level::Allow => {
418                if has_future_breakage {
419                    rustc_errors::Level::Allow
420                } else {
421                    return;
422                }
423            }
424            Level::Expect => {
425                // This case is special as we actually allow the lint itself in this context, but
426                // we can't return early like in the case for `Level::Allow` because we still
427                // need the lint diagnostic to be emitted to `rustc_error::DiagCtxtInner`.
428                //
429                // We can also not mark the lint expectation as fulfilled here right away, as it
430                // can still be cancelled in the decorate function. All of this means that we simply
431                // create a `Diag` and continue as we would for warnings.
432                rustc_errors::Level::Expect
433            }
434            Level::ForceWarn => rustc_errors::Level::ForceWarning,
435            Level::Warn => rustc_errors::Level::Warning,
436            Level::Deny | Level::Forbid => rustc_errors::Level::Error,
437        };
438
439        let disable_suggestions = if let Some(ref span) = span
440            // If this code originates in a foreign macro, aka something that this crate
441            // did not itself author, then it's likely that there's nothing this crate
442            // can do about it. We probably want to skip the lint entirely.
443            && span.primary_spans().iter().any(|s| s.in_external_macro(sess.source_map()))
444        {
445            true
446        } else {
447            false
448        };
449
450        if disable_suggestions {
451            // If this is a future incompatible that is not an edition fixing lint
452            // it'll become a hard error, so we have to emit *something*. Also,
453            // if this lint occurs in the expansion of a macro from an external crate,
454            // allow individual lints to opt-out from being reported.
455            let incompatible = future_incompatible.is_some_and(|f| f.reason.edition().is_none());
456
457            // In rustc, for the find_attr macro, we want to always emit this.
458            // This completely circumvents normal lint checking, which usually doesn't happen for macros from other crates.
459            // However, we kind of want that when using find_attr from another rustc crate. So we cheat a little.
460            let is_in_find_attr = sess.enable_internal_lints()
461                && span.as_ref().is_some_and(|span| {
462                    span.primary_spans().iter().any(|s| {
463                        s.source_callee().is_some_and(|i| {
464                            #[allow(non_exhaustive_omitted_patterns)] match i.kind {
    ExpnKind::Macro(_, name) if name.as_str() == "find_attr" => true,
    _ => false,
}matches!(i.kind, ExpnKind::Macro(_, name) if name.as_str() == "find_attr")
465                        })
466                    })
467                });
468
469            if !incompatible && !lint.report_in_external_macro && !is_in_find_attr {
470                // Don't continue further, since we don't want to have
471                // `diag_span_note_once` called for a diagnostic that isn't emitted.
472                return;
473            }
474        }
475        // Finally, run `decorate`. `decorate` can call `trimmed_path_str` (directly or indirectly),
476        // so we need to make sure when we do call `decorate` that the diagnostic is eventually
477        // emitted or we'll get a `must_produce_diag` ICE.
478        //
479        // When is a diagnostic *eventually* emitted? Well, that is determined by 2 factors:
480        // 1. If the corresponding `rustc_errors::Level` is beyond warning, i.e. `ForceWarning(_)`
481        //    or `Error`, then the diagnostic will be emitted regardless of CLI options.
482        // 2. If the corresponding `rustc_errors::Level` is warning, then that can be affected by
483        //    `-A warnings` or `--cap-lints=xxx` on the command line. In which case, the diagnostic
484        //    will be emitted if `can_emit_warnings` is true.
485        let skip = err_level == rustc_errors::Level::Warning && !sess.dcx().can_emit_warnings();
486
487        let mut err: Diag<'_, ()> = if !skip {
488            decorate(sess.dcx(), err_level)
489        } else {
490            Diag::new(sess.dcx(), err_level, "")
491        };
492        // FIXME: Find a nicer way to expose the `DiagLocation`
493        err.emitted_at = DiagLocation::caller();
494
495        if let Some(span) = span
496            && err.span.primary_span().is_none()
497        {
498            // We can't use `err.span()` because it overwrites the labels, so we need to do it manually.
499            for primary in span.primary_spans() {
500                err.span.push_primary_span(*primary);
501            }
502            for (label_span, label) in span.span_labels_raw() {
503                err.span.push_span_diag(*label_span, label.clone());
504            }
505        }
506        if let Some(lint_id) = lint_id {
507            err.lint_id(lint_id);
508        }
509
510        if disable_suggestions {
511            // Any suggestions made here are likely to be incorrect, so anything we
512            // emit shouldn't be automatically fixed by rustfix.
513            err.disable_suggestions();
514        }
515
516        err.is_lint(lint.name_lower(), has_future_breakage, lint.rust_version);
517        // Lint diagnostics that are covered by the expect level will not be emitted outside
518        // the compiler. It is therefore not necessary to add any information for the user.
519        // This will therefore directly call the decorate function which will in turn emit
520        // the diagnostic.
521        if let Level::Expect = level {
522            err.emit();
523            return;
524        }
525
526        if let Some(future_incompatible) = future_incompatible {
527            let explanation = match future_incompatible.reason {
528                FutureIncompatibilityReason::FutureReleaseError(_) => {
529                    "this was previously accepted by the compiler but is being phased out; \
530                         it will become a hard error in a future release!"
531                        .to_owned()
532                }
533                FutureIncompatibilityReason::FutureReleaseSemanticsChange(_) => {
534                    "this will change its meaning in a future release!".to_owned()
535                }
536                FutureIncompatibilityReason::EditionError(EditionFcw { edition, .. }) => {
537                    let current_edition = sess.edition();
538                    ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("this is accepted in the current edition (Rust {0}) but is a hard error in Rust {1}!",
                current_edition, edition))
    })format!(
539                        "this is accepted in the current edition (Rust {current_edition}) but is a hard error in Rust {edition}!"
540                    )
541                }
542                FutureIncompatibilityReason::EditionSemanticsChange(EditionFcw {
543                    edition, ..
544                }) => {
545                    ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("this changes meaning in Rust {0}",
                edition))
    })format!("this changes meaning in Rust {edition}")
546                }
547                FutureIncompatibilityReason::EditionAndFutureReleaseError(EditionFcw {
548                    edition,
549                    ..
550                }) => {
551                    ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("this was previously accepted by the compiler but is being phased out; it will become a hard error in Rust {0} and in a future release in all editions!",
                edition))
    })format!(
552                        "this was previously accepted by the compiler but is being phased out; \
553                         it will become a hard error in Rust {edition} and in a future release in all editions!"
554                    )
555                }
556                FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(
557                    EditionFcw { edition, .. },
558                ) => {
559                    ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("this changes meaning in Rust {0} and in a future release in all editions!",
                edition))
    })format!(
560                        "this changes meaning in Rust {edition} and in a future release in all editions!"
561                    )
562                }
563                FutureIncompatibilityReason::Custom(reason, _) => reason.to_owned(),
564                FutureIncompatibilityReason::Unreachable => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
565            };
566
567            if future_incompatible.explain_reason {
568                err.warn(explanation);
569            }
570
571            let citation =
572                ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("for more information, see {0}",
                future_incompatible.reason.reference()))
    })format!("for more information, see {}", future_incompatible.reason.reference());
573            err.note(citation);
574        }
575
576        explain_lint_level_source(sess, lint, level, src, &mut err);
577        err.emit();
578    }
579    emit_lint_base_impl(
580        sess,
581        lint,
582        level_spec.into(),
583        span,
584        Box::new(move |dcx, level| decorate.into_diag(dcx, level)),
585    );
586}