Skip to content

Commit d313405

Browse files
authored
Merge pull request #4308 from rust-lang/rustup-2025-05-03
Automatic Rustup
2 parents 0238548 + 4d87349 commit d313405

File tree

342 files changed

+5330
-1760
lines changed

Some content is hidden

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

342 files changed

+5330
-1760
lines changed

compiler/rustc_ast/src/ast.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,9 @@ pub enum ExprKind {
16331633
/// An `if` block, with an optional `else` block.
16341634
///
16351635
/// `if expr { block } else { expr }`
1636+
///
1637+
/// If present, the "else" expr is always `ExprKind::Block` (for `else`) or
1638+
/// `ExprKind::If` (for `else if`).
16361639
If(P<Expr>, P<Block>, Option<P<Expr>>),
16371640
/// A while loop, with an optional label.
16381641
///

compiler/rustc_ast_lowering/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle, StashKey};
5555
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
5656
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId};
5757
use rustc_hir::{
58-
self as hir, ConstArg, GenericArg, HirId, ItemLocalMap, LangItem, LifetimeSource,
59-
LifetimeSyntax, ParamName, TraitCandidate,
58+
self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LangItem,
59+
LifetimeSource, LifetimeSyntax, ParamName, TraitCandidate,
6060
};
6161
use rustc_index::{Idx, IndexSlice, IndexVec};
6262
use rustc_macros::extension;
@@ -1087,7 +1087,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10871087
match arg {
10881088
ast::GenericArg::Lifetime(lt) => GenericArg::Lifetime(self.lower_lifetime(
10891089
lt,
1090-
LifetimeSource::Path { with_angle_brackets: true },
1090+
LifetimeSource::Path { angle_brackets: hir::AngleBrackets::Full },
10911091
lt.ident.into(),
10921092
)),
10931093
ast::GenericArg::Type(ty) => {
@@ -1779,13 +1779,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
17791779
&mut self,
17801780
id: NodeId,
17811781
span: Span,
1782-
with_angle_brackets: bool,
1782+
angle_brackets: AngleBrackets,
17831783
) -> &'hir hir::Lifetime {
17841784
self.new_named_lifetime(
17851785
id,
17861786
id,
17871787
Ident::new(kw::UnderscoreLifetime, span),
1788-
LifetimeSource::Path { with_angle_brackets },
1788+
LifetimeSource::Path { angle_brackets },
17891789
LifetimeSyntax::Hidden,
17901790
)
17911791
}

compiler/rustc_ast_lowering/src/path.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -432,27 +432,31 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
432432

433433
// Note: these spans are used for diagnostics when they can't be inferred.
434434
// See rustc_resolve::late::lifetimes::LifetimeContext::add_missing_lifetime_specifiers_label
435-
let (elided_lifetime_span, with_angle_brackets) = if generic_args.span.is_empty() {
436-
// If there are no brackets, use the identifier span.
435+
let (elided_lifetime_span, angle_brackets) = if generic_args.span.is_empty() {
436+
// No brackets, e.g. `Path`: use an empty span just past the end of the identifier.
437437
// HACK: we use find_ancestor_inside to properly suggest elided spans in paths
438438
// originating from macros, since the segment's span might be from a macro arg.
439-
(segment_ident_span.find_ancestor_inside(path_span).unwrap_or(path_span), false)
440-
} else if generic_args.is_empty() {
441-
// If there are brackets, but not generic arguments, then use the opening bracket
442-
(generic_args.span.with_hi(generic_args.span.lo() + BytePos(1)), true)
439+
(
440+
segment_ident_span.find_ancestor_inside(path_span).unwrap_or(path_span),
441+
hir::AngleBrackets::Missing,
442+
)
443443
} else {
444-
// Else use an empty span right after the opening bracket.
445-
(generic_args.span.with_lo(generic_args.span.lo() + BytePos(1)).shrink_to_lo(), true)
444+
// Brackets, e.g. `Path<>` or `Path<T>`: use an empty span just after the `<`.
445+
(
446+
generic_args.span.with_lo(generic_args.span.lo() + BytePos(1)).shrink_to_lo(),
447+
if generic_args.is_empty() {
448+
hir::AngleBrackets::Empty
449+
} else {
450+
hir::AngleBrackets::Full
451+
},
452+
)
446453
};
447454

448455
generic_args.args.insert_many(
449456
0,
450457
(start..end).map(|id| {
451-
let l = self.lower_lifetime_hidden_in_path(
452-
id,
453-
elided_lifetime_span,
454-
with_angle_brackets,
455-
);
458+
let l =
459+
self.lower_lifetime_hidden_in_path(id, elided_lifetime_span, angle_brackets);
456460
GenericArg::Lifetime(l)
457461
}),
458462
);

compiler/rustc_ast_pretty/src/pprust/state.rs

+19
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ pub fn print_crate<'a>(
240240
let mut s =
241241
State { s: pp::Printer::new(), comments: Some(Comments::new(sm, filename, input)), ann };
242242

243+
// We need to print shebang before anything else
244+
// otherwise the resulting code will not compile
245+
// and shebang will be useless.
246+
s.maybe_print_shebang();
247+
243248
if is_expanded && !krate.attrs.iter().any(|attr| attr.has_name(sym::no_core)) {
244249
// We need to print `#![no_std]` (and its feature gate) so that
245250
// compiling pretty-printed source won't inject libstd again.
@@ -560,6 +565,20 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
560565
self.word(st)
561566
}
562567

568+
fn maybe_print_shebang(&mut self) {
569+
if let Some(cmnt) = self.peek_comment() {
570+
// Comment is a shebang if it's:
571+
// Isolated, starts with #! and doesn't continue with `[`
572+
// See [rustc_lexer::strip_shebang] and [gather_comments] from pprust/state.rs for details
573+
if cmnt.style == CommentStyle::Isolated
574+
&& cmnt.lines.first().map_or(false, |l| l.starts_with("#!"))
575+
{
576+
let cmnt = self.next_comment().unwrap();
577+
self.print_comment(cmnt);
578+
}
579+
}
580+
}
581+
563582
fn print_inner_attributes(&mut self, attrs: &[ast::Attribute]) -> bool {
564583
self.print_either_attributes(attrs, ast::AttrStyle::Inner, false, true)
565584
}

compiler/rustc_borrowck/src/constraints/mod.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::ty::{RegionVid, TyCtxt, VarianceDiagInfo};
77
use rustc_span::Span;
88
use tracing::{debug, instrument};
99

10-
use crate::region_infer::{ConstraintSccs, RegionDefinition, RegionTracker};
10+
use crate::region_infer::{AnnotatedSccs, ConstraintSccs, RegionDefinition, SccAnnotations};
1111
use crate::type_check::Locations;
1212
use crate::universal_regions::UniversalRegions;
1313

@@ -61,12 +61,14 @@ impl<'tcx> OutlivesConstraintSet<'tcx> {
6161
&self,
6262
static_region: RegionVid,
6363
definitions: &IndexVec<RegionVid, RegionDefinition<'tcx>>,
64-
) -> ConstraintSccs {
64+
) -> AnnotatedSccs {
6565
let constraint_graph = self.graph(definitions.len());
6666
let region_graph = &constraint_graph.region_graph(self, static_region);
67-
ConstraintSccs::new_with_annotation(&region_graph, |r| {
68-
RegionTracker::new(r, &definitions[r])
69-
})
67+
let mut annotation_visitor = SccAnnotations::new(definitions);
68+
(
69+
ConstraintSccs::new_with_annotation(&region_graph, &mut annotation_visitor),
70+
annotation_visitor.scc_to_annotation,
71+
)
7072
}
7173

7274
/// This method handles Universe errors by rewriting the constraint
@@ -79,12 +81,12 @@ impl<'tcx> OutlivesConstraintSet<'tcx> {
7981
/// eventually go away.
8082
///
8183
/// For a more precise definition, see the documentation for
82-
/// [`RegionTracker::has_incompatible_universes()`].
84+
/// [`crate::region_infer::RegionTracker`].
8385
///
8486
/// This edge case used to be handled during constraint propagation
8587
/// by iterating over the strongly connected components in the constraint
8688
/// graph while maintaining a set of bookkeeping mappings similar
87-
/// to what is stored in `RegionTracker` and manually adding 'sttaic as
89+
/// to what is stored in `RegionTracker` and manually adding 'static as
8890
/// needed.
8991
///
9092
/// It was rewritten as part of the Polonius project with the goal of moving
@@ -108,9 +110,9 @@ impl<'tcx> OutlivesConstraintSet<'tcx> {
108110
&mut self,
109111
universal_regions: &UniversalRegions<'tcx>,
110112
definitions: &IndexVec<RegionVid, RegionDefinition<'tcx>>,
111-
) -> ConstraintSccs {
113+
) -> AnnotatedSccs {
112114
let fr_static = universal_regions.fr_static;
113-
let sccs = self.compute_sccs(fr_static, definitions);
115+
let (sccs, annotations) = self.compute_sccs(fr_static, definitions);
114116

115117
// Changed to `true` if we added any constraints to `self` and need to
116118
// recompute SCCs.
@@ -124,7 +126,7 @@ impl<'tcx> OutlivesConstraintSet<'tcx> {
124126
continue;
125127
}
126128

127-
let annotation = sccs.annotation(scc);
129+
let annotation = annotations[scc];
128130

129131
// If this SCC participates in a universe violation,
130132
// e.g. if it reaches a region with a universe smaller than
@@ -154,7 +156,7 @@ impl<'tcx> OutlivesConstraintSet<'tcx> {
154156
self.compute_sccs(fr_static, definitions)
155157
} else {
156158
// If we didn't add any back-edges; no more work needs doing
157-
sccs
159+
(sccs, annotations)
158160
}
159161
}
160162
}

compiler/rustc_borrowck/src/region_infer/mod.rs

+40-10
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ mod reverse_sccs;
4747

4848
pub(crate) mod values;
4949

50-
pub(crate) type ConstraintSccs = Sccs<RegionVid, ConstraintSccIndex, RegionTracker>;
50+
pub(crate) type ConstraintSccs = Sccs<RegionVid, ConstraintSccIndex>;
51+
pub(crate) type AnnotatedSccs = (ConstraintSccs, IndexVec<ConstraintSccIndex, RegionTracker>);
5152

5253
/// An annotation for region graph SCCs that tracks
53-
/// the values of its elements.
54+
/// the values of its elements. This annotates a single SCC.
5455
#[derive(Copy, Debug, Clone)]
55-
pub struct RegionTracker {
56+
pub(crate) struct RegionTracker {
5657
/// The largest universe of a placeholder reached from this SCC.
5758
/// This includes placeholders within this SCC.
5859
max_placeholder_universe_reached: UniverseIndex,
@@ -97,6 +98,32 @@ impl scc::Annotation for RegionTracker {
9798
}
9899
}
99100

101+
/// A Visitor for SCC annotation construction.
102+
pub(crate) struct SccAnnotations<'d, 'tcx, A: scc::Annotation> {
103+
pub(crate) scc_to_annotation: IndexVec<ConstraintSccIndex, A>,
104+
definitions: &'d IndexVec<RegionVid, RegionDefinition<'tcx>>,
105+
}
106+
107+
impl<'d, 'tcx, A: scc::Annotation> SccAnnotations<'d, 'tcx, A> {
108+
pub(crate) fn new(definitions: &'d IndexVec<RegionVid, RegionDefinition<'tcx>>) -> Self {
109+
Self { scc_to_annotation: IndexVec::new(), definitions }
110+
}
111+
}
112+
113+
impl scc::Annotations<RegionVid> for SccAnnotations<'_, '_, RegionTracker> {
114+
fn new(&self, element: RegionVid) -> RegionTracker {
115+
RegionTracker::new(element, &self.definitions[element])
116+
}
117+
118+
fn annotate_scc(&mut self, scc: ConstraintSccIndex, annotation: RegionTracker) {
119+
let idx = self.scc_to_annotation.push(annotation);
120+
assert!(idx == scc);
121+
}
122+
123+
type Ann = RegionTracker;
124+
type SccIdx = ConstraintSccIndex;
125+
}
126+
100127
impl RegionTracker {
101128
pub(crate) fn new(rvid: RegionVid, definition: &RegionDefinition<'_>) -> Self {
102129
let (representative_is_placeholder, representative_is_existential) = match definition.origin
@@ -166,6 +193,8 @@ pub struct RegionInferenceContext<'tcx> {
166193
/// compute the values of each region.
167194
constraint_sccs: ConstraintSccs,
168195

196+
scc_annotations: IndexVec<ConstraintSccIndex, RegionTracker>,
197+
169198
/// Reverse of the SCC constraint graph -- i.e., an edge `A -> B` exists if
170199
/// `B: A`. This is used to compute the universal regions that are required
171200
/// to outlive a given SCC. Computed lazily.
@@ -446,7 +475,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
446475

447476
let definitions = create_definitions(infcx, &universal_regions);
448477

449-
let constraint_sccs =
478+
let (constraint_sccs, scc_annotations) =
450479
outlives_constraints.add_outlives_static(&universal_regions, &definitions);
451480
let constraints = Frozen::freeze(outlives_constraints);
452481
let constraint_graph = Frozen::freeze(constraints.graph(definitions.len()));
@@ -472,6 +501,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
472501
constraints,
473502
constraint_graph,
474503
constraint_sccs,
504+
scc_annotations,
475505
rev_scc_graph: None,
476506
member_constraints,
477507
member_constraints_applied: Vec::new(),
@@ -798,7 +828,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
798828

799829
// If the member region lives in a higher universe, we currently choose
800830
// the most conservative option by leaving it unchanged.
801-
if !self.constraint_sccs().annotation(scc).min_universe().is_root() {
831+
if !self.scc_universe(scc).is_root() {
802832
return;
803833
}
804834

@@ -874,8 +904,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
874904
/// in `scc_a`. Used during constraint propagation, and only once
875905
/// the value of `scc_b` has been computed.
876906
fn universe_compatible(&self, scc_b: ConstraintSccIndex, scc_a: ConstraintSccIndex) -> bool {
877-
let a_annotation = self.constraint_sccs().annotation(scc_a);
878-
let b_annotation = self.constraint_sccs().annotation(scc_b);
907+
let a_annotation = self.scc_annotations[scc_a];
908+
let b_annotation = self.scc_annotations[scc_b];
879909
let a_universe = a_annotation.min_universe();
880910

881911
// If scc_b's declared universe is a subset of
@@ -991,7 +1021,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
9911021
"lower_bound = {:?} r_scc={:?} universe={:?}",
9921022
lower_bound,
9931023
r_scc,
994-
self.constraint_sccs.annotation(r_scc).min_universe()
1024+
self.scc_universe(r_scc)
9951025
);
9961026
// If the type test requires that `T: 'a` where `'a` is a
9971027
// placeholder from another universe, that effectively requires
@@ -1472,7 +1502,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
14721502
/// The minimum universe of any variable reachable from this
14731503
/// SCC, inside or outside of it.
14741504
fn scc_universe(&self, scc: ConstraintSccIndex) -> UniverseIndex {
1475-
self.constraint_sccs().annotation(scc).min_universe()
1505+
self.scc_annotations[scc].min_universe()
14761506
}
14771507

14781508
/// Checks the final value for the free region `fr` to see if it
@@ -2216,7 +2246,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22162246
/// they *must* be equal (though not having the same repr does not
22172247
/// mean they are unequal).
22182248
fn scc_representative(&self, scc: ConstraintSccIndex) -> RegionVid {
2219-
self.constraint_sccs.annotation(scc).representative
2249+
self.scc_annotations[scc].representative
22202250
}
22212251

22222252
pub(crate) fn liveness_constraints(&self) -> &LivenessValues {

compiler/rustc_codegen_llvm/src/llvm_util.rs

+6
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,12 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
273273
("aarch64", "fpmr") => None, // only existed in 18
274274
("arm", "fp16") => Some(LLVMFeature::new("fullfp16")),
275275
// Filter out features that are not supported by the current LLVM version
276+
("loongarch64", "div32" | "lam-bh" | "lamcas" | "ld-seq-sa" | "scq")
277+
if get_version().0 < 20 =>
278+
{
279+
None
280+
}
281+
// Filter out features that are not supported by the current LLVM version
276282
("riscv32" | "riscv64", "zacas") if get_version().0 < 20 => None,
277283
// Enable the evex512 target feature if an avx512 target feature is enabled.
278284
("x86", s) if s.starts_with("avx512") => {

0 commit comments

Comments
 (0)