Skip to content
44 changes: 43 additions & 1 deletion compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::collections::VecDeque;
use std::fmt;
use std::rc::Rc;

use rustc_data_structures::frozen::Frozen;
Expand Down Expand Up @@ -182,7 +183,7 @@ pub(crate) enum Cause {
/// For more information about this translation, see
/// `InferCtxt::process_registered_region_obligations` and
/// `InferCtxt::type_must_outlive` in `rustc_infer::infer::InferCtxt`.
#[derive(Clone, Debug)]
#[derive(Clone)]
pub(crate) struct TypeTest<'tcx> {
/// The type `T` that must outlive the region.
pub generic_kind: GenericKind<'tcx>,
Expand All @@ -198,6 +199,47 @@ pub(crate) struct TypeTest<'tcx> {
pub verify_bound: VerifyBound<'tcx>,
}

impl fmt::Debug for TypeTest<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn fmt_bound(
f: &mut fmt::Formatter<'_>,
generic_kind: GenericKind<'_>,
lower: RegionVid,
bound: &VerifyBound<'_>,
) -> fmt::Result {
let fmt_bounds =
|f: &mut fmt::Formatter<'_>, bounds: &[VerifyBound<'_>]| -> fmt::Result {
let mut it = bounds.iter().peekable();
while let Some(bound) = it.next() {
fmt_bound(f, generic_kind, lower, bound)?;
if it.peek().is_some() {
write!(f, ", ")?
}
}
Ok(())
};
match bound {
VerifyBound::IfEq(binder) => write!(f, "{:?} == {:?}", generic_kind, binder),
VerifyBound::OutlivedBy(region) => write!(f, "{region:?}: {lower:?}"),
VerifyBound::AnyBound(verify_bounds) => {
write!(f, "Any[")?;
fmt_bounds(f, verify_bounds)?;
write!(f, "]")
}
VerifyBound::AllBounds(verify_bounds) => {
write!(f, "All[")?;
fmt_bounds(f, verify_bounds)?;
write!(f, "]")
}
VerifyBound::IsEmpty => write!(f, "Empty({lower:?})"),
}
}
write!(f, "TypeTest from {:?}[", self.span)?;
fmt_bound(f, self.generic_kind, self.lower_bound, &self.verify_bound)?;
write!(f, "] ⊢ {:?}: {:?}", self.generic_kind, self.lower_bound)
}
}

/// When we have an unmet lifetime constraint, we try to propagate it outward (e.g. to a closure
/// environment). If we can't, it is an error.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use super::metadata::{MetadataPosition, create_wrapper_file};
use super::rpath::{self, RPathConfig};
use super::{apple, rmeta_link, versioned_llvm_target};
use crate::base::needs_allocator_shim_for_linking;
use crate::{CodegenLintLevels, CompiledModule, CompiledModules, CrateInfo, NativeLib, errors};
use crate::{CodegenLintLevelSpecs, CompiledModule, CompiledModules, CrateInfo, NativeLib, errors};

pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) {
if let Err(e) = fs::remove_file(path) {
Expand Down Expand Up @@ -728,7 +728,12 @@ fn is_windows_gnu_clang(sess: &Session) -> bool {
&& sess.target.options.cfg_abi == CfgAbi::Llvm
}

fn report_linker_output(sess: &Session, levels: CodegenLintLevels, stdout: &[u8], stderr: &[u8]) {
fn report_linker_output(
sess: &Session,
levels: CodegenLintLevelSpecs,
stdout: &[u8],
stderr: &[u8],
) {
let mut escaped_stderr = escape_string(&stderr);
let mut escaped_stdout = escape_string(&stdout);
let mut linker_info = String::new();
Expand Down Expand Up @@ -1106,7 +1111,7 @@ fn link_natively(
}

info!("reporting linker output: flavor={flavor:?}");
report_linker_output(sess, crate_info.lint_levels, &prog.stdout, &prog.stderr);
report_linker_output(sess, crate_info.lint_level_specs, &prog.stdout, &prog.stderr);
}
Err(e) => {
let linker_not_found = e.kind() == io::ErrorKind::NotFound;
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ use crate::meth::load_vtable;
use crate::mir::operand::OperandValue;
use crate::mir::place::PlaceRef;
use crate::traits::*;
use crate::{CachedModuleCodegen, CodegenLintLevels, CrateInfo, ModuleCodegen, errors, meth, mir};
use crate::{
CachedModuleCodegen, CodegenLintLevelSpecs, CrateInfo, ModuleCodegen, errors, meth, mir,
};

pub(crate) fn bin_op_to_icmp_predicate(op: BinOp, signed: bool) -> IntPredicate {
match (op, signed) {
Expand Down Expand Up @@ -953,7 +955,7 @@ impl CrateInfo {
dependency_formats: Arc::clone(tcx.dependency_formats(())),
windows_subsystem,
natvis_debugger_visualizers: Default::default(),
lint_levels: CodegenLintLevels::from_tcx(tcx),
lint_level_specs: CodegenLintLevelSpecs::from_tcx(tcx),
metadata_symbol: exported_symbols::metadata_symbol_name(tcx),
each_linked_rlib_file_for_lto: Default::default(),
exported_symbols_for_lto: Default::default(),
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rustc_lint_defs::builtin::LINKER_INFO;
use rustc_macros::{Decodable, Encodable};
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::WorkProduct;
use rustc_middle::lint::LevelAndSource;
use rustc_middle::lint::LevelSpec;
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
use rustc_middle::middle::dependency_format::Dependencies;
use rustc_middle::middle::exported_symbols::SymbolExportKind;
Expand Down Expand Up @@ -223,7 +223,7 @@ pub struct CrateInfo {
pub dependency_formats: Arc<Dependencies>,
pub windows_subsystem: Option<WindowsSubsystemKind>,
pub natvis_debugger_visualizers: BTreeSet<DebuggerVisualizerFile>,
pub lint_levels: CodegenLintLevels,
pub lint_level_specs: CodegenLintLevelSpecs,
pub metadata_symbol: String,
pub each_linked_rlib_file_for_lto: Vec<PathBuf>,
pub exported_symbols_for_lto: Vec<String>,
Expand Down Expand Up @@ -341,16 +341,16 @@ impl CompiledModules {
/// solely from the `.rlink` file. `Lint`s are defined too early to be encodeable.
/// Instead, encode exactly the information we need.
#[derive(Copy, Clone, Debug, Encodable, Decodable)]
pub struct CodegenLintLevels {
linker_messages: LevelAndSource,
linker_info: LevelAndSource,
pub struct CodegenLintLevelSpecs {
linker_messages: LevelSpec,
linker_info: LevelSpec,
}

impl CodegenLintLevels {
impl CodegenLintLevelSpecs {
pub fn from_tcx(tcx: TyCtxt<'_>) -> Self {
Self {
linker_messages: tcx.lint_level_at_node(LINKER_MESSAGES, CRATE_HIR_ID),
linker_info: tcx.lint_level_at_node(LINKER_INFO, CRATE_HIR_ID),
linker_messages: tcx.lint_level_spec_at_node(LINKER_MESSAGES, CRATE_HIR_ID),
linker_info: tcx.lint_level_spec_at_node(LINKER_INFO, CRATE_HIR_ID),
}
}
}
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,11 +735,11 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
let hir_id = ecx.machine.best_lint_scope(*ecx.tcx);
let is_error = ecx
.tcx
.lint_level_at_node(
.lint_level_spec_at_node(
rustc_session::lint::builtin::LONG_RUNNING_CONST_EVAL,
hir_id,
)
.level
.level()
.is_error();
let span = ecx.cur_span();
ecx.tcx.emit_node_span_lint(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ fn print_crate_info(
let lint_store = crate::unerased_lint_store(sess);
let features = rustc_expand::config::features(sess, attrs, crate_name);
let registered_tools = rustc_resolve::registered_tools_ast(sess.dcx(), attrs, sess);
let lint_levels = rustc_lint::LintLevelsBuilder::crate_root(
let builder = rustc_lint::LintLevelsBuilder::crate_root(
sess,
&features,
true,
Expand All @@ -729,7 +729,7 @@ fn print_crate_info(
// lint is unstable and feature gate isn't active, don't print
continue;
}
let level = lint_levels.lint_level(lint).level;
let level = builder.lint_level_spec(lint).level();
println_info!("{}={}", lint.name_lower(), level.as_str());
}
}
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_hir_typeck/src/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2415,11 +2415,8 @@ fn should_do_rust_2021_incompatible_closure_captures_analysis(
return false;
}

let level = tcx
.lint_level_at_node(lint::builtin::RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES, closure_id)
.level;

!matches!(level, lint::Level::Allow)
!tcx.lint_level_spec_at_node(lint::builtin::RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES, closure_id)
.is_allow()
}

/// Return a two string tuple (s1, s2)
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
use rustc_hir::intravisit::FnKind as HirFnKind;
use rustc_hir::{self as hir, Body, FnDecl, ImplItemImplKind, PatKind, PredicateOrigin, find_attr};
use rustc_middle::bug;
use rustc_middle::lint::LevelAndSource;
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{
Expand Down Expand Up @@ -61,7 +60,8 @@ use crate::lints::{
BuiltinUnreachablePub, BuiltinUnsafe, BuiltinUnstableFeatures, BuiltinUnusedDocComment,
BuiltinUnusedDocCommentSub, BuiltinWhileTrue, EqInternalMethodImplemented, InvalidAsmLabel,
};
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, Level, LintContext};
use crate::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};

declare_lint! {
/// The `while_true` lint detects `while true { }`.
///
Expand Down Expand Up @@ -695,9 +695,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
}

// Avoid listing trait impls if the trait is allowed.
let LevelAndSource { level, .. } =
cx.tcx.lint_level_at_node(MISSING_DEBUG_IMPLEMENTATIONS, item.hir_id());
if level == Level::Allow {
if cx.tcx.lint_level_spec_at_node(MISSING_DEBUG_IMPLEMENTATIONS, item.hir_id()).is_allow() {
return;
}

Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use rustc_hir::def_id::{CrateNum, DefId};
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
use rustc_hir::{Pat, PatKind};
use rustc_middle::bug;
use rustc_middle::lint::LevelAndSource;
use rustc_middle::lint::LevelSpec;
use rustc_middle::middle::privacy::EffectiveVisibilities;
use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
use rustc_middle::ty::print::{PrintError, PrintTraitRefExt as _, Printer, with_no_trimmed_paths};
Expand Down Expand Up @@ -537,8 +537,8 @@ pub trait LintContext {
self.opt_span_lint(lint, Some(span), decorator);
}

/// This returns the lint level for the given lint at the current location.
fn get_lint_level(&self, lint: &'static Lint) -> LevelAndSource;
/// This returns the lint level spec for the given lint at the current location.
fn get_lint_level_spec(&self, lint: &'static Lint) -> LevelSpec;

/// This function can be used to manually fulfill an expectation. This can
/// be used for lints which contain several spans, and should be suppressed,
Expand Down Expand Up @@ -604,8 +604,8 @@ impl<'tcx> LintContext for LateContext<'tcx> {
}
}

fn get_lint_level(&self, lint: &'static Lint) -> LevelAndSource {
self.tcx.lint_level_at_node(lint, self.last_node_with_lint_attrs)
fn get_lint_level_spec(&self, lint: &'static Lint) -> LevelSpec {
self.tcx.lint_level_spec_at_node(lint, self.last_node_with_lint_attrs)
}
}

Expand All @@ -624,8 +624,8 @@ impl LintContext for EarlyContext<'_> {
self.builder.opt_span_lint(lint, span.map(|s| s.into()), decorator)
}

fn get_lint_level(&self, lint: &'static Lint) -> LevelAndSource {
self.builder.lint_level(lint)
fn get_lint_level_spec(&self, lint: &'static Lint) -> LevelSpec {
self.builder.lint_level_spec(lint)
}
}

Expand Down
Loading
Loading