Skip to content

Commit 3f55023

Browse files
committed
Auto merge of rust-lang#139023 - jhpratt:rollup-4ou6ei4, r=jhpratt
Rollup of 7 pull requests Successful merges: - rust-lang#138844 (expand: Leave traces when expanding `cfg` attributes) - rust-lang#138926 (Remove `kw::Empty` uses from `rustc_middle`.) - rust-lang#138989 (Clean up a few things in rustc_hir_analysis::check::region) - rust-lang#138999 (Report compiletest pass mode if forced) - rust-lang#139014 (Improve suggest construct with literal syntax instead of calling) - rust-lang#139015 (Remove unneeded LLVM CI test assertions) - rust-lang#139016 (Add job duration changes to post-merge analysis report) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 217693a + 1b8089d commit 3f55023

File tree

44 files changed

+429
-251
lines changed

Some content is hidden

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

44 files changed

+429
-251
lines changed

.github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ jobs:
6969
env:
7070
CI_JOB_NAME: ${{ matrix.name }}
7171
CI_JOB_DOC_URL: ${{ matrix.doc_url }}
72+
GITHUB_WORKFLOW_RUN_ID: ${{ github.run_id }}
73+
GITHUB_REPOSITORY: ${{ github.repository }}
7274
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
7375
# commit of PR sha or commit sha. `GITHUB_SHA` is not accurate for PRs.
7476
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}

compiler/rustc_ast_passes/src/ast_validation.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ impl<'a> AstValidator<'a> {
334334
.filter(|attr| {
335335
let arr = [
336336
sym::allow,
337-
sym::cfg,
338-
sym::cfg_attr,
337+
sym::cfg_trace,
339338
sym::cfg_attr_trace,
340339
sym::deny,
341340
sym::expect,

compiler/rustc_ast_pretty/src/pprust/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
593593
}
594594

595595
fn print_attribute_inline(&mut self, attr: &ast::Attribute, is_inline: bool) -> bool {
596-
if attr.has_name(sym::cfg_attr_trace) {
596+
if attr.has_name(sym::cfg_trace) || attr.has_name(sym::cfg_attr_trace) {
597597
// It's not a valid identifier, so avoid printing it
598598
// to keep the printed code reasonably parse-able.
599599
return false;

compiler/rustc_expand/src/config.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,19 @@ pub fn pre_configure_attrs(sess: &Session, attrs: &[Attribute]) -> ast::AttrVec
156156
.collect()
157157
}
158158

159+
pub(crate) fn attr_into_trace(mut attr: Attribute, trace_name: Symbol) -> Attribute {
160+
match &mut attr.kind {
161+
AttrKind::Normal(normal) => {
162+
let NormalAttr { item, tokens } = &mut **normal;
163+
item.path.segments[0].ident.name = trace_name;
164+
// This makes the trace attributes unobservable to token-based proc macros.
165+
*tokens = Some(LazyAttrTokenStream::new(AttrTokenStream::default()));
166+
}
167+
AttrKind::DocComment(..) => unreachable!(),
168+
}
169+
attr
170+
}
171+
159172
#[macro_export]
160173
macro_rules! configure {
161174
($this:ident, $node:ident) => {
@@ -280,16 +293,7 @@ impl<'a> StripUnconfigured<'a> {
280293

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

294298
let Some((cfg_predicate, expanded_attrs)) =
295299
rustc_parse::parse_cfg_attr(cfg_attr, &self.sess.psess)

compiler/rustc_expand/src/expand.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use rustc_span::{ErrorGuaranteed, FileName, Ident, LocalExpnId, Span, sym};
3333
use smallvec::SmallVec;
3434

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

20372036
(res, meta_item)

compiler/rustc_feature/src/builtin_attrs.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -760,10 +760,14 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
760760
template!(Word, List: r#""...""#), DuplicatesOk,
761761
EncodeCrossCrate::Yes, INTERNAL_UNSTABLE
762762
),
763-
// Trace that is left when a `cfg_attr` attribute is expanded.
764-
// The attribute is not gated, to avoid stability errors, but it cannot be used in stable or
765-
// unstable code directly because `sym::cfg_attr_trace` is not a valid identifier, it can only
766-
// be generated by the compiler.
763+
// Traces that are left when `cfg` and `cfg_attr` attributes are expanded.
764+
// The attributes are not gated, to avoid stability errors, but they cannot be used in stable
765+
// or unstable code directly because `sym::cfg_(attr_)trace` are not valid identifiers, they
766+
// can only be generated by the compiler.
767+
ungated!(
768+
cfg_trace, Normal, template!(Word /* irrelevant */), DuplicatesOk,
769+
EncodeCrossCrate::No
770+
),
767771
ungated!(
768772
cfg_attr_trace, Normal, template!(Word /* irrelevant */), DuplicatesOk,
769773
EncodeCrossCrate::No

compiler/rustc_hir_analysis/src/check/region.rs

+18-21
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@ use tracing::debug;
2525
struct Context {
2626
/// The scope that contains any new variables declared, plus its depth in
2727
/// the scope tree.
28-
var_parent: Option<(Scope, ScopeDepth)>,
28+
var_parent: Option<Scope>,
2929

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

34+
impl Context {
35+
fn set_var_parent(&mut self) {
36+
self.var_parent = self.parent.map(|(p, _)| p);
37+
}
38+
}
39+
3440
struct ScopeResolutionVisitor<'tcx> {
3541
tcx: TyCtxt<'tcx>,
3642

@@ -78,7 +84,7 @@ fn record_var_lifetime(visitor: &mut ScopeResolutionVisitor<'_>, var_id: hir::It
7884
//
7985
// extern fn isalnum(c: c_int) -> c_int
8086
}
81-
Some((parent_scope, _)) => visitor.scope_tree.record_var_scope(var_id, parent_scope),
87+
Some(parent_scope) => visitor.scope_tree.record_var_scope(var_id, parent_scope),
8288
}
8389
}
8490

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

115121
visitor.enter_node_scope_with_dtor(blk.hir_id.local_id);
116-
visitor.cx.var_parent = visitor.cx.parent;
122+
visitor.cx.set_var_parent();
117123

118124
{
119125
// This block should be kept approximately in sync with
@@ -132,7 +138,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
132138
local_id: blk.hir_id.local_id,
133139
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
134140
});
135-
visitor.cx.var_parent = visitor.cx.parent;
141+
visitor.cx.set_var_parent();
136142
visitor.visit_stmt(statement);
137143
// We need to back out temporarily to the last enclosing scope
138144
// for the `else` block, so that even the temporaries receiving
@@ -157,7 +163,7 @@ fn resolve_block<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, blk: &'tcx hi
157163
local_id: blk.hir_id.local_id,
158164
data: ScopeData::Remainder(FirstStatementIndex::new(i)),
159165
});
160-
visitor.cx.var_parent = visitor.cx.parent;
166+
visitor.cx.set_var_parent();
161167
visitor.visit_stmt(statement)
162168
}
163169
hir::StmtKind::Item(..) => {
@@ -207,7 +213,7 @@ fn resolve_arm<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, arm: &'tcx hir:
207213
visitor.terminating_scopes.insert(arm.hir_id.local_id);
208214

209215
visitor.enter_node_scope_with_dtor(arm.hir_id.local_id);
210-
visitor.cx.var_parent = visitor.cx.parent;
216+
visitor.cx.set_var_parent();
211217

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

223229
fn resolve_pat<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, pat: &'tcx hir::Pat<'tcx>) {
224-
visitor.record_child_scope(Scope { local_id: pat.hir_id.local_id, data: ScopeData::Node });
225-
226230
// If this is a binding then record the lifetime of that binding.
227231
if let PatKind::Binding(..) = pat.kind {
228232
record_var_lifetime(visitor, pat.hir_id.local_id);
@@ -486,7 +490,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
486490
ScopeData::IfThen
487491
};
488492
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
489-
visitor.cx.var_parent = visitor.cx.parent;
493+
visitor.cx.set_var_parent();
490494
visitor.visit_expr(cond);
491495
visitor.visit_expr(then);
492496
visitor.cx = expr_cx;
@@ -501,7 +505,7 @@ fn resolve_expr<'tcx>(visitor: &mut ScopeResolutionVisitor<'tcx>, expr: &'tcx hi
501505
ScopeData::IfThen
502506
};
503507
visitor.enter_scope(Scope { local_id: then.hir_id.local_id, data });
504-
visitor.cx.var_parent = visitor.cx.parent;
508+
visitor.cx.set_var_parent();
505509
visitor.visit_expr(cond);
506510
visitor.visit_expr(then);
507511
visitor.cx = expr_cx;
@@ -560,7 +564,7 @@ fn resolve_local<'tcx>(
560564
) {
561565
debug!("resolve_local(pat={:?}, init={:?})", pat, init);
562566

563-
let blk_scope = visitor.cx.var_parent.map(|(p, _)| p);
567+
let blk_scope = visitor.cx.var_parent;
564568

565569
// As an exception to the normal rules governing temporary
566570
// lifetimes, initializers in a let have a temporary lifetime
@@ -625,10 +629,7 @@ fn resolve_local<'tcx>(
625629
if is_binding_pat(pat) {
626630
visitor.scope_tree.record_rvalue_candidate(
627631
expr.hir_id,
628-
RvalueCandidateType::Pattern {
629-
target: expr.hir_id.local_id,
630-
lifetime: blk_scope,
631-
},
632+
RvalueCandidate { target: expr.hir_id.local_id, lifetime: blk_scope },
632633
);
633634
}
634635
}
@@ -733,10 +734,7 @@ fn resolve_local<'tcx>(
733734
record_rvalue_scope_if_borrow_expr(visitor, subexpr, blk_id);
734735
visitor.scope_tree.record_rvalue_candidate(
735736
subexpr.hir_id,
736-
RvalueCandidateType::Borrow {
737-
target: subexpr.hir_id.local_id,
738-
lifetime: blk_id,
739-
},
737+
RvalueCandidate { target: subexpr.hir_id.local_id, lifetime: blk_id },
740738
);
741739
}
742740
hir::ExprKind::Struct(_, fields, _) => {
@@ -857,13 +855,12 @@ impl<'tcx> Visitor<'tcx> for ScopeResolutionVisitor<'tcx> {
857855
self.enter_body(body.value.hir_id, |this| {
858856
if this.tcx.hir_body_owner_kind(owner_id).is_fn_or_closure() {
859857
// The arguments and `self` are parented to the fn.
860-
this.cx.var_parent = this.cx.parent.take();
858+
this.cx.set_var_parent();
861859
for param in body.params {
862860
this.visit_pat(param.pat);
863861
}
864862

865863
// The body of the every fn is a root scope.
866-
this.cx.parent = this.cx.var_parent;
867864
this.visit_expr(body.value)
868865
} else {
869866
// Only functions have an outer terminating (drop) scope, while

compiler/rustc_hir_typeck/src/rvalue_scopes.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use hir::Node;
22
use hir::def_id::DefId;
33
use rustc_hir as hir;
44
use rustc_middle::bug;
5-
use rustc_middle::middle::region::{RvalueCandidateType, Scope, ScopeTree};
5+
use rustc_middle::middle::region::{RvalueCandidate, Scope, ScopeTree};
66
use rustc_middle::ty::RvalueScopes;
77
use tracing::debug;
88

@@ -55,15 +55,11 @@ fn record_rvalue_scope_rec(
5555
fn record_rvalue_scope(
5656
rvalue_scopes: &mut RvalueScopes,
5757
expr: &hir::Expr<'_>,
58-
candidate: &RvalueCandidateType,
58+
candidate: &RvalueCandidate,
5959
) {
6060
debug!("resolve_rvalue_scope(expr={expr:?}, candidate={candidate:?})");
61-
match candidate {
62-
RvalueCandidateType::Borrow { lifetime, .. }
63-
| RvalueCandidateType::Pattern { lifetime, .. } => {
64-
record_rvalue_scope_rec(rvalue_scopes, expr, *lifetime)
65-
} // FIXME(@dingxiangfei2009): handle the candidates in the function call arguments
66-
}
61+
record_rvalue_scope_rec(rvalue_scopes, expr, candidate.lifetime)
62+
// FIXME(@dingxiangfei2009): handle the candidates in the function call arguments
6763
}
6864

6965
pub(crate) fn resolve_rvalue_scopes<'a, 'tcx>(

compiler/rustc_middle/src/middle/region.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ pub struct ScopeTree {
224224
/// and not the enclosing *statement*. Expressions that are not present in this
225225
/// table are not rvalue candidates. The set of rvalue candidates is computed
226226
/// during type check based on a traversal of the AST.
227-
pub rvalue_candidates: HirIdMap<RvalueCandidateType>,
227+
pub rvalue_candidates: HirIdMap<RvalueCandidate>,
228228

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

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

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

347-
pub fn record_rvalue_candidate(&mut self, var: HirId, candidate_type: RvalueCandidateType) {
348-
debug!("record_rvalue_candidate(var={var:?}, type={candidate_type:?})");
349-
match &candidate_type {
350-
RvalueCandidateType::Borrow { lifetime: Some(lifetime), .. }
351-
| RvalueCandidateType::Pattern { lifetime: Some(lifetime), .. } => {
352-
assert!(var.local_id != lifetime.local_id)
353-
}
354-
_ => {}
346+
pub fn record_rvalue_candidate(&mut self, var: HirId, candidate: RvalueCandidate) {
347+
debug!("record_rvalue_candidate(var={var:?}, candidate={candidate:?})");
348+
if let Some(lifetime) = &candidate.lifetime {
349+
assert!(var.local_id != lifetime.local_id)
355350
}
356-
self.rvalue_candidates.insert(var, candidate_type);
351+
self.rvalue_candidates.insert(var, candidate);
357352
}
358353

359354
/// Returns the narrowest scope that encloses `id`, if any.

compiler/rustc_middle/src/ty/generics.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ impl GenericParamDef {
7373

7474
pub fn is_anonymous_lifetime(&self) -> bool {
7575
match self.kind {
76-
GenericParamDefKind::Lifetime => {
77-
self.name == kw::UnderscoreLifetime || self.name == kw::Empty
78-
}
76+
GenericParamDefKind::Lifetime => self.name == kw::UnderscoreLifetime,
7977
_ => false,
8078
}
8179
}

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ impl EarlyParamRegion {
457457
/// Does this early bound region have a name? Early bound regions normally
458458
/// always have names except when using anonymous lifetimes (`'_`).
459459
pub fn has_name(&self) -> bool {
460-
self.name != kw::UnderscoreLifetime && self.name != kw::Empty
460+
self.name != kw::UnderscoreLifetime
461461
}
462462
}
463463

compiler/rustc_middle/src/ty/print/pretty.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -2591,11 +2591,9 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
25912591
// to fit that into a short string. Hence the recommendation to use
25922592
// `explain_region()` or `note_and_explain_region()`.
25932593
match *region {
2594-
ty::ReEarlyParam(ref data) => {
2595-
if data.name != kw::Empty {
2596-
p!(write("{}", data.name));
2597-
return Ok(());
2598-
}
2594+
ty::ReEarlyParam(data) => {
2595+
p!(write("{}", data.name));
2596+
return Ok(());
25992597
}
26002598
ty::ReLateParam(ty::LateParamRegion { kind, .. }) => {
26012599
if let Some(name) = kind.get_name() {
@@ -2834,7 +2832,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
28342832

28352833
(name, ty::BoundRegionKind::Named(CRATE_DEF_ID.to_def_id(), name))
28362834
}
2837-
ty::BoundRegionKind::Named(def_id, kw::UnderscoreLifetime | kw::Empty) => {
2835+
ty::BoundRegionKind::Named(def_id, kw::UnderscoreLifetime) => {
28382836
let name = next_name(self);
28392837

28402838
if let Some(lt_idx) = lifetime_idx {

0 commit comments

Comments
 (0)