Skip to main content

rustc_lint/
context.rs

1//! Basic types for managing and implementing lints.
2//!
3//! See <https://rustc-dev-guide.rust-lang.org/diagnostics.html> for an
4//! overview of how lints are implemented.
5
6use std::cell::Cell;
7use std::slice;
8
9use rustc_abi as abi;
10use rustc_ast::BindingMode;
11use rustc_ast::util::parser::ExprPrecedence;
12use rustc_data_structures::fx::FxIndexMap;
13use rustc_data_structures::sync;
14use rustc_data_structures::unord::UnordMap;
15use rustc_errors::{Diagnostic, LintBuffer, MultiSpan};
16use rustc_feature::Features;
17use rustc_hir as hir;
18use rustc_hir::def::Res;
19use rustc_hir::def_id::{CrateNum, DefId};
20use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
21use rustc_hir::{Pat, PatKind};
22use rustc_middle::bug;
23use rustc_middle::lint::{LevelSpec, StableLevelSpec, UnstableLevelSpec};
24use rustc_middle::middle::privacy::EffectiveVisibilities;
25use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
26use rustc_middle::ty::print::{PrintError, PrintTraitRefExt as _, Printer, with_no_trimmed_paths};
27use rustc_middle::ty::{
28    self, GenericArg, RegisteredTools, Ty, TyCtxt, TypingEnv, TypingMode, Unnormalized,
29};
30use rustc_session::lint::{
31    FutureIncompatibleInfo, Lint, LintExpectationId, LintId, StableLintExpectationId,
32    UnstableLintExpectationId,
33};
34use rustc_session::{DynLintStore, Session};
35use rustc_span::edit_distance::find_best_match_for_names;
36use rustc_span::{Ident, Span, Symbol, sym};
37use tracing::debug;
38
39use self::TargetLint::*;
40use crate::levels::LintLevelsBuilder;
41use crate::passes::{EarlyLintPassObject, LateLintPassObject};
42
43pub(crate) type EarlyLintPassFactory =
44    Box<dyn Fn() -> EarlyLintPassObject + sync::DynSend + sync::DynSync>;
45type LateLintPassFactory =
46    Box<dyn for<'tcx> Fn(TyCtxt<'tcx>) -> LateLintPassObject<'tcx> + sync::DynSend + sync::DynSync>;
47
48/// Information about the registered lints.
49pub struct LintStore {
50    /// Registered lints.
51    lints: Vec<&'static Lint>,
52
53    /// Constructor functions for each variety of lint pass.
54    ///
55    /// These should only be called once, but since we want to avoid locks or
56    /// interior mutability, we don't enforce this (and lints should, in theory,
57    /// be compatible with being constructed more than once, though not
58    /// necessarily in a sane manner. This is safe though.)
59    pub pre_expansion_passes: Vec<EarlyLintPassFactory>,
60    pub early_passes: Vec<EarlyLintPassFactory>,
61    pub late_passes: Vec<LateLintPassFactory>,
62    /// This is unique in that we construct them per-module, so not once.
63    pub late_module_passes: Vec<LateLintPassFactory>,
64
65    /// Lints indexed by name.
66    by_name: UnordMap<String, TargetLint>,
67
68    /// Map of registered lint groups to what lints they expand to.
69    lint_groups: FxIndexMap<&'static str, LintGroup>,
70}
71
72impl DynLintStore for LintStore {
73    fn lint_groups_iter(&self) -> Box<dyn Iterator<Item = rustc_session::LintGroup> + '_> {
74        Box::new(self.get_lint_groups().map(|(name, lints, is_externally_loaded)| {
75            rustc_session::LintGroup { name, lints, is_externally_loaded }
76        }))
77    }
78}
79
80/// The target of the `by_name` map, which accounts for renaming/deprecation.
81#[derive(#[automatically_derived]
impl ::core::fmt::Debug for TargetLint {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            TargetLint::Id(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Id",
                    &__self_0),
            TargetLint::Renamed(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f,
                    "Renamed", __self_0, &__self_1),
            TargetLint::Removed(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "Removed", &__self_0),
            TargetLint::Ignored =>
                ::core::fmt::Formatter::write_str(f, "Ignored"),
        }
    }
}Debug)]
82enum TargetLint {
83    /// A direct lint target
84    Id(LintId),
85
86    /// Temporary renaming, used for easing migration pain; see #16545
87    Renamed(String, LintId),
88
89    /// Lint with this name existed previously, but has been removed/deprecated.
90    /// The string argument is the reason for removal.
91    Removed(String),
92
93    /// A lint name that should give no warnings and have no effect.
94    ///
95    /// This is used by rustc to avoid warning about old rustdoc lints before rustdoc registers
96    /// them as tool lints.
97    Ignored,
98}
99
100struct LintAlias {
101    name: &'static str,
102    /// Whether deprecation warnings should be suppressed for this alias.
103    silent: bool,
104}
105
106struct LintGroup {
107    lint_ids: Vec<LintId>,
108    is_externally_loaded: bool,
109    depr: Option<LintAlias>,
110}
111
112#[derive(#[automatically_derived]
impl<'a> ::core::fmt::Debug for CheckLintNameResult<'a> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            CheckLintNameResult::Ok(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "Ok",
                    &__self_0),
            CheckLintNameResult::NoLint(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f, "NoLint",
                    &__self_0),
            CheckLintNameResult::NoTool =>
                ::core::fmt::Formatter::write_str(f, "NoTool"),
            CheckLintNameResult::Renamed(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "Renamed", &__self_0),
            CheckLintNameResult::Removed(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "Removed", &__self_0),
            CheckLintNameResult::Tool(__self_0, __self_1) =>
                ::core::fmt::Formatter::debug_tuple_field2_finish(f, "Tool",
                    __self_0, &__self_1),
            CheckLintNameResult::MissingTool =>
                ::core::fmt::Formatter::write_str(f, "MissingTool"),
        }
    }
}Debug)]
113pub enum CheckLintNameResult<'a> {
114    Ok(&'a [LintId]),
115    /// Lint doesn't exist. Potentially contains a suggestion for a correct lint name.
116    NoLint(Option<(Symbol, bool)>),
117    /// The lint refers to a tool that has not been registered.
118    NoTool,
119    /// The lint has been renamed to a new name.
120    Renamed(String),
121    /// The lint has been removed due to the given reason.
122    Removed(String),
123
124    /// The lint is from a tool. The `LintId` will be returned as if it were a
125    /// rustc lint. The `Option<String>` indicates if the lint has been
126    /// renamed.
127    Tool(&'a [LintId], Option<String>),
128
129    /// The lint is from a tool. Either the lint does not exist in the tool or
130    /// the code was not compiled with the tool and therefore the lint was
131    /// never added to the `LintStore`.
132    MissingTool,
133}
134
135impl LintStore {
136    pub fn new() -> LintStore {
137        LintStore {
138            lints: ::alloc::vec::Vec::new()vec![],
139            pre_expansion_passes: ::alloc::vec::Vec::new()vec![],
140            early_passes: ::alloc::vec::Vec::new()vec![],
141            late_passes: ::alloc::vec::Vec::new()vec![],
142            late_module_passes: ::alloc::vec::Vec::new()vec![],
143            by_name: Default::default(),
144            lint_groups: Default::default(),
145        }
146    }
147
148    pub fn get_lints<'t>(&'t self) -> &'t [&'static Lint] {
149        &self.lints
150    }
151
152    pub fn get_lint_groups(&self) -> impl Iterator<Item = (&'static str, Vec<LintId>, bool)> {
153        self.lint_groups
154            .iter()
155            .filter(|(_, LintGroup { depr, .. })| {
156                // Don't display deprecated lint groups.
157                depr.is_none()
158            })
159            .map(|(k, LintGroup { lint_ids, is_externally_loaded, .. })| {
160                (*k, lint_ids.clone(), *is_externally_loaded)
161            })
162    }
163
164    /// Returns all lint group names, including deprecated/aliased groups
165    pub fn get_all_group_names(&self) -> impl Iterator<Item = &'static str> {
166        self.lint_groups.keys().copied()
167    }
168
169    pub fn register_early_pass(&mut self, pass: EarlyLintPassFactory) {
170        self.early_passes.push(pass);
171    }
172
173    /// This lint pass is softly deprecated. It misses expanded code and has caused a few
174    /// errors in the past. Currently, it is only used in Clippy. New implementations
175    /// should avoid using this interface, as it might be removed in the future.
176    ///
177    /// * See [rust#69838](https://github.com/rust-lang/rust/pull/69838)
178    /// * See [rust-clippy#5518](https://github.com/rust-lang/rust-clippy/pull/5518)
179    pub fn register_pre_expansion_pass(&mut self, pass: EarlyLintPassFactory) {
180        self.pre_expansion_passes.push(pass);
181    }
182
183    pub fn register_late_pass(&mut self, pass: LateLintPassFactory) {
184        self.late_passes.push(pass);
185    }
186
187    pub fn register_late_mod_pass(&mut self, pass: LateLintPassFactory) {
188        self.late_module_passes.push(pass);
189    }
190
191    /// Helper method for register_early/late_pass
192    pub fn register_lints(&mut self, lints: &[&'static Lint]) {
193        for lint in lints {
194            self.lints.push(lint);
195
196            let id = LintId::of(lint);
197            if self.by_name.insert(lint.name_lower(), Id(id)).is_some() {
198                ::rustc_middle::util::bug::bug_fmt(format_args!("duplicate specification of lint {0}",
        lint.name_lower()))bug!("duplicate specification of lint {}", lint.name_lower())
199            }
200
201            if let Some(FutureIncompatibleInfo { reason, .. }) = lint.future_incompatible {
202                if let Some(edition) = reason.edition() {
203                    self.lint_groups
204                        .entry(edition.lint_name())
205                        .or_insert(LintGroup {
206                            lint_ids: ::alloc::vec::Vec::new()vec![],
207                            is_externally_loaded: lint.is_externally_loaded,
208                            depr: None,
209                        })
210                        .lint_ids
211                        .push(id);
212                } else {
213                    // Lints belonging to the `future_incompatible` lint group are lints where a
214                    // future version of rustc will cause existing code to stop compiling.
215                    // Lints tied to an edition don't count because they are opt-in.
216                    self.lint_groups
217                        .entry("future_incompatible")
218                        .or_insert(LintGroup {
219                            lint_ids: ::alloc::vec::Vec::new()vec![],
220                            is_externally_loaded: lint.is_externally_loaded,
221                            depr: None,
222                        })
223                        .lint_ids
224                        .push(id);
225                }
226            }
227        }
228    }
229
230    fn insert_group(&mut self, name: &'static str, group: LintGroup) {
231        let previous = self.lint_groups.insert(name, group);
232        if previous.is_some() {
233            ::rustc_middle::util::bug::bug_fmt(format_args!("group {0:?} already exists",
        name));bug!("group {name:?} already exists");
234        }
235    }
236
237    pub fn register_group_alias(&mut self, group_name: &'static str, alias: &'static str) {
238        let Some(LintGroup { lint_ids, .. }) = self.lint_groups.get(group_name) else {
239            ::rustc_middle::util::bug::bug_fmt(format_args!("group alias {0:?} points to unregistered group {1:?}",
        alias, group_name))bug!("group alias {alias:?} points to unregistered group {group_name:?}")
240        };
241
242        self.insert_group(
243            alias,
244            LintGroup {
245                lint_ids: lint_ids.clone(),
246                is_externally_loaded: false,
247                depr: Some(LintAlias { name: group_name, silent: true }),
248            },
249        );
250    }
251
252    pub fn register_group(
253        &mut self,
254        is_externally_loaded: bool,
255        name: &'static str,
256        deprecated_name: Option<&'static str>,
257        to: Vec<LintId>,
258    ) {
259        if let Some(deprecated) = deprecated_name {
260            self.insert_group(
261                deprecated,
262                LintGroup {
263                    lint_ids: to.clone(),
264                    is_externally_loaded,
265                    depr: Some(LintAlias { name, silent: false }),
266                },
267            );
268        }
269        self.insert_group(name, LintGroup { lint_ids: to, is_externally_loaded, depr: None });
270    }
271
272    /// This lint should give no warning and have no effect.
273    ///
274    /// This is used by rustc to avoid warning about old rustdoc lints before rustdoc registers them as tool lints.
275    #[track_caller]
276    pub fn register_ignored(&mut self, name: &str) {
277        if self.by_name.insert(name.to_string(), Ignored).is_some() {
278            ::rustc_middle::util::bug::bug_fmt(format_args!("duplicate specification of lint {0}",
        name));bug!("duplicate specification of lint {}", name);
279        }
280    }
281
282    /// This lint has been renamed; warn about using the new name and apply the lint.
283    #[track_caller]
284    pub fn register_renamed(&mut self, old_name: &str, new_name: &str) {
285        let Some(&Id(target)) = self.by_name.get(new_name) else {
286            ::rustc_middle::util::bug::bug_fmt(format_args!("invalid lint renaming of {0} to {1}",
        old_name, new_name));bug!("invalid lint renaming of {} to {}", old_name, new_name);
287        };
288        self.by_name.insert(old_name.to_string(), Renamed(new_name.to_string(), target));
289    }
290
291    pub fn register_removed(&mut self, name: &str, reason: &str) {
292        self.by_name.insert(name.into(), Removed(reason.into()));
293    }
294
295    pub fn find_lints(&self, lint_name: &str) -> Option<&[LintId]> {
296        match self.by_name.get(lint_name) {
297            Some(Id(lint_id)) => Some(slice::from_ref(lint_id)),
298            Some(Renamed(_, lint_id)) => Some(slice::from_ref(lint_id)),
299            Some(Removed(_)) => None,
300            Some(Ignored) => Some(&[]),
301            None => match self.lint_groups.get(lint_name) {
302                Some(LintGroup { lint_ids, .. }) => Some(lint_ids),
303                None => None,
304            },
305        }
306    }
307
308    /// True if this symbol represents a lint group name.
309    pub fn is_lint_group(&self, lint_name: Symbol) -> bool {
310        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_lint/src/context.rs:310",
                        "rustc_lint::context", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_lint/src/context.rs"),
                        ::tracing_core::__macro_support::Option::Some(310u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_lint::context"),
                        ::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!("is_lint_group(lint_name={0:?}, lint_groups={1:?})",
                                                    lint_name, self.lint_groups.keys().collect::<Vec<_>>()) as
                                            &dyn Value))])
            });
    } else { ; }
};debug!(
311            "is_lint_group(lint_name={:?}, lint_groups={:?})",
312            lint_name,
313            self.lint_groups.keys().collect::<Vec<_>>()
314        );
315        let lint_name_str = lint_name.as_str();
316        self.lint_groups.contains_key(lint_name_str) || {
317            let warnings_name_str = crate::WARNINGS.name_lower();
318            lint_name_str == warnings_name_str
319        }
320    }
321
322    /// Checks the name of a lint for its existence, and whether it was
323    /// renamed or removed. Generates a `Diag` containing a
324    /// warning for renamed and removed lints. This is over both lint
325    /// names from attributes and those passed on the command line. Since
326    /// it emits non-fatal warnings and there are *two* lint passes that
327    /// inspect attributes, this is only run from the late pass to avoid
328    /// printing duplicate warnings.
329    pub fn check_lint_name(
330        &self,
331        lint_name: &str,
332        tool_name: Option<Symbol>,
333        registered_tools: &RegisteredTools,
334    ) -> CheckLintNameResult<'_> {
335        if let Some(tool_name) = tool_name {
336            // FIXME: rustc and rustdoc are considered tools for lints, but not for attributes.
337            if tool_name != sym::rustc
338                && tool_name != sym::rustdoc
339                && !registered_tools.contains(&Ident::with_dummy_span(tool_name))
340            {
341                return CheckLintNameResult::NoTool;
342            }
343        }
344
345        let complete_name = if let Some(tool_name) = tool_name {
346            ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0}::{1}", tool_name, lint_name))
    })format!("{tool_name}::{lint_name}")
347        } else {
348            lint_name.to_string()
349        };
350        // If the lint was scoped with `tool::` check if the tool lint exists
351        if let Some(tool_name) = tool_name {
352            match self.by_name.get(&complete_name) {
353                None => match self.lint_groups.get(&*complete_name) {
354                    // If the lint isn't registered, there are two possibilities:
355                    None => {
356                        // 1. The tool is currently running, so this lint really doesn't exist.
357                        // FIXME: should this handle tools that never register a lint, like rustfmt?
358                        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_lint/src/context.rs:358",
                        "rustc_lint::context", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_lint/src/context.rs"),
                        ::tracing_core::__macro_support::Option::Some(358u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_lint::context"),
                        ::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!("lints={0:?}",
                                                    self.by_name) as &dyn Value))])
            });
    } else { ; }
};debug!("lints={:?}", self.by_name);
359                        let tool_prefix = ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0}::", tool_name))
    })format!("{tool_name}::");
360
361                        return if self.by_name.keys().any(|lint| lint.starts_with(&tool_prefix)) {
362                            self.no_lint_suggestion(&complete_name, tool_name.as_str())
363                        } else {
364                            // 2. The tool isn't currently running, so no lints will be registered.
365                            // To avoid giving a false positive, ignore all unknown lints.
366                            CheckLintNameResult::MissingTool
367                        };
368                    }
369                    Some(LintGroup { lint_ids, depr, .. }) => {
370                        return if let &Some(LintAlias { name, silent: false }) = depr {
371                            CheckLintNameResult::Tool(lint_ids, Some(name.to_string()))
372                        } else {
373                            CheckLintNameResult::Tool(lint_ids, None)
374                        };
375                    }
376                },
377                Some(Id(id)) => return CheckLintNameResult::Tool(slice::from_ref(id), None),
378                // If the lint was registered as removed or renamed by the lint tool, we don't need
379                // to treat tool_lints and rustc lints different and can use the code below.
380                _ => {}
381            }
382        }
383        match self.by_name.get(&complete_name) {
384            Some(Renamed(new_name, _)) => CheckLintNameResult::Renamed(new_name.to_string()),
385            Some(Removed(reason)) => CheckLintNameResult::Removed(reason.to_string()),
386            None => match self.lint_groups.get(&*complete_name) {
387                // If neither the lint, nor the lint group exists check if there is a `clippy::`
388                // variant of this lint
389                None => self.check_tool_name_for_backwards_compat(&complete_name, "clippy"),
390                Some(LintGroup { lint_ids, depr, .. }) => {
391                    // Check if the lint group name is deprecated
392                    if let &Some(LintAlias { name, silent: false }) = depr {
393                        CheckLintNameResult::Tool(lint_ids, Some(name.to_string()))
394                    } else {
395                        CheckLintNameResult::Ok(lint_ids)
396                    }
397                }
398            },
399            Some(Id(id)) => CheckLintNameResult::Ok(slice::from_ref(id)),
400            Some(&Ignored) => CheckLintNameResult::Ok(&[]),
401        }
402    }
403
404    fn no_lint_suggestion(&self, lint_name: &str, tool_name: &str) -> CheckLintNameResult<'_> {
405        let name_lower = lint_name.to_lowercase();
406
407        if lint_name.chars().any(char::is_uppercase) && self.find_lints(&name_lower).is_some() {
408            // First check if the lint name is (partly) in upper case instead of lower case...
409            return CheckLintNameResult::NoLint(Some((Symbol::intern(&name_lower), false)));
410        }
411
412        // ...if not, search for lints with a similar name
413        // Note: find_best_match_for_name depends on the sort order of its input vector.
414        // To ensure deterministic output, sort elements of the lint_groups hash map.
415        // Also, never suggest deprecated lint groups.
416        // We will soon sort, so the initial order does not matter.
417        #[allow(rustc::potential_query_instability)]
418        let mut groups: Vec<_> = self
419            .lint_groups
420            .iter()
421            .filter_map(|(k, LintGroup { depr, .. })| depr.is_none().then_some(k))
422            .collect();
423        groups.sort();
424        let groups = groups.iter().map(|k| Symbol::intern(k));
425        let lints = self.lints.iter().map(|l| Symbol::intern(&l.name_lower()));
426        let names: Vec<Symbol> = groups.chain(lints).collect();
427        let mut lookups = ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [Symbol::intern(&name_lower)]))vec![Symbol::intern(&name_lower)];
428        if let Some(stripped) = name_lower.split("::").last() {
429            lookups.push(Symbol::intern(stripped));
430        }
431        let res = find_best_match_for_names(&names, &lookups, None);
432        let is_rustc = res.map_or_else(
433            || false,
434            |s| name_lower.contains("::") && !s.as_str().starts_with(tool_name),
435        );
436        let suggestion = res.map(|s| (s, is_rustc));
437        CheckLintNameResult::NoLint(suggestion)
438    }
439
440    fn check_tool_name_for_backwards_compat(
441        &self,
442        lint_name: &str,
443        tool_name: &str,
444    ) -> CheckLintNameResult<'_> {
445        let complete_name = ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0}::{1}", tool_name, lint_name))
    })format!("{tool_name}::{lint_name}");
446        match self.by_name.get(&complete_name) {
447            None => match self.lint_groups.get(&*complete_name) {
448                // Now we are sure, that this lint exists nowhere
449                None => self.no_lint_suggestion(lint_name, tool_name),
450                Some(LintGroup { lint_ids, .. }) => {
451                    CheckLintNameResult::Tool(lint_ids, Some(complete_name))
452                }
453            },
454            Some(Id(id)) => CheckLintNameResult::Tool(slice::from_ref(id), Some(complete_name)),
455            Some(other) => {
456                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_lint/src/context.rs:456",
                        "rustc_lint::context", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_lint/src/context.rs"),
                        ::tracing_core::__macro_support::Option::Some(456u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_lint::context"),
                        ::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!("got renamed lint {0:?}",
                                                    other) as &dyn Value))])
            });
    } else { ; }
};debug!("got renamed lint {:?}", other);
457                CheckLintNameResult::NoLint(None)
458            }
459        }
460    }
461}
462
463/// Context for lint checking outside of type inference.
464pub struct LateContext<'tcx> {
465    /// Type context we're checking in.
466    pub tcx: TyCtxt<'tcx>,
467
468    /// Current body, or `None` if outside a body.
469    pub enclosing_body: Option<hir::BodyId>,
470
471    /// Type-checking results for the current body. Access using the `typeck_results`
472    /// and `maybe_typeck_results` methods, which handle querying the typeck results on demand.
473    // FIXME(eddyb) move all the code accessing internal fields like this,
474    // to this module, to avoid exposing it to lint logic.
475    pub(super) cached_typeck_results: Cell<Option<&'tcx ty::TypeckResults<'tcx>>>,
476
477    /// Parameter environment for the item we are in.
478    pub param_env: ty::ParamEnv<'tcx>,
479
480    /// Items accessible from the crate being checked.
481    pub effective_visibilities: &'tcx EffectiveVisibilities,
482
483    pub last_node_with_lint_attrs: hir::HirId,
484
485    /// Generic type parameters in scope for the item we are in.
486    pub generics: Option<&'tcx hir::Generics<'tcx>>,
487
488    /// We are only looking at one module
489    pub only_module: bool,
490}
491
492/// Context for lint checking of the AST, after expansion, before lowering to HIR.
493pub struct EarlyContext<'a> {
494    pub builder: LintLevelsBuilder<'a, crate::levels::TopDown>,
495    pub buffered: LintBuffer,
496}
497
498pub trait LintContext {
499    type LintExpectationId: Copy + Into<LintExpectationId>;
500
501    fn sess(&self) -> &Session;
502
503    // FIXME: These methods should not take an Into<MultiSpan> -- instead, callers should need to
504    // set the span in their `decorate` function (preferably using set_span).
505    /// Emit a lint at the appropriate level, with an optional associated span.
506    ///
507    /// [`emit_lint_base`]: rustc_middle::lint::emit_lint_base#decorate-signature
508    #[track_caller]
509    fn opt_span_lint<S: Into<MultiSpan>>(
510        &self,
511        lint: &'static Lint,
512        span: Option<S>,
513        decorate: impl for<'a> Diagnostic<'a, ()>,
514    );
515
516    /// Emit a lint at `span` from a lint struct (some type that implements `Diagnostic`,
517    /// typically generated by `#[derive(Diagnostic)]`).
518    #[track_caller]
519    fn emit_span_lint<S: Into<MultiSpan>>(
520        &self,
521        lint: &'static Lint,
522        span: S,
523        decorator: impl for<'a> Diagnostic<'a, ()>,
524    ) {
525        self.opt_span_lint(lint, Some(span), decorator);
526    }
527
528    /// This returns the lint level spec for the given lint at the current location.
529    fn get_lint_level_spec(&self, lint: &'static Lint) -> LevelSpec<Self::LintExpectationId>;
530
531    /// This function can be used to manually fulfill an expectation. This can
532    /// be used for lints which contain several spans, and should be suppressed,
533    /// if either location was marked with an expectation.
534    ///
535    /// Note that this function should only be called for [`LintExpectationId`]s
536    /// retrieved from the current lint pass. Buffered or manually created ids can
537    /// cause ICEs.
538    fn fulfill_expectation(&self, expectation: Self::LintExpectationId) {
539        // We need to make sure that submitted expectation ids are correctly fulfilled suppressed
540        // and stored between compilation sessions. To not manually do these steps, we simply create
541        // a dummy diagnostic and emit it as usual, which will be suppressed and stored like a
542        // normal expected lint diagnostic.
543        self.sess()
544            .dcx()
545            .struct_expect(
546                "this is a dummy diagnostic, to submit and store an expectation",
547                expectation.into(),
548            )
549            .emit();
550    }
551}
552
553impl<'a> EarlyContext<'a> {
554    pub(crate) fn new(
555        sess: &'a Session,
556        features: &'a Features,
557        lint_added_lints: bool,
558        lint_store: &'a LintStore,
559        registered_tools: &'a RegisteredTools,
560        buffered: LintBuffer,
561    ) -> EarlyContext<'a> {
562        EarlyContext {
563            builder: LintLevelsBuilder::new(
564                sess,
565                features,
566                lint_added_lints,
567                lint_store,
568                registered_tools,
569            ),
570            buffered,
571        }
572    }
573}
574
575impl<'tcx> LintContext for LateContext<'tcx> {
576    type LintExpectationId = StableLintExpectationId;
577
578    /// Gets the overall compiler `Session` object.
579    fn sess(&self) -> &Session {
580        self.tcx.sess
581    }
582
583    fn opt_span_lint<S: Into<MultiSpan>>(
584        &self,
585        lint: &'static Lint,
586        span: Option<S>,
587        decorate: impl for<'a> Diagnostic<'a, ()>,
588    ) {
589        let hir_id = self.last_node_with_lint_attrs;
590
591        match span {
592            Some(s) => self.tcx.emit_node_span_lint(lint, hir_id, s, decorate),
593            None => self.tcx.emit_node_lint(lint, hir_id, decorate),
594        }
595    }
596
597    fn get_lint_level_spec(&self, lint: &'static Lint) -> StableLevelSpec {
598        self.tcx.lint_level_spec_at_node(lint, self.last_node_with_lint_attrs)
599    }
600}
601
602impl LintContext for EarlyContext<'_> {
603    type LintExpectationId = UnstableLintExpectationId;
604
605    /// Gets the overall compiler `Session` object.
606    fn sess(&self) -> &Session {
607        self.builder.sess()
608    }
609
610    fn opt_span_lint<S: Into<MultiSpan>>(
611        &self,
612        lint: &'static Lint,
613        span: Option<S>,
614        decorator: impl for<'a> Diagnostic<'a, ()>,
615    ) {
616        self.builder.opt_span_lint(lint, span.map(|s| s.into()), decorator)
617    }
618
619    fn get_lint_level_spec(&self, lint: &'static Lint) -> UnstableLevelSpec {
620        self.builder.lint_level_spec(lint)
621    }
622}
623
624impl<'tcx> LateContext<'tcx> {
625    /// The typing mode of the currently visited node. Use this when
626    /// building a new `InferCtxt`.
627    pub fn typing_mode(&self) -> TypingMode<'tcx> {
628        if let Some(body_id) = self.enclosing_body
629            && self.tcx.use_typing_mode_post_typeck_until_borrowck()
630        {
631            let def_id = self.tcx.hir_enclosing_body_owner(body_id.hir_id);
632            TypingMode::borrowck(self.tcx, def_id)
633        } else {
634            TypingMode::non_body_analysis()
635        }
636    }
637
638    pub fn typing_env(&self) -> TypingEnv<'tcx> {
639        TypingEnv::new(self.param_env, self.typing_mode())
640    }
641
642    pub fn type_is_copy_modulo_regions(&self, ty: Ty<'tcx>) -> bool {
643        self.tcx.type_is_copy_modulo_regions(self.typing_env(), ty)
644    }
645
646    pub fn type_is_use_cloned_modulo_regions(&self, ty: Ty<'tcx>) -> bool {
647        self.tcx.type_is_use_cloned_modulo_regions(self.typing_env(), ty)
648    }
649
650    /// Gets the type-checking results for the current body,
651    /// or `None` if outside a body.
652    pub fn maybe_typeck_results(&self) -> Option<&'tcx ty::TypeckResults<'tcx>> {
653        self.cached_typeck_results.get().or_else(|| {
654            self.enclosing_body.map(|body| {
655                let typeck_results = self.tcx.typeck_body(body);
656                self.cached_typeck_results.set(Some(typeck_results));
657                typeck_results
658            })
659        })
660    }
661
662    /// Gets the type-checking results for the current body.
663    /// As this will ICE if called outside bodies, only call when working with
664    /// `Expr` or `Pat` nodes (they are guaranteed to be found only in bodies).
665    #[track_caller]
666    pub fn typeck_results(&self) -> &'tcx ty::TypeckResults<'tcx> {
667        self.maybe_typeck_results().expect("`LateContext::typeck_results` called outside of body")
668    }
669
670    /// Returns the final resolution of a `QPath`, or `Res::Err` if unavailable.
671    /// Unlike `.typeck_results().qpath_res(qpath, id)`, this can be used even outside
672    /// bodies (e.g. for paths in `hir::Ty`), without any risk of ICE-ing.
673    pub fn qpath_res(&self, qpath: &hir::QPath<'_>, id: hir::HirId) -> Res {
674        match *qpath {
675            hir::QPath::Resolved(_, path) => path.res,
676            hir::QPath::TypeRelative(..) => self
677                .maybe_typeck_results()
678                .filter(|typeck_results| typeck_results.hir_owner == id.owner)
679                .or_else(|| {
680                    self.tcx
681                        .has_typeck_results(id.owner.def_id)
682                        .then(|| self.tcx.typeck(id.owner.def_id))
683                })
684                .and_then(|typeck_results| typeck_results.type_dependent_def(id))
685                .map_or(Res::Err, |(kind, def_id)| Res::Def(kind, def_id)),
686        }
687    }
688
689    /// Gets the absolute path of `def_id` as a vector of `Symbol`.
690    ///
691    /// Note that this is kinda expensive because it has to
692    /// travel the tree and pretty-print. Use sparingly.
693    ///
694    /// If you're trying to match for an item given by its path, use a
695    /// diagnostic item. If you're only interested in given sections, use more
696    /// specific functions, such as [`TyCtxt::crate_name`]
697    ///
698    /// FIXME: It would be great if this could be optimized.
699    ///
700    /// # Examples
701    ///
702    /// ```rust,ignore (no context or def id available)
703    /// let def_path = cx.get_def_path(def_id);
704    /// if let &[sym::core, sym::option, sym::Option] = &def_path[..] {
705    ///     // The given `def_id` is that of an `Option` type
706    /// }
707    /// ```
708    pub fn get_def_path(&self, def_id: DefId) -> Vec<Symbol> {
709        struct LintPathPrinter<'tcx> {
710            tcx: TyCtxt<'tcx>,
711            path: Vec<Symbol>,
712        }
713
714        impl<'tcx> Printer<'tcx> for LintPathPrinter<'tcx> {
715            fn tcx(&self) -> TyCtxt<'tcx> {
716                self.tcx
717            }
718
719            fn print_region(&mut self, _region: ty::Region<'_>) -> Result<(), PrintError> {
720                ::core::panicking::panic("internal error: entered unreachable code");unreachable!(); // because `print_path_with_generic_args` ignores the `GenericArgs`
721            }
722
723            fn print_type(&mut self, _ty: Ty<'tcx>) -> Result<(), PrintError> {
724                ::core::panicking::panic("internal error: entered unreachable code");unreachable!(); // because `print_path_with_generic_args` ignores the `GenericArgs`
725            }
726
727            fn print_dyn_existential(
728                &mut self,
729                _predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
730            ) -> Result<(), PrintError> {
731                ::core::panicking::panic("internal error: entered unreachable code");unreachable!(); // because `print_path_with_generic_args` ignores the `GenericArgs`
732            }
733
734            fn print_const(&mut self, _ct: ty::Const<'tcx>) -> Result<(), PrintError> {
735                ::core::panicking::panic("internal error: entered unreachable code");unreachable!(); // because `print_path_with_generic_args` ignores the `GenericArgs`
736            }
737
738            fn print_crate_name(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
739                self.path = ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
        [self.tcx.crate_name(cnum)]))vec![self.tcx.crate_name(cnum)];
740                Ok(())
741            }
742
743            fn print_path_with_qualified(
744                &mut self,
745                self_ty: Ty<'tcx>,
746                trait_ref: Option<ty::TraitRef<'tcx>>,
747            ) -> Result<(), PrintError> {
748                if trait_ref.is_none()
749                    && let ty::Adt(def, args) = self_ty.kind()
750                {
751                    return self.print_def_path(def.did(), args);
752                }
753
754                // This shouldn't ever be needed, but just in case:
755                {
    let _guard = NoTrimmedGuard::new();
    {
        self.path =
            ::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
                    [match trait_ref {
                                Some(trait_ref) =>
                                    Symbol::intern(&::alloc::__export::must_use({
                                                    ::alloc::fmt::format(format_args!("{0:?}", trait_ref))
                                                })),
                                None =>
                                    Symbol::intern(&::alloc::__export::must_use({
                                                    ::alloc::fmt::format(format_args!("<{0}>", self_ty))
                                                })),
                            }]));
        Ok(())
    }
}with_no_trimmed_paths!({
756                    self.path = vec![match trait_ref {
757                        Some(trait_ref) => Symbol::intern(&format!("{trait_ref:?}")),
758                        None => Symbol::intern(&format!("<{self_ty}>")),
759                    }];
760                    Ok(())
761                })
762            }
763
764            fn print_path_with_impl(
765                &mut self,
766                print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
767                self_ty: Ty<'tcx>,
768                trait_ref: Option<ty::TraitRef<'tcx>>,
769            ) -> Result<(), PrintError> {
770                print_prefix(self)?;
771
772                // This shouldn't ever be needed, but just in case:
773                self.path.push(match trait_ref {
774                    Some(trait_ref) => {
775                        {
    let _guard = NoTrimmedGuard::new();
    Symbol::intern(&::alloc::__export::must_use({
                    ::alloc::fmt::format(format_args!("<impl {0} for {1}>",
                            trait_ref.print_only_trait_path(), self_ty))
                }))
}with_no_trimmed_paths!(Symbol::intern(&format!(
776                            "<impl {} for {}>",
777                            trait_ref.print_only_trait_path(),
778                            self_ty
779                        )))
780                    }
781                    None => {
782                        {
    let _guard = NoTrimmedGuard::new();
    Symbol::intern(&::alloc::__export::must_use({
                    ::alloc::fmt::format(format_args!("<impl {0}>", self_ty))
                }))
}with_no_trimmed_paths!(Symbol::intern(&format!("<impl {self_ty}>")))
783                    }
784                });
785
786                Ok(())
787            }
788
789            fn print_path_with_simple(
790                &mut self,
791                print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
792                disambiguated_data: &DisambiguatedDefPathData,
793            ) -> Result<(), PrintError> {
794                print_prefix(self)?;
795
796                // Skip `::{{extern}}` blocks and `::{{constructor}}` on tuple/unit structs.
797                if let DefPathData::ForeignMod | DefPathData::Ctor = disambiguated_data.data {
798                    return Ok(());
799                }
800
801                self.path.push(match disambiguated_data.data.get_opt_name() {
802                    Some(sym) => sym,
803                    None => Symbol::intern(&disambiguated_data.data.to_string()),
804                });
805                Ok(())
806            }
807
808            fn print_path_with_generic_args(
809                &mut self,
810                print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
811                _args: &[GenericArg<'tcx>],
812            ) -> Result<(), PrintError> {
813                print_prefix(self)
814            }
815        }
816
817        let mut p = LintPathPrinter { tcx: self.tcx, path: ::alloc::vec::Vec::new()vec![] };
818        p.print_def_path(def_id, &[]).unwrap();
819        p.path
820    }
821
822    /// Returns the associated type `name` for `self_ty` as an implementation of `trait_id`.
823    /// Do not invoke without first verifying that the type implements the trait.
824    pub fn get_associated_type(
825        &self,
826        self_ty: Ty<'tcx>,
827        trait_id: DefId,
828        name: Symbol,
829    ) -> Option<Ty<'tcx>> {
830        let tcx = self.tcx;
831        tcx.associated_items(trait_id)
832            .find_by_ident_and_kind(tcx, Ident::with_dummy_span(name), ty::AssocTag::Type, trait_id)
833            .and_then(|assoc| {
834                let proj = Ty::new_projection(tcx, ty::IsRigid::No, assoc.def_id, [self_ty]);
835                tcx.try_normalize_erasing_regions(self.typing_env(), Unnormalized::new_wip(proj))
836                    .ok()
837            })
838    }
839
840    /// Returns the effective precedence of an expression for the purpose of
841    /// rendering diagnostic. This is not the same as the precedence that would
842    /// be used for pretty-printing HIR by rustc_hir_pretty.
843    pub fn precedence(&self, expr: &hir::Expr<'_>) -> ExprPrecedence {
844        let has_attr = |id: hir::HirId| -> bool {
845            self.tcx.hir_attrs(id).iter().any(hir::Attribute::is_prefix_attr_for_suggestions)
846        };
847        expr.precedence(&has_attr)
848    }
849
850    /// If the given expression is a local binding, find the initializer expression.
851    /// If that initializer expression is another local binding, find its initializer again.
852    ///
853    /// This process repeats as long as possible (but usually no more than once).
854    /// Type-check adjustments are not taken in account in this function.
855    ///
856    /// Examples:
857    /// ```
858    /// let abc = 1;
859    /// let def = abc + 2;
860    /// //        ^^^^^^^ output
861    /// let def = def;
862    /// dbg!(def);
863    /// //   ^^^ input
864    /// ```
865    pub fn expr_or_init<'a>(&self, mut expr: &'a hir::Expr<'tcx>) -> &'a hir::Expr<'tcx> {
866        expr = expr.peel_blocks();
867
868        while let hir::ExprKind::Path(ref qpath) = expr.kind
869            && let Some(parent_node) = match self.qpath_res(qpath, expr.hir_id) {
870                Res::Local(hir_id) => Some(self.tcx.parent_hir_node(hir_id)),
871                _ => None,
872            }
873            && let Some(init) = match parent_node {
874                hir::Node::Expr(expr) => Some(expr),
875                hir::Node::LetStmt(hir::LetStmt {
876                    init,
877                    // Binding is immutable, init cannot be re-assigned
878                    pat: Pat { kind: PatKind::Binding(BindingMode::NONE, ..), .. },
879                    ..
880                }) => *init,
881                _ => None,
882            }
883        {
884            expr = init.peel_blocks();
885        }
886        expr
887    }
888
889    /// If the given expression is a local binding, find the initializer expression.
890    /// If that initializer expression is another local or **outside** (`const`/`static`)
891    /// binding, find its initializer again.
892    ///
893    /// This process repeats as long as possible (but usually no more than once).
894    /// Type-check adjustments are not taken in account in this function.
895    ///
896    /// Examples:
897    /// ```
898    /// const ABC: i32 = 1;
899    /// //               ^ output
900    /// let def = ABC;
901    /// dbg!(def);
902    /// //   ^^^ input
903    ///
904    /// // or...
905    /// let abc = 1;
906    /// let def = abc + 2;
907    /// //        ^^^^^^^ output
908    /// dbg!(def);
909    /// //   ^^^ input
910    /// ```
911    pub fn expr_or_init_with_outside_body<'a>(
912        &self,
913        mut expr: &'a hir::Expr<'tcx>,
914    ) -> &'a hir::Expr<'tcx> {
915        expr = expr.peel_blocks();
916
917        while let hir::ExprKind::Path(ref qpath) = expr.kind
918            && let Some(parent_node) = match self.qpath_res(qpath, expr.hir_id) {
919                Res::Local(hir_id) => Some(self.tcx.parent_hir_node(hir_id)),
920                Res::Def(_, def_id) => self.tcx.hir_get_if_local(def_id),
921                _ => None,
922            }
923            && let Some(init) = match parent_node {
924                hir::Node::Expr(expr) => Some(expr),
925                hir::Node::LetStmt(hir::LetStmt {
926                    init,
927                    // Binding is immutable, init cannot be re-assigned
928                    pat: Pat { kind: PatKind::Binding(BindingMode::NONE, ..), .. },
929                    ..
930                }) => *init,
931                hir::Node::Item(item) => match item.kind {
932                    // FIXME(mgca): figure out how to handle ConstArgKind::Path (or don't but add warning in docs here)
933                    hir::ItemKind::Const(.., hir::ConstItemRhs::Body(body_id))
934                    | hir::ItemKind::Static(.., body_id) => Some(self.tcx.hir_body(body_id).value),
935                    _ => None,
936                },
937                _ => None,
938            }
939        {
940            expr = init.peel_blocks();
941        }
942        expr
943    }
944}
945
946impl<'tcx> abi::HasDataLayout for LateContext<'tcx> {
947    #[inline]
948    fn data_layout(&self) -> &abi::TargetDataLayout {
949        &self.tcx.data_layout
950    }
951}
952
953impl<'tcx> ty::layout::HasTyCtxt<'tcx> for LateContext<'tcx> {
954    #[inline]
955    fn tcx(&self) -> TyCtxt<'tcx> {
956        self.tcx
957    }
958}
959
960impl<'tcx> ty::layout::HasTypingEnv<'tcx> for LateContext<'tcx> {
961    #[inline]
962    fn typing_env(&self) -> ty::TypingEnv<'tcx> {
963        self.typing_env()
964    }
965}
966
967impl<'tcx> LayoutOfHelpers<'tcx> for LateContext<'tcx> {
968    type LayoutOfResult = Result<TyAndLayout<'tcx>, LayoutError<'tcx>>;
969
970    #[inline]
971    fn handle_layout_err(&self, err: LayoutError<'tcx>, _: Span, _: Ty<'tcx>) -> LayoutError<'tcx> {
972        err
973    }
974}