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

Method parse_expectation_range

src/attribute.rs:251–362  ·  view source on GitHub ↗
(
        &self,
        mut cursor: Cursor<'a>,
    )

Source from the content-addressed store, hash-verified

249 }
250
251 fn parse_expectation_range<'a>(
252 &self,
253 mut cursor: Cursor<'a>,
254 ) -> Result<((u32, Option<u32>), Cursor<'a>), ErrorGuaranteed> {
255 let expect_range = |span| {
256 Err(self.tcx.dcx().emit_err(InvalidPreemptCountAttribute {
257 span,
258 help: "a range expected",
259 }))
260 };
261
262 let start_span = cursor.peek().span();
263 let mut start = 0;
264 if !matches!(
265 cursor.peek(),
266 TokenTree::Token(
267 token::Token {
268 kind: token::TokenKind::DotDot | token::TokenKind::DotDotEq,
269 ..
270 },
271 _
272 )
273 ) {
274 let token = cursor.next();
275 let TokenTree::Token(
276 token::Token {
277 kind: token::TokenKind::Literal(lit),
278 ..
279 },
280 _,
281 ) = token
282 else {
283 expect_range(token.span())?
284 };
285 if lit.kind != token::LitKind::Integer {
286 expect_range(token.span())?;
287 }
288 let Some(v) = lit.symbol.as_str().parse::<u32>().ok() else {
289 expect_range(token.span())?;
290 };
291 start = v;
292 }
293
294 let inclusive = match cursor.peek() {
295 TokenTree::Token(
296 token::Token {
297 kind: token::TokenKind::DotDot,
298 ..
299 },
300 _,
301 ) => Some(false),
302 TokenTree::Token(
303 token::Token {
304 kind: token::TokenKind::DotDotEq,
305 ..
306 },
307 _,
308 ) => Some(true),

Callers 1

parse_preempt_countMethod · 0.80

Calls 4

spanMethod · 0.80
peekMethod · 0.80
nextMethod · 0.80
unwrapMethod · 0.80

Tested by

no test coverage detected