Skip to content

Commit d4eb454

Browse files
committed
Auto merge of #144891 - Zalathar:rollup-7tsclc3, r=Zalathar
Rollup of 5 pull requests Successful merges: - #144741 (fix: Error on illegal `[const]`s inside blocks within legal positions) - #144779 (Implement debugging output of the bootstrap Step graph into a DOT file) - #144813 (Add a tidy check to prevent adding UI tests directly under `tests/ui/`) - #144866 (Remove `SHOULD_EMIT_LINTS` in favor of `should_emit`) - #144887 (`rust-analyzer` subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e1b9081 + 1771fb5 commit d4eb454

File tree

239 files changed

+6066
-4967
lines changed

Some content is hidden

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

239 files changed

+6066
-4967
lines changed

compiler/rustc_ast_passes/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,10 @@ ast_passes_tilde_const_disallowed = `[const]` is not allowed here
241241
.trait_assoc_ty = associated types in non-`const` traits cannot have `[const]` trait bounds
242242
.trait_impl_assoc_ty = associated types in non-const impls cannot have `[const]` trait bounds
243243
.inherent_assoc_ty = inherent associated types cannot have `[const]` trait bounds
244+
.struct = structs cannot have `[const]` trait bounds
245+
.enum = enums cannot have `[const]` trait bounds
246+
.union = unions cannot have `[const]` trait bounds
247+
.anon_const = anonymous constants cannot have `[const]` trait bounds
244248
.object = trait objects cannot have `[const]` trait bounds
245249
.item = this item cannot have `[const]` trait bounds
246250

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11241124
);
11251125
}
11261126
}
1127-
visit::walk_item(self, item)
1127+
self.with_tilde_const(Some(TildeConstReason::Enum { span: item.span }), |this| {
1128+
visit::walk_item(this, item)
1129+
});
11281130
}
11291131
ItemKind::Trait(box Trait {
11301132
constness,
@@ -1175,26 +1177,32 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11751177
}
11761178
visit::walk_item(self, item)
11771179
}
1178-
ItemKind::Struct(ident, generics, vdata) => match vdata {
1179-
VariantData::Struct { fields, .. } => {
1180-
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
1181-
self.visit_generics(generics);
1182-
walk_list!(self, visit_field_def, fields);
1183-
}
1184-
_ => visit::walk_item(self, item),
1185-
},
1180+
ItemKind::Struct(ident, generics, vdata) => {
1181+
self.with_tilde_const(Some(TildeConstReason::Struct { span: item.span }), |this| {
1182+
match vdata {
1183+
VariantData::Struct { fields, .. } => {
1184+
this.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
1185+
this.visit_generics(generics);
1186+
walk_list!(this, visit_field_def, fields);
1187+
}
1188+
_ => visit::walk_item(this, item),
1189+
}
1190+
})
1191+
}
11861192
ItemKind::Union(ident, generics, vdata) => {
11871193
if vdata.fields().is_empty() {
11881194
self.dcx().emit_err(errors::FieldlessUnion { span: item.span });
11891195
}
1190-
match vdata {
1191-
VariantData::Struct { fields, .. } => {
1192-
self.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
1193-
self.visit_generics(generics);
1194-
walk_list!(self, visit_field_def, fields);
1196+
self.with_tilde_const(Some(TildeConstReason::Union { span: item.span }), |this| {
1197+
match vdata {
1198+
VariantData::Struct { fields, .. } => {
1199+
this.visit_attrs_vis_ident(&item.attrs, &item.vis, ident);
1200+
this.visit_generics(generics);
1201+
walk_list!(this, visit_field_def, fields);
1202+
}
1203+
_ => visit::walk_item(this, item),
11951204
}
1196-
_ => visit::walk_item(self, item),
1197-
}
1205+
});
11981206
}
11991207
ItemKind::Const(box ConstItem { defaultness, expr, .. }) => {
12001208
self.check_defaultness(item.span, *defaultness);
@@ -1623,6 +1631,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
16231631
_ => self.with_in_trait_impl(None, |this| visit::walk_assoc_item(this, item, ctxt)),
16241632
}
16251633
}
1634+
1635+
fn visit_anon_const(&mut self, anon_const: &'a AnonConst) {
1636+
self.with_tilde_const(
1637+
Some(TildeConstReason::AnonConst { span: anon_const.value.span }),
1638+
|this| visit::walk_anon_const(this, anon_const),
1639+
)
1640+
}
16261641
}
16271642

16281643
/// When encountering an equality constraint in a `where` clause, emit an error. If the code seems

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,26 @@ pub(crate) enum TildeConstReason {
623623
#[primary_span]
624624
span: Span,
625625
},
626+
#[note(ast_passes_struct)]
627+
Struct {
628+
#[primary_span]
629+
span: Span,
630+
},
631+
#[note(ast_passes_enum)]
632+
Enum {
633+
#[primary_span]
634+
span: Span,
635+
},
636+
#[note(ast_passes_union)]
637+
Union {
638+
#[primary_span]
639+
span: Span,
640+
},
641+
#[note(ast_passes_anon_const)]
642+
AnonConst {
643+
#[primary_span]
644+
span: Span,
645+
},
626646
#[note(ast_passes_object)]
627647
TraitObject,
628648
#[note(ast_passes_item)]

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ mod private {
222222
#[allow(private_interfaces)]
223223
pub trait Stage: Sized + 'static + Sealed {
224224
type Id: Copy;
225-
const SHOULD_EMIT_LINTS: bool;
226225

227226
fn parsers() -> &'static GroupType<Self>;
228227

@@ -231,13 +230,14 @@ pub trait Stage: Sized + 'static + Sealed {
231230
sess: &'sess Session,
232231
diag: impl for<'x> Diagnostic<'x>,
233232
) -> ErrorGuaranteed;
233+
234+
fn should_emit(&self) -> ShouldEmit;
234235
}
235236

236237
// allow because it's a sealed trait
237238
#[allow(private_interfaces)]
238239
impl Stage for Early {
239240
type Id = NodeId;
240-
const SHOULD_EMIT_LINTS: bool = false;
241241

242242
fn parsers() -> &'static GroupType<Self> {
243243
&early::ATTRIBUTE_PARSERS
@@ -253,13 +253,16 @@ impl Stage for Early {
253253
sess.dcx().create_err(diag).delay_as_bug()
254254
}
255255
}
256+
257+
fn should_emit(&self) -> ShouldEmit {
258+
self.emit_errors
259+
}
256260
}
257261

258262
// allow because it's a sealed trait
259263
#[allow(private_interfaces)]
260264
impl Stage for Late {
261265
type Id = HirId;
262-
const SHOULD_EMIT_LINTS: bool = true;
263266

264267
fn parsers() -> &'static GroupType<Self> {
265268
&late::ATTRIBUTE_PARSERS
@@ -271,6 +274,10 @@ impl Stage for Late {
271274
) -> ErrorGuaranteed {
272275
tcx.dcx().emit_err(diag)
273276
}
277+
278+
fn should_emit(&self) -> ShouldEmit {
279+
ShouldEmit::ErrorsAndLints
280+
}
274281
}
275282

276283
/// used when parsing attributes for miscellaneous things *before* ast lowering
@@ -309,7 +316,7 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
309316
/// must be delayed until after HIR is built. This method will take care of the details of
310317
/// that.
311318
pub(crate) fn emit_lint(&mut self, lint: AttributeLintKind, span: Span) {
312-
if !S::SHOULD_EMIT_LINTS {
319+
if !self.stage.should_emit().should_emit() {
313320
return;
314321
}
315322
let id = self.target_id;

src/bootstrap/src/bin/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ fn main() {
159159
if is_bootstrap_profiling_enabled() {
160160
build.report_summary(start_time);
161161
}
162+
163+
#[cfg(feature = "tracing")]
164+
build.report_step_graph();
162165
}
163166

164167
fn check_version(config: &Config) -> Option<String> {

src/bootstrap/src/core/builder/mod.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl Deref for Builder<'_> {
7777
/// type's [`Debug`] implementation.
7878
///
7979
/// (Trying to debug-print `dyn Any` results in the unhelpful `"Any { .. }"`.)
80-
trait AnyDebug: Any + Debug {}
80+
pub trait AnyDebug: Any + Debug {}
8181
impl<T: Any + Debug> AnyDebug for T {}
8282
impl dyn AnyDebug {
8383
/// Equivalent to `<dyn Any>::downcast_ref`.
@@ -197,6 +197,14 @@ impl StepMetadata {
197197
// For everything else, a stage N things gets built by a stage N-1 compiler.
198198
.map(|compiler| if self.name == "std" { compiler.stage } else { compiler.stage + 1 }))
199199
}
200+
201+
pub fn get_name(&self) -> &str {
202+
&self.name
203+
}
204+
205+
pub fn get_target(&self) -> TargetSelection {
206+
self.target
207+
}
200208
}
201209

202210
pub struct RunConfig<'a> {
@@ -1657,9 +1665,24 @@ You have to build a stage1 compiler for `{}` first, and then use it to build a s
16571665
if let Some(out) = self.cache.get(&step) {
16581666
self.verbose_than(1, || println!("{}c {:?}", " ".repeat(stack.len()), step));
16591667

1668+
#[cfg(feature = "tracing")]
1669+
{
1670+
if let Some(parent) = stack.last() {
1671+
let mut graph = self.build.step_graph.borrow_mut();
1672+
graph.register_cached_step(&step, parent, self.config.dry_run());
1673+
}
1674+
}
16601675
return out;
16611676
}
16621677
self.verbose_than(1, || println!("{}> {:?}", " ".repeat(stack.len()), step));
1678+
1679+
#[cfg(feature = "tracing")]
1680+
{
1681+
let parent = stack.last();
1682+
let mut graph = self.build.step_graph.borrow_mut();
1683+
graph.register_step_execution(&step, parent, self.config.dry_run());
1684+
}
1685+
16631686
stack.push(Box::new(step.clone()));
16641687
}
16651688

src/bootstrap/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ pub enum GitRepo {
188188
/// although most functions are implemented as free functions rather than
189189
/// methods specifically on this structure itself (to make it easier to
190190
/// organize).
191-
#[derive(Clone)]
192191
pub struct Build {
193192
/// User-specified configuration from `bootstrap.toml`.
194193
config: Config,
@@ -244,6 +243,9 @@ pub struct Build {
244243

245244
#[cfg(feature = "build-metrics")]
246245
metrics: crate::utils::metrics::BuildMetrics,
246+
247+
#[cfg(feature = "tracing")]
248+
step_graph: std::cell::RefCell<crate::utils::step_graph::StepGraph>,
247249
}
248250

249251
#[derive(Debug, Clone)]
@@ -547,6 +549,9 @@ impl Build {
547549

548550
#[cfg(feature = "build-metrics")]
549551
metrics: crate::utils::metrics::BuildMetrics::init(),
552+
553+
#[cfg(feature = "tracing")]
554+
step_graph: std::cell::RefCell::new(crate::utils::step_graph::StepGraph::default()),
550555
};
551556

552557
// If local-rust is the same major.minor as the current version, then force a
@@ -2024,6 +2029,11 @@ to download LLVM rather than building it.
20242029
pub fn report_summary(&self, start_time: Instant) {
20252030
self.config.exec_ctx.profiler().report_summary(start_time);
20262031
}
2032+
2033+
#[cfg(feature = "tracing")]
2034+
pub fn report_step_graph(self) {
2035+
self.step_graph.into_inner().store_to_dot_files();
2036+
}
20272037
}
20282038

20292039
impl AsRef<ExecutionContext> for Build {

src/bootstrap/src/utils/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@ pub(crate) mod tracing;
1919
#[cfg(feature = "build-metrics")]
2020
pub(crate) mod metrics;
2121

22+
#[cfg(feature = "tracing")]
23+
pub(crate) mod step_graph;
24+
2225
#[cfg(test)]
2326
pub(crate) mod tests;

0 commit comments

Comments
 (0)