Skip to content

Rollup of 7 pull requests #139023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Mar 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ca9988e
Remove `kw::Empty` uses from `rustc_middle`.
nnethercote Mar 25, 2025
92d802e
expand: Leave traces when expanding `cfg` attributes
petrochenkov Mar 22, 2025
1da5e60
Don't record child scopes for patterns.
m-ou-se Mar 26, 2025
227f933
Simplify RvalueCandidateType.
m-ou-se Mar 26, 2025
0ad0142
Don't set cx.parent to None; it seems unnecessary.
m-ou-se Mar 26, 2025
2cc3fa3
Remove ScopeDepth from var_parent.
m-ou-se Mar 26, 2025
3d58aec
Report compiletest pass mode if forced
jieyouxu Mar 26, 2025
5a6ed74
Remove `kw::Empty` uses from `src/librustdoc`.
nnethercote Mar 27, 2025
215c2c2
Remove some asserts from the `download_ci_llvm` bootstrap test
Kobzol Mar 27, 2025
a3bafca
Add job duration changes stats in post-merge analysis
Kobzol Mar 25, 2025
4a43675
Add cache for job metrics
Kobzol Mar 27, 2025
a37cef9
Add a note about interpreting job duration changes
Kobzol Mar 27, 2025
d0353f5
Add ui test for struct construction by calling syntax
xizheyin Mar 27, 2025
4648650
Improve suggest construct with literal syntax instead of calling
xizheyin Mar 27, 2025
27cca0a
Add CI metadata to bootstrap metrics
Kobzol Mar 27, 2025
3a8621d
Rollup merge of #138844 - petrochenkov:cfgtrace2, r=nnethercote
jhpratt Mar 27, 2025
10debec
Rollup merge of #138926 - nnethercote:less-kw-Empty-rustc_middle, r=lcnr
jhpratt Mar 27, 2025
322d1c1
Rollup merge of #138989 - m-ou-se:clean-up-things, r=jdonszelmann,din…
jhpratt Mar 27, 2025
ed75219
Rollup merge of #138999 - jieyouxu:spellout-pass-mode, r=wesleywiser
jhpratt Mar 27, 2025
d517a4f
Rollup merge of #139014 - xizheyin:issue-138931, r=oli-obk
jhpratt Mar 27, 2025
ecaa35f
Rollup merge of #139015 - Kobzol:llvm-ci-test-fixes, r=onur-ozkan
jhpratt Mar 27, 2025
1b8089d
Rollup merge of #139016 - Kobzol:post-merge-analysis-durations, r=mar…
jhpratt Mar 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ jobs:
env:
CI_JOB_NAME: ${{ matrix.name }}
CI_JOB_DOC_URL: ${{ matrix.doc_url }}
GITHUB_WORKFLOW_RUN_ID: ${{ github.run_id }}
GITHUB_REPOSITORY: ${{ github.repository }}
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
# commit of PR sha or commit sha. `GITHUB_SHA` is not accurate for PRs.
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ impl<'a> AstValidator<'a> {
.filter(|attr| {
let arr = [
sym::allow,
sym::cfg,
sym::cfg_attr,
sym::cfg_trace,
sym::cfg_attr_trace,
sym::deny,
sym::expect,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
}

fn print_attribute_inline(&mut self, attr: &ast::Attribute, is_inline: bool) -> bool {
if attr.has_name(sym::cfg_attr_trace) {
if attr.has_name(sym::cfg_trace) || attr.has_name(sym::cfg_attr_trace) {
// It's not a valid identifier, so avoid printing it
// to keep the printed code reasonably parse-able.
return false;
Expand Down
24 changes: 14 additions & 10 deletions compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ pub fn pre_configure_attrs(sess: &Session, attrs: &[Attribute]) -> ast::AttrVec
.collect()
}

pub(crate) fn attr_into_trace(mut attr: Attribute, trace_name: Symbol) -> Attribute {
match &mut attr.kind {
AttrKind::Normal(normal) => {
let NormalAttr { item, tokens } = &mut **normal;
item.path.segments[0].ident.name = trace_name;
// This makes the trace attributes unobservable to token-based proc macros.
*tokens = Some(LazyAttrTokenStream::new(AttrTokenStream::default()));
}
AttrKind::DocComment(..) => unreachable!(),
}
attr
}

#[macro_export]
macro_rules! configure {
($this:ident, $node:ident) => {
Expand Down Expand Up @@ -280,16 +293,7 @@ impl<'a> StripUnconfigured<'a> {

// A trace attribute left in AST in place of the original `cfg_attr` attribute.
// It can later be used by lints or other diagnostics.
let mut trace_attr = cfg_attr.clone();
match &mut trace_attr.kind {
AttrKind::Normal(normal) => {
let NormalAttr { item, tokens } = &mut **normal;
item.path.segments[0].ident.name = sym::cfg_attr_trace;
// This makes the trace attributes unobservable to token-based proc macros.
*tokens = Some(LazyAttrTokenStream::new(AttrTokenStream::default()));
}
AttrKind::DocComment(..) => unreachable!(),
}
let trace_attr = attr_into_trace(cfg_attr.clone(), sym::cfg_attr_trace);

let Some((cfg_predicate, expanded_attrs)) =
rustc_parse::parse_cfg_attr(cfg_attr, &self.sess.psess)
Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use rustc_span::{ErrorGuaranteed, FileName, Ident, LocalExpnId, Span, sym};
use smallvec::SmallVec;

use crate::base::*;
use crate::config::StripUnconfigured;
use crate::config::{StripUnconfigured, attr_into_trace};
use crate::errors::{
EmptyDelegationMac, GlobDelegationOutsideImpls, GlobDelegationTraitlessQpath, IncompleteParse,
RecursionLimitReached, RemoveExprNotSupported, RemoveNodeNotSupported, UnsupportedKeyValue,
Expand Down Expand Up @@ -2003,7 +2003,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
let attr_name = attr.ident().unwrap().name;
// `#[cfg]` and `#[cfg_attr]` are special - they are
// eagerly evaluated.
if attr_name != sym::cfg && attr_name != sym::cfg_attr_trace {
if attr_name != sym::cfg_trace && attr_name != sym::cfg_attr_trace {
self.cx.sess.psess.buffer_lint(
UNUSED_ATTRIBUTES,
attr.span,
Expand All @@ -2027,11 +2027,10 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
) -> (bool, Option<ast::MetaItem>) {
let (res, meta_item) = self.cfg().cfg_true(&attr);
if res {
// FIXME: `cfg(TRUE)` attributes do not currently remove themselves during expansion,
// and some tools like rustdoc and clippy rely on that. Find a way to remove them
// while keeping the tools working.
self.cx.expanded_inert_attrs.mark(&attr);
node.visit_attrs(|attrs| attrs.insert(pos, attr));
// A trace attribute left in AST in place of the original `cfg` attribute.
// It can later be used by lints or other diagnostics.
let trace_attr = attr_into_trace(attr, sym::cfg_trace);
node.visit_attrs(|attrs| attrs.insert(pos, trace_attr));
}

(res, meta_item)
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,10 +760,14 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
template!(Word, List: r#""...""#), DuplicatesOk,
EncodeCrossCrate::Yes, INTERNAL_UNSTABLE
),
// Trace that is left when a `cfg_attr` attribute is expanded.
// The attribute is not gated, to avoid stability errors, but it cannot be used in stable or
// unstable code directly because `sym::cfg_attr_trace` is not a valid identifier, it can only
// be generated by the compiler.
// Traces that are left when `cfg` and `cfg_attr` attributes are expanded.
// The attributes are not gated, to avoid stability errors, but they cannot be used in stable
// or unstable code directly because `sym::cfg_(attr_)trace` are not valid identifiers, they
// can only be generated by the compiler.
ungated!(
cfg_trace, Normal, template!(Word /* irrelevant */), DuplicatesOk,
EncodeCrossCrate::No
),
ungated!(
cfg_attr_trace, Normal, template!(Word /* irrelevant */), DuplicatesOk,
EncodeCrossCrate::No
Expand Down
39 changes: 18 additions & 21 deletions compiler/rustc_hir_analysis/src/check/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ use tracing::debug;
struct Context {
/// The scope that contains any new variables declared, plus its depth in
/// the scope tree.
var_parent: Option<(Scope, ScopeDepth)>,
var_parent: Option<Scope>,

/// Region parent of expressions, etc., plus its depth in the scope tree.
parent: Option<(Scope, ScopeDepth)>,
}

impl Context {
fn set_var_parent(&mut self) {
self.var_parent = self.parent.map(|(p, _)| p);
}
}

struct ScopeResolutionVisitor<'tcx> {
tcx: TyCtxt<'tcx>,

Expand Down Expand Up @@ -78,7 +84,7 @@ fn record_var_lifetime(visitor: &mut ScopeResolutionVisitor<'_>, var_id: hir::It
//
// extern fn isalnum(c: c_int) -> c_int
}
Some((parent_scope, _)) => visitor.scope_tree.record_var_scope(var_id, parent_scope),
Some(parent_scope) => visitor.scope_tree.record_var_scope(var_id, parent_scope),
}
}

Expand Down Expand Up @@ -113,7 +119,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
// itself has returned.

visitor.enter_node_scope_with_dtor(blk.hir_id.local_id);
visitor.cx.var_parent = visitor.cx.parent;
visitor.cx.set_var_parent();

{
// This block should be kept approximately in sync with
Expand All @@ -132,7 +138,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
local_id: blk.hir_id.local_id,
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
});
visitor.cx.var_parent = visitor.cx.parent;
visitor.cx.set_var_parent();
visitor.visit_stmt(statement);
// We need to back out temporarily to the last enclosing scope
// for the `else` block, so that even the temporaries receiving
Expand All @@ -157,7 +163,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
local_id: blk.hir_id.local_id,
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
});
visitor.cx.var_parent = visitor.cx.parent;
visitor.cx.set_var_parent();
visitor.visit_stmt(statement)
}
hir::StmtKind::Item(..) => {
Expand Down Expand Up @@ -207,7 +213,7 @@ fn resolve_arm<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, arm: &'tcx hir:
visitor.terminating_scopes.insert(arm.hir_id.local_id);

visitor.enter_node_scope_with_dtor(arm.hir_id.local_id);
visitor.cx.var_parent = visitor.cx.parent;
visitor.cx.set_var_parent();

if let Some(expr) = arm.guard
&& !has_let_expr(expr)
Expand All @@ -221,8 +227,6 @@ fn resolve_arm<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, arm: &'tcx hir:
}

fn resolve_pat<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, pat: &'tcx hir::Pat<'tcx>) {
visitor.record_child_scope(Scope { local_id: pat.hir_id.local_id, data: ScopeData::Node });

// If this is a binding then record the lifetime of that binding.
if let PatKind::Binding(..) = pat.kind {
record_var_lifetime(visitor, pat.hir_id.local_id);
Expand Down Expand Up @@ -486,7 +490,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
ScopeData::IfThen
};
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
visitor.cx.var_parent = visitor.cx.parent;
visitor.cx.set_var_parent();
visitor.visit_expr(cond);
visitor.visit_expr(then);
visitor.cx = expr_cx;
Expand All @@ -501,7 +505,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
ScopeData::IfThen
};
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
visitor.cx.var_parent = visitor.cx.parent;
visitor.cx.set_var_parent();
visitor.visit_expr(cond);
visitor.visit_expr(then);
visitor.cx = expr_cx;
Expand Down Expand Up @@ -560,7 +564,7 @@ fn resolve_local<'tcx>(
) {
debug!("resolve_local(pat={:?}, init={:?})", pat, init);

let blk_scope = visitor.cx.var_parent.map(|(p, _)| p);
let blk_scope = visitor.cx.var_parent;

// As an exception to the normal rules governing temporary
// lifetimes, initializers in a let have a temporary lifetime
Expand Down Expand Up @@ -625,10 +629,7 @@ fn resolve_local<'tcx>(
if is_binding_pat(pat) {
visitor.scope_tree.record_rvalue_candidate(
expr.hir_id,
RvalueCandidateType::Pattern {
target: expr.hir_id.local_id,
lifetime: blk_scope,
},
RvalueCandidate { target: expr.hir_id.local_id, lifetime: blk_scope },
);
}
}
Expand Down Expand Up @@ -733,10 +734,7 @@ fn resolve_local<'tcx>(
record_rvalue_scope_if_borrow_expr(visitor, subexpr, blk_id);
visitor.scope_tree.record_rvalue_candidate(
subexpr.hir_id,
RvalueCandidateType::Borrow {
target: subexpr.hir_id.local_id,
lifetime: blk_id,
},
RvalueCandidate { target: subexpr.hir_id.local_id, lifetime: blk_id },
);
}
hir::ExprKind::Struct(_, fields, _) => {
Expand Down Expand Up @@ -857,13 +855,12 @@ impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> {
self.enter_body(body.value.hir_id, |this| {
if this.tcx.hir_body_owner_kind(owner_id).is_fn_or_closure() {
// The arguments and `self` are parented to the fn.
this.cx.var_parent = this.cx.parent.take();
this.cx.set_var_parent();
for param in body.params {
this.visit_pat(param.pat);
}

// The body of the every fn is a root scope.
this.cx.parent = this.cx.var_parent;
this.visit_expr(body.value)
} else {
// Only functions have an outer terminating (drop) scope, while
Expand Down
12 changes: 4 additions & 8 deletions compiler/rustc_hir_typeck/src/rvalue_scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use hir::Node;
use hir::def_id::DefId;
use rustc_hir as hir;
use rustc_middle::bug;
use rustc_middle::middle::region::{RvalueCandidateType, Scope, ScopeTree};
use rustc_middle::middle::region::{RvalueCandidate, Scope, ScopeTree};
use rustc_middle::ty::RvalueScopes;
use tracing::debug;

Expand Down Expand Up @@ -55,15 +55,11 @@ fn record_rvalue_scope_rec(
fn record_rvalue_scope(
rvalue_scopes: &mut RvalueScopes,
expr: &hir::Expr<'_>,
candidate: &RvalueCandidateType,
candidate: &RvalueCandidate,
) {
debug!("resolve_rvalue_scope(expr={expr:?}, candidate={candidate:?})");
match candidate {
RvalueCandidateType::Borrow { lifetime, .. }
| RvalueCandidateType::Pattern { lifetime, .. } => {
record_rvalue_scope_rec(rvalue_scopes, expr, *lifetime)
} // FIXME(@dingxiangfei2009): handle the candidates in the function call arguments
}
record_rvalue_scope_rec(rvalue_scopes, expr, candidate.lifetime)
// FIXME(@dingxiangfei2009): handle the candidates in the function call arguments
}

pub(crate) fn resolve_rvalue_scopes<'a, 'tcx>(
Expand Down
31 changes: 13 additions & 18 deletions compiler/rustc_middle/src/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub struct ScopeTree {
/// and not the enclosing *statement*. Expressions that are not present in this
/// table are not rvalue candidates. The set of rvalue candidates is computed
/// during type check based on a traversal of the AST.
pub rvalue_candidates: HirIdMap<RvalueCandidateType>,
pub rvalue_candidates: HirIdMap<RvalueCandidate>,

/// Backwards incompatible scoping that will be introduced in future editions.
/// This information is used later for linting to identify locals and
Expand Down Expand Up @@ -308,15 +308,14 @@ pub struct ScopeTree {
pub yield_in_scope: UnordMap<Scope, Vec<YieldData>>,
}

/// Identifies the reason that a given expression is an rvalue candidate
/// (see the `rvalue_candidates` field for more information what rvalue
/// candidates in general). In constants, the `lifetime` field is None
/// to indicate that certain expressions escape into 'static and
/// should have no local cleanup scope.
/// See the `rvalue_candidates` field for more information on rvalue
/// candidates in general.
/// The `lifetime` field is None to indicate that certain expressions escape
/// into 'static and should have no local cleanup scope.
#[derive(Debug, Copy, Clone, HashStable)]
pub enum RvalueCandidateType {
Borrow { target: hir::ItemLocalId, lifetime: Option<Scope> },
Pattern { target: hir::ItemLocalId, lifetime: Option<Scope> },
pub struct RvalueCandidate {
pub target: hir::ItemLocalId,
pub lifetime: Option<Scope>,
}

#[derive(Debug, Copy, Clone, HashStable)]
Expand Down Expand Up @@ -344,16 +343,12 @@ impl ScopeTree {
self.var_map.insert(var, lifetime);
}

pub fn record_rvalue_candidate(&mut self, var: HirId, candidate_type: RvalueCandidateType) {
debug!("record_rvalue_candidate(var={var:?}, type={candidate_type:?})");
match &candidate_type {
RvalueCandidateType::Borrow { lifetime: Some(lifetime), .. }
| RvalueCandidateType::Pattern { lifetime: Some(lifetime), .. } => {
assert!(var.local_id != lifetime.local_id)
}
_ => {}
pub fn record_rvalue_candidate(&mut self, var: HirId, candidate: RvalueCandidate) {
debug!("record_rvalue_candidate(var={var:?}, candidate={candidate:?})");
if let Some(lifetime) = &candidate.lifetime {
assert!(var.local_id != lifetime.local_id)
}
self.rvalue_candidates.insert(var, candidate_type);
self.rvalue_candidates.insert(var, candidate);
}

/// Returns the narrowest scope that encloses `id`, if any.
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_middle/src/ty/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ impl GenericParamDef {

pub fn is_anonymous_lifetime(&self) -> bool {
match self.kind {
GenericParamDefKind::Lifetime => {
self.name == kw::UnderscoreLifetime || self.name == kw::Empty
}
GenericParamDefKind::Lifetime => self.name == kw::UnderscoreLifetime,
_ => false,
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ impl EarlyParamRegion {
/// Does this early bound region have a name? Early bound regions normally
/// always have names except when using anonymous lifetimes (`'_`).
pub fn has_name(&self) -> bool {
self.name != kw::UnderscoreLifetime && self.name != kw::Empty
self.name != kw::UnderscoreLifetime
}
}

Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2591,11 +2591,9 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
// to fit that into a short string. Hence the recommendation to use
// `explain_region()` or `note_and_explain_region()`.
match *region {
ty::ReEarlyParam(ref data) => {
if data.name != kw::Empty {
p!(write("{}", data.name));
return Ok(());
}
ty::ReEarlyParam(data) => {
p!(write("{}", data.name));
return Ok(());
}
ty::ReLateParam(ty::LateParamRegion { kind, .. }) => {
if let Some(name) = kind.get_name() {
Expand Down Expand Up @@ -2834,7 +2832,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {

(name, ty::BoundRegionKind::Named(CRATE_DEF_ID.to_def_id(), name))
}
ty::BoundRegionKind::Named(def_id, kw::UnderscoreLifetime | kw::Empty) => {
ty::BoundRegionKind::Named(def_id, kw::UnderscoreLifetime) => {
let name = next_name(self);

if let Some(lt_idx) = lifetime_idx {
Expand Down
Loading
Loading