MCPcopy Create free account
hub / github.com/Rust-for-Linux/klint / parse_preempt_count

Method parse_preempt_count

src/attribute.rs:364–433  ·  view source on GitHub ↗
(
        &self,
        attr: &Attribute,
        item: &AttrItem,
    )

Source from the content-addressed store, hash-verified

362 }
363
364 fn parse_preempt_count(
365 &self,
366 attr: &Attribute,
367 item: &AttrItem,
368 ) -> Result<PreemptionCount, ErrorGuaranteed> {
369 let mut adjustment = None;
370 let mut expectation = None;
371 let mut unchecked = false;
372
373 let AttrArgs::Delimited(DelimArgs {
374 dspan: delim_span,
375 tokens: tts,
376 ..
377 }) = &item.args
378 else {
379 Err(self.tcx.dcx().emit_err(InvalidPreemptCountAttribute {
380 span: attr.span(),
381 help: "correct usage looks like `#[kint::preempt_count(...)]`",
382 }))?
383 };
384
385 self.parse_comma_delimited(Cursor::new(tts.iter(), delim_span.close), |cursor| {
386 self.parse_eq_delimited(
387 cursor,
388 |name| {
389 Ok(match name.name {
390 crate::symbol::adjust | sym::expect => true,
391 crate::symbol::unchecked => false,
392 _ => Err(self.tcx.dcx().emit_err(InvalidPreemptCountAttribute {
393 span: name.span,
394 help: "unknown property, expected `adjust`, `expect` or `unchecked`",
395 }))?,
396 })
397 },
398 |name, mut cursor| {
399 match name.name {
400 crate::symbol::adjust => {
401 let v;
402 (v, cursor) = self.parse_i32(cursor)?;
403 adjustment = Some(v);
404 }
405 sym::expect => {
406 let (lo, hi);
407 ((lo, hi), cursor) = self.parse_expectation_range(cursor)?;
408 expectation = Some(ExpectationRange { lo, hi });
409 }
410 crate::symbol::unchecked => {
411 unchecked = true;
412 }
413 _ => unreachable!(),
414 }
415
416 Ok(cursor)
417 },
418 )
419 })?;
420
421 if adjustment.is_none() && expectation.is_none() {

Callers 1

parseMethod · 0.80

Calls 5

spanMethod · 0.80
parse_comma_delimitedMethod · 0.80
parse_eq_delimitedMethod · 0.80
parse_i32Method · 0.80

Tested by

no test coverage detected