Skip to content

Commit ccfac54

Browse files
committed
Rename LevelAndSource
It is misnamed, given that it has three fields: `level`, `lint_id`, and `src`. (Presumably the `lint_id` was added later.) This commit renames it as `LevelSpec`. (I also considered `LevelInfo` but that's very generic. `Spec` has pre-existing uses in `LintLevelsProvider::current_specs` and `LintSet::specs` and `ShallowLintLevelMap::specs`.) Related things renamed as well: - `level` -> `level_spec` (where appropriate) - `lint_levels` -> `lint_level_specs` - `get_lint_level` -> `get_lint_level_spec` - `level_and_source` -> `level_spec` - `CodegenLintLevels` -> `CodegenLintLevelSpecs` - `raw_lint_id_level` -> `raw_lint_level_spec` - `lint_level_at_node` -> `lint_level_spec_at_node` - `reveal_actual_level` -> `reveal_actual_level_spec` - `probe_for_lint_level` -> `probe_for_lint_level_spec` This clears up a lot of `Level` vs. `LevelSpec` ambiguity. E.g. no more `level.level` expressions.
1 parent ff9a9ea commit ccfac54

28 files changed

Lines changed: 199 additions & 196 deletions

File tree

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use super::metadata::{MetadataPosition, create_wrapper_file};
6060
use super::rpath::{self, RPathConfig};
6161
use super::{apple, rmeta_link, versioned_llvm_target};
6262
use crate::base::needs_allocator_shim_for_linking;
63-
use crate::{CodegenLintLevels, CompiledModule, CompiledModules, CrateInfo, NativeLib, errors};
63+
use crate::{CodegenLintLevelSpecs, CompiledModule, CompiledModules, CrateInfo, NativeLib, errors};
6464

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

731-
fn report_linker_output(sess: &Session, levels: CodegenLintLevels, stdout: &[u8], stderr: &[u8]) {
731+
fn report_linker_output(
732+
sess: &Session,
733+
levels: CodegenLintLevelSpecs,
734+
stdout: &[u8],
735+
stderr: &[u8],
736+
) {
732737
let mut escaped_stderr = escape_string(&stderr);
733738
let mut escaped_stdout = escape_string(&stdout);
734739
let mut linker_info = String::new();
@@ -1106,7 +1111,7 @@ fn link_natively(
11061111
}
11071112

11081113
info!("reporting linker output: flavor={flavor:?}");
1109-
report_linker_output(sess, crate_info.lint_levels, &prog.stdout, &prog.stderr);
1114+
report_linker_output(sess, crate_info.lint_level_specs, &prog.stdout, &prog.stderr);
11101115
}
11111116
Err(e) => {
11121117
let linker_not_found = e.kind() == io::ErrorKind::NotFound;

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ use crate::meth::load_vtable;
4949
use crate::mir::operand::OperandValue;
5050
use crate::mir::place::PlaceRef;
5151
use crate::traits::*;
52-
use crate::{CachedModuleCodegen, CodegenLintLevels, CrateInfo, ModuleCodegen, errors, meth, mir};
52+
use crate::{
53+
CachedModuleCodegen, CodegenLintLevelSpecs, CrateInfo, ModuleCodegen, errors, meth, mir,
54+
};
5355

5456
pub(crate) fn bin_op_to_icmp_predicate(op: BinOp, signed: bool) -> IntPredicate {
5557
match (op, signed) {
@@ -953,7 +955,7 @@ impl CrateInfo {
953955
dependency_formats: Arc::clone(tcx.dependency_formats(())),
954956
windows_subsystem,
955957
natvis_debugger_visualizers: Default::default(),
956-
lint_levels: CodegenLintLevels::from_tcx(tcx),
958+
lint_level_specs: CodegenLintLevelSpecs::from_tcx(tcx),
957959
metadata_symbol: exported_symbols::metadata_symbol_name(tcx),
958960
each_linked_rlib_file_for_lto: Default::default(),
959961
exported_symbols_for_lto: Default::default(),

compiler/rustc_codegen_ssa/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_lint_defs::builtin::LINKER_INFO;
2626
use rustc_macros::{Decodable, Encodable};
2727
use rustc_metadata::EncodedMetadata;
2828
use rustc_middle::dep_graph::WorkProduct;
29-
use rustc_middle::lint::LevelAndSource;
29+
use rustc_middle::lint::LevelSpec;
3030
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
3131
use rustc_middle::middle::dependency_format::Dependencies;
3232
use rustc_middle::middle::exported_symbols::SymbolExportKind;
@@ -223,7 +223,7 @@ pub struct CrateInfo {
223223
pub dependency_formats: Arc<Dependencies>,
224224
pub windows_subsystem: Option<WindowsSubsystemKind>,
225225
pub natvis_debugger_visualizers: BTreeSet<DebuggerVisualizerFile>,
226-
pub lint_levels: CodegenLintLevels,
226+
pub lint_level_specs: CodegenLintLevelSpecs,
227227
pub metadata_symbol: String,
228228
pub each_linked_rlib_file_for_lto: Vec<PathBuf>,
229229
pub exported_symbols_for_lto: Vec<String>,
@@ -341,16 +341,16 @@ impl CompiledModules {
341341
/// solely from the `.rlink` file. `Lint`s are defined too early to be encodeable.
342342
/// Instead, encode exactly the information we need.
343343
#[derive(Copy, Clone, Debug, Encodable, Decodable)]
344-
pub struct CodegenLintLevels {
345-
linker_messages: LevelAndSource,
346-
linker_info: LevelAndSource,
344+
pub struct CodegenLintLevelSpecs {
345+
linker_messages: LevelSpec,
346+
linker_info: LevelSpec,
347347
}
348348

349-
impl CodegenLintLevels {
349+
impl CodegenLintLevelSpecs {
350350
pub fn from_tcx(tcx: TyCtxt<'_>) -> Self {
351351
Self {
352-
linker_messages: tcx.lint_level_at_node(LINKER_MESSAGES, CRATE_HIR_ID),
353-
linker_info: tcx.lint_level_at_node(LINKER_INFO, CRATE_HIR_ID),
352+
linker_messages: tcx.lint_level_spec_at_node(LINKER_MESSAGES, CRATE_HIR_ID),
353+
linker_info: tcx.lint_level_spec_at_node(LINKER_INFO, CRATE_HIR_ID),
354354
}
355355
}
356356
}

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
735735
let hir_id = ecx.machine.best_lint_scope(*ecx.tcx);
736736
let is_error = ecx
737737
.tcx
738-
.lint_level_at_node(
738+
.lint_level_spec_at_node(
739739
rustc_session::lint::builtin::LONG_RUNNING_CONST_EVAL,
740740
hir_id,
741741
)

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ fn print_crate_info(
714714
let lint_store = crate::unerased_lint_store(sess);
715715
let features = rustc_expand::config::features(sess, attrs, crate_name);
716716
let registered_tools = rustc_resolve::registered_tools_ast(sess.dcx(), attrs, sess);
717-
let lint_levels = rustc_lint::LintLevelsBuilder::crate_root(
717+
let builder = rustc_lint::LintLevelsBuilder::crate_root(
718718
sess,
719719
&features,
720720
true,
@@ -729,7 +729,7 @@ fn print_crate_info(
729729
// lint is unstable and feature gate isn't active, don't print
730730
continue;
731731
}
732-
let level = lint_levels.lint_level(lint).level;
732+
let level = builder.lint_level_spec(lint).level;
733733
println_info!("{}={}", lint.name_lower(), level.as_str());
734734
}
735735
}

compiler/rustc_hir_typeck/src/upvar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,7 @@ fn should_do_rust_2021_incompatible_closure_captures_analysis(
24162416
}
24172417

24182418
let level = tcx
2419-
.lint_level_at_node(lint::builtin::RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES, closure_id)
2419+
.lint_level_spec_at_node(lint::builtin::RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES, closure_id)
24202420
.level;
24212421

24222422
!matches!(level, lint::Level::Allow)

compiler/rustc_lint/src/builtin.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
3030
use rustc_hir::intravisit::FnKind as HirFnKind;
3131
use rustc_hir::{self as hir, Body, FnDecl, ImplItemImplKind, PatKind, PredicateOrigin, find_attr};
3232
use rustc_middle::bug;
33-
use rustc_middle::lint::LevelAndSource;
3433
use rustc_middle::ty::layout::LayoutOf;
3534
use rustc_middle::ty::print::with_no_trimmed_paths;
3635
use rustc_middle::ty::{
@@ -695,8 +694,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
695694
}
696695

697696
// Avoid listing trait impls if the trait is allowed.
698-
let LevelAndSource { level, .. } =
699-
cx.tcx.lint_level_at_node(MISSING_DEBUG_IMPLEMENTATIONS, item.hir_id());
697+
let level =
698+
cx.tcx.lint_level_spec_at_node(MISSING_DEBUG_IMPLEMENTATIONS, item.hir_id()).level;
700699
if level == Level::Allow {
701700
return;
702701
}

compiler/rustc_lint/src/context.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_hir::def_id::{CrateNum, DefId};
2020
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
2121
use rustc_hir::{Pat, PatKind};
2222
use rustc_middle::bug;
23-
use rustc_middle::lint::LevelAndSource;
23+
use rustc_middle::lint::LevelSpec;
2424
use rustc_middle::middle::privacy::EffectiveVisibilities;
2525
use rustc_middle::ty::layout::{LayoutError, LayoutOfHelpers, TyAndLayout};
2626
use rustc_middle::ty::print::{PrintError, PrintTraitRefExt as _, Printer, with_no_trimmed_paths};
@@ -537,8 +537,8 @@ pub trait LintContext {
537537
self.opt_span_lint(lint, Some(span), decorator);
538538
}
539539

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

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

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

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

627-
fn get_lint_level(&self, lint: &'static Lint) -> LevelAndSource {
628-
self.builder.lint_level(lint)
627+
fn get_lint_level_spec(&self, lint: &'static Lint) -> LevelSpec {
628+
self.builder.lint_level_spec(lint)
629629
}
630630
}
631631

0 commit comments

Comments
 (0)