Files
cargo_fmt
coverage_test_macros
git_rustfmt
rustc_apfloat
rustc_arena
rustc_ast
rustc_ast_lowering
rustc_ast_passes
rustc_ast_pretty
rustc_attr
rustc_borrowck
rustc_builtin_macros
rustc_codegen_llvm
rustc_codegen_ssa
rustc_const_eval
rustc_data_structures
rustc_driver
rustc_error_codes
rustc_errors
rustc_expand
rustc_feature
rustc_fs_util
rustc_graphviz
rustc_hir
rustc_hir_pretty
rustc_incremental
rustc_index
rustc_infer
rustc_interface
rustc_lexer
rustc_lint
rustc_lint_defs
rustc_llvm
rustc_macros
rustc_metadata
rustc_middle
rustc_mir_build
rustc_mir_dataflow
rustc_mir_transform
rustc_monomorphize
rustc_parse
rustc_parse_format
rustc_passes
rustc_plugin_impl
rustc_privacy
rustc_query_impl
rustc_query_system
rustc_resolve
rustc_save_analysis
rustc_serialize
rustc_session
rustc_span
rustc_symbol_mangling
rustc_target
abi
asm
spec
aarch64_apple_darwin.rsaarch64_apple_ios.rsaarch64_apple_ios_macabi.rsaarch64_apple_ios_sim.rsaarch64_apple_tvos.rsaarch64_be_unknown_linux_gnu.rsaarch64_be_unknown_linux_gnu_ilp32.rsaarch64_fuchsia.rsaarch64_kmc_solid_asp3.rsaarch64_linux_android.rsaarch64_pc_windows_msvc.rsaarch64_unknown_freebsd.rsaarch64_unknown_hermit.rsaarch64_unknown_linux_gnu.rsaarch64_unknown_linux_gnu_ilp32.rsaarch64_unknown_linux_musl.rsaarch64_unknown_netbsd.rsaarch64_unknown_none.rsaarch64_unknown_none_softfloat.rsaarch64_unknown_openbsd.rsaarch64_unknown_redox.rsaarch64_unknown_uefi.rsaarch64_uwp_windows_msvc.rsaarch64_wrs_vxworks.rsabi.rsandroid_base.rsapple_base.rsapple_sdk_base.rsarm_linux_androideabi.rsarm_unknown_linux_gnueabi.rsarm_unknown_linux_gnueabihf.rsarm_unknown_linux_musleabi.rsarm_unknown_linux_musleabihf.rsarmebv7r_none_eabi.rsarmebv7r_none_eabihf.rsarmv4t_unknown_linux_gnueabi.rsarmv5te_unknown_linux_gnueabi.rsarmv5te_unknown_linux_musleabi.rsarmv5te_unknown_linux_uclibceabi.rsarmv6_unknown_freebsd.rsarmv6_unknown_netbsd_eabihf.rsarmv6k_nintendo_3ds.rsarmv7_apple_ios.rsarmv7_linux_androideabi.rsarmv7_unknown_freebsd.rsarmv7_unknown_linux_gnueabi.rsarmv7_unknown_linux_gnueabihf.rsarmv7_unknown_linux_musleabi.rsarmv7_unknown_linux_musleabihf.rsarmv7_unknown_linux_uclibceabihf.rsarmv7_unknown_netbsd_eabihf.rsarmv7_wrs_vxworks_eabihf.rsarmv7a_kmc_solid_asp3_eabi.rsarmv7a_kmc_solid_asp3_eabihf.rsarmv7a_none_eabi.rsarmv7a_none_eabihf.rsarmv7r_none_eabi.rsarmv7r_none_eabihf.rsarmv7s_apple_ios.rsasmjs_unknown_emscripten.rsavr_gnu_base.rsavr_unknown_gnu_atmega328.rsbpf_base.rsbpfeb_unknown_none.rsbpfel_unknown_none.rscrt_objects.rsdragonfly_base.rsfreebsd_base.rsfuchsia_base.rshaiku_base.rshermit_base.rshermit_kernel_base.rshexagon_unknown_linux_musl.rsi386_apple_ios.rsi586_pc_windows_msvc.rsi586_unknown_linux_gnu.rsi586_unknown_linux_musl.rsi686_apple_darwin.rsi686_linux_android.rsi686_pc_windows_gnu.rsi686_pc_windows_msvc.rsi686_unknown_freebsd.rsi686_unknown_haiku.rsi686_unknown_linux_gnu.rsi686_unknown_linux_musl.rsi686_unknown_netbsd.rsi686_unknown_openbsd.rsi686_unknown_uefi.rsi686_uwp_windows_gnu.rsi686_uwp_windows_msvc.rsi686_wrs_vxworks.rsillumos_base.rsl4re_base.rslinux_base.rslinux_gnu_base.rslinux_kernel_base.rslinux_musl_base.rslinux_uclibc_base.rsm68k_unknown_linux_gnu.rsmips64_unknown_linux_gnuabi64.rsmips64_unknown_linux_muslabi64.rsmips64el_unknown_linux_gnuabi64.rsmips64el_unknown_linux_muslabi64.rsmips_unknown_linux_gnu.rsmips_unknown_linux_musl.rsmips_unknown_linux_uclibc.rsmipsel_sony_psp.rsmipsel_unknown_linux_gnu.rsmipsel_unknown_linux_musl.rsmipsel_unknown_linux_uclibc.rsmipsel_unknown_none.rsmipsisa32r6_unknown_linux_gnu.rsmipsisa32r6el_unknown_linux_gnu.rsmipsisa64r6_unknown_linux_gnuabi64.rsmipsisa64r6el_unknown_linux_gnuabi64.rsmod.rsmsp430_none_elf.rsmsvc_base.rsnetbsd_base.rsnvptx64_nvidia_cuda.rsopenbsd_base.rspowerpc64_unknown_freebsd.rspowerpc64_unknown_linux_gnu.rspowerpc64_unknown_linux_musl.rspowerpc64_wrs_vxworks.rspowerpc64le_unknown_freebsd.rspowerpc64le_unknown_linux_gnu.rspowerpc64le_unknown_linux_musl.rspowerpc_unknown_freebsd.rspowerpc_unknown_linux_gnu.rspowerpc_unknown_linux_gnuspe.rspowerpc_unknown_linux_musl.rspowerpc_unknown_netbsd.rspowerpc_unknown_openbsd.rspowerpc_wrs_vxworks.rspowerpc_wrs_vxworks_spe.rsredox_base.rsriscv32gc_unknown_linux_gnu.rsriscv32gc_unknown_linux_musl.rsriscv32i_unknown_none_elf.rsriscv32imac_unknown_none_elf.rsriscv32imc_esp_espidf.rsriscv32imc_unknown_none_elf.rsriscv64gc_unknown_linux_gnu.rsriscv64gc_unknown_linux_musl.rsriscv64gc_unknown_none_elf.rsriscv64imac_unknown_none_elf.rss390x_unknown_linux_gnu.rss390x_unknown_linux_musl.rssolaris_base.rssolid_base.rssparc64_unknown_linux_gnu.rssparc64_unknown_netbsd.rssparc64_unknown_openbsd.rssparc_unknown_linux_gnu.rssparcv9_sun_solaris.rsthumb_base.rsthumbv4t_none_eabi.rsthumbv6m_none_eabi.rsthumbv7a_pc_windows_msvc.rsthumbv7a_uwp_windows_msvc.rsthumbv7em_none_eabi.rsthumbv7em_none_eabihf.rsthumbv7m_none_eabi.rsthumbv7neon_linux_androideabi.rsthumbv7neon_unknown_linux_gnueabihf.rsthumbv7neon_unknown_linux_musleabihf.rsthumbv8m_base_none_eabi.rsthumbv8m_main_none_eabi.rsthumbv8m_main_none_eabihf.rsuefi_msvc_base.rsvxworks_base.rswasm32_unknown_emscripten.rswasm32_unknown_unknown.rswasm32_wasi.rswasm64_unknown_unknown.rswasm_base.rswindows_gnu_base.rswindows_msvc_base.rswindows_uwp_gnu_base.rswindows_uwp_msvc_base.rsx86_64_apple_darwin.rsx86_64_apple_ios.rsx86_64_apple_ios_macabi.rsx86_64_apple_tvos.rsx86_64_fortanix_unknown_sgx.rsx86_64_fuchsia.rsx86_64_linux_android.rsx86_64_pc_solaris.rsx86_64_pc_windows_gnu.rsx86_64_pc_windows_msvc.rsx86_64_sun_solaris.rsx86_64_unknown_dragonfly.rsx86_64_unknown_freebsd.rsx86_64_unknown_haiku.rsx86_64_unknown_hermit.rsx86_64_unknown_illumos.rsx86_64_unknown_l4re_uclibc.rsx86_64_unknown_linux_gnu.rsx86_64_unknown_linux_gnux32.rsx86_64_unknown_linux_musl.rsx86_64_unknown_netbsd.rsx86_64_unknown_none_hermitkernel.rsx86_64_unknown_none_linuxkernel.rsx86_64_unknown_openbsd.rsx86_64_unknown_redox.rsx86_64_unknown_uefi.rsx86_64_uwp_windows_gnu.rsx86_64_uwp_windows_msvc.rsx86_64_wrs_vxworks.rs
rustc_trait_selection
rustc_traits
rustc_ty_utils
rustc_type_ir
rustc_typeck
rustdoc
rustdoc_json_types
rustfmt
rustfmt_format_diff
rustfmt_nightly
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
//! A pass that annotates every item and method with its stability level,
//! propagating default levels lexically from parent to children ast nodes.

pub use self::StabilityLevel::*;

use crate::ty::{self, TyCtxt};
use rustc_ast::NodeId;
use rustc_attr::{self as attr, ConstStability, Deprecation, Stability};
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_feature::GateIssue;
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX};
use rustc_hir::{self, HirId};
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_session::lint::builtin::{DEPRECATED, DEPRECATED_IN_FUTURE, SOFT_UNSTABLE};
use rustc_session::lint::{BuiltinLintDiagnostics, Level, Lint, LintBuffer};
use rustc_session::parse::feature_err_issue;
use rustc_session::{DiagnosticMessageId, Session};
use rustc_span::symbol::{sym, Symbol};
use rustc_span::{MultiSpan, Span};
use std::num::NonZeroU32;

#[derive(PartialEq, Clone, Copy, Debug)]
pub enum StabilityLevel {
    Unstable,
    Stable,
}

/// An entry in the `depr_map`.
#[derive(Clone, HashStable, Debug)]
pub struct DeprecationEntry {
    /// The metadata of the attribute associated with this entry.
    pub attr: Deprecation,
    /// The `DefId` where the attr was originally attached. `None` for non-local
    /// `DefId`'s.
    origin: Option<LocalDefId>,
}

impl DeprecationEntry {
    pub fn local(attr: Deprecation, def_id: LocalDefId) -> DeprecationEntry {
        DeprecationEntry { attr, origin: Some(def_id) }
    }

    pub fn external(attr: Deprecation) -> DeprecationEntry {
        DeprecationEntry { attr, origin: None }
    }

    pub fn same_origin(&self, other: &DeprecationEntry) -> bool {
        match (self.origin, other.origin) {
            (Some(o1), Some(o2)) => o1 == o2,
            _ => false,
        }
    }
}

/// A stability index, giving the stability level for items and methods.
#[derive(HashStable, Debug)]
pub struct Index<'tcx> {
    /// This is mostly a cache, except the stabilities of local items
    /// are filled by the annotator.
    pub stab_map: FxHashMap<LocalDefId, &'tcx Stability>,
    pub const_stab_map: FxHashMap<LocalDefId, &'tcx ConstStability>,
    pub depr_map: FxHashMap<LocalDefId, DeprecationEntry>,

    /// Maps for each crate whether it is part of the staged API.
    pub staged_api: FxHashMap<CrateNum, bool>,

    /// Features enabled for this crate.
    pub active_features: FxHashSet<Symbol>,
}

impl<'tcx> Index<'tcx> {
    pub fn local_stability(&self, def_id: LocalDefId) -> Option<&'tcx Stability> {
        self.stab_map.get(&def_id).copied()
    }

    pub fn local_const_stability(&self, def_id: LocalDefId) -> Option<&'tcx ConstStability> {
        self.const_stab_map.get(&def_id).copied()
    }

    pub fn local_deprecation_entry(&self, def_id: LocalDefId) -> Option<DeprecationEntry> {
        self.depr_map.get(&def_id).cloned()
    }
}

pub fn report_unstable(
    sess: &Session,
    feature: Symbol,
    reason: Option<Symbol>,
    issue: Option<NonZeroU32>,
    is_soft: bool,
    span: Span,
    soft_handler: impl FnOnce(&'static Lint, Span, &str),
) {
    let msg = match reason {
        Some(r) => format!("use of unstable library feature '{}': {}", feature, r),
        None => format!("use of unstable library feature '{}'", &feature),
    };

    let msp: MultiSpan = span.into();
    let sm = &sess.parse_sess.source_map();
    let span_key = msp.primary_span().and_then(|sp: Span| {
        if !sp.is_dummy() {
            let file = sm.lookup_char_pos(sp.lo()).file;
            if file.is_imported() { None } else { Some(span) }
        } else {
            None
        }
    });

    let error_id = (DiagnosticMessageId::StabilityId(issue), span_key, msg.clone());
    let fresh = sess.one_time_diagnostics.borrow_mut().insert(error_id);
    if fresh {
        if is_soft {
            soft_handler(SOFT_UNSTABLE, span, &msg)
        } else {
            feature_err_issue(&sess.parse_sess, feature, span, GateIssue::Library(issue), &msg)
                .emit();
        }
    }
}

/// Checks whether an item marked with `deprecated(since="X")` is currently
/// deprecated (i.e., whether X is not greater than the current rustc version).
pub fn deprecation_in_effect(depr: &Deprecation) -> bool {
    let is_since_rustc_version = depr.is_since_rustc_version;
    let since = depr.since.map(Symbol::as_str);
    let since = since.as_deref();

    fn parse_version(ver: &str) -> Vec<u32> {
        // We ignore non-integer components of the version (e.g., "nightly").
        ver.split(|c| c == '.' || c == '-').flat_map(|s| s.parse()).collect()
    }

    if !is_since_rustc_version {
        // The `since` field doesn't have semantic purpose in the stable `deprecated`
        // attribute, only in `rustc_deprecated`.
        return true;
    }

    if let Some(since) = since {
        if since == "TBD" {
            return false;
        }

        if let Some(rustc) = option_env!("CFG_RELEASE") {
            let since: Vec<u32> = parse_version(&since);
            let rustc: Vec<u32> = parse_version(rustc);
            // We simply treat invalid `since` attributes as relating to a previous
            // Rust version, thus always displaying the warning.
            if since.len() != 3 {
                return true;
            }
            return since <= rustc;
        }
    };

    // Assume deprecation is in effect if "since" field is missing
    // or if we can't determine the current Rust version.
    true
}

pub fn deprecation_suggestion(
    diag: &mut DiagnosticBuilder<'_>,
    kind: &str,
    suggestion: Option<Symbol>,
    span: Span,
) {
    if let Some(suggestion) = suggestion {
        diag.span_suggestion(
            span,
            &format!("replace the use of the deprecated {}", kind),
            suggestion.to_string(),
            Applicability::MachineApplicable,
        );
    }
}

fn deprecation_lint(is_in_effect: bool) -> &'static Lint {
    if is_in_effect { DEPRECATED } else { DEPRECATED_IN_FUTURE }
}

fn deprecation_message(
    is_in_effect: bool,
    since: Option<Symbol>,
    note: Option<Symbol>,
    kind: &str,
    path: &str,
) -> String {
    let message = if is_in_effect {
        format!("use of deprecated {} `{}`", kind, path)
    } else {
        let since = since.map(Symbol::as_str);

        if since.as_deref() == Some("TBD") {
            format!("use of {} `{}` that will be deprecated in a future Rust version", kind, path)
        } else {
            format!(
                "use of {} `{}` that will be deprecated in future version {}",
                kind,
                path,
                since.unwrap()
            )
        }
    };

    match note {
        Some(reason) => format!("{}: {}", message, reason),
        None => message,
    }
}

pub fn deprecation_message_and_lint(
    depr: &Deprecation,
    kind: &str,
    path: &str,
) -> (String, &'static Lint) {
    let is_in_effect = deprecation_in_effect(depr);
    (
        deprecation_message(is_in_effect, depr.since, depr.note, kind, path),
        deprecation_lint(is_in_effect),
    )
}

pub fn early_report_deprecation(
    lint_buffer: &'a mut LintBuffer,
    message: &str,
    suggestion: Option<Symbol>,
    lint: &'static Lint,
    span: Span,
    node_id: NodeId,
) {
    if span.in_derive_expansion() {
        return;
    }

    let diag = BuiltinLintDiagnostics::DeprecatedMacro(suggestion, span);
    lint_buffer.buffer_lint_with_diagnostic(lint, node_id, span, message, diag);
}

fn late_report_deprecation(
    tcx: TyCtxt<'_>,
    message: &str,
    suggestion: Option<Symbol>,
    lint: &'static Lint,
    span: Span,
    method_span: Option<Span>,
    hir_id: HirId,
    def_id: DefId,
) {
    if span.in_derive_expansion() {
        return;
    }
    let method_span = method_span.unwrap_or(span);
    tcx.struct_span_lint_hir(lint, hir_id, method_span, |lint| {
        let mut diag = lint.build(message);
        if let hir::Node::Expr(_) = tcx.hir().get(hir_id) {
            let kind = tcx.def_kind(def_id).descr(def_id);
            deprecation_suggestion(&mut diag, kind, suggestion, method_span);
        }
        diag.emit()
    });
}

/// Result of `TyCtxt::eval_stability`.
pub enum EvalResult {
    /// We can use the item because it is stable or we provided the
    /// corresponding feature gate.
    Allow,
    /// We cannot use the item because it is unstable and we did not provide the
    /// corresponding feature gate.
    Deny { feature: Symbol, reason: Option<Symbol>, issue: Option<NonZeroU32>, is_soft: bool },
    /// The item does not have the `#[stable]` or `#[unstable]` marker assigned.
    Unmarked,
}

// See issue #38412.
fn skip_stability_check_due_to_privacy(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
    if tcx.def_kind(def_id) == DefKind::TyParam {
        // Have no visibility, considered public for the purpose of this check.
        return false;
    }
    match tcx.visibility(def_id) {
        // Must check stability for `pub` items.
        ty::Visibility::Public => false,

        // These are not visible outside crate; therefore
        // stability markers are irrelevant, if even present.
        ty::Visibility::Restricted(..) | ty::Visibility::Invisible => true,
    }
}

impl<'tcx> TyCtxt<'tcx> {
    /// Evaluates the stability of an item.
    ///
    /// Returns `EvalResult::Allow` if the item is stable, or unstable but the corresponding
    /// `#![feature]` has been provided. Returns `EvalResult::Deny` which describes the offending
    /// unstable feature otherwise.
    ///
    /// If `id` is `Some(_)`, this function will also check if the item at `def_id` has been
    /// deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to
    /// `id`.
    pub fn eval_stability(
        self,
        def_id: DefId,
        id: Option<HirId>,
        span: Span,
        method_span: Option<Span>,
    ) -> EvalResult {
        // Deprecated attributes apply in-crate and cross-crate.
        if let Some(id) = id {
            if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) {
                let parent_def_id = self.hir().local_def_id(self.hir().get_parent_item(id));
                let skip = self
                    .lookup_deprecation_entry(parent_def_id.to_def_id())
                    .map_or(false, |parent_depr| parent_depr.same_origin(&depr_entry));

                // #[deprecated] doesn't emit a notice if we're not on the
                // topmost deprecation. For example, if a struct is deprecated,
                // the use of a field won't be linted.
                //
                // #[rustc_deprecated] however wants to emit down the whole
                // hierarchy.
                let depr_attr = &depr_entry.attr;
                if !skip || depr_attr.is_since_rustc_version {
                    // Calculating message for lint involves calling `self.def_path_str`.
                    // Which by default to calculate visible path will invoke expensive `visible_parent_map` query.
                    // So we skip message calculation altogether, if lint is allowed.
                    let is_in_effect = deprecation_in_effect(depr_attr);
                    let lint = deprecation_lint(is_in_effect);
                    if self.lint_level_at_node(lint, id).0 != Level::Allow {
                        let def_path = &with_no_trimmed_paths(|| self.def_path_str(def_id));
                        let def_kind = self.def_kind(def_id).descr(def_id);

                        late_report_deprecation(
                            self,
                            &deprecation_message(
                                is_in_effect,
                                depr_attr.since,
                                depr_attr.note,
                                def_kind,
                                def_path,
                            ),
                            depr_attr.suggestion,
                            lint,
                            span,
                            method_span,
                            id,
                            def_id,
                        );
                    }
                }
            };
        }

        let is_staged_api =
            self.lookup_stability(DefId { index: CRATE_DEF_INDEX, ..def_id }).is_some();
        if !is_staged_api {
            return EvalResult::Allow;
        }

        let stability = self.lookup_stability(def_id);
        debug!(
            "stability: \
                inspecting def_id={:?} span={:?} of stability={:?}",
            def_id, span, stability
        );

        // Only the cross-crate scenario matters when checking unstable APIs
        let cross_crate = !def_id.is_local();
        if !cross_crate {
            return EvalResult::Allow;
        }

        // Issue #38412: private items lack stability markers.
        if skip_stability_check_due_to_privacy(self, def_id) {
            return EvalResult::Allow;
        }

        match stability {
            Some(&Stability {
                level: attr::Unstable { reason, issue, is_soft }, feature, ..
            }) => {
                if span.allows_unstable(feature) {
                    debug!("stability: skipping span={:?} since it is internal", span);
                    return EvalResult::Allow;
                }
                if self.stability().active_features.contains(&feature) {
                    return EvalResult::Allow;
                }

                // When we're compiling the compiler itself we may pull in
                // crates from crates.io, but those crates may depend on other
                // crates also pulled in from crates.io. We want to ideally be
                // able to compile everything without requiring upstream
                // modifications, so in the case that this looks like a
                // `rustc_private` crate (e.g., a compiler crate) and we also have
                // the `-Z force-unstable-if-unmarked` flag present (we're
                // compiling a compiler crate), then let this missing feature
                // annotation slide.
                if feature == sym::rustc_private && issue == NonZeroU32::new(27812) {
                    if self.sess.opts.debugging_opts.force_unstable_if_unmarked {
                        return EvalResult::Allow;
                    }
                }

                EvalResult::Deny { feature, reason, issue, is_soft }
            }
            Some(_) => {
                // Stable APIs are always ok to call and deprecated APIs are
                // handled by the lint emitting logic above.
                EvalResult::Allow
            }
            None => EvalResult::Unmarked,
        }
    }

    /// Checks if an item is stable or error out.
    ///
    /// If the item defined by `def_id` is unstable and the corresponding `#![feature]` does not
    /// exist, emits an error.
    ///
    /// This function will also check if the item is deprecated.
    /// If so, and `id` is not `None`, a deprecated lint attached to `id` will be emitted.
    pub fn check_stability(
        self,
        def_id: DefId,
        id: Option<HirId>,
        span: Span,
        method_span: Option<Span>,
    ) {
        self.check_optional_stability(def_id, id, span, method_span, |span, def_id| {
            // The API could be uncallable for other reasons, for example when a private module
            // was referenced.
            self.sess.delay_span_bug(span, &format!("encountered unmarked API: {:?}", def_id));
        })
    }

    /// Like `check_stability`, except that we permit items to have custom behaviour for
    /// missing stability attributes (not necessarily just emit a `bug!`). This is necessary
    /// for default generic parameters, which only have stability attributes if they were
    /// added after the type on which they're defined.
    pub fn check_optional_stability(
        self,
        def_id: DefId,
        id: Option<HirId>,
        span: Span,
        method_span: Option<Span>,
        unmarked: impl FnOnce(Span, DefId),
    ) {
        let soft_handler = |lint, span, msg: &_| {
            self.struct_span_lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, |lint| {
                lint.build(msg).emit()
            })
        };
        match self.eval_stability(def_id, id, span, method_span) {
            EvalResult::Allow => {}
            EvalResult::Deny { feature, reason, issue, is_soft } => {
                report_unstable(self.sess, feature, reason, issue, is_soft, span, soft_handler)
            }
            EvalResult::Unmarked => unmarked(span, def_id),
        }
    }

    pub fn lookup_deprecation(self, id: DefId) -> Option<Deprecation> {
        self.lookup_deprecation_entry(id).map(|depr| depr.attr)
    }
}