Skip to content

Commit cb0d74b

Browse files
authored
Rollup merge of rust-lang#120958 - ShoyuVanilla:remove-subst, r=oli-obk
Dejargonize `subst` In favor of rust-lang#110793, replace almost every occurence of `subst` and `substitution` from rustc codes, but they still remains in subtrees under `src/tools/` like clippy and test codes (I'd like to replace them after this)
2 parents 15896bd + 8959434 commit cb0d74b

File tree

130 files changed

+576
-543
lines changed

Some content is hidden

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

130 files changed

+576
-543
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
691691

692692
// If the type is opaque/param/closure, and it is Fn or FnMut, let's suggest (mutably)
693693
// borrowing the type, since `&mut F: FnMut` iff `F: FnMut` and similarly for `Fn`.
694-
// These types seem reasonably opaque enough that they could be substituted with their
694+
// These types seem reasonably opaque enough that they could be instantiated with their
695695
// borrowed variants in a function body when we see a move error.
696696
let borrow_level = match *ty.kind() {
697697
ty::Param(_) => tcx

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
4545
/// be allowed:
4646
/// `fn f<'a: 'b, 'b: 'a>(x: *mut &'b i32) -> impl Sized + 'a { x }`
4747
///
48-
/// Then we map the regions in both the type and the subst to their
48+
/// Then we map the regions in both the type and the generic parameters to their
4949
/// `external_name` giving `concrete_type = &'a i32`,
5050
/// `args = ['static, 'a]`. This will then allow
5151
/// `infer_opaque_definition_from_instantiation` to determine that
@@ -77,9 +77,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
7777
let args = opaque_type_key.args;
7878
debug!(?concrete_type, ?args);
7979

80-
let mut subst_regions = vec![self.universal_regions.fr_static];
80+
let mut arg_regions = vec![self.universal_regions.fr_static];
8181

82-
let to_universal_region = |vid, subst_regions: &mut Vec<_>| {
82+
let to_universal_region = |vid, arg_regions: &mut Vec<_>| {
8383
trace!(?vid);
8484
let scc = self.constraint_sccs.scc(vid);
8585
trace!(?scc);
@@ -88,11 +88,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
8888
}) {
8989
Some(region) => {
9090
let vid = self.universal_regions.to_region_vid(region);
91-
subst_regions.push(vid);
91+
arg_regions.push(vid);
9292
region
9393
}
9494
None => {
95-
subst_regions.push(vid);
95+
arg_regions.push(vid);
9696
ty::Region::new_error_with_message(
9797
infcx.tcx,
9898
concrete_type.span,
@@ -106,10 +106,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
106106
// This will ensure they get precedence when folding the regions in the concrete type.
107107
if let Some(&ci) = member_constraints.get(&opaque_type_key) {
108108
for &vid in self.member_constraints.choice_regions(ci) {
109-
to_universal_region(vid, &mut subst_regions);
109+
to_universal_region(vid, &mut arg_regions);
110110
}
111111
}
112-
debug!(?subst_regions);
112+
debug!(?arg_regions);
113113

114114
// Next, insert universal regions from args, so we can translate regions that appear
115115
// in them but are not subject to member constraints, for instance closure args.
@@ -119,18 +119,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
119119
return region;
120120
}
121121
let vid = self.to_region_vid(region);
122-
to_universal_region(vid, &mut subst_regions)
122+
to_universal_region(vid, &mut arg_regions)
123123
});
124124
debug!(?universal_args);
125-
debug!(?subst_regions);
125+
debug!(?arg_regions);
126126

127127
// Deduplicate the set of regions while keeping the chosen order.
128-
let subst_regions = subst_regions.into_iter().collect::<FxIndexSet<_>>();
129-
debug!(?subst_regions);
128+
let arg_regions = arg_regions.into_iter().collect::<FxIndexSet<_>>();
129+
debug!(?arg_regions);
130130

131131
let universal_concrete_type =
132132
infcx.tcx.fold_regions(concrete_type, |region, _| match *region {
133-
ty::ReVar(vid) => subst_regions
133+
ty::ReVar(vid) => arg_regions
134134
.iter()
135135
.find(|ur_vid| self.eval_equal(vid, **ur_vid))
136136
.and_then(|ur_vid| self.definitions[*ur_vid].external_name)

compiler/rustc_const_eval/src/interpret/eval_context.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -554,18 +554,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
554554

555555
/// Call this on things you got out of the MIR (so it is as generic as the current
556556
/// stack frame), to bring it into the proper environment for this interpreter.
557-
pub(super) fn subst_from_current_frame_and_normalize_erasing_regions<
557+
pub(super) fn instantiate_from_current_frame_and_normalize_erasing_regions<
558558
T: TypeFoldable<TyCtxt<'tcx>>,
559559
>(
560560
&self,
561561
value: T,
562562
) -> Result<T, ErrorHandled> {
563-
self.subst_from_frame_and_normalize_erasing_regions(self.frame(), value)
563+
self.instantiate_from_frame_and_normalize_erasing_regions(self.frame(), value)
564564
}
565565

566566
/// Call this on things you got out of the MIR (so it is as generic as the provided
567567
/// stack frame), to bring it into the proper environment for this interpreter.
568-
pub(super) fn subst_from_frame_and_normalize_erasing_regions<T: TypeFoldable<TyCtxt<'tcx>>>(
568+
pub(super) fn instantiate_from_frame_and_normalize_erasing_regions<
569+
T: TypeFoldable<TyCtxt<'tcx>>,
570+
>(
569571
&self,
570572
frame: &Frame<'mir, 'tcx, M::Provenance, M::FrameExtra>,
571573
value: T,
@@ -656,7 +658,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
656658

657659
let layout = from_known_layout(self.tcx, self.param_env, layout, || {
658660
let local_ty = frame.body.local_decls[local].ty;
659-
let local_ty = self.subst_from_frame_and_normalize_erasing_regions(frame, local_ty)?;
661+
let local_ty =
662+
self.instantiate_from_frame_and_normalize_erasing_regions(frame, local_ty)?;
660663
self.layout_of(local_ty)
661664
})?;
662665

@@ -791,8 +794,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
791794
// Make sure all the constants required by this frame evaluate successfully (post-monomorphization check).
792795
if M::POST_MONO_CHECKS {
793796
for &const_ in &body.required_consts {
794-
let c =
795-
self.subst_from_current_frame_and_normalize_erasing_regions(const_.const_)?;
797+
let c = self
798+
.instantiate_from_current_frame_and_normalize_erasing_regions(const_.const_)?;
796799
c.eval(*self.tcx, self.param_env, Some(const_.span)).map_err(|err| {
797800
err.emit_note(*self.tcx);
798801
err

compiler/rustc_const_eval/src/interpret/operand.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
696696
trace!("eval_place_to_op: got {:?}", op);
697697
// Sanity-check the type we ended up with.
698698
if cfg!(debug_assertions) {
699-
let normalized_place_ty = self.subst_from_current_frame_and_normalize_erasing_regions(
700-
mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty,
701-
)?;
699+
let normalized_place_ty = self
700+
.instantiate_from_current_frame_and_normalize_erasing_regions(
701+
mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty,
702+
)?;
702703
if !mir_assign_valid_types(
703704
*self.tcx,
704705
self.param_env,
@@ -731,8 +732,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
731732
&Copy(place) | &Move(place) => self.eval_place_to_op(place, layout)?,
732733

733734
Constant(constant) => {
734-
let c =
735-
self.subst_from_current_frame_and_normalize_erasing_regions(constant.const_)?;
735+
let c = self.instantiate_from_current_frame_and_normalize_erasing_regions(
736+
constant.const_,
737+
)?;
736738

737739
// This can still fail:
738740
// * During ConstProp, with `TooGeneric` or since the `required_consts` were not all

compiler/rustc_const_eval/src/interpret/place.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,10 @@ where
542542
trace!("{:?}", self.dump_place(&place));
543543
// Sanity-check the type we ended up with.
544544
if cfg!(debug_assertions) {
545-
let normalized_place_ty = self.subst_from_current_frame_and_normalize_erasing_regions(
546-
mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty,
547-
)?;
545+
let normalized_place_ty = self
546+
.instantiate_from_current_frame_and_normalize_erasing_regions(
547+
mir_place.ty(&self.frame().body.local_decls, *self.tcx).ty,
548+
)?;
548549
if !mir_assign_valid_types(
549550
*self.tcx,
550551
self.param_env,

compiler/rustc_const_eval/src/interpret/step.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
235235
}
236236

237237
NullaryOp(ref null_op, ty) => {
238-
let ty = self.subst_from_current_frame_and_normalize_erasing_regions(ty)?;
238+
let ty = self.instantiate_from_current_frame_and_normalize_erasing_regions(ty)?;
239239
let layout = self.layout_of(ty)?;
240240
if let mir::NullOp::SizeOf | mir::NullOp::AlignOf = null_op
241241
&& layout.is_unsized()
@@ -276,7 +276,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
276276
Cast(cast_kind, ref operand, cast_ty) => {
277277
let src = self.eval_operand(operand, None)?;
278278
let cast_ty =
279-
self.subst_from_current_frame_and_normalize_erasing_regions(cast_ty)?;
279+
self.instantiate_from_current_frame_and_normalize_erasing_regions(cast_ty)?;
280280
self.cast(&src, cast_kind, cast_ty, &dest)?;
281281
}
282282

compiler/rustc_const_eval/src/interpret/terminator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
173173
Drop { place, target, unwind, replace: _ } => {
174174
let frame = self.frame();
175175
let ty = place.ty(&frame.body.local_decls, *self.tcx).ty;
176-
let ty = self.subst_from_frame_and_normalize_erasing_regions(frame, ty)?;
176+
let ty = self.instantiate_from_frame_and_normalize_erasing_regions(frame, ty)?;
177177
let instance = Instance::resolve_drop_in_place(*self.tcx, ty);
178178
if let ty::InstanceDef::DropGlue(_, None) = instance.def {
179179
// This is the branch we enter if and only if the dropped type has no drop glue
@@ -672,8 +672,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
672672
// Construct the destination place for this argument. At this point all
673673
// locals are still dead, so we cannot construct a `PlaceTy`.
674674
let dest = mir::Place::from(local);
675-
// `layout_of_local` does more than just the substitution we need to get the
676-
// type, but the result gets cached so this avoids calling the substitution
675+
// `layout_of_local` does more than just the instantiation we need to get the
676+
// type, but the result gets cached so this avoids calling the instantiation
677677
// query *again* the next time this local is accessed.
678678
let ty = self.layout_of_local(self.frame(), local, None)?.ty;
679679
if Some(local) == body.spread_arg {

compiler/rustc_const_eval/src/interpret/util.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ where
1919
}
2020

2121
struct FoundParam;
22-
struct UsedParamsNeedSubstVisitor<'tcx> {
22+
struct UsedParamsNeedInstantiationVisitor<'tcx> {
2323
tcx: TyCtxt<'tcx>,
2424
}
2525

26-
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for UsedParamsNeedSubstVisitor<'tcx> {
26+
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for UsedParamsNeedInstantiationVisitor<'tcx> {
2727
type BreakTy = FoundParam;
2828

2929
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
@@ -39,17 +39,17 @@ where
3939
| ty::FnDef(def_id, args) => {
4040
let instance = ty::InstanceDef::Item(def_id);
4141
let unused_params = self.tcx.unused_generic_params(instance);
42-
for (index, subst) in args.into_iter().enumerate() {
42+
for (index, arg) in args.into_iter().enumerate() {
4343
let index = index
4444
.try_into()
4545
.expect("more generic parameters than can fit into a `u32`");
4646
// Only recurse when generic parameters in fns, closures and coroutines
4747
// are used and have to be instantiated.
4848
//
49-
// Just in case there are closures or coroutines within this subst,
49+
// Just in case there are closures or coroutines within this arg,
5050
// recurse.
51-
if unused_params.is_used(index) && subst.has_param() {
52-
return subst.visit_with(self);
51+
if unused_params.is_used(index) && arg.has_param() {
52+
return arg.visit_with(self);
5353
}
5454
}
5555
ControlFlow::Continue(())
@@ -66,7 +66,7 @@ where
6666
}
6767
}
6868

69-
let mut vis = UsedParamsNeedSubstVisitor { tcx };
69+
let mut vis = UsedParamsNeedInstantiationVisitor { tcx };
7070
if matches!(ty.visit_with(&mut vis), ControlFlow::Break(FoundParam)) {
7171
throw_inval!(TooGeneric);
7272
} else {

compiler/rustc_error_codes/src/error_codes/E0139.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ fn foo<T>(x: Vec<T>) {
2222
In this specific case there's a good chance that the transmute is harmless (but
2323
this is not guaranteed by Rust). However, when alignment and enum optimizations
2424
come into the picture, it's quite likely that the sizes may or may not match
25-
with different type parameter substitutions. It's not possible to check this for
26-
_all_ possible types, so `transmute()` simply only accepts types without any
27-
unsubstituted type parameters.
25+
with different type parameter instantiations. It's not possible to check this
26+
for _all_ possible types, so `transmute()` simply only accepts types without any
27+
uninstantiated type parameters.
2828

2929
If you need this, there's a good chance you're doing something wrong. Keep in
3030
mind that Rust doesn't guarantee much about the layout of different structs
3131
(even two structs with identical declarations may have different layouts). If
3232
there is a solution that avoids the transmute entirely, try it instead.
3333

3434
If it's possible, hand-monomorphize the code by writing the function for each
35-
possible type substitution. It's possible to use traits to do this cleanly,
35+
possible type instantiation. It's possible to use traits to do this cleanly,
3636
for example:
3737

3838
```

compiler/rustc_error_codes/src/error_codes/E0230.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ There will be an error about `bool` not implementing `Index<u8>`, followed by a
1515
note saying "the type `bool` cannot be indexed by `u8`".
1616

1717
As you can see, you can specify type parameters in curly braces for
18-
substitution with the actual types (using the regular format string syntax) in
19-
a given situation. Furthermore, `{Self}` will substitute to the type (in this
20-
case, `bool`) that we tried to use.
18+
instantiation with the actual types (using the regular format string syntax) in
19+
a given situation. Furthermore, `{Self}` will be instantiated to the type (in
20+
this case, `bool`) that we tried to use.
2121

2222
This error appears when the curly braces contain an identifier which doesn't
2323
match with any of the type parameters or the string `Self`. This might happen

compiler/rustc_error_codes/src/error_codes/E0231.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ there will be an error about `bool` not implementing `Index<u8>`, followed by a
1515
note saying "the type `bool` cannot be indexed by `u8`".
1616

1717
As you can see, you can specify type parameters in curly braces for
18-
substitution with the actual types (using the regular format string syntax) in
19-
a given situation. Furthermore, `{Self}` will substitute to the type (in this
20-
case, `bool`) that we tried to use.
18+
instantiation with the actual types (using the regular format string syntax) in
19+
a given situation. Furthermore, `{Self}` will be instantiated to the type (in
20+
this case, `bool`) that we tried to use.
2121

2222
This error appears when the curly braces do not contain an identifier. Please
2323
add one of the same name as a type parameter. If you intended to use literal

compiler/rustc_error_codes/src/error_codes/E0393.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ fn together_we_will_rule_the_galaxy(son: &A) {}
1212
```
1313

1414
A trait object is defined over a single, fully-defined trait. With a regular
15-
default parameter, this parameter can just be substituted in. However, if the
15+
default parameter, this parameter can just be instantiated in. However, if the
1616
default parameter is `Self`, the trait changes for each concrete type; i.e.
1717
`i32` will be expected to implement `A<i32>`, `bool` will be expected to
1818
implement `A<bool>`, etc... These types will not share an implementation of a
1919
fully-defined trait; instead they share implementations of a trait with
20-
different parameters substituted in for each implementation. This is
20+
different parameters instantiated in for each implementation. This is
2121
irreconcilable with what we need to make a trait object work, and is thus
2222
disallowed. Making the trait concrete by explicitly specifying the value of the
2323
defaulted parameter will fix this issue. Fixed example:

compiler/rustc_error_codes/src/error_codes/E0794.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let _ = foo::<'static>;
1414

1515
The type of a concrete instance of a generic function is universally quantified
1616
over late-bound lifetime parameters. This is because we want the function to
17-
work for any lifetime substituted for the late-bound lifetime parameter, no
17+
work for any lifetime instantiated for the late-bound lifetime parameter, no
1818
matter where the function is called. Consequently, it doesn't make sense to
1919
specify arguments for late-bound lifetime parameters, since they are not
2020
resolved until the function's call site(s).
@@ -56,7 +56,7 @@ let bar_fn3 = bar::<Bar>; // OK
5656

5757
In the definition of `bar`, the lifetime parameter `'a` is late-bound, while
5858
`'b` is early-bound. This is reflected in the type annotation for `bar_fn`,
59-
where `'a` is universally quantified and `'b` is substituted by a specific
59+
where `'a` is universally quantified and `'b` is instantiated with a specific
6060
lifetime. It is not allowed to explicitly specify early-bound lifetime
6161
arguments when late-bound lifetime parameters are present (as for `bar_fn2`,
6262
see [issue #42868](https://github.com/rust-lang/rust/issues/42868)), although

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2536,7 +2536,7 @@ pub struct OpaqueTy<'hir> {
25362536
/// lifetimes that are captured from the function signature they originate from.
25372537
///
25382538
/// This is done by generating a new early-bound lifetime parameter local to the
2539-
/// opaque which is substituted in the function signature with the late-bound
2539+
/// opaque which is instantiated in the function signature with the late-bound
25402540
/// lifetime.
25412541
///
25422542
/// This mapping associated a captured lifetime (first parameter) with the new

compiler/rustc_hir_analysis/messages.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ hir_analysis_function_not_have_default_implementation = function doesn't have a
153153
hir_analysis_functions_names_duplicated = functions names are duplicated
154154
.note = all `#[rustc_must_implement_one_of]` arguments must be unique
155155
156+
hir_analysis_generic_args_on_overridden_impl = could not resolve generic parameters on overridden impl
157+
156158
hir_analysis_impl_not_marked_default = `{$ident}` specializes an item from a parent `impl`, but that item is not marked `default`
157159
.label = cannot specialize default item `{$ident}`
158160
.ok_label = parent `impl` is here
@@ -387,8 +389,6 @@ hir_analysis_static_mut_ref_lint = {$shared}reference of mutable static is disco
387389
388390
hir_analysis_static_specialize = cannot specialize on `'static` lifetime
389391
390-
hir_analysis_substs_on_overridden_impl = could not resolve substs on overridden impl
391-
392392
hir_analysis_tait_forward_compat = item constrains opaque type that is not in its signature
393393
.note = this item must mention the opaque type in its signature in order to be able to register hidden types
394394

0 commit comments

Comments
 (0)