Skip to content

Commit 1de3926

Browse files
committed
fixup limit handling code
1 parent 23503ad commit 1de3926

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
@@ -4409,7 +4409,6 @@ dependencies = [
44094409
"rustc_middle",
44104410
"rustc_query_system",
44114411
"rustc_serialize",
4412-
"rustc_session",
44134412
"rustc_span",
44144413
"tracing",
44154414
]

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,7 +1,6 @@
1-
// templates
1+
// data structures
22
#[doc(hidden)]
33
pub(super) use rustc_feature::{AttributeTemplate, AttributeType, template};
4-
// data structures
54
#[doc(hidden)]
65
pub(super) use rustc_hir::attrs::AttributeKind;
76
#[doc(hidden)]

compiler/rustc_attr_parsing/src/context.rs

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

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)]
@@ -566,7 +567,7 @@ pub enum AttributeKind {
566567
MayDangle(Span),
567568

568569
/// Represents `#[move_size_limit]`
569-
MoveSizeLimit { attr_span: Span, limit_span: Span, limit: usize },
570+
MoveSizeLimit { attr_span: Span, limit_span: Span, limit: Limit },
570571

571572
/// Represents `#[must_use]`.
572573
MustUse {
@@ -600,7 +601,7 @@ pub enum AttributeKind {
600601
Path(Symbol, Span),
601602

602603
/// Represents `#[pattern_complexity_limit]`
603-
PatternComplexityLimit { attr_span: Span, limit_span: Span, limit: usize },
604+
PatternComplexityLimit { attr_span: Span, limit_span: Span, limit: Limit },
604605

605606
/// Represents `#[pointee]`
606607
Pointee(Span),
@@ -618,7 +619,7 @@ pub enum AttributeKind {
618619
PubTransparent(Span),
619620

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

623624
/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
624625
Repr { reprs: ThinVec<(ReprAttr, Span)>, first_span: Span },
@@ -671,7 +672,7 @@ pub enum AttributeKind {
671672
TypeConst(Span),
672673

673674
/// Represents `#[type_length_limit]`
674-
TypeLengthLimit { attr_span: Span, limit_span: Span, limit: usize },
675+
TypeLengthLimit { attr_span: Span, limit_span: Span, limit: Limit },
675676

676677
/// Represents `#[rustc_unsafe_specialization_marker]`.
677678
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)