Skip to content

Rollup of 7 pull requests #139268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0a05677
`lower_pat_expr`: use the pattern's type instead of the literal's
dianne Mar 26, 2025
3779c6b
add a temporary workaround for `string_deref_patterns`
dianne Mar 26, 2025
e638ba6
interpret: add a version of run_for_validation for &self
RalfJung Apr 1, 2025
9bdac17
Simplify control flow in `AstValidator::visit_item`.
nnethercote Mar 31, 2025
ccb2194
Factor some code out of `AstValidator::visit_items`.
nnethercote Apr 1, 2025
fb01485
Rename span-related names in `AstValidator`.
nnethercote Apr 2, 2025
7a4d4de
add tests for array/slice const patterns
dianne Apr 2, 2025
2e7de1a
Reduce scope of `AstValidator::with_*` calls.
nnethercote Apr 2, 2025
927ad16
Add a dep kind for use of the anon node with zero dependencies
Zoxc Apr 2, 2025
4be5f7e
Split ExpectationLintId off Level
oli-obk Mar 18, 2025
144e27d
Make LevelAndSource a struct
oli-obk Mar 19, 2025
ad88a46
Remove `LintExpectationId` from `Level` variants
oli-obk Mar 19, 2025
6b38555
Upvars HirIds always have the same owner, thus just use an ItemLocalId
oli-obk Mar 17, 2025
76b30b0
impl !PartialOrd for UpvarMigrationInfo
oli-obk Mar 17, 2025
7103ce7
impl !PartialOrd for HirId
oli-obk Mar 17, 2025
d5f7e9c
Add dianqk to codegen reviewers
dianqk Apr 2, 2025
d8d27ca
Fix two incorrect turbofish suggestions
freyacodes Apr 2, 2025
e1333a3
Rollup merge of #138610 - oli-obk:no-sort-hir-ids, r=compiler-errors
matthiaskrgr Apr 2, 2025
0b72def
Rollup merge of #138992 - dianne:simplify-byte-string-to-pat, r=oli-obk
matthiaskrgr Apr 2, 2025
8d1b9b7
Rollup merge of #139211 - RalfJung:interpret-run-for-validation, r=ol…
matthiaskrgr Apr 2, 2025
73afaba
Rollup merge of #139235 - nnethercote:AstValidator-tweaks, r=compiler…
matthiaskrgr Apr 2, 2025
9714282
Rollup merge of #139237 - Zoxc:anon-0-deps-kind, r=compiler-errors
matthiaskrgr Apr 2, 2025
8d854ee
Rollup merge of #139260 - dianqk:dianqk-codegen-reviewers, r=Urgau
matthiaskrgr Apr 2, 2025
8277081
Rollup merge of #139264 - freyacodes:fix/bad-turbofish-hints, r=petro…
matthiaskrgr Apr 2, 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
313 changes: 157 additions & 156 deletions compiler/rustc_ast_passes/src/ast_validation.rs

Large diffs are not rendered by default.

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
43 changes: 32 additions & 11 deletions compiler/rustc_const_eval/src/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

use std::assert_matches::assert_matches;
use std::borrow::{Borrow, Cow};
use std::cell::Cell;
use std::collections::VecDeque;
use std::{fmt, mem, ptr};
use std::{fmt, ptr};

use rustc_abi::{Align, HasDataLayout, Size};
use rustc_ast::Mutability;
Expand Down Expand Up @@ -131,7 +132,7 @@ pub struct Memory<'tcx, M: Machine<'tcx>> {
/// This stores whether we are currently doing reads purely for the purpose of validation.
/// Those reads do not trigger the machine's hooks for memory reads.
/// Needless to say, this must only be set with great care!
validation_in_progress: bool,
validation_in_progress: Cell<bool>,
}

/// A reference to some allocation that was already bounds-checked for the given region
Expand All @@ -158,7 +159,7 @@ impl<'tcx, M: Machine<'tcx>> Memory<'tcx, M> {
alloc_map: M::MemoryMap::default(),
extra_fn_ptr_map: FxIndexMap::default(),
dead_alloc_map: FxIndexMap::default(),
validation_in_progress: false,
validation_in_progress: Cell::new(false),
}
}

Expand Down Expand Up @@ -715,15 +716,15 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
// We want to call the hook on *all* accesses that involve an AllocId, including zero-sized
// accesses. That means we cannot rely on the closure above or the `Some` branch below. We
// do this after `check_and_deref_ptr` to ensure some basic sanity has already been checked.
if !self.memory.validation_in_progress {
if !self.memory.validation_in_progress.get() {
if let Ok((alloc_id, ..)) = self.ptr_try_get_alloc_id(ptr, size_i64) {
M::before_alloc_read(self, alloc_id)?;
}
}

if let Some((alloc_id, offset, prov, alloc)) = ptr_and_alloc {
let range = alloc_range(offset, size);
if !self.memory.validation_in_progress {
if !self.memory.validation_in_progress.get() {
M::before_memory_read(
self.tcx,
&self.machine,
Expand Down Expand Up @@ -801,7 +802,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
) -> InterpResult<'tcx, Option<AllocRefMut<'a, 'tcx, M::Provenance, M::AllocExtra, M::Bytes>>>
{
let tcx = self.tcx;
let validation_in_progress = self.memory.validation_in_progress;
let validation_in_progress = self.memory.validation_in_progress.get();

let size_i64 = i64::try_from(size.bytes()).unwrap(); // it would be an error to even ask for more than isize::MAX bytes
let ptr_and_alloc = Self::check_and_deref_ptr(
Expand Down Expand Up @@ -1087,23 +1088,43 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
///
/// We do this so Miri's allocation access tracking does not show the validation
/// reads as spurious accesses.
pub fn run_for_validation<R>(&mut self, f: impl FnOnce(&mut Self) -> R) -> R {
pub fn run_for_validation_mut<R>(&mut self, f: impl FnOnce(&mut Self) -> R) -> R {
// This deliberately uses `==` on `bool` to follow the pattern
// `assert!(val.replace(new) == old)`.
assert!(
mem::replace(&mut self.memory.validation_in_progress, true) == false,
self.memory.validation_in_progress.replace(true) == false,
"`validation_in_progress` was already set"
);
let res = f(self);
assert!(
mem::replace(&mut self.memory.validation_in_progress, false) == true,
self.memory.validation_in_progress.replace(false) == true,
"`validation_in_progress` was unset by someone else"
);
res
}

/// Runs the closure in "validation" mode, which means the machine's memory read hooks will be
/// suppressed. Needless to say, this must only be set with great care! Cannot be nested.
///
/// We do this so Miri's allocation access tracking does not show the validation
/// reads as spurious accesses.
pub fn run_for_validation_ref<R>(&self, f: impl FnOnce(&Self) -> R) -> R {
// This deliberately uses `==` on `bool` to follow the pattern
// `assert!(val.replace(new) == old)`.
assert!(
self.memory.validation_in_progress.replace(true) == false,
"`validation_in_progress` was already set"
);
let res = f(self);
assert!(
self.memory.validation_in_progress.replace(false) == true,
"`validation_in_progress` was unset by someone else"
);
res
}

pub(super) fn validation_in_progress(&self) -> bool {
self.memory.validation_in_progress
self.memory.validation_in_progress.get()
}
}

Expand Down Expand Up @@ -1375,7 +1396,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
};
let src_alloc = self.get_alloc_raw(src_alloc_id)?;
let src_range = alloc_range(src_offset, size);
assert!(!self.memory.validation_in_progress, "we can't be copying during validation");
assert!(!self.memory.validation_in_progress.get(), "we can't be copying during validation");
// For the overlapping case, it is crucial that we trigger the read hook
// before the write hook -- the aliasing model cares about the order.
M::before_memory_read(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
trace!("validate_operand_internal: {:?}, {:?}", *val, val.layout.ty);

// Run the visitor.
self.run_for_validation(|ecx| {
self.run_for_validation_mut(|ecx| {
let reset_padding = reset_provenance_and_padding && {
// Check if `val` is actually stored in memory. If not, padding is not even
// represented and we need not reset it.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_errors/src/annotate_snippet_emitter_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ fn annotation_level_for_level(level: Level) -> annotate_snippets::Level {
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => {
annotate_snippets::Level::Error
}
Level::ForceWarning(_) | Level::Warning => annotate_snippets::Level::Warning,
Level::ForceWarning | Level::Warning => annotate_snippets::Level::Warning,
Level::Note | Level::OnceNote => annotate_snippets::Level::Note,
Level::Help | Level::OnceHelp => annotate_snippets::Level::Help,
// FIXME(#59346): Not sure how to map this level
Level::FailureNote => annotate_snippets::Level::Error,
Level::Allow => panic!("Should not call with Allow"),
Level::Expect(_) => panic!("Should not call with Expect"),
Level::Expect => panic!("Should not call with Expect"),
}
}

Expand Down
21 changes: 17 additions & 4 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::thread::panicking;

use rustc_data_structures::fx::FxIndexMap;
use rustc_error_messages::{FluentValue, fluent_value_from_str_list_sep_by_and};
use rustc_lint_defs::Applicability;
use rustc_lint_defs::{Applicability, LintExpectationId};
use rustc_macros::{Decodable, Encodable};
use rustc_span::source_map::Spanned;
use rustc_span::{DUMMY_SP, Span, Symbol};
Expand Down Expand Up @@ -296,6 +296,7 @@ pub struct DiagInner {

pub messages: Vec<(DiagMessage, Style)>,
pub code: Option<ErrCode>,
pub lint_id: Option<LintExpectationId>,
pub span: MultiSpan,
pub children: Vec<Subdiag>,
pub suggestions: Suggestions,
Expand Down Expand Up @@ -324,6 +325,7 @@ impl DiagInner {
pub fn new_with_messages(level: Level, messages: Vec<(DiagMessage, Style)>) -> Self {
DiagInner {
level,
lint_id: None,
messages,
code: None,
span: MultiSpan::new(),
Expand All @@ -346,15 +348,15 @@ impl DiagInner {
match self.level {
Level::Bug | Level::Fatal | Level::Error | Level::DelayedBug => true,

Level::ForceWarning(_)
Level::ForceWarning
| Level::Warning
| Level::Note
| Level::OnceNote
| Level::Help
| Level::OnceHelp
| Level::FailureNote
| Level::Allow
| Level::Expect(_) => false,
| Level::Expect => false,
}
}

Expand All @@ -365,7 +367,7 @@ impl DiagInner {

pub(crate) fn is_force_warn(&self) -> bool {
match self.level {
Level::ForceWarning(_) => {
Level::ForceWarning => {
assert!(self.is_lint.is_some());
true
}
Expand Down Expand Up @@ -1259,6 +1261,17 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
self
} }

with_fn! { with_lint_id,
/// Add an argument.
#[rustc_lint_diagnostics]
pub fn lint_id(
&mut self,
id: LintExpectationId,
) -> &mut Self {
self.lint_id = Some(id);
self
} }

with_fn! { with_primary_message,
/// Add a primary message.
#[rustc_lint_diagnostics]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_errors/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl Emitter for JsonEmitter {
//
// So to avoid ICEs and confused users we "upgrade" the lint level for
// those `FutureBreakageItem` to warn.
if matches!(diag.level, crate::Level::Allow | crate::Level::Expect(..)) {
if matches!(diag.level, crate::Level::Allow | crate::Level::Expect) {
diag.level = crate::Level::Warning;
}
FutureBreakageItem {
Expand Down
39 changes: 19 additions & 20 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -905,8 +905,8 @@ impl<'a> DiagCtxtHandle<'a> {
DelayedBug => {
return self.inner.borrow_mut().emit_diagnostic(diag, self.tainted_with_errors);
}
ForceWarning(_) | Warning | Note | OnceNote | Help | OnceHelp | FailureNote | Allow
| Expect(_) => None,
ForceWarning | Warning | Note | OnceNote | Help | OnceHelp | FailureNote | Allow
| Expect => None,
};

// FIXME(Centril, #69537): Consider reintroducing panic on overwriting a stashed diagnostic
Expand Down Expand Up @@ -1045,7 +1045,7 @@ impl<'a> DiagCtxtHandle<'a> {
// Use `ForceWarning` rather than `Warning` to guarantee emission, e.g. with a
// configuration like `--cap-lints allow --force-warn bare_trait_objects`.
inner.emit_diagnostic(
DiagInner::new(ForceWarning(None), DiagMessage::Str(warnings)),
DiagInner::new(ForceWarning, DiagMessage::Str(warnings)),
None,
);
}
Expand Down Expand Up @@ -1450,7 +1450,7 @@ impl<'a> DiagCtxtHandle<'a> {
#[rustc_lint_diagnostics]
#[track_caller]
pub fn struct_expect(self, msg: impl Into<DiagMessage>, id: LintExpectationId) -> Diag<'a, ()> {
Diag::new(self, Expect(id), msg)
Diag::new(self, Expect, msg).with_lint_id(id)
}
}

Expand Down Expand Up @@ -1510,7 +1510,7 @@ impl DiagCtxtInner {
// Future breakages aren't emitted if they're `Level::Allow` or
// `Level::Expect`, but they still need to be constructed and
// stashed below, so they'll trigger the must_produce_diag check.
assert_matches!(diagnostic.level, Error | Warning | Allow | Expect(_));
assert_matches!(diagnostic.level, Error | Warning | Allow | Expect);
self.future_breakage_diagnostics.push(diagnostic.clone());
}

Expand Down Expand Up @@ -1558,7 +1558,7 @@ impl DiagCtxtInner {
};
}
}
ForceWarning(None) => {} // `ForceWarning(Some(...))` is below, with `Expect`
ForceWarning if diagnostic.lint_id.is_none() => {} // `ForceWarning(Some(...))` is below, with `Expect`
Warning => {
if !self.flags.can_emit_warnings {
// We are not emitting warnings.
Expand All @@ -1580,9 +1580,9 @@ impl DiagCtxtInner {
}
return None;
}
Expect(expect_id) | ForceWarning(Some(expect_id)) => {
self.fulfilled_expectations.insert(expect_id);
if let Expect(_) = diagnostic.level {
Expect | ForceWarning => {
self.fulfilled_expectations.insert(diagnostic.lint_id.unwrap());
if let Expect = diagnostic.level {
// Nothing emitted here for expected lints.
TRACK_DIAGNOSTIC(diagnostic, &mut |_| None);
self.suppressed_expected_diag = true;
Expand Down Expand Up @@ -1631,7 +1631,7 @@ impl DiagCtxtInner {

if is_error {
self.deduplicated_err_count += 1;
} else if matches!(diagnostic.level, ForceWarning(_) | Warning) {
} else if matches!(diagnostic.level, ForceWarning | Warning) {
self.deduplicated_warn_count += 1;
}
self.has_printed = true;
Expand Down Expand Up @@ -1899,9 +1899,9 @@ pub enum Level {
/// A `force-warn` lint warning about the code being compiled. Does not prevent compilation
/// from finishing.
///
/// The [`LintExpectationId`] is used for expected lint diagnostics. In all other cases this
/// Requires a [`LintExpectationId`] for expected lint diagnostics. In all other cases this
/// should be `None`.
ForceWarning(Option<LintExpectationId>),
ForceWarning,

/// A warning about the code being compiled. Does not prevent compilation from finishing.
/// Will be skipped if `can_emit_warnings` is false.
Expand All @@ -1926,8 +1926,8 @@ pub enum Level {
/// Only used for lints.
Allow,

/// Only used for lints.
Expect(LintExpectationId),
/// Only used for lints. Requires a [`LintExpectationId`] for silencing the lints.
Expect,
}

impl fmt::Display for Level {
Expand All @@ -1943,7 +1943,7 @@ impl Level {
Bug | Fatal | Error | DelayedBug => {
spec.set_fg(Some(Color::Red)).set_intense(true);
}
ForceWarning(_) | Warning => {
ForceWarning | Warning => {
spec.set_fg(Some(Color::Yellow)).set_intense(cfg!(windows));
}
Note | OnceNote => {
Expand All @@ -1953,7 +1953,7 @@ impl Level {
spec.set_fg(Some(Color::Cyan)).set_intense(true);
}
FailureNote => {}
Allow | Expect(_) => unreachable!(),
Allow | Expect => unreachable!(),
}
spec
}
Expand All @@ -1962,11 +1962,11 @@ impl Level {
match self {
Bug | DelayedBug => "error: internal compiler error",
Fatal | Error => "error",
ForceWarning(_) | Warning => "warning",
ForceWarning | Warning => "warning",
Note | OnceNote => "note",
Help | OnceHelp => "help",
FailureNote => "failure-note",
Allow | Expect(_) => unreachable!(),
Allow | Expect => unreachable!(),
}
}

Expand All @@ -1977,8 +1977,7 @@ impl Level {
// Can this level be used in a subdiagnostic message?
fn can_be_subdiag(&self) -> bool {
match self {
Bug | DelayedBug | Fatal | Error | ForceWarning(_) | FailureNote | Allow
| Expect(_) => false,
Bug | DelayedBug | Fatal | Error | ForceWarning | FailureNote | Allow | Expect => false,

Warning | Note | Help | OnceNote | OnceHelp => true,
}
Expand Down
Loading
Loading