Skip to content
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

Get rid of HIR const checker #133321

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const_eval_extern_type_field = `extern type` field does not have a known offset
const_eval_fn_ptr_call =
function pointers need an RFC before allowed to be called in {const_eval_const_context}s
const_eval_for_loop_into_iter_non_const =
cannot convert `{$ty}` into an iterator in {const_eval_const_context}s
cannot use `for` loop on `{$ty}` in {const_eval_const_context}s

const_eval_frame_note = {$times ->
[0] {const_eval_frame_note_inner}
Expand Down Expand Up @@ -324,11 +324,11 @@ const_eval_ptr_as_bytes_1 =
this code performed an operation that depends on the underlying bytes representing a pointer
const_eval_ptr_as_bytes_2 =
the absolute address of a pointer is not known at compile-time, so such operations are not supported
const_eval_question_branch_non_const =
`?` cannot determine the branch of `{$ty}` in {const_eval_const_context}s

const_eval_question_branch_non_const =
`?` is not allowed on `{$ty}` in {const_eval_const_context}s
const_eval_question_from_residual_non_const =
`?` cannot convert from residual of `{$ty}` in {const_eval_const_context}s
`?` is not allowed on `{$ty}` in {const_eval_const_context}s

const_eval_range = in the range {$lo}..={$hi}
const_eval_range_lower = greater or equal to {$lo}
Expand Down
11 changes: 5 additions & 6 deletions compiler/rustc_const_eval/src/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,10 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
};
}

let mut err = match kind {
CallDesugaringKind::ForLoopIntoIter => {
// Don't point at the trait if this is a desugaring...
// FIXME(const_trait_impl): we could perhaps do this for `Iterator`.
match kind {
CallDesugaringKind::ForLoopIntoIter | CallDesugaringKind::ForLoopNext => {
error!(NonConstForLoopIntoIter)
}
CallDesugaringKind::QuestionBranch => {
Expand All @@ -196,10 +198,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
CallDesugaringKind::Await => {
error!(NonConstAwait)
}
};

diag_trait(&mut err, self_ty, kind.trait_def_id(tcx));
err
}
}
CallKind::FnCall { fn_trait_id, self_ty } => {
let note = match self_ty.kind() {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,6 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
tcx.ensure().check_mod_attrs(module);
tcx.ensure().check_mod_naked_functions(module);
tcx.ensure().check_mod_unstable_api_usage(module);
tcx.ensure().check_mod_const_bodies(module);
});
},
{
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -958,11 +958,6 @@ rustc_queries! {
desc { |tcx| "checking for unstable API usage in {}", describe_as_module(key, tcx) }
}

/// Checks the const bodies in the module for illegal operations (e.g. `if` or `loop`).
query check_mod_const_bodies(key: LocalModDefId) {
desc { |tcx| "checking consts in {}", describe_as_module(key, tcx) }
}

/// Checks the loops in the module.
query check_mod_loops(key: LocalModDefId) {
desc { |tcx| "checking loops in {}", describe_as_module(key, tcx) }
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/util/call_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use crate::ty::{AssocItemContainer, GenericArgsRef, Instance, Ty, TyCtxt, Typing
pub enum CallDesugaringKind {
/// for _ in x {} calls x.into_iter()
ForLoopIntoIter,
/// for _ in x {} calls iter.next()
ForLoopNext,
/// x? calls x.branch()
QuestionBranch,
/// x? calls type_of(x)::from_residual()
Expand All @@ -28,6 +30,7 @@ impl CallDesugaringKind {
pub fn trait_def_id(self, tcx: TyCtxt<'_>) -> DefId {
match self {
Self::ForLoopIntoIter => tcx.get_diagnostic_item(sym::IntoIterator).unwrap(),
Self::ForLoopNext => tcx.require_lang_item(LangItem::Iterator, None),
Self::QuestionBranch | Self::TryBlockFromOutput => {
tcx.require_lang_item(LangItem::Try, None)
}
Expand Down Expand Up @@ -121,6 +124,10 @@ pub fn call_kind<'tcx>(
&& fn_call_span.desugaring_kind() == Some(DesugaringKind::ForLoop)
{
Some((CallDesugaringKind::ForLoopIntoIter, method_args.type_at(0)))
} else if tcx.is_lang_item(method_did, LangItem::IteratorNext)
&& fn_call_span.desugaring_kind() == Some(DesugaringKind::ForLoop)
{
Some((CallDesugaringKind::ForLoopNext, method_args.type_at(0)))
} else if fn_call_span.desugaring_kind() == Some(DesugaringKind::QuestionMark) {
if tcx.is_lang_item(method_did, LangItem::TryTraitBranch) {
Some((CallDesugaringKind::QuestionBranch, method_args.type_at(0)))
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,6 @@ passes_should_be_applied_to_trait =
attribute should be applied to a trait
.label = not a trait

passes_skipping_const_checks = skipping const checks

passes_stability_promotable =
attribute cannot be applied to an expression

Expand Down
236 changes: 0 additions & 236 deletions compiler/rustc_passes/src/check_const.rs

This file was deleted.

7 changes: 0 additions & 7 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1670,13 +1670,6 @@ pub(crate) struct ProcMacroBadSig {
pub kind: ProcMacroKind,
}

#[derive(Diagnostic)]
#[diag(passes_skipping_const_checks)]
pub(crate) struct SkippingConstChecks {
#[primary_span]
pub span: Span,
}

#[derive(LintDiagnostic)]
#[diag(passes_unreachable_due_to_uninhabited)]
pub(crate) struct UnreachableDueToUninhabited<'desc, 'tcx> {
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_passes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use rustc_middle::query::Providers;

pub mod abi_test;
mod check_attr;
mod check_const;
pub mod dead;
mod debugger_visualizer;
mod diagnostic_items;
Expand All @@ -43,7 +42,6 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

pub fn provide(providers: &mut Providers) {
check_attr::provide(providers);
check_const::provide(providers);
dead::provide(providers);
debugger_visualizer::provide(providers);
diagnostic_items::provide(providers);
Expand Down
Loading
Loading