Skip to content

Commit 06599a5

Browse files
committed
fixup limit handling code
1 parent 47d8c14 commit 06599a5

File tree

46 files changed

+365
-442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+365
-442
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4482,7 +4482,6 @@ dependencies = [
44824482
"rustc_middle",
44834483
"rustc_query_system",
44844484
"rustc_serialize",
4485-
"rustc_session",
44864485
"rustc_span",
44874486
"tracing",
44884487
]

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
use std::num::IntErrorKind;
22

3-
use crate::session_diagnostics::LimitInvalid;
3+
use rustc_hir::limit::Limit;
44

55
use super::prelude::*;
6+
use crate::session_diagnostics::LimitInvalid;
67

78
impl<S: Stage> AcceptContext<'_, '_, S> {
8-
fn parse_limit_int(&self, nv: &NameValueParser) -> Option<usize> {
9+
fn parse_limit_int(&self, nv: &NameValueParser) -> Option<Limit> {
910
let Some(limit) = nv.value_as_str() else {
1011
self.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
1112
return None;
1213
};
1314

1415
let error_str = match limit.as_str().parse() {
15-
Ok(i) => return Some(i),
16+
Ok(i) => return Some(Limit::new(i)),
1617
Err(e) => match e.kind() {
1718
IntErrorKind::PosOverflow => "`limit` is too large",
1819
IntErrorKind::Empty => "`limit` must be a non-negative integer",

compiler/rustc_attr_parsing/src/attributes/prelude.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// parsing
22
// templates
3-
pub(super) use rustc_feature::{AttributeTemplate, template};
43
// data structures
5-
pub(super) use rustc_feature::AttributeType;
4+
pub(super) use rustc_feature::{AttributeTemplate, AttributeType, template};
65
pub(super) use rustc_hir::attrs::AttributeKind;
76
pub(super) use rustc_hir::lints::AttributeLintKind;
87
pub(super) use rustc_hir::{MethodKind, Target};

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,10 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
352352
/// must be delayed until after HIR is built. This method will take care of the details of
353353
/// that.
354354
pub(crate) fn emit_lint(&mut self, lint: AttributeLintKind, span: Span) {
355-
if matches!(self.stage.should_emit(), ShouldEmit::Nothing) {
355+
if !matches!(
356+
self.stage.should_emit(),
357+
ShouldEmit::ErrorsAndLints | ShouldEmit::EarlyFatal { also_emit_lints: true }
358+
) {
356359
return;
357360
}
358361
let id = self.target_id;
@@ -676,7 +679,7 @@ pub enum ShouldEmit {
676679
///
677680
/// Only relevant when early parsing, in late parsing equivalent to `ErrorsAndLints`.
678681
/// Late parsing is never fatal, and instead tries to emit as many diagnostics as possible.
679-
EarlyFatal,
682+
EarlyFatal { also_emit_lints: bool },
680683
/// The operation will emit errors and lints.
681684
/// This is usually what you need.
682685
ErrorsAndLints,
@@ -688,8 +691,8 @@ pub enum ShouldEmit {
688691
impl ShouldEmit {
689692
pub(crate) fn emit_err(&self, diag: Diag<'_>) -> ErrorGuaranteed {
690693
match self {
691-
ShouldEmit::EarlyFatal if diag.level() == Level::DelayedBug => diag.emit(),
692-
ShouldEmit::EarlyFatal => diag.upgrade_to_fatal().emit(),
694+
ShouldEmit::EarlyFatal { .. } if diag.level() == Level::DelayedBug => diag.emit(),
695+
ShouldEmit::EarlyFatal { .. } => diag.upgrade_to_fatal().emit(),
693696
ShouldEmit::ErrorsAndLints => diag.emit(),
694697
ShouldEmit::Nothing => diag.delay_as_bug(),
695698
}

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use either::{Left, Right};
44
use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout};
55
use rustc_errors::DiagCtxtHandle;
66
use rustc_hir::def_id::DefId;
7+
use rustc_hir::limit::Limit;
78
use rustc_middle::mir::interpret::{ErrorHandled, InvalidMetaKind, ReportedErrorInfo};
89
use rustc_middle::query::TyCtxtAt;
910
use rustc_middle::ty::layout::{
@@ -12,7 +13,6 @@ use rustc_middle::ty::layout::{
1213
};
1314
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypingEnv, Variance};
1415
use rustc_middle::{mir, span_bug};
15-
use rustc_session::Limit;
1616
use rustc_span::Span;
1717
use rustc_target::callconv::FnAbi;
1818
use tracing::{debug, trace};

compiler/rustc_expand/src/base.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ use rustc_feature::Features;
1818
use rustc_hir as hir;
1919
use rustc_hir::attrs::{AttributeKind, CfgEntry, Deprecation};
2020
use rustc_hir::def::MacroKinds;
21+
use rustc_hir::limit::Limit;
2122
use rustc_hir::{Stability, find_attr};
2223
use rustc_lint_defs::RegisteredTools;
2324
use rustc_parse::MACRO_ARGUMENTS;
2425
use rustc_parse::parser::{ForceCollect, Parser};
26+
use rustc_session::Session;
2527
use rustc_session::config::CollapseMacroDebuginfo;
2628
use rustc_session::parse::ParseSess;
27-
use rustc_session::{Limit, Session};
2829
use rustc_span::def_id::{CrateNum, DefId, LocalDefId};
2930
use rustc_span::edition::Edition;
3031
use rustc_span::hygiene::{AstPass, ExpnData, ExpnKind, LocalExpnId, MacroKind};

compiler/rustc_expand/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use std::borrow::Cow;
22

33
use rustc_ast::ast;
44
use rustc_errors::codes::*;
5+
use rustc_hir::limit::Limit;
56
use rustc_macros::{Diagnostic, Subdiagnostic};
6-
use rustc_session::Limit;
77
use rustc_span::{Ident, MacroRulesNormalizedIdent, Span, Symbol};
88

99
#[derive(Diagnostic)]

compiler/rustc_expand/src/expand.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ use rustc_errors::PResult;
1919
use rustc_feature::Features;
2020
use rustc_hir::Target;
2121
use rustc_hir::def::MacroKinds;
22+
use rustc_hir::limit::Limit;
2223
use rustc_parse::parser::{
2324
AttemptLocalParseRecovery, CommaRecoveryMode, ForceCollect, Parser, RecoverColon, RecoverComma,
2425
token_descr,
2526
};
27+
use rustc_session::Session;
2628
use rustc_session::lint::BuiltinLintDiag;
2729
use rustc_session::lint::builtin::{UNUSED_ATTRIBUTES, UNUSED_DOC_COMMENTS};
2830
use rustc_session::parse::feature_err;
29-
use rustc_session::{Limit, Session};
3031
use rustc_span::hygiene::SyntaxContext;
3132
use rustc_span::{ErrorGuaranteed, FileName, Ident, LocalExpnId, Span, Symbol, sym};
3233
use smallvec::SmallVec;
@@ -2529,6 +2530,7 @@ impl ExpansionConfig<'_> {
25292530
ExpansionConfig {
25302531
crate_name,
25312532
features,
2533+
// FIXME should this limit be configurable?
25322534
recursion_limit: Limit::new(1024),
25332535
trace_mac: false,
25342536
should_test: false,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub use rustc_target::spec::SanitizerSet;
1414
use thin_vec::ThinVec;
1515

1616
use crate::attrs::pretty_printing::PrintAttribute;
17+
use crate::limit::Limit;
1718
use crate::{DefaultBodyStability, PartialConstStability, RustcVersion, Stability};
1819

1920
#[derive(Copy, Clone, PartialEq, Encodable, Decodable, Debug, HashStable_Generic, PrintAttribute)]
@@ -449,7 +450,7 @@ pub enum AttributeKind {
449450
MayDangle(Span),
450451

451452
/// Represents `#[move_size_limit]`
452-
MoveSizeLimit { attr_span: Span, limit_span: Span, limit: usize },
453+
MoveSizeLimit { attr_span: Span, limit_span: Span, limit: Limit },
453454

454455
/// Represents `#[must_use]`.
455456
MustUse {
@@ -483,7 +484,7 @@ pub enum AttributeKind {
483484
Path(Symbol, Span),
484485

485486
/// Represents `#[pattern_complexity_limit]`
486-
PatternComplexityLimit { attr_span: Span, limit_span: Span, limit: usize },
487+
PatternComplexityLimit { attr_span: Span, limit_span: Span, limit: Limit },
487488

488489
/// Represents `#[pointee]`
489490
Pointee(Span),
@@ -501,7 +502,7 @@ pub enum AttributeKind {
501502
PubTransparent(Span),
502503

503504
/// Represents [`#[recursion_limit]`](https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute)
504-
RecursionLimit { attr_span: Span, limit_span: Span, limit: usize },
505+
RecursionLimit { attr_span: Span, limit_span: Span, limit: Limit },
505506

506507
/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
507508
Repr { reprs: ThinVec<(ReprAttr, Span)>, first_span: Span },
@@ -554,7 +555,7 @@ pub enum AttributeKind {
554555
TypeConst(Span),
555556

556557
/// Represents `#[type_length_limit]`
557-
TypeLengthLimit { attr_span: Span, limit_span: Span, limit: usize },
558+
TypeLengthLimit { attr_span: Span, limit_span: Span, limit: Limit },
558559

559560
/// Represents `#[rustc_unsafe_specialization_marker]`.
560561
UnsafeSpecializationMarker(Span),

compiler/rustc_hir/src/attrs/pretty_printing.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol};
99
use rustc_target::spec::SanitizerSet;
1010
use thin_vec::ThinVec;
1111

12+
use crate::limit::Limit;
13+
1214
/// This trait is used to print attributes in `rustc_hir_pretty`.
1315
///
1416
/// For structs and enums it can be derived using [`rustc_macros::PrintAttribute`].
@@ -146,7 +148,7 @@ macro_rules! print_tup {
146148

147149
print_tup!(A B C D E F G H);
148150
print_skip!(Span, (), ErrorGuaranteed);
149-
print_disp!(u16, bool, NonZero<u32>, usize);
151+
print_disp!(u16, bool, NonZero<u32>, Limit);
150152
print_debug!(
151153
Symbol,
152154
Ident,

0 commit comments

Comments
 (0)