Skip to content

Commit 30ea1a2

Browse files
committed
Auto merge of #125976 - compiler-errors:rollup-xt3le7w, r=compiler-errors
Rollup of 8 pull requests Successful merges: - #125667 (Silence follow-up errors directly based on error types and regions) - #125717 (Refactor `#[diagnostic::do_not_recommend]` support) - #125795 (Improve renaming suggestion for names with leading underscores) - #125865 (Fix ICE caused by ignoring EffectVars in type inference) - #125953 (Streamline `nested` calls.) - #125959 (Reduce `pub` exposure in `rustc_mir_build`) - #125967 (Split smir `Const` into `TyConst` and `MirConst`) - #125968 (Store the types of `ty::Expr` arguments in the `ty::Expr`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents bc33782 + a5dc684 commit 30ea1a2

File tree

93 files changed

+1294
-917
lines changed

Some content is hidden

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

93 files changed

+1294
-917
lines changed

compiler/rustc_borrowck/src/nll.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
125125
placeholder_indices,
126126
placeholder_index_to_region: _,
127127
liveness_constraints,
128-
outlives_constraints,
129-
member_constraints,
128+
mut outlives_constraints,
129+
mut member_constraints,
130130
universe_causes,
131131
type_tests,
132132
} = constraints;
@@ -144,6 +144,16 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
144144
&universal_region_relations,
145145
);
146146

147+
if let Some(guar) = universal_regions.tainted_by_errors() {
148+
// Suppress unhelpful extra errors in `infer_opaque_types` by clearing out all
149+
// outlives bounds that we may end up checking.
150+
outlives_constraints = Default::default();
151+
member_constraints = Default::default();
152+
153+
// Also taint the entire scope.
154+
infcx.set_tainted_by_errors(guar);
155+
}
156+
147157
let mut regioncx = RegionInferenceContext::new(
148158
infcx,
149159
var_origins,

compiler/rustc_borrowck/src/universal_regions.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ use rustc_middle::ty::{self, InlineConstArgs, InlineConstArgsParts, RegionVid, T
2929
use rustc_middle::ty::{GenericArgs, GenericArgsRef};
3030
use rustc_middle::{bug, span_bug};
3131
use rustc_span::symbol::{kw, sym};
32-
use rustc_span::Symbol;
32+
use rustc_span::{ErrorGuaranteed, Symbol};
33+
use std::cell::Cell;
3334
use std::iter;
3435

3536
use crate::renumber::RegionCtxt;
@@ -186,6 +187,10 @@ struct UniversalRegionIndices<'tcx> {
186187

187188
/// The vid assigned to `'static`. Used only for diagnostics.
188189
pub fr_static: RegionVid,
190+
191+
/// Whether we've encountered an error region. If we have, cancel all
192+
/// outlives errors, as they are likely bogus.
193+
pub tainted_by_errors: Cell<Option<ErrorGuaranteed>>,
189194
}
190195

191196
#[derive(Debug, PartialEq)]
@@ -408,6 +413,10 @@ impl<'tcx> UniversalRegions<'tcx> {
408413
}
409414
}
410415
}
416+
417+
pub fn tainted_by_errors(&self) -> Option<ErrorGuaranteed> {
418+
self.indices.tainted_by_errors.get()
419+
}
411420
}
412421

413422
struct UniversalRegionsBuilder<'cx, 'tcx> {
@@ -663,7 +672,11 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
663672
let global_mapping = iter::once((tcx.lifetimes.re_static, fr_static));
664673
let arg_mapping = iter::zip(identity_args.regions(), fr_args.regions().map(|r| r.as_var()));
665674

666-
UniversalRegionIndices { indices: global_mapping.chain(arg_mapping).collect(), fr_static }
675+
UniversalRegionIndices {
676+
indices: global_mapping.chain(arg_mapping).collect(),
677+
fr_static,
678+
tainted_by_errors: Cell::new(None),
679+
}
667680
}
668681

669682
fn compute_inputs_and_output(
@@ -868,7 +881,8 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
868881
pub fn to_region_vid(&self, r: ty::Region<'tcx>) -> RegionVid {
869882
if let ty::ReVar(..) = *r {
870883
r.as_var()
871-
} else if r.is_error() {
884+
} else if let ty::ReError(guar) = *r {
885+
self.tainted_by_errors.set(Some(guar));
872886
// We use the `'static` `RegionVid` because `ReError` doesn't actually exist in the
873887
// `UniversalRegionIndices`. This is fine because 1) it is a fallback only used if
874888
// errors are being emitted and 2) it leaves the happy path unaffected.

compiler/rustc_driver_impl/src/pretty.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
use rustc_ast as ast;
44
use rustc_ast_pretty::pprust as pprust_ast;
55
use rustc_errors::FatalError;
6-
use rustc_hir as hir;
76
use rustc_hir_pretty as pprust_hir;
87
use rustc_middle::bug;
98
use rustc_middle::mir::{write_mir_graphviz, write_mir_pretty};
@@ -70,11 +69,7 @@ struct HirIdentifiedAnn<'tcx> {
7069

7170
impl<'tcx> pprust_hir::PpAnn for HirIdentifiedAnn<'tcx> {
7271
fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
73-
pprust_hir::PpAnn::nested(
74-
&(&self.tcx.hir() as &dyn hir::intravisit::Map<'_>),
75-
state,
76-
nested,
77-
)
72+
self.tcx.nested(state, nested)
7873
}
7974

8075
fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
@@ -152,8 +147,7 @@ impl<'tcx> pprust_hir::PpAnn for HirTypedAnn<'tcx> {
152147
if let pprust_hir::Nested::Body(id) = nested {
153148
self.maybe_typeck_results.set(Some(self.tcx.typeck_body(id)));
154149
}
155-
let pp_ann = &(&self.tcx.hir() as &dyn hir::intravisit::Map<'_>);
156-
pprust_hir::PpAnn::nested(pp_ann, state, nested);
150+
self.tcx.nested(state, nested);
157151
self.maybe_typeck_results.set(old_maybe_typeck_results);
158152
}
159153

compiler/rustc_hir_analysis/src/collect/type_of.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
502502
bug!("unexpected sort of node in type_of(): {:?}", x);
503503
}
504504
};
505-
if let Err(e) = icx.check_tainted_by_errors() {
505+
if let Err(e) = icx.check_tainted_by_errors()
506+
&& !output.references_error()
507+
{
506508
ty::EarlyBinder::bind(Ty::new_error(tcx, e))
507509
} else {
508510
ty::EarlyBinder::bind(output)

compiler/rustc_infer/src/infer/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ pub enum FixupError {
587587
UnresolvedFloatTy(FloatVid),
588588
UnresolvedTy(TyVid),
589589
UnresolvedConst(ConstVid),
590+
UnresolvedEffect(EffectVid),
590591
}
591592

592593
/// See the `region_obligations` field for more information.
@@ -614,6 +615,7 @@ impl fmt::Display for FixupError {
614615
),
615616
UnresolvedTy(_) => write!(f, "unconstrained type"),
616617
UnresolvedConst(_) => write!(f, "unconstrained const value"),
618+
UnresolvedEffect(_) => write!(f, "unconstrained effect value"),
617619
}
618620
}
619621
}

compiler/rustc_infer/src/infer/resolve.rs

+3
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for FullTypeResolver<'a, 'tcx> {
167167
ty::ConstKind::Infer(InferConst::Fresh(_)) => {
168168
bug!("Unexpected const in full const resolver: {:?}", c);
169169
}
170+
ty::ConstKind::Infer(InferConst::EffectVar(evid)) => {
171+
return Err(FixupError::UnresolvedEffect(evid));
172+
}
170173
_ => {}
171174
}
172175
c.try_super_fold_with(self)

compiler/rustc_middle/src/ty/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub type ConstKind<'tcx> = ir::ConstKind<TyCtxt<'tcx>>;
2424
pub type UnevaluatedConst<'tcx> = ir::UnevaluatedConst<TyCtxt<'tcx>>;
2525

2626
#[cfg(target_pointer_width = "64")]
27-
rustc_data_structures::static_assert_size!(ConstKind<'_>, 32);
27+
rustc_data_structures::static_assert_size!(ConstKind<'_>, 24);
2828

2929
/// Use this rather than `ConstData`, whenever possible.
3030
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)]
@@ -58,7 +58,7 @@ pub struct ConstData<'tcx> {
5858
}
5959

6060
#[cfg(target_pointer_width = "64")]
61-
rustc_data_structures::static_assert_size!(ConstData<'_>, 40);
61+
rustc_data_structures::static_assert_size!(ConstData<'_>, 32);
6262

6363
impl<'tcx> Const<'tcx> {
6464
#[inline]

compiler/rustc_middle/src/ty/consts/kind.rs

+118-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::Const;
22
use crate::mir;
33
use crate::ty::abstract_const::CastKind;
4-
use crate::ty::{self, visit::TypeVisitableExt as _, List, Ty, TyCtxt};
4+
use crate::ty::{self, visit::TypeVisitableExt as _, Ty, TyCtxt};
55
use rustc_macros::{extension, HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
66

77
#[extension(pub(crate) trait UnevaluatedConstEvalExt<'tcx>)]
@@ -40,14 +40,125 @@ impl<'tcx> ty::UnevaluatedConst<'tcx> {
4040
}
4141
}
4242

43+
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
44+
#[derive(HashStable, TyEncodable, TyDecodable, TypeVisitable, TypeFoldable)]
45+
pub enum ExprKind {
46+
Binop(mir::BinOp),
47+
UnOp(mir::UnOp),
48+
FunctionCall,
49+
Cast(CastKind),
50+
}
4351
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
4452
#[derive(HashStable, TyEncodable, TyDecodable, TypeVisitable, TypeFoldable)]
45-
pub enum Expr<'tcx> {
46-
Binop(mir::BinOp, Const<'tcx>, Const<'tcx>),
47-
UnOp(mir::UnOp, Const<'tcx>),
48-
FunctionCall(Const<'tcx>, &'tcx List<Const<'tcx>>),
49-
Cast(CastKind, Const<'tcx>, Ty<'tcx>),
53+
pub struct Expr<'tcx> {
54+
pub kind: ExprKind,
55+
args: ty::GenericArgsRef<'tcx>,
56+
}
57+
impl<'tcx> Expr<'tcx> {
58+
pub fn new_binop(
59+
tcx: TyCtxt<'tcx>,
60+
binop: mir::BinOp,
61+
lhs_ty: Ty<'tcx>,
62+
rhs_ty: Ty<'tcx>,
63+
lhs_ct: Const<'tcx>,
64+
rhs_ct: Const<'tcx>,
65+
) -> Self {
66+
let args = tcx.mk_args_from_iter::<_, ty::GenericArg<'tcx>>(
67+
[lhs_ty.into(), rhs_ty.into(), lhs_ct.into(), rhs_ct.into()].into_iter(),
68+
);
69+
70+
Self { kind: ExprKind::Binop(binop), args }
71+
}
72+
73+
pub fn binop_args(self) -> (Ty<'tcx>, Ty<'tcx>, Const<'tcx>, Const<'tcx>) {
74+
assert!(matches!(self.kind, ExprKind::Binop(_)));
75+
76+
match self.args().as_slice() {
77+
[lhs_ty, rhs_ty, lhs_ct, rhs_ct] => (
78+
lhs_ty.expect_ty(),
79+
rhs_ty.expect_ty(),
80+
lhs_ct.expect_const(),
81+
rhs_ct.expect_const(),
82+
),
83+
_ => bug!("Invalid args for `Binop` expr {self:?}"),
84+
}
85+
}
86+
87+
pub fn new_unop(tcx: TyCtxt<'tcx>, unop: mir::UnOp, ty: Ty<'tcx>, ct: Const<'tcx>) -> Self {
88+
let args =
89+
tcx.mk_args_from_iter::<_, ty::GenericArg<'tcx>>([ty.into(), ct.into()].into_iter());
90+
91+
Self { kind: ExprKind::UnOp(unop), args }
92+
}
93+
94+
pub fn unop_args(self) -> (Ty<'tcx>, Const<'tcx>) {
95+
assert!(matches!(self.kind, ExprKind::UnOp(_)));
96+
97+
match self.args().as_slice() {
98+
[ty, ct] => (ty.expect_ty(), ct.expect_const()),
99+
_ => bug!("Invalid args for `UnOp` expr {self:?}"),
100+
}
101+
}
102+
103+
pub fn new_call(
104+
tcx: TyCtxt<'tcx>,
105+
func_ty: Ty<'tcx>,
106+
func_expr: Const<'tcx>,
107+
arguments: impl Iterator<Item = Const<'tcx>>,
108+
) -> Self {
109+
let args = tcx.mk_args_from_iter::<_, ty::GenericArg<'tcx>>(
110+
[func_ty.into(), func_expr.into()].into_iter().chain(arguments.map(|ct| ct.into())),
111+
);
112+
113+
Self { kind: ExprKind::FunctionCall, args }
114+
}
115+
116+
pub fn call_args(self) -> (Ty<'tcx>, Const<'tcx>, impl Iterator<Item = Const<'tcx>>) {
117+
assert!(matches!(self.kind, ExprKind::FunctionCall));
118+
119+
match self.args().as_slice() {
120+
[func_ty, func, rest @ ..] => (
121+
func_ty.expect_ty(),
122+
func.expect_const(),
123+
rest.iter().map(|arg| arg.expect_const()),
124+
),
125+
_ => bug!("Invalid args for `Call` expr {self:?}"),
126+
}
127+
}
128+
129+
pub fn new_cast(
130+
tcx: TyCtxt<'tcx>,
131+
cast: CastKind,
132+
value_ty: Ty<'tcx>,
133+
value: Const<'tcx>,
134+
to_ty: Ty<'tcx>,
135+
) -> Self {
136+
let args = tcx.mk_args_from_iter::<_, ty::GenericArg<'tcx>>(
137+
[value_ty.into(), value.into(), to_ty.into()].into_iter(),
138+
);
139+
140+
Self { kind: ExprKind::Cast(cast), args }
141+
}
142+
143+
pub fn cast_args(self) -> (Ty<'tcx>, Const<'tcx>, Ty<'tcx>) {
144+
assert!(matches!(self.kind, ExprKind::Cast(_)));
145+
146+
match self.args().as_slice() {
147+
[value_ty, value, to_ty] => {
148+
(value_ty.expect_ty(), value.expect_const(), to_ty.expect_ty())
149+
}
150+
_ => bug!("Invalid args for `Cast` expr {self:?}"),
151+
}
152+
}
153+
154+
pub fn new(kind: ExprKind, args: ty::GenericArgsRef<'tcx>) -> Self {
155+
Self { kind, args }
156+
}
157+
158+
pub fn args(&self) -> ty::GenericArgsRef<'tcx> {
159+
self.args
160+
}
50161
}
51162

52163
#[cfg(target_pointer_width = "64")]
53-
rustc_data_structures::static_assert_size!(Expr<'_>, 24);
164+
rustc_data_structures::static_assert_size!(Expr<'_>, 16);

compiler/rustc_middle/src/ty/flags.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -374,26 +374,7 @@ impl FlagComputation {
374374
self.add_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE);
375375
}
376376
ty::ConstKind::Value(_) => {}
377-
ty::ConstKind::Expr(e) => {
378-
use ty::Expr;
379-
match e {
380-
Expr::Binop(_, l, r) => {
381-
self.add_const(l);
382-
self.add_const(r);
383-
}
384-
Expr::UnOp(_, v) => self.add_const(v),
385-
Expr::FunctionCall(f, args) => {
386-
self.add_const(f);
387-
for arg in args {
388-
self.add_const(arg);
389-
}
390-
}
391-
Expr::Cast(_, c, t) => {
392-
self.add_ty(t);
393-
self.add_const(c);
394-
}
395-
}
396-
}
377+
ty::ConstKind::Expr(e) => self.add_args(e.args()),
397378
ty::ConstKind::Error(_) => self.add_flags(TypeFlags::HAS_ERROR),
398379
}
399380
}

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub use self::closure::{
8787
CAPTURE_STRUCT_LOCAL,
8888
};
8989
pub use self::consts::{
90-
Const, ConstData, ConstInt, ConstKind, Expr, ScalarInt, UnevaluatedConst, ValTree,
90+
Const, ConstData, ConstInt, ConstKind, Expr, ExprKind, ScalarInt, UnevaluatedConst, ValTree,
9191
};
9292
pub use self::context::{
9393
tls, CtxtInterners, CurrentGcx, DeducedParamAttrs, Feed, FreeRegionInfo, GlobalCtxt, Lift,

0 commit comments

Comments
 (0)