|
| 1 | +use std::path::PathBuf; |
| 2 | + |
1 | 3 | use rustc_ast::{LitIntType, LitKind, MetaItemLit}; |
2 | | -use rustc_hir::attrs::RustcLayoutType; |
| 4 | +use rustc_hir::attrs::{BorrowckGraphvizFormatKind, RustcLayoutType, RustcMirKind}; |
3 | 5 | use rustc_session::errors; |
4 | 6 |
|
5 | 7 | use super::prelude::*; |
@@ -357,7 +359,6 @@ impl<S: Stage> CombineAttributeParser<S> for RustcLayoutParser { |
357 | 359 |
|
358 | 360 | const TEMPLATE: AttributeTemplate = |
359 | 361 | template!(List: &["abi", "align", "size", "homogenous_aggregate", "debug"]); |
360 | | - |
361 | 362 | fn extend( |
362 | 363 | cx: &mut AcceptContext<'_, '_, S>, |
363 | 364 | args: &ArgParser, |
@@ -397,6 +398,94 @@ impl<S: Stage> CombineAttributeParser<S> for RustcLayoutParser { |
397 | 398 | } |
398 | 399 | } |
399 | 400 |
|
| 401 | +pub(crate) struct RustcMirParser; |
| 402 | + |
| 403 | +impl<S: Stage> CombineAttributeParser<S> for RustcMirParser { |
| 404 | + const PATH: &[rustc_span::Symbol] = &[sym::rustc_mir]; |
| 405 | + |
| 406 | + type Item = RustcMirKind; |
| 407 | + |
| 408 | + const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::RustcMir(items); |
| 409 | + |
| 410 | + const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[ |
| 411 | + Allow(Target::Fn), |
| 412 | + Allow(Target::Method(MethodKind::Inherent)), |
| 413 | + Allow(Target::Method(MethodKind::TraitImpl)), |
| 414 | + Allow(Target::Method(MethodKind::Trait { body: false })), |
| 415 | + Allow(Target::Method(MethodKind::Trait { body: true })), |
| 416 | + ]); |
| 417 | + |
| 418 | + const TEMPLATE: AttributeTemplate = template!(List: &["arg1, arg2, ..."]); |
| 419 | + |
| 420 | + fn extend( |
| 421 | + cx: &mut AcceptContext<'_, '_, S>, |
| 422 | + args: &ArgParser, |
| 423 | + ) -> impl IntoIterator<Item = Self::Item> { |
| 424 | + let Some(list) = args.list() else { |
| 425 | + cx.expected_list(cx.attr_span, args); |
| 426 | + return ThinVec::new(); |
| 427 | + }; |
| 428 | + |
| 429 | + list.mixed() |
| 430 | + .filter_map(|arg| arg.meta_item()) |
| 431 | + .filter_map(|mi| { |
| 432 | + if let Some(ident) = mi.ident() { |
| 433 | + match ident.name { |
| 434 | + sym::rustc_peek_maybe_init => Some(RustcMirKind::PeekMaybeInit), |
| 435 | + sym::rustc_peek_maybe_uninit => Some(RustcMirKind::PeekMaybeUninit), |
| 436 | + sym::rustc_peek_liveness => Some(RustcMirKind::PeekLiveness), |
| 437 | + sym::stop_after_dataflow => Some(RustcMirKind::StopAfterDataflow), |
| 438 | + sym::borrowck_graphviz_postflow => { |
| 439 | + let Some(nv) = mi.args().name_value() else { |
| 440 | + cx.expected_name_value( |
| 441 | + mi.span(), |
| 442 | + Some(sym::borrowck_graphviz_postflow), |
| 443 | + ); |
| 444 | + return None; |
| 445 | + }; |
| 446 | + let Some(path) = nv.value_as_str() else { |
| 447 | + cx.expected_string_literal(nv.value_span, None); |
| 448 | + return None; |
| 449 | + }; |
| 450 | + let path = PathBuf::from(path.to_string()); |
| 451 | + if path.file_name().is_some() { |
| 452 | + Some(RustcMirKind::BorrowckGraphvizPostflow { path }) |
| 453 | + } else { |
| 454 | + cx.expected_filename_literal(nv.value_span); |
| 455 | + None |
| 456 | + } |
| 457 | + } |
| 458 | + sym::borrowck_graphviz_format => { |
| 459 | + let Some(nv) = mi.args().name_value() else { |
| 460 | + cx.expected_name_value( |
| 461 | + mi.span(), |
| 462 | + Some(sym::borrowck_graphviz_format), |
| 463 | + ); |
| 464 | + return None; |
| 465 | + }; |
| 466 | + let Some(format) = nv.value_as_ident() else { |
| 467 | + cx.expected_identifier(nv.value_span); |
| 468 | + return None; |
| 469 | + }; |
| 470 | + match format.name { |
| 471 | + sym::two_phase => Some(RustcMirKind::BorrowckGraphvizFormat { |
| 472 | + format: BorrowckGraphvizFormatKind::TwoPhase, |
| 473 | + }), |
| 474 | + _ => { |
| 475 | + cx.expected_specific_argument(format.span, &[sym::two_phase]); |
| 476 | + None |
| 477 | + } |
| 478 | + } |
| 479 | + } |
| 480 | + _ => None, |
| 481 | + } |
| 482 | + } else { |
| 483 | + None |
| 484 | + } |
| 485 | + }) |
| 486 | + .collect() |
| 487 | + } |
| 488 | +} |
400 | 489 | pub(crate) struct RustcNonConstTraitMethodParser; |
401 | 490 |
|
402 | 491 | impl<S: Stage> NoArgsAttributeParser<S> for RustcNonConstTraitMethodParser { |
|
0 commit comments