Skip to content

Commit 6b1dad9

Browse files
committed
Auto merge of #120088 - matthiaskrgr:rollup-4eak9yf, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #119172 (Detect `NulInCStr` error earlier.) - #119833 (Make tcx optional from StableMIR run macro and extend it to accept closures) - #119955 (Modify GenericArg and Term structs to use strict provenance rules) - #120021 (don't store const var origins for known vars) - #120038 (Don't create a separate "basename" when naming and opening a MIR dump file) - #120057 (Don't ICE when deducing future output if other errors already occurred) - #120073 (Remove spastorino from users_on_vacation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c485ee7 + 15066d3 commit 6b1dad9

Some content is hidden

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

41 files changed

+397
-318
lines changed

Diff for: compiler/rustc_ast/src/util/literal.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_lexer::unescape::{
88
};
99
use rustc_span::symbol::{kw, sym, Symbol};
1010
use rustc_span::Span;
11-
use std::ops::Range;
1211
use std::{ascii, fmt, str};
1312

1413
// Escapes a string, represented as a symbol. Reuses the original symbol,
@@ -39,7 +38,6 @@ pub enum LitError {
3938
InvalidFloatSuffix,
4039
NonDecimalFloat(u32),
4140
IntTooLarge(u32),
42-
NulInCStr(Range<usize>),
4341
}
4442

4543
impl LitKind {
@@ -156,10 +154,7 @@ impl LitKind {
156154
let s = symbol.as_str();
157155
let mut buf = Vec::with_capacity(s.len());
158156
let mut error = Ok(());
159-
unescape_c_string(s, Mode::CStr, &mut |span, c| match c {
160-
Ok(CStrUnit::Byte(0) | CStrUnit::Char('\0')) => {
161-
error = Err(LitError::NulInCStr(span));
162-
}
157+
unescape_c_string(s, Mode::CStr, &mut |_span, c| match c {
163158
Ok(CStrUnit::Byte(b)) => buf.push(b),
164159
Ok(CStrUnit::Char(c)) => {
165160
buf.extend_from_slice(c.encode_utf8(&mut [0; 4]).as_bytes())
@@ -179,10 +174,7 @@ impl LitKind {
179174
// can convert the symbol directly to a `Lrc<u8>` on success.
180175
let s = symbol.as_str();
181176
let mut error = Ok(());
182-
unescape_c_string(s, Mode::RawCStr, &mut |span, c| match c {
183-
Ok(CStrUnit::Byte(0) | CStrUnit::Char('\0')) => {
184-
error = Err(LitError::NulInCStr(span));
185-
}
177+
unescape_c_string(s, Mode::RawCStr, &mut |_, c| match c {
186178
Ok(_) => {}
187179
Err(err) => {
188180
if err.is_fatal() {

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

+10-4
Original file line numberDiff line numberDiff line change
@@ -754,16 +754,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
754754
get_future_output(obligation.predicate, obligation.cause.span)
755755
})?
756756
}
757+
ty::Alias(ty::Projection, _) => {
758+
return Some(Ty::new_error_with_message(
759+
self.tcx,
760+
closure_span,
761+
"this projection should have been projected to an opaque type",
762+
));
763+
}
757764
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => self
758765
.tcx
759766
.explicit_item_bounds(def_id)
760767
.iter_instantiated_copied(self.tcx, args)
761768
.find_map(|(p, s)| get_future_output(p.as_predicate(), s))?,
762769
ty::Error(_) => return Some(ret_ty),
763-
_ => span_bug!(
764-
closure_span,
765-
"async fn coroutine return type not an inference variable: {ret_ty}"
766-
),
770+
_ => {
771+
span_bug!(closure_span, "invalid async fn coroutine return type: {ret_ty:?}")
772+
}
767773
};
768774

769775
let output_ty = self.normalize(closure_span, output_ty);

Diff for: compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use rustc_hir::def_id::{DefId, LocalDefId};
1313
use rustc_hir::intravisit::{self, Visitor};
1414
use rustc_hir::{Body, Closure, Expr, ExprKind, FnRetTy, HirId, Local, LocalSource};
1515
use rustc_middle::hir::nested_filter;
16-
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
16+
use rustc_middle::infer::unify_key::{
17+
ConstVariableOrigin, ConstVariableOriginKind, ConstVariableValue,
18+
};
1719
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
1820
use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
1921
use rustc_middle::ty::{self, InferConst};
@@ -178,17 +180,23 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
178180
}
179181
};
180182
printer.ty_infer_name_resolver = Some(Box::new(ty_getter));
181-
let const_getter = move |ct_vid| {
182-
if infcx.probe_const_var(ct_vid).is_ok() {
183+
let const_getter = move |ct_vid| match infcx
184+
.inner
185+
.borrow_mut()
186+
.const_unification_table()
187+
.probe_value(ct_vid)
188+
{
189+
ConstVariableValue::Known { value: _ } => {
183190
warn!("resolved const var in error message");
184-
}
185-
if let ConstVariableOriginKind::ConstParameterDefinition(name, _) =
186-
infcx.inner.borrow_mut().const_unification_table().probe_value(ct_vid).origin.kind
187-
{
188-
return Some(name);
189-
} else {
190191
None
191192
}
193+
ConstVariableValue::Unknown { origin, universe: _ } => {
194+
if let ConstVariableOriginKind::ConstParameterDefinition(name, _) = origin.kind {
195+
return Some(name);
196+
} else {
197+
None
198+
}
199+
}
192200
};
193201
printer.const_infer_name_resolver = Some(Box::new(const_getter));
194202
printer
@@ -303,7 +311,12 @@ impl<'tcx> InferCtxt<'tcx> {
303311
GenericArgKind::Const(ct) => {
304312
if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.kind() {
305313
let origin =
306-
self.inner.borrow_mut().const_unification_table().probe_value(vid).origin;
314+
match self.inner.borrow_mut().const_unification_table().probe_value(vid) {
315+
ConstVariableValue::Known { value } => {
316+
bug!("resolved infer var: {vid:?} {value}")
317+
}
318+
ConstVariableValue::Unknown { origin, universe: _ } => origin,
319+
};
307320
if let ConstVariableOriginKind::ConstParameterDefinition(name, def_id) =
308321
origin.kind
309322
{

Diff for: compiler/rustc_infer/src/infer/freshen.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,8 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
146146
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
147147
match ct.kind() {
148148
ty::ConstKind::Infer(ty::InferConst::Var(v)) => {
149-
let opt_ct = self
150-
.infcx
151-
.inner
152-
.borrow_mut()
153-
.const_unification_table()
154-
.probe_value(v)
155-
.val
156-
.known();
149+
let opt_ct =
150+
self.infcx.inner.borrow_mut().const_unification_table().probe_value(v).known();
157151
self.freshen_const(opt_ct, ty::InferConst::Var(v), ty::InferConst::Fresh, ct.ty())
158152
}
159153
ty::ConstKind::Infer(ty::InferConst::EffectVar(v)) => {

Diff for: compiler/rustc_infer/src/infer/fudge.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_middle::infer::unify_key::ConstVidKey;
1+
use rustc_middle::infer::unify_key::{ConstVariableOriginKind, ConstVariableValue, ConstVidKey};
22
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
33
use rustc_middle::ty::{self, ConstVid, FloatVid, IntVid, RegionVid, Ty, TyCtxt, TyVid};
44

@@ -28,10 +28,17 @@ fn const_vars_since_snapshot<'tcx>(
2828
snapshot_var_len: usize,
2929
) -> (Range<ConstVid>, Vec<ConstVariableOrigin>) {
3030
let range = vars_since_snapshot(table, snapshot_var_len);
31+
3132
(
3233
range.start.vid..range.end.vid,
3334
(range.start.index()..range.end.index())
34-
.map(|index| table.probe_value(ConstVid::from_u32(index)).origin)
35+
.map(|index| match table.probe_value(ConstVid::from_u32(index)) {
36+
ConstVariableValue::Known { value: _ } => ConstVariableOrigin {
37+
kind: ConstVariableOriginKind::MiscVariable,
38+
span: rustc_span::DUMMY_SP,
39+
},
40+
ConstVariableValue::Unknown { origin, universe: _ } => origin,
41+
})
3542
.collect(),
3643
)
3744
}

Diff for: compiler/rustc_infer/src/infer/mod.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ use rustc_data_structures::unify as ut;
2323
use rustc_errors::{DiagCtxt, DiagnosticBuilder, ErrorGuaranteed};
2424
use rustc_hir::def_id::{DefId, LocalDefId};
2525
use rustc_middle::infer::canonical::{Canonical, CanonicalVarValues};
26-
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue, EffectVarValue};
2726
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
27+
use rustc_middle::infer::unify_key::{ConstVariableValue, EffectVarValue};
2828
use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult};
2929
use rustc_middle::mir::ConstraintCategory;
3030
use rustc_middle::traits::{select, DefiningAnchor};
@@ -1086,7 +1086,7 @@ impl<'tcx> InferCtxt<'tcx> {
10861086
.inner
10871087
.borrow_mut()
10881088
.const_unification_table()
1089-
.new_key(ConstVarValue { origin, val: ConstVariableValue::Unknown { universe } })
1089+
.new_key(ConstVariableValue::Unknown { origin, universe })
10901090
.vid;
10911091
ty::Const::new_var(self.tcx, vid, ty)
10921092
}
@@ -1095,10 +1095,7 @@ impl<'tcx> InferCtxt<'tcx> {
10951095
self.inner
10961096
.borrow_mut()
10971097
.const_unification_table()
1098-
.new_key(ConstVarValue {
1099-
origin,
1100-
val: ConstVariableValue::Unknown { universe: self.universe() },
1101-
})
1098+
.new_key(ConstVariableValue::Unknown { origin, universe: self.universe() })
11021099
.vid
11031100
}
11041101

@@ -1217,10 +1214,7 @@ impl<'tcx> InferCtxt<'tcx> {
12171214
.inner
12181215
.borrow_mut()
12191216
.const_unification_table()
1220-
.new_key(ConstVarValue {
1221-
origin,
1222-
val: ConstVariableValue::Unknown { universe: self.universe() },
1223-
})
1217+
.new_key(ConstVariableValue::Unknown { origin, universe: self.universe() })
12241218
.vid;
12251219
ty::Const::new_var(
12261220
self.tcx,
@@ -1410,9 +1404,9 @@ impl<'tcx> InferCtxt<'tcx> {
14101404
}
14111405

14121406
pub fn probe_const_var(&self, vid: ty::ConstVid) -> Result<ty::Const<'tcx>, ty::UniverseIndex> {
1413-
match self.inner.borrow_mut().const_unification_table().probe_value(vid).val {
1407+
match self.inner.borrow_mut().const_unification_table().probe_value(vid) {
14141408
ConstVariableValue::Known { value } => Ok(value),
1415-
ConstVariableValue::Unknown { universe } => Err(universe),
1409+
ConstVariableValue::Unknown { origin: _, universe } => Err(universe),
14161410
}
14171411
}
14181412

@@ -1709,7 +1703,7 @@ impl<'tcx> InferCtxt<'tcx> {
17091703
// `ty::ConstKind::Infer(ty::InferConst::Var(v))`.
17101704
//
17111705
// Not `inlined_probe_value(v)` because this call site is colder.
1712-
match self.inner.borrow_mut().const_unification_table().probe_value(v).val {
1706+
match self.inner.borrow_mut().const_unification_table().probe_value(v) {
17131707
ConstVariableValue::Unknown { .. } => false,
17141708
ConstVariableValue::Known { .. } => true,
17151709
}
@@ -1876,7 +1870,6 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for ShallowResolver<'a, 'tcx> {
18761870
.borrow_mut()
18771871
.const_unification_table()
18781872
.probe_value(vid)
1879-
.val
18801873
.known()
18811874
.unwrap_or(ct),
18821875
ty::ConstKind::Infer(InferConst::EffectVar(vid)) => self

Diff for: compiler/rustc_infer/src/infer/relate/combine.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ use super::sub::Sub;
3030
use crate::infer::{DefineOpaqueTypes, InferCtxt, TypeTrace};
3131
use crate::traits::{Obligation, PredicateObligations};
3232
use rustc_middle::infer::canonical::OriginalQueryValues;
33-
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue, EffectVarValue};
34-
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
33+
use rustc_middle::infer::unify_key::{ConstVariableValue, EffectVarValue};
3534
use rustc_middle::ty::error::{ExpectedFound, TypeError};
3635
use rustc_middle::ty::relate::{RelateResult, TypeRelation};
3736
use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeVisitableExt};
3837
use rustc_middle::ty::{AliasRelationDirection, TyVar};
3938
use rustc_middle::ty::{IntType, UintType};
40-
use rustc_span::DUMMY_SP;
4139

4240
#[derive(Clone)]
4341
pub struct CombineFields<'infcx, 'tcx> {
@@ -328,8 +326,12 @@ impl<'tcx> InferCtxt<'tcx> {
328326
ct: ty::Const<'tcx>,
329327
param_env: ty::ParamEnv<'tcx>,
330328
) -> RelateResult<'tcx, ty::Const<'tcx>> {
331-
let span =
332-
self.inner.borrow_mut().const_unification_table().probe_value(target_vid).origin.span;
329+
let span = match self.inner.borrow_mut().const_unification_table().probe_value(target_vid) {
330+
ConstVariableValue::Known { value } => {
331+
bug!("instantiating a known const var: {target_vid:?} {value} {ct}")
332+
}
333+
ConstVariableValue::Unknown { origin, universe: _ } => origin.span,
334+
};
333335
// FIXME(generic_const_exprs): Occurs check failures for unevaluated
334336
// constants and generic expressions are not yet handled correctly.
335337
let Generalization { value_may_be_infer: value, needs_wf: _ } = generalize::generalize(
@@ -340,16 +342,10 @@ impl<'tcx> InferCtxt<'tcx> {
340342
ty::Variance::Invariant,
341343
)?;
342344

343-
self.inner.borrow_mut().const_unification_table().union_value(
344-
target_vid,
345-
ConstVarValue {
346-
origin: ConstVariableOrigin {
347-
kind: ConstVariableOriginKind::ConstInference,
348-
span: DUMMY_SP,
349-
},
350-
val: ConstVariableValue::Known { value },
351-
},
352-
);
345+
self.inner
346+
.borrow_mut()
347+
.const_unification_table()
348+
.union_value(target_vid, ConstVariableValue::Known { value });
353349
Ok(value)
354350
}
355351

Diff for: compiler/rustc_infer/src/infer/relate/generalize.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::mem;
33
use rustc_data_structures::sso::SsoHashMap;
44
use rustc_data_structures::stack::ensure_sufficient_stack;
55
use rustc_hir::def_id::DefId;
6-
use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
6+
use rustc_middle::infer::unify_key::ConstVariableValue;
77
use rustc_middle::ty::error::TypeError;
88
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
99
use rustc_middle::ty::visit::MaxUniverse;
@@ -431,22 +431,19 @@ where
431431

432432
let mut inner = self.infcx.inner.borrow_mut();
433433
let variable_table = &mut inner.const_unification_table();
434-
let var_value = variable_table.probe_value(vid);
435-
match var_value.val {
434+
match variable_table.probe_value(vid) {
436435
ConstVariableValue::Known { value: u } => {
437436
drop(inner);
438437
self.relate(u, u)
439438
}
440-
ConstVariableValue::Unknown { universe } => {
439+
ConstVariableValue::Unknown { origin, universe } => {
441440
if self.for_universe.can_name(universe) {
442441
Ok(c)
443442
} else {
444443
let new_var_id = variable_table
445-
.new_key(ConstVarValue {
446-
origin: var_value.origin,
447-
val: ConstVariableValue::Unknown {
448-
universe: self.for_universe,
449-
},
444+
.new_key(ConstVariableValue::Unknown {
445+
origin,
446+
universe: self.for_universe,
450447
})
451448
.vid;
452449
Ok(ty::Const::new_var(self.tcx(), new_var_id, c.ty()))

0 commit comments

Comments
 (0)