diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 0d79cadef34de..605f7a610a4b1 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -19,6 +19,7 @@ use crate::token::{self, CommentKind, Delimiter, Token}; use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, Spacing, TokenStream, TokenTree}; use crate::util::comments; use crate::util::literal::escape_string_symbol; +use crate::NodeId; pub struct MarkedAttrs(GrowableBitSet); @@ -506,6 +507,16 @@ impl MetaItemKind { } } } + + pub fn defines(&self) -> Vec { + match self { + MetaItemKind::Word => vec![], + MetaItemKind::List(things) => { + things.iter().filter_map(|i| Some(i.meta_item()?.path.segments[0].id)).collect() + } + MetaItemKind::NameValue(_) => vec![], + } + } } impl MetaItemInner { diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index bac3f974ccae9..fef83db96cd73 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -95,6 +95,8 @@ struct LoweringContext<'a, 'hir> { /// Bodies inside the owner being lowered. bodies: Vec<(hir::ItemLocalId, &'hir hir::Body<'hir>)>, + /// Bodies inside the owner being lowered. + defines: SortedMap, /// Attributes inside the owner being lowered. attrs: SortedMap, /// Collect items that were created by lowering the current owner. @@ -146,6 +148,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // HirId handling. bodies: Vec::new(), + defines: SortedMap::default(), attrs: SortedMap::default(), children: Vec::default(), current_hir_id_owner: hir::CRATE_OWNER_ID, @@ -528,6 +531,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let current_attrs = std::mem::take(&mut self.attrs); let current_bodies = std::mem::take(&mut self.bodies); + let current_defines = std::mem::take(&mut self.defines); let current_ident_and_label_to_local_id = std::mem::take(&mut self.ident_and_label_to_local_id); @@ -560,6 +564,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let info = self.make_owner_info(item); self.attrs = current_attrs; + self.defines = current_defines; self.bodies = current_bodies; self.ident_and_label_to_local_id = current_ident_and_label_to_local_id; @@ -578,6 +583,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } fn make_owner_info(&mut self, node: hir::OwnerNode<'hir>) -> &'hir hir::OwnerInfo<'hir> { + let defines = std::mem::take(&mut self.defines); let attrs = std::mem::take(&mut self.attrs); let mut bodies = std::mem::take(&mut self.bodies); let trait_map = std::mem::take(&mut self.trait_map); @@ -595,11 +601,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // Don't hash unless necessary, because it's expensive. let (opt_hash_including_bodies, attrs_hash) = - self.tcx.hash_owner_nodes(node, &bodies, &attrs); + self.tcx.hash_owner_nodes(node, &bodies, &attrs, &defines); let num_nodes = self.item_local_id_counter.as_usize(); let (nodes, parenting) = index::index_hir(self.tcx, node, &bodies, num_nodes); let nodes = hir::OwnerNodes { opt_hash_including_bodies, nodes, bodies }; - let attrs = hir::AttributeMap { map: attrs, opt_hash: attrs_hash }; + let attrs = hir::AttributeMap { map: attrs, defines, opt_hash: attrs_hash }; self.arena.alloc(hir::OwnerInfo { nodes, parenting, attrs, trait_map }) } @@ -847,6 +853,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { debug_assert_eq!(id.owner, self.current_hir_id_owner); let ret = self.arena.alloc_from_iter(attrs.iter().map(|a| self.lower_attr(a))); debug_assert!(!ret.is_empty()); + + let defines = &*self.arena.alloc_from_iter( + ret.iter() + .filter(|attr| attr.has_name(sym::defines)) + .filter_map(|attr| self.resolver.defines.get(&attr.id)) + // TODO: error reporting for non-local items being mentioned and tests that go through these code paths + .flat_map(|defines| defines.into_iter().map(|did| did.expect_local())), + ); + trace!(?id, ?ret, ?defines, "lower_attrs"); + + self.defines.insert(id.local_id, defines); self.attrs.insert(id.local_id, ret); ret } diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index a9696627f11b1..f63ab83c79cf5 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -941,13 +941,18 @@ pub struct ParentedNode<'tcx> { #[derive(Debug)] pub struct AttributeMap<'tcx> { pub map: SortedMap, + /// Preprocessed `#[defines]` attribute. + pub defines: SortedMap, // Only present when the crate hash is needed. pub opt_hash: Option, } impl<'tcx> AttributeMap<'tcx> { - pub const EMPTY: &'static AttributeMap<'static> = - &AttributeMap { map: SortedMap::new(), opt_hash: Some(Fingerprint::ZERO) }; + pub const EMPTY: &'static AttributeMap<'static> = &AttributeMap { + map: SortedMap::new(), + defines: SortedMap::new(), + opt_hash: Some(Fingerprint::ZERO), + }; #[inline] pub fn get(&self, id: ItemLocalId) -> &'tcx [Attribute] { diff --git a/compiler/rustc_hir/src/stable_hash_impls.rs b/compiler/rustc_hir/src/stable_hash_impls.rs index fe169e989ec9f..1e9bf2423843e 100644 --- a/compiler/rustc_hir/src/stable_hash_impls.rs +++ b/compiler/rustc_hir/src/stable_hash_impls.rs @@ -100,9 +100,9 @@ impl<'tcx, HirCtx: crate::HashStableContext> HashStable for OwnerNodes<' impl<'tcx, HirCtx: crate::HashStableContext> HashStable for AttributeMap<'tcx> { fn hash_stable(&self, hcx: &mut HirCtx, hasher: &mut StableHasher) { - // We ignore the `map` since it refers to information included in `opt_hash` which is + // We ignore the `map` and `defines` since they refer to information included in `opt_hash` which is // hashed in the collector and used for the crate hash. - let AttributeMap { opt_hash, map: _ } = *self; + let AttributeMap { opt_hash, map: _, defines: _ } = *self; opt_hash.unwrap().hash_stable(hcx, hasher); } } diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 022a6d457ec56..6e21198bedd8d 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -518,19 +518,18 @@ 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) { + for (_id, node) in tcx.hir().parent_iter(tcx.local_def_id_to_hir_id(opaque_def_id)) { + return match node { 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), + Node::Crate(_) => tcx.hir().walk_toplevel_module(&mut locator), + _ => continue, } - }; - found.break_value() + .break_value(); + } + unreachable!() } } } 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 66255829dcffe..25f6f4be6c2a5 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs @@ -1,15 +1,14 @@ use rustc_errors::StashKey; 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_middle::bug; +use rustc_hir::{self as hir, Expr, ImplItem, Item, Node, TraitItem, def, intravisit}; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt}; +use rustc_middle::{bug, span_bug}; 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. @@ -83,38 +82,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 @@ -138,12 +108,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_name(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) } @@ -177,6 +142,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.is_empty() { + 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 @@ -216,8 +188,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 { @@ -226,18 +196,12 @@ 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), - }); + span_bug!( + hidden_type.span, + "item registered hidden type {} for {:?}, even though it does not define it", + hidden_type.ty, + opaque_type_key + ); } let concrete_type = self.tcx.erase_regions(hidden_type.remap_generic_params_to_declaration_params( @@ -311,19 +275,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 4142dcff226bf..ce9dcea089959 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -423,16 +423,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/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 0c701c834f27e..a54fb687f46a6 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -657,17 +657,6 @@ impl<'hir> Map<'hir> { None } - /// Returns the defining scope for an opaque type definition. - pub fn get_defining_scope(self, id: HirId) -> HirId { - let mut scope = id; - loop { - scope = self.get_enclosing_scope(scope).unwrap_or(CRATE_HIR_ID); - if scope == CRATE_HIR_ID || !matches!(self.tcx.hir_node(scope), Node::Block(_)) { - return scope; - } - } - } - pub fn get_foreign_abi(self, hir_id: HirId) -> ExternAbi { let parent = self.get_parent_item(hir_id); if let OwnerNode::Item(Item { kind: ItemKind::ForeignMod { abi, .. }, .. }) = diff --git a/compiler/rustc_middle/src/hir/mod.rs b/compiler/rustc_middle/src/hir/mod.rs index ad0d70152e1ad..b01ae61da1d2d 100644 --- a/compiler/rustc_middle/src/hir/mod.rs +++ b/compiler/rustc_middle/src/hir/mod.rs @@ -152,6 +152,7 @@ impl<'tcx> TyCtxt<'tcx> { node: OwnerNode<'_>, bodies: &SortedMap>, attrs: &SortedMap, + defines: &SortedMap, ) -> (Option, Option) { if self.needs_crate_hash() { self.with_stable_hashing_context(|mut hcx| { @@ -163,6 +164,7 @@ impl<'tcx> TyCtxt<'tcx> { let mut stable_hasher = StableHasher::new(); attrs.hash_stable(&mut hcx, &mut stable_hasher); + defines.hash_stable(&mut hcx, &mut stable_hasher); let h2 = stable_hasher.finish(); (Some(h1), Some(h2)) }) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 3cbb2a3acf592..18dae68940255 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1228,7 +1228,8 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> { let bodies = Default::default(); let attrs = hir::AttributeMap::EMPTY; - let (opt_hash_including_bodies, _) = self.tcx.hash_owner_nodes(node, &bodies, &attrs.map); + let (opt_hash_including_bodies, _) = + self.tcx.hash_owner_nodes(node, &bodies, &attrs.map, &attrs.defines); let node = node.into(); self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes { opt_hash_including_bodies, diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index c7a2223ecd78b..1cd34ef9a08ab 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -213,6 +213,9 @@ pub struct ResolverAstLowering { /// Information about functions signatures for delegation items expansion pub delegation_fn_sigs: LocalDefIdMap, + + /// List of resolved `#[defines]` attribute arguments. + pub defines: FxHashMap>, } #[derive(Debug)] diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index 7a0a518bb513a..f962ce105e5b4 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -137,6 +137,10 @@ passes_debug_visualizer_placement = passes_debug_visualizer_unreadable = couldn't read {$file}: {$error} +passes_defines_not_fn_or_const = + attribute should be applied to a function definition, a closure, a static, or a const + .label = cannot define hidden types + passes_deprecated = attribute is ignored here diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 074fe77324faf..0d95fc0097e70 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -125,6 +125,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } [sym::inline, ..] => self.check_inline(hir_id, attr, span, target), [sym::coverage, ..] => self.check_coverage(attr, span, target), + [sym::defines] => self.check_defines(attr, span, target), [sym::optimize, ..] => self.check_optimize(hir_id, attr, span, target), [sym::no_sanitize, ..] => self.check_no_sanitize(attr, span, target), [sym::non_exhaustive, ..] => self.check_non_exhaustive(hir_id, attr, span, target), @@ -481,6 +482,25 @@ impl<'tcx> CheckAttrVisitor<'tcx> { } } + /// Checks that `#[defines(..)]` is applied to a function/const/static. + fn check_defines(&self, attr: &Attribute, span: Span, target: Target) { + match target { + Target::Fn + | Target::Closure + | Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) + | Target::Const + | Target::AssocConst + | Target::Static => {} + + _ => { + self.dcx().emit_err(errors::DefinesNotFnOrConst { + attr_span: attr.span, + defn_span: span, + }); + } + } + } + fn check_generic_attr( &self, hir_id: HirId, diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index fdc7e1bba2f0e..ee2e16f64362a 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -86,6 +86,15 @@ pub(crate) struct OptimizeInvalidTarget { pub on_crate: bool, } +#[derive(Diagnostic)] +#[diag(passes_defines_not_fn_or_const)] +pub(crate) struct DefinesNotFnOrConst { + #[primary_span] + pub attr_span: Span, + #[label] + pub defn_span: Span, +} + #[derive(Diagnostic)] #[diag(passes_should_be_applied_to_fn)] pub(crate) struct AttrShouldBeAppliedToFn { diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index fc92dc8b4ed71..53519d5817f47 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -1377,6 +1377,32 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { } } + fn resolve_defines_attr(&mut self, attrs: &[Attribute]) { + for attr in attrs { + // for `#[defines(Path, other::Path)]` attributes we need to resolve the paths + if attr.has_name(sym::defines) { + for item in attr.meta_item_list().unwrap() { + let item = item.meta_item().unwrap(); + match self.resolve_path( + &Segment::from_path(&item.path), + Some(Namespace::TypeNS), + None, + ) { + // TODO: error reporting and tests that go through these code paths + PathResult::Module(_) => todo!(), + PathResult::NonModule(partial_res) => { + let id = self.r.next_node_id(); + self.r.record_partial_res(id, partial_res); + self.r.defines.entry(attr.id).or_default().push(id); + } + PathResult::Indeterminate => todo!(), + PathResult::Failed { .. } => todo!(), + } + } + } + } + } + fn maybe_resolve_ident_in_lexical_scope( &mut self, ident: Ident, @@ -2535,6 +2561,8 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { let name = item.ident.name; debug!("(resolving item) resolving {} ({:?})", name, item.kind); + self.resolve_defines_attr(&item.attrs); + let def_kind = self.r.local_def_kind(item.id); match item.kind { ItemKind::TyAlias(box TyAlias { ref generics, .. }) => { @@ -2990,7 +3018,10 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { &generics.params, RibKind::AssocItem, LifetimeRibKind::Generics { binder: item.id, span: generics.span, kind }, - |this| visit::walk_assoc_item(this, item, AssocCtxt::Trait), + |this| { + this.resolve_defines_attr(&item.attrs); + visit::walk_assoc_item(this, item, AssocCtxt::Trait) + }, ); }; @@ -3193,6 +3224,8 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { seen_trait_items: &mut FxHashMap, trait_id: Option, ) { + self.resolve_defines_attr(&item.attrs); + use crate::ResolutionError::*; self.resolve_doc_links(&item.attrs, MaybeExported::ImplItem(trait_id.ok_or(&item.vis))); match &item.kind { diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index ca4adce37ce03..274a244892a6e 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -40,8 +40,8 @@ use rustc_arena::{DroplessArena, TypedArena}; use rustc_ast::expand::StrippedCfgItem; use rustc_ast::node_id::NodeMap; use rustc_ast::{ - self as ast, AngleBracketedArg, CRATE_NODE_ID, Crate, Expr, ExprKind, GenericArg, GenericArgs, - LitKind, NodeId, Path, attr, + self as ast, AngleBracketedArg, AttrId, CRATE_NODE_ID, Crate, Expr, ExprKind, GenericArg, + GenericArgs, LitKind, NodeId, Path, attr, }; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::intern::Interned; @@ -1018,6 +1018,11 @@ pub struct Resolver<'ra, 'tcx> { /// Used for hints during error reporting. field_visibility_spans: FxHashMap>, + /// Processed `#[defines]` attributes into a list of defines on them (if any). + /// The node ids are ids that can be resolved to the items mentioned + /// in the `defines` list. + defines: FxHashMap>, + /// All imports known to succeed or fail. determined_imports: Vec>, @@ -1433,6 +1438,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { field_names: Default::default(), field_visibility_spans: FxHashMap::default(), + defines: Default::default(), + determined_imports: Vec::new(), indeterminate_imports: Vec::new(), @@ -1640,6 +1647,18 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { stripped_cfg_items, }; let ast_lowering = ty::ResolverAstLowering { + defines: self + .defines + .into_iter() + .map(|(k, v)| { + ( + k, + v.iter() + .map(|id| self.partial_res_map[id].expect_full_res().def_id()) + .collect(), + ) + }) + .collect(), legacy_const_generic_args: self.legacy_const_generic_args, partial_res_map: self.partial_res_map, import_res_map: self.import_res_map, 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 b97f3dc303ba1..2b8c875b64642 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); + // TODO: 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 `#[defines({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_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 41a35c31fe432..978b4bb1acaf0 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2412,6 +2412,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { match self.tcx().type_of_opaque(def_id) { Ok(ty) => t.rebind(vec![ty.instantiate(self.tcx(), args)]), Err(_) => { + // TODO: check if this is still reachable return Err(SelectionError::OpaqueTypeAutoTraitLeakageUnknown(def_id)); } } diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 1cc21f9c5daf1..26ba570faff5f 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -1,13 +1,13 @@ 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}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor}; -use rustc_span::{Span, sym}; +use rustc_span::Span; use tracing::{instrument, trace}; use crate::errors::{DuplicateArg, NotParam}; @@ -30,14 +30,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 `#[defines]` 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 +80,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 +112,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; @@ -193,9 +173,22 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { } } - fn collect_taits_from_defines_attr(&mut self) -> bool { - let Some(_attr) = self.tcx.get_attr(self.item, sym::defines) else { return false }; - true + /// Returns true if a defines attr with entries was found + #[instrument(level = "trace", skip(self))] + fn collect_taits_from_defines_attr(&mut self) { + // TODO: add a nice HIR helper for this, just like `get_attr` + let hir_id = self.tcx.local_def_id_to_hir_id(self.item); + let Some(&defines) = self.tcx.hir_attrs(hir_id.owner).defines.get(&hir_id.local_id) else { + return; + }; + for &define in defines { + // TODO: check that `define` is a type alias (and add tests) + 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; + } } } @@ -215,6 +208,7 @@ impl<'tcx> TypeVisitor> for OpaqueTypeCollector<'tcx> { self.visit_opaque_ty(alias_ty); } // Skips type aliases, as they are meant to be transparent. + // TODO: remove this to require 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) @@ -288,6 +282,7 @@ impl<'tcx> TypeVisitor> for OpaqueTypeCollector<'tcx> { self.visit_opaque_ty(alias_ty); } } + // TODO: remove this arm and fix tests ty::Adt(def, _) if def.did().is_local() => { if let CollectionMode::ImplTraitInAssocTypes = self.mode { return; @@ -322,9 +317,8 @@ fn opaque_types_defined_by<'tcx>( let kind = tcx.def_kind(item); trace!(?kind); let mut collector = OpaqueTypeCollector::new(tcx, item); - if !collector.collect_taits_from_defines_attr() { - super::sig_types::walk_types(tcx, item, &mut collector); - } + collector.collect_taits_from_defines_attr(); + super::sig_types::walk_types(tcx, item, &mut collector); match kind { DefKind::AssocFn | DefKind::Fn @@ -359,6 +353,7 @@ fn opaque_types_defined_by<'tcx>( | 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. + // TODO: just require `defines` attrs on them? DefKind::Closure | DefKind::InlineConst => { collector.opaques.extend(tcx.opaque_types_defined_by(tcx.local_parent(item))); } diff --git a/library/std/src/backtrace.rs b/library/std/src/backtrace.rs index fc333d7ff3f95..cdff315766b53 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), defines(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/tests/ui/associated-inherent-types/constrain_opaque_types_during_projection.rs b/tests/ui/associated-inherent-types/constrain_opaque_types_during_projection.rs index 292733cd49239..c1cea47b90b81 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) { +#[defines(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 07a00b6b9a95f..c05547c55f1fb 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 fecb3b153386b..89e56d79bb5e5 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:, -{ +#[defines(Tait)] +fn hello() { let _: Tait = |x| {}; } 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 fb6a4fcbe9768..6cd75eb1077cd 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; +#[defines(Et1)] fn def_et1() -> Et1 { S1 } @@ -39,6 +40,7 @@ pub fn use_et1() { } type Et2 = impl Tr1; +#[defines(Et2)] fn def_et2() -> Et2 { S1 } @@ -47,6 +49,7 @@ pub fn use_et2() { } type Et3 = impl Tr1>>>; +#[defines(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>>; +#[defines(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 11faf9ac98304..906f5fe115fdc 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(async_closure, type_alias_impl_trait)] type Tait = impl AsyncFn(); +#[defines(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 4a8b5af5769bd..d943a1d8cbea7 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. +#[defines(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. +#[defines(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 19d70c2c6eeb5..40db8b9504432 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; +#[defines(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 d6b3554a5a812..e288958743853 100644 --- a/tests/ui/attributes/collapse-debuginfo-invalid.rs +++ b/tests/ui/attributes/collapse-debuginfo-invalid.rs @@ -85,6 +85,7 @@ impl Foobar for Bar { type Bar = u32; } +#[defines(AFoobar)] fn constraining() -> AFoobar { Bar { field: 3 } } diff --git a/tests/ui/attributes/collapse-debuginfo-invalid.stderr b/tests/ui/attributes/collapse-debuginfo-invalid.stderr index 7cbbd1d647e71..1e97c86b20a5e 100644 --- a/tests/ui/attributes/collapse-debuginfo-invalid.stderr +++ b/tests/ui/attributes/collapse-debuginfo-invalid.stderr @@ -177,7 +177,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)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -201,7 +201,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)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -210,7 +210,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/auto-traits/opaque_type_candidate_selection.rs b/tests/ui/auto-traits/opaque_type_candidate_selection.rs new file mode 100644 index 0000000000000..8b137891791fe --- /dev/null +++ b/tests/ui/auto-traits/opaque_type_candidate_selection.rs @@ -0,0 +1 @@ + diff --git a/tests/ui/auto-traits/opaque_type_candidate_selection.stderr b/tests/ui/auto-traits/opaque_type_candidate_selection.stderr new file mode 100644 index 0000000000000..da5af06e4b953 --- /dev/null +++ b/tests/ui/auto-traits/opaque_type_candidate_selection.stderr @@ -0,0 +1,9 @@ +error[E0601]: `main` function not found in crate `opaque_type_candidate_selection` + --> $DIR/opaque_type_candidate_selection.rs:1:2 + | +LL | + | ^ consider adding a `main` function to `$DIR/opaque_type_candidate_selection.rs` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0601`. diff --git a/tests/ui/coherence/coherence-with-closure.rs b/tests/ui/coherence/coherence-with-closure.rs index 5b6a62b24d4b3..59dcca75aca8b 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; +#[defines(OpaqueClosure)] fn defining_use() -> OpaqueClosure { || () } diff --git a/tests/ui/coherence/coherence-with-closure.stderr b/tests/ui/coherence/coherence-with-closure.stderr index 501279ffe6a72..37f393ceeb70a 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 6b0617e950b7d..0a0f37d61bbbe 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; +#[defines(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 5f58b3088f14d..c7af384df6d30 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 675e9fdfdba7a..42eb75df7960c 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; +#[defines(InnerSend)] fn constrain() -> InnerSend { () } diff --git a/tests/ui/coherence/issue-99663.rs b/tests/ui/coherence/issue-99663.rs index 00d15977d8f09..2f2458bd71fe2 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; +#[defines(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 f3fc22027c26a..d3850df521820 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 04fd139f901ba..508e6f4023426 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.old.stderr b/tests/ui/coherence/occurs-check/opaques.old.stderr new file mode 100644 index 0000000000000..fa13f8630e591 --- /dev/null +++ b/tests/ui/coherence/occurs-check/opaques.old.stderr @@ -0,0 +1,27 @@ +warning: type `Container, T>` is more private than the item `cast` + --> $DIR/opaques.rs:13:1 + | +LL | pub fn cast(x: Container, T>) -> Container { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `cast` is reachable at visibility `pub` + | +note: but type `Container, T>` is only usable at visibility `pub(crate)` + --> $DIR/opaques.rs:18:1 + | +LL | struct Container, U> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: `#[warn(private_interfaces)]` on by default + +warning: type `Container` is more private than the item `cast` + --> $DIR/opaques.rs:13:1 + | +LL | pub fn cast(x: Container, T>) -> Container { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function `cast` is reachable at visibility `pub` + | +note: but type `Container` is only usable at visibility `pub(crate)` + --> $DIR/opaques.rs:18:1 + | +LL | struct Container, U> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +warning: 2 warnings emitted + diff --git a/tests/ui/coherence/occurs-check/opaques.rs b/tests/ui/coherence/occurs-check/opaques.rs index e197256c78c77..036e024e09148 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; + +#[defines(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.classic.stderr b/tests/ui/coherence/orphan-check-opaque-types-not-covering.classic.stderr new file mode 100644 index 0000000000000..f6ae3e9aeff07 --- /dev/null +++ b/tests/ui/coherence/orphan-check-opaque-types-not-covering.classic.stderr @@ -0,0 +1,21 @@ +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:18: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`) + | + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type + = 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:28: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`) + | + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type + = 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: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0210`. diff --git a/tests/ui/coherence/orphan-check-opaque-types-not-covering.next.stderr b/tests/ui/coherence/orphan-check-opaque-types-not-covering.next.stderr new file mode 100644 index 0000000000000..f6ae3e9aeff07 --- /dev/null +++ b/tests/ui/coherence/orphan-check-opaque-types-not-covering.next.stderr @@ -0,0 +1,21 @@ +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:18: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`) + | + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type + = 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:28: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`) + | + = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type + = 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: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0210`. 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 02e9eb65570c0..3adf0734a649b 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; +#[defines(Identity)] fn define_identity(x: T) -> Identity { x } @@ -16,6 +17,7 @@ impl foreign::Trait0 for Identity {} type Opaque = impl Sized; +#[defines(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 57f5bbd227875..6203742b47c0a 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.stderr b/tests/ui/const-generics/generic_const_exprs/opaque_type.stderr index e9fb8c0f403ae..17ff84184b8ea 100644 --- a/tests/ui/const-generics/generic_const_exprs/opaque_type.stderr +++ b/tests/ui/const-generics/generic_const_exprs/opaque_type.stderr @@ -1,3 +1,11 @@ +error: unconstrained opaque type + --> $DIR/opaque_type.rs:4:12 + | +LL | type Foo = impl Sized; + | ^^^^^^^^^^ + | + = note: `Foo` must be used in combination with a concrete type within the same crate + error[E0308]: mismatched types --> $DIR/opaque_type.rs:10:17 | @@ -16,7 +24,7 @@ error[E0605]: non-primitive cast: `usize` as `Foo` 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 -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0308, E0605. For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/opaque_types.rs b/tests/ui/const-generics/opaque_types.rs index 2c7170c889fb3..5be7b20ff0b18 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 +#[defines(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 a060488b3287e..ec7cd2b19960c 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 fd57438bb6171..b92d664c472c9 100644 --- a/tests/ui/const-generics/opaque_types2.rs +++ b/tests/ui/const-generics/opaque_types2.rs @@ -4,12 +4,11 @@ type Foo = impl Sized; fn foo() {} +#[defines(Foo)] const C: Foo = 42; -fn bar() -where - Foo:, -{ +#[defines(Foo)] +fn bar() { foo::(); //~^ ERROR: mismatched types } diff --git a/tests/ui/const-generics/opaque_types2.stderr b/tests/ui/const-generics/opaque_types2.stderr index 2fb1669b7bfab..426e433b82b35 100644 --- a/tests/ui/const-generics/opaque_types2.stderr +++ b/tests/ui/const-generics/opaque_types2.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/opaque_types2.rs:13:11 + --> $DIR/opaque_types2.rs:12:11 | LL | type Foo = impl Sized; | ---------- the found opaque type 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 a92b99976e262..86d7b731be2ba 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,16 @@ type Foo = impl Send; struct A; +#[defines(Foo)] +//~^ ERROR is an experimental feature const VALUE: Foo = value(); //~^ ERROR cannot find function `value` in this scope 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 daf0ccaa776ca..225bb5a693d35 100644 --- a/tests/ui/consts/const-eval/ice-unhandled-type-122191.stderr +++ b/tests/ui/consts/const-eval/ice-unhandled-type-122191.stderr @@ -8,14 +8,24 @@ LL | type Foo = impl Send; = 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]: the `#[defines]` attribute is an experimental feature + --> $DIR/ice-unhandled-type-122191.rs:6:1 + | +LL | #[defines(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[E0425]: cannot find function `value` in this scope - --> $DIR/ice-unhandled-type-122191.rs:6:20 + --> $DIR/ice-unhandled-type-122191.rs:8:20 | LL | const VALUE: Foo = value(); | ^^^^^ not found in this scope error[E0308]: mismatched types - --> $DIR/ice-unhandled-type-122191.rs:11:9 + --> $DIR/ice-unhandled-type-122191.rs:13:9 | LL | type Foo = impl Send; | --------- the expected opaque type @@ -27,14 +37,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 `#[defines(Foo)]` attribute to be able to define hidden types + --> $DIR/ice-unhandled-type-122191.rs:11:4 | LL | fn test() { | ^^^^ error[E0308]: mismatched types - --> $DIR/ice-unhandled-type-122191.rs:11:13 + --> $DIR/ice-unhandled-type-122191.rs:13:13 | LL | type Foo = impl Send; | --------- the expected opaque type @@ -46,13 +56,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 `#[defines(Foo)]` attribute to be able to define hidden types + --> $DIR/ice-unhandled-type-122191.rs:11: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 b9d5cbf801a80..267e0808a3d35 100644 --- a/tests/ui/consts/const-promoted-opaque.atomic.stderr +++ b/tests/ui/consts/const-promoted-opaque.atomic.stderr @@ -1,4 +1,4 @@ -error[E0493]: destructor of `helper::Foo` cannot be evaluated at compile-time +error[E0493]: destructor of `Foo` cannot be evaluated at compile-time --> $DIR/const-promoted-opaque.rs:28:26 | LL | let _: &'static _ = &FOO; diff --git a/tests/ui/consts/const-promoted-opaque.rs b/tests/ui/consts/const-promoted-opaque.rs index bb33e92778aa9..5d6e5147d82c4 100644 --- a/tests/ui/consts/const-promoted-opaque.rs +++ b/tests/ui/consts/const-promoted-opaque.rs @@ -10,23 +10,23 @@ //@[unit] check-pass -mod helper { - pub type Foo = impl Sized; +pub type Foo = impl Sized; - #[cfg(string)] - pub const FOO: Foo = String::new(); +#[cfg(string)] +#[defines(Foo)] +pub const FOO: Foo = String::new(); - #[cfg(atomic)] - pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42); +#[cfg(atomic)] +#[defines(Foo)] +pub const FOO: Foo = std::sync::atomic::AtomicU8::new(42); - #[cfg(unit)] - pub const FOO: Foo = (); -} -use helper::*; +#[cfg(unit)] +#[defines(Foo)] +pub const FOO: Foo = (); const BAR: () = { let _: &'static _ = &FOO; - //[string,atomic]~^ ERROR: destructor of `helper::Foo` cannot be evaluated at compile-time + //[string,atomic]~^ ERROR: destructor of `Foo` cannot be evaluated at compile-time }; const BAZ: &Foo = &FOO; diff --git a/tests/ui/consts/const-promoted-opaque.string.stderr b/tests/ui/consts/const-promoted-opaque.string.stderr index 33e5f426448ca..c8f65d96f9aa7 100644 --- a/tests/ui/consts/const-promoted-opaque.string.stderr +++ b/tests/ui/consts/const-promoted-opaque.string.stderr @@ -1,4 +1,4 @@ -error[E0493]: destructor of `helper::Foo` cannot be evaluated at compile-time +error[E0493]: destructor of `Foo` cannot be evaluated at compile-time --> $DIR/const-promoted-opaque.rs:28:26 | LL | let _: &'static _ = &FOO; 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 795e021ceb084..0549444adad1c 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 { } } + #[defines(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 3e26cf17d29ec..e5ae8b60030f5 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; +#[defines(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 ceadb62c99988..91e352164357d 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 9c3a7e4378e39..9f4fb3e9aea96 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 = ()>; + #[defines(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 35d05e6cf64a3..4436a859ed59a 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; +#[defines(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 bec229631e189..ea2c9b949e429 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 d0be240e07ba6..e0780815e82b3 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,6 +4,7 @@ pub mod foo { type MainFn = impl Fn(); fn bar() {} + #[defines(MainFn)] pub const BAR: MainFn = bar; } 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 50e4cd7d39f79..1e7d82a73bc93 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:11: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 6d17f5e837d94..039f26baf38ea 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); +#[defines(Foo)] fn define() -> Bar { Bar(42) } type Foo2 = impl Debug; -fn define2(_: Foo2) { +#[defines(Foo2)] +fn define2() { let x = || -> Foo2 { 42 }; } type Foo3 = impl Debug; +#[defines(Foo3)] fn define3(x: Foo3) { let y: i32 = x; } -fn define3_1(_: Foo3) { +#[defines(Foo3)] +fn define3_1() { define3(42) } type Foo4 = impl Debug; +#[defines(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 0a8810cf4f8ac..7d505e366c748 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; +#[defines(F)] fn f(a: F) { let mut x = foo::; x = foo::<()>; @@ -20,6 +21,7 @@ fn f(a: F) { type G = impl Sized; +#[defines(G)] fn g(a: G) { let x = foo::<()>; let _: () = x(a); @@ -27,6 +29,7 @@ fn g(a: G) { type H = impl Sized; +#[defines(H)] fn h(a: H) { let x = foo::; let _: H = x(()); @@ -34,6 +37,7 @@ fn h(a: H) { type I = impl Sized; +#[defines(I)] fn i(a: I) { let mut x = foo::<()>; x = foo::; @@ -43,6 +47,7 @@ fn i(a: I) { type J = impl Sized; +#[defines(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 5250e3a3d93e6..ff112d9de015c 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; +#[defines(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; +#[defines(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; +#[defines(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 5000601e90f86..4a0991d0eb3cb 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 7b7610b21c7dc..afaf928dcad09 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>; + #[defines(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 73f984dcfb868..906ce1f50da79 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 5d64ad8eeae0c..c773ca6ef7b49 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; + #[defines(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 54ecc5cfcd810..d8522fda825ab 100644 --- a/tests/ui/generic-associated-types/issue-88287.stderr +++ b/tests/ui/generic-associated-types/issue-88287.stderr @@ -1,11 +1,11 @@ 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:23:3 | LL | type SearchFutureTy<'f, A, B: 'f> | - this type parameter needs to be `Sized` ... -LL | async move { todo!() } - | ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time +LL | = impl Future, ()>> + 'f; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | note: required by an implicit `Sized` bound in `>` --> $DIR/issue-88287.rs:24:6 diff --git a/tests/ui/generic-associated-types/issue-90014-tait.stderr b/tests/ui/generic-associated-types/issue-90014-tait.stderr index 09c2903ab0281..83ea2f4d41091 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 `#[defines(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 ef54a89aaae58..4eda480a29f17 100644 --- a/tests/ui/generic-associated-types/issue-90014-tait2.rs +++ b/tests/ui/generic-associated-types/issue-90014-tait2.rs @@ -22,6 +22,7 @@ impl<'x, T: 'x> Trait<'x> for (T,) { } impl Foo<'_> { + #[defines(Fut)] fn make_fut(&self) -> Box Trait<'a, Thing = Fut<'a>>> { Box::new((async { () },)) } diff --git a/tests/ui/generic-associated-types/issue-90014-tait2.stderr b/tests/ui/generic-associated-types/issue-90014-tait2.stderr index be6f4272ce18c..58390032d92d6 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:26:9 + --> $DIR/issue-90014-tait2.rs:27: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.next.stderr b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.next.stderr index 9e04e90a98ac0..72646b7bc768b 100644 --- a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.next.stderr +++ b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.next.stderr @@ -1,5 +1,5 @@ error[E0284]: type annotations needed: cannot satisfy `Foo == _` - --> $DIR/norm-before-method-resolution-opaque-type.rs:15:19 + --> $DIR/norm-before-method-resolution-opaque-type.rs:16:19 | LL | fn weird_bound(x: &>::Out) -> X | ^ cannot satisfy `Foo == _` 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 479f59843557f..f60839e4f4703 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:15:4 + --> $DIR/norm-before-method-resolution-opaque-type.rs:16: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 ffbfc622bb012..f3a08e90ae30c 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 @@ -12,6 +12,7 @@ impl<'a, T> Trait<'a> for T { type Foo = impl Sized; +#[defines(Foo)] fn weird_bound(x: &>::Out) -> X //[old]~^ ERROR: item does not constrain //[next]~^^ ERROR: cannot satisfy `Foo == _` 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 65e90c1ca53c0..6d5eebb8ca9d2 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,8 @@ unsafe impl Send for MyTy<'_, 'static> {} pub mod step1 { use super::*; pub type Step1<'a, 'b: 'a> = impl Sized + Captures<'b> + 'a; + //~^ ERROR: cycle + #[defines(Step1)] pub fn step1<'a, 'b: 'a>() -> Step1<'a, 'b> { MyTy::<'a, 'b>(None) } @@ -22,8 +24,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. + #[defines(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 +36,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 58d7f9959d346..5a8b84ff0def3 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:32:9 | LL | pub type Step2<'a> = impl Send + 'a; | -------------- opaque type defined here @@ -10,6 +10,28 @@ LL | pub fn step2<'a, 'b: 'a>() -> Step2<'a> LL | crate::step1::step1::<'a, 'b>() | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error[E0391]: cycle detected when computing type of opaque `step1::Step1::{opaque#0}` + --> $DIR/tait-hidden-erased-unsoundness-2.rs:13:34 + | +LL | pub type Step1<'a, 'b: 'a> = impl Sized + Captures<'b> + 'a; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: ...which requires type-checking `step2::step2`... + --> $DIR/tait-hidden-erased-unsoundness-2.rs:28:5 + | +LL | / pub fn step2<'a, 'b: 'a>() -> Step2<'a> +LL | | where +LL | | crate::step1::Step1<'a, 'b>: Send, + | |__________________________________________^ + = note: ...which again requires computing type of opaque `step1::Step1::{opaque#0}`, completing the cycle +note: cycle used when computing type of `step1::Step1::{opaque#0}` + --> $DIR/tait-hidden-erased-unsoundness-2.rs:13:34 + | +LL | pub type Step1<'a, 'b: 'a> = impl Sized + Captures<'b> + 'a; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = 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 2 previous errors -For more information about this error, try `rustc --explain E0700`. +Some errors have detailed explanations: E0391, E0700. +For more information about an error, try `rustc --explain E0391`. 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 40efd941e338c..83eb169234d47 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,16 @@ 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; +#[defines(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>() + //~^ ERROR satisfies auto traits + 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 6c9b8cf24273b..5ad0274474c45 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,13 +1,30 @@ error[E0700]: hidden type for `Tait<'a>` captures lifetime that does not appear in bounds - --> $DIR/tait-hidden-erased-unsoundness.rs:18:9 - | -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>() - | ^^^^^^^^^^^^^^^^^^^^^^^^ + --> $DIR/tait-hidden-erased-unsoundness.rs:18:5 + | +LL | type Tait<'a> = impl Sized + 'a; + | --------------- opaque type defined here +LL | #[defines(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: cannot check whether the hidden type of `tait_hidden_erased_unsoundness[87ee]::Tait::{opaque#0}` satisfies auto traits + --> $DIR/tait-hidden-erased-unsoundness.rs:22:27 + | +LL | fn step3<'a, 'b: 'a>() -> impl Send + 'a { + | ^^^^^^^^^^^^^^ +LL | +LL | step2::<'a, 'b>() + | ----------------- return type was inferred to be `Tait<'_>` here + | + = 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/tait-hidden-erased-unsoundness.rs:15:17 + | +LL | type Tait<'a> = impl Sized + 'a; + | ^^^^^^^^^^^^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0700`. diff --git a/tests/ui/impl-trait/associated-type-undefine.rs b/tests/ui/impl-trait/associated-type-undefine.rs index c8f07021fbf16..895525960fc1a 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 5d9d525eb93bf..5f179684bbb81 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 `#[defines(<() 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 0fb355c523373..2eb9ab680c7c1 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)] + #[defines(OpeningReadFuture)] fn read_fut(&mut self) -> OpeningReadFuture<'_> { self.read() } #[cfg(rpit)] + #[defines(PendingReader)] fn read_fut( &mut self, ) -> impl std::future::Future, CantOpen>> { diff --git a/tests/ui/impl-trait/auto-trait-coherence.next.stderr b/tests/ui/impl-trait/auto-trait-coherence.next.stderr index cd91bfcb48d73..4119078381229 100644 --- a/tests/ui/impl-trait/auto-trait-coherence.next.stderr +++ b/tests/ui/impl-trait/auto-trait-coherence.next.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<_>` - --> $DIR/auto-trait-coherence.rs:24:1 + --> $DIR/auto-trait-coherence.rs:25:1 | LL | impl AnotherTrait for T {} | -------------------------------- first implementation here diff --git a/tests/ui/impl-trait/auto-trait-coherence.old.stderr b/tests/ui/impl-trait/auto-trait-coherence.old.stderr index cd91bfcb48d73..ac4c94522fff6 100644 --- a/tests/ui/impl-trait/auto-trait-coherence.old.stderr +++ b/tests/ui/impl-trait/auto-trait-coherence.old.stderr @@ -1,5 +1,5 @@ -error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D<_>` - --> $DIR/auto-trait-coherence.rs:24:1 +error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D` + --> $DIR/auto-trait-coherence.rs:25:1 | LL | impl AnotherTrait for T {} | -------------------------------- first implementation here diff --git a/tests/ui/impl-trait/auto-trait-coherence.rs b/tests/ui/impl-trait/auto-trait-coherence.rs index 0d7fef21cc92b..9d17ab7439df2 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; +#[defines(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 e0f4c857717cf..cfeccc3d76664 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 801187b6f5e0e..62009ff367703 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>; + #[defines(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 e8c1fcdd21334..4bde457f5770c 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` + #[defines(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 4e452994f72e7..8c9fd2422c1d0 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) { +#[defines(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 af623dc7cd9d1..5d25f8ad600de 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 {} - } +#[defines(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 01c5a553dc502..dca0a7b0a1a9f 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 01c5a553dc502..dca0a7b0a1a9f 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 78ac8363ba930..c830eee1c8563 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; +#[defines(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 3111a21e2096f..c1b2636f02778 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; +#[defines(Tait)] fn reify_as_tait() -> Thunk { Thunk::new(|mut cont| { cont.reify_as(); diff --git a/tests/ui/impl-trait/in-assoc-type-unconstrained.stderr b/tests/ui/impl-trait/in-assoc-type-unconstrained.stderr index 75cbe43eeb4a1..0eebc60da3aab 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 `#[defines(<() 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 d5b543ea953df..3c8e6874c2529 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 `#[defines(<() 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 caf080245687b..1b4c649b17281 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; +#[defines(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 7db2e31549c09..d27eae5a02d61 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; +#[defines(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 acbf3e3e2a024..ff8d539ecf757 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; +#[defines(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 bb248ef717733..8f694c5478a86 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 } +#[defines(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 6ced0bbba8b36..6f5844e46ca9c 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; +#[defines(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; +#[defines(Foo)] +pub fn ham() -> Foo { + //~^ ERROR: item does not constrain `FooRet::{opaque#0}`, but has it in its signature + Bar(1) +} +#[defines(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 4b23a02aaee3f..97d243f249038 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 51bd5f67ed574..6c9da99cb8077 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) { +#[defines(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 f8e85f7ae0008..7a49041cace7e 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 a7e7b067d5ff8..ab915d7157a88 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)] +#[defines(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 e811620c03bad..fd129bd73160f 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: [(); { + #[defines(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 27b4b71283023..ede830bf72c8b 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 5518c2cf12a3b..d7f155699ce78 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; + #[defines(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 109bda0c5cd60..84c7dfb033849 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 cde0b86116033..7b519adf1c406 100644 --- a/tests/ui/impl-trait/issues/issue-86201.rs +++ b/tests/ui/impl-trait/issues/issue-86201.rs @@ -4,6 +4,7 @@ //@ check-pass type FunType = impl Fn<()>; +#[defines(FunType)] static STATIC_FN: FunType = some_fn; fn some_fn() {} diff --git a/tests/ui/impl-trait/issues/issue-86800.rs b/tests/ui/impl-trait/issues/issue-86800.rs index ff1d273ae482e..aea4dd12f3e4f 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>; +#[defines(TransactionFuture)] fn execute_transaction_fut<'f, F, O>( //~^ ERROR: item does not constrain f: F, @@ -36,6 +37,7 @@ where } impl Context { + #[defines(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 fd9b8e7ac9993..3e68221e7d05e 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 3b0e976780beb..cd3fe909ef18f 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 - } +#[defines(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 b05579f216620..c384b745be97b 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; } +#[defines(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 2a2be6b742992..a1e23fe7bdce0 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; +#[defines(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 b968592beffd9..712cbbecd74b4 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 367e7f4e6eafb..baaa36ebdb26f 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; +#[defines(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 00709ee7438a7..780687cfaf834 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 6f90160866ba4..3c9bf83c6279e 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>; +#[defines(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 0474dc0beda6d..809750cad9eb7 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; +#[defines(OpaqueType)] fn mk_opaque() -> OpaqueType { () } diff --git a/tests/ui/impl-trait/negative-reasoning.stderr b/tests/ui/impl-trait/negative-reasoning.stderr index 631784c817b87..2918be5135cec 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 7cb98cfe0601f..9e21d5226fb33 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. +#[defines(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 4383e8ab3a0cd..8105990eac4a3 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 574602079d434..aa1fcf35189fe 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. +#[defines(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 e342973178257..348cd4b7d4c52 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. +#[defines(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 05759fb26979c..f862df49e9fbb 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; +#[defines(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 d32944a0d7214..bb1f524b99250 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 927fa8d596b9d..4267892f07f23 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 +#[defines(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 5b3b2d2e1986e..c7b367a36e2ea 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 +#[defines(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 203fbfc1d2c55..eb1e6f7577fb1 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.stderr +++ b/tests/ui/impl-trait/normalize-tait-in-const.stderr @@ -26,6 +26,33 @@ note: required by a bound in `with_positive` LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { | ^^^^^^ required by this bound in `with_positive` +error: unconstrained opaque type + --> $DIR/normalize-tait-in-const.rs:13: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/normalize-tait-in-const.rs:21: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 `#[defines(foo::Alias)]` attribute to be able to define hidden types + --> $DIR/normalize-tait-in-const.rs:20:18 + | +LL | pub const fn filter_positive<'a>() -> &'a Alias<'a> { + | ^^^^^^^^^^^^^^^ + error[E0015]: cannot call non-const closure in constant functions --> $DIR/normalize-tait-in-const.rs:27:5 | @@ -38,7 +65,7 @@ help: consider further restricting this bound LL | const fn with_positive ~const Fn(&'a Alias<'a>) + ~const Destruct + ~const Fn(&foo::Alias<'_>)>(fun: F) { | ++++++++++++++++++++++++++++ -error: aborting due to 4 previous errors +error: aborting due to 6 previous errors -Some errors have detailed explanations: E0015, E0277. +Some errors have detailed explanations: E0015, E0277, 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 0b29af5df5b58..49a6ae377c7af 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 - } +#[defines(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 3f41c5984b419..3458d0b0f036c 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 { + #[defines(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 b127bf418003e..b613eb002fede 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 @@ -15,7 +15,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 { | ^^ @@ -28,7 +28,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 @@ -38,8 +38,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 `#[defines(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 { | ^^ @@ -49,12 +49,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 aab10be2de27a..3bff992b5b315 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 { } } +#[defines(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 bc810c0f88f3d..a9a5483caa9d4 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 bf194f997b4a4..8845b3ff2c824 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 ebfe7f674be0c..56233b9407487 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 {} +#[defines(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 7d02a0606fc2b..c7fc2b9cf3349 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 5316160125bff..1a4c0f5f7eef5 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 1681b019418e7..a33194d6247ed 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 {} +#[defines(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 fa353a7753606..7b0003ff59b15 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 33695d8ed8030..5d2e500849d63 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 {} +#[defines(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 4879d2db40b81..b2e185d7286a2 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; + #[defines(Existential)] fn f() -> Existential {} println!("{:?}", f()); } diff --git a/tests/ui/implied-bounds/dyn-erasure-tait.rs b/tests/ui/implied-bounds/dyn-erasure-tait.rs index 4766d221d67c0..fed2ec94423fa 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>; +#[defines(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 166321798de30..e121cd0ac61c8 100644 --- a/tests/ui/layout/debug.rs +++ b/tests/ui/layout/debug.rs @@ -17,6 +17,7 @@ type Test = Result; //~ ERROR: layout_of #[rustc_layout(debug)] type T = impl std::fmt::Debug; //~ ERROR: layout_of +#[defines(T)] fn f() -> T { 0i32 } diff --git a/tests/ui/layout/debug.stderr b/tests/ui/layout/debug.stderr index bd31665dac1f7..3bed325660c06 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:82:1 + --> $DIR/debug.rs:83:1 | LL | union EmptyUnion {} | ^^^^^^^^^^^^^^^^^^^ @@ -350,7 +350,7 @@ error: layout_of(V) = Layout { max_repr_align: None, unadjusted_abi_align: Align(2 bytes), } - --> $DIR/debug.rs:25:1 + --> $DIR/debug.rs:26:1 | LL | pub union V { | ^^^^^^^^^^^ @@ -374,7 +374,7 @@ error: layout_of(W) = Layout { max_repr_align: None, unadjusted_abi_align: Align(2 bytes), } - --> $DIR/debug.rs:31:1 + --> $DIR/debug.rs:32:1 | LL | pub union W { | ^^^^^^^^^^^ @@ -398,7 +398,7 @@ error: layout_of(Y) = Layout { max_repr_align: None, unadjusted_abi_align: Align(2 bytes), } - --> $DIR/debug.rs:37:1 + --> $DIR/debug.rs:38:1 | LL | pub union Y { | ^^^^^^^^^^^ @@ -422,7 +422,7 @@ error: layout_of(P1) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:44:1 + --> $DIR/debug.rs:45:1 | LL | union P1 { x: u32 } | ^^^^^^^^ @@ -446,7 +446,7 @@ error: layout_of(P2) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:48:1 + --> $DIR/debug.rs:49:1 | LL | union P2 { x: (u32, u32) } | ^^^^^^^^ @@ -470,7 +470,7 @@ error: layout_of(P3) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:56:1 + --> $DIR/debug.rs:57:1 | LL | union P3 { x: F32x4 } | ^^^^^^^^ @@ -494,7 +494,7 @@ error: layout_of(P4) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:60:1 + --> $DIR/debug.rs:61:1 | LL | union P4 { x: E } | ^^^^^^^^ @@ -523,7 +523,7 @@ error: layout_of(P5) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:64:1 + --> $DIR/debug.rs:65:1 | LL | union P5 { zst: [u16; 0], byte: u8 } | ^^^^^^^^ @@ -552,19 +552,19 @@ error: layout_of(MaybeUninit) = Layout { max_repr_align: None, unadjusted_abi_align: Align(1 bytes), } - --> $DIR/debug.rs:67:1 + --> $DIR/debug.rs:68: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:70:1 + --> $DIR/debug.rs:71:1 | LL | const C: () = (); | ^^^^^^^^^^^ error[E0277]: the size for values of type `str` cannot be known at compilation time - --> $DIR/debug.rs:78:19 + --> $DIR/debug.rs:79:19 | LL | type Impossible = (str, str); | ^^^^^^^^^^ doesn't have a size known at compile-time @@ -573,13 +573,13 @@ LL | type Impossible = (str, str); = note: only the last element of a tuple may have a dynamically sized type error: the type `EmptyUnion` has an unknown layout - --> $DIR/debug.rs:82:1 + --> $DIR/debug.rs:83:1 | LL | union EmptyUnion {} | ^^^^^^^^^^^^^^^^ error: `#[rustc_layout]` can only be applied to `struct`/`enum`/`union` declarations and type aliases - --> $DIR/debug.rs:74:5 + --> $DIR/debug.rs:75: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 95239e2e341c8..3eb6072b5fd08 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; +#[defines(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; +#[defines(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 9e93762277518..793409b9c78e4 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 467400f1c2445..42c8740038b07 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; +#[defines(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 30c0af8a5dc97..c76bad28fc740 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; +#[defines(Foo)] fn foo() -> Foo { if true { |s| s.len() //~ ERROR type annotations needed @@ -10,6 +11,8 @@ fn foo() -> Foo { panic!() } } + +#[defines(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 fe2631f947420..117d189867bd7 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 5193356059904..74d1f883a3a2c 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; +#[defines(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 e14da32e1166e..8484f9333cf96 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; +#[defines(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 7f1cedae068f0..41d08a763fa14 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; +#[defines(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 e1d5cafedc808..0cbedfb69f85a 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 57dd7fb067c6d..fd2470d096ad7 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; +#[defines(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 d8ac39a4f27a3..b04bf6b99877a 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 6f08223945640..f6dc3e91663df 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; +#[defines(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 4eee4f3639297..f77fb8556663e 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 `#[defines(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 84abb933911f5..2cb68d9b9c806 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; +#[defines(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 e4b1872bba55a..a549eb6dc9f3d 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; | ^^^^^^^^^ @@ -19,7 +19,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 f30377d6c16e3..d76f39547bf98 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; +#[defines(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 ef30a406969d3..2d0dfe94f097e 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 ef8ab7e03d2f0..fce11d4bb2d60 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; +#[defines(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 e5607ba72e978..e1a313a290651 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 083fb6c5fb16d..633b581970230 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; +#[defines(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 fcb106c485d85..c4fa955de05ed 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 fc11f23a1049c..d03ba6410c836 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; } +#[defines(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 a3b3ebaac3031..675a9de51cd02 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 fbe0a58f3b5bb..193dd80eb09ba 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; +#[defines(AliasA)] fn use_of_a() -> AliasA { 3 } +#[defines(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 40a9cd00c50ff..634950b29ed43 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 68eeb67deeae3..6e25181536d26 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; +#[defines(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 c83bca4a4c570..6a5f390f92c1a 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; +#[defines(AliasA)] fn use_of_a() -> AliasA { 3 } +#[defines(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 9efc187833f00..020eac4febb80 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 5faeac9ed4c38..56c63863aa4ce 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(); +#[defines(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 7f5d1792bf12a..5c52f70267141 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 b170e6805f646..f86f0e1e22ac1 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; +#[defines(Bar)] fn bar() -> Bar { 42_u32 } impl Foo { + #[defines(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 38684f3548f29..406ed17e714c6 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; +#[defines(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 a464d3266f4eb..91032bc3797e5 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 12c187b9e82aa..b7abe9df7e9ec 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; +#[defines(Foo)] fn a() -> Foo { //~^ ERROR `(): T` is not satisfied panic!() } +#[defines(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 4c32dce465b85..0f197aa5cc6fb 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 ed645b82394a0..b4b8f3a4593ad 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; +#[defines(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 fde8d0896dda2..11425a749534f 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 fe62773fa02db..0e235369f563f 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!() } +#[defines(Foo)] fn a() -> Foo { foo() } diff --git a/tests/ui/pattern/usefulness/impl-trait.rs b/tests/ui/pattern/usefulness/impl-trait.rs index 16560a092675f..689aef883b9cc 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; +#[defines(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; +#[defines(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; +#[defines(V)] fn infer_in_match(x: Option) { match x { None => {} @@ -116,6 +119,7 @@ struct Rec<'a> { n: u32, w: Option<&'a W>, } +#[defines(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); +#[defines(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); +#[defines(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 34f8eb1e1635d..0e3e986b22d01 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 fd0e07fb9b49e..689eeaee8cbac 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; +#[defines(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 34b94f2e1c782..f7c328e062a4f 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; + #[defines(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>>; + #[defines(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>>; + #[defines(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>>; + #[defines(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; + #[defines(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; + #[defines(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>>; + #[defines(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 fb1e4cca3f40b..072bd6c79deb2 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 | #[defines(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 | #[defines(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 | #[defines(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 db5e5e05e54be..7b9eb61dd1abc 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,6 +14,7 @@ impl Trait for Struct { type Assoc<'a> = &'a u32; } +#[defines(Foo)] const FOO: Foo = Struct; //~^ ERROR: expected generic lifetime parameter, found `'a` 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 9b361445f1ec3..8c8f2cd2f95da 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,5 +1,5 @@ error[E0792]: expected generic lifetime parameter, found `'a` - --> $DIR/higher-ranked-regions-gat.rs:17:18 + --> $DIR/higher-ranked-regions-gat.rs:18:18 | LL | pub type FooAssoc<'a> = impl Sized; | -- this generic parameter must be used with a generic lifetime parameter diff --git a/tests/ui/self/arbitrary-self-opaque.rs b/tests/ui/self/arbitrary-self-opaque.rs index c26ef658b695f..4e6498ad7ab49 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 { + #[defines(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 c75165d9f8e27..628db948a5d74 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 7531dcaccf235..fa0e3d49cd7fa 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() {} } +#[defines(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 0cd8be84ed370..0cd18d026e452 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() {} } +#[defines(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 6f0012bf08967..95e86709e5be6 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; +#[defines(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 47181c3f33ed6..7d2bdd7e18635 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 cb9fe176ac958..839f7785cfb31 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) { +#[defines(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 8d92c88ae7251..4a6b77b53a7f6 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) { +#[defines(Tait)] +fn a() { let _: Tait = IntoIterator::into_iter([0i32; 32]); } diff --git a/tests/ui/traits/next-solver/dont-remap-tait-substs.rs b/tests/ui/traits/next-solver/dont-remap-tait-substs.rs new file mode 100644 index 0000000000000..8b137891791fe --- /dev/null +++ b/tests/ui/traits/next-solver/dont-remap-tait-substs.rs @@ -0,0 +1 @@ + diff --git a/tests/ui/traits/next-solver/dont-remap-tait-substs.stderr b/tests/ui/traits/next-solver/dont-remap-tait-substs.stderr new file mode 100644 index 0000000000000..60443c6810937 --- /dev/null +++ b/tests/ui/traits/next-solver/dont-remap-tait-substs.stderr @@ -0,0 +1,9 @@ +error[E0601]: `main` function not found in crate `dont_remap_tait_substs` + --> $DIR/dont-remap-tait-substs.rs:1:2 + | +LL | + | ^ consider adding a `main` function to `$DIR/dont-remap-tait-substs.rs` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0601`. diff --git a/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.is_send.stderr b/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.is_send.stderr new file mode 100644 index 0000000000000..37f81e276934d --- /dev/null +++ b/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.is_send.stderr @@ -0,0 +1,17 @@ +error: this file contains an unclosed delimiter + --> $DIR/dont-type_of-tait-in-defining-scope.rs:30:30 + | +LL | -fn test(_: Foo) { + | - unclosed delimiter +LL | +#[defines(Foo)] +LL | +fn test() { + | - this delimiter might not be properly closed... +... +LL | } + | - ...as it matches this but it has different indentation +... +LL | >>>>>>> Conflict 1 of 1 ends + | ^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.not_send.stderr b/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.not_send.stderr new file mode 100644 index 0000000000000..37f81e276934d --- /dev/null +++ b/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.not_send.stderr @@ -0,0 +1,17 @@ +error: this file contains an unclosed delimiter + --> $DIR/dont-type_of-tait-in-defining-scope.rs:30:30 + | +LL | -fn test(_: Foo) { + | - unclosed delimiter +LL | +#[defines(Foo)] +LL | +fn test() { + | - this delimiter might not be properly closed... +... +LL | } + | - ...as it matches this but it has different indentation +... +LL | >>>>>>> Conflict 1 of 1 ends + | ^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.rs b/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.rs new file mode 100644 index 0000000000000..8b137891791fe --- /dev/null +++ b/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.rs @@ -0,0 +1 @@ + diff --git a/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.stderr b/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.stderr new file mode 100644 index 0000000000000..e0964e8489f06 --- /dev/null +++ b/tests/ui/traits/next-solver/dont-type_of-tait-in-defining-scope.stderr @@ -0,0 +1,9 @@ +error[E0601]: `main` function not found in crate `dont_type_of_tait_in_defining_scope` + --> $DIR/dont-type_of-tait-in-defining-scope.rs:1:2 + | +LL | + | ^ consider adding a `main` function to `$DIR/dont-type_of-tait-in-defining-scope.rs` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0601`. 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 158fefd1538f3..961e094b193d9 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,9 +1,30 @@ -error[E0284]: type annotations needed: cannot satisfy `Foo == _` - --> $DIR/dont-type_of-tait-in-defining-scope.rs:15:18 +error: unconstrained opaque type + --> $DIR/dont-type_of-tait-in-defining-scope.rs:7:12 | -LL | needs_send::(); - | ^^^ cannot satisfy `Foo == _` +LL | type Foo = impl Send; + | ^^^^^^^^^ + | + = note: `Foo` must be used in combination with a concrete type within the same crate + +error[E0308]: mismatched types + --> $DIR/dont-type_of-tait-in-defining-scope.rs:20:18 + | +LL | type Foo = impl Send; + | --------- the expected opaque type +... +LL | let _: Foo = (); + | --- ^^ types differ + | | + | expected due to this + | + = note: expected opaque type `Foo` + found unit type `()` +note: this item must have a `#[defines(Foo)]` attribute to be able to define hidden types + --> $DIR/dont-type_of-tait-in-defining-scope.rs:19:4 + | +LL | fn defines(_: Foo) { + | ^^^^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0284`. +For more information about this error, try `rustc --explain E0308`. 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 158fefd1538f3..e2e9e67ebb57c 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,9 +1,30 @@ -error[E0284]: type annotations needed: cannot satisfy `Foo == _` - --> $DIR/dont-type_of-tait-in-defining-scope.rs:15:18 +error: unconstrained opaque type + --> $DIR/dont-type_of-tait-in-defining-scope.rs:10:12 | -LL | needs_send::(); - | ^^^ cannot satisfy `Foo == _` +LL | type Foo = impl Sized; + | ^^^^^^^^^^ + | + = note: `Foo` must be used in combination with a concrete type within the same crate + +error[E0308]: mismatched types + --> $DIR/dont-type_of-tait-in-defining-scope.rs:20:18 + | +LL | type Foo = impl Sized; + | ---------- the expected opaque type +... +LL | let _: Foo = (); + | --- ^^ types differ + | | + | expected due to this + | + = note: expected opaque type `Foo` + found unit type `()` +note: this item must have a `#[defines(Foo)]` attribute to be able to define hidden types + --> $DIR/dont-type_of-tait-in-defining-scope.rs:19:4 + | +LL | fn defines(_: Foo) { + | ^^^^^^^ -error: aborting due to 1 previous error +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0284`. +For more information about this error, try `rustc --explain E0308`. 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 9a28dc093c1be..61a847e721ab0 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 @@ -1,34 +1,133 @@ -error: unconstrained opaque type - --> $DIR/no-define-in-wf-check.rs:19:18 +error[E0308]: mismatched types + --> $DIR/no-define-in-wf-check.rs:22:13 | LL | type Tait1 = impl Sized; - | ^^^^^^^^^^ + | ---------- the expected opaque type +... +LL | let () = x; + | ^^ - this expression has type `ex1::Tait1` + | | + | expected opaque type, found `()` | - = note: `Tait1` must be used in combination with a concrete type within the same module + = note: expected opaque type `ex1::Tait1` + found unit type `()` +note: this item must have a `#[defines(ex1::Tait1)]` attribute to be able to define hidden types + --> $DIR/no-define-in-wf-check.rs:21:8 + | +LL | fn foo(x: Tait1) -> impl Sized { + | ^^^ -error: unconstrained opaque type - --> $DIR/no-define-in-wf-check.rs:27:18 +error[E0308]: mismatched types + --> $DIR/no-define-in-wf-check.rs:31:13 | LL | type Tait1 = impl Sized; - | ^^^^^^^^^^ + | ---------- the expected opaque type +... +LL | let () = x; + | ^^ - this expression has type `ex2::Tait1` + | | + | expected opaque type, found `()` + | + = note: expected opaque type `ex2::Tait1` + found unit type `()` +note: this item must have a `#[defines(ex2::Tait1)]` attribute to be able to define hidden types + --> $DIR/no-define-in-wf-check.rs:30:8 + | +LL | fn foo(x: Tait1) -> Tait2 { + | ^^^ + +error[E0308]: mismatched types + --> $DIR/no-define-in-wf-check.rs:30:25 | - = note: `Tait1` must be used in combination with a concrete type within the same module +LL | type Tait2 = impl Sized; + | ---------- the expected opaque type +LL | fn foo(x: Tait1) -> Tait2 { + | --- ^^^^^ expected opaque type, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression + | + = note: expected opaque type `ex2::Tait2` + found unit type `()` +note: this item must have a `#[defines(ex2::Tait2)]` attribute to be able to define hidden types + --> $DIR/no-define-in-wf-check.rs:30:8 + | +LL | fn foo(x: Tait1) -> Tait2 { + | ^^^ -error: unconstrained opaque type - --> $DIR/no-define-in-wf-check.rs:36:18 +error[E0308]: mismatched types + --> $DIR/no-define-in-wf-check.rs:42:13 | LL | type Tait1 = impl Sized; - | ^^^^^^^^^^ + | ---------- the expected opaque type +... +LL | let () = x; + | ^^ - this expression has type `ex3::Tait1` + | | + | expected opaque type, found `()` + | + = note: expected opaque type `ex3::Tait1` + found unit type `()` +note: this item must have a `#[defines(ex3::Tait1)]` attribute to be able to define hidden types + --> $DIR/no-define-in-wf-check.rs:41:8 + | +LL | fn foo(x: Tait1) -> Tait2 { + | ^^^ + +error[E0308]: mismatched types + --> $DIR/no-define-in-wf-check.rs:41:25 + | +LL | type Tait2 = impl Something; + | --------------------- the expected opaque type +LL | fn foo(x: Tait1) -> Tait2 { + | --- ^^^^^ expected opaque type, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression | - = note: `Tait1` must be used in combination with a concrete type within the same module + = note: expected opaque type `ex3::Tait2` + found unit type `()` +note: this item must have a `#[defines(ex3::Tait2)]` attribute to be able to define hidden types + --> $DIR/no-define-in-wf-check.rs:41:8 + | +LL | fn foo(x: Tait1) -> Tait2 { + | ^^^ -error: unconstrained opaque type - --> $DIR/no-define-in-wf-check.rs:47:18 +error[E0308]: mismatched types + --> $DIR/no-define-in-wf-check.rs:62:13 | LL | type Tait1 = impl Sized; - | ^^^^^^^^^^ + | ---------- the expected opaque type +... +LL | let () = x; + | ^^ - this expression has type `ex4::Tait1` + | | + | expected opaque type, found `()` + | + = note: expected opaque type `ex4::Tait1` + found unit type `()` +note: this item must have a `#[defines(ex4::Tait1)]` attribute to be able to define hidden types + --> $DIR/no-define-in-wf-check.rs:61:8 + | +LL | fn foo(x: Tait1) -> Tait2 { + | ^^^ + +error[E0308]: mismatched types + --> $DIR/no-define-in-wf-check.rs:61:25 + | +LL | type Tait2 = impl Trait<(), Assoc = impl Trait>; + | ----------------------------------------- the expected opaque type +LL | fn foo(x: Tait1) -> Tait2 { + | --- ^^^^^ expected opaque type, found `()` + | | + | implicitly returns `()` as its body has no tail or `return` expression + | + = note: expected opaque type `ex4::Tait2` + found unit type `()` +note: this item must have a `#[defines(ex4::Tait2)]` attribute to be able to define hidden types + --> $DIR/no-define-in-wf-check.rs:61:8 | - = note: `Tait1` must be used in combination with a concrete type within the same module +LL | fn foo(x: Tait1) -> Tait2 { + | ^^^ -error: aborting due to 4 previous errors +error: aborting due to 7 previous errors +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/traits/pointee-tail-is-generic-errors.rs b/tests/ui/traits/pointee-tail-is-generic-errors.rs index 92a83f40b184c..bd682b0568574 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; +#[defines(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 0c3d7060dd7c3..907f07026a43a 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 14bdf0880c73b..60513dd4bac72 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 {} - } +#[defines(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 a3a1ce29465b1..2b9361c60cfa8 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>; } +#[defines(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 07f1549e177fb..ef58c8fa04c71 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; +#[defines(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 cdf9deecd5159..7f51d1519db22 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 7382d4c78c7df..6fe4fdd0bb101 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; - } +#[defines(Foo)] +fn foo1(mut x: Foo) { + x = 22_u32; +} - pub fn foo_value() -> Foo { - 11_u32 - } +#[defines(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 9dcbc75db3f12..b76eecd42c82c 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 - } +#[defines(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 a1185cd5ba88f..f160102b16021 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; + #[defines(Helper)] fn foo() -> Helper { Dummy } + #[defines(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 a03a146d0418c..dd75a9e8e9891 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 - } +#[defines(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 fc89b0e870e39..fdb5f52f27d6e 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) - } +#[defines(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 2ed918eca1714..d2db468b51958 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 cad75cffe05f6..54284b736e30f 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; + #[defines(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 index 6bdc76aab4503..e69de29bb2d1d 100644 --- a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr +++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr @@ -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 e7bca2231de4b..09f09c49abebe 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; +#[defines(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 54a22510066fe..45f496912900e 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; +#[defines(Tait)] fn _constrain() -> Tait {} struct WrapperWithDrop(T); 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 55df117d0664c..7ccf067ce1754 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,30 +26,13 @@ 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 +error: unconstrained 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 | -LL | fn uwu(x: UninhabitedVariants) { - | ^^^ - | - = note: consider moving the opaque type's declaration and defining uses into a separate module -note: this opaque type is in the signature - --> $DIR/bad-tait-no-substs.rs:5:21 - | -LL | type Alias<'a, U> = impl Trait; - | ^^^^^^^^^^^^^ + = note: `Alias` must be used in combination with a concrete type within the same crate error[E0004]: non-exhaustive patterns: `UninhabitedVariants::Tuple(_)` not covered --> $DIR/bad-tait-no-substs.rs:16:11 @@ -72,7 +55,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 3b83b2e544b01..ad769abd04d56 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; +#[defines(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 74012e34e9214..8fb5a1d58ec48 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 {} +#[defines(Foo)] fn foo_desugared {} impl Trait for () {} +#[defines(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 14f9dbbdb4e93..289826cc1d02e 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 45f54266014d6..db62771fdbbe0 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 - } +#[defines(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 8f887a6ac68f9..7bead92f68f75 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,18 @@ error[E0277]: the trait bound `T: Clone` is not satisfied - --> $DIR/bounds-are-checked-2.rs:10:9 + --> $DIR/bounds-are-checked-2.rs:6:17 | -LL | t - | ^ the trait `Clone` is not implemented for `T` +LL | pub type X = impl Clone; + | ^^^^^^^^^^ 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; - | ^^^^^ -note: this definition site has more where clauses than the opaque type - --> $DIR/bounds-are-checked-2.rs:9:5 - | -LL | fn f(t: T) -> X { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | pub type X = impl Clone; + | ^^^^^ help: consider restricting type parameter `T` | -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 7c3a3a8440606..9b5d776f1ada5 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>; +#[defines(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 ad1b9f19d8ef9..7617268dd8e0c 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 5a9e87c091961..0259b5735ba86 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` +#[defines(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 8e24a937d1d47..ef8bc931b85f1 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); +#[defines(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 0dfa1f40ae6c2..3507c76d9d79c 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<'_> { - () - } +#[defines(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 effc6cae482a8..5f8972803361b 100644 --- a/tests/ui/type-alias-impl-trait/closure_args.rs +++ b/tests/ui/type-alias-impl-trait/closure_args.rs @@ -8,6 +8,7 @@ pub trait Anything {} impl Anything for T {} pub type Input = impl Anything; +#[defines(Input)] fn bop(_: Input) { run( |x: u32| { @@ -17,7 +18,6 @@ fn bop(_: Input) { ); } -#[defines()] 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 13ac3d31d838a..e3b8520f399ad 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; +#[defines(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 fa0514c34a091..ca21442645593 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; +#[defines(Foo)] fn foo() -> Foo { || -> _ {} } // The `_` in the closure return type can also be the TAIT itself. type Bar = impl Sized; +#[defines(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 e78c7c16c8e68..c9d9a6eda0e1e 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; + #[defines(Opaque)] fn define<'a: 'a>() -> Opaque { || {} } @@ -31,6 +32,7 @@ mod test2 { &'a (): Trait, = impl Sized + 'a; + #[defines(Opaque)] fn define<'a, 'x, 'y>() -> Opaque<'a> where &'a (): Trait, @@ -52,6 +54,7 @@ mod test3 { (&'a (), &'b ()): Trait, = impl Sized + 'a + 'b; + #[defines(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 caa9b6d979aba..2f45e3af0c11c 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; + #[defines(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; + #[defines(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; + #[defines(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; + #[defines(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 04288112fa86d..527da9cd997bd 100644 --- a/tests/ui/type-alias-impl-trait/closure_wf_outlives.stderr +++ b/tests/ui/type-alias-impl-trait/closure_wf_outlives.stderr @@ -1,8 +1,8 @@ error[E0478]: lifetime bound not satisfied - --> $DIR/closure_wf_outlives.rs:20:9 + --> $DIR/closure_wf_outlives.rs:14:27 | -LL | || {} - | ^^^^^ +LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b; + | ^^^^^^^^^^^^^^^^^^^^ | note: lifetime parameter instantiated with the lifetime `'a` as defined here --> $DIR/closure_wf_outlives.rs:14:17 @@ -16,43 +16,43 @@ LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b; | ^^ error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements - --> $DIR/closure_wf_outlives.rs:34:9 + --> $DIR/closure_wf_outlives.rs:28:27 | -LL | || {} - | ^^^^^ +LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b; + | ^^^^^^^^^^^^^^^^^^^^ | 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:28:27 | -LL | || {} - | ^^^^^ +LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b; + | ^^^^^^^^^^^^^^^^^^^^ 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:28:27 | -LL | || {} - | ^^^^^ +LL | type Opaque<'a, 'b> = impl Sized + 'a + 'b; + | ^^^^^^^^^^^^^^^^^^^^ error[E0310]: the parameter type `T` may not live long enough - --> $DIR/closure_wf_outlives.rs:60:9 + --> $DIR/closure_wf_outlives.rs:57:22 | -LL | || {} - | ^^^^^ - | | - | the parameter type `T` must be valid for the static lifetime... - | ...so that the type `T` will meet its required lifetime bounds... +LL | type Opaque = impl Sized; + | ^^^^^^^^^^ + | | + | the parameter type `T` must be valid for the static lifetime... + | ...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 7bb490bbec818..e658887a1069b 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; +#[defines(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; +#[defines(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 9cc15f14a991d..849ffd214f07d 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 98badeef382de..e99d4636b1343 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 8d7183831109a..6d14594e33a0f 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 760e5210c5b7a..b682bfda49bce 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; +#[defines(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 c1958e4f246d7..02d705d0ace06 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; +#[defines(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 893a27faced67..6b251cfac73c8 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 39b3d535ad45c..175571ccdd8c9 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)` +#[defines(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 2d7de1add490d..1f715d91ce9e6 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; +#[defines(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 5b77bb6c2bc26..b7999a695e7f3 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 8888f2d49df1e..aca487a642d30 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 7149370048b35..6caae406083e7 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; +#[defines(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 d96c86a2e6f16..25f21abfec666 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` 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 7d7d16361ae6d..407e890662cb0 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) { +#[defines(Bar)] +fn bop() { let x = >::Assoc::default(); //[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 909f1f6d61cbe..9d75ca7ed5707 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` 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 0d6eac4216bae..7c09ab6a91ae9 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 af222f6c15347..f864544026e78 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) { +#[defines(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 1391a2036b2e1..af7da2f916191 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; + #[defines(Ty)] fn defining(s: &str) -> Ty<'_> { s } + #[defines(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; + #[defines(Ty)] fn defining(s: &str) -> Ty<'_> { move || s } + #[defines(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; + #[defines(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 436326e66c386..a84edccf39ae1 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 3bae0f1730994..cc6a293d0c20c 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; +#[defines(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 948bd6deacd0d..0edb0a068846d 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 db9c2cc096ab3..32454790dbd04 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; +#[defines(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 772f487d96aae..c2c401da0e89d 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 d60f1ffbccc2d..fb9c975b8188e 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 `#[defines(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 75a4fbdb5d635..2dce515349768 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; + #[defines(Opq)] fn define_1(_: Opq) { let _ = None::<<(Opq, u8) as Indirect>::Ty>; } + #[defines(Opq)] fn define_2() -> Opq { 0u8 } @@ -23,6 +25,7 @@ mod basic { mod lifetime { use super::*; type Opq<'a> = impl Sized + 'a; + #[defines(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 9101e4385b3d3..cb5cc97311526 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; + #[defines(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; + #[defines(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 a8fd1f691dd40..2210291d37b5a 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 3e7bc32640f52..1ea95001d0aa2 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 { + #[defines(super::Foo)] pub(crate) fn foo() -> super::Foo { "foo" } pub(crate) mod bar { + #[defines(crate::Bar)] pub(crate) fn bar() -> crate::Bar { 1 } } } + +mod bar { + pub type Baz = impl std::fmt::Display; +} + +#[defines(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 eadf21c9138c3..53d748cd264d6 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; +#[defines(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 8ce471e395681..c8fbad58c3ce0 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; +#[defines(Opaque)] fn get_one<'a>(a: *mut &'a str) -> Opaque<'a> { a } +#[defines(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 f27f223452523..59b05e7c81f30 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 43dfea97e6dbd..6f8cdbf777d59 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; +#[defines(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 213272f5f3451..562ab4168b536 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 ea69175ba3108..a582ff2f181d1 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 - } +#[defines(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 d8f70e3d77825..06d6433c4b5fd 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 4505c4d95248c..1a762f8cb391a 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; +#[defines(Foo)] fn foo() -> Foo { "" } +#[defines(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 9e6169b2af73f..9a7f4b416f4b4 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 4b5f455e38150..d09325143e82d 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; +#[defines(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 6f5be5467f704..d4bd397592477 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 a4ac27378e1d8..ebd579f516aff 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; +#[defines(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 0fdcb81f66726..cb12fddd9a037 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 0b8157fe33dd7..39ac5cd9625c0 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; +#[defines(Foo)] fn foo() -> Foo { "" } +#[defines(Foo)] fn bar() -> Foo { //~ ERROR: concrete type differs from previous defining opaque type use panic!() } +#[defines(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 2a77eb4c4ac33..38afa3cbcd0ec 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 c39cc192dc74d..d0c30710bf25f 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; +#[defines(Foo)] fn foo() -> Foo { "" } +#[defines(Foo)] fn bar(arg: bool) -> Foo { if arg { panic!() @@ -19,6 +21,7 @@ fn bar(arg: bool) -> Foo { } } +#[defines(Foo)] fn boo(arg: bool) -> Foo { if arg { loop {} @@ -27,6 +30,7 @@ fn boo(arg: bool) -> Foo { } } +#[defines(Foo)] fn bar2(arg: bool) -> Foo { if arg { "bar2" @@ -35,6 +39,7 @@ fn bar2(arg: bool) -> Foo { } } +#[defines(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 bc827a8f2113a..186c677bc3037 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; +#[defines(Tait)] fn one() -> Tait { One } struct Two(T); +#[defines(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 abf4a0d241b2c..21fab8180633f 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 4f424b8c665ad..93e89747d7408 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; +#[defines(OneLifetime)] fn foo<'a, 'b>(a: &'a u32, b: &'b u32) -> OneLifetime<'a, 'b> { a } +#[defines(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 07ba17ad27b8f..b87e884708ab1 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.stderr b/tests/ui/type-alias-impl-trait/drop-analysis-on-unconstrained-tait.stderr index 8e5838d5ddf55..0e54f244bae5c 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 @@ -4,7 +4,38 @@ error: unconstrained opaque type 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 +error: unconstrained opaque type + --> $DIR/drop-analysis-on-unconstrained-tait.rs:9:25 + | +LL | pub type OpaqueIf = impl Trait; + | ^^^^^^^^^^ + | + = note: `OpaqueIf` must be used in combination with a concrete type within the same crate + +error[E0308]: mismatched types + --> $DIR/drop-analysis-on-unconstrained-tait.rs:15:9 + | +LL | pub type OpaqueIf = impl Trait; + | ---------- the expected opaque type +... +LL | pub fn if_impl() -> Parser { + | ---------------- expected `Parser` because of return type +LL | bind(option(block()), |_| block()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Parser`, found `Parser>` +... +LL | pub fn option(arg: Parser

) -> Parser { + | ---------- the found opaque type + | + = note: expected struct `Parser` + found struct `Parser>` +note: this item must have a `#[defines(OpaqueIf)]` attribute to be able to define hidden types + --> $DIR/drop-analysis-on-unconstrained-tait.rs:14:12 + | +LL | pub fn if_impl() -> Parser { + | ^^^^^^^ + +error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0308`. 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 b1d5961067bd7..b002d8cb0d08c 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; +#[defines(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 b209b4bc89df3..5f39553012948 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>; + #[defines(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>; + #[defines(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>; + #[defines(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>; + #[defines(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 b08bc8b826873..c5778c15e3c41 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 | #[defines(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 0ce85a4d6cbe1..955b7ac77e933 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>; + #[defines(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; + #[defines(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 07206dd2491eb..b8863a06a662c 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 () {} +#[defines(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 9ed010f2293ec..51b13283003c3 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 = (); + #[defines(StateWidget)] fn make_state(&self) -> Self::State {} //~^ ERROR item does not constrain } +#[defines(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 9a3f4ae4c1c31..850e81bd6ddb0 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 d8cf7d71fef74..275201b6b1e53 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` +#[defines(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. +#[defines(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 c909ab66f0ee2..1eb0afb13a8d0 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 24e430afac3ab..eaf5735ddca00 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, } +#[defines(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 36d1dcd00ad13..f2dc62dd84e83 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; +#[defines(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 b20073fcdfcde..8dccbc0aadb0c 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:12:21 | -LL | async move { bar.bar() } - | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `B` +LL | type FooFuture = impl Future; + | ^^^^^^^^^^^^^^^^^^^^^^^^ 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 e5f86c8c19355..43e887f36c5fe 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 693af69d6fab9..4a5360c9922e9 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 a059fd3b8227e..378caacccfce8 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>; +#[defines(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 8b683ad282883..fa3713ab93f62 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; +#[defines(MyIter)] fn my_iter(t: T) -> MyIter { std::iter::once(t) } +#[defines(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 72271d158a1a9..6d3279144d8fb 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 169d4f8d50941..e8dee9ef8c911 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; +#[defines(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 b03bf2466e60c..352e6fd3c5c84 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 e3c6f4d874bcb..4061b0b10c58b 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; +#[defines(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 } +#[defines(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 } +#[defines(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 73570de53266f..3e048c8138d04 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 439214911eb97..a6c18ec40aaed 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; +#[defines(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 201535efe1532..e7925a2e33774 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; +#[defines(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 af6e6e1e66e8f..f3d66267e5ac3 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,19 +1,14 @@ error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use2.rs:11:5 + --> $DIR/generic_duplicate_param_use2.rs:8:18 | -LL | t - | ^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` +LL | type Two = impl Debug; + | ^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` | note: required by a bound in an opaque type --> $DIR/generic_duplicate_param_use2.rs:8:23 | 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 - | -LL | fn two(t: T, _: U) -> Two { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider restricting type parameter `T` | LL | type Two = impl Debug; 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 2074f12750f67..9d20f3dd114d3 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; +#[defines(Two)] fn two(t: T, _: U) -> Two { t } +#[defines(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 9a10a4980d806..b0a1bd77f8578 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 d1e5a0f0198b6..c9f6081701f36 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; +#[defines(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 a847bed93da79..edcb3137084ef 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,19 +1,14 @@ error[E0277]: `U` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use4.rs:11:5 + --> $DIR/generic_duplicate_param_use4.rs:8:18 | -LL | u - | ^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` +LL | type Two = impl Debug; + | ^^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` | note: required by a bound in an opaque type --> $DIR/generic_duplicate_param_use4.rs:8:23 | 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 - | -LL | fn three(_: T, u: U) -> Two { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider restricting type parameter `U` | LL | type Two = impl Debug; 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 b3d6beaf84869..fa00a21260edb 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; +#[defines(Two)] fn two(t: T, u: U) -> Two { (t, u) } +#[defines(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 b0027f8fa57bb..b8a2a93741614 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 fa8b2a290b933..4cce200858b56 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; +#[defines(Two)] fn two(t: T, u: U) -> Two { (t, t) } +#[defines(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 09c01932cef7c..983e58d3c7024 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 adc912294fdf9..ab977ccff4034 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; +#[defines(Two)] fn two(t: T, u: U) -> Two { (t, t) } +#[defines(Two)] fn three(t: T, t2: T, u: U) -> Two { (t, t2) } +#[defines(Two)] fn four(t: T, t2: T, u: U, v: V) -> Two { (t, t2) } +#[defines(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 76c13bb027b0f..f931982e34aff 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; +#[defines(Two)] fn two(t: T, _: U) -> Two { (t, 4u32) } +#[defines(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 09d2abe366366..48c98c1e2b15c 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 5da7aab0da7a6..65b176a2dbb92 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; } +#[defines(Two)] fn two(t: T, u: U) -> Two { (t, u, T::BAR) } +#[defines(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 6e1bb3dfa1744..542324c949f19 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 b9b34f55e7e22..bd552e8885802 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; +#[defines(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 68f4c6923ae18..da54746e430c1 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. +#[defines(OneTy)] fn concrete_ty() -> OneTy { - //~^ ERROR: non-defining opaque type use in defining scope 5u32 //~^ ERROR: expected generic type parameter, found `u32` } +#[defines(OneLifetime)] fn concrete_lifetime() -> OneLifetime<'static> { - //~^ ERROR: non-defining opaque type use in defining scope 6u32 //~^ ERROR: expected generic lifetime parameter, found `'static` } +#[defines(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 bd68b4e3ea469..1b0ce7cc619f5 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 c70f473cff578..890835c465ffb 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 +#[defines(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 fd720239a5239..5fe2fefcecfd0 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 c60f5c11cd18c..023e34cc8d504 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 + #[defines(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 c352a33fbbcf0..2b3f7d7502835 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 1acacc778de6c..62c7f4d5ec3e9 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 +#[defines(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 88529b370f133..9f1df384d0506 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:51 + --> $DIR/generic_underconstrained.rs:10:51 | LL | fn underconstrain(_: T) -> Underconstrained { | ___________________________________________________^ diff --git a/tests/ui/type-alias-impl-trait/generic_underconstrained2.rs b/tests/ui/type-alias-impl-trait/generic_underconstrained2.rs index 1e1bece9a1c0b..f26606a09bc57 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 +#[defines(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 +#[defines(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 b3b9cbca96854..90d708742318a 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:53 + --> $DIR/generic_underconstrained2.rs:9:53 | LL | fn underconstrained(_: U) -> Underconstrained { | _____________________________________________________^ @@ -52,7 +52,7 @@ LL | fn underconstrained(_: U) -> Underconstrained { | +++++++++++++++++ error[E0277]: `V` doesn't implement `Debug` - --> $DIR/generic_underconstrained2.rs:17:64 + --> $DIR/generic_underconstrained2.rs:19:64 | LL | fn underconstrained2(_: U, _: V) -> Underconstrained2 { | ________________________________________________________________^ @@ -63,7 +63,7 @@ LL | | } | |_^ `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 eb19b49c7e213..bf97dd9a25c5d 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 00aedfae46375..651170f94c5b9 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 `#[defines(::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 3117060cef0d2..b1dcf98f4dd27 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 4910e794e8d6e..b7cc19e4020d2 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 `#[defines(::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.stderr b/tests/ui/type-alias-impl-trait/hidden_behind_struct_field3.stderr index f10ccc0029973..026d43f6fccae 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 @@ -9,7 +9,7 @@ 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 +note: this item must have a `#[defines(::Assoc2)]` attribute to be able to define hidden types --> $DIR/hidden_behind_struct_field3.rs:18:8 | LL | fn foo() -> Self::Assoc { 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 5b5acb31812f3..e07a4aa3af906 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; + #[defines(Sep)] pub fn mk_sep() -> Sep { String::from("hello") } @@ -34,6 +35,8 @@ 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>; + //~^ ERROR type mismatch + #[defines(Tait)] pub fn define_tait() -> Tait where // this proves `Bar<()>: Copy`, but `define_tait` is @@ -41,7 +44,6 @@ mod sus { (): Proj, { Bar { inner: 1i32, _marker: () } - //~^ ERROR type mismatch } } 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 be68bac55756b..c460e67e34b08 100644 --- a/tests/ui/type-alias-impl-trait/hidden_type_mismatch.stderr +++ b/tests/ui/type-alias-impl-trait/hidden_type_mismatch.stderr @@ -1,40 +1,31 @@ error[E0271]: type mismatch resolving `<() as Proj>::Assoc == i32` - --> $DIR/hidden_type_mismatch.rs:43:9 + --> $DIR/hidden_type_mismatch.rs:37:21 | LL | pub type Sep = impl Sized + std::fmt::Display; | ------------------------------ the found opaque type ... -LL | Bar { inner: 1i32, _marker: () } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<() as Proj>::Assoc == i32` +LL | pub type Tait = impl Copy + From> + Into>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 - | -LL | / pub fn define_tait() -> Tait -LL | | where -LL | | // this proves `Bar<()>: Copy`, but `define_tait` is -LL | | // now uncallable -LL | | (): Proj, - | |______________________________^ error: aborting due to 1 previous error 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 e43f53e40578c..640ea786bc420 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 { + #[defines(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 19c6099135d83..63bd29bddc917 100644 --- a/tests/ui/type-alias-impl-trait/higher_kinded_params2.rs +++ b/tests/ui/type-alias-impl-trait/higher_kinded_params2.rs @@ -22,6 +22,7 @@ struct Terminator; type Successors<'a> = impl std::fmt::Debug + 'a; impl Terminator { + #[defines(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 790e7fe858037..0274d731966fd 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,5 @@ error[E0308]: mismatched types - --> $DIR/higher_kinded_params2.rs:26:13 + --> $DIR/higher_kinded_params2.rs:27:13 | LL | type Tait = impl std::fmt::Debug; | -------------------- the expected opaque type @@ -9,8 +9,8 @@ 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 `#[defines(Tait)]` attribute to be able to define hidden types + --> $DIR/higher_kinded_params2.rs:26:8 | LL | fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> { | ^^^^^^^^^^ 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 3845cde29fa55..65c117a4d603f 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 { + #[defines(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_params3.stderr b/tests/ui/type-alias-impl-trait/higher_kinded_params3.stderr index 41a3f9ce26820..170fc72f03762 100644 --- a/tests/ui/type-alias-impl-trait/higher_kinded_params3.stderr +++ b/tests/ui/type-alias-impl-trait/higher_kinded_params3.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/higher_kinded_params3.rs:26:13 + --> $DIR/higher_kinded_params3.rs:27:13 | LL | type Tait<'a> = impl std::fmt::Debug + 'a; | ------------------------- the expected opaque type @@ -9,8 +9,8 @@ LL | f = g; | = 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 +note: this item must have a `#[defines(Tait)]` attribute to be able to define hidden types + --> $DIR/higher_kinded_params3.rs:26:8 | LL | fn successors(&self, mut f: for<'x> fn(&'x ()) -> <&'x A as B>::C) -> Successors<'_> { | ^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/hkl_forbidden.rs b/tests/ui/type-alias-impl-trait/hkl_forbidden.rs index c6d1202ef85fd..df9194e44c135 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; +#[defines(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; +#[defines(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; +#[defines(Opaque3)] fn test3(s: &str) -> (impl Fn(&str) -> Opaque3<'_>, Opaque3<'_>) { (id, s) //~ ERROR expected generic lifetime parameter, found `'_` } type Opaque4<'a> = impl Sized + 'a; +#[defines(Opaque4)] fn test4(s: &str) -> (Opaque4<'_>, impl Fn(&str) -> Opaque4<'_>) { (s, id) //~ ERROR expected generic lifetime parameter, found `'_` } type Inner<'a> = impl Sized; +#[defines(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 d49be73d94e77..d404d60f31ed9 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 3d583d4413d9a..138930411c7df 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 = (); } +#[defines(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 0a9a9d6bcf4e6..7404c844ae7b0 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 a4148599f77a3..ecad68dddb5bf 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 } +#[defines(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 d262177a86bca..b8c04185a7d14 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 fd06ea677c336..346782f6697f0 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` } +#[defines(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 08ebc3208d7eb..e265921f3adbc 100644 --- a/tests/ui/type-alias-impl-trait/hkl_forbidden4.stderr +++ b/tests/ui/type-alias-impl-trait/hkl_forbidden4.stderr @@ -1,5 +1,5 @@ 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) | ^^^^ @@ -12,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 | / { LL | | @@ -49,7 +49,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 0ee188d825f0d..80763dc30e1ba 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; +#[defines(DummyT)] fn _dummy_t() -> DummyT {} struct Phantom1(PhantomData); @@ -25,6 +26,7 @@ struct Phantom2(PhantomData); struct Scope(Phantom2>); impl Scope { + #[defines(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; + #[defines(DummyT)] fn my_index(self) -> Self::O { //~^ ERROR item does not constrain 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 eace96317dc1d..864b6dcd6f200 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 { | ^^^ @@ -18,7 +18,7 @@ LL | type DummyT = impl F; | ^^^^^^ error: item does not constrain `DummyT::{opaque#0}`, but has it in its signature - --> $DIR/ice-failed-to-resolve-instance-for-110696.rs:44:8 + --> $DIR/ice-failed-to-resolve-instance-for-110696.rs:47:8 | LL | fn my_index(self) -> Self::O { | ^^^^^^^^ 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 00d1a1a226d2f..c374281e4fa5a 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` +#[defines(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 91610c92d2278..da50db51104f1 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; +#[defines(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 3f1a9d12b44f9..5c0d160c7c99b 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; +#[defines(Bar)] fn defining_use() -> Bar { 42 } @@ -18,6 +19,7 @@ impl Bop for Bar {} //~^ ERROR conflicting implementations type Barr = impl std::fmt::Debug; +#[defines(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 aaf75cc3db97c..2f44ee481adcd 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 bce5ba7c91c30..e253ded11c3a2 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; +#[defines(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 8ec20acef4de6..409149311da5f 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 {} +#[defines(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 9840bcef7d14b..0ebf9f064373e 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 a4b8c2d190db9..2303e3eae058f 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 {} +#[defines(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 2259aa7bb1508..4fff9ad26cb35 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 1d7a97c536713..5e602f1b9b8be 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 `#[defines(<() 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 `#[defines(<() 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 269c0eff025d2..19ccd592aaa6b 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; +#[defines(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 23f1141e54447..eda87bcbf90c4 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 845476ef97419..de2953286776d 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; +#[defines(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 76a63741e18e5..c8ce95c92a6e9 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; +#[defines(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 391a8a75786af..887c8552d2f74 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 49997b073c954..3bc6b9205ec15 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 d85c7f60023ee..0adf3d23474c8 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; +#[defines(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 fb251e9bde155..05e521b7a5457 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; + #[defines(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; + #[defines(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; + #[defines(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; + #[defines(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 b7c9c131c7d1a..bbc0b91cd5031 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 7b2bbc995307e..a455a3151d965 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; +//~^ ERROR: the parameter type `A` may not live long enough +#[defines(Ty)] +fn defining(s: A) -> Ty { + s } -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 f23b978d0b640..5fbc245ce7c3d 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:3:18 | -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 | pub type Ty = impl Sized + 'static; + | ^^^^^^^^^^^^^^^^^^^^ + | | + | 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 4a9f162823e35..97a4ccad75212 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; + #[defines(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 065af57a86416..65fe1637a7413 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 +#[defines(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 5ac09e20b02c2..114cac64573ce 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 4c8bf2cfca11e..9b5803ee437fb 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; +#[defines(Foo)] fn bar() -> Foo { None //~^ ERROR: type annotations needed [E0282] } +#[defines(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 3976a43a89c53..0b2bac0a153f9 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 6e4507ed46063..c57f241772a60 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 - } +#[defines(Foo)] +pub fn foo() -> Foo { + is_send(bar()) +} - fn baz() -> Foo { - () - } +pub fn bar() { + is_send(foo()); +} - fn is_send(_: T) {} +#[defines(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 index 8b809ba014d96..e69de29bb2d1d 100644 --- a/tests/ui/type-alias-impl-trait/inference-cycle.stderr +++ b/tests/ui/type-alias-impl-trait/inference-cycle.stderr @@ -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 6609d4eb5a274..c1b097811b76a 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,7 @@ type T = impl Copy; //~^ ERROR cannot resolve opaque type +#[defines(T)] static STATIC: 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 93c52126d69b0..ae9712bd891af 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 169d8e41d20d7..d0dbcf7949771 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 `#[defines(<() 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 9367be8ca07fd..d074b570f0a11 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 - } +#[defines(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 4914632161450..d69a687fa43f5 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; +#[defines(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 df5a6c320a8a7..4f227310ee789 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 d3eb652159346..c57857ff70a81 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; + #[defines(FnType)] fn deref(&self) -> &Self::Target { //~^ ERROR: item does not constrain `ReturnType + #[defines(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 2a4aa63bb8ca1..2e4c24898a66c 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 50eeff0b18fd4..d18b83f70b474 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,14 @@ // 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; + #[defines(Opaque)] fn _unused() -> Opaque { String::new() } - let null = || -> Opaque { 0 }; + let null = #[defines(Opaque)] || -> Opaque { 0 }; //~^ ERROR: concrete type differs from previous defining opaque type use 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 4570ce8e41da0..528ee43a57fa9 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,11 +1,11 @@ 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:50 | -LL | let null = || -> Opaque { 0 }; - | ^ expected `String`, got `i32` +LL | let null = #[defines(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() } | ^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/issue-52843.rs b/tests/ui/type-alias-impl-trait/issue-52843.rs index 159d3ccd27e01..b9ac3d802ae27 100644 --- a/tests/ui/type-alias-impl-trait/issue-52843.rs +++ b/tests/ui/type-alias-impl-trait/issue-52843.rs @@ -1,11 +1,12 @@ #![feature(type_alias_impl_trait)] type Foo = impl Default; +//~^ ERROR: the trait bound `T: Default` is not satisfied #[allow(unused)] +#[defines(Foo)] fn foo(t: T) -> Foo { t - //~^ ERROR: the trait bound `T: Default` is not satisfied } struct NotDefault; diff --git a/tests/ui/type-alias-impl-trait/issue-52843.stderr b/tests/ui/type-alias-impl-trait/issue-52843.stderr index a6bdddbc98c67..fdf22bb808e86 100644 --- a/tests/ui/type-alias-impl-trait/issue-52843.stderr +++ b/tests/ui/type-alias-impl-trait/issue-52843.stderr @@ -1,19 +1,14 @@ error[E0277]: the trait bound `T: Default` is not satisfied - --> $DIR/issue-52843.rs:7:5 + --> $DIR/issue-52843.rs:3:15 | -LL | t - | ^ the trait `Default` is not implemented for `T` +LL | type Foo = impl Default; + | ^^^^^^^^^^^^ the trait `Default` is not implemented for `T` | note: required by a bound in an opaque type --> $DIR/issue-52843.rs:3:20 | LL | type Foo = impl Default; | ^^^^^^^ -note: this definition site has more where clauses than the opaque type - --> $DIR/issue-52843.rs:6:1 - | -LL | fn foo(t: T) -> Foo { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider restricting type parameter `T` | LL | type Foo = impl Default; 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 2383008d042f7..890cb08426e45 100644 --- a/tests/ui/type-alias-impl-trait/issue-53092-2.rs +++ b/tests/ui/type-alias-impl-trait/issue-53092-2.rs @@ -3,10 +3,12 @@ type Bug = impl Fn(T) -> U + Copy; +#[defines(Bug)] const CONST_BUG: Bug = unsafe { std::mem::transmute(|_: u8| ()) }; -//~^ ERROR cycle detected -//~| ERROR: non-defining opaque type use +//~^ ERROR: item does not constrain +//~| ERROR: item does not constrain +#[defines(Bug)] fn make_bug>() -> Bug { |x| x.into() } 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 ac580866704d7..86ee62c32004a 100644 --- a/tests/ui/type-alias-impl-trait/issue-53092-2.stderr +++ b/tests/ui/type-alias-impl-trait/issue-53092-2.stderr @@ -1,17 +1,5 @@ -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` - --> $DIR/issue-53092-2.rs:6:1 + --> $DIR/issue-53092-2.rs:7:1 | LL | const CONST_BUG: Bug = unsafe { std::mem::transmute(|_: u8| ()) }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -30,13 +18,12 @@ 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 + --> $DIR/issue-53092-2.rs:7:1 | 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 -error: aborting due to 2 previous errors +error: aborting due to 1 previous error -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 E0391`. diff --git a/tests/ui/type-alias-impl-trait/issue-53092.rs b/tests/ui/type-alias-impl-trait/issue-53092.rs index 83b51227aaae9..a48c3b2700fa9 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; +//~^ ERROR the trait bound `U: From` is not satisfied - fn make_bug>() -> Bug { - |x| x.into() //~ ERROR the trait bound `U: From` is not satisfied - } +#[defines(Bug)] +fn make_bug>() -> Bug { + |x| x.into() } -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 f04750866c762..d10c0638e117f 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:4:22 | -LL | |x| x.into() - | ^^^^^^^^^^^^ the trait `From` is not implemented for `U` +LL | pub type Bug = impl Fn(T) -> U + Copy; + | ^^^^^^^^^^^^^^^^^^^^^^ 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` | -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 590fce84fc9f1..4d7a9ac32e08f 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; +#[defines(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 0a744e7be9cbd..53490896af798 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 0d9126d399334..137ab6e8085c8 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; +#[defines(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 e54dd01122e0a..1c758409cde6c 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> { + #[defines(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 61af7a0f62500..b03e38f377a27 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` } +#[defines(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 899e81ed562fc..3b28ab7391759 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; +#[defines(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; +#[defines(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 9d74c0687fe67..1701f42390142 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; + +#[defines(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 fb92b1274365c..f7a3529386b43 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 - } +#[defines(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 b9f27b031c72f..f7a3529386b43 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 - } +#[defines(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 6c7c76b5ac728..9be02f17c0721 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 - } +#[defines(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 bba9092e97756..f517d5b65fa28 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 48bd70bcca950..1e44face82b4a 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; + #[defines(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 d42495e934d33..6aaed7d4296a5 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 38abc3ec7e859..5de42024c7228 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(); +#[defines(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 02f2111468a25..f28d8099b1fe0 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(); +#[defines(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 97158ee297da2..8f0e9c5fde04d 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 a0d0355b5af5c..976712056f5ff 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; + #[defines(FooImpl)] fn foo() -> Self::Foo { () } @@ -33,10 +34,12 @@ impl Baz for () { type Foo = FooImpl; type Bar = BarImpl; + #[defines(FooImpl)] fn foo() -> Self::Foo { () } + #[defines(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 6755c03805607..8195c963ce330 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 51f95637969a5..41dff1318ef32 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(()) } +#[defines(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 44ca5cb94b0f1..6a04be433c799 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 { } +#[defines(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 f98ce4a426c46..54751b6aad9ef 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 + +#[defines(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 275b9717cef33..847aa9f433c46 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; +#[defines(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 0e3d01c2d6181..34c053e5aeb0b 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(); +#[defines(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 c320b0db31bb4..794237953c877 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; } +#[defines(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 9dcdb578568aa..8fe832646d9e7 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; +#[defines(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 085bffe907b4b..178aa5cf34535 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 dfe2ee8204c75..0eadca8c658cd 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; +#[defines(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 ea704ffff97ab..bfbd506a7a5c0 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 a0f8e48e268c9..50dfba4e09d0f 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` +#[defines(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 8e631fd1b6a3d..0022bd9d39abe 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; +#[defines(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 18bc4cf91787f..ea4a458f1dadd 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>; +#[defines(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 b90bd312a0ba7..3129da23e7a78 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; +#[defines(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 ed2eb17fbead4..88d2d68ef2465 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 `#[defines(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 0353b7f3787bc..7c972bae7bfef 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::*; +#[defines(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 ce8a38a3361f8..6c4071dd5e1be 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); +#[defines(A)] fn foo() -> A { //~^ ERROR: type annotations needed |_| () diff --git a/tests/ui/type-alias-impl-trait/issue-74244.stderr b/tests/ui/type-alias-impl-trait/issue-74244.stderr index d2b50ffd86b59..b8b869f6c9b43 100644 --- a/tests/ui/type-alias-impl-trait/issue-74244.stderr +++ b/tests/ui/type-alias-impl-trait/issue-74244.stderr @@ -5,7 +5,7 @@ LL | impl Allocator for DefaultAllocator { | ^ unconstrained type parameter error[E0282]: type annotations needed - --> $DIR/issue-74244.rs:16:13 + --> $DIR/issue-74244.rs:17:13 | LL | fn foo() -> A { | ^ cannot infer type for type parameter `T` diff --git a/tests/ui/type-alias-impl-trait/issue-74280.rs b/tests/ui/type-alias-impl-trait/issue-74280.rs index ad641eaa00d38..b91f3e2004445 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; +#[defines(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 c09efbe4e1333..a89a3f77b3d52 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 90ab4fd8d9773..4a5be250bf14b 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; +#[defines(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; +#[defines(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 1dc74c6b5fea2..4c81298907ca9 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; +#[defines(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 85a943c26e2d5..9a382d19b2df4 100644 --- a/tests/ui/type-alias-impl-trait/issue-77179.stderr +++ b/tests/ui/type-alias-impl-trait/issue-77179.stderr @@ -1,31 +1,14 @@ -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<_>; | ^ @@ -33,7 +16,16 @@ LL | fn bar() -> Pointer<_>; | not allowed in type signatures | help: use type parameters instead: `T` +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 2a39da1176c30..451fe1ef1052a 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; +#[defines(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 ec7b9e0e12b3f..ea55a9594f2ad 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 e33102f687c53..9e83de5375fd7 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 f3234bafd1153..fc28f30707883 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; +#[defines(Bar)] fn _defining_use() -> Bar {} trait Trait { @@ -19,6 +20,7 @@ trait Trait { impl Trait for Out { type Out = Out; + #[defines(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 f734c518dd21e..ed677f6d52774 100644 --- a/tests/ui/type-alias-impl-trait/issue-89686.rs +++ b/tests/ui/type-alias-impl-trait/issue-89686.rs @@ -5,18 +5,19 @@ use std::future::Future; type G<'a, T> = impl Future; +//~^ ERROR: the trait bound `T: Trait` is not satisfied trait Trait { type F: Future; fn f(&self) -> Self::F; + #[defines(G)] fn g<'a>(&'a self) -> G<'a, Self> where Self: Sized, { async move { self.f().await } - //~^ ERROR: the trait bound `T: Trait` is not satisfied } } diff --git a/tests/ui/type-alias-impl-trait/issue-89686.stderr b/tests/ui/type-alias-impl-trait/issue-89686.stderr index 91d71339a0848..150be191e1e5b 100644 --- a/tests/ui/type-alias-impl-trait/issue-89686.stderr +++ b/tests/ui/type-alias-impl-trait/issue-89686.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `T: Trait` is not satisfied - --> $DIR/issue-89686.rs:18:9 + --> $DIR/issue-89686.rs:7:17 | -LL | async move { self.f().await } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` +LL | type G<'a, T> = impl Future; + | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` | help: consider restricting type parameter `T` | diff --git a/tests/ui/type-alias-impl-trait/issue-93411.rs b/tests/ui/type-alias-impl-trait/issue-93411.rs index 2d08b7ba4c11a..3ef4d8debc618 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; +#[defines(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 7097123d608c6..abb3f96c93c98 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; + #[defines(T)] fn foo(foo: T) { let (mut x, mut y) = foo; x = 42; @@ -52,6 +53,7 @@ mod only_pattern { type U = impl Copy; + #[defines(U)] fn bar(bar: Option) { match bar { Some((mut x, mut y)) => { @@ -64,6 +66,7 @@ mod only_pattern { type V = impl Copy; + #[defines(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 c177201431a61..e5f2fa0bd5258 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 `#[defines(<() 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 1bc352041a57d..d906a9de83273 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() -> (); +#[defines(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 921667f577b4e..0bee0dfa9c7a3 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 45a55050c4435..b672293913d1f 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; +#[defines(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; +#[defines(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 4f7b0f1740765..719748edc011f 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 a9c05ad33424d..07e7126f8a058 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 6b34358a56ea3..7462d2b478bb6 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 f636aba15c0c4..cf2e285dbad68 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 { + #[defines(Foo)] fn bar(mut self) { self.0 = 42_u32; } @@ -23,6 +24,7 @@ impl Bar { } } +#[defines(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 f69661db79922..0da6c497bc4c0 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 { + #[defines(Foo)] fn bar(self) { self.foo() } @@ -21,6 +22,7 @@ impl Bar { fn foo(self) {} } +#[defines(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 0e6176bfe03c7..c121f75f965b2 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) {} } +#[defines(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 8ffdb21f2517b..9d530eb542703 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`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) 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 8ffdb21f2517b..9d530eb542703 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`, `self: Box`, `self: Rc`, `self: Arc`, or `self: Pin

` (where P is one of the previous types except `Self`) 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 f33b4e473ae86..39a63a6b02407 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 - } +#[defines(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 64355e4560de2..957dada3721ba 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 { + #[defines(Foo)] fn bar(mut self) { self.0 = 42_u32; } } impl Bar { - fn foo(self) - where - Foo:, - { + #[defines(Foo)] + fn foo(self) { self.bar() } } +#[defines(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 f331da1af8793..3012ba2354e16 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 2617ce124c105..bbdd3923821ff 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 b6adf08853f2f..bd7f143b392b5 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 { + #[defines(Tait)] pub fn new() -> Foo { Foo { bar: std::iter::empty() } } + #[defines(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 c178fcf5a9142..066b0b8fe38a3 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; +#[defines(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 e2c21f1636b0c..38293f64d5dfe 100644 --- a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr +++ b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr @@ -1,7 +1,7 @@ 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 } +LL | fn defining<'a, T>(x: &'a i32) -> Opaque { | -- ^ this elided lifetime gets resolved as `'a` | | | lifetime `'a` declared here @@ -9,15 +9,15 @@ 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:7:5 | 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 } - | -- ^ - | | - | hidden type `&'a i32` captures the lifetime `'a` as defined here +... +LL | fn defining<'a, T>(x: &'a i32) -> Opaque { + | -- hidden type `&'a i32` captures the lifetime `'a` as defined here +LL | x + | ^ error: aborting due to 1 previous error; 1 warning emitted 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 b887fcf30831d..8a0b57700afd8 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; +#[defines(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 b050b08a8e2e4..d6558576577f4 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 580fb58ef8388..9f3c66a5e3e6e 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; +#[defines(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 b2b9e604a6b69..03f2b1c532a00 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 aba41a9d85235..9177ac91b4d6b 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; +#[defines(X)] fn f(a: A, b: B) -> (X, X) { (a.clone(), a) } type Tait<'x> = impl Sized; +#[defines(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 da845e86147b7..6fda66be5d4df 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>; +#[defines(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 b5f38074632ee..05a169882cb11 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 14510a5294e69..9714dd990c68f 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; +#[defines(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 c7a4b2115bf23..15e9b6fbf7615 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 11a922443e64a..44fcaeec86e59 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; +#[defines(X)] fn f(a: A, b: B) -> (X, X) { (a, b) } +#[defines(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 c3128ea6f5e9e..42ba769797b7f 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 ca15b134a9947..3a13ab7cb9570 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 aa0c1076117cc..54389efc9c6de 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 ba705d6f85ac7..71ecbfe182939 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; +#[defines(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; +#[defines(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 f208730552d90..eceab2ad9c054 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 | #[defines(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 915432bbe675f..b19f34a67ff7d 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 50d51c7faf91b..bd21f0bc3f62e 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 () {} +#[defines(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 9da3926ac7081..27372ceed9499 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 9647d9e376eb4..b733739e4c863 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 28d72b0cbeede..09c1e1d684ebe 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 () {} +#[defines(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 aaf2812532d36..89d3d26e46258 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 () {} +#[defines(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 969409ebc59e8..282b2d72059f8 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 524703939f1dc..eece8cd5a4318 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 {} +#[defines(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 ca1cf6058ea95..efb82bc8ee667 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 004e79d673879..1cca4599391fe 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; +#[defines(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 4def8948708fc..efd65cc920b41 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 - } +#[defines(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 - } +#[defines(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 889cff1ba09eb..92de050424c43 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 590107d10384a..ca70bc0880610 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; +#[defines(NoReveal)] fn define_no_reveal() -> NoReveal { "" } +#[defines(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 41238c27351d1..c210b074cda9a 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' +#[defines(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 eed88c5df4f46..92df641fbf421 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 61153b1e17141..8417f3df57d5f 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; +#[defines(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 863282a0ff94d..51b6301af4f3c 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 `#[defines(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 `#[defines(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 9fcf42e188c78..82c144ab5ce1d 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() } - } +#[defines(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 a40dac06a01c3..e584073ee98be 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,5 @@ -error: concrete type differs from previous defining opaque type use - --> $DIR/normalize-hidden-types.rs:26: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 - | -LL | dyn_hoops::<_>(0) - | ^^^^^^^^^^^^^^^^^ - -error: concrete type differs from previous defining opaque type use - --> $DIR/normalize-hidden-types.rs:34: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 - | -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 @@ -38,18 +14,6 @@ LL | let _: Opaque = dyn_hoops::(0); = help: consider constraining the associated type `::Gat<'_>` to `()` or calling a method that returns `::Gat<'_>` = 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 - | -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 - | -LL | None - | ^^^^ - -error: aborting due to 4 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0308`. 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 4028dba82bf15..0820b80ce66c2 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; + #[defines(Opaque)] fn define() -> Opaque { dyn_hoops::<_>(0) } @@ -31,13 +32,16 @@ mod typeof_1 { mod typeof_2 { use super::*; type Opaque = impl Sized; + #[defines(Opaque)] fn define_1() -> Opaque { dyn_hoops::<_>(0) } + #[defines(Opaque)] fn define_2() -> Opaque { dyn_hoops::(0) } } mod typeck { use super::*; type Opaque = impl Sized; + #[defines(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; + #[defines(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 131f8d999d878..112ee4d557156 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 d4528fb76fed9..0ed1292fd2b91 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 `#[defines(<() 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 b5ef1470629bf..e906777f6686c 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; +#[defines(Two)] fn three(t: T) -> Two { (t, 5i8) } @@ -20,6 +21,7 @@ impl Bar for u32 { const FOO: i32 = 42; } +#[defines(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 b59f9c49b0776..d90e4531879b9 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 0cf8d41c7fd4a..41bc8d27a3e67 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 () {} +#[defines(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 e3698b23be86f..4d04b4aee4f0e 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>; +#[defines(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 2c6f44d5416e4..931e4783d9523 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; +#[defines(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 c746503071376..ff3f1eb9973c3 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 +#[defines(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 09ec550d71834..07a8ce38f9808 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 c7d5eaa16aaec..18dcc6c1e2bf4 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; +#[defines(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 1ecdd7c2b54c6..f5ecade2f02e6 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 03c133d5d3c2c..6c08a40575746 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; +#[defines(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; +#[defines(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 b8805f9b7f650..7565bbfc6ff0d 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 e072f3ab8e05b..44d2e5470899c 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 +#[defines(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 d3fdea25a3dc4..647637ae32a7c 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/privacy.rs b/tests/ui/type-alias-impl-trait/privacy.rs index a5386bbec0d23..810a08b587251 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); +#[defines(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 50870905c30dd..eeb49b1a4ac92 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 3d1759097d6b3..d67ad9df350d3 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; +#[defines(Diff)] pub fn lift() -> Diff { |_: usize |loop {} } +#[defines(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 e8925b9b489fa..1a8ab21940498 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 10588398c9d7f..851787dd63d64 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" } +#[defines(Op)] +fn foo() -> Op { + &"hello world" +} fn transform() -> impl std::fmt::Display { &0usize } +#[defines(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 eec35548c5504..259f3b2b9f3dc 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 38fb493b49893..9eee41a6e7dd2 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 - } +#[defines(TestImpl)] +pub fn test() -> TestImpl { + A +} - fn make_option2() -> Option { - let inner = make_option().unwrap(); +#[defines(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 252c5d7dfa760..47471c9728c4a 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 34f3788e2341b..a58f315cfbe6b 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 } +#[defines(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 9829c58cf73b7..bd0828885910b 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 37d84feee4b86..351fa13f964bd 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() - } +#[defines(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 80f1b1502d3b5..5133e5ffb695a 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); - } +#[defines(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 e4399f2d8f4d3..dca3ae05bb0ec 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 f96364ccfcddf..0ea3eec5f4bf6 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; +#[defines(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 b33051da2d779..7619eb9e6d686 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-3.rs +++ b/tests/ui/type-alias-impl-trait/self-referential-3.rs @@ -4,6 +4,7 @@ type Bar<'a, 'b> = impl PartialEq> + std::fmt::Debug; +#[defines(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 32eac622e5181..82ce102405441 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:7:31 + --> $DIR/self-referential-3.rs:8: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 29b5a042b7df1..82c3ea23a8f60 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-4.rs +++ b/tests/ui/type-alias-impl-trait/self-referential-4.rs @@ -4,18 +4,21 @@ type Bar<'a, 'b> = impl PartialEq> + std::fmt::Debug; +#[defines(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; +#[defines(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; +#[defines(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 e7f9e232a2747..93d8f0dc1bf63 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:7:31 + --> $DIR/self-referential-4.rs:8: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:13:31 + --> $DIR/self-referential-4.rs:15: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:19:31 + --> $DIR/self-referential-4.rs:22: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 2bd450e6c8609..b7d37f348f16f 100644 --- a/tests/ui/type-alias-impl-trait/self-referential.rs +++ b/tests/ui/type-alias-impl-trait/self-referential.rs @@ -4,6 +4,7 @@ type Bar<'a, 'b> = impl PartialEq> + std::fmt::Debug; +#[defines(Bar)] fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { //~^ ERROR can't compare `&i32` with `Bar<'b, 'a>` i @@ -11,6 +12,7 @@ fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { type Foo<'a, 'b> = (i32, impl PartialEq> + std::fmt::Debug); +#[defines(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) @@ -18,6 +20,7 @@ fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> { type Moo<'a, 'b> = (i32, impl PartialEq> + std::fmt::Debug); +#[defines(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 396237c78980c..4df980a6f9a2d 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:7:31 + --> $DIR/self-referential.rs:8: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:14:31 + --> $DIR/self-referential.rs:16: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:21:31 + --> $DIR/self-referential.rs:24: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 56464af96ed8d..1fbf670f00866 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> { + #[defines(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 index dad515aaa7bd9..6694520d0b569 100644 --- a/tests/ui/type-alias-impl-trait/static-const-types.rs +++ b/tests/ui/type-alias-impl-trait/static-const-types.rs @@ -7,7 +7,9 @@ use std::fmt::Debug; type Foo = impl Debug; +#[defines(Foo)] static FOO1: Foo = 22_u32; +#[defines(Foo)] 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 27f5799c38043..940ffdf08e7c0 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) +#[defines(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.rs b/tests/ui/type-alias-impl-trait/structural-match.rs index 5025959153976..7ba13e719c4f8 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 - } +#[defines(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 c7478b0a135e5..0b72183f3aaaf 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: `foo::Foo` cannot be used in patterns - --> $DIR/structural-match.rs:18:9 +error: `Foo` cannot be used in patterns + --> $DIR/structural-match.rs:17:9 | LL | VALUE => (), | ^^^^^ diff --git a/tests/ui/type-alias-impl-trait/taint.rs b/tests/ui/type-alias-impl-trait/taint.rs index dfb947637c042..4de54058d247a 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 } +#[defines(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 17fcd4b7e9325..e2e34a5d1ba4b 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 109a70c766d42..56721ca3316ce 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; +#[defines(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 be743e8e27003..5362a13641e09 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; +#[defines(TaitSized)] fn def_tait1() -> TaitSized {} type TaitCopy = impl Copy; +#[defines(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 66a6c0a35b50e..9b0595ac16409 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>; +#[defines(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 e46d2bd559cf2..66cd8286283aa 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; +#[defines(Foo)] fn make_foo() -> Foo { vec![1, 2].into_iter() } @@ -12,6 +13,8 @@ fn make_foo() -> Foo { type Bar = impl Send; type Baz = impl Iterator; +// TODO: require `Bar` in this list, too (stop walking through type aliases in `opaque_types_defined_by`) +#[defines(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 6b37552fed145..39dd92275c895 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 @@ -6,6 +6,7 @@ use std::fmt::Debug; pub type Foo = impl Debug; +#[defines(Foo)] const _FOO: Foo = 5; fn main() {} 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 cbd91066c49da..4c54fe5e1de4f 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 {} +#[defines(TE)] fn bla() -> TE { return MyStruct { v: 1 }; } +#[defines(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 819bde0218368..d303cc9aa2bee 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 188b23732f912..2dd7c415f34fd 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; +#[defines(A)] fn f1() -> A { 0 } type B = impl ?Sized; +#[defines(B)] fn f2() -> &'static B { &[0] } type C = impl ?Sized + 'static; +#[defines(C)] fn f3() -> &'static C { &[0] } type D = impl ?Sized; +#[defines(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 1340a4214ee54..b2332a0c63bc5 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; +#[defines(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 8e90f96995324..ebd5de4d06511 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 - } +#[defines(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 ee8922b673e2f..ad96a0eeb87de 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 3d0f1d30ca2b0..e5bb8163a8113 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 675689bac4295..157310bf62366 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 8ca279eec921b..970fef953f33c 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 +#[defines(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 3f7acd3383010..da8fc595f6a6b 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 0fe653ac471a1..9d32f72eba880 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; +#[defines(Foo)] fn foo() -> Foo { "foo" } @@ -24,30 +25,36 @@ fn foo() -> Foo { // two definitions type Bar = impl std::fmt::Display; +#[defines(Bar)] fn bar1() -> Bar { "bar1" } +#[defines(Bar)] fn bar2() -> Bar { "bar2" } type MyIter = impl Iterator; +#[defines(MyIter)] fn my_iter(t: T) -> MyIter { std::iter::once(t) } +#[defines(MyIter)] fn my_iter2(t: T) -> MyIter { std::iter::once(t) } // param names should not have an effect! +#[defines(MyIter)] fn my_iter3(u: U) -> MyIter { std::iter::once(u) } // param position should not have an effect! +#[defines(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; +#[defines(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; +#[defines(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 - } +#[defines(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 65e2feaf7954d..050f7a95b86aa 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; +#[defines(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" - } +#[defines(Bar)] +pub fn bar1() -> Bar { + "bar1" +} - pub type MyIter = impl Iterator; +#[defines(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) - } +#[defines(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) - } +#[defines(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! +#[defines(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! +#[defines(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; +#[defines(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; +#[defines(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 - } +#[defines(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 af575a4ff36ba..e79178bdb1cc3 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>; +#[defines(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 7cf2fe42da8b0..d4a2c23f7a77f 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 cc8caf886cfc3..364f4c69d73c4 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; +#[defines(Foo)] fn foo1() -> (u32, Foo) { let x: Foo = 22_u32; (x, todo!()) } +#[defines(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 09ff006acbddb..3fdbcd5b023b3 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; +#[defines(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 ae3d317ab4649..6825e2b7ec21d 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... +#[defines(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 6d9c8eabfad59..5c98c0bfacaea 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 b3510067047b6..bd78a2a415920 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; +#[defines(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 6206f169c5b9e..7a86685787ced 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 caf21d64027dc..6f53ebf2c01c5 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; +#[defines(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 f4a121ce440d7..0589f9ae11cd1 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 aa537dfc9176c..2d2cb8111e381 100644 --- a/tests/ui/type-alias-impl-trait/underconstrained_generic.rs +++ b/tests/ui/type-alias-impl-trait/underconstrained_generic.rs @@ -17,12 +17,11 @@ impl ProofForConversion for () { } type Converter = impl ProofForConversion; +//~^ ERROR the trait bound `T: Trait` is not satisfied +#[defines(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 48cef847fbbff..2f6b890406b3b 100644 --- a/tests/ui/type-alias-impl-trait/underconstrained_generic.stderr +++ b/tests/ui/type-alias-impl-trait/underconstrained_generic.stderr @@ -1,8 +1,8 @@ error[E0277]: the trait bound `T: Trait` is not satisfied - --> $DIR/underconstrained_generic.rs:22:5 + --> $DIR/underconstrained_generic.rs:19:21 | -LL | () - | ^^ the trait `Trait` is not implemented for `T` +LL | type Converter = impl ProofForConversion; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` | note: required for `()` to implement `ProofForConversion` --> $DIR/underconstrained_generic.rs:13:16 @@ -16,11 +16,6 @@ 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 - | -LL | fn _defining_use() -> Converter { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider restricting type parameter `T` | LL | type Converter = impl ProofForConversion; diff --git a/tests/ui/type-alias-impl-trait/underconstrained_lifetime.rs b/tests/ui/type-alias-impl-trait/underconstrained_lifetime.rs index e8e7dd0ea0822..2f233a2573ac2 100644 --- a/tests/ui/type-alias-impl-trait/underconstrained_lifetime.rs +++ b/tests/ui/type-alias-impl-trait/underconstrained_lifetime.rs @@ -13,11 +13,12 @@ impl<'a, 'b> ProofForConversion<'a, 'b> for &'b &'a () { } type Converter<'a, 'b> = impl ProofForConversion<'a, 'b>; +//~^ ERROR reference has a longer lifetime than the data it references // Even _defining_use with an explicit `'a: 'b` compiles fine, too. +#[defines(Converter)] fn _defining_use<'a, 'b>(x: &'b &'a ()) -> Converter<'a, 'b> { x - //~^ ERROR reference has a longer lifetime than the data it references } fn extend_lifetime<'a, 'b, T: ?Sized>(x: &'a T) -> &'b T { diff --git a/tests/ui/type-alias-impl-trait/underconstrained_lifetime.stderr b/tests/ui/type-alias-impl-trait/underconstrained_lifetime.stderr index 7c07578d887e3..34b50fb1f05e4 100644 --- a/tests/ui/type-alias-impl-trait/underconstrained_lifetime.stderr +++ b/tests/ui/type-alias-impl-trait/underconstrained_lifetime.stderr @@ -1,8 +1,8 @@ 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:15:26 | -LL | x - | ^ +LL | type Converter<'a, 'b> = impl ProofForConversion<'a, 'b>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: the pointer is valid for the lifetime `'b` as defined here --> $DIR/underconstrained_lifetime.rs:15:20 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 56d975355c3e7..2dab81cba6f6a 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 279bd3bca5abe..b58eae671209b 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 5813f529dea19..17309db6ec5a8 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 { + #[defines(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 5b331c5660d9c..a2690dabbb5bb 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 b675bc2e6225f..2853656228eed 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; +#[defines(PartiallyDefined)] fn partially_defined(_: T) -> PartiallyDefined { 4u32 } type PartiallyDefined2 = impl Sized; +#[defines(PartiallyDefined2)] fn partially_defined2(_: T) -> PartiallyDefined2 { 4u32 } +#[defines(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 40e8ec0129a32..de0077eabe899 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> = >, >, >; +#[defines(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 79ce8148f19a4..138e4080c29d3 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 29d4faa7ba908..be87bf17e89ae 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; +#[defines(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 19dd4c1793677..eba7696e10b65 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; +#[defines(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> { +#[defines(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; +#[defines(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 449e9fbd0d847..2bb32dfd81622 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 @@ -5,11 +5,14 @@ trait Bar { } type FooFn = impl FnOnce(B); +//~^ ERROR the trait bound `B: Bar` is not satisfied +#[defines(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 } fn main() { 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 47bea7bbe608c..452784b89fd12 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:7:17 | -LL | mop // NOTE: no function pointer, but function zst item - | ^^^ the trait `Bar` is not implemented for `B` +LL | type FooFn = impl FnOnce(B); + | ^^^^^^^^^^^^^^ 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:12: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` | 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 1484d9fd0734f..50a67adaba815 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); +#[defines(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 56c524c6db066..4d76fbccc914f 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>; +#[defines(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>; +#[defines(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 6d50e11c5da84..d7ac5146c1e72 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 2c70696ffcf48..ad650e11e7b19 100644 --- a/tests/ui/type-alias-impl-trait/wf_check_closures.rs +++ b/tests/ui/type-alias-impl-trait/wf_check_closures.rs @@ -5,10 +5,11 @@ trait Bar { } type FooFn = impl FnOnce(); +//~^ ERROR the trait bound `B: Bar` is not satisfied +#[defines(FooFn)] fn foo(bar: B) -> FooFn { - move || { bar.bar() } - //~^ ERROR the trait bound `B: Bar` is not satisfied + move || bar.bar() } fn main() { 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 09a42f73490a0..ea8d8b8301a1a 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:7:17 | -LL | move || { bar.bar() } - | ^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `B` +LL | type FooFn = impl FnOnce(); + | ^^^^^^^^^^^^^ 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:11: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 437a1aed40307..70ef415104212 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.rs +++ b/tests/ui/typeck/typeck_type_placeholder_item.rs @@ -180,7 +180,8 @@ struct Struct; trait Trait {} impl Trait for Struct {} type Y = impl Trait<_>; -//~^ ERROR the placeholder `_` is not allowed within types on item signatures for type aliases +//~^ ERROR the placeholder `_` is not allowed within types on item signatures for opaque types +#[defines(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 5e32d5c429ef0..bbf2c72d0555b 100644 --- a/tests/ui/typeck/typeck_type_placeholder_item.stderr +++ b/tests/ui/typeck/typeck_type_placeholder_item.stderr @@ -28,663 +28,24 @@ error: expected identifier, found reserved identifier `_` 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 +error: expected item, found `+` + --> $DIR/typeck_type_placeholder_item.rs:184:1 | -LL | const C: _; - | ^^^^^^^^^^- - | | - | help: provide a definition for the constant: `= ;` - -error[E0403]: the name `_` is already used for a generic parameter in this item's generic parameters - --> $DIR/typeck_type_placeholder_item.rs:167:22 - | -LL | struct BadStruct1<_, _>(_); - | - ^ already used - | | - | first use of `_` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:7:14 - | -LL | fn test() -> _ { 5 } - | ^ - | | - | not allowed in type signatures - | help: replace with the correct return type: `i32` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:10:16 - | -LL | fn test2() -> (_, _) { (5, 5) } - | -^--^- - | || | - | || not allowed in type signatures - | |not allowed in type signatures - | help: replace with the correct return type: `(i32, i32)` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:13:15 - | -LL | static TEST3: _ = "test"; - | ^ - | | - | not allowed in type signatures - | help: replace with the correct type: `&str` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:16:15 - | -LL | static TEST4: _ = 145; - | ^ - | | - | not allowed in type signatures - | help: replace with the correct type: `i32` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:19:15 - | -LL | static TEST5: (_, _) = (1, 2); - | ^^^^^^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:22:13 - | -LL | fn test6(_: _) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn test6(_: T) { } - | +++ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:25:18 - | -LL | fn test6_b(_: _, _: T) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn test6_b(_: U, _: T) { } - | +++ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:28:30 - | -LL | fn test6_c(_: _, _: (T, K, L, A, B)) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn test6_c(_: U, _: (T, K, L, A, B)) { } - | +++ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:31:13 - | -LL | fn test7(x: _) { let _x: usize = x; } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn test7(x: T) { let _x: usize = x; } - | +++ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:34:22 - | -LL | fn test8(_f: fn() -> _) { } - | ^ - | | - | not allowed in type signatures - | help: use type parameters instead: `T` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:34:22 - | -LL | fn test8(_f: fn() -> _) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn test8(_f: fn() -> T) { } - | +++ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:48:26 - | -LL | fn test11(x: &usize) -> &_ { - | -^ - | || - | |not allowed in type signatures - | help: replace with the correct return type: `&&usize` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:53:52 - | -LL | unsafe fn test12(x: *const usize) -> *const *const _ { - | --------------^ - | | | - | | not allowed in type signatures - | help: replace with the correct return type: `*const *const usize` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:59:24 - | -LL | fn clone(&self) -> _ { Test9 } - | ^ not allowed in type signatures - | -help: try replacing `_` with the type in the corresponding trait method signature - | -LL | fn clone(&self) -> Test9 { Test9 } - | ~~~~~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:62:37 - | -LL | fn clone_from(&mut self, other: _) { *self = Test9; } - | ^ not allowed in type signatures - | -help: try replacing `_` with the type in the corresponding trait method signature - | -LL | fn clone_from(&mut self, other: &Test9) { *self = Test9; } - | ~~~~~~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:67:8 - | -LL | a: _, - | ^ not allowed in type signatures -LL | -LL | b: (_, _), - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: use type parameters instead - | -LL ~ struct Test10 { -LL ~ a: T, -LL | -LL ~ b: (T, T), +LL | +#[defines(Y)] + | ^ expected item | + = note: for a full list of items that can appear in modules, see error: missing type for `static` item --> $DIR/typeck_type_placeholder_item.rs:73:13 | LL | static A = 42; - | ^ help: provide a type for the static variable: `: i32` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:75:15 - | -LL | static B: _ = 42; - | ^ - | | - | not allowed in type signatures - | help: replace with the correct type: `i32` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:77:15 - | -LL | static C: Option<_> = Some(42); - | ^^^^^^^^^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:79:21 - | -LL | fn fn_test() -> _ { 5 } - | ^ - | | - | not allowed in type signatures - | help: replace with the correct return type: `i32` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:82:23 - | -LL | fn fn_test2() -> (_, _) { (5, 5) } - | -^--^- - | || | - | || not allowed in type signatures - | |not allowed in type signatures - | help: replace with the correct return type: `(i32, i32)` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:85:22 - | -LL | static FN_TEST3: _ = "test"; - | ^ - | | - | not allowed in type signatures - | help: replace with the correct type: `&str` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:88:22 - | -LL | static FN_TEST4: _ = 145; - | ^ - | | - | not allowed in type signatures - | help: replace with the correct type: `i32` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for static variables - --> $DIR/typeck_type_placeholder_item.rs:91:22 - | -LL | static FN_TEST5: (_, _) = (1, 2); - | ^^^^^^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:94:20 - | -LL | fn fn_test6(_: _) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn fn_test6(_: T) { } - | +++ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:97:20 - | -LL | fn fn_test7(x: _) { let _x: usize = x; } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn fn_test7(x: T) { let _x: usize = x; } - | +++ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:100:29 - | -LL | fn fn_test8(_f: fn() -> _) { } - | ^ - | | - | not allowed in type signatures - | help: use type parameters instead: `T` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:100:29 - | -LL | fn fn_test8(_f: fn() -> _) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn fn_test8(_f: fn() -> T) { } - | +++ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:115:28 - | -LL | fn clone(&self) -> _ { FnTest9 } - | ^ not allowed in type signatures - | -help: try replacing `_` with the type in the corresponding trait method signature - | -LL | fn clone(&self) -> FnTest9 { FnTest9 } - | ~~~~~~~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:118:41 - | -LL | fn clone_from(&mut self, other: _) { *self = FnTest9; } - | ^ not allowed in type signatures - | -help: try replacing `_` with the type in the corresponding trait method signature - | -LL | fn clone_from(&mut self, other: &FnTest9) { *self = FnTest9; } - | ~~~~~~~~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:123:12 - | -LL | a: _, - | ^ not allowed in type signatures -LL | -LL | b: (_, _), - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: use type parameters instead - | -LL ~ struct FnTest10 { -LL ~ a: T, -LL | -LL ~ b: (T, T), - | - -error[E0282]: type annotations needed - --> $DIR/typeck_type_placeholder_item.rs:128:21 - | -LL | fn fn_test11(_: _) -> (_, _) { panic!() } - | ^ cannot infer type - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:128:28 - | -LL | fn fn_test11(_: _) -> (_, _) { panic!() } - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:132:30 - | -LL | fn fn_test12(x: i32) -> (_, _) { (x, x) } - | -^--^- - | || | - | || not allowed in type signatures - | |not allowed in type signatures - | help: replace with the correct return type: `(i32, i32)` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:135:33 - | -LL | fn fn_test13(x: _) -> (i32, _) { (x, x) } - | ------^- - | | | - | | not allowed in type signatures - | help: replace with the correct return type: `(i32, i32)` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:140:31 - | -LL | fn method_test1(&self, x: _); - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn method_test1(&self, x: T); - | +++ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:142:31 - | -LL | fn method_test2(&self, x: _) -> _; - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: use type parameters instead - | -LL | fn method_test2(&self, x: T) -> T; - | +++ ~ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:144:31 - | -LL | fn method_test3(&self) -> _; - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn method_test3(&self) -> T; - | +++ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:146:26 - | -LL | fn assoc_fn_test1(x: _); - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn assoc_fn_test1(x: T); - | +++ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:148:26 - | -LL | fn assoc_fn_test2(x: _) -> _; - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: use type parameters instead - | -LL | fn assoc_fn_test2(x: T) -> T; - | +++ ~ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:150:28 - | -LL | fn assoc_fn_test3() -> _; - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn assoc_fn_test3() -> T; - | +++ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:154:21 - | -LL | struct BadStruct<_>(_); - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | struct BadStruct(T); - | ~ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for implementations - --> $DIR/typeck_type_placeholder_item.rs:159:15 - | -LL | impl BadTrait<_> for BadStruct<_> {} - | ^ ^ not allowed in type signatures - | | - | not allowed in type signatures - | -help: use type parameters instead - | -LL | impl BadTrait for BadStruct {} - | +++ ~ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:162:34 - | -LL | fn impl_trait() -> impl BadTrait<_> { - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn impl_trait() -> impl BadTrait { - | +++ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:167:25 - | -LL | struct BadStruct1<_, _>(_); - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | struct BadStruct1(T); - | ~ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs - --> $DIR/typeck_type_placeholder_item.rs:172:25 - | -LL | struct BadStruct2<_, T>(_, T); - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | struct BadStruct2(U, T); - | ~ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for type aliases - --> $DIR/typeck_type_placeholder_item.rs:176:14 - | -LL | type X = Box<_>; - | ^ not allowed in type signatures - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for type aliases - --> $DIR/typeck_type_placeholder_item.rs:182:21 - | -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 - | -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 - | -LL | const D: _ = 42; - | ^ - | | - | not allowed in type signatures - | help: replace with the correct type: `i32` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated constants - --> $DIR/typeck_type_placeholder_item.rs:209: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 - | -LL | type F: std::ops::Fn(_); - | ----------------------- `F` from trait -... -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 - | -LL | fn value() -> Option<&'static _> { - | ----------------^- - | | | - | | not allowed in type signatures - | 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:10 - | -LL | const _: Option<_> = map(value); - | ^^^^^^^^^ - | | - | not allowed in type signatures - | help: replace with the correct type: `Option` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:225:31 - | -LL | fn evens_squared(n: usize) -> _ { - | ^ - | | - | not allowed in type signatures - | 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:230: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:230:29}>, {closure@typeck_type_placeholder_item.rs:230:49}>` cannot be named - --> $DIR/typeck_type_placeholder_item.rs:230:14 - | -LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:41:24 - | -LL | fn test9(&self) -> _ { () } - | ^ - | | - | not allowed in type signatures - | help: replace with the correct return type: `()` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:44:27 - | -LL | fn test10(&self, _x : _) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -LL | fn test10(&self, _x : T) { } - | +++ ~ - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types - --> $DIR/typeck_type_placeholder_item.rs:107:31 - | -LL | fn fn_test9(&self) -> _ { () } - | ^ - | | - | not allowed in type signatures - | help: replace with the correct return type: `()` - -error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/typeck_type_placeholder_item.rs:110:34 - | -LL | fn fn_test10(&self, _x : _) { } - | ^ not allowed in type signatures - | -help: use type parameters instead - | -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 - | -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 - | -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 - | -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 - | -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 - | -LL | type F: std::ops::Fn(_); - | ^ not allowed in type signatures - -error[E0015]: cannot call non-const fn ` as Iterator>::filter::<{closure@$DIR/typeck_type_placeholder_item.rs:230:29: 230:32}>` in constants - --> $DIR/typeck_type_placeholder_item.rs:230: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 fn `, {closure@$DIR/typeck_type_placeholder_item.rs:230:29: 230:32}> as Iterator>::map::` in constants - --> $DIR/typeck_type_placeholder_item.rs:230:45 + | ^ | -LL | const _: _ = (1..10).filter(|x| x % 2 == 0).map(|x| x * x); - | ^^^^^^^^^^^^^^ +help: provide a type for the item | - = note: calls in constants are limited to constant functions, tuple structs and tuple variants +LL | static A: = 42; + | ++++++++ -error: aborting due to 74 previous errors +error: aborting due to 7 previous errors -Some errors have detailed explanations: E0015, E0046, E0121, E0282, E0403. -For more information about an error, try `rustc --explain E0015`.