Skip to content

Commit b45dd71

Browse files
committed
Auto merge of rust-lang#140529 - matthiaskrgr:rollup-jpaa2ky, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - rust-lang#140385 (Subtree update of `rust-analyzer`) - rust-lang#140458 (Fix for async drop ice with partly dropped tuple) - 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 251cda5 + a477172 commit b45dd71

File tree

896 files changed

+33319
-39602
lines changed

Some content is hidden

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

896 files changed

+33319
-39602
lines changed

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

@@ -26,15 +32,6 @@ use crate::FnCtxt;
2632
///////////////////////////////////////////////////////////////////////////
2733
// Entry point
2834

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

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

@@ -877,7 +871,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
877871
let cause = ObligationCause::misc(self.span.to_span(tcx), body_id);
878872
let at = self.fcx.at(&cause, self.fcx.param_env);
879873
let universes = vec![None; outer_exclusive_binder(value).as_usize()];
880-
match solve::deeply_normalize_with_skipped_universes_and_ambiguous_goals(
874+
match solve::deeply_normalize_with_skipped_universes_and_ambiguous_coroutine_goals(
881875
at, value, universes,
882876
) {
883877
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
@@ -58,13 +58,62 @@ mod tokenstream {
5858
}
5959

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

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,

src/ci/docker/scripts/rfl-build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -euo pipefail
44

5-
LINUX_VERSION=v6.14-rc3
5+
LINUX_VERSION=v6.15-rc4
66

77
# Build rustc, rustdoc, cargo, clippy-driver and rustfmt
88
../x.py build --stage 2 library rustdoc clippy rustfmt

src/tools/rust-analyzer/.github/ISSUE_TEMPLATE/bug_report.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ assignees: ''
88
---
99

1010
<!--
11-
Troubleshooting guide: https://rust-analyzer.github.io/manual.html#troubleshooting
11+
Troubleshooting guide: https://rust-analyzer.github.io/book/troubleshooting.html
1212
Forum for questions: https://users.rust-lang.org/c/ide/14
1313
1414
Before submitting, please make sure that you're not running into one of these known issues:
@@ -28,7 +28,7 @@ Otherwise please try to provide information which will help us to fix the issue
2828

2929
**repository link (if public, optional)**: (eg. [rust-analyzer](https://github.com/rust-lang/rust-analyzer))
3030

31-
**code snippet to reproduce**:
31+
**code snippet to reproduce**:
3232
```rust
3333
// add your code here
3434

src/tools/rust-analyzer/.github/ISSUE_TEMPLATE/critical_nightly_regression.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ assignees: ''
88
---
99

1010
<!--
11-
Troubleshooting guide: https://rust-analyzer.github.io/manual.html#troubleshooting
11+
Troubleshooting guide: https://rust-analyzer.github.io/book/troubleshooting.html
1212
1313
Please try to provide information which will help us to fix the issue faster. Minimal reproducible examples with few dependencies are especially lovely <3.
1414
-->

0 commit comments

Comments
 (0)