Skip to content

Commit 223c95f

Browse files
committed
Move rustc_middle::limits to rustc_interface.
It's always good to make `rustc_middle` smaller. `rustc_interface` is the best destination, because it's the only crate that calls `get_recursive_limit`.
1 parent 13280ee commit 223c95f

File tree

9 files changed

+23
-26
lines changed

9 files changed

+23
-26
lines changed

compiler/rustc_interface/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ interface_ignoring_out_dir = ignoring --out-dir flag due to -o flag
3333
interface_input_file_would_be_overwritten =
3434
the input file "{$path}" would be overwritten by the generated executable
3535
36+
interface_limit_invalid =
37+
`limit` must be a non-negative integer
38+
.label = {$error_str}
39+
3640
interface_mixed_bin_crate =
3741
cannot mix `bin` crate type with others
3842

compiler/rustc_interface/src/errors.rs

+10
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,13 @@ pub(crate) struct AbiRequiredTargetFeature<'a> {
127127
pub feature: &'a str,
128128
pub enabled: &'a str,
129129
}
130+
131+
#[derive(Diagnostic)]
132+
#[diag(interface_limit_invalid)]
133+
pub(crate) struct LimitInvalid<'a> {
134+
#[primary_span]
135+
pub span: Span,
136+
#[label]
137+
pub value_span: Span,
138+
pub error_str: &'a str,
139+
}

compiler/rustc_interface/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
mod callbacks;
1111
pub mod errors;
1212
pub mod interface;
13+
mod limits;
1314
pub mod passes;
1415
mod proc_macro_decls;
1516
mod queries;

compiler/rustc_middle/src/middle/limits.rs renamed to compiler/rustc_interface/src/limits.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
use std::num::IntErrorKind;
1212

1313
use rustc_ast::attr::AttributeExt;
14+
use rustc_middle::bug;
15+
use rustc_middle::query::Providers;
1416
use rustc_session::{Limit, Limits, Session};
1517
use rustc_span::{Symbol, sym};
1618

17-
use crate::error::LimitInvalid;
18-
use crate::query::Providers;
19+
use crate::errors::LimitInvalid;
1920

20-
pub fn provide(providers: &mut Providers) {
21+
pub(crate) fn provide(providers: &mut Providers) {
2122
providers.limits = |tcx, ()| Limits {
2223
recursion_limit: get_recursion_limit(tcx.hir().krate_attrs(), tcx.sess),
2324
move_size_limit: get_limit(
@@ -42,7 +43,7 @@ pub fn provide(providers: &mut Providers) {
4243
}
4344

4445
// This one is separate because it must be read prior to macro expansion.
45-
pub fn get_recursion_limit(krate_attrs: &[impl AttributeExt], sess: &Session) -> Limit {
46+
pub(crate) fn get_recursion_limit(krate_attrs: &[impl AttributeExt], sess: &Session) -> Limit {
4647
get_limit(krate_attrs, sess, sym::recursion_limit, Limit::new(128))
4748
}
4849

compiler/rustc_interface/src/passes.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use rustc_trait_selection::traits;
3939
use tracing::{info, instrument};
4040

4141
use crate::interface::Compiler;
42-
use crate::{errors, proc_macro_decls, util};
42+
use crate::{errors, limits, proc_macro_decls, util};
4343

4444
pub fn parse<'a>(sess: &'a Session) -> ast::Crate {
4545
let krate = sess
@@ -687,6 +687,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
687687
|tcx, _| tcx.arena.alloc_from_iter(tcx.resolutions(()).stripped_cfg_items.steal());
688688
providers.resolutions = |tcx, ()| tcx.resolver_for_lowering_raw(()).1;
689689
providers.early_lint_checks = early_lint_checks;
690+
limits::provide(providers);
690691
proc_macro_decls::provide(providers);
691692
rustc_const_eval::provide(providers);
692693
rustc_middle::hir::provide(providers);
@@ -1134,7 +1135,7 @@ fn get_recursion_limit(krate_attrs: &[ast::Attribute], sess: &Session) -> Limit
11341135
// because that would require expanding this while in the middle of expansion, which needs to
11351136
// know the limit before expanding.
11361137
let _ = validate_and_find_value_str_builtin_attr(sym::recursion_limit, sess, krate_attrs);
1137-
rustc_middle::middle::limits::get_recursion_limit(krate_attrs, sess)
1138+
crate::limits::get_recursion_limit(krate_attrs, sess)
11381139
}
11391140

11401141
/// Validate *all* occurrences of the given "[value-str]" built-in attribute and return the first find.

compiler/rustc_middle/messages.ftl

-4
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ middle_failed_writing_file =
8181
middle_layout_references_error =
8282
the type has an unknown layout
8383
84-
middle_limit_invalid =
85-
`limit` must be a non-negative integer
86-
.label = {$error_str}
87-
8884
middle_opaque_hidden_type_mismatch =
8985
concrete type differs from previous defining opaque type use
9086
.label = expected `{$self_ty}`, got `{$other_ty}`

compiler/rustc_middle/src/error.rs

-10
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,6 @@ pub enum TypeMismatchReason {
6767
},
6868
}
6969

70-
#[derive(Diagnostic)]
71-
#[diag(middle_limit_invalid)]
72-
pub(crate) struct LimitInvalid<'a> {
73-
#[primary_span]
74-
pub span: Span,
75-
#[label]
76-
pub value_span: Span,
77-
pub error_str: &'a str,
78-
}
79-
8070
#[derive(Diagnostic)]
8171
#[diag(middle_recursion_limit_reached)]
8272
#[help]

compiler/rustc_middle/src/middle/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ pub mod lib_features {
3030
}
3131
}
3232
}
33-
pub mod limits;
3433
pub mod privacy;
3534
pub mod region;
3635
pub mod resolve_bound_vars;
3736
pub mod stability;
38-
39-
pub fn provide(providers: &mut crate::query::Providers) {
40-
limits::provide(providers);
41-
}

compiler/rustc_middle/src/ty/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2168,7 +2168,6 @@ pub fn provide(providers: &mut Providers) {
21682168
util::provide(providers);
21692169
print::provide(providers);
21702170
super::util::bug::provide(providers);
2171-
super::middle::provide(providers);
21722171
*providers = Providers {
21732172
trait_impls_of: trait_def::trait_impls_of_provider,
21742173
incoherent_impls: trait_def::incoherent_impls_provider,

0 commit comments

Comments
 (0)