Skip to content

Commit 2777386

Browse files
committed
Replace abstract type with type alias impl Trait
1 parent 70c8839 commit 2777386

File tree

4 files changed

+45
-45
lines changed

4 files changed

+45
-45
lines changed

Diff for: src/librustc/hir/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1894,7 +1894,7 @@ impl<'a> LoweringContext<'a> {
18941894
hir::LifetimeName::Implicit | hir::LifetimeName::Underscore => {
18951895
if self.collect_elided_lifetimes {
18961896
// Use `'_` for both implicit and underscore lifetimes in
1897-
// `abstract type Foo<'_>: SomeTrait<'_>;`.
1897+
// `type Foo<'_> = impl SomeTrait<'_>;`.
18981898
hir::LifetimeName::Underscore
18991899
} else {
19001900
return;

Diff for: src/librustc/infer/opaque_types/mod.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ use syntax_pos::Span;
1818

1919
pub type OpaqueTypeMap<'tcx> = DefIdMap<OpaqueTypeDecl<'tcx>>;
2020

21-
/// Information about the opaque, abstract types whose values we
21+
/// Information about the opaque types whose values we
2222
/// are inferring in this function (these are the `impl Trait` that
2323
/// appear in the return type).
2424
#[derive(Copy, Clone, Debug)]
2525
pub struct OpaqueTypeDecl<'tcx> {
26-
/// The substitutions that we apply to the abstract that this
26+
/// The substitutions that we apply to the opaque type that this
2727
/// `impl Trait` desugars to. e.g., if:
2828
///
2929
/// fn foo<'a, 'b, T>() -> impl Trait<'a>
3030
///
3131
/// winds up desugared to:
3232
///
33-
/// abstract type Foo<'x, X>: Trait<'x>
33+
/// type Foo<'x, X> = impl Trait<'x>
3434
/// fn foo<'a, 'b, T>() -> Foo<'a, T>
3535
///
3636
/// then `substs` would be `['a, T]`.
@@ -50,7 +50,7 @@ pub struct OpaqueTypeDecl<'tcx> {
5050
/// over-approximated, but better than nothing.
5151
pub definition_span: Span,
5252

53-
/// The type variable that represents the value of the abstract type
53+
/// The type variable that represents the value of the opaque type
5454
/// that we require. In other words, after we compile this function,
5555
/// we will be created a constraint like:
5656
///
@@ -164,12 +164,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
164164
/// Here, we have two `impl Trait` types whose values are being
165165
/// inferred (the `impl Bar<'a>` and the `impl
166166
/// Bar<'b>`). Conceptually, this is sugar for a setup where we
167-
/// define underlying abstract types (`Foo1`, `Foo2`) and then, in
167+
/// define underlying opaque types (`Foo1`, `Foo2`) and then, in
168168
/// the return type of `foo`, we *reference* those definitions:
169169
///
170170
/// ```text
171-
/// abstract type Foo1<'x>: Bar<'x>;
172-
/// abstract type Foo2<'x>: Bar<'x>;
171+
/// type Foo1<'x> = impl Bar<'x>;
172+
/// type Foo2<'x> = impl Bar<'x>;
173173
/// fn foo<'a, 'b>(..) -> (Foo1<'a>, Foo2<'b>) { .. }
174174
/// // ^^^^ ^^
175175
/// // | |
@@ -228,7 +228,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
228228
///
229229
/// This is actually a bit of a tricky constraint in general. We
230230
/// want to say that each variable (e.g., `'0`) can only take on
231-
/// values that were supplied as arguments to the abstract type
231+
/// values that were supplied as arguments to the opaque type
232232
/// (e.g., `'a` for `Foo1<'a>`) or `'static`, which is always in
233233
/// scope. We don't have a constraint quite of this kind in the current
234234
/// region checker.
@@ -279,10 +279,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
279279
/// # The `free_region_relations` parameter
280280
///
281281
/// The `free_region_relations` argument is used to find the
282-
/// "minimum" of the regions supplied to a given abstract type.
282+
/// "minimum" of the regions supplied to a given opaque type.
283283
/// It must be a relation that can answer whether `'a <= 'b`,
284284
/// where `'a` and `'b` are regions that appear in the "substs"
285-
/// for the abstract type references (the `<'a>` in `Foo1<'a>`).
285+
/// for the opaque type references (the `<'a>` in `Foo1<'a>`).
286286
///
287287
/// Note that we do not impose the constraints based on the
288288
/// generic regions from the `Foo1` definition (e.g., `'x`). This
@@ -298,7 +298,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
298298
///
299299
/// Here, the fact that `'b: 'a` is known only because of the
300300
/// implied bounds from the `&'a &'b u32` parameter, and is not
301-
/// "inherent" to the abstract type definition.
301+
/// "inherent" to the opaque type definition.
302302
///
303303
/// # Parameters
304304
///
@@ -361,7 +361,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
361361
// There were no `required_region_bounds`,
362362
// so we have to search for a `least_region`.
363363
// Go through all the regions used as arguments to the
364-
// abstract type. These are the parameters to the abstract
364+
// opaque type. These are the parameters to the opaque
365365
// type; so in our example above, `substs` would contain
366366
// `['a]` for the first impl trait and `'b` for the
367367
// second.
@@ -528,12 +528,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
528528

529529
/// Given the fully resolved, instantiated type for an opaque
530530
/// type, i.e., the value of an inference variable like C1 or C2
531-
/// (*), computes the "definition type" for an abstract type
531+
/// (*), computes the "definition type" for an opaque type
532532
/// definition -- that is, the inferred value of `Foo1<'x>` or
533533
/// `Foo2<'x>` that we would conceptually use in its definition:
534534
///
535-
/// abstract type Foo1<'x>: Bar<'x> = AAA; <-- this type AAA
536-
/// abstract type Foo2<'x>: Bar<'x> = BBB; <-- or this type BBB
535+
/// type Foo1<'x> = impl Bar<'x> = AAA; <-- this type AAA
536+
/// type Foo2<'x> = impl Bar<'x> = BBB; <-- or this type BBB
537537
/// fn foo<'a, 'b>(..) -> (Foo1<'a>, Foo2<'b>) { .. }
538538
///
539539
/// Note that these values are defined in terms of a distinct set of
@@ -994,15 +994,15 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
994994
// value we are inferring. At present, this is
995995
// always true during the first phase of
996996
// type-check, but not always true later on during
997-
// NLL. Once we support named abstract types more fully,
997+
// NLL. Once we support named opaque types more fully,
998998
// this same scenario will be able to arise during all phases.
999999
//
1000-
// Here is an example using `abstract type` that indicates
1001-
// the distinction we are checking for:
1000+
// Here is an example using type alias `impl Trait`
1001+
// that indicates the distinction we are checking for:
10021002
//
10031003
// ```rust
10041004
// mod a {
1005-
// pub abstract type Foo: Iterator;
1005+
// pub type Foo = impl Iterator;
10061006
// pub fn make_foo() -> Foo { .. }
10071007
// }
10081008
//

Diff for: src/librustc/middle/resolve_lifetime.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -268,17 +268,17 @@ enum Scope<'a> {
268268
track_lifetime_uses: bool,
269269

270270
/// Whether or not this binder would serve as the parent
271-
/// binder for abstract types introduced within. For example:
271+
/// binder for opaque types introduced within. For example:
272272
///
273273
/// fn foo<'a>() -> impl for<'b> Trait<Item = impl Trait2<'a>>
274274
///
275-
/// Here, the abstract types we create for the `impl Trait`
275+
/// Here, the opaque types we create for the `impl Trait`
276276
/// and `impl Trait2` references will both have the `foo` item
277277
/// as their parent. When we get to `impl Trait2`, we find
278278
/// that it is nested within the `for<>` binder -- this flag
279279
/// allows us to skip that when looking for the parent binder
280-
/// of the resulting abstract type.
281-
abstract_type_parent: bool,
280+
/// of the resulting opaque type.
281+
opaque_type_parent: bool,
282282

283283
s: ScopeRef<'a>,
284284
},
@@ -526,7 +526,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
526526
let scope = Scope::Binder {
527527
lifetimes,
528528
next_early_index: index + non_lifetime_count,
529-
abstract_type_parent: true,
529+
opaque_type_parent: true,
530530
track_lifetime_uses,
531531
s: ROOT_SCOPE,
532532
};
@@ -574,7 +574,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
574574
s: self.scope,
575575
next_early_index,
576576
track_lifetime_uses: true,
577-
abstract_type_parent: false,
577+
opaque_type_parent: false,
578578
};
579579
self.with(scope, |old_scope, this| {
580580
// a bare fn has no bounds, so everything
@@ -622,9 +622,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
622622
hir::TyKind::Def(item_id, ref lifetimes) => {
623623
// Resolve the lifetimes in the bounds to the lifetime defs in the generics.
624624
// `fn foo<'a>() -> impl MyTrait<'a> { ... }` desugars to
625-
// `abstract type MyAnonTy<'b>: MyTrait<'b>;`
626-
// ^ ^ this gets resolved in the scope of
627-
// the exist_ty generics
625+
// `type MyAnonTy<'b> = impl MyTrait<'b>;`
626+
// ^ ^ this gets resolved in the scope of
627+
// the opaque_ty generics
628628
let (generics, bounds) = match self.tcx.hir().expect_item(item_id.id).node
629629
{
630630
// Named opaque `impl Trait` types are reached via `TyKind::Path`.
@@ -687,7 +687,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
687687

688688
// We want to start our early-bound indices at the end of the parent scope,
689689
// not including any parent `impl Trait`s.
690-
let mut index = self.next_early_index_for_abstract_type();
690+
let mut index = self.next_early_index_for_opaque_type();
691691
debug!("visit_ty: index = {}", index);
692692

693693
let mut elision = None;
@@ -728,7 +728,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
728728
next_early_index,
729729
s: this.scope,
730730
track_lifetime_uses: true,
731-
abstract_type_parent: false,
731+
opaque_type_parent: false,
732732
};
733733
this.with(scope, |_old_scope, this| {
734734
this.visit_generics(generics);
@@ -743,7 +743,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
743743
next_early_index,
744744
s: self.scope,
745745
track_lifetime_uses: true,
746-
abstract_type_parent: false,
746+
opaque_type_parent: false,
747747
};
748748
self.with(scope, |_old_scope, this| {
749749
this.visit_generics(generics);
@@ -796,7 +796,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
796796
next_early_index: index + non_lifetime_count,
797797
s: self.scope,
798798
track_lifetime_uses: true,
799-
abstract_type_parent: true,
799+
opaque_type_parent: true,
800800
};
801801
self.with(scope, |_old_scope, this| {
802802
this.visit_generics(generics);
@@ -848,7 +848,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
848848
next_early_index: index + non_lifetime_count,
849849
s: self.scope,
850850
track_lifetime_uses: true,
851-
abstract_type_parent: true,
851+
opaque_type_parent: true,
852852
};
853853
self.with(scope, |_old_scope, this| {
854854
this.visit_generics(generics);
@@ -879,7 +879,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
879879
next_early_index,
880880
s: self.scope,
881881
track_lifetime_uses: true,
882-
abstract_type_parent: true,
882+
opaque_type_parent: true,
883883
};
884884
self.with(scope, |_old_scope, this| {
885885
this.visit_generics(generics);
@@ -967,7 +967,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
967967
s: self.scope,
968968
next_early_index,
969969
track_lifetime_uses: true,
970-
abstract_type_parent: false,
970+
opaque_type_parent: false,
971971
};
972972
let result = self.with(scope, |old_scope, this| {
973973
this.check_lifetime_params(old_scope, &bound_generic_params);
@@ -1037,7 +1037,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
10371037
s: self.scope,
10381038
next_early_index,
10391039
track_lifetime_uses: true,
1040-
abstract_type_parent: false,
1040+
opaque_type_parent: false,
10411041
};
10421042
self.with(scope, |old_scope, this| {
10431043
this.check_lifetime_params(old_scope, &trait_ref.bound_generic_params);
@@ -1753,7 +1753,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
17531753
lifetimes,
17541754
next_early_index,
17551755
s: self.scope,
1756-
abstract_type_parent: true,
1756+
opaque_type_parent: true,
17571757
track_lifetime_uses: false,
17581758
};
17591759
self.with(scope, move |old_scope, this| {
@@ -1762,17 +1762,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
17621762
});
17631763
}
17641764

1765-
fn next_early_index_helper(&self, only_abstract_type_parent: bool) -> u32 {
1765+
fn next_early_index_helper(&self, only_opaque_type_parent: bool) -> u32 {
17661766
let mut scope = self.scope;
17671767
loop {
17681768
match *scope {
17691769
Scope::Root => return 0,
17701770

17711771
Scope::Binder {
17721772
next_early_index,
1773-
abstract_type_parent,
1773+
opaque_type_parent,
17741774
..
1775-
} if (!only_abstract_type_parent || abstract_type_parent) =>
1775+
} if (!only_opaque_type_parent || opaque_type_parent) =>
17761776
{
17771777
return next_early_index
17781778
}
@@ -1792,10 +1792,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
17921792
}
17931793

17941794
/// Returns the next index one would use for an `impl Trait` that
1795-
/// is being converted into an `abstract type`. This will be the
1795+
/// is being converted into an opaque type alias `impl Trait`. This will be the
17961796
/// next early index from the enclosing item, for the most
1797-
/// part. See the `abstract_type_parent` field for more info.
1798-
fn next_early_index_for_abstract_type(&self) -> u32 {
1797+
/// part. See the `opaque_type_parent` field for more info.
1798+
fn next_early_index_for_opaque_type(&self) -> u32 {
17991799
self.next_early_index_helper(false)
18001800
}
18011801

Diff for: src/test/rustdoc-ui/coverage/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub trait MyAlias = ThisTrait + Send + Sync;
3131

3232
// FIXME(58624): once rustdoc can process opaque `impl Trait` types,
3333
// we need to make sure they're counted
34-
// /// woah, getting all abstract in here
34+
// /// woah, getting all opaque in here
3535
// pub type ThisExists = impl ThisTrait;
3636
//
3737
// /// why don't we get a little more concrete

0 commit comments

Comments
 (0)