Skip to content

Commit fe843fe

Browse files
committedMay 9, 2024
Use fewer origins when creating type variables.
`InferCtxt::next_{ty,const}_var*` all take an origin, but the `param_def_id` is almost always `None`. This commit changes them to just take a `Span` and build the origin within the method, and adds new methods for the rare cases where `param_def_id` might not be `None`. This avoids a lot of tedious origin building. Specifically: - next_ty_var{,_id_in_universe,_in_universe}: now take `Span` instead of `TypeVariableOrigin` - next_ty_var_with_origin: added - next_const_var{,_in_universe}: takes Span instead of ConstVariableOrigin - next_const_var_with_origin: added - next_region_var, next_region_var_in_universe: these are unchanged, still take RegionVariableOrigin The API inconsistency (ty/const vs region) seems worth it for the large conciseness improvements.
1 parent 11f2ca3 commit fe843fe

File tree

41 files changed

+119
-312
lines changed

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

+119
-312
lines changed
 

‎compiler/rustc_borrowck/src/type_check/input_output.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use std::assert_matches::assert_matches;
1111

1212
use itertools::Itertools;
1313
use rustc_hir as hir;
14-
use rustc_infer::infer::type_variable::TypeVariableOrigin;
1514
use rustc_infer::infer::{BoundRegionConversionTime, RegionVariableOrigin};
1615
use rustc_middle::mir::*;
1716
use rustc_middle::ty::{self, Ty};
@@ -74,9 +73,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
7473
}),
7574
);
7675

77-
let next_ty_var = || {
78-
self.infcx.next_ty_var(TypeVariableOrigin { span: body.span, param_def_id: None })
79-
};
76+
let next_ty_var = || self.infcx.next_ty_var(body.span);
8077
let output_ty = Ty::new_coroutine(
8178
self.tcx(),
8279
self.tcx().coroutine_for_closure(mir_def_id),

‎compiler/rustc_borrowck/src/type_check/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use rustc_index::{IndexSlice, IndexVec};
1616
use rustc_infer::infer::canonical::QueryRegionConstraints;
1717
use rustc_infer::infer::outlives::env::RegionBoundPairs;
1818
use rustc_infer::infer::region_constraints::RegionConstraintData;
19-
use rustc_infer::infer::type_variable::TypeVariableOrigin;
2019
use rustc_infer::infer::{
2120
BoundRegion, BoundRegionConversionTime, InferCtxt, NllRegionVariableOrigin,
2221
};
@@ -2356,10 +2355,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
23562355
// Types with regions are comparable if they have a common super-type.
23572356
ty::RawPtr(_, _) | ty::FnPtr(_) => {
23582357
let ty_right = right.ty(body, tcx);
2359-
let common_ty = self.infcx.next_ty_var(TypeVariableOrigin {
2360-
param_def_id: None,
2361-
span: body.source_info(location).span,
2362-
});
2358+
let common_ty = self.infcx.next_ty_var(body.source_info(location).span);
23632359
self.sub_types(
23642360
ty_left,
23652361
common_ty,

0 commit comments

Comments
 (0)