Skip to content

Commit b7b5409

Browse files
committed
Auto merge of #143507 - matthiaskrgr:rollup-lpg7t12, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #143238 (Port `#[ignore]` to the new attribute parsing infrastructure) - #143441 (Stop using `Key` trait unnecessarily) - #143478 (Miri subtree update) - #143486 (remove armv5te-unknown-linux-gnueabi target maintainer) - #143489 (Complete rustc_ast::mut_visit for spans.) - #143494 (Remove yields_in_scope from the scope tree.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5adb489 + c3c4fd7 commit b7b5409

File tree

75 files changed

+1719
-809
lines changed

Some content is hidden

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

75 files changed

+1719
-809
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,6 +2394,7 @@ dependencies = [
23942394
"regex",
23952395
"rustc_version",
23962396
"serde",
2397+
"serde_json",
23972398
"smallvec",
23982399
"tempfile",
23992400
"tikv-jemalloc-sys",

compiler/rustc_ast/src/visit.rs

Lines changed: 79 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,9 +1202,10 @@ macro_rules! common_visitor_and_walkers {
12021202
let TyPat { id, kind, span, tokens: _ } = tp;
12031203
try_visit!(visit_id(vis, id));
12041204
match kind {
1205-
TyPatKind::Range(start, end, _include_end) => {
1205+
TyPatKind::Range(start, end, Spanned { span, node: _include_end }) => {
12061206
visit_opt!(vis, visit_anon_const, start);
12071207
visit_opt!(vis, visit_anon_const, end);
1208+
try_visit!(visit_span(vis, span));
12081209
}
12091210
TyPatKind::Or(variants) => walk_list!(vis, visit_ty_pat, variants),
12101211
TyPatKind::Err(_) => {}
@@ -1523,16 +1524,26 @@ macro_rules! common_visitor_and_walkers {
15231524
}
15241525

15251526
pub fn walk_inline_asm<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, asm: &$($lt)? $($mut)? InlineAsm) -> V::Result {
1526-
// FIXME: Visit spans inside all this currently ignored stuff.
15271527
let InlineAsm {
15281528
asm_macro: _,
1529-
template: _,
1530-
template_strs: _,
1529+
template,
1530+
template_strs,
15311531
operands,
1532-
clobber_abis: _,
1532+
clobber_abis,
15331533
options: _,
1534-
line_spans: _,
1534+
line_spans,
15351535
} = asm;
1536+
for piece in template {
1537+
match piece {
1538+
InlineAsmTemplatePiece::String(_str) => {}
1539+
InlineAsmTemplatePiece::Placeholder { operand_idx: _, modifier: _, span } => {
1540+
try_visit!(visit_span(vis, span));
1541+
}
1542+
}
1543+
}
1544+
for (_s1, _s2, span) in template_strs {
1545+
try_visit!(visit_span(vis, span));
1546+
}
15361547
for (op, span) in operands {
15371548
match op {
15381549
InlineAsmOperand::In { expr, reg: _ }
@@ -1553,6 +1564,12 @@ macro_rules! common_visitor_and_walkers {
15531564
}
15541565
try_visit!(visit_span(vis, span));
15551566
}
1567+
for (_s1, span) in clobber_abis {
1568+
try_visit!(visit_span(vis, span))
1569+
}
1570+
for span in line_spans {
1571+
try_visit!(visit_span(vis, span))
1572+
}
15561573
V::Result::output()
15571574
}
15581575

@@ -1565,9 +1582,9 @@ macro_rules! common_visitor_and_walkers {
15651582
vis.visit_path(path)
15661583
}
15671584

1568-
// FIXME: visit the template exhaustively.
15691585
pub fn walk_format_args<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, fmt: &$($lt)? $($mut)? FormatArgs) -> V::Result {
1570-
let FormatArgs { span, template: _, arguments, uncooked_fmt_str: _, is_source_literal: _ } = fmt;
1586+
let FormatArgs { span, template, arguments, uncooked_fmt_str: _, is_source_literal: _ } = fmt;
1587+
15711588
let args = $(${ignore($mut)} arguments.all_args_mut())? $(${ignore($lt)} arguments.all_args())? ;
15721589
for FormatArgument { kind, expr } in args {
15731590
match kind {
@@ -1578,9 +1595,58 @@ macro_rules! common_visitor_and_walkers {
15781595
}
15791596
try_visit!(vis.visit_expr(expr));
15801597
}
1598+
for piece in template {
1599+
match piece {
1600+
FormatArgsPiece::Literal(_symbol) => {}
1601+
FormatArgsPiece::Placeholder(placeholder) => try_visit!(walk_format_placeholder(vis, placeholder)),
1602+
}
1603+
}
15811604
visit_span(vis, span)
15821605
}
15831606

1607+
fn walk_format_placeholder<$($lt,)? V: $Visitor$(<$lt>)?>(
1608+
vis: &mut V,
1609+
placeholder: &$($lt)? $($mut)? FormatPlaceholder,
1610+
) -> V::Result {
1611+
let FormatPlaceholder { argument, span, format_options, format_trait: _ } = placeholder;
1612+
if let Some(span) = span {
1613+
try_visit!(visit_span(vis, span));
1614+
}
1615+
let FormatArgPosition { span, index: _, kind: _ } = argument;
1616+
if let Some(span) = span {
1617+
try_visit!(visit_span(vis, span));
1618+
}
1619+
let FormatOptions {
1620+
width,
1621+
precision,
1622+
alignment: _,
1623+
fill: _,
1624+
sign: _,
1625+
alternate: _,
1626+
zero_pad: _,
1627+
debug_hex: _,
1628+
} = format_options;
1629+
match width {
1630+
None => {}
1631+
Some(FormatCount::Literal(_)) => {}
1632+
Some(FormatCount::Argument(FormatArgPosition { span, index: _, kind: _ })) => {
1633+
if let Some(span) = span {
1634+
try_visit!(visit_span(vis, span));
1635+
}
1636+
}
1637+
}
1638+
match precision {
1639+
None => {}
1640+
Some(FormatCount::Literal(_)) => {}
1641+
Some(FormatCount::Argument(FormatArgPosition { span, index: _, kind: _ })) => {
1642+
if let Some(span) = span {
1643+
try_visit!(visit_span(vis, span));
1644+
}
1645+
}
1646+
}
1647+
V::Result::output()
1648+
}
1649+
15841650
pub fn walk_expr<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, expression: &$($lt)? $($mut)? Expr) -> V::Result {
15851651
let Expr { id, kind, span, attrs, tokens: _ } = expression;
15861652
try_visit!(visit_id(vis, id));
@@ -1601,7 +1667,7 @@ macro_rules! common_visitor_and_walkers {
16011667
try_visit!(visit_expr_fields(vis, fields));
16021668
match rest {
16031669
StructRest::Base(expr) => try_visit!(vis.visit_expr(expr)),
1604-
StructRest::Rest(_span) => {}
1670+
StructRest::Rest(span) => try_visit!(visit_span(vis, span)),
16051671
StructRest::None => {}
16061672
}
16071673
}
@@ -1688,7 +1754,8 @@ macro_rules! common_visitor_and_walkers {
16881754
visit_opt!(vis, visit_label, opt_label);
16891755
try_visit!(vis.visit_block(block));
16901756
}
1691-
ExprKind::Gen(_capt, body, _kind, decl_span) => {
1757+
ExprKind::Gen(capture_clause, body, _kind, decl_span) => {
1758+
try_visit!(vis.visit_capture_by(capture_clause));
16921759
try_visit!(vis.visit_block(body));
16931760
try_visit!(visit_span(vis, decl_span));
16941761
}
@@ -1705,9 +1772,10 @@ macro_rules! common_visitor_and_walkers {
17051772
try_visit!(vis.visit_expr(rhs));
17061773
try_visit!(visit_span(vis, span));
17071774
}
1708-
ExprKind::AssignOp(_op, left_expression, right_expression) => {
1775+
ExprKind::AssignOp(Spanned { span, node: _ }, left_expression, right_expression) => {
17091776
try_visit!(vis.visit_expr(left_expression));
17101777
try_visit!(vis.visit_expr(right_expression));
1778+
try_visit!(visit_span(vis, span));
17111779
}
17121780
ExprKind::Field(subexpression, ident) => {
17131781
try_visit!(vis.visit_expr(subexpression));

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ pub enum AttributeKind {
250250
span: Span,
251251
},
252252

253+
/// Represents `#[ignore]`
254+
Ignore {
255+
span: Span,
256+
/// ignore can optionally have a reason: `#[ignore = "reason this is ignored"]`
257+
reason: Option<Symbol>,
258+
},
259+
253260
/// Represents `#[inline]` and `#[rustc_force_inline]`.
254261
Inline(InlineAttr, Span),
255262

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl AttributeKind {
2626
Deprecation { .. } => Yes,
2727
DocComment { .. } => Yes,
2828
ExportName { .. } => Yes,
29+
Ignore { .. } => No,
2930
Inline(..) => No,
3031
LinkName { .. } => Yes,
3132
LinkSection { .. } => No,

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub(crate) mod repr;
4141
pub(crate) mod rustc_internal;
4242
pub(crate) mod semantics;
4343
pub(crate) mod stability;
44+
pub(crate) mod test_attrs;
4445
pub(crate) mod traits;
4546
pub(crate) mod transparency;
4647
pub(crate) mod util;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
use rustc_attr_data_structures::AttributeKind;
2+
use rustc_attr_data_structures::lints::AttributeLintKind;
3+
use rustc_feature::{AttributeTemplate, template};
4+
use rustc_span::{Symbol, sym};
5+
6+
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
7+
use crate::context::{AcceptContext, Stage};
8+
use crate::parser::ArgParser;
9+
10+
pub(crate) struct IgnoreParser;
11+
12+
impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
13+
const PATH: &[Symbol] = &[sym::ignore];
14+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
15+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
16+
const TEMPLATE: AttributeTemplate = template!(Word, NameValueStr: "reason");
17+
18+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
19+
Some(AttributeKind::Ignore {
20+
span: cx.attr_span,
21+
reason: match args {
22+
ArgParser::NoArgs => None,
23+
ArgParser::NameValue(name_value) => {
24+
let Some(str_value) = name_value.value_as_str() else {
25+
let suggestions = <Self as SingleAttributeParser<S>>::TEMPLATE
26+
.suggestions(false, "ignore");
27+
let span = cx.attr_span;
28+
cx.emit_lint(
29+
AttributeLintKind::IllFormedAttributeInput { suggestions },
30+
span,
31+
);
32+
return None;
33+
};
34+
Some(str_value)
35+
}
36+
ArgParser::List(_) => {
37+
let suggestions =
38+
<Self as SingleAttributeParser<S>>::TEMPLATE.suggestions(false, "ignore");
39+
let span = cx.attr_span;
40+
cx.emit_lint(AttributeLintKind::IllFormedAttributeInput { suggestions }, span);
41+
return None;
42+
}
43+
},
44+
})
45+
}
46+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ use crate::attributes::semantics::MayDangleParser;
3737
use crate::attributes::stability::{
3838
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
3939
};
40+
use crate::attributes::test_attrs::IgnoreParser;
4041
use crate::attributes::traits::SkipDuringMethodDispatchParser;
4142
use crate::attributes::transparency::TransparencyParser;
4243
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
@@ -126,6 +127,7 @@ attribute_parsers!(
126127
// tidy-alphabetical-start
127128
Single<DeprecationParser>,
128129
Single<ExportNameParser>,
130+
Single<IgnoreParser>,
129131
Single<InlineParser>,
130132
Single<LinkNameParser>,
131133
Single<LinkSectionParser>,

compiler/rustc_const_eval/src/const_eval/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Not in interpret to make sure we do not use private implementation details
22

33
use rustc_abi::{FieldIdx, VariantIdx};
4-
use rustc_middle::query::Key;
54
use rustc_middle::ty::{self, Ty, TyCtxt};
65
use rustc_middle::{bug, mir};
6+
use rustc_span::DUMMY_SP;
77
use tracing::instrument;
88

99
use crate::interpret::InterpCx;
@@ -71,8 +71,7 @@ pub fn tag_for_variant_provider<'tcx>(
7171
let (ty, variant_index) = key.value;
7272
assert!(ty.is_enum());
7373

74-
let ecx =
75-
InterpCx::new(tcx, ty.default_span(tcx), key.typing_env, crate::const_eval::DummyMachine);
74+
let ecx = InterpCx::new(tcx, DUMMY_SP, key.typing_env, crate::const_eval::DummyMachine);
7675

7776
let layout = ecx.layout_of(ty).unwrap();
7877
ecx.tag_for_variant(layout, variant_index).unwrap().map(|(tag, _tag_field)| tag)

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,7 @@ impl AttributeExt for Attribute {
13031303
Attribute::Parsed(AttributeKind::Deprecation { span, .. }) => *span,
13041304
Attribute::Parsed(AttributeKind::DocComment { span, .. }) => *span,
13051305
Attribute::Parsed(AttributeKind::MayDangle(span)) => *span,
1306+
Attribute::Parsed(AttributeKind::Ignore { span, .. }) => *span,
13061307
a => panic!("can't get the span of an arbitrary parsed attribute: {a:?}"),
13071308
}
13081309
}

0 commit comments

Comments
 (0)