From 21d8962d1f12988edf7a66e725a5b95362cda869 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 26 Feb 2025 09:01:44 +0000 Subject: [PATCH 1/6] Avoid a now-unnecessary generalization --- compiler/rustc_metadata/src/rmeta/encoder.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 88a88847e6b8..42975674b4fd 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -5,7 +5,6 @@ use std::io::{Read, Seek, Write}; use std::path::{Path, PathBuf}; use std::sync::Arc; -use rustc_ast::attr::AttributeExt; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::memmap::{Mmap, MmapMut}; use rustc_data_structures::sync::{join, par_for_each_in}; @@ -820,7 +819,7 @@ struct AnalyzeAttrState<'a> { /// visibility: this is a piece of data that can be computed once per defid, and not once per /// attribute. Some attributes would only be usable downstream if they are public. #[inline] -fn analyze_attr(attr: &impl AttributeExt, state: &mut AnalyzeAttrState<'_>) -> bool { +fn analyze_attr(attr: &hir::Attribute, state: &mut AnalyzeAttrState<'_>) -> bool { let mut should_encode = false; if !rustc_feature::encode_cross_crate(attr.name_or_empty()) { // Attributes not marked encode-cross-crate don't need to be encoded for downstream crates. From 23d4c37331e4c24c30cbbc0bf33c373a394c4008 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 26 Feb 2025 09:01:44 +0000 Subject: [PATCH 2/6] Add a method for deciding whether parsed attrs go into metadata --- .../src/attributes.rs | 19 +++++++++++++++++++ compiler/rustc_metadata/src/rmeta/encoder.rs | 4 +++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_attr_data_structures/src/attributes.rs b/compiler/rustc_attr_data_structures/src/attributes.rs index 9ac8de0227d7..e5411db84b63 100644 --- a/compiler/rustc_attr_data_structures/src/attributes.rs +++ b/compiler/rustc_attr_data_structures/src/attributes.rs @@ -195,3 +195,22 @@ pub enum AttributeKind { }, // tidy-alphabetical-end } + +impl AttributeKind { + pub fn encode_cross_crate(&self) -> bool { + match self { + AttributeKind::AllowConstFnUnstable(..) + | AttributeKind::AllowInternalUnstable(..) + | AttributeKind::BodyStability { .. } + | AttributeKind::Confusables { .. } + | AttributeKind::ConstStability { .. } + | AttributeKind::ConstStabilityIndirect + | AttributeKind::Deprecation { .. } + | AttributeKind::Diagnostic(..) + | AttributeKind::DocComment { .. } + | AttributeKind::MacroTransparency(..) + | AttributeKind::Repr(..) + | AttributeKind::Stability { .. } => true, + } + } +} diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 42975674b4fd..683ef1daf1dc 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -821,7 +821,9 @@ struct AnalyzeAttrState<'a> { #[inline] fn analyze_attr(attr: &hir::Attribute, state: &mut AnalyzeAttrState<'_>) -> bool { let mut should_encode = false; - if !rustc_feature::encode_cross_crate(attr.name_or_empty()) { + if let hir::Attribute::Parsed(p) = attr { + should_encode = p.encode_cross_crate(); + } else if !rustc_feature::encode_cross_crate(attr.name_or_empty()) { // Attributes not marked encode-cross-crate don't need to be encoded for downstream crates. } else if attr.doc_str().is_some() { // We keep all doc comments reachable to rustdoc because they might be "imported" into From 2df2fd9b5a2767114ab4be0a3c97e1b0529cacd4 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 26 Jul 2024 10:04:02 +0000 Subject: [PATCH 3/6] Implement `#[define_opaques]` attribute for functions. --- Cargo.lock | 1 + compiler/rustc_ast/src/ast.rs | 3 +- compiler/rustc_ast/src/mut_visit.rs | 14 +- compiler/rustc_ast/src/visit.rs | 15 ++- compiler/rustc_ast_lowering/src/item.rs | 40 +++++- compiler/rustc_ast_lowering/src/lib.rs | 16 ++- .../rustc_ast_passes/src/ast_validation.rs | 11 +- compiler/rustc_ast_pretty/src/pprust/state.rs | 11 +- .../rustc_ast_pretty/src/pprust/state/item.rs | 13 +- .../src/attributes.rs | 4 + .../rustc_attr_data_structures/src/lib.rs | 3 +- .../src/alloc_error_handler.rs | 1 + .../src/define_opaques.rs | 54 ++++++++ .../src/deriving/generic/mod.rs | 1 + .../src/global_allocator.rs | 1 + compiler/rustc_builtin_macros/src/lib.rs | 2 + .../rustc_builtin_macros/src/test_harness.rs | 1 + .../src/obligation_forest/mod.rs | 1 + compiler/rustc_error_messages/src/lib.rs | 1 + compiler/rustc_hir_analysis/messages.ftl | 3 - .../rustc_hir_analysis/src/check/check.rs | 20 +-- .../src/collect/type_of/opaque.rs | 80 +++-------- compiler/rustc_hir_analysis/src/errors.rs | 10 -- compiler/rustc_middle/src/mir/terminator.rs | 3 + compiler/rustc_middle/src/query/erase.rs | 2 + compiler/rustc_parse/src/parser/item.rs | 9 +- compiler/rustc_resolve/src/late.rs | 67 +++++++--- compiler/rustc_span/src/symbol.rs | 1 + .../error_reporting/infer/note_and_explain.rs | 10 +- compiler/rustc_ty_utils/Cargo.toml | 1 + compiler/rustc_ty_utils/src/opaque_types.rs | 121 +++++++---------- library/core/src/macros/mod.rs | 15 +++ library/core/src/prelude/v1.rs | 8 ++ library/std/src/backtrace.rs | 1 + library/std/src/prelude/v1.rs | 9 ++ src/librustdoc/html/render/span_map.rs | 2 +- .../clippy/clippy_utils/src/ast_utils/mod.rs | 6 + tests/crashes/120016.rs | 1 + tests/crashes/122904-2.rs | 2 + tests/crashes/122904.rs | 1 + tests/crashes/125185.rs | 14 +- tests/crashes/126680.rs | 22 +-- tests/crashes/131298.rs | 12 -- tests/crashes/131886.rs | 5 +- tests/crashes/135528.rs | 2 + ...onstrain_opaque_types_during_projection.rs | 3 +- .../issue-109299-1.stderr | 2 +- .../dont-imply-atb-in-closure-inference.rs | 6 +- tests/ui/associated-type-bounds/duplicate.rs | 6 + .../associated-type-bounds/duplicate.stderr | 126 ++++++++++++------ .../trait-alias-impl-trait.rs | 4 + tests/ui/async-await/async-fn/impl-trait.rs | 5 +- .../issues/issue-60655-latebound-regions.rs | 4 +- ...normalize-output-in-signature-deduction.rs | 1 + .../attributes/collapse-debuginfo-invalid.rs | 19 +-- .../collapse-debuginfo-invalid.stderr | 6 +- .../overwrite-anon-late-param-regions.rs | 1 + .../overwrite-anon-late-param-regions.stderr | 4 +- tests/ui/coherence/coherence-with-closure.rs | 1 + .../coherence/coherence-with-closure.stderr | 2 +- .../ui/coherence/coherence-with-coroutine.rs | 1 + .../coherence-with-coroutine.stock.stderr | 2 +- tests/ui/coherence/issue-99663-2.rs | 1 + tests/ui/coherence/issue-99663.rs | 1 + .../occurs-check/opaques.current.stderr | 6 +- .../occurs-check/opaques.next.stderr | 12 +- tests/ui/coherence/occurs-check/opaques.rs | 17 ++- .../orphan-check-opaque-types-not-covering.rs | 2 + ...han-check-opaque-types-not-covering.stderr | 4 +- .../generic_const_exprs/opaque_type.rs | 4 +- .../generic_const_exprs/opaque_type.stderr | 4 +- tests/ui/const-generics/opaque_types.rs | 3 +- tests/ui/const-generics/opaque_types.stderr | 110 +-------------- tests/ui/const-generics/opaque_types2.rs | 13 +- tests/ui/const-generics/opaque_types2.stderr | 6 +- .../const-eval/ice-unhandled-type-122191.rs | 14 +- .../ice-unhandled-type-122191.stderr | 33 +++-- .../const-promoted-opaque.atomic.stderr | 8 +- tests/ui/consts/const-promoted-opaque.rs | 30 +++-- .../const-promoted-opaque.string.stderr | 6 +- .../consts/const-promoted-opaque.unit.stderr | 24 ++++ .../collect-in-dead-fn-behind-opaque-type.rs | 1 + tests/ui/coroutine/layout-error.rs | 24 ++-- tests/ui/coroutine/layout-error.stderr | 6 +- .../metadata-sufficient-for-layout.rs | 1 + tests/ui/drop/drop_elaboration_with_errors.rs | 1 + .../drop/drop_elaboration_with_errors.stderr | 2 +- ...orted_main_const_fn_item_type_forbidden.rs | 6 +- ...d_main_const_fn_item_type_forbidden.stderr | 2 +- .../feature-gate-type_alias_impl_trait.rs | 9 +- tests/ui/fn/fn_def_opaque_coercion.rs | 5 + .../ui/fn/fn_def_opaque_coercion_to_fn_ptr.rs | 3 + .../fn_def_opaque_coercion_to_fn_ptr.stderr | 4 +- .../generic-associated-types/issue-87258_b.rs | 1 + .../issue-87258_b.stderr | 2 +- .../generic-associated-types/issue-88287.rs | 1 + .../issue-88287.stderr | 2 +- .../issue-90014-tait.stderr | 12 +- .../issue-90014-tait2.rs | 1 + .../issue-90014-tait2.stderr | 2 +- ...e-method-resolution-opaque-type.old.stderr | 4 +- ...rm-before-method-resolution-opaque-type.rs | 1 + .../tait-hidden-erased-unsoundness-2.rs | 7 +- .../tait-hidden-erased-unsoundness-2.stderr | 2 +- .../tait-hidden-erased-unsoundness.rs | 13 +- .../tait-hidden-erased-unsoundness.stderr | 15 ++- .../ui/impl-trait/associated-type-undefine.rs | 1 + .../associated-type-undefine.stderr | 16 ++- tests/ui/impl-trait/async_scope_creep.rs | 2 + tests/ui/impl-trait/auto-trait-coherence.rs | 1 + .../ui/impl-trait/auto-trait-coherence.stderr | 2 +- .../ui/impl-trait/bound-normalization-pass.rs | 1 + .../impl-trait/coherence-treats-tait-ambig.rs | 3 +- .../deduce-signature-from-supertrait.rs | 3 +- .../future-no-bound-vars-ice-112347.rs | 11 +- .../hidden-type-is-opaque-2.default.stderr | 2 +- .../hidden-type-is-opaque-2.next.stderr | 2 +- .../ui/impl-trait/hidden-type-is-opaque-2.rs | 1 + tests/ui/impl-trait/hidden-type-is-opaque.rs | 1 + ...bstituting-in-region-112823.current.stderr | 14 +- ...nsubstituting-in-region-112823.next.stderr | 18 ++- ...-type-whensubstituting-in-region-112823.rs | 1 + .../in-assoc-type-unconstrained.stderr | 2 +- tests/ui/impl-trait/in-assoc-type.stderr | 2 +- tests/ui/impl-trait/issue-108591.rs | 1 + tests/ui/impl-trait/issue-108592.rs | 11 +- tests/ui/impl-trait/issue-99642-2.rs | 3 +- tests/ui/impl-trait/issues/issue-53457.rs | 1 + tests/ui/impl-trait/issues/issue-70877.rs | 38 +++--- tests/ui/impl-trait/issues/issue-70877.stderr | 57 +++++++- tests/ui/impl-trait/issues/issue-74282.rs | 3 +- tests/ui/impl-trait/issues/issue-74282.stderr | 10 +- tests/ui/impl-trait/issues/issue-77987.rs | 13 +- tests/ui/impl-trait/issues/issue-78722-2.rs | 1 + .../ui/impl-trait/issues/issue-78722-2.stderr | 8 +- tests/ui/impl-trait/issues/issue-78722.rs | 1 + tests/ui/impl-trait/issues/issue-78722.stderr | 6 +- tests/ui/impl-trait/issues/issue-86201.rs | 7 +- tests/ui/impl-trait/issues/issue-86800.rs | 2 + tests/ui/impl-trait/issues/issue-86800.stderr | 10 +- tests/ui/impl-trait/issues/issue-89312.rs | 24 ++-- .../issues/issue-99348-impl-compatibility.rs | 1 + .../multiple-lifetimes/error-handling-2.rs | 1 + .../error-handling-2.stderr | 4 +- .../multiple-lifetimes/error-handling.rs | 1 + .../multiple-lifetimes/error-handling.stderr | 2 +- ...nds-pick-original-type-alias-impl-trait.rs | 1 + tests/ui/impl-trait/negative-reasoning.rs | 1 + tests/ui/impl-trait/negative-reasoning.stderr | 2 +- .../ui/impl-trait/nested-return-type2-tait.rs | 4 +- .../nested-return-type2-tait.stderr | 2 +- .../impl-trait/nested-return-type2-tait2.rs | 4 +- .../impl-trait/nested-return-type2-tait3.rs | 4 +- .../ui/impl-trait/nested-return-type3-tait.rs | 4 +- .../nested-return-type3-tait.stderr | 2 +- .../impl-trait/nested-return-type3-tait2.rs | 4 +- .../impl-trait/nested-return-type3-tait3.rs | 4 +- .../impl-trait/normalize-tait-in-const.stderr | 32 ++++- ...ias-impl-trait-declaration-too-subtle-2.rs | 10 +- ...alias-impl-trait-declaration-too-subtle.rs | 1 + ...s-impl-trait-declaration-too-subtle.stderr | 14 +- ...rsive-type-alias-impl-trait-declaration.rs | 1 + ...e-type-alias-impl-trait-declaration.stderr | 2 +- ...wo_tait_defining_each_other.current.stderr | 2 +- .../two_tait_defining_each_other.rs | 1 + ...o_tait_defining_each_other2.current.stderr | 4 +- .../two_tait_defining_each_other2.next.stderr | 2 +- .../two_tait_defining_each_other2.rs | 1 + ...o_tait_defining_each_other3.current.stderr | 2 +- .../two_tait_defining_each_other3.rs | 1 + .../type-alias-impl-trait-in-fn-body.rs | 1 + tests/ui/impl-trait/where-allowed.rs | 1 + tests/ui/impl-trait/where-allowed.stderr | 58 ++++---- tests/ui/implied-bounds/dyn-erasure-tait.rs | 1 + tests/ui/layout/debug.rs | 1 + tests/ui/layout/debug.stderr | 30 ++--- .../ui/lazy-type-alias-impl-trait/branches.rs | 2 + .../branches.stderr | 2 +- .../lazy-type-alias-impl-trait/branches2.rs | 13 +- .../lazy-type-alias-impl-trait/branches3.rs | 3 + .../branches3.stderr | 8 +- .../lazy-type-alias-impl-trait/recursion.rs | 5 +- .../lazy-type-alias-impl-trait/recursion2.rs | 3 +- .../lazy-type-alias-impl-trait/recursion3.rs | 5 +- .../recursion3.stderr | 4 +- .../lazy-type-alias-impl-trait/recursion4.rs | 1 + .../recursion4.stderr | 4 +- tests/ui/lint/issue-99387.rs | 1 + tests/ui/lint/issue-99387.stderr | 6 +- .../let_underscore/issue-119697-extra-let.rs | 2 +- .../issue-119697-extra-let.stderr | 4 +- tests/ui/lint/lint-ctypes-73249-2.rs | 1 + tests/ui/lint/lint-ctypes-73249-2.stderr | 2 +- tests/ui/lint/lint-ctypes-73249-3.rs | 1 + tests/ui/lint/lint-ctypes-73249-3.stderr | 2 +- tests/ui/lint/lint-ctypes-73249-5.rs | 1 + tests/ui/lint/lint-ctypes-73249-5.stderr | 2 +- tests/ui/lint/lint-ctypes-73251-1.rs | 1 + tests/ui/lint/lint-ctypes-73251-1.stderr | 2 +- tests/ui/lint/lint-ctypes-73251-2.rs | 2 + tests/ui/lint/lint-ctypes-73251-2.stderr | 2 +- tests/ui/lint/lint-ctypes-73251.rs | 1 + .../lint/opaque-ty-ffi-normalization-cycle.rs | 2 + .../opaque-ty-ffi-normalization-cycle.stderr | 2 +- tests/ui/lint/opaque-ty-ffi-unsafe.rs | 1 + tests/ui/lint/opaque-ty-ffi-unsafe.stderr | 2 +- tests/ui/methods/opaque_param_in_ufc.rs | 2 + tests/ui/mir/issue-75053.rs | 12 +- tests/ui/mir/issue-75053.stderr | 2 +- tests/ui/never_type/impl_trait_fallback2.rs | 2 + .../ui/never_type/impl_trait_fallback2.stderr | 2 +- tests/ui/never_type/impl_trait_fallback3.rs | 1 + .../ui/never_type/impl_trait_fallback3.stderr | 2 +- tests/ui/never_type/impl_trait_fallback4.rs | 1 + tests/ui/pattern/usefulness/impl-trait.rs | 6 + tests/ui/pattern/usefulness/impl-trait.stderr | 80 +++++------ ...private-in-public-type-alias-impl-trait.rs | 1 + .../higher-ranked-regions-basic.rs | 13 +- .../higher-ranked-regions-basic.stderr | 53 +++----- .../higher-ranked-regions-gat.rs | 7 +- .../higher-ranked-regions-gat.stderr | 6 +- tests/ui/self/arbitrary-self-opaque.rs | 1 + tests/ui/self/arbitrary-self-opaque.stderr | 4 +- .../min_specialization/impl-on-opaque.rs | 1 + .../min_specialization/impl-on-opaque2.rs | 1 + tests/ui/traits/alias/issue-83613.rs | 1 + tests/ui/traits/alias/issue-83613.stderr | 2 +- .../alias-relate/tait-eq-proj-2.rs | 3 +- .../next-solver/alias-relate/tait-eq-proj.rs | 3 +- .../opaques/dont-remap-tait-substs.rs | 3 +- ...e_of-tait-in-defining-scope.is_send.stderr | 2 +- ..._of-tait-in-defining-scope.not_send.stderr | 2 +- .../dont-type_of-tait-in-defining-scope.rs | 4 +- .../no-define-in-wf-check.current.stderr | 14 +- .../opaques/no-define-in-wf-check.rs | 4 + .../traits/pointee-tail-is-generic-errors.rs | 1 + .../pointee-tail-is-generic-errors.stderr | 8 +- tests/ui/traits/pointee-tail-is-generic.rs | 11 +- .../type-checking-test-opaques.rs | 1 + .../trait-upcasting/upcast-defining-opaque.rs | 1 + .../coherence-bikeshed-intrinsic-from.stderr | 2 +- .../type-alias-impl-trait/argument-types.rs | 19 ++- .../assoc-projection-ice.rs | 24 ++-- .../associated-type-alias-impl-trait.rs | 2 + .../auto-trait-leakage.rs | 11 +- .../auto-trait-leakage2.rs | 17 ++- .../auto-trait-leakage2.stderr | 18 +-- .../auto-trait-leakage3.rs | 4 +- .../auto-trait-leakage3.stderr | 22 --- .../auxiliary/cross_crate_ice.rs | 1 + .../auxiliary/drop-shim-relates-opaque-aux.rs | 1 + .../bad-tait-no-substs.rs | 2 +- .../bad-tait-no-substs.stderr | 16 +-- ...ariant-duplicate-lifetime-unconstrained.rs | 1 + .../type-alias-impl-trait/bound_reduction.rs | 1 + .../type-alias-impl-trait/bound_reduction2.rs | 2 +- .../bound_reduction2.stderr | 14 +- .../bounds-are-checked-2.rs | 12 +- .../bounds-are-checked-2.stderr | 22 +-- .../bounds-are-checked.rs | 1 + .../bounds-are-checked.stderr | 2 +- .../bounds-are-checked3.rs | 1 + tests/ui/type-alias-impl-trait/bounds.rs | 1 + .../closure-normalization-ice-109020.rs | 10 +- .../ui/type-alias-impl-trait/closure_args.rs | 24 ++-- .../ui/type-alias-impl-trait/closure_args2.rs | 34 +++-- .../ui/type-alias-impl-trait/closure_infer.rs | 2 + .../closure_parent_substs.rs | 3 + .../closure_wf_outlives.rs | 4 + .../closure_wf_outlives.stderr | 16 +-- .../closures_in_branches.rs | 3 +- .../closures_in_branches.stderr | 4 +- .../coherence.classic.stderr | 2 +- .../coherence.next.stderr | 2 +- tests/ui/type-alias-impl-trait/coherence.rs | 1 + .../coherence_cross_crate.rs | 1 + .../coherence_cross_crate.stderr | 2 +- .../coherence_different_hidden_ty.rs | 1 + .../coherence_generalization.rs | 1 + .../const_generic_type.infer.stderr | 2 +- .../const_generic_type.no_infer.stderr | 6 +- .../const_generic_type.rs | 1 + .../constrain_in_projection.current.stderr | 4 +- .../constrain_in_projection.rs | 3 +- .../constrain_in_projection2.current.stderr | 4 +- .../constrain_in_projection2.next.stderr | 2 +- .../constrain_in_projection2.rs | 3 +- .../type-alias-impl-trait/constrain_inputs.rs | 5 + .../constrain_inputs.stderr | 18 +-- .../constrain_inputs_unsound.rs | 5 +- .../constrain_inputs_unsound.stderr | 2 +- .../debug-ty-with-weak.rs | 10 +- .../declared_but_never_defined.stderr | 2 +- .../declared_but_not_defined_in_scope.stderr | 4 +- .../defined-by-user-annotation.rs | 3 + .../defined-in-closure-external-lifetime.rs | 2 + ...efined-in-closure-external-lifetime.stderr | 8 +- .../defining-use-submodule.rs | 11 ++ .../destructure_tait-ice-113594.rs | 1 + .../different_args_considered_equal.rs | 2 + .../different_args_considered_equal.stderr | 2 +- .../different_args_considered_equal2.rs | 1 + .../different_args_considered_equal2.stderr | 4 +- .../different_args_considered_equal3.rs | 10 +- .../different_args_considered_equal3.stderr | 2 +- .../different_defining_uses.rs | 2 + .../different_defining_uses.stderr | 4 +- .../different_defining_uses_never_type-2.rs | 1 + ...ifferent_defining_uses_never_type-2.stderr | 8 +- .../different_defining_uses_never_type-3.rs | 1 + ...ifferent_defining_uses_never_type-3.stderr | 4 +- .../different_defining_uses_never_type.rs | 3 + .../different_defining_uses_never_type.stderr | 4 +- .../different_defining_uses_never_type2.rs | 5 + .../different_defining_uses_never_type3.rs | 2 + ...different_defining_uses_never_type3.stderr | 4 +- .../different_lifetimes_defining_uses.rs | 2 + .../different_lifetimes_defining_uses.stderr | 4 +- .../drop-analysis-on-unconstrained-tait.rs | 36 ++--- ...drop-analysis-on-unconstrained-tait.stderr | 8 +- ...ate-lifetimes-from-rpit-containing-tait.rs | 1 + .../equal-lifetime-params-not-ok.rs | 5 +- .../equal-lifetime-params-not-ok.stderr | 25 +--- .../equal-lifetime-params-ok.rs | 2 + .../escaping-bound-var.rs | 1 + .../failed-to-normalize-ice-99945.rs | 2 + .../failed-to-normalize-ice-99945.stderr | 24 ++-- tests/ui/type-alias-impl-trait/fallback.rs | 5 +- .../ui/type-alias-impl-trait/fallback.stderr | 2 +- tests/ui/type-alias-impl-trait/field-types.rs | 4 + tests/ui/type-alias-impl-trait/future.rs | 1 + tests/ui/type-alias-impl-trait/future.stderr | 4 +- .../generic-not-strictly-equal.basic.stderr | 2 +- ...t-strictly-equal.member_constraints.stderr | 4 +- .../generic-not-strictly-equal.rs | 1 + .../generic_different_defining_uses.rs | 2 + .../generic_different_defining_uses.stderr | 4 +- .../generic_duplicate_lifetime_param.rs | 2 +- .../generic_duplicate_lifetime_param.stderr | 14 +- .../generic_duplicate_param_use.rs | 6 +- .../generic_duplicate_param_use.stderr | 38 +----- .../generic_duplicate_param_use10.rs | 1 + .../generic_duplicate_param_use2.rs | 1 + .../generic_duplicate_param_use2.stderr | 4 +- .../generic_duplicate_param_use3.rs | 2 + .../generic_duplicate_param_use3.stderr | 4 +- .../generic_duplicate_param_use4.rs | 1 + .../generic_duplicate_param_use4.stderr | 4 +- .../generic_duplicate_param_use5.rs | 2 + .../generic_duplicate_param_use5.stderr | 4 +- .../generic_duplicate_param_use6.rs | 2 + .../generic_duplicate_param_use6.stderr | 4 +- .../generic_duplicate_param_use7.rs | 4 + .../generic_duplicate_param_use8.rs | 2 + .../generic_duplicate_param_use8.stderr | 4 +- .../generic_duplicate_param_use9.rs | 2 + .../generic_duplicate_param_use9.stderr | 4 +- .../generic_lifetime_param.rs | 1 + .../generic_nondefining_use.rs | 6 +- .../generic_nondefining_use.stderr | 38 +----- .../type-alias-impl-trait/generic_not_used.rs | 1 + .../generic_not_used.stderr | 2 +- .../generic_type_does_not_live_long_enough.rs | 1 + ...eric_type_does_not_live_long_enough.stderr | 2 +- .../generic_underconstrained.rs | 1 + .../generic_underconstrained.stderr | 4 +- .../generic_underconstrained2.rs | 2 + .../generic_underconstrained2.stderr | 12 +- ...n_behind_projection_behind_struct_field.rs | 1 + ...hind_projection_behind_struct_field.stderr | 18 ++- .../hidden_behind_struct_field2.rs | 1 + .../hidden_behind_struct_field2.stderr | 18 ++- .../hidden_behind_struct_field3.rs | 1 + .../hidden_behind_struct_field3.stderr | 16 ++- .../hidden_type_mismatch.rs | 2 + .../hidden_type_mismatch.stderr | 10 +- .../higher_kinded_params.rs | 1 + .../higher_kinded_params2.rs | 2 + .../higher_kinded_params2.stderr | 16 ++- .../higher_kinded_params3.rs | 1 + .../higher_kinded_params3.stderr | 11 +- .../ui/type-alias-impl-trait/hkl_forbidden.rs | 5 + .../hkl_forbidden.stderr | 14 +- .../type-alias-impl-trait/hkl_forbidden2.rs | 1 + .../hkl_forbidden2.stderr | 2 +- .../type-alias-impl-trait/hkl_forbidden3.rs | 1 + .../hkl_forbidden3.stderr | 2 +- .../type-alias-impl-trait/hkl_forbidden4.rs | 1 + .../hkl_forbidden4.stderr | 30 ++--- ...e-failed-to-resolve-instance-for-110696.rs | 3 + ...iled-to-resolve-instance-for-110696.stderr | 4 +- ...mpl-trait-in-type-alias-with-bad-substs.rs | 1 + ...trait-in-type-alias-with-bad-substs.stderr | 10 +- .../impl_for_weak_alias.rs | 1 + .../impl_trait_for_generic_tait.rs | 1 + .../impl_trait_for_same_tait.rs | 2 + .../impl_trait_for_same_tait.stderr | 6 +- .../impl_trait_for_tait.rs | 1 + .../impl_trait_for_tait_bound.rs | 13 +- .../impl_trait_for_tait_bound.stderr | 6 +- .../impl_trait_for_tait_bound2.rs | 7 +- .../impl_trait_for_tait_bound2.stderr | 6 +- ...rait_in_trait_defined_outside_trait.stderr | 4 +- .../type-alias-impl-trait/implied_bounds.rs | 9 +- .../implied_bounds.stderr | 2 +- .../type-alias-impl-trait/implied_bounds2.rs | 10 +- .../implied_bounds_from_types.rs | 9 +- .../implied_bounds_from_types.stderr | 2 +- .../implied_lifetime_wf_check.error.stderr | 2 +- .../implied_lifetime_wf_check.rs | 1 + .../implied_lifetime_wf_check3.rs | 13 +- .../implied_lifetime_wf_check3.stderr | 8 +- .../implied_lifetime_wf_check4_static.rs | 14 +- .../implied_lifetime_wf_check4_static.stderr | 24 ++-- .../imply_bounds_from_bounds.rs | 20 ++- .../type-alias-impl-trait/in-where-clause.rs | 1 + .../in-where-clause.stderr | 6 +- .../incomplete-inference.rs | 2 + .../incomplete-inference.stderr | 2 +- .../type-alias-impl-trait/inference-cycle.rs | 28 ++-- .../inference-cycle.stderr | 22 --- .../infinite-cycle-involving-weak.rs | 5 +- .../invalid_impl_trait_in_assoc_ty.rs | 1 + .../invalid_impl_trait_in_assoc_ty.stderr | 18 ++- .../ui/type-alias-impl-trait/issue-101750.rs | 17 +-- .../ui/type-alias-impl-trait/issue-104817.rs | 1 + .../issue-104817.stock.stderr | 2 +- .../ui/type-alias-impl-trait/issue-109054.rs | 2 + .../type-alias-impl-trait/issue-109054.stderr | 4 +- .../issue-52843-closure-constrain.rs | 6 +- .../issue-52843-closure-constrain.stderr | 16 ++- tests/ui/type-alias-impl-trait/issue-52843.rs | 1 + .../type-alias-impl-trait/issue-52843.stderr | 4 +- .../ui/type-alias-impl-trait/issue-53092-2.rs | 7 +- .../issue-53092-2.stderr | 49 +++---- tests/ui/type-alias-impl-trait/issue-53092.rs | 11 +- .../type-alias-impl-trait/issue-53092.stderr | 16 +-- tests/ui/type-alias-impl-trait/issue-53096.rs | 10 +- .../type-alias-impl-trait/issue-53096.stderr | 2 +- .../issue-53678-coroutine-and-const-fn.rs | 19 ++- .../issue-55099-lifetime-inference.rs | 1 + tests/ui/type-alias-impl-trait/issue-57961.rs | 1 + .../issue-58662-coroutine-with-lifetime.rs | 2 + .../issue-58662-simplified.rs | 5 +- .../ui/type-alias-impl-trait/issue-58951-2.rs | 10 +- tests/ui/type-alias-impl-trait/issue-58951.rs | 11 +- tests/ui/type-alias-impl-trait/issue-60407.rs | 10 +- .../type-alias-impl-trait/issue-60407.stderr | 2 +- tests/ui/type-alias-impl-trait/issue-60564.rs | 2 +- .../type-alias-impl-trait/issue-60564.stderr | 14 +- .../issue-63263-closure-return.rs | 1 + tests/ui/type-alias-impl-trait/issue-63279.rs | 1 + .../type-alias-impl-trait/issue-63279.stderr | 12 +- tests/ui/type-alias-impl-trait/issue-63355.rs | 3 + .../type-alias-impl-trait/issue-63355.stderr | 4 +- .../issue-63677-type-alias-coherence.rs | 5 +- tests/ui/type-alias-impl-trait/issue-65384.rs | 3 +- ...sue-65679-inst-opaque-ty-from-val-twice.rs | 23 ++-- tests/ui/type-alias-impl-trait/issue-65918.rs | 12 +- .../issue-66580-closure-coherence.rs | 1 + .../issue-67844-nested-opaque.rs | 1 + .../issue-68368-non-defining-use-2.rs | 4 +- .../issue-68368-non-defining-use-2.stderr | 18 +-- .../issue-68368-non-defining-use.rs | 2 +- .../issue-68368-non-defining-use.stderr | 18 +-- ...ssue-69136-inner-lifetime-resolve-error.rs | 1 + .../issue-69136-inner-lifetime-resolve-ok.rs | 1 + tests/ui/type-alias-impl-trait/issue-69323.rs | 1 + tests/ui/type-alias-impl-trait/issue-70121.rs | 1 + .../type-alias-impl-trait/issue-70121.stderr | 6 +- tests/ui/type-alias-impl-trait/issue-72793.rs | 25 ++-- tests/ui/type-alias-impl-trait/issue-74244.rs | 1 + tests/ui/type-alias-impl-trait/issue-74280.rs | 1 + .../type-alias-impl-trait/issue-74280.stderr | 2 +- .../issue-76202-trait-impl-for-tait.rs | 29 ++-- tests/ui/type-alias-impl-trait/issue-77179.rs | 3 +- .../type-alias-impl-trait/issue-77179.stderr | 40 +++--- .../issue-84660-trait-impl-for-tait.rs | 1 + .../issue-84660-unsoundness.current.stderr | 4 +- .../issue-84660-unsoundness.next.stderr | 4 +- .../issue-84660-unsoundness.rs | 2 + tests/ui/type-alias-impl-trait/issue-89686.rs | 1 + .../type-alias-impl-trait/issue-89686.stderr | 2 +- tests/ui/type-alias-impl-trait/issue-93411.rs | 1 + .../issue-96572-unconstrained.rs | 3 + .../itiat-forbid-nested-items.stderr | 2 +- .../lazy_subtyping_of_opaques.rs | 1 + .../lazy_subtyping_of_opaques.stderr | 6 +- .../lifetime_mismatch.rs | 2 + .../lifetime_mismatch.stderr | 8 +- .../method_resolution.current.stderr | 2 +- .../method_resolution.next.stderr | 2 +- .../method_resolution.rs | 2 + .../method_resolution2.rs | 2 + .../method_resolution3.rs | 1 + .../method_resolution4.current.stderr | 4 +- .../method_resolution4.next.stderr | 4 +- .../method_resolution4.rs | 10 +- .../method_resolution5.rs | 8 +- ...on_trait_method_from_opaque.current.stderr | 2 +- ...ution_trait_method_from_opaque.next.stderr | 2 +- ...hod_resolution_trait_method_from_opaque.rs | 2 + .../missing_lifetime_bound.rs | 1 + .../missing_lifetime_bound.stderr | 6 +- .../multiple-def-uses-in-one-fn-infer.rs | 1 + .../multiple-def-uses-in-one-fn-infer.stderr | 2 +- .../multiple-def-uses-in-one-fn-lifetimes.rs | 1 + ...ltiple-def-uses-in-one-fn-lifetimes.stderr | 4 +- .../multiple-def-uses-in-one-fn-pass.rs | 2 + .../multiple-def-uses-in-one-fn.rs | 1 + .../multiple-def-uses-in-one-fn.stderr | 2 +- .../multiple-def-uses-in-one-fn2.rs | 1 + .../multiple-def-uses-in-one-fn2.stderr | 2 +- .../multiple-def-uses-in-one-fn3.rs | 2 + .../multiple-def-uses-in-one-fn3.stderr | 2 +- .../nested-impl-trait-in-tait.stderr | 4 +- .../nested-in-anon-const.stderr | 2 +- .../type-alias-impl-trait/nested-tait-hrtb.rs | 2 + .../nested-tait-hrtb.stderr | 7 +- .../nested-tait-inference.current.stderr | 2 +- .../nested-tait-inference.rs | 1 + .../nested-tait-inference2.current.stderr | 2 +- .../nested-tait-inference2.next.stderr | 2 +- .../nested-tait-inference2.rs | 1 + .../nested-tait-inference3.rs | 1 + .../nested-tait-inference3.stderr | 2 +- tests/ui/type-alias-impl-trait/nested.rs | 1 + tests/ui/type-alias-impl-trait/nested.stderr | 4 +- .../nested_inference_failure.rs | 1 + .../nested_type_alias_impl_trait.rs | 24 ++-- .../nested_type_alias_impl_trait.stderr | 30 ++--- .../never_reveal_concrete_type.rs | 2 + .../no_inferrable_concrete_type.rs | 15 +-- .../no_inferrable_concrete_type.stderr | 12 +- .../no_revealing_outside_defining_module.rs | 13 +- ...o_revealing_outside_defining_module.stderr | 26 ++-- .../normalize-alias-type.rs | 15 +-- .../normalize-hidden-types.current.stderr | 14 +- .../normalize-hidden-types.rs | 5 + .../not-matching-trait-refs-isnt-defining.rs | 1 + ...t-matching-trait-refs-isnt-defining.stderr | 16 ++- .../not_a_defining_use.rs | 2 + .../not_a_defining_use.stderr | 4 +- .../type-alias-impl-trait/not_well_formed.rs | 1 + .../type-alias-impl-trait/obligation_ice.rs | 1 + .../outlives-bound-var.rs | 8 +- .../type-alias-impl-trait/param_mismatch.rs | 1 + .../param_mismatch.stderr | 2 +- .../type-alias-impl-trait/param_mismatch2.rs | 1 + .../param_mismatch2.stderr | 2 +- .../type-alias-impl-trait/param_mismatch3.rs | 2 + .../param_mismatch3.stderr | 4 +- .../type-alias-impl-trait/param_mismatch4.rs | 1 + .../param_mismatch4.stderr | 2 +- .../path_resolution_taint.rs | 16 +++ .../path_resolution_taint.stderr | 9 ++ tests/ui/type-alias-impl-trait/privacy.rs | 1 + tests/ui/type-alias-impl-trait/privacy.stderr | 2 +- .../recursive-fn-tait.rs | 2 + .../recursive-fn-tait.stderr | 6 +- .../recursive-tait-conflicting-defn-2.rs | 6 +- .../recursive-tait-conflicting-defn-2.stderr | 8 +- .../recursive-tait-conflicting-defn.rs | 25 ++-- .../recursive-tait-conflicting-defn.stderr | 12 +- .../ui/type-alias-impl-trait/reveal_local.rs | 7 +- .../type-alias-impl-trait/reveal_local.stderr | 22 +-- .../rpit_tait_equality_in_canonical_query.rs | 15 +-- ...rpit_tait_equality_in_canonical_query_2.rs | 12 +- .../self-referential-2.current.stderr | 2 +- .../self-referential-2.rs | 1 + .../self-referential-3.rs | 1 + .../self-referential-3.stderr | 2 +- .../self-referential-4.rs | 3 + .../self-referential-4.stderr | 6 +- .../type-alias-impl-trait/self-referential.rs | 3 + .../self-referential.stderr | 6 +- .../type-alias-impl-trait/self_implication.rs | 9 +- .../static-const-types.rs | 13 -- .../structural-match-no-leak.rs | 16 +-- .../structural-match-no-leak.stderr | 4 +- .../type-alias-impl-trait/structural-match.rs | 17 ++- .../structural-match.stderr | 4 +- tests/ui/type-alias-impl-trait/taint.rs | 1 + tests/ui/type-alias-impl-trait/taint.stderr | 2 +- ...function-return-type-issue-101903-fixed.rs | 1 + .../tait-param-inference-issue-117310.rs | 2 + .../type-alias-impl-trait-assoc-dyn.rs | 1 + .../type-alias-impl-trait-assoc-impl-trait.rs | 2 + .../type-alias-impl-trait-const.rs | 12 +- .../type-alias-impl-trait-const.stderr | 57 ++++++++ .../type-alias-impl-trait-fns.rs | 2 + .../type-alias-impl-trait-fns.stderr | 4 +- .../type-alias-impl-trait-sized.rs | 4 + .../type-alias-impl-trait-struct.rs | 1 + .../type-alias-impl-trait-tuple.rs | 15 +-- ...alias-impl-trait-with-cycle-error-1.stderr | 11 +- ...alias-impl-trait-with-cycle-error-2.stderr | 11 +- ...alias-impl-trait-with-cycle-error-3.stderr | 11 +- .../type-alias-impl-trait-with-no-traits.rs | 1 + ...ype-alias-impl-trait-with-no-traits.stderr | 2 +- .../type-alias-impl-trait.rs | 20 ++- .../type-alias-impl-trait2.rs | 105 ++++++++------- .../type-alias-nested-impl-trait.rs | 1 + .../type_of_a_let.current.stderr | 4 +- .../ui/type-alias-impl-trait/type_of_a_let.rs | 2 + .../unbounded_opaque_type.rs | 9 +- .../unconstrained-due-to-bad-pattern.rs | 1 + .../unconstrained-due-to-bad-pattern.stderr | 2 +- .../unconstrained-impl-param.rs | 1 + .../unconstrained-impl-param.stderr | 2 +- .../ui/type-alias-impl-trait/under-binder.rs | 1 + .../type-alias-impl-trait/under-binder.stderr | 2 +- .../underconstrained_generic.rs | 5 +- .../underconstrained_generic.stderr | 4 +- .../underconstrained_lifetime.rs | 1 + .../underconstrained_lifetime.stderr | 2 +- .../underef-index-out-of-bounds-121472.rs | 1 + .../underef-index-out-of-bounds-121472.stderr | 14 +- .../type-alias-impl-trait/unnameable_type.rs | 1 + .../unnameable_type.stderr | 4 +- .../unused_generic_param.rs | 3 + tests/ui/type-alias-impl-trait/variance.rs | 1 + .../ui/type-alias-impl-trait/variance.stderr | 10 +- .../weird-return-types.rs | 3 +- .../wf-check-definition-site.rs | 6 +- .../type-alias-impl-trait/wf-check-fn-def.rs | 5 +- .../wf-check-fn-def.stderr | 6 +- .../type-alias-impl-trait/wf-check-fn-ptrs.rs | 5 +- tests/ui/type-alias-impl-trait/wf-nested.rs | 3 +- .../ui/type-alias-impl-trait/wf-nested.stderr | 2 +- .../wf_check_closures.rs | 3 +- .../wf_check_closures.stderr | 8 +- .../ui/typeck/typeck_type_placeholder_item.rs | 1 + .../typeck_type_placeholder_item.stderr | 42 +++--- 634 files changed, 2594 insertions(+), 2101 deletions(-) create mode 100644 compiler/rustc_builtin_macros/src/define_opaques.rs delete mode 100644 tests/crashes/131298.rs create mode 100644 tests/ui/consts/const-promoted-opaque.unit.stderr delete mode 100644 tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr delete mode 100644 tests/ui/type-alias-impl-trait/inference-cycle.stderr create mode 100644 tests/ui/type-alias-impl-trait/path_resolution_taint.rs create mode 100644 tests/ui/type-alias-impl-trait/path_resolution_taint.stderr delete mode 100644 tests/ui/type-alias-impl-trait/static-const-types.rs create mode 100644 tests/ui/type-alias-impl-trait/type-alias-impl-trait-const.stderr diff --git a/Cargo.lock b/Cargo.lock index fb4cf235c6f4..c43811bd8501 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4513,6 +4513,7 @@ version = "0.0.0" dependencies = [ "itertools", "rustc_abi", + "rustc_attr_parsing", "rustc_data_structures", "rustc_errors", "rustc_fluent_macro", diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 29c1d34a125a..2fc7b85d081e 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -3381,6 +3381,7 @@ pub struct Fn { pub generics: Generics, pub sig: FnSig, pub contract: Option>, + pub define_opaques: Option>, pub body: Option>, } @@ -3678,7 +3679,7 @@ mod size_asserts { static_assert_size!(Block, 32); static_assert_size!(Expr, 72); static_assert_size!(ExprKind, 40); - static_assert_size!(Fn, 168); + static_assert_size!(Fn, 176); static_assert_size!(ForeignItem, 88); static_assert_size!(ForeignItemKind, 16); static_assert_size!(GenericArg, 24); diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 40b29fdba250..04dc43cfec8a 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -978,7 +978,14 @@ fn walk_fn(vis: &mut T, kind: FnKind<'_>) { _ctxt, _ident, _vis, - Fn { defaultness, generics, contract, body, sig: FnSig { header, decl, span } }, + Fn { + defaultness, + generics, + contract, + body, + sig: FnSig { header, decl, span }, + define_opaques, + }, ) => { // Identifier and visibility are visited as a part of the item. visit_defaultness(vis, defaultness); @@ -992,6 +999,11 @@ fn walk_fn(vis: &mut T, kind: FnKind<'_>) { vis.visit_block(body); } vis.visit_span(span); + + for (id, path) in define_opaques.iter_mut().flatten() { + vis.visit_id(id); + vis.visit_path(path) + } } FnKind::Closure(binder, coroutine_kind, decl, body) => { vis.visit_closure_binder(binder); diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 1cb32b56875c..67734f60e0e2 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -802,6 +802,7 @@ pub fn walk_generics<'a, V: Visitor<'a>>(visitor: &mut V, generics: &'a Generics let WhereClause { has_where_token: _, predicates, span: _ } = where_clause; walk_list!(visitor, visit_generic_param, params); walk_list!(visitor, visit_where_predicate, predicates); + V::Result::output() } @@ -891,7 +892,14 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Resu _ctxt, _ident, _vis, - Fn { defaultness: _, sig: FnSig { header, decl, span: _ }, generics, contract, body }, + Fn { + defaultness: _, + sig: FnSig { header, decl, span: _ }, + generics, + contract, + body, + define_opaques, + }, ) => { // Identifier and visibility are visited as a part of the item. try_visit!(visitor.visit_fn_header(header)); @@ -899,6 +907,9 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>) -> V::Resu try_visit!(visitor.visit_fn_decl(decl)); visit_opt!(visitor, visit_contract, contract); visit_opt!(visitor, visit_block, body); + for (id, path) in define_opaques.iter().flatten() { + try_visit!(visitor.visit_path(path, *id)) + } } FnKind::Closure(binder, coroutine_kind, decl, body) => { try_visit!(visitor.visit_closure_binder(binder)); @@ -1202,7 +1213,7 @@ pub fn walk_expr<'a, V: Visitor<'a>>(visitor: &mut V, expression: &'a Expr) -> V FnKind::Closure(binder, coroutine_kind, fn_decl, body), *span, *id - )) + )); } ExprKind::Block(block, opt_label) => { visit_opt!(visitor, visit_label, opt_label); diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index a4fc4b3e3a12..d14784a49c95 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -2,6 +2,7 @@ use rustc_abi::ExternAbi; use rustc_ast::ptr::P; use rustc_ast::visit::AssocCtxt; use rustc_ast::*; +use rustc_attr_parsing::AttributeKind; use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; use rustc_hir::PredicateOrigin; @@ -158,7 +159,11 @@ impl<'hir> LoweringContext<'_, 'hir> { let mut ident = i.ident; let vis_span = self.lower_span(i.vis.span); let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id); - let attrs = self.lower_attrs(hir_id, &i.attrs, i.span); + let define_opaques = match &i.kind { + ItemKind::Fn(f) => self.lower_define_opaques(&f.define_opaques), + _ => None, + }; + let attrs = self.lower_attrs_with_extra(hir_id, &i.attrs, i.span, define_opaques); let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, vis_span, &i.kind); let item = hir::Item { owner_id: hir_id.expect_owner(), @@ -760,7 +765,12 @@ impl<'hir> LoweringContext<'_, 'hir> { fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> { let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id); - let attrs = self.lower_attrs(hir_id, &i.attrs, i.span); + let define_opaques = match &i.kind { + AssocItemKind::Fn(f) => self.lower_define_opaques(&f.define_opaques), + _ => None, + }; + let attrs = self.lower_attrs_with_extra(hir_id, &i.attrs, i.span, define_opaques); + let trait_item_def_id = hir_id.expect_owner(); let (generics, kind, has_default) = match &i.kind { @@ -896,7 +906,11 @@ impl<'hir> LoweringContext<'_, 'hir> { let has_value = true; let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value); let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id); - let attrs = self.lower_attrs(hir_id, &i.attrs, i.span); + let define_opaques = match &i.kind { + AssocItemKind::Fn(f) => self.lower_define_opaques(&f.define_opaques), + _ => None, + }; + let attrs = self.lower_attrs_with_extra(hir_id, &i.attrs, i.span, define_opaques); let (generics, kind) = match &i.kind { AssocItemKind::Const(box ConstItem { generics, ty, expr, .. }) => self.lower_generics( @@ -1657,6 +1671,26 @@ impl<'hir> LoweringContext<'_, 'hir> { (lowered_generics, res) } + pub(super) fn lower_define_opaques( + &mut self, + define_opaques: &Option>, + ) -> Option { + let define_opaques = define_opaques.as_ref()?; + let define_opaques = define_opaques + .iter() + // TODO: error reporting for non-local items being mentioned and tests that go through these code paths + .map(|(id, _path)| { + self.resolver + .get_partial_res(*id) + .unwrap() + .expect_full_res() + .def_id() + .expect_local() + }) + .collect(); + Some(hir::Attribute::Parsed(AttributeKind::DefineOpaques(define_opaques))) + } + pub(super) fn lower_generic_bound_predicate( &mut self, ident: Ident, diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 1c69937eed07..51b4c1793a60 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -35,6 +35,7 @@ #![doc(rust_logo)] #![feature(assert_matches)] #![feature(box_patterns)] +#![feature(exact_size_is_empty)] #![feature(if_let_guard)] #![feature(let_chains)] #![feature(rustdoc_internals)] @@ -867,13 +868,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { attrs: &[Attribute], target_span: Span, ) -> &'hir [hir::Attribute] { - if attrs.is_empty() { + self.lower_attrs_with_extra(id, attrs, target_span, std::iter::empty()) + } + + fn lower_attrs_with_extra( + &mut self, + id: HirId, + attrs: &[Attribute], + target_span: Span, + extra: impl IntoIterator, + ) -> &'hir [hir::Attribute] { + let extra = extra.into_iter(); + if attrs.is_empty() && extra.is_empty() { &[] } else { let lowered_attrs = self.lower_attrs_vec(attrs, self.lower_span(target_span)); debug_assert_eq!(id.owner, self.current_hir_id_owner); - let ret = self.arena.alloc_from_iter(lowered_attrs); + let ret = self.arena.alloc_from_iter(lowered_attrs.into_iter().chain(extra)); // this is possible if an item contained syntactical attribute, // but none of them parse succesfully or all of them were ignored diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index f9f4035cb22f..1f7c91d10cbe 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -917,7 +917,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> { walk_list!(self, visit_attribute, &item.attrs); return; // Avoid visiting again. } - ItemKind::Fn(func @ box Fn { defaultness, generics: _, sig, contract: _, body }) => { + ItemKind::Fn( + func @ box Fn { + defaultness, + generics: _, + sig, + contract: _, + body, + define_opaques: _, + }, + ) => { self.check_defaultness(item.span, *defaultness); let is_intrinsic = diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 44e956dc37f3..af7a6cab30d5 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -26,7 +26,6 @@ use rustc_span::edition::Edition; use rustc_span::source_map::{SourceMap, Spanned}; use rustc_span::symbol::IdentPrinter; use rustc_span::{BytePos, CharPos, DUMMY_SP, FileName, Ident, Pos, Span, Symbol, kw, sym}; -use thin_vec::ThinVec; use crate::pp::Breaks::{Consistent, Inconsistent}; use crate::pp::{self, Breaks}; @@ -1970,15 +1969,7 @@ impl<'a> State<'a> { ) { self.ibox(INDENT_UNIT); self.print_formal_generic_params(generic_params); - let generics = ast::Generics { - params: ThinVec::new(), - where_clause: ast::WhereClause { - has_where_token: false, - predicates: ThinVec::new(), - span: DUMMY_SP, - }, - span: DUMMY_SP, - }; + let generics = ast::Generics::default(); let header = ast::FnHeader { safety, ext, ..ast::FnHeader::default() }; self.print_fn(decl, header, name, &generics); self.end(); diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs index c10b5ad34e10..4b6c8f3dfc3d 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs @@ -650,7 +650,16 @@ impl<'a> State<'a> { attrs: &[ast::Attribute], func: &ast::Fn, ) { - let ast::Fn { defaultness, generics, sig, contract, body } = func; + let ast::Fn { defaultness, generics, sig, contract, body, define_opaques } = func; + + if let Some(define_opaques) = define_opaques { + for (_, path) in define_opaques { + self.word("define opaques from "); + self.print_path(path, false, 0); + self.word(","); + } + } + if body.is_some() { self.head(""); } @@ -698,7 +707,7 @@ impl<'a> State<'a> { } self.print_generic_params(&generics.params); self.print_fn_params_and_ret(decl, false); - self.print_where_clause(&generics.where_clause) + self.print_where_clause(&generics.where_clause); } pub(crate) fn print_fn_params_and_ret(&mut self, decl: &ast::FnDecl, is_closure: bool) { diff --git a/compiler/rustc_attr_data_structures/src/attributes.rs b/compiler/rustc_attr_data_structures/src/attributes.rs index e5411db84b63..cf5024ceeda8 100644 --- a/compiler/rustc_attr_data_structures/src/attributes.rs +++ b/compiler/rustc_attr_data_structures/src/attributes.rs @@ -2,6 +2,7 @@ use rustc_abi::Align; use rustc_ast::token::CommentKind; use rustc_ast::{self as ast, AttrStyle}; use rustc_macros::{Decodable, Encodable, HashStable_Generic, PrintAttribute}; +use rustc_span::def_id::LocalDefId; use rustc_span::hygiene::Transparency; use rustc_span::{Span, Symbol}; use thin_vec::ThinVec; @@ -175,6 +176,8 @@ pub enum AttributeKind { span: Span, }, ConstStabilityIndirect, + /// List of type aliases that contain the opaque types that can be defined by the current item. + DefineOpaques(ThinVec), Deprecation { deprecation: Deprecation, span: Span, @@ -199,6 +202,7 @@ pub enum AttributeKind { impl AttributeKind { pub fn encode_cross_crate(&self) -> bool { match self { + AttributeKind::DefineOpaques(..) => false, AttributeKind::AllowConstFnUnstable(..) | AttributeKind::AllowInternalUnstable(..) | AttributeKind::BodyStability { .. } diff --git a/compiler/rustc_attr_data_structures/src/lib.rs b/compiler/rustc_attr_data_structures/src/lib.rs index e4bb459e6df5..b48fab365698 100644 --- a/compiler/rustc_attr_data_structures/src/lib.rs +++ b/compiler/rustc_attr_data_structures/src/lib.rs @@ -17,6 +17,7 @@ use rustc_abi::Align; use rustc_ast::token::CommentKind; use rustc_ast::{AttrStyle, IntTy, UintTy}; use rustc_ast_pretty::pp::Printer; +use rustc_span::def_id::LocalDefId; use rustc_span::hygiene::Transparency; use rustc_span::{Span, Symbol}; pub use stability::*; @@ -148,4 +149,4 @@ macro_rules! print_tup { print_tup!(A B C D E F G H); print_skip!(Span, ()); print_disp!(Symbol, u16, bool, NonZero); -print_debug!(UintTy, IntTy, Align, AttrStyle, CommentKind, Transparency); +print_debug!(UintTy, IntTy, Align, AttrStyle, CommentKind, Transparency, LocalDefId); diff --git a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs index 78bf2195975d..96b873ff86d9 100644 --- a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs +++ b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs @@ -88,6 +88,7 @@ fn generate_handler(cx: &ExtCtxt<'_>, handler: Ident, span: Span, sig_span: Span generics: Generics::default(), contract: None, body, + define_opaques: None, })); let attrs = thin_vec![cx.attr_word(sym::rustc_std_internal_symbol, span)]; diff --git a/compiler/rustc_builtin_macros/src/define_opaques.rs b/compiler/rustc_builtin_macros/src/define_opaques.rs new file mode 100644 index 000000000000..811c22da1ecf --- /dev/null +++ b/compiler/rustc_builtin_macros/src/define_opaques.rs @@ -0,0 +1,54 @@ +use rustc_ast::{DUMMY_NODE_ID, ast}; +use rustc_expand::base::{Annotatable, ExtCtxt}; +use rustc_span::Span; + +pub(crate) fn expand( + ecx: &mut ExtCtxt<'_>, + _expand_span: Span, + meta_item: &ast::MetaItem, + mut item: Annotatable, +) -> Vec { + let define_opaques = match &mut item { + Annotatable::Item(p) => match &mut p.kind { + ast::ItemKind::Fn(f) => Some(&mut f.define_opaques), + _ => None, + }, + Annotatable::AssocItem(i, _assoc_ctxt) => match &mut i.kind { + ast::AssocItemKind::Fn(func) => Some(&mut func.define_opaques), + _ => None, + }, + Annotatable::Stmt(s) => match &mut s.kind { + ast::StmtKind::Item(p) => match &mut p.kind { + ast::ItemKind::Fn(f) => Some(&mut f.define_opaques), + _ => None, + }, + _ => None, + }, + _ => None, + }; + + let Some(list) = meta_item.meta_item_list() else { + ecx.dcx().span_err(meta_item.span, "expected list of type aliases"); + return vec![item]; + }; + + if let Some(define_opaques) = define_opaques { + *define_opaques = Some( + list.iter() + .filter_map(|entry| match entry { + ast::MetaItemInner::MetaItem(meta_item) if meta_item.is_word() => { + Some((DUMMY_NODE_ID, meta_item.path.clone())) + } + _ => { + ecx.dcx().span_err(entry.span(), "expected path to type alias"); + None + } + }) + .collect(), + ); + } else { + ecx.dcx().span_err(meta_item.span, "only functions and methods can define opaque types"); + } + + vec![item] +} diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index 6b59ac258275..c3b5f6220dad 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -1033,6 +1033,7 @@ impl<'a> MethodDef<'a> { generics: fn_generics, contract: None, body: Some(body_block), + define_opaques: None, })), tokens: None, }) diff --git a/compiler/rustc_builtin_macros/src/global_allocator.rs b/compiler/rustc_builtin_macros/src/global_allocator.rs index 8fdbbf8e704a..dfc3c95f83e2 100644 --- a/compiler/rustc_builtin_macros/src/global_allocator.rs +++ b/compiler/rustc_builtin_macros/src/global_allocator.rs @@ -83,6 +83,7 @@ impl AllocFnFactory<'_, '_> { generics: Generics::default(), contract: None, body, + define_opaques: None, })); let item = self.cx.item( self.span, diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index ca16583a45de..fe7dad6fedad 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -39,6 +39,7 @@ mod compile_error; mod concat; mod concat_bytes; mod concat_idents; +mod define_opaques; mod derive; mod deriving; mod edition_panic; @@ -114,6 +115,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) { bench: test::expand_bench, cfg_accessible: cfg_accessible::Expander, cfg_eval: cfg_eval::expand, + define_opaques: define_opaques::expand, derive: derive::Expander { is_const: false }, derive_const: derive::Expander { is_const: true }, global_allocator: global_allocator::expand, diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 472e16e62d5b..30a821da125a 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -346,6 +346,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P { generics: ast::Generics::default(), contract: None, body: Some(main_body), + define_opaques: None, })); // Honor the reexport_test_harness_main attribute diff --git a/compiler/rustc_data_structures/src/obligation_forest/mod.rs b/compiler/rustc_data_structures/src/obligation_forest/mod.rs index 78d69a66edc8..f6eabaee9982 100644 --- a/compiler/rustc_data_structures/src/obligation_forest/mod.rs +++ b/compiler/rustc_data_structures/src/obligation_forest/mod.rs @@ -315,6 +315,7 @@ mod helper { use super::*; pub type ObligationTreeIdGenerator = impl Iterator; impl ObligationForest { + #[cfg_attr(not(bootstrap), define_opaques(ObligationTreeIdGenerator))] pub fn new() -> ObligationForest { ObligationForest { nodes: vec![], diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index ba1c3e185c2d..d52dfe529f9b 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -209,6 +209,7 @@ pub type LazyFallbackBundle = Arc Fluent /// Return the default `FluentBundle` with standard "en-US" diagnostic messages. #[instrument(level = "trace", skip(resources))] +#[cfg_attr(not(bootstrap), define_opaques(LazyFallbackBundle))] pub fn fallback_fluent_bundle( resources: Vec<&'static str>, with_directionality_markers: bool, diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index 3f75cce00922..a4bde8b13845 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -514,9 +514,6 @@ hir_analysis_supertrait_item_shadowee = item from `{$supertrait}` is shadowed by hir_analysis_supertrait_item_shadowing = trait item `{$item}` from `{$subtrait}` shadows identically named item from supertrait -hir_analysis_tait_forward_compat = item constrains opaque type that is not in its signature - .note = this item must mention the opaque type in its signature in order to be able to register hidden types - hir_analysis_tait_forward_compat2 = item does not constrain `{$opaque_type}`, but has it in its signature .note = consider moving the opaque type's declaration and defining uses into a separate module .opaque = this opaque type is in the signature diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index f2331f3fd8e1..2235ecb2df8c 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -423,6 +423,12 @@ fn best_definition_site_of_opaque<'tcx>( return ControlFlow::Continue(()); } + let opaque_types_defined_by = self.tcx.opaque_types_defined_by(item_def_id); + // Don't try to check items that cannot possibly constrain the type. + if !opaque_types_defined_by.contains(&self.opaque_def_id) { + return ControlFlow::Continue(()); + } + if let Some(hidden_ty) = self.tcx.mir_borrowck(item_def_id).concrete_opaque_types.get(&self.opaque_def_id) { @@ -482,19 +488,7 @@ fn best_definition_site_of_opaque<'tcx>( None } hir::OpaqueTyOrigin::TyAlias { in_assoc_ty: false, .. } => { - let scope = tcx.hir_get_defining_scope(tcx.local_def_id_to_hir_id(opaque_def_id)); - let found = if scope == hir::CRATE_HIR_ID { - tcx.hir_walk_toplevel_module(&mut locator) - } else { - match tcx.hir_node(scope) { - Node::Item(it) => locator.visit_item(it), - Node::ImplItem(it) => locator.visit_impl_item(it), - Node::TraitItem(it) => locator.visit_trait_item(it), - Node::ForeignItem(it) => locator.visit_foreign_item(it), - other => bug!("{:?} is not a valid scope for an opaque type item", other), - } - }; - found.break_value() + tcx.hir_walk_toplevel_module(&mut locator).break_value() } } } diff --git a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs index 399c4fbe55a9..142078900f0e 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs @@ -1,14 +1,13 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; -use rustc_hir::intravisit::{self, Visitor}; -use rustc_hir::{self as hir, Expr, ImplItem, Item, Node, TraitItem, def}; +use rustc_hir::{self as hir, Expr, ImplItem, Item, Node, TraitItem, def, intravisit}; use rustc_middle::bug; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt}; use rustc_span::DUMMY_SP; use tracing::{debug, instrument, trace}; -use crate::errors::{TaitForwardCompat, TaitForwardCompat2, UnconstrainedOpaqueType}; +use crate::errors::{TaitForwardCompat2, UnconstrainedOpaqueType}; /// Checks "defining uses" of opaque `impl Trait` in associated types. /// These can only be defined by associated items of the same trait. @@ -82,38 +81,9 @@ pub(super) fn find_opaque_ty_constraints_for_impl_trait_in_assoc_type( /// ``` #[instrument(skip(tcx), level = "debug")] pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> { - let hir_id = tcx.local_def_id_to_hir_id(def_id); - let scope = tcx.hir_get_defining_scope(hir_id); let mut locator = TaitConstraintLocator { def_id, tcx, found: None, typeck_types: vec![] }; - debug!(?scope); - - if scope == hir::CRATE_HIR_ID { - tcx.hir_walk_toplevel_module(&mut locator); - } else { - trace!("scope={:#?}", tcx.hir_node(scope)); - match tcx.hir_node(scope) { - // We explicitly call `visit_*` methods, instead of using `intravisit::walk_*` methods - // This allows our visitor to process the defining item itself, causing - // it to pick up any 'sibling' defining uses. - // - // For example, this code: - // ``` - // fn foo() { - // type Blah = impl Debug; - // let my_closure = || -> Blah { true }; - // } - // ``` - // - // requires us to explicitly process `foo()` in order - // to notice the defining usage of `Blah`. - Node::Item(it) => locator.visit_item(it), - Node::ImplItem(it) => locator.visit_impl_item(it), - Node::TraitItem(it) => locator.visit_trait_item(it), - Node::ForeignItem(it) => locator.visit_foreign_item(it), - other => bug!("{:?} is not a valid scope for an opaque type item", other), - } - } + tcx.hir_walk_toplevel_module(&mut locator); if let Some(hidden) = locator.found { // Only check against typeck if we didn't already error @@ -137,12 +107,7 @@ pub(super) fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: Local let reported = tcx.dcx().emit_err(UnconstrainedOpaqueType { span: tcx.def_span(def_id), name: tcx.item_ident(parent_def_id.to_def_id()), - what: match tcx.hir_node(scope) { - _ if scope == hir::CRATE_HIR_ID => "module", - Node::Item(hir::Item { kind: hir::ItemKind::Mod(_), .. }) => "module", - Node::Item(hir::Item { kind: hir::ItemKind::Impl(_), .. }) => "impl", - _ => "item", - }, + what: "crate", }); Ty::new_error(tcx, reported) } @@ -176,6 +141,13 @@ impl TaitConstraintLocator<'_> { return; } + let opaque_types_defined_by = self.tcx.opaque_types_defined_by(item_def_id); + // Don't try to check items that cannot possibly constrain the type. + if !opaque_types_defined_by.contains(&self.def_id) { + debug!("no constraint: no opaque types defined"); + return; + } + // Function items with `_` in their return type already emit an error, skip any // "non-defining use" errors for them. // Note that we use `Node::fn_sig` instead of `Node::fn_decl` here, because the former @@ -215,8 +187,6 @@ impl TaitConstraintLocator<'_> { return; } - let opaque_types_defined_by = self.tcx.opaque_types_defined_by(item_def_id); - let mut constrained = false; for (&opaque_type_key, &hidden_type) in &tables.concrete_opaque_types { if opaque_type_key.def_id != self.def_id { @@ -224,20 +194,6 @@ impl TaitConstraintLocator<'_> { } constrained = true; - if !opaque_types_defined_by.contains(&self.def_id) { - let guar = self.tcx.dcx().emit_err(TaitForwardCompat { - span: hidden_type.span, - item_span: self - .tcx - .def_ident_span(item_def_id) - .unwrap_or_else(|| self.tcx.def_span(item_def_id)), - }); - // Avoid "opaque type not constrained" errors on the opaque itself. - self.found = Some(ty::OpaqueHiddenType { - span: DUMMY_SP, - ty: Ty::new_error(self.tcx, guar), - }); - } let concrete_type = self.tcx.erase_regions(hidden_type.remap_generic_params_to_declaration_params( opaque_type_key, @@ -309,19 +265,13 @@ impl<'tcx> intravisit::Visitor<'tcx> for TaitConstraintLocator<'tcx> { } fn visit_item(&mut self, it: &'tcx Item<'tcx>) { trace!(?it.owner_id); - // The opaque type itself or its children are not within its reveal scope. - if it.owner_id.def_id != self.def_id { - self.check(it.owner_id.def_id); - intravisit::walk_item(self, it); - } + self.check(it.owner_id.def_id); + intravisit::walk_item(self, it); } fn visit_impl_item(&mut self, it: &'tcx ImplItem<'tcx>) { trace!(?it.owner_id); - // The opaque type itself or its children are not within its reveal scope. - if it.owner_id.def_id != self.def_id { - self.check(it.owner_id.def_id); - intravisit::walk_impl_item(self, it); - } + self.check(it.owner_id.def_id); + intravisit::walk_impl_item(self, it); } fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) { trace!(?it.owner_id); diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 852533ff5c95..49a0fc6fdb86 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -424,16 +424,6 @@ pub(crate) struct UnconstrainedOpaqueType { pub what: &'static str, } -#[derive(Diagnostic)] -#[diag(hir_analysis_tait_forward_compat)] -#[note] -pub(crate) struct TaitForwardCompat { - #[primary_span] - pub span: Span, - #[note] - pub item_span: Span, -} - #[derive(Diagnostic)] #[diag(hir_analysis_tait_forward_compat2)] #[note] diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs index b887370fd699..58217bb9ca4a 100644 --- a/compiler/rustc_middle/src/mir/terminator.rs +++ b/compiler/rustc_middle/src/mir/terminator.rs @@ -454,6 +454,7 @@ mod helper { /// Like [`SwitchTargets::target_for_value`], but returning the same type as /// [`Terminator::successors`]. #[inline] + #[cfg_attr(not(bootstrap), define_opaques(Successors))] pub fn successors_for_value(&self, value: u128) -> Successors<'_> { let target = self.target_for_value(value); (&[]).into_iter().copied().chain(Some(target)) @@ -462,6 +463,7 @@ mod helper { impl<'tcx> TerminatorKind<'tcx> { #[inline] + #[cfg_attr(not(bootstrap), define_opaques(Successors))] pub fn successors(&self) -> Successors<'_> { use self::TerminatorKind::*; match *self { @@ -500,6 +502,7 @@ mod helper { } #[inline] + #[cfg_attr(not(bootstrap), define_opaques(SuccessorsMut))] pub fn successors_mut(&mut self) -> SuccessorsMut<'_> { use self::TerminatorKind::*; match *self { diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index cbd60920bc57..985eeaf3c3c5 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -24,6 +24,7 @@ pub trait EraseType: Copy { pub type Erase = Erased; #[inline(always)] +#[cfg_attr(not(bootstrap), define_opaques(Erase))] pub fn erase(src: T) -> Erase { // Ensure the sizes match const { @@ -47,6 +48,7 @@ pub fn erase(src: T) -> Erase { /// Restores an erased value. #[inline(always)] +#[cfg_attr(not(bootstrap), define_opaques(Erase))] pub fn restore(value: Erase) -> T { let value: Erased<::Result> = value; // See comment in `erase` for why we use `transmute_unchecked`. diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index c923717ecaf2..98f70a87a090 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -217,7 +217,14 @@ impl<'a> Parser<'a> { self.parse_fn(attrs, fn_parse_mode, lo, vis, case)?; ( ident, - ItemKind::Fn(Box::new(Fn { defaultness: def_(), sig, generics, contract, body })), + ItemKind::Fn(Box::new(Fn { + defaultness: def_(), + sig, + generics, + contract, + body, + define_opaques: None, + })), ) } else if self.eat_keyword(exp!(Extern)) { if self.eat_keyword(exp!(Crate)) { diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index ad9c3465f0cc..fa26b2edffa9 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -394,32 +394,37 @@ pub(crate) enum AliasPossibility { #[derive(Copy, Clone, Debug)] pub(crate) enum PathSource<'a> { - // Type paths `Path`. + /// Type paths `Path`. Type, - // Trait paths in bounds or impls. + /// Trait paths in bounds or impls. Trait(AliasPossibility), - // Expression paths `path`, with optional parent context. + /// Expression paths `path`, with optional parent context. Expr(Option<&'a Expr>), - // Paths in path patterns `Path`. + /// Paths in path patterns `Path`. Pat, - // Paths in struct expressions and patterns `Path { .. }`. + /// Paths in struct expressions and patterns `Path { .. }`. Struct, - // Paths in tuple struct patterns `Path(..)`. + /// Paths in tuple struct patterns `Path(..)`. TupleStruct(Span, &'a [Span]), - // `m::A::B` in `::B::C`. + /// `m::A::B` in `::B::C`. TraitItem(Namespace), - // Paths in delegation item + /// Paths in delegation item Delegation, /// An arg in a `use<'a, N>` precise-capturing bound. PreciseCapturingArg(Namespace), - // Paths that end with `(..)`, for return type notation. + /// Paths that end with `(..)`, for return type notation. ReturnTypeNotation, + /// Paths from `#[define_opaques]` attributes + DefineOpaques, } impl<'a> PathSource<'a> { fn namespace(self) -> Namespace { match self { - PathSource::Type | PathSource::Trait(_) | PathSource::Struct => TypeNS, + PathSource::Type + | PathSource::Trait(_) + | PathSource::Struct + | PathSource::DefineOpaques => TypeNS, PathSource::Expr(..) | PathSource::Pat | PathSource::TupleStruct(..) @@ -440,6 +445,7 @@ impl<'a> PathSource<'a> { | PathSource::ReturnTypeNotation => true, PathSource::Trait(_) | PathSource::TraitItem(..) + | PathSource::DefineOpaques | PathSource::Delegation | PathSource::PreciseCapturingArg(..) => false, } @@ -447,6 +453,7 @@ impl<'a> PathSource<'a> { fn descr_expected(self) -> &'static str { match &self { + PathSource::DefineOpaques => "type alias or associated type with opaqaue types", PathSource::Type => "type", PathSource::Trait(_) => "trait", PathSource::Pat => "unit struct, unit variant or constant", @@ -490,6 +497,19 @@ impl<'a> PathSource<'a> { pub(crate) fn is_expected(self, res: Res) -> bool { match self { + PathSource::DefineOpaques => { + matches!( + res, + Res::Def( + DefKind::Struct + | DefKind::Union + | DefKind::Enum + | DefKind::TyAlias + | DefKind::AssocTy, + _ + ) | Res::SelfTyAlias { .. } + ) + } PathSource::Type => matches!( res, Res::Def( @@ -569,16 +589,16 @@ impl<'a> PathSource<'a> { match (self, has_unexpected_resolution) { (PathSource::Trait(_), true) => E0404, (PathSource::Trait(_), false) => E0405, - (PathSource::Type, true) => E0573, - (PathSource::Type, false) => E0412, + (PathSource::Type | PathSource::DefineOpaques, true) => E0573, + (PathSource::Type | PathSource::DefineOpaques, false) => E0412, (PathSource::Struct, true) => E0574, (PathSource::Struct, false) => E0422, (PathSource::Expr(..), true) | (PathSource::Delegation, true) => E0423, (PathSource::Expr(..), false) | (PathSource::Delegation, false) => E0425, (PathSource::Pat | PathSource::TupleStruct(..), true) => E0532, (PathSource::Pat | PathSource::TupleStruct(..), false) => E0531, - (PathSource::TraitItem(..), true) | (PathSource::ReturnTypeNotation, true) => E0575, - (PathSource::TraitItem(..), false) | (PathSource::ReturnTypeNotation, false) => E0576, + (PathSource::TraitItem(..) | PathSource::ReturnTypeNotation, true) => E0575, + (PathSource::TraitItem(..) | PathSource::ReturnTypeNotation, false) => E0576, (PathSource::PreciseCapturingArg(..), true) => E0799, (PathSource::PreciseCapturingArg(..), false) => E0800, } @@ -1984,6 +2004,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { | PathSource::Pat | PathSource::Struct | PathSource::TupleStruct(..) + | PathSource::DefineOpaques | PathSource::Delegation => true, }; if inferred { @@ -2597,7 +2618,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { ); } - ItemKind::Fn(box Fn { ref generics, .. }) => { + ItemKind::Fn(box Fn { ref generics, ref define_opaques, .. }) => { self.with_generic_param_rib( &generics.params, RibKind::Item(HasGenericParams::Yes(generics.span), def_kind), @@ -2608,6 +2629,10 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { }, |this| visit::walk_item(this, item), ); + + for (id, path) in define_opaques.iter().flatten() { + self.smart_resolve_path(*id, &None, path, PathSource::DefineOpaques); + } } ItemKind::Enum(_, ref generics) @@ -3078,8 +3103,12 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { }, ); } - AssocItemKind::Fn(box Fn { generics, .. }) => { + AssocItemKind::Fn(box Fn { generics, define_opaques, .. }) => { walk_assoc_item(self, generics, LifetimeBinderKind::Function, item); + + for (id, path) in define_opaques.iter().flatten() { + self.smart_resolve_path(*id, &None, path, PathSource::DefineOpaques); + } } AssocItemKind::Delegation(delegation) => { self.with_generic_param_rib( @@ -3288,7 +3317,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { }, ); } - AssocItemKind::Fn(box Fn { generics, .. }) => { + AssocItemKind::Fn(box Fn { generics, define_opaques, .. }) => { debug!("resolve_implementation AssocItemKind::Fn"); // We also need a new scope for the impl item type parameters. self.with_generic_param_rib( @@ -3315,6 +3344,10 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { visit::walk_assoc_item(this, item, AssocCtxt::Impl) }, ); + + for (id, path) in define_opaques.iter().flatten() { + self.smart_resolve_path(*id, &None, path, PathSource::DefineOpaques); + } } AssocItemKind::Type(box TyAlias { generics, .. }) => { self.diag_metadata.in_non_gat_assoc_type = Some(generics.params.is_empty()); diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 501c9039f2de..662bf059cc75 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -776,6 +776,7 @@ symbols! { default_method_body_is_const, default_type_parameter_fallback, default_type_params, + define_opaques, delayed_bug_from_inside_query, deny, deprecated, diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs index 514615735a50..34852654525b 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs @@ -395,10 +395,16 @@ impl Trait for X { let sp = tcx .def_ident_span(body_owner_def_id) .unwrap_or_else(|| tcx.def_span(body_owner_def_id)); + let mut alias_def_id = opaque_ty.def_id; + while let DefKind::OpaqueTy = tcx.def_kind(alias_def_id) { + alias_def_id = tcx.parent(alias_def_id); + } + let opaque_path = tcx.def_path_str(alias_def_id); + // FIXME(type_alias_impl_trait): make this a structured suggestion diag.span_note( sp, - "this item must have the opaque type in its signature in order to \ - be able to register hidden types", + format!("this item must have a `#[define_opaques({opaque_path})]` attribute to be able \ + to define hidden types"), ); } // If two if arms can be coerced to a trait object, provide a structured diff --git a/compiler/rustc_ty_utils/Cargo.toml b/compiler/rustc_ty_utils/Cargo.toml index 4c7a57f2931b..7e96b64408c1 100644 --- a/compiler/rustc_ty_utils/Cargo.toml +++ b/compiler/rustc_ty_utils/Cargo.toml @@ -7,6 +7,7 @@ edition = "2024" # tidy-alphabetical-start itertools = "0.12" rustc_abi = { path = "../rustc_abi" } +rustc_attr_parsing = { path = "../rustc_attr_parsing" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_fluent_macro = { path = "../rustc_fluent_macro" } diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 98881905bcf8..be67b774b7a2 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -1,8 +1,9 @@ +use rustc_attr_parsing::{AttributeKind, find_attr}; use rustc_data_structures::fx::FxHashSet; use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; +use rustc_hir::intravisit; use rustc_hir::intravisit::Visitor; -use rustc_hir::{CRATE_HIR_ID, intravisit}; use rustc_middle::bug; use rustc_middle::query::Providers; use rustc_middle::ty::util::{CheckRegions, NotUniqueParam}; @@ -30,14 +31,21 @@ enum CollectionMode { /// For impl trait in assoc types we only permit collecting them from /// associated types of the same impl block. ImplTraitInAssocTypes, - TypeAliasImplTraitTransition, + /// When collecting for an explicit `#[define_opaques]` attribute, find all TAITs + Taits, + /// The default case, only collect RPITs and AsyncFn return types, as these are + /// always defined by the current item. + RpitAndAsyncFnOnly, } impl<'tcx> OpaqueTypeCollector<'tcx> { fn new(tcx: TyCtxt<'tcx>, item: LocalDefId) -> Self { - let mode = match tcx.def_kind(tcx.local_parent(item)) { - DefKind::Impl { of_trait: true } => CollectionMode::ImplTraitInAssocTypes, - _ => CollectionMode::TypeAliasImplTraitTransition, + let mode = match tcx.def_kind(item) { + DefKind::AssocConst | DefKind::AssocFn | DefKind::AssocTy => { + CollectionMode::ImplTraitInAssocTypes + } + DefKind::TyAlias => CollectionMode::Taits, + _ => CollectionMode::RpitAndAsyncFnOnly, }; Self { tcx, opaques: Vec::new(), item, seen: Default::default(), span: None, mode } } @@ -73,40 +81,6 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { } } - /// Returns `true` if `opaque_hir_id` is a sibling or a child of a sibling of `self.item`. - /// - /// Example: - /// ```ignore UNSOLVED (is this a bug?) - /// # #![feature(type_alias_impl_trait)] - /// pub mod foo { - /// pub mod bar { - /// pub trait Bar { /* ... */ } - /// pub type Baz = impl Bar; - /// - /// # impl Bar for () {} - /// fn f1() -> Baz { /* ... */ } - /// } - /// fn f2() -> bar::Baz { /* ... */ } - /// } - /// ``` - /// - /// and `opaque_def_id` is the `DefId` of the definition of the opaque type `Baz`. - /// For the above example, this function returns `true` for `f1` and `false` for `f2`. - #[instrument(level = "trace", skip(self), ret)] - fn check_tait_defining_scope(&self, opaque_def_id: LocalDefId) -> bool { - let mut hir_id = self.tcx.local_def_id_to_hir_id(self.item); - let opaque_hir_id = self.tcx.local_def_id_to_hir_id(opaque_def_id); - - // Named opaque types can be defined by any siblings or children of siblings. - let scope = self.tcx.hir_get_defining_scope(opaque_hir_id); - // We walk up the node tree until we hit the root or the scope of the opaque type. - while hir_id != scope && hir_id != CRATE_HIR_ID { - hir_id = self.tcx.hir_get_parent_item(hir_id).into(); - } - // Syntactically, we are allowed to define the concrete type if: - hir_id == scope - } - #[instrument(level = "trace", skip(self))] fn collect_taits_declared_in_body(&mut self) { let body = self.tcx.hir_body_owned_by(self.item).value; @@ -139,18 +113,25 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { } // TAITs outside their defining scopes are ignored. - let origin = self.tcx.local_opaque_ty_origin(alias_ty.def_id.expect_local()); - trace!(?origin); - match origin { + match self.tcx.local_opaque_ty_origin(alias_ty.def_id.expect_local()) { rustc_hir::OpaqueTyOrigin::FnReturn { .. } | rustc_hir::OpaqueTyOrigin::AsyncFn { .. } => {} - rustc_hir::OpaqueTyOrigin::TyAlias { in_assoc_ty, .. } => { - if !in_assoc_ty && !self.check_tait_defining_scope(alias_ty.def_id.expect_local()) { - return; + rustc_hir::OpaqueTyOrigin::TyAlias { in_assoc_ty, .. } => match self.mode { + CollectionMode::ImplTraitInAssocTypes => { + if !in_assoc_ty { + return; + } } - } + CollectionMode::Taits => { + if in_assoc_ty { + return; + } + } + CollectionMode::RpitAndAsyncFnOnly => return, + }, } + trace!(?alias_ty, "adding"); self.opaques.push(alias_ty.def_id.expect_local()); let parent_count = self.tcx.generics_of(alias_ty.def_id).parent_count; @@ -192,6 +173,26 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { } } } + + /// Returns true if a define_opaques attr with entries was found + #[instrument(level = "trace", skip(self))] + fn collect_taits_from_defines_attr(&mut self) { + let Some(defines) = + find_attr!(self.tcx.get_all_attrs(self.item), AttributeKind::DefineOpaques(r) => r) + else { + return; + }; + for &define in defines { + trace!(?define); + let mode = std::mem::replace(&mut self.mode, CollectionMode::Taits); + // TODO: check that opaque types were introduced and error otherwise (also add tests) + super::sig_types::walk_types(self.tcx, define, self); + self.mode = mode; + } + // Allow using `#[define_opaques]` on assoc methods and type aliases to override the default collection mode in + // case it was capturing too much. + self.mode = CollectionMode::RpitAndAsyncFnOnly; + } } impl<'tcx> super::sig_types::SpannedTypeVisitor<'tcx> for OpaqueTypeCollector<'tcx> { @@ -210,6 +211,7 @@ impl<'tcx> TypeVisitor> for OpaqueTypeCollector<'tcx> { self.visit_opaque_ty(alias_ty); } // Skips type aliases, as they are meant to be transparent. + // FIXME(type_alias_impl_trait): can we reqauire mentioning nested type aliases explicitly? ty::Alias(ty::Weak, alias_ty) if alias_ty.def_id.is_local() => { self.tcx .type_of(alias_ty.def_id) @@ -283,28 +285,6 @@ impl<'tcx> TypeVisitor> for OpaqueTypeCollector<'tcx> { self.visit_opaque_ty(alias_ty); } } - ty::Adt(def, _) if def.did().is_local() => { - if let CollectionMode::ImplTraitInAssocTypes = self.mode { - return; - } - if !self.seen.insert(def.did().expect_local()) { - return; - } - for variant in def.variants().iter() { - for field in variant.fields.iter() { - // Don't use the `ty::Adt` args, we either - // * found the opaque in the args - // * will find the opaque in the uninstantiated fields - // The only other situation that can occur is that after instantiating, - // some projection resolves to an opaque that we would have otherwise - // not found. While we could instantiate and walk those, that would mean we - // would have to walk all generic parameters of an Adt, which can quickly - // degenerate into looking at an exponential number of types. - let ty = self.tcx.type_of(field.did).instantiate_identity(); - self.visit_spanned(self.tcx.def_span(field.did), ty); - } - } - } _ => trace!(kind=?t.kind()), } } @@ -317,7 +297,9 @@ fn opaque_types_defined_by<'tcx>( let kind = tcx.def_kind(item); trace!(?kind); let mut collector = OpaqueTypeCollector::new(tcx, item); + collector.collect_taits_from_defines_attr(); super::sig_types::walk_types(tcx, item, &mut collector); + match kind { DefKind::AssocFn | DefKind::Fn @@ -350,8 +332,7 @@ fn opaque_types_defined_by<'tcx>( | DefKind::GlobalAsm | DefKind::Impl { .. } | DefKind::SyntheticCoroutineBody => {} - // Closures and coroutines are type checked with their parent, so we need to allow all - // opaques from the closure signature *and* from the parent body. + // Closures and coroutines are type checked with their parent DefKind::Closure | DefKind::InlineConst => { collector.opaques.extend(tcx.opaque_types_defined_by(tcx.local_parent(item))); } diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 16200184422b..7d60917e0188 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -1743,6 +1743,21 @@ pub(crate) mod builtin { /* compiler built-in */ } + /// Provide a list of type aliases and other opaque-type-containing type definitions. + /// This list will be used in the body of the item it is applied to to define opaque + /// types' hidden types. + /// Can only be applied to things that have bodies. + #[unstable( + feature = "type_alias_impl_trait", + issue = "63063", + reason = "`type_alias_impl_trait` has open design concerns" + )] + #[rustc_builtin_macro] + #[cfg(not(bootstrap))] + pub macro define_opaques($($tt:tt)*) { + /* compiler built-in */ + } + /// Unstable placeholder for type ascription. #[allow_internal_unstable(builtin_syntax)] #[unstable( diff --git a/library/core/src/prelude/v1.rs b/library/core/src/prelude/v1.rs index 50fd67e83955..593334c53dde 100644 --- a/library/core/src/prelude/v1.rs +++ b/library/core/src/prelude/v1.rs @@ -111,3 +111,11 @@ pub use crate::macros::builtin::type_ascribe; reason = "placeholder syntax for deref patterns" )] pub use crate::macros::builtin::deref; + +#[unstable( + feature = "type_alias_impl_trait", + issue = "63063", + reason = "`type_alias_impl_trait` has open design concerns" +)] +#[cfg(not(bootstrap))] +pub use crate::macros::builtin::define_opaques; diff --git a/library/std/src/backtrace.rs b/library/std/src/backtrace.rs index fc333d7ff3f9..b98b637977df 100644 --- a/library/std/src/backtrace.rs +++ b/library/std/src/backtrace.rs @@ -432,6 +432,7 @@ mod helper { use super::*; pub(super) type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe; + #[cfg_attr(not(bootstrap), define_opaques(LazyResolve))] pub(super) fn lazy_resolve(mut capture: Capture) -> LazyResolve { move || { // Use the global backtrace lock to synchronize this as it's a diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs index 5b324b2e9167..624576911904 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -103,6 +103,15 @@ pub use core::prelude::v1::type_ascribe; )] pub use core::prelude::v1::deref; +// Do not `doc(no_inline)` either. +#[unstable( + feature = "type_alias_impl_trait", + issue = "63063", + reason = "`type_alias_impl_trait` has open design concerns" +)] +#[cfg(not(bootstrap))] +pub use core::prelude::v1::define_opaques; + // The file so far is equivalent to core/src/prelude/v1.rs. It is duplicated // rather than glob imported because we want docs to show these re-exports as // pointing to within `std`. diff --git a/src/librustdoc/html/render/span_map.rs b/src/librustdoc/html/render/span_map.rs index ce9c42c01cc7..3db09ed62710 100644 --- a/src/librustdoc/html/render/span_map.rs +++ b/src/librustdoc/html/render/span_map.rs @@ -274,7 +274,7 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> { fn visit_item(&mut self, item: &'tcx Item<'tcx>) { match item.kind { - ItemKind::Static(_, _, _) + ItemKind::Static(..) | ItemKind::Const(_, _, _) | ItemKind::Fn { .. } | ItemKind::Macro(_, _) diff --git a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs index ab5f97199ce3..268dbeff42df 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs @@ -364,6 +364,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { generics: lg, contract: lc, body: lb, + define_opaques: _, }), Fn(box ast::Fn { defaultness: rd, @@ -371,6 +372,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { generics: rg, contract: rc, body: rb, + define_opaques: _, }), ) => { eq_defaultness(*ld, *rd) @@ -502,6 +504,7 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { generics: lg, contract: lc, body: lb, + define_opaques: _, }), Fn(box ast::Fn { defaultness: rd, @@ -509,6 +512,7 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { generics: rg, contract: rc, body: rb, + define_opaques: _, }), ) => { eq_defaultness(*ld, *rd) @@ -567,6 +571,7 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { generics: lg, contract: lc, body: lb, + define_opaques: _, }), Fn(box ast::Fn { defaultness: rd, @@ -574,6 +579,7 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { generics: rg, contract: rc, body: rb, + define_opaques: _, }), ) => { eq_defaultness(*ld, *rd) diff --git a/tests/crashes/120016.rs b/tests/crashes/120016.rs index 09175689256a..cfc6c2abfbce 100644 --- a/tests/crashes/120016.rs +++ b/tests/crashes/120016.rs @@ -6,6 +6,7 @@ struct Bug { V1: [(); { type F = impl std::future::Future; + #[define_opaques(F)] fn concrete_use() -> F { //~^ ERROR to be a future that resolves to `u8`, but it resolves to `()` async {} diff --git a/tests/crashes/122904-2.rs b/tests/crashes/122904-2.rs index 85ed91c2fa48..e26ef202f92a 100644 --- a/tests/crashes/122904-2.rs +++ b/tests/crashes/122904-2.rs @@ -6,10 +6,12 @@ type Alias<'a> = impl T; struct S; impl<'a> T for &'a S {} +#[define_opaques(Alias)] fn with_positive(fun: impl Fn(Alias<'_>)) { with_positive(|&n| ()); } +#[define_opaques(Alias)] fn main(Alias<'_>) { with_positive(|&a| ()); } diff --git a/tests/crashes/122904.rs b/tests/crashes/122904.rs index 8b8bb35d56c1..930b54f582f2 100644 --- a/tests/crashes/122904.rs +++ b/tests/crashes/122904.rs @@ -6,6 +6,7 @@ type Alias<'a> = impl T; struct S; impl<'a> T for &'a S {} +#[define_opaques(Alias)] fn with_positive(fun: impl Fn(Alias<'_>)) { with_positive(|&n| ()); } diff --git a/tests/crashes/125185.rs b/tests/crashes/125185.rs index 8693d6c7662b..1f1d626c6950 100644 --- a/tests/crashes/125185.rs +++ b/tests/crashes/125185.rs @@ -1,16 +1,26 @@ //@ known-bug: rust-lang/rust#125185 //@ compile-flags: -Zvalidate-mir +#![feature(type_alias_impl_trait)] + type Foo = impl Send; struct A; -const VALUE: Foo = value(); +#[define_opaques(Foo)] +const fn foo() -> Foo { + value() +} + +const VALUE: Foo = foo(); -fn test(foo: Foo<'a>, f: impl for<'b> FnMut()) { +#[define_opaques(Foo)] +fn test(foo: Foo, f: impl for<'b> FnMut()) { match VALUE { 0 | 0 => {} _ => (), } } + +fn main() {} diff --git a/tests/crashes/126680.rs b/tests/crashes/126680.rs index b1566d5e6bee..b3288acabb98 100644 --- a/tests/crashes/126680.rs +++ b/tests/crashes/126680.rs @@ -8,14 +8,18 @@ use std::path::Path; struct A { pub func: fn(check: Bar, b: Option<&Path>), } -const MY_A: A = A { - func: |check, b| { - if check { - () - } else if let Some(_) = b.and_then(|p| p.parent()) { - () - } - }, -}; + +#[define_opaques(Bar)] +fn foo() -> A { + A { + func: |check, b| { + if check { + () + } else if let Some(_) = b.and_then(|p| p.parent()) { + () + } + }, + } +} fn main() {} diff --git a/tests/crashes/131298.rs b/tests/crashes/131298.rs deleted file mode 100644 index 833f1b04ffab..000000000000 --- a/tests/crashes/131298.rs +++ /dev/null @@ -1,12 +0,0 @@ -//@ known-bug: #131298 - -fn dyn_hoops() -> *const dyn Iterator { - loop {} -} - -mod typeck { - type Opaque = impl Sized; - fn define() -> Opaque { - let _: Opaque = super::dyn_hoops::(); - } -} diff --git a/tests/crashes/131886.rs b/tests/crashes/131886.rs index 2c692dfb7771..f93a1171c820 100644 --- a/tests/crashes/131886.rs +++ b/tests/crashes/131886.rs @@ -1,5 +1,5 @@ //@ known-bug: #131886 -//@ compile-flags: -Zvalidate-mir --crate-type=lib +//@ compile-flags: -Zvalidate-mir #![feature(type_alias_impl_trait)] type Tait = impl Sized; @@ -7,6 +7,9 @@ type Tait = impl Sized; trait Foo<'a>: Bar<'a, 'a, Tait> {} trait Bar<'a, 'b, T> {} +#[define_opaques(Tait)] fn test_correct3<'a>(x: &dyn Foo<'a>, _: Tait) { let _ = x as &dyn Bar<'_, '_, ()>; } + +fn main() {} diff --git a/tests/crashes/135528.rs b/tests/crashes/135528.rs index a1418f40be6a..9ee2e9243cf4 100644 --- a/tests/crashes/135528.rs +++ b/tests/crashes/135528.rs @@ -7,10 +7,12 @@ fn set(x: &isize) -> isize { *x } +#[define_opaques(Tait)] fn d(x: Tait) { set(x); } +#[define_opaques(Tait)] fn other_define() -> Tait { () } diff --git a/tests/ui/associated-inherent-types/constrain_opaque_types_during_projection.rs b/tests/ui/associated-inherent-types/constrain_opaque_types_during_projection.rs index 292733cd4923..ed4ebde7c1fa 100644 --- a/tests/ui/associated-inherent-types/constrain_opaque_types_during_projection.rs +++ b/tests/ui/associated-inherent-types/constrain_opaque_types_during_projection.rs @@ -11,7 +11,8 @@ impl Foo { type Tait = impl Sized; -fn bar(_: Tait) { +#[define_opaques(Tait)] +fn bar() { let x: Foo::Assoc = 42; } diff --git a/tests/ui/associated-inherent-types/issue-109299-1.stderr b/tests/ui/associated-inherent-types/issue-109299-1.stderr index 07a00b6b9a95..c05547c55f1f 100644 --- a/tests/ui/associated-inherent-types/issue-109299-1.stderr +++ b/tests/ui/associated-inherent-types/issue-109299-1.stderr @@ -29,7 +29,7 @@ error: unconstrained opaque type LL | type X = impl for Fn() -> Lexer::Cursor; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `X` must be used in combination with a concrete type within the same module + = note: `X` must be used in combination with a concrete type within the same crate error: aborting due to 3 previous errors diff --git a/tests/ui/associated-type-bounds/dont-imply-atb-in-closure-inference.rs b/tests/ui/associated-type-bounds/dont-imply-atb-in-closure-inference.rs index fecb3b153386..b4447137013b 100644 --- a/tests/ui/associated-type-bounds/dont-imply-atb-in-closure-inference.rs +++ b/tests/ui/associated-type-bounds/dont-imply-atb-in-closure-inference.rs @@ -11,10 +11,8 @@ impl IsPtr for T { type Tait = impl IsPtr + Fn(u32); -fn hello() -where - Tait:, -{ +#[define_opaques(Tait)] +fn hello() { let _: Tait = |x| {}; } diff --git a/tests/ui/associated-type-bounds/duplicate.rs b/tests/ui/associated-type-bounds/duplicate.rs index 2b4a01376d77..e9d94787e982 100644 --- a/tests/ui/associated-type-bounds/duplicate.rs +++ b/tests/ui/associated-type-bounds/duplicate.rs @@ -179,19 +179,25 @@ where type ETAI1> = impl Copy; //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] +//~| ERROR unconstrained opaque type type ETAI2> = impl Copy; //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] +//~| ERROR unconstrained opaque type type ETAI3> = impl Copy; //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] +//~| ERROR unconstrained opaque type type ETAI4 = impl Iterator; //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] //~| ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] +//~| ERROR unconstrained opaque type type ETAI5 = impl Iterator; //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] //~| ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] +//~| ERROR unconstrained opaque type type ETAI6 = impl Iterator; //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] //~| ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] +//~| ERROR unconstrained opaque type trait TRI1> {} //~^ ERROR the value of the associated type `Item` in trait `Iterator` is already specified [E0719] diff --git a/tests/ui/associated-type-bounds/duplicate.stderr b/tests/ui/associated-type-bounds/duplicate.stderr index 0dabcbdce1bb..1ce212a9ff3e 100644 --- a/tests/ui/associated-type-bounds/duplicate.stderr +++ b/tests/ui/associated-type-bounds/duplicate.stderr @@ -325,7 +325,7 @@ LL | type ETAI1> = impl Copy; | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:182:36 + --> $DIR/duplicate.rs:183:36 | LL | type ETAI2> = impl Copy; | ---------- ^^^^^^^^^^ re-bound here @@ -333,7 +333,7 @@ LL | type ETAI2> = impl Copy; | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:184:39 + --> $DIR/duplicate.rs:186:39 | LL | type ETAI3> = impl Copy; | ------------- ^^^^^^^^^^^^^ re-bound here @@ -341,7 +341,7 @@ LL | type ETAI3> = impl Copy; | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:186:40 + --> $DIR/duplicate.rs:189:40 | LL | type ETAI4 = impl Iterator; | ---------- ^^^^^^^^^^ re-bound here @@ -349,7 +349,7 @@ LL | type ETAI4 = impl Iterator; | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:186:40 + --> $DIR/duplicate.rs:189:40 | LL | type ETAI4 = impl Iterator; | ---------- ^^^^^^^^^^ re-bound here @@ -359,7 +359,7 @@ LL | type ETAI4 = impl Iterator; = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:189:40 + --> $DIR/duplicate.rs:193:40 | LL | type ETAI5 = impl Iterator; | ---------- ^^^^^^^^^^ re-bound here @@ -367,7 +367,7 @@ LL | type ETAI5 = impl Iterator; | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:189:40 + --> $DIR/duplicate.rs:193:40 | LL | type ETAI5 = impl Iterator; | ---------- ^^^^^^^^^^ re-bound here @@ -377,7 +377,7 @@ LL | type ETAI5 = impl Iterator; = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:192:43 + --> $DIR/duplicate.rs:197:43 | LL | type ETAI6 = impl Iterator; | ------------- ^^^^^^^^^^^^^ re-bound here @@ -385,7 +385,7 @@ LL | type ETAI6 = impl Iterator; | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:192:43 + --> $DIR/duplicate.rs:197:43 | LL | type ETAI6 = impl Iterator; | ------------- ^^^^^^^^^^^^^ re-bound here @@ -395,7 +395,7 @@ LL | type ETAI6 = impl Iterator; = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:196:36 + --> $DIR/duplicate.rs:202:36 | LL | trait TRI1> {} | ---------- ^^^^^^^^^^ re-bound here @@ -403,7 +403,7 @@ LL | trait TRI1> {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:198:36 + --> $DIR/duplicate.rs:204:36 | LL | trait TRI2> {} | ---------- ^^^^^^^^^^ re-bound here @@ -411,7 +411,7 @@ LL | trait TRI2> {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:200:39 + --> $DIR/duplicate.rs:206:39 | LL | trait TRI3> {} | ------------- ^^^^^^^^^^^^^ re-bound here @@ -419,7 +419,7 @@ LL | trait TRI3> {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:202:34 + --> $DIR/duplicate.rs:208:34 | LL | trait TRS1: Iterator {} | ---------- ^^^^^^^^^^ re-bound here @@ -427,7 +427,7 @@ LL | trait TRS1: Iterator {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:202:34 + --> $DIR/duplicate.rs:208:34 | LL | trait TRS1: Iterator {} | ---------- ^^^^^^^^^^ re-bound here @@ -437,7 +437,7 @@ LL | trait TRS1: Iterator {} = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:202:34 + --> $DIR/duplicate.rs:208:34 | LL | trait TRS1: Iterator {} | ---------- ^^^^^^^^^^ re-bound here @@ -447,7 +447,7 @@ LL | trait TRS1: Iterator {} = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:206:34 + --> $DIR/duplicate.rs:212:34 | LL | trait TRS2: Iterator {} | ---------- ^^^^^^^^^^ re-bound here @@ -455,7 +455,7 @@ LL | trait TRS2: Iterator {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:206:34 + --> $DIR/duplicate.rs:212:34 | LL | trait TRS2: Iterator {} | ---------- ^^^^^^^^^^ re-bound here @@ -465,7 +465,7 @@ LL | trait TRS2: Iterator {} = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:206:34 + --> $DIR/duplicate.rs:212:34 | LL | trait TRS2: Iterator {} | ---------- ^^^^^^^^^^ re-bound here @@ -475,7 +475,7 @@ LL | trait TRS2: Iterator {} = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:210:37 + --> $DIR/duplicate.rs:216:37 | LL | trait TRS3: Iterator {} | ------------- ^^^^^^^^^^^^^ re-bound here @@ -483,7 +483,7 @@ LL | trait TRS3: Iterator {} | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:210:37 + --> $DIR/duplicate.rs:216:37 | LL | trait TRS3: Iterator {} | ------------- ^^^^^^^^^^^^^ re-bound here @@ -493,7 +493,7 @@ LL | trait TRS3: Iterator {} = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:210:37 + --> $DIR/duplicate.rs:216:37 | LL | trait TRS3: Iterator {} | ------------- ^^^^^^^^^^^^^ re-bound here @@ -503,7 +503,7 @@ LL | trait TRS3: Iterator {} = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:216:29 + --> $DIR/duplicate.rs:222:29 | LL | T: Iterator, | ---------- ^^^^^^^^^^ re-bound here @@ -511,7 +511,7 @@ LL | T: Iterator, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:222:29 + --> $DIR/duplicate.rs:228:29 | LL | T: Iterator, | ---------- ^^^^^^^^^^ re-bound here @@ -519,7 +519,7 @@ LL | T: Iterator, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:228:32 + --> $DIR/duplicate.rs:234:32 | LL | T: Iterator, | ------------- ^^^^^^^^^^^^^ re-bound here @@ -527,7 +527,7 @@ LL | T: Iterator, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:234:32 + --> $DIR/duplicate.rs:240:32 | LL | Self: Iterator, | ---------- ^^^^^^^^^^ re-bound here @@ -535,7 +535,7 @@ LL | Self: Iterator, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:234:32 + --> $DIR/duplicate.rs:240:32 | LL | Self: Iterator, | ---------- ^^^^^^^^^^ re-bound here @@ -545,7 +545,7 @@ LL | Self: Iterator, = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:234:32 + --> $DIR/duplicate.rs:240:32 | LL | Self: Iterator, | ---------- ^^^^^^^^^^ re-bound here @@ -555,7 +555,7 @@ LL | Self: Iterator, = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:242:32 + --> $DIR/duplicate.rs:248:32 | LL | Self: Iterator, | ---------- ^^^^^^^^^^ re-bound here @@ -563,7 +563,7 @@ LL | Self: Iterator, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:242:32 + --> $DIR/duplicate.rs:248:32 | LL | Self: Iterator, | ---------- ^^^^^^^^^^ re-bound here @@ -573,7 +573,7 @@ LL | Self: Iterator, = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:242:32 + --> $DIR/duplicate.rs:248:32 | LL | Self: Iterator, | ---------- ^^^^^^^^^^ re-bound here @@ -583,7 +583,7 @@ LL | Self: Iterator, = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:250:35 + --> $DIR/duplicate.rs:256:35 | LL | Self: Iterator, | ------------- ^^^^^^^^^^^^^ re-bound here @@ -591,7 +591,7 @@ LL | Self: Iterator, | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:250:35 + --> $DIR/duplicate.rs:256:35 | LL | Self: Iterator, | ------------- ^^^^^^^^^^^^^ re-bound here @@ -601,7 +601,7 @@ LL | Self: Iterator, = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:250:35 + --> $DIR/duplicate.rs:256:35 | LL | Self: Iterator, | ------------- ^^^^^^^^^^^^^ re-bound here @@ -611,7 +611,7 @@ LL | Self: Iterator, = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:257:34 + --> $DIR/duplicate.rs:263:34 | LL | type A: Iterator; | ---------- ^^^^^^^^^^ re-bound here @@ -619,7 +619,7 @@ LL | type A: Iterator; | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:257:34 + --> $DIR/duplicate.rs:263:34 | LL | type A: Iterator; | ---------- ^^^^^^^^^^ re-bound here @@ -629,7 +629,7 @@ LL | type A: Iterator; = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:262:34 + --> $DIR/duplicate.rs:268:34 | LL | type A: Iterator; | ---------- ^^^^^^^^^^ re-bound here @@ -637,7 +637,7 @@ LL | type A: Iterator; | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:262:34 + --> $DIR/duplicate.rs:268:34 | LL | type A: Iterator; | ---------- ^^^^^^^^^^ re-bound here @@ -647,7 +647,7 @@ LL | type A: Iterator; = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:267:37 + --> $DIR/duplicate.rs:273:37 | LL | type A: Iterator; | ------------- ^^^^^^^^^^^^^ re-bound here @@ -655,7 +655,7 @@ LL | type A: Iterator; | `Item` bound here first error[E0719]: the value of the associated type `Item` in trait `Iterator` is already specified - --> $DIR/duplicate.rs:267:37 + --> $DIR/duplicate.rs:273:37 | LL | type A: Iterator; | ------------- ^^^^^^^^^^^^^ re-bound here @@ -697,7 +697,55 @@ help: consider specifying the generic argument LL | iter::empty::() | +++++ -error: aborting due to 81 previous errors +error: unconstrained opaque type + --> $DIR/duplicate.rs:180:51 + | +LL | type ETAI1> = impl Copy; + | ^^^^^^^^^ + | + = note: `ETAI1` must be used in combination with a concrete type within the same crate + +error: unconstrained opaque type + --> $DIR/duplicate.rs:183:51 + | +LL | type ETAI2> = impl Copy; + | ^^^^^^^^^ + | + = note: `ETAI2` must be used in combination with a concrete type within the same crate + +error: unconstrained opaque type + --> $DIR/duplicate.rs:186:57 + | +LL | type ETAI3> = impl Copy; + | ^^^^^^^^^ + | + = note: `ETAI3` must be used in combination with a concrete type within the same crate + +error: unconstrained opaque type + --> $DIR/duplicate.rs:189:14 + | +LL | type ETAI4 = impl Iterator; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `ETAI4` must be used in combination with a concrete type within the same crate + +error: unconstrained opaque type + --> $DIR/duplicate.rs:193:14 + | +LL | type ETAI5 = impl Iterator; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `ETAI5` must be used in combination with a concrete type within the same crate + +error: unconstrained opaque type + --> $DIR/duplicate.rs:197:14 + | +LL | type ETAI6 = impl Iterator; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `ETAI6` must be used in combination with a concrete type within the same crate + +error: aborting due to 87 previous errors Some errors have detailed explanations: E0282, E0719. For more information about an error, try `rustc --explain E0282`. diff --git a/tests/ui/associated-type-bounds/trait-alias-impl-trait.rs b/tests/ui/associated-type-bounds/trait-alias-impl-trait.rs index fb6a4fcbe976..5b2f2a0848c7 100644 --- a/tests/ui/associated-type-bounds/trait-alias-impl-trait.rs +++ b/tests/ui/associated-type-bounds/trait-alias-impl-trait.rs @@ -31,6 +31,7 @@ impl Tr1 for S1 { } type Et1 = impl Tr1; +#[define_opaques(Et1)] fn def_et1() -> Et1 { S1 } @@ -39,6 +40,7 @@ pub fn use_et1() { } type Et2 = impl Tr1; +#[define_opaques(Et2)] fn def_et2() -> Et2 { S1 } @@ -47,6 +49,7 @@ pub fn use_et2() { } type Et3 = impl Tr1>>>; +#[define_opaques(Et3)] fn def_et3() -> Et3 { struct A; impl Tr1 for A { @@ -68,6 +71,7 @@ pub fn use_et3() { } type Et4 = impl Tr1 Tr2<'a>>; +#[define_opaques(Et4)] fn def_et4() -> Et4 { #[derive(Copy, Clone)] struct A; diff --git a/tests/ui/async-await/async-fn/impl-trait.rs b/tests/ui/async-await/async-fn/impl-trait.rs index f284de8981ad..d3777e1670f8 100644 --- a/tests/ui/async-await/async-fn/impl-trait.rs +++ b/tests/ui/async-await/async-fn/impl-trait.rs @@ -4,11 +4,14 @@ #![feature(type_alias_impl_trait)] type Tait = impl AsyncFn(); +#[define_opaques(Tait)] fn tait() -> Tait { || async {} } -fn foo(x: impl AsyncFn()) -> impl AsyncFn() { x } +fn foo(x: impl AsyncFn()) -> impl AsyncFn() { + x +} fn param() {} diff --git a/tests/ui/async-await/issues/issue-60655-latebound-regions.rs b/tests/ui/async-await/issues/issue-60655-latebound-regions.rs index 4a8b5af5769b..de359879546d 100644 --- a/tests/ui/async-await/issues/issue-60655-latebound-regions.rs +++ b/tests/ui/async-await/issues/issue-60655-latebound-regions.rs @@ -11,15 +11,17 @@ pub type Func = impl Sized; // Late bound region should be allowed to escape the function, since it's bound // in the type. +#[define_opaques(Func)] fn null_function_ptr() -> Func { None:: fn(&'a ())> } async fn async_nop(_: &u8) {} -pub type ServeFut = impl Future; +pub type ServeFut = impl Future; // Late bound regions occur in the coroutine witness type here. +#[define_opaques(ServeFut)] fn serve() -> ServeFut { async move { let x = 5; diff --git a/tests/ui/async-await/normalize-output-in-signature-deduction.rs b/tests/ui/async-await/normalize-output-in-signature-deduction.rs index 19d70c2c6eeb..500f23abcec6 100644 --- a/tests/ui/async-await/normalize-output-in-signature-deduction.rs +++ b/tests/ui/async-await/normalize-output-in-signature-deduction.rs @@ -13,6 +13,7 @@ pub trait Trait {} pub type TAIT = impl Trait; +#[define_opaques(TAIT)] async fn foo() -> TAIT { Foo } diff --git a/tests/ui/attributes/collapse-debuginfo-invalid.rs b/tests/ui/attributes/collapse-debuginfo-invalid.rs index d6b3554a5a81..cae79aee8f90 100644 --- a/tests/ui/attributes/collapse-debuginfo-invalid.rs +++ b/tests/ui/attributes/collapse-debuginfo-invalid.rs @@ -24,15 +24,15 @@ const BAR: u32 = 3; //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions fn foo() { let _ = #[collapse_debuginfo(yes)] || { }; -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions #[collapse_debuginfo(yes)] -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions let _ = 3; let _ = #[collapse_debuginfo(yes)] 3; -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions match (3, 4) { #[collapse_debuginfo(yes)] -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions _ => (), } } @@ -50,7 +50,7 @@ type Map = HashMap; //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions enum Foo { #[collapse_debuginfo(yes)] -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions Variant, } @@ -58,7 +58,7 @@ enum Foo { //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions struct Bar { #[collapse_debuginfo(yes)] -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions field: u32, } @@ -73,7 +73,7 @@ union Qux { //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions trait Foobar { #[collapse_debuginfo(yes)] -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions type Bar; } @@ -85,6 +85,7 @@ impl Foobar for Bar { type Bar = u32; } +#[define_opaques(AFoobar)] fn constraining() -> AFoobar { Bar { field: 3 } } @@ -93,11 +94,11 @@ fn constraining() -> AFoobar { //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions impl Bar { #[collapse_debuginfo(yes)] -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions const FOO: u32 = 3; #[collapse_debuginfo(yes)] -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions fn bar(&self) {} } diff --git a/tests/ui/attributes/collapse-debuginfo-invalid.stderr b/tests/ui/attributes/collapse-debuginfo-invalid.stderr index 70376f985cb1..081e4445a869 100644 --- a/tests/ui/attributes/collapse-debuginfo-invalid.stderr +++ b/tests/ui/attributes/collapse-debuginfo-invalid.stderr @@ -176,7 +176,7 @@ LL | type AFoobar = impl Foobar; | --------------------------- not a macro definition error: `collapse_debuginfo` attribute should be applied to macro definitions - --> $DIR/collapse-debuginfo-invalid.rs:92:1 + --> $DIR/collapse-debuginfo-invalid.rs:93:1 | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -200,7 +200,7 @@ LL | type Bar; | --------- not a macro definition error: `collapse_debuginfo` attribute should be applied to macro definitions - --> $DIR/collapse-debuginfo-invalid.rs:95:5 + --> $DIR/collapse-debuginfo-invalid.rs:96:5 | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -209,7 +209,7 @@ LL | const FOO: u32 = 3; | ------------------- not a macro definition error: `collapse_debuginfo` attribute should be applied to macro definitions - --> $DIR/collapse-debuginfo-invalid.rs:99:5 + --> $DIR/collapse-debuginfo-invalid.rs:100:5 | LL | #[collapse_debuginfo(yes)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/borrowck/overwrite-anon-late-param-regions.rs b/tests/ui/borrowck/overwrite-anon-late-param-regions.rs index 7b0f784068f6..f4e303cc0c73 100644 --- a/tests/ui/borrowck/overwrite-anon-late-param-regions.rs +++ b/tests/ui/borrowck/overwrite-anon-late-param-regions.rs @@ -6,6 +6,7 @@ #![feature(type_alias_impl_trait)] type Opaque2<'a> = impl Sized + 'a; +#[define_opaques(Opaque2)] fn test2() -> impl for<'a, 'b> Fn((&'a str, &'b str)) -> (Opaque2<'a>, Opaque2<'a>) { |x| x //~^ ERROR lifetime may not live long enough diff --git a/tests/ui/borrowck/overwrite-anon-late-param-regions.stderr b/tests/ui/borrowck/overwrite-anon-late-param-regions.stderr index c5b7284271e4..96b3ebf1eb49 100644 --- a/tests/ui/borrowck/overwrite-anon-late-param-regions.stderr +++ b/tests/ui/borrowck/overwrite-anon-late-param-regions.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/overwrite-anon-late-param-regions.rs:10:9 + --> $DIR/overwrite-anon-late-param-regions.rs:11:9 | LL | |x| x | - ^ closure was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` @@ -8,7 +8,7 @@ LL | |x| x | has type `(&'2 str, &str)` error[E0792]: expected generic lifetime parameter, found `'a` - --> $DIR/overwrite-anon-late-param-regions.rs:10:5 + --> $DIR/overwrite-anon-late-param-regions.rs:11:5 | LL | type Opaque2<'a> = impl Sized + 'a; | -- this generic parameter must be used with a generic lifetime parameter diff --git a/tests/ui/coherence/coherence-with-closure.rs b/tests/ui/coherence/coherence-with-closure.rs index 5b6a62b24d4b..9372bb9df117 100644 --- a/tests/ui/coherence/coherence-with-closure.rs +++ b/tests/ui/coherence/coherence-with-closure.rs @@ -1,6 +1,7 @@ // Test that encountering closures during coherence does not cause issues. #![feature(type_alias_impl_trait)] type OpaqueClosure = impl Sized; +#[define_opaques(OpaqueClosure)] fn defining_use() -> OpaqueClosure { || () } diff --git a/tests/ui/coherence/coherence-with-closure.stderr b/tests/ui/coherence/coherence-with-closure.stderr index 501279ffe6a7..37f393ceeb70 100644 --- a/tests/ui/coherence/coherence-with-closure.stderr +++ b/tests/ui/coherence/coherence-with-closure.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Trait` for type `Wrapper` - --> $DIR/coherence-with-closure.rs:11:1 + --> $DIR/coherence-with-closure.rs:12:1 | LL | impl Trait for Wrapper {} | ------------------------------------- first implementation here diff --git a/tests/ui/coherence/coherence-with-coroutine.rs b/tests/ui/coherence/coherence-with-coroutine.rs index 6b0617e950b7..a1cdf9a23db3 100644 --- a/tests/ui/coherence/coherence-with-coroutine.rs +++ b/tests/ui/coherence/coherence-with-coroutine.rs @@ -7,6 +7,7 @@ //@ [specialized]check-pass type OpaqueCoroutine = impl Sized; +#[define_opaques(OpaqueCoroutine)] fn defining_use() -> OpaqueCoroutine { #[coroutine] || { diff --git a/tests/ui/coherence/coherence-with-coroutine.stock.stderr b/tests/ui/coherence/coherence-with-coroutine.stock.stderr index 5f58b3088f14..c7af384df6d3 100644 --- a/tests/ui/coherence/coherence-with-coroutine.stock.stderr +++ b/tests/ui/coherence/coherence-with-coroutine.stock.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Trait` for type `Wrapper` - --> $DIR/coherence-with-coroutine.rs:22:1 + --> $DIR/coherence-with-coroutine.rs:23:1 | LL | impl Trait for Wrapper {} | --------------------------------------- first implementation here diff --git a/tests/ui/coherence/issue-99663-2.rs b/tests/ui/coherence/issue-99663-2.rs index 675e9fdfdba7..82f87776495e 100644 --- a/tests/ui/coherence/issue-99663-2.rs +++ b/tests/ui/coherence/issue-99663-2.rs @@ -8,6 +8,7 @@ struct Outer { type InnerSend = impl Send; +#[define_opaques(InnerSend)] fn constrain() -> InnerSend { () } diff --git a/tests/ui/coherence/issue-99663.rs b/tests/ui/coherence/issue-99663.rs index 00d15977d8f0..aef88f760696 100644 --- a/tests/ui/coherence/issue-99663.rs +++ b/tests/ui/coherence/issue-99663.rs @@ -8,6 +8,7 @@ struct Send { type InnerSend = impl Sized; +#[define_opaques(InnerSend)] fn constrain() -> InnerSend { () } diff --git a/tests/ui/coherence/occurs-check/opaques.current.stderr b/tests/ui/coherence/occurs-check/opaques.current.stderr index f3fc22027c26..d3850df52182 100644 --- a/tests/ui/coherence/occurs-check/opaques.current.stderr +++ b/tests/ui/coherence/occurs-check/opaques.current.stderr @@ -1,11 +1,11 @@ error[E0119]: conflicting implementations of trait `Trait<_>` - --> $DIR/opaques.rs:28:1 + --> $DIR/opaques.rs:27:1 | LL | impl Trait for T { | ---------------------- first implementation here ... -LL | impl Trait for defining_scope::Alias { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation +LL | impl Trait for Alias { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation error: aborting due to 1 previous error diff --git a/tests/ui/coherence/occurs-check/opaques.next.stderr b/tests/ui/coherence/occurs-check/opaques.next.stderr index 04fd139f901b..508e6f402342 100644 --- a/tests/ui/coherence/occurs-check/opaques.next.stderr +++ b/tests/ui/coherence/occurs-check/opaques.next.stderr @@ -1,17 +1,17 @@ error[E0119]: conflicting implementations of trait `Trait<_>` - --> $DIR/opaques.rs:28:1 + --> $DIR/opaques.rs:27:1 | LL | impl Trait for T { | ---------------------- first implementation here ... -LL | impl Trait for defining_scope::Alias { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation +LL | impl Trait for Alias { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation error[E0282]: type annotations needed - --> $DIR/opaques.rs:11:23 + --> $DIR/opaques.rs:11:19 | -LL | pub fn cast(x: Container, T>) -> Container { - | ^^^^^^^^^^^^^^^^^^^^^^ cannot infer type +LL | pub fn cast(x: Container, T>) -> Container { + | ^^^^^^^^^^^^^^^^^^^^^^ cannot infer type error: aborting due to 2 previous errors diff --git a/tests/ui/coherence/occurs-check/opaques.rs b/tests/ui/coherence/occurs-check/opaques.rs index e197256c78c7..03f96a48d5b9 100644 --- a/tests/ui/coherence/occurs-check/opaques.rs +++ b/tests/ui/coherence/occurs-check/opaques.rs @@ -4,14 +4,13 @@ // A regression test for #105787 #![feature(type_alias_impl_trait)] -mod defining_scope { - use super::*; - pub type Alias = impl Sized; - pub fn cast(x: Container, T>) -> Container { - //[next]~^ ERROR type annotations needed - x - } +pub type Alias = impl Sized; + +#[define_opaques(Alias)] +pub fn cast(x: Container, T>) -> Container { + //[next]~^ ERROR type annotations needed + x } struct Container, U> { @@ -25,12 +24,12 @@ trait Trait { impl Trait for T { type Assoc = Box; } -impl Trait for defining_scope::Alias { +impl Trait for Alias { //~^ ERROR conflicting implementations of trait type Assoc = usize; } fn main() { - let x: Box = defining_scope::cast::<()>(Container { x: 0 }).x; + let x: Box = cast::<()>(Container { x: 0 }).x; println!("{}", *x); } diff --git a/tests/ui/coherence/orphan-check-opaque-types-not-covering.rs b/tests/ui/coherence/orphan-check-opaque-types-not-covering.rs index 02e9eb65570c..f68dfd7d76c4 100644 --- a/tests/ui/coherence/orphan-check-opaque-types-not-covering.rs +++ b/tests/ui/coherence/orphan-check-opaque-types-not-covering.rs @@ -7,6 +7,7 @@ type Identity = impl Sized; +#[define_opaques(Identity)] fn define_identity(x: T) -> Identity { x } @@ -16,6 +17,7 @@ impl foreign::Trait0 for Identity {} type Opaque = impl Sized; +#[define_opaques(Opaque)] fn define_local() -> Opaque { Local } diff --git a/tests/ui/coherence/orphan-check-opaque-types-not-covering.stderr b/tests/ui/coherence/orphan-check-opaque-types-not-covering.stderr index 57f5bbd22787..6203742b47c0 100644 --- a/tests/ui/coherence/orphan-check-opaque-types-not-covering.stderr +++ b/tests/ui/coherence/orphan-check-opaque-types-not-covering.stderr @@ -1,5 +1,5 @@ error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`) - --> $DIR/orphan-check-opaque-types-not-covering.rs:14:6 + --> $DIR/orphan-check-opaque-types-not-covering.rs:15:6 | LL | impl foreign::Trait0 for Identity {} | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) @@ -8,7 +8,7 @@ LL | impl foreign::Trait0 for Identity {} = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait for T0`, where `T0` is the first and `Tn` is the last error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Local`) - --> $DIR/orphan-check-opaque-types-not-covering.rs:23:6 + --> $DIR/orphan-check-opaque-types-not-covering.rs:25:6 | LL | impl foreign::Trait1 for Opaque {} | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Local`) diff --git a/tests/ui/const-generics/generic_const_exprs/opaque_type.rs b/tests/ui/const-generics/generic_const_exprs/opaque_type.rs index 56b8acbf88cd..d64946e9e142 100644 --- a/tests/ui/const-generics/generic_const_exprs/opaque_type.rs +++ b/tests/ui/const-generics/generic_const_exprs/opaque_type.rs @@ -3,14 +3,14 @@ type Foo = impl Sized; -fn with_bound() -> Foo +#[define_opaques(Foo)] +fn with_bound() where [u8; (N / 2) as usize]: Sized, { let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize]; //~^ ERROR mismatched types //~| ERROR non-primitive cast: `usize` as `Foo` - todo!() } fn main() { diff --git a/tests/ui/const-generics/generic_const_exprs/opaque_type.stderr b/tests/ui/const-generics/generic_const_exprs/opaque_type.stderr index e9fb8c0f403a..9f48a8563c8a 100644 --- a/tests/ui/const-generics/generic_const_exprs/opaque_type.stderr +++ b/tests/ui/const-generics/generic_const_exprs/opaque_type.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/opaque_type.rs:10:17 + --> $DIR/opaque_type.rs:11:17 | LL | type Foo = impl Sized; | ---------- the found opaque type @@ -11,7 +11,7 @@ LL | let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize]; found opaque type `Foo` error[E0605]: non-primitive cast: `usize` as `Foo` - --> $DIR/opaque_type.rs:10:17 + --> $DIR/opaque_type.rs:11:17 | LL | let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize]; | ^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object diff --git a/tests/ui/const-generics/opaque_types.rs b/tests/ui/const-generics/opaque_types.rs index 2c7170c889fb..f24ca965cf86 100644 --- a/tests/ui/const-generics/opaque_types.rs +++ b/tests/ui/const-generics/opaque_types.rs @@ -1,9 +1,8 @@ #![feature(type_alias_impl_trait)] type Foo = impl Sized; -//~^ ERROR: cycle -//~| ERROR: cycle +#[define_opaques(Foo)] fn foo() {} //~^ ERROR: `Foo` is forbidden as the type of a const generic parameter //~| ERROR: item does not constrain diff --git a/tests/ui/const-generics/opaque_types.stderr b/tests/ui/const-generics/opaque_types.stderr index a060488b3287..ec7cd2b19960 100644 --- a/tests/ui/const-generics/opaque_types.stderr +++ b/tests/ui/const-generics/opaque_types.stderr @@ -1,5 +1,5 @@ error: `Foo` is forbidden as the type of a const generic parameter - --> $DIR/opaque_types.rs:7:17 + --> $DIR/opaque_types.rs:6:17 | LL | fn foo() {} | ^^^ @@ -7,7 +7,7 @@ LL | fn foo() {} = note: the only supported types are integers, `bool`, and `char` error: item does not constrain `Foo::{opaque#0}`, but has it in its signature - --> $DIR/opaque_types.rs:7:4 + --> $DIR/opaque_types.rs:6:4 | LL | fn foo() {} | ^^^ @@ -20,7 +20,7 @@ LL | type Foo = impl Sized; | ^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/opaque_types.rs:12:11 + --> $DIR/opaque_types.rs:11:11 | LL | type Foo = impl Sized; | ---------- the expected opaque type @@ -31,106 +31,6 @@ LL | foo::<42>(); = note: expected opaque type `Foo` found type `{integer}` -error[E0391]: cycle detected when computing type of `Foo::{opaque#0}` - --> $DIR/opaque_types.rs:3:12 - | -LL | type Foo = impl Sized; - | ^^^^^^^^^^ - | -note: ...which requires computing type of opaque `Foo::{opaque#0}`... - --> $DIR/opaque_types.rs:3:12 - | -LL | type Foo = impl Sized; - | ^^^^^^^^^^ -note: ...which requires type-checking `main`... - --> $DIR/opaque_types.rs:11:1 - | -LL | fn main() { - | ^^^^^^^^^ -note: ...which requires evaluating type-level constant... - --> $DIR/opaque_types.rs:12:11 - | -LL | foo::<42>(); - | ^^ -note: ...which requires const-evaluating + checking `main::{constant#0}`... - --> $DIR/opaque_types.rs:12:11 - | -LL | foo::<42>(); - | ^^ -note: ...which requires caching mir of `main::{constant#0}` for CTFE... - --> $DIR/opaque_types.rs:12:11 - | -LL | foo::<42>(); - | ^^ -note: ...which requires elaborating drops for `main::{constant#0}`... - --> $DIR/opaque_types.rs:12:11 - | -LL | foo::<42>(); - | ^^ - = note: ...which requires normalizing `Foo`... - = note: ...which again requires computing type of `Foo::{opaque#0}`, completing the cycle -note: cycle used when checking that `Foo::{opaque#0}` is well-formed - --> $DIR/opaque_types.rs:3:12 - | -LL | type Foo = impl Sized; - | ^^^^^^^^^^ - = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information - -error[E0391]: cycle detected when computing type of opaque `Foo::{opaque#0}` - --> $DIR/opaque_types.rs:3:12 - | -LL | type Foo = impl Sized; - | ^^^^^^^^^^ - | -note: ...which requires type-checking `main`... - --> $DIR/opaque_types.rs:11:1 - | -LL | fn main() { - | ^^^^^^^^^ -note: ...which requires evaluating type-level constant... - --> $DIR/opaque_types.rs:12:11 - | -LL | foo::<42>(); - | ^^ -note: ...which requires const-evaluating + checking `main::{constant#0}`... - --> $DIR/opaque_types.rs:12:11 - | -LL | foo::<42>(); - | ^^ -note: ...which requires caching mir of `main::{constant#0}` for CTFE... - --> $DIR/opaque_types.rs:12:11 - | -LL | foo::<42>(); - | ^^ -note: ...which requires elaborating drops for `main::{constant#0}`... - --> $DIR/opaque_types.rs:12:11 - | -LL | foo::<42>(); - | ^^ -note: ...which requires borrow-checking `main::{constant#0}`... - --> $DIR/opaque_types.rs:12:11 - | -LL | foo::<42>(); - | ^^ -note: ...which requires promoting constants in MIR for `main::{constant#0}`... - --> $DIR/opaque_types.rs:12:11 - | -LL | foo::<42>(); - | ^^ -note: ...which requires const checking `main::{constant#0}`... - --> $DIR/opaque_types.rs:12:11 - | -LL | foo::<42>(); - | ^^ - = note: ...which again requires computing type of opaque `Foo::{opaque#0}`, completing the cycle -note: cycle used when computing type of `Foo::{opaque#0}` - --> $DIR/opaque_types.rs:3:12 - | -LL | type Foo = impl Sized; - | ^^^^^^^^^^ - = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information - -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0308, E0391. -For more information about an error, try `rustc --explain E0308`. +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/opaque_types2.rs b/tests/ui/const-generics/opaque_types2.rs index fd57438bb617..e4cf84c6a41b 100644 --- a/tests/ui/const-generics/opaque_types2.rs +++ b/tests/ui/const-generics/opaque_types2.rs @@ -4,13 +4,14 @@ type Foo = impl Sized; fn foo() {} -const C: Foo = 42; +#[define_opaques(Foo)] +const fn baz() -> Foo { + 42 +} -fn bar() -where - Foo:, -{ - foo::(); +#[define_opaques(Foo)] +fn bar() { + foo::<{ baz() }>(); //~^ ERROR: mismatched types } diff --git a/tests/ui/const-generics/opaque_types2.stderr b/tests/ui/const-generics/opaque_types2.stderr index 2fb1669b7bfa..98d96c3ccee3 100644 --- a/tests/ui/const-generics/opaque_types2.stderr +++ b/tests/ui/const-generics/opaque_types2.stderr @@ -1,11 +1,11 @@ error[E0308]: mismatched types - --> $DIR/opaque_types2.rs:13:11 + --> $DIR/opaque_types2.rs:14:13 | LL | type Foo = impl Sized; | ---------- the found opaque type ... -LL | foo::(); - | ^ expected `u32`, found opaque type +LL | foo::<{ baz() }>(); + | ^^^^^ expected `u32`, found opaque type | = note: expected type `u32` found opaque type `Foo` diff --git a/tests/ui/consts/const-eval/ice-unhandled-type-122191.rs b/tests/ui/consts/const-eval/ice-unhandled-type-122191.rs index a92b99976e26..9f77ddf371df 100644 --- a/tests/ui/consts/const-eval/ice-unhandled-type-122191.rs +++ b/tests/ui/consts/const-eval/ice-unhandled-type-122191.rs @@ -3,14 +3,20 @@ type Foo = impl Send; struct A; -const VALUE: Foo = value(); -//~^ ERROR cannot find function `value` in this scope +#[define_opaques(Foo)] +//~^ ERROR unstable library feature +const fn foo() -> Foo { + value() + //~^ ERROR cannot find function `value` in this scope +} + +const VALUE: Foo = foo(); fn test() { match VALUE { 0 | 0 => {} -//~^ ERROR mismatched types -//~| ERROR mismatched types + //~^ ERROR mismatched types + //~| ERROR mismatched types _ => (), } } diff --git a/tests/ui/consts/const-eval/ice-unhandled-type-122191.stderr b/tests/ui/consts/const-eval/ice-unhandled-type-122191.stderr index daf0ccaa776c..eeb35c37a156 100644 --- a/tests/ui/consts/const-eval/ice-unhandled-type-122191.stderr +++ b/tests/ui/consts/const-eval/ice-unhandled-type-122191.stderr @@ -1,3 +1,13 @@ +error[E0658]: use of unstable library feature `type_alias_impl_trait`: `type_alias_impl_trait` has open design concerns + --> $DIR/ice-unhandled-type-122191.rs:6:3 + | +LL | #[define_opaques(Foo)] + | ^^^^^^^^^^^^^^ + | + = note: see issue #63063 for more information + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + error[E0658]: `impl Trait` in type aliases is unstable --> $DIR/ice-unhandled-type-122191.rs:1:12 | @@ -9,13 +19,16 @@ LL | type Foo = impl Send; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0425]: cannot find function `value` in this scope - --> $DIR/ice-unhandled-type-122191.rs:6:20 + --> $DIR/ice-unhandled-type-122191.rs:9:5 | -LL | const VALUE: Foo = value(); - | ^^^^^ not found in this scope +LL | value() + | ^^^^^ help: a constant with a similar name exists: `VALUE` +... +LL | const VALUE: Foo = foo(); + | ------------------------- similarly named constant `VALUE` defined here error[E0308]: mismatched types - --> $DIR/ice-unhandled-type-122191.rs:11:9 + --> $DIR/ice-unhandled-type-122191.rs:17:9 | LL | type Foo = impl Send; | --------- the expected opaque type @@ -27,14 +40,14 @@ LL | 0 | 0 => {} | = note: expected opaque type `Foo` found type `{integer}` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/ice-unhandled-type-122191.rs:9:4 +note: this item must have a `#[define_opaques(Foo)]` attribute to be able to define hidden types + --> $DIR/ice-unhandled-type-122191.rs:15:4 | LL | fn test() { | ^^^^ error[E0308]: mismatched types - --> $DIR/ice-unhandled-type-122191.rs:11:13 + --> $DIR/ice-unhandled-type-122191.rs:17:13 | LL | type Foo = impl Send; | --------- the expected opaque type @@ -46,13 +59,13 @@ LL | 0 | 0 => {} | = note: expected opaque type `Foo` found type `{integer}` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/ice-unhandled-type-122191.rs:9:4 +note: this item must have a `#[define_opaques(Foo)]` attribute to be able to define hidden types + --> $DIR/ice-unhandled-type-122191.rs:15:4 | LL | fn test() { | ^^^^ -error: aborting due to 4 previous errors +error: aborting due to 5 previous errors Some errors have detailed explanations: E0308, E0425, E0658. For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/consts/const-promoted-opaque.atomic.stderr b/tests/ui/consts/const-promoted-opaque.atomic.stderr index b9d5cbf801a8..9c0c969d586c 100644 --- a/tests/ui/consts/const-promoted-opaque.atomic.stderr +++ b/tests/ui/consts/const-promoted-opaque.atomic.stderr @@ -1,5 +1,5 @@ -error[E0493]: destructor of `helper::Foo` cannot be evaluated at compile-time - --> $DIR/const-promoted-opaque.rs:28:26 +error[E0493]: destructor of `Foo` cannot be evaluated at compile-time + --> $DIR/const-promoted-opaque.rs:32:26 | LL | let _: &'static _ = &FOO; | ^^^ the destructor for this type cannot be evaluated in constants @@ -8,13 +8,13 @@ LL | }; | - value is dropped here error[E0492]: constants cannot refer to interior mutable data - --> $DIR/const-promoted-opaque.rs:32:19 + --> $DIR/const-promoted-opaque.rs:36:19 | LL | const BAZ: &Foo = &FOO; | ^^^^ this borrow of an interior mutable value may end up in the final value error[E0716]: temporary value dropped while borrowed - --> $DIR/const-promoted-opaque.rs:36:26 + --> $DIR/const-promoted-opaque.rs:40:26 | LL | let _: &'static _ = &FOO; | ---------- ^^^ creates a temporary value which is freed while still in use diff --git a/tests/ui/consts/const-promoted-opaque.rs b/tests/ui/consts/const-promoted-opaque.rs index bb33e92778aa..6e12a4bd47b0 100644 --- a/tests/ui/consts/const-promoted-opaque.rs +++ b/tests/ui/consts/const-promoted-opaque.rs @@ -8,25 +8,29 @@ //! hidden type of the opaque type. Thus we ended up relying on the //! result of our analysis to compute the result of our analysis. -//@[unit] check-pass +pub type Foo = impl Sized; -mod helper { - pub type Foo = impl Sized; +#[cfg(string)] +#[define_opaques(Foo)] +const fn foo() -> Foo { + String::new() +} - #[cfg(string)] - pub const FOO: Foo = String::new(); +#[cfg(atomic)] +#[define_opaques(Foo)] +const fn foo() -> Foo { + std::sync::atomic::AtomicU8::new(42) +} - #[cfg(atomic)] - pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42); +#[cfg(unit)] +#[define_opaques(Foo)] +const fn foo() -> Foo {} - #[cfg(unit)] - pub const FOO: Foo = (); -} -use helper::*; +const FOO: Foo = foo(); const BAR: () = { let _: &'static _ = &FOO; - //[string,atomic]~^ ERROR: destructor of `helper::Foo` cannot be evaluated at compile-time + //[string,atomic,unit]~^ ERROR: destructor of `Foo` cannot be evaluated at compile-time }; const BAZ: &Foo = &FOO; @@ -34,5 +38,5 @@ const BAZ: &Foo = &FOO; fn main() { let _: &'static _ = &FOO; - //[string,atomic]~^ ERROR: temporary value dropped while borrowed + //[string,atomic,unit]~^ ERROR: temporary value dropped while borrowed } diff --git a/tests/ui/consts/const-promoted-opaque.string.stderr b/tests/ui/consts/const-promoted-opaque.string.stderr index 33e5f426448c..847a466f21c5 100644 --- a/tests/ui/consts/const-promoted-opaque.string.stderr +++ b/tests/ui/consts/const-promoted-opaque.string.stderr @@ -1,5 +1,5 @@ -error[E0493]: destructor of `helper::Foo` cannot be evaluated at compile-time - --> $DIR/const-promoted-opaque.rs:28:26 +error[E0493]: destructor of `Foo` cannot be evaluated at compile-time + --> $DIR/const-promoted-opaque.rs:32:26 | LL | let _: &'static _ = &FOO; | ^^^ the destructor for this type cannot be evaluated in constants @@ -8,7 +8,7 @@ LL | }; | - value is dropped here error[E0716]: temporary value dropped while borrowed - --> $DIR/const-promoted-opaque.rs:36:26 + --> $DIR/const-promoted-opaque.rs:40:26 | LL | let _: &'static _ = &FOO; | ---------- ^^^ creates a temporary value which is freed while still in use diff --git a/tests/ui/consts/const-promoted-opaque.unit.stderr b/tests/ui/consts/const-promoted-opaque.unit.stderr new file mode 100644 index 000000000000..847a466f21c5 --- /dev/null +++ b/tests/ui/consts/const-promoted-opaque.unit.stderr @@ -0,0 +1,24 @@ +error[E0493]: destructor of `Foo` cannot be evaluated at compile-time + --> $DIR/const-promoted-opaque.rs:32:26 + | +LL | let _: &'static _ = &FOO; + | ^^^ the destructor for this type cannot be evaluated in constants +LL | +LL | }; + | - value is dropped here + +error[E0716]: temporary value dropped while borrowed + --> $DIR/const-promoted-opaque.rs:40:26 + | +LL | let _: &'static _ = &FOO; + | ---------- ^^^ creates a temporary value which is freed while still in use + | | + | type annotation requires that borrow lasts for `'static` +LL | +LL | } + | - temporary value is freed at the end of this statement + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0493, E0716. +For more information about an error, try `rustc --explain E0493`. diff --git a/tests/ui/consts/required-consts/collect-in-dead-fn-behind-opaque-type.rs b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-opaque-type.rs index 795e021ceb08..f53714323a69 100644 --- a/tests/ui/consts/required-consts/collect-in-dead-fn-behind-opaque-type.rs +++ b/tests/ui/consts/required-consts/collect-in-dead-fn-behind-opaque-type.rs @@ -20,6 +20,7 @@ mod m { } } + #[define_opaques(NotCalledFn)] fn mk_not_called() -> NotCalledFn { not_called:: } diff --git a/tests/ui/coroutine/layout-error.rs b/tests/ui/coroutine/layout-error.rs index 3e26cf17d29e..13973a4f6251 100644 --- a/tests/ui/coroutine/layout-error.rs +++ b/tests/ui/coroutine/layout-error.rs @@ -16,22 +16,20 @@ impl Task { } } -mod helper { - use super::*; - pub type F = impl Future; - fn foo() - where - F:, - { - async fn cb() { - let a = Foo; //~ ERROR cannot find value `Foo` in this scope - } - - Task::spawn(&POOL, || cb()); +pub type F = impl Future; +#[define_opaques(F)] +fn foo() +where + F:, +{ + async fn cb() { + let a = Foo; //~ ERROR cannot find value `Foo` in this scope } + + Task::spawn(&POOL, || cb()); } // Check that statics are inhabited computes they layout. -static POOL: Task = Task::new(); +static POOL: Task = Task::new(); fn main() {} diff --git a/tests/ui/coroutine/layout-error.stderr b/tests/ui/coroutine/layout-error.stderr index ceadb62c9998..91e352164357 100644 --- a/tests/ui/coroutine/layout-error.stderr +++ b/tests/ui/coroutine/layout-error.stderr @@ -1,8 +1,8 @@ error[E0425]: cannot find value `Foo` in this scope - --> $DIR/layout-error.rs:27:21 + --> $DIR/layout-error.rs:26:17 | -LL | let a = Foo; - | ^^^ not found in this scope +LL | let a = Foo; + | ^^^ not found in this scope error: aborting due to 1 previous error diff --git a/tests/ui/coroutine/metadata-sufficient-for-layout.rs b/tests/ui/coroutine/metadata-sufficient-for-layout.rs index 9c3a7e4378e3..1d0945b7a6b9 100644 --- a/tests/ui/coroutine/metadata-sufficient-for-layout.rs +++ b/tests/ui/coroutine/metadata-sufficient-for-layout.rs @@ -15,6 +15,7 @@ mod helper { use std::ops::Coroutine; pub type F = impl Coroutine<(), Yield = (), Return = ()>; + #[define_opaques(F)] fn f() -> F { metadata_sufficient_for_layout::g() } diff --git a/tests/ui/drop/drop_elaboration_with_errors.rs b/tests/ui/drop/drop_elaboration_with_errors.rs index 35d05e6cf64a..a779a1ca7582 100644 --- a/tests/ui/drop/drop_elaboration_with_errors.rs +++ b/tests/ui/drop/drop_elaboration_with_errors.rs @@ -10,6 +10,7 @@ struct Foo { type Tait = impl Sized; +#[define_opaques(Tait)] fn ice_cold(beverage: Tait) { let Foo { field } = beverage; _ = field; diff --git a/tests/ui/drop/drop_elaboration_with_errors.stderr b/tests/ui/drop/drop_elaboration_with_errors.stderr index bec229631e18..ea2c9b949e42 100644 --- a/tests/ui/drop/drop_elaboration_with_errors.stderr +++ b/tests/ui/drop/drop_elaboration_with_errors.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/drop_elaboration_with_errors.rs:19:5 + --> $DIR/drop_elaboration_with_errors.rs:20:5 | LL | fn main() { | - expected `()` because of default return type diff --git a/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs b/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs index d0be240e07ba..17e0fe66af4e 100644 --- a/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs +++ b/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs @@ -4,7 +4,11 @@ pub mod foo { type MainFn = impl Fn(); fn bar() {} - pub const BAR: MainFn = bar; + #[define_opaques(MainFn)] + const fn def() -> MainFn { + bar + } + pub const BAR: MainFn = def(); } use foo::BAR as main; //~ ERROR `main` function not found in crate diff --git a/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr b/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr index 50e4cd7d39f7..375b3a53030a 100644 --- a/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr +++ b/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.stderr @@ -1,5 +1,5 @@ error[E0601]: `main` function not found in crate `imported_main_const_fn_item_type_forbidden` - --> $DIR/imported_main_const_fn_item_type_forbidden.rs:10:22 + --> $DIR/imported_main_const_fn_item_type_forbidden.rs:14:22 | LL | use foo::BAR as main; | ---------------- ^ consider adding a `main` function to `$DIR/imported_main_const_fn_item_type_forbidden.rs` diff --git a/tests/ui/feature-gates/feature-gate-type_alias_impl_trait.rs b/tests/ui/feature-gates/feature-gate-type_alias_impl_trait.rs index 6d17f5e837d9..5ac8bdc1198e 100644 --- a/tests/ui/feature-gates/feature-gate-type_alias_impl_trait.rs +++ b/tests/ui/feature-gates/feature-gate-type_alias_impl_trait.rs @@ -5,27 +5,32 @@ use std::fmt::Debug; type Foo = impl Debug; struct Bar(Foo); +#[define_opaques(Foo)] fn define() -> Bar { Bar(42) } type Foo2 = impl Debug; -fn define2(_: Foo2) { +#[define_opaques(Foo2)] +fn define2() { let x = || -> Foo2 { 42 }; } type Foo3 = impl Debug; +#[define_opaques(Foo3)] fn define3(x: Foo3) { let y: i32 = x; } -fn define3_1(_: Foo3) { +#[define_opaques(Foo3)] +fn define3_1() { define3(42) } type Foo4 = impl Debug; +#[define_opaques(Foo4)] fn define4(_: Foo4) { let y: Foo4 = 42; } diff --git a/tests/ui/fn/fn_def_opaque_coercion.rs b/tests/ui/fn/fn_def_opaque_coercion.rs index 0a8810cf4f8a..97deea7881ba 100644 --- a/tests/ui/fn/fn_def_opaque_coercion.rs +++ b/tests/ui/fn/fn_def_opaque_coercion.rs @@ -11,6 +11,7 @@ fn foo(t: T) -> T { type F = impl Sized; +#[define_opaques(F)] fn f(a: F) { let mut x = foo::; x = foo::<()>; @@ -20,6 +21,7 @@ fn f(a: F) { type G = impl Sized; +#[define_opaques(G)] fn g(a: G) { let x = foo::<()>; let _: () = x(a); @@ -27,6 +29,7 @@ fn g(a: G) { type H = impl Sized; +#[define_opaques(H)] fn h(a: H) { let x = foo::; let _: H = x(()); @@ -34,6 +37,7 @@ fn h(a: H) { type I = impl Sized; +#[define_opaques(I)] fn i(a: I) { let mut x = foo::<()>; x = foo::; @@ -43,6 +47,7 @@ fn i(a: I) { type J = impl Sized; +#[define_opaques(J)] fn j(a: J) { let x = match true { true => foo::, diff --git a/tests/ui/fn/fn_def_opaque_coercion_to_fn_ptr.rs b/tests/ui/fn/fn_def_opaque_coercion_to_fn_ptr.rs index 5250e3a3d93e..70a8567c9257 100644 --- a/tests/ui/fn/fn_def_opaque_coercion_to_fn_ptr.rs +++ b/tests/ui/fn/fn_def_opaque_coercion_to_fn_ptr.rs @@ -13,6 +13,7 @@ fn bar(t: T) -> T { type F = impl Sized; +#[define_opaques(F)] fn f(a: F) { let mut x = bar::; x = foo::<()>; //~ ERROR: mismatched types @@ -22,6 +23,7 @@ fn f(a: F) { type I = impl Sized; +#[define_opaques(I)] fn i(a: I) { let mut x = bar::<()>; x = foo::; //~ ERROR: mismatched types @@ -31,6 +33,7 @@ fn i(a: I) { type J = impl Sized; +#[define_opaques(J)] fn j(a: J) { let x = match true { true => bar::, diff --git a/tests/ui/fn/fn_def_opaque_coercion_to_fn_ptr.stderr b/tests/ui/fn/fn_def_opaque_coercion_to_fn_ptr.stderr index 5000601e90f8..4a0991d0eb3c 100644 --- a/tests/ui/fn/fn_def_opaque_coercion_to_fn_ptr.stderr +++ b/tests/ui/fn/fn_def_opaque_coercion_to_fn_ptr.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/fn_def_opaque_coercion_to_fn_ptr.rs:18:9 + --> $DIR/fn_def_opaque_coercion_to_fn_ptr.rs:19:9 | LL | type F = impl Sized; | ---------- the expected opaque type @@ -13,7 +13,7 @@ LL | x = foo::<()>; found fn item `fn(()) -> () {foo::<()>}` error[E0308]: mismatched types - --> $DIR/fn_def_opaque_coercion_to_fn_ptr.rs:27:9 + --> $DIR/fn_def_opaque_coercion_to_fn_ptr.rs:29:9 | LL | fn foo(t: T) -> T { | -------------------- function `foo` defined here diff --git a/tests/ui/generic-associated-types/issue-87258_b.rs b/tests/ui/generic-associated-types/issue-87258_b.rs index 7b7610b21c7d..2763b0ffabe3 100644 --- a/tests/ui/generic-associated-types/issue-87258_b.rs +++ b/tests/ui/generic-associated-types/issue-87258_b.rs @@ -18,6 +18,7 @@ type Helper<'xenon, 'yttrium, KABOOM: Trait2> = impl Trait1; impl<'c, S: Trait2> Trait2 for &'c mut S { type FooFuture<'a> = Helper<'c, 'a, S>; + #[define_opaques(Helper)] fn foo<'a>() -> Self::FooFuture<'a> { Struct(unimplemented!()) } diff --git a/tests/ui/generic-associated-types/issue-87258_b.stderr b/tests/ui/generic-associated-types/issue-87258_b.stderr index 73f984dcfb86..906ce1f50da7 100644 --- a/tests/ui/generic-associated-types/issue-87258_b.stderr +++ b/tests/ui/generic-associated-types/issue-87258_b.stderr @@ -4,7 +4,7 @@ error: unconstrained opaque type LL | type Helper<'xenon, 'yttrium, KABOOM: Trait2> = impl Trait1; | ^^^^^^^^^^^ | - = note: `Helper` must be used in combination with a concrete type within the same module + = note: `Helper` must be used in combination with a concrete type within the same crate error: aborting due to 1 previous error diff --git a/tests/ui/generic-associated-types/issue-88287.rs b/tests/ui/generic-associated-types/issue-88287.rs index 5d64ad8eeae0..5246bbbb8a48 100644 --- a/tests/ui/generic-associated-types/issue-88287.rs +++ b/tests/ui/generic-associated-types/issue-88287.rs @@ -30,6 +30,7 @@ where A: SearchableResource + ?Sized + 'f, Self: 'f; + #[define_opaques(SearchFutureTy)] fn search<'c>(&'c self, _client: &'c ()) -> Self::Future<'c, Self, Criteria> { async move { todo!() } //~^ ERROR: the size for values of type `A` cannot be known at compilation time diff --git a/tests/ui/generic-associated-types/issue-88287.stderr b/tests/ui/generic-associated-types/issue-88287.stderr index 54ecc5cfcd81..71cd6677e63f 100644 --- a/tests/ui/generic-associated-types/issue-88287.stderr +++ b/tests/ui/generic-associated-types/issue-88287.stderr @@ -1,5 +1,5 @@ error[E0277]: the size for values of type `A` cannot be known at compilation time - --> $DIR/issue-88287.rs:34:9 + --> $DIR/issue-88287.rs:35:9 | LL | type SearchFutureTy<'f, A, B: 'f> | - this type parameter needs to be `Sized` diff --git a/tests/ui/generic-associated-types/issue-90014-tait.stderr b/tests/ui/generic-associated-types/issue-90014-tait.stderr index 09c2903ab028..b76896ba704e 100644 --- a/tests/ui/generic-associated-types/issue-90014-tait.stderr +++ b/tests/ui/generic-associated-types/issue-90014-tait.stderr @@ -1,3 +1,11 @@ +error: unconstrained opaque type + --> $DIR/issue-90014-tait.rs:15:20 + | +LL | type Fut<'a> = impl Future; + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `Fut` must be used in combination with a concrete type within the same impl + error[E0308]: mismatched types --> $DIR/issue-90014-tait.rs:18:9 | @@ -11,12 +19,12 @@ LL | async { () } | = note: expected opaque type `Foo<'_>::Fut<'a>` found `async` block `{async block@$DIR/issue-90014-tait.rs:18:9: 18:14}` -note: this item must have the opaque type in its signature in order to be able to register hidden types +note: this item must have a `#[define_opaques(Foo<'_>::Fut)]` attribute to be able to define hidden types --> $DIR/issue-90014-tait.rs:17:8 | LL | fn make_fut<'a>(&'a self) -> Self::Fut<'a> { | ^^^^^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/generic-associated-types/issue-90014-tait2.rs b/tests/ui/generic-associated-types/issue-90014-tait2.rs index 3f7a9ff63c31..347e4969eddf 100644 --- a/tests/ui/generic-associated-types/issue-90014-tait2.rs +++ b/tests/ui/generic-associated-types/issue-90014-tait2.rs @@ -20,6 +20,7 @@ impl<'x, T: 'x> Trait<'x> for (T,) { } impl Foo<'_> { + #[define_opaques(Fut)] fn make_fut(&self) -> Box Trait<'a, Thing = Fut<'a>>> { Box::new((async { () },)) //~^ ERROR expected generic lifetime parameter, found `'a` diff --git a/tests/ui/generic-associated-types/issue-90014-tait2.stderr b/tests/ui/generic-associated-types/issue-90014-tait2.stderr index aa427d42649a..bf944aac7975 100644 --- a/tests/ui/generic-associated-types/issue-90014-tait2.stderr +++ b/tests/ui/generic-associated-types/issue-90014-tait2.stderr @@ -1,5 +1,5 @@ error[E0792]: expected generic lifetime parameter, found `'a` - --> $DIR/issue-90014-tait2.rs:24:9 + --> $DIR/issue-90014-tait2.rs:25:9 | LL | type Fut<'a> = impl Future; | -- this generic parameter must be used with a generic lifetime parameter diff --git a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.old.stderr b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.old.stderr index 57cbe1691182..6306d2e68c88 100644 --- a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.old.stderr +++ b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.old.stderr @@ -1,5 +1,5 @@ error: item does not constrain `Foo::{opaque#0}`, but has it in its signature - --> $DIR/norm-before-method-resolution-opaque-type.rs:16:4 + --> $DIR/norm-before-method-resolution-opaque-type.rs:17:4 | LL | fn weird_bound(x: &>::Out) -> X | ^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL | type Foo = impl Sized; | ^^^^^^^^^^ error[E0507]: cannot move out of `*x` which is behind a shared reference - --> $DIR/norm-before-method-resolution-opaque-type.rs:22:13 + --> $DIR/norm-before-method-resolution-opaque-type.rs:23:13 | LL | let x = *x; | ^^ move occurs because `*x` has type `>::Out`, which does not implement the `Copy` trait diff --git a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs index 43207d892764..fdf423126d15 100644 --- a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs +++ b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.rs @@ -13,6 +13,7 @@ impl<'a, T> Trait<'a> for T { type Foo = impl Sized; +#[define_opaques(Foo)] fn weird_bound(x: &>::Out) -> X //[old]~^ ERROR: item does not constrain where diff --git a/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness-2.rs b/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness-2.rs index 65e90c1ca53c..3f72e2a896f9 100644 --- a/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness-2.rs +++ b/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness-2.rs @@ -11,6 +11,7 @@ unsafe impl Send for MyTy<'_, 'static> {} pub mod step1 { use super::*; pub type Step1<'a, 'b: 'a> = impl Sized + Captures<'b> + 'a; + #[define_opaques(Step1)] pub fn step1<'a, 'b: 'a>() -> Step1<'a, 'b> { MyTy::<'a, 'b>(None) } @@ -22,8 +23,10 @@ pub mod step2 { // Although `Step2` is WF at the definition site, it's not WF in its // declaration site (above). We check this in `check_opaque_meets_bounds`, // which must remain sound. + #[define_opaques(Step2)] pub fn step2<'a, 'b: 'a>() -> Step2<'a> - where crate::step1::Step1<'a, 'b>: Send + where + crate::step1::Step1<'a, 'b>: Send, { crate::step1::step1::<'a, 'b>() //~^ ERROR hidden type for `Step2<'a>` captures lifetime that does not appear in bounds @@ -32,7 +35,7 @@ pub mod step2 { fn step3<'a, 'b>() { fn is_send() {} - is_send::>(); + is_send::>(); } fn main() {} diff --git a/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness-2.stderr b/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness-2.stderr index 58d7f9959d34..6b599aafd79b 100644 --- a/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness-2.stderr +++ b/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness-2.stderr @@ -1,5 +1,5 @@ error[E0700]: hidden type for `Step2<'a>` captures lifetime that does not appear in bounds - --> $DIR/tait-hidden-erased-unsoundness-2.rs:28:9 + --> $DIR/tait-hidden-erased-unsoundness-2.rs:31:9 | LL | pub type Step2<'a> = impl Send + 'a; | -------------- opaque type defined here diff --git a/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness.rs b/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness.rs index 40efd941e338..d5f7dad23d73 100644 --- a/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness.rs +++ b/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness.rs @@ -12,16 +12,15 @@ fn step1<'a, 'b: 'a>() -> impl Sized + Captures<'b> + 'a { MyTy::<'a, 'b>(None) } -mod tait { - type Tait<'a> = impl Sized + 'a; - pub(super) fn step2<'a, 'b: 'a>() -> Tait<'a> { - super::step1::<'a, 'b>() - //~^ ERROR hidden type for `Tait<'a>` captures lifetime that does not appear in bounds - } +type Tait<'a> = impl Sized + 'a; +#[define_opaques(Tait)] +fn step2<'a, 'b: 'a>() -> Tait<'a> { + step1::<'a, 'b>() + //~^ ERROR hidden type for `Tait<'a>` captures lifetime that does not appear in bounds } fn step3<'a, 'b: 'a>() -> impl Send + 'a { - tait::step2::<'a, 'b>() + step2::<'a, 'b>() // This should not be Send unless `'b: 'static` } diff --git a/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness.stderr b/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness.stderr index 6c9b8cf24273..d1c0e27c38d1 100644 --- a/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness.stderr +++ b/tests/ui/impl-trait/alias-liveness/tait-hidden-erased-unsoundness.stderr @@ -1,12 +1,13 @@ error[E0700]: hidden type for `Tait<'a>` captures lifetime that does not appear in bounds - --> $DIR/tait-hidden-erased-unsoundness.rs:18:9 + --> $DIR/tait-hidden-erased-unsoundness.rs:18:5 | -LL | type Tait<'a> = impl Sized + 'a; - | --------------- opaque type defined here -LL | pub(super) fn step2<'a, 'b: 'a>() -> Tait<'a> { - | -- hidden type `impl Captures<'b> + 'a` captures the lifetime `'b` as defined here -LL | super::step1::<'a, 'b>() - | ^^^^^^^^^^^^^^^^^^^^^^^^ +LL | type Tait<'a> = impl Sized + 'a; + | --------------- opaque type defined here +LL | #[define_opaques(Tait)] +LL | fn step2<'a, 'b: 'a>() -> Tait<'a> { + | -- hidden type `impl Captures<'b> + 'a` captures the lifetime `'b` as defined here +LL | step1::<'a, 'b>() + | ^^^^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/associated-type-undefine.rs b/tests/ui/impl-trait/associated-type-undefine.rs index c8f07021fbf1..895525960fc1 100644 --- a/tests/ui/impl-trait/associated-type-undefine.rs +++ b/tests/ui/impl-trait/associated-type-undefine.rs @@ -16,6 +16,7 @@ impl Foo for u32 { impl Foo for () { type Bar = impl Sized; + //~^ ERROR: unconstrained opaque type type Gat = ::Bar; // Because we encounter `Gat` first, we never walk into another `Gat` // again, thus missing the opaque type that we could be defining. diff --git a/tests/ui/impl-trait/associated-type-undefine.stderr b/tests/ui/impl-trait/associated-type-undefine.stderr index 5d9d525eb93b..24c690d67a93 100644 --- a/tests/ui/impl-trait/associated-type-undefine.stderr +++ b/tests/ui/impl-trait/associated-type-undefine.stderr @@ -1,5 +1,13 @@ +error: unconstrained opaque type + --> $DIR/associated-type-undefine.rs:18:16 + | +LL | type Bar = impl Sized; + | ^^^^^^^^^^ + | + = note: `Bar` must be used in combination with a concrete type within the same impl + error[E0308]: mismatched types - --> $DIR/associated-type-undefine.rs:23:14 + --> $DIR/associated-type-undefine.rs:24:14 | LL | type Bar = impl Sized; | ---------- the expected opaque type @@ -9,12 +17,12 @@ LL | ((), ()) | = note: expected opaque type `<() as Foo>::Bar` found unit type `()` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/associated-type-undefine.rs:22:8 +note: this item must have a `#[define_opaques(<() as Foo>::Bar)]` attribute to be able to define hidden types + --> $DIR/associated-type-undefine.rs:23:8 | LL | fn foo(self) -> (::Gat, ::Gat) { | ^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/impl-trait/async_scope_creep.rs b/tests/ui/impl-trait/async_scope_creep.rs index 0fb355c52337..80a870f2bd54 100644 --- a/tests/ui/impl-trait/async_scope_creep.rs +++ b/tests/ui/impl-trait/async_scope_creep.rs @@ -22,11 +22,13 @@ impl Pending { } #[cfg(tait)] + #[define_opaques(OpeningReadFuture)] fn read_fut(&mut self) -> OpeningReadFuture<'_> { self.read() } #[cfg(rpit)] + #[define_opaques(PendingReader)] fn read_fut( &mut self, ) -> impl std::future::Future, CantOpen>> { diff --git a/tests/ui/impl-trait/auto-trait-coherence.rs b/tests/ui/impl-trait/auto-trait-coherence.rs index 0d7fef21cc92..4e3b41677a6c 100644 --- a/tests/ui/impl-trait/auto-trait-coherence.rs +++ b/tests/ui/impl-trait/auto-trait-coherence.rs @@ -5,6 +5,7 @@ trait OpaqueTrait {} impl OpaqueTrait for T {} type OpaqueType = impl OpaqueTrait; +#[define_opaques(OpaqueType)] fn mk_opaque() -> OpaqueType { () } diff --git a/tests/ui/impl-trait/auto-trait-coherence.stderr b/tests/ui/impl-trait/auto-trait-coherence.stderr index e0f4c857717c..cfeccc3d7666 100644 --- a/tests/ui/impl-trait/auto-trait-coherence.stderr +++ b/tests/ui/impl-trait/auto-trait-coherence.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<_>` - --> $DIR/auto-trait-coherence.rs:21:1 + --> $DIR/auto-trait-coherence.rs:22:1 | LL | impl AnotherTrait for T {} | -------------------------------- first implementation here diff --git a/tests/ui/impl-trait/bound-normalization-pass.rs b/tests/ui/impl-trait/bound-normalization-pass.rs index 801187b6f5e0..1d5719937412 100644 --- a/tests/ui/impl-trait/bound-normalization-pass.rs +++ b/tests/ui/impl-trait/bound-normalization-pass.rs @@ -77,6 +77,7 @@ mod opaque_types { type Ex = impl Trait::Assoc>; + #[define_opaques(Ex)] fn define() -> Ex { () } diff --git a/tests/ui/impl-trait/coherence-treats-tait-ambig.rs b/tests/ui/impl-trait/coherence-treats-tait-ambig.rs index e8c1fcdd2133..c85add6a5098 100644 --- a/tests/ui/impl-trait/coherence-treats-tait-ambig.rs +++ b/tests/ui/impl-trait/coherence-treats-tait-ambig.rs @@ -5,7 +5,8 @@ type T = impl Sized; struct Foo; impl Into for Foo { -//~^ ERROR conflicting implementations of trait `Into<_>` for type `Foo` + //~^ ERROR conflicting implementations of trait `Into<_>` for type `Foo` + #[define_opaques(T)] fn into(self) -> T { Foo } diff --git a/tests/ui/impl-trait/deduce-signature-from-supertrait.rs b/tests/ui/impl-trait/deduce-signature-from-supertrait.rs index 4e452994f72e..d6254cf83c72 100644 --- a/tests/ui/impl-trait/deduce-signature-from-supertrait.rs +++ b/tests/ui/impl-trait/deduce-signature-from-supertrait.rs @@ -8,7 +8,8 @@ impl SuperExpectation for T {} type Foo = impl SuperExpectation; -fn bop(_: Foo) { +#[define_opaques(Foo)] +fn bop() { let _: Foo = |x| { let _ = x.to_string(); }; diff --git a/tests/ui/impl-trait/future-no-bound-vars-ice-112347.rs b/tests/ui/impl-trait/future-no-bound-vars-ice-112347.rs index af623dc7cd9d..4f7790254f49 100644 --- a/tests/ui/impl-trait/future-no-bound-vars-ice-112347.rs +++ b/tests/ui/impl-trait/future-no-bound-vars-ice-112347.rs @@ -7,15 +7,12 @@ use std::future::Future; -mod foo { - use std::future::Future; - pub type Fut<'a> = impl Future + 'a; +pub type Fut<'a> = impl Future + 'a; - fn foo<'a>(_: &()) -> Fut<'_> { - async {} - } +#[define_opaques(Fut)] +fn foo<'a>(_: &()) -> Fut<'_> { + async {} } -use foo::*; trait Test { fn hello(); diff --git a/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr b/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr index 01c5a553dc50..dca0a7b0a1a9 100644 --- a/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr +++ b/tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr @@ -13,7 +13,7 @@ LL | Thunk::new(|mut cont: /* Type */| { | ++++++++++++ error[E0282]: type annotations needed - --> $DIR/hidden-type-is-opaque-2.rs:20:17 + --> $DIR/hidden-type-is-opaque-2.rs:21:17 | LL | Thunk::new(|mut cont| { | ^^^^^^^^ diff --git a/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr b/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr index 01c5a553dc50..dca0a7b0a1a9 100644 --- a/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr +++ b/tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr @@ -13,7 +13,7 @@ LL | Thunk::new(|mut cont: /* Type */| { | ++++++++++++ error[E0282]: type annotations needed - --> $DIR/hidden-type-is-opaque-2.rs:20:17 + --> $DIR/hidden-type-is-opaque-2.rs:21:17 | LL | Thunk::new(|mut cont| { | ^^^^^^^^ diff --git a/tests/ui/impl-trait/hidden-type-is-opaque-2.rs b/tests/ui/impl-trait/hidden-type-is-opaque-2.rs index 78ac8363ba93..e314ac2138dd 100644 --- a/tests/ui/impl-trait/hidden-type-is-opaque-2.rs +++ b/tests/ui/impl-trait/hidden-type-is-opaque-2.rs @@ -16,6 +16,7 @@ fn reify_as() -> Thunk Continuation> { type Tait = impl FnOnce(Continuation) -> Continuation; +#[define_opaques(Tait)] fn reify_as_tait() -> Thunk { Thunk::new(|mut cont| { //~^ ERROR type annotations needed diff --git a/tests/ui/impl-trait/hidden-type-is-opaque.rs b/tests/ui/impl-trait/hidden-type-is-opaque.rs index 3111a21e2096..1ad18067d387 100644 --- a/tests/ui/impl-trait/hidden-type-is-opaque.rs +++ b/tests/ui/impl-trait/hidden-type-is-opaque.rs @@ -10,6 +10,7 @@ fn reify_as() -> Thunk { type Tait = impl ContFn; +#[define_opaques(Tait)] fn reify_as_tait() -> Thunk { Thunk::new(|mut cont| { cont.reify_as(); diff --git a/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.current.stderr b/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.current.stderr index 146a3d21068c..c76415d8114b 100644 --- a/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.current.stderr +++ b/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.current.stderr @@ -1,5 +1,5 @@ error[E0407]: method `line_stream` is not a member of trait `X` - --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:28:5 + --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:29:5 | LL | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `X` @@ -17,15 +17,23 @@ LL | type LineStream<'c, 'd> = impl Stream; | | | found 0 type parameters +error: unconstrained opaque type + --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:25:31 + | +LL | type LineStream<'c, 'd> = impl Stream; + | ^^^^^^^^^^^ + | + = note: `LineStream` must be used in combination with a concrete type within the same impl + error[E0277]: `()` is not a future - --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:28:43 + --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:29:43 | LL | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not a future | = help: the trait `Future` is not implemented for `()` -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0049, E0277, E0407. For more information about an error, try `rustc --explain E0049`. diff --git a/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.next.stderr b/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.next.stderr index ce64a022214e..4d72490ff956 100644 --- a/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.next.stderr +++ b/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.next.stderr @@ -1,5 +1,5 @@ error[E0407]: method `line_stream` is not a member of trait `X` - --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:28:5 + --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:29:5 | LL | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a member of trait `X` @@ -17,25 +17,33 @@ LL | type LineStream<'c, 'd> = impl Stream; | | | found 0 type parameters +error: unconstrained opaque type + --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:25:31 + | +LL | type LineStream<'c, 'd> = impl Stream; + | ^^^^^^^^^^^ + | + = note: `LineStream` must be used in combination with a concrete type within the same impl + error[E0271]: type mismatch resolving `::LineStreamFut<'a, Repr> == ()` - --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:28:43 + --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:29:43 | LL | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ error[E0271]: type mismatch resolving `::LineStreamFut<'a, Repr> normalizes-to _` - --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:28:73 + --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:29:73 | LL | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {} | ^^ types differ error[E0271]: type mismatch resolving `::LineStreamFut<'a, Repr> normalizes-to _` - --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:28:5 + --> $DIR/ice-unexpected-param-type-whensubstituting-in-region-112823.rs:29:5 | LL | fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ -error: aborting due to 5 previous errors +error: aborting due to 6 previous errors Some errors have detailed explanations: E0049, E0271, E0407. For more information about an error, try `rustc --explain E0049`. diff --git a/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.rs b/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.rs index cb32723b22dd..a5a37dbb210f 100644 --- a/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.rs +++ b/tests/ui/impl-trait/ice-unexpected-param-type-whensubstituting-in-region-112823.rs @@ -24,6 +24,7 @@ struct Y; impl X for Y { type LineStream<'c, 'd> = impl Stream; //~^ ERROR type `LineStream` has 0 type parameters but its trait declaration has 1 type parameter + //~| ERROR: unconstrained opaque type type LineStreamFut<'a, Repr> = impl Future>; fn line_stream<'a, Repr>(&'a self) -> Self::LineStreamFut<'a, Repr> {} //~^ method `line_stream` is not a member of trait `X` diff --git a/tests/ui/impl-trait/in-assoc-type-unconstrained.stderr b/tests/ui/impl-trait/in-assoc-type-unconstrained.stderr index 8351175099c9..dd9977f294f9 100644 --- a/tests/ui/impl-trait/in-assoc-type-unconstrained.stderr +++ b/tests/ui/impl-trait/in-assoc-type-unconstrained.stderr @@ -36,7 +36,7 @@ LL | fn method() -> Self::Ty; | ^^^^^^^^ = note: expected signature `fn() -> <() as compare_method::Trait>::Ty` found signature `fn() -> ()` -note: this item must have the opaque type in its signature in order to be able to register hidden types +note: this item must have a `#[define_opaques(<() as compare_method::Trait>::Ty)]` attribute to be able to define hidden types --> $DIR/in-assoc-type-unconstrained.rs:22:12 | LL | fn method() -> () {} diff --git a/tests/ui/impl-trait/in-assoc-type.stderr b/tests/ui/impl-trait/in-assoc-type.stderr index d5b543ea953d..522693ff1755 100644 --- a/tests/ui/impl-trait/in-assoc-type.stderr +++ b/tests/ui/impl-trait/in-assoc-type.stderr @@ -11,7 +11,7 @@ LL | fn foo(&self) -> >::Bar {} | = note: expected opaque type `<() as Foo<()>>::Bar` found unit type `()` -note: this item must have the opaque type in its signature in order to be able to register hidden types +note: this item must have a `#[define_opaques(<() as Foo<()>>::Bar)]` attribute to be able to define hidden types --> $DIR/in-assoc-type.rs:20:8 | LL | fn foo(&self) -> >::Bar {} diff --git a/tests/ui/impl-trait/issue-108591.rs b/tests/ui/impl-trait/issue-108591.rs index caf080245687..3f14c7656f3e 100644 --- a/tests/ui/impl-trait/issue-108591.rs +++ b/tests/ui/impl-trait/issue-108591.rs @@ -15,6 +15,7 @@ impl MyTy<'_> { type Opaque2 = impl Sized; type Opaque<'a> = Opaque2; +#[define_opaques(Opaque)] fn define<'a>() -> Opaque<'a> {} fn test<'a>() { diff --git a/tests/ui/impl-trait/issue-108592.rs b/tests/ui/impl-trait/issue-108592.rs index 7db2e31549c0..cb6de95b4b1a 100644 --- a/tests/ui/impl-trait/issue-108592.rs +++ b/tests/ui/impl-trait/issue-108592.rs @@ -11,13 +11,10 @@ fn test_closure() { closure(&opaque()); } -mod helper { - pub type Opaque2 = impl Sized; - pub type Opaque<'a> = Opaque2; - fn define<'a>() -> Opaque<'a> {} -} - -use helper::*; +pub type Opaque2 = impl Sized; +pub type Opaque<'a> = Opaque2; +#[define_opaques(Opaque)] +fn define<'a>() -> Opaque<'a> {} fn test_tait(_: &Opaque<'_>) { None::<&'static Opaque<'_>>; diff --git a/tests/ui/impl-trait/issue-99642-2.rs b/tests/ui/impl-trait/issue-99642-2.rs index acbf3e3e2a02..0b23cb1a3bc1 100644 --- a/tests/ui/impl-trait/issue-99642-2.rs +++ b/tests/ui/impl-trait/issue-99642-2.rs @@ -2,7 +2,8 @@ #![feature(type_alias_impl_trait)] type Opq = impl Sized; +#[define_opaques(Opq)] fn test() -> impl Iterator { Box::new(0..) as Box> } -fn main(){} +fn main() {} diff --git a/tests/ui/impl-trait/issues/issue-53457.rs b/tests/ui/impl-trait/issues/issue-53457.rs index bb248ef71773..2b185aa85b74 100644 --- a/tests/ui/impl-trait/issues/issue-53457.rs +++ b/tests/ui/impl-trait/issues/issue-53457.rs @@ -7,6 +7,7 @@ fn bar(f: F) -> F { f } +#[define_opaques(X)] fn foo() -> X { bar(|_| ()) } diff --git a/tests/ui/impl-trait/issues/issue-70877.rs b/tests/ui/impl-trait/issues/issue-70877.rs index 6ced0bbba8b3..42bc3161ce33 100644 --- a/tests/ui/impl-trait/issues/issue-70877.rs +++ b/tests/ui/impl-trait/issues/issue-70877.rs @@ -15,27 +15,27 @@ impl Iterator for Bar { } } -mod ret { - pub type FooRet = impl std::fmt::Debug; - pub fn quux(st: super::FooArg) -> FooRet { - Some(st.to_string()) - } +pub type FooRet = impl std::fmt::Debug; +#[define_opaques(FooRet)] +pub fn quux(st: FooArg) -> FooRet { + Some(st.to_string()) } -use ret::*; -mod foo { - pub type Foo = impl Iterator; - pub fn ham() -> Foo { - super::Bar(1) - } - pub fn oof(_: Foo) -> impl std::fmt::Debug { - //~^ ERROR: item does not constrain `Foo::{opaque#0}`, but has it in its signature - let mut bar = ham(); - let func = bar.next().unwrap(); - return func(&"oof"); - } +pub type Foo = impl Iterator; +#[define_opaques(Foo)] +pub fn ham() -> Foo { + //~^ ERROR: item does not constrain `FooRet::{opaque#0}`, but has it in its signature + Bar(1) +} +#[define_opaques(Foo)] +pub fn oof() -> impl std::fmt::Debug { + //~^ ERROR: item does not constrain `FooRet::{opaque#0}`, but has it in its signature + //~| ERROR: item does not constrain `Foo::{opaque#0}`, but has it in its signature + let mut bar = ham(); + let func = bar.next().unwrap(); + return func(&"oof"); + //~^ ERROR: opaque type's hidden type cannot be another opaque type } -use foo::*; fn main() { - let _ = oof(ham()); + let _ = oof(); } diff --git a/tests/ui/impl-trait/issues/issue-70877.stderr b/tests/ui/impl-trait/issues/issue-70877.stderr index 4b23a02aaee3..97d243f24903 100644 --- a/tests/ui/impl-trait/issues/issue-70877.stderr +++ b/tests/ui/impl-trait/issues/issue-70877.stderr @@ -1,15 +1,58 @@ +error: item does not constrain `FooRet::{opaque#0}`, but has it in its signature + --> $DIR/issue-70877.rs:25:8 + | +LL | pub fn ham() -> Foo { + | ^^^ + | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/issue-70877.rs:18:19 + | +LL | pub type FooRet = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ + +error: item does not constrain `FooRet::{opaque#0}`, but has it in its signature + --> $DIR/issue-70877.rs:30:8 + | +LL | pub fn oof() -> impl std::fmt::Debug { + | ^^^ + | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/issue-70877.rs:18:19 + | +LL | pub type FooRet = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ + error: item does not constrain `Foo::{opaque#0}`, but has it in its signature - --> $DIR/issue-70877.rs:30:12 + --> $DIR/issue-70877.rs:30:8 | -LL | pub fn oof(_: Foo) -> impl std::fmt::Debug { - | ^^^ +LL | pub fn oof() -> impl std::fmt::Debug { + | ^^^ | = note: consider moving the opaque type's declaration and defining uses into a separate module note: this opaque type is in the signature - --> $DIR/issue-70877.rs:26:20 + --> $DIR/issue-70877.rs:23:16 + | +LL | pub type Foo = impl Iterator; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: opaque type's hidden type cannot be another opaque type from the same scope + --> $DIR/issue-70877.rs:35:12 + | +LL | return func(&"oof"); + | ^^^^^^^^^^^^ one of the two opaque types used here has to be outside its defining scope + | +note: opaque type whose hidden type is being assigned + --> $DIR/issue-70877.rs:30:17 + | +LL | pub fn oof() -> impl std::fmt::Debug { + | ^^^^^^^^^^^^^^^^^^^^ +note: opaque type being used as hidden type + --> $DIR/issue-70877.rs:18:19 | -LL | pub type Foo = impl Iterator; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | pub type FooRet = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: aborting due to 4 previous errors diff --git a/tests/ui/impl-trait/issues/issue-74282.rs b/tests/ui/impl-trait/issues/issue-74282.rs index 51bd5f67ed57..c1e12a740eaa 100644 --- a/tests/ui/impl-trait/issues/issue-74282.rs +++ b/tests/ui/impl-trait/issues/issue-74282.rs @@ -3,7 +3,8 @@ type Closure = impl Fn() -> u64; struct Anonymous(Closure); -fn bop(_: Closure) { +#[define_opaques(Closure)] +fn bop() { let y = || -> Closure { || 3 }; Anonymous(|| { //~^ ERROR mismatched types diff --git a/tests/ui/impl-trait/issues/issue-74282.stderr b/tests/ui/impl-trait/issues/issue-74282.stderr index f8e85f7ae000..7a49041cace7 100644 --- a/tests/ui/impl-trait/issues/issue-74282.stderr +++ b/tests/ui/impl-trait/issues/issue-74282.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-74282.rs:8:15 + --> $DIR/issue-74282.rs:9:15 | LL | type Closure = impl Fn() -> u64; | ---------------- the expected opaque type @@ -14,7 +14,7 @@ LL | | }) | |_____^ expected opaque type, found closure | = note: expected opaque type `Closure` - found closure `{closure@$DIR/issue-74282.rs:8:15: 8:17}` + found closure `{closure@$DIR/issue-74282.rs:9:15: 9:17}` = note: no two closures, even if identical, have the same type = help: consider boxing your closure and/or using it as a trait object note: tuple struct defined here @@ -24,7 +24,7 @@ LL | struct Anonymous(Closure); | ^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/issue-74282.rs:8:5 + --> $DIR/issue-74282.rs:9:5 | LL | / Anonymous(|| { LL | | @@ -38,8 +38,8 @@ LL | }); | + help: try adding a return type | -LL | fn bop(_: Closure) -> Anonymous { - | ++++++++++++ +LL | fn bop() -> Anonymous { + | ++++++++++++ error: aborting due to 2 previous errors diff --git a/tests/ui/impl-trait/issues/issue-77987.rs b/tests/ui/impl-trait/issues/issue-77987.rs index a7e7b067d5ff..8d304ae86fef 100644 --- a/tests/ui/impl-trait/issues/issue-77987.rs +++ b/tests/ui/impl-trait/issues/issue-77987.rs @@ -5,17 +5,16 @@ pub trait Foo {} impl Foo for U {} -mod scope { - pub type Scope = impl super::Foo<()>; +pub type Scope = impl Foo<()>; - #[allow(unused)] - fn infer_scope() -> Scope { - () - } +#[allow(unused)] +#[define_opaques(Scope)] +fn infer_scope() -> Scope { + () } #[allow(unused)] -fn ice() -> impl Foo { +fn ice() -> impl Foo { loop {} } diff --git a/tests/ui/impl-trait/issues/issue-78722-2.rs b/tests/ui/impl-trait/issues/issue-78722-2.rs index e811620c03ba..cfe975f2fb55 100644 --- a/tests/ui/impl-trait/issues/issue-78722-2.rs +++ b/tests/ui/impl-trait/issues/issue-78722-2.rs @@ -8,6 +8,7 @@ type F = impl core::future::Future; struct Bug { V1: [(); { + #[define_opaques(F)] fn concrete_use() -> F { //~^ ERROR future that resolves to `u8`, but it resolves to `()` async {} diff --git a/tests/ui/impl-trait/issues/issue-78722-2.stderr b/tests/ui/impl-trait/issues/issue-78722-2.stderr index 27b4b7128302..ede830bf72c8 100644 --- a/tests/ui/impl-trait/issues/issue-78722-2.stderr +++ b/tests/ui/impl-trait/issues/issue-78722-2.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-78722-2.rs:16:20 + --> $DIR/issue-78722-2.rs:17:20 | LL | type F = impl core::future::Future; | -------------------------------------- the expected future @@ -10,10 +10,10 @@ LL | let f: F = async { 1 }; | expected due to this | = note: expected opaque type `F` - found `async` block `{async block@$DIR/issue-78722-2.rs:16:20: 16:25}` + found `async` block `{async block@$DIR/issue-78722-2.rs:17:20: 17:25}` -error[E0271]: expected `{async block@$DIR/issue-78722-2.rs:13:13: 13:18}` to be a future that resolves to `u8`, but it resolves to `()` - --> $DIR/issue-78722-2.rs:11:30 +error[E0271]: expected `{async block@$DIR/issue-78722-2.rs:14:13: 14:18}` to be a future that resolves to `u8`, but it resolves to `()` + --> $DIR/issue-78722-2.rs:12:30 | LL | fn concrete_use() -> F { | ^ expected `u8`, found `()` diff --git a/tests/ui/impl-trait/issues/issue-78722.rs b/tests/ui/impl-trait/issues/issue-78722.rs index 5518c2cf12a3..8417a7132d60 100644 --- a/tests/ui/impl-trait/issues/issue-78722.rs +++ b/tests/ui/impl-trait/issues/issue-78722.rs @@ -5,6 +5,7 @@ struct Bug { V1: [(); { type F = impl core::future::Future; + #[define_opaques(F)] fn concrete_use() -> F { //~^ ERROR to be a future that resolves to `u8`, but it resolves to `()` async {} diff --git a/tests/ui/impl-trait/issues/issue-78722.stderr b/tests/ui/impl-trait/issues/issue-78722.stderr index 109bda0c5cd6..84c7dfb03384 100644 --- a/tests/ui/impl-trait/issues/issue-78722.stderr +++ b/tests/ui/impl-trait/issues/issue-78722.stderr @@ -1,5 +1,5 @@ error[E0658]: `async` blocks are not allowed in constants - --> $DIR/issue-78722.rs:12:20 + --> $DIR/issue-78722.rs:13:20 | LL | let f: F = async { 1 }; | ^^^^^^^^^^^ @@ -8,8 +8,8 @@ LL | let f: F = async { 1 }; = help: add `#![feature(const_async_blocks)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error[E0271]: expected `{async block@$DIR/issue-78722.rs:10:13: 10:18}` to be a future that resolves to `u8`, but it resolves to `()` - --> $DIR/issue-78722.rs:8:30 +error[E0271]: expected `{async block@$DIR/issue-78722.rs:11:13: 11:18}` to be a future that resolves to `u8`, but it resolves to `()` + --> $DIR/issue-78722.rs:9:30 | LL | fn concrete_use() -> F { | ^ expected `u8`, found `()` diff --git a/tests/ui/impl-trait/issues/issue-86201.rs b/tests/ui/impl-trait/issues/issue-86201.rs index cde0b8611603..efebc35f9c69 100644 --- a/tests/ui/impl-trait/issues/issue-86201.rs +++ b/tests/ui/impl-trait/issues/issue-86201.rs @@ -4,10 +4,13 @@ //@ check-pass type FunType = impl Fn<()>; -static STATIC_FN: FunType = some_fn; +#[define_opaques(FunType)] +fn foo() -> FunType { + some_fn +} fn some_fn() {} fn main() { - let _: >::Output = STATIC_FN(); + let _: >::Output = foo()(); } diff --git a/tests/ui/impl-trait/issues/issue-86800.rs b/tests/ui/impl-trait/issues/issue-86800.rs index ff1d273ae482..28f21dc7a10e 100644 --- a/tests/ui/impl-trait/issues/issue-86800.rs +++ b/tests/ui/impl-trait/issues/issue-86800.rs @@ -24,6 +24,7 @@ type TransactionResult = Result; type TransactionFuture<'__, O> = impl '__ + Future>; +#[define_opaques(TransactionFuture)] fn execute_transaction_fut<'f, F, O>( //~^ ERROR: item does not constrain f: F, @@ -36,6 +37,7 @@ where } impl Context { + #[define_opaques(TransactionFuture)] async fn do_transaction( //~^ ERROR: item does not constrain &self, f: impl FnOnce(&mut dyn Transaction) -> TransactionFuture<'_, O> diff --git a/tests/ui/impl-trait/issues/issue-86800.stderr b/tests/ui/impl-trait/issues/issue-86800.stderr index fd9b8e7ac999..3e68221e7d05 100644 --- a/tests/ui/impl-trait/issues/issue-86800.stderr +++ b/tests/ui/impl-trait/issues/issue-86800.stderr @@ -1,5 +1,5 @@ error: item does not constrain `TransactionFuture::{opaque#0}`, but has it in its signature - --> $DIR/issue-86800.rs:27:4 + --> $DIR/issue-86800.rs:28:4 | LL | fn execute_transaction_fut<'f, F, O>( | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -12,7 +12,7 @@ LL | type TransactionFuture<'__, O> = impl '__ + Future $DIR/issue-86800.rs:39:14 + --> $DIR/issue-86800.rs:41:14 | LL | async fn do_transaction( | ^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL | type TransactionFuture<'__, O> = impl '__ + Future $DIR/issue-86800.rs:43:5 + --> $DIR/issue-86800.rs:45:5 | LL | / { LL | | @@ -44,7 +44,7 @@ LL | type TransactionFuture<'__, O> = impl '__ + Future $DIR/issue-86800.rs:34:5 + --> $DIR/issue-86800.rs:35:5 | LL | type TransactionFuture<'__, O> = impl '__ + Future>; | --- this generic parameter must be used with a generic lifetime parameter @@ -53,7 +53,7 @@ LL | f | ^ error[E0792]: expected generic lifetime parameter, found `'_` - --> $DIR/issue-86800.rs:43:5 + --> $DIR/issue-86800.rs:45:5 | LL | type TransactionFuture<'__, O> = impl '__ + Future>; | --- this generic parameter must be used with a generic lifetime parameter diff --git a/tests/ui/impl-trait/issues/issue-89312.rs b/tests/ui/impl-trait/issues/issue-89312.rs index 3b0e976780be..da985089f3bf 100644 --- a/tests/ui/impl-trait/issues/issue-89312.rs +++ b/tests/ui/impl-trait/issues/issue-89312.rs @@ -2,23 +2,21 @@ //@ check-pass -mod helper { - pub trait T { - type Item; - } +pub trait T { + type Item; +} - pub type Alias<'a> = impl T; +pub type Alias<'a> = impl T; - struct S; - impl<'a> T for &'a S { - type Item = &'a (); - } +struct S; +impl<'a> T for &'a S { + type Item = &'a (); +} - pub fn filter_positive<'a>() -> Alias<'a> { - &S - } +#[define_opaques(Alias)] +pub fn filter_positive<'a>() -> Alias<'a> { + &S } -use helper::*; fn with_positive(fun: impl Fn(Alias<'_>)) { fun(filter_positive()); diff --git a/tests/ui/impl-trait/issues/issue-99348-impl-compatibility.rs b/tests/ui/impl-trait/issues/issue-99348-impl-compatibility.rs index b05579f21662..f56b36470fe5 100644 --- a/tests/ui/impl-trait/issues/issue-99348-impl-compatibility.rs +++ b/tests/ui/impl-trait/issues/issue-99348-impl-compatibility.rs @@ -21,6 +21,7 @@ trait Bar { type Other; } +#[define_opaques(Tait)] fn tait() -> Tait {} fn main() {} diff --git a/tests/ui/impl-trait/multiple-lifetimes/error-handling-2.rs b/tests/ui/impl-trait/multiple-lifetimes/error-handling-2.rs index 2a2be6b74299..0f4d71caafc7 100644 --- a/tests/ui/impl-trait/multiple-lifetimes/error-handling-2.rs +++ b/tests/ui/impl-trait/multiple-lifetimes/error-handling-2.rs @@ -7,6 +7,7 @@ impl Copy for CopyIfEq {} type E<'a, 'b> = impl Sized; +#[define_opaques(E)] fn foo<'a: 'b, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { let v = CopyIfEq::<*mut _, *mut _>(&mut { x }, &mut y); diff --git a/tests/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr b/tests/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr index b968592beffd..712cbbecd74b 100644 --- a/tests/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr +++ b/tests/ui/impl-trait/multiple-lifetimes/error-handling-2.stderr @@ -1,9 +1,9 @@ error[E0700]: hidden type for `E<'b, 'c>` captures lifetime that does not appear in bounds - --> $DIR/error-handling-2.rs:22:5 + --> $DIR/error-handling-2.rs:23:5 | LL | type E<'a, 'b> = impl Sized; | ---------- opaque type defined here -LL | +... LL | fn foo<'a: 'b, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { | -- hidden type `*mut &'a i32` captures the lifetime `'a` as defined here ... diff --git a/tests/ui/impl-trait/multiple-lifetimes/error-handling.rs b/tests/ui/impl-trait/multiple-lifetimes/error-handling.rs index 367e7f4e6eaf..0fb279667c62 100644 --- a/tests/ui/impl-trait/multiple-lifetimes/error-handling.rs +++ b/tests/ui/impl-trait/multiple-lifetimes/error-handling.rs @@ -7,6 +7,7 @@ impl Copy for CopyIfEq {} type E<'a, 'b> = impl Sized; +#[define_opaques(E)] fn foo<'a, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { let v = CopyIfEq::<*mut _, *mut _>(&mut { x }, &mut y); diff --git a/tests/ui/impl-trait/multiple-lifetimes/error-handling.stderr b/tests/ui/impl-trait/multiple-lifetimes/error-handling.stderr index 945fb0fc618f..3732307ca354 100644 --- a/tests/ui/impl-trait/multiple-lifetimes/error-handling.stderr +++ b/tests/ui/impl-trait/multiple-lifetimes/error-handling.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/error-handling.rs:20:16 + --> $DIR/error-handling.rs:21:16 | LL | fn foo<'a, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { | -- -- lifetime `'b` defined here diff --git a/tests/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-type-alias-impl-trait.rs b/tests/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-type-alias-impl-trait.rs index 6f90160866ba..5e790c70306e 100644 --- a/tests/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-type-alias-impl-trait.rs +++ b/tests/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-type-alias-impl-trait.rs @@ -10,6 +10,7 @@ impl Trait<'_, '_> for T {} type Foo<'a, 'b> = impl Trait<'a, 'b>; +#[define_opaques(Foo)] 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 // diff --git a/tests/ui/impl-trait/negative-reasoning.rs b/tests/ui/impl-trait/negative-reasoning.rs index 0474dc0beda6..4921c1bcb6da 100644 --- a/tests/ui/impl-trait/negative-reasoning.rs +++ b/tests/ui/impl-trait/negative-reasoning.rs @@ -5,6 +5,7 @@ trait OpaqueTrait {} impl OpaqueTrait for T {} type OpaqueType = impl OpaqueTrait; +#[define_opaques(OpaqueType)] fn mk_opaque() -> OpaqueType { () } diff --git a/tests/ui/impl-trait/negative-reasoning.stderr b/tests/ui/impl-trait/negative-reasoning.stderr index 631784c817b8..2918be5135ce 100644 --- a/tests/ui/impl-trait/negative-reasoning.stderr +++ b/tests/ui/impl-trait/negative-reasoning.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<_>` - --> $DIR/negative-reasoning.rs:19:1 + --> $DIR/negative-reasoning.rs:20:1 | LL | impl AnotherTrait for T {} | ------------------------------------------- first implementation here diff --git a/tests/ui/impl-trait/nested-return-type2-tait.rs b/tests/ui/impl-trait/nested-return-type2-tait.rs index 7cb98cfe0601..a1a3079118bf 100644 --- a/tests/ui/impl-trait/nested-return-type2-tait.rs +++ b/tests/ui/impl-trait/nested-return-type2-tait.rs @@ -25,10 +25,10 @@ type Sendable = impl Send; // the hidden type. We already have obligations registered on the inference // var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque // type does not implement `Duh`, but if its hidden type does. +#[define_opaques(Sendable)] fn foo() -> impl Trait { //~^ WARN opaque type `impl Trait` does not satisfy its associated type bounds || 42 } -fn main() { -} +fn main() {} diff --git a/tests/ui/impl-trait/nested-return-type2-tait.stderr b/tests/ui/impl-trait/nested-return-type2-tait.stderr index 4383e8ab3a0c..8105990eac4a 100644 --- a/tests/ui/impl-trait/nested-return-type2-tait.stderr +++ b/tests/ui/impl-trait/nested-return-type2-tait.stderr @@ -1,5 +1,5 @@ warning: opaque type `impl Trait` does not satisfy its associated type bounds - --> $DIR/nested-return-type2-tait.rs:28:24 + --> $DIR/nested-return-type2-tait.rs:29:24 | LL | type Assoc: Duh; | --- this associated type bound is unsatisfied for `Sendable` diff --git a/tests/ui/impl-trait/nested-return-type2-tait2.rs b/tests/ui/impl-trait/nested-return-type2-tait2.rs index 574602079d43..22ff6972a6dd 100644 --- a/tests/ui/impl-trait/nested-return-type2-tait2.rs +++ b/tests/ui/impl-trait/nested-return-type2-tait2.rs @@ -26,9 +26,9 @@ type Traitable = impl Trait; // the hidden type. We already have obligations registered on the inference // var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque // type does not implement `Duh`, even if its hidden type does. So we error out. +#[define_opaques(Traitable)] fn foo() -> Traitable { || 42 } -fn main() { -} +fn main() {} diff --git a/tests/ui/impl-trait/nested-return-type2-tait3.rs b/tests/ui/impl-trait/nested-return-type2-tait3.rs index e34297317825..43752fd7d1f8 100644 --- a/tests/ui/impl-trait/nested-return-type2-tait3.rs +++ b/tests/ui/impl-trait/nested-return-type2-tait3.rs @@ -25,9 +25,9 @@ type Traitable = impl Trait; // the hidden type. We already have obligations registered on the inference // var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque // type does not implement `Duh`, even if its hidden type does. So we error out. +#[define_opaques(Traitable)] fn foo() -> Traitable { || 42 } -fn main() { -} +fn main() {} diff --git a/tests/ui/impl-trait/nested-return-type3-tait.rs b/tests/ui/impl-trait/nested-return-type3-tait.rs index 05759fb26979..f050e7dbd3e5 100644 --- a/tests/ui/impl-trait/nested-return-type3-tait.rs +++ b/tests/ui/impl-trait/nested-return-type3-tait.rs @@ -16,10 +16,10 @@ impl Trait for F { type Sendable = impl Send; +#[define_opaques(Sendable)] fn foo() -> impl Trait { //~^ WARN opaque type `impl Trait` does not satisfy its associated type bounds 42 } -fn main() { -} +fn main() {} diff --git a/tests/ui/impl-trait/nested-return-type3-tait.stderr b/tests/ui/impl-trait/nested-return-type3-tait.stderr index d32944a0d721..bb1f524b9925 100644 --- a/tests/ui/impl-trait/nested-return-type3-tait.stderr +++ b/tests/ui/impl-trait/nested-return-type3-tait.stderr @@ -1,5 +1,5 @@ warning: opaque type `impl Trait` does not satisfy its associated type bounds - --> $DIR/nested-return-type3-tait.rs:19:24 + --> $DIR/nested-return-type3-tait.rs:20:24 | LL | type Assoc: Duh; | --- this associated type bound is unsatisfied for `Sendable` diff --git a/tests/ui/impl-trait/nested-return-type3-tait2.rs b/tests/ui/impl-trait/nested-return-type3-tait2.rs index 927fa8d596b9..fae27b42b5cb 100644 --- a/tests/ui/impl-trait/nested-return-type3-tait2.rs +++ b/tests/ui/impl-trait/nested-return-type3-tait2.rs @@ -18,9 +18,9 @@ type Sendable = impl Send; type Traitable = impl Trait; //~^ WARN opaque type `Traitable` does not satisfy its associated type bounds +#[define_opaques(Traitable)] fn foo() -> Traitable { 42 } -fn main() { -} +fn main() {} diff --git a/tests/ui/impl-trait/nested-return-type3-tait3.rs b/tests/ui/impl-trait/nested-return-type3-tait3.rs index 5b3b2d2e1986..037b577b9881 100644 --- a/tests/ui/impl-trait/nested-return-type3-tait3.rs +++ b/tests/ui/impl-trait/nested-return-type3-tait3.rs @@ -17,9 +17,9 @@ impl Trait for F { type Traitable = impl Trait; //~^ WARN opaque type `Traitable` does not satisfy its associated type bounds +#[define_opaques(Traitable)] fn foo() -> Traitable { 42 } -fn main() { -} +fn main() {} diff --git a/tests/ui/impl-trait/normalize-tait-in-const.stderr b/tests/ui/impl-trait/normalize-tait-in-const.stderr index c6cd1b139c5b..a35d41fc2761 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.stderr +++ b/tests/ui/impl-trait/normalize-tait-in-const.stderr @@ -17,6 +17,14 @@ note: `Fn` can't be used with `~const` because it isn't annotated with `#[const_ --> $SRC_DIR/core/src/ops/function.rs:LL:COL = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` +error: unconstrained opaque type + --> $DIR/normalize-tait-in-const.rs:14:26 + | +LL | pub type Alias<'a> = impl T; + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: `Alias` must be used in combination with a concrete type within the same crate + error[E0015]: cannot call non-const closure in constant functions --> $DIR/normalize-tait-in-const.rs:28:5 | @@ -25,6 +33,26 @@ LL | fun(filter_positive()); | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error: aborting due to 3 previous errors +error[E0308]: mismatched types + --> $DIR/normalize-tait-in-const.rs:22:9 + | +LL | pub type Alias<'a> = impl T; + | --------------------- the expected opaque type +... +LL | pub const fn filter_positive<'a>() -> &'a Alias<'a> { + | ------------- expected `&'a foo::Alias<'a>` because of return type +LL | &&S + | ^^^ expected `&Alias<'_>`, found `&&S` + | + = note: expected reference `&'a foo::Alias<'a>` + found reference `&&S` +note: this item must have a `#[define_opaques(foo::Alias)]` attribute to be able to define hidden types + --> $DIR/normalize-tait-in-const.rs:21:18 + | +LL | pub const fn filter_positive<'a>() -> &'a Alias<'a> { + | ^^^^^^^^^^^^^^^ + +error: aborting due to 5 previous errors -For more information about this error, try `rustc --explain E0015`. +Some errors have detailed explanations: E0015, E0308. +For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle-2.rs b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle-2.rs index 0b29af5df5b5..11c007dbba7c 100644 --- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle-2.rs +++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle-2.rs @@ -2,14 +2,12 @@ //@ check-pass -mod foo { - pub type Foo = impl PartialEq<(Foo, i32)>; +pub type Foo = impl PartialEq<(Foo, i32)>; - fn foo() -> Foo { - super::Bar - } +#[define_opaques(Foo)] +fn foo() -> Foo { + Bar } -use foo::Foo; struct Bar; diff --git a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.rs b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.rs index 3f41c5984b41..63855414b0d5 100644 --- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.rs +++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.rs @@ -6,6 +6,7 @@ mod a { struct Bar; impl PartialEq<(Bar, i32)> for Bar { + #[define_opaques(Foo)] fn eq(&self, _other: &(Foo, i32)) -> bool { //~^ ERROR: `eq` has an incompatible type for trait //~| ERROR: item does not constrain `a::Foo::{opaque#0}` diff --git a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr index 767bd312407a..9344bdba59af 100644 --- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr +++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr @@ -1,5 +1,5 @@ error[E0053]: method `eq` has an incompatible type for trait - --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:9:30 + --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:10:30 | LL | type Foo = impl PartialEq<(Foo, i32)>; | -------------------------- the found opaque type @@ -16,7 +16,7 @@ LL + fn eq(&self, _other: &(a::Bar, i32)) -> bool { | error: item does not constrain `a::Foo::{opaque#0}`, but has it in its signature - --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:9:12 + --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:10:12 | LL | fn eq(&self, _other: &(Foo, i32)) -> bool { | ^^ @@ -29,7 +29,7 @@ LL | type Foo = impl PartialEq<(Foo, i32)>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0053]: method `eq` has an incompatible type for trait - --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:24:30 + --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:25:30 | LL | type Foo = impl PartialEq<(Foo, i32)>; | -------------------------- the expected opaque type @@ -39,8 +39,8 @@ LL | fn eq(&self, _other: &(Bar, i32)) -> bool { | = note: expected signature `fn(&b::Bar, &(b::Foo, _)) -> _` found signature `fn(&b::Bar, &(b::Bar, _)) -> _` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:24:12 +note: this item must have a `#[define_opaques(b::Foo)]` attribute to be able to define hidden types + --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:25:12 | LL | fn eq(&self, _other: &(Bar, i32)) -> bool { | ^^ @@ -51,12 +51,12 @@ LL + fn eq(&self, _other: &(b::Foo, i32)) -> bool { | error: unconstrained opaque type - --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:18:16 + --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:19:16 | LL | type Foo = impl PartialEq<(Foo, i32)>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `Foo` must be used in combination with a concrete type within the same module + = note: `Foo` must be used in combination with a concrete type within the same crate error: aborting due to 4 previous errors diff --git a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.rs b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.rs index aab10be2de27..2af8685ccd50 100644 --- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.rs +++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.rs @@ -10,6 +10,7 @@ impl PartialEq<(Bar, i32)> for Bar { } } +#[define_opaques(Foo)] fn foo() -> Foo { //~^ ERROR can't compare `Bar` with `(Foo, i32)` Bar diff --git a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.stderr b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.stderr index bc810c0f88f3..a9a5483caa9d 100644 --- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.stderr +++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration.stderr @@ -1,5 +1,5 @@ error[E0277]: can't compare `Bar` with `(Foo, i32)` - --> $DIR/recursive-type-alias-impl-trait-declaration.rs:13:13 + --> $DIR/recursive-type-alias-impl-trait-declaration.rs:14:13 | LL | fn foo() -> Foo { | ^^^ no implementation for `Bar == (Foo, i32)` diff --git a/tests/ui/impl-trait/two_tait_defining_each_other.current.stderr b/tests/ui/impl-trait/two_tait_defining_each_other.current.stderr index bf194f997b4a..8845b3ff2c82 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other.current.stderr +++ b/tests/ui/impl-trait/two_tait_defining_each_other.current.stderr @@ -1,5 +1,5 @@ error: opaque type's hidden type cannot be another opaque type from the same scope - --> $DIR/two_tait_defining_each_other.rs:17:5 + --> $DIR/two_tait_defining_each_other.rs:18:5 | LL | x // A's hidden type is `Bar`, because all the hidden types of `B` are compared with each other | ^ one of the two opaque types used here has to be outside its defining scope diff --git a/tests/ui/impl-trait/two_tait_defining_each_other.rs b/tests/ui/impl-trait/two_tait_defining_each_other.rs index ebfe7f674be0..b7f7463525e7 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other.rs +++ b/tests/ui/impl-trait/two_tait_defining_each_other.rs @@ -10,6 +10,7 @@ type B = impl Foo; trait Foo {} +#[define_opaques(A, B)] fn muh(x: A) -> B { if false { return Bar; // B's hidden type is Bar diff --git a/tests/ui/impl-trait/two_tait_defining_each_other2.current.stderr b/tests/ui/impl-trait/two_tait_defining_each_other2.current.stderr index 7d02a0606fc2..c7fc2b9cf334 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other2.current.stderr +++ b/tests/ui/impl-trait/two_tait_defining_each_other2.current.stderr @@ -1,5 +1,5 @@ error: item does not constrain `A::{opaque#0}`, but has it in its signature - --> $DIR/two_tait_defining_each_other2.rs:11:4 + --> $DIR/two_tait_defining_each_other2.rs:12:4 | LL | fn muh(x: A) -> B { | ^^^ @@ -12,7 +12,7 @@ LL | type A = impl Foo; | ^^^^^^^^ error: opaque type's hidden type cannot be another opaque type from the same scope - --> $DIR/two_tait_defining_each_other2.rs:14:5 + --> $DIR/two_tait_defining_each_other2.rs:15:5 | LL | x // B's hidden type is A (opaquely) | ^ one of the two opaque types used here has to be outside its defining scope diff --git a/tests/ui/impl-trait/two_tait_defining_each_other2.next.stderr b/tests/ui/impl-trait/two_tait_defining_each_other2.next.stderr index 5316160125bf..1a4c0f5f7eef 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other2.next.stderr +++ b/tests/ui/impl-trait/two_tait_defining_each_other2.next.stderr @@ -1,5 +1,5 @@ error[E0284]: type annotations needed: cannot satisfy `_ == A` - --> $DIR/two_tait_defining_each_other2.rs:11:8 + --> $DIR/two_tait_defining_each_other2.rs:12:8 | LL | fn muh(x: A) -> B { | ^ cannot satisfy `_ == A` diff --git a/tests/ui/impl-trait/two_tait_defining_each_other2.rs b/tests/ui/impl-trait/two_tait_defining_each_other2.rs index 1681b019418e..9d8f4444a9cb 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other2.rs +++ b/tests/ui/impl-trait/two_tait_defining_each_other2.rs @@ -8,6 +8,7 @@ type B = impl Foo; trait Foo {} +#[define_opaques(A, B)] fn muh(x: A) -> B { //[current]~^ ERROR: item does not constrain `A::{opaque#0}` //[next]~^^ ERROR: cannot satisfy `_ == A` diff --git a/tests/ui/impl-trait/two_tait_defining_each_other3.current.stderr b/tests/ui/impl-trait/two_tait_defining_each_other3.current.stderr index fa353a775360..7b0003ff59b1 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other3.current.stderr +++ b/tests/ui/impl-trait/two_tait_defining_each_other3.current.stderr @@ -1,5 +1,5 @@ error: opaque type's hidden type cannot be another opaque type from the same scope - --> $DIR/two_tait_defining_each_other3.rs:14:16 + --> $DIR/two_tait_defining_each_other3.rs:15:16 | LL | return x; // B's hidden type is A (opaquely) | ^ one of the two opaque types used here has to be outside its defining scope diff --git a/tests/ui/impl-trait/two_tait_defining_each_other3.rs b/tests/ui/impl-trait/two_tait_defining_each_other3.rs index 33695d8ed803..7f57a11414d1 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other3.rs +++ b/tests/ui/impl-trait/two_tait_defining_each_other3.rs @@ -9,6 +9,7 @@ type B = impl Foo; trait Foo {} +#[define_opaques(A, B)] fn muh(x: A) -> B { if false { return x; // B's hidden type is A (opaquely) diff --git a/tests/ui/impl-trait/type-alias-impl-trait-in-fn-body.rs b/tests/ui/impl-trait/type-alias-impl-trait-in-fn-body.rs index 4879d2db40b8..31a8eb2b3c84 100644 --- a/tests/ui/impl-trait/type-alias-impl-trait-in-fn-body.rs +++ b/tests/ui/impl-trait/type-alias-impl-trait-in-fn-body.rs @@ -9,6 +9,7 @@ fn main() { //~^ ERROR: item does not constrain type Existential = impl Debug; + #[define_opaques(Existential)] fn f() -> Existential {} println!("{:?}", f()); } diff --git a/tests/ui/impl-trait/where-allowed.rs b/tests/ui/impl-trait/where-allowed.rs index 3f435f0f443b..1c3c66c537ff 100644 --- a/tests/ui/impl-trait/where-allowed.rs +++ b/tests/ui/impl-trait/where-allowed.rs @@ -157,6 +157,7 @@ extern "C" fn in_extern_fn_return() -> impl Debug { type InTypeAlias = impl Debug; //~^ ERROR `impl Trait` in type aliases is unstable +//~| ERROR unconstrained opaque type type InReturnInTypeAlias = fn() -> impl Debug; //~^ ERROR `impl Trait` is not allowed in `fn` pointer diff --git a/tests/ui/impl-trait/where-allowed.stderr b/tests/ui/impl-trait/where-allowed.stderr index ebce9b7e445b..052ae5a99315 100644 --- a/tests/ui/impl-trait/where-allowed.stderr +++ b/tests/ui/impl-trait/where-allowed.stderr @@ -37,7 +37,7 @@ LL | type InTypeAlias = impl Debug; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: `impl Trait` in type aliases is unstable - --> $DIR/where-allowed.rs:161:39 + --> $DIR/where-allowed.rs:162:39 | LL | type InReturnInTypeAlias = fn() -> impl Debug; | ^^^^^^^^^^ @@ -199,7 +199,7 @@ LL | fn in_foreign_return() -> impl Debug; = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in `fn` pointer return types - --> $DIR/where-allowed.rs:161:39 + --> $DIR/where-allowed.rs:162:39 | LL | type InReturnInTypeAlias = fn() -> impl Debug; | ^^^^^^^^^^ @@ -207,7 +207,7 @@ LL | type InReturnInTypeAlias = fn() -> impl Debug; = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in traits - --> $DIR/where-allowed.rs:166:16 + --> $DIR/where-allowed.rs:167:16 | LL | impl PartialEq for () { | ^^^^^^^^^^ @@ -215,7 +215,7 @@ LL | impl PartialEq for () { = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in impl headers - --> $DIR/where-allowed.rs:171:24 + --> $DIR/where-allowed.rs:172:24 | LL | impl PartialEq<()> for impl Debug { | ^^^^^^^^^^ @@ -223,7 +223,7 @@ LL | impl PartialEq<()> for impl Debug { = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in impl headers - --> $DIR/where-allowed.rs:176:6 + --> $DIR/where-allowed.rs:177:6 | LL | impl impl Debug { | ^^^^^^^^^^ @@ -231,7 +231,7 @@ LL | impl impl Debug { = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in impl headers - --> $DIR/where-allowed.rs:182:24 + --> $DIR/where-allowed.rs:183:24 | LL | impl InInherentImplAdt { | ^^^^^^^^^^ @@ -239,7 +239,7 @@ LL | impl InInherentImplAdt { = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in bounds - --> $DIR/where-allowed.rs:188:11 + --> $DIR/where-allowed.rs:189:11 | LL | where impl Debug: Debug | ^^^^^^^^^^ @@ -247,7 +247,7 @@ LL | where impl Debug: Debug = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in bounds - --> $DIR/where-allowed.rs:195:15 + --> $DIR/where-allowed.rs:196:15 | LL | where Vec: Debug | ^^^^^^^^^^ @@ -255,7 +255,7 @@ LL | where Vec: Debug = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in bounds - --> $DIR/where-allowed.rs:202:24 + --> $DIR/where-allowed.rs:203:24 | LL | where T: PartialEq | ^^^^^^^^^^ @@ -263,7 +263,7 @@ LL | where T: PartialEq = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in the parameters of `Fn` trait bounds - --> $DIR/where-allowed.rs:209:17 + --> $DIR/where-allowed.rs:210:17 | LL | where T: Fn(impl Debug) | ^^^^^^^^^^ @@ -271,7 +271,7 @@ LL | where T: Fn(impl Debug) = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in the return type of `Fn` trait bounds - --> $DIR/where-allowed.rs:216:22 + --> $DIR/where-allowed.rs:217:22 | LL | where T: Fn() -> impl Debug | ^^^^^^^^^^ @@ -279,7 +279,7 @@ LL | where T: Fn() -> impl Debug = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in generic parameter defaults - --> $DIR/where-allowed.rs:222:40 + --> $DIR/where-allowed.rs:223:40 | LL | struct InStructGenericParamDefault(T); | ^^^^^^^^^^ @@ -287,7 +287,7 @@ LL | struct InStructGenericParamDefault(T); = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in generic parameter defaults - --> $DIR/where-allowed.rs:226:36 + --> $DIR/where-allowed.rs:227:36 | LL | enum InEnumGenericParamDefault { Variant(T) } | ^^^^^^^^^^ @@ -295,7 +295,7 @@ LL | enum InEnumGenericParamDefault { Variant(T) } = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in generic parameter defaults - --> $DIR/where-allowed.rs:230:38 + --> $DIR/where-allowed.rs:231:38 | LL | trait InTraitGenericParamDefault {} | ^^^^^^^^^^ @@ -303,7 +303,7 @@ LL | trait InTraitGenericParamDefault {} = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in generic parameter defaults - --> $DIR/where-allowed.rs:234:41 + --> $DIR/where-allowed.rs:235:41 | LL | type InTypeAliasGenericParamDefault = T; | ^^^^^^^^^^ @@ -311,7 +311,7 @@ LL | type InTypeAliasGenericParamDefault = T; = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in generic parameter defaults - --> $DIR/where-allowed.rs:238:11 + --> $DIR/where-allowed.rs:239:11 | LL | impl T {} | ^^^^^^^^^^ @@ -319,7 +319,7 @@ LL | impl T {} = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in generic parameter defaults - --> $DIR/where-allowed.rs:245:40 + --> $DIR/where-allowed.rs:246:40 | LL | fn in_method_generic_param_default(_: T) {} | ^^^^^^^^^^ @@ -327,7 +327,7 @@ LL | fn in_method_generic_param_default(_: T) {} = note: `impl Trait` is only allowed in arguments and return types of functions and methods error[E0562]: `impl Trait` is not allowed in the type of variable bindings - --> $DIR/where-allowed.rs:251:29 + --> $DIR/where-allowed.rs:252:29 | LL | let _in_local_variable: impl Fn() = || {}; | ^^^^^^^^^ @@ -338,7 +338,7 @@ LL | let _in_local_variable: impl Fn() = || {}; = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0562]: `impl Trait` is not allowed in closure return types - --> $DIR/where-allowed.rs:253:46 + --> $DIR/where-allowed.rs:254:46 | LL | let _in_return_in_local_variable = || -> impl Fn() { || {} }; | ^^^^^^^^^ @@ -369,7 +369,7 @@ LL + fn in_trait_impl_return() -> <() as DummyTrait>::Out { () } | error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions - --> $DIR/where-allowed.rs:245:36 + --> $DIR/where-allowed.rs:246:36 | LL | fn in_method_generic_param_default(_: T) {} | ^^^^^^^^^^^^^^ @@ -379,7 +379,7 @@ LL | fn in_method_generic_param_default(_: T) {} = note: `#[deny(invalid_type_param_default)]` on by default error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions - --> $DIR/where-allowed.rs:238:7 + --> $DIR/where-allowed.rs:239:7 | LL | impl T {} | ^^^^^^^^^^^^^^ @@ -408,7 +408,7 @@ LL | fn in_impl_Fn_return_in_return() -> &'static impl Fn() -> impl Debug { pani where Args: Tuple, F: Fn, A: Allocator, F: ?Sized; error[E0118]: no nominal type found for inherent implementation - --> $DIR/where-allowed.rs:238:1 + --> $DIR/where-allowed.rs:239:1 | LL | impl T {} | ^^^^^^^^^^^^^^^^^^^^^^^ impl requires a nominal type @@ -423,13 +423,21 @@ LL | type Out = impl Debug; | = note: `Out` must be used in combination with a concrete type within the same impl -error: aborting due to 49 previous errors +error: unconstrained opaque type + --> $DIR/where-allowed.rs:158:23 + | +LL | type InTypeAlias = impl Debug; + | ^^^^^^^^^^ + | + = note: `InTypeAlias` must be used in combination with a concrete type within the same crate + +error: aborting due to 50 previous errors Some errors have detailed explanations: E0053, E0118, E0283, E0562, E0658, E0666. For more information about an error, try `rustc --explain E0053`. Future incompatibility report: Future breakage diagnostic: error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions - --> $DIR/where-allowed.rs:245:36 + --> $DIR/where-allowed.rs:246:36 | LL | fn in_method_generic_param_default(_: T) {} | ^^^^^^^^^^^^^^ @@ -440,7 +448,7 @@ LL | fn in_method_generic_param_default(_: T) {} Future breakage diagnostic: error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions - --> $DIR/where-allowed.rs:238:7 + --> $DIR/where-allowed.rs:239:7 | LL | impl T {} | ^^^^^^^^^^^^^^ diff --git a/tests/ui/implied-bounds/dyn-erasure-tait.rs b/tests/ui/implied-bounds/dyn-erasure-tait.rs index 4766d221d67c..534ff959c27e 100644 --- a/tests/ui/implied-bounds/dyn-erasure-tait.rs +++ b/tests/ui/implied-bounds/dyn-erasure-tait.rs @@ -14,6 +14,7 @@ type T<'lt> = &'lt str; type F<'a, 'b> = impl 'static + Fn(T<'a>) -> T<'b>; +#[define_opaques(F)] fn helper<'a, 'b>(_: [&'b &'a (); 0]) -> F<'a, 'b> { |x: T<'a>| -> T<'b> { x } // this should *not* be `: 'static` } diff --git a/tests/ui/layout/debug.rs b/tests/ui/layout/debug.rs index b87a1d2031df..2a6648ee562b 100644 --- a/tests/ui/layout/debug.rs +++ b/tests/ui/layout/debug.rs @@ -18,6 +18,7 @@ type Test = Result; //~ ERROR: layout_of #[rustc_layout(debug)] type T = impl std::fmt::Debug; //~ ERROR: layout_of +#[define_opaques(T)] fn f() -> T { 0i32 } diff --git a/tests/ui/layout/debug.stderr b/tests/ui/layout/debug.stderr index 07cad7766920..d82a092d80d8 100644 --- a/tests/ui/layout/debug.stderr +++ b/tests/ui/layout/debug.stderr @@ -1,5 +1,5 @@ error: unions cannot have zero fields - --> $DIR/debug.rs:83:1 + --> $DIR/debug.rs:84:1 | LL | union EmptyUnion {} | ^^^^^^^^^^^^^^^^^^^ @@ -372,7 +372,7 @@ error: layout_of(V) = Layout { unadjusted_abi_align: Align(2 bytes), randomization_seed: $SEED, } - --> $DIR/debug.rs:26:1 + --> $DIR/debug.rs:27:1 | LL | pub union V { | ^^^^^^^^^^^ @@ -398,7 +398,7 @@ error: layout_of(W) = Layout { unadjusted_abi_align: Align(2 bytes), randomization_seed: $SEED, } - --> $DIR/debug.rs:32:1 + --> $DIR/debug.rs:33:1 | LL | pub union W { | ^^^^^^^^^^^ @@ -424,7 +424,7 @@ error: layout_of(Y) = Layout { unadjusted_abi_align: Align(2 bytes), randomization_seed: $SEED, } - --> $DIR/debug.rs:38:1 + --> $DIR/debug.rs:39:1 | LL | pub union Y { | ^^^^^^^^^^^ @@ -450,7 +450,7 @@ error: layout_of(P1) = Layout { unadjusted_abi_align: Align(1 bytes), randomization_seed: $SEED, } - --> $DIR/debug.rs:45:1 + --> $DIR/debug.rs:46:1 | LL | union P1 { x: u32 } | ^^^^^^^^ @@ -476,7 +476,7 @@ error: layout_of(P2) = Layout { unadjusted_abi_align: Align(1 bytes), randomization_seed: $SEED, } - --> $DIR/debug.rs:49:1 + --> $DIR/debug.rs:50:1 | LL | union P2 { x: (u32, u32) } | ^^^^^^^^ @@ -502,7 +502,7 @@ error: layout_of(P3) = Layout { unadjusted_abi_align: Align(1 bytes), randomization_seed: $SEED, } - --> $DIR/debug.rs:57:1 + --> $DIR/debug.rs:58:1 | LL | union P3 { x: F32x4 } | ^^^^^^^^ @@ -528,7 +528,7 @@ error: layout_of(P4) = Layout { unadjusted_abi_align: Align(1 bytes), randomization_seed: $SEED, } - --> $DIR/debug.rs:61:1 + --> $DIR/debug.rs:62:1 | LL | union P4 { x: E } | ^^^^^^^^ @@ -559,7 +559,7 @@ error: layout_of(P5) = Layout { unadjusted_abi_align: Align(1 bytes), randomization_seed: $SEED, } - --> $DIR/debug.rs:65:1 + --> $DIR/debug.rs:66:1 | LL | union P5 { zst: [u16; 0], byte: u8 } | ^^^^^^^^ @@ -590,19 +590,19 @@ error: layout_of(MaybeUninit) = Layout { unadjusted_abi_align: Align(1 bytes), randomization_seed: $SEED, } - --> $DIR/debug.rs:68:1 + --> $DIR/debug.rs:69:1 | LL | type X = std::mem::MaybeUninit; | ^^^^^^ error: `#[rustc_layout]` can only be applied to `struct`/`enum`/`union` declarations and type aliases - --> $DIR/debug.rs:71:1 + --> $DIR/debug.rs:72:1 | LL | const C: () = (); | ^^^^^^^^^^^ error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/debug.rs:79:19 + --> $DIR/debug.rs:80:19 | LL | type Impossible = (str, str); | ^^^^^^^^^^ doesn't have a size known at compile-time @@ -611,19 +611,19 @@ LL | type Impossible = (str, str); = note: only the last element of a tuple may have a dynamically sized type error: the type has an unknown layout - --> $DIR/debug.rs:83:1 + --> $DIR/debug.rs:84:1 | LL | union EmptyUnion {} | ^^^^^^^^^^^^^^^^ error: the type `T` does not have a fixed layout - --> $DIR/debug.rs:89:1 + --> $DIR/debug.rs:90:1 | LL | type TooGeneric = T; | ^^^^^^^^^^^^^^^^^^ error: `#[rustc_layout]` can only be applied to `struct`/`enum`/`union` declarations and type aliases - --> $DIR/debug.rs:75:5 + --> $DIR/debug.rs:76:5 | LL | const C: () = (); | ^^^^^^^^^^^ diff --git a/tests/ui/lazy-type-alias-impl-trait/branches.rs b/tests/ui/lazy-type-alias-impl-trait/branches.rs index 95239e2e341c..9ce6ca4f294a 100644 --- a/tests/ui/lazy-type-alias-impl-trait/branches.rs +++ b/tests/ui/lazy-type-alias-impl-trait/branches.rs @@ -2,6 +2,7 @@ type Foo = impl std::fmt::Debug; +#[define_opaques(Foo)] fn foo(b: bool) -> Foo { if b { vec![42_i32] @@ -12,6 +13,7 @@ fn foo(b: bool) -> Foo { type Bar = impl std::fmt::Debug; +#[define_opaques(Bar)] fn bar(b: bool) -> Bar { let x: Bar = if b { vec![42_i32] diff --git a/tests/ui/lazy-type-alias-impl-trait/branches.stderr b/tests/ui/lazy-type-alias-impl-trait/branches.stderr index 9e9376227751..793409b9c78e 100644 --- a/tests/ui/lazy-type-alias-impl-trait/branches.stderr +++ b/tests/ui/lazy-type-alias-impl-trait/branches.stderr @@ -1,5 +1,5 @@ error[E0277]: a value of type `Bar` cannot be built from an iterator over elements of type `_` - --> $DIR/branches.rs:19:28 + --> $DIR/branches.rs:21:28 | LL | std::iter::empty().collect() | ^^^^^^^ value of type `Bar` cannot be built from `std::iter::Iterator` diff --git a/tests/ui/lazy-type-alias-impl-trait/branches2.rs b/tests/ui/lazy-type-alias-impl-trait/branches2.rs index 467400f1c244..7ffb8d29160e 100644 --- a/tests/ui/lazy-type-alias-impl-trait/branches2.rs +++ b/tests/ui/lazy-type-alias-impl-trait/branches2.rs @@ -4,20 +4,13 @@ type Foo = impl std::iter::FromIterator + PartialEq> + std::fmt::Debug; +#[define_opaques(Foo)] fn foo(b: bool) -> Foo { - if b { - vec![42_i32] - } else { - std::iter::empty().collect() - } + if b { vec![42_i32] } else { std::iter::empty().collect() } } fn bar(b: bool) -> impl PartialEq> + std::fmt::Debug { - if b { - vec![42_i32] - } else { - std::iter::empty().collect() - } + if b { vec![42_i32] } else { std::iter::empty().collect() } } fn main() { diff --git a/tests/ui/lazy-type-alias-impl-trait/branches3.rs b/tests/ui/lazy-type-alias-impl-trait/branches3.rs index 30c0af8a5dc9..3904a128671f 100644 --- a/tests/ui/lazy-type-alias-impl-trait/branches3.rs +++ b/tests/ui/lazy-type-alias-impl-trait/branches3.rs @@ -3,6 +3,7 @@ type Foo = impl for<'a> FnOnce(&'a str) -> usize; type Bar = impl FnOnce(&'static str) -> usize; +#[define_opaques(Foo)] fn foo() -> Foo { if true { |s| s.len() //~ ERROR type annotations needed @@ -10,6 +11,8 @@ fn foo() -> Foo { panic!() } } + +#[define_opaques(Bar)] fn bar() -> Bar { if true { |s| s.len() //~ ERROR type annotations needed diff --git a/tests/ui/lazy-type-alias-impl-trait/branches3.stderr b/tests/ui/lazy-type-alias-impl-trait/branches3.stderr index fe2631f94742..117d189867bd 100644 --- a/tests/ui/lazy-type-alias-impl-trait/branches3.stderr +++ b/tests/ui/lazy-type-alias-impl-trait/branches3.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed - --> $DIR/branches3.rs:8:10 + --> $DIR/branches3.rs:9:10 | LL | |s| s.len() | ^ - type must be known at this point @@ -10,7 +10,7 @@ LL | |s: /* Type */| s.len() | ++++++++++++ error[E0282]: type annotations needed - --> $DIR/branches3.rs:15:10 + --> $DIR/branches3.rs:18:10 | LL | |s| s.len() | ^ - type must be known at this point @@ -21,7 +21,7 @@ LL | |s: /* Type */| s.len() | ++++++++++++ error[E0282]: type annotations needed - --> $DIR/branches3.rs:23:10 + --> $DIR/branches3.rs:26:10 | LL | |s| s.len() | ^ - type must be known at this point @@ -32,7 +32,7 @@ LL | |s: /* Type */| s.len() | ++++++++++++ error[E0282]: type annotations needed - --> $DIR/branches3.rs:30:10 + --> $DIR/branches3.rs:33:10 | LL | |s| s.len() | ^ - type must be known at this point diff --git a/tests/ui/lazy-type-alias-impl-trait/recursion.rs b/tests/ui/lazy-type-alias-impl-trait/recursion.rs index 519335605990..11ae0e5a55a4 100644 --- a/tests/ui/lazy-type-alias-impl-trait/recursion.rs +++ b/tests/ui/lazy-type-alias-impl-trait/recursion.rs @@ -4,9 +4,10 @@ type Foo = impl std::fmt::Debug; +#[define_opaques(Foo)] fn foo(b: bool) -> Foo { if b { - return 42 + return 42; } let x: u32 = foo(false); 99 @@ -14,7 +15,7 @@ fn foo(b: bool) -> Foo { fn bar(b: bool) -> impl std::fmt::Debug { if b { - return 42 + return 42; } let x: u32 = bar(false); 99 diff --git a/tests/ui/lazy-type-alias-impl-trait/recursion2.rs b/tests/ui/lazy-type-alias-impl-trait/recursion2.rs index e14da32e1166..e2ce3af28422 100644 --- a/tests/ui/lazy-type-alias-impl-trait/recursion2.rs +++ b/tests/ui/lazy-type-alias-impl-trait/recursion2.rs @@ -4,6 +4,7 @@ type Foo = impl std::fmt::Debug; +#[define_opaques(Foo)] fn foo(b: bool) -> Foo { if b { return vec![]; @@ -14,7 +15,7 @@ fn foo(b: bool) -> Foo { fn bar(b: bool) -> impl std::fmt::Debug { if b { - return vec![] + return vec![]; } let x: Vec = bar(false); std::iter::empty().collect() diff --git a/tests/ui/lazy-type-alias-impl-trait/recursion3.rs b/tests/ui/lazy-type-alias-impl-trait/recursion3.rs index 7f1cedae068f..43aa2d72b99e 100644 --- a/tests/ui/lazy-type-alias-impl-trait/recursion3.rs +++ b/tests/ui/lazy-type-alias-impl-trait/recursion3.rs @@ -2,9 +2,10 @@ type Foo = impl std::fmt::Debug; +#[define_opaques(Foo)] fn foo(b: bool) -> Foo { if b { - return 42 + return 42; } let x: u32 = foo(false) + 42; //~ ERROR cannot add 99 @@ -12,7 +13,7 @@ fn foo(b: bool) -> Foo { fn bar(b: bool) -> impl std::fmt::Debug { if b { - return 42 + return 42; } let x: u32 = bar(false) + 42; //~ ERROR cannot add 99 diff --git a/tests/ui/lazy-type-alias-impl-trait/recursion3.stderr b/tests/ui/lazy-type-alias-impl-trait/recursion3.stderr index e1d5cafedc80..0cbedfb69f85 100644 --- a/tests/ui/lazy-type-alias-impl-trait/recursion3.stderr +++ b/tests/ui/lazy-type-alias-impl-trait/recursion3.stderr @@ -1,5 +1,5 @@ error[E0369]: cannot add `{integer}` to `Foo` - --> $DIR/recursion3.rs:9:29 + --> $DIR/recursion3.rs:10:29 | LL | let x: u32 = foo(false) + 42; | ---------- ^ -- {integer} @@ -7,7 +7,7 @@ LL | let x: u32 = foo(false) + 42; | Foo error[E0369]: cannot add `{integer}` to `impl Debug` - --> $DIR/recursion3.rs:17:29 + --> $DIR/recursion3.rs:18:29 | LL | let x: u32 = bar(false) + 42; | ---------- ^ -- {integer} diff --git a/tests/ui/lazy-type-alias-impl-trait/recursion4.rs b/tests/ui/lazy-type-alias-impl-trait/recursion4.rs index 57dd7fb067c6..15627a657e0a 100644 --- a/tests/ui/lazy-type-alias-impl-trait/recursion4.rs +++ b/tests/ui/lazy-type-alias-impl-trait/recursion4.rs @@ -2,6 +2,7 @@ type Foo = impl std::fmt::Debug; +#[define_opaques(Foo)] fn foo(b: bool) -> Foo { if b { return vec![]; diff --git a/tests/ui/lazy-type-alias-impl-trait/recursion4.stderr b/tests/ui/lazy-type-alias-impl-trait/recursion4.stderr index d8ac39a4f27a..b04bf6b99877 100644 --- a/tests/ui/lazy-type-alias-impl-trait/recursion4.stderr +++ b/tests/ui/lazy-type-alias-impl-trait/recursion4.stderr @@ -1,5 +1,5 @@ error[E0277]: a value of type `Foo` cannot be built from an iterator over elements of type `_` - --> $DIR/recursion4.rs:10:28 + --> $DIR/recursion4.rs:11:28 | LL | x = std::iter::empty().collect(); | ^^^^^^^ value of type `Foo` cannot be built from `std::iter::Iterator` @@ -9,7 +9,7 @@ note: required by a bound in `collect` --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL error[E0277]: a value of type `impl Debug` cannot be built from an iterator over elements of type `_` - --> $DIR/recursion4.rs:19:28 + --> $DIR/recursion4.rs:20:28 | LL | x = std::iter::empty().collect(); | ^^^^^^^ value of type `impl Debug` cannot be built from `std::iter::Iterator` diff --git a/tests/ui/lint/issue-99387.rs b/tests/ui/lint/issue-99387.rs index 6f0822394564..1cde61a7b48b 100644 --- a/tests/ui/lint/issue-99387.rs +++ b/tests/ui/lint/issue-99387.rs @@ -6,6 +6,7 @@ pub type Successors<'a> = impl Iterator; +#[define_opaques(Successors)] pub fn f<'a>() -> Successors<'a> { None.into_iter() } diff --git a/tests/ui/lint/issue-99387.stderr b/tests/ui/lint/issue-99387.stderr index 4eee4f363929..1e438f416836 100644 --- a/tests/ui/lint/issue-99387.stderr +++ b/tests/ui/lint/issue-99387.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-99387.rs:22:5 + --> $DIR/issue-99387.rs:23:5 | LL | pub type Successors<'a> = impl Iterator; | ---------------------------- the expected opaque type @@ -11,8 +11,8 @@ LL | None.into_iter() | = note: expected opaque type `Successors<'a>` found struct `std::option::IntoIter<_>` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/issue-99387.rs:21:8 +note: this item must have a `#[define_opaques(Successors)]` attribute to be able to define hidden types + --> $DIR/issue-99387.rs:22:8 | LL | pub fn ohno<'a>() -> <&'a () as Tr>::Item { | ^^^^ diff --git a/tests/ui/lint/let_underscore/issue-119697-extra-let.rs b/tests/ui/lint/let_underscore/issue-119697-extra-let.rs index 84abb933911f..29a5b7e100fb 100644 --- a/tests/ui/lint/let_underscore/issue-119697-extra-let.rs +++ b/tests/ui/lint/let_underscore/issue-119697-extra-let.rs @@ -8,6 +8,7 @@ pub struct Foo { pub type Tait = impl Sized; +#[define_opaques(Tait)] pub fn ice_cold(beverage: Tait) { // Must destructure at least one field of `Foo` let Foo { field } = beverage; @@ -17,5 +18,4 @@ pub fn ice_cold(beverage: Tait) { let _ = field; //~ ERROR non-binding let on a type that has a destructor } - pub fn main() {} diff --git a/tests/ui/lint/let_underscore/issue-119697-extra-let.stderr b/tests/ui/lint/let_underscore/issue-119697-extra-let.stderr index 3ff57ab441dc..8d5deadd46e2 100644 --- a/tests/ui/lint/let_underscore/issue-119697-extra-let.stderr +++ b/tests/ui/lint/let_underscore/issue-119697-extra-let.stderr @@ -1,5 +1,5 @@ error: non-binding let on a type that has a destructor - --> $DIR/issue-119697-extra-let.rs:15:5 + --> $DIR/issue-119697-extra-let.rs:16:5 | LL | _ = field; | ^^^^^^^^^ @@ -21,7 +21,7 @@ LL + drop(field); | error: non-binding let on a type that has a destructor - --> $DIR/issue-119697-extra-let.rs:17:5 + --> $DIR/issue-119697-extra-let.rs:18:5 | LL | let _ = field; | ^^^^^^^^^^^^^^ diff --git a/tests/ui/lint/lint-ctypes-73249-2.rs b/tests/ui/lint/lint-ctypes-73249-2.rs index f30377d6c16e..68f0af969ab2 100644 --- a/tests/ui/lint/lint-ctypes-73249-2.rs +++ b/tests/ui/lint/lint-ctypes-73249-2.rs @@ -7,6 +7,7 @@ impl Baz for () {} type Qux = impl Baz; +#[define_opaques(Qux)] fn assign() -> Qux {} trait Foo { diff --git a/tests/ui/lint/lint-ctypes-73249-2.stderr b/tests/ui/lint/lint-ctypes-73249-2.stderr index ef30a406969d..2d0dfe94f097 100644 --- a/tests/ui/lint/lint-ctypes-73249-2.stderr +++ b/tests/ui/lint/lint-ctypes-73249-2.stderr @@ -1,5 +1,5 @@ error: `extern` block uses type `Qux`, which is not FFI-safe - --> $DIR/lint-ctypes-73249-2.rs:26:21 + --> $DIR/lint-ctypes-73249-2.rs:27:21 | LL | fn lint_me() -> A<()>; | ^^^^^ not FFI-safe diff --git a/tests/ui/lint/lint-ctypes-73249-3.rs b/tests/ui/lint/lint-ctypes-73249-3.rs index ef8ab7e03d2f..69007c008a3e 100644 --- a/tests/ui/lint/lint-ctypes-73249-3.rs +++ b/tests/ui/lint/lint-ctypes-73249-3.rs @@ -7,6 +7,7 @@ impl Baz for u32 {} type Qux = impl Baz; +#[define_opaques(Qux)] fn assign() -> Qux { 3 } diff --git a/tests/ui/lint/lint-ctypes-73249-3.stderr b/tests/ui/lint/lint-ctypes-73249-3.stderr index e5607ba72e97..e1a313a29065 100644 --- a/tests/ui/lint/lint-ctypes-73249-3.stderr +++ b/tests/ui/lint/lint-ctypes-73249-3.stderr @@ -1,5 +1,5 @@ error: `extern` block uses type `Qux`, which is not FFI-safe - --> $DIR/lint-ctypes-73249-3.rs:20:25 + --> $DIR/lint-ctypes-73249-3.rs:21:25 | LL | pub fn lint_me() -> A; | ^ not FFI-safe diff --git a/tests/ui/lint/lint-ctypes-73249-5.rs b/tests/ui/lint/lint-ctypes-73249-5.rs index 083fb6c5fb16..fb241bc7e8f9 100644 --- a/tests/ui/lint/lint-ctypes-73249-5.rs +++ b/tests/ui/lint/lint-ctypes-73249-5.rs @@ -7,6 +7,7 @@ impl Baz for u32 {} type Qux = impl Baz; +#[define_opaques(Qux)] fn assign() -> Qux { 3 } diff --git a/tests/ui/lint/lint-ctypes-73249-5.stderr b/tests/ui/lint/lint-ctypes-73249-5.stderr index fcb106c485d8..c4fa955de05e 100644 --- a/tests/ui/lint/lint-ctypes-73249-5.stderr +++ b/tests/ui/lint/lint-ctypes-73249-5.stderr @@ -1,5 +1,5 @@ error: `extern` block uses type `Qux`, which is not FFI-safe - --> $DIR/lint-ctypes-73249-5.rs:20:25 + --> $DIR/lint-ctypes-73249-5.rs:21:25 | LL | pub fn lint_me() -> A; | ^ not FFI-safe diff --git a/tests/ui/lint/lint-ctypes-73251-1.rs b/tests/ui/lint/lint-ctypes-73251-1.rs index fc11f23a1049..d542426abd1d 100644 --- a/tests/ui/lint/lint-ctypes-73251-1.rs +++ b/tests/ui/lint/lint-ctypes-73251-1.rs @@ -15,6 +15,7 @@ impl Foo for u32 { type Assoc = Qux; } +#[define_opaques(Qux)] fn assign() -> Qux { 1 } diff --git a/tests/ui/lint/lint-ctypes-73251-1.stderr b/tests/ui/lint/lint-ctypes-73251-1.stderr index a3b3ebaac303..675a9de51cd0 100644 --- a/tests/ui/lint/lint-ctypes-73251-1.stderr +++ b/tests/ui/lint/lint-ctypes-73251-1.stderr @@ -1,5 +1,5 @@ error: `extern` block uses type `Qux`, which is not FFI-safe - --> $DIR/lint-ctypes-73251-1.rs:23:21 + --> $DIR/lint-ctypes-73251-1.rs:24:21 | LL | fn lint_me() -> ::Assoc; | ^^^^^^^^^^^^^^^^^^^ not FFI-safe diff --git a/tests/ui/lint/lint-ctypes-73251-2.rs b/tests/ui/lint/lint-ctypes-73251-2.rs index fbe0a58f3b5b..9ebba4a902f0 100644 --- a/tests/ui/lint/lint-ctypes-73251-2.rs +++ b/tests/ui/lint/lint-ctypes-73251-2.rs @@ -24,10 +24,12 @@ type AliasA = impl TraitA; type AliasB = impl TraitB; +#[define_opaques(AliasA)] fn use_of_a() -> AliasA { 3 } +#[define_opaques(AliasB)] fn use_of_b() -> AliasB { 3 } diff --git a/tests/ui/lint/lint-ctypes-73251-2.stderr b/tests/ui/lint/lint-ctypes-73251-2.stderr index 40a9cd00c50f..634950b29ed4 100644 --- a/tests/ui/lint/lint-ctypes-73251-2.stderr +++ b/tests/ui/lint/lint-ctypes-73251-2.stderr @@ -1,5 +1,5 @@ error: `extern` block uses type `AliasA`, which is not FFI-safe - --> $DIR/lint-ctypes-73251-2.rs:36:21 + --> $DIR/lint-ctypes-73251-2.rs:38:21 | LL | fn lint_me() -> ::Assoc; | ^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe diff --git a/tests/ui/lint/lint-ctypes-73251.rs b/tests/ui/lint/lint-ctypes-73251.rs index 68eeb67deeae..92effd58a966 100644 --- a/tests/ui/lint/lint-ctypes-73251.rs +++ b/tests/ui/lint/lint-ctypes-73251.rs @@ -13,6 +13,7 @@ impl Foo for () { type Bar = impl Foo; +#[define_opaques(Bar)] fn assign() -> Bar {} extern "C" { diff --git a/tests/ui/lint/opaque-ty-ffi-normalization-cycle.rs b/tests/ui/lint/opaque-ty-ffi-normalization-cycle.rs index c83bca4a4c57..70f7e9e663d7 100644 --- a/tests/ui/lint/opaque-ty-ffi-normalization-cycle.rs +++ b/tests/ui/lint/opaque-ty-ffi-normalization-cycle.rs @@ -25,10 +25,12 @@ type AliasA = impl TraitA; type AliasB = impl TraitB; +#[define_opaques(AliasA)] fn use_of_a() -> AliasA { 3 } +#[define_opaques(AliasB)] fn use_of_b() -> AliasB { 3 } diff --git a/tests/ui/lint/opaque-ty-ffi-normalization-cycle.stderr b/tests/ui/lint/opaque-ty-ffi-normalization-cycle.stderr index 9efc187833f0..020eac4febb8 100644 --- a/tests/ui/lint/opaque-ty-ffi-normalization-cycle.stderr +++ b/tests/ui/lint/opaque-ty-ffi-normalization-cycle.stderr @@ -1,5 +1,5 @@ error: `extern` block uses type `AliasB`, which is not FFI-safe - --> $DIR/opaque-ty-ffi-normalization-cycle.rs:37:21 + --> $DIR/opaque-ty-ffi-normalization-cycle.rs:39:21 | LL | fn lint_me() -> ::Assoc; | ^^^^^^^^^^^^^^^^^^^^^^^^^ not FFI-safe diff --git a/tests/ui/lint/opaque-ty-ffi-unsafe.rs b/tests/ui/lint/opaque-ty-ffi-unsafe.rs index 5faeac9ed4c3..e81fe0211c98 100644 --- a/tests/ui/lint/opaque-ty-ffi-unsafe.rs +++ b/tests/ui/lint/opaque-ty-ffi-unsafe.rs @@ -3,6 +3,7 @@ type A = impl Fn(); +#[define_opaques(A)] pub(crate) fn ret_closure() -> A { || {} } diff --git a/tests/ui/lint/opaque-ty-ffi-unsafe.stderr b/tests/ui/lint/opaque-ty-ffi-unsafe.stderr index 7f5d1792bf12..5c52f7026714 100644 --- a/tests/ui/lint/opaque-ty-ffi-unsafe.stderr +++ b/tests/ui/lint/opaque-ty-ffi-unsafe.stderr @@ -1,5 +1,5 @@ error: `extern` block uses type `A`, which is not FFI-safe - --> $DIR/opaque-ty-ffi-unsafe.rs:11:24 + --> $DIR/opaque-ty-ffi-unsafe.rs:12:24 | LL | pub(crate) fn a(_: A); | ^ not FFI-safe diff --git a/tests/ui/methods/opaque_param_in_ufc.rs b/tests/ui/methods/opaque_param_in_ufc.rs index b170e6805f64..0d038d410305 100644 --- a/tests/ui/methods/opaque_param_in_ufc.rs +++ b/tests/ui/methods/opaque_param_in_ufc.rs @@ -11,11 +11,13 @@ impl Foo { type Bar = impl Sized; +#[define_opaques(Bar)] fn bar() -> Bar { 42_u32 } impl Foo { + #[define_opaques(Bar)] fn foo() -> Bar { Self::method(); Foo::::method(); diff --git a/tests/ui/mir/issue-75053.rs b/tests/ui/mir/issue-75053.rs index 38684f3548f2..de81325e8e1a 100644 --- a/tests/ui/mir/issue-75053.rs +++ b/tests/ui/mir/issue-75053.rs @@ -13,13 +13,11 @@ trait MyFrom: Sized { fn my_from(value: T) -> Result; } -mod f { - pub trait F {} - impl F for () {} - pub type DummyT = impl F; - fn _dummy_t() -> DummyT {} -} -use f::*; +pub trait F {} +impl F for () {} +pub type DummyT = impl F; +#[define_opaques(DummyT)] +fn _dummy_t() -> DummyT {} struct Phantom1(PhantomData); struct Phantom2(PhantomData); diff --git a/tests/ui/mir/issue-75053.stderr b/tests/ui/mir/issue-75053.stderr index a464d3266f4e..91032bc3797e 100644 --- a/tests/ui/mir/issue-75053.stderr +++ b/tests/ui/mir/issue-75053.stderr @@ -1,5 +1,5 @@ error: fatal error triggered by #[rustc_error] - --> $DIR/issue-75053.rs:49:1 + --> $DIR/issue-75053.rs:47:1 | LL | fn main() { | ^^^^^^^^^ diff --git a/tests/ui/never_type/impl_trait_fallback2.rs b/tests/ui/never_type/impl_trait_fallback2.rs index 12c187b9e82a..8116f5e64401 100644 --- a/tests/ui/never_type/impl_trait_fallback2.rs +++ b/tests/ui/never_type/impl_trait_fallback2.rs @@ -12,11 +12,13 @@ fn should_ret_unit() -> impl T { type Foo = impl T; +#[define_opaques(Foo)] fn a() -> Foo { //~^ ERROR `(): T` is not satisfied panic!() } +#[define_opaques(Foo)] fn b() -> Foo { 42 } diff --git a/tests/ui/never_type/impl_trait_fallback2.stderr b/tests/ui/never_type/impl_trait_fallback2.stderr index 4c32dce465b8..0f197aa5cc6f 100644 --- a/tests/ui/never_type/impl_trait_fallback2.stderr +++ b/tests/ui/never_type/impl_trait_fallback2.stderr @@ -10,7 +10,7 @@ LL | panic!() = help: the trait `T` is implemented for `i32` error[E0277]: the trait bound `(): T` is not satisfied - --> $DIR/impl_trait_fallback2.rs:15:11 + --> $DIR/impl_trait_fallback2.rs:16:11 | LL | fn a() -> Foo { | ^^^ the trait `T` is not implemented for `()` diff --git a/tests/ui/never_type/impl_trait_fallback3.rs b/tests/ui/never_type/impl_trait_fallback3.rs index ed645b82394a..74b1f6e87947 100644 --- a/tests/ui/never_type/impl_trait_fallback3.rs +++ b/tests/ui/never_type/impl_trait_fallback3.rs @@ -8,6 +8,7 @@ trait T { type Foo = impl T; +#[define_opaques(Foo)] fn a() -> Foo { //~^ ERROR the trait bound `(): T` is not satisfied // This is not a defining use, it doesn't actually constrain the opaque type. diff --git a/tests/ui/never_type/impl_trait_fallback3.stderr b/tests/ui/never_type/impl_trait_fallback3.stderr index fde8d0896dda..11425a749534 100644 --- a/tests/ui/never_type/impl_trait_fallback3.stderr +++ b/tests/ui/never_type/impl_trait_fallback3.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `(): T` is not satisfied - --> $DIR/impl_trait_fallback3.rs:11:11 + --> $DIR/impl_trait_fallback3.rs:12:11 | LL | fn a() -> Foo { | ^^^ the trait `T` is not implemented for `()` diff --git a/tests/ui/never_type/impl_trait_fallback4.rs b/tests/ui/never_type/impl_trait_fallback4.rs index fe62773fa02d..05a2a829cf9b 100644 --- a/tests/ui/never_type/impl_trait_fallback4.rs +++ b/tests/ui/never_type/impl_trait_fallback4.rs @@ -15,6 +15,7 @@ fn foo() -> impl T { panic!() } +#[define_opaques(Foo)] fn a() -> Foo { foo() } diff --git a/tests/ui/pattern/usefulness/impl-trait.rs b/tests/ui/pattern/usefulness/impl-trait.rs index 16560a092675..726b0a4ead97 100644 --- a/tests/ui/pattern/usefulness/impl-trait.rs +++ b/tests/ui/pattern/usefulness/impl-trait.rs @@ -25,6 +25,7 @@ fn friend_of_return_never_rpit(x: Void) { } type T = impl Copy; +#[define_opaques(T)] fn return_never_tait(x: Void) -> T { if false { match return_never_tait(x) { @@ -88,6 +89,7 @@ fn inner_tuple() { } type U = impl Copy; +#[define_opaques(U)] fn unify_never(x: Void, u: U) -> U { if false { match u { @@ -98,6 +100,7 @@ fn unify_never(x: Void, u: U) -> U { } type V = impl Copy; +#[define_opaques(V)] fn infer_in_match(x: Option) { match x { None => {} @@ -116,6 +119,7 @@ struct Rec<'a> { n: u32, w: Option<&'a W>, } +#[define_opaques(W)] fn recursive_opaque() -> W { if false { match recursive_opaque() { @@ -130,6 +134,7 @@ fn recursive_opaque() -> W { type X = impl Copy; struct SecretelyVoid(X); +#[define_opaques(X)] fn nested_empty_opaque(x: Void) -> X { if false { let opaque_void = nested_empty_opaque(x); @@ -143,6 +148,7 @@ fn nested_empty_opaque(x: Void) -> X { type Y = (impl Copy, impl Copy); struct SecretelyDoubleVoid(Y); +#[define_opaques(Y)] fn super_nested_empty_opaque(x: Void) -> Y { if false { let opaque_void = super_nested_empty_opaque(x); diff --git a/tests/ui/pattern/usefulness/impl-trait.stderr b/tests/ui/pattern/usefulness/impl-trait.stderr index c3e1c267b614..62045151968e 100644 --- a/tests/ui/pattern/usefulness/impl-trait.stderr +++ b/tests/ui/pattern/usefulness/impl-trait.stderr @@ -15,7 +15,7 @@ LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/impl-trait.rs:31:13 + --> $DIR/impl-trait.rs:32:13 | LL | _ => {} | ^------ @@ -25,22 +25,8 @@ LL | _ => {} | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types -error[E0004]: non-exhaustive patterns: type `impl Copy` is non-empty - --> $DIR/impl-trait.rs:23:11 - | -LL | match return_never_rpit(x) {} - | ^^^^^^^^^^^^^^^^^^^^ - | - = note: the matched value is of type `impl Copy` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown - | -LL ~ match return_never_rpit(x) { -LL + _ => todo!(), -LL ~ } - | - error: unreachable pattern - --> $DIR/impl-trait.rs:45:13 + --> $DIR/impl-trait.rs:46:13 | LL | Some(_) => {} | ^^^^^^^------ @@ -51,7 +37,7 @@ LL | Some(_) => {} = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types error: unreachable pattern - --> $DIR/impl-trait.rs:49:13 + --> $DIR/impl-trait.rs:50:13 | LL | None => {} | ---- matches all the relevant values @@ -59,7 +45,7 @@ LL | _ => {} | ^ no value can reach this error: unreachable pattern - --> $DIR/impl-trait.rs:59:13 + --> $DIR/impl-trait.rs:60:13 | LL | Some(_) => {} | ^^^^^^^------ @@ -70,7 +56,7 @@ LL | Some(_) => {} = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types error: unreachable pattern - --> $DIR/impl-trait.rs:63:13 + --> $DIR/impl-trait.rs:64:13 | LL | None => {} | ---- matches all the relevant values @@ -78,7 +64,7 @@ LL | _ => {} | ^ no value can reach this error: unreachable pattern - --> $DIR/impl-trait.rs:76:9 + --> $DIR/impl-trait.rs:77:9 | LL | _ => {} | ^------ @@ -89,7 +75,7 @@ LL | _ => {} = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types error: unreachable pattern - --> $DIR/impl-trait.rs:86:9 + --> $DIR/impl-trait.rs:87:9 | LL | _ => {} | - matches any value @@ -97,7 +83,7 @@ LL | Some((a, b)) => {} | ^^^^^^^^^^^^ no value can reach this error: unreachable pattern - --> $DIR/impl-trait.rs:94:13 + --> $DIR/impl-trait.rs:96:13 | LL | _ => {} | ^------ @@ -107,22 +93,8 @@ LL | _ => {} | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types -error[E0004]: non-exhaustive patterns: type `T` is non-empty - --> $DIR/impl-trait.rs:37:11 - | -LL | match return_never_tait(x) {} - | ^^^^^^^^^^^^^^^^^^^^ - | - = note: the matched value is of type `T` -help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown - | -LL ~ match return_never_tait(x) { -LL + _ => todo!(), -LL ~ } - | - error: unreachable pattern - --> $DIR/impl-trait.rs:105:9 + --> $DIR/impl-trait.rs:108:9 | LL | Some((a, b)) => {} | ------------ matches all the relevant values @@ -130,7 +102,7 @@ LL | Some((mut x, mut y)) => { | ^^^^^^^^^^^^^^^^^^^^ no value can reach this error: unreachable pattern - --> $DIR/impl-trait.rs:124:13 + --> $DIR/impl-trait.rs:128:13 | LL | _ => {} | - matches any value @@ -138,7 +110,7 @@ LL | Rec { n: 0, w: Some(Rec { n: 0, w: _ }) } => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no value can reach this error: unreachable pattern - --> $DIR/impl-trait.rs:138:13 + --> $DIR/impl-trait.rs:143:13 | LL | _ => {} | ^------ @@ -149,7 +121,7 @@ LL | _ => {} = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types error: unreachable pattern - --> $DIR/impl-trait.rs:151:13 + --> $DIR/impl-trait.rs:157:13 | LL | _ => {} | ^------ @@ -159,6 +131,34 @@ LL | _ => {} | = note: to learn more about uninhabited types, see https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types +error[E0004]: non-exhaustive patterns: type `impl Copy` is non-empty + --> $DIR/impl-trait.rs:23:11 + | +LL | match return_never_rpit(x) {} + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: the matched value is of type `impl Copy` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match return_never_rpit(x) { +LL + _ => todo!(), +LL ~ } + | + +error[E0004]: non-exhaustive patterns: type `T` is non-empty + --> $DIR/impl-trait.rs:38:11 + | +LL | match return_never_tait(x) {} + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: the matched value is of type `T` +help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown + | +LL ~ match return_never_tait(x) { +LL + _ => todo!(), +LL ~ } + | + error: aborting due to 15 previous errors For more information about this error, try `rustc --explain E0004`. diff --git a/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs b/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs index fd0e07fb9b49..f5861e054c59 100644 --- a/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs +++ b/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs @@ -8,6 +8,7 @@ pub type Pub = impl Default; #[derive(Default)] struct Priv; +#[define_opaques(Pub)] fn check() -> Pub { Priv } diff --git a/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.rs b/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.rs index 34b94f2e1c78..3ecc07e5438c 100644 --- a/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.rs +++ b/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.rs @@ -12,6 +12,7 @@ impl<'a, T> Trait<'a> for T { mod basic_pass { use super::*; type Opq<'a> = impl Sized + 'a; + #[define_opaques(Opq)] fn test() -> impl for<'a> Trait<'a, Ty = Opq<'a>> {} //~^ ERROR: expected generic lifetime parameter, found `'a` } @@ -27,6 +28,7 @@ mod capture_tait { type Opq0 = impl Sized; type Opq1<'a> = impl for<'b> Trait<'b, Ty = Opq0>; type Opq2 = impl for<'a> Trait<'a, Ty = Opq1<'a>>; + #[define_opaques(Opq2)] fn test() -> Opq2 {} //~^ ERROR hidden type for `capture_tait::Opq0` captures lifetime that does not appear in bounds } @@ -36,6 +38,7 @@ mod capture_tait_complex_pass { type Opq0<'a> = impl Sized; type Opq1<'a> = impl for<'b> Trait<'b, Ty = Opq0<'b>>; // <- Note 'b type Opq2 = impl for<'a> Trait<'a, Ty = Opq1<'a>>; + #[define_opaques(Opq2)] fn test() -> Opq2 {} //~^ ERROR: expected generic lifetime parameter, found `'a` } @@ -46,6 +49,7 @@ mod capture_tait_complex_fail { type Opq0<'a> = impl Sized; type Opq1<'a> = impl for<'b> Trait<'b, Ty = Opq0<'a>>; // <- Note 'a type Opq2 = impl for<'a> Trait<'a, Ty = Opq1<'a>>; + #[define_opaques(Opq2)] fn test() -> Opq2 {} //~^ ERROR hidden type for `capture_tait_complex_fail::Opq0<'a>` captures lifetime that does not appear in bounds } @@ -54,18 +58,18 @@ mod capture_tait_complex_fail { mod constrain_fail0 { use super::*; type Opq0<'a, 'b> = impl Sized; + #[define_opaques(Opq0)] fn test() -> impl for<'a> Trait<'a, Ty = Opq0<'a, 'static>> {} - //~^ ERROR non-defining opaque type use in defining scope - //~| ERROR: expected generic lifetime parameter, found `'a` + //~^ ERROR: expected generic lifetime parameter, found `'a` } // non-defining use because generic lifetime is used multiple times. mod constrain_fail { use super::*; type Opq0<'a, 'b> = impl Sized; + #[define_opaques(Opq0)] fn test() -> impl for<'a> Trait<'a, Ty = Opq0<'a, 'a>> {} - //~^ ERROR non-defining opaque type use in defining scope - //~| ERROR: expected generic lifetime parameter, found `'a` + //~^ ERROR: expected generic lifetime parameter, found `'a` } mod constrain_pass { @@ -73,6 +77,7 @@ mod constrain_pass { type Opq0<'a, 'b> = impl Sized; type Opq1<'a> = impl for<'b> Trait<'b, Ty = Opq0<'a, 'b>>; type Opq2 = impl for<'a> Trait<'a, Ty = Opq1<'a>>; + #[define_opaques(Opq2)] fn test() -> Opq2 {} //~^ ERROR: expected generic lifetime parameter, found `'a` } diff --git a/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.stderr b/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.stderr index fb1e4cca3f40..ca30a235ed16 100644 --- a/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.stderr +++ b/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-basic.stderr @@ -1,13 +1,14 @@ error[E0792]: expected generic lifetime parameter, found `'a` - --> $DIR/higher-ranked-regions-basic.rs:15:55 + --> $DIR/higher-ranked-regions-basic.rs:16:55 | LL | type Opq<'a> = impl Sized + 'a; | -- this generic parameter must be used with a generic lifetime parameter +LL | #[define_opaques(Opq)] LL | fn test() -> impl for<'a> Trait<'a, Ty = Opq<'a>> {} | ^^ error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds - --> $DIR/higher-ranked-regions-basic.rs:21:58 + --> $DIR/higher-ranked-regions-basic.rs:22:58 | LL | fn test() -> impl for<'a> Trait<'a, Ty = impl Sized> {} | -- ---------- ^^ @@ -16,86 +17,64 @@ LL | fn test() -> impl for<'a> Trait<'a, Ty = impl Sized> {} | hidden type `&'a ()` captures the lifetime `'a` as defined here error[E0700]: hidden type for `capture_tait::Opq0` captures lifetime that does not appear in bounds - --> $DIR/higher-ranked-regions-basic.rs:30:23 + --> $DIR/higher-ranked-regions-basic.rs:32:23 | LL | type Opq0 = impl Sized; | ---------- opaque type defined here LL | type Opq1<'a> = impl for<'b> Trait<'b, Ty = Opq0>; | -- hidden type `&'b ()` captures the lifetime `'b` as defined here -LL | type Opq2 = impl for<'a> Trait<'a, Ty = Opq1<'a>>; +... LL | fn test() -> Opq2 {} | ^^ error[E0792]: expected generic lifetime parameter, found `'a` - --> $DIR/higher-ranked-regions-basic.rs:39:23 + --> $DIR/higher-ranked-regions-basic.rs:42:23 | LL | type Opq1<'a> = impl for<'b> Trait<'b, Ty = Opq0<'b>>; // <- Note 'b | -- this generic parameter must be used with a generic lifetime parameter -LL | type Opq2 = impl for<'a> Trait<'a, Ty = Opq1<'a>>; +... LL | fn test() -> Opq2 {} | ^^ error[E0700]: hidden type for `capture_tait_complex_fail::Opq0<'a>` captures lifetime that does not appear in bounds - --> $DIR/higher-ranked-regions-basic.rs:49:23 + --> $DIR/higher-ranked-regions-basic.rs:53:23 | LL | type Opq0<'a> = impl Sized; | ---------- opaque type defined here LL | type Opq1<'a> = impl for<'b> Trait<'b, Ty = Opq0<'a>>; // <- Note 'a | -- hidden type `&'b ()` captures the lifetime `'b` as defined here -LL | type Opq2 = impl for<'a> Trait<'a, Ty = Opq1<'a>>; +... LL | fn test() -> Opq2 {} | ^^ -error[E0792]: non-defining opaque type use in defining scope - --> $DIR/higher-ranked-regions-basic.rs:57:41 - | -LL | fn test() -> impl for<'a> Trait<'a, Ty = Opq0<'a, 'static>> {} - | ^^^^^^^^^^^^^^^^^^^^^^ argument `'static` is not a generic parameter - | -note: for this opaque type - --> $DIR/higher-ranked-regions-basic.rs:56:25 - | -LL | type Opq0<'a, 'b> = impl Sized; - | ^^^^^^^^^^ - error[E0792]: expected generic lifetime parameter, found `'a` - --> $DIR/higher-ranked-regions-basic.rs:57:65 + --> $DIR/higher-ranked-regions-basic.rs:62:65 | LL | type Opq0<'a, 'b> = impl Sized; | -- this generic parameter must be used with a generic lifetime parameter +LL | #[define_opaques(Opq0)] LL | fn test() -> impl for<'a> Trait<'a, Ty = Opq0<'a, 'static>> {} | ^^ -error: non-defining opaque type use in defining scope - --> $DIR/higher-ranked-regions-basic.rs:66:41 - | -LL | fn test() -> impl for<'a> Trait<'a, Ty = Opq0<'a, 'a>> {} - | ^^^^^^^^^^^^^^^^^ generic argument `'a` used twice - | -note: for this opaque type - --> $DIR/higher-ranked-regions-basic.rs:65:25 - | -LL | type Opq0<'a, 'b> = impl Sized; - | ^^^^^^^^^^ - error[E0792]: expected generic lifetime parameter, found `'a` - --> $DIR/higher-ranked-regions-basic.rs:66:60 + --> $DIR/higher-ranked-regions-basic.rs:71:60 | LL | type Opq0<'a, 'b> = impl Sized; | -- this generic parameter must be used with a generic lifetime parameter +LL | #[define_opaques(Opq0)] LL | fn test() -> impl for<'a> Trait<'a, Ty = Opq0<'a, 'a>> {} | ^^ error[E0792]: expected generic lifetime parameter, found `'a` - --> $DIR/higher-ranked-regions-basic.rs:76:23 + --> $DIR/higher-ranked-regions-basic.rs:81:23 | LL | type Opq1<'a> = impl for<'b> Trait<'b, Ty = Opq0<'a, 'b>>; | -- this generic parameter must be used with a generic lifetime parameter -LL | type Opq2 = impl for<'a> Trait<'a, Ty = Opq1<'a>>; +... LL | fn test() -> Opq2 {} | ^^ -error: aborting due to 10 previous errors +error: aborting due to 8 previous errors Some errors have detailed explanations: E0700, E0792. For more information about an error, try `rustc --explain E0700`. diff --git a/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-gat.rs b/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-gat.rs index db5e5e05e54b..11dac3b414e7 100644 --- a/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-gat.rs +++ b/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-gat.rs @@ -14,7 +14,10 @@ impl Trait for Struct { type Assoc<'a> = &'a u32; } -const FOO: Foo = Struct; -//~^ ERROR: expected generic lifetime parameter, found `'a` +#[define_opaques(Foo)] +fn foo() -> Foo { + Struct + //~^ ERROR: expected generic lifetime parameter, found `'a` +} fn main() {} diff --git a/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-gat.stderr b/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-gat.stderr index 9b361445f1ec..b3edc9427327 100644 --- a/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-gat.stderr +++ b/tests/ui/rfcs/type-alias-impl-trait/higher-ranked-regions-gat.stderr @@ -1,11 +1,11 @@ error[E0792]: expected generic lifetime parameter, found `'a` - --> $DIR/higher-ranked-regions-gat.rs:17:18 + --> $DIR/higher-ranked-regions-gat.rs:19:5 | LL | pub type FooAssoc<'a> = impl Sized; | -- this generic parameter must be used with a generic lifetime parameter ... -LL | const FOO: Foo = Struct; - | ^^^^^^ +LL | Struct + | ^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/self/arbitrary-self-opaque.rs b/tests/ui/self/arbitrary-self-opaque.rs index c26ef658b695..ce4403133226 100644 --- a/tests/ui/self/arbitrary-self-opaque.rs +++ b/tests/ui/self/arbitrary-self-opaque.rs @@ -4,6 +4,7 @@ struct Foo; type Bar = impl Sized; impl Foo { + #[define_opaques(Bar)] fn foo(self: Bar) {} //~^ ERROR: invalid `self` parameter type: `Bar` //~| ERROR: item does not constrain diff --git a/tests/ui/self/arbitrary-self-opaque.stderr b/tests/ui/self/arbitrary-self-opaque.stderr index c75165d9f8e2..628db948a5d7 100644 --- a/tests/ui/self/arbitrary-self-opaque.stderr +++ b/tests/ui/self/arbitrary-self-opaque.stderr @@ -1,5 +1,5 @@ error[E0307]: invalid `self` parameter type: `Bar` - --> $DIR/arbitrary-self-opaque.rs:7:18 + --> $DIR/arbitrary-self-opaque.rs:8:18 | LL | fn foo(self: Bar) {} | ^^^ @@ -8,7 +8,7 @@ LL | fn foo(self: Bar) {} = help: consider changing to `self`, `&self`, `&mut self`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) error: item does not constrain `Bar::{opaque#0}`, but has it in its signature - --> $DIR/arbitrary-self-opaque.rs:7:8 + --> $DIR/arbitrary-self-opaque.rs:8:8 | LL | fn foo(self: Bar) {} | ^^^ diff --git a/tests/ui/specialization/min_specialization/impl-on-opaque.rs b/tests/ui/specialization/min_specialization/impl-on-opaque.rs index 7531dcaccf23..1ba5d4fbdf61 100644 --- a/tests/ui/specialization/min_specialization/impl-on-opaque.rs +++ b/tests/ui/specialization/min_specialization/impl-on-opaque.rs @@ -26,6 +26,7 @@ impl SpecTrait for () { fn f() {} } +#[define_opaques(Opaque)] fn foo() -> Opaque {} fn main() {} diff --git a/tests/ui/specialization/min_specialization/impl-on-opaque2.rs b/tests/ui/specialization/min_specialization/impl-on-opaque2.rs index 0cd8be84ed37..0371d5ff46f7 100644 --- a/tests/ui/specialization/min_specialization/impl-on-opaque2.rs +++ b/tests/ui/specialization/min_specialization/impl-on-opaque2.rs @@ -23,6 +23,7 @@ impl SpecTrait<(), Opaque> for () { fn f() {} } +#[define_opaques(Opaque)] fn foo() -> Opaque {} fn main() {} diff --git a/tests/ui/traits/alias/issue-83613.rs b/tests/ui/traits/alias/issue-83613.rs index 6f0012bf0896..37ab05192077 100644 --- a/tests/ui/traits/alias/issue-83613.rs +++ b/tests/ui/traits/alias/issue-83613.rs @@ -2,6 +2,7 @@ trait OpaqueTrait {} impl OpaqueTrait for T {} type OpaqueType = impl OpaqueTrait; +#[define_opaques(OpaqueType)] fn mk_opaque() -> OpaqueType { || 0 } diff --git a/tests/ui/traits/alias/issue-83613.stderr b/tests/ui/traits/alias/issue-83613.stderr index 47181c3f33ed..7d2bdd7e1863 100644 --- a/tests/ui/traits/alias/issue-83613.stderr +++ b/tests/ui/traits/alias/issue-83613.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `AnotherTrait` - --> $DIR/issue-83613.rs:10:1 + --> $DIR/issue-83613.rs:11:1 | LL | impl AnotherTrait for T {} | -------------------------------- first implementation here diff --git a/tests/ui/traits/next-solver/alias-relate/tait-eq-proj-2.rs b/tests/ui/traits/next-solver/alias-relate/tait-eq-proj-2.rs index cb9fe176ac95..05b428ea3191 100644 --- a/tests/ui/traits/next-solver/alias-relate/tait-eq-proj-2.rs +++ b/tests/ui/traits/next-solver/alias-relate/tait-eq-proj-2.rs @@ -12,7 +12,8 @@ fn mk() -> T { todo!() } -fn a(_: Tait) { +#[define_opaques(Tait)] +fn a() { let x: Tait = mk(); let mut array = mk(); let mut z = IntoIterator::into_iter(array); diff --git a/tests/ui/traits/next-solver/alias-relate/tait-eq-proj.rs b/tests/ui/traits/next-solver/alias-relate/tait-eq-proj.rs index 8d92c88ae725..83f569927f89 100644 --- a/tests/ui/traits/next-solver/alias-relate/tait-eq-proj.rs +++ b/tests/ui/traits/next-solver/alias-relate/tait-eq-proj.rs @@ -28,7 +28,8 @@ goals together. Essentially: */ -fn a(_: Tait) { +#[define_opaques(Tait)] +fn a() { let _: Tait = IntoIterator::into_iter([0i32; 32]); } diff --git a/tests/ui/traits/next-solver/opaques/dont-remap-tait-substs.rs b/tests/ui/traits/next-solver/opaques/dont-remap-tait-substs.rs index 904bc1794959..5c9ae262f6aa 100644 --- a/tests/ui/traits/next-solver/opaques/dont-remap-tait-substs.rs +++ b/tests/ui/traits/next-solver/opaques/dont-remap-tait-substs.rs @@ -12,7 +12,8 @@ type Foo = impl NeedsSend; trait NeedsSend {} impl NeedsSend for T {} -fn define(a: A, b: B, _: Foo) { +#[define_opaques(Foo)] +fn define(a: A, b: B) { let y: Option> = Some(b); } diff --git a/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.is_send.stderr b/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.is_send.stderr index 158fefd1538f..736c8c10da97 100644 --- a/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.is_send.stderr +++ b/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.is_send.stderr @@ -1,5 +1,5 @@ error[E0284]: type annotations needed: cannot satisfy `Foo == _` - --> $DIR/dont-type_of-tait-in-defining-scope.rs:15:18 + --> $DIR/dont-type_of-tait-in-defining-scope.rs:16:18 | LL | needs_send::(); | ^^^ cannot satisfy `Foo == _` diff --git a/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.not_send.stderr b/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.not_send.stderr index 158fefd1538f..736c8c10da97 100644 --- a/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.not_send.stderr +++ b/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.not_send.stderr @@ -1,5 +1,5 @@ error[E0284]: type annotations needed: cannot satisfy `Foo == _` - --> $DIR/dont-type_of-tait-in-defining-scope.rs:15:18 + --> $DIR/dont-type_of-tait-in-defining-scope.rs:16:18 | LL | needs_send::(); | ^^^ cannot satisfy `Foo == _` diff --git a/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.rs b/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.rs index 10b746cc9895..96d732d28b06 100644 --- a/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.rs +++ b/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.rs @@ -11,12 +11,14 @@ type Foo = impl Sized; fn needs_send() {} +#[define_opaques(Foo)] fn test(_: Foo) { needs_send::(); //~^ ERROR type annotations needed: cannot satisfy `Foo == _` } -fn defines(_: Foo) { +#[define_opaques(Foo)] +fn defines() { let _: Foo = (); } diff --git a/tests/ui/traits/next-solver/opaques/no-define-in-wf-check.current.stderr b/tests/ui/traits/next-solver/opaques/no-define-in-wf-check.current.stderr index 9a28dc093c1b..5625cb24d426 100644 --- a/tests/ui/traits/next-solver/opaques/no-define-in-wf-check.current.stderr +++ b/tests/ui/traits/next-solver/opaques/no-define-in-wf-check.current.stderr @@ -4,31 +4,31 @@ error: unconstrained opaque type LL | type Tait1 = impl Sized; | ^^^^^^^^^^ | - = note: `Tait1` must be used in combination with a concrete type within the same module + = note: `Tait1` must be used in combination with a concrete type within the same crate error: unconstrained opaque type - --> $DIR/no-define-in-wf-check.rs:27:18 + --> $DIR/no-define-in-wf-check.rs:28:18 | LL | type Tait1 = impl Sized; | ^^^^^^^^^^ | - = note: `Tait1` must be used in combination with a concrete type within the same module + = note: `Tait1` must be used in combination with a concrete type within the same crate error: unconstrained opaque type - --> $DIR/no-define-in-wf-check.rs:36:18 + --> $DIR/no-define-in-wf-check.rs:38:18 | LL | type Tait1 = impl Sized; | ^^^^^^^^^^ | - = note: `Tait1` must be used in combination with a concrete type within the same module + = note: `Tait1` must be used in combination with a concrete type within the same crate error: unconstrained opaque type - --> $DIR/no-define-in-wf-check.rs:47:18 + --> $DIR/no-define-in-wf-check.rs:50:18 | LL | type Tait1 = impl Sized; | ^^^^^^^^^^ | - = note: `Tait1` must be used in combination with a concrete type within the same module + = note: `Tait1` must be used in combination with a concrete type within the same crate error: aborting due to 4 previous errors diff --git a/tests/ui/traits/next-solver/opaques/no-define-in-wf-check.rs b/tests/ui/traits/next-solver/opaques/no-define-in-wf-check.rs index dd6df097da1b..c61ab416adb8 100644 --- a/tests/ui/traits/next-solver/opaques/no-define-in-wf-check.rs +++ b/tests/ui/traits/next-solver/opaques/no-define-in-wf-check.rs @@ -18,6 +18,7 @@ mod ex0 { mod ex1 { type Tait1 = impl Sized; //[current]~^ ERROR unconstrained opaque type + #[define_opaques(Tait1)] fn foo(x: Tait1) -> impl Sized { let () = x; } @@ -27,6 +28,7 @@ mod ex2 { type Tait1 = impl Sized; //[current]~^ ERROR unconstrained opaque type type Tait2 = impl Sized; + #[define_opaques(Tait1, Tait2)] fn foo(x: Tait1) -> Tait2 { let () = x; } @@ -38,6 +40,7 @@ mod ex3 { trait Something {} impl Something for T {} type Tait2 = impl Something; + #[define_opaques(Tait1, Tait2)] fn foo(x: Tait1) -> Tait2 { let () = x; } @@ -58,6 +61,7 @@ mod ex4 { // // ambiguity proving `(): Trait`. type Tait2 = impl Trait<(), Assoc = impl Trait>; + #[define_opaques(Tait1, Tait2)] fn foo(x: Tait1) -> Tait2 { let () = x; } diff --git a/tests/ui/traits/pointee-tail-is-generic-errors.rs b/tests/ui/traits/pointee-tail-is-generic-errors.rs index 92a83f40b184..52b8727cbda9 100644 --- a/tests/ui/traits/pointee-tail-is-generic-errors.rs +++ b/tests/ui/traits/pointee-tail-is-generic-errors.rs @@ -5,6 +5,7 @@ type Opaque = impl std::fmt::Debug + ?Sized; +#[define_opaques(Opaque)] fn opaque() -> &'static Opaque { &[1] as &[i32] } diff --git a/tests/ui/traits/pointee-tail-is-generic-errors.stderr b/tests/ui/traits/pointee-tail-is-generic-errors.stderr index 0c3d7060dd7c..907f07026a43 100644 --- a/tests/ui/traits/pointee-tail-is-generic-errors.stderr +++ b/tests/ui/traits/pointee-tail-is-generic-errors.stderr @@ -1,5 +1,5 @@ error[E0271]: type mismatch resolving `::Metadata == ()` - --> $DIR/pointee-tail-is-generic-errors.rs:13:15 + --> $DIR/pointee-tail-is-generic-errors.rs:14:15 | LL | is_thin::(); | ^ expected `()`, found associated type @@ -9,13 +9,13 @@ LL | is_thin::(); = help: consider constraining the associated type `::Metadata` to `()` = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html note: required by a bound in `is_thin` - --> $DIR/pointee-tail-is-generic-errors.rs:20:33 + --> $DIR/pointee-tail-is-generic-errors.rs:21:33 | LL | fn is_thin + ?Sized>() {} | ^^^^^^^^^^^^^ required by this bound in `is_thin` error[E0271]: type mismatch resolving `::Metadata == ()` - --> $DIR/pointee-tail-is-generic-errors.rs:16:15 + --> $DIR/pointee-tail-is-generic-errors.rs:17:15 | LL | type Opaque = impl std::fmt::Debug + ?Sized; | ----------------------------- the found opaque type @@ -26,7 +26,7 @@ LL | is_thin::(); = note: expected unit type `()` found associated type `::Metadata` note: required by a bound in `is_thin` - --> $DIR/pointee-tail-is-generic-errors.rs:20:33 + --> $DIR/pointee-tail-is-generic-errors.rs:21:33 | LL | fn is_thin + ?Sized>() {} | ^^^^^^^^^^^^^ required by this bound in `is_thin` diff --git a/tests/ui/traits/pointee-tail-is-generic.rs b/tests/ui/traits/pointee-tail-is-generic.rs index 14bdf0880c73..7ff5082c4fe8 100644 --- a/tests/ui/traits/pointee-tail-is-generic.rs +++ b/tests/ui/traits/pointee-tail-is-generic.rs @@ -4,12 +4,11 @@ #![feature(ptr_metadata)] #![feature(type_alias_impl_trait)] -mod opaque { - pub type Opaque = impl std::future::Future; +pub type Opaque = impl std::future::Future; - fn opaque() -> Opaque { - async {} - } +#[define_opaques(Opaque)] +fn opaque() -> Opaque { + async {} } fn a() { @@ -18,7 +17,7 @@ fn a() { // tail of ADT (which is a type param) is known to be sized is_thin::>(); // opaque type is known to be sized - is_thin::(); + is_thin::(); } fn a2() { diff --git a/tests/ui/traits/trait-upcasting/type-checking-test-opaques.rs b/tests/ui/traits/trait-upcasting/type-checking-test-opaques.rs index ab3817da28b1..2b2832de3c92 100644 --- a/tests/ui/traits/trait-upcasting/type-checking-test-opaques.rs +++ b/tests/ui/traits/trait-upcasting/type-checking-test-opaques.rs @@ -15,6 +15,7 @@ fn test_correct2<'a>(x: &dyn Foo<'a>) { let _ = x as &dyn Bar<'_, '_, Tait>; } +#[define_opaques(Tait)] fn test_correct3<'a>(x: &dyn Foo<'a>, _: Tait) { let _ = x as &dyn Bar<'_, '_, ()>; } diff --git a/tests/ui/traits/trait-upcasting/upcast-defining-opaque.rs b/tests/ui/traits/trait-upcasting/upcast-defining-opaque.rs index 0548eda04684..99d71651381f 100644 --- a/tests/ui/traits/trait-upcasting/upcast-defining-opaque.rs +++ b/tests/ui/traits/trait-upcasting/upcast-defining-opaque.rs @@ -17,6 +17,7 @@ impl Super for T { type Foo = impl Sized; +#[define_opaques(Foo)] fn upcast(x: &dyn Sub) -> &dyn Super { x } diff --git a/tests/ui/transmutability/malformed-program-gracefulness/coherence-bikeshed-intrinsic-from.stderr b/tests/ui/transmutability/malformed-program-gracefulness/coherence-bikeshed-intrinsic-from.stderr index cdf9deecd515..7f51d1519db2 100644 --- a/tests/ui/transmutability/malformed-program-gracefulness/coherence-bikeshed-intrinsic-from.stderr +++ b/tests/ui/transmutability/malformed-program-gracefulness/coherence-bikeshed-intrinsic-from.stderr @@ -19,7 +19,7 @@ error: unconstrained opaque type LL | type OpaqueType = impl OpaqueTrait; | ^^^^^^^^^^^^^^^^ | - = note: `OpaqueType` must be used in combination with a concrete type within the same module + = note: `OpaqueType` must be used in combination with a concrete type within the same crate error: aborting due to 3 previous errors diff --git a/tests/ui/type-alias-impl-trait/argument-types.rs b/tests/ui/type-alias-impl-trait/argument-types.rs index 7382d4c78c7d..f2bf162d4d22 100644 --- a/tests/ui/type-alias-impl-trait/argument-types.rs +++ b/tests/ui/type-alias-impl-trait/argument-types.rs @@ -2,20 +2,19 @@ #![allow(dead_code)] //@ check-pass -mod foo { - use std::fmt::Debug; +use std::fmt::Debug; - pub type Foo = impl Debug; +pub type Foo = impl Debug; - fn foo1(mut x: Foo) { - x = 22_u32; - } +#[define_opaques(Foo)] +fn foo1(mut x: Foo) { + x = 22_u32; +} - pub fn foo_value() -> Foo { - 11_u32 - } +#[define_opaques(Foo)] +pub fn foo_value() -> Foo { + 11_u32 } -use foo::*; fn foo2(mut x: Foo) { // no constraint on x diff --git a/tests/ui/type-alias-impl-trait/assoc-projection-ice.rs b/tests/ui/type-alias-impl-trait/assoc-projection-ice.rs index 9dcbc75db3f1..49d1cd366b07 100644 --- a/tests/ui/type-alias-impl-trait/assoc-projection-ice.rs +++ b/tests/ui/type-alias-impl-trait/assoc-projection-ice.rs @@ -2,23 +2,21 @@ //@ build-pass -mod helper { - pub trait T { - type Item; - } +pub trait T { + type Item; +} - pub type Alias<'a> = impl T; +pub type Alias<'a> = impl T; - struct S; - impl<'a> T for &'a S { - type Item = &'a (); - } +struct S; +impl<'a> T for &'a S { + type Item = &'a (); +} - pub fn filter_positive<'a>() -> Alias<'a> { - &S - } +#[define_opaques(Alias)] +pub fn filter_positive<'a>() -> Alias<'a> { + &S } -use helper::*; fn with_positive(fun: impl Fn(Alias<'_>)) { fun(filter_positive()); diff --git a/tests/ui/type-alias-impl-trait/associated-type-alias-impl-trait.rs b/tests/ui/type-alias-impl-trait/associated-type-alias-impl-trait.rs index a1185cd5ba88..41835b48e46f 100644 --- a/tests/ui/type-alias-impl-trait/associated-type-alias-impl-trait.rs +++ b/tests/ui/type-alias-impl-trait/associated-type-alias-impl-trait.rs @@ -15,9 +15,11 @@ type Helper = impl Bar; impl Foo for i32 { type Assoc = Helper; + #[define_opaques(Helper)] fn foo() -> Helper { Dummy } + #[define_opaques(Helper)] fn bar() -> Helper { Dummy } diff --git a/tests/ui/type-alias-impl-trait/auto-trait-leakage.rs b/tests/ui/type-alias-impl-trait/auto-trait-leakage.rs index a03a146d0418..c94aa22911cb 100644 --- a/tests/ui/type-alias-impl-trait/auto-trait-leakage.rs +++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage.rs @@ -3,16 +3,15 @@ #![feature(type_alias_impl_trait)] #![allow(dead_code)] -mod m { - pub(crate) type Foo = impl std::fmt::Debug; +pub(crate) type Foo = impl std::fmt::Debug; - pub(crate) fn foo() -> Foo { - 22_u32 - } +#[define_opaques(Foo)] +pub(crate) fn foo() -> Foo { + 22_u32 } fn is_send(_: T) {} fn main() { - is_send(m::foo()); + is_send(foo()); } diff --git a/tests/ui/type-alias-impl-trait/auto-trait-leakage2.rs b/tests/ui/type-alias-impl-trait/auto-trait-leakage2.rs index fc89b0e870e3..ee7cbc2f3d20 100644 --- a/tests/ui/type-alias-impl-trait/auto-trait-leakage2.rs +++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage2.rs @@ -1,16 +1,15 @@ #![feature(type_alias_impl_trait)] #![allow(dead_code)] -mod m { - use std::rc::Rc; +use std::rc::Rc; - type Foo = impl std::fmt::Debug; //~ NOTE appears within the type - //~^ within this `Foo` - //~| expansion of desugaring +type Foo = impl std::fmt::Debug; //~ NOTE appears within the type +//~^ within this `Foo` +//~| expansion of desugaring - pub fn foo() -> Foo { - Rc::new(22_u32) - } +#[define_opaques(Foo)] +pub fn foo() -> Foo { + Rc::new(22_u32) } fn is_send(_: T) {} @@ -18,7 +17,7 @@ fn is_send(_: T) {} //~| required by a bound fn main() { - is_send(m::foo()); + is_send(foo()); //~^ ERROR: `Rc` cannot be sent between threads safely [E0277] //~| NOTE cannot be sent //~| NOTE required by a bound diff --git a/tests/ui/type-alias-impl-trait/auto-trait-leakage2.stderr b/tests/ui/type-alias-impl-trait/auto-trait-leakage2.stderr index 2ed918eca171..d2db468b5195 100644 --- a/tests/ui/type-alias-impl-trait/auto-trait-leakage2.stderr +++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage2.stderr @@ -1,22 +1,22 @@ error[E0277]: `Rc` cannot be sent between threads safely - --> $DIR/auto-trait-leakage2.rs:21:13 + --> $DIR/auto-trait-leakage2.rs:20:13 | -LL | type Foo = impl std::fmt::Debug; - | -------------------- within this `Foo` +LL | type Foo = impl std::fmt::Debug; + | -------------------- within this `Foo` ... -LL | is_send(m::foo()); - | ------- ^^^^^^^^ `Rc` cannot be sent between threads safely +LL | is_send(foo()); + | ------- ^^^^^ `Rc` cannot be sent between threads safely | | | required by a bound introduced by this call | = help: within `Foo`, the trait `Send` is not implemented for `Rc` note: required because it appears within the type `Foo` - --> $DIR/auto-trait-leakage2.rs:7:16 + --> $DIR/auto-trait-leakage2.rs:6:12 | -LL | type Foo = impl std::fmt::Debug; - | ^^^^^^^^^^^^^^^^^^^^ +LL | type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ note: required by a bound in `is_send` - --> $DIR/auto-trait-leakage2.rs:16:15 + --> $DIR/auto-trait-leakage2.rs:15:15 | LL | fn is_send(_: T) {} | ^^^^ required by this bound in `is_send` diff --git a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.rs b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.rs index cad75cffe05f..bc82f2332739 100644 --- a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.rs +++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.rs @@ -1,17 +1,17 @@ #![feature(type_alias_impl_trait)] #![allow(dead_code)] -// FIXME This should compile, but it currently doesn't +//@ check-pass mod m { pub type Foo = impl std::fmt::Debug; + #[define_opaques(Foo)] pub fn foo() -> Foo { 22_u32 } pub fn bar() { is_send(foo()); - //~^ ERROR: cannot check whether the hidden type of `auto_trait_leakage3[211d]::m::Foo::{opaque#0} } fn is_send(_: T) {} diff --git a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr deleted file mode 100644 index 6bdc76aab450..000000000000 --- a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: cannot check whether the hidden type of `auto_trait_leakage3[211d]::m::Foo::{opaque#0}` satisfies auto traits - --> $DIR/auto-trait-leakage3.rs:13:17 - | -LL | is_send(foo()); - | ------- ^^^^^ - | | - | required by a bound introduced by this call - | - = note: fetching the hidden types of an opaque inside of the defining scope is not supported. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule -note: opaque type is declared here - --> $DIR/auto-trait-leakage3.rs:7:20 - | -LL | pub type Foo = impl std::fmt::Debug; - | ^^^^^^^^^^^^^^^^^^^^ -note: required by a bound in `is_send` - --> $DIR/auto-trait-leakage3.rs:17:19 - | -LL | fn is_send(_: T) {} - | ^^^^ required by this bound in `is_send` - -error: aborting due to 1 previous error - diff --git a/tests/ui/type-alias-impl-trait/auxiliary/cross_crate_ice.rs b/tests/ui/type-alias-impl-trait/auxiliary/cross_crate_ice.rs index e7bca2231de4..7a7b4263cedc 100644 --- a/tests/ui/type-alias-impl-trait/auxiliary/cross_crate_ice.rs +++ b/tests/ui/type-alias-impl-trait/auxiliary/cross_crate_ice.rs @@ -5,6 +5,7 @@ pub type Foo = impl std::fmt::Debug; +#[define_opaques(Foo)] pub fn foo() -> Foo { 5 } diff --git a/tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs b/tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs index 54a22510066f..43784fe05d92 100644 --- a/tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs +++ b/tests/ui/type-alias-impl-trait/auxiliary/drop-shim-relates-opaque-aux.rs @@ -3,6 +3,7 @@ #![feature(type_alias_impl_trait)] type Tait = impl Sized; +#[define_opaques(Tait)] fn _constrain() -> Tait {} struct WrapperWithDrop(T); diff --git a/tests/ui/type-alias-impl-trait/bad-tait-no-substs.rs b/tests/ui/type-alias-impl-trait/bad-tait-no-substs.rs index 4b2ee344aa32..4cd028e84ffe 100644 --- a/tests/ui/type-alias-impl-trait/bad-tait-no-substs.rs +++ b/tests/ui/type-alias-impl-trait/bad-tait-no-substs.rs @@ -8,9 +8,9 @@ pub enum UninhabitedVariants { Tuple(Alias), //~^ ERROR missing lifetime specifier //~| ERROR missing generics - //~| ERROR non-defining opaque type use in defining scope } +#[define_opaques(Alias)] fn uwu(x: UninhabitedVariants) { //~^ ERROR item does not constrain match x {} diff --git a/tests/ui/type-alias-impl-trait/bad-tait-no-substs.stderr b/tests/ui/type-alias-impl-trait/bad-tait-no-substs.stderr index 38fbff9d59da..dd7ea3ac2020 100644 --- a/tests/ui/type-alias-impl-trait/bad-tait-no-substs.stderr +++ b/tests/ui/type-alias-impl-trait/bad-tait-no-substs.stderr @@ -26,18 +26,6 @@ help: add missing generic argument LL | Tuple(Alias), | +++ -error[E0792]: non-defining opaque type use in defining scope - --> $DIR/bad-tait-no-substs.rs:8:11 - | -LL | Tuple(Alias), - | ^^^^^ argument `'_` is not a generic parameter - | -note: for this opaque type - --> $DIR/bad-tait-no-substs.rs:5:21 - | -LL | type Alias<'a, U> = impl Trait; - | ^^^^^^^^^^^^^ - error: item does not constrain `Alias::{opaque#0}`, but has it in its signature --> $DIR/bad-tait-no-substs.rs:14:4 | @@ -72,7 +60,7 @@ LL + UninhabitedVariants::Tuple(_) => todo!(), LL ~ } | -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0004, E0106, E0107, E0792. +Some errors have detailed explanations: E0004, E0106, E0107. For more information about an error, try `rustc --explain E0004`. diff --git a/tests/ui/type-alias-impl-trait/bivariant-duplicate-lifetime-unconstrained.rs b/tests/ui/type-alias-impl-trait/bivariant-duplicate-lifetime-unconstrained.rs index 3b83b2e544b0..609b94603f36 100644 --- a/tests/ui/type-alias-impl-trait/bivariant-duplicate-lifetime-unconstrained.rs +++ b/tests/ui/type-alias-impl-trait/bivariant-duplicate-lifetime-unconstrained.rs @@ -11,6 +11,7 @@ type Opaque<'a> = impl Sized + 'a; +#[define_opaques(Opaque)] fn test<'a>() -> Opaque<'a> { let _: () = test::<'a>(); } diff --git a/tests/ui/type-alias-impl-trait/bound_reduction.rs b/tests/ui/type-alias-impl-trait/bound_reduction.rs index 74012e34e921..37c087f77e21 100644 --- a/tests/ui/type-alias-impl-trait/bound_reduction.rs +++ b/tests/ui/type-alias-impl-trait/bound_reduction.rs @@ -10,6 +10,7 @@ type Foo = impl std::fmt::Debug; trait Trait {} +#[define_opaques(Foo)] fn foo_desugared {} impl Trait for () {} +#[define_opaques(Foo)] fn foo_desugared(_: T) -> Foo { - //~^ ERROR non-defining opaque type use () //~^ ERROR expected generic type parameter, found `::Assoc` } diff --git a/tests/ui/type-alias-impl-trait/bound_reduction2.stderr b/tests/ui/type-alias-impl-trait/bound_reduction2.stderr index 14f9dbbdb4e9..289826cc1d02 100644 --- a/tests/ui/type-alias-impl-trait/bound_reduction2.stderr +++ b/tests/ui/type-alias-impl-trait/bound_reduction2.stderr @@ -1,15 +1,3 @@ -error[E0792]: non-defining opaque type use in defining scope - --> $DIR/bound_reduction2.rs:15:46 - | -LL | fn foo_desugared(_: T) -> Foo { - | ^^^^^^^^^^^^^ argument `::Assoc` is not a generic parameter - | -note: for this opaque type - --> $DIR/bound_reduction2.rs:9:15 - | -LL | type Foo = impl Trait; - | ^^^^^^^^^^^^^ - error[E0792]: expected generic type parameter, found `::Assoc` --> $DIR/bound_reduction2.rs:17:5 | @@ -19,6 +7,6 @@ LL | type Foo = impl Trait; LL | () | ^^ -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0792`. diff --git a/tests/ui/type-alias-impl-trait/bounds-are-checked-2.rs b/tests/ui/type-alias-impl-trait/bounds-are-checked-2.rs index 45f54266014d..c1362418f8d3 100644 --- a/tests/ui/type-alias-impl-trait/bounds-are-checked-2.rs +++ b/tests/ui/type-alias-impl-trait/bounds-are-checked-2.rs @@ -3,15 +3,13 @@ #![feature(type_alias_impl_trait)] -mod foo { - pub type X = impl Clone; +pub type X = impl Clone; - fn f(t: T) -> X { - t - //~^ ERROR the trait bound `T: Clone` is not satisfied - } +#[define_opaques(X)] +fn f(t: T) -> X { + t + //~^ ERROR the trait bound `T: Clone` is not satisfied } -use foo::X; fn g(o: Option>) -> Option> { o.clone() diff --git a/tests/ui/type-alias-impl-trait/bounds-are-checked-2.stderr b/tests/ui/type-alias-impl-trait/bounds-are-checked-2.stderr index bbb32b2d604d..21166631c3e2 100644 --- a/tests/ui/type-alias-impl-trait/bounds-are-checked-2.stderr +++ b/tests/ui/type-alias-impl-trait/bounds-are-checked-2.stderr @@ -1,23 +1,23 @@ error[E0277]: the trait bound `T: Clone` is not satisfied - --> $DIR/bounds-are-checked-2.rs:10:9 + --> $DIR/bounds-are-checked-2.rs:10:5 | -LL | t - | ^ the trait `Clone` is not implemented for `T` +LL | t + | ^ the trait `Clone` is not implemented for `T` | note: required by a bound in an opaque type - --> $DIR/bounds-are-checked-2.rs:7:26 + --> $DIR/bounds-are-checked-2.rs:6:22 | -LL | pub type X = impl Clone; - | ^^^^^ +LL | pub type X = impl Clone; + | ^^^^^ note: this definition site has more where clauses than the opaque type - --> $DIR/bounds-are-checked-2.rs:9:5 + --> $DIR/bounds-are-checked-2.rs:9:1 | -LL | fn f(t: T) -> X { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | fn f(t: T) -> X { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider restricting type parameter `T` with trait `Clone` | -LL | pub type X = impl Clone; - | +++++++++++++++++++ +LL | pub type X = impl Clone; + | +++++++++++++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/bounds-are-checked.rs b/tests/ui/type-alias-impl-trait/bounds-are-checked.rs index 7c3a3a844060..0eee73d26592 100644 --- a/tests/ui/type-alias-impl-trait/bounds-are-checked.rs +++ b/tests/ui/type-alias-impl-trait/bounds-are-checked.rs @@ -5,6 +5,7 @@ type X<'a> = impl Into<&'static str> + From<&'a str>; +#[define_opaques(X)] fn f<'a: 'static>(t: &'a str) -> X<'a> { t //~^ ERROR expected generic lifetime parameter, found `'static` diff --git a/tests/ui/type-alias-impl-trait/bounds-are-checked.stderr b/tests/ui/type-alias-impl-trait/bounds-are-checked.stderr index ad1b9f19d8ef..7617268dd8e0 100644 --- a/tests/ui/type-alias-impl-trait/bounds-are-checked.stderr +++ b/tests/ui/type-alias-impl-trait/bounds-are-checked.stderr @@ -1,5 +1,5 @@ error[E0792]: expected generic lifetime parameter, found `'static` - --> $DIR/bounds-are-checked.rs:9:5 + --> $DIR/bounds-are-checked.rs:10:5 | LL | type X<'a> = impl Into<&'static str> + From<&'a str>; | -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type diff --git a/tests/ui/type-alias-impl-trait/bounds-are-checked3.rs b/tests/ui/type-alias-impl-trait/bounds-are-checked3.rs index 5a9e87c09196..ca9099bde9bb 100644 --- a/tests/ui/type-alias-impl-trait/bounds-are-checked3.rs +++ b/tests/ui/type-alias-impl-trait/bounds-are-checked3.rs @@ -9,6 +9,7 @@ struct Struct(Option); type Foo = (impl Debug, Struct); //~^ ERROR: `T` doesn't implement `std::fmt::Display` +#[define_opaques(Foo)] fn foo() -> Foo { (Vec::::new(), Struct(None)) } diff --git a/tests/ui/type-alias-impl-trait/bounds.rs b/tests/ui/type-alias-impl-trait/bounds.rs index 8e24a937d1d4..c6a11642eaf9 100644 --- a/tests/ui/type-alias-impl-trait/bounds.rs +++ b/tests/ui/type-alias-impl-trait/bounds.rs @@ -9,6 +9,7 @@ use std::fmt::Debug; // type alias bounds. type Foo = (impl Debug, usize); +#[define_opaques(Foo)] fn foo() -> Foo { (Vec::::new(), 1234) } diff --git a/tests/ui/type-alias-impl-trait/closure-normalization-ice-109020.rs b/tests/ui/type-alias-impl-trait/closure-normalization-ice-109020.rs index 0dfa1f40ae6c..a782916c3624 100644 --- a/tests/ui/type-alias-impl-trait/closure-normalization-ice-109020.rs +++ b/tests/ui/type-alias-impl-trait/closure-normalization-ice-109020.rs @@ -6,14 +6,12 @@ use std::marker::PhantomData; -mod foo { - pub type WithEmplacableForFn<'a> = impl super::EmplacableFn + 'a; +type WithEmplacableForFn<'a> = impl EmplacableFn + 'a; - fn _constrain(_: &mut ()) -> WithEmplacableForFn<'_> { - () - } +#[define_opaques(WithEmplacableForFn)] +fn _constrain(_: &mut ()) -> WithEmplacableForFn<'_> { + () } -use foo::*; fn with_emplacable_for<'a, F, R>(mut f: F) -> R where diff --git a/tests/ui/type-alias-impl-trait/closure_args.rs b/tests/ui/type-alias-impl-trait/closure_args.rs index 0141a01aad02..173a8d41cc3c 100644 --- a/tests/ui/type-alias-impl-trait/closure_args.rs +++ b/tests/ui/type-alias-impl-trait/closure_args.rs @@ -4,21 +4,19 @@ #![feature(type_alias_impl_trait)] -mod foo { - pub trait Anything {} - impl Anything for T {} - pub type Input = impl Anything; +pub trait Anything {} +impl Anything for T {} +pub type Input = impl Anything; - fn bop(_: Input) { - super::run( - |x: u32| { - println!("{x}"); - }, - 0, - ); - } +#[define_opaques(Input)] +fn bop(_: Input) { + run( + |x: u32| { + println!("{x}"); + }, + 0, + ); } -use foo::Input; fn run ()>(f: F, i: Input) { f(i); diff --git a/tests/ui/type-alias-impl-trait/closure_args2.rs b/tests/ui/type-alias-impl-trait/closure_args2.rs index 13ac3d31d838..d229f4d63f05 100644 --- a/tests/ui/type-alias-impl-trait/closure_args2.rs +++ b/tests/ui/type-alias-impl-trait/closure_args2.rs @@ -2,27 +2,25 @@ #![feature(type_alias_impl_trait)] -mod foo { - pub trait Foo { - // This was reachable in https://github.com/rust-lang/rust/issues/100800 - fn foo(&self) { - unreachable!() - } +pub trait Foo { + // This was reachable in https://github.com/rust-lang/rust/issues/100800 + fn foo(&self) { + unreachable!() } - impl Foo for T {} +} +impl Foo for T {} - pub struct B; - impl B { - fn foo(&self) {} - } - pub type Input = impl Foo; - fn bop() -> Input { - super::run1(|x: B| x.foo(), B); - super::run2(|x: B| x.foo(), B); - panic!() - } +pub struct B; +impl B { + fn foo(&self) {} +} +pub type Input = impl Foo; +#[define_opaques(Input)] +fn bop() -> Input { + run1(|x: B| x.foo(), B); + run2(|x: B| x.foo(), B); + panic!() } -use foo::*; fn run1(f: F, i: Input) { f(i) diff --git a/tests/ui/type-alias-impl-trait/closure_infer.rs b/tests/ui/type-alias-impl-trait/closure_infer.rs index fa0514c34a09..9267c61c9d53 100644 --- a/tests/ui/type-alias-impl-trait/closure_infer.rs +++ b/tests/ui/type-alias-impl-trait/closure_infer.rs @@ -22,12 +22,14 @@ impl StreamConsumer for DispatchExecutor { // Functions that constrain TAITs can contain closures with an `_` in the return type. type Foo = impl Sized; +#[define_opaques(Foo)] fn foo() -> Foo { || -> _ {} } // The `_` in the closure return type can also be the TAIT itself. type Bar = impl Sized; +#[define_opaques(Bar)] fn bar() -> impl FnOnce() -> Bar { || -> _ {} } diff --git a/tests/ui/type-alias-impl-trait/closure_parent_substs.rs b/tests/ui/type-alias-impl-trait/closure_parent_substs.rs index e78c7c16c8e6..5e16cddf78ad 100644 --- a/tests/ui/type-alias-impl-trait/closure_parent_substs.rs +++ b/tests/ui/type-alias-impl-trait/closure_parent_substs.rs @@ -15,6 +15,7 @@ mod test1 { // Hidden type = Closure['?0] type Opaque = impl Sized; + #[define_opaques(Opaque)] fn define<'a: 'a>() -> Opaque { || {} } @@ -31,6 +32,7 @@ mod test2 { &'a (): Trait, = impl Sized + 'a; + #[define_opaques(Opaque)] fn define<'a, 'x, 'y>() -> Opaque<'a> where &'a (): Trait, @@ -52,6 +54,7 @@ mod test3 { (&'a (), &'b ()): Trait, = impl Sized + 'a + 'b; + #[define_opaques(Opaque)] fn define<'a, 'b, 'x>() -> Opaque<'a, 'b> where (&'a (), &'b ()): Trait, diff --git a/tests/ui/type-alias-impl-trait/closure_wf_outlives.rs b/tests/ui/type-alias-impl-trait/closure_wf_outlives.rs index caa9b6d979ab..001e0cb38b5f 100644 --- a/tests/ui/type-alias-impl-trait/closure_wf_outlives.rs +++ b/tests/ui/type-alias-impl-trait/closure_wf_outlives.rs @@ -13,6 +13,7 @@ mod test1 { type Opaque<'a, 'b> = impl Sized + 'a + 'b; + #[define_opaques(Opaque)] fn define<'a, 'b>() -> Opaque<'a, 'b> where 'a: 'b, @@ -26,6 +27,7 @@ mod test1 { mod test2 { type Opaque<'a, 'b> = impl Sized + 'a + 'b; + #[define_opaques(Opaque)] fn define<'a, 'b, 'x>() -> Opaque<'a, 'b> where 'a: 'x, @@ -40,6 +42,7 @@ mod test2 { mod test2_fixed { type Opaque<'a: 'b, 'b> = impl Sized + 'a + 'b; + #[define_opaques(Opaque)] fn define<'a, 'b, 'x>() -> Opaque<'a, 'b> where 'a: 'x, @@ -53,6 +56,7 @@ mod test2_fixed { mod test3 { type Opaque = impl Sized; + #[define_opaques(Opaque)] fn define() -> Opaque where T: 'static, diff --git a/tests/ui/type-alias-impl-trait/closure_wf_outlives.stderr b/tests/ui/type-alias-impl-trait/closure_wf_outlives.stderr index ae00d3fc6678..ccba2d37fd03 100644 --- a/tests/ui/type-alias-impl-trait/closure_wf_outlives.stderr +++ b/tests/ui/type-alias-impl-trait/closure_wf_outlives.stderr @@ -1,5 +1,5 @@ error[E0478]: lifetime bound not satisfied - --> $DIR/closure_wf_outlives.rs:20:9 + --> $DIR/closure_wf_outlives.rs:21:9 | LL | || {} | ^^^^^ @@ -16,34 +16,34 @@ LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b; | ^^ error[E0803]: cannot infer an appropriate lifetime due to conflicting requirements - --> $DIR/closure_wf_outlives.rs:34:9 + --> $DIR/closure_wf_outlives.rs:36:9 | LL | || {} | ^^^^^ | note: first, the lifetime cannot outlive the lifetime `'a` as defined here... - --> $DIR/closure_wf_outlives.rs:27:17 + --> $DIR/closure_wf_outlives.rs:28:17 | LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b; | ^^ note: ...so that the declared lifetime parameter bounds are satisfied - --> $DIR/closure_wf_outlives.rs:34:9 + --> $DIR/closure_wf_outlives.rs:36:9 | LL | || {} | ^^^^^ note: but, the lifetime must be valid for the lifetime `'b` as defined here... - --> $DIR/closure_wf_outlives.rs:27:21 + --> $DIR/closure_wf_outlives.rs:28:21 | LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b; | ^^ note: ...so that the declared lifetime parameter bounds are satisfied - --> $DIR/closure_wf_outlives.rs:34:9 + --> $DIR/closure_wf_outlives.rs:36:9 | LL | || {} | ^^^^^ error[E0310]: the parameter type `T` may not live long enough - --> $DIR/closure_wf_outlives.rs:60:9 + --> $DIR/closure_wf_outlives.rs:64:9 | LL | || {} | ^^^^^ @@ -52,7 +52,7 @@ LL | || {} | ...so that the type `T` will meet its required lifetime bounds... | note: ...that is required by this bound - --> $DIR/closure_wf_outlives.rs:58:12 + --> $DIR/closure_wf_outlives.rs:62:12 | LL | T: 'static, | ^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/closures_in_branches.rs b/tests/ui/type-alias-impl-trait/closures_in_branches.rs index 7bb490bbec81..4371ba2ed354 100644 --- a/tests/ui/type-alias-impl-trait/closures_in_branches.rs +++ b/tests/ui/type-alias-impl-trait/closures_in_branches.rs @@ -2,6 +2,7 @@ type Foo = impl std::ops::FnOnce(String) -> usize; +#[define_opaques(Foo)] fn foo(b: bool) -> Foo { if b { |x| x.len() //~ ERROR type annotations needed @@ -10,8 +11,8 @@ fn foo(b: bool) -> Foo { } } - type Foo1 = impl std::ops::FnOnce(String) -> usize; +#[define_opaques(Foo1)] fn foo1(b: bool) -> Foo1 { |x| x.len() } diff --git a/tests/ui/type-alias-impl-trait/closures_in_branches.stderr b/tests/ui/type-alias-impl-trait/closures_in_branches.stderr index 9cc15f14a991..849ffd214f07 100644 --- a/tests/ui/type-alias-impl-trait/closures_in_branches.stderr +++ b/tests/ui/type-alias-impl-trait/closures_in_branches.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed - --> $DIR/closures_in_branches.rs:7:10 + --> $DIR/closures_in_branches.rs:8:10 | LL | |x| x.len() | ^ - type must be known at this point @@ -10,7 +10,7 @@ LL | |x: /* Type */| x.len() | ++++++++++++ error[E0282]: type annotations needed - --> $DIR/closures_in_branches.rs:21:10 + --> $DIR/closures_in_branches.rs:22:10 | LL | |x| x.len() | ^ - type must be known at this point diff --git a/tests/ui/type-alias-impl-trait/coherence.classic.stderr b/tests/ui/type-alias-impl-trait/coherence.classic.stderr index 98badeef382d..e99d4636b134 100644 --- a/tests/ui/type-alias-impl-trait/coherence.classic.stderr +++ b/tests/ui/type-alias-impl-trait/coherence.classic.stderr @@ -1,5 +1,5 @@ error[E0117]: only traits defined in the current crate can be implemented for arbitrary types - --> $DIR/coherence.rs:16:1 + --> $DIR/coherence.rs:17:1 | LL | impl foreign_crate::ForeignTrait for AliasOfForeignType<()> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------- diff --git a/tests/ui/type-alias-impl-trait/coherence.next.stderr b/tests/ui/type-alias-impl-trait/coherence.next.stderr index 8d7183831109..6d14594e33a0 100644 --- a/tests/ui/type-alias-impl-trait/coherence.next.stderr +++ b/tests/ui/type-alias-impl-trait/coherence.next.stderr @@ -1,5 +1,5 @@ error[E0117]: only traits defined in the current crate can be implemented for arbitrary types - --> $DIR/coherence.rs:16:1 + --> $DIR/coherence.rs:17:1 | LL | impl foreign_crate::ForeignTrait for AliasOfForeignType<()> {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------------------- diff --git a/tests/ui/type-alias-impl-trait/coherence.rs b/tests/ui/type-alias-impl-trait/coherence.rs index 760e5210c5b7..b204436bf69d 100644 --- a/tests/ui/type-alias-impl-trait/coherence.rs +++ b/tests/ui/type-alias-impl-trait/coherence.rs @@ -9,6 +9,7 @@ trait LocalTrait {} impl LocalTrait for foreign_crate::ForeignType {} type AliasOfForeignType = impl LocalTrait; +#[define_opaques(AliasOfForeignType)] fn use_alias(val: T) -> AliasOfForeignType { foreign_crate::ForeignType(val) } diff --git a/tests/ui/type-alias-impl-trait/coherence_cross_crate.rs b/tests/ui/type-alias-impl-trait/coherence_cross_crate.rs index c1958e4f246d..5dc19c9156ef 100644 --- a/tests/ui/type-alias-impl-trait/coherence_cross_crate.rs +++ b/tests/ui/type-alias-impl-trait/coherence_cross_crate.rs @@ -13,6 +13,7 @@ trait OtherTrait {} type Alias = impl SomeTrait; +#[define_opaques(Alias)] fn constrain() -> Alias { () } diff --git a/tests/ui/type-alias-impl-trait/coherence_cross_crate.stderr b/tests/ui/type-alias-impl-trait/coherence_cross_crate.stderr index 893a27faced6..6b251cfac73c 100644 --- a/tests/ui/type-alias-impl-trait/coherence_cross_crate.stderr +++ b/tests/ui/type-alias-impl-trait/coherence_cross_crate.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `OtherTrait` for type `Alias` - --> $DIR/coherence_cross_crate.rs:21:1 + --> $DIR/coherence_cross_crate.rs:22:1 | LL | impl OtherTrait for Alias {} | ------------------------- first implementation here diff --git a/tests/ui/type-alias-impl-trait/coherence_different_hidden_ty.rs b/tests/ui/type-alias-impl-trait/coherence_different_hidden_ty.rs index 39b3d535ad45..d74c45f72156 100644 --- a/tests/ui/type-alias-impl-trait/coherence_different_hidden_ty.rs +++ b/tests/ui/type-alias-impl-trait/coherence_different_hidden_ty.rs @@ -20,6 +20,7 @@ impl Trait for (TAIT, TAIT) {} impl Trait for (u32, i32) {} //~^ ERROR conflicting implementations of trait `Trait` for type `(TAIT, TAIT)` +#[define_opaques(TAIT)] fn define() -> TAIT {} fn main() {} diff --git a/tests/ui/type-alias-impl-trait/coherence_generalization.rs b/tests/ui/type-alias-impl-trait/coherence_generalization.rs index 2d7de1add490..6e1872cdc95a 100644 --- a/tests/ui/type-alias-impl-trait/coherence_generalization.rs +++ b/tests/ui/type-alias-impl-trait/coherence_generalization.rs @@ -6,6 +6,7 @@ #![feature(type_alias_impl_trait)] trait Trait {} type Opaque = impl Sized; +#[define_opaques(Opaque)] fn foo() -> Opaque { () } diff --git a/tests/ui/type-alias-impl-trait/const_generic_type.infer.stderr b/tests/ui/type-alias-impl-trait/const_generic_type.infer.stderr index 5b77bb6c2bc2..b7999a695e7f 100644 --- a/tests/ui/type-alias-impl-trait/const_generic_type.infer.stderr +++ b/tests/ui/type-alias-impl-trait/const_generic_type.infer.stderr @@ -1,5 +1,5 @@ error: `Bar` is forbidden as the type of a const generic parameter - --> $DIR/const_generic_type.rs:7:24 + --> $DIR/const_generic_type.rs:8:24 | LL | async fn test() { | ^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/const_generic_type.no_infer.stderr b/tests/ui/type-alias-impl-trait/const_generic_type.no_infer.stderr index c7c93eee63e9..48b920db0d5a 100644 --- a/tests/ui/type-alias-impl-trait/const_generic_type.no_infer.stderr +++ b/tests/ui/type-alias-impl-trait/const_generic_type.no_infer.stderr @@ -1,5 +1,5 @@ error: `Bar` is forbidden as the type of a const generic parameter - --> $DIR/const_generic_type.rs:7:24 + --> $DIR/const_generic_type.rs:8:24 | LL | async fn test() { | ^^^^^^^^^^ @@ -7,7 +7,7 @@ LL | async fn test() { = note: the only supported types are integers, `bool`, and `char` error: item does not constrain `Bar::{opaque#0}`, but has it in its signature - --> $DIR/const_generic_type.rs:7:10 + --> $DIR/const_generic_type.rs:8:10 | LL | async fn test() { | ^^^^ @@ -20,7 +20,7 @@ LL | type Bar = impl std::fmt::Display; | ^^^^^^^^^^^^^^^^^^^^^^ error: item does not constrain `Bar::{opaque#0}`, but has it in its signature - --> $DIR/const_generic_type.rs:7:38 + --> $DIR/const_generic_type.rs:8:38 | LL | async fn test() { | ______________________________________^ diff --git a/tests/ui/type-alias-impl-trait/const_generic_type.rs b/tests/ui/type-alias-impl-trait/const_generic_type.rs index 7149370048b3..fb398d40190d 100644 --- a/tests/ui/type-alias-impl-trait/const_generic_type.rs +++ b/tests/ui/type-alias-impl-trait/const_generic_type.rs @@ -4,6 +4,7 @@ #![feature(type_alias_impl_trait)] type Bar = impl std::fmt::Display; +#[define_opaques(Bar)] async fn test() { //~^ ERROR: `Bar` is forbidden as the type of a const generic parameter //[no_infer]~^^ ERROR item does not constrain diff --git a/tests/ui/type-alias-impl-trait/constrain_in_projection.current.stderr b/tests/ui/type-alias-impl-trait/constrain_in_projection.current.stderr index 580258bbb28e..c4c55d8e0927 100644 --- a/tests/ui/type-alias-impl-trait/constrain_in_projection.current.stderr +++ b/tests/ui/type-alias-impl-trait/constrain_in_projection.current.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `Foo: Trait` is not satisfied - --> $DIR/constrain_in_projection.rs:24:14 + --> $DIR/constrain_in_projection.rs:25:14 | LL | let x = >::Assoc::default(); | ^^^ the trait `Trait` is not implemented for `Foo` @@ -8,7 +8,7 @@ LL | let x = >::Assoc::default(); but trait `Trait<()>` is implemented for it error[E0277]: the trait bound `Foo: Trait` is not satisfied - --> $DIR/constrain_in_projection.rs:24:13 + --> $DIR/constrain_in_projection.rs:25:13 | LL | let x = >::Assoc::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `Foo` diff --git a/tests/ui/type-alias-impl-trait/constrain_in_projection.rs b/tests/ui/type-alias-impl-trait/constrain_in_projection.rs index 355c0e1692b2..7d05888a513c 100644 --- a/tests/ui/type-alias-impl-trait/constrain_in_projection.rs +++ b/tests/ui/type-alias-impl-trait/constrain_in_projection.rs @@ -20,7 +20,8 @@ impl Trait<()> for Foo { type Assoc = u32; } -fn bop(_: Bar) { +#[define_opaques(Bar)] +fn bop() { let x = >::Assoc::default(); //[current]~^ `Foo: Trait` is not satisfied //[current]~| `Foo: Trait` is not satisfied diff --git a/tests/ui/type-alias-impl-trait/constrain_in_projection2.current.stderr b/tests/ui/type-alias-impl-trait/constrain_in_projection2.current.stderr index 777fe1e2788c..d7fb6e67ad29 100644 --- a/tests/ui/type-alias-impl-trait/constrain_in_projection2.current.stderr +++ b/tests/ui/type-alias-impl-trait/constrain_in_projection2.current.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `Foo: Trait` is not satisfied - --> $DIR/constrain_in_projection2.rs:27:14 + --> $DIR/constrain_in_projection2.rs:28:14 | LL | let x = >::Assoc::default(); | ^^^ the trait `Trait` is not implemented for `Foo` @@ -9,7 +9,7 @@ LL | let x = >::Assoc::default(); `Foo` implements `Trait` error[E0277]: the trait bound `Foo: Trait` is not satisfied - --> $DIR/constrain_in_projection2.rs:27:13 + --> $DIR/constrain_in_projection2.rs:28:13 | LL | let x = >::Assoc::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `Foo` diff --git a/tests/ui/type-alias-impl-trait/constrain_in_projection2.next.stderr b/tests/ui/type-alias-impl-trait/constrain_in_projection2.next.stderr index 0d6eac4216ba..7c09ab6a91ae 100644 --- a/tests/ui/type-alias-impl-trait/constrain_in_projection2.next.stderr +++ b/tests/ui/type-alias-impl-trait/constrain_in_projection2.next.stderr @@ -1,5 +1,5 @@ error[E0283]: type annotations needed: cannot satisfy `Foo: Trait` - --> $DIR/constrain_in_projection2.rs:27:14 + --> $DIR/constrain_in_projection2.rs:28:14 | LL | let x = >::Assoc::default(); | ^^^ help: use the fully qualified path to an implementation: `::Assoc` diff --git a/tests/ui/type-alias-impl-trait/constrain_in_projection2.rs b/tests/ui/type-alias-impl-trait/constrain_in_projection2.rs index 16b1329b52f3..f67a58445089 100644 --- a/tests/ui/type-alias-impl-trait/constrain_in_projection2.rs +++ b/tests/ui/type-alias-impl-trait/constrain_in_projection2.rs @@ -23,7 +23,8 @@ impl Trait for Foo { type Assoc = u32; } -fn bop(_: Bar) { +#[define_opaques(Bar)] +fn bop() { let x = >::Assoc::default(); //[next]~^ ERROR: cannot satisfy `Foo: Trait` //[current]~^^ ERROR: `Foo: Trait` is not satisfied diff --git a/tests/ui/type-alias-impl-trait/constrain_inputs.rs b/tests/ui/type-alias-impl-trait/constrain_inputs.rs index 1391a2036b2e..b0d13b7041e2 100644 --- a/tests/ui/type-alias-impl-trait/constrain_inputs.rs +++ b/tests/ui/type-alias-impl-trait/constrain_inputs.rs @@ -2,7 +2,9 @@ mod lifetime_params { type Ty<'a> = impl Sized; + #[define_opaques(Ty)] fn defining(s: &str) -> Ty<'_> { s } + #[define_opaques(Ty)] fn execute(ty: Ty<'_>) -> &str { todo!() } //~^ ERROR return type references an anonymous lifetime, which is not constrained by the fn input types //~| ERROR item does not constrain @@ -15,7 +17,9 @@ mod lifetime_params { mod lifetime_params_2 { type Ty<'a> = impl FnOnce() -> &'a str; + #[define_opaques(Ty)] fn defining(s: &str) -> Ty<'_> { move || s } + #[define_opaques(Ty)] fn execute(ty: Ty<'_>) -> &str { ty() } //~^ ERROR return type references an anonymous lifetime, which is not constrained by the fn input types //~| ERROR item does not constrain @@ -24,6 +28,7 @@ mod lifetime_params_2 { // regression test for https://github.com/rust-lang/rust/issues/97104 mod type_params { type Ty = impl Sized; + #[define_opaques(Ty)] fn define(s: T) -> Ty { s } type BadFnSig = fn(Ty<&str>) -> &str; diff --git a/tests/ui/type-alias-impl-trait/constrain_inputs.stderr b/tests/ui/type-alias-impl-trait/constrain_inputs.stderr index 436326e66c38..a84edccf39ae 100644 --- a/tests/ui/type-alias-impl-trait/constrain_inputs.stderr +++ b/tests/ui/type-alias-impl-trait/constrain_inputs.stderr @@ -1,5 +1,5 @@ error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types - --> $DIR/constrain_inputs.rs:6:31 + --> $DIR/constrain_inputs.rs:8:31 | LL | fn execute(ty: Ty<'_>) -> &str { todo!() } | ^^^^ @@ -8,7 +8,7 @@ LL | fn execute(ty: Ty<'_>) -> &str { todo!() } = note: consider introducing a named lifetime parameter error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types - --> $DIR/constrain_inputs.rs:10:35 + --> $DIR/constrain_inputs.rs:12:35 | LL | type BadFnSig = fn(Ty<'_>) -> &str; | ^^^^ @@ -17,7 +17,7 @@ LL | type BadFnSig = fn(Ty<'_>) -> &str; = note: consider introducing a named lifetime parameter error[E0582]: binding for associated type `Output` references an anonymous lifetime, which does not appear in the trait input types - --> $DIR/constrain_inputs.rs:12:42 + --> $DIR/constrain_inputs.rs:14:42 | LL | type BadTraitRef = dyn Fn(Ty<'_>) -> &str; | ^^^^ @@ -26,7 +26,7 @@ LL | type BadTraitRef = dyn Fn(Ty<'_>) -> &str; = note: consider introducing a named lifetime parameter error: item does not constrain `lifetime_params::Ty::{opaque#0}`, but has it in its signature - --> $DIR/constrain_inputs.rs:6:8 + --> $DIR/constrain_inputs.rs:8:8 | LL | fn execute(ty: Ty<'_>) -> &str { todo!() } | ^^^^^^^ @@ -39,7 +39,7 @@ LL | type Ty<'a> = impl Sized; | ^^^^^^^^^^ error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types - --> $DIR/constrain_inputs.rs:19:31 + --> $DIR/constrain_inputs.rs:23:31 | LL | fn execute(ty: Ty<'_>) -> &str { ty() } | ^^^^ @@ -48,20 +48,20 @@ LL | fn execute(ty: Ty<'_>) -> &str { ty() } = note: consider introducing a named lifetime parameter error: item does not constrain `lifetime_params_2::Ty::{opaque#0}`, but has it in its signature - --> $DIR/constrain_inputs.rs:19:8 + --> $DIR/constrain_inputs.rs:23:8 | LL | fn execute(ty: Ty<'_>) -> &str { ty() } | ^^^^^^^ | = note: consider moving the opaque type's declaration and defining uses into a separate module note: this opaque type is in the signature - --> $DIR/constrain_inputs.rs:17:19 + --> $DIR/constrain_inputs.rs:19:19 | LL | type Ty<'a> = impl FnOnce() -> &'a str; | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0581]: return type references an anonymous lifetime, which is not constrained by the fn input types - --> $DIR/constrain_inputs.rs:29:37 + --> $DIR/constrain_inputs.rs:34:37 | LL | type BadFnSig = fn(Ty<&str>) -> &str; | ^^^^ @@ -70,7 +70,7 @@ LL | type BadFnSig = fn(Ty<&str>) -> &str; = note: consider introducing a named lifetime parameter error[E0582]: binding for associated type `Output` references an anonymous lifetime, which does not appear in the trait input types - --> $DIR/constrain_inputs.rs:31:44 + --> $DIR/constrain_inputs.rs:36:44 | LL | type BadTraitRef = dyn Fn(Ty<&str>) -> &str; | ^^^^ diff --git a/tests/ui/type-alias-impl-trait/constrain_inputs_unsound.rs b/tests/ui/type-alias-impl-trait/constrain_inputs_unsound.rs index 3bae0f173099..a499d9c959fc 100644 --- a/tests/ui/type-alias-impl-trait/constrain_inputs_unsound.rs +++ b/tests/ui/type-alias-impl-trait/constrain_inputs_unsound.rs @@ -4,9 +4,12 @@ trait Static: 'static {} impl Static for () {} type Gal = impl Static; +#[define_opaques(Gal)] fn _defining() -> Gal {} -trait Callable { type Output; } +trait Callable { + type Output; +} /// We can infer `>::Output: 'static`, /// because we know `C: 'static` and `Arg: 'static`, diff --git a/tests/ui/type-alias-impl-trait/constrain_inputs_unsound.stderr b/tests/ui/type-alias-impl-trait/constrain_inputs_unsound.stderr index 948bd6deacd0..0edb0a068846 100644 --- a/tests/ui/type-alias-impl-trait/constrain_inputs_unsound.stderr +++ b/tests/ui/type-alias-impl-trait/constrain_inputs_unsound.stderr @@ -1,5 +1,5 @@ error[E0582]: binding for associated type `Output` references lifetime `'a`, which does not appear in the trait input types - --> $DIR/constrain_inputs_unsound.rs:23:58 + --> $DIR/constrain_inputs_unsound.rs:26:58 | LL | type MalformedTy = dyn for<'a> Callable, Output = &'a str>; | ^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs b/tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs index db9c2cc096ab..88a506e0bd3f 100644 --- a/tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs +++ b/tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs @@ -3,12 +3,10 @@ #![feature(type_alias_impl_trait)] -mod bar { - pub type Debuggable = impl core::fmt::Debug; - fn foo() -> Debuggable { - 0u32 - } +pub type Debuggable = impl core::fmt::Debug; +#[define_opaques(Debuggable)] +fn foo() -> Debuggable { + 0u32 } -use bar::Debuggable; static mut TEST: Option = None; diff --git a/tests/ui/type-alias-impl-trait/declared_but_never_defined.stderr b/tests/ui/type-alias-impl-trait/declared_but_never_defined.stderr index 772f487d96aa..c2c401da0e89 100644 --- a/tests/ui/type-alias-impl-trait/declared_but_never_defined.stderr +++ b/tests/ui/type-alias-impl-trait/declared_but_never_defined.stderr @@ -4,7 +4,7 @@ error: unconstrained opaque type LL | type Bar = impl std::fmt::Debug; | ^^^^^^^^^^^^^^^^^^^^ | - = note: `Bar` must be used in combination with a concrete type within the same module + = note: `Bar` must be used in combination with a concrete type within the same crate error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.stderr b/tests/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.stderr index d60f1ffbccc2..83cd3d7ba14f 100644 --- a/tests/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.stderr +++ b/tests/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.stderr @@ -4,7 +4,7 @@ error: unconstrained opaque type LL | pub type Boo = impl ::std::fmt::Debug; | ^^^^^^^^^^^^^^^^^^^^^^ | - = note: `Boo` must be used in combination with a concrete type within the same module + = note: `Boo` must be used in combination with a concrete type within the same crate error[E0308]: mismatched types --> $DIR/declared_but_not_defined_in_scope.rs:11:5 @@ -19,7 +19,7 @@ LL | "" | = note: expected opaque type `Boo` found reference `&'static str` -note: this item must have the opaque type in its signature in order to be able to register hidden types +note: this item must have a `#[define_opaques(Boo)]` attribute to be able to define hidden types --> $DIR/declared_but_not_defined_in_scope.rs:10:4 | LL | fn bomp() -> boo::Boo { diff --git a/tests/ui/type-alias-impl-trait/defined-by-user-annotation.rs b/tests/ui/type-alias-impl-trait/defined-by-user-annotation.rs index 75a4fbdb5d63..defb4309d286 100644 --- a/tests/ui/type-alias-impl-trait/defined-by-user-annotation.rs +++ b/tests/ui/type-alias-impl-trait/defined-by-user-annotation.rs @@ -11,9 +11,11 @@ impl> Indirect for (A, B) { type Ty = (); } mod basic { use super::*; type Opq = impl Sized; + #[define_opaques(Opq)] fn define_1(_: Opq) { let _ = None::<<(Opq, u8) as Indirect>::Ty>; } + #[define_opaques(Opq)] fn define_2() -> Opq { 0u8 } @@ -23,6 +25,7 @@ mod basic { mod lifetime { use super::*; type Opq<'a> = impl Sized + 'a; + #[define_opaques(Opq)] fn define<'a: 'b, 'b: 'a>(_: Opq<'a>) { let _ = None::<<(Opq<'a>, &'b u8) as Indirect>::Ty>; } diff --git a/tests/ui/type-alias-impl-trait/defined-in-closure-external-lifetime.rs b/tests/ui/type-alias-impl-trait/defined-in-closure-external-lifetime.rs index 9101e4385b3d..447ed774bbc1 100644 --- a/tests/ui/type-alias-impl-trait/defined-in-closure-external-lifetime.rs +++ b/tests/ui/type-alias-impl-trait/defined-in-closure-external-lifetime.rs @@ -2,6 +2,7 @@ mod case1 { type Opaque<'x> = impl Sized + 'x; + #[define_opaques(Opaque)] fn foo<'s>() -> Opaque<'s> { let _ = || { let _: Opaque<'s> = (); }; //~^ ERROR expected generic lifetime parameter, found `'_` @@ -10,6 +11,7 @@ mod case1 { mod case2 { type Opaque<'x> = impl Sized + 'x; + #[define_opaques(Opaque)] fn foo<'s>() -> Opaque<'s> { let _ = || -> Opaque<'s> {}; //~^ ERROR expected generic lifetime parameter, found `'_` diff --git a/tests/ui/type-alias-impl-trait/defined-in-closure-external-lifetime.stderr b/tests/ui/type-alias-impl-trait/defined-in-closure-external-lifetime.stderr index a8fd1f691dd4..2210291d37b5 100644 --- a/tests/ui/type-alias-impl-trait/defined-in-closure-external-lifetime.stderr +++ b/tests/ui/type-alias-impl-trait/defined-in-closure-external-lifetime.stderr @@ -1,18 +1,18 @@ error[E0792]: expected generic lifetime parameter, found `'_` - --> $DIR/defined-in-closure-external-lifetime.rs:6:29 + --> $DIR/defined-in-closure-external-lifetime.rs:7:29 | LL | type Opaque<'x> = impl Sized + 'x; | -- this generic parameter must be used with a generic lifetime parameter -LL | fn foo<'s>() -> Opaque<'s> { +... LL | let _ = || { let _: Opaque<'s> = (); }; | ^^^^^^^^^^ error[E0792]: expected generic lifetime parameter, found `'_` - --> $DIR/defined-in-closure-external-lifetime.rs:14:34 + --> $DIR/defined-in-closure-external-lifetime.rs:16:34 | LL | type Opaque<'x> = impl Sized + 'x; | -- this generic parameter must be used with a generic lifetime parameter -LL | fn foo<'s>() -> Opaque<'s> { +... LL | let _ = || -> Opaque<'s> {}; | ^^ diff --git a/tests/ui/type-alias-impl-trait/defining-use-submodule.rs b/tests/ui/type-alias-impl-trait/defining-use-submodule.rs index 3e7bc32640f5..21e64e309d21 100644 --- a/tests/ui/type-alias-impl-trait/defining-use-submodule.rs +++ b/tests/ui/type-alias-impl-trait/defining-use-submodule.rs @@ -11,13 +11,24 @@ type Foo = impl std::fmt::Display; type Bar = impl std::fmt::Display; mod foo { + #[define_opaques(super::Foo)] pub(crate) fn foo() -> super::Foo { "foo" } pub(crate) mod bar { + #[define_opaques(crate::Bar)] pub(crate) fn bar() -> crate::Bar { 1 } } } + +mod bar { + pub type Baz = impl std::fmt::Display; +} + +#[define_opaques(bar::Baz)] +fn baz() -> bar::Baz { + "boom" +} diff --git a/tests/ui/type-alias-impl-trait/destructure_tait-ice-113594.rs b/tests/ui/type-alias-impl-trait/destructure_tait-ice-113594.rs index eadf21c9138c..459f44ec2bf4 100644 --- a/tests/ui/type-alias-impl-trait/destructure_tait-ice-113594.rs +++ b/tests/ui/type-alias-impl-trait/destructure_tait-ice-113594.rs @@ -10,6 +10,7 @@ pub struct Foo { pub type Tait = impl Sized; +#[define_opaques(Tait)] pub async fn ice_cold(beverage: Tait) { // Must destructure at least one field of `Foo` let Foo { field } = beverage; diff --git a/tests/ui/type-alias-impl-trait/different_args_considered_equal.rs b/tests/ui/type-alias-impl-trait/different_args_considered_equal.rs index 8ce471e39568..39de2fa64099 100644 --- a/tests/ui/type-alias-impl-trait/different_args_considered_equal.rs +++ b/tests/ui/type-alias-impl-trait/different_args_considered_equal.rs @@ -2,10 +2,12 @@ pub type Opaque<'a> = impl Sized; +#[define_opaques(Opaque)] fn get_one<'a>(a: *mut &'a str) -> Opaque<'a> { a } +#[define_opaques(Opaque)] fn get_iter<'a>() -> impl IntoIterator> { //~^ ERROR: item does not constrain None::> diff --git a/tests/ui/type-alias-impl-trait/different_args_considered_equal.stderr b/tests/ui/type-alias-impl-trait/different_args_considered_equal.stderr index f27f22345252..59b05e7c81f3 100644 --- a/tests/ui/type-alias-impl-trait/different_args_considered_equal.stderr +++ b/tests/ui/type-alias-impl-trait/different_args_considered_equal.stderr @@ -1,5 +1,5 @@ error: item does not constrain `Opaque::{opaque#0}`, but has it in its signature - --> $DIR/different_args_considered_equal.rs:9:4 + --> $DIR/different_args_considered_equal.rs:11:4 | LL | fn get_iter<'a>() -> impl IntoIterator> { | ^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/different_args_considered_equal2.rs b/tests/ui/type-alias-impl-trait/different_args_considered_equal2.rs index 43dfea97e6db..ea247fa60382 100644 --- a/tests/ui/type-alias-impl-trait/different_args_considered_equal2.rs +++ b/tests/ui/type-alias-impl-trait/different_args_considered_equal2.rs @@ -2,6 +2,7 @@ pub type Opaque<'a> = impl Sized; +#[define_opaques(Opaque)] fn get_one<'a>(a: *mut &'a str) -> impl IntoIterator> { if a.is_null() { Some(a) diff --git a/tests/ui/type-alias-impl-trait/different_args_considered_equal2.stderr b/tests/ui/type-alias-impl-trait/different_args_considered_equal2.stderr index 213272f5f345..562ab4168b53 100644 --- a/tests/ui/type-alias-impl-trait/different_args_considered_equal2.stderr +++ b/tests/ui/type-alias-impl-trait/different_args_considered_equal2.stderr @@ -1,9 +1,9 @@ error[E0700]: hidden type for `Opaque<'static>` captures lifetime that does not appear in bounds - --> $DIR/different_args_considered_equal2.rs:9:9 + --> $DIR/different_args_considered_equal2.rs:10:9 | LL | pub type Opaque<'a> = impl Sized; | ---------- opaque type defined here -LL | +... LL | fn get_one<'a>(a: *mut &'a str) -> impl IntoIterator> { | -- hidden type `*mut &'a str` captures the lifetime `'a` as defined here ... diff --git a/tests/ui/type-alias-impl-trait/different_args_considered_equal3.rs b/tests/ui/type-alias-impl-trait/different_args_considered_equal3.rs index ea69175ba310..174d325745c8 100644 --- a/tests/ui/type-alias-impl-trait/different_args_considered_equal3.rs +++ b/tests/ui/type-alias-impl-trait/different_args_considered_equal3.rs @@ -5,14 +5,12 @@ #![feature(type_alias_impl_trait)] -mod defining_scope { - pub type Opaque<'a> = impl Sized; +pub type Opaque<'a> = impl Sized; - fn get_one<'a>(a: *mut &'a str) -> Opaque<'a> { - a - } +#[define_opaques(Opaque)] +fn get_one<'a>(a: *mut &'a str) -> Opaque<'a> { + a } -use defining_scope::Opaque; fn get_iter<'a>() -> impl IntoIterator> { None::> diff --git a/tests/ui/type-alias-impl-trait/different_args_considered_equal3.stderr b/tests/ui/type-alias-impl-trait/different_args_considered_equal3.stderr index d8f70e3d7782..06d6433c4b5f 100644 --- a/tests/ui/type-alias-impl-trait/different_args_considered_equal3.stderr +++ b/tests/ui/type-alias-impl-trait/different_args_considered_equal3.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/different_args_considered_equal3.rs:18:5 + --> $DIR/different_args_considered_equal3.rs:16:5 | LL | fn get_iter<'a>() -> impl IntoIterator> { | -- lifetime `'a` defined here diff --git a/tests/ui/type-alias-impl-trait/different_defining_uses.rs b/tests/ui/type-alias-impl-trait/different_defining_uses.rs index 4505c4d95248..72766a595468 100644 --- a/tests/ui/type-alias-impl-trait/different_defining_uses.rs +++ b/tests/ui/type-alias-impl-trait/different_defining_uses.rs @@ -5,10 +5,12 @@ fn main() {} // two definitions with different types type Foo = impl std::fmt::Debug; +#[define_opaques(Foo)] fn foo() -> Foo { "" } +#[define_opaques(Foo)] fn bar() -> Foo { 42i32 //~^ ERROR concrete type differs from previous diff --git a/tests/ui/type-alias-impl-trait/different_defining_uses.stderr b/tests/ui/type-alias-impl-trait/different_defining_uses.stderr index 9e6169b2af73..9a7f4b416f4b 100644 --- a/tests/ui/type-alias-impl-trait/different_defining_uses.stderr +++ b/tests/ui/type-alias-impl-trait/different_defining_uses.stderr @@ -1,11 +1,11 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/different_defining_uses.rs:13:5 + --> $DIR/different_defining_uses.rs:15:5 | LL | 42i32 | ^^^^^ expected `&'static str`, got `i32` | note: previous use here - --> $DIR/different_defining_uses.rs:9:5 + --> $DIR/different_defining_uses.rs:10:5 | LL | "" | ^^ diff --git a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.rs b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.rs index 4b5f455e3815..b73e0945e36f 100644 --- a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.rs +++ b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.rs @@ -2,6 +2,7 @@ type Tait<'a> = impl Sized + 'a; +#[define_opaques(Tait)] fn foo<'a, 'b>() -> Tait<'a> { if false { if { return } { diff --git a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.stderr b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.stderr index 6f5be5467f70..d4bd39759247 100644 --- a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.stderr +++ b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-2.stderr @@ -1,23 +1,23 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/different_defining_uses_never_type-2.rs:13:5 + --> $DIR/different_defining_uses_never_type-2.rs:14:5 | LL | x | ^ expected `i32`, got `()` | note: previous use here - --> $DIR/different_defining_uses_never_type-2.rs:8:31 + --> $DIR/different_defining_uses_never_type-2.rs:9:31 | LL | let y: Tait<'b> = 1i32; | ^^^^ error: concrete type differs from previous defining opaque type use - --> $DIR/different_defining_uses_never_type-2.rs:8:31 + --> $DIR/different_defining_uses_never_type-2.rs:9:31 | LL | let y: Tait<'b> = 1i32; | ^^^^ expected `()`, got `i32` | note: previous use here - --> $DIR/different_defining_uses_never_type-2.rs:7:14 + --> $DIR/different_defining_uses_never_type-2.rs:8:14 | LL | if { return } { | ^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-3.rs b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-3.rs index a4ac27378e1d..2dc93102afad 100644 --- a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-3.rs +++ b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-3.rs @@ -2,6 +2,7 @@ type Tait = impl Sized; +#[define_opaques(Tait)] fn foo() -> Tait { if false { if { return } { diff --git a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-3.stderr b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-3.stderr index 0fdcb81f6672..cb12fddd9a03 100644 --- a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-3.stderr +++ b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type-3.stderr @@ -1,11 +1,11 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/different_defining_uses_never_type-3.rs:8:30 + --> $DIR/different_defining_uses_never_type-3.rs:9:30 | LL | let y: Tait = 1i32; | ^^^^ expected `()`, got `i32` | note: previous use here - --> $DIR/different_defining_uses_never_type-3.rs:12:22 + --> $DIR/different_defining_uses_never_type-3.rs:13:22 | LL | let x: Tait = (); | ^^ diff --git a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type.rs b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type.rs index 0b8157fe33dd..022fed42ada2 100644 --- a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type.rs +++ b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type.rs @@ -5,14 +5,17 @@ fn main() {} // two definitions with different types type Foo = impl std::fmt::Debug; +#[define_opaques(Foo)] fn foo() -> Foo { "" } +#[define_opaques(Foo)] fn bar() -> Foo { //~ ERROR: concrete type differs from previous defining opaque type use panic!() } +#[define_opaques(Foo)] fn boo() -> Foo { loop {} } diff --git a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type.stderr b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type.stderr index 2a77eb4c4ac3..38afa3cbcd0e 100644 --- a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type.stderr +++ b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type.stderr @@ -1,11 +1,11 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/different_defining_uses_never_type.rs:12:13 + --> $DIR/different_defining_uses_never_type.rs:14:13 | LL | fn bar() -> Foo { | ^^^ expected `&'static str`, got `()` | note: previous use here - --> $DIR/different_defining_uses_never_type.rs:9:5 + --> $DIR/different_defining_uses_never_type.rs:10:5 | LL | "" | ^^ diff --git a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type2.rs b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type2.rs index c39cc192dc74..daf302e757fe 100644 --- a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type2.rs +++ b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type2.rs @@ -7,10 +7,12 @@ fn main() {} // two definitions with different types type Foo = impl std::fmt::Debug; +#[define_opaques(Foo)] fn foo() -> Foo { "" } +#[define_opaques(Foo)] fn bar(arg: bool) -> Foo { if arg { panic!() @@ -19,6 +21,7 @@ fn bar(arg: bool) -> Foo { } } +#[define_opaques(Foo)] fn boo(arg: bool) -> Foo { if arg { loop {} @@ -27,6 +30,7 @@ fn boo(arg: bool) -> Foo { } } +#[define_opaques(Foo)] fn bar2(arg: bool) -> Foo { if arg { "bar2" @@ -35,6 +39,7 @@ fn bar2(arg: bool) -> Foo { } } +#[define_opaques(Foo)] fn boo2(arg: bool) -> Foo { if arg { "boo2" diff --git a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type3.rs b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type3.rs index bc827a8f2113..fab62883f20b 100644 --- a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type3.rs +++ b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type3.rs @@ -3,9 +3,11 @@ type Tait = impl Sized; struct One; +#[define_opaques(Tait)] fn one() -> Tait { One } struct Two(T); +#[define_opaques(Tait)] fn two() -> Tait { Two::<()>(todo!()) } //~^ ERROR concrete type differs from previous defining opaque type use diff --git a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type3.stderr b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type3.stderr index abf4a0d241b2..21fab8180633 100644 --- a/tests/ui/type-alias-impl-trait/different_defining_uses_never_type3.stderr +++ b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type3.stderr @@ -1,11 +1,11 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/different_defining_uses_never_type3.rs:9:13 + --> $DIR/different_defining_uses_never_type3.rs:11:13 | LL | fn two() -> Tait { Two::<()>(todo!()) } | ^^^^ expected `One`, got `Two<()>` | note: previous use here - --> $DIR/different_defining_uses_never_type3.rs:6:20 + --> $DIR/different_defining_uses_never_type3.rs:7:20 | LL | fn one() -> Tait { One } | ^^^ diff --git a/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs b/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs index 4f424b8c665a..8d86d2cf53f2 100644 --- a/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs +++ b/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.rs @@ -3,10 +3,12 @@ type OneLifetime<'a, 'b> = impl std::fmt::Debug; +#[define_opaques(OneLifetime)] fn foo<'a, 'b>(a: &'a u32, b: &'b u32) -> OneLifetime<'a, 'b> { a } +#[define_opaques(OneLifetime)] fn bar<'a, 'b>(a: &'a u32, b: &'b u32) -> OneLifetime<'a, 'b> { b //~^ ERROR: concrete type differs from previous defining opaque type use diff --git a/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr b/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr index 07ba17ad27b8..b87e884708ab 100644 --- a/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr +++ b/tests/ui/type-alias-impl-trait/different_lifetimes_defining_uses.stderr @@ -1,11 +1,11 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/different_lifetimes_defining_uses.rs:11:5 + --> $DIR/different_lifetimes_defining_uses.rs:13:5 | LL | b | ^ expected `&'a u32`, got `&'b u32` | note: previous use here - --> $DIR/different_lifetimes_defining_uses.rs:7:5 + --> $DIR/different_lifetimes_defining_uses.rs:8:5 | LL | a | ^ diff --git a/tests/ui/type-alias-impl-trait/drop-analysis-on-unconstrained-tait.rs b/tests/ui/type-alias-impl-trait/drop-analysis-on-unconstrained-tait.rs index 4332f1264a80..b222ff54c1f0 100644 --- a/tests/ui/type-alias-impl-trait/drop-analysis-on-unconstrained-tait.rs +++ b/tests/ui/type-alias-impl-trait/drop-analysis-on-unconstrained-tait.rs @@ -2,29 +2,32 @@ #![feature(type_alias_impl_trait)] -mod impl_trait_mod { - use super::*; - pub type OpaqueBlock = impl Trait; - //~^ ERROR unconstrained opaque type - pub type OpaqueIf = impl Trait; +pub type OpaqueBlock = impl Trait; +//~^ ERROR unconstrained opaque type +pub type OpaqueIf = impl Trait; - pub struct BlockWrapper(OpaqueBlock); - pub struct IfWrapper(pub OpaqueIf); +pub struct BlockWrapper(OpaqueBlock); +pub struct IfWrapper(pub OpaqueIf); - pub fn if_impl() -> Parser { - bind(option(block()), |_| block()) - } +#[define_opaques(OpaqueIf)] +pub fn if_impl() -> Parser { + bind(option(block()), |_| block()) } -use impl_trait_mod::*; pub trait Trait { type Assoc; } pub struct Parser

(P); pub struct Bind(P, F); -impl Trait for Bind { type Assoc = (); } -impl Trait for BlockWrapper { type Assoc = (); } -impl Trait for IfWrapper { type Assoc = (); } +impl Trait for Bind { + type Assoc = (); +} +impl Trait for BlockWrapper { + type Assoc = (); +} +impl Trait for IfWrapper { + type Assoc = (); +} pub fn block() -> Parser { loop {} @@ -32,8 +35,9 @@ pub fn block() -> Parser { pub fn option(arg: Parser

) -> Parser { bind(arg, |_| block()) } -fn bind Parser>(_: Parser

, _: F) -> Parser> - { loop {} } +fn bind Parser>(_: Parser

, _: F) -> Parser> { + loop {} +} fn main() { if_impl().0; diff --git a/tests/ui/type-alias-impl-trait/drop-analysis-on-unconstrained-tait.stderr b/tests/ui/type-alias-impl-trait/drop-analysis-on-unconstrained-tait.stderr index 8e5838d5ddf5..db97954f6985 100644 --- a/tests/ui/type-alias-impl-trait/drop-analysis-on-unconstrained-tait.stderr +++ b/tests/ui/type-alias-impl-trait/drop-analysis-on-unconstrained-tait.stderr @@ -1,10 +1,10 @@ error: unconstrained opaque type - --> $DIR/drop-analysis-on-unconstrained-tait.rs:7:28 + --> $DIR/drop-analysis-on-unconstrained-tait.rs:5:24 | -LL | pub type OpaqueBlock = impl Trait; - | ^^^^^^^^^^ +LL | pub type OpaqueBlock = impl Trait; + | ^^^^^^^^^^ | - = note: `OpaqueBlock` must be used in combination with a concrete type within the same module + = note: `OpaqueBlock` must be used in combination with a concrete type within the same crate error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/duplicate-lifetimes-from-rpit-containing-tait.rs b/tests/ui/type-alias-impl-trait/duplicate-lifetimes-from-rpit-containing-tait.rs index b1d5961067bd..2ca3435c6c31 100644 --- a/tests/ui/type-alias-impl-trait/duplicate-lifetimes-from-rpit-containing-tait.rs +++ b/tests/ui/type-alias-impl-trait/duplicate-lifetimes-from-rpit-containing-tait.rs @@ -4,6 +4,7 @@ type Opaque<'lt> = impl Sized + 'lt; +#[define_opaques(Opaque)] fn test<'a>( arg: impl Iterator, ) -> impl Iterator> { diff --git a/tests/ui/type-alias-impl-trait/equal-lifetime-params-not-ok.rs b/tests/ui/type-alias-impl-trait/equal-lifetime-params-not-ok.rs index b209b4bc89df..7b217700033c 100644 --- a/tests/ui/type-alias-impl-trait/equal-lifetime-params-not-ok.rs +++ b/tests/ui/type-alias-impl-trait/equal-lifetime-params-not-ok.rs @@ -7,19 +7,21 @@ impl Trait<'_, '_> for T {} mod mod1 { type Opaque<'a, 'b> = impl super::Trait<'a, 'b>; + #[define_opaques(Opaque)] fn test<'a>() -> Opaque<'a, 'a> {} //~^ ERROR non-defining opaque type use in defining scope - //~| ERROR non-defining opaque type use in defining scope } mod mod2 { type Opaque<'a, 'b> = impl super::Trait<'a, 'b>; + #[define_opaques(Opaque)] fn test<'a: 'b, 'b: 'a>() -> Opaque<'a, 'b> {} //~^ ERROR non-defining opaque type use in defining scope } mod mod3 { type Opaque<'a, 'b> = impl super::Trait<'a, 'b>; + #[define_opaques(Opaque)] fn test<'a: 'b, 'b: 'a>(a: &'a str) -> Opaque<'a, 'b> { a } //~^ ERROR non-defining opaque type use in defining scope } @@ -30,6 +32,7 @@ mod mod3 { // it is ambiguous whether `Opaque<'a> := &'a ()` or `Opaque<'a> := &'static ()` mod mod4 { type Opaque<'a> = impl super::Trait<'a, 'a>; + #[define_opaques(Opaque)] fn test<'a: 'static>() -> Opaque<'a> {} //~^ ERROR expected generic lifetime parameter, found `'static` } diff --git a/tests/ui/type-alias-impl-trait/equal-lifetime-params-not-ok.stderr b/tests/ui/type-alias-impl-trait/equal-lifetime-params-not-ok.stderr index b08bc8b82687..a1683fda35e4 100644 --- a/tests/ui/type-alias-impl-trait/equal-lifetime-params-not-ok.stderr +++ b/tests/ui/type-alias-impl-trait/equal-lifetime-params-not-ok.stderr @@ -1,17 +1,5 @@ error: non-defining opaque type use in defining scope - --> $DIR/equal-lifetime-params-not-ok.rs:10:22 - | -LL | fn test<'a>() -> Opaque<'a, 'a> {} - | ^^^^^^^^^^^^^^ generic argument `'a` used twice - | -note: for this opaque type - --> $DIR/equal-lifetime-params-not-ok.rs:9:27 - | -LL | type Opaque<'a, 'b> = impl super::Trait<'a, 'b>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: non-defining opaque type use in defining scope - --> $DIR/equal-lifetime-params-not-ok.rs:10:37 + --> $DIR/equal-lifetime-params-not-ok.rs:11:37 | LL | fn test<'a>() -> Opaque<'a, 'a> {} | ^^ @@ -23,7 +11,7 @@ LL | type Opaque<'a, 'b> = impl super::Trait<'a, 'b>; | ^^ ^^ error: non-defining opaque type use in defining scope - --> $DIR/equal-lifetime-params-not-ok.rs:17:49 + --> $DIR/equal-lifetime-params-not-ok.rs:18:49 | LL | fn test<'a: 'b, 'b: 'a>() -> Opaque<'a, 'b> {} | ^^ @@ -35,25 +23,26 @@ LL | type Opaque<'a, 'b> = impl super::Trait<'a, 'b>; | ^^ ^^ error: non-defining opaque type use in defining scope - --> $DIR/equal-lifetime-params-not-ok.rs:23:61 + --> $DIR/equal-lifetime-params-not-ok.rs:25:61 | LL | fn test<'a: 'b, 'b: 'a>(a: &'a str) -> Opaque<'a, 'b> { a } | ^ | note: lifetime used multiple times - --> $DIR/equal-lifetime-params-not-ok.rs:22:17 + --> $DIR/equal-lifetime-params-not-ok.rs:23:17 | LL | type Opaque<'a, 'b> = impl super::Trait<'a, 'b>; | ^^ ^^ error[E0792]: expected generic lifetime parameter, found `'static` - --> $DIR/equal-lifetime-params-not-ok.rs:33:42 + --> $DIR/equal-lifetime-params-not-ok.rs:36:42 | LL | type Opaque<'a> = impl super::Trait<'a, 'a>; | -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type +LL | #[define_opaques(Opaque)] LL | fn test<'a: 'static>() -> Opaque<'a> {} | ^^ -error: aborting due to 5 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0792`. diff --git a/tests/ui/type-alias-impl-trait/equal-lifetime-params-ok.rs b/tests/ui/type-alias-impl-trait/equal-lifetime-params-ok.rs index 0ce85a4d6cbe..e818eb7345df 100644 --- a/tests/ui/type-alias-impl-trait/equal-lifetime-params-ok.rs +++ b/tests/ui/type-alias-impl-trait/equal-lifetime-params-ok.rs @@ -12,6 +12,7 @@ impl Trait<'_, '_> for T {} mod equal_params { type Opaque<'a: 'b, 'b: 'a> = impl super::Trait<'a, 'b>; + #[define_opaques(Opaque)] fn test<'a: 'b, 'b: 'a>() -> Opaque<'a, 'b> { let _ = None::<&'a &'b &'a ()>; 0u8 @@ -20,6 +21,7 @@ mod equal_params { mod equal_static { type Opaque<'a: 'static> = impl Sized + 'a; + #[define_opaques(Opaque)] fn test<'a: 'static>() -> Opaque<'a> { let _ = None::<&'static &'a ()>; 0u8 diff --git a/tests/ui/type-alias-impl-trait/escaping-bound-var.rs b/tests/ui/type-alias-impl-trait/escaping-bound-var.rs index 07206dd2491e..5727888b3103 100644 --- a/tests/ui/type-alias-impl-trait/escaping-bound-var.rs +++ b/tests/ui/type-alias-impl-trait/escaping-bound-var.rs @@ -16,6 +16,7 @@ impl Trait<'_> for () { impl Test<'_> for () {} +#[define_opaques(Foo)] fn constrain() -> Foo { () } diff --git a/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.rs b/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.rs index 9ed010f2293e..3de3932668ef 100644 --- a/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.rs +++ b/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.rs @@ -22,10 +22,12 @@ type StateWidget<'a> = impl Widget<&'a ()>; impl Fn(&'a ()) -> StateWidget<'a>> Widget<()> for StatefulWidget { type State = (); + #[define_opaques(StateWidget)] fn make_state(&self) -> Self::State {} //~^ ERROR item does not constrain } +#[define_opaques(StateWidget)] fn new_stateful_widget Fn(&'a ()) -> StateWidget<'a>>(build: F) -> impl Widget<()> { //~^ ERROR item does not constrain StatefulWidget(build) diff --git a/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.stderr b/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.stderr index 9a3f4ae4c1c3..850e81bd6ddb 100644 --- a/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.stderr +++ b/tests/ui/type-alias-impl-trait/failed-to-normalize-ice-99945.stderr @@ -1,5 +1,5 @@ error: item does not constrain `StateWidget::{opaque#0}`, but has it in its signature - --> $DIR/failed-to-normalize-ice-99945.rs:25:8 + --> $DIR/failed-to-normalize-ice-99945.rs:26:8 | LL | fn make_state(&self) -> Self::State {} | ^^^^^^^^^^ @@ -12,7 +12,7 @@ LL | type StateWidget<'a> = impl Widget<&'a ()>; | ^^^^^^^^^^^^^^^^^^^ error: item does not constrain `StateWidget::{opaque#0}`, but has it in its signature - --> $DIR/failed-to-normalize-ice-99945.rs:29:4 + --> $DIR/failed-to-normalize-ice-99945.rs:31:4 | LL | fn new_stateful_widget Fn(&'a ()) -> StateWidget<'a>>(build: F) -> impl Widget<()> { | ^^^^^^^^^^^^^^^^^^^ @@ -24,8 +24,17 @@ note: this opaque type is in the signature LL | type StateWidget<'a> = impl Widget<&'a ()>; | ^^^^^^^^^^^^^^^^^^^ +error[E0792]: expected generic lifetime parameter, found `'a` + --> $DIR/failed-to-normalize-ice-99945.rs:33:5 + | +LL | type StateWidget<'a> = impl Widget<&'a ()>; + | -- this generic parameter must be used with a generic lifetime parameter +... +LL | StatefulWidget(build) + | ^^^^^^^^^^^^^^^^^^^^^ + error[E0308]: mismatched types - --> $DIR/failed-to-normalize-ice-99945.rs:36:29 + --> $DIR/failed-to-normalize-ice-99945.rs:38:29 | LL | type StateWidget<'a> = impl Widget<&'a ()>; | ------------------- the expected opaque type @@ -36,15 +45,6 @@ LL | new_stateful_widget(|_| ()).make_state(); = note: expected opaque type `StateWidget<'_>` found unit type `()` -error[E0792]: expected generic lifetime parameter, found `'a` - --> $DIR/failed-to-normalize-ice-99945.rs:31:5 - | -LL | type StateWidget<'a> = impl Widget<&'a ()>; - | -- this generic parameter must be used with a generic lifetime parameter -... -LL | StatefulWidget(build) - | ^^^^^^^^^^^^^^^^^^^^^ - error: aborting due to 4 previous errors Some errors have detailed explanations: E0308, E0792. diff --git a/tests/ui/type-alias-impl-trait/fallback.rs b/tests/ui/type-alias-impl-trait/fallback.rs index d8cf7d71fef7..b325317946f1 100644 --- a/tests/ui/type-alias-impl-trait/fallback.rs +++ b/tests/ui/type-alias-impl-trait/fallback.rs @@ -7,19 +7,20 @@ type Foo = impl Copy; enum Wrapper { First(T), - Second + Second, } // This method constrains `Foo` to be `bool` +#[define_opaques(Foo)] fn constrained_foo() -> Foo { true } - // This method does not constrain `Foo`. // Per RFC 2071, function bodies may either // fully constrain an opaque type, or place no // constraints on it. +#[define_opaques(Foo)] fn unconstrained_foo() -> Wrapper { Wrapper::Second //~^ ERROR: type annotations needed diff --git a/tests/ui/type-alias-impl-trait/fallback.stderr b/tests/ui/type-alias-impl-trait/fallback.stderr index c909ab66f0ee..1eb0afb13a8d 100644 --- a/tests/ui/type-alias-impl-trait/fallback.stderr +++ b/tests/ui/type-alias-impl-trait/fallback.stderr @@ -1,5 +1,5 @@ error[E0283]: type annotations needed - --> $DIR/fallback.rs:24:5 + --> $DIR/fallback.rs:25:5 | LL | fn unconstrained_foo() -> Wrapper { | ------------ type must be known at this point diff --git a/tests/ui/type-alias-impl-trait/field-types.rs b/tests/ui/type-alias-impl-trait/field-types.rs index 24e430afac3a..e18b93e907d7 100644 --- a/tests/ui/type-alias-impl-trait/field-types.rs +++ b/tests/ui/type-alias-impl-trait/field-types.rs @@ -1,3 +1,6 @@ +//! Show that `defines(StructName)` works for +//! fields of that struct being an opaque type. + #![feature(type_alias_impl_trait)] #![allow(dead_code)] @@ -11,6 +14,7 @@ struct Bar { foo: Foo, } +#[define_opaques(Bar)] fn bar() -> Bar { Bar { foo: "foo" } } diff --git a/tests/ui/type-alias-impl-trait/future.rs b/tests/ui/type-alias-impl-trait/future.rs index 36d1dcd00ad1..9770dead8357 100644 --- a/tests/ui/type-alias-impl-trait/future.rs +++ b/tests/ui/type-alias-impl-trait/future.rs @@ -11,6 +11,7 @@ trait Bar { type FooFuture = impl Future; +#[define_opaques(FooFuture)] fn foo(bar: B) -> FooFuture { async move { bar.bar() } //~^ ERROR: the trait bound `B: Bar` is not satisfied diff --git a/tests/ui/type-alias-impl-trait/future.stderr b/tests/ui/type-alias-impl-trait/future.stderr index 047ad164239c..8510ab27fb75 100644 --- a/tests/ui/type-alias-impl-trait/future.stderr +++ b/tests/ui/type-alias-impl-trait/future.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `B: Bar` is not satisfied - --> $DIR/future.rs:15:5 + --> $DIR/future.rs:16:5 | LL | async move { bar.bar() } | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `B` | note: required by a bound in `foo` - --> $DIR/future.rs:14:11 + --> $DIR/future.rs:15:11 | LL | fn foo(bar: B) -> FooFuture { | ^^^ required by this bound in `foo` diff --git a/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.basic.stderr b/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.basic.stderr index e5f86c8c1935..43e887f36c5f 100644 --- a/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.basic.stderr +++ b/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.basic.stderr @@ -1,5 +1,5 @@ error[E0792]: expected generic lifetime parameter, found `'_` - --> $DIR/generic-not-strictly-equal.rs:33:5 + --> $DIR/generic-not-strictly-equal.rs:34:5 | LL | type Opaque<'a> = impl Copy + Captures<'a>; | -- this generic parameter must be used with a generic lifetime parameter diff --git a/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.member_constraints.stderr b/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.member_constraints.stderr index 693af69d6fab..4a5360c9922e 100644 --- a/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.member_constraints.stderr +++ b/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.member_constraints.stderr @@ -1,9 +1,9 @@ error[E0700]: hidden type for `Opaque<'x>` captures lifetime that does not appear in bounds - --> $DIR/generic-not-strictly-equal.rs:33:5 + --> $DIR/generic-not-strictly-equal.rs:34:5 | LL | type Opaque<'a> = impl Copy + Captures<'a>; | ------------------------ opaque type defined here -LL | +... LL | fn test<'x>(_: Opaque<'x>) { | -- hidden type `&'x u8` captures the lifetime `'x` as defined here ... diff --git a/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.rs b/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.rs index a059fd3b8227..3cc1649a8c54 100644 --- a/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.rs +++ b/tests/ui/type-alias-impl-trait/generic-not-strictly-equal.rs @@ -20,6 +20,7 @@ fn relate(_: X, _: X) {} type Opaque<'a> = impl Copy + Captures<'a>; +#[define_opaques(Opaque)] fn test<'x>(_: Opaque<'x>) { let opaque = None::>; // let's call this lifetime '?1 diff --git a/tests/ui/type-alias-impl-trait/generic_different_defining_uses.rs b/tests/ui/type-alias-impl-trait/generic_different_defining_uses.rs index 8b683ad28288..3555b78be9ac 100644 --- a/tests/ui/type-alias-impl-trait/generic_different_defining_uses.rs +++ b/tests/ui/type-alias-impl-trait/generic_different_defining_uses.rs @@ -4,10 +4,12 @@ fn main() {} type MyIter = impl Iterator; +#[define_opaques(MyIter)] fn my_iter(t: T) -> MyIter { std::iter::once(t) } +#[define_opaques(MyIter)] fn my_iter2(t: T) -> MyIter { Some(t).into_iter() //~^ ERROR concrete type differs from previous diff --git a/tests/ui/type-alias-impl-trait/generic_different_defining_uses.stderr b/tests/ui/type-alias-impl-trait/generic_different_defining_uses.stderr index 72271d158a1a..6d3279144d8f 100644 --- a/tests/ui/type-alias-impl-trait/generic_different_defining_uses.stderr +++ b/tests/ui/type-alias-impl-trait/generic_different_defining_uses.stderr @@ -1,11 +1,11 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/generic_different_defining_uses.rs:12:5 + --> $DIR/generic_different_defining_uses.rs:14:5 | LL | Some(t).into_iter() | ^^^^^^^^^^^^^^^^^^^ expected `std::iter::Once`, got `std::option::IntoIter` | note: previous use here - --> $DIR/generic_different_defining_uses.rs:8:5 + --> $DIR/generic_different_defining_uses.rs:9:5 | LL | std::iter::once(t) | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs index 169d4f8d5094..c88193ce4dff 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.rs @@ -4,8 +4,8 @@ fn main() {} type Two<'a, 'b> = impl std::fmt::Debug; +#[define_opaques(Two)] fn one<'a>(t: &'a ()) -> Two<'a, 'a> { - //~^ ERROR non-defining opaque type use t //~^ ERROR non-defining opaque type use } diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr index b03bf2466e60..352e6fd3c5c8 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_lifetime_param.stderr @@ -1,15 +1,3 @@ -error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_lifetime_param.rs:7:26 - | -LL | fn one<'a>(t: &'a ()) -> Two<'a, 'a> { - | ^^^^^^^^^^^ generic argument `'a` used twice - | -note: for this opaque type - --> $DIR/generic_duplicate_lifetime_param.rs:5:20 - | -LL | type Two<'a, 'b> = impl std::fmt::Debug; - | ^^^^^^^^^^^^^^^^^^^^ - error: non-defining opaque type use in defining scope --> $DIR/generic_duplicate_lifetime_param.rs:9:5 | @@ -22,5 +10,5 @@ note: lifetime used multiple times LL | type Two<'a, 'b> = impl std::fmt::Debug; | ^^ ^^ -error: aborting due to 2 previous errors +error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs index e3c6f4d874bc..9c00407174dd 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.rs @@ -18,20 +18,20 @@ type TwoLifetimes<'a, 'b> = impl Debug; type TwoConsts = impl Debug; +#[define_opaques(TwoTys)] fn one_ty(t: T) -> TwoTys { - //~^ ERROR non-defining opaque type use in defining scope t //~^ ERROR non-defining opaque type use in defining scope } +#[define_opaques(TwoLifetimes)] fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> { - //~^ ERROR non-defining opaque type use in defining scope t //~^ ERROR non-defining opaque type use in defining scope } +#[define_opaques(TwoConsts)] fn one_const(t: *mut [u8; N]) -> TwoConsts { - //~^ ERROR non-defining opaque type use in defining scope t //~^ ERROR non-defining opaque type use in defining scope } diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr index 73570de53266..3e048c8138d0 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr @@ -1,15 +1,3 @@ -error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:21:30 - | -LL | fn one_ty(t: T) -> TwoTys { - | ^^^^^^^^^^^^ generic argument `T` used twice - | -note: for this opaque type - --> $DIR/generic_duplicate_param_use.rs:15:21 - | -LL | type TwoTys = impl Debug; - | ^^^^^^^^^^ - error: non-defining opaque type use in defining scope --> $DIR/generic_duplicate_param_use.rs:23:5 | @@ -22,30 +10,6 @@ note: type used multiple times LL | type TwoTys = impl Debug; | ^ ^ -error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:27:36 - | -LL | fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> { - | ^^^^^^^^^^^^^^^^^^^^ generic argument `'a` used twice - | -note: for this opaque type - --> $DIR/generic_duplicate_param_use.rs:17:29 - | -LL | type TwoLifetimes<'a, 'b> = impl Debug; - | ^^^^^^^^^^ - -error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:33:50 - | -LL | fn one_const(t: *mut [u8; N]) -> TwoConsts { - | ^^^^^^^^^^^^^^^ generic argument `N` used twice - | -note: for this opaque type - --> $DIR/generic_duplicate_param_use.rs:19:50 - | -LL | type TwoConsts = impl Debug; - | ^^^^^^^^^^ - error: non-defining opaque type use in defining scope --> $DIR/generic_duplicate_param_use.rs:29:5 | @@ -70,5 +34,5 @@ note: constant used multiple times LL | type TwoConsts = impl Debug; | ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ -error: aborting due to 6 previous errors +error: aborting due to 3 previous errors diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use10.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use10.rs index 439214911eb9..15fd95d5257d 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use10.rs +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use10.rs @@ -7,6 +7,7 @@ fn main() {} type Two = impl Debug; +#[define_opaques(Two)] fn two(t: T, _: U) -> Two { (t, 4u32) } diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use2.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use2.rs index 201535efe153..d7527f8ffb66 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use2.rs +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use2.rs @@ -7,6 +7,7 @@ fn main() {} // test that unused generic parameters are ok type Two = impl Debug; +#[define_opaques(Two)] fn two(t: T, _: U) -> Two { t //~^ ERROR `T` doesn't implement `Debug` diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use2.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use2.stderr index cd6e85764bda..ef0e73f1481f 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use2.stderr +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use2.stderr @@ -1,5 +1,5 @@ error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use2.rs:11:5 + --> $DIR/generic_duplicate_param_use2.rs:12:5 | LL | t | ^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` @@ -10,7 +10,7 @@ note: required by a bound in an opaque type LL | type Two = impl Debug; | ^^^^^ note: this definition site has more where clauses than the opaque type - --> $DIR/generic_duplicate_param_use2.rs:10:1 + --> $DIR/generic_duplicate_param_use2.rs:11:1 | LL | fn two(t: T, _: U) -> Two { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use3.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use3.rs index 2074f12750f6..ef37ed00fa7a 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use3.rs +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use3.rs @@ -7,10 +7,12 @@ fn main() {} // test that unused generic parameters are ok type Two = impl Debug; +#[define_opaques(Two)] fn two(t: T, _: U) -> Two { t } +#[define_opaques(Two)] fn three(_: T, u: U) -> Two { u //~^ ERROR concrete type differs diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use3.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use3.stderr index 9a10a4980d80..b0a1bd77f857 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use3.stderr +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use3.stderr @@ -1,11 +1,11 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/generic_duplicate_param_use3.rs:15:5 + --> $DIR/generic_duplicate_param_use3.rs:17:5 | LL | u | ^ expected `T`, got `U` | note: previous use here - --> $DIR/generic_duplicate_param_use3.rs:11:5 + --> $DIR/generic_duplicate_param_use3.rs:12:5 | LL | t | ^ diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use4.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use4.rs index d1e5a0f0198b..29ec3e3c3a42 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use4.rs +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use4.rs @@ -7,6 +7,7 @@ fn main() {} // test that unused generic parameters are ok type Two = impl Debug; +#[define_opaques(Two)] fn three(_: T, u: U) -> Two { u //~^ ERROR `U` doesn't implement `Debug` diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use4.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use4.stderr index bf3c4a0e04fe..0932c72ff934 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use4.stderr +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use4.stderr @@ -1,5 +1,5 @@ error[E0277]: `U` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use4.rs:11:5 + --> $DIR/generic_duplicate_param_use4.rs:12:5 | LL | u | ^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` @@ -10,7 +10,7 @@ note: required by a bound in an opaque type LL | type Two = impl Debug; | ^^^^^ note: this definition site has more where clauses than the opaque type - --> $DIR/generic_duplicate_param_use4.rs:10:1 + --> $DIR/generic_duplicate_param_use4.rs:11:1 | LL | fn three(_: T, u: U) -> Two { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use5.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use5.rs index b3d6beaf8486..f0f87bd05ecf 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use5.rs +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use5.rs @@ -7,10 +7,12 @@ fn main() {} // test that unused generic parameters are ok type Two = impl Debug; +#[define_opaques(Two)] fn two(t: T, u: U) -> Two { (t, u) } +#[define_opaques(Two)] fn three(t: T, u: U) -> Two { (u, t) //~^ ERROR concrete type differs diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr index b0027f8fa57b..b8a2a9374161 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use5.stderr @@ -1,11 +1,11 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/generic_duplicate_param_use5.rs:15:5 + --> $DIR/generic_duplicate_param_use5.rs:17:5 | LL | (u, t) | ^^^^^^ expected `(T, U)`, got `(U, T)` | note: previous use here - --> $DIR/generic_duplicate_param_use5.rs:11:5 + --> $DIR/generic_duplicate_param_use5.rs:12:5 | LL | (t, u) | ^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use6.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use6.rs index fa8b2a290b93..304148f14d4e 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use6.rs +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use6.rs @@ -7,10 +7,12 @@ fn main() {} // test that unused generic parameters are ok type Two = impl Debug; +#[define_opaques(Two)] fn two(t: T, u: U) -> Two { (t, t) } +#[define_opaques(Two)] fn three(t: T, u: U) -> Two { (u, t) //~^ ERROR concrete type differs diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr index 09c01932cef7..983e58d3c702 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use6.stderr @@ -1,11 +1,11 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/generic_duplicate_param_use6.rs:15:5 + --> $DIR/generic_duplicate_param_use6.rs:17:5 | LL | (u, t) | ^^^^^^ expected `(T, T)`, got `(U, T)` | note: previous use here - --> $DIR/generic_duplicate_param_use6.rs:11:5 + --> $DIR/generic_duplicate_param_use6.rs:12:5 | LL | (t, t) | ^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use7.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use7.rs index adc912294fdf..bb2c8c1e5430 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use7.rs +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use7.rs @@ -7,18 +7,22 @@ fn main() {} type Two = impl Debug; +#[define_opaques(Two)] fn two(t: T, u: U) -> Two { (t, t) } +#[define_opaques(Two)] fn three(t: T, t2: T, u: U) -> Two { (t, t2) } +#[define_opaques(Two)] fn four(t: T, t2: T, u: U, v: V) -> Two { (t, t2) } +#[define_opaques(Two)] fn five(x: X, y: Y, y2: Y) -> Two { (y, y2) } diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use8.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use8.rs index 76c13bb027b0..427049aa492e 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use8.rs +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use8.rs @@ -6,10 +6,12 @@ fn main() {} type Two = impl Debug; +#[define_opaques(Two)] fn two(t: T, _: U) -> Two { (t, 4u32) } +#[define_opaques(Two)] fn three(_: T, u: U) -> Two { (u, 4u32) //~^ concrete type differs diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr index 09d2abe36636..48c98c1e2b15 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use8.stderr @@ -1,11 +1,11 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/generic_duplicate_param_use8.rs:14:5 + --> $DIR/generic_duplicate_param_use8.rs:16:5 | LL | (u, 4u32) | ^^^^^^^^^ expected `(T, u32)`, got `(U, u32)` | note: previous use here - --> $DIR/generic_duplicate_param_use8.rs:10:5 + --> $DIR/generic_duplicate_param_use8.rs:11:5 | LL | (t, 4u32) | ^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs index 5da7aab0da7a..7654482ef2e9 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs @@ -11,10 +11,12 @@ trait Foo { const BAR: Self::Bar; } +#[define_opaques(Two)] fn two(t: T, u: U) -> Two { (t, u, T::BAR) } +#[define_opaques(Two)] fn three(t: T, u: U) -> Two { (t, u, 42) //~^ ERROR concrete type differs diff --git a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr index 6e1bb3dfa174..542324c949f1 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use9.stderr @@ -1,11 +1,11 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/generic_duplicate_param_use9.rs:19:5 + --> $DIR/generic_duplicate_param_use9.rs:21:5 | LL | (t, u, 42) | ^^^^^^^^^^ expected `(A, B, ::Bar)`, got `(A, B, i32)` | note: previous use here - --> $DIR/generic_duplicate_param_use9.rs:15:5 + --> $DIR/generic_duplicate_param_use9.rs:16:5 | LL | (t, u, T::BAR) | ^^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/generic_lifetime_param.rs b/tests/ui/type-alias-impl-trait/generic_lifetime_param.rs index b9b34f55e7e2..1ac80f88cc42 100644 --- a/tests/ui/type-alias-impl-trait/generic_lifetime_param.rs +++ b/tests/ui/type-alias-impl-trait/generic_lifetime_param.rs @@ -6,6 +6,7 @@ fn main() {} type Region<'a> = impl std::fmt::Debug; +#[define_opaques(Region)] fn region<'b>(a: &'b ()) -> Region<'b> { a } diff --git a/tests/ui/type-alias-impl-trait/generic_nondefining_use.rs b/tests/ui/type-alias-impl-trait/generic_nondefining_use.rs index 68f4c6923ae1..ce6a713d7843 100644 --- a/tests/ui/type-alias-impl-trait/generic_nondefining_use.rs +++ b/tests/ui/type-alias-impl-trait/generic_nondefining_use.rs @@ -12,20 +12,20 @@ type OneConst = impl Debug; // Not defining uses, because they doesn't define *all* possible generics. +#[define_opaques(OneTy)] fn concrete_ty() -> OneTy { - //~^ ERROR: non-defining opaque type use in defining scope 5u32 //~^ ERROR: expected generic type parameter, found `u32` } +#[define_opaques(OneLifetime)] fn concrete_lifetime() -> OneLifetime<'static> { - //~^ ERROR: non-defining opaque type use in defining scope 6u32 //~^ ERROR: expected generic lifetime parameter, found `'static` } +#[define_opaques(OneConst)] fn concrete_const() -> OneConst<{ 123 }> { - //~^ ERROR: non-defining opaque type use in defining scope 7u32 //~^ ERROR: expected generic constant parameter, found `123` } diff --git a/tests/ui/type-alias-impl-trait/generic_nondefining_use.stderr b/tests/ui/type-alias-impl-trait/generic_nondefining_use.stderr index bd68b4e3ea46..1b0ce7cc619f 100644 --- a/tests/ui/type-alias-impl-trait/generic_nondefining_use.stderr +++ b/tests/ui/type-alias-impl-trait/generic_nondefining_use.stderr @@ -1,15 +1,3 @@ -error[E0792]: non-defining opaque type use in defining scope - --> $DIR/generic_nondefining_use.rs:15:21 - | -LL | fn concrete_ty() -> OneTy { - | ^^^^^^^^^^ argument `u32` is not a generic parameter - | -note: for this opaque type - --> $DIR/generic_nondefining_use.rs:7:17 - | -LL | type OneTy = impl Debug; - | ^^^^^^^^^^ - error[E0792]: expected generic type parameter, found `u32` --> $DIR/generic_nondefining_use.rs:17:5 | @@ -19,30 +7,6 @@ LL | type OneTy = impl Debug; LL | 5u32 | ^^^^ -error[E0792]: non-defining opaque type use in defining scope - --> $DIR/generic_nondefining_use.rs:21:27 - | -LL | fn concrete_lifetime() -> OneLifetime<'static> { - | ^^^^^^^^^^^^^^^^^^^^ argument `'static` is not a generic parameter - | -note: for this opaque type - --> $DIR/generic_nondefining_use.rs:9:24 - | -LL | type OneLifetime<'a> = impl Debug; - | ^^^^^^^^^^ - -error[E0792]: non-defining opaque type use in defining scope - --> $DIR/generic_nondefining_use.rs:27:24 - | -LL | fn concrete_const() -> OneConst<{ 123 }> { - | ^^^^^^^^^^^^^^^^^ argument `123` is not a generic parameter - | -note: for this opaque type - --> $DIR/generic_nondefining_use.rs:11:33 - | -LL | type OneConst = impl Debug; - | ^^^^^^^^^^ - error[E0792]: expected generic lifetime parameter, found `'static` --> $DIR/generic_nondefining_use.rs:23:5 | @@ -61,6 +25,6 @@ LL | type OneConst = impl Debug; LL | 7u32 | ^^^^ -error: aborting due to 6 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0792`. diff --git a/tests/ui/type-alias-impl-trait/generic_not_used.rs b/tests/ui/type-alias-impl-trait/generic_not_used.rs index c70f473cff57..5e5b470d679e 100644 --- a/tests/ui/type-alias-impl-trait/generic_not_used.rs +++ b/tests/ui/type-alias-impl-trait/generic_not_used.rs @@ -5,6 +5,7 @@ fn main() {} type WrongGeneric = impl 'static; //~^ ERROR: at least one trait must be specified +#[define_opaques(WrongGeneric)] fn wrong_generic(_: U, v: V) -> WrongGeneric { v //~^ ERROR type parameter `V` is part of concrete type but not used in parameter list diff --git a/tests/ui/type-alias-impl-trait/generic_not_used.stderr b/tests/ui/type-alias-impl-trait/generic_not_used.stderr index fd720239a523..5fe2fefcecfd 100644 --- a/tests/ui/type-alias-impl-trait/generic_not_used.stderr +++ b/tests/ui/type-alias-impl-trait/generic_not_used.stderr @@ -5,7 +5,7 @@ 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:9:5 + --> $DIR/generic_not_used.rs:10:5 | LL | v | ^ diff --git a/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs b/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs index c60f5c11cd18..0db25350a63b 100644 --- a/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs +++ b/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs @@ -9,6 +9,7 @@ fn main() { type WrongGeneric = impl 'static; //~^ ERROR: at least one trait must be specified + #[define_opaques(WrongGeneric)] fn wrong_generic(t: T) -> WrongGeneric { t //~^ ERROR the parameter type `T` may not live long enough diff --git a/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr b/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr index c352a33fbbcf..2b3f7d750283 100644 --- a/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr +++ b/tests/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr @@ -14,7 +14,7 @@ LL | type WrongGeneric = impl 'static; | - this generic parameter must be used with a generic type parameter error[E0310]: the parameter type `T` may not live long enough - --> $DIR/generic_type_does_not_live_long_enough.rs:13:9 + --> $DIR/generic_type_does_not_live_long_enough.rs:14:9 | LL | t | ^ diff --git a/tests/ui/type-alias-impl-trait/generic_underconstrained.rs b/tests/ui/type-alias-impl-trait/generic_underconstrained.rs index 1acacc778de6..82bff064fcf9 100644 --- a/tests/ui/type-alias-impl-trait/generic_underconstrained.rs +++ b/tests/ui/type-alias-impl-trait/generic_underconstrained.rs @@ -6,6 +6,7 @@ trait Trait {} type Underconstrained = impl Send; // no `Trait` bound +#[define_opaques(Underconstrained)] fn underconstrain(_: T) -> Underconstrained { //~^ ERROR the trait bound `T: Trait` //~| ERROR the trait bound `T: Trait` diff --git a/tests/ui/type-alias-impl-trait/generic_underconstrained.stderr b/tests/ui/type-alias-impl-trait/generic_underconstrained.stderr index c24f8fd867fb..b1bc62c5910e 100644 --- a/tests/ui/type-alias-impl-trait/generic_underconstrained.stderr +++ b/tests/ui/type-alias-impl-trait/generic_underconstrained.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `T: Trait` is not satisfied - --> $DIR/generic_underconstrained.rs:9:31 + --> $DIR/generic_underconstrained.rs:10:31 | LL | fn underconstrain(_: T) -> Underconstrained { | ^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` @@ -15,7 +15,7 @@ LL | fn underconstrain(_: T) -> Underconstrained { | +++++++ error[E0277]: the trait bound `T: Trait` is not satisfied - --> $DIR/generic_underconstrained.rs:9:31 + --> $DIR/generic_underconstrained.rs:10:31 | LL | fn underconstrain(_: T) -> Underconstrained { | ^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` diff --git a/tests/ui/type-alias-impl-trait/generic_underconstrained2.rs b/tests/ui/type-alias-impl-trait/generic_underconstrained2.rs index 1e1bece9a1c0..b9da8e7c159e 100644 --- a/tests/ui/type-alias-impl-trait/generic_underconstrained2.rs +++ b/tests/ui/type-alias-impl-trait/generic_underconstrained2.rs @@ -5,6 +5,7 @@ fn main() {} type Underconstrained = impl Send; // not a defining use, because it doesn't define *all* possible generics +#[define_opaques(Underconstrained)] fn underconstrained(_: U) -> Underconstrained { //~^ ERROR `U` doesn't implement `Debug` //~| ERROR `U` doesn't implement `Debug` @@ -14,6 +15,7 @@ fn underconstrained(_: U) -> Underconstrained { type Underconstrained2 = impl Send; // not a defining use, because it doesn't define *all* possible generics +#[define_opaques(Underconstrained2)] fn underconstrained2(_: U, _: V) -> Underconstrained2 { //~^ ERROR `V` doesn't implement `Debug` //~| ERROR `V` doesn't implement `Debug` diff --git a/tests/ui/type-alias-impl-trait/generic_underconstrained2.stderr b/tests/ui/type-alias-impl-trait/generic_underconstrained2.stderr index 93df5ddca796..429c3b9175a5 100644 --- a/tests/ui/type-alias-impl-trait/generic_underconstrained2.stderr +++ b/tests/ui/type-alias-impl-trait/generic_underconstrained2.stderr @@ -1,5 +1,5 @@ error[E0277]: `U` doesn't implement `Debug` - --> $DIR/generic_underconstrained2.rs:8:33 + --> $DIR/generic_underconstrained2.rs:9:33 | LL | fn underconstrained(_: U) -> Underconstrained { | ^^^^^^^^^^^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` @@ -15,13 +15,13 @@ LL | fn underconstrained(_: U) -> Underconstrained { | +++++++++++++++++ error[E0277]: `V` doesn't implement `Debug` - --> $DIR/generic_underconstrained2.rs:17:43 + --> $DIR/generic_underconstrained2.rs:19:43 | LL | fn underconstrained2(_: U, _: V) -> Underconstrained2 { | ^^^^^^^^^^^^^^^^^^^^ `V` cannot be formatted using `{:?}` because it doesn't implement `Debug` | note: required by a bound on the type alias `Underconstrained2` - --> $DIR/generic_underconstrained2.rs:14:27 + --> $DIR/generic_underconstrained2.rs:15:27 | LL | type Underconstrained2 = impl Send; | ^^^^^^^^^^^^^^^ required by this bound @@ -31,7 +31,7 @@ LL | fn underconstrained2(_: U, _: V) -> Underconstrained | +++++++++++++++++ error[E0277]: `U` doesn't implement `Debug` - --> $DIR/generic_underconstrained2.rs:8:33 + --> $DIR/generic_underconstrained2.rs:9:33 | LL | fn underconstrained(_: U) -> Underconstrained { | ^^^^^^^^^^^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` @@ -48,13 +48,13 @@ LL | fn underconstrained(_: U) -> Underconstrained { | +++++++++++++++++ error[E0277]: `V` doesn't implement `Debug` - --> $DIR/generic_underconstrained2.rs:17:43 + --> $DIR/generic_underconstrained2.rs:19:43 | LL | fn underconstrained2(_: U, _: V) -> Underconstrained2 { | ^^^^^^^^^^^^^^^^^^^^ `V` cannot be formatted using `{:?}` because it doesn't implement `Debug` | note: required by a bound on the type alias `Underconstrained2` - --> $DIR/generic_underconstrained2.rs:14:27 + --> $DIR/generic_underconstrained2.rs:15:27 | LL | type Underconstrained2 = impl Send; | ^^^^^^^^^^^^^^^ required by this bound diff --git a/tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.rs b/tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.rs index eb19b49c7e21..bf97dd9a25c5 100644 --- a/tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.rs +++ b/tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.rs @@ -15,6 +15,7 @@ trait Trait: Sized { impl Trait for Bar { type Assoc = impl std::fmt::Debug; + //~^ ERROR: unconstrained opaque type fn foo() -> Foo { Foo { field: () } //~^ ERROR: mismatched types diff --git a/tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.stderr b/tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.stderr index 00aedfae4637..1174b2e32191 100644 --- a/tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.stderr +++ b/tests/ui/type-alias-impl-trait/hidden_behind_projection_behind_struct_field.stderr @@ -1,20 +1,28 @@ +error: unconstrained opaque type + --> $DIR/hidden_behind_projection_behind_struct_field.rs:17:18 + | +LL | type Assoc = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `Assoc` must be used in combination with a concrete type within the same impl + error[E0308]: mismatched types - --> $DIR/hidden_behind_projection_behind_struct_field.rs:19:22 + --> $DIR/hidden_behind_projection_behind_struct_field.rs:20:22 | LL | type Assoc = impl std::fmt::Debug; | -------------------- the expected opaque type -LL | fn foo() -> Foo { +... LL | Foo { field: () } | ^^ expected opaque type, found `()` | = note: expected opaque type `::Assoc` found unit type `()` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/hidden_behind_projection_behind_struct_field.rs:18:8 +note: this item must have a `#[define_opaques(::Assoc)]` attribute to be able to define hidden types + --> $DIR/hidden_behind_projection_behind_struct_field.rs:19:8 | LL | fn foo() -> Foo { | ^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.rs b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.rs index 3117060cef0d..b1dcf98f4dd2 100644 --- a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.rs +++ b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.rs @@ -13,6 +13,7 @@ trait Trait: Sized { impl Trait for Bar { type Assoc = impl std::fmt::Debug; + //~^ ERROR: unconstrained opaque type fn foo() -> Foo { Foo { field: () } //~^ ERROR: mismatched types diff --git a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.stderr b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.stderr index 4910e794e8d6..037721305b71 100644 --- a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.stderr +++ b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field2.stderr @@ -1,20 +1,28 @@ +error: unconstrained opaque type + --> $DIR/hidden_behind_struct_field2.rs:15:18 + | +LL | type Assoc = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `Assoc` must be used in combination with a concrete type within the same impl + error[E0308]: mismatched types - --> $DIR/hidden_behind_struct_field2.rs:17:22 + --> $DIR/hidden_behind_struct_field2.rs:18:22 | LL | type Assoc = impl std::fmt::Debug; | -------------------- the expected opaque type -LL | fn foo() -> Foo { +... LL | Foo { field: () } | ^^ expected opaque type, found `()` | = note: expected opaque type `::Assoc` found unit type `()` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/hidden_behind_struct_field2.rs:16:8 +note: this item must have a `#[define_opaques(::Assoc)]` attribute to be able to define hidden types + --> $DIR/hidden_behind_struct_field2.rs:17:8 | LL | fn foo() -> Foo { | ^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.rs b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.rs index c1f135994121..70697e2fa658 100644 --- a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.rs +++ b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.rs @@ -14,6 +14,7 @@ trait Trait: Sized { impl Trait for Bar { type Assoc2 = impl std::fmt::Debug; + //~^ ERROR: unconstrained opaque type type Assoc = impl Iterator; fn foo() -> Self::Assoc { vec![Foo { field: () }].into_iter() diff --git a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.stderr b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.stderr index f10ccc002997..9ed994877d82 100644 --- a/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.stderr +++ b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.stderr @@ -1,5 +1,13 @@ +error: unconstrained opaque type + --> $DIR/hidden_behind_struct_field3.rs:16:19 + | +LL | type Assoc2 = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `Assoc2` must be used in combination with a concrete type within the same impl + error[E0308]: mismatched types - --> $DIR/hidden_behind_struct_field3.rs:19:27 + --> $DIR/hidden_behind_struct_field3.rs:20:27 | LL | type Assoc2 = impl std::fmt::Debug; | -------------------- the expected opaque type @@ -9,12 +17,12 @@ LL | vec![Foo { field: () }].into_iter() | = note: expected opaque type `::Assoc2` found unit type `()` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/hidden_behind_struct_field3.rs:18:8 +note: this item must have a `#[define_opaques(::Assoc2)]` attribute to be able to define hidden types + --> $DIR/hidden_behind_struct_field3.rs:19:8 | LL | fn foo() -> Self::Assoc { | ^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/hidden_type_mismatch.rs b/tests/ui/type-alias-impl-trait/hidden_type_mismatch.rs index 5b5acb31812f..d711f35a14dc 100644 --- a/tests/ui/type-alias-impl-trait/hidden_type_mismatch.rs +++ b/tests/ui/type-alias-impl-trait/hidden_type_mismatch.rs @@ -9,6 +9,7 @@ mod sus { use super::*; pub type Sep = impl Sized + std::fmt::Display; + #[define_opaques(Sep)] pub fn mk_sep() -> Sep { String::from("hello") } @@ -34,6 +35,7 @@ mod sus { // `define_tait` is not actually callable, and thus assumed // `Bar<()>: Copy` even though it isn't. pub type Tait = impl Copy + From> + Into>; + #[define_opaques(Tait)] pub fn define_tait() -> Tait where // this proves `Bar<()>: Copy`, but `define_tait` is diff --git a/tests/ui/type-alias-impl-trait/hidden_type_mismatch.stderr b/tests/ui/type-alias-impl-trait/hidden_type_mismatch.stderr index 8547fd53c18e..20991a30b531 100644 --- a/tests/ui/type-alias-impl-trait/hidden_type_mismatch.stderr +++ b/tests/ui/type-alias-impl-trait/hidden_type_mismatch.stderr @@ -1,5 +1,5 @@ error[E0271]: type mismatch resolving `<() as Proj>::Assoc == i32` - --> $DIR/hidden_type_mismatch.rs:43:9 + --> $DIR/hidden_type_mismatch.rs:45:9 | LL | pub type Sep = impl Sized + std::fmt::Display; | ------------------------------ the found opaque type @@ -8,26 +8,26 @@ LL | Bar { inner: 1i32, _marker: () } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<() as Proj>::Assoc == i32` | note: expected this to be `i32` - --> $DIR/hidden_type_mismatch.rs:20:22 + --> $DIR/hidden_type_mismatch.rs:21:22 | LL | type Assoc = sus::Sep; | ^^^^^^^^ = note: expected type `i32` found opaque type `Sep` note: required for `Bar<()>` to implement `Copy` - --> $DIR/hidden_type_mismatch.rs:32:39 + --> $DIR/hidden_type_mismatch.rs:33:39 | LL | impl + Copy> Copy for Bar {} | ----------- ^^^^ ^^^^^^ | | | unsatisfied trait bound introduced here note: required by a bound in an opaque type - --> $DIR/hidden_type_mismatch.rs:36:26 + --> $DIR/hidden_type_mismatch.rs:37:26 | LL | pub type Tait = impl Copy + From> + Into>; | ^^^^ note: this definition site has more where clauses than the opaque type - --> $DIR/hidden_type_mismatch.rs:37:5 + --> $DIR/hidden_type_mismatch.rs:39:5 | LL | / pub fn define_tait() -> Tait LL | | where diff --git a/tests/ui/type-alias-impl-trait/higher_kinded_params.rs b/tests/ui/type-alias-impl-trait/higher_kinded_params.rs index e43f53e40578..90e8ae2d8bd6 100644 --- a/tests/ui/type-alias-impl-trait/higher_kinded_params.rs +++ b/tests/ui/type-alias-impl-trait/higher_kinded_params.rs @@ -22,6 +22,7 @@ struct Terminator; type Successors<'a> = impl std::fmt::Debug + 'a; impl Terminator { + #[define_opaques(Successors)] fn successors(&self, _: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> {} } diff --git a/tests/ui/type-alias-impl-trait/higher_kinded_params2.rs b/tests/ui/type-alias-impl-trait/higher_kinded_params2.rs index 19c6099135d8..d40f59de12ec 100644 --- a/tests/ui/type-alias-impl-trait/higher_kinded_params2.rs +++ b/tests/ui/type-alias-impl-trait/higher_kinded_params2.rs @@ -16,12 +16,14 @@ impl<'a> B for &'a A { } type Tait = impl std::fmt::Debug; +//~^ ERROR: unconstrained opaque type struct Terminator; type Successors<'a> = impl std::fmt::Debug + 'a; impl Terminator { + #[define_opaques(Successors)] fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> { f = g; //~^ ERROR mismatched types diff --git a/tests/ui/type-alias-impl-trait/higher_kinded_params2.stderr b/tests/ui/type-alias-impl-trait/higher_kinded_params2.stderr index 790e7fe85803..0d9d647c8fb9 100644 --- a/tests/ui/type-alias-impl-trait/higher_kinded_params2.stderr +++ b/tests/ui/type-alias-impl-trait/higher_kinded_params2.stderr @@ -1,5 +1,13 @@ +error: unconstrained opaque type + --> $DIR/higher_kinded_params2.rs:18:13 + | +LL | type Tait = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `Tait` must be used in combination with a concrete type within the same crate + error[E0308]: mismatched types - --> $DIR/higher_kinded_params2.rs:26:13 + --> $DIR/higher_kinded_params2.rs:28:13 | LL | type Tait = impl std::fmt::Debug; | -------------------- the expected opaque type @@ -9,12 +17,12 @@ LL | f = g; | = note: expected fn pointer `for<'x> fn(&'x ()) -> Tait` found fn item `for<'a> fn(&'a ()) -> String {g}` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/higher_kinded_params2.rs:25:8 +note: this item must have a `#[define_opaques(Tait)]` attribute to be able to define hidden types + --> $DIR/higher_kinded_params2.rs:27:8 | LL | fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> { | ^^^^^^^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/higher_kinded_params3.rs b/tests/ui/type-alias-impl-trait/higher_kinded_params3.rs index 3845cde29fa5..c32de820a122 100644 --- a/tests/ui/type-alias-impl-trait/higher_kinded_params3.rs +++ b/tests/ui/type-alias-impl-trait/higher_kinded_params3.rs @@ -22,6 +22,7 @@ struct Terminator; type Successors<'a> = impl std::fmt::Debug + 'a; impl Terminator { + #[define_opaques(Successors, Tait)] fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> { f = g; //~^ ERROR mismatched types diff --git a/tests/ui/type-alias-impl-trait/higher_kinded_params3.stderr b/tests/ui/type-alias-impl-trait/higher_kinded_params3.stderr index 41a3f9ce2682..558792987f31 100644 --- a/tests/ui/type-alias-impl-trait/higher_kinded_params3.stderr +++ b/tests/ui/type-alias-impl-trait/higher_kinded_params3.stderr @@ -1,19 +1,14 @@ error[E0308]: mismatched types - --> $DIR/higher_kinded_params3.rs:26:13 + --> $DIR/higher_kinded_params3.rs:27:9 | LL | type Tait<'a> = impl std::fmt::Debug + 'a; | ------------------------- the expected opaque type ... LL | f = g; - | ^ expected fn pointer, found fn item + | ^^^^^ one type is more general than the other | = note: expected fn pointer `for<'x> fn(&'x ()) -> Tait<'x>` - found fn item `for<'a> fn(&'a ()) -> &'a () {g}` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/higher_kinded_params3.rs:25:8 - | -LL | fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> { - | ^^^^^^^^^^ + found fn pointer `for<'a> fn(&'a ()) -> &'a ()` error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/hkl_forbidden.rs b/tests/ui/type-alias-impl-trait/hkl_forbidden.rs index c6d1202ef85f..39c887879b13 100644 --- a/tests/ui/type-alias-impl-trait/hkl_forbidden.rs +++ b/tests/ui/type-alias-impl-trait/hkl_forbidden.rs @@ -6,6 +6,7 @@ fn id(s: &str) -> &str { type Opaque<'a> = impl Sized + 'a; +#[define_opaques(Opaque)] fn test(s: &str) -> (impl Fn(&str) -> Opaque<'_>, impl Fn(&str) -> Opaque<'_>) { (id, id) //~ ERROR expected generic lifetime parameter, found `'_` } @@ -16,22 +17,26 @@ fn id2<'a, 'b>(s: (&'a str, &'b str)) -> (&'a str, &'b str) { type Opaque2<'a> = impl Sized + 'a; +#[define_opaques(Opaque2)] fn test2() -> impl for<'a, 'b> Fn((&'a str, &'b str)) -> (Opaque2<'a>, Opaque2<'b>) { id2 //~ ERROR expected generic lifetime parameter, found `'a` } type Opaque3<'a> = impl Sized + 'a; +#[define_opaques(Opaque3)] fn test3(s: &str) -> (impl Fn(&str) -> Opaque3<'_>, Opaque3<'_>) { (id, s) //~ ERROR expected generic lifetime parameter, found `'_` } type Opaque4<'a> = impl Sized + 'a; +#[define_opaques(Opaque4)] fn test4(s: &str) -> (Opaque4<'_>, impl Fn(&str) -> Opaque4<'_>) { (s, id) //~ ERROR expected generic lifetime parameter, found `'_` } type Inner<'a> = impl Sized; +#[define_opaques(Inner)] fn outer_impl() -> impl for<'a> Fn(&'a ()) -> Inner<'a> { |x| x //~ ERROR expected generic lifetime parameter, found `'a` } diff --git a/tests/ui/type-alias-impl-trait/hkl_forbidden.stderr b/tests/ui/type-alias-impl-trait/hkl_forbidden.stderr index d49be73d94e7..d404d60f31ed 100644 --- a/tests/ui/type-alias-impl-trait/hkl_forbidden.stderr +++ b/tests/ui/type-alias-impl-trait/hkl_forbidden.stderr @@ -1,5 +1,5 @@ error[E0792]: expected generic lifetime parameter, found `'_` - --> $DIR/hkl_forbidden.rs:10:5 + --> $DIR/hkl_forbidden.rs:11:5 | LL | type Opaque<'a> = impl Sized + 'a; | -- this generic parameter must be used with a generic lifetime parameter @@ -8,7 +8,7 @@ LL | (id, id) | ^^^^^^^^ error[E0792]: expected generic lifetime parameter, found `'a` - --> $DIR/hkl_forbidden.rs:20:5 + --> $DIR/hkl_forbidden.rs:22:5 | LL | type Opaque2<'a> = impl Sized + 'a; | -- this generic parameter must be used with a generic lifetime parameter @@ -17,7 +17,7 @@ LL | id2 | ^^^ error[E0792]: expected generic lifetime parameter, found `'_` - --> $DIR/hkl_forbidden.rs:26:5 + --> $DIR/hkl_forbidden.rs:29:5 | LL | type Opaque3<'a> = impl Sized + 'a; | -- this generic parameter must be used with a generic lifetime parameter @@ -26,20 +26,20 @@ LL | (id, s) | ^^^^^^^ error[E0792]: expected generic lifetime parameter, found `'_` - --> $DIR/hkl_forbidden.rs:31:5 + --> $DIR/hkl_forbidden.rs:35:5 | LL | type Opaque4<'a> = impl Sized + 'a; | -- this generic parameter must be used with a generic lifetime parameter -LL | fn test4(s: &str) -> (Opaque4<'_>, impl Fn(&str) -> Opaque4<'_>) { +... LL | (s, id) | ^^^^^^^ error[E0792]: expected generic lifetime parameter, found `'a` - --> $DIR/hkl_forbidden.rs:36:5 + --> $DIR/hkl_forbidden.rs:41:5 | LL | type Inner<'a> = impl Sized; | -- this generic parameter must be used with a generic lifetime parameter -LL | fn outer_impl() -> impl for<'a> Fn(&'a ()) -> Inner<'a> { +... LL | |x| x | ^^^^^ diff --git a/tests/ui/type-alias-impl-trait/hkl_forbidden2.rs b/tests/ui/type-alias-impl-trait/hkl_forbidden2.rs index 3d583d4413d9..f1c8ed7d66cf 100644 --- a/tests/ui/type-alias-impl-trait/hkl_forbidden2.rs +++ b/tests/ui/type-alias-impl-trait/hkl_forbidden2.rs @@ -10,6 +10,7 @@ impl<'a> Trait<'a> for () { type Assoc = (); } +#[define_opaques(Opaque)] fn test() -> &'static dyn for<'a> Trait<'a, Assoc = Opaque<'a>> { &() //~^ ERROR: expected generic lifetime parameter, found `'a` diff --git a/tests/ui/type-alias-impl-trait/hkl_forbidden2.stderr b/tests/ui/type-alias-impl-trait/hkl_forbidden2.stderr index 0a9a9d6bcf4e..7404c844ae7b 100644 --- a/tests/ui/type-alias-impl-trait/hkl_forbidden2.stderr +++ b/tests/ui/type-alias-impl-trait/hkl_forbidden2.stderr @@ -1,5 +1,5 @@ error[E0792]: expected generic lifetime parameter, found `'a` - --> $DIR/hkl_forbidden2.rs:14:5 + --> $DIR/hkl_forbidden2.rs:15:5 | LL | type Opaque<'a> = impl Sized + 'a; | -- this generic parameter must be used with a generic lifetime parameter diff --git a/tests/ui/type-alias-impl-trait/hkl_forbidden3.rs b/tests/ui/type-alias-impl-trait/hkl_forbidden3.rs index a4148599f77a..c7239051eed9 100644 --- a/tests/ui/type-alias-impl-trait/hkl_forbidden3.rs +++ b/tests/ui/type-alias-impl-trait/hkl_forbidden3.rs @@ -6,6 +6,7 @@ fn foo<'a>(x: &'a ()) -> &'a () { x } +#[define_opaques(Opaque)] fn test() -> for<'a> fn(&'a ()) -> Opaque<'a> { foo //~ ERROR: mismatched types } diff --git a/tests/ui/type-alias-impl-trait/hkl_forbidden3.stderr b/tests/ui/type-alias-impl-trait/hkl_forbidden3.stderr index d262177a86bc..b8c04185a7d1 100644 --- a/tests/ui/type-alias-impl-trait/hkl_forbidden3.stderr +++ b/tests/ui/type-alias-impl-trait/hkl_forbidden3.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/hkl_forbidden3.rs:10:5 + --> $DIR/hkl_forbidden3.rs:11:5 | LL | type Opaque<'a> = impl Sized + 'a; | --------------- the expected opaque type diff --git a/tests/ui/type-alias-impl-trait/hkl_forbidden4.rs b/tests/ui/type-alias-impl-trait/hkl_forbidden4.rs index fd06ea677c33..025351f99d0a 100644 --- a/tests/ui/type-alias-impl-trait/hkl_forbidden4.rs +++ b/tests/ui/type-alias-impl-trait/hkl_forbidden4.rs @@ -15,6 +15,7 @@ async fn operation(_: &mut ()) -> () { //~^ ERROR: expected generic lifetime parameter, found `'any` } +#[define_opaques(FutNothing)] async fn call(_f: F) //~^ ERROR item does not constrain where diff --git a/tests/ui/type-alias-impl-trait/hkl_forbidden4.stderr b/tests/ui/type-alias-impl-trait/hkl_forbidden4.stderr index feb161c3b048..db836b2a31b3 100644 --- a/tests/ui/type-alias-impl-trait/hkl_forbidden4.stderr +++ b/tests/ui/type-alias-impl-trait/hkl_forbidden4.stderr @@ -1,17 +1,5 @@ -error: concrete type differs from previous defining opaque type use - --> $DIR/hkl_forbidden4.rs:12:1 - | -LL | async fn operation(_: &mut ()) -> () { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `FutNothing<'_>`, got `{async fn body of operation()}` - | -note: previous use here - --> $DIR/hkl_forbidden4.rs:14:5 - | -LL | call(operation).await - | ^^^^^^^^^^^^^^^ - error: item does not constrain `FutNothing::{opaque#0}`, but has it in its signature - --> $DIR/hkl_forbidden4.rs:18:10 + --> $DIR/hkl_forbidden4.rs:19:10 | LL | async fn call(_f: F) | ^^^^ @@ -24,7 +12,7 @@ LL | type FutNothing<'a> = impl 'a + Future; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: item does not constrain `FutNothing::{opaque#0}`, but has it in its signature - --> $DIR/hkl_forbidden4.rs:22:1 + --> $DIR/hkl_forbidden4.rs:23:1 | LL | / { ... | @@ -38,6 +26,18 @@ note: this opaque type is in the signature LL | type FutNothing<'a> = impl 'a + Future; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +error: concrete type differs from previous defining opaque type use + --> $DIR/hkl_forbidden4.rs:12:1 + | +LL | async fn operation(_: &mut ()) -> () { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `FutNothing<'_>`, got `{async fn body of operation()}` + | +note: previous use here + --> $DIR/hkl_forbidden4.rs:14:5 + | +LL | call(operation).await + | ^^^^^^^^^^^^^^^ + error[E0792]: expected generic lifetime parameter, found `'any` --> $DIR/hkl_forbidden4.rs:14:5 | @@ -48,7 +48,7 @@ LL | call(operation).await | ^^^^^^^^^^^^^^^ error[E0792]: expected generic lifetime parameter, found `'any` - --> $DIR/hkl_forbidden4.rs:22:1 + --> $DIR/hkl_forbidden4.rs:23:1 | LL | type FutNothing<'a> = impl 'a + Future; | -- this generic parameter must be used with a generic lifetime parameter diff --git a/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.rs b/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.rs index 2bcb8f06f4fd..0ad52f4a48b7 100644 --- a/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.rs +++ b/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.rs @@ -18,6 +18,7 @@ trait MyFrom: Sized { trait F {} impl F for () {} type DummyT = impl F; +#[define_opaques(DummyT)] fn _dummy_t() -> DummyT {} struct Phantom1(PhantomData); @@ -25,6 +26,7 @@ struct Phantom2(PhantomData); struct Scope(Phantom2>); impl Scope { + #[define_opaques(DummyT)] fn new() -> Self { //~^ ERROR item does not constrain unimplemented!() @@ -41,6 +43,7 @@ impl MyFrom> for Phantom1 { impl>>, U> MyIndex> for Scope { //~^ ERROR the type parameter `T` is not constrained by the impl type O = T; + #[define_opaques(DummyT)] fn my_index(self) -> Self::O { MyFrom::my_from(self.0).ok().unwrap() } diff --git a/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.stderr b/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.stderr index 0ab4c34381a2..7c9c0cc808e4 100644 --- a/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.stderr +++ b/tests/ui/type-alias-impl-trait/ice-failed-to-resolve-instance-for-110696.stderr @@ -1,11 +1,11 @@ error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates - --> $DIR/ice-failed-to-resolve-instance-for-110696.rs:41:6 + --> $DIR/ice-failed-to-resolve-instance-for-110696.rs:43:6 | LL | impl>>, U> MyIndex> for Scope { | ^ unconstrained type parameter error: item does not constrain `DummyT::{opaque#0}`, but has it in its signature - --> $DIR/ice-failed-to-resolve-instance-for-110696.rs:28:8 + --> $DIR/ice-failed-to-resolve-instance-for-110696.rs:30:8 | LL | fn new() -> Self { | ^^^ diff --git a/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.rs b/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.rs index 71416eb531ac..a9cae611ec55 100644 --- a/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.rs +++ b/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.rs @@ -18,6 +18,7 @@ impl Foo for () { type Baz = impl Sized; //~^ ERROR type `Baz` has 1 type parameter but its trait declaration has 0 type parameters + //~| ERROR: unconstrained opaque type fn test<'a>() -> Self::Bar<'a> { &() diff --git a/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.stderr b/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.stderr index e5a21ff8b4e8..13f5d8b8ea6e 100644 --- a/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.stderr +++ b/tests/ui/type-alias-impl-trait/impl-trait-in-type-alias-with-bad-substs.stderr @@ -7,6 +7,14 @@ LL | type Baz<'a>; LL | type Baz = impl Sized; | ^ found 1 type parameter -error: aborting due to 1 previous error +error: unconstrained opaque type + --> $DIR/impl-trait-in-type-alias-with-bad-substs.rs:19:19 + | +LL | type Baz = impl Sized; + | ^^^^^^^^^^ + | + = note: `Baz` must be used in combination with a concrete type within the same impl + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0049`. diff --git a/tests/ui/type-alias-impl-trait/impl_for_weak_alias.rs b/tests/ui/type-alias-impl-trait/impl_for_weak_alias.rs index 00d1a1a226d2..cee3af0d98e6 100644 --- a/tests/ui/type-alias-impl-trait/impl_for_weak_alias.rs +++ b/tests/ui/type-alias-impl-trait/impl_for_weak_alias.rs @@ -7,6 +7,7 @@ auto trait Trait {} impl Trait for Alias {} //~^ ERROR traits with a default impl, like `Trait`, cannot be implemented for type alias `Alias` +#[define_opaques(Alias)] fn _def() -> Alias { (42, 42) } diff --git a/tests/ui/type-alias-impl-trait/impl_trait_for_generic_tait.rs b/tests/ui/type-alias-impl-trait/impl_trait_for_generic_tait.rs index 91610c92d227..96e4729aaa09 100644 --- a/tests/ui/type-alias-impl-trait/impl_trait_for_generic_tait.rs +++ b/tests/ui/type-alias-impl-trait/impl_trait_for_generic_tait.rs @@ -9,6 +9,7 @@ impl Foo for i32 { type Assoc = u32; } type ImplTrait = impl Sized; +#[define_opaques(ImplTrait)] fn constrain() -> ImplTrait { 1u64 } diff --git a/tests/ui/type-alias-impl-trait/impl_trait_for_same_tait.rs b/tests/ui/type-alias-impl-trait/impl_trait_for_same_tait.rs index 3f1a9d12b44f..8fa7b3b3c2a6 100644 --- a/tests/ui/type-alias-impl-trait/impl_trait_for_same_tait.rs +++ b/tests/ui/type-alias-impl-trait/impl_trait_for_same_tait.rs @@ -5,6 +5,7 @@ impl Foo for () {} impl Foo for i32 {} type Bar = impl std::fmt::Debug; +#[define_opaques(Bar)] fn defining_use() -> Bar { 42 } @@ -18,6 +19,7 @@ impl Bop for Bar {} //~^ ERROR conflicting implementations type Barr = impl std::fmt::Debug; +#[define_opaques(Barr)] fn defining_use2() -> Barr { 42 } diff --git a/tests/ui/type-alias-impl-trait/impl_trait_for_same_tait.stderr b/tests/ui/type-alias-impl-trait/impl_trait_for_same_tait.stderr index aaf75cc3db97..2f44ee481adc 100644 --- a/tests/ui/type-alias-impl-trait/impl_trait_for_same_tait.stderr +++ b/tests/ui/type-alias-impl-trait/impl_trait_for_same_tait.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Bop` for type `Bar<()>` - --> $DIR/impl_trait_for_same_tait.rs:17:1 + --> $DIR/impl_trait_for_same_tait.rs:18:1 | LL | impl Bop for Bar<()> {} | -------------------- first implementation here @@ -8,7 +8,7 @@ LL | impl Bop for Bar {} | ^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Bar<()>` error[E0119]: conflicting implementations of trait `Bop` for type `Bar<()>` - --> $DIR/impl_trait_for_same_tait.rs:26:1 + --> $DIR/impl_trait_for_same_tait.rs:28:1 | LL | impl Bop for Bar<()> {} | -------------------- first implementation here @@ -17,7 +17,7 @@ LL | impl Bop for Barr {} | ^^^^^^^^^^^^^^^^^ conflicting implementation for `Bar<()>` error[E0119]: conflicting implementations of trait `Bop` for type `Bar<()>` - --> $DIR/impl_trait_for_same_tait.rs:30:1 + --> $DIR/impl_trait_for_same_tait.rs:32:1 | LL | impl Bop for Bar<()> {} | -------------------- first implementation here diff --git a/tests/ui/type-alias-impl-trait/impl_trait_for_tait.rs b/tests/ui/type-alias-impl-trait/impl_trait_for_tait.rs index bce5ba7c91c3..3cf20395848f 100644 --- a/tests/ui/type-alias-impl-trait/impl_trait_for_tait.rs +++ b/tests/ui/type-alias-impl-trait/impl_trait_for_tait.rs @@ -4,6 +4,7 @@ #![feature(type_alias_impl_trait)] type Alias = impl Sized; +#[define_opaques(Alias)] fn constrain() -> Alias { 1i32 } diff --git a/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound.rs b/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound.rs index 8ec20acef4de..b1b27e45d527 100644 --- a/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound.rs +++ b/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound.rs @@ -3,17 +3,18 @@ use std::fmt::Debug; type Foo = impl Debug; -pub trait Yay { } -impl Yay for Foo { } +pub trait Yay {} +impl Yay for Foo {} +#[define_opaques(Foo)] fn foo() { - is_yay::(); //~ ERROR: the trait bound `u32: Yay` is not satisfied + is_yay::(); //~ ERROR: the trait bound `u32: Yay` is not satisfied is_debug::(); // OK - is_yay::(); // OK + is_yay::(); // OK is_debug::(); // OK } -fn is_yay() { } -fn is_debug() { } +fn is_yay() {} +fn is_debug() {} fn main() {} diff --git a/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound.stderr b/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound.stderr index 9840bcef7d14..0ebf9f064373 100644 --- a/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound.stderr +++ b/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound.stderr @@ -1,14 +1,14 @@ error[E0277]: the trait bound `u32: Yay` is not satisfied - --> $DIR/impl_trait_for_tait_bound.rs:10:14 + --> $DIR/impl_trait_for_tait_bound.rs:11:14 | LL | is_yay::(); | ^^^ the trait `Yay` is not implemented for `u32` | = help: the trait `Yay` is implemented for `Foo` note: required by a bound in `is_yay` - --> $DIR/impl_trait_for_tait_bound.rs:16:14 + --> $DIR/impl_trait_for_tait_bound.rs:17:14 | -LL | fn is_yay() { } +LL | fn is_yay() {} | ^^^ required by this bound in `is_yay` error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound2.rs b/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound2.rs index a4b8c2d190db..1c02dadc56c8 100644 --- a/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound2.rs +++ b/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound2.rs @@ -4,13 +4,14 @@ use std::fmt::Debug; type Foo = impl Debug; -pub trait Yay { } -impl Yay for u32 { } +pub trait Yay {} +impl Yay for u32 {} +#[define_opaques(Foo)] fn foo() { is_yay::(); //~ ERROR: the trait bound `Foo: Yay` is not satisfied } -fn is_yay() { } +fn is_yay() {} fn main() {} diff --git a/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound2.stderr b/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound2.stderr index 2259aa7bb150..4fff9ad26cb3 100644 --- a/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound2.stderr +++ b/tests/ui/type-alias-impl-trait/impl_trait_for_tait_bound2.stderr @@ -1,14 +1,14 @@ error[E0277]: the trait bound `Foo: Yay` is not satisfied - --> $DIR/impl_trait_for_tait_bound2.rs:11:14 + --> $DIR/impl_trait_for_tait_bound2.rs:12:14 | LL | is_yay::(); | ^^^ the trait `Yay` is not implemented for `Foo` | = help: the trait `Yay` is implemented for `u32` note: required by a bound in `is_yay` - --> $DIR/impl_trait_for_tait_bound2.rs:14:14 + --> $DIR/impl_trait_for_tait_bound2.rs:15:14 | -LL | fn is_yay() { } +LL | fn is_yay() {} | ^^^ required by this bound in `is_yay` error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/impl_trait_in_trait_defined_outside_trait.stderr b/tests/ui/type-alias-impl-trait/impl_trait_in_trait_defined_outside_trait.stderr index 1d7a97c53671..1a57c3e78404 100644 --- a/tests/ui/type-alias-impl-trait/impl_trait_in_trait_defined_outside_trait.stderr +++ b/tests/ui/type-alias-impl-trait/impl_trait_in_trait_defined_outside_trait.stderr @@ -11,7 +11,7 @@ LL | let x: Self::Assoc = 42; | = note: expected opaque type `<() as Trait>::Assoc` found type `{integer}` -note: this item must have the opaque type in its signature in order to be able to register hidden types +note: this item must have a `#[define_opaques(<() as Trait>::Assoc)]` attribute to be able to define hidden types --> $DIR/impl_trait_in_trait_defined_outside_trait.rs:14:8 | LL | fn foo() { @@ -30,7 +30,7 @@ LL | let x: Self::Assoc = 42; | = note: expected opaque type `<() as Trait2>::Assoc` found type `{integer}` -note: this item must have the opaque type in its signature in order to be able to register hidden types +note: this item must have a `#[define_opaques(<() as Trait2>::Assoc)]` attribute to be able to define hidden types --> $DIR/impl_trait_in_trait_defined_outside_trait.rs:30:11 | LL | const FOO: () = { diff --git a/tests/ui/type-alias-impl-trait/implied_bounds.rs b/tests/ui/type-alias-impl-trait/implied_bounds.rs index 269c0eff025d..7f54b1d3f275 100644 --- a/tests/ui/type-alias-impl-trait/implied_bounds.rs +++ b/tests/ui/type-alias-impl-trait/implied_bounds.rs @@ -1,11 +1,8 @@ #![feature(type_alias_impl_trait)] -mod foo { - use super::Equals; - pub type WithLifetime<'a> = impl Equals; - fn _defining_use<'a>() -> WithLifetime<'a> {} -} -use foo::WithLifetime; +pub type WithLifetime<'a> = impl Equals; +#[define_opaques(WithLifetime)] +fn _defining_use<'a>() -> WithLifetime<'a> {} trait Convert<'a> { type Witness; diff --git a/tests/ui/type-alias-impl-trait/implied_bounds.stderr b/tests/ui/type-alias-impl-trait/implied_bounds.stderr index 23f1141e5444..eda87bcbf90c 100644 --- a/tests/ui/type-alias-impl-trait/implied_bounds.stderr +++ b/tests/ui/type-alias-impl-trait/implied_bounds.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/implied_bounds.rs:21:9 + --> $DIR/implied_bounds.rs:18:9 | LL | impl<'a> Convert<'a> for () { | -- lifetime `'a` defined here diff --git a/tests/ui/type-alias-impl-trait/implied_bounds2.rs b/tests/ui/type-alias-impl-trait/implied_bounds2.rs index 845476ef9741..b04a4eb3413a 100644 --- a/tests/ui/type-alias-impl-trait/implied_bounds2.rs +++ b/tests/ui/type-alias-impl-trait/implied_bounds2.rs @@ -2,12 +2,10 @@ #![feature(type_alias_impl_trait)] -mod helper { - pub type Ty<'a, A> = impl Sized + 'a; - fn defining<'a, A>() -> Ty<'a, A> {} - pub fn assert_static() {} -} -use helper::*; +pub type Ty<'a, A> = impl Sized + 'a; +#[define_opaques(Ty)] +fn defining<'a, A>() -> Ty<'a, A> {} +pub fn assert_static() {} fn test<'a, A>() where Ty<'a, A>: 'static, diff --git a/tests/ui/type-alias-impl-trait/implied_bounds_from_types.rs b/tests/ui/type-alias-impl-trait/implied_bounds_from_types.rs index 76a63741e18e..cd803ce71b6b 100644 --- a/tests/ui/type-alias-impl-trait/implied_bounds_from_types.rs +++ b/tests/ui/type-alias-impl-trait/implied_bounds_from_types.rs @@ -1,11 +1,8 @@ #![feature(type_alias_impl_trait)] -mod foo { - use super::Equals; - pub type WithLifetime = impl Equals; - fn _defining_use() -> WithLifetime {} -} -use foo::WithLifetime; +pub type WithLifetime = impl Equals; +#[define_opaques(WithLifetime)] +fn _defining_use() -> WithLifetime {} trait Convert<'a> { type Witness; diff --git a/tests/ui/type-alias-impl-trait/implied_bounds_from_types.stderr b/tests/ui/type-alias-impl-trait/implied_bounds_from_types.stderr index 391a8a75786a..887c8552d2f7 100644 --- a/tests/ui/type-alias-impl-trait/implied_bounds_from_types.stderr +++ b/tests/ui/type-alias-impl-trait/implied_bounds_from_types.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/implied_bounds_from_types.rs:21:9 + --> $DIR/implied_bounds_from_types.rs:18:9 | LL | impl<'a> Convert<'a> for () { | -- lifetime `'a` defined here diff --git a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check.error.stderr b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check.error.stderr index 49997b073c95..3bc6b9205ec1 100644 --- a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check.error.stderr +++ b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check.error.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Yay` for type `<() as HideIt>::Assoc` - --> $DIR/implied_lifetime_wf_check.rs:26:1 + --> $DIR/implied_lifetime_wf_check.rs:27:1 | LL | impl Yay for <() as HideIt>::Assoc {} | ---------------------------------- first implementation here diff --git a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check.rs b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check.rs index d85c7f60023e..0a4c013b9c71 100644 --- a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check.rs +++ b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check.rs @@ -7,6 +7,7 @@ type Alias = impl Sized; +#[define_opaques(Alias)] fn constrain() -> Alias { 1i32 } diff --git a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs index fb251e9bde15..3b7ea40860b5 100644 --- a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs +++ b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.rs @@ -2,6 +2,7 @@ mod test_lifetime_param { pub type Ty<'a> = impl Sized; + #[define_opaques(Ty)] fn defining(a: &str) -> Ty<'_> { a } @@ -17,6 +18,7 @@ where mod test_higher_kinded_lifetime_param { pub type Ty<'a> = impl Sized + 'a; + #[define_opaques(Ty)] fn defining(a: &str) -> Ty<'_> { a } @@ -40,6 +42,7 @@ mod test_higher_kinded_lifetime_param2 { mod test_type_param { pub type Ty = impl Sized; + #[define_opaques(Ty)] fn defining(s: A) -> Ty { s } @@ -54,13 +57,13 @@ where } mod test_implied_from_fn_sig { - mod foo { - pub type Opaque = impl Sized; - fn defining() -> Opaque {} - } + pub type Opaque = impl Sized; + #[define_opaques(Opaque)] + fn defining() -> Opaque {} + fn assert_static() {} - fn test(_: foo::Opaque) { + fn test(_: Opaque) { assert_static::(); } } diff --git a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr index b7c9c131c7d1..bbc0b91cd503 100644 --- a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr +++ b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check3.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/implied_lifetime_wf_check3.rs:14:5 + --> $DIR/implied_lifetime_wf_check3.rs:15:5 | LL | fn test_lifetime_param_test<'a>() | -- lifetime `'a` defined here @@ -8,7 +8,7 @@ LL | test_lifetime_param::assert_static::<'a>() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` error: lifetime may not live long enough - --> $DIR/implied_lifetime_wf_check3.rs:29:5 + --> $DIR/implied_lifetime_wf_check3.rs:31:5 | LL | fn test_higher_kinded_lifetime_param_test<'a>() | -- lifetime `'a` defined here @@ -17,7 +17,7 @@ LL | test_higher_kinded_lifetime_param::assert_static::<'a>() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` error: lifetime may not live long enough - --> $DIR/implied_lifetime_wf_check3.rs:36:9 + --> $DIR/implied_lifetime_wf_check3.rs:38:9 | LL | fn test<'a>() { | -- lifetime `'a` defined here @@ -25,7 +25,7 @@ LL | assert_static::<'a>() | ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` error[E0310]: the parameter type `A` may not live long enough - --> $DIR/implied_lifetime_wf_check3.rs:52:5 + --> $DIR/implied_lifetime_wf_check3.rs:55:5 | LL | test_type_param::assert_static::() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs index 7b2bbc995307..d55a86dc7db6 100644 --- a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs +++ b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs @@ -1,14 +1,12 @@ #![feature(type_alias_impl_trait)] -mod test_type_param_static { - pub type Ty = impl Sized + 'static; - fn defining(s: A) -> Ty { - s - //~^ ERROR: the parameter type `A` may not live long enough - } - pub fn assert_static() {} +pub type Ty = impl Sized + 'static; +#[define_opaques(Ty)] +fn defining(s: A) -> Ty { + s + //~^ ERROR: the parameter type `A` may not live long enough } -use test_type_param_static::*; +pub fn assert_static() {} fn test() where diff --git a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr index f23b978d0b64..710e4a5ce9e8 100644 --- a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr +++ b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr @@ -1,24 +1,24 @@ error[E0310]: the parameter type `A` may not live long enough - --> $DIR/implied_lifetime_wf_check4_static.rs:6:9 + --> $DIR/implied_lifetime_wf_check4_static.rs:6:5 | -LL | s - | ^ - | | - | the parameter type `A` must be valid for the static lifetime... - | ...so that the type `A` will meet its required lifetime bounds... +LL | s + | ^ + | | + | the parameter type `A` must be valid for the static lifetime... + | ...so that the type `A` will meet its required lifetime bounds... | note: ...that is required by this bound - --> $DIR/implied_lifetime_wf_check4_static.rs:4:35 + --> $DIR/implied_lifetime_wf_check4_static.rs:3:31 | -LL | pub type Ty = impl Sized + 'static; - | ^^^^^^^ +LL | pub type Ty = impl Sized + 'static; + | ^^^^^^^ help: consider adding an explicit lifetime bound | -LL | pub type Ty = impl Sized + 'static; - | +++++++++ +LL | pub type Ty = impl Sized + 'static; + | +++++++++ error[E0310]: the parameter type `A` may not live long enough - --> $DIR/implied_lifetime_wf_check4_static.rs:17:5 + --> $DIR/implied_lifetime_wf_check4_static.rs:15:5 | LL | assert_static::() | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/imply_bounds_from_bounds.rs b/tests/ui/type-alias-impl-trait/imply_bounds_from_bounds.rs index 4a9f162823e3..b7b5e5d01405 100644 --- a/tests/ui/type-alias-impl-trait/imply_bounds_from_bounds.rs +++ b/tests/ui/type-alias-impl-trait/imply_bounds_from_bounds.rs @@ -2,19 +2,17 @@ #![feature(impl_trait_in_assoc_type, type_alias_impl_trait)] -mod foo { - pub trait Callable { - type Output; - fn call() -> Self::Output; - } +pub trait Callable { + type Output; + fn call() -> Self::Output; +} - pub type OutputHelper = impl Sized; - impl<'a> Callable for &'a () { - type Output = OutputHelper; - fn call() -> Self::Output {} - } +pub type OutputHelper = impl Sized; +impl<'a> Callable for &'a () { + type Output = OutputHelper; + #[define_opaques(OutputHelper)] + fn call() -> Self::Output {} } -use foo::*; fn test<'a>() -> impl Sized { <&'a () as Callable>::call() diff --git a/tests/ui/type-alias-impl-trait/in-where-clause.rs b/tests/ui/type-alias-impl-trait/in-where-clause.rs index 065af57a8641..00444cc98009 100644 --- a/tests/ui/type-alias-impl-trait/in-where-clause.rs +++ b/tests/ui/type-alias-impl-trait/in-where-clause.rs @@ -5,6 +5,7 @@ type Bar = impl Sized; //~^ ERROR: cycle +#[define_opaques(Bar)] fn foo() -> Bar where Bar: Send, diff --git a/tests/ui/type-alias-impl-trait/in-where-clause.stderr b/tests/ui/type-alias-impl-trait/in-where-clause.stderr index 5ac09e20b02c..114cac64573c 100644 --- a/tests/ui/type-alias-impl-trait/in-where-clause.stderr +++ b/tests/ui/type-alias-impl-trait/in-where-clause.stderr @@ -1,12 +1,12 @@ error[E0283]: type annotations needed: cannot satisfy `Bar: Send` - --> $DIR/in-where-clause.rs:12:9 + --> $DIR/in-where-clause.rs:13:9 | LL | [0; 1 + 2] | ^^^^^ | = note: cannot satisfy `Bar: Send` note: required by a bound in `foo` - --> $DIR/in-where-clause.rs:10:10 + --> $DIR/in-where-clause.rs:11:10 | LL | fn foo() -> Bar | --- required by a bound in this function @@ -21,7 +21,7 @@ LL | type Bar = impl Sized; | ^^^^^^^^^^ | note: ...which requires type-checking `foo`... - --> $DIR/in-where-clause.rs:8:1 + --> $DIR/in-where-clause.rs:9:1 | LL | / fn foo() -> Bar LL | | where diff --git a/tests/ui/type-alias-impl-trait/incomplete-inference.rs b/tests/ui/type-alias-impl-trait/incomplete-inference.rs index 4c8bf2cfca11..ef5b4c03b449 100644 --- a/tests/ui/type-alias-impl-trait/incomplete-inference.rs +++ b/tests/ui/type-alias-impl-trait/incomplete-inference.rs @@ -2,11 +2,13 @@ type Foo = impl Sized; +#[define_opaques(Foo)] fn bar() -> Foo { None //~^ ERROR: type annotations needed [E0282] } +#[define_opaques(Foo)] fn baz() -> Foo { Some(()) } diff --git a/tests/ui/type-alias-impl-trait/incomplete-inference.stderr b/tests/ui/type-alias-impl-trait/incomplete-inference.stderr index 3976a43a89c5..0b2bac0a153f 100644 --- a/tests/ui/type-alias-impl-trait/incomplete-inference.stderr +++ b/tests/ui/type-alias-impl-trait/incomplete-inference.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed - --> $DIR/incomplete-inference.rs:6:5 + --> $DIR/incomplete-inference.rs:7:5 | LL | None | ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option` diff --git a/tests/ui/type-alias-impl-trait/inference-cycle.rs b/tests/ui/type-alias-impl-trait/inference-cycle.rs index 6e4507ed4606..cb506627a0e5 100644 --- a/tests/ui/type-alias-impl-trait/inference-cycle.rs +++ b/tests/ui/type-alias-impl-trait/inference-cycle.rs @@ -1,24 +1,24 @@ #![feature(type_alias_impl_trait)] #![allow(dead_code)] -mod m { - pub type Foo = impl std::fmt::Debug; +//@ check-pass - pub fn foo() -> Foo { - is_send(bar()) - } +pub type Foo = impl std::fmt::Debug; - pub fn bar() { - // Cycle: error today, but it'd be nice if it eventually worked - is_send(foo()); - //~^ ERROR: cannot check whether the hidden type of `inference_cycle[4ecc]::m::Foo::{opaque#0}` satisfies auto traits - } +#[define_opaques(Foo)] +pub fn foo() -> Foo { + is_send(bar()) +} - fn baz() -> Foo { - () - } +pub fn bar() { + is_send(foo()); +} - fn is_send(_: T) {} +#[define_opaques(Foo)] +fn baz() -> Foo { + () } +fn is_send(_: T) {} + fn main() {} diff --git a/tests/ui/type-alias-impl-trait/inference-cycle.stderr b/tests/ui/type-alias-impl-trait/inference-cycle.stderr deleted file mode 100644 index 8b809ba014d9..000000000000 --- a/tests/ui/type-alias-impl-trait/inference-cycle.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error: cannot check whether the hidden type of `inference_cycle[4ecc]::m::Foo::{opaque#0}` satisfies auto traits - --> $DIR/inference-cycle.rs:13:17 - | -LL | is_send(foo()); - | ------- ^^^^^ - | | - | required by a bound introduced by this call - | - = note: fetching the hidden types of an opaque inside of the defining scope is not supported. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule -note: opaque type is declared here - --> $DIR/inference-cycle.rs:5:20 - | -LL | pub type Foo = impl std::fmt::Debug; - | ^^^^^^^^^^^^^^^^^^^^ -note: required by a bound in `is_send` - --> $DIR/inference-cycle.rs:21:19 - | -LL | fn is_send(_: T) {} - | ^^^^ required by this bound in `is_send` - -error: aborting due to 1 previous error - diff --git a/tests/ui/type-alias-impl-trait/infinite-cycle-involving-weak.rs b/tests/ui/type-alias-impl-trait/infinite-cycle-involving-weak.rs index 6609d4eb5a27..c6726ba3d397 100644 --- a/tests/ui/type-alias-impl-trait/infinite-cycle-involving-weak.rs +++ b/tests/ui/type-alias-impl-trait/infinite-cycle-involving-weak.rs @@ -3,6 +3,9 @@ type T = impl Copy; //~^ ERROR cannot resolve opaque type -static STATIC: T = None::<&'static T>; +#[define_opaques(T)] +fn foo() -> T { + None::<&'static T> +} fn main() {} diff --git a/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.rs b/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.rs index 93c52126d69b..ae9712bd891a 100644 --- a/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.rs +++ b/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.rs @@ -7,6 +7,7 @@ trait Foo { impl Foo for () { type Foo = impl std::fmt::Debug; + //~^ ERROR: unconstrained opaque type fn bar() { let x: Self::Foo = (); //~^ ERROR: mismatched types diff --git a/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.stderr b/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.stderr index 169d8e41d20d..0edc52a53fa5 100644 --- a/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.stderr +++ b/tests/ui/type-alias-impl-trait/invalid_impl_trait_in_assoc_ty.stderr @@ -1,9 +1,17 @@ +error: unconstrained opaque type + --> $DIR/invalid_impl_trait_in_assoc_ty.rs:9:16 + | +LL | type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `Foo` must be used in combination with a concrete type within the same impl + error[E0308]: mismatched types - --> $DIR/invalid_impl_trait_in_assoc_ty.rs:11:28 + --> $DIR/invalid_impl_trait_in_assoc_ty.rs:12:28 | LL | type Foo = impl std::fmt::Debug; | -------------------- the expected opaque type -LL | fn bar() { +... LL | let x: Self::Foo = (); | --------- ^^ expected opaque type, found `()` | | @@ -11,12 +19,12 @@ LL | let x: Self::Foo = (); | = note: expected opaque type `<() as Foo>::Foo` found unit type `()` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/invalid_impl_trait_in_assoc_ty.rs:10:8 +note: this item must have a `#[define_opaques(<() as Foo>::Foo)]` attribute to be able to define hidden types + --> $DIR/invalid_impl_trait_in_assoc_ty.rs:11:8 | LL | fn bar() { | ^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/issue-101750.rs b/tests/ui/type-alias-impl-trait/issue-101750.rs index 9367be8ca07f..1b952929c858 100644 --- a/tests/ui/type-alias-impl-trait/issue-101750.rs +++ b/tests/ui/type-alias-impl-trait/issue-101750.rs @@ -2,21 +2,18 @@ //@ check-pass -mod foo { - pub trait Trait {} +pub trait Trait {} - pub type TAIT = impl Trait; +pub type TAIT = impl Trait; - pub struct Concrete; - impl Trait for Concrete {} +pub struct Concrete; +impl Trait for Concrete {} - pub fn tait() -> TAIT { - Concrete - } +#[define_opaques(TAIT)] +pub fn tait() -> TAIT { + Concrete } -use foo::*; - trait OuterTrait { type Item; } diff --git a/tests/ui/type-alias-impl-trait/issue-104817.rs b/tests/ui/type-alias-impl-trait/issue-104817.rs index 491463216145..8faca8627cb8 100644 --- a/tests/ui/type-alias-impl-trait/issue-104817.rs +++ b/tests/ui/type-alias-impl-trait/issue-104817.rs @@ -8,6 +8,7 @@ trait OpaqueTrait {} impl OpaqueTrait for T {} type OpaqueType = impl OpaqueTrait; +#[define_opaques(OpaqueType)] fn mk_opaque() -> OpaqueType { || 0 } diff --git a/tests/ui/type-alias-impl-trait/issue-104817.stock.stderr b/tests/ui/type-alias-impl-trait/issue-104817.stock.stderr index df5a6c320a8a..4f227310ee78 100644 --- a/tests/ui/type-alias-impl-trait/issue-104817.stock.stderr +++ b/tests/ui/type-alias-impl-trait/issue-104817.stock.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `AnotherTrait` - --> $DIR/issue-104817.rs:16:1 + --> $DIR/issue-104817.rs:17:1 | LL | impl AnotherTrait for T {} | -------------------------------- first implementation here diff --git a/tests/ui/type-alias-impl-trait/issue-109054.rs b/tests/ui/type-alias-impl-trait/issue-109054.rs index d3eb65215934..7720ffc98952 100644 --- a/tests/ui/type-alias-impl-trait/issue-109054.rs +++ b/tests/ui/type-alias-impl-trait/issue-109054.rs @@ -10,8 +10,10 @@ type FnType = impl Fn(&u32) -> ReturnType; impl std::ops::Deref for CallMe { type Target = FnType; + #[define_opaques(FnType)] fn deref(&self) -> &Self::Target { //~^ ERROR: item does not constrain `ReturnType + #[define_opaques(ReturnType)] fn inner(val: &u32) -> ReturnType { async move { *val * 2 } } diff --git a/tests/ui/type-alias-impl-trait/issue-109054.stderr b/tests/ui/type-alias-impl-trait/issue-109054.stderr index 2a4aa63bb8ca..2e4c24898a66 100644 --- a/tests/ui/type-alias-impl-trait/issue-109054.stderr +++ b/tests/ui/type-alias-impl-trait/issue-109054.stderr @@ -1,5 +1,5 @@ error: item does not constrain `ReturnType::{opaque#0}`, but has it in its signature - --> $DIR/issue-109054.rs:13:8 + --> $DIR/issue-109054.rs:14:8 | LL | fn deref(&self) -> &Self::Target { | ^^^^^ @@ -12,7 +12,7 @@ LL | type ReturnType<'a> = impl std::future::Future + 'a; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0792]: expected generic lifetime parameter, found `'_` - --> $DIR/issue-109054.rs:19:9 + --> $DIR/issue-109054.rs:21:9 | LL | type ReturnType<'a> = impl std::future::Future + 'a; | -- this generic parameter must be used with a generic lifetime parameter diff --git a/tests/ui/type-alias-impl-trait/issue-52843-closure-constrain.rs b/tests/ui/type-alias-impl-trait/issue-52843-closure-constrain.rs index 50eeff0b18fd..181adcb48dba 100644 --- a/tests/ui/type-alias-impl-trait/issue-52843-closure-constrain.rs +++ b/tests/ui/type-alias-impl-trait/issue-52843-closure-constrain.rs @@ -1,13 +1,15 @@ // Checks to ensure that we properly detect when a closure constrains an opaque type -#![feature(type_alias_impl_trait)] +#![feature(type_alias_impl_trait, stmt_expr_attributes)] use std::fmt::Debug; fn main() { type Opaque = impl Debug; + #[define_opaques(Opaque)] fn _unused() -> Opaque { String::new() } - let null = || -> Opaque { 0 }; + let null = #[define_opaques(Opaque)] || -> Opaque { 0 }; //~^ ERROR: concrete type differs from previous defining opaque type use + //~| ERROR: only functions and methods can define opaque types println!("{:?}", null()); } diff --git a/tests/ui/type-alias-impl-trait/issue-52843-closure-constrain.stderr b/tests/ui/type-alias-impl-trait/issue-52843-closure-constrain.stderr index 4570ce8e41da..00e0628f2167 100644 --- a/tests/ui/type-alias-impl-trait/issue-52843-closure-constrain.stderr +++ b/tests/ui/type-alias-impl-trait/issue-52843-closure-constrain.stderr @@ -1,14 +1,20 @@ +error: only functions and methods can define opaque types + --> $DIR/issue-52843-closure-constrain.rs:11:16 + | +LL | let null = #[define_opaques(Opaque)] || -> Opaque { 0 }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + error: concrete type differs from previous defining opaque type use - --> $DIR/issue-52843-closure-constrain.rs:10:31 + --> $DIR/issue-52843-closure-constrain.rs:11:57 | -LL | let null = || -> Opaque { 0 }; - | ^ expected `String`, got `i32` +LL | let null = #[define_opaques(Opaque)] || -> Opaque { 0 }; + | ^ expected `String`, got `i32` | note: previous use here - --> $DIR/issue-52843-closure-constrain.rs:9:30 + --> $DIR/issue-52843-closure-constrain.rs:10:30 | LL | fn _unused() -> Opaque { String::new() } | ^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors diff --git a/tests/ui/type-alias-impl-trait/issue-52843.rs b/tests/ui/type-alias-impl-trait/issue-52843.rs index 159d3ccd27e0..682dc5d20941 100644 --- a/tests/ui/type-alias-impl-trait/issue-52843.rs +++ b/tests/ui/type-alias-impl-trait/issue-52843.rs @@ -3,6 +3,7 @@ type Foo = impl Default; #[allow(unused)] +#[define_opaques(Foo)] fn foo(t: T) -> Foo { t //~^ ERROR: the trait bound `T: Default` is not satisfied diff --git a/tests/ui/type-alias-impl-trait/issue-52843.stderr b/tests/ui/type-alias-impl-trait/issue-52843.stderr index 6673b03525d0..ee2390d09451 100644 --- a/tests/ui/type-alias-impl-trait/issue-52843.stderr +++ b/tests/ui/type-alias-impl-trait/issue-52843.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `T: Default` is not satisfied - --> $DIR/issue-52843.rs:7:5 + --> $DIR/issue-52843.rs:8:5 | LL | t | ^ the trait `Default` is not implemented for `T` @@ -10,7 +10,7 @@ note: required by a bound in an opaque type LL | type Foo = impl Default; | ^^^^^^^ note: this definition site has more where clauses than the opaque type - --> $DIR/issue-52843.rs:6:1 + --> $DIR/issue-52843.rs:7:1 | LL | fn foo(t: T) -> Foo { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/issue-53092-2.rs b/tests/ui/type-alias-impl-trait/issue-53092-2.rs index 2383008d042f..579cbd099c8a 100644 --- a/tests/ui/type-alias-impl-trait/issue-53092-2.rs +++ b/tests/ui/type-alias-impl-trait/issue-53092-2.rs @@ -3,12 +3,13 @@ type Bug = impl Fn(T) -> U + Copy; +#[define_opaques(Bug)] +//~^ ERROR: only functions and methods can define opaque types const CONST_BUG: Bug = unsafe { std::mem::transmute(|_: u8| ()) }; -//~^ ERROR cycle detected -//~| ERROR: non-defining opaque type use +#[define_opaques(Bug)] fn make_bug>() -> Bug { - |x| x.into() + |x| x.into() //~ ERROR is not satisfied } fn main() { diff --git a/tests/ui/type-alias-impl-trait/issue-53092-2.stderr b/tests/ui/type-alias-impl-trait/issue-53092-2.stderr index ac580866704d..dfbec3de8b37 100644 --- a/tests/ui/type-alias-impl-trait/issue-53092-2.stderr +++ b/tests/ui/type-alias-impl-trait/issue-53092-2.stderr @@ -1,42 +1,25 @@ -error[E0792]: non-defining opaque type use in defining scope - --> $DIR/issue-53092-2.rs:6:18 - | -LL | const CONST_BUG: Bug = unsafe { std::mem::transmute(|_: u8| ()) }; - | ^^^^^^^^^^^ argument `u8` is not a generic parameter - | -note: for this opaque type - --> $DIR/issue-53092-2.rs:4:18 - | -LL | type Bug = impl Fn(T) -> U + Copy; - | ^^^^^^^^^^^^^^^^^^^^^^ - -error[E0391]: cycle detected when type-checking `CONST_BUG` +error: only functions and methods can define opaque types --> $DIR/issue-53092-2.rs:6:1 | -LL | const CONST_BUG: Bug = unsafe { std::mem::transmute(|_: u8| ()) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #[define_opaques(Bug)] + | ^^^^^^^^^^^^^^^^^^^^^^ + +error[E0277]: the trait bound `U: From` is not satisfied + --> $DIR/issue-53092-2.rs:12:5 | - = note: ...which requires computing layout of `Bug`... - = note: ...which requires normalizing `Bug`... -note: ...which requires computing type of `Bug::{opaque#0}`... - --> $DIR/issue-53092-2.rs:4:18 +LL | |x| x.into() + | ^^^^^^^^^^^^ the trait `From` is not implemented for `U` | -LL | type Bug = impl Fn(T) -> U + Copy; - | ^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires computing type of opaque `Bug::{opaque#0}`... - --> $DIR/issue-53092-2.rs:4:18 +note: required by a bound in `make_bug` + --> $DIR/issue-53092-2.rs:11:19 | -LL | type Bug = impl Fn(T) -> U + Copy; - | ^^^^^^^^^^^^^^^^^^^^^^ - = note: ...which again requires type-checking `CONST_BUG`, completing the cycle -note: cycle used when checking that `CONST_BUG` is well-formed - --> $DIR/issue-53092-2.rs:6:1 +LL | fn make_bug>() -> Bug { + | ^^^^^^^ required by this bound in `make_bug` +help: consider restricting type parameter `U` with trait `From` | -LL | const CONST_BUG: Bug = unsafe { std::mem::transmute(|_: u8| ()) }; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information +LL | type Bug> = impl Fn(T) -> U + Copy; + | +++++++++++++++++++++++ error: aborting due to 2 previous errors -Some errors have detailed explanations: E0391, E0792. -For more information about an error, try `rustc --explain E0391`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/type-alias-impl-trait/issue-53092.rs b/tests/ui/type-alias-impl-trait/issue-53092.rs index 83b51227aaae..bf72f6ac7ac1 100644 --- a/tests/ui/type-alias-impl-trait/issue-53092.rs +++ b/tests/ui/type-alias-impl-trait/issue-53092.rs @@ -1,14 +1,13 @@ #![feature(type_alias_impl_trait)] #![allow(dead_code)] -mod bug { - pub type Bug = impl Fn(T) -> U + Copy; +pub type Bug = impl Fn(T) -> U + Copy; - fn make_bug>() -> Bug { - |x| x.into() //~ ERROR the trait bound `U: From` is not satisfied - } +#[define_opaques(Bug)] +fn make_bug>() -> Bug { + |x| x.into() + //~^ ERROR the trait bound `U: From` is not satisfied } -use bug::Bug; union Moo { x: Bug, diff --git a/tests/ui/type-alias-impl-trait/issue-53092.stderr b/tests/ui/type-alias-impl-trait/issue-53092.stderr index 579902aa3ab2..a8554b9a9892 100644 --- a/tests/ui/type-alias-impl-trait/issue-53092.stderr +++ b/tests/ui/type-alias-impl-trait/issue-53092.stderr @@ -1,18 +1,18 @@ error[E0277]: the trait bound `U: From` is not satisfied - --> $DIR/issue-53092.rs:8:9 + --> $DIR/issue-53092.rs:8:5 | -LL | |x| x.into() - | ^^^^^^^^^^^^ the trait `From` is not implemented for `U` +LL | |x| x.into() + | ^^^^^^^^^^^^ the trait `From` is not implemented for `U` | note: required by a bound in `make_bug` - --> $DIR/issue-53092.rs:7:23 + --> $DIR/issue-53092.rs:7:19 | -LL | fn make_bug>() -> Bug { - | ^^^^^^^ required by this bound in `make_bug` +LL | fn make_bug>() -> Bug { + | ^^^^^^^ required by this bound in `make_bug` help: consider restricting type parameter `U` with trait `From` | -LL | pub type Bug> = impl Fn(T) -> U + Copy; - | +++++++++++++++++++++++ +LL | pub type Bug> = impl Fn(T) -> U + Copy; + | +++++++++++++++++++++++ error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/issue-53096.rs b/tests/ui/type-alias-impl-trait/issue-53096.rs index 590fce84fc9f..744d8e7679d4 100644 --- a/tests/ui/type-alias-impl-trait/issue-53096.rs +++ b/tests/ui/type-alias-impl-trait/issue-53096.rs @@ -1,13 +1,11 @@ #![feature(rustc_attrs)] #![feature(type_alias_impl_trait)] -mod foo { - pub type Foo = impl Fn() -> usize; - pub const fn bar() -> Foo { - || 0usize - } +pub type Foo = impl Fn() -> usize; +#[define_opaques(Foo)] +pub const fn bar() -> Foo { + || 0usize } -use foo::*; const BAZR: Foo = bar(); #[rustc_error] diff --git a/tests/ui/type-alias-impl-trait/issue-53096.stderr b/tests/ui/type-alias-impl-trait/issue-53096.stderr index 0a744e7be9cb..53490896af79 100644 --- a/tests/ui/type-alias-impl-trait/issue-53096.stderr +++ b/tests/ui/type-alias-impl-trait/issue-53096.stderr @@ -1,5 +1,5 @@ error: fatal error triggered by #[rustc_error] - --> $DIR/issue-53096.rs:14:1 + --> $DIR/issue-53096.rs:12:1 | LL | fn main() {} | ^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/issue-53678-coroutine-and-const-fn.rs b/tests/ui/type-alias-impl-trait/issue-53678-coroutine-and-const-fn.rs index 0d9126d39933..e1b0d489c895 100644 --- a/tests/ui/type-alias-impl-trait/issue-53678-coroutine-and-const-fn.rs +++ b/tests/ui/type-alias-impl-trait/issue-53678-coroutine-and-const-fn.rs @@ -3,21 +3,20 @@ //@ check-pass -mod gen { - use std::ops::Coroutine; +use std::ops::Coroutine; - pub type CoroOnce = impl Coroutine; +pub type CoroOnce = impl Coroutine; - pub const fn const_coroutine(yielding: Y, returning: R) -> CoroOnce { - #[coroutine] - move || { - yield yielding; +#[define_opaques(CoroOnce)] +pub const fn const_coroutine(yielding: Y, returning: R) -> CoroOnce { + #[coroutine] + move || { + yield yielding; - return returning; - } + return returning; } } -const FOO: gen::CoroOnce = gen::const_coroutine(10, 100); +const FOO: CoroOnce = const_coroutine(10, 100); fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-55099-lifetime-inference.rs b/tests/ui/type-alias-impl-trait/issue-55099-lifetime-inference.rs index e54dd01122e0..d974d76204e7 100644 --- a/tests/ui/type-alias-impl-trait/issue-55099-lifetime-inference.rs +++ b/tests/ui/type-alias-impl-trait/issue-55099-lifetime-inference.rs @@ -18,6 +18,7 @@ struct Foo<'a> { type F = impl Future; impl<'a> Foo<'a> { + #[define_opaques(F)] fn reply(&mut self) -> F { AndThen(|| ()) } diff --git a/tests/ui/type-alias-impl-trait/issue-57961.rs b/tests/ui/type-alias-impl-trait/issue-57961.rs index 61af7a0f6250..f745186a5074 100644 --- a/tests/ui/type-alias-impl-trait/issue-57961.rs +++ b/tests/ui/type-alias-impl-trait/issue-57961.rs @@ -11,6 +11,7 @@ impl Foo for () { //~^ ERROR expected `IntoIter` to be an iterator that yields `X`, but it yields `u32` } +#[define_opaques(X)] fn incoherent() -> X { 22_i32 } diff --git a/tests/ui/type-alias-impl-trait/issue-58662-coroutine-with-lifetime.rs b/tests/ui/type-alias-impl-trait/issue-58662-coroutine-with-lifetime.rs index 899e81ed562f..02df1f729f05 100644 --- a/tests/ui/type-alias-impl-trait/issue-58662-coroutine-with-lifetime.rs +++ b/tests/ui/type-alias-impl-trait/issue-58662-coroutine-with-lifetime.rs @@ -7,6 +7,7 @@ use std::ops::{Coroutine, CoroutineState}; use std::pin::Pin; type RandCoroutine<'a> = impl Coroutine + 'a; +#[define_opaques(RandCoroutine)] fn rand_coroutine<'a>(rng: &'a ()) -> RandCoroutine<'a> { #[coroutine] move || { @@ -18,6 +19,7 @@ fn rand_coroutine<'a>(rng: &'a ()) -> RandCoroutine<'a> { } pub type RandCoroutineWithIndirection<'c> = impl Coroutine + 'c; +#[define_opaques(RandCoroutineWithIndirection)] pub fn rand_coroutine_with_indirection<'a>(rng: &'a ()) -> RandCoroutineWithIndirection<'a> { fn helper<'b>(rng: &'b ()) -> impl 'b + Coroutine { #[coroutine] diff --git a/tests/ui/type-alias-impl-trait/issue-58662-simplified.rs b/tests/ui/type-alias-impl-trait/issue-58662-simplified.rs index 9d74c0687fe6..2173b894ed11 100644 --- a/tests/ui/type-alias-impl-trait/issue-58662-simplified.rs +++ b/tests/ui/type-alias-impl-trait/issue-58662-simplified.rs @@ -8,6 +8,8 @@ trait Trait {} impl Trait for T {} type Foo<'c> = impl Trait + 'c; + +#[define_opaques(Foo)] fn foo<'a>(rng: &'a ()) -> Foo<'a> { fn helper<'b>(rng: &'b ()) -> impl 'b + Trait { rng @@ -16,5 +18,4 @@ fn foo<'a>(rng: &'a ()) -> Foo<'a> { helper(rng) } -fn main() { -} +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-58951-2.rs b/tests/ui/type-alias-impl-trait/issue-58951-2.rs index fb92b1274365..fe8664e4accf 100644 --- a/tests/ui/type-alias-impl-trait/issue-58951-2.rs +++ b/tests/ui/type-alias-impl-trait/issue-58951-2.rs @@ -2,14 +2,12 @@ #![feature(type_alias_impl_trait)] -mod defining_use_scope { - pub type A = impl Iterator; +pub type A = impl Iterator; - pub fn def_a() -> A { - 0..1 - } +#[define_opaques(A)] +pub fn def_a() -> A { + 0..1 } -use defining_use_scope::*; pub fn use_a() { def_a().map(|x| x); diff --git a/tests/ui/type-alias-impl-trait/issue-58951.rs b/tests/ui/type-alias-impl-trait/issue-58951.rs index b9f27b031c72..fe8664e4accf 100644 --- a/tests/ui/type-alias-impl-trait/issue-58951.rs +++ b/tests/ui/type-alias-impl-trait/issue-58951.rs @@ -2,16 +2,15 @@ #![feature(type_alias_impl_trait)] -mod helper { - pub type A = impl Iterator; +pub type A = impl Iterator; - pub fn def_a() -> A { - 0..1 - } +#[define_opaques(A)] +pub fn def_a() -> A { + 0..1 } pub fn use_a() { - helper::def_a().map(|x| x); + def_a().map(|x| x); } fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-60407.rs b/tests/ui/type-alias-impl-trait/issue-60407.rs index 6c7c76b5ac72..048e7edffce8 100644 --- a/tests/ui/type-alias-impl-trait/issue-60407.rs +++ b/tests/ui/type-alias-impl-trait/issue-60407.rs @@ -1,13 +1,11 @@ #![feature(type_alias_impl_trait, rustc_attrs)] -mod bar { - pub type Debuggable = impl core::fmt::Debug; +pub type Debuggable = impl core::fmt::Debug; - pub fn foo() -> Debuggable { - 0u32 - } +#[define_opaques(Debuggable)] +pub fn foo() -> Debuggable { + 0u32 } -use bar::*; static mut TEST: Option = None; diff --git a/tests/ui/type-alias-impl-trait/issue-60407.stderr b/tests/ui/type-alias-impl-trait/issue-60407.stderr index bba9092e9775..f517d5b65fa2 100644 --- a/tests/ui/type-alias-impl-trait/issue-60407.stderr +++ b/tests/ui/type-alias-impl-trait/issue-60407.stderr @@ -1,5 +1,5 @@ error: fatal error triggered by #[rustc_error] - --> $DIR/issue-60407.rs:15:1 + --> $DIR/issue-60407.rs:13:1 | LL | fn main() { | ^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/issue-60564.rs b/tests/ui/type-alias-impl-trait/issue-60564.rs index 48bd70bcca95..ec320e188166 100644 --- a/tests/ui/type-alias-impl-trait/issue-60564.rs +++ b/tests/ui/type-alias-impl-trait/issue-60564.rs @@ -16,8 +16,8 @@ where E: std::fmt::Debug, { type BitsIter = IterBitsIter; + #[define_opaques(IterBitsIter)] fn iter_bits(self, n: u8) -> Self::BitsIter { - //~^ ERROR non-defining opaque type use (0u8..n).rev().map(move |shift| ((self >> T::from(shift)) & T::from(1)).try_into().unwrap()) //~^ ERROR expected generic type parameter, found `u8` } diff --git a/tests/ui/type-alias-impl-trait/issue-60564.stderr b/tests/ui/type-alias-impl-trait/issue-60564.stderr index d42495e934d3..6aaed7d4296a 100644 --- a/tests/ui/type-alias-impl-trait/issue-60564.stderr +++ b/tests/ui/type-alias-impl-trait/issue-60564.stderr @@ -1,15 +1,3 @@ -error[E0792]: non-defining opaque type use in defining scope - --> $DIR/issue-60564.rs:19:34 - | -LL | fn iter_bits(self, n: u8) -> Self::BitsIter { - | ^^^^^^^^^^^^^^ argument `u8` is not a generic parameter - | -note: for this opaque type - --> $DIR/issue-60564.rs:8:30 - | -LL | type IterBitsIter = impl std::iter::Iterator; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - error[E0792]: expected generic type parameter, found `u8` --> $DIR/issue-60564.rs:21:9 | @@ -19,6 +7,6 @@ LL | type IterBitsIter = impl std::iter::Iterator; LL | (0u8..n).rev().map(move |shift| ((self >> T::from(shift)) & T::from(1)).try_into().unwrap()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0792`. diff --git a/tests/ui/type-alias-impl-trait/issue-63263-closure-return.rs b/tests/ui/type-alias-impl-trait/issue-63263-closure-return.rs index 38abc3ec7e85..1b1ba4181022 100644 --- a/tests/ui/type-alias-impl-trait/issue-63263-closure-return.rs +++ b/tests/ui/type-alias-impl-trait/issue-63263-closure-return.rs @@ -8,6 +8,7 @@ pub type Closure = impl FnOnce(); +#[define_opaques(Closure)] fn bop() -> Closure { || -> Closure { || () }; panic!() diff --git a/tests/ui/type-alias-impl-trait/issue-63279.rs b/tests/ui/type-alias-impl-trait/issue-63279.rs index 02f2111468a2..2b7dc476a5a8 100644 --- a/tests/ui/type-alias-impl-trait/issue-63279.rs +++ b/tests/ui/type-alias-impl-trait/issue-63279.rs @@ -2,6 +2,7 @@ type Closure = impl FnOnce(); +#[define_opaques(Closure)] fn c() -> Closure { //~^ ERROR: expected a `FnOnce()` closure, found `()` || -> Closure { || () } diff --git a/tests/ui/type-alias-impl-trait/issue-63279.stderr b/tests/ui/type-alias-impl-trait/issue-63279.stderr index 97158ee297da..8f0e9c5fde04 100644 --- a/tests/ui/type-alias-impl-trait/issue-63279.stderr +++ b/tests/ui/type-alias-impl-trait/issue-63279.stderr @@ -1,5 +1,5 @@ error[E0277]: expected a `FnOnce()` closure, found `()` - --> $DIR/issue-63279.rs:5:11 + --> $DIR/issue-63279.rs:6:11 | LL | fn c() -> Closure { | ^^^^^^^ expected an `FnOnce()` closure, found `()` @@ -8,7 +8,7 @@ LL | fn c() -> Closure { = note: wrap the `()` in a closure with no arguments: `|| { /* code */ }` error[E0277]: expected a `FnOnce()` closure, found `()` - --> $DIR/issue-63279.rs:7:11 + --> $DIR/issue-63279.rs:8:11 | LL | || -> Closure { || () } | ^^^^^^^ expected an `FnOnce()` closure, found `()` @@ -17,26 +17,26 @@ LL | || -> Closure { || () } = note: wrap the `()` in a closure with no arguments: `|| { /* code */ }` error[E0308]: mismatched types - --> $DIR/issue-63279.rs:7:21 + --> $DIR/issue-63279.rs:8:21 | LL | || -> Closure { || () } | ^^^^^ expected `()`, found closure | = note: expected unit type `()` - found closure `{closure@$DIR/issue-63279.rs:7:21: 7:23}` + found closure `{closure@$DIR/issue-63279.rs:8:21: 8:23}` help: use parentheses to call this closure | LL | || -> Closure { (|| ())() } | + +++ error[E0308]: mismatched types - --> $DIR/issue-63279.rs:7:5 + --> $DIR/issue-63279.rs:8:5 | LL | || -> Closure { || () } | ^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found closure | = note: expected unit type `()` - found closure `{closure@$DIR/issue-63279.rs:7:5: 7:18}` + found closure `{closure@$DIR/issue-63279.rs:8:5: 8:18}` help: use parentheses to call this closure | LL | (|| -> Closure { || () })() diff --git a/tests/ui/type-alias-impl-trait/issue-63355.rs b/tests/ui/type-alias-impl-trait/issue-63355.rs index a0d0355b5af5..158e20d9c5a9 100644 --- a/tests/ui/type-alias-impl-trait/issue-63355.rs +++ b/tests/ui/type-alias-impl-trait/issue-63355.rs @@ -21,6 +21,7 @@ impl Foo for () {} impl Bar for () { type Foo = FooImpl; + #[define_opaques(FooImpl)] fn foo() -> Self::Foo { () } @@ -33,10 +34,12 @@ impl Baz for () { type Foo = FooImpl; type Bar = BarImpl; + #[define_opaques(FooImpl)] fn foo() -> Self::Foo { () } + #[define_opaques(BarImpl)] fn bar() -> Self::Bar { //~^ ERROR: item does not constrain `FooImpl::{opaque#0}` () diff --git a/tests/ui/type-alias-impl-trait/issue-63355.stderr b/tests/ui/type-alias-impl-trait/issue-63355.stderr index 6755c0380560..8195c963ce33 100644 --- a/tests/ui/type-alias-impl-trait/issue-63355.stderr +++ b/tests/ui/type-alias-impl-trait/issue-63355.stderr @@ -1,12 +1,12 @@ error: item does not constrain `FooImpl::{opaque#0}`, but has it in its signature - --> $DIR/issue-63355.rs:40:8 + --> $DIR/issue-63355.rs:43:8 | LL | fn bar() -> Self::Bar { | ^^^ | = note: consider moving the opaque type's declaration and defining uses into a separate module note: this opaque type is in the signature - --> $DIR/issue-63355.rs:29:20 + --> $DIR/issue-63355.rs:30:20 | LL | pub type FooImpl = impl Foo; | ^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/issue-63677-type-alias-coherence.rs b/tests/ui/type-alias-impl-trait/issue-63677-type-alias-coherence.rs index 51f95637969a..0e747de692c1 100644 --- a/tests/ui/type-alias-impl-trait/issue-63677-type-alias-coherence.rs +++ b/tests/ui/type-alias-impl-trait/issue-63677-type-alias-coherence.rs @@ -16,6 +16,9 @@ impl Trait for S1 {} impl S2 {} impl T3 {} -pub fn use_t1() -> T1 { S1(()) } +#[define_opaques(T1)] +pub fn use_t1() -> T1 { + S1(()) +} fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-65384.rs b/tests/ui/type-alias-impl-trait/issue-65384.rs index 44ca5cb94b0f..8c27b3c5a5c2 100644 --- a/tests/ui/type-alias-impl-trait/issue-65384.rs +++ b/tests/ui/type-alias-impl-trait/issue-65384.rs @@ -9,6 +9,7 @@ type Bar = impl MyTrait; impl MyTrait for Bar {} //~^ ERROR: conflicting implementations of trait `MyTrait` for type `()` -fn bazr() -> Bar { } +#[define_opaques(Bar)] +fn bazr() -> Bar {} fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs b/tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs index f98ce4a426c4..c66ef0561c17 100644 --- a/tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs +++ b/tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs @@ -1,20 +1,19 @@ //@ check-pass #![feature(type_alias_impl_trait, rustc_attrs)] -mod foo { - pub type T = impl Sized; - // The concrete type referred by impl-trait-type-alias(`T`) is guaranteed - // to be the same as where it occurs, whereas `impl Trait`'s instance is location sensitive; - // so difference assertion should not be declared on impl-trait-type-alias's instances. - // for details, check RFC-2515: - // https://github.com/rust-lang/rfcs/blob/master/text/2515-type_alias_impl_trait.md - fn bop(_: T) { - super::take(|| {}); - super::take(|| {}); - } +pub type T = impl Sized; +// The concrete type referred by impl-trait-type-alias(`T`) is guaranteed +// to be the same as where it occurs, whereas `impl Trait`'s instance is location sensitive; +// so difference assertion should not be declared on impl-trait-type-alias's instances. +// for details, check RFC-2515: +// https://github.com/rust-lang/rfcs/blob/master/text/2515-type_alias_impl_trait.md + +#[define_opaques(T)] +fn bop() { + take(|| {}); + take(|| {}); } -use foo::*; fn take(_: fn() -> T) {} diff --git a/tests/ui/type-alias-impl-trait/issue-65918.rs b/tests/ui/type-alias-impl-trait/issue-65918.rs index 275b9717cef3..304ca42c270f 100644 --- a/tests/ui/type-alias-impl-trait/issue-65918.rs +++ b/tests/ui/type-alias-impl-trait/issue-65918.rs @@ -15,13 +15,11 @@ trait MyFrom: Sized { } /* MCVE starts here */ -mod f { - pub trait F {} - impl F for () {} - pub type DummyT = impl F; - fn _dummy_t() -> DummyT {} -} -use f::DummyT; +pub trait F {} +impl F for () {} +pub type DummyT = impl F; +#[define_opaques(DummyT)] +fn _dummy_t() -> DummyT {} struct Phantom1(PhantomData); struct Phantom2(PhantomData); diff --git a/tests/ui/type-alias-impl-trait/issue-66580-closure-coherence.rs b/tests/ui/type-alias-impl-trait/issue-66580-closure-coherence.rs index 0e3d01c2d618..da2d23ce079a 100644 --- a/tests/ui/type-alias-impl-trait/issue-66580-closure-coherence.rs +++ b/tests/ui/type-alias-impl-trait/issue-66580-closure-coherence.rs @@ -6,6 +6,7 @@ type Closure = impl FnOnce(); +#[define_opaques(Closure)] fn closure() -> Closure { || {} } diff --git a/tests/ui/type-alias-impl-trait/issue-67844-nested-opaque.rs b/tests/ui/type-alias-impl-trait/issue-67844-nested-opaque.rs index c320b0db31bb..e794c8d55fd9 100644 --- a/tests/ui/type-alias-impl-trait/issue-67844-nested-opaque.rs +++ b/tests/ui/type-alias-impl-trait/issue-67844-nested-opaque.rs @@ -22,6 +22,7 @@ impl WithAssoc for MyStruct { type AssocType = MyParam; } +#[define_opaques(Return)] fn my_fun() -> Return { MyStruct } diff --git a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.rs b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.rs index 9dcdb578568a..5fb06c02d304 100644 --- a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.rs +++ b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.rs @@ -6,9 +6,9 @@ trait Trait {} type Alias<'a, U> = impl Trait; +#[define_opaques(Alias)] fn f<'a>() -> Alias<'a, ()> {} -//~^ ERROR non-defining opaque type use -//~| ERROR expected generic type parameter, found `()` +//~^ ERROR expected generic type parameter, found `()` fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.stderr b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.stderr index 085bffe907b4..178aa5cf3453 100644 --- a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.stderr +++ b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use-2.stderr @@ -1,24 +1,12 @@ -error[E0792]: non-defining opaque type use in defining scope - --> $DIR/issue-68368-non-defining-use-2.rs:9:15 - | -LL | fn f<'a>() -> Alias<'a, ()> {} - | ^^^^^^^^^^^^^ argument `()` is not a generic parameter - | -note: for this opaque type - --> $DIR/issue-68368-non-defining-use-2.rs:7:21 - | -LL | type Alias<'a, U> = impl Trait; - | ^^^^^^^^^^^^^ - error[E0792]: expected generic type parameter, found `()` - --> $DIR/issue-68368-non-defining-use-2.rs:9:29 + --> $DIR/issue-68368-non-defining-use-2.rs:10:29 | LL | type Alias<'a, U> = impl Trait; | - this generic parameter must be used with a generic type parameter -LL | +... LL | fn f<'a>() -> Alias<'a, ()> {} | ^^ -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0792`. diff --git a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs index dfe2ee8204c7..7c9aac74fc5d 100644 --- a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs +++ b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.rs @@ -6,9 +6,9 @@ trait Trait {} type Alias<'a, U> = impl Trait; +#[define_opaques(Alias)] fn f<'a>() -> Alias<'a, ()> {} //~^ ERROR expected generic type parameter, found `()` -//~| ERROR non-defining opaque type use fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr index ea704ffff97a..bfbd506a7a5c 100644 --- a/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr +++ b/tests/ui/type-alias-impl-trait/issue-68368-non-defining-use.stderr @@ -1,24 +1,12 @@ -error[E0792]: non-defining opaque type use in defining scope - --> $DIR/issue-68368-non-defining-use.rs:9:15 - | -LL | fn f<'a>() -> Alias<'a, ()> {} - | ^^^^^^^^^^^^^ argument `()` is not a generic parameter - | -note: for this opaque type - --> $DIR/issue-68368-non-defining-use.rs:7:21 - | -LL | type Alias<'a, U> = impl Trait; - | ^^^^^^^^^^^^^ - error[E0792]: expected generic type parameter, found `()` - --> $DIR/issue-68368-non-defining-use.rs:9:29 + --> $DIR/issue-68368-non-defining-use.rs:10:29 | LL | type Alias<'a, U> = impl Trait; | - this generic parameter must be used with a generic type parameter -LL | +... LL | fn f<'a>() -> Alias<'a, ()> {} | ^^ -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0792`. diff --git a/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.rs b/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.rs index a0f8e48e268c..20992cba3bec 100644 --- a/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.rs +++ b/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.rs @@ -19,6 +19,7 @@ impl WithAssoc for () { type Return = impl WithAssoc; //~^ ERROR use of undeclared lifetime name `'a` +#[define_opaques(Return)] fn my_fun() -> Return {} fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-ok.rs b/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-ok.rs index 8e631fd1b6a3..b53dc4b083ab 100644 --- a/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-ok.rs +++ b/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-ok.rs @@ -18,6 +18,7 @@ impl WithAssoc for () { type Return<'a> = impl WithAssoc; +#[define_opaques(Return)] fn my_fun<'a>() -> Return<'a> {} fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-69323.rs b/tests/ui/type-alias-impl-trait/issue-69323.rs index 18bc4cf91787..f671519f2b4b 100644 --- a/tests/ui/type-alias-impl-trait/issue-69323.rs +++ b/tests/ui/type-alias-impl-trait/issue-69323.rs @@ -9,6 +9,7 @@ fn test1>(x: A) -> Chain = Chain>; +#[define_opaques(I)] fn test2>(x: A) -> I { x.chain(once(",")) } diff --git a/tests/ui/type-alias-impl-trait/issue-70121.rs b/tests/ui/type-alias-impl-trait/issue-70121.rs index b90bd312a0ba..93720cf40e05 100644 --- a/tests/ui/type-alias-impl-trait/issue-70121.rs +++ b/tests/ui/type-alias-impl-trait/issue-70121.rs @@ -2,6 +2,7 @@ pub type Successors<'a> = impl Iterator; +#[define_opaques(Successors)] pub fn f<'a>() -> Successors<'a> { None.into_iter() } diff --git a/tests/ui/type-alias-impl-trait/issue-70121.stderr b/tests/ui/type-alias-impl-trait/issue-70121.stderr index ed2eb17fbead..7fc2cc23fa1a 100644 --- a/tests/ui/type-alias-impl-trait/issue-70121.stderr +++ b/tests/ui/type-alias-impl-trait/issue-70121.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-70121.rs:18:5 + --> $DIR/issue-70121.rs:19:5 | LL | pub type Successors<'a> = impl Iterator; | ---------------------------- the expected opaque type @@ -11,8 +11,8 @@ LL | None.into_iter() | = note: expected opaque type `Successors<'a>` found struct `std::option::IntoIter<_>` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/issue-70121.rs:17:8 +note: this item must have a `#[define_opaques(Successors)]` attribute to be able to define hidden types + --> $DIR/issue-70121.rs:18:8 | LL | pub fn kazusa<'a>() -> <&'a () as Tr>::Item { | ^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/issue-72793.rs b/tests/ui/type-alias-impl-trait/issue-72793.rs index 0353b7f3787b..54a2e81dd2d1 100644 --- a/tests/ui/type-alias-impl-trait/issue-72793.rs +++ b/tests/ui/type-alias-impl-trait/issue-72793.rs @@ -3,24 +3,21 @@ #![feature(type_alias_impl_trait)] -mod foo { - pub trait T { - type Item; - } - - pub type Alias<'a> = impl T; +pub trait T { + type Item; +} - struct S; - impl<'a> T for &'a S { - type Item = &'a (); - } +pub type Alias<'a> = impl T; - pub fn filter_positive<'a>() -> Alias<'a> { - &S - } +struct S; +impl<'a> T for &'a S { + type Item = &'a (); } -use foo::*; +#[define_opaques(Alias)] +pub fn filter_positive<'a>() -> Alias<'a> { + &S +} fn with_positive(fun: impl Fn(Alias<'_>)) { fun(filter_positive()); diff --git a/tests/ui/type-alias-impl-trait/issue-74244.rs b/tests/ui/type-alias-impl-trait/issue-74244.rs index bb4104b3d251..d87a0285aa06 100644 --- a/tests/ui/type-alias-impl-trait/issue-74244.rs +++ b/tests/ui/type-alias-impl-trait/issue-74244.rs @@ -13,6 +13,7 @@ impl Allocator for DefaultAllocator { type A = impl Fn(::Buffer); +#[define_opaques(A)] fn foo() -> A { |_| () } diff --git a/tests/ui/type-alias-impl-trait/issue-74280.rs b/tests/ui/type-alias-impl-trait/issue-74280.rs index ad641eaa00d3..5f6739775837 100644 --- a/tests/ui/type-alias-impl-trait/issue-74280.rs +++ b/tests/ui/type-alias-impl-trait/issue-74280.rs @@ -4,6 +4,7 @@ type Test = impl Copy; +#[define_opaques(Test)] fn test() -> Test { let y = || -> Test { () }; 7 //~ ERROR mismatched types diff --git a/tests/ui/type-alias-impl-trait/issue-74280.stderr b/tests/ui/type-alias-impl-trait/issue-74280.stderr index c09efbe4e133..a89a3f77b3d5 100644 --- a/tests/ui/type-alias-impl-trait/issue-74280.stderr +++ b/tests/ui/type-alias-impl-trait/issue-74280.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-74280.rs:9:5 + --> $DIR/issue-74280.rs:10:5 | LL | fn test() -> Test { | ---- expected `()` because of return type diff --git a/tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs b/tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs index 90ab4fd8d977..cb2f42a841af 100644 --- a/tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs +++ b/tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs @@ -7,19 +7,17 @@ //@ check-pass #![feature(type_alias_impl_trait)] -mod g { - pub trait Dummy {} - impl Dummy for () {} - pub type F = impl Dummy; - pub fn f() -> F {} -} -use g::*; +pub trait Dummy {} +impl Dummy for () {} +pub type F = impl Dummy; +#[define_opaques(F)] +pub fn f() -> F {} trait Test { fn test(self); } -impl Test for define::F { +impl Test for F { fn test(self) {} } @@ -29,17 +27,14 @@ impl Test for i32 { fn test(self) {} } -mod define { - use super::*; - - pub trait Dummy {} - impl Dummy for () {} +pub trait Dummy2 {} +impl Dummy2 for () {} - pub type F = impl Dummy; - pub fn f() -> F {} -} +pub type F2 = impl Dummy2; +#[define_opaques(F2)] +pub fn f2() -> F2 {} fn main() { - let x = define::f(); + let x = f(); x.test(); } diff --git a/tests/ui/type-alias-impl-trait/issue-77179.rs b/tests/ui/type-alias-impl-trait/issue-77179.rs index 1dc74c6b5fea..f163e60e1c44 100644 --- a/tests/ui/type-alias-impl-trait/issue-77179.rs +++ b/tests/ui/type-alias-impl-trait/issue-77179.rs @@ -4,10 +4,11 @@ type Pointer = impl std::ops::Deref; +#[define_opaques(Pointer)] fn test() -> Pointer<_> { //~^ ERROR: the placeholder `_` is not allowed within types Box::new(1) - //~^ ERROR: mismatched types + //~^ ERROR: expected generic type parameter, found `i32` } fn main() { diff --git a/tests/ui/type-alias-impl-trait/issue-77179.stderr b/tests/ui/type-alias-impl-trait/issue-77179.stderr index 16bbc996d909..bc11283f3282 100644 --- a/tests/ui/type-alias-impl-trait/issue-77179.stderr +++ b/tests/ui/type-alias-impl-trait/issue-77179.stderr @@ -1,36 +1,28 @@ -error[E0308]: mismatched types - --> $DIR/issue-77179.rs:9:5 - | -LL | type Pointer = impl std::ops::Deref; - | -------------------------------- the expected opaque type -LL | -LL | fn test() -> Pointer<_> { - | ---------- expected `Pointer<_>` because of return type -LL | -LL | Box::new(1) - | ^^^^^^^^^^^ expected opaque type, found `Box<{integer}>` - | - = note: expected opaque type `Pointer<_>` - found struct `Box<{integer}>` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/issue-77179.rs:7:4 - | -LL | fn test() -> Pointer<_> { - | ^^^^ - error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/issue-77179.rs:7:22 + --> $DIR/issue-77179.rs:8:22 | LL | fn test() -> Pointer<_> { - | ^ not allowed in type signatures + | --------^- + | | | + | | not allowed in type signatures + | help: replace with the correct return type: `Pointer` error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/issue-77179.rs:18:25 + --> $DIR/issue-77179.rs:19:25 | LL | fn bar() -> Pointer<_>; | ^ not allowed in type signatures +error[E0792]: expected generic type parameter, found `i32` + --> $DIR/issue-77179.rs:10:5 + | +LL | type Pointer = impl std::ops::Deref; + | - this generic parameter must be used with a generic type parameter +... +LL | Box::new(1) + | ^^^^^^^^^^^ + error: aborting due to 3 previous errors -Some errors have detailed explanations: E0121, E0308. +Some errors have detailed explanations: E0121, E0792. For more information about an error, try `rustc --explain E0121`. diff --git a/tests/ui/type-alias-impl-trait/issue-84660-trait-impl-for-tait.rs b/tests/ui/type-alias-impl-trait/issue-84660-trait-impl-for-tait.rs index 2a39da1176c3..5a2b1192b3d3 100644 --- a/tests/ui/type-alias-impl-trait/issue-84660-trait-impl-for-tait.rs +++ b/tests/ui/type-alias-impl-trait/issue-84660-trait-impl-for-tait.rs @@ -8,6 +8,7 @@ trait Foo {} impl Foo for () {} type Bar = impl Foo; +#[define_opaques(Bar)] fn _defining_use() -> Bar {} trait TraitArg { diff --git a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.current.stderr b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.current.stderr index ec7b9e0e12b3..ea55a9594f2a 100644 --- a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.current.stderr +++ b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.current.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Trait` - --> $DIR/issue-84660-unsoundness.rs:29:1 + --> $DIR/issue-84660-unsoundness.rs:31:1 | LL | impl Trait for Out { | ------------------------------------ first implementation here @@ -8,7 +8,7 @@ LL | impl Trait<(), In> for Out { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation error: item does not constrain `Bar::{opaque#0}`, but has it in its signature - --> $DIR/issue-84660-unsoundness.rs:22:8 + --> $DIR/issue-84660-unsoundness.rs:24:8 | LL | fn convert(_i: In) -> Self::Out { | ^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr index e33102f687c5..9e83de5375fd 100644 --- a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr +++ b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Trait` - --> $DIR/issue-84660-unsoundness.rs:29:1 + --> $DIR/issue-84660-unsoundness.rs:31:1 | LL | impl Trait for Out { | ------------------------------------ first implementation here @@ -8,7 +8,7 @@ LL | impl Trait<(), In> for Out { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation error[E0284]: type annotations needed: cannot satisfy `Bar == _` - --> $DIR/issue-84660-unsoundness.rs:22:37 + --> $DIR/issue-84660-unsoundness.rs:24:37 | LL | fn convert(_i: In) -> Self::Out { | _____________________________________^ diff --git a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs index f3234bafd115..989b55b9132b 100644 --- a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs +++ b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.rs @@ -10,6 +10,7 @@ trait Foo {} impl Foo for () {} type Bar = impl Foo; +#[define_opaques(Bar)] fn _defining_use() -> Bar {} trait Trait { @@ -19,6 +20,7 @@ trait Trait { impl Trait for Out { type Out = Out; + #[define_opaques(Bar)] fn convert(_i: In) -> Self::Out { //[next]~^ ERROR: cannot satisfy `Bar == _` //[current]~^^ ERROR: item does not constrain `Bar::{opaque#0}`, but has it in its signature diff --git a/tests/ui/type-alias-impl-trait/issue-89686.rs b/tests/ui/type-alias-impl-trait/issue-89686.rs index f734c518dd21..b193aa47ae4d 100644 --- a/tests/ui/type-alias-impl-trait/issue-89686.rs +++ b/tests/ui/type-alias-impl-trait/issue-89686.rs @@ -11,6 +11,7 @@ trait Trait { fn f(&self) -> Self::F; + #[define_opaques(G)] fn g<'a>(&'a self) -> G<'a, Self> where Self: Sized, diff --git a/tests/ui/type-alias-impl-trait/issue-89686.stderr b/tests/ui/type-alias-impl-trait/issue-89686.stderr index 6fa7e197c40c..7ad1442f666c 100644 --- a/tests/ui/type-alias-impl-trait/issue-89686.stderr +++ b/tests/ui/type-alias-impl-trait/issue-89686.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `T: Trait` is not satisfied - --> $DIR/issue-89686.rs:18:9 + --> $DIR/issue-89686.rs:19:9 | LL | async move { self.f().await } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` diff --git a/tests/ui/type-alias-impl-trait/issue-93411.rs b/tests/ui/type-alias-impl-trait/issue-93411.rs index 2d08b7ba4c11..1a6b35b6fff3 100644 --- a/tests/ui/type-alias-impl-trait/issue-93411.rs +++ b/tests/ui/type-alias-impl-trait/issue-93411.rs @@ -14,6 +14,7 @@ fn main() { } type BlahFut<'a> = impl Future + Send + 'a; +#[define_opaques(BlahFut)] fn blah<'a>(_value: &'a u8) -> BlahFut<'a> { async {} } diff --git a/tests/ui/type-alias-impl-trait/issue-96572-unconstrained.rs b/tests/ui/type-alias-impl-trait/issue-96572-unconstrained.rs index 7097123d608c..04d53c8ebc10 100644 --- a/tests/ui/type-alias-impl-trait/issue-96572-unconstrained.rs +++ b/tests/ui/type-alias-impl-trait/issue-96572-unconstrained.rs @@ -44,6 +44,7 @@ fn r#struct() { mod only_pattern { type T = impl Copy; + #[define_opaques(T)] fn foo(foo: T) { let (mut x, mut y) = foo; x = 42; @@ -52,6 +53,7 @@ mod only_pattern { type U = impl Copy; + #[define_opaques(U)] fn bar(bar: Option) { match bar { Some((mut x, mut y)) => { @@ -64,6 +66,7 @@ mod only_pattern { type V = impl Copy; + #[define_opaques(V)] fn baz(baz: Option) { match baz { _ => {} diff --git a/tests/ui/type-alias-impl-trait/itiat-forbid-nested-items.stderr b/tests/ui/type-alias-impl-trait/itiat-forbid-nested-items.stderr index c177201431a6..17271dda020a 100644 --- a/tests/ui/type-alias-impl-trait/itiat-forbid-nested-items.stderr +++ b/tests/ui/type-alias-impl-trait/itiat-forbid-nested-items.stderr @@ -11,7 +11,7 @@ LL | let x: <() as Foo>::Assoc = 42_i32; | = note: expected opaque type `<() as Foo>::Assoc` found type `i32` -note: this item must have the opaque type in its signature in order to be able to register hidden types +note: this item must have a `#[define_opaques(<() as Foo>::Assoc)]` attribute to be able to define hidden types --> $DIR/itiat-forbid-nested-items.rs:11:12 | LL | fn foo() -> <() as Foo>::Assoc { diff --git a/tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.rs b/tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.rs index 1bc352041a57..813b7b3c8f86 100644 --- a/tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.rs +++ b/tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.rs @@ -6,6 +6,7 @@ type Tait = impl FnOnce() -> (); +#[define_opaques(Tait)] fn reify_as_tait() -> Thunk { //~^ ERROR: expected a `FnOnce()` closure, found `()` Thunk::new(|cont| cont) diff --git a/tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.stderr b/tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.stderr index 921667f577b4..0bee0dfa9c7a 100644 --- a/tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.stderr +++ b/tests/ui/type-alias-impl-trait/lazy_subtyping_of_opaques.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/lazy_subtyping_of_opaques.rs:11:5 + --> $DIR/lazy_subtyping_of_opaques.rs:12:5 | LL | fn reify_as_tait() -> Thunk { | ----------- expected `Thunk<_>` because of return type @@ -11,7 +11,7 @@ LL | Thunk::new(|cont| cont) found unit type `()` error[E0277]: expected a `FnOnce()` closure, found `()` - --> $DIR/lazy_subtyping_of_opaques.rs:11:23 + --> $DIR/lazy_subtyping_of_opaques.rs:12:23 | LL | Thunk::new(|cont| cont) | ^^^^ expected an `FnOnce()` closure, found `()` @@ -20,7 +20,7 @@ LL | Thunk::new(|cont| cont) = note: wrap the `()` in a closure with no arguments: `|| { /* code */ }` error[E0277]: expected a `FnOnce()` closure, found `()` - --> $DIR/lazy_subtyping_of_opaques.rs:9:23 + --> $DIR/lazy_subtyping_of_opaques.rs:10:23 | LL | fn reify_as_tait() -> Thunk { | ^^^^^^^^^^^ expected an `FnOnce()` closure, found `()` diff --git a/tests/ui/type-alias-impl-trait/lifetime_mismatch.rs b/tests/ui/type-alias-impl-trait/lifetime_mismatch.rs index 45a55050c443..7d0ab074b0f4 100644 --- a/tests/ui/type-alias-impl-trait/lifetime_mismatch.rs +++ b/tests/ui/type-alias-impl-trait/lifetime_mismatch.rs @@ -2,6 +2,7 @@ type Foo<'a> = impl Sized; +#[define_opaques(Foo)] fn foo<'a, 'b>(x: &'a u32, y: &'b u32) -> (Foo<'a>, Foo<'b>) { (x, y) //~^ ERROR opaque type used twice with different lifetimes @@ -9,6 +10,7 @@ fn foo<'a, 'b>(x: &'a u32, y: &'b u32) -> (Foo<'a>, Foo<'b>) { type Bar<'a, 'b> = impl std::fmt::Debug; +#[define_opaques(Bar)] fn bar<'x, 'y>(i: &'x i32, j: &'y i32) -> (Bar<'x, 'y>, Bar<'y, 'x>) { (i, j) //~^ ERROR opaque type used twice with different lifetimes diff --git a/tests/ui/type-alias-impl-trait/lifetime_mismatch.stderr b/tests/ui/type-alias-impl-trait/lifetime_mismatch.stderr index 4f7b0f174076..719748edc011 100644 --- a/tests/ui/type-alias-impl-trait/lifetime_mismatch.stderr +++ b/tests/ui/type-alias-impl-trait/lifetime_mismatch.stderr @@ -1,5 +1,5 @@ error: opaque type used twice with different lifetimes - --> $DIR/lifetime_mismatch.rs:6:5 + --> $DIR/lifetime_mismatch.rs:7:5 | LL | (x, y) | ^^^^^^ @@ -8,13 +8,13 @@ LL | (x, y) | lifetime `'b` previously used here | note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types - --> $DIR/lifetime_mismatch.rs:6:5 + --> $DIR/lifetime_mismatch.rs:7:5 | LL | (x, y) | ^^^^^^ error: opaque type used twice with different lifetimes - --> $DIR/lifetime_mismatch.rs:13:5 + --> $DIR/lifetime_mismatch.rs:15:5 | LL | (i, j) | ^^^^^^ @@ -23,7 +23,7 @@ LL | (i, j) | lifetime `'y` previously used here | note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types - --> $DIR/lifetime_mismatch.rs:13:5 + --> $DIR/lifetime_mismatch.rs:15:5 | LL | (i, j) | ^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/method_resolution.current.stderr b/tests/ui/type-alias-impl-trait/method_resolution.current.stderr index a9c05ad33424..07e7126f8a05 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution.current.stderr +++ b/tests/ui/type-alias-impl-trait/method_resolution.current.stderr @@ -1,5 +1,5 @@ error[E0599]: no method named `bar` found for struct `Bar` in the current scope - --> $DIR/method_resolution.rs:21:14 + --> $DIR/method_resolution.rs:22:14 | LL | struct Bar(T); | ------------- method `bar` not found for this struct diff --git a/tests/ui/type-alias-impl-trait/method_resolution.next.stderr b/tests/ui/type-alias-impl-trait/method_resolution.next.stderr index 6b34358a56ea..7462d2b478bb 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution.next.stderr +++ b/tests/ui/type-alias-impl-trait/method_resolution.next.stderr @@ -1,5 +1,5 @@ error[E0599]: no method named `bar` found for struct `Bar` in the current scope - --> $DIR/method_resolution.rs:21:14 + --> $DIR/method_resolution.rs:22:14 | LL | struct Bar(T); | ------------- method `bar` not found for this struct diff --git a/tests/ui/type-alias-impl-trait/method_resolution.rs b/tests/ui/type-alias-impl-trait/method_resolution.rs index f636aba15c0c..0b2d553b21c6 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution.rs +++ b/tests/ui/type-alias-impl-trait/method_resolution.rs @@ -11,6 +11,7 @@ type Foo = impl Sized; struct Bar(T); impl Bar { + #[define_opaques(Foo)] fn bar(mut self) { self.0 = 42_u32; } @@ -23,6 +24,7 @@ impl Bar { } } +#[define_opaques(Foo)] fn foo() -> Foo { 42_u32 } diff --git a/tests/ui/type-alias-impl-trait/method_resolution2.rs b/tests/ui/type-alias-impl-trait/method_resolution2.rs index f69661db7992..d5f72ebc4744 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution2.rs +++ b/tests/ui/type-alias-impl-trait/method_resolution2.rs @@ -12,6 +12,7 @@ type Foo = impl Sized; struct Bar(T); impl Bar { + #[define_opaques(Foo)] fn bar(self) { self.foo() } @@ -21,6 +22,7 @@ impl Bar { fn foo(self) {} } +#[define_opaques(Foo)] fn foo() -> Foo { 42_u32 } diff --git a/tests/ui/type-alias-impl-trait/method_resolution3.rs b/tests/ui/type-alias-impl-trait/method_resolution3.rs index 0e6176bfe03c..363651283ef6 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution3.rs +++ b/tests/ui/type-alias-impl-trait/method_resolution3.rs @@ -27,6 +27,7 @@ impl Bar { fn foo(self) {} } +#[define_opaques(Foo)] fn foo() -> Foo { 42_u32 } diff --git a/tests/ui/type-alias-impl-trait/method_resolution4.current.stderr b/tests/ui/type-alias-impl-trait/method_resolution4.current.stderr index e4c4d121733b..569a9f49bbe4 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution4.current.stderr +++ b/tests/ui/type-alias-impl-trait/method_resolution4.current.stderr @@ -1,5 +1,5 @@ error[E0307]: invalid `self` parameter type: `Bar` - --> $DIR/method_resolution4.rs:27:18 + --> $DIR/method_resolution4.rs:25:18 | LL | fn foo(self: Bar) { | ^^^^^^^^ @@ -8,7 +8,7 @@ LL | fn foo(self: Bar) { = help: consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box`, `self: Rc`, or `self: Arc` error[E0307]: invalid `self` parameter type: `&Bar` - --> $DIR/method_resolution4.rs:31:20 + --> $DIR/method_resolution4.rs:29:20 | LL | fn foomp(self: &Bar) { | ^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/method_resolution4.next.stderr b/tests/ui/type-alias-impl-trait/method_resolution4.next.stderr index e4c4d121733b..569a9f49bbe4 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution4.next.stderr +++ b/tests/ui/type-alias-impl-trait/method_resolution4.next.stderr @@ -1,5 +1,5 @@ error[E0307]: invalid `self` parameter type: `Bar` - --> $DIR/method_resolution4.rs:27:18 + --> $DIR/method_resolution4.rs:25:18 | LL | fn foo(self: Bar) { | ^^^^^^^^ @@ -8,7 +8,7 @@ LL | fn foo(self: Bar) { = help: consider changing to `self`, `&self`, `&mut self`, or a type implementing `Receiver` such as `self: Box`, `self: Rc`, or `self: Arc` error[E0307]: invalid `self` parameter type: `&Bar` - --> $DIR/method_resolution4.rs:31:20 + --> $DIR/method_resolution4.rs:29:20 | LL | fn foomp(self: &Bar) { | ^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/method_resolution4.rs b/tests/ui/type-alias-impl-trait/method_resolution4.rs index f33b4e473ae8..6346f38b9c35 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution4.rs +++ b/tests/ui/type-alias-impl-trait/method_resolution4.rs @@ -7,14 +7,12 @@ #![feature(type_alias_impl_trait, arbitrary_self_types)] -mod foo { - pub type Foo = impl Copy; +pub type Foo = impl Copy; - fn foo() -> Foo { - 42_u32 - } +#[define_opaques(Foo)] +fn foo() -> Foo { + 42_u32 } -use foo::Foo; #[derive(Copy, Clone)] struct Bar(T); diff --git a/tests/ui/type-alias-impl-trait/method_resolution5.rs b/tests/ui/type-alias-impl-trait/method_resolution5.rs index 64355e4560de..9f35c3534191 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution5.rs +++ b/tests/ui/type-alias-impl-trait/method_resolution5.rs @@ -12,20 +12,20 @@ type Foo = impl Sized; struct Bar(T); impl Bar { + #[define_opaques(Foo)] fn bar(mut self) { self.0 = 42_u32; } } impl Bar { - fn foo(self) - where - Foo:, - { + #[define_opaques(Foo)] + fn foo(self) { self.bar() } } +#[define_opaques(Foo)] fn foo() -> Foo { 42_u32 } diff --git a/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.current.stderr b/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.current.stderr index f331da1af879..3012ba2354e1 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.current.stderr +++ b/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.current.stderr @@ -1,5 +1,5 @@ error: item does not constrain `Tait::{opaque#0}`, but has it in its signature - --> $DIR/method_resolution_trait_method_from_opaque.rs:24:8 + --> $DIR/method_resolution_trait_method_from_opaque.rs:26:8 | LL | fn foo(&mut self) { | ^^^ diff --git a/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr b/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr index 2617ce124c10..bbdd3923821f 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr +++ b/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed - --> $DIR/method_resolution_trait_method_from_opaque.rs:26:9 + --> $DIR/method_resolution_trait_method_from_opaque.rs:28:9 | LL | self.bar.next().unwrap(); | ^^^^^^^^ cannot infer type diff --git a/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.rs b/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.rs index b6adf08853f2..3e717ec4d0cd 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.rs +++ b/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.rs @@ -17,10 +17,12 @@ pub struct Foo { type Tait = impl Iterator; impl Foo { + #[define_opaques(Tait)] pub fn new() -> Foo { Foo { bar: std::iter::empty() } } + #[define_opaques(Tait)] fn foo(&mut self) { //[current]~^ ERROR: item does not constrain self.bar.next().unwrap(); diff --git a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.rs b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.rs index c178fcf5a914..ee1bba4dced6 100644 --- a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.rs +++ b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.rs @@ -2,6 +2,7 @@ type Opaque2 = impl Sized; type Opaque<'a, T> = Opaque2; +#[define_opaques(Opaque)] fn defining<'a, T>(x: &'a i32) -> Opaque { x } //~ WARNING elided lifetime has a name //~^ ERROR: hidden type for `Opaque2` captures lifetime that does not appear in bounds diff --git a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr index e2c21f1636b0..61eb76ffc5ae 100644 --- a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr +++ b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr @@ -1,5 +1,5 @@ warning: elided lifetime has a name - --> $DIR/missing_lifetime_bound.rs:5:41 + --> $DIR/missing_lifetime_bound.rs:6:41 | LL | fn defining<'a, T>(x: &'a i32) -> Opaque { x } | -- ^ this elided lifetime gets resolved as `'a` @@ -9,11 +9,11 @@ LL | fn defining<'a, T>(x: &'a i32) -> Opaque { x } = note: `#[warn(elided_named_lifetimes)]` on by default error[E0700]: hidden type for `Opaque2` captures lifetime that does not appear in bounds - --> $DIR/missing_lifetime_bound.rs:5:47 + --> $DIR/missing_lifetime_bound.rs:6:47 | LL | type Opaque2 = impl Sized; | ---------- opaque type defined here -LL | type Opaque<'a, T> = Opaque2; +... LL | fn defining<'a, T>(x: &'a i32) -> Opaque { x } | -- ^ | | diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-infer.rs b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-infer.rs index b887fcf30831..b168451f9d46 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-infer.rs +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-infer.rs @@ -6,6 +6,7 @@ type Y = impl std::fmt::Debug; +#[define_opaques(Y)] fn g() -> (Y, Y) { (42_i64, 60) //~ ERROR concrete type differs from previous defining opaque type use } diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-infer.stderr b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-infer.stderr index b050b08a8e2e..d6558576577f 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-infer.stderr +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-infer.stderr @@ -1,5 +1,5 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/multiple-def-uses-in-one-fn-infer.rs:10:5 + --> $DIR/multiple-def-uses-in-one-fn-infer.rs:11:5 | LL | (42_i64, 60) | ^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs index 580fb58ef838..6b4bbdda324a 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.rs @@ -2,6 +2,7 @@ type Foo<'a, 'b> = impl std::fmt::Debug; +#[define_opaques(Foo)] fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) { (i, j) //~^ ERROR opaque type used twice with different lifetimes diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr index b2b9e604a6b6..03f2b1c532a0 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-lifetimes.stderr @@ -1,5 +1,5 @@ error: opaque type used twice with different lifetimes - --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 + --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:7:5 | LL | (i, j) | ^^^^^^ @@ -8,7 +8,7 @@ LL | (i, j) | lifetime `'y` previously used here | note: if all non-lifetime generic parameters are the same, but the lifetime parameters differ, it is not possible to differentiate the opaque types - --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:6:5 + --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:7:5 | LL | (i, j) | ^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs index aba41a9d8523..6bdeabb70d7e 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn-pass.rs @@ -3,11 +3,13 @@ type X = impl ToString; +#[define_opaques(X)] fn f(a: A, b: B) -> (X, X) { (a.clone(), a) } type Tait<'x> = impl Sized; +#[define_opaques(Tait)] fn define<'a: 'b, 'b: 'a>(x: &'a u8, y: &'b u8) -> (Tait<'a>, Tait<'b>) { ((), ()) } diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs index da845e86147b..3bd952db8e57 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.rs @@ -6,6 +6,7 @@ type X = impl Into<&'static A>; +#[define_opaques(X)] fn f(a: &'static A, b: B) -> (X, X) { //~^ ERROR the trait bound `&'static B: From<&A>` is not satisfied (a, a) diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr index b5f38074632e..05a169882cb1 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `&'static B: From<&A>` is not satisfied - --> $DIR/multiple-def-uses-in-one-fn.rs:9:45 + --> $DIR/multiple-def-uses-in-one-fn.rs:10:45 | LL | fn f(a: &'static A, b: B) -> (X, X) { | ^^^^^^^^^^^^^^^^^^ the trait `From<&A>` is not implemented for `&'static B` diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn2.rs b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn2.rs index 14510a5294e6..1ced760ee5d0 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn2.rs +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn2.rs @@ -6,6 +6,7 @@ type X = impl ToString; +#[define_opaques(X)] fn f(a: A, b: B) -> (X, X) { (a.clone(), a) //~^ ERROR concrete type differs from previous defining opaque type diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn2.stderr b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn2.stderr index c7a4b2115bf2..15e9b6fbf761 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn2.stderr +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn2.stderr @@ -1,5 +1,5 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/multiple-def-uses-in-one-fn2.rs:10:5 + --> $DIR/multiple-def-uses-in-one-fn2.rs:11:5 | LL | (a.clone(), a) | ^^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.rs b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.rs index 11a922443e64..b011dae62c1c 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.rs +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.rs @@ -6,10 +6,12 @@ type X = impl ToString; +#[define_opaques(X)] fn f(a: A, b: B) -> (X, X) { (a, b) } +#[define_opaques(X)] fn g(a: A, b: B) -> (X, X) { (a, b) //~^ ERROR mismatched types diff --git a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.stderr b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.stderr index c3128ea6f5e9..42ba769797b7 100644 --- a/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.stderr +++ b/tests/ui/type-alias-impl-trait/multiple-def-uses-in-one-fn3.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/multiple-def-uses-in-one-fn3.rs:14:9 + --> $DIR/multiple-def-uses-in-one-fn3.rs:16:9 | LL | fn g(a: A, b: B) -> (X, X) { | - - found type parameter diff --git a/tests/ui/type-alias-impl-trait/nested-impl-trait-in-tait.stderr b/tests/ui/type-alias-impl-trait/nested-impl-trait-in-tait.stderr index ca15b134a994..3a13ab7cb957 100644 --- a/tests/ui/type-alias-impl-trait/nested-impl-trait-in-tait.stderr +++ b/tests/ui/type-alias-impl-trait/nested-impl-trait-in-tait.stderr @@ -31,7 +31,7 @@ error: unconstrained opaque type LL | pub type Tait = impl Iterator; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `Tait` must be used in combination with a concrete type within the same module + = note: `Tait` must be used in combination with a concrete type within the same crate error: unconstrained opaque type --> $DIR/nested-impl-trait-in-tait.rs:3:54 @@ -39,7 +39,7 @@ error: unconstrained opaque type LL | pub type Tait = impl Iterator; | ^^^^^^^^^^^^^ | - = note: `Tait` must be used in combination with a concrete type within the same module + = note: `Tait` must be used in combination with a concrete type within the same crate error: aborting due to 4 previous errors diff --git a/tests/ui/type-alias-impl-trait/nested-in-anon-const.stderr b/tests/ui/type-alias-impl-trait/nested-in-anon-const.stderr index aa0c1076117c..54389efc9c6d 100644 --- a/tests/ui/type-alias-impl-trait/nested-in-anon-const.stderr +++ b/tests/ui/type-alias-impl-trait/nested-in-anon-const.stderr @@ -13,7 +13,7 @@ error: unconstrained opaque type LL | type B = impl Sized; | ^^^^^^^^^^ | - = note: `B` must be used in combination with a concrete type within the same item + = note: `B` must be used in combination with a concrete type within the same crate error: aborting due to 2 previous errors diff --git a/tests/ui/type-alias-impl-trait/nested-tait-hrtb.rs b/tests/ui/type-alias-impl-trait/nested-tait-hrtb.rs index ba705d6f85ac..6094d8636b26 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-hrtb.rs +++ b/tests/ui/type-alias-impl-trait/nested-tait-hrtb.rs @@ -4,11 +4,13 @@ trait Trait<'a> { type Assoc; } impl<'a> Trait<'a> for () { type Assoc = &'a str; } type WithoutLt = impl Sized; +#[define_opaques(WithoutLt)] fn without_lt() -> impl for<'a> Trait<'a, Assoc = WithoutLt> {} //~^ ERROR captures lifetime that does not appear in bounds type WithLt<'a> = impl Sized + 'a; +#[define_opaques(WithLt)] fn with_lt() -> impl for<'a> Trait<'a, Assoc = WithLt<'a>> {} //~^ ERROR expected generic lifetime parameter, found `'a` diff --git a/tests/ui/type-alias-impl-trait/nested-tait-hrtb.stderr b/tests/ui/type-alias-impl-trait/nested-tait-hrtb.stderr index f208730552d9..479c75bdb7e2 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-hrtb.stderr +++ b/tests/ui/type-alias-impl-trait/nested-tait-hrtb.stderr @@ -1,19 +1,20 @@ error[E0700]: hidden type for `WithoutLt` captures lifetime that does not appear in bounds - --> $DIR/nested-tait-hrtb.rs:7:62 + --> $DIR/nested-tait-hrtb.rs:8:62 | LL | type WithoutLt = impl Sized; | ---------- opaque type defined here +LL | #[define_opaques(WithoutLt)] LL | fn without_lt() -> impl for<'a> Trait<'a, Assoc = WithoutLt> {} | -- ^^ | | | hidden type `&'a str` captures the lifetime `'a` as defined here error[E0792]: expected generic lifetime parameter, found `'a` - --> $DIR/nested-tait-hrtb.rs:12:60 + --> $DIR/nested-tait-hrtb.rs:14:60 | LL | type WithLt<'a> = impl Sized + 'a; | -- this generic parameter must be used with a generic lifetime parameter -LL | +... LL | fn with_lt() -> impl for<'a> Trait<'a, Assoc = WithLt<'a>> {} | ^^ diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference.current.stderr b/tests/ui/type-alias-impl-trait/nested-tait-inference.current.stderr index 915432bbe675..b19f34a67ff7 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-inference.current.stderr +++ b/tests/ui/type-alias-impl-trait/nested-tait-inference.current.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `(): Foo` is not satisfied - --> $DIR/nested-tait-inference.rs:17:13 + --> $DIR/nested-tait-inference.rs:18:13 | LL | fn foo() -> impl Foo { | ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `()` diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference.rs b/tests/ui/type-alias-impl-trait/nested-tait-inference.rs index 50d51c7faf91..843b6dd60343 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-inference.rs +++ b/tests/ui/type-alias-impl-trait/nested-tait-inference.rs @@ -14,6 +14,7 @@ trait Foo {} impl Foo<()> for () {} +#[define_opaques(FooX)] fn foo() -> impl Foo { //[current]~^ ERROR: the trait bound `(): Foo` is not satisfied // FIXME(type-alias-impl-trait): We could probably make this work. diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference2.current.stderr b/tests/ui/type-alias-impl-trait/nested-tait-inference2.current.stderr index 9da3926ac708..27372ceed949 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-inference2.current.stderr +++ b/tests/ui/type-alias-impl-trait/nested-tait-inference2.current.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `(): Foo` is not satisfied - --> $DIR/nested-tait-inference2.rs:17:13 + --> $DIR/nested-tait-inference2.rs:18:13 | LL | fn foo() -> impl Foo { | ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `()` diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference2.next.stderr b/tests/ui/type-alias-impl-trait/nested-tait-inference2.next.stderr index 9647d9e376eb..b733739e4c86 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-inference2.next.stderr +++ b/tests/ui/type-alias-impl-trait/nested-tait-inference2.next.stderr @@ -1,5 +1,5 @@ error[E0284]: type annotations needed: cannot satisfy `impl Foo == ()` - --> $DIR/nested-tait-inference2.rs:19:5 + --> $DIR/nested-tait-inference2.rs:20:5 | LL | () | ^^ cannot satisfy `impl Foo == ()` diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference2.rs b/tests/ui/type-alias-impl-trait/nested-tait-inference2.rs index 28d72b0cbeed..3c4900a74e70 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-inference2.rs +++ b/tests/ui/type-alias-impl-trait/nested-tait-inference2.rs @@ -14,6 +14,7 @@ trait Foo {} impl Foo<()> for () {} impl Foo for () {} +#[define_opaques(FooX)] fn foo() -> impl Foo { //[current]~^ ERROR: the trait bound `(): Foo` is not satisfied () diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference3.rs b/tests/ui/type-alias-impl-trait/nested-tait-inference3.rs index aaf2812532d3..d96ee1ed9ef2 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-inference3.rs +++ b/tests/ui/type-alias-impl-trait/nested-tait-inference3.rs @@ -9,6 +9,7 @@ trait Foo {} impl Foo for () {} +#[define_opaques(FooX)] fn foo() -> impl Foo { //~^ ERROR: item does not constrain () diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference3.stderr b/tests/ui/type-alias-impl-trait/nested-tait-inference3.stderr index 969409ebc59e..282b2d72059f 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-inference3.stderr +++ b/tests/ui/type-alias-impl-trait/nested-tait-inference3.stderr @@ -1,5 +1,5 @@ error: item does not constrain `FooX::{opaque#0}`, but has it in its signature - --> $DIR/nested-tait-inference3.rs:12:4 + --> $DIR/nested-tait-inference3.rs:13:4 | LL | fn foo() -> impl Foo { | ^^^ diff --git a/tests/ui/type-alias-impl-trait/nested.rs b/tests/ui/type-alias-impl-trait/nested.rs index 524703939f1d..b33c4ad95fbf 100644 --- a/tests/ui/type-alias-impl-trait/nested.rs +++ b/tests/ui/type-alias-impl-trait/nested.rs @@ -7,6 +7,7 @@ trait Trait {} impl Trait for U {} +#[define_opaques(Bar)] fn bar() -> Bar { //~^ ERROR: item does not constrain 42 diff --git a/tests/ui/type-alias-impl-trait/nested.stderr b/tests/ui/type-alias-impl-trait/nested.stderr index ca1cf6058ea9..efb82bc8ee66 100644 --- a/tests/ui/type-alias-impl-trait/nested.stderr +++ b/tests/ui/type-alias-impl-trait/nested.stderr @@ -1,5 +1,5 @@ error: item does not constrain `Foo::{opaque#0}`, but has it in its signature - --> $DIR/nested.rs:10:4 + --> $DIR/nested.rs:11:4 | LL | fn bar() -> Bar { | ^^^ @@ -12,7 +12,7 @@ LL | type Foo = impl std::fmt::Debug; | ^^^^^^^^^^^^^^^^^^^^ error[E0277]: `Bar` doesn't implement `Debug` - --> $DIR/nested.rs:16:22 + --> $DIR/nested.rs:17:22 | LL | println!("{:?}", bar()); | ^^^^^ `Bar` cannot be formatted using `{:?}` because it doesn't implement `Debug` diff --git a/tests/ui/type-alias-impl-trait/nested_inference_failure.rs b/tests/ui/type-alias-impl-trait/nested_inference_failure.rs index 004e79d67387..15d0bca703f1 100644 --- a/tests/ui/type-alias-impl-trait/nested_inference_failure.rs +++ b/tests/ui/type-alias-impl-trait/nested_inference_failure.rs @@ -22,6 +22,7 @@ struct Foo { type ImplT = impl Debug; type FooImpl = Foo; +#[define_opaques(FooImpl)] fn bar() -> FooImpl { Foo:: { f: |_| (), _phantom: PhantomData } } diff --git a/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs b/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs index 4def8948708f..c0b518a53e1d 100644 --- a/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs +++ b/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs @@ -1,21 +1,21 @@ #![feature(type_alias_impl_trait)] -mod my_mod { - use std::fmt::Debug; +use std::fmt::Debug; - pub type Foo = impl Debug; - pub type Foot = impl Debug; +pub type Foo = impl Debug; +pub type Foot = impl Debug; - pub fn get_foo() -> Foo { - 5i32 - } +#[define_opaques(Foo)] +pub fn get_foo() -> Foo { + 5i32 +} - pub fn get_foot(_: Foo) -> Foot { - //~^ ERROR: item does not constrain `Foo::{opaque#0}`, but has it in its signature - get_foo() //~ ERROR opaque type's hidden type cannot be another opaque type - } +#[define_opaques(Foot, Foo)] +pub fn get_foot(_: Foo) -> Foot { + //~^ ERROR: item does not constrain `Foo::{opaque#0}`, but has it in its signature + get_foo() //~ ERROR opaque type's hidden type cannot be another opaque type } fn main() { - let _: my_mod::Foot = my_mod::get_foot(my_mod::get_foo()); + let _: Foot = get_foot(get_foo()); } diff --git a/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.stderr b/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.stderr index 889cff1ba09e..92de050424c4 100644 --- a/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.stderr +++ b/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.stderr @@ -1,32 +1,32 @@ error: item does not constrain `Foo::{opaque#0}`, but has it in its signature - --> $DIR/nested_type_alias_impl_trait.rs:13:12 + --> $DIR/nested_type_alias_impl_trait.rs:14:8 | -LL | pub fn get_foot(_: Foo) -> Foot { - | ^^^^^^^^ +LL | pub fn get_foot(_: Foo) -> Foot { + | ^^^^^^^^ | = note: consider moving the opaque type's declaration and defining uses into a separate module note: this opaque type is in the signature - --> $DIR/nested_type_alias_impl_trait.rs:6:20 + --> $DIR/nested_type_alias_impl_trait.rs:5:16 | -LL | pub type Foo = impl Debug; - | ^^^^^^^^^^ +LL | pub type Foo = impl Debug; + | ^^^^^^^^^^ error: opaque type's hidden type cannot be another opaque type from the same scope - --> $DIR/nested_type_alias_impl_trait.rs:15:9 + --> $DIR/nested_type_alias_impl_trait.rs:16:5 | -LL | get_foo() - | ^^^^^^^^^ one of the two opaque types used here has to be outside its defining scope +LL | get_foo() + | ^^^^^^^^^ one of the two opaque types used here has to be outside its defining scope | note: opaque type whose hidden type is being assigned - --> $DIR/nested_type_alias_impl_trait.rs:7:21 + --> $DIR/nested_type_alias_impl_trait.rs:6:17 | -LL | pub type Foot = impl Debug; - | ^^^^^^^^^^ +LL | pub type Foot = impl Debug; + | ^^^^^^^^^^ note: opaque type being used as hidden type - --> $DIR/nested_type_alias_impl_trait.rs:6:20 + --> $DIR/nested_type_alias_impl_trait.rs:5:16 | -LL | pub type Foo = impl Debug; - | ^^^^^^^^^^ +LL | pub type Foo = impl Debug; + | ^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/type-alias-impl-trait/never_reveal_concrete_type.rs b/tests/ui/type-alias-impl-trait/never_reveal_concrete_type.rs index 590107d10384..406c318bdf90 100644 --- a/tests/ui/type-alias-impl-trait/never_reveal_concrete_type.rs +++ b/tests/ui/type-alias-impl-trait/never_reveal_concrete_type.rs @@ -4,10 +4,12 @@ fn main() {} type NoReveal = impl std::fmt::Debug; +#[define_opaques(NoReveal)] fn define_no_reveal() -> NoReveal { "" } +#[define_opaques(NoReveal)] fn no_reveal(x: NoReveal) { let _: &'static str = x; let _ = x as &'static str; diff --git a/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs b/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs index 41238c27351d..d8409d218fe4 100644 --- a/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs +++ b/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs @@ -3,18 +3,17 @@ #![feature(type_alias_impl_trait)] -mod foo { - pub type Foo = impl Copy; +pub type Foo = impl Copy; - // make compiler happy about using 'Foo' - pub fn bar(x: Foo) -> Foo { - //~^ ERROR: item does not constrain `Foo::{opaque#0}` - x - } +// make compiler happy about using 'Foo' +#[define_opaques(Foo)] +pub fn bar(x: Foo) -> Foo { + //~^ ERROR: item does not constrain `Foo::{opaque#0}` + x } fn main() { unsafe { - let _: foo::Foo = std::mem::transmute(0u8); + let _: Foo = std::mem::transmute(0u8); } } diff --git a/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr b/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr index eed88c5df4f4..92df641fbf42 100644 --- a/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr +++ b/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr @@ -1,15 +1,15 @@ error: item does not constrain `Foo::{opaque#0}`, but has it in its signature - --> $DIR/no_inferrable_concrete_type.rs:10:12 + --> $DIR/no_inferrable_concrete_type.rs:10:8 | -LL | pub fn bar(x: Foo) -> Foo { - | ^^^ +LL | pub fn bar(x: Foo) -> Foo { + | ^^^ | = note: consider moving the opaque type's declaration and defining uses into a separate module note: this opaque type is in the signature - --> $DIR/no_inferrable_concrete_type.rs:7:20 + --> $DIR/no_inferrable_concrete_type.rs:6:16 | -LL | pub type Foo = impl Copy; - | ^^^^^^^^^ +LL | pub type Foo = impl Copy; + | ^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.rs b/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.rs index 61153b1e1714..c08334e1c555 100644 --- a/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.rs +++ b/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.rs @@ -2,11 +2,10 @@ fn main() {} -mod boo { - pub type Boo = impl ::std::fmt::Debug; - fn bomp() -> Boo { - "" - } +pub type Boo = impl ::std::fmt::Debug; +#[define_opaques(Boo)] +fn define() -> Boo { + "" } // We don't actually know the type here. @@ -15,10 +14,10 @@ fn bomp2() { let _: &str = bomp(); //~ ERROR mismatched types } -fn bomp() -> boo::Boo { +fn bomp() -> Boo { "" //~ ERROR mismatched types } -fn bomp_loop() -> boo::Boo { +fn bomp_loop() -> Boo { loop {} } diff --git a/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr b/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr index 863282a0ff94..426873d15304 100644 --- a/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr +++ b/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.stderr @@ -1,8 +1,8 @@ error[E0308]: mismatched types - --> $DIR/no_revealing_outside_defining_module.rs:15:19 + --> $DIR/no_revealing_outside_defining_module.rs:14:19 | -LL | pub type Boo = impl ::std::fmt::Debug; - | ---------------------- the found opaque type +LL | pub type Boo = impl ::std::fmt::Debug; + | ---------------------- the found opaque type ... LL | let _: &str = bomp(); | ---- ^^^^^^ expected `&str`, found opaque type @@ -11,29 +11,29 @@ LL | let _: &str = bomp(); | = note: expected reference `&str` found opaque type `Boo` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/no_revealing_outside_defining_module.rs:14:4 +note: this item must have a `#[define_opaques(Boo)]` attribute to be able to define hidden types + --> $DIR/no_revealing_outside_defining_module.rs:13:4 | LL | fn bomp2() { | ^^^^^ error[E0308]: mismatched types - --> $DIR/no_revealing_outside_defining_module.rs:19:5 + --> $DIR/no_revealing_outside_defining_module.rs:18:5 | -LL | pub type Boo = impl ::std::fmt::Debug; - | ---------------------- the expected opaque type +LL | pub type Boo = impl ::std::fmt::Debug; + | ---------------------- the expected opaque type ... -LL | fn bomp() -> boo::Boo { - | -------- expected `Boo` because of return type +LL | fn bomp() -> Boo { + | --- expected `Boo` because of return type LL | "" | ^^ expected opaque type, found `&str` | = note: expected opaque type `Boo` found reference `&'static str` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/no_revealing_outside_defining_module.rs:18:4 +note: this item must have a `#[define_opaques(Boo)]` attribute to be able to define hidden types + --> $DIR/no_revealing_outside_defining_module.rs:17:4 | -LL | fn bomp() -> boo::Boo { +LL | fn bomp() -> Boo { | ^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/type-alias-impl-trait/normalize-alias-type.rs b/tests/ui/type-alias-impl-trait/normalize-alias-type.rs index 9fcf42e188c7..aa0a2bf8eacb 100644 --- a/tests/ui/type-alias-impl-trait/normalize-alias-type.rs +++ b/tests/ui/type-alias-impl-trait/normalize-alias-type.rs @@ -18,7 +18,7 @@ pub fn tr1() -> impl Tr { } struct Inner { - x: helper::X, + x: X, } impl Tr for Inner { fn get(&self) -> u32 { @@ -26,14 +26,9 @@ impl Tr for Inner { } } -mod helper { - pub use super::*; - pub type X = impl Tr; +pub type X = impl Tr; - pub fn tr2() -> impl Tr - where - X:, - { - Inner { x: tr1() } - } +#[define_opaques(X)] +pub fn tr2() -> impl Tr { + Inner { x: tr1() } } diff --git a/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr b/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr index a40dac06a01c..75cc5948e93c 100644 --- a/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr +++ b/tests/ui/type-alias-impl-trait/normalize-hidden-types.current.stderr @@ -1,29 +1,29 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/normalize-hidden-types.rs:26:20 + --> $DIR/normalize-hidden-types.rs:27:20 | LL | fn define() -> Opaque { | ^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(::Gat<'a>)` | note: previous use here - --> $DIR/normalize-hidden-types.rs:27:9 + --> $DIR/normalize-hidden-types.rs:28:9 | LL | dyn_hoops::<_>(0) | ^^^^^^^^^^^^^^^^^ error: concrete type differs from previous defining opaque type use - --> $DIR/normalize-hidden-types.rs:34:22 + --> $DIR/normalize-hidden-types.rs:36:22 | LL | fn define_1() -> Opaque { dyn_hoops::<_>(0) } | ^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(::Gat<'a>)` | note: previous use here - --> $DIR/normalize-hidden-types.rs:34:31 + --> $DIR/normalize-hidden-types.rs:36:31 | LL | fn define_1() -> Opaque { dyn_hoops::<_>(0) } | ^^^^^^^^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/normalize-hidden-types.rs:43:25 + --> $DIR/normalize-hidden-types.rs:47:25 | LL | type Opaque = impl Sized; | ---------- the expected opaque type @@ -39,13 +39,13 @@ LL | let _: Opaque = dyn_hoops::(0); = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html error: concrete type differs from previous defining opaque type use - --> $DIR/normalize-hidden-types.rs:52:25 + --> $DIR/normalize-hidden-types.rs:57:25 | LL | let _: Opaque = dyn_hoops::<_>(0); | ^^^^^^^^^^^^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(::Gat<'a>)` | note: previous use here - --> $DIR/normalize-hidden-types.rs:53:9 + --> $DIR/normalize-hidden-types.rs:58:9 | LL | None | ^^^^ diff --git a/tests/ui/type-alias-impl-trait/normalize-hidden-types.rs b/tests/ui/type-alias-impl-trait/normalize-hidden-types.rs index 4028dba82bf1..ba18582c2069 100644 --- a/tests/ui/type-alias-impl-trait/normalize-hidden-types.rs +++ b/tests/ui/type-alias-impl-trait/normalize-hidden-types.rs @@ -23,6 +23,7 @@ fn dyn_hoops(_: T) -> *const dyn FnOnce(T::Gat<'_>) { mod typeof_1 { use super::*; type Opaque = impl Sized; + #[define_opaques(Opaque)] fn define() -> Opaque { dyn_hoops::<_>(0) } @@ -31,13 +32,16 @@ mod typeof_1 { mod typeof_2 { use super::*; type Opaque = impl Sized; + #[define_opaques(Opaque)] fn define_1() -> Opaque { dyn_hoops::<_>(0) } + #[define_opaques(Opaque)] fn define_2() -> Opaque { dyn_hoops::(0) } } mod typeck { use super::*; type Opaque = impl Sized; + #[define_opaques(Opaque)] fn define() -> Option { let _: Opaque = dyn_hoops::<_>(0); let _: Opaque = dyn_hoops::(0); @@ -48,6 +52,7 @@ mod typeck { mod borrowck { use super::*; type Opaque = impl Sized; + #[define_opaques(Opaque)] fn define() -> Option { let _: Opaque = dyn_hoops::<_>(0); None diff --git a/tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.rs b/tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.rs index 131f8d999d87..112ee4d55715 100644 --- a/tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.rs +++ b/tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.rs @@ -9,6 +9,7 @@ trait Foo { struct DefinesOpaque; impl Foo for () { type Assoc = impl Sized; + //~^ ERROR: unconstrained opaque type // This test's return type is `u32`, *not* the opaque that is defined above. // Previously we were only checking that the self type of the assoc matched, diff --git a/tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.stderr b/tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.stderr index d4528fb76fed..d01d05bd3ad0 100644 --- a/tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.stderr +++ b/tests/ui/type-alias-impl-trait/not-matching-trait-refs-isnt-defining.stderr @@ -1,5 +1,13 @@ +error: unconstrained opaque type + --> $DIR/not-matching-trait-refs-isnt-defining.rs:11:18 + | +LL | type Assoc = impl Sized; + | ^^^^^^^^^^ + | + = note: `Assoc` must be used in combination with a concrete type within the same impl + error[E0308]: mismatched types - --> $DIR/not-matching-trait-refs-isnt-defining.rs:17:54 + --> $DIR/not-matching-trait-refs-isnt-defining.rs:18:54 | LL | type Assoc = impl Sized; | ---------- the expected opaque type @@ -11,12 +19,12 @@ LL | let _: >::Assoc = ""; | = note: expected opaque type `<() as Foo>::Assoc` found reference `&'static str` -note: this item must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/not-matching-trait-refs-isnt-defining.rs:16:8 +note: this item must have a `#[define_opaques(<() as Foo>::Assoc)]` attribute to be able to define hidden types + --> $DIR/not-matching-trait-refs-isnt-defining.rs:17:8 | LL | fn test() -> <() as Foo>::Assoc { | ^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/not_a_defining_use.rs b/tests/ui/type-alias-impl-trait/not_a_defining_use.rs index b5ef1470629b..50cd21bafef7 100644 --- a/tests/ui/type-alias-impl-trait/not_a_defining_use.rs +++ b/tests/ui/type-alias-impl-trait/not_a_defining_use.rs @@ -6,6 +6,7 @@ fn main() {} type Two = impl Debug; +#[define_opaques(Two)] fn three(t: T) -> Two { (t, 5i8) } @@ -20,6 +21,7 @@ impl Bar for u32 { const FOO: i32 = 42; } +#[define_opaques(Two)] fn four(t: T) -> Two { (t, ::FOO) //~^ ERROR concrete type differs diff --git a/tests/ui/type-alias-impl-trait/not_a_defining_use.stderr b/tests/ui/type-alias-impl-trait/not_a_defining_use.stderr index b59f9c49b077..d90e4531879b 100644 --- a/tests/ui/type-alias-impl-trait/not_a_defining_use.stderr +++ b/tests/ui/type-alias-impl-trait/not_a_defining_use.stderr @@ -1,11 +1,11 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/not_a_defining_use.rs:24:5 + --> $DIR/not_a_defining_use.rs:26:5 | LL | (t, ::FOO) | ^^^^^^^^^^^^^^^^^^^^ expected `(T, i8)`, got `(T, ::Blub)` | note: previous use here - --> $DIR/not_a_defining_use.rs:10:5 + --> $DIR/not_a_defining_use.rs:11:5 | LL | (t, 5i8) | ^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/not_well_formed.rs b/tests/ui/type-alias-impl-trait/not_well_formed.rs index 0cf8d41c7fd4..2a74bf649870 100644 --- a/tests/ui/type-alias-impl-trait/not_well_formed.rs +++ b/tests/ui/type-alias-impl-trait/not_well_formed.rs @@ -16,6 +16,7 @@ trait Trait {} impl Trait for () {} +#[define_opaques(Foo)] fn foo_desugared(_: T) -> Foo { () } diff --git a/tests/ui/type-alias-impl-trait/obligation_ice.rs b/tests/ui/type-alias-impl-trait/obligation_ice.rs index e3698b23be86..44f0b123ebe4 100644 --- a/tests/ui/type-alias-impl-trait/obligation_ice.rs +++ b/tests/ui/type-alias-impl-trait/obligation_ice.rs @@ -8,6 +8,7 @@ trait Trait<'a, 'b: 'a> {} impl<'a, 'b: 'a, T> Trait<'a, 'b> for std::iter::Cloned {} type I<'a, 'b: 'a, A: Trait<'a, 'b>> = Chain>; +#[define_opaques(I)] fn test2<'a, 'b, A: Trait<'a, 'b> + Iterator>(x: A) -> I<'a, 'b, A> { x.chain(once("5")) } diff --git a/tests/ui/type-alias-impl-trait/outlives-bound-var.rs b/tests/ui/type-alias-impl-trait/outlives-bound-var.rs index 2c6f44d5416e..cbf4670213c9 100644 --- a/tests/ui/type-alias-impl-trait/outlives-bound-var.rs +++ b/tests/ui/type-alias-impl-trait/outlives-bound-var.rs @@ -5,11 +5,9 @@ //@ check-pass #![feature(type_alias_impl_trait)] -mod tait { - pub type Ty<'a> = impl Sized + 'a; - fn define<'a>() -> Ty<'a> {} -} -use tait::Ty; +pub type Ty<'a> = impl Sized + 'a; +#[define_opaques(Ty)] +fn define<'a>() -> Ty<'a> {} // Ty<'^0>: 'static fn test1(_: &'static fn(Ty<'_>)) {} diff --git a/tests/ui/type-alias-impl-trait/param_mismatch.rs b/tests/ui/type-alias-impl-trait/param_mismatch.rs index c74650307137..03427bdcf135 100644 --- a/tests/ui/type-alias-impl-trait/param_mismatch.rs +++ b/tests/ui/type-alias-impl-trait/param_mismatch.rs @@ -8,6 +8,7 @@ fn id(s: &str) -> &str { } type Opaque<'a> = impl Sized + 'a; // The second `Opaque<'_>` has a higher kinded lifetime, not a generic parameter +#[define_opaques(Opaque)] fn test(s: &str) -> (Opaque<'_>, impl Fn(&str) -> Opaque<'_>) { (s, id) //~^ ERROR: expected generic lifetime parameter, found `'_` diff --git a/tests/ui/type-alias-impl-trait/param_mismatch.stderr b/tests/ui/type-alias-impl-trait/param_mismatch.stderr index 09ec550d7183..07a8ce38f980 100644 --- a/tests/ui/type-alias-impl-trait/param_mismatch.stderr +++ b/tests/ui/type-alias-impl-trait/param_mismatch.stderr @@ -1,5 +1,5 @@ error[E0792]: expected generic lifetime parameter, found `'_` - --> $DIR/param_mismatch.rs:12:5 + --> $DIR/param_mismatch.rs:13:5 | LL | type Opaque<'a> = impl Sized + 'a; | -- this generic parameter must be used with a generic lifetime parameter diff --git a/tests/ui/type-alias-impl-trait/param_mismatch2.rs b/tests/ui/type-alias-impl-trait/param_mismatch2.rs index c7d5eaa16aae..1a465de4acba 100644 --- a/tests/ui/type-alias-impl-trait/param_mismatch2.rs +++ b/tests/ui/type-alias-impl-trait/param_mismatch2.rs @@ -9,6 +9,7 @@ fn id(s: &str) -> &str { type Opaque<'a> = impl Sized + 'a; +#[define_opaques(Opaque)] fn test(s: &str) -> (impl Fn(&str) -> Opaque<'_>, impl Fn(&str) -> Opaque<'_>) { (id, id) //~ ERROR: expected generic lifetime parameter, found `'_` } diff --git a/tests/ui/type-alias-impl-trait/param_mismatch2.stderr b/tests/ui/type-alias-impl-trait/param_mismatch2.stderr index 1ecdd7c2b54c..f5ecade2f02e 100644 --- a/tests/ui/type-alias-impl-trait/param_mismatch2.stderr +++ b/tests/ui/type-alias-impl-trait/param_mismatch2.stderr @@ -1,5 +1,5 @@ error[E0792]: expected generic lifetime parameter, found `'_` - --> $DIR/param_mismatch2.rs:13:5 + --> $DIR/param_mismatch2.rs:14:5 | LL | type Opaque<'a> = impl Sized + 'a; | -- this generic parameter must be used with a generic lifetime parameter diff --git a/tests/ui/type-alias-impl-trait/param_mismatch3.rs b/tests/ui/type-alias-impl-trait/param_mismatch3.rs index 03c133d5d3c2..f7411c1ac891 100644 --- a/tests/ui/type-alias-impl-trait/param_mismatch3.rs +++ b/tests/ui/type-alias-impl-trait/param_mismatch3.rs @@ -9,6 +9,7 @@ fn id2<'a, 'b>(s: (&'a str, &'b str)) -> (&'a str, &'b str) { type Opaque<'a> = impl Sized + 'a; +#[define_opaques(Opaque)] fn test() -> impl for<'a, 'b> Fn((&'a str, &'b str)) -> (Opaque<'a>, Opaque<'b>) { id2 //~ ERROR expected generic lifetime parameter, found `'a` } @@ -19,6 +20,7 @@ fn id(s: &str) -> &str { type Opaque2<'a> = impl Sized + 'a; +#[define_opaques(Opaque2)] fn test2(s: &str) -> (impl Fn(&str) -> Opaque2<'_>, Opaque2<'_>) { (id, s) //~ ERROR: expected generic lifetime parameter, found `'_` } diff --git a/tests/ui/type-alias-impl-trait/param_mismatch3.stderr b/tests/ui/type-alias-impl-trait/param_mismatch3.stderr index b8805f9b7f65..7565bbfc6ff0 100644 --- a/tests/ui/type-alias-impl-trait/param_mismatch3.stderr +++ b/tests/ui/type-alias-impl-trait/param_mismatch3.stderr @@ -1,5 +1,5 @@ error[E0792]: expected generic lifetime parameter, found `'a` - --> $DIR/param_mismatch3.rs:13:5 + --> $DIR/param_mismatch3.rs:14:5 | LL | type Opaque<'a> = impl Sized + 'a; | -- this generic parameter must be used with a generic lifetime parameter @@ -8,7 +8,7 @@ LL | id2 | ^^^ error[E0792]: expected generic lifetime parameter, found `'_` - --> $DIR/param_mismatch3.rs:23:5 + --> $DIR/param_mismatch3.rs:25:5 | LL | type Opaque2<'a> = impl Sized + 'a; | -- this generic parameter must be used with a generic lifetime parameter diff --git a/tests/ui/type-alias-impl-trait/param_mismatch4.rs b/tests/ui/type-alias-impl-trait/param_mismatch4.rs index e072f3ab8e05..919ebdbff44c 100644 --- a/tests/ui/type-alias-impl-trait/param_mismatch4.rs +++ b/tests/ui/type-alias-impl-trait/param_mismatch4.rs @@ -8,6 +8,7 @@ type Opq<'a> = impl Sized; // Two defining uses: Opq<'{empty}> and Opq<'a>. // This used to ICE. // issue: #122782 +#[define_opaques(Opq)] fn build<'a>() -> Opq<'a> { let _: Opq<'_> = (); //~^ ERROR expected generic lifetime parameter, found `'_` diff --git a/tests/ui/type-alias-impl-trait/param_mismatch4.stderr b/tests/ui/type-alias-impl-trait/param_mismatch4.stderr index d3fdea25a3dc..647637ae32a7 100644 --- a/tests/ui/type-alias-impl-trait/param_mismatch4.stderr +++ b/tests/ui/type-alias-impl-trait/param_mismatch4.stderr @@ -1,5 +1,5 @@ error[E0792]: expected generic lifetime parameter, found `'_` - --> $DIR/param_mismatch4.rs:12:12 + --> $DIR/param_mismatch4.rs:13:12 | LL | type Opq<'a> = impl Sized; | -- this generic parameter must be used with a generic lifetime parameter diff --git a/tests/ui/type-alias-impl-trait/path_resolution_taint.rs b/tests/ui/type-alias-impl-trait/path_resolution_taint.rs new file mode 100644 index 000000000000..430588153ce4 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/path_resolution_taint.rs @@ -0,0 +1,16 @@ +//! This test used to ICE #131298 + +#![feature(type_alias_impl_trait)] + +fn dyn_hoops() -> *const dyn Iterator { + //~^ ERROR: cannot find trait `Captures` in this scope + loop {} +} + +type Opaque = impl Sized; +#[define_opaques(Opaque)] +fn define() -> Opaque { + let _: Opaque = dyn_hoops::(); +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/path_resolution_taint.stderr b/tests/ui/type-alias-impl-trait/path_resolution_taint.stderr new file mode 100644 index 000000000000..122c7c1ffbfa --- /dev/null +++ b/tests/ui/type-alias-impl-trait/path_resolution_taint.stderr @@ -0,0 +1,9 @@ +error[E0405]: cannot find trait `Captures` in this scope + --> $DIR/path_resolution_taint.rs:5:54 + | +LL | fn dyn_hoops() -> *const dyn Iterator { + | ^^^^^^^^ not found in this scope + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0405`. diff --git a/tests/ui/type-alias-impl-trait/privacy.rs b/tests/ui/type-alias-impl-trait/privacy.rs index a5386bbec0d2..ca2137dbbc10 100644 --- a/tests/ui/type-alias-impl-trait/privacy.rs +++ b/tests/ui/type-alias-impl-trait/privacy.rs @@ -3,6 +3,7 @@ #![feature(type_alias_impl_trait)] type Foo = (impl Sized, u8); +#[define_opaques(Foo)] pub fn foo() -> Foo { //~^ WARNING type alias `Foo` is more private than the item `foo` (42, 42) diff --git a/tests/ui/type-alias-impl-trait/privacy.stderr b/tests/ui/type-alias-impl-trait/privacy.stderr index 50870905c30d..eeb49b1a4ac9 100644 --- a/tests/ui/type-alias-impl-trait/privacy.stderr +++ b/tests/ui/type-alias-impl-trait/privacy.stderr @@ -1,5 +1,5 @@ warning: type alias `Foo` is more private than the item `foo` - --> $DIR/privacy.rs:6:1 + --> $DIR/privacy.rs:7:1 | LL | pub fn foo() -> Foo { | ^^^^^^^^^^^^^^^^^^^ function `foo` is reachable at visibility `pub` diff --git a/tests/ui/type-alias-impl-trait/recursive-fn-tait.rs b/tests/ui/type-alias-impl-trait/recursive-fn-tait.rs index 3d1759097d6b..5f45c5bdf459 100644 --- a/tests/ui/type-alias-impl-trait/recursive-fn-tait.rs +++ b/tests/ui/type-alias-impl-trait/recursive-fn-tait.rs @@ -3,10 +3,12 @@ pub type Diff = impl Fn(usize) -> usize; +#[define_opaques(Diff)] pub fn lift() -> Diff { |_: usize |loop {} } +#[define_opaques(Diff)] pub fn add( n: Diff, m: Diff, diff --git a/tests/ui/type-alias-impl-trait/recursive-fn-tait.stderr b/tests/ui/type-alias-impl-trait/recursive-fn-tait.stderr index e8925b9b489f..1a8ab2194049 100644 --- a/tests/ui/type-alias-impl-trait/recursive-fn-tait.stderr +++ b/tests/ui/type-alias-impl-trait/recursive-fn-tait.stderr @@ -1,11 +1,11 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/recursive-fn-tait.rs:14:5 + --> $DIR/recursive-fn-tait.rs:16:5 | LL | move |x: usize| m(n(x)) - | ^^^^^^^^^^^^^^^^^^^^^^^ expected `{closure@$DIR/recursive-fn-tait.rs:7:5: 7:16}`, got `{closure@$DIR/recursive-fn-tait.rs:14:5: 14:20}` + | ^^^^^^^^^^^^^^^^^^^^^^^ expected `{closure@$DIR/recursive-fn-tait.rs:8:5: 8:16}`, got `{closure@$DIR/recursive-fn-tait.rs:16:5: 16:20}` | note: previous use here - --> $DIR/recursive-fn-tait.rs:7:5 + --> $DIR/recursive-fn-tait.rs:8:5 | LL | |_: usize |loop {} | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.rs b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.rs index 10588398c9d7..c6d5a1228c4b 100644 --- a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.rs +++ b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.rs @@ -3,11 +3,15 @@ #![feature(type_alias_impl_trait)] type Op = impl std::fmt::Display; -fn foo() -> Op { &"hello world" } +#[define_opaques(Op)] +fn foo() -> Op { + &"hello world" +} fn transform() -> impl std::fmt::Display { &0usize } +#[define_opaques(Op)] fn bad() -> Op { transform::() //~^ ERROR concrete type differs from previous defining opaque type use diff --git a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.stderr b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.stderr index eec35548c550..259f3b2b9f3d 100644 --- a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.stderr +++ b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn-2.stderr @@ -1,14 +1,14 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/recursive-tait-conflicting-defn-2.rs:12:5 + --> $DIR/recursive-tait-conflicting-defn-2.rs:16:5 | LL | transform::() | ^^^^^^^^^^^^^^^^^ expected `&'static &'static str`, got `impl std::fmt::Display` | note: previous use here - --> $DIR/recursive-tait-conflicting-defn-2.rs:6:18 + --> $DIR/recursive-tait-conflicting-defn-2.rs:8:5 | -LL | fn foo() -> Op { &"hello world" } - | ^^^^^^^^^^^^^^ +LL | &"hello world" + | ^^^^^^^^^^^^^^ error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs index 38fb493b4989..68058f4539f0 100644 --- a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs +++ b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs @@ -14,24 +14,23 @@ struct B { impl Test for B {} -mod helper { - use super::*; - pub type TestImpl = impl Test; +pub type TestImpl = impl Test; - pub fn test() -> TestImpl { - A - } +#[define_opaques(TestImpl)] +pub fn test() -> TestImpl { + A +} - fn make_option2() -> Option { - let inner = make_option().unwrap(); +#[define_opaques(TestImpl)] +fn make_option2() -> Option { + let inner = make_option().unwrap(); - Some(B { inner }) - //~^ ERROR concrete type differs from previous defining opaque type use - } + Some(B { inner }) + //~^ ERROR concrete type differs from previous defining opaque type use } -fn make_option() -> Option { - Some(helper::test()) +fn make_option() -> Option { + Some(test()) } fn main() {} diff --git a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr index 252c5d7dfa76..47471c9728c4 100644 --- a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr +++ b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr @@ -1,14 +1,14 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/recursive-tait-conflicting-defn.rs:28:9 + --> $DIR/recursive-tait-conflicting-defn.rs:28:5 | -LL | Some(B { inner }) - | ^^^^^^^^^^^^^^^^^ expected `A`, got `B` +LL | Some(B { inner }) + | ^^^^^^^^^^^^^^^^^ expected `A`, got `B` | note: previous use here - --> $DIR/recursive-tait-conflicting-defn.rs:22:9 + --> $DIR/recursive-tait-conflicting-defn.rs:21:5 | -LL | A - | ^ +LL | A + | ^ error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/reveal_local.rs b/tests/ui/type-alias-impl-trait/reveal_local.rs index 34f3788e2341..50958306f15f 100644 --- a/tests/ui/type-alias-impl-trait/reveal_local.rs +++ b/tests/ui/type-alias-impl-trait/reveal_local.rs @@ -7,12 +7,13 @@ type Foo = impl Debug; fn is_send() {} fn not_good() { - // Error: this function does not constrain `Foo` to any particular - // hidden type, so it cannot rely on `Send` being true. + // This function does not define `Foo`, + // so it can actually check auto traits on the hidden type without + // risking cycle errors. is_send::(); - //~^ ERROR: cannot check whether the hidden type of `reveal_local[9507]::Foo::{opaque#0}` satisfies auto traits } +#[define_opaques(Foo)] fn not_gooder() -> Foo { // Constrain `Foo = u32` let x: Foo = 22_u32; diff --git a/tests/ui/type-alias-impl-trait/reveal_local.stderr b/tests/ui/type-alias-impl-trait/reveal_local.stderr index 9829c58cf73b..bd0828885910 100644 --- a/tests/ui/type-alias-impl-trait/reveal_local.stderr +++ b/tests/ui/type-alias-impl-trait/reveal_local.stderr @@ -1,23 +1,5 @@ -error: cannot check whether the hidden type of `reveal_local[9507]::Foo::{opaque#0}` satisfies auto traits - --> $DIR/reveal_local.rs:12:15 - | -LL | is_send::(); - | ^^^ - | - = note: fetching the hidden types of an opaque inside of the defining scope is not supported. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule -note: opaque type is declared here - --> $DIR/reveal_local.rs:5:12 - | -LL | type Foo = impl Debug; - | ^^^^^^^^^^ -note: required by a bound in `is_send` - --> $DIR/reveal_local.rs:7:15 - | -LL | fn is_send() {} - | ^^^^ required by this bound in `is_send` - error[E0283]: type annotations needed: cannot satisfy `Foo: Send` - --> $DIR/reveal_local.rs:22:15 + --> $DIR/reveal_local.rs:23:15 | LL | is_send::(); | ^^^ @@ -29,6 +11,6 @@ note: required by a bound in `is_send` LL | fn is_send() {} | ^^^^ required by this bound in `is_send` -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs index 37d84feee4b8..06f756d5dac7 100644 --- a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs +++ b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs @@ -12,19 +12,16 @@ #![feature(type_alias_impl_trait)] -mod helper { - pub type Opaque = impl Sized; +pub type Opaque = impl Sized; - pub fn get_rpit() -> impl Clone {} +pub fn get_rpit() -> impl Clone {} - fn test() -> Opaque { - super::query(get_rpit); - get_rpit() - } +#[define_opaques(Opaque)] +fn test() -> Opaque { + query(get_rpit); + get_rpit() } -use helper::*; - fn query(_: impl FnOnce() -> Opaque) {} fn main() {} diff --git a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs index 80f1b1502d3b..587eec26c7b0 100644 --- a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs +++ b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs @@ -5,16 +5,14 @@ #![feature(type_alias_impl_trait)] -mod helper { - pub type Opaque = impl Sized; +pub type Opaque = impl Sized; - pub fn get_rpit() -> impl Sized {} +pub fn get_rpit() -> impl Sized {} - fn test(_: Opaque) { - super::query(get_rpit); - } +#[define_opaques(Opaque)] +fn test() { + query(get_rpit); } -use helper::*; fn query(_: impl FnOnce() -> Opaque) {} diff --git a/tests/ui/type-alias-impl-trait/self-referential-2.current.stderr b/tests/ui/type-alias-impl-trait/self-referential-2.current.stderr index e4399f2d8f4d..dca3ae05bb0e 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-2.current.stderr +++ b/tests/ui/type-alias-impl-trait/self-referential-2.current.stderr @@ -1,5 +1,5 @@ error[E0277]: can't compare `i32` with `Foo` - --> $DIR/self-referential-2.rs:10:13 + --> $DIR/self-referential-2.rs:11:13 | LL | fn bar() -> Bar { | ^^^ no implementation for `i32 == Foo` diff --git a/tests/ui/type-alias-impl-trait/self-referential-2.rs b/tests/ui/type-alias-impl-trait/self-referential-2.rs index f96364ccfcdd..f4654f806090 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-2.rs +++ b/tests/ui/type-alias-impl-trait/self-referential-2.rs @@ -7,6 +7,7 @@ type Foo = impl std::fmt::Debug; type Bar = impl PartialEq; +#[define_opaques(Bar)] fn bar() -> Bar { 42_i32 //[current]~^ ERROR can't compare `i32` with `Foo` } diff --git a/tests/ui/type-alias-impl-trait/self-referential-3.rs b/tests/ui/type-alias-impl-trait/self-referential-3.rs index 18f09b548675..1ec2100c4d01 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-3.rs +++ b/tests/ui/type-alias-impl-trait/self-referential-3.rs @@ -2,6 +2,7 @@ type Bar<'a, 'b> = impl PartialEq> + std::fmt::Debug; +#[define_opaques(Bar)] fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { //~^ ERROR can't compare `&i32` with `Bar<'a, 'b>` i diff --git a/tests/ui/type-alias-impl-trait/self-referential-3.stderr b/tests/ui/type-alias-impl-trait/self-referential-3.stderr index 15ebcdafca6f..d0b1d46c29e0 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-3.stderr +++ b/tests/ui/type-alias-impl-trait/self-referential-3.stderr @@ -1,5 +1,5 @@ error[E0277]: can't compare `&i32` with `Bar<'a, 'b>` - --> $DIR/self-referential-3.rs:5:31 + --> $DIR/self-referential-3.rs:6:31 | LL | fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { | ^^^^^^^^^^^ no implementation for `&i32 == Bar<'a, 'b>` diff --git a/tests/ui/type-alias-impl-trait/self-referential-4.rs b/tests/ui/type-alias-impl-trait/self-referential-4.rs index 36742c8ad57f..f948808fad9b 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-4.rs +++ b/tests/ui/type-alias-impl-trait/self-referential-4.rs @@ -2,18 +2,21 @@ type Bar<'a, 'b> = impl PartialEq> + std::fmt::Debug; +#[define_opaques(Bar)] fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { i //~^ ERROR can't compare `&i32` with `Bar<'b, 'static>` } type Foo<'a, 'b> = impl PartialEq> + std::fmt::Debug; +#[define_opaques(Foo)] fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> { i //~^ ERROR can't compare `&i32` with `Foo<'static, 'b>` } type Moo<'a, 'b> = impl PartialEq> + std::fmt::Debug; +#[define_opaques(Moo)] fn moo<'a, 'b>(i: &'a i32) -> Moo<'a, 'b> { i //~^ ERROR can't compare `&i32` with `Moo<'static, 'a>` } diff --git a/tests/ui/type-alias-impl-trait/self-referential-4.stderr b/tests/ui/type-alias-impl-trait/self-referential-4.stderr index 98c762e3d382..92534981eb94 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-4.stderr +++ b/tests/ui/type-alias-impl-trait/self-referential-4.stderr @@ -1,5 +1,5 @@ error[E0277]: can't compare `&i32` with `Bar<'b, 'static>` - --> $DIR/self-referential-4.rs:5:31 + --> $DIR/self-referential-4.rs:6:31 | LL | fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { | ^^^^^^^^^^^ no implementation for `&i32 == Bar<'b, 'static>` @@ -10,7 +10,7 @@ LL | i = help: the trait `PartialEq` is implemented for `i32` error[E0277]: can't compare `&i32` with `Foo<'static, 'b>` - --> $DIR/self-referential-4.rs:11:31 + --> $DIR/self-referential-4.rs:13:31 | LL | fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> { | ^^^^^^^^^^^ no implementation for `&i32 == Foo<'static, 'b>` @@ -21,7 +21,7 @@ LL | i = help: the trait `PartialEq` is implemented for `i32` error[E0277]: can't compare `&i32` with `Moo<'static, 'a>` - --> $DIR/self-referential-4.rs:17:31 + --> $DIR/self-referential-4.rs:20:31 | LL | fn moo<'a, 'b>(i: &'a i32) -> Moo<'a, 'b> { | ^^^^^^^^^^^ no implementation for `&i32 == Moo<'static, 'a>` diff --git a/tests/ui/type-alias-impl-trait/self-referential.rs b/tests/ui/type-alias-impl-trait/self-referential.rs index b899b12cc4a1..6aa2212ec81a 100644 --- a/tests/ui/type-alias-impl-trait/self-referential.rs +++ b/tests/ui/type-alias-impl-trait/self-referential.rs @@ -2,6 +2,7 @@ type Bar<'a, 'b> = impl PartialEq> + std::fmt::Debug; +#[define_opaques(Bar)] fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { //~^ ERROR can't compare `&i32` with `Bar<'b, 'a>` i @@ -9,6 +10,7 @@ fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { type Foo<'a, 'b> = (i32, impl PartialEq> + std::fmt::Debug); +#[define_opaques(Foo)] fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> { //~^ ERROR can't compare `&i32` with `(i32, Foo<'a, 'b>::{opaque#0}<'a, 'b>)` (42, i) @@ -16,6 +18,7 @@ fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> { type Moo<'a, 'b> = (i32, impl PartialEq> + std::fmt::Debug); +#[define_opaques(Moo)] fn moo<'a, 'b>(i: &'a i32) -> Moo<'a, 'b> { //~^ ERROR can't compare `&i32` with `(i32, Moo<'b, 'a>::{opaque#0}<'b, 'a>)` (42, i) diff --git a/tests/ui/type-alias-impl-trait/self-referential.stderr b/tests/ui/type-alias-impl-trait/self-referential.stderr index 57d67f693761..4bcf659e8e61 100644 --- a/tests/ui/type-alias-impl-trait/self-referential.stderr +++ b/tests/ui/type-alias-impl-trait/self-referential.stderr @@ -1,5 +1,5 @@ error[E0277]: can't compare `&i32` with `Bar<'b, 'a>` - --> $DIR/self-referential.rs:5:31 + --> $DIR/self-referential.rs:6:31 | LL | fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { | ^^^^^^^^^^^ no implementation for `&i32 == Bar<'b, 'a>` @@ -11,7 +11,7 @@ LL | i = help: the trait `PartialEq` is implemented for `i32` error[E0277]: can't compare `&i32` with `(i32, Foo<'a, 'b>::{opaque#0}<'a, 'b>)` - --> $DIR/self-referential.rs:12:31 + --> $DIR/self-referential.rs:14:31 | LL | fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> { | ^^^^^^^^^^^ no implementation for `&i32 == (i32, Foo<'a, 'b>::{opaque#0}<'a, 'b>)` @@ -23,7 +23,7 @@ LL | (42, i) = help: the trait `PartialEq` is implemented for `i32` error[E0277]: can't compare `&i32` with `(i32, Moo<'b, 'a>::{opaque#0}<'b, 'a>)` - --> $DIR/self-referential.rs:19:31 + --> $DIR/self-referential.rs:22:31 | LL | fn moo<'a, 'b>(i: &'a i32) -> Moo<'a, 'b> { | ^^^^^^^^^^^ no implementation for `&i32 == (i32, Moo<'b, 'a>::{opaque#0}<'b, 'a>)` diff --git a/tests/ui/type-alias-impl-trait/self_implication.rs b/tests/ui/type-alias-impl-trait/self_implication.rs index 56464af96ed8..fe9130a53617 100644 --- a/tests/ui/type-alias-impl-trait/self_implication.rs +++ b/tests/ui/type-alias-impl-trait/self_implication.rs @@ -20,11 +20,10 @@ struct Foo<'a> { x: &'a mut u8, } // desugared -mod foo { - pub type FooX = impl Sized; - impl<'a> super::Foo<'a> { - pub fn foo(&self) -> FooX {} - } +pub type FooX = impl Sized; +impl<'a> Foo<'a> { + #[define_opaques(FooX)] + pub fn foo(&self) -> FooX {} } fn bar() { diff --git a/tests/ui/type-alias-impl-trait/static-const-types.rs b/tests/ui/type-alias-impl-trait/static-const-types.rs deleted file mode 100644 index dad515aaa7bd..000000000000 --- a/tests/ui/type-alias-impl-trait/static-const-types.rs +++ /dev/null @@ -1,13 +0,0 @@ -#![feature(type_alias_impl_trait)] -#![allow(dead_code)] - -//@ check-pass - -use std::fmt::Debug; - -type Foo = impl Debug; - -static FOO1: Foo = 22_u32; -const FOO2: Foo = 22_u32; - -fn main() {} diff --git a/tests/ui/type-alias-impl-trait/structural-match-no-leak.rs b/tests/ui/type-alias-impl-trait/structural-match-no-leak.rs index 27f5799c3804..4f93dd910967 100644 --- a/tests/ui/type-alias-impl-trait/structural-match-no-leak.rs +++ b/tests/ui/type-alias-impl-trait/structural-match-no-leak.rs @@ -1,15 +1,15 @@ #![feature(type_alias_impl_trait)] -mod bar { - pub type Bar = impl Send; +pub type Bar = impl Send; - // While i32 is structural-match, we do not want to leak this information. - // (See https://github.com/rust-lang/rust/issues/72156) - pub const fn leak_free() -> Bar { - 7i32 - } +// While i32 is structural-match, we do not want to leak this information. +// (See https://github.com/rust-lang/rust/issues/72156) +#[define_opaques(Bar)] +pub const fn leak_free() -> Bar { + 7i32 } -const LEAK_FREE: bar::Bar = bar::leak_free(); + +const LEAK_FREE: Bar = leak_free(); fn leak_free_test() { match LEAK_FREE { diff --git a/tests/ui/type-alias-impl-trait/structural-match-no-leak.stderr b/tests/ui/type-alias-impl-trait/structural-match-no-leak.stderr index 28f5d6728a9d..5067d78d1697 100644 --- a/tests/ui/type-alias-impl-trait/structural-match-no-leak.stderr +++ b/tests/ui/type-alias-impl-trait/structural-match-no-leak.stderr @@ -1,8 +1,8 @@ error: opaque type `Bar` cannot be used in patterns --> $DIR/structural-match-no-leak.rs:16:9 | -LL | const LEAK_FREE: bar::Bar = bar::leak_free(); - | ------------------------- constant defined here +LL | const LEAK_FREE: Bar = leak_free(); + | -------------------- constant defined here ... LL | LEAK_FREE => (), | ^^^^^^^^^ opaque type can't be used in patterns diff --git a/tests/ui/type-alias-impl-trait/structural-match.rs b/tests/ui/type-alias-impl-trait/structural-match.rs index 502595915397..91f56049130b 100644 --- a/tests/ui/type-alias-impl-trait/structural-match.rs +++ b/tests/ui/type-alias-impl-trait/structural-match.rs @@ -1,22 +1,21 @@ #![feature(type_alias_impl_trait)] -mod foo { - pub type Foo = impl Send; +pub type Foo = impl Send; - // This is not structural-match - struct A; +// This is not structural-match +struct A; - pub const fn value() -> Foo { - A - } +#[define_opaques(Foo)] +pub const fn value() -> Foo { + A } -use foo::*; + const VALUE: Foo = value(); fn test() { match VALUE { VALUE => (), - //~^ `foo::Foo` cannot be used in patterns + //~^ `Foo` cannot be used in patterns _ => (), } } diff --git a/tests/ui/type-alias-impl-trait/structural-match.stderr b/tests/ui/type-alias-impl-trait/structural-match.stderr index b06b31a060fb..a86b7f42ead6 100644 --- a/tests/ui/type-alias-impl-trait/structural-match.stderr +++ b/tests/ui/type-alias-impl-trait/structural-match.stderr @@ -1,5 +1,5 @@ -error: opaque type `foo::Foo` cannot be used in patterns - --> $DIR/structural-match.rs:18:9 +error: opaque type `Foo` cannot be used in patterns + --> $DIR/structural-match.rs:17:9 | LL | const VALUE: Foo = value(); | ---------------- constant defined here diff --git a/tests/ui/type-alias-impl-trait/taint.rs b/tests/ui/type-alias-impl-trait/taint.rs index dfb947637c04..97837762f068 100644 --- a/tests/ui/type-alias-impl-trait/taint.rs +++ b/tests/ui/type-alias-impl-trait/taint.rs @@ -9,6 +9,7 @@ fn set(x: &mut isize) -> isize { *x } +#[define_opaques(Two)] fn d(x: Two) { let c1 = || set(x); //~ ERROR: expected generic lifetime parameter, found `'_` c1; diff --git a/tests/ui/type-alias-impl-trait/taint.stderr b/tests/ui/type-alias-impl-trait/taint.stderr index 17fcd4b7e932..e2e34a5d1ba4 100644 --- a/tests/ui/type-alias-impl-trait/taint.stderr +++ b/tests/ui/type-alias-impl-trait/taint.stderr @@ -1,5 +1,5 @@ error[E0792]: expected generic lifetime parameter, found `'_` - --> $DIR/taint.rs:13:17 + --> $DIR/taint.rs:14:17 | LL | type Two<'a, 'b> = impl std::fmt::Debug; | -- this generic parameter must be used with a generic lifetime parameter diff --git a/tests/ui/type-alias-impl-trait/tait-in-function-return-type-issue-101903-fixed.rs b/tests/ui/type-alias-impl-trait/tait-in-function-return-type-issue-101903-fixed.rs index 109a70c766d4..fd1c95a9a6c6 100644 --- a/tests/ui/type-alias-impl-trait/tait-in-function-return-type-issue-101903-fixed.rs +++ b/tests/ui/type-alias-impl-trait/tait-in-function-return-type-issue-101903-fixed.rs @@ -19,6 +19,7 @@ type Sendable = impl Send + Duh; type Foo = impl Trait; +#[define_opaques(Foo)] fn foo() -> Foo { || 42 } diff --git a/tests/ui/type-alias-impl-trait/tait-param-inference-issue-117310.rs b/tests/ui/type-alias-impl-trait/tait-param-inference-issue-117310.rs index be743e8e2700..feb4d43563c0 100644 --- a/tests/ui/type-alias-impl-trait/tait-param-inference-issue-117310.rs +++ b/tests/ui/type-alias-impl-trait/tait-param-inference-issue-117310.rs @@ -10,9 +10,11 @@ impl Trait for (A, B, u8) where A: Deref, B: Deref, {} impl Trait for (A, B, i8) {} type TaitSized = impl Sized; +#[define_opaques(TaitSized)] fn def_tait1() -> TaitSized {} type TaitCopy = impl Copy; +#[define_opaques(TaitCopy)] fn def_tait2() -> TaitCopy {} fn impl_trait () {} diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-assoc-dyn.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-assoc-dyn.rs index 66a6c0a35b50..053a32b8578b 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-assoc-dyn.rs +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-assoc-dyn.rs @@ -5,6 +5,7 @@ type Foo = Box>; +#[define_opaques(Foo)] fn make_foo() -> Foo { Box::new(vec![1, 2, 3].into_iter()) } diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-assoc-impl-trait.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-assoc-impl-trait.rs index e46d2bd559cf..1f27d8e4f7c3 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-assoc-impl-trait.rs +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-assoc-impl-trait.rs @@ -5,6 +5,7 @@ type Foo = impl Iterator; +#[define_opaques(Foo)] fn make_foo() -> Foo { vec![1, 2].into_iter() } @@ -12,6 +13,7 @@ fn make_foo() -> Foo { type Bar = impl Send; type Baz = impl Iterator; +#[define_opaques(Baz)] fn make_baz() -> Baz { vec!["1", "2"].into_iter() } diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-const.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-const.rs index 6b37552fed14..d151c7adcfdb 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-const.rs +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-const.rs @@ -1,11 +1,19 @@ #![feature(type_alias_impl_trait)] -//@ check-pass -// Ensures that `const` items can constrain an opaque `impl Trait`. +// Ensures that `const` items can not constrain an opaque `impl Trait`. use std::fmt::Debug; pub type Foo = impl Debug; +//~^ ERROR unconstrained opaque type +#[define_opaques(Foo)] +//~^ ERROR only functions and methods can define opaque types const _FOO: Foo = 5; +//~^ ERROR mismatched types + +#[define_opaques(Foo)] +//~^ ERROR only functions and methods can define opaque types +static _BAR: Foo = 22_u32; +//~^ ERROR mismatched types fn main() {} diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-const.stderr b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-const.stderr new file mode 100644 index 000000000000..57d5d580f541 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-const.stderr @@ -0,0 +1,57 @@ +error: only functions and methods can define opaque types + --> $DIR/type-alias-impl-trait-const.rs:9:1 + | +LL | #[define_opaques(Foo)] + | ^^^^^^^^^^^^^^^^^^^^^^ + +error: only functions and methods can define opaque types + --> $DIR/type-alias-impl-trait-const.rs:14:1 + | +LL | #[define_opaques(Foo)] + | ^^^^^^^^^^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/type-alias-impl-trait-const.rs:11:19 + | +LL | pub type Foo = impl Debug; + | ---------- the expected opaque type +... +LL | const _FOO: Foo = 5; + | ^ expected opaque type, found integer + | + = note: expected opaque type `Foo` + found type `{integer}` +note: this item must have a `#[define_opaques(Foo)]` attribute to be able to define hidden types + --> $DIR/type-alias-impl-trait-const.rs:11:7 + | +LL | const _FOO: Foo = 5; + | ^^^^ + +error: unconstrained opaque type + --> $DIR/type-alias-impl-trait-const.rs:6:16 + | +LL | pub type Foo = impl Debug; + | ^^^^^^^^^^ + | + = note: `Foo` must be used in combination with a concrete type within the same crate + +error[E0308]: mismatched types + --> $DIR/type-alias-impl-trait-const.rs:16:20 + | +LL | pub type Foo = impl Debug; + | ---------- the expected opaque type +... +LL | static _BAR: Foo = 22_u32; + | ^^^^^^ expected opaque type, found `u32` + | + = note: expected opaque type `Foo` + found type `u32` +note: this item must have a `#[define_opaques(Foo)]` attribute to be able to define hidden types + --> $DIR/type-alias-impl-trait-const.rs:16:8 + | +LL | static _BAR: Foo = 22_u32; + | ^^^^ + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs index cbd91066c49d..c104f45c0745 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.rs @@ -11,10 +11,12 @@ struct MyStruct { impl MyTrait for MyStruct {} +#[define_opaques(TE)] fn bla() -> TE { return MyStruct { v: 1 }; } +#[define_opaques(TE)] fn bla2() -> TE { //~^ ERROR: item does not constrain `TE::{opaque#0}`, but has it in its signature bla() diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.stderr b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.stderr index 819bde021836..d303cc9aa2be 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.stderr +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.stderr @@ -1,12 +1,12 @@ error: item does not constrain `TE::{opaque#0}`, but has it in its signature - --> $DIR/type-alias-impl-trait-fns.rs:18:4 + --> $DIR/type-alias-impl-trait-fns.rs:20:4 | LL | fn bla2() -> TE { | ^^^^ | = note: consider moving the opaque type's declaration and defining uses into a separate module note: this opaque type is in the signature - --> $DIR/type-alias-impl-trait-fns.rs:23:11 + --> $DIR/type-alias-impl-trait-fns.rs:25:11 | LL | type TE = impl MyTrait; | ^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-sized.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-sized.rs index 188b23732f91..6784d4482e29 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-sized.rs +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-sized.rs @@ -3,21 +3,25 @@ #![feature(type_alias_impl_trait)] type A = impl Sized; +#[define_opaques(A)] fn f1() -> A { 0 } type B = impl ?Sized; +#[define_opaques(B)] fn f2() -> &'static B { &[0] } type C = impl ?Sized + 'static; +#[define_opaques(C)] fn f3() -> &'static C { &[0] } type D = impl ?Sized; +#[define_opaques(D)] fn f4() -> &'static D { &1 } diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-struct.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-struct.rs index 1340a4214ee5..990ccab45065 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-struct.rs +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-struct.rs @@ -5,6 +5,7 @@ type Foo = Vec; +#[define_opaques(Foo)] fn make_foo() -> Foo { vec![true, false] } diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-tuple.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-tuple.rs index 8e90f9699532..d10ff615d6d1 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-tuple.rs +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-tuple.rs @@ -6,20 +6,17 @@ #![feature(type_alias_impl_trait)] #![allow(dead_code)] -mod foo { - pub trait MyTrait {} +pub trait MyTrait {} - impl MyTrait for bool {} +impl MyTrait for bool {} - pub type Foo = impl MyTrait; +pub type Foo = impl MyTrait; - pub fn make_foo() -> Foo { - true - } +#[define_opaques(Foo)] +pub fn make_foo() -> Foo { + true } -use foo::*; - struct Blah { my_foo: Foo, my_u8: u8, diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error-1.stderr b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error-1.stderr index ee8922b673e2..ad96a0eeb87d 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error-1.stderr +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error-1.stderr @@ -1,9 +1,10 @@ -error[E0275]: overflow evaluating the requirement `>::Output == Foo` - --> $DIR/type-alias-impl-trait-with-cycle-error-1.rs:6:21 +error: unconstrained opaque type + --> $DIR/type-alias-impl-trait-with-cycle-error-1.rs:4:12 | -LL | fn crash(x: Foo) -> Foo { - | ^^^ +LL | type Foo = impl Fn() -> Foo; + | ^^^^^^^^^^^^^^^^ + | + = note: `Foo` must be used in combination with a concrete type within the same crate error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error-2.stderr b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error-2.stderr index 3d0f1d30ca2b..e5bb8163a811 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error-2.stderr +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error-2.stderr @@ -1,9 +1,10 @@ -error[E0275]: overflow evaluating the requirement `>::Item == Foo` - --> $DIR/type-alias-impl-trait-with-cycle-error-2.rs:10:21 +error: unconstrained opaque type + --> $DIR/type-alias-impl-trait-with-cycle-error-2.rs:8:12 | -LL | fn crash(x: Foo) -> Foo { - | ^^^ +LL | type Foo = impl Bar; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `Foo` must be used in combination with a concrete type within the same crate error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error-3.stderr b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error-3.stderr index 675689bac429..157310bf6236 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error-3.stderr +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error-3.stderr @@ -1,9 +1,10 @@ -error[E0275]: overflow evaluating the requirement ` as FnOnce<()>>::Output == Foo<'a>` - --> $DIR/type-alias-impl-trait-with-cycle-error-3.rs:6:40 +error: unconstrained opaque type + --> $DIR/type-alias-impl-trait-with-cycle-error-3.rs:4:16 | -LL | fn crash<'a>(_: &'a (), x: Foo<'a>) -> Foo<'a> { - | ^^^^^^^ +LL | type Foo<'a> = impl Fn() -> Foo<'a>; + | ^^^^^^^^^^^^^^^^^^^^ + | + = note: `Foo` must be used in combination with a concrete type within the same crate error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0275`. diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.rs index 8ca279eec921..a46461ef17f4 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.rs +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.rs @@ -3,6 +3,7 @@ type Foo = impl 'static; //~^ ERROR: at least one trait must be specified +#[define_opaques(Foo)] fn foo() -> Foo { "foo" } diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.stderr b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.stderr index 3f7acd338301..da8fc595f6a6 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.stderr +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-no-traits.stderr @@ -5,7 +5,7 @@ LL | type Foo = impl 'static; | ^^^^^^^^^^^^ error: at least one trait must be specified - --> $DIR/type-alias-impl-trait-with-no-traits.rs:10:13 + --> $DIR/type-alias-impl-trait-with-no-traits.rs:11:13 | LL | fn bar() -> impl 'static { | ^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait.rs index 0fe653ac471a..0e6f87ae0890 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait.rs +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait.rs @@ -17,6 +17,7 @@ fn main() { // single definition type Foo = impl std::fmt::Display; +#[define_opaques(Foo)] fn foo() -> Foo { "foo" } @@ -24,30 +25,36 @@ fn foo() -> Foo { // two definitions type Bar = impl std::fmt::Display; +#[define_opaques(Bar)] fn bar1() -> Bar { "bar1" } +#[define_opaques(Bar)] fn bar2() -> Bar { "bar2" } type MyIter = impl Iterator; +#[define_opaques(MyIter)] fn my_iter(t: T) -> MyIter { std::iter::once(t) } +#[define_opaques(MyIter)] fn my_iter2(t: T) -> MyIter { std::iter::once(t) } // param names should not have an effect! +#[define_opaques(MyIter)] fn my_iter3(u: U) -> MyIter { std::iter::once(u) } // param position should not have an effect! +#[define_opaques(MyIter)] fn my_iter4(_: U, v: V) -> MyIter { std::iter::once(v) } @@ -55,6 +62,7 @@ fn my_iter4(_: U, v: V) -> MyIter { // param names should not have an effect! type MyOtherIter = impl Iterator; +#[define_opaques(MyOtherIter)] fn my_other_iter(u: U) -> MyOtherIter { std::iter::once(u) } @@ -62,18 +70,18 @@ fn my_other_iter(u: U) -> MyOtherIter { trait Trait {} type GenericBound<'a, T: Trait + 'a> = impl Sized + 'a; +#[define_opaques(GenericBound)] fn generic_bound<'a, T: Trait + 'a>(t: T) -> GenericBound<'a, T> { t } -mod pass_through { - pub type Passthrough = impl Sized + 'static; +pub type Passthrough = impl Sized + 'static; - fn define_passthrough(t: T) -> Passthrough { - t - } +#[define_opaques(Passthrough)] +fn define_passthrough(t: T) -> Passthrough { + t } -fn use_passthrough(x: pass_through::Passthrough) -> pass_through::Passthrough { +fn use_passthrough(x: Passthrough) -> Passthrough { x } diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait2.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait2.rs index 65e2feaf7954..d23da3f44158 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait2.rs +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait2.rs @@ -14,71 +14,74 @@ fn main() { assert_eq!(my_iter(42u8).collect::>(), vec![42u8]); } -use defining_use_scope::*; +// single definition +pub type Foo = impl std::fmt::Display; -mod defining_use_scope { - // single definition - pub type Foo = impl std::fmt::Display; - - pub fn foo() -> Foo { - "foo" - } - - // two definitions - pub type Bar = impl std::fmt::Display; +#[define_opaques(Foo)] +pub fn foo() -> Foo { + "foo" +} - pub fn bar1() -> Bar { - "bar1" - } +// two definitions +pub type Bar = impl std::fmt::Display; - pub fn bar2() -> Bar { - "bar2" - } +#[define_opaques(Bar)] +pub fn bar1() -> Bar { + "bar1" +} - pub type MyIter = impl Iterator; +#[define_opaques(Bar)] +pub fn bar2() -> Bar { + "bar2" +} - pub fn my_iter(t: T) -> MyIter { - std::iter::once(t) - } +pub type MyIter = impl Iterator; - fn my_iter2(t: T) -> MyIter { - std::iter::once(t) - } +#[define_opaques(MyIter)] +pub fn my_iter(t: T) -> MyIter { + std::iter::once(t) +} - // param names should not have an effect! - fn my_iter3(u: U) -> MyIter { - std::iter::once(u) - } +#[define_opaques(MyIter)] +fn my_iter2(t: T) -> MyIter { + std::iter::once(t) +} - // 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! +#[define_opaques(MyIter)] +fn my_iter3(u: U) -> MyIter { + std::iter::once(u) +} - // param names should not have an effect! - type MyOtherIter = impl Iterator; +// param position should not have an effect! +#[define_opaques(MyIter)] +fn my_iter4(_: U, v: V) -> MyIter { + std::iter::once(v) +} - fn my_other_iter(u: U) -> MyOtherIter { - std::iter::once(u) - } +// param names should not have an effect! +type MyOtherIter = impl Iterator; - trait Trait {} - type GenericBound<'a, T: Trait + 'a> = impl Sized + 'a; +#[define_opaques(MyOtherIter)] +fn my_other_iter(u: U) -> MyOtherIter { + std::iter::once(u) +} - fn generic_bound<'a, T: Trait + 'a>(t: T) -> GenericBound<'a, T> { - t - } +trait Trait {} +type GenericBound<'a, T: Trait + 'a> = impl Sized + 'a; - mod pass_through { - pub type Passthrough = impl Sized + 'static; +#[define_opaques(GenericBound)] +fn generic_bound<'a, T: Trait + 'a>(t: T) -> GenericBound<'a, T> { + t +} - fn define_passthrough(t: T) -> Passthrough { - t - } - } +pub type Passthrough = impl Sized + 'static; - fn use_passthrough(x: pass_through::Passthrough) -> pass_through::Passthrough { - x - } +#[define_opaques(Passthrough)] +fn define_passthrough(t: T) -> Passthrough { + t +} +fn use_passthrough(x: Passthrough) -> Passthrough { + x } diff --git a/tests/ui/type-alias-impl-trait/type-alias-nested-impl-trait.rs b/tests/ui/type-alias-impl-trait/type-alias-nested-impl-trait.rs index af575a4ff36b..9faa6d8b038e 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-nested-impl-trait.rs +++ b/tests/ui/type-alias-impl-trait/type-alias-nested-impl-trait.rs @@ -5,6 +5,7 @@ use std::iter::{once, Chain}; type I = Chain>; +#[define_opaques(I)] fn test2>(x: A) -> I { x.chain(once("5")) } diff --git a/tests/ui/type-alias-impl-trait/type_of_a_let.current.stderr b/tests/ui/type-alias-impl-trait/type_of_a_let.current.stderr index 7cf2fe42da8b..d4a2c23f7a77 100644 --- a/tests/ui/type-alias-impl-trait/type_of_a_let.current.stderr +++ b/tests/ui/type-alias-impl-trait/type_of_a_let.current.stderr @@ -1,5 +1,5 @@ error[E0382]: use of moved value: `x` - --> $DIR/type_of_a_let.rs:21:16 + --> $DIR/type_of_a_let.rs:23:16 | LL | let x: Foo = 22_u32; | - move occurs because `x` has type `Foo`, which does not implement the `Copy` trait @@ -9,7 +9,7 @@ LL | same_type((x, y)); | ^ value used here after move error[E0382]: use of moved value: `y` - --> $DIR/type_of_a_let.rs:22:6 + --> $DIR/type_of_a_let.rs:24:6 | LL | let y: Foo = x; | - move occurs because `y` has type `Foo`, which does not implement the `Copy` trait diff --git a/tests/ui/type-alias-impl-trait/type_of_a_let.rs b/tests/ui/type-alias-impl-trait/type_of_a_let.rs index cc8caf886cfc..1b8a7ec26798 100644 --- a/tests/ui/type-alias-impl-trait/type_of_a_let.rs +++ b/tests/ui/type-alias-impl-trait/type_of_a_let.rs @@ -10,11 +10,13 @@ use std::fmt::Debug; type Foo = impl Debug; +#[define_opaques(Foo)] fn foo1() -> (u32, Foo) { let x: Foo = 22_u32; (x, todo!()) } +#[define_opaques(Foo)] fn foo2() -> (u32, Foo) { let x: Foo = 22_u32; let y: Foo = x; diff --git a/tests/ui/type-alias-impl-trait/unbounded_opaque_type.rs b/tests/ui/type-alias-impl-trait/unbounded_opaque_type.rs index 09ff006acbdd..4e2b141adc90 100644 --- a/tests/ui/type-alias-impl-trait/unbounded_opaque_type.rs +++ b/tests/ui/type-alias-impl-trait/unbounded_opaque_type.rs @@ -2,12 +2,9 @@ #![feature(type_alias_impl_trait)] -mod opaque { - pub type Opaque = impl Sized; - fn defining() -> Opaque {} -} - -use opaque::Opaque; +pub type Opaque = impl Sized; +#[define_opaques(Opaque)] +fn defining() -> Opaque {} struct Ss<'a, T>(&'a Opaque); diff --git a/tests/ui/type-alias-impl-trait/unconstrained-due-to-bad-pattern.rs b/tests/ui/type-alias-impl-trait/unconstrained-due-to-bad-pattern.rs index ae3d317ab464..5f3e1d081031 100644 --- a/tests/ui/type-alias-impl-trait/unconstrained-due-to-bad-pattern.rs +++ b/tests/ui/type-alias-impl-trait/unconstrained-due-to-bad-pattern.rs @@ -3,6 +3,7 @@ type Tait = impl Copy; // Make sure that this TAIT isn't considered unconstrained... +#[define_opaques(Tait)] fn empty_opaque() -> Tait { if false { match empty_opaque() {} diff --git a/tests/ui/type-alias-impl-trait/unconstrained-due-to-bad-pattern.stderr b/tests/ui/type-alias-impl-trait/unconstrained-due-to-bad-pattern.stderr index 5c9a4688105f..549e3bc8dc14 100644 --- a/tests/ui/type-alias-impl-trait/unconstrained-due-to-bad-pattern.stderr +++ b/tests/ui/type-alias-impl-trait/unconstrained-due-to-bad-pattern.stderr @@ -1,5 +1,5 @@ error[E0004]: non-exhaustive patterns: type `Tait` is non-empty - --> $DIR/unconstrained-due-to-bad-pattern.rs:8:15 + --> $DIR/unconstrained-due-to-bad-pattern.rs:9:15 | LL | match empty_opaque() {} | ^^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/unconstrained-impl-param.rs b/tests/ui/type-alias-impl-trait/unconstrained-impl-param.rs index b3510067047b..1f5d31af54f1 100644 --- a/tests/ui/type-alias-impl-trait/unconstrained-impl-param.rs +++ b/tests/ui/type-alias-impl-trait/unconstrained-impl-param.rs @@ -3,6 +3,7 @@ use std::fmt::Display; type Opaque = impl Sized + 'static; +#[define_opaques(Opaque)] fn define() -> Opaque {} trait Trait { diff --git a/tests/ui/type-alias-impl-trait/unconstrained-impl-param.stderr b/tests/ui/type-alias-impl-trait/unconstrained-impl-param.stderr index 6206f169c5b9..7a86685787ce 100644 --- a/tests/ui/type-alias-impl-trait/unconstrained-impl-param.stderr +++ b/tests/ui/type-alias-impl-trait/unconstrained-impl-param.stderr @@ -1,5 +1,5 @@ error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates - --> $DIR/unconstrained-impl-param.rs:11:6 + --> $DIR/unconstrained-impl-param.rs:12:6 | LL | impl<'a> Trait for Opaque<&'a str> { | ^^ unconstrained lifetime parameter diff --git a/tests/ui/type-alias-impl-trait/under-binder.rs b/tests/ui/type-alias-impl-trait/under-binder.rs index caf21d64027d..6588bd2decc5 100644 --- a/tests/ui/type-alias-impl-trait/under-binder.rs +++ b/tests/ui/type-alias-impl-trait/under-binder.rs @@ -2,6 +2,7 @@ type Opaque<'a> = impl Sized + 'a; +#[define_opaques(Opaque)] fn test(f: fn(u8)) -> fn(Opaque<'_>) { f //~ ERROR E0792 } diff --git a/tests/ui/type-alias-impl-trait/under-binder.stderr b/tests/ui/type-alias-impl-trait/under-binder.stderr index f4a121ce440d..0589f9ae11cd 100644 --- a/tests/ui/type-alias-impl-trait/under-binder.stderr +++ b/tests/ui/type-alias-impl-trait/under-binder.stderr @@ -1,5 +1,5 @@ error[E0792]: expected generic lifetime parameter, found `'_` - --> $DIR/under-binder.rs:6:5 + --> $DIR/under-binder.rs:7:5 | LL | type Opaque<'a> = impl Sized + 'a; | -- this generic parameter must be used with a generic lifetime parameter diff --git a/tests/ui/type-alias-impl-trait/underconstrained_generic.rs b/tests/ui/type-alias-impl-trait/underconstrained_generic.rs index aa537dfc9176..b237e9799bd5 100644 --- a/tests/ui/type-alias-impl-trait/underconstrained_generic.rs +++ b/tests/ui/type-alias-impl-trait/underconstrained_generic.rs @@ -18,11 +18,10 @@ impl ProofForConversion for () { type Converter = impl ProofForConversion; +#[define_opaques(Converter)] fn _defining_use() -> Converter { () //~^ ERROR the trait bound `T: Trait` is not satisfied } - -fn main() { -} +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/underconstrained_generic.stderr b/tests/ui/type-alias-impl-trait/underconstrained_generic.stderr index e50949ed8f36..e05c3094d53a 100644 --- a/tests/ui/type-alias-impl-trait/underconstrained_generic.stderr +++ b/tests/ui/type-alias-impl-trait/underconstrained_generic.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `T: Trait` is not satisfied - --> $DIR/underconstrained_generic.rs:22:5 + --> $DIR/underconstrained_generic.rs:23:5 | LL | () | ^^ the trait `Trait` is not implemented for `T` @@ -17,7 +17,7 @@ note: required by a bound in an opaque type LL | type Converter = impl ProofForConversion; | ^^^^^^^^^^^^^^^^^^^^^ note: this definition site has more where clauses than the opaque type - --> $DIR/underconstrained_generic.rs:21:1 + --> $DIR/underconstrained_generic.rs:22:1 | LL | fn _defining_use() -> Converter { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/underconstrained_lifetime.rs b/tests/ui/type-alias-impl-trait/underconstrained_lifetime.rs index e8e7dd0ea082..0dd7570d09ee 100644 --- a/tests/ui/type-alias-impl-trait/underconstrained_lifetime.rs +++ b/tests/ui/type-alias-impl-trait/underconstrained_lifetime.rs @@ -15,6 +15,7 @@ impl<'a, 'b> ProofForConversion<'a, 'b> for &'b &'a () { type Converter<'a, 'b> = impl ProofForConversion<'a, 'b>; // Even _defining_use with an explicit `'a: 'b` compiles fine, too. +#[define_opaques(Converter)] fn _defining_use<'a, 'b>(x: &'b &'a ()) -> Converter<'a, 'b> { x //~^ ERROR reference has a longer lifetime than the data it references diff --git a/tests/ui/type-alias-impl-trait/underconstrained_lifetime.stderr b/tests/ui/type-alias-impl-trait/underconstrained_lifetime.stderr index 7c07578d887e..6a1f2b49397a 100644 --- a/tests/ui/type-alias-impl-trait/underconstrained_lifetime.stderr +++ b/tests/ui/type-alias-impl-trait/underconstrained_lifetime.stderr @@ -1,5 +1,5 @@ error[E0491]: in type `&'b &'a ()`, reference has a longer lifetime than the data it references - --> $DIR/underconstrained_lifetime.rs:19:5 + --> $DIR/underconstrained_lifetime.rs:20:5 | LL | x | ^ diff --git a/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.rs b/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.rs index 56d975355c3e..2dab81cba6f6 100644 --- a/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.rs +++ b/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.rs @@ -5,6 +5,7 @@ mod foo { pub trait T {} pub type Alias<'a> = impl T; + //~^ ERROR: unconstrained opaque type fn bar() { super::with_positive(|&n| ()); //~^ ERROR mismatched types diff --git a/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.stderr b/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.stderr index 279bd3bca5ab..b58eae671209 100644 --- a/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.stderr +++ b/tests/ui/type-alias-impl-trait/underef-index-out-of-bounds-121472.stderr @@ -1,9 +1,17 @@ +error: unconstrained opaque type + --> $DIR/underef-index-out-of-bounds-121472.rs:7:26 + | +LL | pub type Alias<'a> = impl T; + | ^^^^^^ + | + = note: `Alias` must be used in combination with a concrete type within the same crate + error[E0308]: mismatched types - --> $DIR/underef-index-out-of-bounds-121472.rs:9:31 + --> $DIR/underef-index-out-of-bounds-121472.rs:10:31 | LL | pub type Alias<'a> = impl T; | ------ the expected opaque type -LL | fn bar() { +... LL | super::with_positive(|&n| ()); | ^^ | | @@ -18,6 +26,6 @@ LL - super::with_positive(|&n| ()); LL + super::with_positive(|n| ()); | -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/unnameable_type.rs b/tests/ui/type-alias-impl-trait/unnameable_type.rs index 5813f529dea1..4dd809cefa45 100644 --- a/tests/ui/type-alias-impl-trait/unnameable_type.rs +++ b/tests/ui/type-alias-impl-trait/unnameable_type.rs @@ -16,6 +16,7 @@ use private::Trait; // downstream type MyPrivate = impl Sized; impl Trait for u32 { + #[define_opaques(MyPrivate)] fn dont_define_this(private: MyPrivate) { //~^ ERROR: incompatible type for trait let _: () = private; diff --git a/tests/ui/type-alias-impl-trait/unnameable_type.stderr b/tests/ui/type-alias-impl-trait/unnameable_type.stderr index 25dc41df4193..6e4e024ce691 100644 --- a/tests/ui/type-alias-impl-trait/unnameable_type.stderr +++ b/tests/ui/type-alias-impl-trait/unnameable_type.stderr @@ -1,9 +1,9 @@ error[E0053]: method `dont_define_this` has an incompatible type for trait - --> $DIR/unnameable_type.rs:19:34 + --> $DIR/unnameable_type.rs:20:34 | LL | type MyPrivate = impl Sized; | ---------- the found opaque type -LL | impl Trait for u32 { +... LL | fn dont_define_this(private: MyPrivate) { | ^^^^^^^^^ expected `Private`, found opaque type | diff --git a/tests/ui/type-alias-impl-trait/unused_generic_param.rs b/tests/ui/type-alias-impl-trait/unused_generic_param.rs index b675bc2e6225..de70d80298f8 100644 --- a/tests/ui/type-alias-impl-trait/unused_generic_param.rs +++ b/tests/ui/type-alias-impl-trait/unused_generic_param.rs @@ -7,16 +7,19 @@ fn main() {} type PartiallyDefined = impl Sized; +#[define_opaques(PartiallyDefined)] fn partially_defined(_: T) -> PartiallyDefined { 4u32 } type PartiallyDefined2 = impl Sized; +#[define_opaques(PartiallyDefined2)] fn partially_defined2(_: T) -> PartiallyDefined2 { 4u32 } +#[define_opaques(PartiallyDefined2)] fn partially_defined22(_: T) -> PartiallyDefined2 { 4u32 } diff --git a/tests/ui/type-alias-impl-trait/variance.rs b/tests/ui/type-alias-impl-trait/variance.rs index 40e8ec0129a3..409edde20e87 100644 --- a/tests/ui/type-alias-impl-trait/variance.rs +++ b/tests/ui/type-alias-impl-trait/variance.rs @@ -72,6 +72,7 @@ type NestedDeeply<'a> = >, >, >; +#[define_opaques(NestedDeeply)] fn test<'a>() -> NestedDeeply<'a> { &() } diff --git a/tests/ui/type-alias-impl-trait/variance.stderr b/tests/ui/type-alias-impl-trait/variance.stderr index 79ce8148f19a..138e4080c29d 100644 --- a/tests/ui/type-alias-impl-trait/variance.stderr +++ b/tests/ui/type-alias-impl-trait/variance.stderr @@ -28,7 +28,7 @@ error: unconstrained opaque type LL | type NotCapturedEarly<'a> = impl Sized; | ^^^^^^^^^^ | - = note: `NotCapturedEarly` must be used in combination with a concrete type within the same module + = note: `NotCapturedEarly` must be used in combination with a concrete type within the same crate error: unconstrained opaque type --> $DIR/variance.rs:11:26 @@ -36,7 +36,7 @@ error: unconstrained opaque type LL | type CapturedEarly<'a> = impl Sized + Captures<'a>; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `CapturedEarly` must be used in combination with a concrete type within the same module + = note: `CapturedEarly` must be used in combination with a concrete type within the same crate error: unconstrained opaque type --> $DIR/variance.rs:14:56 @@ -44,7 +44,7 @@ error: unconstrained opaque type LL | type NotCapturedLate<'a> = dyn for<'b> Iterator; | ^^^^^^^^^^ | - = note: `NotCapturedLate` must be used in combination with a concrete type within the same module + = note: `NotCapturedLate` must be used in combination with a concrete type within the same crate error: unconstrained opaque type --> $DIR/variance.rs:18:49 @@ -52,7 +52,7 @@ error: unconstrained opaque type LL | type Captured<'a> = dyn for<'b> Iterator>; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `Captured` must be used in combination with a concrete type within the same module + = note: `Captured` must be used in combination with a concrete type within the same crate error: unconstrained opaque type --> $DIR/variance.rs:22:27 @@ -60,7 +60,7 @@ error: unconstrained opaque type LL | type Bar<'a, 'b: 'b, T> = impl Sized; | ^^^^^^^^^^ | - = note: `Bar` must be used in combination with a concrete type within the same module + = note: `Bar` must be used in combination with a concrete type within the same crate error: unconstrained opaque type --> $DIR/variance.rs:34:32 diff --git a/tests/ui/type-alias-impl-trait/weird-return-types.rs b/tests/ui/type-alias-impl-trait/weird-return-types.rs index 29d4faa7ba90..c1ef077b8209 100644 --- a/tests/ui/type-alias-impl-trait/weird-return-types.rs +++ b/tests/ui/type-alias-impl-trait/weird-return-types.rs @@ -4,11 +4,12 @@ #![feature(type_alias_impl_trait)] #![allow(dead_code)] -use std::future::Future; use std::fmt::Debug; +use std::future::Future; type Foo = impl Debug; +#[define_opaques(Foo)] fn f() -> impl Future { async move { 22_u32 } } diff --git a/tests/ui/type-alias-impl-trait/wf-check-definition-site.rs b/tests/ui/type-alias-impl-trait/wf-check-definition-site.rs index 19dd4c179367..514beaeb0d88 100644 --- a/tests/ui/type-alias-impl-trait/wf-check-definition-site.rs +++ b/tests/ui/type-alias-impl-trait/wf-check-definition-site.rs @@ -14,6 +14,7 @@ struct Static(T); type OpaqueRet<'a> = impl Sized + 'a; +#[define_opaques(OpaqueRet)] fn test_return<'a>(msg: Static<&'static u8>) -> OpaqueRet<'a> { msg } @@ -23,9 +24,9 @@ fn test_rpit<'a>(msg: Static<&'static u8>) -> impl Sized + 'a { } type OpaqueAssign<'a> = impl Sized + 'a; -fn test_assign<'a>(msg: Static<&'static u8>) -> Option> { +#[define_opaques(OpaqueAssign)] +fn test_assign<'a>(msg: Static<&'static u8>) { let _: OpaqueAssign<'a> = msg; - None } // `OpaqueRef<'a, T> = Ref<'a, T>`, vs @@ -33,6 +34,7 @@ fn test_assign<'a>(msg: Static<&'static u8>) -> Option> { trait RefAt<'a>: 'a {} struct Ref<'a, T: RefAt<'a>>(&'a T); type OpaqueRef<'a, T: RefAt<'static>> = impl Sized + 'a; +#[define_opaques(OpaqueRef)] fn test_trait<'a, T: RefAt<'static>>(msg: Ref<'static, T>) -> OpaqueRef<'a, T> { msg } diff --git a/tests/ui/type-alias-impl-trait/wf-check-fn-def.rs b/tests/ui/type-alias-impl-trait/wf-check-fn-def.rs index 449e9fbd0d84..a375957aeb0d 100644 --- a/tests/ui/type-alias-impl-trait/wf-check-fn-def.rs +++ b/tests/ui/type-alias-impl-trait/wf-check-fn-def.rs @@ -6,8 +6,11 @@ trait Bar { type FooFn = impl FnOnce(B); +#[define_opaques(FooFn)] fn foo() -> FooFn { - fn mop(bar: B) { bar.bar() } + fn mop(bar: B) { + bar.bar() + } mop // NOTE: no function pointer, but function zst item //~^ ERROR the trait bound `B: Bar` is not satisfied } diff --git a/tests/ui/type-alias-impl-trait/wf-check-fn-def.stderr b/tests/ui/type-alias-impl-trait/wf-check-fn-def.stderr index 9046a8a76b82..b52ed3f43f48 100644 --- a/tests/ui/type-alias-impl-trait/wf-check-fn-def.stderr +++ b/tests/ui/type-alias-impl-trait/wf-check-fn-def.stderr @@ -1,13 +1,13 @@ error[E0277]: the trait bound `B: Bar` is not satisfied - --> $DIR/wf-check-fn-def.rs:11:5 + --> $DIR/wf-check-fn-def.rs:14:5 | LL | mop // NOTE: no function pointer, but function zst item | ^^^ the trait `Bar` is not implemented for `B` | note: required by a bound in `mop` - --> $DIR/wf-check-fn-def.rs:10:15 + --> $DIR/wf-check-fn-def.rs:11:15 | -LL | fn mop(bar: B) { bar.bar() } +LL | fn mop(bar: B) { | ^^^ required by this bound in `mop` help: consider restricting type parameter `B` with trait `Bar` | diff --git a/tests/ui/type-alias-impl-trait/wf-check-fn-ptrs.rs b/tests/ui/type-alias-impl-trait/wf-check-fn-ptrs.rs index 1484d9fd0734..4d1857339378 100644 --- a/tests/ui/type-alias-impl-trait/wf-check-fn-ptrs.rs +++ b/tests/ui/type-alias-impl-trait/wf-check-fn-ptrs.rs @@ -8,8 +8,11 @@ trait Bar { type FooFn = impl FnOnce(B); +#[define_opaques(FooFn)] fn foo() -> FooFn { - fn mop(bar: B) { bar.bar() } + fn mop(bar: B) { + bar.bar() + } mop as fn(B) // function pointers don't have any obligations on them, // thus the above compiles. It's obviously unsound to just diff --git a/tests/ui/type-alias-impl-trait/wf-nested.rs b/tests/ui/type-alias-impl-trait/wf-nested.rs index 56c524c6db06..289700363933 100644 --- a/tests/ui/type-alias-impl-trait/wf-nested.rs +++ b/tests/ui/type-alias-impl-trait/wf-nested.rs @@ -19,7 +19,6 @@ impl Trait<&'static T> for () { type Out = IsStatic; } - // We could theoretically allow this (and previously did), as even // though the nested opaque is not well-formed, it can only be // used by normalizing the projection @@ -27,6 +26,7 @@ impl Trait<&'static T> for () { // Assuming that we check that this projection is well-formed, the wf // of the nested opaque is implied. type OuterOpaque1 = impl Trait<&'static T, Out = impl Sized>; +#[define_opaques(OuterOpaque1)] fn define() -> OuterOpaque1 {} //~^ ERROR `T` may not live long enough @@ -38,6 +38,7 @@ fn define_rpit() -> impl Trait<&'static T, Out = impl Sized> {} // soundness. type InnerOpaque = impl Sized; type OuterOpaque2 = impl Trait<&'static T, Out = InnerOpaque>; +#[define_opaques(OuterOpaque2)] fn define_nested_rpit() -> OuterOpaque2 {} //~^ ERROR the parameter type `T` may not live long enough diff --git a/tests/ui/type-alias-impl-trait/wf-nested.stderr b/tests/ui/type-alias-impl-trait/wf-nested.stderr index 6d50e11c5da8..d7ac5146c1e7 100644 --- a/tests/ui/type-alias-impl-trait/wf-nested.stderr +++ b/tests/ui/type-alias-impl-trait/wf-nested.stderr @@ -27,7 +27,7 @@ LL | fn define_rpit() -> impl Trait<&'static T, Out = impl Sized> {} | +++++++++ error[E0310]: the parameter type `T` may not live long enough - --> $DIR/wf-nested.rs:41:47 + --> $DIR/wf-nested.rs:42:47 | LL | fn define_nested_rpit() -> OuterOpaque2 {} | ^^ diff --git a/tests/ui/type-alias-impl-trait/wf_check_closures.rs b/tests/ui/type-alias-impl-trait/wf_check_closures.rs index 2c70696ffcf4..59e0e1b41615 100644 --- a/tests/ui/type-alias-impl-trait/wf_check_closures.rs +++ b/tests/ui/type-alias-impl-trait/wf_check_closures.rs @@ -6,8 +6,9 @@ trait Bar { type FooFn = impl FnOnce(); +#[define_opaques(FooFn)] fn foo(bar: B) -> FooFn { - move || { bar.bar() } + move || bar.bar() //~^ ERROR the trait bound `B: Bar` is not satisfied } diff --git a/tests/ui/type-alias-impl-trait/wf_check_closures.stderr b/tests/ui/type-alias-impl-trait/wf_check_closures.stderr index 4156f0ca96ae..57e40445c87c 100644 --- a/tests/ui/type-alias-impl-trait/wf_check_closures.stderr +++ b/tests/ui/type-alias-impl-trait/wf_check_closures.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `B: Bar` is not satisfied - --> $DIR/wf_check_closures.rs:10:5 + --> $DIR/wf_check_closures.rs:11:5 | -LL | move || { bar.bar() } - | ^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `B` +LL | move || bar.bar() + | ^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `B` | note: required by a bound in `foo` - --> $DIR/wf_check_closures.rs:9:11 + --> $DIR/wf_check_closures.rs:10:11 | LL | fn foo(bar: B) -> FooFn { | ^^^ required by this bound in `foo` diff --git a/tests/ui/typeck/typeck_type_placeholder_item.rs b/tests/ui/typeck/typeck_type_placeholder_item.rs index 9f1bfd7909e3..acb3aea7893e 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.rs +++ b/tests/ui/typeck/typeck_type_placeholder_item.rs @@ -181,6 +181,7 @@ trait Trait {} impl Trait for Struct {} type Y = impl Trait<_>; //~^ ERROR the placeholder `_` is not allowed within types on item signatures for type aliases +#[define_opaques(Y)] fn foo() -> Y { Struct } diff --git a/tests/ui/typeck/typeck_type_placeholder_item.stderr b/tests/ui/typeck/typeck_type_placeholder_item.stderr index c5bf9a47e913..2a4a5a62ab4c 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item.stderr @@ -29,7 +29,7 @@ LL | struct BadStruct2<_, T>(_, T); | ^ expected identifier, found reserved identifier error: associated constant in `impl` without body - --> $DIR/typeck_type_placeholder_item.rs:206:5 + --> $DIR/typeck_type_placeholder_item.rs:207:5 | LL | const C: _; | ^^^^^^^^^^- @@ -578,13 +578,13 @@ LL | type Y = impl Trait<_>; | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:206:14 + --> $DIR/typeck_type_placeholder_item.rs:207:14 | LL | const C: _; | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:194:14 + --> $DIR/typeck_type_placeholder_item.rs:195:14 | LL | const D: _ = 42; | ^ not allowed in type signatures @@ -596,13 +596,13 @@ LL + const D: i32 = 42; | error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:209:14 + --> $DIR/typeck_type_placeholder_item.rs:210:14 | LL | const D: _ = 42; | ^ not allowed in type signatures error[E0046]: not all trait items implemented, missing: `F` - --> $DIR/typeck_type_placeholder_item.rs:200:1 + --> $DIR/typeck_type_placeholder_item.rs:201:1 | LL | type F: std::ops::Fn(_); | ----------------------- `F` from trait @@ -611,7 +611,7 @@ LL | impl Qux for Struct { | ^^^^^^^^^^^^^^^^^^^ missing `F` in implementation error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:217:31 + --> $DIR/typeck_type_placeholder_item.rs:218:31 | LL | fn value() -> Option<&'static _> { | ----------------^- @@ -620,7 +620,7 @@ LL | fn value() -> Option<&'static _> { | help: replace with the correct return type: `Option<&'static u8>` error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item.rs:222:17 + --> $DIR/typeck_type_placeholder_item.rs:223:17 | LL | const _: Option<_> = map(value); | ^ not allowed in type signatures @@ -632,7 +632,7 @@ LL + const _: Option = map(value); | error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:226:31 + --> $DIR/typeck_type_placeholder_item.rs:227:31 | LL | fn evens_squared(n: usize) -> _ { | ^ @@ -641,13 +641,13 @@ LL | fn evens_squared(n: usize) -> _ { | help: replace with an appropriate return type: `impl Iterator` error[E0121]: the placeholder `_` is not allowed within types on item signatures for constants - --> $DIR/typeck_type_placeholder_item.rs:231:10 + --> $DIR/typeck_type_placeholder_item.rs:232:10 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); | ^ not allowed in type signatures | -note: however, the inferred type `Map, {closure@typeck_type_placeholder_item.rs:231:29}>, {closure@typeck_type_placeholder_item.rs:231:49}>` cannot be named - --> $DIR/typeck_type_placeholder_item.rs:231:14 +note: however, the inferred type `Map, {closure@typeck_type_placeholder_item.rs:232:29}>, {closure@typeck_type_placeholder_item.rs:232:49}>` cannot be named + --> $DIR/typeck_type_placeholder_item.rs:232:14 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -695,53 +695,53 @@ LL + fn fn_test10(&self, _x : T) { } | error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:202:14 + --> $DIR/typeck_type_placeholder_item.rs:203:14 | LL | type A = _; | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:204:14 + --> $DIR/typeck_type_placeholder_item.rs:205:14 | LL | type B = _; | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:190:14 + --> $DIR/typeck_type_placeholder_item.rs:191:14 | LL | type B = _; | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:192:14 + --> $DIR/typeck_type_placeholder_item.rs:193:14 | LL | const C: _; | ^ not allowed in type signatures error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types - --> $DIR/typeck_type_placeholder_item.rs:197:26 + --> $DIR/typeck_type_placeholder_item.rs:198:26 | LL | type F: std::ops::Fn(_); | ^ not allowed in type signatures error[E0015]: cannot call non-const function `map::` in constants - --> $DIR/typeck_type_placeholder_item.rs:222:22 + --> $DIR/typeck_type_placeholder_item.rs:223:22 | LL | const _: Option<_> = map(value); | ^^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants -error[E0015]: cannot call non-const method ` as Iterator>::filter::<{closure@$DIR/typeck_type_placeholder_item.rs:231:29: 231:32}>` in constants - --> $DIR/typeck_type_placeholder_item.rs:231:22 +error[E0015]: cannot call non-const method ` as Iterator>::filter::<{closure@$DIR/typeck_type_placeholder_item.rs:232:29: 232:32}>` in constants + --> $DIR/typeck_type_placeholder_item.rs:232:22 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); | ^^^^^^^^^^^^^^^^^^^^^^ | = note: calls in constants are limited to constant functions, tuple structs and tuple variants -error[E0015]: cannot call non-const method `, {closure@$DIR/typeck_type_placeholder_item.rs:231:29: 231:32}> as Iterator>::map::` in constants - --> $DIR/typeck_type_placeholder_item.rs:231:45 +error[E0015]: cannot call non-const method `, {closure@$DIR/typeck_type_placeholder_item.rs:232:29: 232:32}> as Iterator>::map::` in constants + --> $DIR/typeck_type_placeholder_item.rs:232:45 | LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); | ^^^^^^^^^^^^^^ From 536f4dcaa94807255cf8430558384fc7683c93c6 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 25 Feb 2025 09:52:55 +0000 Subject: [PATCH 4/6] Test invalid `define_opaques` attributes --- compiler/rustc_ast_lowering/src/item.rs | 22 +++++++++----- .../define_opaques_attr/foreign_type.rs | 5 ++++ .../define_opaques_attr/foreign_type.stderr | 8 +++++ .../define_opaques_attr/generics.rs | 13 +++++++++ .../define_opaques_attr/generics.stderr | 29 +++++++++++++++++++ .../define_opaques_attr/invalid_path.rs | 5 ++++ .../define_opaques_attr/invalid_path.stderr | 9 ++++++ .../define_opaques_attr/missing_parens.rs | 5 ++++ .../define_opaques_attr/missing_parens.stderr | 8 +++++ .../define_opaques_attr/no_opaque.rs | 8 +++++ .../define_opaques_attr/non_type.rs | 7 +++++ .../define_opaques_attr/non_type.stderr | 9 ++++++ 12 files changed, 120 insertions(+), 8 deletions(-) create mode 100644 tests/ui/type-alias-impl-trait/define_opaques_attr/foreign_type.rs create mode 100644 tests/ui/type-alias-impl-trait/define_opaques_attr/foreign_type.stderr create mode 100644 tests/ui/type-alias-impl-trait/define_opaques_attr/generics.rs create mode 100644 tests/ui/type-alias-impl-trait/define_opaques_attr/generics.stderr create mode 100644 tests/ui/type-alias-impl-trait/define_opaques_attr/invalid_path.rs create mode 100644 tests/ui/type-alias-impl-trait/define_opaques_attr/invalid_path.stderr create mode 100644 tests/ui/type-alias-impl-trait/define_opaques_attr/missing_parens.rs create mode 100644 tests/ui/type-alias-impl-trait/define_opaques_attr/missing_parens.stderr create mode 100644 tests/ui/type-alias-impl-trait/define_opaques_attr/no_opaque.rs create mode 100644 tests/ui/type-alias-impl-trait/define_opaques_attr/non_type.rs create mode 100644 tests/ui/type-alias-impl-trait/define_opaques_attr/non_type.stderr diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index d14784a49c95..6dcb3f7c4688 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1678,14 +1678,20 @@ impl<'hir> LoweringContext<'_, 'hir> { let define_opaques = define_opaques.as_ref()?; let define_opaques = define_opaques .iter() - // TODO: error reporting for non-local items being mentioned and tests that go through these code paths - .map(|(id, _path)| { - self.resolver - .get_partial_res(*id) - .unwrap() - .expect_full_res() - .def_id() - .expect_local() + .filter_map(|(id, path)| { + let res = self.resolver.get_partial_res(*id).unwrap(); + let Some(did) = res.expect_full_res().opt_def_id() else { + self.dcx().span_delayed_bug(path.span, "should have errored in resolve"); + return None; + }; + let Some(did) = did.as_local() else { + self.dcx().span_err( + path.span, + "only opaque types defined in the local crate can be defined", + ); + return None; + }; + Some(did) }) .collect(); Some(hir::Attribute::Parsed(AttributeKind::DefineOpaques(define_opaques))) diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/foreign_type.rs b/tests/ui/type-alias-impl-trait/define_opaques_attr/foreign_type.rs new file mode 100644 index 000000000000..939d70b63921 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/foreign_type.rs @@ -0,0 +1,5 @@ +#![feature(type_alias_impl_trait)] + +#[define_opaques(String)] +//~^ ERROR: only opaque types defined in the local crate can be defined +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/foreign_type.stderr b/tests/ui/type-alias-impl-trait/define_opaques_attr/foreign_type.stderr new file mode 100644 index 000000000000..8cf3ba68968b --- /dev/null +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/foreign_type.stderr @@ -0,0 +1,8 @@ +error: only opaque types defined in the local crate can be defined + --> $DIR/foreign_type.rs:3:18 + | +LL | #[define_opaques(String)] + | ^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/generics.rs b/tests/ui/type-alias-impl-trait/define_opaques_attr/generics.rs new file mode 100644 index 000000000000..745ee43a1c7d --- /dev/null +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/generics.rs @@ -0,0 +1,13 @@ +#![feature(type_alias_impl_trait)] + +type Tait = impl Sized; +//~^ ERROR: unconstrained opaque type + +#[define_opaques(Tait::<()>)] +//~^ ERROR: expected unsuffixed literal +fn foo() {} + +#[define_opaques(Tait<()>)] +//~^ ERROR: expected one of `(`, `,`, `::`, or `=`, found `<` +fn main() {} +//~^ ERROR: `main` function not found diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/generics.stderr b/tests/ui/type-alias-impl-trait/define_opaques_attr/generics.stderr new file mode 100644 index 000000000000..eaa3a7c62f6b --- /dev/null +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/generics.stderr @@ -0,0 +1,29 @@ +error: expected unsuffixed literal, found `<` + --> $DIR/generics.rs:6:24 + | +LL | #[define_opaques(Tait::<()>)] + | ^ + +error: expected one of `(`, `,`, `::`, or `=`, found `<` + --> $DIR/generics.rs:10:22 + | +LL | #[define_opaques(Tait<()>)] + | ^ expected one of `(`, `,`, `::`, or `=` + +error[E0601]: `main` function not found in crate `generics` + --> $DIR/generics.rs:12:13 + | +LL | fn main() {} + | ^ consider adding a `main` function to `$DIR/generics.rs` + +error: unconstrained opaque type + --> $DIR/generics.rs:3:16 + | +LL | type Tait = impl Sized; + | ^^^^^^^^^^ + | + = note: `Tait` must be used in combination with a concrete type within the same crate + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0601`. diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/invalid_path.rs b/tests/ui/type-alias-impl-trait/define_opaques_attr/invalid_path.rs new file mode 100644 index 000000000000..566d5e78ca8a --- /dev/null +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/invalid_path.rs @@ -0,0 +1,5 @@ +#![feature(type_alias_impl_trait)] + +#[define_opaques(Boom)] +//~^ ERROR: cannot find type alias or associated type +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/invalid_path.stderr b/tests/ui/type-alias-impl-trait/define_opaques_attr/invalid_path.stderr new file mode 100644 index 000000000000..2c5466259af1 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/invalid_path.stderr @@ -0,0 +1,9 @@ +error[E0412]: cannot find type alias or associated type with opaqaue types `Boom` in this scope + --> $DIR/invalid_path.rs:3:18 + | +LL | #[define_opaques(Boom)] + | ^^^^ not found in this scope + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0412`. diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/missing_parens.rs b/tests/ui/type-alias-impl-trait/define_opaques_attr/missing_parens.rs new file mode 100644 index 000000000000..f1d05c96822c --- /dev/null +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/missing_parens.rs @@ -0,0 +1,5 @@ +#![feature(type_alias_impl_trait)] + +#[define_opaques] +//~^ ERROR: expected list of type aliases +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/missing_parens.stderr b/tests/ui/type-alias-impl-trait/define_opaques_attr/missing_parens.stderr new file mode 100644 index 000000000000..cd30c71ad0b2 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/missing_parens.stderr @@ -0,0 +1,8 @@ +error: expected list of type aliases + --> $DIR/missing_parens.rs:3:1 + | +LL | #[define_opaques] + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/no_opaque.rs b/tests/ui/type-alias-impl-trait/define_opaques_attr/no_opaque.rs new file mode 100644 index 000000000000..af0a9ad10afa --- /dev/null +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/no_opaque.rs @@ -0,0 +1,8 @@ +//@ check-pass + +#![feature(type_alias_impl_trait)] + +type Thing = (); + +#[define_opaques(Thing)] +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/non_type.rs b/tests/ui/type-alias-impl-trait/define_opaques_attr/non_type.rs new file mode 100644 index 000000000000..981bea54f11c --- /dev/null +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/non_type.rs @@ -0,0 +1,7 @@ +#![feature(type_alias_impl_trait)] + +fn foo() {} + +#[define_opaques(foo)] +//~^ ERROR: expected type alias or associated type with opaqaue types +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/non_type.stderr b/tests/ui/type-alias-impl-trait/define_opaques_attr/non_type.stderr new file mode 100644 index 000000000000..61c8fffa625f --- /dev/null +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/non_type.stderr @@ -0,0 +1,9 @@ +error[E0573]: expected type alias or associated type with opaqaue types, found function `foo` + --> $DIR/non_type.rs:5:18 + | +LL | #[define_opaques(foo)] + | ^^^ not a type alias or associated type with opaqaue types + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0573`. From 7b5e9825052aabe4fbb49f6fe6de9b1e56637dc3 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 25 Feb 2025 10:22:19 +0000 Subject: [PATCH 5/6] Keep items around even if builtin macros on them fail to parse --- compiler/rustc_expand/src/expand.rs | 4 ++-- .../define_opaques_attr/generics.rs | 1 - .../define_opaques_attr/generics.stderr | 9 +-------- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index e3f31ebeca3f..7acfd3d0e85c 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -770,8 +770,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> { } } Err(err) => { - let guar = err.emit(); - fragment_kind.dummy(span, guar) + let _guar = err.emit(); + fragment_kind.expect_from_annotatables(iter::once(item)) } } } diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/generics.rs b/tests/ui/type-alias-impl-trait/define_opaques_attr/generics.rs index 745ee43a1c7d..fe28c3b41bc1 100644 --- a/tests/ui/type-alias-impl-trait/define_opaques_attr/generics.rs +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/generics.rs @@ -10,4 +10,3 @@ fn foo() {} #[define_opaques(Tait<()>)] //~^ ERROR: expected one of `(`, `,`, `::`, or `=`, found `<` fn main() {} -//~^ ERROR: `main` function not found diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/generics.stderr b/tests/ui/type-alias-impl-trait/define_opaques_attr/generics.stderr index eaa3a7c62f6b..66e2426976d4 100644 --- a/tests/ui/type-alias-impl-trait/define_opaques_attr/generics.stderr +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/generics.stderr @@ -10,12 +10,6 @@ error: expected one of `(`, `,`, `::`, or `=`, found `<` LL | #[define_opaques(Tait<()>)] | ^ expected one of `(`, `,`, `::`, or `=` -error[E0601]: `main` function not found in crate `generics` - --> $DIR/generics.rs:12:13 - | -LL | fn main() {} - | ^ consider adding a `main` function to `$DIR/generics.rs` - error: unconstrained opaque type --> $DIR/generics.rs:3:16 | @@ -24,6 +18,5 @@ LL | type Tait = impl Sized; | = note: `Tait` must be used in combination with a concrete type within the same crate -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0601`. From 6b3cb097a675eee6b65fa70d4a30b7071834e7cf Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 25 Feb 2025 10:31:11 +0000 Subject: [PATCH 6/6] Error on `define_opaques` entries without any opaques actually referenced --- compiler/rustc_ast_lowering/src/item.rs | 2 +- compiler/rustc_attr_data_structures/src/attributes.rs | 2 +- compiler/rustc_ty_utils/src/opaque_types.rs | 7 +++++-- .../define_opaques_attr/no_opaque.rs | 3 +-- .../define_opaques_attr/no_opaque.stderr | 8 ++++++++ 5 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 tests/ui/type-alias-impl-trait/define_opaques_attr/no_opaque.stderr diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 6dcb3f7c4688..7512e00f62ba 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1691,7 +1691,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ); return None; }; - Some(did) + Some((self.lower_span(path.span), did)) }) .collect(); Some(hir::Attribute::Parsed(AttributeKind::DefineOpaques(define_opaques))) diff --git a/compiler/rustc_attr_data_structures/src/attributes.rs b/compiler/rustc_attr_data_structures/src/attributes.rs index cf5024ceeda8..8562f6396e24 100644 --- a/compiler/rustc_attr_data_structures/src/attributes.rs +++ b/compiler/rustc_attr_data_structures/src/attributes.rs @@ -177,7 +177,7 @@ pub enum AttributeKind { }, ConstStabilityIndirect, /// List of type aliases that contain the opaque types that can be defined by the current item. - DefineOpaques(ThinVec), + DefineOpaques(ThinVec<(Span, LocalDefId)>), Deprecation { deprecation: Deprecation, span: Span, diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index be67b774b7a2..d63e559c6339 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -182,11 +182,14 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { else { return; }; - for &define in defines { + for &(span, define) in defines { trace!(?define); let mode = std::mem::replace(&mut self.mode, CollectionMode::Taits); - // TODO: check that opaque types were introduced and error otherwise (also add tests) + let n = self.opaques.len(); super::sig_types::walk_types(self.tcx, define, self); + if n == self.opaques.len() { + self.tcx.dcx().span_err(span, "item does not contain any opaque types"); + } self.mode = mode; } // Allow using `#[define_opaques]` on assoc methods and type aliases to override the default collection mode in diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/no_opaque.rs b/tests/ui/type-alias-impl-trait/define_opaques_attr/no_opaque.rs index af0a9ad10afa..bb636228d56b 100644 --- a/tests/ui/type-alias-impl-trait/define_opaques_attr/no_opaque.rs +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/no_opaque.rs @@ -1,8 +1,7 @@ -//@ check-pass - #![feature(type_alias_impl_trait)] type Thing = (); #[define_opaques(Thing)] +//~^ ERROR item does not contain any opaque types fn main() {} diff --git a/tests/ui/type-alias-impl-trait/define_opaques_attr/no_opaque.stderr b/tests/ui/type-alias-impl-trait/define_opaques_attr/no_opaque.stderr new file mode 100644 index 000000000000..dd136b4a31da --- /dev/null +++ b/tests/ui/type-alias-impl-trait/define_opaques_attr/no_opaque.stderr @@ -0,0 +1,8 @@ +error: item does not contain any opaque types + --> $DIR/no_opaque.rs:5:18 + | +LL | #[define_opaques(Thing)] + | ^^^^^ + +error: aborting due to 1 previous error +