Skip to content

Commit c639c67

Browse files
committed
Auto merge of rust-lang#140501 - Zalathar:rollup-86sqqur, r=Zalathar
Rollup of 14 pull requests Successful merges: - rust-lang#140380 (transmutability: uninit transition matches unit byte only) - rust-lang#140385 (Subtree update of `rust-analyzer`) - rust-lang#140395 (organize and extend forbidden target feature tests) - rust-lang#140430 (Improve test coverage of HIR pretty printing.) - rust-lang#140458 (Fix for async drop ice with partly dropped tuple) - rust-lang#140460 (Fix handling of LoongArch target features not supported by LLVM 19) - rust-lang#140465 (chore: edit and move tests) - rust-lang#140467 (Don't FCW assoc consts in patterns) - rust-lang#140468 (Minor tweaks to make some normalization (adjacent) code less confusing) - rust-lang#140470 (CI: rfl: move job forward to Linux v6.15-rc4) - rust-lang#140476 (chore: delete unused ui/auxiliary crates) - rust-lang#140481 (Require sanitizers be enabled for asan_odr_windows.rs) - rust-lang#140486 (rustfmt: Also allow bool literals as first item of let chain) - rust-lang#140494 (Parser: Document restrictions) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d2eadb7 + fbd8cc1 commit c639c67

File tree

934 files changed

+34632
-40107
lines changed

Some content is hidden

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

934 files changed

+34632
-40107
lines changed

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") => {

compiler/rustc_hir_typeck/src/writeback.rs

+15-21
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
// Type resolution: the phase that finds all the types in the AST with
2-
// unresolved type variables and replaces "ty_var" types with their
3-
// generic parameters.
1+
//! During type inference, partially inferred terms are
2+
//! represented using inference variables (ty::Infer). These don't appear in
3+
//! the final [`ty::TypeckResults`] since all of the types should have been
4+
//! inferred once typeck is done.
5+
//!
6+
//! When type inference is running however, having to update the typeck results
7+
//! every time a new type is inferred would be unreasonably slow, so instead all
8+
//! of the replacement happens at the end in [`FnCtxt::resolve_type_vars_in_body`],
9+
//! which creates a new `TypeckResults` which doesn't contain any inference variables.
410
511
use std::mem;
612

@@ -27,15 +33,6 @@ use crate::FnCtxt;
2733
///////////////////////////////////////////////////////////////////////////
2834
// Entry point
2935

30-
// During type inference, partially inferred types are
31-
// represented using Type variables (ty::Infer). These don't appear in
32-
// the final TypeckResults since all of the types should have been
33-
// inferred once typeck is done.
34-
// When type inference is running however, having to update the typeck
35-
// typeck results every time a new type is inferred would be unreasonably slow,
36-
// so instead all of the replacement happens at the end in
37-
// resolve_type_vars_in_body, which creates a new TypeTables which
38-
// doesn't contain any inference types.
3936
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4037
pub(crate) fn resolve_type_vars_in_body(
4138
&self,
@@ -90,14 +87,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
9087
}
9188
}
9289

93-
///////////////////////////////////////////////////////////////////////////
94-
// The Writeback context. This visitor walks the HIR, checking the
95-
// fn-specific typeck results to find references to types or regions. It
96-
// resolves those regions to remove inference variables and writes the
97-
// final result back into the master typeck results in the tcx. Here and
98-
// there, it applies a few ad-hoc checks that were not convenient to
99-
// do elsewhere.
100-
90+
/// The Writeback context. This visitor walks the HIR, checking the
91+
/// fn-specific typeck results to find inference variables. It resolves
92+
/// those inference variables and writes the final result into the
93+
/// `TypeckResults`. It also applies a few ad-hoc checks that were not
94+
/// convenient to do elsewhere.
10195
struct WritebackCx<'cx, 'tcx> {
10296
fcx: &'cx FnCtxt<'cx, 'tcx>,
10397

@@ -897,7 +891,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
897891
let cause = ObligationCause::misc(self.span.to_span(tcx), body_id);
898892
let at = self.fcx.at(&cause, self.fcx.param_env);
899893
let universes = vec![None; outer_exclusive_binder(value).as_usize()];
900-
match solve::deeply_normalize_with_skipped_universes_and_ambiguous_goals(
894+
match solve::deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals(
901895
at, value, universes,
902896
) {
903897
Ok((value, goals)) => {

compiler/rustc_middle/src/mir/interpret/queries.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,16 @@ impl<'tcx> TyCtxt<'tcx> {
115115
// @lcnr believes that successfully evaluating even though there are
116116
// used generic parameters is a bug of evaluation, so checking for it
117117
// here does feel somewhat sensible.
118-
if !self.features().generic_const_exprs() && ct.args.has_non_region_param() {
119-
let def_kind = self.def_kind(instance.def_id());
120-
assert!(
121-
matches!(
122-
def_kind,
123-
DefKind::InlineConst | DefKind::AnonConst | DefKind::AssocConst
124-
),
125-
"{cid:?} is {def_kind:?}",
126-
);
118+
if !self.features().generic_const_exprs()
119+
&& ct.args.has_non_region_param()
120+
// We only FCW for anon consts as repeat expr counts with anon consts are the only place
121+
// that we have a back compat hack for. We don't need to check this is a const argument
122+
// as only anon consts as const args should get evaluated "for the type system".
123+
//
124+
// If we don't *only* FCW anon consts we can wind up incorrectly FCW'ing uses of assoc
125+
// consts in pattern positions. #140447
126+
&& self.def_kind(instance.def_id()) == DefKind::AnonConst
127+
{
127128
let mir_body = self.mir_for_ctfe(instance.def_id());
128129
if mir_body.is_polymorphic {
129130
let Some(local_def_id) = ct.def.as_local() else { return };

compiler/rustc_mir_transform/src/elaborate_drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ where
376376
if self.tcx().features().async_drop()
377377
&& self.elaborator.body().coroutine.is_some()
378378
&& self.elaborator.allow_async_drops()
379-
&& !self.elaborator.body()[bb].is_cleanup
379+
&& !self.elaborator.patch_ref().block(self.elaborator.body(), bb).is_cleanup
380380
&& drop_ty.needs_async_drop(self.tcx(), self.elaborator.typing_env())
381381
{
382382
self.build_async_drop(

compiler/rustc_mir_transform/src/patch.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,20 @@ impl<'tcx> MirPatch<'tcx> {
148148
self.term_patch_map[bb].is_some()
149149
}
150150

151+
/// Universal getter for block data, either it is in 'old' blocks or in patched ones
152+
pub(crate) fn block<'a>(
153+
&'a self,
154+
body: &'a Body<'tcx>,
155+
bb: BasicBlock,
156+
) -> &'a BasicBlockData<'tcx> {
157+
match bb.index().checked_sub(body.basic_blocks.len()) {
158+
Some(new) => &self.new_blocks[new],
159+
None => &body[bb],
160+
}
161+
}
162+
151163
pub(crate) fn terminator_loc(&self, body: &Body<'tcx>, bb: BasicBlock) -> Location {
152-
let offset = match bb.index().checked_sub(body.basic_blocks.len()) {
153-
Some(index) => self.new_blocks[index].statements.len(),
154-
None => body[bb].statements.len(),
155-
};
164+
let offset = self.block(body, bb).statements.len();
156165
Location { block: bb, statement_index: offset }
157166
}
158167

@@ -284,10 +293,7 @@ impl<'tcx> MirPatch<'tcx> {
284293
}
285294

286295
pub(crate) fn source_info_for_location(&self, body: &Body<'tcx>, loc: Location) -> SourceInfo {
287-
let data = match loc.block.index().checked_sub(body.basic_blocks.len()) {
288-
Some(new) => &self.new_blocks[new],
289-
None => &body[loc.block],
290-
};
296+
let data = self.block(body, loc.block);
291297
Self::source_info_for_index(data, loc)
292298
}
293299
}

compiler/rustc_parse/src/parser/mod.rs

+49
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,62 @@ mod mut_visit {
6262
}
6363

6464
bitflags::bitflags! {
65+
/// Restrictions applied while parsing.
66+
///
67+
/// The parser maintains a bitset of restrictions it will honor while
68+
/// parsing. This is essentially used as a way of tracking state of what
69+
/// is being parsed and to change behavior based on that.
6570
#[derive(Clone, Copy, Debug)]
6671
struct Restrictions: u8 {
72+
/// Restricts expressions for use in statement position.
73+
///
74+
/// When expressions are used in various places, like statements or
75+
/// match arms, this is used to stop parsing once certain tokens are
76+
/// reached.
77+
///
78+
/// For example, `if true {} & 1` with `STMT_EXPR` in effect is parsed
79+
/// as two separate expression statements (`if` and a reference to 1).
80+
/// Otherwise it is parsed as a bitwise AND where `if` is on the left
81+
/// and 1 is on the right.
6782
const STMT_EXPR = 1 << 0;
83+
/// Do not allow struct literals.
84+
///
85+
/// There are several places in the grammar where we don't want to
86+
/// allow struct literals because they can require lookahead, or
87+
/// otherwise could be ambiguous or cause confusion. For example,
88+
/// `if Foo {} {}` isn't clear if it is `Foo{}` struct literal, or
89+
/// just `Foo` is the condition, followed by a consequent block,
90+
/// followed by an empty block.
91+
///
92+
/// See [RFC 92](https://rust-lang.github.io/rfcs/0092-struct-grammar.html).
6893
const NO_STRUCT_LITERAL = 1 << 1;
94+
/// Used to provide better error messages for const generic arguments.
95+
///
96+
/// An un-braced const generic argument is limited to a very small
97+
/// subset of expressions. This is used to detect the situation where
98+
/// an expression outside of that subset is used, and to suggest to
99+
/// wrap the expression in braces.
69100
const CONST_EXPR = 1 << 2;
101+
/// Allows `let` expressions.
102+
///
103+
/// `let pattern = scrutinee` is parsed as an expression, but it is
104+
/// only allowed in let chains (`if` and `while` conditions).
105+
/// Otherwise it is not an expression (note that `let` in statement
106+
/// positions is treated as a `StmtKind::Let` statement, which has a
107+
/// slightly different grammar).
70108
const ALLOW_LET = 1 << 3;
109+
/// Used to detect a missing `=>` in a match guard.
110+
///
111+
/// This is used for error handling in a match guard to give a better
112+
/// error message if the `=>` is missing. It is set when parsing the
113+
/// guard expression.
71114
const IN_IF_GUARD = 1 << 4;
115+
/// Used to detect the incorrect use of expressions in patterns.
116+
///
117+
/// This is used for error handling while parsing a pattern. During
118+
/// error recovery, this will be set to try to parse the pattern as an
119+
/// expression, but halts parsing the expression when reaching certain
120+
/// tokens like `=`.
72121
const IS_PAT = 1 << 5;
73122
}
74123
}

compiler/rustc_target/src/target_features.rs

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ impl Stability {
102102
// check whether they're named already elsewhere in rust
103103
// e.g. in stdarch and whether the given name matches LLVM's
104104
// if it doesn't, to_llvm_feature in llvm_util in rustc_codegen_llvm needs to be adapted.
105+
// Additionally, if the feature is not available in older version of LLVM supported by the current
106+
// rust, the same function must be updated to filter out these features to avoid triggering
107+
// warnings.
105108
//
106109
// Also note that all target features listed here must be purely additive: for target_feature 1.1 to
107110
// be sound, we can never allow features like `+soft-float` (on x86) to be controlled on a

compiler/rustc_trait_selection/src/solve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ pub use fulfill::{FulfillmentCtxt, NextSolverError};
1111
pub(crate) use normalize::deeply_normalize_for_diagnostics;
1212
pub use normalize::{
1313
deeply_normalize, deeply_normalize_with_skipped_universes,
14-
deeply_normalize_with_skipped_universes_and_ambiguous_goals,
14+
deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals,
1515
};
1616
pub use select::InferCtxtSelectExt;

compiler/rustc_trait_selection/src/solve/normalize.rs

+32-25
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ where
4545
T: TypeFoldable<TyCtxt<'tcx>>,
4646
E: FromSolverError<'tcx, NextSolverError<'tcx>>,
4747
{
48-
let (value, goals) =
49-
deeply_normalize_with_skipped_universes_and_ambiguous_goals(at, value, universes)?;
50-
assert_eq!(goals, vec![]);
48+
let (value, coroutine_goals) =
49+
deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals(
50+
at, value, universes,
51+
)?;
52+
assert_eq!(coroutine_goals, vec![]);
5153

5254
Ok(value)
5355
}
@@ -59,9 +61,9 @@ where
5961
/// entered before passing `value` to the function. This is currently needed for
6062
/// `normalize_erasing_regions`, which skips binders as it walks through a type.
6163
///
62-
/// This returns a set of stalled obligations if the typing mode of the underlying infcx
63-
/// has any stalled coroutine def ids.
64-
pub fn deeply_normalize_with_skipped_universes_and_ambiguous_goals<'tcx, T, E>(
64+
/// This returns a set of stalled obligations involving coroutines if the typing mode of
65+
/// the underlying infcx has any stalled coroutine def ids.
66+
pub fn deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals<'tcx, T, E>(
6567
at: At<'_, 'tcx>,
6668
value: T,
6769
universes: Vec<Option<UniverseIndex>>,
@@ -71,19 +73,24 @@ where
7173
E: FromSolverError<'tcx, NextSolverError<'tcx>>,
7274
{
7375
let fulfill_cx = FulfillmentCtxt::new(at.infcx);
74-
let mut folder =
75-
NormalizationFolder { at, fulfill_cx, depth: 0, universes, stalled_goals: vec![] };
76+
let mut folder = NormalizationFolder {
77+
at,
78+
fulfill_cx,
79+
depth: 0,
80+
universes,
81+
stalled_coroutine_goals: vec![],
82+
};
7683
let value = value.try_fold_with(&mut folder)?;
7784
let errors = folder.fulfill_cx.select_all_or_error(at.infcx);
78-
if errors.is_empty() { Ok((value, folder.stalled_goals)) } else { Err(errors) }
85+
if errors.is_empty() { Ok((value, folder.stalled_coroutine_goals)) } else { Err(errors) }
7986
}
8087

8188
struct NormalizationFolder<'me, 'tcx, E> {
8289
at: At<'me, 'tcx>,
8390
fulfill_cx: FulfillmentCtxt<'tcx, E>,
8491
depth: usize,
8592
universes: Vec<Option<UniverseIndex>>,
86-
stalled_goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
93+
stalled_coroutine_goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
8794
}
8895

8996
impl<'tcx, E> NormalizationFolder<'_, 'tcx, E>
@@ -182,7 +189,7 @@ where
182189
return Err(errors);
183190
}
184191

185-
self.stalled_goals.extend(
192+
self.stalled_coroutine_goals.extend(
186193
self.fulfill_cx
187194
.drain_stalled_obligations_for_coroutines(self.at.infcx)
188195
.into_iter()
@@ -298,13 +305,13 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for DeeplyNormalizeForDiagnosticsFolder<'_,
298305

299306
fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
300307
let infcx = self.at.infcx;
301-
let result =
302-
infcx.commit_if_ok(|_| {
303-
deeply_normalize_with_skipped_universes_and_ambiguous_goals::<
304-
_,
305-
ScrubbedTraitError<'tcx>,
306-
>(self.at, ty, vec![None; ty.outer_exclusive_binder().as_usize()])
307-
});
308+
let result: Result<_, Vec<ScrubbedTraitError<'tcx>>> = infcx.commit_if_ok(|_| {
309+
deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals(
310+
self.at,
311+
ty,
312+
vec![None; ty.outer_exclusive_binder().as_usize()],
313+
)
314+
});
308315
match result {
309316
Ok((ty, _)) => ty,
310317
Err(_) => ty.super_fold_with(self),
@@ -313,13 +320,13 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for DeeplyNormalizeForDiagnosticsFolder<'_,
313320

314321
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
315322
let infcx = self.at.infcx;
316-
let result =
317-
infcx.commit_if_ok(|_| {
318-
deeply_normalize_with_skipped_universes_and_ambiguous_goals::<
319-
_,
320-
ScrubbedTraitError<'tcx>,
321-
>(self.at, ct, vec![None; ct.outer_exclusive_binder().as_usize()])
322-
});
323+
let result: Result<_, Vec<ScrubbedTraitError<'tcx>>> = infcx.commit_if_ok(|_| {
324+
deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals(
325+
self.at,
326+
ct,
327+
vec![None; ct.outer_exclusive_binder().as_usize()],
328+
)
329+
});
323330
match result {
324331
Ok((ct, _)) => ct,
325332
Err(_) => ct.super_fold_with(self),

compiler/rustc_trait_selection/src/traits/normalize.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,14 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
260260
}
261261

262262
ty::Projection if !data.has_escaping_bound_vars() => {
263-
// This branch is *mostly* just an optimization: when we don't
264-
// have escaping bound vars, we don't need to replace them with
265-
// placeholders (see branch below). *Also*, we know that we can
266-
// register an obligation to *later* project, since we know
267-
// there won't be bound vars there.
263+
// When we don't have escaping bound vars we can normalize ambig aliases
264+
// to inference variables (done in `normalize_projection_ty`). This would
265+
// be wrong if there were escaping bound vars as even if we instantiated
266+
// the bound vars with placeholders, we wouldn't be able to map them back
267+
// after normalization succeeded.
268+
//
269+
// Also, as an optimization: when we don't have escaping bound vars, we don't
270+
// need to replace them with placeholders (see branch below).
268271
let data = data.fold_with(self);
269272
let normalized_ty = project::normalize_projection_ty(
270273
self.selcx,

compiler/rustc_transmute/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ edition = "2024"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
itertools = "0.12"
98
rustc_abi = { path = "../rustc_abi", optional = true }
109
rustc_data_structures = { path = "../rustc_data_structures" }
1110
rustc_hir = { path = "../rustc_hir", optional = true }
@@ -15,6 +14,11 @@ smallvec = "1.8.1"
1514
tracing = "0.1"
1615
# tidy-alphabetical-end
1716

17+
[dev-dependencies]
18+
# tidy-alphabetical-start
19+
itertools = "0.12"
20+
# tidy-alphabetical-end
21+
1822
[features]
1923
rustc = [
2024
"dep:rustc_abi",

0 commit comments

Comments
 (0)