From 87738fe83401ee2a7d2556df8db0df4dec7cd58d Mon Sep 17 00:00:00 2001 From: varkor Date: Tue, 30 Jul 2019 00:11:50 +0100 Subject: Switch existential_type to type_alias_impl_trait --- src/libsyntax/parse/parser.rs | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 7096d6799e2..ec95a2090d6 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -6805,40 +6805,29 @@ impl<'a> Parser<'a> { Ok(self.mk_item(lo.to(prev_span), invalid, ItemKind::ForeignMod(m), visibility, attrs)) } - /// Parses `type Foo = Bar;` - /// or - /// `existential type Foo: Bar;` - /// or - /// `return `None`` + /// Parses `type Foo = Bar;` or returns `None` /// without modifying the parser state. fn eat_type(&mut self) -> Option> { // This parses the grammar: // Ident ["<"...">"] ["where" ...] ("=" | ":") Ty ";" - if self.check_keyword(kw::Type) || - self.check_keyword(kw::Existential) && - self.is_keyword_ahead(1, &[kw::Type]) { - let existential = self.eat_keyword(kw::Existential); - assert!(self.eat_keyword(kw::Type)); - Some(self.parse_existential_or_alias(existential)) + if self.eat_keyword(kw::Type) { + Some(self.parse_type_alias()) } else { None } } /// Parses a type alias or existential type. - fn parse_existential_or_alias( - &mut self, - existential: bool, - ) -> PResult<'a, (Ident, AliasKind, ast::Generics)> { + fn parse_type_alias(&mut self) -> PResult<'a, (Ident, AliasKind, ast::Generics)> { let ident = self.parse_ident()?; let mut tps = self.parse_generics()?; tps.where_clause = self.parse_where_clause()?; - let alias = if existential { - self.expect(&token::Colon)?; + self.expect(&token::Eq)?; + let alias = if self.check_keyword(kw::Impl) { + self.bump(); let bounds = self.parse_generic_bounds(Some(self.prev_span))?; AliasKind::Existential(bounds) } else { - self.expect(&token::Eq)?; let ty = self.parse_ty()?; AliasKind::Weak(ty) }; -- cgit 1.4.1-3-g733a5 From c28ce3e4ca021aea5ca25227c0e46d9b47095db6 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 1 Aug 2019 00:41:54 +0100 Subject: Replace "existential" by "opaque" --- src/librustc/hir/check_attr.rs | 6 +- src/librustc/hir/def.rs | 16 +- src/librustc/hir/intravisit.rs | 4 +- src/librustc/hir/lowering.rs | 80 +++---- src/librustc/hir/map/def_collector.rs | 4 +- src/librustc/hir/map/mod.rs | 14 +- src/librustc/hir/mod.rs | 38 ++-- src/librustc/hir/print.rs | 13 +- src/librustc/ich/impls_syntax.rs | 2 +- src/librustc/infer/error_reporting/mod.rs | 2 +- src/librustc/infer/opaque_types/mod.rs | 75 ++++--- src/librustc/middle/dead.rs | 2 +- src/librustc/middle/reachable.rs | 6 +- src/librustc/middle/resolve_lifetime.rs | 24 +-- src/librustc/traits/project.rs | 2 +- .../traits/specialize/specialization_graph.rs | 4 +- src/librustc/ty/context.rs | 16 +- src/librustc/ty/mod.rs | 15 +- src/librustc/ty/sty.rs | 2 +- src/librustc/ty/wf.rs | 2 +- src/librustc_incremental/persist/dirty_clean.rs | 2 +- src/librustc_lint/builtin.rs | 2 +- src/librustc_metadata/decoder.rs | 8 +- src/librustc_metadata/encoder.rs | 19 +- src/librustc_metadata/schema.rs | 4 +- .../borrow_check/nll/type_check/input_output.rs | 5 +- .../borrow_check/nll/type_check/mod.rs | 8 +- src/librustc_mir/monomorphize/collector.rs | 2 +- src/librustc_passes/ast_validation.rs | 2 +- src/librustc_privacy/lib.rs | 18 +- src/librustc_resolve/build_reduced_graph.rs | 6 +- src/librustc_resolve/lib.rs | 6 +- src/librustc_save_analysis/dump_visitor.rs | 4 +- src/librustc_save_analysis/lib.rs | 4 +- src/librustc_save_analysis/sig.rs | 6 +- src/librustc_traits/lowering/mod.rs | 2 +- src/librustc_typeck/astconv.rs | 2 +- src/librustc_typeck/check/method/probe.rs | 2 +- src/librustc_typeck/check/mod.rs | 10 +- src/librustc_typeck/check/wfcheck.rs | 52 ++--- src/librustc_typeck/check/writeback.rs | 12 +- src/librustc_typeck/collect.rs | 74 +++---- src/librustc_typeck/namespace.rs | 4 +- src/librustc_typeck/outlives/implicit_infer.rs | 2 +- src/librustdoc/clean/mod.rs | 18 +- src/librustdoc/doctree.rs | 8 +- src/librustdoc/html/item_type.rs | 8 +- src/librustdoc/html/render.rs | 22 +- src/librustdoc/passes/mod.rs | 2 +- src/librustdoc/visit_ast.rs | 6 +- src/libsyntax/ast.rs | 14 +- src/libsyntax/feature_gate.rs | 8 +- src/libsyntax/mut_visit.rs | 4 +- src/libsyntax/parse/parser.rs | 18 +- src/libsyntax/print/pprust.rs | 14 +- src/libsyntax/visit.rs | 4 +- src/libsyntax_pos/hygiene.rs | 6 +- src/libsyntax_pos/symbol.rs | 1 - src/test/rustdoc-ui/coverage/traits.rs | 7 +- .../bounds-on-assoc-in-trait.rs | 2 +- .../associated-type-bounds/dyn-existential-type.rs | 66 ------ .../associated-type-bounds/dyn-impl-trait-type.rs | 66 ++++++ .../ui/associated-type-bounds/existential-type.rs | 67 ------ .../trait-alias-impl-trait.rs | 67 ++++++ src/test/ui/async-await/async-await.rs | 2 +- src/test/ui/async-await/await-macro.rs | 230 +++++++++++++++++++++ .../issues/issue-60655-latebound-regions.rs | 2 +- .../existential_types/auxiliary/cross_crate_ice.rs | 11 - .../auxiliary/cross_crate_ice2.rs | 21 -- src/test/ui/existential_types/bound_reduction.rs | 20 -- src/test/ui/existential_types/bound_reduction2.rs | 19 -- .../ui/existential_types/bound_reduction2.stderr | 16 -- src/test/ui/existential_types/cross_crate_ice.rs | 16 -- src/test/ui/existential_types/cross_crate_ice2.rs | 11 - .../declared_but_never_defined.rs | 6 - .../declared_but_never_defined.stderr | 8 - .../declared_but_not_defined_in_scope.rs | 12 -- .../declared_but_not_defined_in_scope.stderr | 8 - .../existential_types/different_defining_uses.rs | 14 -- .../different_defining_uses.stderr | 18 -- .../different_defining_uses_never_type.rs | 18 -- .../different_defining_uses_never_type.stderr | 34 --- .../different_defining_uses_never_type2.rs | 44 ---- .../existential-associated-type.rs | 26 --- .../existential-types-with-cycle-error.rs | 12 -- .../existential-types-with-cycle-error.stderr | 8 - .../existential-types-with-cycle-error2.rs | 16 -- .../existential-types-with-cycle-error2.stderr | 8 - .../existential-types-with-no-traits.rs | 14 -- .../existential-types-with-no-traits.stderr | 14 -- .../ui/existential_types/existential_type_const.rs | 20 -- .../existential_type_const.stderr | 8 - .../ui/existential_types/existential_type_fns.rs | 27 --- .../ui/existential_types/existential_type_tuple.rs | 33 --- .../generic_different_defining_uses.rs | 13 -- .../generic_different_defining_uses.stderr | 18 -- .../generic_duplicate_lifetime_param.rs | 9 - .../generic_duplicate_lifetime_param.stderr | 16 -- .../generic_duplicate_param_use.rs | 2 +- .../generic_duplicate_param_use.stderr | 2 +- .../generic_duplicate_param_use10.rs | 12 -- .../generic_duplicate_param_use2.rs | 2 +- .../generic_duplicate_param_use2.stderr | 11 - .../generic_duplicate_param_use3.rs | 2 +- .../generic_duplicate_param_use3.stderr | 28 --- .../generic_duplicate_param_use4.rs | 2 +- .../generic_duplicate_param_use4.stderr | 11 - .../generic_duplicate_param_use5.rs | 17 -- .../generic_duplicate_param_use5.stderr | 19 -- .../generic_duplicate_param_use6.rs | 17 -- .../generic_duplicate_param_use6.stderr | 19 -- .../generic_duplicate_param_use7.rs | 24 --- .../generic_duplicate_param_use8.rs | 16 -- .../generic_duplicate_param_use8.stderr | 19 -- .../generic_duplicate_param_use9.rs | 20 -- .../generic_duplicate_param_use9.stderr | 18 -- .../ui/existential_types/generic_lifetime_param.rs | 11 - .../existential_types/generic_nondefining_use.rs | 13 -- .../generic_nondefining_use.stderr | 22 -- src/test/ui/existential_types/generic_not_used.rs | 11 - .../ui/existential_types/generic_not_used.stderr | 18 -- ...neric_type_does_not_live_long_enough.nll.stderr | 18 -- .../generic_type_does_not_live_long_enough.rs | 15 -- .../generic_type_does_not_live_long_enough.stderr | 34 --- .../existential_types/generic_underconstrained.rs | 12 -- .../generic_underconstrained.stderr | 18 -- .../existential_types/generic_underconstrained2.rs | 21 -- .../generic_underconstrained2.stderr | 35 ---- src/test/ui/existential_types/issue-58887.stderr | 4 +- src/test/ui/existential_types/issue-60371.rs | 2 +- src/test/ui/existential_types/issue-60371.stderr | 2 +- .../existential_types/nested_existential_types.rs | 20 -- .../never_reveal_concrete_type.rs | 15 -- .../never_reveal_concrete_type.stderr | 21 -- .../no_inferrable_concrete_type.rs | 2 +- .../no_revealing_outside_defining_module.rs | 24 --- .../no_revealing_outside_defining_module.stderr | 23 --- .../ui/existential_types/not_a_defining_use.rs | 2 +- .../ui/existential_types/not_a_defining_use.stderr | 4 +- src/test/ui/existential_types/not_well_formed.rs | 18 -- .../ui/existential_types/not_well_formed.stderr | 9 - src/test/ui/existential_types/private_unused.rs | 13 -- .../ui/existential_types/unused_generic_param.rs | 22 -- .../existential_types/unused_generic_param.stderr | 14 -- .../feature-gate-type_alias_impl_trait.rs | 4 +- .../feature-gate-type_alias_impl_trait.stderr | 4 +- .../associated-existential-type-generic-trait.rs | 30 --- .../associated-existential-type-trivial.rs | 20 -- .../ui/impl-trait/associated-existential-type.rs | 24 --- .../associated-impl-trait-type-generic-trait.rs | 30 +++ .../associated-impl-trait-type-trivial.rs | 20 ++ .../ui/impl-trait/associated-impl-trait-type.rs | 24 +++ src/test/ui/impl-trait/existential-minimal.rs | 5 - .../ui/impl-trait/existential_type_in_fn_body.rs | 12 -- src/test/ui/impl-trait/issue-55872-1.rs | 2 +- src/test/ui/impl-trait/issue-55872-1.stderr | 2 +- src/test/ui/impl-trait/issue-55872-2.rs | 2 +- src/test/ui/impl-trait/issue-55872-2.stderr | 2 +- src/test/ui/impl-trait/issue-55872.rs | 2 +- src/test/ui/impl-trait/issue-55872.stderr | 2 +- .../ordinary-bounds-pick-original-existential.rs | 32 --- ...y-bounds-pick-original-type-alias-impl-trait.rs | 32 +++ .../return-position-impl-trait-minimal.rs | 5 + .../impl-trait/type-alias-impl-trait-in-fn-body.rs | 12 ++ src/test/ui/impl-trait/where-allowed.rs | 4 +- src/test/ui/impl-trait/where-allowed.stderr | 4 +- src/test/ui/in-band-lifetimes.rs | 10 +- src/test/ui/issues/issue-60662.stdout | 2 +- .../ui/privacy/private-in-public-existential.rs | 25 --- .../private-in-public-type-alias-impl-trait.rs | 25 +++ src/test/ui/type-alias-impl-trait.rs | 89 ++++++++ .../associated-type-alias-impl-trait.rs | 26 +++ .../auxiliary/cross_crate_ice.rs | 11 + .../auxiliary/cross_crate_ice2.rs | 21 ++ .../ui/type-alias-impl-trait/bound_reduction.rs | 20 ++ .../ui/type-alias-impl-trait/bound_reduction2.rs | 19 ++ .../type-alias-impl-trait/bound_reduction2.stderr | 16 ++ .../ui/type-alias-impl-trait/cross_crate_ice.rs | 16 ++ .../ui/type-alias-impl-trait/cross_crate_ice2.rs | 11 + .../declared_but_never_defined.rs | 6 + .../declared_but_never_defined.stderr | 8 + .../declared_but_not_defined_in_scope.rs | 12 ++ .../declared_but_not_defined_in_scope.stderr | 8 + .../different_defining_uses.rs | 14 ++ .../different_defining_uses.stderr | 18 ++ .../different_defining_uses_never_type.rs | 18 ++ .../different_defining_uses_never_type.stderr | 34 +++ .../different_defining_uses_never_type2.rs | 44 ++++ .../generic_different_defining_uses.rs | 13 ++ .../generic_different_defining_uses.stderr | 18 ++ .../generic_duplicate_lifetime_param.rs | 9 + .../generic_duplicate_lifetime_param.stderr | 16 ++ .../generic_duplicate_param_use.rs | 14 ++ .../generic_duplicate_param_use.stderr | 17 ++ .../generic_duplicate_param_use10.rs | 12 ++ .../generic_duplicate_param_use2.rs | 17 ++ .../generic_duplicate_param_use2.stderr | 11 + .../generic_duplicate_param_use3.rs | 22 ++ .../generic_duplicate_param_use3.stderr | 28 +++ .../generic_duplicate_param_use4.rs | 17 ++ .../generic_duplicate_param_use4.stderr | 11 + .../generic_duplicate_param_use5.rs | 17 ++ .../generic_duplicate_param_use5.stderr | 19 ++ .../generic_duplicate_param_use6.rs | 17 ++ .../generic_duplicate_param_use6.stderr | 19 ++ .../generic_duplicate_param_use7.rs | 24 +++ .../generic_duplicate_param_use8.rs | 16 ++ .../generic_duplicate_param_use8.stderr | 19 ++ .../generic_duplicate_param_use9.rs | 20 ++ .../generic_duplicate_param_use9.stderr | 18 ++ .../generic_lifetime_param.rs | 11 + .../generic_nondefining_use.rs | 13 ++ .../generic_nondefining_use.stderr | 22 ++ .../ui/type-alias-impl-trait/generic_not_used.rs | 11 + .../type-alias-impl-trait/generic_not_used.stderr | 18 ++ ...neric_type_does_not_live_long_enough.nll.stderr | 18 ++ .../generic_type_does_not_live_long_enough.rs | 15 ++ .../generic_type_does_not_live_long_enough.stderr | 34 +++ .../generic_underconstrained.rs | 12 ++ .../generic_underconstrained.stderr | 18 ++ .../generic_underconstrained2.rs | 21 ++ .../generic_underconstrained2.stderr | 35 ++++ src/test/ui/type-alias-impl-trait/issue-58887.rs | 23 +++ .../ui/type-alias-impl-trait/issue-58887.stderr | 30 +++ src/test/ui/type-alias-impl-trait/issue-60371.rs | 15 ++ .../ui/type-alias-impl-trait/issue-60371.stderr | 29 +++ .../nested_type_alias_impl_trait.rs | 20 ++ .../never_reveal_concrete_type.rs | 15 ++ .../never_reveal_concrete_type.stderr | 21 ++ .../no_inferrable_concrete_type.rs | 13 ++ .../no_inferrable_concrete_type.stderr | 8 + .../no_revealing_outside_defining_module.rs | 24 +++ .../no_revealing_outside_defining_module.stderr | 23 +++ .../ui/type-alias-impl-trait/not_a_defining_use.rs | 40 ++++ .../not_a_defining_use.stderr | 27 +++ .../ui/type-alias-impl-trait/not_well_formed.rs | 18 ++ .../type-alias-impl-trait/not_well_formed.stderr | 9 + .../ui/type-alias-impl-trait/private_unused.rs | 13 ++ .../type-alias-impl-trait-const.rs | 20 ++ .../type-alias-impl-trait-const.stderr | 8 + .../type-alias-impl-trait-fns.rs | 27 +++ .../type-alias-impl-trait-tuple.rs | 33 +++ .../type-alias-impl-trait-with-cycle-error.rs | 12 ++ .../type-alias-impl-trait-with-cycle-error.stderr | 8 + .../type-alias-impl-trait-with-cycle-error2.rs | 16 ++ .../type-alias-impl-trait-with-cycle-error2.stderr | 8 + .../type-alias-impl-trait-with-no-traits.rs | 14 ++ .../type-alias-impl-trait-with-no-traits.stderr | 14 ++ .../type-alias-impl-trait/unused_generic_param.rs | 22 ++ .../unused_generic_param.stderr | 14 ++ 250 files changed, 2430 insertions(+), 1830 deletions(-) delete mode 100644 src/test/ui/associated-type-bounds/dyn-existential-type.rs create mode 100644 src/test/ui/associated-type-bounds/dyn-impl-trait-type.rs delete mode 100644 src/test/ui/associated-type-bounds/existential-type.rs create mode 100644 src/test/ui/associated-type-bounds/trait-alias-impl-trait.rs create mode 100644 src/test/ui/async-await/await-macro.rs delete mode 100644 src/test/ui/existential_types/auxiliary/cross_crate_ice.rs delete mode 100644 src/test/ui/existential_types/auxiliary/cross_crate_ice2.rs delete mode 100644 src/test/ui/existential_types/bound_reduction.rs delete mode 100644 src/test/ui/existential_types/bound_reduction2.rs delete mode 100644 src/test/ui/existential_types/bound_reduction2.stderr delete mode 100644 src/test/ui/existential_types/cross_crate_ice.rs delete mode 100644 src/test/ui/existential_types/cross_crate_ice2.rs delete mode 100644 src/test/ui/existential_types/declared_but_never_defined.rs delete mode 100644 src/test/ui/existential_types/declared_but_never_defined.stderr delete mode 100644 src/test/ui/existential_types/declared_but_not_defined_in_scope.rs delete mode 100644 src/test/ui/existential_types/declared_but_not_defined_in_scope.stderr delete mode 100644 src/test/ui/existential_types/different_defining_uses.rs delete mode 100644 src/test/ui/existential_types/different_defining_uses.stderr delete mode 100644 src/test/ui/existential_types/different_defining_uses_never_type.rs delete mode 100644 src/test/ui/existential_types/different_defining_uses_never_type.stderr delete mode 100644 src/test/ui/existential_types/different_defining_uses_never_type2.rs delete mode 100644 src/test/ui/existential_types/existential-associated-type.rs delete mode 100644 src/test/ui/existential_types/existential-types-with-cycle-error.rs delete mode 100644 src/test/ui/existential_types/existential-types-with-cycle-error.stderr delete mode 100644 src/test/ui/existential_types/existential-types-with-cycle-error2.rs delete mode 100644 src/test/ui/existential_types/existential-types-with-cycle-error2.stderr delete mode 100644 src/test/ui/existential_types/existential-types-with-no-traits.rs delete mode 100644 src/test/ui/existential_types/existential-types-with-no-traits.stderr delete mode 100644 src/test/ui/existential_types/existential_type_const.rs delete mode 100644 src/test/ui/existential_types/existential_type_const.stderr delete mode 100644 src/test/ui/existential_types/existential_type_fns.rs delete mode 100644 src/test/ui/existential_types/existential_type_tuple.rs delete mode 100644 src/test/ui/existential_types/generic_different_defining_uses.rs delete mode 100644 src/test/ui/existential_types/generic_different_defining_uses.stderr delete mode 100644 src/test/ui/existential_types/generic_duplicate_lifetime_param.rs delete mode 100644 src/test/ui/existential_types/generic_duplicate_lifetime_param.stderr delete mode 100644 src/test/ui/existential_types/generic_duplicate_param_use10.rs delete mode 100644 src/test/ui/existential_types/generic_duplicate_param_use2.stderr delete mode 100644 src/test/ui/existential_types/generic_duplicate_param_use3.stderr delete mode 100644 src/test/ui/existential_types/generic_duplicate_param_use4.stderr delete mode 100644 src/test/ui/existential_types/generic_duplicate_param_use5.rs delete mode 100644 src/test/ui/existential_types/generic_duplicate_param_use5.stderr delete mode 100644 src/test/ui/existential_types/generic_duplicate_param_use6.rs delete mode 100644 src/test/ui/existential_types/generic_duplicate_param_use6.stderr delete mode 100644 src/test/ui/existential_types/generic_duplicate_param_use7.rs delete mode 100644 src/test/ui/existential_types/generic_duplicate_param_use8.rs delete mode 100644 src/test/ui/existential_types/generic_duplicate_param_use8.stderr delete mode 100644 src/test/ui/existential_types/generic_duplicate_param_use9.rs delete mode 100644 src/test/ui/existential_types/generic_duplicate_param_use9.stderr delete mode 100644 src/test/ui/existential_types/generic_lifetime_param.rs delete mode 100644 src/test/ui/existential_types/generic_nondefining_use.rs delete mode 100644 src/test/ui/existential_types/generic_nondefining_use.stderr delete mode 100644 src/test/ui/existential_types/generic_not_used.rs delete mode 100644 src/test/ui/existential_types/generic_not_used.stderr delete mode 100644 src/test/ui/existential_types/generic_type_does_not_live_long_enough.nll.stderr delete mode 100644 src/test/ui/existential_types/generic_type_does_not_live_long_enough.rs delete mode 100644 src/test/ui/existential_types/generic_type_does_not_live_long_enough.stderr delete mode 100644 src/test/ui/existential_types/generic_underconstrained.rs delete mode 100644 src/test/ui/existential_types/generic_underconstrained.stderr delete mode 100644 src/test/ui/existential_types/generic_underconstrained2.rs delete mode 100644 src/test/ui/existential_types/generic_underconstrained2.stderr delete mode 100644 src/test/ui/existential_types/nested_existential_types.rs delete mode 100644 src/test/ui/existential_types/never_reveal_concrete_type.rs delete mode 100644 src/test/ui/existential_types/never_reveal_concrete_type.stderr delete mode 100644 src/test/ui/existential_types/no_revealing_outside_defining_module.rs delete mode 100644 src/test/ui/existential_types/no_revealing_outside_defining_module.stderr delete mode 100644 src/test/ui/existential_types/not_well_formed.rs delete mode 100644 src/test/ui/existential_types/not_well_formed.stderr delete mode 100644 src/test/ui/existential_types/private_unused.rs delete mode 100644 src/test/ui/existential_types/unused_generic_param.rs delete mode 100644 src/test/ui/existential_types/unused_generic_param.stderr delete mode 100644 src/test/ui/impl-trait/associated-existential-type-generic-trait.rs delete mode 100644 src/test/ui/impl-trait/associated-existential-type-trivial.rs delete mode 100644 src/test/ui/impl-trait/associated-existential-type.rs create mode 100644 src/test/ui/impl-trait/associated-impl-trait-type-generic-trait.rs create mode 100644 src/test/ui/impl-trait/associated-impl-trait-type-trivial.rs create mode 100644 src/test/ui/impl-trait/associated-impl-trait-type.rs delete mode 100644 src/test/ui/impl-trait/existential-minimal.rs delete mode 100644 src/test/ui/impl-trait/existential_type_in_fn_body.rs delete mode 100644 src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-existential.rs create mode 100644 src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-type-alias-impl-trait.rs create mode 100644 src/test/ui/impl-trait/return-position-impl-trait-minimal.rs create mode 100644 src/test/ui/impl-trait/type-alias-impl-trait-in-fn-body.rs delete mode 100644 src/test/ui/privacy/private-in-public-existential.rs create mode 100644 src/test/ui/privacy/private-in-public-type-alias-impl-trait.rs create mode 100644 src/test/ui/type-alias-impl-trait.rs create mode 100644 src/test/ui/type-alias-impl-trait/associated-type-alias-impl-trait.rs create mode 100644 src/test/ui/type-alias-impl-trait/auxiliary/cross_crate_ice.rs create mode 100644 src/test/ui/type-alias-impl-trait/auxiliary/cross_crate_ice2.rs create mode 100644 src/test/ui/type-alias-impl-trait/bound_reduction.rs create mode 100644 src/test/ui/type-alias-impl-trait/bound_reduction2.rs create mode 100644 src/test/ui/type-alias-impl-trait/bound_reduction2.stderr create mode 100644 src/test/ui/type-alias-impl-trait/cross_crate_ice.rs create mode 100644 src/test/ui/type-alias-impl-trait/cross_crate_ice2.rs create mode 100644 src/test/ui/type-alias-impl-trait/declared_but_never_defined.rs create mode 100644 src/test/ui/type-alias-impl-trait/declared_but_never_defined.stderr create mode 100644 src/test/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.rs create mode 100644 src/test/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.stderr create mode 100644 src/test/ui/type-alias-impl-trait/different_defining_uses.rs create mode 100644 src/test/ui/type-alias-impl-trait/different_defining_uses.stderr create mode 100644 src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.rs create mode 100644 src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.stderr create mode 100644 src/test/ui/type-alias-impl-trait/different_defining_uses_never_type2.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_different_defining_uses.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_different_defining_uses.stderr create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use10.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.stderr create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.stderr create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.stderr create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use7.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr create mode 100644 src/test/ui/type-alias-impl-trait/generic_lifetime_param.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_nondefining_use.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr create mode 100644 src/test/ui/type-alias-impl-trait/generic_not_used.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_not_used.stderr create mode 100644 src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr create mode 100644 src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr create mode 100644 src/test/ui/type-alias-impl-trait/generic_underconstrained.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_underconstrained.stderr create mode 100644 src/test/ui/type-alias-impl-trait/generic_underconstrained2.rs create mode 100644 src/test/ui/type-alias-impl-trait/generic_underconstrained2.stderr create mode 100644 src/test/ui/type-alias-impl-trait/issue-58887.rs create mode 100644 src/test/ui/type-alias-impl-trait/issue-58887.stderr create mode 100644 src/test/ui/type-alias-impl-trait/issue-60371.rs create mode 100644 src/test/ui/type-alias-impl-trait/issue-60371.stderr create mode 100644 src/test/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs create mode 100644 src/test/ui/type-alias-impl-trait/never_reveal_concrete_type.rs create mode 100644 src/test/ui/type-alias-impl-trait/never_reveal_concrete_type.stderr create mode 100644 src/test/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs create mode 100644 src/test/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr create mode 100644 src/test/ui/type-alias-impl-trait/no_revealing_outside_defining_module.rs create mode 100644 src/test/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr create mode 100644 src/test/ui/type-alias-impl-trait/not_a_defining_use.rs create mode 100644 src/test/ui/type-alias-impl-trait/not_a_defining_use.stderr create mode 100644 src/test/ui/type-alias-impl-trait/not_well_formed.rs create mode 100644 src/test/ui/type-alias-impl-trait/not_well_formed.stderr create mode 100644 src/test/ui/type-alias-impl-trait/private_unused.rs create mode 100644 src/test/ui/type-alias-impl-trait/type-alias-impl-trait-const.rs create mode 100644 src/test/ui/type-alias-impl-trait/type-alias-impl-trait-const.stderr create mode 100644 src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs create mode 100644 src/test/ui/type-alias-impl-trait/type-alias-impl-trait-tuple.rs create mode 100644 src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.rs create mode 100644 src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.stderr create mode 100644 src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.rs create mode 100644 src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.stderr create mode 100644 src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.rs create mode 100644 src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.stderr create mode 100644 src/test/ui/type-alias-impl-trait/unused_generic_param.rs create mode 100644 src/test/ui/type-alias-impl-trait/unused_generic_param.stderr (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 316ca642473..db90e44b892 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -27,7 +27,7 @@ pub(crate) enum Target { ForeignMod, GlobalAsm, Ty, - Existential, + OpaqueTy, Enum, Struct, Union, @@ -51,7 +51,7 @@ impl Display for Target { Target::ForeignMod => "foreign module", Target::GlobalAsm => "global asm", Target::Ty => "type alias", - Target::Existential => "existential type", + Target::OpaqueTy => "opaque type", Target::Enum => "enum", Target::Struct => "struct", Target::Union => "union", @@ -76,7 +76,7 @@ impl Target { hir::ItemKind::ForeignMod(..) => Target::ForeignMod, hir::ItemKind::GlobalAsm(..) => Target::GlobalAsm, hir::ItemKind::Ty(..) => Target::Ty, - hir::ItemKind::Existential(..) => Target::Existential, + hir::ItemKind::OpaqueTy(..) => Target::OpaqueTy, hir::ItemKind::Enum(..) => Target::Enum, hir::ItemKind::Struct(..) => Target::Struct, hir::ItemKind::Union(..) => Target::Union, diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index db568dbf9fb..40992e92744 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -55,15 +55,15 @@ pub enum DefKind { /// Refers to the variant itself, `DefKind::Ctor` refers to its constructor if it exists. Variant, Trait, - /// `existential type Foo: Bar;` - Existential, + /// `type Foo = impl Bar;` + OpaqueTy, /// `type Foo = Bar;` TyAlias, ForeignTy, TraitAlias, AssocTy, - /// `existential type Foo: Bar;` - AssocExistential, + /// `type Foo = impl Bar;` + AssocOpaqueTy, TyParam, // Value namespace @@ -96,11 +96,11 @@ impl DefKind { DefKind::Ctor(CtorOf::Struct, CtorKind::Const) => "unit struct", DefKind::Ctor(CtorOf::Struct, CtorKind::Fictive) => bug!("impossible struct constructor"), - DefKind::Existential => "existential type", + DefKind::OpaqueTy => "opaque type", DefKind::TyAlias => "type alias", DefKind::TraitAlias => "trait alias", DefKind::AssocTy => "associated type", - DefKind::AssocExistential => "associated existential type", + DefKind::AssocOpaqueTy => "associated opaque type", DefKind::Union => "union", DefKind::Trait => "trait", DefKind::ForeignTy => "foreign type", @@ -118,9 +118,9 @@ impl DefKind { match *self { DefKind::AssocTy | DefKind::AssocConst - | DefKind::AssocExistential + | DefKind::AssocOpaqueTy | DefKind::Enum - | DefKind::Existential => "an", + | DefKind::OpaqueTy => "an", DefKind::Macro(macro_kind) => macro_kind.article(), _ => "a", } diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 3781d7df176..397529d4e19 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -505,7 +505,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_ty(ty); visitor.visit_generics(generics) } - ItemKind::Existential(ExistTy { + ItemKind::OpaqueTy(ExistTy { ref generics, ref bounds, .. @@ -930,7 +930,7 @@ pub fn walk_impl_item<'v, V: Visitor<'v>>(visitor: &mut V, impl_item: &'v ImplIt visitor.visit_id(impl_item.hir_id); visitor.visit_ty(ty); } - ImplItemKind::Existential(ref bounds) => { + ImplItemKind::OpaqueTy(ref bounds) => { visitor.visit_id(impl_item.hir_id); walk_list!(visitor, visit_param_bound, bounds); } diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 026c3cc6f95..f92ea8a008e 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -189,14 +189,14 @@ enum ImplTraitContext<'a> { /// Newly generated parameters should be inserted into the given `Vec`. Universal(&'a mut Vec), - /// Treat `impl Trait` as shorthand for a new existential parameter. + /// Treat `impl Trait` as shorthand for a new opaque type. /// Example: `fn foo() -> impl Debug`, where `impl Debug` is conceptually - /// equivalent to a fresh existential parameter like `existential type T; fn foo() -> T`. + /// equivalent to a new opaque type like `type T = impl Debug; fn foo() -> T`. /// /// We optionally store a `DefId` for the parent item here so we can look up necessary /// information later. It is `None` when no information about the context should be stored /// (e.g., for consts and statics). - Existential(Option /* fn def-ID */), + OpaqueTy(Option /* fn def-ID */), /// `impl Trait` is not accepted in this position. Disallowed(ImplTraitPosition), @@ -222,7 +222,7 @@ impl<'a> ImplTraitContext<'a> { use self::ImplTraitContext::*; match self { Universal(params) => Universal(params), - Existential(fn_def_id) => Existential(*fn_def_id), + OpaqueTy(fn_def_id) => OpaqueTy(*fn_def_id), Disallowed(pos) => Disallowed(*pos), } } @@ -487,7 +487,7 @@ impl<'a> LoweringContext<'a> { | ItemKind::Union(_, ref generics) | ItemKind::Enum(_, ref generics) | ItemKind::Ty(_, ref generics) - | ItemKind::Existential(_, ref generics) + | ItemKind::OpaqueTy(_, ref generics) | ItemKind::Trait(_, _, ref generics, ..) => { let def_id = self.lctx.resolver.definitions().local_def_id(item.id); let count = generics @@ -1422,7 +1422,7 @@ impl<'a> LoweringContext<'a> { // so desugar to // // fn foo() -> impl Iterator - ImplTraitContext::Existential(_) => (true, itctx), + ImplTraitContext::OpaqueTy(_) => (true, itctx), // We are in the argument position, but within a dyn type: // @@ -1436,11 +1436,11 @@ impl<'a> LoweringContext<'a> { // In `type Foo = dyn Iterator` we desugar to // `type Foo = dyn Iterator` but we have to override the // "impl trait context" to permit `impl Debug` in this position (it desugars - // then to an existential type). + // then to an opaque type). // // FIXME: this is only needed until `impl Trait` is allowed in type aliases. ImplTraitContext::Disallowed(_) if self.is_in_dyn_type => - (true, ImplTraitContext::Existential(None)), + (true, ImplTraitContext::OpaqueTy(None)), // We are in the argument position, but not within a dyn type: // @@ -1634,8 +1634,8 @@ impl<'a> LoweringContext<'a> { TyKind::ImplTrait(def_node_id, ref bounds) => { let span = t.span; match itctx { - ImplTraitContext::Existential(fn_def_id) => { - self.lower_existential_impl_trait( + ImplTraitContext::OpaqueTy(fn_def_id) => { + self.lower_opaque_impl_trait( span, fn_def_id, def_node_id, |this| this.lower_param_bounds(bounds, itctx), ) @@ -1717,7 +1717,7 @@ impl<'a> LoweringContext<'a> { } } - fn lower_existential_impl_trait( + fn lower_opaque_impl_trait( &mut self, span: Span, fn_def_id: Option, @@ -1730,7 +1730,7 @@ impl<'a> LoweringContext<'a> { // Not tracking it makes lints in rustc and clippy very fragile, as // frequently opened issues show. let exist_ty_span = self.mark_span_with_reason( - DesugaringKind::ExistentialType, + DesugaringKind::OpaqueTy, span, None, ); @@ -1763,11 +1763,11 @@ impl<'a> LoweringContext<'a> { }, bounds: hir_bounds, impl_trait_fn: fn_def_id, - origin: hir::ExistTyOrigin::ReturnImplTrait, + origin: hir::OpaqueTyOrigin::ReturnImplTrait, }; trace!("exist ty from impl trait def-index: {:#?}", exist_ty_def_index); - let exist_ty_id = lctx.generate_existential_type( + let exist_ty_id = lctx.generate_opaque_type( exist_ty_node_id, exist_ty_item, span, @@ -1779,19 +1779,19 @@ impl<'a> LoweringContext<'a> { }) } - /// Registers a new existential type with the proper `NodeId`s and - /// returns the lowered node-ID for the existential type. - fn generate_existential_type( + /// Registers a new opaque type with the proper `NodeId`s and + /// returns the lowered node-ID for the opaque type. + fn generate_opaque_type( &mut self, exist_ty_node_id: NodeId, exist_ty_item: hir::ExistTy, span: Span, exist_ty_span: Span, ) -> hir::HirId { - let exist_ty_item_kind = hir::ItemKind::Existential(exist_ty_item); + let exist_ty_item_kind = hir::ItemKind::OpaqueTy(exist_ty_item); let exist_ty_id = self.lower_node_id(exist_ty_node_id); - // Generate an `existential type Foo: Trait;` declaration. - trace!("registering existential type with id {:#?}", exist_ty_id); + // Generate an `type Foo = impl Trait;` declaration. + trace!("registering opaque type with id {:#?}", exist_ty_id); let exist_ty_item = hir::Item { hir_id: exist_ty_id, ident: Ident::invalid(), @@ -1802,7 +1802,7 @@ impl<'a> LoweringContext<'a> { }; // Insert the item into the global item list. This usually happens - // automatically for all AST items. But this existential type item + // automatically for all AST items. But this opaque type item // does not actually exist in the AST. self.insert_item(exist_ty_item); exist_ty_id @@ -2439,7 +2439,7 @@ impl<'a> LoweringContext<'a> { .as_ref() .map(|t| self.lower_ty(t, if self.sess.features_untracked().impl_trait_in_bindings { - ImplTraitContext::Existential(Some(parent_def_id)) + ImplTraitContext::OpaqueTy(Some(parent_def_id)) } else { ImplTraitContext::Disallowed(ImplTraitPosition::Binding) } @@ -2500,7 +2500,7 @@ impl<'a> LoweringContext<'a> { let lt_mode = if make_ret_async.is_some() { // In `async fn`, argument-position elided lifetimes // must be transformed into fresh generic parameters so that - // they can be applied to the existential return type. + // they can be applied to the opaque `impl Trait` return type. AnonymousLifetimeMode::CreateParameter } else { self.anonymous_lifetime_mode @@ -2539,7 +2539,7 @@ impl<'a> LoweringContext<'a> { FunctionRetTy::Ty(ref ty) => match in_band_ty_params { Some((def_id, _)) if impl_trait_return_allow => { hir::Return(self.lower_ty(ty, - ImplTraitContext::Existential(Some(def_id)) + ImplTraitContext::OpaqueTy(Some(def_id)) )) } _ => { @@ -2585,12 +2585,12 @@ impl<'a> LoweringContext<'a> { // Transforms `-> T` for `async fn` into `-> ExistTy { .. }` // combined with the following definition of `ExistTy`: // - // existential type ExistTy: Future; + // type ExistTy = impl Future; // // `inputs`: lowered types of arguments to the function (used to collect lifetimes) // `output`: unlowered output type (`T` in `-> T`) // `fn_def_id`: `DefId` of the parent function (used to create child impl trait definition) - // `exist_ty_node_id`: `NodeId` of the existential type that should be created + // `exist_ty_node_id`: `NodeId` of the opaque `impl Trait` type that should be created // `elided_lt_replacement`: replacement for elided lifetimes in the return type fn lower_async_fn_ret_ty( &mut self, @@ -2626,7 +2626,7 @@ impl<'a> LoweringContext<'a> { ); // Calculate all the lifetimes that should be captured - // by the existential type. This should include all in-scope + // by the opaque type. This should include all in-scope // lifetime parameters, including those defined in-band. // // Note: this must be done after lowering the output type, @@ -2657,11 +2657,11 @@ impl<'a> LoweringContext<'a> { }, bounds: hir_vec![future_bound], impl_trait_fn: Some(fn_def_id), - origin: hir::ExistTyOrigin::AsyncFn, + origin: hir::OpaqueTyOrigin::AsyncFn, }; trace!("exist ty from async fn def index: {:#?}", exist_ty_def_index); - let exist_ty_id = this.generate_existential_type( + let exist_ty_id = this.generate_opaque_type( exist_ty_node_id, exist_ty_item, span, @@ -2702,7 +2702,7 @@ impl<'a> LoweringContext<'a> { // Compute the `T` in `Future` from the return type. let output_ty = match output { FunctionRetTy::Ty(ty) => { - self.lower_ty(ty, ImplTraitContext::Existential(Some(fn_def_id))) + self.lower_ty(ty, ImplTraitContext::OpaqueTy(Some(fn_def_id))) } FunctionRetTy::Default(ret_ty_span) => { P(hir::Ty { @@ -2905,7 +2905,7 @@ impl<'a> LoweringContext<'a> { let kind = hir::GenericParamKind::Type { default: default.as_ref().map(|x| { - self.lower_ty(x, ImplTraitContext::Existential(None)) + self.lower_ty(x, ImplTraitContext::OpaqueTy(None)) }), synthetic: param.attrs.iter() .filter(|attr| attr.check_name(sym::rustc_synthetic)) @@ -3384,7 +3384,7 @@ impl<'a> LoweringContext<'a> { self.lower_ty( t, if self.sess.features_untracked().impl_trait_in_bindings { - ImplTraitContext::Existential(None) + ImplTraitContext::OpaqueTy(None) } else { ImplTraitContext::Disallowed(ImplTraitPosition::Binding) } @@ -3398,7 +3398,7 @@ impl<'a> LoweringContext<'a> { self.lower_ty( t, if self.sess.features_untracked().impl_trait_in_bindings { - ImplTraitContext::Existential(None) + ImplTraitContext::OpaqueTy(None) } else { ImplTraitContext::Disallowed(ImplTraitPosition::Binding) } @@ -3444,14 +3444,14 @@ impl<'a> LoweringContext<'a> { self.lower_ty(t, ImplTraitContext::disallowed()), self.lower_generics(generics, ImplTraitContext::disallowed()), ), - ItemKind::Existential(ref b, ref generics) => hir::ItemKind::Existential( + ItemKind::OpaqueTy(ref b, ref generics) => hir::ItemKind::OpaqueTy( hir::ExistTy { generics: self.lower_generics(generics, - ImplTraitContext::Existential(None)), + ImplTraitContext::OpaqueTy(None)), bounds: self.lower_param_bounds(b, - ImplTraitContext::Existential(None)), + ImplTraitContext::OpaqueTy(None)), impl_trait_fn: None, - origin: hir::ExistTyOrigin::ExistentialType, + origin: hir::OpaqueTyOrigin::TraitAliasImplTrait, }, ), ItemKind::Enum(ref enum_definition, ref generics) => { @@ -3918,9 +3918,9 @@ impl<'a> LoweringContext<'a> { self.lower_generics(&i.generics, ImplTraitContext::disallowed()), hir::ImplItemKind::Type(self.lower_ty(ty, ImplTraitContext::disallowed())), ), - ImplItemKind::Existential(ref bounds) => ( + ImplItemKind::OpaqueTy(ref bounds) => ( self.lower_generics(&i.generics, ImplTraitContext::disallowed()), - hir::ImplItemKind::Existential( + hir::ImplItemKind::OpaqueTy( self.lower_param_bounds(bounds, ImplTraitContext::disallowed()), ), ), @@ -3951,7 +3951,7 @@ impl<'a> LoweringContext<'a> { kind: match i.node { ImplItemKind::Const(..) => hir::AssocItemKind::Const, ImplItemKind::Type(..) => hir::AssocItemKind::Type, - ImplItemKind::Existential(..) => hir::AssocItemKind::Existential, + ImplItemKind::OpaqueTy(..) => hir::AssocItemKind::OpaqueTy, ImplItemKind::Method(ref sig, _) => hir::AssocItemKind::Method { has_self: sig.decl.has_self(), }, diff --git a/src/librustc/hir/map/def_collector.rs b/src/librustc/hir/map/def_collector.rs index d02aab54127..c44942a1626 100644 --- a/src/librustc/hir/map/def_collector.rs +++ b/src/librustc/hir/map/def_collector.rs @@ -92,7 +92,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> { } ItemKind::Mod(..) | ItemKind::Trait(..) | ItemKind::TraitAlias(..) | ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) | - ItemKind::Existential(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | + ItemKind::OpaqueTy(..) | ItemKind::ExternCrate(..) | ItemKind::ForeignMod(..) | ItemKind::Ty(..) => DefPathData::TypeNs(i.ident.as_interned_str()), ItemKind::Fn( ref decl, @@ -223,7 +223,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> { ImplItemKind::Method(..) | ImplItemKind::Const(..) => DefPathData::ValueNs(ii.ident.as_interned_str()), ImplItemKind::Type(..) | - ImplItemKind::Existential(..) => { + ImplItemKind::OpaqueTy(..) => { DefPathData::TypeNs(ii.ident.as_interned_str()) }, ImplItemKind::Macro(..) => return self.visit_macro_invoc(ii.id), diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 5a28d9e7b7d..48ff4bb9e42 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -301,7 +301,7 @@ impl<'hir> Map<'hir> { ItemKind::Const(..) => DefKind::Const, ItemKind::Fn(..) => DefKind::Fn, ItemKind::Mod(..) => DefKind::Mod, - ItemKind::Existential(..) => DefKind::Existential, + ItemKind::OpaqueTy(..) => DefKind::OpaqueTy, ItemKind::Ty(..) => DefKind::TyAlias, ItemKind::Enum(..) => DefKind::Enum, ItemKind::Struct(..) => DefKind::Struct, @@ -334,7 +334,7 @@ impl<'hir> Map<'hir> { ImplItemKind::Const(..) => DefKind::AssocConst, ImplItemKind::Method(..) => DefKind::Method, ImplItemKind::Type(..) => DefKind::AssocTy, - ImplItemKind::Existential(..) => DefKind::AssocExistential, + ImplItemKind::OpaqueTy(..) => DefKind::AssocOpaqueTy, } } Node::Variant(_) => DefKind::Variant, @@ -816,7 +816,7 @@ impl<'hir> Map<'hir> { }, |_| false).ok() } - /// Returns the defining scope for an existential type definition. + /// Returns the defining scope for an opaque type definition. pub fn get_defining_scope(&self, id: HirId) -> Option { let mut scope = id; loop { @@ -827,7 +827,7 @@ impl<'hir> Map<'hir> { match self.get(scope) { Node::Item(i) => { match i.node { - ItemKind::Existential(ExistTy { impl_trait_fn: None, .. }) => {} + ItemKind::OpaqueTy(ExistTy { impl_trait_fn: None, .. }) => {} _ => break, } } @@ -1270,7 +1270,7 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String { ItemKind::ForeignMod(..) => "foreign mod", ItemKind::GlobalAsm(..) => "global asm", ItemKind::Ty(..) => "ty", - ItemKind::Existential(..) => "existential type", + ItemKind::OpaqueTy(..) => "opaque type", ItemKind::Enum(..) => "enum", ItemKind::Struct(..) => "struct", ItemKind::Union(..) => "union", @@ -1294,8 +1294,8 @@ fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String { ImplItemKind::Type(_) => { format!("assoc type {} in {}{}", ii.ident, path_str(), id_str) } - ImplItemKind::Existential(_) => { - format!("assoc existential type {} in {}{}", ii.ident, path_str(), id_str) + ImplItemKind::OpaqueTy(_) => { + format!("assoc opaque type {} in {}{}", ii.ident, path_str(), id_str) } } } diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index f9a49447801..f293ddbf467 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1815,7 +1815,7 @@ pub struct ImplItemId { pub hir_id: HirId, } -/// Represents anything within an `impl` block +/// Represents anything within an `impl` block. #[derive(RustcEncodable, RustcDecodable, Debug)] pub struct ImplItem { pub ident: Ident, @@ -1832,14 +1832,14 @@ pub struct ImplItem { #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub enum ImplItemKind { /// An associated constant of the given type, set to the constant result - /// of the expression + /// of the expression. Const(P, BodyId), - /// A method implementation with the given signature and body + /// A method implementation with the given signature and body. Method(MethodSig, BodyId), - /// An associated type + /// An associated type. Type(P), - /// An associated existential type - Existential(GenericBounds), + /// An associated `type = impl Trait`. + OpaqueTy(GenericBounds), } /// Bind a type to an associated type (i.e., `A = Foo`). @@ -1926,14 +1926,14 @@ pub struct ExistTy { pub generics: Generics, pub bounds: GenericBounds, pub impl_trait_fn: Option, - pub origin: ExistTyOrigin, + pub origin: OpaqueTyOrigin, } -/// Where the existential type came from +/// Where the opaque type came from #[derive(Copy, Clone, RustcEncodable, RustcDecodable, Debug, HashStable)] -pub enum ExistTyOrigin { - /// `existential type Foo: Trait;` - ExistentialType, +pub enum OpaqueTyOrigin { + /// `type Foo = impl Trait;` + TraitAliasImplTrait, /// `-> impl Trait` ReturnImplTrait, /// `async fn` @@ -1962,7 +1962,7 @@ pub enum TyKind { /// /// Type parameters may be stored in each `PathSegment`. Path(QPath), - /// A type definition itself. This is currently only used for the `existential type` + /// A type definition itself. This is currently only used for the `type Foo = impl Trait` /// item that `impl Trait` in return position desugars to. /// /// The generic argument list contains the lifetimes (and in the future possibly parameters) @@ -2421,17 +2421,17 @@ pub enum ItemKind { GlobalAsm(P), /// A type alias, e.g., `type Foo = Bar` Ty(P, Generics), - /// An existential type definition, e.g., `existential type Foo: Bar;` - Existential(ExistTy), + /// An opaque `impl Trait` type alias, e.g., `type Foo = impl Bar;` + OpaqueTy(ExistTy), /// An enum definition, e.g., `enum Foo {C, D}` Enum(EnumDef, Generics), /// A struct definition, e.g., `struct Foo {x: A}` Struct(VariantData, Generics), /// A union definition, e.g., `union Foo {x: A, y: B}` Union(VariantData, Generics), - /// Represents a Trait Declaration + /// A trait definition Trait(IsAuto, Unsafety, Generics, GenericBounds, HirVec), - /// Represents a Trait Alias Declaration + /// A trait alias TraitAlias(Generics, GenericBounds), /// An implementation, eg `impl Trait for Foo { .. }` @@ -2456,7 +2456,7 @@ impl ItemKind { ItemKind::ForeignMod(..) => "foreign module", ItemKind::GlobalAsm(..) => "global asm", ItemKind::Ty(..) => "type alias", - ItemKind::Existential(..) => "existential type", + ItemKind::OpaqueTy(..) => "opaque type", ItemKind::Enum(..) => "enum", ItemKind::Struct(..) => "struct", ItemKind::Union(..) => "union", @@ -2479,7 +2479,7 @@ impl ItemKind { Some(match *self { ItemKind::Fn(_, _, ref generics, _) | ItemKind::Ty(_, ref generics) | - ItemKind::Existential(ExistTy { ref generics, impl_trait_fn: None, .. }) | + ItemKind::OpaqueTy(ExistTy { ref generics, impl_trait_fn: None, .. }) | ItemKind::Enum(_, ref generics) | ItemKind::Struct(_, ref generics) | ItemKind::Union(_, ref generics) | @@ -2528,7 +2528,7 @@ pub enum AssocItemKind { Const, Method { has_self: bool }, Type, - Existential, + OpaqueTy, } #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 9c32831cf88..7d6c6e1d09d 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -565,9 +565,10 @@ impl<'a> State<'a> { self.s.word(";"); self.end(); // end the outer ibox } - hir::ItemKind::Existential(ref exist) => { - self.head(visibility_qualified(&item.vis, "existential type")); + hir::ItemKind::OpaqueTy(ref exist) => { + self.head(visibility_qualified(&item.vis, "type")); self.print_ident(item.ident); + self.word_space("= impl"); self.print_generic_params(&exist.generics.params); self.end(); // end the inner ibox @@ -908,9 +909,11 @@ impl<'a> State<'a> { hir::ImplItemKind::Type(ref ty) => { self.print_associated_type(ii.ident, None, Some(ty)); } - hir::ImplItemKind::Existential(ref bounds) => { - self.word_space("existential"); - self.print_associated_type(ii.ident, Some(bounds), None); + hir::ImplItemKind::OpaqueTy(ref bounds) => { + self.word_space("type"); + self.print_ident(ii.ident); + self.print_bounds("= impl", bounds); + self.s.word(";"); } } self.ann.post(self, AnnNode::SubItem(ii.hir_id)) diff --git a/src/librustc/ich/impls_syntax.rs b/src/librustc/ich/impls_syntax.rs index e0e7988a744..0c9c9adcf9d 100644 --- a/src/librustc/ich/impls_syntax.rs +++ b/src/librustc/ich/impls_syntax.rs @@ -418,7 +418,7 @@ impl_stable_hash_for!(enum ::syntax_pos::hygiene::DesugaringKind { Async, Await, QuestionMark, - ExistentialType, + OpaqueTy, ForLoop, TryBlock }); diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index cbfb048c064..f92e0336244 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -269,7 +269,7 @@ impl<'tcx> TyCtxt<'tcx> { match item.node { hir::ImplItemKind::Method(..) => "method body", hir::ImplItemKind::Const(..) - | hir::ImplItemKind::Existential(..) + | hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::Type(..) => "associated item", } } diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index 73a76ebcb74..d7b93cd01a7 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -40,7 +40,7 @@ pub struct OpaqueTypeDecl<'tcx> { /// for example: /// /// ``` - /// existential type Foo; + /// type Foo = impl Baz; /// fn bar() -> Foo { /// ^^^ This is the span we are looking for! /// ``` @@ -87,8 +87,8 @@ pub struct OpaqueTypeDecl<'tcx> { /// check.) pub has_required_region_bounds: bool, - /// The origin of the existential type - pub origin: hir::ExistTyOrigin, + /// The origin of the opaque type. + pub origin: hir::OpaqueTyOrigin, } impl<'a, 'tcx> InferCtxt<'a, 'tcx> { @@ -143,8 +143,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { InferOk { value: (value, instantiator.opaque_types), obligations: instantiator.obligations } } - /// Given the map `opaque_types` containing the existential `impl - /// Trait` types whose underlying, hidden types are being + /// Given the map `opaque_types` containing the opaque + /// `impl Trait` types whose underlying, hidden types are being /// inferred, this method adds constraints to the regions /// appearing in those underlying hidden types to ensure that they /// at least do not refer to random scopes within the current @@ -265,14 +265,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { /// } /// /// // Equivalent to: - /// existential type FooReturn<'a, T>: Foo<'a>; + /// type FooReturn<'a, T> = impl Foo<'a>; /// fn foo<'a, T>(..) -> FooReturn<'a, T> { .. } /// ``` /// /// then the hidden type `Tc` would be `(&'0 u32, T)` (where `'0` /// is an inference variable). If we generated a constraint that /// `Tc: 'a`, then this would incorrectly require that `T: 'a` -- - /// but this is not necessary, because the existential type we + /// but this is not necessary, because the opaque type we /// create will be allowed to reference `T`. So we only generate a /// constraint that `'0: 'a`. /// @@ -492,11 +492,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { // Without a feature-gate, we only generate member-constraints for async-await. let context_name = match opaque_defn.origin { // No feature-gate required for `async fn`. - hir::ExistTyOrigin::AsyncFn => return false, + hir::OpaqueTyOrigin::AsyncFn => return false, // Otherwise, generate the label we'll use in the error message. - hir::ExistTyOrigin::ExistentialType => "existential type", - hir::ExistTyOrigin::ReturnImplTrait => "impl Trait", + hir::OpaqueTyOrigin::TraitAliasImplTrait => "impl Trait", + hir::OpaqueTyOrigin::ReturnImplTrait => "impl Trait", }; let msg = format!("ambiguous lifetime bound in `{}`", context_name); let mut err = self.tcx.sess.struct_span_err(span, &msg); @@ -842,12 +842,12 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> { self.tcx.sess .struct_span_err( self.span, - "non-defining existential type use in defining scope" + "non-defining opaque type use in defining scope" ) .span_label( self.span, format!("lifetime `{}` is part of concrete type but not used in \ - parameter list of existential type", r), + parameter list of the `impl Trait` type alias", r), ) .emit(); @@ -863,7 +863,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> { // we encounter a closure here, it is always a closure // from within the function that we are currently // type-checking -- one that is now being encapsulated - // in an existential abstract type. Ideally, we would + // in an opaque type. Ideally, we would // go through the types/lifetimes that it references // and treat them just like we would any other type, // which means we would error out if we find any @@ -918,7 +918,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> { // Look it up in the substitution list. match self.map.get(&ty.into()).map(|k| k.unpack()) { // Found it in the substitution list; replace with the parameter from the - // existential type. + // opaque type. Some(UnpackedKind::Type(t1)) => t1, Some(u) => panic!("type mapped to unexpected kind: {:?}", u), None => { @@ -926,7 +926,8 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> { .struct_span_err( self.span, &format!("type parameter `{}` is part of concrete type but not \ - used in parameter list for existential type", ty), + used in parameter list for the `impl Trait` type alias", + ty), ) .emit(); @@ -947,7 +948,7 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> { // Look it up in the substitution list. match self.map.get(&ct.into()).map(|k| k.unpack()) { // Found it in the substitution list, replace with the parameter from the - // existential type. + // opaque type. Some(UnpackedKind::Const(c1)) => c1, Some(u) => panic!("const mapped to unexpected kind: {:?}", u), None => { @@ -955,7 +956,8 @@ impl TypeFolder<'tcx> for ReverseMapper<'tcx> { .struct_span_err( self.span, &format!("const parameter `{}` is part of concrete type but not \ - used in parameter list for existential type", ct) + used in parameter list for the `impl Trait` type alias", + ct) ) .emit(); @@ -1031,36 +1033,40 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { let (in_definition_scope, origin) = match tcx.hir().find(opaque_hir_id) { Some(Node::Item(item)) => match item.node { // Anonymous `impl Trait` - hir::ItemKind::Existential(hir::ExistTy { + hir::ItemKind::OpaqueTy(hir::ExistTy { impl_trait_fn: Some(parent), origin, .. }) => (parent == self.parent_def_id, origin), - // Named `existential type` - hir::ItemKind::Existential(hir::ExistTy { + // Named `type Foo = impl Bar;` + hir::ItemKind::OpaqueTy(hir::ExistTy { impl_trait_fn: None, origin, .. }) => ( - may_define_existential_type( + may_define_opaque_type( tcx, self.parent_def_id, opaque_hir_id, ), origin, ), - _ => (def_scope_default(), hir::ExistTyOrigin::ExistentialType), + _ => { + (def_scope_default(), hir::OpaqueTyOrigin::TraitAliasImplTrait) + } }, Some(Node::ImplItem(item)) => match item.node { - hir::ImplItemKind::Existential(_) => ( - may_define_existential_type( + hir::ImplItemKind::OpaqueTy(_) => ( + may_define_opaque_type( tcx, self.parent_def_id, opaque_hir_id, ), - hir::ExistTyOrigin::ExistentialType, + hir::OpaqueTyOrigin::TraitAliasImplTrait, ), - _ => (def_scope_default(), hir::ExistTyOrigin::ExistentialType), + _ => { + (def_scope_default(), hir::OpaqueTyOrigin::TraitAliasImplTrait) + } }, _ => bug!( "expected (impl) item, found {}", @@ -1092,7 +1098,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { ty: Ty<'tcx>, def_id: DefId, substs: SubstsRef<'tcx>, - origin: hir::ExistTyOrigin, + origin: hir::OpaqueTyOrigin, ) -> Ty<'tcx> { let infcx = self.infcx; let tcx = infcx.tcx; @@ -1123,7 +1129,7 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { debug!("instantiate_opaque_types: required_region_bounds={:?}", required_region_bounds); // Make sure that we are in fact defining the *entire* type - // (e.g., `existential type Foo: Bar;` needs to be + // (e.g., `type Foo = impl Bar;` needs to be // defined by a function like `fn foo() -> Foo`). debug!("instantiate_opaque_types: param_env={:#?}", self.param_env,); debug!("instantiate_opaque_types: generics={:#?}", tcx.generics_of(def_id),); @@ -1171,7 +1177,9 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { /// ```rust /// pub mod foo { /// pub mod bar { -/// pub existential type Baz; +/// pub trait Bar { .. } +/// +/// pub type Baz = impl Bar; /// /// fn f1() -> Baz { .. } /// } @@ -1180,18 +1188,17 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> { /// } /// ``` /// -/// Here, `def_id` is the `DefId` of the defining use of the existential type (e.g., `f1` or `f2`), -/// and `opaque_hir_id` is the `HirId` of the definition of the existential type `Baz`. +/// Here, `def_id` is the `DefId` of the defining use of the opaque type (e.g., `f1` or `f2`), +/// and `opaque_hir_id` is the `HirId` of the definition of the opaque type `Baz`. /// For the above example, this function returns `true` for `f1` and `false` for `f2`. -pub fn may_define_existential_type( +pub fn may_define_opaque_type( tcx: TyCtxt<'_>, def_id: DefId, opaque_hir_id: hir::HirId, ) -> bool { let mut hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - - // Named existential types can be defined by any siblings or children of siblings. + // Named opaque types can be defined by any siblings or children of siblings. let scope = tcx.hir().get_defining_scope(opaque_hir_id).expect("could not get defining scope"); // We walk up the node tree until we hit the root or the scope of the opaque type. while hir_id != scope && hir_id != hir::CRATE_HIR_ID { diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 88de77829a6..1e4e3531e5f 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -638,7 +638,7 @@ impl Visitor<'tcx> for DeadVisitor<'tcx> { } self.visit_nested_body(body_id) } - hir::ImplItemKind::Existential(..) | + hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::Type(..) => {} } } diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index b9a95219d31..233cec2ef7d 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -188,7 +188,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { } } } - hir::ImplItemKind::Existential(..) | + hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::Type(_) => false, } } @@ -263,7 +263,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { // worklist, as determined by the privacy pass hir::ItemKind::ExternCrate(_) | hir::ItemKind::Use(..) | - hir::ItemKind::Existential(..) | + hir::ItemKind::OpaqueTy(..) | hir::ItemKind::Ty(..) | hir::ItemKind::Static(..) | hir::ItemKind::Mod(..) | @@ -301,7 +301,7 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { self.visit_nested_body(body) } } - hir::ImplItemKind::Existential(..) | + hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::Type(_) => {} } } diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index f6c62d191fa..4862af38022 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -480,16 +480,16 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { }; self.with(scope, |_, this| intravisit::walk_item(this, item)); } - hir::ItemKind::Existential(hir::ExistTy { + hir::ItemKind::OpaqueTy(hir::ExistTy { impl_trait_fn: Some(_), .. }) => { - // currently existential type declarations are just generated from impl Trait - // items. doing anything on this node is irrelevant, as we currently don't need + // Currently opaque type declarations are just generated from `impl Trait` + // items. Doing anything on this node is irrelevant, as we currently don't need // it. } hir::ItemKind::Ty(_, ref generics) - | hir::ItemKind::Existential(hir::ExistTy { + | hir::ItemKind::OpaqueTy(hir::ExistTy { impl_trait_fn: None, ref generics, .. @@ -627,9 +627,9 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { // the exist_ty generics let (generics, bounds) = match self.tcx.hir().expect_item(item_id.id).node { - // named existential types are reached via TyKind::Path - // this arm is for `impl Trait` in the types of statics, constants and locals - hir::ItemKind::Existential(hir::ExistTy { + // Named opaque `impl Trait` types are reached via `TyKind::Path`. + // This arm is for `impl Trait` in the types of statics, constants and locals. + hir::ItemKind::OpaqueTy(hir::ExistTy { impl_trait_fn: None, .. }) => { @@ -637,15 +637,15 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { return; } // RPIT (return position impl trait) - hir::ItemKind::Existential(hir::ExistTy { + hir::ItemKind::OpaqueTy(hir::ExistTy { ref generics, ref bounds, .. }) => (generics, bounds), - ref i => bug!("impl Trait pointed to non-existential type?? {:#?}", i), + ref i => bug!("`impl Trait` pointed to non-opaque type?? {:#?}", i), }; - // Resolve the lifetimes that are applied to the existential type. + // Resolve the lifetimes that are applied to the opaque type. // These are resolved in the current scope. // `fn foo<'a>() -> impl MyTrait<'a> { ... }` desugars to // `fn foo<'a>() -> MyAnonTy<'a> { ... }` @@ -855,7 +855,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { this.visit_ty(ty); }); } - Existential(ref bounds) => { + OpaqueTy(ref bounds) => { let generics = &impl_item.generics; let mut index = self.next_early_index(); let mut next_early_index = index; @@ -1254,7 +1254,7 @@ fn compute_object_lifetime_defaults(tcx: TyCtxt<'_>) -> HirIdMap( }; } let substs = translate_substs(selcx.infcx(), param_env, impl_def_id, substs, assoc_ty.node); - let ty = if let ty::AssocKind::Existential = assoc_ty.item.kind { + let ty = if let ty::AssocKind::OpaqueTy = assoc_ty.item.kind { let item_substs = InternalSubsts::identity_for_item(tcx, assoc_ty.item.def_id); tcx.mk_opaque(assoc_ty.item.def_id, item_substs) } else { diff --git a/src/librustc/traits/specialize/specialization_graph.rs b/src/librustc/traits/specialize/specialization_graph.rs index f736c5ef9b1..b43881defdb 100644 --- a/src/librustc/traits/specialize/specialization_graph.rs +++ b/src/librustc/traits/specialize/specialization_graph.rs @@ -484,13 +484,13 @@ impl<'tcx> Ancestors<'tcx> { | (Const, Const) | (Method, Method) | (Type, Type) - | (Type, Existential) + | (Type, OpaqueTy) => tcx.hygienic_eq(impl_item.ident, trait_item_name, trait_def_id), | (Const, _) | (Method, _) | (Type, _) - | (Existential, _) + | (OpaqueTy, _) => false, }).map(move |item| NodeItem { node: node, item: item }) }) diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 46b8114030f..f6190f3ec1b 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -281,14 +281,14 @@ impl<'a, V> LocalTableInContextMut<'a, V> { } } -/// All information necessary to validate and reveal an `impl Trait` or `existential Type` +/// All information necessary to validate and reveal an `impl Trait`. #[derive(RustcEncodable, RustcDecodable, Debug, HashStable)] pub struct ResolvedOpaqueTy<'tcx> { /// The revealed type as seen by this function. pub concrete_type: Ty<'tcx>, /// Generic parameters on the opaque type as passed by this function. - /// For `existential type Foo; fn foo() -> Foo { .. }` this is `[T, U]`, not - /// `[A, B]` + /// For `type Foo = impl Bar; fn foo() -> Foo { .. }` + /// this is `[T, U]`, not `[A, B]`. pub substs: SubstsRef<'tcx>, } @@ -392,9 +392,9 @@ pub struct TypeckTables<'tcx> { /// read-again by borrowck. pub free_region_map: FreeRegionMap<'tcx>, - /// All the existential types that are restricted to concrete types + /// All the opaque types that are restricted to concrete types /// by this function - pub concrete_existential_types: FxHashMap>, + pub concrete_opaque_types: FxHashMap>, /// Given the closure ID this map provides the list of UpvarIDs used by it. /// The upvarID contains the HIR node ID and it also contains the full path @@ -424,7 +424,7 @@ impl<'tcx> TypeckTables<'tcx> { used_trait_imports: Lrc::new(Default::default()), tainted_by_errors: false, free_region_map: Default::default(), - concrete_existential_types: Default::default(), + concrete_opaque_types: Default::default(), upvar_list: Default::default(), } } @@ -733,7 +733,7 @@ impl<'a, 'tcx> HashStable> for TypeckTables<'tcx> { ref used_trait_imports, tainted_by_errors, ref free_region_map, - ref concrete_existential_types, + ref concrete_opaque_types, ref upvar_list, } = *self; @@ -777,7 +777,7 @@ impl<'a, 'tcx> HashStable> for TypeckTables<'tcx> { used_trait_imports.hash_stable(hcx, hasher); tainted_by_errors.hash_stable(hcx, hasher); free_region_map.hash_stable(hcx, hasher); - concrete_existential_types.hash_stable(hcx, hasher); + concrete_opaque_types.hash_stable(hcx, hasher); upvar_list.hash_stable(hcx, hasher); }) } diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 44897c8e903..dbc0abcd222 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -185,7 +185,7 @@ pub struct AssocItem { pub enum AssocKind { Const, Method, - Existential, + OpaqueTy, Type } @@ -195,7 +195,7 @@ impl AssocItem { AssocKind::Const => DefKind::AssocConst, AssocKind::Method => DefKind::Method, AssocKind::Type => DefKind::AssocTy, - AssocKind::Existential => DefKind::AssocExistential, + AssocKind::OpaqueTy => DefKind::AssocOpaqueTy, } } @@ -203,7 +203,7 @@ impl AssocItem { /// for ! pub fn relevant_for_never(&self) -> bool { match self.kind { - AssocKind::Existential | + AssocKind::OpaqueTy | AssocKind::Const | AssocKind::Type => true, // FIXME(canndrew): Be more thorough here, check if any argument is uninhabited. @@ -221,7 +221,8 @@ impl AssocItem { tcx.fn_sig(self.def_id).skip_binder().to_string() } ty::AssocKind::Type => format!("type {};", self.ident), - ty::AssocKind::Existential => format!("existential type {};", self.ident), + // FIXME(trait_alias_impl_trait): we should print bounds here too. + ty::AssocKind::OpaqueTy => format!("type {};", self.ident), ty::AssocKind::Const => { format!("const {}: {:?};", self.ident, tcx.type_of(self.def_id)) } @@ -2822,7 +2823,7 @@ impl<'tcx> TyCtxt<'tcx> { (ty::AssocKind::Method, has_self) } hir::AssocItemKind::Type => (ty::AssocKind::Type, false), - hir::AssocItemKind::Existential => bug!("only impls can have existentials"), + hir::AssocItemKind::OpaqueTy => bug!("only impls can have opaque types"), }; AssocItem { @@ -2848,7 +2849,7 @@ impl<'tcx> TyCtxt<'tcx> { (ty::AssocKind::Method, has_self) } hir::AssocItemKind::Type => (ty::AssocKind::Type, false), - hir::AssocItemKind::Existential => (ty::AssocKind::Existential, false), + hir::AssocItemKind::OpaqueTy => (ty::AssocKind::OpaqueTy, false), }; AssocItem { @@ -3213,7 +3214,7 @@ fn trait_of_item(tcx: TyCtxt<'_>, def_id: DefId) -> Option { pub fn is_impl_trait_defn(tcx: TyCtxt<'_>, def_id: DefId) -> Option { if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) { if let Node::Item(item) = tcx.hir().get(hir_id) { - if let hir::ItemKind::Existential(ref exist_ty) = item.node { + if let hir::ItemKind::OpaqueTy(ref exist_ty) = item.node { return exist_ty.impl_trait_fn; } } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index 77b8ebba216..b8533424740 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -185,7 +185,7 @@ pub enum TyKind<'tcx> { /// Opaque (`impl Trait`) type found in a return type. /// The `DefId` comes either from /// * the `impl Trait` ast::Ty node, - /// * or the `existential type` declaration + /// * or the `type Foo = impl Trait` declaration /// The substitutions are for the generics of the function in question. /// After typeck, the concrete type can be found in the `types` map. Opaque(DefId, SubstsRef<'tcx>), diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index 1979b4317a7..d32c32af29e 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -362,7 +362,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { // should've been checked by the instantiation // of whatever returned this exact `impl Trait`. - // for named existential types we still need to check them + // for named opaque `impl Trait` types we still need to check them if super::is_impl_trait_defn(self.infcx.tcx, did).is_none() { let obligations = self.nominal_obligations(did, substs); self.out.extend(obligations); diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index aa98ebae543..e621101324d 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -406,7 +406,7 @@ impl DirtyCleanVisitor<'tcx> { ImplItemKind::Method(..) => ("Node::ImplItem", LABELS_FN_IN_IMPL), ImplItemKind::Const(..) => ("NodeImplConst", LABELS_CONST_IN_IMPL), ImplItemKind::Type(..) => ("NodeImplType", LABELS_CONST_IN_IMPL), - ImplItemKind::Existential(..) => ("NodeImplType", LABELS_CONST_IN_IMPL), + ImplItemKind::OpaqueTy(..) => ("NodeImplType", LABELS_CONST_IN_IMPL), } }, _ => self.tcx.sess.span_fatal( diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 6ac68e86e4b..08a8d400779 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -461,7 +461,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingDoc { hir::ImplItemKind::Const(..) => "an associated constant", hir::ImplItemKind::Method(..) => "a method", hir::ImplItemKind::Type(_) => "an associated type", - hir::ImplItemKind::Existential(_) => "an associated existential type", + hir::ImplItemKind::OpaqueTy(_) => "an associated `impl Trait` type", }; self.check_missing_docs_attrs(cx, Some(impl_item.hir_id), diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 8e76dbb882e..335ce868894 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -413,9 +413,9 @@ impl<'tcx> EntryKind<'tcx> { EntryKind::Type => DefKind::TyAlias, EntryKind::TypeParam => DefKind::TyParam, EntryKind::ConstParam => DefKind::ConstParam, - EntryKind::Existential => DefKind::Existential, + EntryKind::OpaqueTy => DefKind::OpaqueTy, EntryKind::AssocType(_) => DefKind::AssocTy, - EntryKind::AssocExistential(_) => DefKind::AssocExistential, + EntryKind::AssocOpaqueTy(_) => DefKind::AssocOpaqueTy, EntryKind::Mod(_) => DefKind::Mod, EntryKind::Variant(_) => DefKind::Variant, EntryKind::Trait(_) => DefKind::Trait, @@ -910,8 +910,8 @@ impl<'a, 'tcx> CrateMetadata { EntryKind::AssocType(container) => { (ty::AssocKind::Type, container, false) } - EntryKind::AssocExistential(container) => { - (ty::AssocKind::Existential, container, false) + EntryKind::AssocOpaqueTy(container) => { + (ty::AssocKind::OpaqueTy, container, false) } _ => bug!("cannot get associated-item of `{:?}`", def_key) }; diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 567b6b1a891..28252117dd2 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -868,8 +868,7 @@ impl EncodeContext<'tcx> { })) } ty::AssocKind::Type => EntryKind::AssocType(container), - ty::AssocKind::Existential => - span_bug!(ast_item.span, "existential type in trait"), + ty::AssocKind::OpaqueTy => span_bug!(ast_item.span, "opaque type in trait"), }; Entry { @@ -893,7 +892,7 @@ impl EncodeContext<'tcx> { None } } - ty::AssocKind::Existential => unreachable!(), + ty::AssocKind::OpaqueTy => unreachable!(), }, inherent_impls: LazySeq::empty(), variances: if trait_item.kind == ty::AssocKind::Method { @@ -964,7 +963,7 @@ impl EncodeContext<'tcx> { has_self: impl_item.method_has_self_argument, })) } - ty::AssocKind::Existential => EntryKind::AssocExistential(container), + ty::AssocKind::OpaqueTy => EntryKind::AssocOpaqueTy(container), ty::AssocKind::Type => EntryKind::AssocType(container) }; @@ -980,7 +979,7 @@ impl EncodeContext<'tcx> { let always_encode_mir = self.tcx.sess.opts.debugging_opts.always_encode_mir; needs_inline || is_const_fn || always_encode_mir }, - hir::ImplItemKind::Existential(..) | + hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::Type(..) => false, }; @@ -1096,7 +1095,7 @@ impl EncodeContext<'tcx> { hir::ItemKind::ForeignMod(_) => EntryKind::ForeignMod, hir::ItemKind::GlobalAsm(..) => EntryKind::GlobalAsm, hir::ItemKind::Ty(..) => EntryKind::Type, - hir::ItemKind::Existential(..) => EntryKind::Existential, + hir::ItemKind::OpaqueTy(..) => EntryKind::OpaqueTy, hir::ItemKind::Enum(..) => EntryKind::Enum(get_repr_options(tcx, def_id)), hir::ItemKind::Struct(ref struct_def, _) => { let variant = tcx.adt_def(def_id).non_enum_variant(); @@ -1229,7 +1228,7 @@ impl EncodeContext<'tcx> { hir::ItemKind::Const(..) | hir::ItemKind::Fn(..) | hir::ItemKind::Ty(..) | - hir::ItemKind::Existential(..) | + hir::ItemKind::OpaqueTy(..) | hir::ItemKind::Enum(..) | hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) | @@ -1253,7 +1252,7 @@ impl EncodeContext<'tcx> { hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) | hir::ItemKind::Impl(..) | - hir::ItemKind::Existential(..) | + hir::ItemKind::OpaqueTy(..) | hir::ItemKind::Trait(..) => Some(self.encode_generics(def_id)), hir::ItemKind::TraitAlias(..) => Some(self.encode_generics(def_id)), _ => None, @@ -1267,7 +1266,7 @@ impl EncodeContext<'tcx> { hir::ItemKind::Struct(..) | hir::ItemKind::Union(..) | hir::ItemKind::Impl(..) | - hir::ItemKind::Existential(..) | + hir::ItemKind::OpaqueTy(..) | hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) => Some(self.encode_predicates(def_id)), _ => None, @@ -1763,7 +1762,7 @@ impl EncodeContext<'tcx> { hir::ItemKind::ExternCrate(..) | hir::ItemKind::Use(..) | hir::ItemKind::Ty(..) | - hir::ItemKind::Existential(..) | + hir::ItemKind::OpaqueTy(..) | hir::ItemKind::TraitAlias(..) => { // no sub-item recording needed in these cases } diff --git a/src/librustc_metadata/schema.rs b/src/librustc_metadata/schema.rs index b7dd1d03e44..c0ac6915933 100644 --- a/src/librustc_metadata/schema.rs +++ b/src/librustc_metadata/schema.rs @@ -239,7 +239,7 @@ pub enum EntryKind<'tcx> { Type, TypeParam, ConstParam, - Existential, + OpaqueTy, Enum(ReprOptions), Field, Variant(Lazy>), @@ -255,7 +255,7 @@ pub enum EntryKind<'tcx> { Impl(Lazy>), Method(Lazy>), AssocType(AssocContainer), - AssocExistential(AssocContainer), + AssocOpaqueTy(AssocContainer), AssocConst(AssocContainer, ConstQualif, Lazy), TraitAlias(Lazy>), } diff --git a/src/librustc_mir/borrow_check/nll/type_check/input_output.rs b/src/librustc_mir/borrow_check/nll/type_check/input_output.rs index 3954d62ad5c..99661b1f737 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/input_output.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/input_output.rs @@ -1,7 +1,7 @@ //! This module contains code to equate the input/output types appearing //! in the MIR with the expected input/output types from the function //! signature. This requires a bit of processing, as the expected types -//! are supplied to us before normalization and may contain existential +//! are supplied to us before normalization and may contain opaque //! `impl Trait` instances. In contrast, the input/output types found in //! the MIR (specifically, in the special local variables for the //! `RETURN_PLACE` the MIR arguments) are always fully normalized (and @@ -113,8 +113,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { self.equate_normalized_input_or_output(ur_yield_ty, mir_yield_ty, yield_span); } - // Return types are a bit more complex. They may contain existential `impl Trait` - // types. + // Return types are a bit more complex. They may contain opaque `impl Trait` types. let mir_output_ty = body.local_decls[RETURN_PLACE].ty; let output_span = body.local_decls[RETURN_PLACE].source_info.span; if let Err(terr) = self.eq_opaque_type_and_type( diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 50c0640f885..3f1e1d83d85 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -1291,10 +1291,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { concrete_is_opaque ); - // concrete_is_opaque is `true` when we're using an existential + // concrete_is_opaque is `true` when we're using an opaque `impl Trait` // type without 'revealing' it. For example, code like this: // - // existential type Foo: Debug; + // type Foo = impl Debug; // fn foo1() -> Foo { ... } // fn foo2() -> Foo { foo1() } // @@ -1303,8 +1303,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // // When this occurs, we do *not* want to try to equate // the concrete type with the underlying defining type - // of the existential type - this will always fail, since - // the defining type of an existential type is always + // of the opaque type - this will always fail, since + // the defining type of an opaque type is always // some other type (e.g. not itself) // Essentially, none of the normal obligations apply here - // we're just passing around some unknown opaque type, diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index ee0f9119544..b378dadce58 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -972,7 +972,7 @@ impl ItemLikeVisitor<'v> for RootCollector<'_, 'v> { hir::ItemKind::Ty(..) | hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) | - hir::ItemKind::Existential(..) | + hir::ItemKind::OpaqueTy(..) | hir::ItemKind::Mod(..) => { // Nothing to do, just keep recursing... } diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 7ad37e65f71..3c31bcef32b 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -667,7 +667,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { "unions cannot have zero fields"); } } - ItemKind::Existential(ref bounds, _) => { + ItemKind::OpaqueTy(ref bounds, _) => { if !bounds.iter() .any(|b| if let GenericBound::Trait(..) = *b { true } else { false }) { let msp = MultiSpan::from_spans(bounds.iter() diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index e291f40ffd2..ac18f0e440b 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -533,7 +533,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { hir::ItemKind::GlobalAsm(..) | hir::ItemKind::Fn(..) | hir::ItemKind::Mod(..) | hir::ItemKind::Static(..) | hir::ItemKind::Struct(..) | hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..) | - hir::ItemKind::Existential(..) | + hir::ItemKind::OpaqueTy(..) | hir::ItemKind::Ty(..) | hir::ItemKind::Union(..) | hir::ItemKind::Use(..) => { if item.vis.node.is_pub() { self.prev_level } else { None } } @@ -584,7 +584,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { } } } - hir::ItemKind::Existential(..) | + hir::ItemKind::OpaqueTy(..) | hir::ItemKind::Use(..) | hir::ItemKind::Static(..) | hir::ItemKind::Const(..) | @@ -612,7 +612,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> { } // The interface is empty. hir::ItemKind::GlobalAsm(..) => {} - hir::ItemKind::Existential(..) => { + hir::ItemKind::OpaqueTy(..) => { // FIXME: This is some serious pessimization intended to workaround deficiencies // in the reachability pass (`middle/reachable.rs`). Types are marked as link-time // reachable if they are returned via `impl Trait`, even from private functions. @@ -1113,7 +1113,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> { DefKind::Method | DefKind::AssocConst | DefKind::AssocTy - | DefKind::AssocExistential + | DefKind::AssocOpaqueTy | DefKind::Static => true, _ => false, } @@ -1370,7 +1370,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { self.access_levels.is_reachable( impl_item_ref.id.hir_id) } - hir::ImplItemKind::Existential(..) | + hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::Type(_) => false, } }); @@ -1707,9 +1707,9 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> { let (check_ty, is_assoc_ty) = match assoc_item_kind { AssocItemKind::Const | AssocItemKind::Method { .. } => (true, false), AssocItemKind::Type => (defaultness.has_value(), true), - // `ty()` for existential types is the underlying type, + // `ty()` for opaque types is the underlying type, // it's not a part of interface, so we skip it. - AssocItemKind::Existential => (false, true), + AssocItemKind::OpaqueTy => (false, true), }; check.in_assoc_ty = is_assoc_ty; check.generics().predicates(); @@ -1742,8 +1742,8 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> hir::ItemKind::Fn(..) | hir::ItemKind::Ty(..) => { self.check(item.hir_id, item_visibility).generics().predicates().ty(); } - hir::ItemKind::Existential(..) => { - // `ty()` for existential types is the underlying type, + hir::ItemKind::OpaqueTy(..) => { + // `ty()` for opaque types is the underlying type, // it's not a part of interface, so we skip it. self.check(item.hir_id, item_visibility).generics().predicates(); } diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 41349cf72a1..b66cc9e57f7 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -464,8 +464,8 @@ impl<'a> Resolver<'a> { self.define(parent, ident, TypeNS, (res, vis, sp, expansion)); } - ItemKind::Existential(_, _) => { - let res = Res::Def(DefKind::Existential, self.definitions.local_def_id(item.id)); + ItemKind::OpaqueTy(_, _) => { + let res = Res::Def(DefKind::OpaqueTy, self.definitions.local_def_id(item.id)); self.define(parent, ident, TypeNS, (res, vis, sp, expansion)); } @@ -656,7 +656,7 @@ impl<'a> Resolver<'a> { Res::Def(DefKind::Variant, _) | Res::Def(DefKind::TyAlias, _) | Res::Def(DefKind::ForeignTy, _) - | Res::Def(DefKind::Existential, _) + | Res::Def(DefKind::OpaqueTy, _) | Res::Def(DefKind::TraitAlias, _) | Res::PrimTy(..) | Res::ToolMod => { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index c8dd8282fd0..a49be7c27c9 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -605,7 +605,7 @@ impl<'a> PathSource<'a> { | Res::PrimTy(..) | Res::Def(DefKind::TyParam, _) | Res::SelfTy(..) - | Res::Def(DefKind::Existential, _) + | Res::Def(DefKind::OpaqueTy, _) | Res::Def(DefKind::ForeignTy, _) => true, _ => false, }, @@ -2710,7 +2710,7 @@ impl<'a> Resolver<'a> { match item.node { ItemKind::Ty(_, ref generics) | - ItemKind::Existential(_, ref generics) | + ItemKind::OpaqueTy(_, ref generics) | ItemKind::Fn(_, _, ref generics, _) => { self.with_generic_param_rib( HasGenericParams(generics, ItemRibKind), @@ -3089,7 +3089,7 @@ impl<'a> Resolver<'a> { this.visit_ty(ty); } - ImplItemKind::Existential(ref bounds) => { + ImplItemKind::OpaqueTy(ref bounds) => { // If this is a trait impl, ensure the type // exists in trait this.check_trait_item(impl_item.ident, diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 6fce7ca1f33..3abec9307ee 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -1173,7 +1173,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> { // trait. self.visit_ty(ty) } - ast::ImplItemKind::Existential(ref bounds) => { + ast::ImplItemKind::OpaqueTy(ref bounds) => { // FIXME: uses of the assoc type should ideally point to this // 'def' and the name here should be a ref to the def in the // trait. @@ -1428,7 +1428,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> { self.visit_ty(&ty); self.process_generic_params(ty_params, &qualname, item.id); } - Existential(ref _bounds, ref ty_params) => { + OpaqueTy(ref _bounds, ref ty_params) => { let qualname = format!("::{}", self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))); // FIXME do something with _bounds diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 634e8db9ea6..c699a8834e0 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -725,10 +725,10 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> { Res::Def(HirDefKind::TyAlias, def_id) | Res::Def(HirDefKind::ForeignTy, def_id) | Res::Def(HirDefKind::TraitAlias, def_id) | - Res::Def(HirDefKind::AssocExistential, def_id) | + Res::Def(HirDefKind::AssocOpaqueTy, def_id) | Res::Def(HirDefKind::AssocTy, def_id) | Res::Def(HirDefKind::Trait, def_id) | - Res::Def(HirDefKind::Existential, def_id) | + Res::Def(HirDefKind::OpaqueTy, def_id) | Res::Def(HirDefKind::TyParam, def_id) => { Some(Ref { kind: RefKind::Type, diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index db8b5eacd94..0aab8125f80 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -438,12 +438,12 @@ impl Sig for ast::Item { refs: vec![], }) } - ast::ItemKind::Existential(ref bounds, ref generics) => { - let text = "existential type ".to_owned(); + ast::ItemKind::OpaqueTy(ref bounds, ref generics) => { + let text = "type ".to_owned(); let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?; if !bounds.is_empty() { - sig.text.push_str(": "); + sig.text.push_str(" = impl "); sig.text.push_str(&pprust::bounds_to_string(bounds)); } sig.text.push(';'); diff --git a/src/librustc_traits/lowering/mod.rs b/src/librustc_traits/lowering/mod.rs index c81b1dc8974..1558ce1bced 100644 --- a/src/librustc_traits/lowering/mod.rs +++ b/src/librustc_traits/lowering/mod.rs @@ -173,7 +173,7 @@ crate fn program_clauses_for(tcx: TyCtxt<'_>, def_id: DefId) -> Clauses<'_> { | Some(DefKind::Enum) | Some(DefKind::TyAlias) | Some(DefKind::Union) - | Some(DefKind::Existential) => program_clauses_for_type_def(tcx, def_id), + | Some(DefKind::OpaqueTy) => program_clauses_for_type_def(tcx, def_id), _ => List::empty(), }, DefPathData::Impl => program_clauses_for_impl(tcx, def_id), diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 5799e58a727..e8e0dd8425b 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1956,7 +1956,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let span = path.span; match path.res { - Res::Def(DefKind::Existential, did) => { + Res::Def(DefKind::OpaqueTy, did) => { // Check for desugared `impl Trait`. assert!(ty::is_impl_trait_defn(tcx, did).is_none()); let item_segment = path.segments.split_last().unwrap(); diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 75428efa73c..1c01c8408be 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -1489,7 +1489,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { match self.mode { Mode::MethodCall => item.method_has_self_argument, Mode::Path => match item.kind { - ty::AssocKind::Existential | + ty::AssocKind::OpaqueTy | ty::AssocKind::Type => false, ty::AssocKind::Method | ty::AssocKind::Const => true }, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 1b4dbfe4be6..26d5f462d8d 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1330,10 +1330,10 @@ fn check_opaque<'tcx>( def_id: DefId, substs: SubstsRef<'tcx>, span: Span, - origin: &hir::ExistTyOrigin + origin: &hir::OpaqueTyOrigin ) { if let Err(partially_expanded_type) = tcx.try_expand_impl_trait_type(def_id, substs) { - if let hir::ExistTyOrigin::AsyncFn = origin { + if let hir::OpaqueTyOrigin::AsyncFn = origin { struct_span_err!( tcx.sess, span, E0733, "recursion in an `async fn` requires boxing", @@ -1403,7 +1403,7 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item) { hir::ItemKind::Union(..) => { check_union(tcx, it.hir_id, it.span); } - hir::ItemKind::Existential(hir::ExistTy{origin, ..}) => { + hir::ItemKind::OpaqueTy(hir::ExistTy{origin, ..}) => { let def_id = tcx.hir().local_def_id(it.hir_id); let substs = InternalSubsts::identity_for_item(tcx, def_id); @@ -1542,7 +1542,7 @@ fn check_specialization_validity<'tcx>( let kind = match impl_item.node { hir::ImplItemKind::Const(..) => ty::AssocKind::Const, hir::ImplItemKind::Method(..) => ty::AssocKind::Method, - hir::ImplItemKind::Existential(..) => ty::AssocKind::Existential, + hir::ImplItemKind::OpaqueTy(..) => ty::AssocKind::OpaqueTy, hir::ImplItemKind::Type(_) => ty::AssocKind::Type }; @@ -1639,7 +1639,7 @@ fn check_impl_items_against_trait<'tcx>( err.emit() } } - hir::ImplItemKind::Existential(..) | + hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::Type(_) => { if ty_trait_item.kind == ty::AssocKind::Type { if ty_trait_item.defaultness.has_value() { diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 32f1f8c6188..35a49d95ec0 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -8,7 +8,7 @@ use rustc::ty::subst::{Subst, InternalSubsts}; use rustc::util::nodemap::{FxHashSet, FxHashMap}; use rustc::mir::interpret::ConstValue; use rustc::middle::lang_items; -use rustc::infer::opaque_types::may_define_existential_type; +use rustc::infer::opaque_types::may_define_opaque_type; use syntax::ast; use syntax::feature_gate::{self, GateIssue}; @@ -218,8 +218,8 @@ fn check_associated_item( fcx.register_wf_obligation(ty, span, code.clone()); } } - ty::AssocKind::Existential => { - // do nothing, existential types check themselves + ty::AssocKind::OpaqueTy => { + // do nothing, opaque types check themselves } } @@ -560,7 +560,7 @@ fn check_where_clauses<'tcx, 'fcx>( let mut predicates = predicates.instantiate_identity(fcx.tcx); if let Some(return_ty) = return_ty { - predicates.predicates.extend(check_existential_types(tcx, fcx, def_id, span, return_ty)); + predicates.predicates.extend(check_opaque_types(tcx, fcx, def_id, span, return_ty)); } let predicates = fcx.normalize_associated_types_in(span, &predicates); @@ -605,14 +605,14 @@ fn check_fn_or_method<'fcx, 'tcx>( check_where_clauses(tcx, fcx, span, def_id, Some(sig.output())); } -/// Checks "defining uses" of existential types to ensure that they meet the restrictions laid for -/// "higher-order pattern unification". +/// Checks "defining uses" of opaque `impl Trait` types to ensure that they meet the restrictions +/// laid for "higher-order pattern unification". /// This ensures that inference is tractable. -/// In particular, definitions of existential types can only use other generics as arguments, +/// In particular, definitions of opaque types can only use other generics as arguments, /// and they cannot repeat an argument. Example: /// /// ```rust -/// existential type Foo; +/// type Foo = impl Bar; /// /// // Okay -- `Foo` is applied to two distinct, generic types. /// fn a() -> Foo { .. } @@ -624,26 +624,26 @@ fn check_fn_or_method<'fcx, 'tcx>( /// fn b() -> Foo { .. } /// ``` /// -fn check_existential_types<'fcx, 'tcx>( +fn check_opaque_types<'fcx, 'tcx>( tcx: TyCtxt<'tcx>, fcx: &FnCtxt<'fcx, 'tcx>, fn_def_id: DefId, span: Span, ty: Ty<'tcx>, ) -> Vec> { - trace!("check_existential_types(ty={:?})", ty); + trace!("check_opaque_types(ty={:?})", ty); let mut substituted_predicates = Vec::new(); ty.fold_with(&mut ty::fold::BottomUpFolder { tcx: fcx.tcx, ty_op: |ty| { if let ty::Opaque(def_id, substs) = ty.sty { - trace!("check_existential_types: opaque_ty, {:?}, {:?}", def_id, substs); + trace!("check_opaque_types: opaque_ty, {:?}, {:?}", def_id, substs); let generics = tcx.generics_of(def_id); - // Only check named existential types defined in this crate. + // Only check named `impl Trait` types defined in this crate. if generics.parent.is_none() && def_id.is_local() { let opaque_hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); - if may_define_existential_type(tcx, fn_def_id, opaque_hir_id) { - trace!("check_existential_types: may define, generics={:#?}", generics); + if may_define_opaque_type(tcx, fn_def_id, opaque_hir_id) { + trace!("check_opaque_types: may define, generics={:#?}", generics); let mut seen: FxHashMap<_, Vec<_>> = FxHashMap::default(); for (subst, param) in substs.iter().zip(&generics.params) { match subst.unpack() { @@ -654,7 +654,7 @@ fn check_existential_types<'fcx, 'tcx>( tcx.sess .struct_span_err( span, - "non-defining existential type use \ + "non-defining opaque type use \ in defining scope", ) .span_note( @@ -676,14 +676,14 @@ fn check_existential_types<'fcx, 'tcx>( .sess .struct_span_err( span, - "non-defining existential type use \ + "non-defining opaque type use \ in defining scope", ) .span_label( param_span, - "cannot use static lifetime, use a bound lifetime \ + "cannot use static lifetime; use a bound lifetime \ instead or remove the lifetime parameter from the \ - existential type", + opaque type", ) .emit(); } else { @@ -697,7 +697,7 @@ fn check_existential_types<'fcx, 'tcx>( tcx.sess .struct_span_err( span, - "non-defining existential type use \ + "non-defining opaque type use \ in defining scope", ) .span_note( @@ -719,7 +719,7 @@ fn check_existential_types<'fcx, 'tcx>( .sess .struct_span_err( span, - "non-defining existential type use \ + "non-defining opaque type use \ in defining scope", ). span_note( @@ -729,21 +729,21 @@ fn check_existential_types<'fcx, 'tcx>( .emit(); } } - } // if may_define_existential_type + } // if may_define_opaque_type - // Now register the bounds on the parameters of the existential type + // Now register the bounds on the parameters of the opaque type // so the parameters given by the function need to fulfill them. // - // existential type Foo: 'static; + // type Foo = impl Baz + 'static; // fn foo() -> Foo { .. *} // // becomes // - // existential type Foo: 'static; + // type Foo = impl Baz + 'static; // fn foo() -> Foo { .. *} let predicates = tcx.predicates_of(def_id); trace!( - "check_existential_types: may define, predicates={:#?}", + "check_opaque_types: may define, predicates={:#?}", predicates, ); for &(pred, _) in predicates.predicates.iter() { @@ -753,7 +753,7 @@ fn check_existential_types<'fcx, 'tcx>( substituted_predicates.push(substituted_pred); } } - } // if is_named_existential_type + } // if is_named_opaque_type } // if let Opaque ty }, diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index cfafdd02a6a..67a8ecaf1da 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -443,10 +443,10 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { // * `fn foo() -> Foo` // from being defining. - // Also replace all generic params with the ones from the existential type + // Also replace all generic params with the ones from the opaque type // definition so that // ```rust - // existential type Foo: 'static; + // type Foo = impl Baz + 'static; // fn foo() -> Foo { .. } // ``` // figures out the concrete type with `U`, but the stored type is with `T`. @@ -464,8 +464,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { } if !opaque_defn.substs.has_local_value() { - // We only want to add an entry into `concrete_existential_types` - // if we actually found a defining usage of this existential type. + // We only want to add an entry into `concrete_opaque_types` + // if we actually found a defining usage of this opaque type. // Otherwise, we do nothing - we'll either find a defining usage // in some other location, or we'll end up emitting an error due // to the lack of defining usage @@ -476,14 +476,14 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { }; let old = self.tables - .concrete_existential_types + .concrete_opaque_types .insert(def_id, new); if let Some(old) = old { if old.concrete_type != definition_ty || old.substs != opaque_defn.substs { span_bug!( span, "visit_opaque_types tried to write different types for the same \ - existential type: {:?}, {:?}, {:?}, {:?}", + opaque type: {:?}, {:?}, {:?}, {:?}", def_id, definition_ty, opaque_defn, diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 395e266ae46..e1334b60e53 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -294,7 +294,7 @@ fn type_param_predicates( ItemKind::Fn(.., ref generics, _) | ItemKind::Impl(_, _, _, ref generics, ..) | ItemKind::Ty(_, ref generics) - | ItemKind::Existential(ExistTy { + | ItemKind::OpaqueTy(ExistTy { ref generics, impl_trait_fn: None, .. @@ -456,12 +456,12 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) { } // Desugared from `impl Trait`, so visited by the function's return type. - hir::ItemKind::Existential(hir::ExistTy { + hir::ItemKind::OpaqueTy(hir::ExistTy { impl_trait_fn: Some(_), .. }) => {} - hir::ItemKind::Existential(..) + hir::ItemKind::OpaqueTy(..) | hir::ItemKind::Ty(..) | hir::ItemKind::Static(..) | hir::ItemKind::Const(..) @@ -896,7 +896,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics { .. }) => Some(tcx.closure_base_def_id(def_id)), Node::Item(item) => match item.node { - ItemKind::Existential(hir::ExistTy { impl_trait_fn, .. }) => impl_trait_fn, + ItemKind::OpaqueTy(hir::ExistTy { impl_trait_fn, .. }) => impl_trait_fn, _ => None, }, _ => None, @@ -920,7 +920,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics { ItemKind::Ty(_, ref generics) | ItemKind::Enum(_, ref generics) | ItemKind::Struct(_, ref generics) - | ItemKind::Existential(hir::ExistTy { ref generics, .. }) + | ItemKind::OpaqueTy(hir::ExistTy { ref generics, .. }) | ItemKind::Union(_, ref generics) => { allow_defaults = true; generics @@ -1210,7 +1210,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option { + ImplItemKind::OpaqueTy(_) => { if tcx .impl_trait_ref(tcx.hir().get_parent_did(hir_id)) .is_none() @@ -1218,7 +1218,7 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option { if tcx @@ -1253,27 +1253,27 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option find_existential_constraints(tcx, def_id), - // Existential types desugared from `impl Trait`. - ItemKind::Existential(hir::ExistTy { + }) => find_opaque_ty_constraints(tcx, def_id), + // Opaque types desugared from `impl Trait`. + ItemKind::OpaqueTy(hir::ExistTy { impl_trait_fn: Some(owner), .. }) => { tcx.typeck_tables_of(owner) - .concrete_existential_types + .concrete_opaque_types .get(&def_id) .map(|opaque| opaque.concrete_type) .unwrap_or_else(|| { // This can occur if some error in the // owner fn prevented us from populating - // the `concrete_existential_types` table. + // the `concrete_opaque_types` table. tcx.sess.delay_span_bug( DUMMY_SP, &format!( - "owner {:?} has no existential type for {:?} in its tables", + "owner {:?} has no opaque type for {:?} in its tables", owner, def_id, ), ); @@ -1505,20 +1505,20 @@ pub fn checked_type_of(tcx: TyCtxt<'_>, def_id: DefId, fail: bool) -> Option, def_id: DefId) -> Ty<'_> { +fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { use rustc::hir::{ImplItem, Item, TraitItem}; - debug!("find_existential_constraints({:?})", def_id); + debug!("find_opaque_ty_constraints({:?})", def_id); struct ConstraintLocator<'tcx> { tcx: TyCtxt<'tcx>, def_id: DefId, - // (first found type span, actual type, mapping from the existential type's generic + // (first found type span, actual type, mapping from the opaque type's generic // parameters to the concrete type's generic parameters) // // The mapping is an index for each use site of a generic parameter in the concrete type // - // The indices index into the generic parameters on the existential type. + // The indices index into the generic parameters on the opaque type. found: Option<(Span, Ty<'tcx>, Vec)>, } @@ -1527,7 +1527,7 @@ fn find_existential_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { // Don't try to check items that cannot possibly constrain the type. if !self.tcx.has_typeck_tables(def_id) { debug!( - "find_existential_constraints: no constraint for `{:?}` at `{:?}`: no tables", + "find_opaque_ty_constraints: no constraint for `{:?}` at `{:?}`: no tables", self.def_id, def_id, ); @@ -1536,11 +1536,11 @@ fn find_existential_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { let ty = self .tcx .typeck_tables_of(def_id) - .concrete_existential_types + .concrete_opaque_types .get(&self.def_id); if let Some(ty::ResolvedOpaqueTy { concrete_type, substs }) = ty { debug!( - "find_existential_constraints: found constraint for `{:?}` at `{:?}`: {:?}", + "find_opaque_ty_constraints: found constraint for `{:?}` at `{:?}`: {:?}", self.def_id, def_id, ty, @@ -1561,7 +1561,7 @@ fn find_existential_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { self.tcx.sess.span_err( span, &format!( - "defining existential type use restricts existential \ + "defining opaque type use restricts opaque \ type by using the generic parameter `{}` twice", p.name ), @@ -1572,14 +1572,14 @@ fn find_existential_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { self.tcx.sess.delay_span_bug( span, &format!( - "non-defining exist ty use in defining scope: {:?}, {:?}", + "non-defining opaque ty use in defining scope: {:?}, {:?}", concrete_type, substs, ), ); } } } - // Compute the index within the existential type for each generic parameter used in + // Compute the index within the opaque type for each generic parameter used in // the concrete type. let indices = concrete_type .subst(self.tcx, substs) @@ -1595,7 +1595,7 @@ fn find_existential_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { if !substs.types().all(is_param) { self.tcx.sess.span_err( span, - "defining existential type use does not fully define existential type", + "defining opaque type use does not fully define opaque type", ); } else if let Some((prev_span, prev_ty, ref prev_indices)) = self.found { let mut ty = concrete_type.walk().fuse(); @@ -1608,11 +1608,11 @@ fn find_existential_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { _ => t == p, }); if !iter_eq || ty.next().is_some() || p_ty.next().is_some() { - debug!("find_existential_constraints: span={:?}", span); - // Found different concrete types for the existential type. + debug!("find_opaque_ty_constraints: span={:?}", span); + // Found different concrete types for the opaque type. let mut err = self.tcx.sess.struct_span_err( span, - "concrete type differs from previous defining existential type use", + "concrete type differs from previous defining opaque type use", ); err.span_label( span, @@ -1651,7 +1651,7 @@ fn find_existential_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { } } else { debug!( - "find_existential_constraints: no constraint for `{:?}` at `{:?}`", + "find_opaque_ty_constraints: no constraint for `{:?}` at `{:?}`", self.def_id, def_id, ); @@ -1666,7 +1666,7 @@ fn find_existential_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { fn visit_item(&mut self, it: &'tcx Item) { debug!("find_existential_constraints: visiting {:?}", it); let def_id = self.tcx.hir().local_def_id(it.hir_id); - // The existential type itself or its children are not within its reveal scope. + // The opaque type itself or its children are not within its reveal scope. if def_id != self.def_id { self.check(def_id); intravisit::walk_item(self, it); @@ -1675,7 +1675,7 @@ fn find_existential_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { fn visit_impl_item(&mut self, it: &'tcx ImplItem) { debug!("find_existential_constraints: visiting {:?}", it); let def_id = self.tcx.hir().local_def_id(it.hir_id); - // The existential type itself or its children are not within its reveal scope. + // The opaque type itself or its children are not within its reveal scope. if def_id != self.def_id { self.check(def_id); intravisit::walk_impl_item(self, it); @@ -1699,12 +1699,12 @@ fn find_existential_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { found: None, }; - debug!("find_existential_constraints: scope={:?}", scope); + debug!("find_opaque_ty_constraints: scope={:?}", scope); if scope == hir::CRATE_HIR_ID { intravisit::walk_crate(&mut locator, tcx.hir().krate()); } else { - debug!("find_existential_constraints: scope={:?}", tcx.hir().get(scope)); + debug!("find_opaque_ty_constraints: scope={:?}", tcx.hir().get(scope)); match tcx.hir().get(scope) { // We explicitly call `visit_*` methods, instead of using `intravisit::walk_*` methods // This allows our visitor to process the defining item itself, causing @@ -1724,7 +1724,7 @@ fn find_existential_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { Node::ImplItem(ref it) => locator.visit_impl_item(it), Node::TraitItem(ref it) => locator.visit_trait_item(it), other => bug!( - "{:?} is not a valid scope for an existential type item", + "{:?} is not a valid scope for an opaque type item", other ), } @@ -2010,7 +2010,7 @@ fn explicit_predicates_of( Node::TraitItem(item) => &item.generics, Node::ImplItem(item) => match item.node { - ImplItemKind::Existential(ref bounds) => { + ImplItemKind::OpaqueTy(ref bounds) => { let substs = InternalSubsts::identity_for_item(tcx, def_id); let opaque_ty = tcx.mk_opaque(def_id, substs); @@ -2051,7 +2051,7 @@ fn explicit_predicates_of( is_trait = Some((ty::TraitRef::identity(tcx, def_id), &empty_trait_items)); generics } - ItemKind::Existential(ExistTy { + ItemKind::OpaqueTy(ExistTy { ref bounds, impl_trait_fn, ref generics, @@ -2077,7 +2077,7 @@ fn explicit_predicates_of( predicates: bounds_predicates, }); } else { - // named existential types + // named opaque types predicates.extend(bounds_predicates); generics } diff --git a/src/librustc_typeck/namespace.rs b/src/librustc_typeck/namespace.rs index 9b6c5bd9f42..732f0d3ebf2 100644 --- a/src/librustc_typeck/namespace.rs +++ b/src/librustc_typeck/namespace.rs @@ -11,7 +11,7 @@ pub enum Namespace { impl From for Namespace { fn from(a_kind: ty::AssocKind) -> Self { match a_kind { - ty::AssocKind::Existential | + ty::AssocKind::OpaqueTy | ty::AssocKind::Type => Namespace::Type, ty::AssocKind::Const | ty::AssocKind::Method => Namespace::Value, @@ -22,7 +22,7 @@ impl From for Namespace { impl<'a> From <&'a hir::ImplItemKind> for Namespace { fn from(impl_kind: &'a hir::ImplItemKind) -> Self { match *impl_kind { - hir::ImplItemKind::Existential(..) | + hir::ImplItemKind::OpaqueTy(..) | hir::ImplItemKind::Type(..) => Namespace::Type, hir::ImplItemKind::Const(..) | hir::ImplItemKind::Method(..) => Namespace::Value, diff --git a/src/librustc_typeck/outlives/implicit_infer.rs b/src/librustc_typeck/outlives/implicit_infer.rs index 6b288347ad0..7cb9c5f04c9 100644 --- a/src/librustc_typeck/outlives/implicit_infer.rs +++ b/src/librustc_typeck/outlives/implicit_infer.rs @@ -296,7 +296,7 @@ pub fn check_explicit_predicates<'tcx>( // struct MyStruct<'x, X> { field: Box> } // ``` // - // The `where Self: 'a` predicate refers to the *existential, hidden type* + // The `where Self: 'a` predicate refers to the *opaque, hidden type* // that is represented by the `dyn Trait`, not to the `X` type parameter // (or any other generic parameter) declared on `MyStruct`. // diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 30419d3d3c6..c82d61632d5 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -538,7 +538,7 @@ pub enum ItemEnum { FunctionItem(Function), ModuleItem(Module), TypedefItem(Typedef, bool /* is associated type */), - ExistentialItem(Existential, bool /* is associated type */), + OpaqueTyItem(OpaqueTy, bool /* is associated type */), StaticItem(Static), ConstantItem(Constant), TraitItem(Trait), @@ -574,7 +574,7 @@ impl ItemEnum { ItemEnum::EnumItem(ref e) => &e.generics, ItemEnum::FunctionItem(ref f) => &f.generics, ItemEnum::TypedefItem(ref t, _) => &t.generics, - ItemEnum::ExistentialItem(ref t, _) => &t.generics, + ItemEnum::OpaqueTyItem(ref t, _) => &t.generics, ItemEnum::TraitItem(ref t) => &t.generics, ItemEnum::ImplItem(ref i) => &i.generics, ItemEnum::TyMethodItem(ref i) => &i.generics, @@ -623,7 +623,7 @@ impl Clean for doctree::Module<'_> { items.extend(self.foreigns.iter().map(|x| x.clean(cx))); items.extend(self.mods.iter().map(|x| x.clean(cx))); items.extend(self.typedefs.iter().map(|x| x.clean(cx))); - items.extend(self.existentials.iter().map(|x| x.clean(cx))); + items.extend(self.opaque_tys.iter().map(|x| x.clean(cx))); items.extend(self.statics.iter().map(|x| x.clean(cx))); items.extend(self.constants.iter().map(|x| x.clean(cx))); items.extend(self.traits.iter().map(|x| x.clean(cx))); @@ -2257,7 +2257,7 @@ impl Clean for hir::ImplItem { type_: ty.clean(cx), generics: Generics::default(), }, true), - hir::ImplItemKind::Existential(ref bounds) => ExistentialItem(Existential { + hir::ImplItemKind::OpaqueTy(ref bounds) => OpaqueTyItem(OpaqueTy { bounds: bounds.clean(cx), generics: Generics::default(), }, true), @@ -2415,7 +2415,7 @@ impl Clean for ty::AssocItem { }, true) } } - ty::AssocKind::Existential => unimplemented!(), + ty::AssocKind::OpaqueTy => unimplemented!(), }; let visibility = match self.container { @@ -2776,7 +2776,7 @@ impl Clean for hir::Ty { TyKind::Tup(ref tys) => Tuple(tys.clean(cx)), TyKind::Def(item_id, _) => { let item = cx.tcx.hir().expect_item(item_id.id); - if let hir::ItemKind::Existential(ref ty) = item.node { + if let hir::ItemKind::OpaqueTy(ref ty) = item.node { ImplTrait(ty.bounds.clean(cx)) } else { unreachable!() @@ -3648,12 +3648,12 @@ impl Clean for doctree::Typedef<'_> { } #[derive(Clone, Debug)] -pub struct Existential { +pub struct OpaqueTy { pub bounds: Vec, pub generics: Generics, } -impl Clean for doctree::Existential<'_> { +impl Clean for doctree::OpaqueTy<'_> { fn clean(&self, cx: &DocContext<'_>) -> Item { Item { name: Some(self.name.clean(cx)), @@ -3663,7 +3663,7 @@ impl Clean for doctree::Existential<'_> { visibility: self.vis.clean(cx), stability: self.stab.clean(cx), deprecation: self.depr.clean(cx), - inner: ExistentialItem(Existential { + inner: OpaqueTyItem(OpaqueTy { bounds: self.exist_ty.bounds.clean(cx), generics: self.exist_ty.generics.clean(cx), }, false), diff --git a/src/librustdoc/doctree.rs b/src/librustdoc/doctree.rs index 45a3c8a3c22..ec60241a92d 100644 --- a/src/librustdoc/doctree.rs +++ b/src/librustdoc/doctree.rs @@ -26,7 +26,7 @@ pub struct Module<'hir> { pub mods: Vec>, pub id: NodeId, pub typedefs: Vec>, - pub existentials: Vec>, + pub opaque_tys: Vec>, pub statics: Vec>, pub constants: Vec>, pub traits: Vec>, @@ -64,7 +64,7 @@ impl Module<'hir> { fns : Vec::new(), mods : Vec::new(), typedefs : Vec::new(), - existentials: Vec::new(), + opaque_tys : Vec::new(), statics : Vec::new(), constants : Vec::new(), traits : Vec::new(), @@ -162,8 +162,8 @@ pub struct Typedef<'hir> { pub depr: Option, } -pub struct Existential<'hir> { - pub exist_ty: &'hir hir::ExistTy, +pub struct OpaqueTy<'hir> { + pub opaque_ty: &'hir hir::OpaqueTy, pub name: Name, pub id: hir::HirId, pub attrs: &'hir hir::HirVec, diff --git a/src/librustdoc/html/item_type.rs b/src/librustdoc/html/item_type.rs index 9affc08141d..dde729b655d 100644 --- a/src/librustdoc/html/item_type.rs +++ b/src/librustdoc/html/item_type.rs @@ -39,7 +39,7 @@ pub enum ItemType { Union = 19, ForeignType = 20, Keyword = 21, - Existential = 22, + OpaqueTy = 22, ProcAttribute = 23, ProcDerive = 24, TraitAlias = 25, @@ -70,7 +70,7 @@ impl<'a> From<&'a clean::Item> for ItemType { clean::EnumItem(..) => ItemType::Enum, clean::FunctionItem(..) => ItemType::Function, clean::TypedefItem(..) => ItemType::Typedef, - clean::ExistentialItem(..) => ItemType::Existential, + clean::OpaqueTyItem(..) => ItemType::OpaqueTy, clean::StaticItem(..) => ItemType::Static, clean::ConstantItem(..) => ItemType::Constant, clean::TraitItem(..) => ItemType::Trait, @@ -144,7 +144,7 @@ impl ItemType { ItemType::AssocConst => "associatedconstant", ItemType::ForeignType => "foreigntype", ItemType::Keyword => "keyword", - ItemType::Existential => "existential", + ItemType::OpaqueTy => "opaque", ItemType::ProcAttribute => "attr", ItemType::ProcDerive => "derive", ItemType::TraitAlias => "traitalias", @@ -161,7 +161,7 @@ impl ItemType { ItemType::Trait | ItemType::Primitive | ItemType::AssocType | - ItemType::Existential | + ItemType::OpaqueTy | ItemType::TraitAlias | ItemType::ForeignType => NameSpace::Type, diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 62cfc61ce2d..962546cb3bc 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1883,7 +1883,7 @@ struct AllTypes { macros: FxHashSet, functions: FxHashSet, typedefs: FxHashSet, - existentials: FxHashSet, + opaque_tys: FxHashSet, statics: FxHashSet, constants: FxHashSet, keywords: FxHashSet, @@ -1904,7 +1904,7 @@ impl AllTypes { macros: new_set(100), functions: new_set(100), typedefs: new_set(100), - existentials: new_set(100), + opaque_tys: new_set(100), statics: new_set(100), constants: new_set(100), keywords: new_set(100), @@ -1929,7 +1929,7 @@ impl AllTypes { ItemType::Macro => self.macros.insert(ItemEntry::new(new_url, name)), ItemType::Function => self.functions.insert(ItemEntry::new(new_url, name)), ItemType::Typedef => self.typedefs.insert(ItemEntry::new(new_url, name)), - ItemType::Existential => self.existentials.insert(ItemEntry::new(new_url, name)), + ItemType::OpaqueTy => self.opaque_tys.insert(ItemEntry::new(new_url, name)), ItemType::Static => self.statics.insert(ItemEntry::new(new_url, name)), ItemType::Constant => self.constants.insert(ItemEntry::new(new_url, name)), ItemType::ProcAttribute => self.attributes.insert(ItemEntry::new(new_url, name)), @@ -1979,7 +1979,7 @@ impl fmt::Display for AllTypes { print_entries(f, &self.functions, "Functions", "functions")?; print_entries(f, &self.typedefs, "Typedefs", "typedefs")?; print_entries(f, &self.trait_aliases, "Trait Aliases", "trait-aliases")?; - print_entries(f, &self.existentials, "Existentials", "existentials")?; + print_entries(f, &self.opaque_tys, "Opaque Types", "opaque-types")?; print_entries(f, &self.statics, "Statics", "statics")?; print_entries(f, &self.constants, "Constants", "constants") } @@ -2477,7 +2477,7 @@ impl<'a> fmt::Display for Item<'a> { clean::ConstantItem(..) => write!(fmt, "Constant ")?, clean::ForeignTypeItem => write!(fmt, "Foreign Type ")?, clean::KeywordItem(..) => write!(fmt, "Keyword ")?, - clean::ExistentialItem(..) => write!(fmt, "Existential Type ")?, + clean::OpaqueTyItem(..) => write!(fmt, "Opaque Type ")?, clean::TraitAliasItem(..) => write!(fmt, "Trait Alias ")?, _ => { // We don't generate pages for any other type. @@ -2516,7 +2516,7 @@ impl<'a> fmt::Display for Item<'a> { clean::ConstantItem(ref c) => item_constant(fmt, self.cx, self.item, c), clean::ForeignTypeItem => item_foreign_type(fmt, self.cx, self.item), clean::KeywordItem(ref k) => item_keyword(fmt, self.cx, self.item, k), - clean::ExistentialItem(ref e, _) => item_existential(fmt, self.cx, self.item, e), + clean::OpaqueTyItem(ref e, _) => item_opaque_ty(fmt, self.cx, self.item, e), clean::TraitAliasItem(ref ta) => item_trait_alias(fmt, self.cx, self.item, ta), _ => { // We don't generate pages for any other type. @@ -4387,15 +4387,15 @@ fn render_impl(w: &mut fmt::Formatter<'_>, cx: &Context, i: &Impl, link: AssocIt Ok(()) } -fn item_existential( +fn item_opaque_ty( w: &mut fmt::Formatter<'_>, cx: &Context, it: &clean::Item, - t: &clean::Existential, + t: &clean::OpaqueTy, ) -> fmt::Result { - write!(w, "
")?;
+    write!(w, "
")?;
     render_attributes(w, it, false)?;
-    write!(w, "existential type {}{}{where_clause}: {bounds};
", + write!(w, "type {}{}{where_clause} = impl {bounds};
", it.name.as_ref().unwrap(), t.generics, where_clause = WhereClause { gens: &t.generics, indent: 0, end_newline: true }, @@ -4983,7 +4983,7 @@ fn item_ty_to_strs(ty: &ItemType) -> (&'static str, &'static str) { ItemType::AssocConst => ("associated-consts", "Associated Constants"), ItemType::ForeignType => ("foreign-types", "Foreign Types"), ItemType::Keyword => ("keywords", "Keywords"), - ItemType::Existential => ("existentials", "Existentials"), + ItemType::OpaqueTy => ("opaque-types", "Opaque Types"), ItemType::ProcAttribute => ("attributes", "Attribute Macros"), ItemType::ProcDerive => ("derives", "Derive Macros"), ItemType::TraitAlias => ("trait-aliases", "Trait aliases"), diff --git a/src/librustdoc/passes/mod.rs b/src/librustdoc/passes/mod.rs index 8fc6b9fdbe6..ca40d6d02f8 100644 --- a/src/librustdoc/passes/mod.rs +++ b/src/librustdoc/passes/mod.rs @@ -159,7 +159,7 @@ impl<'a> DocFolder for Stripper<'a> { return ret; } // These items can all get re-exported - clean::ExistentialItem(..) + clean::OpaqueTyItem(..) | clean::TypedefItem(..) | clean::StaticItem(..) | clean::StructItem(..) diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 4a3743bdf7c..3964460633c 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -472,8 +472,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { }; om.typedefs.push(t); }, - hir::ItemKind::Existential(ref exist_ty) => { - let t = Existential { + hir::ItemKind::OpaqueTy(ref exist_ty) => { + let t = OpaqueTy { exist_ty, name: ident.name, id: item.hir_id, @@ -483,7 +483,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { stab: self.stability(item.hir_id), depr: self.deprecation(item.hir_id), }; - om.existentials.push(t); + om.opaque_tys.push(t); }, hir::ItemKind::Static(ref type_, mutability, expr) => { let s = Static { diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index b633705a65f..38454d7c3b7 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1485,6 +1485,7 @@ pub enum TraitItemKind { Macro(Mac), } +/// Represents anything within an `impl` block. #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct ImplItem { pub id: NodeId, @@ -1499,12 +1500,13 @@ pub struct ImplItem { pub tokens: Option, } +/// Represents various kinds of content within an `impl`. #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub enum ImplItemKind { Const(P, P), Method(MethodSig, P), Type(P), - Existential(GenericBounds), + OpaqueTy(GenericBounds), Macro(Mac), } @@ -1707,7 +1709,7 @@ pub enum TyKind { /// /// The `NodeId` exists to prevent lowering from having to /// generate `NodeId`s on the fly, which would complicate - /// the generation of `existential type` items significantly. + /// the generation of opaque `type Foo = impl Trait` items significantly. ImplTrait(NodeId, GenericBounds), /// No-op; kept solely so that we can pretty-print faithfully. Paren(P), @@ -2331,10 +2333,10 @@ pub enum ItemKind { /// /// E.g., `type Foo = Bar;`. Ty(P, Generics), - /// An existential type declaration (`existential type`). + /// An opaque `impl Trait` type alias. /// - /// E.g., `existential type Foo: Bar + Boo;`. - Existential(GenericBounds, Generics), + /// E.g., `type Foo = impl Bar + Boo;`. + OpaqueTy(GenericBounds, Generics), /// An enum definition (`enum` or `pub enum`). /// /// E.g., `enum Foo { C
, D }`. @@ -2388,7 +2390,7 @@ impl ItemKind { ItemKind::ForeignMod(..) => "foreign module", ItemKind::GlobalAsm(..) => "global asm", ItemKind::Ty(..) => "type alias", - ItemKind::Existential(..) => "existential type", + ItemKind::OpaqueTy(..) => "opaque type", ItemKind::Enum(..) => "enum", ItemKind::Struct(..) => "struct", ItemKind::Union(..) => "union", diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index dd298ce84fa..33d10b269e1 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -2017,12 +2017,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { gate_feature_post!(&self, decl_macro, i.span, msg); } - ast::ItemKind::Existential(..) => { + ast::ItemKind::OpaqueTy(..) => { gate_feature_post!( &self, type_alias_impl_trait, i.span, - "existential types are unstable" + "`impl Trait` in type aliases is unstable" ); } @@ -2246,12 +2246,12 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { match ii.node { ast::ImplItemKind::Method(..) => {} - ast::ImplItemKind::Existential(..) => { + ast::ImplItemKind::OpaqueTy(..) => { gate_feature_post!( &self, type_alias_impl_trait, ii.span, - "existential types are unstable" + "`impl Trait` in type aliases is unstable" ); } ast::ImplItemKind::Type(_) => { diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index 7b328e817bf..a0e24b42e24 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -848,7 +848,7 @@ pub fn noop_visit_item_kind(kind: &mut ItemKind, vis: &mut T) { vis.visit_ty(ty); vis.visit_generics(generics); } - ItemKind::Existential(bounds, generics) => { + ItemKind::OpaqueTy(bounds, generics) => { visit_bounds(bounds, vis); vis.visit_generics(generics); } @@ -931,7 +931,7 @@ pub fn noop_flat_map_impl_item(mut item: ImplItem, visitor: &mut visitor.visit_block(body); } ImplItemKind::Type(ty) => visitor.visit_ty(ty), - ImplItemKind::Existential(bounds) => visit_bounds(bounds, visitor), + ImplItemKind::OpaqueTy(bounds) => visit_bounds(bounds, visitor), ImplItemKind::Macro(mac) => visitor.visit_mac(mac), } visitor.visit_span(span); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ec95a2090d6..89e66e71b25 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -62,12 +62,12 @@ use std::path::{self, Path, PathBuf}; use std::slice; #[derive(Debug)] -/// Whether the type alias or associated type is a concrete type or an existential type +/// Whether the type alias or associated type is a concrete type or an opaque type pub enum AliasKind { /// Just a new name for the same type Weak(P), /// Only trait impls of the type will be usable, not the actual type itself - Existential(GenericBounds), + OpaqueTy(GenericBounds), } bitflags::bitflags! { @@ -4265,11 +4265,6 @@ impl<'a> Parser<'a> { self.token.is_keyword(kw::Crate) && self.look_ahead(1, |t| t != &token::ModSep) } - fn is_existential_type_decl(&self) -> bool { - self.token.is_keyword(kw::Existential) && - self.is_keyword_ahead(1, &[kw::Type]) - } - fn is_auto_trait_item(&self) -> bool { // auto trait (self.token.is_keyword(kw::Auto) && @@ -4367,7 +4362,6 @@ impl<'a> Parser<'a> { !self.token.is_qpath_start() && !self.is_union_item() && !self.is_crate_vis() && - !self.is_existential_type_decl() && !self.is_auto_trait_item() && !self.is_async_fn() { let path = self.parse_path(PathStyle::Expr)?; @@ -5686,7 +5680,7 @@ impl<'a> Parser<'a> { let (name, alias, generics) = type_?; let kind = match alias { AliasKind::Weak(typ) => ast::ImplItemKind::Type(typ), - AliasKind::Existential(bounds) => ast::ImplItemKind::Existential(bounds), + AliasKind::OpaqueTy(bounds) => ast::ImplItemKind::OpaqueTy(bounds), }; (name, kind, generics) } else if self.is_const_item() { @@ -6817,7 +6811,7 @@ impl<'a> Parser<'a> { } } - /// Parses a type alias or existential type. + /// Parses a type alias or opaque type. fn parse_type_alias(&mut self) -> PResult<'a, (Ident, AliasKind, ast::Generics)> { let ident = self.parse_ident()?; let mut tps = self.parse_generics()?; @@ -6826,7 +6820,7 @@ impl<'a> Parser<'a> { let alias = if self.check_keyword(kw::Impl) { self.bump(); let bounds = self.parse_generic_bounds(Some(self.prev_span))?; - AliasKind::Existential(bounds) + AliasKind::OpaqueTy(bounds) } else { let ty = self.parse_ty()?; AliasKind::Weak(ty) @@ -7249,7 +7243,7 @@ impl<'a> Parser<'a> { // TYPE ITEM let item_ = match alias { AliasKind::Weak(ty) => ItemKind::Ty(ty, generics), - AliasKind::Existential(bounds) => ItemKind::Existential(bounds, generics), + AliasKind::OpaqueTy(bounds) => ItemKind::OpaqueTy(bounds, generics), }; let prev_span = self.prev_span; let item = self.mk_item(lo.to(prev_span), diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 88ff6ee9071..fec149f97a7 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1238,9 +1238,10 @@ impl<'a> State<'a> { self.s.word(";"); self.end(); // end the outer ibox } - ast::ItemKind::Existential(ref bounds, ref generics) => { - self.head(visibility_qualified(&item.vis, "existential type")); + ast::ItemKind::OpaqueTy(ref bounds, ref generics) => { + self.head(visibility_qualified(&item.vis, "type")); self.print_ident(item.ident); + self.word_space("= impl"); self.print_generic_params(&generics.params); self.end(); // end the inner ibox @@ -1598,9 +1599,12 @@ impl<'a> State<'a> { ast::ImplItemKind::Type(ref ty) => { self.print_associated_type(ii.ident, None, Some(ty)); } - ast::ImplItemKind::Existential(ref bounds) => { - self.word_space("existential"); - self.print_associated_type(ii.ident, Some(bounds), None); + ast::ImplItemKind::OpaqueTy(ref bounds) => { + self.word_space("type"); + self.print_ident(ii.ident); + self.word_space("= impl"); + self.print_type_bounds(":", bounds); + self.s.word(";"); } ast::ImplItemKind::Macro(ref mac) => { self.print_mac(mac); diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 5fee8ed81ab..67226c2177f 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -259,7 +259,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { visitor.visit_ty(typ); visitor.visit_generics(generics) } - ItemKind::Existential(ref bounds, ref generics) => { + ItemKind::OpaqueTy(ref bounds, ref generics) => { walk_list!(visitor, visit_param_bound, bounds); visitor.visit_generics(generics) } @@ -619,7 +619,7 @@ pub fn walk_impl_item<'a, V: Visitor<'a>>(visitor: &mut V, impl_item: &'a ImplIt ImplItemKind::Type(ref ty) => { visitor.visit_ty(ty); } - ImplItemKind::Existential(ref bounds) => { + ImplItemKind::OpaqueTy(ref bounds) => { walk_list!(visitor, visit_param_bound, bounds); } ImplItemKind::Macro(ref mac) => { diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index f83979b9e9b..f91a2291544 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -744,9 +744,9 @@ pub enum DesugaringKind { QuestionMark, TryBlock, /// Desugaring of an `impl Trait` in return type position - /// to an `existential type Foo: Trait;` and replacing the + /// to an `type Foo = impl Trait;` and replacing the /// `impl Trait` with `Foo`. - ExistentialType, + OpaqueTy, Async, Await, ForLoop, @@ -761,7 +761,7 @@ impl DesugaringKind { DesugaringKind::Await => "`await` expression", DesugaringKind::QuestionMark => "operator `?`", DesugaringKind::TryBlock => "`try` block", - DesugaringKind::ExistentialType => "`existential type`", + DesugaringKind::OpaqueTy => "`impl Trait`", DesugaringKind::ForLoop => "`for` loop", } } diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 331a758aca8..e6197bbca8c 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -95,7 +95,6 @@ symbols! { Auto: "auto", Catch: "catch", Default: "default", - Existential: "existential", Union: "union", } diff --git a/src/test/rustdoc-ui/coverage/traits.rs b/src/test/rustdoc-ui/coverage/traits.rs index 40d68423f1b..797ac00ad53 100644 --- a/src/test/rustdoc-ui/coverage/traits.rs +++ b/src/test/rustdoc-ui/coverage/traits.rs @@ -29,9 +29,10 @@ impl ThisTrait for SomeStruct { /// but what about those aliases? i hear they're pretty exotic pub trait MyAlias = ThisTrait + Send + Sync; -// FIXME(58624): once rustdoc can process existential types, we need to make sure they're counted -// /// woah, getting all existential in here -// pub existential type ThisExists: ThisTrait; +// FIXME(58624): once rustdoc can process opaque `impl Trait` types, +// we need to make sure they're counted +// /// woah, getting all abstract in here +// pub type ThisExists = impl ThisTrait; // // /// why don't we get a little more concrete // pub fn defines() -> ThisExists { SomeStruct {} } diff --git a/src/test/ui/associated-type-bounds/bounds-on-assoc-in-trait.rs b/src/test/ui/associated-type-bounds/bounds-on-assoc-in-trait.rs index 8c9110d03ec..9db5233e21e 100644 --- a/src/test/ui/associated-type-bounds/bounds-on-assoc-in-trait.rs +++ b/src/test/ui/associated-type-bounds/bounds-on-assoc-in-trait.rs @@ -28,7 +28,7 @@ impl Case1 for S1 { type B = Range; } -// Ensure we don't have existential desugaring: +// Ensure we don't have opaque `impl Trait` desugaring: pub trait Foo { type Out: Baz; } pub trait Baz { type Assoc; } diff --git a/src/test/ui/associated-type-bounds/dyn-existential-type.rs b/src/test/ui/associated-type-bounds/dyn-existential-type.rs deleted file mode 100644 index fd9e52a6ff2..00000000000 --- a/src/test/ui/associated-type-bounds/dyn-existential-type.rs +++ /dev/null @@ -1,66 +0,0 @@ -// run-pass - -#![feature(associated_type_bounds)] - -use std::ops::Add; - -trait Tr1 { type As1; fn mk(&self) -> Self::As1; } -trait Tr2<'a> { fn tr2(self) -> &'a Self; } - -fn assert_copy(x: T) { let _x = x; let _x = x; } -fn assert_static(_: T) {} -fn assert_forall_tr2 Tr2<'a>>(_: T) {} - -struct S1; -#[derive(Copy, Clone)] -struct S2; -impl Tr1 for S1 { type As1 = S2; fn mk(&self) -> Self::As1 { S2 } } - -type Et1 = Box>; -fn def_et1() -> Et1 { Box::new(S1) } -pub fn use_et1() { assert_copy(def_et1().mk()); } - -type Et2 = Box>; -fn def_et2() -> Et2 { Box::new(S1) } -pub fn use_et2() { assert_static(def_et2().mk()); } - -type Et3 = Box>>>>; -fn def_et3() -> Et3 { - struct A; - impl Tr1 for A { - type As1 = core::ops::Range; - fn mk(&self) -> Self::As1 { 0..10 } - }; - Box::new(A) -} -pub fn use_et3() { - let _0 = def_et3().mk().clone(); - let mut s = 0u8; - for _1 in _0 { - let _2 = _1 + 1u8; - s += _2.into(); - } - assert_eq!(s, (0..10).map(|x| x + 1).sum()); -} - -type Et4 = Box Tr2<'a>>>; -fn def_et4() -> Et4 { - #[derive(Copy, Clone)] - struct A; - impl Tr1 for A { - type As1 = A; - fn mk(&self) -> A { A } - } - impl<'a> Tr2<'a> for A { - fn tr2(self) -> &'a Self { &A } - } - Box::new(A) -} -pub fn use_et4() { assert_forall_tr2(def_et4().mk()); } - -fn main() { - let _ = use_et1(); - let _ = use_et2(); - let _ = use_et3(); - let _ = use_et4(); -} diff --git a/src/test/ui/associated-type-bounds/dyn-impl-trait-type.rs b/src/test/ui/associated-type-bounds/dyn-impl-trait-type.rs new file mode 100644 index 00000000000..fd9e52a6ff2 --- /dev/null +++ b/src/test/ui/associated-type-bounds/dyn-impl-trait-type.rs @@ -0,0 +1,66 @@ +// run-pass + +#![feature(associated_type_bounds)] + +use std::ops::Add; + +trait Tr1 { type As1; fn mk(&self) -> Self::As1; } +trait Tr2<'a> { fn tr2(self) -> &'a Self; } + +fn assert_copy(x: T) { let _x = x; let _x = x; } +fn assert_static(_: T) {} +fn assert_forall_tr2 Tr2<'a>>(_: T) {} + +struct S1; +#[derive(Copy, Clone)] +struct S2; +impl Tr1 for S1 { type As1 = S2; fn mk(&self) -> Self::As1 { S2 } } + +type Et1 = Box>; +fn def_et1() -> Et1 { Box::new(S1) } +pub fn use_et1() { assert_copy(def_et1().mk()); } + +type Et2 = Box>; +fn def_et2() -> Et2 { Box::new(S1) } +pub fn use_et2() { assert_static(def_et2().mk()); } + +type Et3 = Box>>>>; +fn def_et3() -> Et3 { + struct A; + impl Tr1 for A { + type As1 = core::ops::Range; + fn mk(&self) -> Self::As1 { 0..10 } + }; + Box::new(A) +} +pub fn use_et3() { + let _0 = def_et3().mk().clone(); + let mut s = 0u8; + for _1 in _0 { + let _2 = _1 + 1u8; + s += _2.into(); + } + assert_eq!(s, (0..10).map(|x| x + 1).sum()); +} + +type Et4 = Box Tr2<'a>>>; +fn def_et4() -> Et4 { + #[derive(Copy, Clone)] + struct A; + impl Tr1 for A { + type As1 = A; + fn mk(&self) -> A { A } + } + impl<'a> Tr2<'a> for A { + fn tr2(self) -> &'a Self { &A } + } + Box::new(A) +} +pub fn use_et4() { assert_forall_tr2(def_et4().mk()); } + +fn main() { + let _ = use_et1(); + let _ = use_et2(); + let _ = use_et3(); + let _ = use_et4(); +} diff --git a/src/test/ui/associated-type-bounds/existential-type.rs b/src/test/ui/associated-type-bounds/existential-type.rs deleted file mode 100644 index 9ee33e4149a..00000000000 --- a/src/test/ui/associated-type-bounds/existential-type.rs +++ /dev/null @@ -1,67 +0,0 @@ -// run-pass - -#![feature(associated_type_bounds)] -#![feature(type_alias_impl_trait)] - -use std::ops::Add; - -trait Tr1 { type As1; fn mk(self) -> Self::As1; } -trait Tr2<'a> { fn tr2(self) -> &'a Self; } - -fn assert_copy(x: T) { let _x = x; let _x = x; } -fn assert_static(_: T) {} -fn assert_forall_tr2 Tr2<'a>>(_: T) {} - -struct S1; -#[derive(Copy, Clone)] -struct S2; -impl Tr1 for S1 { type As1 = S2; fn mk(self) -> Self::As1 { S2 } } - -type Et1 = impl Tr1; -fn def_et1() -> Et1 { S1 } -pub fn use_et1() { assert_copy(def_et1().mk()); } - -type Et2 = impl Tr1; -fn def_et2() -> Et2 { S1 } -pub fn use_et2() { assert_static(def_et2().mk()); } - -type Et3 = impl Tr1>>>; -fn def_et3() -> Et3 { - struct A; - impl Tr1 for A { - type As1 = core::ops::Range; - fn mk(self) -> Self::As1 { 0..10 } - }; - A -} -pub fn use_et3() { - let _0 = def_et3().mk().clone(); - let mut s = 0u8; - for _1 in _0 { - let _2 = _1 + 1u8; - s += _2.into(); - } - assert_eq!(s, (0..10).map(|x| x + 1).sum()); -} - -type Et4 = impl Tr1 Tr2<'a>>; -fn def_et4() -> Et4 { - #[derive(Copy, Clone)] - struct A; - impl Tr1 for A { - type As1 = A; - fn mk(self) -> A { A } - } - impl<'a> Tr2<'a> for A { - fn tr2(self) -> &'a Self { &A } - } - A -} -pub fn use_et4() { assert_forall_tr2(def_et4().mk()); } - -fn main() { - let _ = use_et1(); - let _ = use_et2(); - let _ = use_et3(); - let _ = use_et4(); -} diff --git a/src/test/ui/associated-type-bounds/trait-alias-impl-trait.rs b/src/test/ui/associated-type-bounds/trait-alias-impl-trait.rs new file mode 100644 index 00000000000..9ee33e4149a --- /dev/null +++ b/src/test/ui/associated-type-bounds/trait-alias-impl-trait.rs @@ -0,0 +1,67 @@ +// run-pass + +#![feature(associated_type_bounds)] +#![feature(type_alias_impl_trait)] + +use std::ops::Add; + +trait Tr1 { type As1; fn mk(self) -> Self::As1; } +trait Tr2<'a> { fn tr2(self) -> &'a Self; } + +fn assert_copy(x: T) { let _x = x; let _x = x; } +fn assert_static(_: T) {} +fn assert_forall_tr2 Tr2<'a>>(_: T) {} + +struct S1; +#[derive(Copy, Clone)] +struct S2; +impl Tr1 for S1 { type As1 = S2; fn mk(self) -> Self::As1 { S2 } } + +type Et1 = impl Tr1; +fn def_et1() -> Et1 { S1 } +pub fn use_et1() { assert_copy(def_et1().mk()); } + +type Et2 = impl Tr1; +fn def_et2() -> Et2 { S1 } +pub fn use_et2() { assert_static(def_et2().mk()); } + +type Et3 = impl Tr1>>>; +fn def_et3() -> Et3 { + struct A; + impl Tr1 for A { + type As1 = core::ops::Range; + fn mk(self) -> Self::As1 { 0..10 } + }; + A +} +pub fn use_et3() { + let _0 = def_et3().mk().clone(); + let mut s = 0u8; + for _1 in _0 { + let _2 = _1 + 1u8; + s += _2.into(); + } + assert_eq!(s, (0..10).map(|x| x + 1).sum()); +} + +type Et4 = impl Tr1 Tr2<'a>>; +fn def_et4() -> Et4 { + #[derive(Copy, Clone)] + struct A; + impl Tr1 for A { + type As1 = A; + fn mk(self) -> A { A } + } + impl<'a> Tr2<'a> for A { + fn tr2(self) -> &'a Self { &A } + } + A +} +pub fn use_et4() { assert_forall_tr2(def_et4().mk()); } + +fn main() { + let _ = use_et1(); + let _ = use_et2(); + let _ = use_et3(); + let _ = use_et4(); +} diff --git a/src/test/ui/async-await/async-await.rs b/src/test/ui/async-await/async-await.rs index 5ec99c5d183..2580a72687f 100644 --- a/src/test/ui/async-await/async-await.rs +++ b/src/test/ui/async-await/async-await.rs @@ -99,7 +99,7 @@ fn async_fn_with_impl_future_named_lifetime<'a>(x: &'a u8) -> impl Future:;` works +/* FIXME(cramertj) support when `type T<'a, 'b> = impl;` works async fn async_fn_multiple_args(x: &u8, _y: &u8) -> u8 { await!(wake_and_yield_once()); *x diff --git a/src/test/ui/async-await/await-macro.rs b/src/test/ui/async-await/await-macro.rs new file mode 100644 index 00000000000..05176848b01 --- /dev/null +++ b/src/test/ui/async-await/await-macro.rs @@ -0,0 +1,230 @@ +// run-pass + +// edition:2018 +// aux-build:arc_wake.rs + +#![feature(async_await, async_closure, await_macro)] + +extern crate arc_wake; + +use std::pin::Pin; +use std::future::Future; +use std::sync::{ + Arc, + atomic::{self, AtomicUsize}, +}; +use std::task::{Context, Poll}; +use arc_wake::ArcWake; + +struct Counter { + wakes: AtomicUsize, +} + +impl ArcWake for Counter { + fn wake(self: Arc) { + Self::wake_by_ref(&self) + } + fn wake_by_ref(arc_self: &Arc) { + arc_self.wakes.fetch_add(1, atomic::Ordering::SeqCst); + } +} + +struct WakeOnceThenComplete(bool); + +fn wake_and_yield_once() -> WakeOnceThenComplete { WakeOnceThenComplete(false) } + +impl Future for WakeOnceThenComplete { + type Output = (); + fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> { + if self.0 { + Poll::Ready(()) + } else { + cx.waker().wake_by_ref(); + self.0 = true; + Poll::Pending + } + } +} + +fn async_block(x: u8) -> impl Future { + async move { + await!(wake_and_yield_once()); + x + } +} + +fn async_block_with_borrow_named_lifetime<'a>(x: &'a u8) -> impl Future + 'a { + async move { + await!(wake_and_yield_once()); + *x + } +} + +fn async_nonmove_block(x: u8) -> impl Future { + async move { + let future = async { + await!(wake_and_yield_once()); + x + }; + await!(future) + } +} + +fn async_closure(x: u8) -> impl Future { + (async move |x: u8| -> u8 { + await!(wake_and_yield_once()); + x + })(x) +} + +fn async_closure_in_unsafe_block(x: u8) -> impl Future { + (unsafe { + async move |x: u8| unsafe_fn(await!(unsafe_async_fn(x))) + })(x) +} + +async fn async_fn(x: u8) -> u8 { + await!(wake_and_yield_once()); + x +} + +async fn generic_async_fn(x: T) -> T { + await!(wake_and_yield_once()); + x +} + +async fn async_fn_with_borrow(x: &u8) -> u8 { + await!(wake_and_yield_once()); + *x +} + +async fn async_fn_with_borrow_named_lifetime<'a>(x: &'a u8) -> u8 { + await!(wake_and_yield_once()); + *x +} + +fn async_fn_with_impl_future_named_lifetime<'a>(x: &'a u8) -> impl Future + 'a { + async move { + await!(wake_and_yield_once()); + *x + } +} + +/* FIXME(cramertj) support when `type T<'a, 'b> = impl;` works +async fn async_fn_multiple_args(x: &u8, _y: &u8) -> u8 { + await!(wake_and_yield_once()); + *x +} +*/ + +async fn async_fn_multiple_args_named_lifetime<'a>(x: &'a u8, _y: &'a u8) -> u8 { + await!(wake_and_yield_once()); + *x +} + +fn async_fn_with_internal_borrow(y: u8) -> impl Future { + async move { + await!(async_fn_with_borrow_named_lifetime(&y)) + } +} + +async unsafe fn unsafe_async_fn(x: u8) -> u8 { + await!(wake_and_yield_once()); + x +} + +unsafe fn unsafe_fn(x: u8) -> u8 { + x +} + +fn async_block_in_unsafe_block(x: u8) -> impl Future { + unsafe { + async move { + unsafe_fn(await!(unsafe_async_fn(x))) + } + } +} + +struct Foo; + +trait Bar { + fn foo() {} +} + +impl Foo { + async fn async_assoc_item(x: u8) -> u8 { + unsafe { + await!(unsafe_async_fn(x)) + } + } + + async unsafe fn async_unsafe_assoc_item(x: u8) -> u8 { + await!(unsafe_async_fn(x)) + } +} + +fn test_future_yields_once_then_returns(f: F) +where + F: FnOnce(u8) -> Fut, + Fut: Future, +{ + let mut fut = Box::pin(f(9)); + let counter = Arc::new(Counter { wakes: AtomicUsize::new(0) }); + let waker = ArcWake::into_waker(counter.clone()); + let mut cx = Context::from_waker(&waker); + assert_eq!(0, counter.wakes.load(atomic::Ordering::SeqCst)); + assert_eq!(Poll::Pending, fut.as_mut().poll(&mut cx)); + assert_eq!(1, counter.wakes.load(atomic::Ordering::SeqCst)); + assert_eq!(Poll::Ready(9), fut.as_mut().poll(&mut cx)); +} + +fn main() { + macro_rules! test { + ($($fn_name:expr,)*) => { $( + test_future_yields_once_then_returns($fn_name); + )* } + } + + macro_rules! test_with_borrow { + ($($fn_name:expr,)*) => { $( + test_future_yields_once_then_returns(|x| { + async move { + await!($fn_name(&x)) + } + }); + )* } + } + + test! { + async_block, + async_nonmove_block, + async_closure, + async_closure_in_unsafe_block, + async_fn, + generic_async_fn, + async_fn_with_internal_borrow, + async_block_in_unsafe_block, + Foo::async_assoc_item, + |x| { + async move { + unsafe { await!(unsafe_async_fn(x)) } + } + }, + |x| { + async move { + unsafe { await!(Foo::async_unsafe_assoc_item(x)) } + } + }, + } + test_with_borrow! { + async_block_with_borrow_named_lifetime, + async_fn_with_borrow, + async_fn_with_borrow_named_lifetime, + async_fn_with_impl_future_named_lifetime, + |x| { + async move { + await!(async_fn_multiple_args_named_lifetime(x, x)) + } + }, + } +} diff --git a/src/test/ui/async-await/issues/issue-60655-latebound-regions.rs b/src/test/ui/async-await/issues/issue-60655-latebound-regions.rs index f11aff971bf..99213e64d16 100644 --- a/src/test/ui/async-await/issues/issue-60655-latebound-regions.rs +++ b/src/test/ui/async-await/issues/issue-60655-latebound-regions.rs @@ -1,4 +1,4 @@ -// Test that existential types are allowed to contain late-bound regions. +// Test that opaque `impl Trait` types are allowed to contain late-bound regions. // build-pass (FIXME(62277): could be check-pass?) // edition:2018 diff --git a/src/test/ui/existential_types/auxiliary/cross_crate_ice.rs b/src/test/ui/existential_types/auxiliary/cross_crate_ice.rs deleted file mode 100644 index f6d86391388..00000000000 --- a/src/test/ui/existential_types/auxiliary/cross_crate_ice.rs +++ /dev/null @@ -1,11 +0,0 @@ -// Crate that exports an existential type. Used for testing cross-crate. - -#![crate_type="rlib"] - -#![feature(type_alias_impl_trait)] - -pub type Foo = impl std::fmt::Debug; - -pub fn foo() -> Foo { - 5 -} diff --git a/src/test/ui/existential_types/auxiliary/cross_crate_ice2.rs b/src/test/ui/existential_types/auxiliary/cross_crate_ice2.rs deleted file mode 100644 index 2fa7d6ae5c4..00000000000 --- a/src/test/ui/existential_types/auxiliary/cross_crate_ice2.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Crate that exports an existential type. Used for testing cross-crate. - -#![crate_type="rlib"] - -#![feature(type_alias_impl_trait)] - -pub trait View { - type Tmp: Iterator; - - fn test(&self) -> Self::Tmp; -} - -pub struct X; - -impl View for X { - type Tmp = impl Iterator; - - fn test(&self) -> Self::Tmp { - vec![1,2,3].into_iter() - } -} diff --git a/src/test/ui/existential_types/bound_reduction.rs b/src/test/ui/existential_types/bound_reduction.rs deleted file mode 100644 index 18c840d8ed9..00000000000 --- a/src/test/ui/existential_types/bound_reduction.rs +++ /dev/null @@ -1,20 +0,0 @@ -// build-pass (FIXME(62277): could be check-pass?) - -#![allow(warnings)] - -#![feature(type_alias_impl_trait)] - -fn main() { -} - -type Foo = impl std::fmt::Debug; - -trait Trait {} - -fn foo_desugared>(_: T) -> Foo { - (42, std::marker::PhantomData::) -} diff --git a/src/test/ui/existential_types/bound_reduction2.rs b/src/test/ui/existential_types/bound_reduction2.rs deleted file mode 100644 index 919446877a1..00000000000 --- a/src/test/ui/existential_types/bound_reduction2.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() { -} - -trait TraitWithAssoc { - type Assoc; -} - -type Foo = impl Trait; -//~^ ERROR could not find defining uses - -trait Trait {} - -impl Trait for () {} - -fn foo_desugared(_: T) -> Foo { //~ ERROR does not fully define - () -} diff --git a/src/test/ui/existential_types/bound_reduction2.stderr b/src/test/ui/existential_types/bound_reduction2.stderr deleted file mode 100644 index b88a364b852..00000000000 --- a/src/test/ui/existential_types/bound_reduction2.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: defining existential type use does not fully define existential type - --> $DIR/bound_reduction2.rs:17:1 - | -LL | / fn foo_desugared(_: T) -> Foo { -LL | | () -LL | | } - | |_^ - -error: could not find defining uses - --> $DIR/bound_reduction2.rs:10:1 - | -LL | type Foo = impl Trait; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/existential_types/cross_crate_ice.rs b/src/test/ui/existential_types/cross_crate_ice.rs deleted file mode 100644 index c30608176aa..00000000000 --- a/src/test/ui/existential_types/cross_crate_ice.rs +++ /dev/null @@ -1,16 +0,0 @@ -// aux-build:cross_crate_ice.rs -// build-pass (FIXME(62277): could be check-pass?) - -extern crate cross_crate_ice; - -struct Bar(cross_crate_ice::Foo); - -impl Bar { - fn zero(&self) -> &cross_crate_ice::Foo { - &self.0 - } -} - -fn main() { - let _ = cross_crate_ice::foo(); -} diff --git a/src/test/ui/existential_types/cross_crate_ice2.rs b/src/test/ui/existential_types/cross_crate_ice2.rs deleted file mode 100644 index 3a7e490260f..00000000000 --- a/src/test/ui/existential_types/cross_crate_ice2.rs +++ /dev/null @@ -1,11 +0,0 @@ -// aux-build:cross_crate_ice2.rs -// build-pass (FIXME(62277): could be check-pass?) - -extern crate cross_crate_ice2; - -use cross_crate_ice2::View; - -fn main() { - let v = cross_crate_ice2::X; - v.test(); -} diff --git a/src/test/ui/existential_types/declared_but_never_defined.rs b/src/test/ui/existential_types/declared_but_never_defined.rs deleted file mode 100644 index c4bf56a9197..00000000000 --- a/src/test/ui/existential_types/declared_but_never_defined.rs +++ /dev/null @@ -1,6 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() {} - -// declared but never defined -type Bar = impl std::fmt::Debug; //~ ERROR could not find defining uses diff --git a/src/test/ui/existential_types/declared_but_never_defined.stderr b/src/test/ui/existential_types/declared_but_never_defined.stderr deleted file mode 100644 index ae0fee4333b..00000000000 --- a/src/test/ui/existential_types/declared_but_never_defined.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: could not find defining uses - --> $DIR/declared_but_never_defined.rs:6:1 - | -LL | type Bar = impl std::fmt::Debug; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/existential_types/declared_but_not_defined_in_scope.rs b/src/test/ui/existential_types/declared_but_not_defined_in_scope.rs deleted file mode 100644 index 09873a8c8c3..00000000000 --- a/src/test/ui/existential_types/declared_but_not_defined_in_scope.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() {} - -mod boo { - // declared in module but not defined inside of it - pub type Boo = impl ::std::fmt::Debug; //~ ERROR could not find defining uses -} - -fn bomp() -> boo::Boo { - "" -} diff --git a/src/test/ui/existential_types/declared_but_not_defined_in_scope.stderr b/src/test/ui/existential_types/declared_but_not_defined_in_scope.stderr deleted file mode 100644 index 0642407aba3..00000000000 --- a/src/test/ui/existential_types/declared_but_not_defined_in_scope.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: could not find defining uses - --> $DIR/declared_but_not_defined_in_scope.rs:7:5 - | -LL | pub type Boo = impl ::std::fmt::Debug; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/existential_types/different_defining_uses.rs b/src/test/ui/existential_types/different_defining_uses.rs deleted file mode 100644 index 2d7780a126c..00000000000 --- a/src/test/ui/existential_types/different_defining_uses.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() {} - -// two definitions with different types -type Foo = impl std::fmt::Debug; - -fn foo() -> Foo { - "" -} - -fn bar() -> Foo { //~ ERROR concrete type differs from previous - 42i32 -} diff --git a/src/test/ui/existential_types/different_defining_uses.stderr b/src/test/ui/existential_types/different_defining_uses.stderr deleted file mode 100644 index fddba584798..00000000000 --- a/src/test/ui/existential_types/different_defining_uses.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: concrete type differs from previous defining existential type use - --> $DIR/different_defining_uses.rs:12:1 - | -LL | / fn bar() -> Foo { -LL | | 42i32 -LL | | } - | |_^ expected `&'static str`, got `i32` - | -note: previous use here - --> $DIR/different_defining_uses.rs:8:1 - | -LL | / fn foo() -> Foo { -LL | | "" -LL | | } - | |_^ - -error: aborting due to previous error - diff --git a/src/test/ui/existential_types/different_defining_uses_never_type.rs b/src/test/ui/existential_types/different_defining_uses_never_type.rs deleted file mode 100644 index 289b97b00ad..00000000000 --- a/src/test/ui/existential_types/different_defining_uses_never_type.rs +++ /dev/null @@ -1,18 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() {} - -// two definitions with different types -type Foo = impl std::fmt::Debug; - -fn foo() -> Foo { - "" -} - -fn bar() -> Foo { //~ ERROR concrete type differs from previous - panic!() -} - -fn boo() -> Foo { //~ ERROR concrete type differs from previous - loop {} -} diff --git a/src/test/ui/existential_types/different_defining_uses_never_type.stderr b/src/test/ui/existential_types/different_defining_uses_never_type.stderr deleted file mode 100644 index 14b7a810be2..00000000000 --- a/src/test/ui/existential_types/different_defining_uses_never_type.stderr +++ /dev/null @@ -1,34 +0,0 @@ -error: concrete type differs from previous defining existential type use - --> $DIR/different_defining_uses_never_type.rs:12:1 - | -LL | / fn bar() -> Foo { -LL | | panic!() -LL | | } - | |_^ expected `&'static str`, got `()` - | -note: previous use here - --> $DIR/different_defining_uses_never_type.rs:8:1 - | -LL | / fn foo() -> Foo { -LL | | "" -LL | | } - | |_^ - -error: concrete type differs from previous defining existential type use - --> $DIR/different_defining_uses_never_type.rs:16:1 - | -LL | / fn boo() -> Foo { -LL | | loop {} -LL | | } - | |_^ expected `&'static str`, got `()` - | -note: previous use here - --> $DIR/different_defining_uses_never_type.rs:8:1 - | -LL | / fn foo() -> Foo { -LL | | "" -LL | | } - | |_^ - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/existential_types/different_defining_uses_never_type2.rs b/src/test/ui/existential_types/different_defining_uses_never_type2.rs deleted file mode 100644 index 8549687ea78..00000000000 --- a/src/test/ui/existential_types/different_defining_uses_never_type2.rs +++ /dev/null @@ -1,44 +0,0 @@ -// build-pass (FIXME(62277): could be check-pass?) - -#![feature(type_alias_impl_trait)] - -fn main() {} - -// two definitions with different types -type Foo = impl std::fmt::Debug; - -fn foo() -> Foo { - "" -} - -fn bar(arg: bool) -> Foo { - if arg { - panic!() - } else { - "bar" - } -} - -fn boo(arg: bool) -> Foo { - if arg { - loop {} - } else { - "boo" - } -} - -fn bar2(arg: bool) -> Foo { - if arg { - "bar2" - } else { - panic!() - } -} - -fn boo2(arg: bool) -> Foo { - if arg { - "boo2" - } else { - loop {} - } -} diff --git a/src/test/ui/existential_types/existential-associated-type.rs b/src/test/ui/existential_types/existential-associated-type.rs deleted file mode 100644 index 42f07d49ffe..00000000000 --- a/src/test/ui/existential_types/existential-associated-type.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![feature(type_alias_impl_trait)] -// build-pass (FIXME(62277): could be check-pass?) - -trait Bar {} -struct Dummy; -impl Bar for Dummy {} - -trait Foo { - type Assoc: Bar; - fn foo() -> Self::Assoc; - fn bar() -> Self::Assoc; -} - -type Helper = impl Bar; - -impl Foo for i32 { - type Assoc = Helper; - fn foo() -> Helper { - Dummy - } - fn bar() -> Helper { - Dummy - } -} - -fn main() {} diff --git a/src/test/ui/existential_types/existential-types-with-cycle-error.rs b/src/test/ui/existential_types/existential-types-with-cycle-error.rs deleted file mode 100644 index c009952eab7..00000000000 --- a/src/test/ui/existential_types/existential-types-with-cycle-error.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![feature(type_alias_impl_trait)] - -type Foo = impl Fn() -> Foo; -//~^ ERROR: could not find defining uses - -fn crash(x: Foo) -> Foo { - x -} - -fn main() { - -} diff --git a/src/test/ui/existential_types/existential-types-with-cycle-error.stderr b/src/test/ui/existential_types/existential-types-with-cycle-error.stderr deleted file mode 100644 index e044bad37e8..00000000000 --- a/src/test/ui/existential_types/existential-types-with-cycle-error.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: could not find defining uses - --> $DIR/existential-types-with-cycle-error.rs:3:1 - | -LL | type Foo = impl Fn() -> Foo; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/existential_types/existential-types-with-cycle-error2.rs b/src/test/ui/existential_types/existential-types-with-cycle-error2.rs deleted file mode 100644 index 32ecc366618..00000000000 --- a/src/test/ui/existential_types/existential-types-with-cycle-error2.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![feature(type_alias_impl_trait)] - -pub trait Bar { - type Item; -} - -type Foo = impl Bar; -//~^ ERROR: could not find defining uses - -fn crash(x: Foo) -> Foo { - x -} - -fn main() { - -} diff --git a/src/test/ui/existential_types/existential-types-with-cycle-error2.stderr b/src/test/ui/existential_types/existential-types-with-cycle-error2.stderr deleted file mode 100644 index 32c1424ad95..00000000000 --- a/src/test/ui/existential_types/existential-types-with-cycle-error2.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: could not find defining uses - --> $DIR/existential-types-with-cycle-error2.rs:7:1 - | -LL | type Foo = impl Bar; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/existential_types/existential-types-with-no-traits.rs b/src/test/ui/existential_types/existential-types-with-no-traits.rs deleted file mode 100644 index 8ca279eec92..00000000000 --- a/src/test/ui/existential_types/existential-types-with-no-traits.rs +++ /dev/null @@ -1,14 +0,0 @@ -#![feature(type_alias_impl_trait)] - -type Foo = impl 'static; -//~^ ERROR: at least one trait must be specified - -fn foo() -> Foo { - "foo" -} - -fn bar() -> impl 'static { //~ ERROR: at least one trait must be specified - "foo" -} - -fn main() {} diff --git a/src/test/ui/existential_types/existential-types-with-no-traits.stderr b/src/test/ui/existential_types/existential-types-with-no-traits.stderr deleted file mode 100644 index 9703a367ddc..00000000000 --- a/src/test/ui/existential_types/existential-types-with-no-traits.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: at least one trait must be specified - --> $DIR/existential-types-with-no-traits.rs:3:17 - | -LL | type Foo = impl 'static; - | ^^^^^^^ - -error: at least one trait must be specified - --> $DIR/existential-types-with-no-traits.rs:10:13 - | -LL | fn bar() -> impl 'static { - | ^^^^^^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/existential_types/existential_type_const.rs b/src/test/ui/existential_types/existential_type_const.rs deleted file mode 100644 index fdfd4ac8759..00000000000 --- a/src/test/ui/existential_types/existential_type_const.rs +++ /dev/null @@ -1,20 +0,0 @@ -// check-pass - -#![feature(type_alias_impl_trait)] -// Currently, the `type_alias_impl_trait` feature implicitly -// depends on `impl_trait_in_bindings` in order to work properly. -// Specifically, this line requires `impl_trait_in_bindings` to be enabled: -// https://github.com/rust-lang/rust/blob/481068a707679257e2a738b40987246e0420e787/src/librustc_typeck/check/mod.rs#L856 -#![feature(impl_trait_in_bindings)] -//~^ WARN the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash - -// Ensures that `const` items can constrain an `existential type`. - -use std::fmt::Debug; - -pub type Foo = impl Debug; - -const _FOO: Foo = 5; - -fn main() { -} diff --git a/src/test/ui/existential_types/existential_type_const.stderr b/src/test/ui/existential_types/existential_type_const.stderr deleted file mode 100644 index 81754c8f706..00000000000 --- a/src/test/ui/existential_types/existential_type_const.stderr +++ /dev/null @@ -1,8 +0,0 @@ -warning: the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash - --> $DIR/existential_type_const.rs:8:12 - | -LL | #![feature(impl_trait_in_bindings)] - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = note: `#[warn(incomplete_features)]` on by default - diff --git a/src/test/ui/existential_types/existential_type_fns.rs b/src/test/ui/existential_types/existential_type_fns.rs deleted file mode 100644 index a22b12cae6b..00000000000 --- a/src/test/ui/existential_types/existential_type_fns.rs +++ /dev/null @@ -1,27 +0,0 @@ -// check-pass - -#![feature(type_alias_impl_trait)] - -// Regression test for issue #61863 - -pub trait MyTrait {} - -#[derive(Debug)] -pub struct MyStruct { - v: u64 -} - -impl MyTrait for MyStruct {} - -pub fn bla() -> TE { - return MyStruct {v:1} -} - -pub fn bla2() -> TE { - bla() -} - - -type TE = impl MyTrait; - -fn main() {} diff --git a/src/test/ui/existential_types/existential_type_tuple.rs b/src/test/ui/existential_types/existential_type_tuple.rs deleted file mode 100644 index 86c9d482143..00000000000 --- a/src/test/ui/existential_types/existential_type_tuple.rs +++ /dev/null @@ -1,33 +0,0 @@ -// check-pass - -#![feature(type_alias_impl_trait)] -#![allow(dead_code)] - -pub trait MyTrait {} - -impl MyTrait for bool {} - -struct Blah { - my_foo: Foo, - my_u8: u8 -} - -impl Blah { - fn new() -> Blah { - Blah { - my_foo: make_foo(), - my_u8: 12 - } - } - fn into_inner(self) -> (Foo, u8) { - (self.my_foo, self.my_u8) - } -} - -fn make_foo() -> Foo { - true -} - -type Foo = impl MyTrait; - -fn main() {} diff --git a/src/test/ui/existential_types/generic_different_defining_uses.rs b/src/test/ui/existential_types/generic_different_defining_uses.rs deleted file mode 100644 index ac87c2d446a..00000000000 --- a/src/test/ui/existential_types/generic_different_defining_uses.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() {} - -type MyIter = impl Iterator; - -fn my_iter(t: T) -> MyIter { - std::iter::once(t) -} - -fn my_iter2(t: T) -> MyIter { //~ ERROR concrete type differs from previous - Some(t).into_iter() -} diff --git a/src/test/ui/existential_types/generic_different_defining_uses.stderr b/src/test/ui/existential_types/generic_different_defining_uses.stderr deleted file mode 100644 index e5b1539ccbb..00000000000 --- a/src/test/ui/existential_types/generic_different_defining_uses.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: concrete type differs from previous defining existential type use - --> $DIR/generic_different_defining_uses.rs:11:1 - | -LL | / fn my_iter2(t: T) -> MyIter { -LL | | Some(t).into_iter() -LL | | } - | |_^ expected `std::iter::Once`, got `std::option::IntoIter` - | -note: previous use here - --> $DIR/generic_different_defining_uses.rs:7:1 - | -LL | / fn my_iter(t: T) -> MyIter { -LL | | std::iter::once(t) -LL | | } - | |_^ - -error: aborting due to previous error - diff --git a/src/test/ui/existential_types/generic_duplicate_lifetime_param.rs b/src/test/ui/existential_types/generic_duplicate_lifetime_param.rs deleted file mode 100644 index e88aa07b6f0..00000000000 --- a/src/test/ui/existential_types/generic_duplicate_lifetime_param.rs +++ /dev/null @@ -1,9 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() {} - -type Two<'a, 'b> = impl std::fmt::Debug; - -fn one<'a>(t: &'a ()) -> Two<'a, 'a> { //~ ERROR non-defining existential type use - t -} diff --git a/src/test/ui/existential_types/generic_duplicate_lifetime_param.stderr b/src/test/ui/existential_types/generic_duplicate_lifetime_param.stderr deleted file mode 100644 index f63defe8ff7..00000000000 --- a/src/test/ui/existential_types/generic_duplicate_lifetime_param.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error: non-defining existential type use in defining scope - --> $DIR/generic_duplicate_lifetime_param.rs:7:1 - | -LL | / fn one<'a>(t: &'a ()) -> Two<'a, 'a> { -LL | | t -LL | | } - | |_^ - | -note: lifetime used multiple times - --> $DIR/generic_duplicate_lifetime_param.rs:5:10 - | -LL | type Two<'a, 'b> = impl std::fmt::Debug; - | ^^ ^^ - -error: aborting due to previous error - diff --git a/src/test/ui/existential_types/generic_duplicate_param_use.rs b/src/test/ui/existential_types/generic_duplicate_param_use.rs index 7ae82a972da..165e320be5e 100644 --- a/src/test/ui/existential_types/generic_duplicate_param_use.rs +++ b/src/test/ui/existential_types/generic_duplicate_param_use.rs @@ -9,6 +9,6 @@ type Two = impl Debug; //~^ could not find defining uses fn one(t: T) -> Two { -//~^ ERROR defining existential type use restricts existential type +//~^ ERROR defining opaque type use restricts opaque type t } diff --git a/src/test/ui/existential_types/generic_duplicate_param_use.stderr b/src/test/ui/existential_types/generic_duplicate_param_use.stderr index 8c727bae8e7..e1794034e20 100644 --- a/src/test/ui/existential_types/generic_duplicate_param_use.stderr +++ b/src/test/ui/existential_types/generic_duplicate_param_use.stderr @@ -1,4 +1,4 @@ -error: defining existential type use restricts existential type by using the generic parameter `T` twice +error: defining opaque type use restricts opaque type by using the generic parameter `T` twice --> $DIR/generic_duplicate_param_use.rs:11:1 | LL | / fn one(t: T) -> Two { diff --git a/src/test/ui/existential_types/generic_duplicate_param_use10.rs b/src/test/ui/existential_types/generic_duplicate_param_use10.rs deleted file mode 100644 index 898dab1b0b9..00000000000 --- a/src/test/ui/existential_types/generic_duplicate_param_use10.rs +++ /dev/null @@ -1,12 +0,0 @@ -// build-pass (FIXME(62277): could be check-pass?) -#![feature(type_alias_impl_trait)] - -use std::fmt::Debug; - -fn main() {} - -type Two = impl Debug; - -fn two(t: T, _: U) -> Two { - (t, 4u32) -} diff --git a/src/test/ui/existential_types/generic_duplicate_param_use2.rs b/src/test/ui/existential_types/generic_duplicate_param_use2.rs index cf3f5fd8e00..0adce817c5c 100644 --- a/src/test/ui/existential_types/generic_duplicate_param_use2.rs +++ b/src/test/ui/existential_types/generic_duplicate_param_use2.rs @@ -8,7 +8,7 @@ fn main() {} type Two = impl Debug; fn one(t: T) -> Two { -//~^ defining existential type use restricts existential type +//~^ defining opaque type use restricts opaque type t } diff --git a/src/test/ui/existential_types/generic_duplicate_param_use2.stderr b/src/test/ui/existential_types/generic_duplicate_param_use2.stderr deleted file mode 100644 index 74f2802449a..00000000000 --- a/src/test/ui/existential_types/generic_duplicate_param_use2.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: defining existential type use restricts existential type by using the generic parameter `T` twice - --> $DIR/generic_duplicate_param_use2.rs:10:1 - | -LL | / fn one(t: T) -> Two { -LL | | -LL | | t -LL | | } - | |_^ - -error: aborting due to previous error - diff --git a/src/test/ui/existential_types/generic_duplicate_param_use3.rs b/src/test/ui/existential_types/generic_duplicate_param_use3.rs index b980e831b73..8d3e7f9f424 100644 --- a/src/test/ui/existential_types/generic_duplicate_param_use3.rs +++ b/src/test/ui/existential_types/generic_duplicate_param_use3.rs @@ -8,7 +8,7 @@ fn main() {} type Two = impl Debug; fn one(t: T) -> Two { -//~^ defining existential type use restricts existential type +//~^ defining opaque type use restricts opaque type t } diff --git a/src/test/ui/existential_types/generic_duplicate_param_use3.stderr b/src/test/ui/existential_types/generic_duplicate_param_use3.stderr deleted file mode 100644 index 22d5467c363..00000000000 --- a/src/test/ui/existential_types/generic_duplicate_param_use3.stderr +++ /dev/null @@ -1,28 +0,0 @@ -error: defining existential type use restricts existential type by using the generic parameter `T` twice - --> $DIR/generic_duplicate_param_use3.rs:10:1 - | -LL | / fn one(t: T) -> Two { -LL | | -LL | | t -LL | | } - | |_^ - -error: concrete type's generic parameters differ from previous defining use - --> $DIR/generic_duplicate_param_use3.rs:19:1 - | -LL | / fn three(_: T, u: U) -> Two { -LL | | -LL | | u -LL | | } - | |_^ expected [`T`], got [`U`] - | -note: previous use here - --> $DIR/generic_duplicate_param_use3.rs:15:1 - | -LL | / fn two(t: T, _: U) -> Two { -LL | | t -LL | | } - | |_^ - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/existential_types/generic_duplicate_param_use4.rs b/src/test/ui/existential_types/generic_duplicate_param_use4.rs index 34a4a1ed53b..65f7d7f485d 100644 --- a/src/test/ui/existential_types/generic_duplicate_param_use4.rs +++ b/src/test/ui/existential_types/generic_duplicate_param_use4.rs @@ -8,7 +8,7 @@ fn main() {} type Two = impl Debug; fn one(t: T) -> Two { -//~^ ERROR defining existential type use restricts existential type +//~^ ERROR defining opaque type use restricts opaque type t } diff --git a/src/test/ui/existential_types/generic_duplicate_param_use4.stderr b/src/test/ui/existential_types/generic_duplicate_param_use4.stderr deleted file mode 100644 index d7e695578d3..00000000000 --- a/src/test/ui/existential_types/generic_duplicate_param_use4.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: defining existential type use restricts existential type by using the generic parameter `T` twice - --> $DIR/generic_duplicate_param_use4.rs:10:1 - | -LL | / fn one(t: T) -> Two { -LL | | -LL | | t -LL | | } - | |_^ - -error: aborting due to previous error - diff --git a/src/test/ui/existential_types/generic_duplicate_param_use5.rs b/src/test/ui/existential_types/generic_duplicate_param_use5.rs deleted file mode 100644 index ac877310414..00000000000 --- a/src/test/ui/existential_types/generic_duplicate_param_use5.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![feature(type_alias_impl_trait)] - -use std::fmt::Debug; - -fn main() {} - -// test that unused generic parameters are ok -type Two = impl Debug; - -fn two(t: T, u: U) -> Two { - (t, u) -} - -fn three(t: T, u: U) -> Two { -//~^ concrete type differs from previous - (u, t) -} diff --git a/src/test/ui/existential_types/generic_duplicate_param_use5.stderr b/src/test/ui/existential_types/generic_duplicate_param_use5.stderr deleted file mode 100644 index cf4535d6c2c..00000000000 --- a/src/test/ui/existential_types/generic_duplicate_param_use5.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: concrete type differs from previous defining existential type use - --> $DIR/generic_duplicate_param_use5.rs:14:1 - | -LL | / fn three(t: T, u: U) -> Two { -LL | | -LL | | (u, t) -LL | | } - | |_^ expected `(T, U)`, got `(U, T)` - | -note: previous use here - --> $DIR/generic_duplicate_param_use5.rs:10:1 - | -LL | / fn two(t: T, u: U) -> Two { -LL | | (t, u) -LL | | } - | |_^ - -error: aborting due to previous error - diff --git a/src/test/ui/existential_types/generic_duplicate_param_use6.rs b/src/test/ui/existential_types/generic_duplicate_param_use6.rs deleted file mode 100644 index 59e7de413a2..00000000000 --- a/src/test/ui/existential_types/generic_duplicate_param_use6.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![feature(type_alias_impl_trait)] - -use std::fmt::Debug; - -fn main() {} - -// test that unused generic parameters are ok -type Two = impl Debug; - -fn two(t: T, u: U) -> Two { - (t, t) -} - -fn three(t: T, u: U) -> Two { -//~^ concrete type differs from previous - (u, t) -} diff --git a/src/test/ui/existential_types/generic_duplicate_param_use6.stderr b/src/test/ui/existential_types/generic_duplicate_param_use6.stderr deleted file mode 100644 index 1f767dacea8..00000000000 --- a/src/test/ui/existential_types/generic_duplicate_param_use6.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: concrete type differs from previous defining existential type use - --> $DIR/generic_duplicate_param_use6.rs:14:1 - | -LL | / fn three(t: T, u: U) -> Two { -LL | | -LL | | (u, t) -LL | | } - | |_^ expected `(T, T)`, got `(U, T)` - | -note: previous use here - --> $DIR/generic_duplicate_param_use6.rs:10:1 - | -LL | / fn two(t: T, u: U) -> Two { -LL | | (t, t) -LL | | } - | |_^ - -error: aborting due to previous error - diff --git a/src/test/ui/existential_types/generic_duplicate_param_use7.rs b/src/test/ui/existential_types/generic_duplicate_param_use7.rs deleted file mode 100644 index 712a6539f01..00000000000 --- a/src/test/ui/existential_types/generic_duplicate_param_use7.rs +++ /dev/null @@ -1,24 +0,0 @@ -// build-pass (FIXME(62277): could be check-pass?) -#![feature(type_alias_impl_trait)] - -use std::fmt::Debug; - -fn main() {} - -type Two = impl Debug; - -fn two(t: T, u: U) -> Two { - (t, t) -} - -fn three(t: T, t2: T, u: U) -> Two { - (t, t2) -} - -fn four(t: T, t2: T, u: U, v: V) -> Two { - (t, t2) -} - -fn five(x: X, y: Y, y2: Y) -> Two { - (y, y2) -} diff --git a/src/test/ui/existential_types/generic_duplicate_param_use8.rs b/src/test/ui/existential_types/generic_duplicate_param_use8.rs deleted file mode 100644 index 777ded52609..00000000000 --- a/src/test/ui/existential_types/generic_duplicate_param_use8.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![feature(type_alias_impl_trait)] - -use std::fmt::Debug; - -fn main() {} - -type Two = impl Debug; - -fn two(t: T, _: U) -> Two { - (t, 4u32) -} - -fn three(_: T, u: U) -> Two { -//~^ concrete type differs from previous - (u, 4u32) -} diff --git a/src/test/ui/existential_types/generic_duplicate_param_use8.stderr b/src/test/ui/existential_types/generic_duplicate_param_use8.stderr deleted file mode 100644 index 58f4f97b241..00000000000 --- a/src/test/ui/existential_types/generic_duplicate_param_use8.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error: concrete type differs from previous defining existential type use - --> $DIR/generic_duplicate_param_use8.rs:13:1 - | -LL | / fn three(_: T, u: U) -> Two { -LL | | -LL | | (u, 4u32) -LL | | } - | |_^ expected `(T, u32)`, got `(U, u32)` - | -note: previous use here - --> $DIR/generic_duplicate_param_use8.rs:9:1 - | -LL | / fn two(t: T, _: U) -> Two { -LL | | (t, 4u32) -LL | | } - | |_^ - -error: aborting due to previous error - diff --git a/src/test/ui/existential_types/generic_duplicate_param_use9.rs b/src/test/ui/existential_types/generic_duplicate_param_use9.rs deleted file mode 100644 index 491e6647f45..00000000000 --- a/src/test/ui/existential_types/generic_duplicate_param_use9.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![feature(type_alias_impl_trait)] - -use std::fmt::Debug; - -fn main() {} - -type Two = impl Debug; - -trait Foo { - type Bar: Debug; - const BAR: Self::Bar; -} - -fn two(t: T, u: U) -> Two { - (t, u, T::BAR) -} - -fn three(t: T, u: U) -> Two { - (t, u, 42) //~^ ERROR concrete type differs from previous -} diff --git a/src/test/ui/existential_types/generic_duplicate_param_use9.stderr b/src/test/ui/existential_types/generic_duplicate_param_use9.stderr deleted file mode 100644 index fe4ae6cfdd0..00000000000 --- a/src/test/ui/existential_types/generic_duplicate_param_use9.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: concrete type differs from previous defining existential type use - --> $DIR/generic_duplicate_param_use9.rs:18:1 - | -LL | / fn three(t: T, u: U) -> Two { -LL | | (t, u, 42) -LL | | } - | |_^ expected `(A, B, ::Bar)`, got `(A, B, i32)` - | -note: previous use here - --> $DIR/generic_duplicate_param_use9.rs:14:1 - | -LL | / fn two(t: T, u: U) -> Two { -LL | | (t, u, T::BAR) -LL | | } - | |_^ - -error: aborting due to previous error - diff --git a/src/test/ui/existential_types/generic_lifetime_param.rs b/src/test/ui/existential_types/generic_lifetime_param.rs deleted file mode 100644 index e109c38c986..00000000000 --- a/src/test/ui/existential_types/generic_lifetime_param.rs +++ /dev/null @@ -1,11 +0,0 @@ -// build-pass (FIXME(62277): could be check-pass?) - -#![feature(type_alias_impl_trait)] - -fn main() {} - -type Region<'a> = impl std::fmt::Debug; - -fn region<'b>(a: &'b ()) -> Region<'b> { - a -} diff --git a/src/test/ui/existential_types/generic_nondefining_use.rs b/src/test/ui/existential_types/generic_nondefining_use.rs deleted file mode 100644 index e98445e3a0f..00000000000 --- a/src/test/ui/existential_types/generic_nondefining_use.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() {} - -type Cmp = impl 'static; -//~^ ERROR could not find defining uses -//~^^ ERROR: at least one trait must be specified - - -// not a defining use, because it doesn't define *all* possible generics -fn cmp() -> Cmp { //~ ERROR defining existential type use does not fully define - 5u32 -} diff --git a/src/test/ui/existential_types/generic_nondefining_use.stderr b/src/test/ui/existential_types/generic_nondefining_use.stderr deleted file mode 100644 index e50d545a8ad..00000000000 --- a/src/test/ui/existential_types/generic_nondefining_use.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: at least one trait must be specified - --> $DIR/generic_nondefining_use.rs:5:20 - | -LL | type Cmp = impl 'static; - | ^^^^^^^ - -error: defining existential type use does not fully define existential type - --> $DIR/generic_nondefining_use.rs:11:1 - | -LL | / fn cmp() -> Cmp { -LL | | 5u32 -LL | | } - | |_^ - -error: could not find defining uses - --> $DIR/generic_nondefining_use.rs:5:1 - | -LL | type Cmp = impl 'static; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - diff --git a/src/test/ui/existential_types/generic_not_used.rs b/src/test/ui/existential_types/generic_not_used.rs deleted file mode 100644 index ace52dc83ad..00000000000 --- a/src/test/ui/existential_types/generic_not_used.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() {} - -type WrongGeneric = impl 'static; -//~^ ERROR: at least one trait must be specified - -fn wrong_generic(_: U, v: V) -> WrongGeneric { -//~^ ERROR type parameter `V` is part of concrete type but not used in parameter list - v -} diff --git a/src/test/ui/existential_types/generic_not_used.stderr b/src/test/ui/existential_types/generic_not_used.stderr deleted file mode 100644 index 250296d9de9..00000000000 --- a/src/test/ui/existential_types/generic_not_used.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: at least one trait must be specified - --> $DIR/generic_not_used.rs:5:38 - | -LL | type WrongGeneric = impl 'static; - | ^^^^^^^ - -error: type parameter `V` is part of concrete type but not used in parameter list for existential type - --> $DIR/generic_not_used.rs:8:73 - | -LL | fn wrong_generic(_: U, v: V) -> WrongGeneric { - | _________________________________________________________________________^ -LL | | -LL | | v -LL | | } - | |_^ - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/existential_types/generic_type_does_not_live_long_enough.nll.stderr b/src/test/ui/existential_types/generic_type_does_not_live_long_enough.nll.stderr deleted file mode 100644 index f316644156d..00000000000 --- a/src/test/ui/existential_types/generic_type_does_not_live_long_enough.nll.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: at least one trait must be specified - --> $DIR/generic_type_does_not_live_long_enough.rs:9:35 - | -LL | existential type WrongGeneric: 'static; - | ^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/generic_type_does_not_live_long_enough.rs:6:18 - | -LL | let z: i32 = x; - | ^ expected i32, found opaque type - | - = note: expected type `i32` - found type `WrongGeneric::<&{integer}>` - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/existential_types/generic_type_does_not_live_long_enough.rs b/src/test/ui/existential_types/generic_type_does_not_live_long_enough.rs deleted file mode 100644 index c0f939a5048..00000000000 --- a/src/test/ui/existential_types/generic_type_does_not_live_long_enough.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() { - let y = 42; - let x = wrong_generic(&y); - let z: i32 = x; //~ ERROR mismatched types -} - -type WrongGeneric = impl 'static; -//~^ ERROR the parameter type `T` may not live long enough -//~^^ ERROR: at least one trait must be specified - -fn wrong_generic(t: T) -> WrongGeneric { - t -} diff --git a/src/test/ui/existential_types/generic_type_does_not_live_long_enough.stderr b/src/test/ui/existential_types/generic_type_does_not_live_long_enough.stderr deleted file mode 100644 index 12569211df3..00000000000 --- a/src/test/ui/existential_types/generic_type_does_not_live_long_enough.stderr +++ /dev/null @@ -1,34 +0,0 @@ -error: at least one trait must be specified - --> $DIR/generic_type_does_not_live_long_enough.rs:9:29 - | -LL | type WrongGeneric = impl 'static; - | ^^^^^^^ - -error[E0308]: mismatched types - --> $DIR/generic_type_does_not_live_long_enough.rs:6:18 - | -LL | let z: i32 = x; - | ^ expected i32, found opaque type - | - = note: expected type `i32` - found type `WrongGeneric::<&{integer}>` - -error[E0310]: the parameter type `T` may not live long enough - --> $DIR/generic_type_does_not_live_long_enough.rs:9:1 - | -LL | type WrongGeneric = impl 'static; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn wrong_generic(t: T) -> WrongGeneric { - | - help: consider adding an explicit lifetime bound `T: 'static`... - | -note: ...so that the type `T` will meet its required lifetime bounds - --> $DIR/generic_type_does_not_live_long_enough.rs:9:1 - | -LL | type WrongGeneric = impl 'static; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to 3 previous errors - -Some errors have detailed explanations: E0308, E0310. -For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/existential_types/generic_underconstrained.rs b/src/test/ui/existential_types/generic_underconstrained.rs deleted file mode 100644 index 589612d5ed6..00000000000 --- a/src/test/ui/existential_types/generic_underconstrained.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() {} - -trait Trait {} -type Underconstrained = impl 'static; //~ ERROR the trait bound `T: Trait` -//~^ ERROR: at least one trait must be specified - -// no `Trait` bound -fn underconstrain(_: T) -> Underconstrained { - unimplemented!() -} diff --git a/src/test/ui/existential_types/generic_underconstrained.stderr b/src/test/ui/existential_types/generic_underconstrained.stderr deleted file mode 100644 index dd90dd1b06f..00000000000 --- a/src/test/ui/existential_types/generic_underconstrained.stderr +++ /dev/null @@ -1,18 +0,0 @@ -error: at least one trait must be specified - --> $DIR/generic_underconstrained.rs:6:40 - | -LL | type Underconstrained = impl 'static; - | ^^^^^^^ - -error[E0277]: the trait bound `T: Trait` is not satisfied - --> $DIR/generic_underconstrained.rs:6:1 - | -LL | type Underconstrained = impl 'static; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` - | - = help: consider adding a `where T: Trait` bound - = note: the return type of a function must have a statically known size - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/existential_types/generic_underconstrained2.rs b/src/test/ui/existential_types/generic_underconstrained2.rs deleted file mode 100644 index 87b8aaad957..00000000000 --- a/src/test/ui/existential_types/generic_underconstrained2.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() {} - -type Underconstrained = impl 'static; -//~^ ERROR `U` doesn't implement `std::fmt::Debug` -//~^^ ERROR: at least one trait must be specified - -// not a defining use, because it doesn't define *all* possible generics -fn underconstrained(_: U) -> Underconstrained { - 5u32 -} - -type Underconstrained2 = impl 'static; -//~^ ERROR `V` doesn't implement `std::fmt::Debug` -//~^^ ERROR: at least one trait must be specified - -// not a defining use, because it doesn't define *all* possible generics -fn underconstrained2(_: U, _: V) -> Underconstrained2 { - 5u32 -} diff --git a/src/test/ui/existential_types/generic_underconstrained2.stderr b/src/test/ui/existential_types/generic_underconstrained2.stderr deleted file mode 100644 index 574432bdcf6..00000000000 --- a/src/test/ui/existential_types/generic_underconstrained2.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error: at least one trait must be specified - --> $DIR/generic_underconstrained2.rs:5:50 - | -LL | type Underconstrained = impl 'static; - | ^^^^^^^ - -error: at least one trait must be specified - --> $DIR/generic_underconstrained2.rs:14:51 - | -LL | type Underconstrained2 = impl 'static; - | ^^^^^^^ - -error[E0277]: `U` doesn't implement `std::fmt::Debug` - --> $DIR/generic_underconstrained2.rs:5:1 - | -LL | type Underconstrained = impl 'static; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` - | - = help: the trait `std::fmt::Debug` is not implemented for `U` - = help: consider adding a `where U: std::fmt::Debug` bound - = note: the return type of a function must have a statically known size - -error[E0277]: `V` doesn't implement `std::fmt::Debug` - --> $DIR/generic_underconstrained2.rs:14:1 - | -LL | type Underconstrained2 = impl 'static; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `V` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` - | - = help: the trait `std::fmt::Debug` is not implemented for `V` - = help: consider adding a `where V: std::fmt::Debug` bound - = note: the return type of a function must have a statically known size - -error: aborting due to 4 previous errors - -For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/existential_types/issue-58887.stderr b/src/test/ui/existential_types/issue-58887.stderr index cb786f5e161..7e2895711d3 100644 --- a/src/test/ui/existential_types/issue-58887.stderr +++ b/src/test/ui/existential_types/issue-58887.stderr @@ -1,4 +1,4 @@ -error: type parameter `T` is part of concrete type but not used in parameter list for existential type +error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias --> $DIR/issue-58887.rs:16:41 | LL | fn unwrap_items(self) -> Self::Iter { @@ -9,7 +9,7 @@ LL | | self.map(|x| x.unwrap()) LL | | } | |_____^ -error: type parameter `E` is part of concrete type but not used in parameter list for existential type +error: type parameter `E` is part of concrete type but not used in parameter list for the `impl Trait` type alias --> $DIR/issue-58887.rs:16:41 | LL | fn unwrap_items(self) -> Self::Iter { diff --git a/src/test/ui/existential_types/issue-60371.rs b/src/test/ui/existential_types/issue-60371.rs index cfb343f96ca..50b9d1ac793 100644 --- a/src/test/ui/existential_types/issue-60371.rs +++ b/src/test/ui/existential_types/issue-60371.rs @@ -5,7 +5,7 @@ trait Bug { } impl Bug for &() { - type Item = impl Bug; //~ ERROR existential types are unstable + type Item = impl Bug; //~ ERROR `impl Trait` in type aliases is unstable //~^ ERROR the trait bound `(): Bug` is not satisfied //~^^ ERROR could not find defining uses diff --git a/src/test/ui/existential_types/issue-60371.stderr b/src/test/ui/existential_types/issue-60371.stderr index 34936c73a46..1e9b12ebc39 100644 --- a/src/test/ui/existential_types/issue-60371.stderr +++ b/src/test/ui/existential_types/issue-60371.stderr @@ -1,4 +1,4 @@ -error[E0658]: existential types are unstable +error[E0658]: `impl Trait` in type aliases is unstable --> $DIR/issue-60371.rs:8:5 | LL | type Item = impl Bug; diff --git a/src/test/ui/existential_types/nested_existential_types.rs b/src/test/ui/existential_types/nested_existential_types.rs deleted file mode 100644 index 82c9ecd2ac6..00000000000 --- a/src/test/ui/existential_types/nested_existential_types.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![feature(type_alias_impl_trait)] -// build-pass (FIXME(62277): could be check-pass?) -mod my_mod { - use std::fmt::Debug; - - pub type Foo = impl Debug; - pub type Foot = impl Debug; - - pub fn get_foo() -> Foo { - 5i32 - } - - pub fn get_foot() -> Foot { - get_foo() - } -} - -fn main() { - let _: my_mod::Foot = my_mod::get_foot(); -} diff --git a/src/test/ui/existential_types/never_reveal_concrete_type.rs b/src/test/ui/existential_types/never_reveal_concrete_type.rs deleted file mode 100644 index 8787c023eb0..00000000000 --- a/src/test/ui/existential_types/never_reveal_concrete_type.rs +++ /dev/null @@ -1,15 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() {} - -// don't reveal the concrete type -type NoReveal = impl std::fmt::Debug; - -fn define_no_reveal() -> NoReveal { - "" -} - -fn no_reveal(x: NoReveal) { - let _: &'static str = x; //~ mismatched types - let _ = x as &'static str; //~ non-primitive cast -} diff --git a/src/test/ui/existential_types/never_reveal_concrete_type.stderr b/src/test/ui/existential_types/never_reveal_concrete_type.stderr deleted file mode 100644 index 7c195f1fad0..00000000000 --- a/src/test/ui/existential_types/never_reveal_concrete_type.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/never_reveal_concrete_type.rs:13:27 - | -LL | let _: &'static str = x; - | ^ expected reference, found opaque type - | - = note: expected type `&'static str` - found type `NoReveal` - -error[E0605]: non-primitive cast: `NoReveal` as `&'static str` - --> $DIR/never_reveal_concrete_type.rs:14:13 - | -LL | let _ = x as &'static str; - | ^^^^^^^^^^^^^^^^^ - | - = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0308, E0605. -For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/existential_types/no_inferrable_concrete_type.rs b/src/test/ui/existential_types/no_inferrable_concrete_type.rs index f096dd162d5..c9ca504f780 100644 --- a/src/test/ui/existential_types/no_inferrable_concrete_type.rs +++ b/src/test/ui/existential_types/no_inferrable_concrete_type.rs @@ -1,4 +1,4 @@ -// Issue 52985: user code provides no use case that allows an existential type +// Issue 52985: user code provides no use case that allows a type alias `impl Trait` // We now emit a 'could not find defining uses' error #![feature(type_alias_impl_trait)] diff --git a/src/test/ui/existential_types/no_revealing_outside_defining_module.rs b/src/test/ui/existential_types/no_revealing_outside_defining_module.rs deleted file mode 100644 index 61153b1e171..00000000000 --- a/src/test/ui/existential_types/no_revealing_outside_defining_module.rs +++ /dev/null @@ -1,24 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() {} - -mod boo { - pub type Boo = impl ::std::fmt::Debug; - fn bomp() -> Boo { - "" - } -} - -// We don't actually know the type here. - -fn bomp2() { - let _: &str = bomp(); //~ ERROR mismatched types -} - -fn bomp() -> boo::Boo { - "" //~ ERROR mismatched types -} - -fn bomp_loop() -> boo::Boo { - loop {} -} diff --git a/src/test/ui/existential_types/no_revealing_outside_defining_module.stderr b/src/test/ui/existential_types/no_revealing_outside_defining_module.stderr deleted file mode 100644 index 5e5826978fc..00000000000 --- a/src/test/ui/existential_types/no_revealing_outside_defining_module.stderr +++ /dev/null @@ -1,23 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/no_revealing_outside_defining_module.rs:15:19 - | -LL | let _: &str = bomp(); - | ^^^^^^ expected &str, found opaque type - | - = note: expected type `&str` - found type `Boo` - -error[E0308]: mismatched types - --> $DIR/no_revealing_outside_defining_module.rs:19:5 - | -LL | fn bomp() -> boo::Boo { - | -------- expected `Boo` because of return type -LL | "" - | ^^ expected opaque type, found reference - | - = note: expected type `Boo` - found type `&'static str` - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/existential_types/not_a_defining_use.rs b/src/test/ui/existential_types/not_a_defining_use.rs index c49e9bc80f6..ca00e582d34 100644 --- a/src/test/ui/existential_types/not_a_defining_use.rs +++ b/src/test/ui/existential_types/not_a_defining_use.rs @@ -7,7 +7,7 @@ fn main() {} type Two = impl Debug; fn two(t: T) -> Two { - //~^ ERROR defining existential type use does not fully define existential type + //~^ ERROR defining opaque type use does not fully define opaque type (t, 4i8) } diff --git a/src/test/ui/existential_types/not_a_defining_use.stderr b/src/test/ui/existential_types/not_a_defining_use.stderr index f315811cdb4..7bb8939ccf5 100644 --- a/src/test/ui/existential_types/not_a_defining_use.stderr +++ b/src/test/ui/existential_types/not_a_defining_use.stderr @@ -1,4 +1,4 @@ -error: defining existential type use does not fully define existential type +error: defining opaque type use does not fully define opaque type --> $DIR/not_a_defining_use.rs:9:1 | LL | / fn two(t: T) -> Two { @@ -7,7 +7,7 @@ LL | | (t, 4i8) LL | | } | |_^ -error: concrete type differs from previous defining existential type use +error: concrete type differs from previous defining opaque type use --> $DIR/not_a_defining_use.rs:30:1 | LL | / fn four(t: T) -> Two { diff --git a/src/test/ui/existential_types/not_well_formed.rs b/src/test/ui/existential_types/not_well_formed.rs deleted file mode 100644 index 36ec9b34ebd..00000000000 --- a/src/test/ui/existential_types/not_well_formed.rs +++ /dev/null @@ -1,18 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() { -} - -trait TraitWithAssoc { - type Assoc; -} - -type Foo = impl Trait; //~ associated type `Assoc` not found for `V` - -trait Trait {} - -impl Trait for () {} - -fn foo_desugared(_: T) -> Foo { - () -} diff --git a/src/test/ui/existential_types/not_well_formed.stderr b/src/test/ui/existential_types/not_well_formed.stderr deleted file mode 100644 index d374d6d33ee..00000000000 --- a/src/test/ui/existential_types/not_well_formed.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0220]: associated type `Assoc` not found for `V` - --> $DIR/not_well_formed.rs:10:26 - | -LL | type Foo = impl Trait; - | ^^^^^^^^ associated type `Assoc` not found - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0220`. diff --git a/src/test/ui/existential_types/private_unused.rs b/src/test/ui/existential_types/private_unused.rs deleted file mode 100644 index 92268f1861d..00000000000 --- a/src/test/ui/existential_types/private_unused.rs +++ /dev/null @@ -1,13 +0,0 @@ -// build-pass (FIXME(62277): could be check-pass?) - -#[deny(warnings)] - -enum Empty { } -trait Bar {} -impl Bar for () {} - -fn boo() -> impl Bar {} - -fn main() { - boo(); -} diff --git a/src/test/ui/existential_types/unused_generic_param.rs b/src/test/ui/existential_types/unused_generic_param.rs deleted file mode 100644 index a9ab727b193..00000000000 --- a/src/test/ui/existential_types/unused_generic_param.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![feature(type_alias_impl_trait)] - -fn main() { -} - -type PartiallyDefined = impl 'static; -//~^ ERROR: at least one trait must be specified - -fn partially_defined(_: T) -> PartiallyDefined { - 4u32 -} - -type PartiallyDefined2 = impl 'static; -//~^ ERROR: at least one trait must be specified - -fn partially_defined2(_: T) -> PartiallyDefined2 { - 4u32 -} - -fn partially_defined22(_: T) -> PartiallyDefined2 { - 4u32 -} diff --git a/src/test/ui/existential_types/unused_generic_param.stderr b/src/test/ui/existential_types/unused_generic_param.stderr deleted file mode 100644 index 23105026964..00000000000 --- a/src/test/ui/existential_types/unused_generic_param.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: at least one trait must be specified - --> $DIR/unused_generic_param.rs:6:33 - | -LL | type PartiallyDefined = impl 'static; - | ^^^^^^^ - -error: at least one trait must be specified - --> $DIR/unused_generic_param.rs:13:34 - | -LL | type PartiallyDefined2 = impl 'static; - | ^^^^^^^ - -error: aborting due to 2 previous errors - diff --git a/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.rs b/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.rs index e169cbcc34c..4a0c8c52c4e 100644 --- a/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.rs +++ b/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.rs @@ -1,4 +1,4 @@ -type Foo = impl std::fmt::Debug; //~ ERROR existential types are unstable +type Foo = impl std::fmt::Debug; //~ ERROR `impl Trait` in type aliases is unstable trait Bar { type Baa: std::fmt::Debug; @@ -6,7 +6,7 @@ trait Bar { } impl Bar for () { - type Baa = impl std::fmt::Debug; //~ ERROR existential types are unstable + type Baa = impl std::fmt::Debug; //~ ERROR `impl Trait` in type aliases is unstable fn define() -> Self::Baa { 0 } } diff --git a/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.stderr b/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.stderr index 83b16af8586..2d0710ea37c 100644 --- a/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.stderr +++ b/src/test/ui/feature-gates/feature-gate-type_alias_impl_trait.stderr @@ -1,4 +1,4 @@ -error[E0658]: existential types are unstable +error[E0658]: `impl Trait` in type aliases is unstable --> $DIR/feature-gate-type_alias_impl_trait.rs:1:1 | LL | type Foo = impl std::fmt::Debug; @@ -7,7 +7,7 @@ LL | type Foo = impl std::fmt::Debug; = note: for more information, see https://github.com/rust-lang/rust/issues/63063 = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable -error[E0658]: existential types are unstable +error[E0658]: `impl Trait` in type aliases is unstable --> $DIR/feature-gate-type_alias_impl_trait.rs:9:5 | LL | type Baa = impl std::fmt::Debug; diff --git a/src/test/ui/impl-trait/associated-existential-type-generic-trait.rs b/src/test/ui/impl-trait/associated-existential-type-generic-trait.rs deleted file mode 100644 index 6c7c46b0e3d..00000000000 --- a/src/test/ui/impl-trait/associated-existential-type-generic-trait.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![feature(type_alias_impl_trait)] -// build-pass (FIXME(62277): could be check-pass?) - -trait Bar {} -struct Dummy(U); -impl Bar for Dummy {} - -trait Foo { - type Assoc: Bar; - fn foo(t: T) -> Self::Assoc; -} - -impl Foo for i32 { - type Assoc = impl Bar; - fn foo(w: W) -> Self::Assoc { - Dummy(w) - } -} - -struct NonGeneric; -impl Bar for NonGeneric {} - -impl Foo for u32 { - type Assoc = impl Bar; - fn foo(_: W) -> Self::Assoc { - NonGeneric - } -} - -fn main() {} diff --git a/src/test/ui/impl-trait/associated-existential-type-trivial.rs b/src/test/ui/impl-trait/associated-existential-type-trivial.rs deleted file mode 100644 index cdda341cad8..00000000000 --- a/src/test/ui/impl-trait/associated-existential-type-trivial.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![feature(type_alias_impl_trait)] -// build-pass (FIXME(62277): could be check-pass?) - -trait Bar {} -struct Dummy; -impl Bar for Dummy {} - -trait Foo { - type Assoc: Bar; - fn foo() -> Self::Assoc; -} - -impl Foo for i32 { - type Assoc = impl Bar; - fn foo() -> Self::Assoc { - Dummy - } -} - -fn main() {} diff --git a/src/test/ui/impl-trait/associated-existential-type.rs b/src/test/ui/impl-trait/associated-existential-type.rs deleted file mode 100644 index d0661d66f4b..00000000000 --- a/src/test/ui/impl-trait/associated-existential-type.rs +++ /dev/null @@ -1,24 +0,0 @@ -#![feature(type_alias_impl_trait)] -// build-pass (FIXME(62277): could be check-pass?) - -trait Bar {} -struct Dummy; -impl Bar for Dummy {} - -trait Foo { - type Assoc: Bar; - fn foo() -> Self::Assoc; - fn bar() -> Self::Assoc; -} - -impl Foo for i32 { - type Assoc = impl Bar; - fn foo() -> Self::Assoc { - Dummy - } - fn bar() -> Self::Assoc { - Dummy - } -} - -fn main() {} diff --git a/src/test/ui/impl-trait/associated-impl-trait-type-generic-trait.rs b/src/test/ui/impl-trait/associated-impl-trait-type-generic-trait.rs new file mode 100644 index 00000000000..6c7c46b0e3d --- /dev/null +++ b/src/test/ui/impl-trait/associated-impl-trait-type-generic-trait.rs @@ -0,0 +1,30 @@ +#![feature(type_alias_impl_trait)] +// build-pass (FIXME(62277): could be check-pass?) + +trait Bar {} +struct Dummy(U); +impl Bar for Dummy {} + +trait Foo { + type Assoc: Bar; + fn foo(t: T) -> Self::Assoc; +} + +impl Foo for i32 { + type Assoc = impl Bar; + fn foo(w: W) -> Self::Assoc { + Dummy(w) + } +} + +struct NonGeneric; +impl Bar for NonGeneric {} + +impl Foo for u32 { + type Assoc = impl Bar; + fn foo(_: W) -> Self::Assoc { + NonGeneric + } +} + +fn main() {} diff --git a/src/test/ui/impl-trait/associated-impl-trait-type-trivial.rs b/src/test/ui/impl-trait/associated-impl-trait-type-trivial.rs new file mode 100644 index 00000000000..cdda341cad8 --- /dev/null +++ b/src/test/ui/impl-trait/associated-impl-trait-type-trivial.rs @@ -0,0 +1,20 @@ +#![feature(type_alias_impl_trait)] +// build-pass (FIXME(62277): could be check-pass?) + +trait Bar {} +struct Dummy; +impl Bar for Dummy {} + +trait Foo { + type Assoc: Bar; + fn foo() -> Self::Assoc; +} + +impl Foo for i32 { + type Assoc = impl Bar; + fn foo() -> Self::Assoc { + Dummy + } +} + +fn main() {} diff --git a/src/test/ui/impl-trait/associated-impl-trait-type.rs b/src/test/ui/impl-trait/associated-impl-trait-type.rs new file mode 100644 index 00000000000..d0661d66f4b --- /dev/null +++ b/src/test/ui/impl-trait/associated-impl-trait-type.rs @@ -0,0 +1,24 @@ +#![feature(type_alias_impl_trait)] +// build-pass (FIXME(62277): could be check-pass?) + +trait Bar {} +struct Dummy; +impl Bar for Dummy {} + +trait Foo { + type Assoc: Bar; + fn foo() -> Self::Assoc; + fn bar() -> Self::Assoc; +} + +impl Foo for i32 { + type Assoc = impl Bar; + fn foo() -> Self::Assoc { + Dummy + } + fn bar() -> Self::Assoc { + Dummy + } +} + +fn main() {} diff --git a/src/test/ui/impl-trait/existential-minimal.rs b/src/test/ui/impl-trait/existential-minimal.rs deleted file mode 100644 index 6d3c0692970..00000000000 --- a/src/test/ui/impl-trait/existential-minimal.rs +++ /dev/null @@ -1,5 +0,0 @@ -// build-pass (FIXME(62277): could be check-pass?) - -fn main() {} - -fn foo() -> impl std::fmt::Debug { "cake" } diff --git a/src/test/ui/impl-trait/existential_type_in_fn_body.rs b/src/test/ui/impl-trait/existential_type_in_fn_body.rs deleted file mode 100644 index 91be4efd56a..00000000000 --- a/src/test/ui/impl-trait/existential_type_in_fn_body.rs +++ /dev/null @@ -1,12 +0,0 @@ -// build-pass (FIXME(62277): could be check-pass?) - -#![feature(type_alias_impl_trait)] - -use std::fmt::Debug; - -fn main() { - type Existential = impl Debug; - - fn f() -> Existential {} - println!("{:?}", f()); -} diff --git a/src/test/ui/impl-trait/issue-55872-1.rs b/src/test/ui/impl-trait/issue-55872-1.rs index c127e4cef49..f99096b4d58 100644 --- a/src/test/ui/impl-trait/issue-55872-1.rs +++ b/src/test/ui/impl-trait/issue-55872-1.rs @@ -14,7 +14,7 @@ impl Bar for S { //~^^ ERROR the trait bound `T: std::marker::Copy` is not satisfied in `(S, T)` [E0277] fn foo() -> Self::E { - //~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for existential type + //~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias (S::default(), T::default()) } } diff --git a/src/test/ui/impl-trait/issue-55872-1.stderr b/src/test/ui/impl-trait/issue-55872-1.stderr index 8a429626a5b..d5756c01559 100644 --- a/src/test/ui/impl-trait/issue-55872-1.stderr +++ b/src/test/ui/impl-trait/issue-55872-1.stderr @@ -18,7 +18,7 @@ LL | type E = impl Copy; = note: required because it appears within the type `(S, T)` = note: the return type of a function must have a statically known size -error: type parameter `T` is part of concrete type but not used in parameter list for existential type +error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias --> $DIR/issue-55872-1.rs:16:37 | LL | fn foo() -> Self::E { diff --git a/src/test/ui/impl-trait/issue-55872-2.rs b/src/test/ui/impl-trait/issue-55872-2.rs index d7432bda839..dfee20ca649 100644 --- a/src/test/ui/impl-trait/issue-55872-2.rs +++ b/src/test/ui/impl-trait/issue-55872-2.rs @@ -12,7 +12,7 @@ impl Bar for S { type E = impl Copy; //~^ ERROR the trait bound `impl std::future::Future: std::marker::Copy` is not satisfied [E0277] fn foo() -> Self::E { - //~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for existential type + //~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias async {} } } diff --git a/src/test/ui/impl-trait/issue-55872-2.stderr b/src/test/ui/impl-trait/issue-55872-2.stderr index c9cc178d3f8..676c3fe3d4c 100644 --- a/src/test/ui/impl-trait/issue-55872-2.stderr +++ b/src/test/ui/impl-trait/issue-55872-2.stderr @@ -6,7 +6,7 @@ LL | type E = impl Copy; | = note: the return type of a function must have a statically known size -error: type parameter `T` is part of concrete type but not used in parameter list for existential type +error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias --> $DIR/issue-55872-2.rs:14:28 | LL | fn foo() -> Self::E { diff --git a/src/test/ui/impl-trait/issue-55872.rs b/src/test/ui/impl-trait/issue-55872.rs index bf2c5c82208..bc91aae70c7 100644 --- a/src/test/ui/impl-trait/issue-55872.rs +++ b/src/test/ui/impl-trait/issue-55872.rs @@ -11,7 +11,7 @@ impl Bar for S { type E = impl Copy; fn foo() -> Self::E { - //~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for existential type + //~^ ERROR type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias || () } } diff --git a/src/test/ui/impl-trait/issue-55872.stderr b/src/test/ui/impl-trait/issue-55872.stderr index 487f276e317..60654ec3461 100644 --- a/src/test/ui/impl-trait/issue-55872.stderr +++ b/src/test/ui/impl-trait/issue-55872.stderr @@ -1,4 +1,4 @@ -error: type parameter `T` is part of concrete type but not used in parameter list for existential type +error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias --> $DIR/issue-55872.rs:13:28 | LL | fn foo() -> Self::E { diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-existential.rs b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-existential.rs deleted file mode 100644 index ae44b371f4f..00000000000 --- a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-existential.rs +++ /dev/null @@ -1,32 +0,0 @@ -// edition:2018 -// build-pass (FIXME(62277): could be check-pass?) -// revisions: migrate mir -//[mir]compile-flags: -Z borrowck=mir - -#![feature(member_constraints)] -#![feature(type_alias_impl_trait)] - -trait Trait<'a, 'b> { } -impl Trait<'_, '_> for T { } - -// Here we wind up selecting `'a` and `'b` in the hidden type because -// those are the types that appear in the original values. - -type Foo<'a, 'b> = impl Trait<'a, 'b>; - -fn upper_bounds<'a, 'b>(a: &'a u8, b: &'b u8) -> Foo<'a, 'b> { - // In this simple case, you have a hidden type `(&'0 u8, &'1 u8)` and constraints like - // - // ``` - // 'a: '0 - // 'b: '1 - // '0 in ['a, 'b] - // '1 in ['a, 'b] - // ``` - // - // We use the fact that `'a: 0'` must hold (combined with the in - // constraint) to determine that `'0 = 'a` must be the answer. - (a, b) -} - -fn main() { } diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-type-alias-impl-trait.rs b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-type-alias-impl-trait.rs new file mode 100644 index 00000000000..ae44b371f4f --- /dev/null +++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-type-alias-impl-trait.rs @@ -0,0 +1,32 @@ +// edition:2018 +// build-pass (FIXME(62277): could be check-pass?) +// revisions: migrate mir +//[mir]compile-flags: -Z borrowck=mir + +#![feature(member_constraints)] +#![feature(type_alias_impl_trait)] + +trait Trait<'a, 'b> { } +impl Trait<'_, '_> for T { } + +// Here we wind up selecting `'a` and `'b` in the hidden type because +// those are the types that appear in the original values. + +type Foo<'a, 'b> = impl Trait<'a, 'b>; + +fn upper_bounds<'a, 'b>(a: &'a u8, b: &'b u8) -> Foo<'a, 'b> { + // In this simple case, you have a hidden type `(&'0 u8, &'1 u8)` and constraints like + // + // ``` + // 'a: '0 + // 'b: '1 + // '0 in ['a, 'b] + // '1 in ['a, 'b] + // ``` + // + // We use the fact that `'a: 0'` must hold (combined with the in + // constraint) to determine that `'0 = 'a` must be the answer. + (a, b) +} + +fn main() { } diff --git a/src/test/ui/impl-trait/return-position-impl-trait-minimal.rs b/src/test/ui/impl-trait/return-position-impl-trait-minimal.rs new file mode 100644 index 00000000000..6d3c0692970 --- /dev/null +++ b/src/test/ui/impl-trait/return-position-impl-trait-minimal.rs @@ -0,0 +1,5 @@ +// build-pass (FIXME(62277): could be check-pass?) + +fn main() {} + +fn foo() -> impl std::fmt::Debug { "cake" } diff --git a/src/test/ui/impl-trait/type-alias-impl-trait-in-fn-body.rs b/src/test/ui/impl-trait/type-alias-impl-trait-in-fn-body.rs new file mode 100644 index 00000000000..91be4efd56a --- /dev/null +++ b/src/test/ui/impl-trait/type-alias-impl-trait-in-fn-body.rs @@ -0,0 +1,12 @@ +// build-pass (FIXME(62277): could be check-pass?) + +#![feature(type_alias_impl_trait)] + +use std::fmt::Debug; + +fn main() { + type Existential = impl Debug; + + fn f() -> Existential {} + println!("{:?}", f()); +} diff --git a/src/test/ui/impl-trait/where-allowed.rs b/src/test/ui/impl-trait/where-allowed.rs index 5b6105421fe..9eac6b714de 100644 --- a/src/test/ui/impl-trait/where-allowed.rs +++ b/src/test/ui/impl-trait/where-allowed.rs @@ -120,7 +120,7 @@ trait DummyTrait { } impl DummyTrait for () { type Out = impl Debug; - //~^ ERROR existential types are unstable + //~^ ERROR `impl Trait` in type aliases is unstable //~^^ ERROR could not find defining uses fn in_trait_impl_parameter(_: impl Debug) { } @@ -156,7 +156,7 @@ extern "C" fn in_extern_fn_return() -> impl Debug { } type InTypeAlias = impl Debug; -//~^ ERROR existential types are unstable +//~^ ERROR `impl Trait` in type aliases is unstable //~^^ ERROR could not find defining uses type InReturnInTypeAlias = fn() -> impl Debug; diff --git a/src/test/ui/impl-trait/where-allowed.stderr b/src/test/ui/impl-trait/where-allowed.stderr index 08f456199e9..1332fff84f5 100644 --- a/src/test/ui/impl-trait/where-allowed.stderr +++ b/src/test/ui/impl-trait/where-allowed.stderr @@ -16,7 +16,7 @@ LL | fn in_impl_Fn_parameter_in_return() -> &'static impl Fn(impl Debug) { panic | | nested `impl Trait` here | outer `impl Trait` -error[E0658]: existential types are unstable +error[E0658]: `impl Trait` in type aliases is unstable --> $DIR/where-allowed.rs:122:5 | LL | type Out = impl Debug; @@ -25,7 +25,7 @@ LL | type Out = impl Debug; = note: for more information, see https://github.com/rust-lang/rust/issues/63063 = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable -error[E0658]: existential types are unstable +error[E0658]: `impl Trait` in type aliases is unstable --> $DIR/where-allowed.rs:158:1 | LL | type InTypeAlias = impl Debug; diff --git a/src/test/ui/in-band-lifetimes.rs b/src/test/ui/in-band-lifetimes.rs index c9f7d28699e..9b2e1fe83c1 100644 --- a/src/test/ui/in-band-lifetimes.rs +++ b/src/test/ui/in-band-lifetimes.rs @@ -77,19 +77,19 @@ fn impl_trait_in_band(x: &impl MyTrait<'a>) {} trait FunkyTrait<'a> { } impl<'a, T> FunkyTrait<'a> for T { } -fn existential_impl_trait_in_band_outlives(x: &'a u32) -> impl ::std::fmt::Debug + 'a { +fn ret_pos_impl_trait_in_band_outlives(x: &'a u32) -> impl ::std::fmt::Debug + 'a { x } -fn existential_impl_trait_in_band_param(x: &'a u32) -> impl FunkyTrait<'a> { +fn ret_pos_impl_trait_in_band_param(x: &'a u32) -> impl FunkyTrait<'a> { x } -fn existential_impl_trait_in_band_param_static(x: &'a u32) -> impl FunkyTrait<'static> + 'a { +fn ret_pos_impl_trait_in_band_param_static(x: &'a u32) -> impl FunkyTrait<'static> + 'a { x } -fn existential_impl_trait_in_band_param_outlives(x: &'a u32) -> impl FunkyTrait<'a> + 'a { +fn ret_pos_impl_trait_in_band_param_outlives(x: &'a u32) -> impl FunkyTrait<'a> + 'a { x } -fn existential_impl_trait_in_band_higher_ranked(x: &'a u32) -> impl for<'b> FunkyTrait<'b> + 'a { +fn ret_pos_impl_trait_in_band_higher_ranked(x: &'a u32) -> impl for<'b> FunkyTrait<'b> + 'a { x } diff --git a/src/test/ui/issues/issue-60662.stdout b/src/test/ui/issues/issue-60662.stdout index 6389c86ecf7..21bd650bad0 100644 --- a/src/test/ui/issues/issue-60662.stdout +++ b/src/test/ui/issues/issue-60662.stdout @@ -10,5 +10,5 @@ extern crate std; trait Animal { } fn main() { - pub existential type ServeFut : Animal; + pub type ServeFut= impl : Animal; } diff --git a/src/test/ui/privacy/private-in-public-existential.rs b/src/test/ui/privacy/private-in-public-existential.rs deleted file mode 100644 index 40bba720b0f..00000000000 --- a/src/test/ui/privacy/private-in-public-existential.rs +++ /dev/null @@ -1,25 +0,0 @@ -// build-pass (FIXME(62277): could be check-pass?) - -#![feature(type_alias_impl_trait)] -#![deny(private_in_public)] - -pub type Pub = impl Default; - -#[derive(Default)] -struct Priv; - -fn check() -> Pub { - Priv -} - -pub trait Trait { - type Pub: Default; - fn method() -> Self::Pub; -} - -impl Trait for u8 { - type Pub = impl Default; - fn method() -> Self::Pub { Priv } -} - -fn main() {} diff --git a/src/test/ui/privacy/private-in-public-type-alias-impl-trait.rs b/src/test/ui/privacy/private-in-public-type-alias-impl-trait.rs new file mode 100644 index 00000000000..40bba720b0f --- /dev/null +++ b/src/test/ui/privacy/private-in-public-type-alias-impl-trait.rs @@ -0,0 +1,25 @@ +// build-pass (FIXME(62277): could be check-pass?) + +#![feature(type_alias_impl_trait)] +#![deny(private_in_public)] + +pub type Pub = impl Default; + +#[derive(Default)] +struct Priv; + +fn check() -> Pub { + Priv +} + +pub trait Trait { + type Pub: Default; + fn method() -> Self::Pub; +} + +impl Trait for u8 { + type Pub = impl Default; + fn method() -> Self::Pub { Priv } +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait.rs b/src/test/ui/type-alias-impl-trait.rs new file mode 100644 index 00000000000..209134acf01 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait.rs @@ -0,0 +1,89 @@ +// run-pass + +#![allow(dead_code)] +#![allow(unused_assignments)] +#![allow(unused_variables)] +#![feature(type_alias_impl_trait)] + +fn main() { + assert_eq!(foo().to_string(), "foo"); + assert_eq!(bar1().to_string(), "bar1"); + assert_eq!(bar2().to_string(), "bar2"); + let mut x = bar1(); + x = bar2(); + assert_eq!(boo::boo().to_string(), "boo"); + assert_eq!(my_iter(42u8).collect::>(), vec![42u8]); +} + +// single definition +type Foo = impl std::fmt::Display; + +fn foo() -> Foo { + "foo" +} + +// two definitions +type Bar = impl std::fmt::Display; + +fn bar1() -> Bar { + "bar1" +} + +fn bar2() -> Bar { + "bar2" +} + +// definition in submodule +type Boo = impl std::fmt::Display; + +mod boo { + pub fn boo() -> super::Boo { + "boo" + } +} + +type MyIter = impl Iterator; + +fn my_iter(t: T) -> MyIter { + std::iter::once(t) +} + +fn my_iter2(t: T) -> MyIter { + std::iter::once(t) +} + +// param names should not have an effect! +fn my_iter3(u: U) -> MyIter { + std::iter::once(u) +} + +// param position should not have an effect! +fn my_iter4(_: U, v: V) -> MyIter { + std::iter::once(v) +} + +// param names should not have an effect! +type MyOtherIter = impl Iterator; + +fn my_other_iter(u: U) -> MyOtherIter { + std::iter::once(u) +} + +trait Trait {} +type GenericBound<'a, T: Trait> = impl Sized + 'a; + +fn generic_bound<'a, T: Trait + 'a>(t: T) -> GenericBound<'a, T> { + t +} + +mod pass_through { + pub type Passthrough = impl Sized + 'static; + + fn define_passthrough(t: T) -> Passthrough { + t + } +} + +fn use_passthrough(x: pass_through::Passthrough) -> pass_through::Passthrough { + x +} diff --git a/src/test/ui/type-alias-impl-trait/associated-type-alias-impl-trait.rs b/src/test/ui/type-alias-impl-trait/associated-type-alias-impl-trait.rs new file mode 100644 index 00000000000..42f07d49ffe --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/associated-type-alias-impl-trait.rs @@ -0,0 +1,26 @@ +#![feature(type_alias_impl_trait)] +// build-pass (FIXME(62277): could be check-pass?) + +trait Bar {} +struct Dummy; +impl Bar for Dummy {} + +trait Foo { + type Assoc: Bar; + fn foo() -> Self::Assoc; + fn bar() -> Self::Assoc; +} + +type Helper = impl Bar; + +impl Foo for i32 { + type Assoc = Helper; + fn foo() -> Helper { + Dummy + } + fn bar() -> Helper { + Dummy + } +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/auxiliary/cross_crate_ice.rs b/src/test/ui/type-alias-impl-trait/auxiliary/cross_crate_ice.rs new file mode 100644 index 00000000000..f61807cbdbd --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/auxiliary/cross_crate_ice.rs @@ -0,0 +1,11 @@ +// Crate that exports an opaque `impl Trait` type. Used for testing cross-crate. + +#![crate_type="rlib"] + +#![feature(type_alias_impl_trait)] + +pub type Foo = impl std::fmt::Debug; + +pub fn foo() -> Foo { + 5 +} diff --git a/src/test/ui/type-alias-impl-trait/auxiliary/cross_crate_ice2.rs b/src/test/ui/type-alias-impl-trait/auxiliary/cross_crate_ice2.rs new file mode 100644 index 00000000000..00823456267 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/auxiliary/cross_crate_ice2.rs @@ -0,0 +1,21 @@ +// Crate that exports an opaque `impl Trait` type. Used for testing cross-crate. + +#![crate_type="rlib"] + +#![feature(type_alias_impl_trait)] + +pub trait View { + type Tmp: Iterator; + + fn test(&self) -> Self::Tmp; +} + +pub struct X; + +impl View for X { + type Tmp = impl Iterator; + + fn test(&self) -> Self::Tmp { + vec![1,2,3].into_iter() + } +} diff --git a/src/test/ui/type-alias-impl-trait/bound_reduction.rs b/src/test/ui/type-alias-impl-trait/bound_reduction.rs new file mode 100644 index 00000000000..18c840d8ed9 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/bound_reduction.rs @@ -0,0 +1,20 @@ +// build-pass (FIXME(62277): could be check-pass?) + +#![allow(warnings)] + +#![feature(type_alias_impl_trait)] + +fn main() { +} + +type Foo = impl std::fmt::Debug; + +trait Trait {} + +fn foo_desugared>(_: T) -> Foo { + (42, std::marker::PhantomData::) +} diff --git a/src/test/ui/type-alias-impl-trait/bound_reduction2.rs b/src/test/ui/type-alias-impl-trait/bound_reduction2.rs new file mode 100644 index 00000000000..919446877a1 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/bound_reduction2.rs @@ -0,0 +1,19 @@ +#![feature(type_alias_impl_trait)] + +fn main() { +} + +trait TraitWithAssoc { + type Assoc; +} + +type Foo = impl Trait; +//~^ ERROR could not find defining uses + +trait Trait {} + +impl Trait for () {} + +fn foo_desugared(_: T) -> Foo { //~ ERROR does not fully define + () +} diff --git a/src/test/ui/type-alias-impl-trait/bound_reduction2.stderr b/src/test/ui/type-alias-impl-trait/bound_reduction2.stderr new file mode 100644 index 00000000000..886d17aca36 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/bound_reduction2.stderr @@ -0,0 +1,16 @@ +error: defining opaque type use does not fully define opaque type + --> $DIR/bound_reduction2.rs:17:1 + | +LL | / fn foo_desugared(_: T) -> Foo { +LL | | () +LL | | } + | |_^ + +error: could not find defining uses + --> $DIR/bound_reduction2.rs:10:1 + | +LL | type Foo = impl Trait; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/type-alias-impl-trait/cross_crate_ice.rs b/src/test/ui/type-alias-impl-trait/cross_crate_ice.rs new file mode 100644 index 00000000000..c30608176aa --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/cross_crate_ice.rs @@ -0,0 +1,16 @@ +// aux-build:cross_crate_ice.rs +// build-pass (FIXME(62277): could be check-pass?) + +extern crate cross_crate_ice; + +struct Bar(cross_crate_ice::Foo); + +impl Bar { + fn zero(&self) -> &cross_crate_ice::Foo { + &self.0 + } +} + +fn main() { + let _ = cross_crate_ice::foo(); +} diff --git a/src/test/ui/type-alias-impl-trait/cross_crate_ice2.rs b/src/test/ui/type-alias-impl-trait/cross_crate_ice2.rs new file mode 100644 index 00000000000..3a7e490260f --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/cross_crate_ice2.rs @@ -0,0 +1,11 @@ +// aux-build:cross_crate_ice2.rs +// build-pass (FIXME(62277): could be check-pass?) + +extern crate cross_crate_ice2; + +use cross_crate_ice2::View; + +fn main() { + let v = cross_crate_ice2::X; + v.test(); +} diff --git a/src/test/ui/type-alias-impl-trait/declared_but_never_defined.rs b/src/test/ui/type-alias-impl-trait/declared_but_never_defined.rs new file mode 100644 index 00000000000..c4bf56a9197 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/declared_but_never_defined.rs @@ -0,0 +1,6 @@ +#![feature(type_alias_impl_trait)] + +fn main() {} + +// declared but never defined +type Bar = impl std::fmt::Debug; //~ ERROR could not find defining uses diff --git a/src/test/ui/type-alias-impl-trait/declared_but_never_defined.stderr b/src/test/ui/type-alias-impl-trait/declared_but_never_defined.stderr new file mode 100644 index 00000000000..ae0fee4333b --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/declared_but_never_defined.stderr @@ -0,0 +1,8 @@ +error: could not find defining uses + --> $DIR/declared_but_never_defined.rs:6:1 + | +LL | type Bar = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.rs b/src/test/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.rs new file mode 100644 index 00000000000..09873a8c8c3 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.rs @@ -0,0 +1,12 @@ +#![feature(type_alias_impl_trait)] + +fn main() {} + +mod boo { + // declared in module but not defined inside of it + pub type Boo = impl ::std::fmt::Debug; //~ ERROR could not find defining uses +} + +fn bomp() -> boo::Boo { + "" +} diff --git a/src/test/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.stderr b/src/test/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.stderr new file mode 100644 index 00000000000..0642407aba3 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.stderr @@ -0,0 +1,8 @@ +error: could not find defining uses + --> $DIR/declared_but_not_defined_in_scope.rs:7:5 + | +LL | pub type Boo = impl ::std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/type-alias-impl-trait/different_defining_uses.rs b/src/test/ui/type-alias-impl-trait/different_defining_uses.rs new file mode 100644 index 00000000000..2d7780a126c --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/different_defining_uses.rs @@ -0,0 +1,14 @@ +#![feature(type_alias_impl_trait)] + +fn main() {} + +// two definitions with different types +type Foo = impl std::fmt::Debug; + +fn foo() -> Foo { + "" +} + +fn bar() -> Foo { //~ ERROR concrete type differs from previous + 42i32 +} diff --git a/src/test/ui/type-alias-impl-trait/different_defining_uses.stderr b/src/test/ui/type-alias-impl-trait/different_defining_uses.stderr new file mode 100644 index 00000000000..87ed997ec59 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/different_defining_uses.stderr @@ -0,0 +1,18 @@ +error: concrete type differs from previous defining opaque type use + --> $DIR/different_defining_uses.rs:12:1 + | +LL | / fn bar() -> Foo { +LL | | 42i32 +LL | | } + | |_^ expected `&'static str`, got `i32` + | +note: previous use here + --> $DIR/different_defining_uses.rs:8:1 + | +LL | / fn foo() -> Foo { +LL | | "" +LL | | } + | |_^ + +error: aborting due to previous error + diff --git a/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.rs b/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.rs new file mode 100644 index 00000000000..289b97b00ad --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.rs @@ -0,0 +1,18 @@ +#![feature(type_alias_impl_trait)] + +fn main() {} + +// two definitions with different types +type Foo = impl std::fmt::Debug; + +fn foo() -> Foo { + "" +} + +fn bar() -> Foo { //~ ERROR concrete type differs from previous + panic!() +} + +fn boo() -> Foo { //~ ERROR concrete type differs from previous + loop {} +} diff --git a/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.stderr b/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.stderr new file mode 100644 index 00000000000..5be656e8f44 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type.stderr @@ -0,0 +1,34 @@ +error: concrete type differs from previous defining opaque type use + --> $DIR/different_defining_uses_never_type.rs:12:1 + | +LL | / fn bar() -> Foo { +LL | | panic!() +LL | | } + | |_^ expected `&'static str`, got `()` + | +note: previous use here + --> $DIR/different_defining_uses_never_type.rs:8:1 + | +LL | / fn foo() -> Foo { +LL | | "" +LL | | } + | |_^ + +error: concrete type differs from previous defining opaque type use + --> $DIR/different_defining_uses_never_type.rs:16:1 + | +LL | / fn boo() -> Foo { +LL | | loop {} +LL | | } + | |_^ expected `&'static str`, got `()` + | +note: previous use here + --> $DIR/different_defining_uses_never_type.rs:8:1 + | +LL | / fn foo() -> Foo { +LL | | "" +LL | | } + | |_^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type2.rs b/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type2.rs new file mode 100644 index 00000000000..8549687ea78 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/different_defining_uses_never_type2.rs @@ -0,0 +1,44 @@ +// build-pass (FIXME(62277): could be check-pass?) + +#![feature(type_alias_impl_trait)] + +fn main() {} + +// two definitions with different types +type Foo = impl std::fmt::Debug; + +fn foo() -> Foo { + "" +} + +fn bar(arg: bool) -> Foo { + if arg { + panic!() + } else { + "bar" + } +} + +fn boo(arg: bool) -> Foo { + if arg { + loop {} + } else { + "boo" + } +} + +fn bar2(arg: bool) -> Foo { + if arg { + "bar2" + } else { + panic!() + } +} + +fn boo2(arg: bool) -> Foo { + if arg { + "boo2" + } else { + loop {} + } +} diff --git a/src/test/ui/type-alias-impl-trait/generic_different_defining_uses.rs b/src/test/ui/type-alias-impl-trait/generic_different_defining_uses.rs new file mode 100644 index 00000000000..ac87c2d446a --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_different_defining_uses.rs @@ -0,0 +1,13 @@ +#![feature(type_alias_impl_trait)] + +fn main() {} + +type MyIter = impl Iterator; + +fn my_iter(t: T) -> MyIter { + std::iter::once(t) +} + +fn my_iter2(t: T) -> MyIter { //~ ERROR concrete type differs from previous + Some(t).into_iter() +} diff --git a/src/test/ui/type-alias-impl-trait/generic_different_defining_uses.stderr b/src/test/ui/type-alias-impl-trait/generic_different_defining_uses.stderr new file mode 100644 index 00000000000..4bcd2e1cb12 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_different_defining_uses.stderr @@ -0,0 +1,18 @@ +error: concrete type differs from previous defining opaque type use + --> $DIR/generic_different_defining_uses.rs:11:1 + | +LL | / fn my_iter2(t: T) -> MyIter { +LL | | Some(t).into_iter() +LL | | } + | |_^ expected `std::iter::Once`, got `std::option::IntoIter` + | +note: previous use here + --> $DIR/generic_different_defining_uses.rs:7:1 + | +LL | / fn my_iter(t: T) -> MyIter { +LL | | std::iter::once(t) +LL | | } + | |_^ + +error: aborting due to previous error + diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs new file mode 100644 index 00000000000..c18a7116758 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs @@ -0,0 +1,9 @@ +#![feature(type_alias_impl_trait)] + +fn main() {} + +type Two<'a, 'b> = impl std::fmt::Debug; + +fn one<'a>(t: &'a ()) -> Two<'a, 'a> { //~ ERROR non-defining opaque type use + t +} diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr new file mode 100644 index 00000000000..a4d9a672154 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr @@ -0,0 +1,16 @@ +error: non-defining opaque type use in defining scope + --> $DIR/generic_duplicate_lifetime_param.rs:7:1 + | +LL | / fn one<'a>(t: &'a ()) -> Two<'a, 'a> { +LL | | t +LL | | } + | |_^ + | +note: lifetime used multiple times + --> $DIR/generic_duplicate_lifetime_param.rs:5:10 + | +LL | type Two<'a, 'b> = impl std::fmt::Debug; + | ^^ ^^ + +error: aborting due to previous error + diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs new file mode 100644 index 00000000000..165e320be5e --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.rs @@ -0,0 +1,14 @@ +#![feature(type_alias_impl_trait)] + +use std::fmt::Debug; + +fn main() {} + +// test that unused generic parameters are ok +type Two = impl Debug; +//~^ could not find defining uses + +fn one(t: T) -> Two { +//~^ ERROR defining opaque type use restricts opaque type + t +} diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr new file mode 100644 index 00000000000..e1794034e20 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr @@ -0,0 +1,17 @@ +error: defining opaque type use restricts opaque type by using the generic parameter `T` twice + --> $DIR/generic_duplicate_param_use.rs:11:1 + | +LL | / fn one(t: T) -> Two { +LL | | +LL | | t +LL | | } + | |_^ + +error: could not find defining uses + --> $DIR/generic_duplicate_param_use.rs:8:1 + | +LL | type Two = impl Debug; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use10.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use10.rs new file mode 100644 index 00000000000..898dab1b0b9 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use10.rs @@ -0,0 +1,12 @@ +// build-pass (FIXME(62277): could be check-pass?) +#![feature(type_alias_impl_trait)] + +use std::fmt::Debug; + +fn main() {} + +type Two = impl Debug; + +fn two(t: T, _: U) -> Two { + (t, 4u32) +} diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.rs new file mode 100644 index 00000000000..0adce817c5c --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.rs @@ -0,0 +1,17 @@ +#![feature(type_alias_impl_trait)] + +use std::fmt::Debug; + +fn main() {} + +// test that unused generic parameters are ok +type Two = impl Debug; + +fn one(t: T) -> Two { +//~^ defining opaque type use restricts opaque type + t +} + +fn two(t: T, _: U) -> Two { + t +} diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.stderr new file mode 100644 index 00000000000..a9a51fa0b4b --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use2.stderr @@ -0,0 +1,11 @@ +error: defining opaque type use restricts opaque type by using the generic parameter `T` twice + --> $DIR/generic_duplicate_param_use2.rs:10:1 + | +LL | / fn one(t: T) -> Two { +LL | | +LL | | t +LL | | } + | |_^ + +error: aborting due to previous error + diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.rs new file mode 100644 index 00000000000..8d3e7f9f424 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.rs @@ -0,0 +1,22 @@ +#![feature(type_alias_impl_trait)] + +use std::fmt::Debug; + +fn main() {} + +// test that unused generic parameters are ok +type Two = impl Debug; + +fn one(t: T) -> Two { +//~^ defining opaque type use restricts opaque type + t +} + +fn two(t: T, _: U) -> Two { + t +} + +fn three(_: T, u: U) -> Two { +//~^ concrete type's generic parameters differ from previous defining use + u +} diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.stderr new file mode 100644 index 00000000000..04dcdc295f9 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use3.stderr @@ -0,0 +1,28 @@ +error: defining opaque type use restricts opaque type by using the generic parameter `T` twice + --> $DIR/generic_duplicate_param_use3.rs:10:1 + | +LL | / fn one(t: T) -> Two { +LL | | +LL | | t +LL | | } + | |_^ + +error: concrete type's generic parameters differ from previous defining use + --> $DIR/generic_duplicate_param_use3.rs:19:1 + | +LL | / fn three(_: T, u: U) -> Two { +LL | | +LL | | u +LL | | } + | |_^ expected [`T`], got [`U`] + | +note: previous use here + --> $DIR/generic_duplicate_param_use3.rs:15:1 + | +LL | / fn two(t: T, _: U) -> Two { +LL | | t +LL | | } + | |_^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.rs new file mode 100644 index 00000000000..65f7d7f485d --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.rs @@ -0,0 +1,17 @@ +#![feature(type_alias_impl_trait)] + +use std::fmt::Debug; + +fn main() {} + +// test that unused generic parameters are ok +type Two = impl Debug; + +fn one(t: T) -> Two { +//~^ ERROR defining opaque type use restricts opaque type + t +} + +fn three(_: T, u: U) -> Two { + u +} diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.stderr new file mode 100644 index 00000000000..082177b8212 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use4.stderr @@ -0,0 +1,11 @@ +error: defining opaque type use restricts opaque type by using the generic parameter `T` twice + --> $DIR/generic_duplicate_param_use4.rs:10:1 + | +LL | / fn one(t: T) -> Two { +LL | | +LL | | t +LL | | } + | |_^ + +error: aborting due to previous error + diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.rs new file mode 100644 index 00000000000..ac877310414 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.rs @@ -0,0 +1,17 @@ +#![feature(type_alias_impl_trait)] + +use std::fmt::Debug; + +fn main() {} + +// test that unused generic parameters are ok +type Two = impl Debug; + +fn two(t: T, u: U) -> Two { + (t, u) +} + +fn three(t: T, u: U) -> Two { +//~^ concrete type differs from previous + (u, t) +} diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr new file mode 100644 index 00000000000..589ea749319 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr @@ -0,0 +1,19 @@ +error: concrete type differs from previous defining opaque type use + --> $DIR/generic_duplicate_param_use5.rs:14:1 + | +LL | / fn three(t: T, u: U) -> Two { +LL | | +LL | | (u, t) +LL | | } + | |_^ expected `(T, U)`, got `(U, T)` + | +note: previous use here + --> $DIR/generic_duplicate_param_use5.rs:10:1 + | +LL | / fn two(t: T, u: U) -> Two { +LL | | (t, u) +LL | | } + | |_^ + +error: aborting due to previous error + diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.rs new file mode 100644 index 00000000000..59e7de413a2 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.rs @@ -0,0 +1,17 @@ +#![feature(type_alias_impl_trait)] + +use std::fmt::Debug; + +fn main() {} + +// test that unused generic parameters are ok +type Two = impl Debug; + +fn two(t: T, u: U) -> Two { + (t, t) +} + +fn three(t: T, u: U) -> Two { +//~^ concrete type differs from previous + (u, t) +} diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr new file mode 100644 index 00000000000..66649413d38 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr @@ -0,0 +1,19 @@ +error: concrete type differs from previous defining opaque type use + --> $DIR/generic_duplicate_param_use6.rs:14:1 + | +LL | / fn three(t: T, u: U) -> Two { +LL | | +LL | | (u, t) +LL | | } + | |_^ expected `(T, T)`, got `(U, T)` + | +note: previous use here + --> $DIR/generic_duplicate_param_use6.rs:10:1 + | +LL | / fn two(t: T, u: U) -> Two { +LL | | (t, t) +LL | | } + | |_^ + +error: aborting due to previous error + diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use7.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use7.rs new file mode 100644 index 00000000000..712a6539f01 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use7.rs @@ -0,0 +1,24 @@ +// build-pass (FIXME(62277): could be check-pass?) +#![feature(type_alias_impl_trait)] + +use std::fmt::Debug; + +fn main() {} + +type Two = impl Debug; + +fn two(t: T, u: U) -> Two { + (t, t) +} + +fn three(t: T, t2: T, u: U) -> Two { + (t, t2) +} + +fn four(t: T, t2: T, u: U, v: V) -> Two { + (t, t2) +} + +fn five(x: X, y: Y, y2: Y) -> Two { + (y, y2) +} diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.rs new file mode 100644 index 00000000000..777ded52609 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.rs @@ -0,0 +1,16 @@ +#![feature(type_alias_impl_trait)] + +use std::fmt::Debug; + +fn main() {} + +type Two = impl Debug; + +fn two(t: T, _: U) -> Two { + (t, 4u32) +} + +fn three(_: T, u: U) -> Two { +//~^ concrete type differs from previous + (u, 4u32) +} diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr new file mode 100644 index 00000000000..8f4cf4c6084 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr @@ -0,0 +1,19 @@ +error: concrete type differs from previous defining opaque type use + --> $DIR/generic_duplicate_param_use8.rs:13:1 + | +LL | / fn three(_: T, u: U) -> Two { +LL | | +LL | | (u, 4u32) +LL | | } + | |_^ expected `(T, u32)`, got `(U, u32)` + | +note: previous use here + --> $DIR/generic_duplicate_param_use8.rs:9:1 + | +LL | / fn two(t: T, _: U) -> Two { +LL | | (t, 4u32) +LL | | } + | |_^ + +error: aborting due to previous error + diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs new file mode 100644 index 00000000000..491e6647f45 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs @@ -0,0 +1,20 @@ +#![feature(type_alias_impl_trait)] + +use std::fmt::Debug; + +fn main() {} + +type Two = impl Debug; + +trait Foo { + type Bar: Debug; + const BAR: Self::Bar; +} + +fn two(t: T, u: U) -> Two { + (t, u, T::BAR) +} + +fn three(t: T, u: U) -> Two { + (t, u, 42) //~^ ERROR concrete type differs from previous +} diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr new file mode 100644 index 00000000000..4d0b03ba5ed --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr @@ -0,0 +1,18 @@ +error: concrete type differs from previous defining opaque type use + --> $DIR/generic_duplicate_param_use9.rs:18:1 + | +LL | / fn three(t: T, u: U) -> Two { +LL | | (t, u, 42) +LL | | } + | |_^ expected `(A, B, ::Bar)`, got `(A, B, i32)` + | +note: previous use here + --> $DIR/generic_duplicate_param_use9.rs:14:1 + | +LL | / fn two(t: T, u: U) -> Two { +LL | | (t, u, T::BAR) +LL | | } + | |_^ + +error: aborting due to previous error + diff --git a/src/test/ui/type-alias-impl-trait/generic_lifetime_param.rs b/src/test/ui/type-alias-impl-trait/generic_lifetime_param.rs new file mode 100644 index 00000000000..e109c38c986 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_lifetime_param.rs @@ -0,0 +1,11 @@ +// build-pass (FIXME(62277): could be check-pass?) + +#![feature(type_alias_impl_trait)] + +fn main() {} + +type Region<'a> = impl std::fmt::Debug; + +fn region<'b>(a: &'b ()) -> Region<'b> { + a +} diff --git a/src/test/ui/type-alias-impl-trait/generic_nondefining_use.rs b/src/test/ui/type-alias-impl-trait/generic_nondefining_use.rs new file mode 100644 index 00000000000..60106eba175 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_nondefining_use.rs @@ -0,0 +1,13 @@ +#![feature(type_alias_impl_trait)] + +fn main() {} + +type Cmp = impl 'static; +//~^ ERROR could not find defining uses +//~^^ ERROR: at least one trait must be specified + + +// not a defining use, because it doesn't define *all* possible generics +fn cmp() -> Cmp { //~ ERROR defining opaque type use does not fully define + 5u32 +} diff --git a/src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr b/src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr new file mode 100644 index 00000000000..d98d349be3c --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr @@ -0,0 +1,22 @@ +error: at least one trait must be specified + --> $DIR/generic_nondefining_use.rs:5:20 + | +LL | type Cmp = impl 'static; + | ^^^^^^^ + +error: defining opaque type use does not fully define opaque type + --> $DIR/generic_nondefining_use.rs:11:1 + | +LL | / fn cmp() -> Cmp { +LL | | 5u32 +LL | | } + | |_^ + +error: could not find defining uses + --> $DIR/generic_nondefining_use.rs:5:1 + | +LL | type Cmp = impl 'static; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/type-alias-impl-trait/generic_not_used.rs b/src/test/ui/type-alias-impl-trait/generic_not_used.rs new file mode 100644 index 00000000000..ace52dc83ad --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_not_used.rs @@ -0,0 +1,11 @@ +#![feature(type_alias_impl_trait)] + +fn main() {} + +type WrongGeneric = impl 'static; +//~^ ERROR: at least one trait must be specified + +fn wrong_generic(_: U, v: V) -> WrongGeneric { +//~^ ERROR type parameter `V` is part of concrete type but not used in parameter list + v +} diff --git a/src/test/ui/type-alias-impl-trait/generic_not_used.stderr b/src/test/ui/type-alias-impl-trait/generic_not_used.stderr new file mode 100644 index 00000000000..fe353f6e3d2 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_not_used.stderr @@ -0,0 +1,18 @@ +error: at least one trait must be specified + --> $DIR/generic_not_used.rs:5:38 + | +LL | type WrongGeneric = impl 'static; + | ^^^^^^^ + +error: type parameter `V` is part of concrete type but not used in parameter list for the `impl Trait` type alias + --> $DIR/generic_not_used.rs:8:73 + | +LL | fn wrong_generic(_: U, v: V) -> WrongGeneric { + | _________________________________________________________________________^ +LL | | +LL | | v +LL | | } + | |_^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr new file mode 100644 index 00000000000..f316644156d --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr @@ -0,0 +1,18 @@ +error: at least one trait must be specified + --> $DIR/generic_type_does_not_live_long_enough.rs:9:35 + | +LL | existential type WrongGeneric: 'static; + | ^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/generic_type_does_not_live_long_enough.rs:6:18 + | +LL | let z: i32 = x; + | ^ expected i32, found opaque type + | + = note: expected type `i32` + found type `WrongGeneric::<&{integer}>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs new file mode 100644 index 00000000000..c0f939a5048 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs @@ -0,0 +1,15 @@ +#![feature(type_alias_impl_trait)] + +fn main() { + let y = 42; + let x = wrong_generic(&y); + let z: i32 = x; //~ ERROR mismatched types +} + +type WrongGeneric = impl 'static; +//~^ ERROR the parameter type `T` may not live long enough +//~^^ ERROR: at least one trait must be specified + +fn wrong_generic(t: T) -> WrongGeneric { + t +} diff --git a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr new file mode 100644 index 00000000000..12569211df3 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr @@ -0,0 +1,34 @@ +error: at least one trait must be specified + --> $DIR/generic_type_does_not_live_long_enough.rs:9:29 + | +LL | type WrongGeneric = impl 'static; + | ^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/generic_type_does_not_live_long_enough.rs:6:18 + | +LL | let z: i32 = x; + | ^ expected i32, found opaque type + | + = note: expected type `i32` + found type `WrongGeneric::<&{integer}>` + +error[E0310]: the parameter type `T` may not live long enough + --> $DIR/generic_type_does_not_live_long_enough.rs:9:1 + | +LL | type WrongGeneric = impl 'static; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | fn wrong_generic(t: T) -> WrongGeneric { + | - help: consider adding an explicit lifetime bound `T: 'static`... + | +note: ...so that the type `T` will meet its required lifetime bounds + --> $DIR/generic_type_does_not_live_long_enough.rs:9:1 + | +LL | type WrongGeneric = impl 'static; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0308, E0310. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/type-alias-impl-trait/generic_underconstrained.rs b/src/test/ui/type-alias-impl-trait/generic_underconstrained.rs new file mode 100644 index 00000000000..589612d5ed6 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_underconstrained.rs @@ -0,0 +1,12 @@ +#![feature(type_alias_impl_trait)] + +fn main() {} + +trait Trait {} +type Underconstrained = impl 'static; //~ ERROR the trait bound `T: Trait` +//~^ ERROR: at least one trait must be specified + +// no `Trait` bound +fn underconstrain(_: T) -> Underconstrained { + unimplemented!() +} diff --git a/src/test/ui/type-alias-impl-trait/generic_underconstrained.stderr b/src/test/ui/type-alias-impl-trait/generic_underconstrained.stderr new file mode 100644 index 00000000000..dd90dd1b06f --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_underconstrained.stderr @@ -0,0 +1,18 @@ +error: at least one trait must be specified + --> $DIR/generic_underconstrained.rs:6:40 + | +LL | type Underconstrained = impl 'static; + | ^^^^^^^ + +error[E0277]: the trait bound `T: Trait` is not satisfied + --> $DIR/generic_underconstrained.rs:6:1 + | +LL | type Underconstrained = impl 'static; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` + | + = help: consider adding a `where T: Trait` bound + = note: the return type of a function must have a statically known size + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/generic_underconstrained2.rs b/src/test/ui/type-alias-impl-trait/generic_underconstrained2.rs new file mode 100644 index 00000000000..87b8aaad957 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_underconstrained2.rs @@ -0,0 +1,21 @@ +#![feature(type_alias_impl_trait)] + +fn main() {} + +type Underconstrained = impl 'static; +//~^ ERROR `U` doesn't implement `std::fmt::Debug` +//~^^ ERROR: at least one trait must be specified + +// not a defining use, because it doesn't define *all* possible generics +fn underconstrained(_: U) -> Underconstrained { + 5u32 +} + +type Underconstrained2 = impl 'static; +//~^ ERROR `V` doesn't implement `std::fmt::Debug` +//~^^ ERROR: at least one trait must be specified + +// not a defining use, because it doesn't define *all* possible generics +fn underconstrained2(_: U, _: V) -> Underconstrained2 { + 5u32 +} diff --git a/src/test/ui/type-alias-impl-trait/generic_underconstrained2.stderr b/src/test/ui/type-alias-impl-trait/generic_underconstrained2.stderr new file mode 100644 index 00000000000..574432bdcf6 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/generic_underconstrained2.stderr @@ -0,0 +1,35 @@ +error: at least one trait must be specified + --> $DIR/generic_underconstrained2.rs:5:50 + | +LL | type Underconstrained = impl 'static; + | ^^^^^^^ + +error: at least one trait must be specified + --> $DIR/generic_underconstrained2.rs:14:51 + | +LL | type Underconstrained2 = impl 'static; + | ^^^^^^^ + +error[E0277]: `U` doesn't implement `std::fmt::Debug` + --> $DIR/generic_underconstrained2.rs:5:1 + | +LL | type Underconstrained = impl 'static; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` + | + = help: the trait `std::fmt::Debug` is not implemented for `U` + = help: consider adding a `where U: std::fmt::Debug` bound + = note: the return type of a function must have a statically known size + +error[E0277]: `V` doesn't implement `std::fmt::Debug` + --> $DIR/generic_underconstrained2.rs:14:1 + | +LL | type Underconstrained2 = impl 'static; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `V` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug` + | + = help: the trait `std::fmt::Debug` is not implemented for `V` + = help: consider adding a `where V: std::fmt::Debug` bound + = note: the return type of a function must have a statically known size + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/issue-58887.rs b/src/test/ui/type-alias-impl-trait/issue-58887.rs new file mode 100644 index 00000000000..92ba50ae6cf --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-58887.rs @@ -0,0 +1,23 @@ +#![feature(type_alias_impl_trait)] + +trait UnwrapItemsExt { + type Iter; + fn unwrap_items(self) -> Self::Iter; +} + +impl UnwrapItemsExt for I +where + I: Iterator>, + E: std::fmt::Debug, +{ + type Iter = impl Iterator; + //~^ ERROR: could not find defining uses + + fn unwrap_items(self) -> Self::Iter { + //~^ ERROR: type parameter `T` is part of concrete type + //~| ERROR: type parameter `E` is part of concrete type + self.map(|x| x.unwrap()) + } +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/issue-58887.stderr b/src/test/ui/type-alias-impl-trait/issue-58887.stderr new file mode 100644 index 00000000000..7e2895711d3 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-58887.stderr @@ -0,0 +1,30 @@ +error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias + --> $DIR/issue-58887.rs:16:41 + | +LL | fn unwrap_items(self) -> Self::Iter { + | _________________________________________^ +LL | | +LL | | +LL | | self.map(|x| x.unwrap()) +LL | | } + | |_____^ + +error: type parameter `E` is part of concrete type but not used in parameter list for the `impl Trait` type alias + --> $DIR/issue-58887.rs:16:41 + | +LL | fn unwrap_items(self) -> Self::Iter { + | _________________________________________^ +LL | | +LL | | +LL | | self.map(|x| x.unwrap()) +LL | | } + | |_____^ + +error: could not find defining uses + --> $DIR/issue-58887.rs:13:5 + | +LL | type Iter = impl Iterator; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/type-alias-impl-trait/issue-60371.rs b/src/test/ui/type-alias-impl-trait/issue-60371.rs new file mode 100644 index 00000000000..50b9d1ac793 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-60371.rs @@ -0,0 +1,15 @@ +trait Bug { + type Item: Bug; + + const FUN: fn() -> Self::Item; +} + +impl Bug for &() { + type Item = impl Bug; //~ ERROR `impl Trait` in type aliases is unstable + //~^ ERROR the trait bound `(): Bug` is not satisfied + //~^^ ERROR could not find defining uses + + const FUN: fn() -> Self::Item = || (); +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/issue-60371.stderr b/src/test/ui/type-alias-impl-trait/issue-60371.stderr new file mode 100644 index 00000000000..1e9b12ebc39 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/issue-60371.stderr @@ -0,0 +1,29 @@ +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/issue-60371.rs:8:5 + | +LL | type Item = impl Bug; + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/63063 + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error[E0277]: the trait bound `(): Bug` is not satisfied + --> $DIR/issue-60371.rs:8:5 + | +LL | type Item = impl Bug; + | ^^^^^^^^^^^^^^^^^^^^^ the trait `Bug` is not implemented for `()` + | + = help: the following implementations were found: + <&() as Bug> + = note: the return type of a function must have a statically known size + +error: could not find defining uses + --> $DIR/issue-60371.rs:8:5 + | +LL | type Item = impl Bug; + | ^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0277, E0658. +For more information about an error, try `rustc --explain E0277`. diff --git a/src/test/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs b/src/test/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs new file mode 100644 index 00000000000..82c9ecd2ac6 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs @@ -0,0 +1,20 @@ +#![feature(type_alias_impl_trait)] +// build-pass (FIXME(62277): could be check-pass?) +mod my_mod { + use std::fmt::Debug; + + pub type Foo = impl Debug; + pub type Foot = impl Debug; + + pub fn get_foo() -> Foo { + 5i32 + } + + pub fn get_foot() -> Foot { + get_foo() + } +} + +fn main() { + let _: my_mod::Foot = my_mod::get_foot(); +} diff --git a/src/test/ui/type-alias-impl-trait/never_reveal_concrete_type.rs b/src/test/ui/type-alias-impl-trait/never_reveal_concrete_type.rs new file mode 100644 index 00000000000..8787c023eb0 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/never_reveal_concrete_type.rs @@ -0,0 +1,15 @@ +#![feature(type_alias_impl_trait)] + +fn main() {} + +// don't reveal the concrete type +type NoReveal = impl std::fmt::Debug; + +fn define_no_reveal() -> NoReveal { + "" +} + +fn no_reveal(x: NoReveal) { + let _: &'static str = x; //~ mismatched types + let _ = x as &'static str; //~ non-primitive cast +} diff --git a/src/test/ui/type-alias-impl-trait/never_reveal_concrete_type.stderr b/src/test/ui/type-alias-impl-trait/never_reveal_concrete_type.stderr new file mode 100644 index 00000000000..7c195f1fad0 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/never_reveal_concrete_type.stderr @@ -0,0 +1,21 @@ +error[E0308]: mismatched types + --> $DIR/never_reveal_concrete_type.rs:13:27 + | +LL | let _: &'static str = x; + | ^ expected reference, found opaque type + | + = note: expected type `&'static str` + found type `NoReveal` + +error[E0605]: non-primitive cast: `NoReveal` as `&'static str` + --> $DIR/never_reveal_concrete_type.rs:14:13 + | +LL | let _ = x as &'static str; + | ^^^^^^^^^^^^^^^^^ + | + = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0308, E0605. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs b/src/test/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs new file mode 100644 index 00000000000..f096dd162d5 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs @@ -0,0 +1,13 @@ +// Issue 52985: user code provides no use case that allows an existential type +// We now emit a 'could not find defining uses' error + +#![feature(type_alias_impl_trait)] + +type Foo = impl Copy; //~ could not find defining uses + +// make compiler happy about using 'Foo' +fn bar(x: Foo) -> Foo { x } + +fn main() { + let _: Foo = std::mem::transmute(0u8); +} diff --git a/src/test/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr b/src/test/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr new file mode 100644 index 00000000000..444e6e8214f --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr @@ -0,0 +1,8 @@ +error: could not find defining uses + --> $DIR/no_inferrable_concrete_type.rs:6:1 + | +LL | type Foo = impl Copy; + | ^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/type-alias-impl-trait/no_revealing_outside_defining_module.rs b/src/test/ui/type-alias-impl-trait/no_revealing_outside_defining_module.rs new file mode 100644 index 00000000000..61153b1e171 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/no_revealing_outside_defining_module.rs @@ -0,0 +1,24 @@ +#![feature(type_alias_impl_trait)] + +fn main() {} + +mod boo { + pub type Boo = impl ::std::fmt::Debug; + fn bomp() -> Boo { + "" + } +} + +// We don't actually know the type here. + +fn bomp2() { + let _: &str = bomp(); //~ ERROR mismatched types +} + +fn bomp() -> boo::Boo { + "" //~ ERROR mismatched types +} + +fn bomp_loop() -> boo::Boo { + loop {} +} diff --git a/src/test/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr b/src/test/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr new file mode 100644 index 00000000000..5e5826978fc --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr @@ -0,0 +1,23 @@ +error[E0308]: mismatched types + --> $DIR/no_revealing_outside_defining_module.rs:15:19 + | +LL | let _: &str = bomp(); + | ^^^^^^ expected &str, found opaque type + | + = note: expected type `&str` + found type `Boo` + +error[E0308]: mismatched types + --> $DIR/no_revealing_outside_defining_module.rs:19:5 + | +LL | fn bomp() -> boo::Boo { + | -------- expected `Boo` because of return type +LL | "" + | ^^ expected opaque type, found reference + | + = note: expected type `Boo` + found type `&'static str` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/type-alias-impl-trait/not_a_defining_use.rs b/src/test/ui/type-alias-impl-trait/not_a_defining_use.rs new file mode 100644 index 00000000000..ca00e582d34 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/not_a_defining_use.rs @@ -0,0 +1,40 @@ +#![feature(type_alias_impl_trait)] + +use std::fmt::Debug; + +fn main() {} + +type Two = impl Debug; + +fn two(t: T) -> Two { + //~^ ERROR defining opaque type use does not fully define opaque type + (t, 4i8) +} + +fn three(t: T) -> Two { + (t, 5i8) +} + +trait Bar { + type Blub: Debug; + const FOO: Self::Blub; +} + +impl Bar for u32 { + type Blub = i32; + const FOO: i32 = 42; +} + +// this should work! But it requires `two` and `three` not to be defining uses, +// just restricting uses +fn four(t: T) -> Two { //~ concrete type differs from previous + (t, ::FOO) +} + +fn is_sync() {} + +fn asdfl() { + //FIXME(oli-obk): these currently cause cycle errors + //is_sync::>(); + //is_sync::>(); +} diff --git a/src/test/ui/type-alias-impl-trait/not_a_defining_use.stderr b/src/test/ui/type-alias-impl-trait/not_a_defining_use.stderr new file mode 100644 index 00000000000..7bb8939ccf5 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/not_a_defining_use.stderr @@ -0,0 +1,27 @@ +error: defining opaque type use does not fully define opaque type + --> $DIR/not_a_defining_use.rs:9:1 + | +LL | / fn two(t: T) -> Two { +LL | | +LL | | (t, 4i8) +LL | | } + | |_^ + +error: concrete type differs from previous defining opaque type use + --> $DIR/not_a_defining_use.rs:30:1 + | +LL | / fn four(t: T) -> Two { +LL | | (t, ::FOO) +LL | | } + | |_^ expected `(T, i8)`, got `(T, ::Blub)` + | +note: previous use here + --> $DIR/not_a_defining_use.rs:14:1 + | +LL | / fn three(t: T) -> Two { +LL | | (t, 5i8) +LL | | } + | |_^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/type-alias-impl-trait/not_well_formed.rs b/src/test/ui/type-alias-impl-trait/not_well_formed.rs new file mode 100644 index 00000000000..36ec9b34ebd --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/not_well_formed.rs @@ -0,0 +1,18 @@ +#![feature(type_alias_impl_trait)] + +fn main() { +} + +trait TraitWithAssoc { + type Assoc; +} + +type Foo = impl Trait; //~ associated type `Assoc` not found for `V` + +trait Trait {} + +impl Trait for () {} + +fn foo_desugared(_: T) -> Foo { + () +} diff --git a/src/test/ui/type-alias-impl-trait/not_well_formed.stderr b/src/test/ui/type-alias-impl-trait/not_well_formed.stderr new file mode 100644 index 00000000000..d374d6d33ee --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/not_well_formed.stderr @@ -0,0 +1,9 @@ +error[E0220]: associated type `Assoc` not found for `V` + --> $DIR/not_well_formed.rs:10:26 + | +LL | type Foo = impl Trait; + | ^^^^^^^^ associated type `Assoc` not found + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0220`. diff --git a/src/test/ui/type-alias-impl-trait/private_unused.rs b/src/test/ui/type-alias-impl-trait/private_unused.rs new file mode 100644 index 00000000000..92268f1861d --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/private_unused.rs @@ -0,0 +1,13 @@ +// build-pass (FIXME(62277): could be check-pass?) + +#[deny(warnings)] + +enum Empty { } +trait Bar {} +impl Bar for () {} + +fn boo() -> impl Bar {} + +fn main() { + boo(); +} diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-const.rs b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-const.rs new file mode 100644 index 00000000000..0fd4d26ef60 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-const.rs @@ -0,0 +1,20 @@ +// check-pass + +#![feature(type_alias_impl_trait)] +// Currently, the `type_alias_impl_trait` feature implicitly +// depends on `impl_trait_in_bindings` in order to work properly. +// Specifically, this line requires `impl_trait_in_bindings` to be enabled: +// https://github.com/rust-lang/rust/blob/481068a707679257e2a738b40987246e0420e787/src/librustc_typeck/check/mod.rs#L856 +#![feature(impl_trait_in_bindings)] +//~^ WARN the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash + +// Ensures that `const` items can constrain an opaque `impl Trait`. + +use std::fmt::Debug; + +pub type Foo = impl Debug; + +const _FOO: Foo = 5; + +fn main() { +} diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-const.stderr b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-const.stderr new file mode 100644 index 00000000000..691de82c9d8 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-const.stderr @@ -0,0 +1,8 @@ +warning: the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash + --> $DIR/type-alias-impl-trait-const.rs:8:12 + | +LL | #![feature(impl_trait_in_bindings)] + | ^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs new file mode 100644 index 00000000000..a22b12cae6b --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs @@ -0,0 +1,27 @@ +// check-pass + +#![feature(type_alias_impl_trait)] + +// Regression test for issue #61863 + +pub trait MyTrait {} + +#[derive(Debug)] +pub struct MyStruct { + v: u64 +} + +impl MyTrait for MyStruct {} + +pub fn bla() -> TE { + return MyStruct {v:1} +} + +pub fn bla2() -> TE { + bla() +} + + +type TE = impl MyTrait; + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-tuple.rs b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-tuple.rs new file mode 100644 index 00000000000..86c9d482143 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-tuple.rs @@ -0,0 +1,33 @@ +// check-pass + +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +pub trait MyTrait {} + +impl MyTrait for bool {} + +struct Blah { + my_foo: Foo, + my_u8: u8 +} + +impl Blah { + fn new() -> Blah { + Blah { + my_foo: make_foo(), + my_u8: 12 + } + } + fn into_inner(self) -> (Foo, u8) { + (self.my_foo, self.my_u8) + } +} + +fn make_foo() -> Foo { + true +} + +type Foo = impl MyTrait; + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.rs b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.rs new file mode 100644 index 00000000000..c009952eab7 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.rs @@ -0,0 +1,12 @@ +#![feature(type_alias_impl_trait)] + +type Foo = impl Fn() -> Foo; +//~^ ERROR: could not find defining uses + +fn crash(x: Foo) -> Foo { + x +} + +fn main() { + +} diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.stderr b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.stderr new file mode 100644 index 00000000000..02ab3399ea6 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.stderr @@ -0,0 +1,8 @@ +error: could not find defining uses + --> $DIR/type-alias-impl-trait-with-cycle-error.rs:3:1 + | +LL | type Foo = impl Fn() -> Foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.rs b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.rs new file mode 100644 index 00000000000..32ecc366618 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.rs @@ -0,0 +1,16 @@ +#![feature(type_alias_impl_trait)] + +pub trait Bar { + type Item; +} + +type Foo = impl Bar; +//~^ ERROR: could not find defining uses + +fn crash(x: Foo) -> Foo { + x +} + +fn main() { + +} diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.stderr b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.stderr new file mode 100644 index 00000000000..e9abb795886 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.stderr @@ -0,0 +1,8 @@ +error: could not find defining uses + --> $DIR/type-alias-impl-trait-with-cycle-error2.rs:7:1 + | +LL | type Foo = impl Bar; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.rs b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.rs new file mode 100644 index 00000000000..8ca279eec92 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.rs @@ -0,0 +1,14 @@ +#![feature(type_alias_impl_trait)] + +type Foo = impl 'static; +//~^ ERROR: at least one trait must be specified + +fn foo() -> Foo { + "foo" +} + +fn bar() -> impl 'static { //~ ERROR: at least one trait must be specified + "foo" +} + +fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.stderr b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.stderr new file mode 100644 index 00000000000..58028bd0861 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.stderr @@ -0,0 +1,14 @@ +error: at least one trait must be specified + --> $DIR/type-alias-impl-trait-with-no-traits.rs:3:17 + | +LL | type Foo = impl 'static; + | ^^^^^^^ + +error: at least one trait must be specified + --> $DIR/type-alias-impl-trait-with-no-traits.rs:10:13 + | +LL | fn bar() -> impl 'static { + | ^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/type-alias-impl-trait/unused_generic_param.rs b/src/test/ui/type-alias-impl-trait/unused_generic_param.rs new file mode 100644 index 00000000000..a9ab727b193 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/unused_generic_param.rs @@ -0,0 +1,22 @@ +#![feature(type_alias_impl_trait)] + +fn main() { +} + +type PartiallyDefined = impl 'static; +//~^ ERROR: at least one trait must be specified + +fn partially_defined(_: T) -> PartiallyDefined { + 4u32 +} + +type PartiallyDefined2 = impl 'static; +//~^ ERROR: at least one trait must be specified + +fn partially_defined2(_: T) -> PartiallyDefined2 { + 4u32 +} + +fn partially_defined22(_: T) -> PartiallyDefined2 { + 4u32 +} diff --git a/src/test/ui/type-alias-impl-trait/unused_generic_param.stderr b/src/test/ui/type-alias-impl-trait/unused_generic_param.stderr new file mode 100644 index 00000000000..23105026964 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/unused_generic_param.stderr @@ -0,0 +1,14 @@ +error: at least one trait must be specified + --> $DIR/unused_generic_param.rs:6:33 + | +LL | type PartiallyDefined = impl 'static; + | ^^^^^^^ + +error: at least one trait must be specified + --> $DIR/unused_generic_param.rs:13:34 + | +LL | type PartiallyDefined2 = impl 'static; + | ^^^^^^^ + +error: aborting due to 2 previous errors + -- cgit 1.4.1-3-g733a5