Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ac609f9
Distinguish or/refutable/irrefutable patterns in `InterPat`
Zalathar Aug 2, 2026
b12184e
Distinguish or/testable patterns in `MatchPairTree`
Zalathar Aug 2, 2026
a280dde
Rename and combine `then_else_break` to `lower_if_condition`
Zalathar Aug 27, 2026
fde9cd0
Describe if-condition arms as `(true_block, false_block)`
Zalathar Aug 27, 2026
422d1fd
Rename `break_for_else` to `break_from_if_then_scope`
Zalathar Aug 27, 2026
82ee18a
stabilize map functions
Qelxiros Aug 4, 2026
178eb4b
attach naked function target features to module assembly
folkertdev Aug 6, 2026
2060175
bootstrap: stage0 to cbae9b4cae2b108f6a3d18cfe6075714bb739463
weihanglo Aug 31, 2026
2a534f5
`BUILTIN_ATTRIBUTE_MAP` improvements
nnethercote Aug 31, 2026
9670dfa
Use `GateFn` in `AttributeStability`
nnethercote Aug 31, 2026
cd09177
Derive `StableHash` for three feature structs
nnethercote Aug 31, 2026
b18fed1
Return a slice instead of `&Vec<T>` in two methods
nnethercote Aug 31, 2026
799c6d0
Various comment improvements
nnethercote Aug 31, 2026
6146d3a
Use `NonZero<u32>` consistently
nnethercote Aug 31, 2026
ca967fa
Add a missing backtick
nnethercote Aug 31, 2026
ef2ae3a
Streamline a check
nnethercote Aug 31, 2026
60be562
Simplify `find_gated_cfg`
nnethercote Aug 31, 2026
892c6bb
explicitly track inherent const generic args kind
khyperia Aug 31, 2026
af2d4bc
Switch dist-aarch64-linux to EC2 and update dist-x86_64-linux
Mark-Simulacrum Aug 30, 2026
1483f9b
remove `_{style}` recovery for diagnostic structs
mejrs Aug 31, 2026
e18a012
Move track_caller on closures gating to attribute parsing
mejrs Aug 31, 2026
9f89751
Move polonius loan liveness computation prior to RegionInferenceConte…
jackh726 Aug 28, 2026
6ad5c17
Move record_live_region_variance to be a freestanding function
jackh726 Aug 28, 2026
b58ee5b
Minor trace updates
jackh726 Aug 28, 2026
bdd12d7
Rollup merge of #137720 - folkertdev:naked-function-target-feature, r…
jhpratt Sep 1, 2026
e82ccfe
Rollup merge of #160534 - Qelxiros:stabilize-smart-pointer-map, r=nia-e
jhpratt Sep 1, 2026
7c00c3e
Rollup merge of #160551 - Zalathar:inter-pat, r=Nadrieril
jhpratt Sep 1, 2026
c62a074
Rollup merge of #161861 - Zalathar:if-then, r=Nadrieril
jhpratt Sep 1, 2026
90e79ca
Rollup merge of #161929 - khyperia:explicitly-track-inherent-args, r=…
jhpratt Sep 1, 2026
713bc03
Rollup merge of #162040 - weihanglo:bump-stage0, r=cuviper
jhpratt Sep 1, 2026
9f432a2
Rollup merge of #162063 - Mark-Simulacrum:aarch64-ec2, r=Kobzol
jhpratt Sep 1, 2026
f5bc06a
Rollup merge of #161937 - jackh726:polonius-cleanups-2, r=lqd
jhpratt Sep 1, 2026
df16ef7
Rollup merge of #162051 - nnethercote:rustc_feature-cleanups, r=Jonat…
jhpratt Sep 1, 2026
f7e3df1
Rollup merge of #162055 - mejrs:_style, r=JonathanBrouwer
jhpratt Sep 1, 2026
51260d4
Rollup merge of #162075 - mejrs:track_caller_closure_gating, r=Jonath…
jhpratt Sep 1, 2026
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 Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3634,6 +3634,7 @@ version = "0.0.0"
dependencies = [
"rustc_abi",
"rustc_ast",
"rustc_attr_ir",
"rustc_attr_parsing",
"rustc_data_structures",
"rustc_errors",
Expand Down Expand Up @@ -4068,6 +4069,7 @@ name = "rustc_feature"
version = "0.0.0"
dependencies = [
"rustc_data_structures",
"rustc_macros",
"rustc_span",
"serde",
"serde_json",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast_lowering/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ doctest = false
# tidy-alphabetical-start
rustc_abi = { path = "../rustc_abi" }
rustc_ast = { path = "../rustc_ast" }
rustc_attr_ir = { path = "../rustc_attr_ir" }
rustc_attr_parsing = { path = "../rustc_attr_parsing" }
rustc_data_structures = { path = "../rustc_data_structures" }
rustc_errors = { path = "../rustc_errors" }
Expand Down
42 changes: 12 additions & 30 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ use std::ops::ControlFlow;
use std::sync::Arc;

use rustc_ast::node_id::NodeMap;
use rustc_ast::visit::{Visitor, walk_expr};
use rustc_ast::*;
use rustc_attr_ir::lang_items::LangItem;
use rustc_attr_ir::target::Target;
use rustc_errors::msg;
use rustc_hir as hir;
use rustc_hir::attrs::lang_items::LangItem;
use rustc_hir::HirId;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::{HirId, Target, find_attr};
use rustc_middle::span_bug;
use rustc_middle::ty::TyCtxt;
use rustc_session::diagnostics::report_lit_error;
use rustc_span::{ByteSymbol, DUMMY_SP, DesugaringKind, Ident, Span, Spanned, Symbol, respan, sym};
use thin_vec::{ThinVec, thin_vec};
use visit::{Visitor, walk_expr};

mod closure;

use crate::diagnostics::{
Expand Down Expand Up @@ -882,35 +882,17 @@ impl<'hir> LoweringContext<'_, 'hir> {

/// Forwards a possible `#[track_caller]` annotation from `outer_hir_id` to
/// `inner_hir_id` in case the `async_fn_track_caller` feature is enabled.
pub(super) fn maybe_forward_track_caller(
&mut self,
span: Span,
outer_hir_id: HirId,
inner_hir_id: HirId,
) {
pub(super) fn maybe_forward_track_caller(&mut self, outer_hir_id: HirId, inner_hir_id: HirId) {
if self.tcx.features().async_fn_track_caller()
&& let Some(attrs) = self.attrs.get(&outer_hir_id.local_id)
&& find_attr!(*attrs, TrackCaller(_))
&& let Some(t) = attrs.iter().find(|a| {
matches!(
a,
rustc_attr_ir::Attribute::Parsed(rustc_attr_ir::AttributeKind::TrackCaller(_))
)
})
{
let unstable_span = self.mark_span_with_reason(
DesugaringKind::Async,
span,
Some(Arc::clone(&self.allow_gen_future)),
);
self.lower_attrs(
inner_hir_id,
&[Attribute {
kind: AttrKind::Normal(Box::new(NormalAttr::from_ident(Ident::new(
sym::track_caller,
span,
)))),
id: self.tcx.sess.psess.attr_id_generator.mk_attr_id(),
style: AttrStyle::Outer,
span: unstable_span,
}],
span,
Target::Fn,
);
self.attrs.insert(inner_hir_id.local_id, std::slice::from_ref(t));
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/expr/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
)
});

this.maybe_forward_track_caller(body.span, closure_hir_id, expr.hir_id);
this.maybe_forward_track_caller(closure_hir_id, expr.hir_id);

(parameters, expr)
});
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,7 @@ impl<'hir> LoweringContext<'_, 'hir> {

// FIXME(async_fn_track_caller): Can this be moved above?
let hir_id = expr.hir_id;
this.maybe_forward_track_caller(body.span, fn_id, hir_id);
this.maybe_forward_track_caller(fn_id, hir_id);

(parameters, expr)
})
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ fn parse_cfg_attr_internal<'a>(
}

fn try_gate_cfg(name: Symbol, span: Span, sess: &Session, features: Option<&Features>) {
let gate = find_gated_cfg(|sym| sym == name);
let gate = find_gated_cfg(name);
if let (Some(feats), Some(gated_cfg)) = (features, gate) {
gate_cfg(gated_cfg, span, sess, feats);
}
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@ impl NoArgsAttributeParser for TrackCallerParser {
});
}
}
Target::Closure if !cx.features().closure_track_caller() => {
feature_err(
cx.sess(),
sym::closure_track_caller,
attr_span,
"`#[track_caller]` on closures is currently unstable",
)
.emit();
}
_ => {}
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn check_keyword(cx: &mut AcceptContext<'_, '_>, keyword: Symbol, span: Span) ->

fn check_attribute(cx: &mut AcceptContext<'_, '_>, attribute: Symbol, span: Span) -> bool {
// FIXME: This should support attributes with namespace like `diagnostic::do_not_recommend`.
if rustc_feature::BUILTIN_ATTRIBUTE_MAP.contains(&attribute) {
if rustc_feature::BUILTIN_ATTRIBUTE_SET.contains(&attribute) {
return true;
}
cx.emit_err(DocAttributeNotAttribute { span, attribute });
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_attr_ir::target::Target;
use rustc_attr_ir::{AttrArgs, AttrItem, AttrPath, Attribute, AttributeKind, HashIgnoredAttrId};
use rustc_data_structures::sync::{DynSend, DynSync};
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level, MultiSpan};
use rustc_feature::{BUILTIN_ATTRIBUTE_MAP, Features};
use rustc_feature::{BUILTIN_ATTRIBUTE_SET, Features};
use rustc_lint_defs::{LintId, RegisteredTools};
use rustc_session::Session;
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
Expand Down Expand Up @@ -376,7 +376,7 @@ impl<'sess> AttributeParser<'sess> {
);
self.check_attribute_stability(&attr_path, attr_span, accept.stability);
if let [part] = parts.as_slice() {
debug_assert!(BUILTIN_ATTRIBUTE_MAP.contains(part));
debug_assert!(BUILTIN_ATTRIBUTE_SET.contains(part));
}

let Some(args) = ArgParser::from_attr_args(
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/validate_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_ast::{
};
use rustc_attr_ir::AttrPath;
use rustc_errors::{Applicability, Diagnostic, PResult};
use rustc_feature::BUILTIN_ATTRIBUTE_MAP;
use rustc_feature::BUILTIN_ATTRIBUTE_SET;
use rustc_lint_defs::builtin::ILL_FORMED_ATTRIBUTE_INPUT;
use rustc_parse::parse_in;
use rustc_session::diagnostics::report_lit_error;
Expand All @@ -27,7 +27,7 @@ pub fn check_attr(psess: &ParseSess, attr: &Attribute) {
AttrKind::Synthetic(CfgTrace(_) | CfgAttrTrace(_)) | AttrKind::DocComment(..) => return,
}

let builtin_attr_info = attr.name().and_then(|name| BUILTIN_ATTRIBUTE_MAP.get(&name));
let builtin_attr_info = attr.name().and_then(|name| BUILTIN_ATTRIBUTE_SET.get(&name));

// Check input tokens for built-in and key-value attributes.
if let Some(name) = builtin_attr_info {
Expand Down
23 changes: 15 additions & 8 deletions compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub(crate) fn compute_regions<'tcx>(
let polonius_output = root_cx.consumer.as_ref().map_or(false, |c| c.polonius_output())
|| infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled();

let lowered_constraints = compute_sccs_applying_placeholder_outlives_constraints(
let mut lowered_constraints = compute_sccs_applying_placeholder_outlives_constraints(
constraints,
&universal_region_relations,
infcx,
Expand All @@ -144,20 +144,27 @@ pub(crate) fn compute_regions<'tcx>(
&lowered_constraints,
);

// If requested for `-Zpolonius=next`, compute loan liveness information.
// This is done prior to `RegionInferenceContext::new`, because we may add
// additional liveness constraints.
if let Some(polonius_context) = polonius_context.as_mut() {
let _timer = infcx.tcx.prof.generic_activity("borrowck_polonius_loan_liveness");
polonius_context.compute_loan_liveness(
&mut lowered_constraints.liveness_constraints,
lowered_constraints.outlives_constraints.outlives().iter().copied(),
&universal_region_relations.universal_regions,
body,
borrow_set,
);
}

let mut regioncx = RegionInferenceContext::new(
infcx,
lowered_constraints,
universal_region_relations,
location_map,
);

// If requested for `-Zpolonius=next`, convert NLL constraints to localized outlives constraints
// and use them to compute loan liveness.
if let Some(polonius_context) = polonius_context.as_mut() {
let _timer = infcx.tcx.prof.generic_activity("borrowck_polonius_loan_liveness");
polonius_context.compute_loan_liveness(&mut regioncx, body, borrow_set)
}

// If requested: dump NLL facts, and run legacy polonius analysis.
let polonius_output = polonius_facts.as_ref().and_then(|polonius_facts| {
if infcx.tcx.sess.opts.unstable_opts.nll_facts {
Expand Down
32 changes: 15 additions & 17 deletions compiler/rustc_borrowck/src/polonius/liveness_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,23 @@ use rustc_middle::ty::relate::{
};
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeVisitable};

use super::{ConstraintDirection, PoloniusContext};
use super::ConstraintDirection;
use crate::universal_regions::UniversalRegions;

impl PoloniusContext {
/// Record the variance of each region contained within the given value.
pub(crate) fn record_live_region_variance<'tcx>(
&mut self,
tcx: TyCtxt<'tcx>,
universal_regions: &UniversalRegions<'tcx>,
value: impl TypeVisitable<TyCtxt<'tcx>> + Relate<TyCtxt<'tcx>>,
) {
let mut extractor = VarianceExtractor {
tcx,
ambient_variance: ty::Variance::Covariant,
directions: &mut self.live_region_variances,
universal_regions,
};
extractor.relate(value, value).expect("Can't have a type error relating to itself");
}
/// Record the variance of each region contained within the given value.
pub(crate) fn record_live_region_variance<'tcx>(
tcx: TyCtxt<'tcx>,
live_region_variances: &mut BTreeMap<RegionVid, ConstraintDirection>,
universal_regions: &UniversalRegions<'tcx>,
value: impl TypeVisitable<TyCtxt<'tcx>> + Relate<TyCtxt<'tcx>>,
) {
let mut extractor = VarianceExtractor {
tcx,
ambient_variance: ty::Variance::Covariant,
directions: live_region_variances,
universal_regions,
};
extractor.relate(value, value).expect("Can't have a type error relating to itself");
}

/// Extracts variances for regions contained within types. Follows the same structure as
Expand Down
21 changes: 12 additions & 9 deletions compiler/rustc_borrowck/src/polonius/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ use rustc_mir_dataflow::points::PointIndex;

pub(self) use self::constraints::*;
pub(crate) use self::dump::dump_polonius_mir;
pub(crate) use self::liveness_constraints::record_live_region_variance;
use crate::BorrowSet;
use crate::constraints::OutlivesConstraint;
use crate::dataflow::BorrowIndex;
use crate::region_infer::values::LivenessValues;
use crate::{BorrowSet, RegionInferenceContext};
use crate::universal_regions::UniversalRegions;

pub(crate) type LiveLoans = SparseBitMatrix<PointIndex, BorrowIndex>;

Expand All @@ -65,7 +68,7 @@ pub(crate) struct PoloniusContext {

/// The expected edge direction per live region: the kind of directed edge we'll create as
/// liveness constraints depends on the variance of types with respect to each contained region.
live_region_variances: BTreeMap<RegionVid, ConstraintDirection>,
pub(crate) live_region_variances: BTreeMap<RegionVid, ConstraintDirection>,

/// The regions that outlive free regions are used to distinguish relevant live locals from
/// boring locals. A boring local is one whose type contains only such regions. Polonius
Expand All @@ -77,7 +80,7 @@ pub(crate) struct PoloniusContext {
/// The direction a constraint can flow into. Used to create liveness constraints according to
/// variance.
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
enum ConstraintDirection {
pub(crate) enum ConstraintDirection {
/// For covariant cases, we add a forward edge `O at P1 -> O at P2`.
Forward,

Expand All @@ -101,31 +104,31 @@ impl PoloniusContext {
/// The constraint data will be used to compute errors and diagnostics.
pub(crate) fn compute_loan_liveness<'tcx>(
&mut self,
regioncx: &mut RegionInferenceContext<'tcx>,
liveness: &mut LivenessValues,
outlives_constraints: impl Iterator<Item = OutlivesConstraint<'tcx>>,
universal_regions: &UniversalRegions<'tcx>,
body: &Body<'tcx>,
borrow_set: &BorrowSet<'tcx>,
) {
let liveness = regioncx.liveness_constraints();

// We don't need to prepare the graph (index NLL constraints, etc.) if we have no loans to
// trace throughout localized constraints.
if borrow_set.len() > 0 {
// From the outlives constraints, liveness, and variances, we can compute reachability
// on the lazy localized constraint graph to trace the liveness of loans, for the next
// step in the chain (the NLL loan scope and active loans computations).
let graph = LocalizedConstraintGraph::new(liveness, regioncx.outlives_constraints());
let graph = LocalizedConstraintGraph::new(liveness, outlives_constraints);

let mut live_loans = LiveLoans::new(borrow_set.len());
let mut visitor = LoanLivenessVisitor { liveness, live_loans: &mut live_loans };
graph.traverse(
body,
liveness,
&self.live_region_variances,
regioncx.universal_regions(),
universal_regions,
borrow_set,
&mut visitor,
);
regioncx.record_live_loans(live_loans);
liveness.record_live_loans(live_loans);

// The graph can be traversed again during MIR dumping, so we store it here.
self.graph = Some(graph);
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use crate::constraints::{ConstraintSccIndex, OutlivesConstraint, OutlivesConstra
use crate::dataflow::BorrowIndex;
use crate::diagnostics::{RegionErrorKind, RegionErrors, UniverseInfo};
use crate::handle_placeholders::{LoweredConstraints, RegionTracker};
use crate::polonius::LiveLoans;
use crate::polonius::legacy::PoloniusOutput;
use crate::region_infer::values::{LivenessValues, RegionElement, RegionValues};
use crate::type_check::Locations;
Expand Down Expand Up @@ -1874,12 +1873,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
&self.liveness_constraints
}

/// When using `-Zpolonius=next`, records the given live loans for the loan scopes and active
/// loans dataflow computations.
pub(crate) fn record_live_loans(&mut self, live_loans: LiveLoans) {
self.liveness_constraints.record_live_loans(live_loans);
}

/// Returns whether the `loan_idx` is live at the given `location`: whether its issuing
/// region is contained within the type of a variable that is live at this point.
/// Note: for now, the sets of live loans is only available when using `-Zpolonius=next`.
Expand Down
11 changes: 8 additions & 3 deletions compiler/rustc_borrowck/src/type_check/liveness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use tracing::debug;

use super::TypeChecker;
use crate::constraints::OutlivesConstraintSet;
use crate::polonius::PoloniusContext;
use crate::polonius::{PoloniusContext, record_live_region_variance};
use crate::region_infer::values::LivenessValues;
use crate::universal_regions::UniversalRegions;

Expand Down Expand Up @@ -67,7 +67,7 @@ pub(super) fn generate<'tcx>(
let (relevant_live_locals, boring_locals) =
compute_relevant_live_locals(typeck.tcx(), &free_regions, typeck.body);

trace::trace(typeck, location_map, move_data, relevant_live_locals, boring_locals);
trace::trace(typeck, location_map, move_data, &relevant_live_locals, &boring_locals);

// Mark regions that should be live where they appear within rvalues or within a call: like
// args, regions, and types.
Expand Down Expand Up @@ -220,7 +220,12 @@ impl<'a, 'tcx> LiveVariablesVisitor<'a, 'tcx> {

// When using `-Zpolonius=next`, we record the variance of each live region.
if let Some(polonius_context) = self.polonius_context {
polonius_context.record_live_region_variance(self.tcx, self.universal_regions, value);
record_live_region_variance(
self.tcx,
&mut polonius_context.live_region_variances,
self.universal_regions,
value,
);
}
}
}
Loading
Loading