Skip to content

Commit e6e262f

Browse files
committed
Auto merge of #124934 - matthiaskrgr:rollup-eqor0ot, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #124893 (Make a minimal amount of region APIs public) - #124919 (Add `ErrorGuaranteed` to `Recovered::Yes` and use it more.) - #124923 (interpret/miri: better errors on failing offset_from) - #124924 (chore: remove repetitive words) - #124926 (Make `#![feature]` suggestion MaybeIncorrect) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 238c1e7 + 779fe95 commit e6e262f

File tree

26 files changed

+175
-140
lines changed

26 files changed

+175
-140
lines changed

Diff for: compiler/rustc_ast/src/ast.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ pub enum ExprKind {
14221422
/// of `if` / `while` expressions. (e.g., `if let 0 = x { .. }`).
14231423
///
14241424
/// `Span` represents the whole `let pat = expr` statement.
1425-
Let(P<Pat>, P<Expr>, Span, Option<ErrorGuaranteed>),
1425+
Let(P<Pat>, P<Expr>, Span, Recovered),
14261426
/// An `if` block, with an optional `else` block.
14271427
///
14281428
/// `if expr { block } else { expr }`
@@ -2881,17 +2881,20 @@ pub struct FieldDef {
28812881
pub is_placeholder: bool,
28822882
}
28832883

2884+
/// Was parsing recovery performed?
2885+
#[derive(Copy, Clone, Debug, Encodable, Decodable, HashStable_Generic)]
2886+
pub enum Recovered {
2887+
No,
2888+
Yes(ErrorGuaranteed),
2889+
}
2890+
28842891
/// Fields and constructor ids of enum variants and structs.
28852892
#[derive(Clone, Encodable, Decodable, Debug)]
28862893
pub enum VariantData {
28872894
/// Struct variant.
28882895
///
28892896
/// E.g., `Bar { .. }` as in `enum Foo { Bar { .. } }`.
2890-
Struct {
2891-
fields: ThinVec<FieldDef>,
2892-
// FIXME: investigate making this a `Option<ErrorGuaranteed>`
2893-
recovered: bool,
2894-
},
2897+
Struct { fields: ThinVec<FieldDef>, recovered: Recovered },
28952898
/// Tuple variant.
28962899
///
28972900
/// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`.

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
158158
let ohs = self.lower_expr(ohs);
159159
hir::ExprKind::AddrOf(*k, *m, ohs)
160160
}
161-
ExprKind::Let(pat, scrutinee, span, is_recovered) => {
161+
ExprKind::Let(pat, scrutinee, span, recovered) => {
162162
hir::ExprKind::Let(self.arena.alloc(hir::LetExpr {
163163
span: self.lower_span(*span),
164164
pat: self.lower_pat(pat),
165165
ty: None,
166166
init: self.lower_expr(scrutinee),
167-
is_recovered: *is_recovered,
167+
recovered: *recovered,
168168
}))
169169
}
170170
ExprKind::If(cond, then, else_opt) => {

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12831283
fields.iter().enumerate().map(|f| this.lower_field_def(f)),
12841284
);
12851285
let span = t.span;
1286-
let variant_data = hir::VariantData::Struct { fields, recovered: false };
1286+
let variant_data =
1287+
hir::VariantData::Struct { fields, recovered: ast::Recovered::No };
12871288
// FIXME: capture the generics from the outer adt.
12881289
let generics = hir::Generics::empty();
12891290
let kind = match t.kind {

Diff for: compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
494494
{
495495
self.suggest_cloning(err, ty, expr, None, Some(move_spans));
496496
} else if self.suggest_hoisting_call_outside_loop(err, expr) {
497-
// The place where the the type moves would be misleading to suggest clone.
497+
// The place where the type moves would be misleading to suggest clone.
498498
// #121466
499499
self.suggest_cloning(err, ty, expr, None, Some(move_spans));
500500
}

Diff for: compiler/rustc_borrowck/src/region_infer/mod.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -1326,14 +1326,20 @@ impl<'tcx> RegionInferenceContext<'tcx> {
13261326
})
13271327
}
13281328

1329-
// Evaluate whether `sup_region == sub_region`.
1330-
fn eval_equal(&self, r1: RegionVid, r2: RegionVid) -> bool {
1329+
/// Evaluate whether `sup_region == sub_region`.
1330+
///
1331+
/// Panics if called before `solve()` executes,
1332+
// This is `pub` because it's used by unstable external borrowck data users, see `consumers.rs`.
1333+
pub fn eval_equal(&self, r1: RegionVid, r2: RegionVid) -> bool {
13311334
self.eval_outlives(r1, r2) && self.eval_outlives(r2, r1)
13321335
}
13331336

1334-
// Evaluate whether `sup_region: sub_region`.
1337+
/// Evaluate whether `sup_region: sub_region`.
1338+
///
1339+
/// Panics if called before `solve()` executes,
1340+
// This is `pub` because it's used by unstable external borrowck data users, see `consumers.rs`.
13351341
#[instrument(skip(self), level = "debug", ret)]
1336-
fn eval_outlives(&self, sup_region: RegionVid, sub_region: RegionVid) -> bool {
1342+
pub fn eval_outlives(&self, sup_region: RegionVid, sub_region: RegionVid) -> bool {
13371343
debug!(
13381344
"sup_region's value = {:?} universal={:?}",
13391345
self.region_value_str(sup_region),
@@ -2246,7 +2252,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22462252
}
22472253

22482254
/// Access to the SCC constraint graph.
2249-
pub(crate) fn constraint_sccs(&self) -> &Sccs<RegionVid, ConstraintSccIndex> {
2255+
/// This can be used to quickly under-approximate the regions which are equal to each other
2256+
/// and their relative orderings.
2257+
// This is `pub` because it's used by unstable external borrowck data users, see `consumers.rs`.
2258+
pub fn constraint_sccs(&self) -> &Sccs<RegionVid, ConstraintSccIndex> {
22502259
self.constraint_sccs.as_ref()
22512260
}
22522261

Diff for: compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
4040
/// compares lifetimes directly, so we need to map the inference variables
4141
/// back to concrete lifetimes: `'static`, `ReEarlyParam` or `ReLateParam`.
4242
///
43-
/// First we map the regions in the the generic parameters `_Return<'1>` to
43+
/// First we map the regions in the generic parameters `_Return<'1>` to
4444
/// their `external_name` giving `_Return<'a>`. This step is a bit involved.
4545
/// See the [rustc-dev-guide chapter] for more info.
4646
///

Diff for: compiler/rustc_builtin_macros/src/format.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ use rustc_ast::{token, StmtKind};
77
use rustc_ast::{
88
Expr, ExprKind, FormatAlignment, FormatArgPosition, FormatArgPositionKind, FormatArgs,
99
FormatArgsPiece, FormatArgument, FormatArgumentKind, FormatArguments, FormatCount,
10-
FormatDebugHex, FormatOptions, FormatPlaceholder, FormatSign, FormatTrait,
10+
FormatDebugHex, FormatOptions, FormatPlaceholder, FormatSign, FormatTrait, Recovered,
1111
};
1212
use rustc_data_structures::fx::FxHashSet;
1313
use rustc_errors::{Applicability, Diag, MultiSpan, PResult, SingleLabelManySpans};
1414
use rustc_expand::base::*;
1515
use rustc_lint_defs::builtin::NAMED_ARGUMENTS_USED_POSITIONALLY;
1616
use rustc_lint_defs::{BufferedEarlyLint, BuiltinLintDiag, LintId};
17-
use rustc_parse::parser::Recovered;
1817
use rustc_parse_format as parse;
1918
use rustc_span::symbol::{Ident, Symbol};
2019
use rustc_span::{BytePos, ErrorGuaranteed, InnerSpan, Span};
@@ -112,7 +111,7 @@ fn parse_args<'a>(ecx: &ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<'a,
112111
_ => return Err(err),
113112
}
114113
}
115-
Ok(Recovered::Yes) => (),
114+
Ok(Recovered::Yes(_)) => (),
116115
Ok(Recovered::No) => unreachable!(),
117116
}
118117
}

Diff for: compiler/rustc_const_eval/messages.ftl

+8-7
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ const_eval_deref_function_pointer =
6969
accessing {$allocation} which contains a function
7070
const_eval_deref_vtable_pointer =
7171
accessing {$allocation} which contains a vtable
72-
const_eval_different_allocations =
73-
`{$name}` called on pointers into different allocations
74-
7572
const_eval_division_by_zero =
7673
dividing by zero
7774
const_eval_division_overflow =
@@ -234,12 +231,18 @@ const_eval_not_enough_caller_args =
234231
const_eval_nullary_intrinsic_fail =
235232
could not evaluate nullary intrinsic
236233
234+
const_eval_offset_from_different_allocations =
235+
`{$name}` called on pointers into different allocations
236+
const_eval_offset_from_different_integers =
237+
`{$name}` called on different pointers without provenance (i.e., without an associated allocation)
237238
const_eval_offset_from_overflow =
238239
`{$name}` called when first pointer is too far ahead of second
239-
240-
const_eval_offset_from_test = out-of-bounds `offset_from`
240+
const_eval_offset_from_test =
241+
out-of-bounds `offset_from`
241242
const_eval_offset_from_underflow =
242243
`{$name}` called when first pointer is too far before second
244+
const_eval_offset_from_unsigned_overflow =
245+
`ptr_offset_from_unsigned` called when first pointer has smaller offset than second: {$a_offset} < {$b_offset}
243246
244247
const_eval_operator_non_const =
245248
cannot call non-const operator in {const_eval_const_context}s
@@ -381,8 +384,6 @@ const_eval_unreachable = entering unreachable code
381384
const_eval_unreachable_unwind =
382385
unwinding past a stack frame that does not allow unwinding
383386
384-
const_eval_unsigned_offset_from_overflow =
385-
`ptr_offset_from_unsigned` called when first pointer has smaller offset than second: {$a_offset} < {$b_offset}
386387
const_eval_unsized_local = unsized locals are not supported
387388
const_eval_unstable_const_fn = `{$def_path}` is not yet stable as a const fn
388389

Diff for: compiler/rustc_const_eval/src/interpret/intrinsics.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,16 @@ use rustc_middle::ty::layout::{LayoutOf as _, ValidityRequirement};
88
use rustc_middle::ty::GenericArgsRef;
99
use rustc_middle::ty::{Ty, TyCtxt};
1010
use rustc_middle::{
11-
mir::{
12-
self,
13-
interpret::{
14-
Allocation, ConstAllocation, GlobalId, InterpResult, PointerArithmetic, Scalar,
15-
},
16-
BinOp, ConstValue, NonDivergingIntrinsic,
17-
},
11+
mir::{self, BinOp, ConstValue, NonDivergingIntrinsic},
1812
ty::layout::TyAndLayout,
1913
};
2014
use rustc_span::symbol::{sym, Symbol};
2115
use rustc_target::abi::Size;
2216

2317
use super::{
24-
memory::MemoryKind, util::ensure_monomorphic_enough, CheckInAllocMsg, ImmTy, InterpCx,
25-
MPlaceTy, Machine, OpTy, Pointer,
18+
memory::MemoryKind, util::ensure_monomorphic_enough, Allocation, CheckInAllocMsg,
19+
ConstAllocation, GlobalId, ImmTy, InterpCx, InterpResult, MPlaceTy, Machine, OpTy, Pointer,
20+
PointerArithmetic, Scalar,
2621
};
2722

2823
use crate::fluent_generated as fluent;
@@ -249,22 +244,30 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
249244
match (self.ptr_try_get_alloc_id(a), self.ptr_try_get_alloc_id(b)) {
250245
(Err(a), Err(b)) => {
251246
// Neither pointer points to an allocation.
252-
// If these are inequal or null, this *will* fail the deref check below.
247+
// This is okay only if they are the same.
248+
if a != b {
249+
// We'd catch this below in the "dereferenceable" check, but
250+
// show a nicer error for this particular case.
251+
throw_ub_custom!(
252+
fluent::const_eval_offset_from_different_integers,
253+
name = intrinsic_name,
254+
);
255+
}
253256
(a, b)
254257
}
255258
(Err(_), _) | (_, Err(_)) => {
256259
// We managed to find a valid allocation for one pointer, but not the other.
257260
// That means they are definitely not pointing to the same allocation.
258261
throw_ub_custom!(
259-
fluent::const_eval_different_allocations,
262+
fluent::const_eval_offset_from_different_allocations,
260263
name = intrinsic_name,
261264
);
262265
}
263266
(Ok((a_alloc_id, a_offset, _)), Ok((b_alloc_id, b_offset, _))) => {
264267
// Found allocation for both. They must be into the same allocation.
265268
if a_alloc_id != b_alloc_id {
266269
throw_ub_custom!(
267-
fluent::const_eval_different_allocations,
270+
fluent::const_eval_offset_from_different_allocations,
268271
name = intrinsic_name,
269272
);
270273
}
@@ -286,7 +289,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
286289
// a < b
287290
if intrinsic_name == sym::ptr_offset_from_unsigned {
288291
throw_ub_custom!(
289-
fluent::const_eval_unsigned_offset_from_overflow,
292+
fluent::const_eval_offset_from_unsigned_overflow,
290293
a_offset = a_offset,
291294
b_offset = b_offset,
292295
);

Diff for: compiler/rustc_expand/src/placeholders.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ pub(crate) fn placeholder(
174174
}]),
175175
AstFragmentKind::Variants => AstFragment::Variants(smallvec![ast::Variant {
176176
attrs: Default::default(),
177-
data: ast::VariantData::Struct { fields: Default::default(), recovered: false },
177+
data: ast::VariantData::Struct {
178+
fields: Default::default(),
179+
recovered: ast::Recovered::No
180+
},
178181
disr_expr: None,
179182
id,
180183
ident,

Diff for: compiler/rustc_hir/src/hir.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1308,9 +1308,9 @@ pub struct LetExpr<'hir> {
13081308
pub pat: &'hir Pat<'hir>,
13091309
pub ty: Option<&'hir Ty<'hir>>,
13101310
pub init: &'hir Expr<'hir>,
1311-
/// `Some` when this let expressions is not in a syntanctically valid location.
1311+
/// `Recovered::Yes` when this let expressions is not in a syntanctically valid location.
13121312
/// Used to prevent building MIR in such situations.
1313-
pub is_recovered: Option<ErrorGuaranteed>,
1313+
pub recovered: ast::Recovered,
13141314
}
13151315

13161316
#[derive(Debug, Clone, Copy, HashStable_Generic)]
@@ -3030,11 +3030,7 @@ pub enum VariantData<'hir> {
30303030
/// A struct variant.
30313031
///
30323032
/// E.g., `Bar { .. }` as in `enum Foo { Bar { .. } }`.
3033-
Struct {
3034-
fields: &'hir [FieldDef<'hir>],
3035-
// FIXME: investigate making this a `Option<ErrorGuaranteed>`
3036-
recovered: bool,
3037-
},
3033+
Struct { fields: &'hir [FieldDef<'hir>], recovered: ast::Recovered },
30383034
/// A tuple variant.
30393035
///
30403036
/// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`.

Diff for: compiler/rustc_hir/src/intravisit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
768768
ExprKind::DropTemps(ref subexpression) => {
769769
try_visit!(visitor.visit_expr(subexpression));
770770
}
771-
ExprKind::Let(LetExpr { span: _, pat, ty, init, is_recovered: _ }) => {
771+
ExprKind::Let(LetExpr { span: _, pat, ty, init, recovered: _ }) => {
772772
// match the visit order in walk_local
773773
try_visit!(visitor.visit_expr(init));
774774
try_visit!(visitor.visit_pat(pat));

Diff for: compiler/rustc_hir_analysis/src/collect.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//! At present, however, we do run collection across all items in the
1515
//! crate as a kind of pass. This should eventually be factored away.
1616
17+
use rustc_ast::Recovered;
1718
use rustc_data_structures::captures::Captures;
1819
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
1920
use rustc_data_structures::unord::UnordMap;
@@ -1005,10 +1006,7 @@ fn lower_variant(
10051006
vis: tcx.visibility(f.def_id),
10061007
})
10071008
.collect();
1008-
let recovered = match def {
1009-
hir::VariantData::Struct { recovered, .. } => *recovered,
1010-
_ => false,
1011-
};
1009+
let recovered = matches!(def, hir::VariantData::Struct { recovered: Recovered::Yes(_), .. });
10121010
ty::VariantDef::new(
10131011
ident.name,
10141012
variant_did.map(LocalDefId::to_def_id),

Diff for: compiler/rustc_hir_typeck/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12711271
// otherwise check exactly as a let statement
12721272
self.check_decl((let_expr, hir_id).into());
12731273
// but return a bool, for this is a boolean expression
1274-
if let Some(error_guaranteed) = let_expr.is_recovered {
1274+
if let ast::Recovered::Yes(error_guaranteed) = let_expr.recovered {
12751275
self.set_tainted_by_errors(error_guaranteed);
12761276
Ty::new_error(self.tcx, error_guaranteed)
12771277
} else {

Diff for: compiler/rustc_hir_typeck/src/gather_locals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'a> From<&'a hir::LetStmt<'a>> for Declaration<'a> {
5050

5151
impl<'a> From<(&'a hir::LetExpr<'a>, HirId)> for Declaration<'a> {
5252
fn from((let_expr, hir_id): (&'a hir::LetExpr<'a>, HirId)) -> Self {
53-
let hir::LetExpr { pat, ty, span, init, is_recovered: _ } = *let_expr;
53+
let hir::LetExpr { pat, ty, span, init, recovered: _ } = *let_expr;
5454
Declaration { hir_id, pat, ty, span, init: Some(init), origin: DeclOrigin::LetExpr }
5555
}
5656
}

Diff for: compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2449,7 +2449,7 @@ impl<'tcx> TyCtxt<'tcx> {
24492449
span,
24502450
msg,
24512451
format!("#![feature({feature})]\n"),
2452-
Applicability::MachineApplicable,
2452+
Applicability::MaybeIncorrect,
24532453
);
24542454
} else {
24552455
diag.help(msg);

0 commit comments

Comments
 (0)