const-eval: make lint scope computation consistent · rust-lang/rust@1f955a7 (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

``

`@@ -507,15 +511,6 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {

`

507

511

`self.stack().last().map_or(self.tcx.span, |f| f.current_span())

`

508

512

`}

`

509

513

``

510

``

`-

#[inline(always)]

`

511

``

`-

/// Find the first stack frame that is within the current crate, if any, otherwise return the crate's HirId

`

512

``

`-

pub fn best_lint_scope(&self) -> hir::HirId {

`

513

``

`-

self.stack()

`

514

``

`-

.iter()

`

515

``

`-

.find_map(|frame| frame.body.source.def_id().as_local())

`

516

``

`-

.map_or(CRATE_HIR_ID, |def_id| self.tcx.local_def_id_to_hir_id(def_id))

`

517

``

`-

}

`

518

``

-

519

514

`#[inline(always)]

`

520

515

`pub(crate) fn stack(&self) -> &[Frame<'tcx, M::Provenance, M::FrameExtra>] {

`

521

516

`M::stack(self)

`