Skip to content

Commit fe14db9

Browse files
authored
Rollup merge of rust-lang#60742 - varkor:fn-const-array-parameter, r=eddyb
Allow const parameters in array sizes to be unified Fixes rust-lang#60632. Fixes rust-lang#60744. Fixes rust-lang#60923. (The last commit should probably be viewed in isolation, as it just renames things from `type` to `kind`.) r? @eddyb
2 parents 7212685 + 6233d1f commit fe14db9

Some content is hidden

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

66 files changed

+395
-198
lines changed

src/librustc/infer/error_reporting/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
652652
for sp in prior_arms {
653653
err.span_label(*sp, format!(
654654
"this is found to be of type `{}`",
655-
self.resolve_type_vars_if_possible(&last_ty),
655+
self.resolve_vars_if_possible(&last_ty),
656656
));
657657
}
658658
} else if let Some(sp) = prior_arms.last() {
@@ -1278,7 +1278,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12781278
&self,
12791279
exp_found: &ty::error::ExpectedFound<Ty<'tcx>>,
12801280
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
1281-
let exp_found = self.resolve_type_vars_if_possible(exp_found);
1281+
let exp_found = self.resolve_vars_if_possible(exp_found);
12821282
if exp_found.references_error() {
12831283
return None;
12841284
}
@@ -1291,7 +1291,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12911291
&self,
12921292
exp_found: &ty::error::ExpectedFound<T>,
12931293
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
1294-
let exp_found = self.resolve_type_vars_if_possible(exp_found);
1294+
let exp_found = self.resolve_vars_if_possible(exp_found);
12951295
if exp_found.references_error() {
12961296
return None;
12971297
}

src/librustc/infer/error_reporting/need_type_info.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ impl<'a, 'gcx, 'tcx> FindLocalByTypeVisitor<'a, 'gcx, 'tcx> {
2424
});
2525
match ty_opt {
2626
Some(ty) => {
27-
let ty = self.infcx.resolve_type_vars_if_possible(&ty);
27+
let ty = self.infcx.resolve_vars_if_possible(&ty);
2828
ty.walk().any(|inner_ty| {
2929
inner_ty == self.target_ty || match (&inner_ty.sty, &self.target_ty.sty) {
3030
(&Infer(TyVar(a_vid)), &Infer(TyVar(b_vid))) => {
@@ -94,7 +94,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
9494
span: Span,
9595
ty: Ty<'tcx>
9696
) -> DiagnosticBuilder<'gcx> {
97-
let ty = self.resolve_type_vars_if_possible(&ty);
97+
let ty = self.resolve_vars_if_possible(&ty);
9898
let name = self.extract_type_name(&ty, None);
9999

100100
let mut err_span = span;
@@ -166,7 +166,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
166166
span: Span,
167167
ty: Ty<'tcx>
168168
) -> DiagnosticBuilder<'gcx> {
169-
let ty = self.resolve_type_vars_if_possible(&ty);
169+
let ty = self.resolve_vars_if_possible(&ty);
170170
let name = self.extract_type_name(&ty, None);
171171

172172
let mut err = struct_span_err!(self.tcx.sess,

src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,11 @@ impl NiceRegionError<'me, 'gcx, 'tcx> {
210210
_ => (),
211211
}
212212

213-
let expected_trait_ref = self.infcx.resolve_type_vars_if_possible(&ty::TraitRef {
213+
let expected_trait_ref = self.infcx.resolve_vars_if_possible(&ty::TraitRef {
214214
def_id: trait_def_id,
215215
substs: expected_substs,
216216
});
217-
let actual_trait_ref = self.infcx.resolve_type_vars_if_possible(&ty::TraitRef {
217+
let actual_trait_ref = self.infcx.resolve_vars_if_possible(&ty::TraitRef {
218218
def_id: trait_def_id,
219219
substs: actual_substs,
220220
});

src/librustc/infer/fudge.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
7474
let (mut fudger, value) = self.probe(|snapshot| {
7575
match f() {
7676
Ok(value) => {
77-
let value = self.resolve_type_vars_if_possible(&value);
77+
let value = self.resolve_vars_if_possible(&value);
7878

7979
// At this point, `value` could in principle refer
8080
// to inference variables that have been created during

src/librustc/infer/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11741174
/// Process the region constraints and report any errors that
11751175
/// result. After this, no more unification operations should be
11761176
/// done -- or the compiler will panic -- but it is legal to use
1177-
/// `resolve_type_vars_if_possible` as well as `fully_resolve`.
1177+
/// `resolve_vars_if_possible` as well as `fully_resolve`.
11781178
pub fn resolve_regions_and_report_errors(
11791179
&self,
11801180
region_context: DefId,
@@ -1262,7 +1262,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12621262
}
12631263

12641264
pub fn ty_to_string(&self, t: Ty<'tcx>) -> String {
1265-
self.resolve_type_vars_if_possible(&t).to_string()
1265+
self.resolve_vars_if_possible(&t).to_string()
12661266
}
12671267

12681268
pub fn tys_to_string(&self, ts: &[Ty<'tcx>]) -> String {
@@ -1271,7 +1271,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12711271
}
12721272

12731273
pub fn trait_ref_to_string(&self, t: &ty::TraitRef<'tcx>) -> String {
1274-
self.resolve_type_vars_if_possible(t).to_string()
1274+
self.resolve_vars_if_possible(t).to_string()
12751275
}
12761276

12771277
/// If `TyVar(vid)` resolves to a type, return that type. Else, return the
@@ -1297,28 +1297,28 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12971297
self.type_variables.borrow_mut().root_var(var)
12981298
}
12991299

1300-
/// Where possible, replaces type/int/float variables in
1300+
/// Where possible, replaces type/const variables in
13011301
/// `value` with their final value. Note that region variables
1302-
/// are unaffected. If a type variable has not been unified, it
1302+
/// are unaffected. If a type/const variable has not been unified, it
13031303
/// is left as is. This is an idempotent operation that does
13041304
/// not affect inference state in any way and so you can do it
13051305
/// at will.
1306-
pub fn resolve_type_vars_if_possible<T>(&self, value: &T) -> T
1306+
pub fn resolve_vars_if_possible<T>(&self, value: &T) -> T
13071307
where
13081308
T: TypeFoldable<'tcx>,
13091309
{
13101310
if !value.needs_infer() {
13111311
return value.clone(); // avoid duplicated subst-folding
13121312
}
1313-
let mut r = resolve::OpportunisticTypeResolver::new(self);
1313+
let mut r = resolve::OpportunisticVarResolver::new(self);
13141314
value.fold_with(&mut r)
13151315
}
13161316

13171317
/// Returns first unresolved variable contained in `T`. In the
13181318
/// process of visiting `T`, this will resolve (where possible)
13191319
/// type variables in `T`, but it never constructs the final,
13201320
/// resolved type, so it's more efficient than
1321-
/// `resolve_type_vars_if_possible()`.
1321+
/// `resolve_vars_if_possible()`.
13221322
pub fn unresolved_type_vars<T>(&self, value: &T) -> Option<(Ty<'tcx>, Option<Span>)>
13231323
where
13241324
T: TypeFoldable<'tcx>,
@@ -1389,7 +1389,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13891389
where
13901390
M: FnOnce(String) -> DiagnosticBuilder<'tcx>,
13911391
{
1392-
let actual_ty = self.resolve_type_vars_if_possible(&actual_ty);
1392+
let actual_ty = self.resolve_vars_if_possible(&actual_ty);
13931393
debug!("type_error_struct_with_diag({:?}, {:?})", sp, actual_ty);
13941394

13951395
// Don't report an error if actual type is `Error`.
@@ -1446,7 +1446,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14461446
ty: Ty<'tcx>,
14471447
span: Span,
14481448
) -> bool {
1449-
let ty = self.resolve_type_vars_if_possible(&ty);
1449+
let ty = self.resolve_vars_if_possible(&ty);
14501450

14511451
// Even if the type may have no inference variables, during
14521452
// type-checking closure types are in local tables only.

src/librustc/infer/opaque_types/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
286286

287287
let tcx = self.tcx;
288288

289-
let concrete_ty = self.resolve_type_vars_if_possible(&opaque_defn.concrete_ty);
289+
let concrete_ty = self.resolve_vars_if_possible(&opaque_defn.concrete_ty);
290290

291291
debug!("constrain_opaque_type: concrete_ty={:?}", concrete_ty);
292292

src/librustc/infer/outlives/env.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<'a, 'gcx: 'tcx, 'tcx: 'a> OutlivesEnvironment<'tcx> {
168168
debug!("add_implied_bounds()");
169169

170170
for &ty in fn_sig_tys {
171-
let ty = infcx.resolve_type_vars_if_possible(&ty);
171+
let ty = infcx.resolve_vars_if_possible(&ty);
172172
debug!("add_implied_bounds: ty = {}", ty);
173173
let implied_bounds = infcx.implied_outlives_bounds(self.param_env, body_id, ty, span);
174174
self.add_outlives_bounds(Some(infcx), implied_bounds)

src/librustc/infer/outlives/obligations.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
177177
sup_type, sub_region, origin
178178
);
179179

180-
let sup_type = self.resolve_type_vars_if_possible(&sup_type);
180+
let sup_type = self.resolve_vars_if_possible(&sup_type);
181181

182182
if let Some(region_bound_pairs) = region_bound_pairs_map.get(&body_id) {
183183
let outlives = &mut TypeOutlives::new(
@@ -215,7 +215,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
215215
implicit_region_bound,
216216
param_env,
217217
);
218-
let ty = self.resolve_type_vars_if_possible(&ty);
218+
let ty = self.resolve_vars_if_possible(&ty);
219219
outlives.type_must_outlive(origin, ty, region);
220220
}
221221
}

src/librustc/infer/resolve.rs

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
use super::{InferCtxt, FixupError, FixupResult, Span, type_variable::TypeVariableOrigin};
22
use crate::mir::interpret::ConstValue;
3-
use crate::ty::{self, Ty, TyCtxt, TypeFoldable, InferConst};
3+
use crate::ty::{self, Ty, Const, TyCtxt, TypeFoldable, InferConst, TypeFlags};
44
use crate::ty::fold::{TypeFolder, TypeVisitor};
55

66
///////////////////////////////////////////////////////////////////////////
7-
// OPPORTUNISTIC TYPE RESOLVER
7+
// OPPORTUNISTIC VAR RESOLVER
88

9-
/// The opportunistic type resolver can be used at any time. It simply replaces
10-
/// type variables that have been unified with the things they have
9+
/// The opportunistic resolver can be used at any time. It simply replaces
10+
/// type/const variables that have been unified with the things they have
1111
/// been unified with (similar to `shallow_resolve`, but deep). This is
1212
/// useful for printing messages etc but also required at various
1313
/// points for correctness.
14-
pub struct OpportunisticTypeResolver<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
14+
pub struct OpportunisticVarResolver<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
1515
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
1616
}
1717

18-
impl<'a, 'gcx, 'tcx> OpportunisticTypeResolver<'a, 'gcx, 'tcx> {
18+
impl<'a, 'gcx, 'tcx> OpportunisticVarResolver<'a, 'gcx, 'tcx> {
1919
#[inline]
2020
pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>) -> Self {
21-
OpportunisticTypeResolver { infcx }
21+
OpportunisticVarResolver { infcx }
2222
}
2323
}
2424

25-
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for OpportunisticTypeResolver<'a, 'gcx, 'tcx> {
25+
impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for OpportunisticVarResolver<'a, 'gcx, 'tcx> {
2626
fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> {
2727
self.infcx.tcx
2828
}
@@ -31,8 +31,17 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for OpportunisticTypeResolver<'a, 'g
3131
if !t.has_infer_types() {
3232
t // micro-optimize -- if there is nothing in this type that this fold affects...
3333
} else {
34-
let t0 = self.infcx.shallow_resolve(t);
35-
t0.super_fold_with(self)
34+
let t = self.infcx.shallow_resolve(t);
35+
t.super_fold_with(self)
36+
}
37+
}
38+
39+
fn fold_const(&mut self, ct: &'tcx Const<'tcx>) -> &'tcx Const<'tcx> {
40+
if !ct.has_type_flags(TypeFlags::HAS_CT_INFER) {
41+
ct // micro-optimize -- if there is nothing in this const that this fold affects...
42+
} else {
43+
let ct = self.infcx.shallow_resolve(ct);
44+
ct.super_fold_with(self)
3645
}
3746
}
3847
}

src/librustc/middle/mem_categorization.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -458,10 +458,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
458458
.unwrap_or(true)
459459
}
460460

461-
fn resolve_type_vars_if_possible<T>(&self, value: &T) -> T
461+
fn resolve_vars_if_possible<T>(&self, value: &T) -> T
462462
where T: TypeFoldable<'tcx>
463463
{
464-
self.infcx.map(|infcx| infcx.resolve_type_vars_if_possible(value))
464+
self.infcx.map(|infcx| infcx.resolve_vars_if_possible(value))
465465
.unwrap_or_else(|| value.clone())
466466
}
467467

@@ -475,7 +475,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
475475
-> McResult<Ty<'tcx>> {
476476
match ty {
477477
Some(ty) => {
478-
let ty = self.resolve_type_vars_if_possible(&ty);
478+
let ty = self.resolve_vars_if_possible(&ty);
479479
if ty.references_error() || ty.is_ty_var() {
480480
debug!("resolve_type_vars_or_error: error from {:?}", ty);
481481
Err(())
@@ -602,7 +602,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> {
602602
where F: FnOnce() -> McResult<cmt_<'tcx>>
603603
{
604604
debug!("cat_expr_adjusted_with({:?}): {:?}", adjustment, expr);
605-
let target = self.resolve_type_vars_if_possible(&adjustment.target);
605+
let target = self.resolve_vars_if_possible(&adjustment.target);
606606
match adjustment.kind {
607607
adjustment::Adjust::Deref(overloaded) => {
608608
// Equivalent to *expr or something similar.

src/librustc/traits/auto_trait.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,9 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
307307
continue;
308308
}
309309

310-
// Call infcx.resolve_type_vars_if_possible to see if we can
310+
// Call infcx.resolve_vars_if_possible to see if we can
311311
// get rid of any inference variables.
312-
let obligation = infcx.resolve_type_vars_if_possible(
312+
let obligation = infcx.resolve_vars_if_possible(
313313
&Obligation::new(dummy_cause.clone(), new_env, pred)
314314
);
315315
let result = select.select(&obligation);
@@ -642,7 +642,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
642642
fresh_preds.insert(self.clean_pred(select.infcx(), predicate));
643643

644644
// Resolve any inference variables that we can, to help selection succeed
645-
predicate = select.infcx().resolve_type_vars_if_possible(&predicate);
645+
predicate = select.infcx().resolve_vars_if_possible(&predicate);
646646

647647
// We only add a predicate as a user-displayable bound if
648648
// it involves a generic parameter, and doesn't contain

src/librustc/traits/chalk_fulfill.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fn in_environment(
3333
obligation: PredicateObligation<'tcx>
3434
) -> InEnvironment<'tcx, PredicateObligation<'tcx>> {
3535
assert!(!infcx.is_in_snapshot());
36-
let obligation = infcx.resolve_type_vars_if_possible(&obligation);
36+
let obligation = infcx.resolve_vars_if_possible(&obligation);
3737

3838
let environment = match obligation.param_env.def_id {
3939
Some(def_id) => infcx.tcx.environment(def_id),

src/librustc/traits/codegen/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
153153
bug!("Encountered errors `{:?}` resolving bounds after type-checking", errors);
154154
}
155155

156-
let result = self.resolve_type_vars_if_possible(result);
156+
let result = self.resolve_vars_if_possible(result);
157157
let result = self.tcx.erase_regions(&result);
158158

159159
self.tcx.lift_to_global(&result).unwrap_or_else(||
160-
bug!("Uninferred types/regions in `{:?}`", result)
160+
bug!("Uninferred types/regions/consts in `{:?}`", result)
161161
)
162162
}
163163
}

src/librustc/traits/coherence.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ fn overlap_within_probe(
155155
a_impl_header.predicates
156156
.iter()
157157
.chain(&b_impl_header.predicates)
158-
.map(|p| infcx.resolve_type_vars_if_possible(p))
158+
.map(|p| infcx.resolve_vars_if_possible(p))
159159
.map(|p| Obligation { cause: ObligationCause::dummy(),
160160
param_env,
161161
recursion_depth: 0,
@@ -171,7 +171,7 @@ fn overlap_within_probe(
171171
return None
172172
}
173173

174-
let impl_header = selcx.infcx().resolve_type_vars_if_possible(&a_impl_header);
174+
let impl_header = selcx.infcx().resolve_vars_if_possible(&a_impl_header);
175175
let intercrate_ambiguity_causes = selcx.take_intercrate_ambiguity_causes();
176176
debug!("overlap: intercrate_ambiguity_causes={:#?}", intercrate_ambiguity_causes);
177177

0 commit comments

Comments
 (0)