Skip to content

Commit 1becb2a

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 5130d31 commit 1becb2a

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
@@ -29,6 +29,10 @@ interface_ignoring_out_dir = ignoring --out-dir flag due to -o flag
2929
interface_input_file_would_be_overwritten =
3030
the input file "{$path}" would be overwritten by the generated executable
3131
32+
interface_limit_invalid =
33+
`limit` must be a non-negative integer
34+
.label = {$error_str}
35+
3236
interface_mixed_bin_crate =
3337
cannot mix `bin` crate type with others
3438

compiler/rustc_interface/src/errors.rs

+10
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,13 @@ pub(crate) struct AbiRequiredTargetFeature<'a> {
112112
pub feature: &'a str,
113113
pub enabled: &'a str,
114114
}
115+
116+
#[derive(Diagnostic)]
117+
#[diag(interface_limit_invalid)]
118+
pub struct LimitInvalid<'a> {
119+
#[primary_span]
120+
pub span: Span,
121+
#[label]
122+
pub value_span: Span,
123+
pub error_str: &'a str,
124+
}

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
@@ -10,13 +10,14 @@
1010
use std::num::IntErrorKind;
1111

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

16-
use crate::error::LimitInvalid;
17-
use crate::query::Providers;
18+
use crate::errors::LimitInvalid;
1819

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

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

compiler/rustc_interface/src/passes.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use rustc_trait_selection::traits;
3737
use tracing::{info, instrument};
3838

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

4242
pub fn parse<'a>(sess: &'a Session) -> ast::Crate {
4343
let krate = sess
@@ -685,6 +685,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| {
685685
|tcx, _| tcx.arena.alloc_from_iter(tcx.resolutions(()).stripped_cfg_items.steal());
686686
providers.resolutions = |tcx, ()| tcx.resolver_for_lowering_raw(()).1;
687687
providers.early_lint_checks = early_lint_checks;
688+
limits::provide(providers);
688689
proc_macro_decls::provide(providers);
689690
rustc_const_eval::provide(providers);
690691
rustc_middle::hir::provide(providers);
@@ -1091,5 +1092,5 @@ fn get_recursion_limit(krate_attrs: &[ast::Attribute], sess: &Session) -> Limit
10911092
sym::recursion_limit,
10921093
);
10931094
}
1094-
rustc_middle::middle::limits::get_recursion_limit(krate_attrs, sess)
1095+
crate::limits::get_recursion_limit(krate_attrs, sess)
10951096
}

compiler/rustc_middle/messages.ftl

-4
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ middle_failed_writing_file =
8484
middle_layout_references_error =
8585
the type has an unknown layout
8686
87-
middle_limit_invalid =
88-
`limit` must be a non-negative integer
89-
.label = {$error_str}
90-
9187
middle_opaque_hidden_type_mismatch =
9288
concrete type differs from previous defining opaque type use
9389
.label = expected `{$self_ty}`, got `{$other_ty}`

compiler/rustc_middle/src/error.rs

-10
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,6 @@ pub enum TypeMismatchReason {
6565
},
6666
}
6767

68-
#[derive(Diagnostic)]
69-
#[diag(middle_limit_invalid)]
70-
pub struct LimitInvalid<'a> {
71-
#[primary_span]
72-
pub span: Span,
73-
#[label]
74-
pub value_span: Span,
75-
pub error_str: &'a str,
76-
}
77-
7868
#[derive(Diagnostic)]
7969
#[diag(middle_recursion_limit_reached)]
8070
#[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
@@ -2167,7 +2167,6 @@ pub fn provide(providers: &mut Providers) {
21672167
util::provide(providers);
21682168
print::provide(providers);
21692169
super::util::bug::provide(providers);
2170-
super::middle::provide(providers);
21712170
*providers = Providers {
21722171
trait_impls_of: trait_def::trait_impls_of_provider,
21732172
incoherent_impls: trait_def::incoherent_impls_provider,

0 commit comments

Comments
 (0)