diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-02-07 16:19:05 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-02-17 09:30:39 +1100 |
| commit | 223c95fd59f361ff482bf26434900fc8f72fbe04 (patch) | |
| tree | 854df1d9cea4773e4741de1897b0c2dc5d5d9a6f | |
| parent | 13280eed6a04b94efa3702733d733f5496f60d27 (diff) | |
| download | rust-223c95fd59f361ff482bf26434900fc8f72fbe04.tar.gz rust-223c95fd59f361ff482bf26434900fc8f72fbe04.zip | |
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`.
| -rw-r--r-- | compiler/rustc_interface/messages.ftl | 4 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/errors.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/lib.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/limits.rs (renamed from compiler/rustc_middle/src/middle/limits.rs) | 9 | ||||
| -rw-r--r-- | compiler/rustc_interface/src/passes.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_middle/messages.ftl | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/error.rs | 10 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/middle/mod.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/mod.rs | 1 |
9 files changed, 23 insertions, 26 deletions
diff --git a/compiler/rustc_interface/messages.ftl b/compiler/rustc_interface/messages.ftl index 43c69c8e571..adc7ed54e14 100644 --- a/compiler/rustc_interface/messages.ftl +++ b/compiler/rustc_interface/messages.ftl @@ -33,6 +33,10 @@ interface_ignoring_out_dir = ignoring --out-dir flag due to -o flag interface_input_file_would_be_overwritten = the input file "{$path}" would be overwritten by the generated executable +interface_limit_invalid = + `limit` must be a non-negative integer + .label = {$error_str} + interface_mixed_bin_crate = cannot mix `bin` crate type with others diff --git a/compiler/rustc_interface/src/errors.rs b/compiler/rustc_interface/src/errors.rs index c3b858d4f2e..ca4e556dcdb 100644 --- a/compiler/rustc_interface/src/errors.rs +++ b/compiler/rustc_interface/src/errors.rs @@ -127,3 +127,13 @@ pub(crate) struct AbiRequiredTargetFeature<'a> { pub feature: &'a str, pub enabled: &'a str, } + +#[derive(Diagnostic)] +#[diag(interface_limit_invalid)] +pub(crate) struct LimitInvalid<'a> { + #[primary_span] + pub span: Span, + #[label] + pub value_span: Span, + pub error_str: &'a str, +} diff --git a/compiler/rustc_interface/src/lib.rs b/compiler/rustc_interface/src/lib.rs index a2a29612e48..54cd341698f 100644 --- a/compiler/rustc_interface/src/lib.rs +++ b/compiler/rustc_interface/src/lib.rs @@ -10,6 +10,7 @@ mod callbacks; pub mod errors; pub mod interface; +mod limits; pub mod passes; mod proc_macro_decls; mod queries; diff --git a/compiler/rustc_middle/src/middle/limits.rs b/compiler/rustc_interface/src/limits.rs index bc5d629c9ab..08d155a2c23 100644 --- a/compiler/rustc_middle/src/middle/limits.rs +++ b/compiler/rustc_interface/src/limits.rs @@ -11,13 +11,14 @@ use std::num::IntErrorKind; use rustc_ast::attr::AttributeExt; +use rustc_middle::bug; +use rustc_middle::query::Providers; use rustc_session::{Limit, Limits, Session}; use rustc_span::{Symbol, sym}; -use crate::error::LimitInvalid; -use crate::query::Providers; +use crate::errors::LimitInvalid; -pub fn provide(providers: &mut Providers) { +pub(crate) fn provide(providers: &mut Providers) { providers.limits = |tcx, ()| Limits { recursion_limit: get_recursion_limit(tcx.hir().krate_attrs(), tcx.sess), move_size_limit: get_limit( @@ -42,7 +43,7 @@ pub fn provide(providers: &mut Providers) { } // This one is separate because it must be read prior to macro expansion. -pub fn get_recursion_limit(krate_attrs: &[impl AttributeExt], sess: &Session) -> Limit { +pub(crate) fn get_recursion_limit(krate_attrs: &[impl AttributeExt], sess: &Session) -> Limit { get_limit(krate_attrs, sess, sym::recursion_limit, Limit::new(128)) } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index fcebca3ecc9..d7d183e17ed 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -39,7 +39,7 @@ use rustc_trait_selection::traits; use tracing::{info, instrument}; use crate::interface::Compiler; -use crate::{errors, proc_macro_decls, util}; +use crate::{errors, limits, proc_macro_decls, util}; pub fn parse<'a>(sess: &'a Session) -> ast::Crate { let krate = sess @@ -687,6 +687,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock<Providers> = LazyLock::new(|| { |tcx, _| tcx.arena.alloc_from_iter(tcx.resolutions(()).stripped_cfg_items.steal()); providers.resolutions = |tcx, ()| tcx.resolver_for_lowering_raw(()).1; providers.early_lint_checks = early_lint_checks; + limits::provide(providers); proc_macro_decls::provide(providers); rustc_const_eval::provide(providers); rustc_middle::hir::provide(providers); @@ -1134,7 +1135,7 @@ fn get_recursion_limit(krate_attrs: &[ast::Attribute], sess: &Session) -> Limit // because that would require expanding this while in the middle of expansion, which needs to // know the limit before expanding. let _ = validate_and_find_value_str_builtin_attr(sym::recursion_limit, sess, krate_attrs); - rustc_middle::middle::limits::get_recursion_limit(krate_attrs, sess) + crate::limits::get_recursion_limit(krate_attrs, sess) } /// Validate *all* occurrences of the given "[value-str]" built-in attribute and return the first find. diff --git a/compiler/rustc_middle/messages.ftl b/compiler/rustc_middle/messages.ftl index 09c16222be1..dcfa81dab25 100644 --- a/compiler/rustc_middle/messages.ftl +++ b/compiler/rustc_middle/messages.ftl @@ -81,10 +81,6 @@ middle_failed_writing_file = middle_layout_references_error = the type has an unknown layout -middle_limit_invalid = - `limit` must be a non-negative integer - .label = {$error_str} - middle_opaque_hidden_type_mismatch = concrete type differs from previous defining opaque type use .label = expected `{$self_ty}`, got `{$other_ty}` diff --git a/compiler/rustc_middle/src/error.rs b/compiler/rustc_middle/src/error.rs index 91b18295b43..c53e3d54cc4 100644 --- a/compiler/rustc_middle/src/error.rs +++ b/compiler/rustc_middle/src/error.rs @@ -68,16 +68,6 @@ pub enum TypeMismatchReason { } #[derive(Diagnostic)] -#[diag(middle_limit_invalid)] -pub(crate) struct LimitInvalid<'a> { - #[primary_span] - pub span: Span, - #[label] - pub value_span: Span, - pub error_str: &'a str, -} - -#[derive(Diagnostic)] #[diag(middle_recursion_limit_reached)] #[help] pub(crate) struct RecursionLimitReached<'tcx> { diff --git a/compiler/rustc_middle/src/middle/mod.rs b/compiler/rustc_middle/src/middle/mod.rs index 692fe027c49..9f71971ea08 100644 --- a/compiler/rustc_middle/src/middle/mod.rs +++ b/compiler/rustc_middle/src/middle/mod.rs @@ -30,12 +30,7 @@ pub mod lib_features { } } } -pub mod limits; pub mod privacy; pub mod region; pub mod resolve_bound_vars; pub mod stability; - -pub fn provide(providers: &mut crate::query::Providers) { - limits::provide(providers); -} diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 52cb8f57a88..04519008711 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -2168,7 +2168,6 @@ pub fn provide(providers: &mut Providers) { util::provide(providers); print::provide(providers); super::util::bug::provide(providers); - super::middle::provide(providers); *providers = Providers { trait_impls_of: trait_def::trait_impls_of_provider, incoherent_impls: trait_def::incoherent_impls_provider, |
