const-eval: make lint scope computation consistent · rust-lang/rust@54e24c1 (original) (raw)
`@@ -4,7 +4,6 @@ use std::{fmt, mem};
`
4
4
`use either::{Either, Left, Right};
`
5
5
`use tracing::{debug, info, info_span, instrument, trace};
`
6
6
``
7
``
`-
use hir::CRATE_HIR_ID;
`
8
7
`use rustc_errors::DiagCtxt;
`
9
8
`use rustc_hir::{self as hir, def_id::DefId, definitions::DefPathData};
`
10
9
`use rustc_index::IndexVec;
`
`@@ -271,13 +270,18 @@ impl<'tcx, Prov: Provenance, Extra> Frame<'tcx, Prov, Extra> {
`
271
270
`}
`
272
271
`}
`
273
272
``
274
``
`-
pub fn lint_root(&self) -> Optionhir::HirId {
`
275
``
`-
self.current_source_info().and_then(|source_info| {
`
276
``
`-
match &self.body.source_scopes[source_info.scope].local_data {
`
``
273
`+
pub fn lint_root(&self, tcx: TyCtxt<'tcx>) -> Optionhir::HirId {
`
``
274
`+
// We first try to get a HirId via the current source scope,
`
``
275
`` +
// and fall back to body.source
.
``
``
276
`+
self.current_source_info()
`
``
277
`+
.and_then(|source_info| match &self.body.source_scopes[source_info.scope].local_data {
`
277
278
` mir::ClearCrossCrate::Set(data) => Some(data.lint_root),
`
278
279
` mir::ClearCrossCrate::Clear => None,
`
279
``
`-
}
`
280
``
`-
})
`
``
280
`+
})
`
``
281
`+
.or_else(|| {
`
``
282
`+
let def_id = self.body.source.def_id().as_local();
`
``
283
`+
def_id.map(|def_id| tcx.local_def_id_to_hir_id(def_id))
`
``
284
`+
})
`
281
285
`}
`
282
286
``
283
287
`` /// Returns the address of the buffer where the locals are stored. This is used by Place
as a
``
`@@ -509,17 +513,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
`
509
513
`self.stack().last().map_or(self.tcx.span, |f| f.current_span())
`
510
514
`}
`
511
515
``
512
``
`-
/// Find the first stack frame that is within the current crate, if any;
`
513
``
`-
/// otherwise return the crate's HirId.
`
514
``
`-
#[inline(always)]
`
515
``
`-
pub fn best_lint_scope(&self) -> hir::HirId {
`
516
``
`-
self.stack()
`
517
``
`-
.iter()
`
518
``
`-
.find_map(|frame| frame.body.source.def_id().as_local())
`
519
``
`-
.map_or(CRATE_HIR_ID, |def_id| self.tcx.local_def_id_to_hir_id(def_id))
`
520
``
`-
}
`
521
``
-
522
``
`-
#[inline(always)]
`
523
516
`pub(crate) fn stack(&self) -> &[Frame<'tcx, M::Provenance, M::FrameExtra>] {
`
524
517
`M::stack(self)
`
525
518
`}
`