Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2d2307e
Dedup `&mut *` reborrow suggestion in loops
ShE3py Mar 13, 2025
2feb911
io: Avoid marking buffer as uninit when copying to `BufWriter`
a1phyr Mar 28, 2025
8787868
io: Avoid Avoid marking bytes as uninit in `BufReader::peek`
a1phyr Mar 28, 2025
1d6ddd6
Remove unused variables generated in merged doctests
GuillaumeGomez Apr 2, 2025
2dd4501
Put Noratrieb on vacation
Noratrieb Apr 2, 2025
f798c46
Map myself
RossSmyth Mar 4, 2025
076cccd
Remove `Op` type.
nnethercote Dec 19, 2024
ac8ccf0
Use `BinOpKind` instead of `BinOp` for function args where possible.
nnethercote Dec 19, 2024
ddcb370
Tighten up assignment operator representations.
nnethercote Dec 19, 2024
f3eaf16
Split ExpectationLintId off Level
oli-obk Mar 18, 2025
c51816e
Make LevelAndSource a struct
oli-obk Mar 19, 2025
805f389
Remove `LintExpectationId` from `Level` variants
oli-obk Mar 19, 2025
0795b3d
Upvars HirIds always have the same owner, thus just use an ItemLocalId
oli-obk Mar 17, 2025
5a4e7eb
impl !PartialOrd for UpvarMigrationInfo
oli-obk Mar 17, 2025
57c4ab7
impl !PartialOrd for HirId
oli-obk Mar 17, 2025
3df2acd
Allow boolean literals in `check-cfg`
clubby789 Mar 21, 2025
b310e8c
add Marco Ieni to mailmap
marcoieni Apr 3, 2025
e5c7451
Rollup merge of #138017 - nnethercote:tighten-assignment-op, r=spasto…
matthiaskrgr Apr 3, 2025
731ce84
Rollup merge of #138462 - ShE3py:mut-borrow-in-loop, r=oli-obk
matthiaskrgr Apr 3, 2025
48a3919
Rollup merge of #138610 - oli-obk:no-sort-hir-ids, r=compiler-errors
matthiaskrgr Apr 3, 2025
9d733ec
Rollup merge of #138767 - clubby789:check-cfg-bool, r=Urgau
matthiaskrgr Apr 3, 2025
ff8f2ef
Rollup merge of #139068 - a1phyr:less_uninit, r=joboet
matthiaskrgr Apr 3, 2025
ed6efe6
Rollup merge of #139255 - GuillaumeGomez:unused-var-merged-doctest, r…
matthiaskrgr Apr 3, 2025
ec9aa8c
Rollup merge of #139270 - RossSmyth:mailmap, r=Noratrieb
matthiaskrgr Apr 3, 2025
42aef0c
Rollup merge of #139303 - Noratrieb:Noratrieb-patch-3, r=Noratrieb
matthiaskrgr Apr 3, 2025
4cf6c21
Rollup merge of #139312 - marcoieni:marco-mailmap, r=Kobzol
matthiaskrgr Apr 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make LevelAndSource a struct
  • Loading branch information
oli-obk committed Apr 3, 2025
commit c51816ee59576477f79d58e633e145bec381d807
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,9 +959,9 @@ fn link_natively(
}
}

let (level, src) = codegen_results.crate_info.lint_levels.linker_messages;
let level = codegen_results.crate_info.lint_levels.linker_messages;
let lint = |msg| {
lint_level(sess, LINKER_MESSAGES, level, src, None, |diag| {
lint_level(sess, LINKER_MESSAGES, level, None, |diag| {
LinkerOutput { inner: msg }.decorate_lint(diag)
})
};
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_ssa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use rustc_hir::CRATE_HIR_ID;
use rustc_hir::def_id::CrateNum;
use rustc_macros::{Decodable, Encodable, HashStable};
use rustc_middle::dep_graph::WorkProduct;
use rustc_middle::lint::LintLevelSource;
use rustc_middle::lint::LevelAndSource;
use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
use rustc_middle::middle::dependency_format::Dependencies;
use rustc_middle::middle::exported_symbols::SymbolExportKind;
Expand All @@ -45,7 +45,6 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use rustc_session::Session;
use rustc_session::config::{CrateType, OutputFilenames, OutputType, RUST_CGU_EXT};
use rustc_session::cstore::{self, CrateSource};
use rustc_session::lint::Level;
use rustc_session::lint::builtin::LINKER_MESSAGES;
use rustc_session::utils::NativeLibKind;
use rustc_span::Symbol;
Expand Down Expand Up @@ -341,7 +340,7 @@ impl CodegenResults {
/// Instead, encode exactly the information we need.
#[derive(Copy, Clone, Debug, Encodable, Decodable)]
pub struct CodegenLintLevels {
linker_messages: (Level, LintLevelSource),
linker_messages: LevelAndSource,
}

impl CodegenLintLevels {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
rustc_session::lint::builtin::LONG_RUNNING_CONST_EVAL,
hir_id,
)
.0
.level
.is_error();
let span = ecx.cur_span();
ecx.tcx.emit_node_span_lint(
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_hir_typeck/src/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2323,8 +2323,9 @@ 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);
let level = tcx
.lint_level_at_node(lint::builtin::RUST_2021_INCOMPATIBLE_CLOSURE_CAPTURES, closure_id)
.level;

!matches!(level, lint::Level::Allow)
}
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
use rustc_hir::intravisit::FnKind as HirFnKind;
use rustc_hir::{Body, FnDecl, GenericParamKind, PatKind, PredicateOrigin};
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::{self, Ty, TyCtxt, TypeVisitableExt, Upcast, VariantDef};
Expand Down Expand Up @@ -694,7 +695,8 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
}

// Avoid listing trait impls if the trait is allowed.
let (level, _) = cx.tcx.lint_level_at_node(MISSING_DEBUG_IMPLEMENTATIONS, item.hir_id());
let LevelAndSource { level, .. } =
cx.tcx.lint_level_at_node(MISSING_DEBUG_IMPLEMENTATIONS, item.hir_id());
if level == Level::Allow {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ impl<'tcx> LintContext for LateContext<'tcx> {
}

fn get_lint_level(&self, lint: &'static Lint) -> Level {
self.tcx.lint_level_at_node(lint, self.last_node_with_lint_attrs).0
self.tcx.lint_level_at_node(lint, self.last_node_with_lint_attrs).level
}
}

Expand All @@ -664,7 +664,7 @@ impl LintContext for EarlyContext<'_> {
}

fn get_lint_level(&self, lint: &'static Lint) -> Level {
self.builder.lint_level(lint).0
self.builder.lint_level(lint).level
}
}

Expand Down
59 changes: 33 additions & 26 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl LintLevelSets {
let level = reveal_actual_level(level, &mut src, sess, lint, |id| {
self.raw_lint_id_level(id, idx, aux)
});
(level, src)
LevelAndSource { level, src }
}

fn raw_lint_id_level(
Expand All @@ -97,14 +97,14 @@ impl LintLevelSets {
aux: Option<&FxIndexMap<LintId, LevelAndSource>>,
) -> (Option<Level>, LintLevelSource) {
if let Some(specs) = aux
&& let Some(&(level, src)) = specs.get(&id)
&& let Some(&LevelAndSource { level, src }) = specs.get(&id)
{
return (Some(level), src);
}

loop {
let LintSet { ref specs, parent } = self.list[idx];
if let Some(&(level, src)) = specs.get(&id) {
if let Some(&LevelAndSource { level, src }) = specs.get(&id) {
return (Some(level), src);
}
if idx == COMMAND_LINE {
Expand All @@ -131,8 +131,8 @@ fn lints_that_dont_need_to_run(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LintId> {
})
.filter_map(|lint| {
let lint_level = map.lint_level_id_at_node(tcx, LintId::of(lint), CRATE_HIR_ID);
if matches!(lint_level, (Level::Allow, ..))
|| (matches!(lint_level, (.., LintLevelSource::Default)))
if matches!(lint_level.level, Level::Allow)
|| (matches!(lint_level.src, LintLevelSource::Default))
&& lint.default_level(tcx.sess.edition()) == Level::Allow
{
Some(LintId::of(lint))
Expand Down Expand Up @@ -595,15 +595,15 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
};
for id in ids {
// ForceWarn and Forbid cannot be overridden
if let Some((Level::ForceWarn(_) | Level::Forbid, _)) =
if let Some(LevelAndSource { level: Level::ForceWarn(_) | Level::Forbid, .. }) =
self.current_specs().get(&id)
{
continue;
}

if self.check_gated_lint(id, DUMMY_SP, true) {
let src = LintLevelSource::CommandLine(lint_flag_val, orig_level);
self.insert(id, (level, src));
self.insert(id, LevelAndSource { level, src });
}
}
}
Expand All @@ -612,8 +612,9 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
/// Attempts to insert the `id` to `level_src` map entry. If unsuccessful
/// (e.g. if a forbid was already inserted on the same scope), then emits a
/// diagnostic with no change to `specs`.
fn insert_spec(&mut self, id: LintId, (level, src): LevelAndSource) {
let (old_level, old_src) = self.provider.get_lint_level(id.lint, self.sess);
fn insert_spec(&mut self, id: LintId, LevelAndSource { level, src }: LevelAndSource) {
let LevelAndSource { level: old_level, src: old_src } =
self.provider.get_lint_level(id.lint, self.sess);

// Setting to a non-forbid level is an error if the lint previously had
// a forbid level. Note that this is not necessarily true even with a
Expand Down Expand Up @@ -693,13 +694,16 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {

match (old_level, level) {
// If the new level is an expectation store it in `ForceWarn`
(Level::ForceWarn(_), Level::Expect(expectation_id)) => {
self.insert(id, (Level::ForceWarn(Some(expectation_id)), old_src))
}
(Level::ForceWarn(_), Level::Expect(expectation_id)) => self.insert(
id,
LevelAndSource { level: Level::ForceWarn(Some(expectation_id)), src: old_src },
),
// Keep `ForceWarn` level but drop the expectation
(Level::ForceWarn(_), _) => self.insert(id, (Level::ForceWarn(None), old_src)),
(Level::ForceWarn(_), _) => {
self.insert(id, LevelAndSource { level: Level::ForceWarn(None), src: old_src })
}
// Set the lint level as normal
_ => self.insert(id, (level, src)),
_ => self.insert(id, LevelAndSource { level, src }),
};
}

Expand All @@ -714,7 +718,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
if attr.has_name(sym::automatically_derived) {
self.insert(
LintId::of(SINGLE_USE_LIFETIMES),
(Level::Allow, LintLevelSource::Default),
LevelAndSource { level: Level::Allow, src: LintLevelSource::Default },
);
continue;
}
Expand All @@ -725,7 +729,10 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
.meta_item_list()
.is_some_and(|l| ast::attr::list_contains_name(&l, sym::hidden))
{
self.insert(LintId::of(MISSING_DOCS), (Level::Allow, LintLevelSource::Default));
self.insert(
LintId::of(MISSING_DOCS),
LevelAndSource { level: Level::Allow, src: LintLevelSource::Default },
);
continue;
}

Expand Down Expand Up @@ -933,7 +940,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
let src = LintLevelSource::Node { name, span: sp, reason };
for &id in ids {
if self.check_gated_lint(id, sp, false) {
self.insert_spec(id, (level, src));
self.insert_spec(id, LevelAndSource { level, src });
}
}

Expand Down Expand Up @@ -964,7 +971,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
}

if self.lint_added_lints && !is_crate_node {
for (id, &(level, ref src)) in self.current_specs().iter() {
for (id, &LevelAndSource { level, ref src }) in self.current_specs().iter() {
if !id.lint.crate_level_only {
continue;
}
Expand Down Expand Up @@ -1002,10 +1009,10 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {

if self.lint_added_lints {
let lint = builtin::UNKNOWN_LINTS;
let (level, src) = self.lint_level(builtin::UNKNOWN_LINTS);
let level = self.lint_level(builtin::UNKNOWN_LINTS);
// FIXME: make this translatable
#[allow(rustc::diagnostic_outside_of_impl)]
lint_level(self.sess, lint, level, src, Some(span.into()), |lint| {
lint_level(self.sess, lint, level, Some(span.into()), |lint| {
lint.primary_message(fluent::lint_unknown_gated_lint);
lint.arg("name", lint_id.lint.name_lower());
lint.note(fluent::lint_note);
Expand Down Expand Up @@ -1040,8 +1047,8 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
span: Option<MultiSpan>,
decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
) {
let (level, src) = self.lint_level(lint);
lint_level(self.sess, lint, level, src, span, decorate)
let level = self.lint_level(lint);
lint_level(self.sess, lint, level, span, decorate)
}

#[track_caller]
Expand All @@ -1051,16 +1058,16 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
span: MultiSpan,
decorate: impl for<'a> LintDiagnostic<'a, ()>,
) {
let (level, src) = self.lint_level(lint);
lint_level(self.sess, lint, level, src, Some(span), |lint| {
let level = self.lint_level(lint);
lint_level(self.sess, lint, level, Some(span), |lint| {
decorate.decorate_lint(lint);
});
}

#[track_caller]
pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> LintDiagnostic<'a, ()>) {
let (level, src) = self.lint_level(lint);
lint_level(self.sess, lint, level, src, None, |lint| {
let level = self.lint_level(lint);
lint_level(self.sess, lint, level, None, |lint| {
decorate.decorate_lint(lint);
});
}
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_lint/src/non_ascii_idents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ impl EarlyLintPass for NonAsciiIdents {
use rustc_span::Span;
use unicode_security::GeneralSecurityProfile;

let check_non_ascii_idents = cx.builder.lint_level(NON_ASCII_IDENTS).0 != Level::Allow;
let check_non_ascii_idents = cx.builder.lint_level(NON_ASCII_IDENTS).level != Level::Allow;
let check_uncommon_codepoints =
cx.builder.lint_level(UNCOMMON_CODEPOINTS).0 != Level::Allow;
let check_confusable_idents = cx.builder.lint_level(CONFUSABLE_IDENTS).0 != Level::Allow;
cx.builder.lint_level(UNCOMMON_CODEPOINTS).level != Level::Allow;
let check_confusable_idents =
cx.builder.lint_level(CONFUSABLE_IDENTS).level != Level::Allow;
let check_mixed_script_confusables =
cx.builder.lint_level(MIXED_SCRIPT_CONFUSABLES).0 != Level::Allow;
cx.builder.lint_level(MIXED_SCRIPT_CONFUSABLES).level != Level::Allow;

if !check_non_ascii_idents
&& !check_uncommon_codepoints
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl CStore {
}
let level = tcx
.lint_level_at_node(lint::builtin::UNUSED_CRATE_DEPENDENCIES, rustc_hir::CRATE_HIR_ID)
.0;
.level;
if level != lint::Level::Allow {
let unused_externs =
self.unused_externs.iter().map(|ident| ident.to_ident_string()).collect::<Vec<_>>();
Expand Down
28 changes: 16 additions & 12 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ impl LintLevelSource {
}
}

/// A tuple of a lint level and its source.
pub type LevelAndSource = (Level, LintLevelSource);
/// Convenience helper for moving things around together that frequently are paired
#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)]
pub struct LevelAndSource {
pub level: Level,
pub src: LintLevelSource,
}

/// Return type for the `shallow_lint_levels_on` query.
///
Expand Down Expand Up @@ -123,7 +127,7 @@ impl ShallowLintLevelMap {
start: HirId,
) -> (Option<Level>, LintLevelSource) {
if let Some(map) = self.specs.get(&start.local_id)
&& let Some(&(level, src)) = map.get(&id)
&& let Some(&LevelAndSource { level, src }) = map.get(&id)
{
return (Some(level), src);
}
Expand All @@ -137,7 +141,7 @@ impl ShallowLintLevelMap {
specs = &tcx.shallow_lint_levels_on(owner).specs;
}
if let Some(map) = specs.get(&parent.local_id)
&& let Some(&(level, src)) = map.get(&id)
&& let Some(&LevelAndSource { level, src }) = map.get(&id)
{
return (Some(level), src);
}
Expand All @@ -153,18 +157,18 @@ impl ShallowLintLevelMap {
tcx: TyCtxt<'_>,
lint: LintId,
cur: HirId,
) -> (Level, LintLevelSource) {
) -> LevelAndSource {
let (level, mut src) = self.probe_for_lint_level(tcx, lint, cur);
let level = reveal_actual_level(level, &mut src, tcx.sess, lint, |lint| {
self.probe_for_lint_level(tcx, lint, cur)
});
(level, src)
LevelAndSource { level, src }
}
}

impl TyCtxt<'_> {
/// Fetch and return the user-visible lint level for the given lint at the given HirId.
pub fn lint_level_at_node(self, lint: &'static Lint, id: HirId) -> (Level, LintLevelSource) {
pub fn lint_level_at_node(self, lint: &'static Lint, id: HirId) -> LevelAndSource {
self.shallow_lint_levels_on(id.owner).lint_level_id_at_node(self, LintId::of(lint), id)
}
}
Expand Down Expand Up @@ -267,8 +271,7 @@ fn explain_lint_level_source(
pub fn lint_level(
sess: &Session,
lint: &'static Lint,
level: Level,
src: LintLevelSource,
level: LevelAndSource,
span: Option<MultiSpan>,
decorate: impl for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>),
) {
Expand All @@ -278,11 +281,12 @@ pub fn lint_level(
fn lint_level_impl(
sess: &Session,
lint: &'static Lint,
level: Level,
src: LintLevelSource,
level: LevelAndSource,
span: Option<MultiSpan>,
decorate: Box<dyn '_ + for<'a, 'b> FnOnce(&'b mut Diag<'a, ()>)>,
) {
let LevelAndSource { level, src } = level;

// Check for future incompatibility lints and issue a stronger warning.
let future_incompatible = lint.future_incompatible;

Expand Down Expand Up @@ -421,5 +425,5 @@ pub fn lint_level(
explain_lint_level_source(lint, level, src, &mut err);
err.emit()
}
lint_level_impl(sess, lint, level, src, span, Box::new(decorate))
lint_level_impl(sess, lint, level, span, Box::new(decorate))
}
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ fn late_report_deprecation(
// Calculating message for lint involves calling `self.def_path_str`,
// which will by default invoke the expensive `visible_parent_map` query.
// Skip all that work if the lint is allowed anyway.
if tcx.lint_level_at_node(lint, hir_id).0 == Level::Allow {
if tcx.lint_level_at_node(lint, hir_id).level == Level::Allow {
return;
}

Expand Down
Loading