diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index fb9d71b52a8a6..c3d786bf25c51 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -390,13 +390,19 @@ impl GenericParam { pub struct Generics { pub params: ThinVec, pub where_clause: WhereClause, + pub defines_opaque_types: ThinVec<(NodeId, Path)>, pub span: Span, } -impl Default for Generics { +impl Generics { /// Creates an instance of `Generics`. - fn default() -> Generics { - Generics { params: ThinVec::new(), where_clause: Default::default(), span: DUMMY_SP } + pub fn new(span: Span, defines_opaque_types: ThinVec<(NodeId, Path)>) -> Generics { + Generics { + params: ThinVec::new(), + defines_opaque_types, + where_clause: Default::default(), + span, + } } } @@ -2895,6 +2901,7 @@ pub struct StaticItem { pub ty: P, pub mutability: Mutability, pub expr: Option>, + pub defines_opaque_types: ThinVec<(NodeId, Path)>, } #[derive(Clone, Encodable, Decodable, Debug)] @@ -2902,6 +2909,7 @@ pub struct ConstItem { pub defaultness: Defaultness, pub ty: P, pub expr: Option>, + pub defines_opaque_types: ThinVec<(NodeId, Path)>, } #[derive(Clone, Encodable, Decodable, Debug)] @@ -3098,9 +3106,15 @@ pub enum ForeignItemKind { impl From for ItemKind { fn from(foreign_item_kind: ForeignItemKind) -> ItemKind { match foreign_item_kind { - ForeignItemKind::Static(a, b, c) => { - ItemKind::Static(StaticItem { ty: a, mutability: b, expr: c }.into()) - } + ForeignItemKind::Static(a, b, c) => ItemKind::Static( + StaticItem { + ty: a, + mutability: b, + expr: c, + defines_opaque_types: Default::default(), + } + .into(), + ), ForeignItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind), ForeignItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind), ForeignItemKind::MacCall(a) => ItemKind::MacCall(a), @@ -3113,9 +3127,12 @@ impl TryFrom for ForeignItemKind { fn try_from(item_kind: ItemKind) -> Result { Ok(match item_kind { - ItemKind::Static(box StaticItem { ty: a, mutability: b, expr: c }) => { - ForeignItemKind::Static(a, b, c) - } + ItemKind::Static(box StaticItem { + ty: a, + mutability: b, + expr: c, + defines_opaque_types, + }) if defines_opaque_types.is_empty() => ForeignItemKind::Static(a, b, c), ItemKind::Fn(fn_kind) => ForeignItemKind::Fn(fn_kind), ItemKind::TyAlias(ty_alias_kind) => ForeignItemKind::TyAlias(ty_alias_kind), ItemKind::MacCall(a) => ForeignItemKind::MacCall(a), @@ -3138,15 +3155,15 @@ mod size_asserts { static_assert_size!(Block, 32); static_assert_size!(Expr, 72); static_assert_size!(ExprKind, 40); - static_assert_size!(Fn, 152); + static_assert_size!(Fn, 160); static_assert_size!(ForeignItem, 96); static_assert_size!(ForeignItemKind, 24); static_assert_size!(GenericArg, 24); static_assert_size!(GenericBound, 56); - static_assert_size!(Generics, 40); - static_assert_size!(Impl, 136); - static_assert_size!(Item, 136); - static_assert_size!(ItemKind, 64); + static_assert_size!(Generics, 48); + static_assert_size!(Impl, 144); + static_assert_size!(Item, 152); + static_assert_size!(ItemKind, 80); static_assert_size!(LitKind, 24); static_assert_size!(Local, 72); static_assert_size!(MetaItemLit, 40); diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index c4771115cacf2..1805950c6a3bc 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -5,8 +5,8 @@ use crate::ast::{DelimArgs, Expr, ExprKind, LitKind, MetaItemLit}; use crate::ast::{MacDelimiter, MetaItem, MetaItemKind, NestedMetaItem, NormalAttr}; use crate::ast::{Path, PathSegment, DUMMY_NODE_ID}; use crate::ptr::P; -use crate::token::{self, CommentKind, Delimiter, Token}; -use crate::tokenstream::{DelimSpan, Spacing, TokenTree}; +use crate::token::{self, CommentKind, Delimiter, Token, TokenKind}; +use crate::tokenstream::{AttrTokenStream, AttrTokenTree, DelimSpan, Spacing, TokenTree}; use crate::tokenstream::{LazyAttrTokenStream, TokenStream}; use crate::util::comments; use crate::util::literal::escape_string_symbol; @@ -215,6 +215,51 @@ impl Attribute { )]), } } + + pub fn expand_cfg_attr( + self: &Attribute, + attr_id_generator: &AttrIdGenerator, + (item, item_span): (AttrItem, Span), + ) -> Attribute { + let orig_tokens = self.tokens(); + + // We are taking an attribute of the form `#[cfg_attr(pred, attr)]` + // and producing an attribute of the form `#[attr]`. We + // have captured tokens for `attr` itself, but we need to + // synthesize tokens for the wrapper `#` and `[]`, which + // we do below. + + // Use the `#` in `#[cfg_attr(pred, attr)]` as the `#` token + // for `attr` when we expand it to `#[attr]` + let mut orig_trees = orig_tokens.into_trees(); + let TokenTree::Token(pound_token @ Token { kind: TokenKind::Pound, .. }, _) = orig_trees.next().unwrap() else { + panic!("Bad tokens for attribute {:?}", self); + }; + let pound_span = pound_token.span; + + let mut trees = vec![AttrTokenTree::Token(pound_token, Spacing::Alone)]; + if self.style == AttrStyle::Inner { + // For inner attributes, we do the same thing for the `!` in `#![some_attr]` + let TokenTree::Token(bang_token @ Token { kind: TokenKind::Not, .. }, _) = orig_trees.next().unwrap() else { + panic!("Bad tokens for attribute {:?}", self); + }; + trees.push(AttrTokenTree::Token(bang_token, Spacing::Alone)); + } + // We don't really have a good span to use for the synthesized `[]` + // in `#[attr]`, so just use the span of the `#` token. + let bracket_group = AttrTokenTree::Delimited( + DelimSpan::from_single(pound_span), + Delimiter::Bracket, + item.tokens + .as_ref() + .unwrap_or_else(|| panic!("Missing tokens for {:?}", item)) + .to_attr_token_stream(), + ); + trees.push(bracket_group); + let tokens = Some(LazyAttrTokenStream::new(AttrTokenStream::new(trees))); + + mk_attr_from_item(attr_id_generator, item, tokens, self.style, item_span) + } } impl AttrItem { diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 2424073ae53ad..5a2c8b0ab97e9 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -926,10 +926,14 @@ fn noop_visit_lifetime(Lifetime { id, ident }: &mut Lifetime, vis } pub fn noop_visit_generics(generics: &mut Generics, vis: &mut T) { - let Generics { params, where_clause, span } = generics; + let Generics { params, where_clause, span, defines_opaque_types } = generics; params.flat_map_in_place(|param| vis.flat_map_generic_param(param)); vis.visit_where_clause(where_clause); vis.visit_span(span); + for (id, path) in defines_opaque_types { + vis.visit_id(id); + vis.visit_path(path); + } } pub fn noop_visit_where_clause(wc: &mut WhereClause, vis: &mut T) { @@ -1030,9 +1034,13 @@ pub fn noop_visit_item_kind(kind: &mut ItemKind, vis: &mut T) { match kind { ItemKind::ExternCrate(_orig_name) => {} ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree), - ItemKind::Static(box StaticItem { ty, mutability: _, expr }) => { + ItemKind::Static(box StaticItem { ty, mutability: _, expr, defines_opaque_types }) => { vis.visit_ty(ty); visit_opt(expr, |expr| vis.visit_expr(expr)); + for (id, path) in defines_opaque_types { + vis.visit_id(id); + vis.visit_path(path); + } } ItemKind::Const(item) => { visit_const_item(item, vis); @@ -1150,12 +1158,17 @@ pub fn noop_flat_map_assoc_item( } fn visit_const_item( - ConstItem { defaultness, ty, expr }: &mut ConstItem, + ConstItem { defaultness, ty, expr, defines_opaque_types }: &mut ConstItem, visitor: &mut T, ) { visit_defaultness(defaultness, visitor); visitor.visit_ty(ty); visit_opt(expr, |expr| visitor.visit_expr(expr)); + + for (id, path) in defines_opaque_types { + visitor.visit_id(id); + visitor.visit_path(path); + } } pub fn noop_visit_fn_header(header: &mut FnHeader, vis: &mut T) { diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 3b08467fde2bf..0c7d98fcbb2e4 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -305,10 +305,14 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) { match &item.kind { ItemKind::ExternCrate(_) => {} ItemKind::Use(use_tree) => visitor.visit_use_tree(use_tree, item.id, false), - ItemKind::Static(box StaticItem { ty, mutability: _, expr }) - | ItemKind::Const(box ConstItem { ty, expr, .. }) => { + ItemKind::Static(box StaticItem { ty, mutability: _, expr, defines_opaque_types }) + | ItemKind::Const(box ConstItem { ty, expr, defines_opaque_types, .. }) => { visitor.visit_ty(ty); walk_list!(visitor, visit_expr, expr); + + for (id, path) in defines_opaque_types { + visitor.visit_path(path, *id); + } } ItemKind::Fn(box Fn { defaultness: _, generics, sig, body }) => { let kind = @@ -606,6 +610,9 @@ pub fn walk_generic_param<'a, V: Visitor<'a>>(visitor: &mut V, param: &'a Generi pub fn walk_generics<'a, V: Visitor<'a>>(visitor: &mut V, generics: &'a Generics) { walk_list!(visitor, visit_generic_param, &generics.params); walk_list!(visitor, visit_where_predicate, &generics.where_clause.predicates); + for (id, path) in &generics.defines_opaque_types { + visitor.visit_path(path, *id); + } } pub fn walk_closure_binder<'a, V: Visitor<'a>>(visitor: &mut V, binder: &'a ClosureBinder) { diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index f89e254a2f54d..6621d398d557e 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -229,13 +229,20 @@ impl<'hir> LoweringContext<'_, 'hir> { self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs) } - ItemKind::Static(box ast::StaticItem { ty: t, mutability: m, expr: e }) => { + ItemKind::Static(box ast::StaticItem { + ty: t, + mutability: m, + expr: e, + defines_opaque_types, + }) => { let (ty, body_id) = self.lower_const_item(t, span, e.as_deref()); - hir::ItemKind::Static(ty, *m, body_id) + let defines_opaque_types = self.lower_defines(defines_opaque_types); + hir::ItemKind::Static(ty, *m, body_id, defines_opaque_types) } - ItemKind::Const(box ast::ConstItem { ty, expr, .. }) => { + ItemKind::Const(box ast::ConstItem { ty, expr, defines_opaque_types, .. }) => { let (ty, body_id) = self.lower_const_item(ty, span, expr.as_deref()); - hir::ItemKind::Const(ty, body_id) + let defines_opaque_types = self.lower_defines(defines_opaque_types); + hir::ItemKind::Const(ty, body_id, defines_opaque_types) } ItemKind::Fn(box Fn { sig: FnSig { decl, header, span: fn_sig_span }, @@ -1368,17 +1375,40 @@ impl<'hir> LoweringContext<'_, 'hir> { let impl_trait_bounds = std::mem::take(&mut self.impl_trait_bounds); predicates.extend(impl_trait_bounds.into_iter()); + let defines_opaque_types = self.lower_defines(&generics.defines_opaque_types); + let lowered_generics = self.arena.alloc(hir::Generics { params: self.arena.alloc_from_iter(params), predicates: self.arena.alloc_from_iter(predicates), has_where_clause_predicates, where_clause_span, span, + defines_opaque_types, }); (lowered_generics, res) } + fn lower_defines( + &mut self, + defines_opaque_types: &[(NodeId, ast::Path)], + ) -> &'hir [&'hir hir::Path<'hir>] { + let arena = self.arena; + + let defines_opaque_types = defines_opaque_types.iter().map(|(id, path)| { + let qpath = self.lower_qpath( + *id, + &None, + path, + ParamMode::Explicit, + &ImplTraitContext::Disallowed(ImplTraitPosition::Path), + ); + let hir::QPath::Resolved(None, path) = qpath else { panic!("{qpath:?}") }; + path + }); + arena.alloc_from_iter(defines_opaque_types) + } + pub(super) fn lower_generic_bound_predicate( &mut self, ident: Ident, diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index ca659db4dbea2..5a698435549fb 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1593,6 +1593,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { has_where_clause_predicates: false, where_clause_span: lctx.lower_span(span), span: lctx.lower_span(span), + defines_opaque_types: &[], }), bounds: hir_bounds, origin, @@ -2046,6 +2047,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { has_where_clause_predicates: false, where_clause_span: this.lower_span(span), span: this.lower_span(span), + defines_opaque_types: &[], }), bounds: arena_vec![this; future_bound], origin: hir::OpaqueTyOrigin::AsyncFn(fn_def_id), diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 80c451d675355..4000b2332a00b 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1726,6 +1726,7 @@ impl<'a> State<'a> { self.print_formal_generic_params(generic_params); let generics = ast::Generics { params: ThinVec::new(), + defines_opaque_types: ThinVec::new(), where_clause: ast::WhereClause { has_where_token: false, predicates: ThinVec::new(), diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs index c465f8c948a80..1b99ef0bf8324 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs @@ -157,7 +157,12 @@ impl<'a> State<'a> { self.print_use_tree(tree); self.word(";"); } - ast::ItemKind::Static(box StaticItem { ty, mutability: mutbl, expr: body }) => { + ast::ItemKind::Static(box StaticItem { + ty, + mutability: mutbl, + expr: body, + defines_opaque_types: _, + }) => { let def = ast::Defaultness::Final; self.print_item_const( item.ident, @@ -168,7 +173,12 @@ impl<'a> State<'a> { def, ); } - ast::ItemKind::Const(box ast::ConstItem { defaultness, ty, expr }) => { + ast::ItemKind::Const(box ast::ConstItem { + defaultness, + ty, + expr, + defines_opaque_types: _, + }) => { self.print_item_const( item.ident, None, @@ -496,7 +506,7 @@ impl<'a> State<'a> { pub(crate) fn print_variant(&mut self, v: &ast::Variant) { self.head(""); self.print_visibility(&v.vis); - let generics = ast::Generics::default(); + let generics = ast::Generics::new(v.span, Default::default()); self.print_struct(&v.data, &generics, v.ident, v.span, false); if let Some(d) = &v.disr_expr { self.space(); @@ -515,7 +525,12 @@ impl<'a> State<'a> { ast::AssocItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => { self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs); } - ast::AssocItemKind::Const(box ast::ConstItem { defaultness, ty, expr }) => { + ast::AssocItemKind::Const(box ast::ConstItem { + defaultness, + ty, + expr, + defines_opaque_types: _, + }) => { self.print_item_const(ident, None, ty, expr.as_deref(), vis, *defaultness); } ast::AssocItemKind::Type(box ast::TyAlias { diff --git a/compiler/rustc_ast_pretty/src/pprust/tests.rs b/compiler/rustc_ast_pretty/src/pprust/tests.rs index 3b2b60a86f06e..56d878ea3cae7 100644 --- a/compiler/rustc_ast_pretty/src/pprust/tests.rs +++ b/compiler/rustc_ast_pretty/src/pprust/tests.rs @@ -32,7 +32,7 @@ fn test_fun_to_string() { inputs: ThinVec::new(), output: ast::FnRetTy::Default(rustc_span::DUMMY_SP), }; - let generics = ast::Generics::default(); + let generics = ast::Generics::new(rustc_span::DUMMY_SP, Default::default()); assert_eq!( fun_to_string(&decl, ast::FnHeader::default(), abba_ident, &generics), "fn abba()" diff --git a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs index ac6697232cb82..85070637678fc 100644 --- a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs +++ b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs @@ -44,7 +44,13 @@ pub fn expand( // Generate anonymous constant serving as container for the allocator methods. let const_ty = ecx.ty(sig_span, TyKind::Tup(ThinVec::new())); let const_body = ecx.expr_block(ecx.block(span, stmts)); - let const_item = ecx.item_const(span, Ident::new(kw::Underscore, span), const_ty, const_body); + let const_item = ecx.item_const( + span, + Ident::new(kw::Underscore, span), + const_ty, + const_body, + Default::default(), + ); let const_item = if is_stmt { Annotatable::Stmt(P(ecx.stmt_item(span, const_item))) } else { @@ -85,7 +91,7 @@ fn generate_handler(cx: &ExtCtxt<'_>, handler: Ident, span: Span, sig_span: Span let kind = ItemKind::Fn(Box::new(Fn { defaultness: ast::Defaultness::Final, sig, - generics: Generics::default(), + generics: Generics::new(span.shrink_to_hi(), Default::default()), body, })); diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index 6b3053fdfac7e..77ce0f78994bf 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -575,7 +575,7 @@ impl<'a> TraitDef<'a> { attrs: ast::AttrVec::new(), kind: ast::AssocItemKind::Type(Box::new(ast::TyAlias { defaultness: ast::Defaultness::Final, - generics: Generics::default(), + generics: Generics::new(self.span, Default::default()), where_clauses: ( ast::TyAliasWhereClause::default(), ast::TyAliasWhereClause::default(), @@ -736,7 +736,8 @@ impl<'a> TraitDef<'a> { } } - let trait_generics = Generics { params, where_clause, span }; + let trait_generics = + Generics { params, where_clause, span, defines_opaque_types: ThinVec::new() }; // Create the reference to the trait. let trait_ref = cx.trait_ref(trait_path); diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs index 26f91b714b468..fc3c150526ab6 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs @@ -192,6 +192,7 @@ impl Bounds { span, }, span, + defines_opaque_types: ThinVec::new(), } } } diff --git a/compiler/rustc_builtin_macros/src/global_allocator.rs b/compiler/rustc_builtin_macros/src/global_allocator.rs index 866cc5adbf3b1..5c0d2d0adf45e 100644 --- a/compiler/rustc_builtin_macros/src/global_allocator.rs +++ b/compiler/rustc_builtin_macros/src/global_allocator.rs @@ -49,7 +49,13 @@ pub fn expand( // Generate anonymous constant serving as container for the allocator methods. let const_ty = ecx.ty(ty_span, TyKind::Tup(ThinVec::new())); let const_body = ecx.expr_block(ecx.block(span, stmts)); - let const_item = ecx.item_const(span, Ident::new(kw::Underscore, span), const_ty, const_body); + let const_item = ecx.item_const( + span, + Ident::new(kw::Underscore, span), + const_ty, + const_body, + Default::default(), + ); let const_item = if is_stmt { Annotatable::Stmt(P(ecx.stmt_item(span, const_item))) } else { @@ -87,7 +93,7 @@ impl AllocFnFactory<'_, '_> { let kind = ItemKind::Fn(Box::new(Fn { defaultness: ast::Defaultness::Final, sig, - generics: Generics::default(), + generics: Generics::new(self.span.shrink_to_hi(), Default::default()), body, })); let item = self.cx.item( diff --git a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs index 378d5f39f4ab2..0f4a85cfa0bcd 100644 --- a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs +++ b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs @@ -362,6 +362,7 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P { ), ast::Mutability::Not, cx.expr_array_ref(span, decls), + Default::default(), ) .map(|mut i| { i.attrs.push(cx.attr_word(sym::rustc_proc_macro_decls, span)); @@ -379,6 +380,7 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P { Ident::new(kw::Underscore, span), cx.ty(span, ast::TyKind::Tup(ThinVec::new())), block, + Default::default(), ); // Integrate the new item into existing module structures. diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index a76ed4ee6cee3..c010b4b0f2e1c 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -269,6 +269,7 @@ pub fn expand_test_or_bench( ast::ConstItem { defaultness: ast::Defaultness::Final, ty: cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))), + defines_opaque_types: Default::default(), // test::TestDescAndFn { expr: Some( cx.expr_struct( diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 43ab6c0442833..0695d361f9d1f 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -328,7 +328,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P { let main = ast::ItemKind::Fn(Box::new(ast::Fn { defaultness, sig, - generics: ast::Generics::default(), + generics: ast::Generics::new(sp.shrink_to_hi(), Default::default()), body: Some(main_body), })); diff --git a/compiler/rustc_data_structures/src/obligation_forest/mod.rs b/compiler/rustc_data_structures/src/obligation_forest/mod.rs index 27a869eb7cdb0..74786894d0710 100644 --- a/compiler/rustc_data_structures/src/obligation_forest/mod.rs +++ b/compiler/rustc_data_structures/src/obligation_forest/mod.rs @@ -311,6 +311,20 @@ pub struct Error { } impl ObligationForest { + #[cfg(bootstrap)] + pub fn new() -> ObligationForest { + ObligationForest { + nodes: vec![], + done_cache: Default::default(), + active_cache: Default::default(), + reused_node_vec: vec![], + obligation_tree_id_generator: (0..).map(ObligationTreeId), + error_cache: Default::default(), + } + } + #[cfg(not(bootstrap))] + // cannot use cfg_attr as `defines` does not support that yet. + #[defines(ObligationTreeIdGenerator)] pub fn new() -> ObligationForest { ObligationForest { nodes: vec![], diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index 6f319b96f2faf..4031002388b40 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -225,6 +225,34 @@ pub type LazyFallbackBundle = Lrc FluentBund /// Return the default `FluentBundle` with standard "en-US" diagnostic messages. #[instrument(level = "trace")] +#[cfg(bootstrap)] +pub fn fallback_fluent_bundle( + resources: Vec<&'static str>, + with_directionality_markers: bool, +) -> LazyFallbackBundle { + Lrc::new(Lazy::new(move || { + let mut fallback_bundle = new_bundle(vec![langid!("en-US")]); + + register_functions(&mut fallback_bundle); + + // See comment in `fluent_bundle`. + fallback_bundle.set_use_isolating(with_directionality_markers); + + for resource in resources { + let resource = FluentResource::try_new(resource.to_string()) + .expect("failed to parse fallback fluent resource"); + trace!(?resource); + fallback_bundle.add_resource_overriding(resource); + } + + fallback_bundle + })) +} + +/// Return the default `FluentBundle` with standard "en-US" diagnostic messages. +#[instrument(level = "trace")] +#[cfg(not(bootstrap))] +#[defines(LazyFallbackBundle)] pub fn fallback_fluent_bundle( resources: Vec<&'static str>, with_directionality_markers: bool, diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index 264f30fb10a12..527a735f2f817 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -622,12 +622,15 @@ impl<'a> ExtCtxt<'a> { ty: P, mutability: ast::Mutability, expr: P, + defines_opaque_types: ThinVec<(ast::NodeId, ast::Path)>, ) -> P { self.item( span, name, AttrVec::new(), - ast::ItemKind::Static(ast::StaticItem { ty, mutability, expr: Some(expr) }.into()), + ast::ItemKind::Static( + ast::StaticItem { ty, mutability, expr: Some(expr), defines_opaque_types }.into(), + ), ) } @@ -637,13 +640,16 @@ impl<'a> ExtCtxt<'a> { name: Ident, ty: P, expr: P, + defines_opaque_types: ThinVec<(ast::NodeId, ast::Path)>, ) -> P { let defaultness = ast::Defaultness::Final; self.item( span, name, AttrVec::new(), - ast::ItemKind::Const(ast::ConstItem { defaultness, ty, expr: Some(expr) }.into()), + ast::ItemKind::Const( + ast::ConstItem { defaultness, ty, expr: Some(expr), defines_opaque_types }.into(), + ), ) } diff --git a/compiler/rustc_expand/src/config.rs b/compiler/rustc_expand/src/config.rs index a78dc0678d5da..5f68ded8b5d38 100644 --- a/compiler/rustc_expand/src/config.rs +++ b/compiler/rustc_expand/src/config.rs @@ -5,12 +5,11 @@ use crate::errors::{ MalformedFeatureAttribute, MalformedFeatureAttributeHelp, RemoveExprNotSupported, }; use rustc_ast::ptr::P; -use rustc_ast::token::{Delimiter, Token, TokenKind}; +use rustc_ast::token::TokenKind; +use rustc_ast::tokenstream::LazyAttrTokenStream; use rustc_ast::tokenstream::{AttrTokenStream, AttrTokenTree}; -use rustc_ast::tokenstream::{DelimSpan, Spacing}; -use rustc_ast::tokenstream::{LazyAttrTokenStream, TokenTree}; use rustc_ast::NodeId; -use rustc_ast::{self as ast, AttrStyle, Attribute, HasAttrs, HasTokens, MetaItem}; +use rustc_ast::{self as ast, Attribute, HasAttrs, HasTokens, MetaItem}; use rustc_attr as attr; use rustc_data_structures::flat_map_in_place::FlatMapInPlace; use rustc_data_structures::fx::FxHashMap; @@ -347,54 +346,8 @@ impl<'a> StripUnconfigured<'a> { } } - fn expand_cfg_attr_item( - &self, - attr: &Attribute, - (item, item_span): (ast::AttrItem, Span), - ) -> Attribute { - let orig_tokens = attr.tokens(); - - // We are taking an attribute of the form `#[cfg_attr(pred, attr)]` - // and producing an attribute of the form `#[attr]`. We - // have captured tokens for `attr` itself, but we need to - // synthesize tokens for the wrapper `#` and `[]`, which - // we do below. - - // Use the `#` in `#[cfg_attr(pred, attr)]` as the `#` token - // for `attr` when we expand it to `#[attr]` - let mut orig_trees = orig_tokens.into_trees(); - let TokenTree::Token(pound_token @ Token { kind: TokenKind::Pound, .. }, _) = orig_trees.next().unwrap() else { - panic!("Bad tokens for attribute {:?}", attr); - }; - let pound_span = pound_token.span; - - let mut trees = vec![AttrTokenTree::Token(pound_token, Spacing::Alone)]; - if attr.style == AttrStyle::Inner { - // For inner attributes, we do the same thing for the `!` in `#![some_attr]` - let TokenTree::Token(bang_token @ Token { kind: TokenKind::Not, .. }, _) = orig_trees.next().unwrap() else { - panic!("Bad tokens for attribute {:?}", attr); - }; - trees.push(AttrTokenTree::Token(bang_token, Spacing::Alone)); - } - // We don't really have a good span to use for the synthesized `[]` - // in `#[attr]`, so just use the span of the `#` token. - let bracket_group = AttrTokenTree::Delimited( - DelimSpan::from_single(pound_span), - Delimiter::Bracket, - item.tokens - .as_ref() - .unwrap_or_else(|| panic!("Missing tokens for {:?}", item)) - .to_attr_token_stream(), - ); - trees.push(bracket_group); - let tokens = Some(LazyAttrTokenStream::new(AttrTokenStream::new(trees))); - let attr = attr::mk_attr_from_item( - &self.sess.parse_sess.attr_id_generator, - item, - tokens, - attr.style, - item_span, - ); + fn expand_cfg_attr_item(&self, attr: &Attribute, item: (ast::AttrItem, Span)) -> Attribute { + let attr = attr.expand_cfg_attr(&self.sess.parse_sess.attr_id_generator, item); if attr.has_name(sym::crate_type) { self.sess.parse_sess.buffer_lint( rustc_lint_defs::builtin::DEPRECATED_CFG_ATTR_CRATE_TYPE_NAME, diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index c77292fdd1647..c058f38afa0f6 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -494,6 +494,13 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // RFC 2397 gated!(do_not_recommend, Normal, template!(Word), WarnFollowing, experimental!(do_not_recommend)), + // `#[defines]` for type alias impl trait + gated!( + defines, Normal, template!(List: "path"), DuplicatesOk, + @only_local: true, + type_alias_impl_trait, experimental!(type_alias_impl_trait), + ), + // ========================================================================== // Internal attributes: Stability, deprecation, and unsafe: // ========================================================================== diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 35a72f868fbcc..04a7de1c812fc 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -564,6 +564,7 @@ pub struct Generics<'hir> { pub has_where_clause_predicates: bool, pub where_clause_span: Span, pub span: Span, + pub defines_opaque_types: &'hir [&'hir Path<'hir>], } impl<'hir> Generics<'hir> { @@ -574,6 +575,7 @@ impl<'hir> Generics<'hir> { has_where_clause_predicates: false, where_clause_span: DUMMY_SP, span: DUMMY_SP, + defines_opaque_types: &[], }; &NOPE } @@ -3094,15 +3096,15 @@ impl<'hir> Item<'hir> { /// Expect an [`ItemKind::Static`] or panic. #[track_caller] - pub fn expect_static(&self) -> (&'hir Ty<'hir>, Mutability, BodyId) { - let ItemKind::Static(ty, mutbl, body) = self.kind else { self.expect_failed("a static") }; - (ty, mutbl, body) + pub fn expect_static(&self) -> (&'hir Ty<'hir>, Mutability, BodyId, &'hir [&'hir Path<'hir>]) { + let ItemKind::Static(ty, mutbl, body, defs) = self.kind else { self.expect_failed("a static") }; + (ty, mutbl, body, defs) } /// Expect an [`ItemKind::Const`] or panic. #[track_caller] - pub fn expect_const(&self) -> (&'hir Ty<'hir>, BodyId) { - let ItemKind::Const(ty, body) = self.kind else { self.expect_failed("a constant") }; - (ty, body) + pub fn expect_const(&self) -> (&'hir Ty<'hir>, BodyId, &'hir [&'hir Path<'hir>]) { + let ItemKind::Const(ty, body, defs) = self.kind else { self.expect_failed("a constant") }; + (ty, body, defs) } /// Expect an [`ItemKind::Fn`] or panic. #[track_caller] @@ -3283,9 +3285,9 @@ pub enum ItemKind<'hir> { Use(&'hir UsePath<'hir>, UseKind), /// A `static` item. - Static(&'hir Ty<'hir>, Mutability, BodyId), + Static(&'hir Ty<'hir>, Mutability, BodyId, &'hir [&'hir Path<'hir>]), /// A `const` item. - Const(&'hir Ty<'hir>, BodyId), + Const(&'hir Ty<'hir>, BodyId, &'hir [&'hir Path<'hir>]), /// A function declaration. Fn(FnSig<'hir>, &'hir Generics<'hir>, BodyId), /// A MBE macro definition (`macro_rules!` or `macro`). @@ -3974,6 +3976,19 @@ impl<'hir> Node<'hir> { fn expect_failed(&self, expected: &'static str) -> ! { panic!("expected {expected} node, found {self:?}") } + + pub fn defines_opaque_types(&self) -> &'hir [&'hir Path<'hir>] { + match self.generics() { + Some(generics) => generics.defines_opaque_types, + None => match self { + Node::Item(it) => match it.kind { + ItemKind::Static(.., defs) | ItemKind::Const(.., defs) => defs, + _ => &[], + }, + _ => &[], + }, + } + } } // Some nodes are used a lot. Make sure they don't unintentionally get bigger. @@ -3990,7 +4005,7 @@ mod size_asserts { static_assert_size!(ForeignItemKind<'_>, 40); static_assert_size!(GenericArg<'_>, 32); static_assert_size!(GenericBound<'_>, 48); - static_assert_size!(Generics<'_>, 56); + static_assert_size!(Generics<'_>, 72); static_assert_size!(Impl<'_>, 80); static_assert_size!(ImplItem<'_>, 80); static_assert_size!(ImplItemKind<'_>, 32); diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index 234256ab553c5..78abe058882aa 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -464,7 +464,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) { ItemKind::Use(ref path, _) => { visitor.visit_use(path, item.hir_id()); } - ItemKind::Static(ref typ, _, body) | ItemKind::Const(ref typ, body) => { + ItemKind::Static(ref typ, _, body, _) | ItemKind::Const(ref typ, body, _) => { visitor.visit_id(item.hir_id()); visitor.visit_ty(typ); visitor.visit_nested_body(body); diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index 119933697a165..5614fa707addc 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -93,6 +93,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { param_def_id_to_index, has_self: generics.has_self, has_late_bound_regions: generics.has_late_bound_regions, + defines_opaque_types: vec![], }; } @@ -348,6 +349,25 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { let param_def_id_to_index = params.iter().map(|param| (param.def_id, param.index)).collect(); + let defines_opaque_types = node + .defines_opaque_types() + .iter() + .filter_map(|&path| { + if path.res.opt_def_id().is_none() { + tcx.sess.delay_span_bug(tcx.def_span(def_id), format!("unresolved path {path:#?}")); + } + let id = path.res.opt_def_id()?; + if id.is_local() { + // FIXME: not using LocalDefId here, see `Generics::defines_opaque_types`, too + // We want to encode a type here in the future and use it in a new `Predicate` in + // `where` bounds. + Some(id) + } else { + todo!("emit an error about not being able to constrain ids from other crates") + } + }) + .collect(); + ty::Generics { parent: parent_def_id, parent_count, @@ -355,6 +375,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { param_def_id_to_index, has_self: has_self || parent_has_self, has_late_bound_regions: has_late_bound_regions(tcx, node), + defines_opaque_types, } } diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 225b155058076..a9560e81cf35a 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -4,6 +4,7 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit; use rustc_hir::intravisit::Visitor; use rustc_hir::{HirId, Node}; +use rustc_infer::infer::opaque_types::may_define_opaque_type; use rustc_middle::hir::nested_filter; use rustc_middle::ty::print::with_forced_trimmed_paths; use rustc_middle::ty::subst::InternalSubsts; @@ -315,7 +316,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder { match item.kind { - ItemKind::Static(ty, .., body_id) => { + ItemKind::Static(ty, .., body_id, _) => { if is_suggestable_infer_ty(ty) { infer_placeholder_type( tcx, @@ -329,7 +330,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder { + ItemKind::Const(ty, body_id, _) => { if is_suggestable_infer_ty(ty) { infer_placeholder_type( tcx, def_id, body_id, ty.span, item.ident, "constant", @@ -614,6 +615,7 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T impl ConstraintLocator<'_> { #[instrument(skip(self), level = "debug")] fn check(&mut self, item_def_id: LocalDefId) { + let may_define = may_define_opaque_type(self.tcx, item_def_id, self.def_id); // Don't try to check items that cannot possibly constrain the type. if !self.tcx.has_typeck_results(item_def_id) { debug!("no constraint: no typeck results"); @@ -648,6 +650,12 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T let concrete_opaque_types = &self.tcx.mir_borrowck(item_def_id).concrete_opaque_types; debug!(?concrete_opaque_types); if let Some(&concrete_type) = concrete_opaque_types.get(&self.def_id) { + if !may_define { + span_bug!( + concrete_type.span, + "hidden type registered even though no `#[define]` was found" + ); + } debug!(?concrete_type, "found constraint"); if let Some(prev) = &mut self.found { if concrete_type.ty != prev.ty && !(concrete_type, prev.ty).references_error() { @@ -668,8 +676,12 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T self.tcx.hir() } fn visit_expr(&mut self, ex: &'tcx Expr<'tcx>) { - if let hir::ExprKind::Closure(closure) = ex.kind { - self.check(closure.def_id); + match ex.kind { + hir::ExprKind::Closure(closure) => { + self.check(closure.def_id); + } + hir::ExprKind::ConstBlock(block) => self.check(block.def_id), + _ => (), } intravisit::walk_expr(self, ex); } diff --git a/compiler/rustc_hir_analysis/src/hir_wf_check.rs b/compiler/rustc_hir_analysis/src/hir_wf_check.rs index 8269a6ddea5f4..e0c874500275f 100644 --- a/compiler/rustc_hir_analysis/src/hir_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/hir_wf_check.rs @@ -128,7 +128,7 @@ fn diagnostic_hir_wf_check<'tcx>( ref item => bug!("Unexpected TraitItem {:?}", item), }, hir::Node::Item(item) => match item.kind { - hir::ItemKind::Static(ty, _, _) | hir::ItemKind::Const(ty, _) => vec![ty], + hir::ItemKind::Static(ty, _, _, _) | hir::ItemKind::Const(ty, _, _) => vec![ty], hir::ItemKind::Impl(impl_) => match &impl_.of_trait { Some(t) => t .path diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 4f27c01fad2c9..07423e3d1773c 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -515,7 +515,7 @@ impl<'a> State<'a> { self.end(); // end inner head-block self.end(); // end outer head-block } - hir::ItemKind::Static(ty, m, expr) => { + hir::ItemKind::Static(ty, m, expr, _) => { self.head("static"); if m.is_mut() { self.word_space("mut"); @@ -531,7 +531,7 @@ impl<'a> State<'a> { self.word(";"); self.end(); // end the outer cbox } - hir::ItemKind::Const(ty, expr) => { + hir::ItemKind::Const(ty, expr, _) => { self.head("const"); self.print_ident(item.ident); self.word_space(":"); diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index c17aae22ba540..97d07e3dea7d6 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -1336,7 +1336,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }); let Some((_, hir::Node::Local(hir::Local { ty: Some(ty), .. }) - | hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, _), .. })) + | hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, _, _), .. })) ) = parent_node else { return }; diff --git a/compiler/rustc_hir_typeck/src/inherited.rs b/compiler/rustc_hir_typeck/src/inherited.rs index 4110b176b41b1..3a256c7c0dbb3 100644 --- a/compiler/rustc_hir_typeck/src/inherited.rs +++ b/compiler/rustc_hir_typeck/src/inherited.rs @@ -79,7 +79,7 @@ impl<'tcx> Inherited<'tcx> { let infcx = tcx .infer_ctxt() .ignoring_regions() - .with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id)) + .with_opaque_type_inference(DefiningAnchor::Bind(def_id)) .build(); let typeck_results = RefCell::new(ty::TypeckResults::new(hir_owner)); diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 6af095cb4d437..6d67008bcb550 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -110,7 +110,7 @@ fn primary_body_of( ) -> Option<(hir::BodyId, Option<&hir::Ty<'_>>, Option<&hir::FnSig<'_>>)> { match node { Node::Item(item) => match item.kind { - hir::ItemKind::Const(ty, body) | hir::ItemKind::Static(ty, _, body) => { + hir::ItemKind::Const(ty, body, _) | hir::ItemKind::Static(ty, _, body, _) => { Some((body, Some(ty), None)) } hir::ItemKind::Fn(ref sig, .., body) => Some((body, None, Some(sig))), diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 241535b29c5f8..9becff02f8b8d 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -918,7 +918,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { match opt_def_id { Some(def_id) => match self.tcx.hir().get_if_local(def_id) { Some(hir::Node::Item(hir::Item { - kind: hir::ItemKind::Const(_, body_id), .. + kind: hir::ItemKind::Const(_, body_id, _), + .. })) => match self.tcx.hir().get(body_id.hir_id) { hir::Node::Expr(expr) => { if hir::is_range_literal(expr) { diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index c9956b60a56db..82e53fccd0911 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -2049,7 +2049,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { visitor.result.map(|r| &r.peel_refs().kind) } Some(hir::Node::Item(hir::Item { - kind: hir::ItemKind::Const(ty, _), + kind: hir::ItemKind::Const(ty, _, _), .. })) => { Some(&ty.peel_refs().kind) diff --git a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs index b38bbdfe7bb8b..9973bccb2ea65 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs @@ -5,6 +5,7 @@ use rustc_hir as hir; use rustc_middle::traits::ObligationCauseCode; use rustc_middle::ty::error::ExpectedFound; use rustc_middle::ty::print::Printer; +use rustc_middle::ty::AliasTy; use rustc_middle::{ traits::ObligationCause, ty::{self, error::TypeError, print::FmtPrinter, suggest_constraining_type_param, Ty}, @@ -25,6 +26,19 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let tcx = self.tcx; + let is_tait = |alias: &AliasTy<'_>| { + alias.def_id.is_local() && tcx.is_type_alias_impl_trait(alias.def_id) + }; + let mut opaque_defines = |ty| { + let sp = self.tcx.def_span(body_owner_def_id); + diag.span_note( + sp, + format!( + "this item cannot register hidden type without a `#[defines({ty})]` attribute" + ), + ); + }; + match err { ArgumentSorts(values, _) | Sorts(values) => { match (values.expected.kind(), values.found.kind()) { @@ -36,6 +50,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { // Issue #63167 diag.note("distinct uses of `impl Trait` result in different opaque types"); } + (ty::Alias(ty::Opaque, alias), _) if is_tait(alias) => opaque_defines(values.expected), + (_, ty::Alias(ty::Opaque, alias)) if is_tait(alias) => opaque_defines(values.found), (ty::Float(_), ty::Infer(ty::IntVar(_))) if let Ok( // Issue #53280 diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index 3a0a0494a7ed3..98cf39cfd8526 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -3,6 +3,7 @@ use super::{DefineOpaqueTypes, InferResult}; use crate::errors::OpaqueHiddenTypeDiag; use crate::infer::{DefiningAnchor, InferCtxt, InferOk}; use crate::traits; +use hir::def::DefKind; use hir::def_id::{DefId, LocalDefId}; use hir::OpaqueTyOrigin; use rustc_data_structures::fx::FxIndexMap; @@ -368,7 +369,6 @@ impl<'tcx> InferCtxt<'tcx> { /// in its defining scope. #[instrument(skip(self), level = "trace", ret)] pub fn opaque_type_origin(&self, def_id: LocalDefId) -> Option { - let opaque_hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id); let parent_def_id = match self.defining_use_anchor { DefiningAnchor::Bubble | DefiningAnchor::Error => return None, DefiningAnchor::Bind(bind) => bind, @@ -381,9 +381,7 @@ impl<'tcx> InferCtxt<'tcx> { // Anonymous `impl Trait` hir::OpaqueTyOrigin::FnReturn(parent) => parent == parent_def_id, // Named `type Foo = impl Bar;` - hir::OpaqueTyOrigin::TyAlias => { - may_define_opaque_type(self.tcx, parent_def_id, opaque_hir_id) - } + hir::OpaqueTyOrigin::TyAlias => may_define_opaque_type(self.tcx, parent_def_id, def_id), }; in_definition_scope.then_some(origin) } @@ -626,22 +624,72 @@ impl<'tcx> InferCtxt<'tcx> { /// Here, `def_id` is the `LocalDefId` of the defining use of the opaque type (e.g., `f1` or `f2`), /// and `opaque_hir_id` is the `HirId` of the definition of the opaque type `Baz`. /// For the above example, this function returns `true` for `f1` and `false` for `f2`. -fn may_define_opaque_type(tcx: TyCtxt<'_>, def_id: LocalDefId, opaque_hir_id: hir::HirId) -> bool { - let mut hir_id = tcx.hir().local_def_id_to_hir_id(def_id); - - // Named opaque types can be defined by any siblings or children of siblings. - let scope = 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 != hir::CRATE_HIR_ID { - hir_id = tcx.hir().get_parent_item(hir_id).into(); +#[instrument(level = "trace", skip(tcx), ret)] +pub fn may_define_opaque_type( + tcx: TyCtxt<'_>, + item_def_id: LocalDefId, + opaque_def_id: LocalDefId, +) -> bool { + // Used for check_opaque_meets_bounds + if item_def_id == opaque_def_id { + return true; + } + + // The parent is usually the type alias or associated type. + let mut parent = tcx.local_parent(opaque_def_id); + // But sometimes the parent is another opaque type, so skip all these opaque types. + while let DefKind::OpaqueTy = tcx.def_kind(parent) { + // Used for check_opaque_meets_bounds + if item_def_id == parent { + return true; + } + trace!(?parent); + parent = tcx.local_parent(parent); + } + trace!(?parent); + + let surrounding_module_or_item = tcx.local_parent(parent); + + trace!(?surrounding_module_or_item); + + let mut item_to_check = item_def_id; + loop { + match tcx.def_kind(item_to_check) { + DefKind::AnonConst + | DefKind::InlineConst + | DefKind::Closure + | DefKind::Generator + | DefKind::OpaqueTy => { + trace!(?item_to_check); + + if surrounding_module_or_item == item_to_check { + // Type alias impl trait defined within a const block or closure is usable within that. + return true; + } + + item_to_check = tcx.local_parent(item_to_check); + } + _ => break, + } + } + trace!(?item_to_check); + + // Type alias impl trait defined within the body of a function is usable within that body + if surrounding_module_or_item == item_to_check { + return true; + } + // Methods may use `impl Trait` from associated types + let kind = tcx.def_kind(item_to_check); + trace!(?kind); + if let DefKind::AssocFn | DefKind::AssocConst | DefKind::AssocTy = kind { + let parent = tcx.local_parent(item_to_check); + trace!(?parent); + if surrounding_module_or_item == parent { + return true; + } } - // Syntactically, we are allowed to define the concrete type if: - let res = hir_id == scope; - trace!( - "may_define_opaque_type(def={:?}, opaque_node={:?}) = {}", - tcx.hir().find(hir_id), - tcx.hir().get(opaque_hir_id), - res - ); - res + // Everything else needs the `#[defines]` attribute + let defines = &tcx.generics_of(item_to_check).defines_opaque_types; + trace!(?defines); + defines.contains(&parent.to_def_id()) } diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 6b387df785e7d..3b936cffafa55 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -1525,12 +1525,12 @@ declare_lint_pass!( impl<'tcx> LateLintPass<'tcx> for UnusedBrokenConst { fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) { match it.kind { - hir::ItemKind::Const(_, body_id) => { + hir::ItemKind::Const(_, body_id, _) => { let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id(); // trigger the query once for all constants since that will already report the errors cx.tcx.ensure().const_eval_poly(def_id); } - hir::ItemKind::Static(_, _, body_id) => { + hir::ItemKind::Static(_, _, body_id, _) => { let def_id = cx.tcx.hir().body_owner_def_id(body_id).to_def_id(); cx.tcx.ensure().eval_static_initializer(def_id); } diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 89a485b47ca8c..27822059f430a 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -23,7 +23,8 @@ pub fn associated_body(node: Node<'_>) -> Option<(LocalDefId, BodyId)> { match node { Node::Item(Item { owner_id, - kind: ItemKind::Const(_, body) | ItemKind::Static(.., body) | ItemKind::Fn(.., body), + kind: + ItemKind::Const(_, body, _) | ItemKind::Static(.., body, _) | ItemKind::Fn(.., body), .. }) | Node::TraitItem(TraitItem { @@ -182,7 +183,7 @@ impl<'hir> Map<'hir> { let hir_id = self.local_def_id_to_hir_id(local_def_id); let def_kind = match self.find(hir_id)? { Node::Item(item) => match item.kind { - ItemKind::Static(_, mt, _) => DefKind::Static(mt), + ItemKind::Static(_, mt, _, _) => DefKind::Static(mt), ItemKind::Const(..) => DefKind::Const, ItemKind::Fn(..) => DefKind::Fn, ItemKind::Macro(_, macro_kind) => DefKind::Macro(macro_kind), diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs index cd970270727f9..a8351fa66baff 100644 --- a/compiler/rustc_middle/src/mir/terminator.rs +++ b/compiler/rustc_middle/src/mir/terminator.rs @@ -105,7 +105,8 @@ pub struct Terminator<'tcx> { pub kind: TerminatorKind<'tcx>, } -pub type Successors<'a> = impl Iterator + 'a; +pub type Successors<'a> = + iter::Chain, std::iter::Copied>>; pub type SuccessorsMut<'a> = iter::Chain, slice::IterMut<'a, BasicBlock>>; diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index baef4ffeda732..ddcca4f0ebf53 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -133,6 +133,10 @@ pub struct Generics { pub has_self: bool, pub has_late_bound_regions: Option, + + // FIXME(type_alias_impl_trait): remove this field when writing it to metadata, it + // is not useful for other crates. + pub defines_opaque_types: Vec, } impl<'tcx> Generics { diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index 415f5b1b1e15d..5bd79ead52557 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -557,7 +557,7 @@ fn construct_const<'a, 'tcx>( // Figure out what primary body this item has. let (span, const_ty_span) = match tcx.hir().get(hir_id) { Node::Item(hir::Item { - kind: hir::ItemKind::Static(ty, _, _) | hir::ItemKind::Const(ty, _), + kind: hir::ItemKind::Static(ty, _, _, _) | hir::ItemKind::Const(ty, _, _), span, .. }) diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index 17466cd0e6dce..6a70df014c170 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -2,7 +2,9 @@ #![feature(array_windows)] #![feature(box_patterns)] +#![feature(generators)] #![feature(if_let_guard)] +#![feature(iter_from_generator)] #![feature(iter_intersperse)] #![feature(let_chains)] #![feature(never_type)] @@ -209,7 +211,8 @@ pub fn stream_to_parser<'a>( } /// Runs the given subparser `f` on the tokens of the given `attr`'s item. -pub fn parse_in<'a, T>( +#[instrument(level = "trace", skip(sess, f), ret)] +pub fn parse_in<'a, T: std::fmt::Debug>( sess: &'a ParseSess, tts: TokenStream, name: &'static str, diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 5210b8fe69d6e..b5c4ec7d888b5 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -363,7 +363,7 @@ impl<'a> Parser<'a> { if valid_prev_keywords.into_iter().any(|x| maybe_keyword.is_keyword(x)) { // if we have a valid keyword, attempt to parse generics // also obtain the keywords symbol - match self.parse_generics() { + match self.parse_generics(&[]) { Ok(generic) => { if let TokenKind::Ident(symbol, _) = maybe_keyword.kind { let ident_name = symbol; diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs index 8d0f168e09d7e..0f327ea7f66b3 100644 --- a/compiler/rustc_parse/src/parser/generics.rs +++ b/compiler/rustc_parse/src/parser/generics.rs @@ -7,13 +7,14 @@ use crate::errors::{ use super::{ForceCollect, Parser, TrailingToken}; use ast::token::Delimiter; +use ast::Attribute; use rustc_ast::token; use rustc_ast::{ self as ast, AttrVec, GenericBounds, GenericParam, GenericParamKind, TyKind, WhereClause, }; use rustc_errors::{Applicability, PResult}; use rustc_span::symbol::{kw, Ident}; -use rustc_span::Span; +use rustc_span::{sym, Span}; use thin_vec::ThinVec; enum PredicateOrStructBody { @@ -245,7 +246,10 @@ impl<'a> Parser<'a> { /// matches generics = ( ) | ( < > ) | ( < typaramseq ( , )? > ) | ( < lifetimes ( , )? > ) /// | ( < lifetimes , typaramseq ( , )? > ) /// where typaramseq = ( typaram ) | ( typaram , typaramseq ) - pub(super) fn parse_generics(&mut self) -> PResult<'a, ast::Generics> { + pub(super) fn parse_generics( + &mut self, + outer_attrs: &[Attribute], + ) -> PResult<'a, ast::Generics> { let span_lo = self.token.span; let (params, span) = if self.eat_lt() { let params = self.parse_generic_params()?; @@ -254,6 +258,9 @@ impl<'a> Parser<'a> { } else { (ThinVec::new(), self.prev_token.span.shrink_to_hi()) }; + + let defines_opaque_types = self.parse_defines(outer_attrs)?; + Ok(ast::Generics { params, where_clause: WhereClause { @@ -262,9 +269,32 @@ impl<'a> Parser<'a> { span: self.prev_token.span.shrink_to_hi(), }, span, + defines_opaque_types, }) } + #[instrument(level = "trace", skip(self), ret)] + pub(super) fn parse_defines( + &mut self, + outer_attrs: &[Attribute], + ) -> PResult<'a, ThinVec<(ast::NodeId, ast::Path)>> { + let mut defines_opaque_types = ThinVec::default(); + for attr in outer_attrs { + if !attr.has_name(sym::defines) { + continue; + } + trace!("{:?}", attr.get_normal_item().args.inner_tokens()); + let path = crate::parse_in( + self.sess, + attr.get_normal_item().args.inner_tokens(), + "defines attribute path", + |parser| parser.parse_path(super::PathStyle::Type), + )?; + defines_opaque_types.push((ast::DUMMY_NODE_ID, path)); + } + Ok(defines_opaque_types) + } + /// Parses an optional where-clause. /// /// ```ignore (only-for-syntax-highlight) @@ -303,7 +333,7 @@ impl<'a> Parser<'a> { // parameter syntax (as in `where<'a>` or `where`. To avoid that being a breaking // change we parse those generics now, but report an error. if self.choose_generics_over_qpath(0) { - let generics = self.parse_generics()?; + let generics = self.parse_generics(&[])?; self.struct_span_err( generics.span, "generic parameters on `where` clauses are reserved for future use", diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 6422b8ac1ba45..edc9319e8d18a 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -228,7 +228,16 @@ impl<'a> Parser<'a> { self.bump(); // `static` let m = self.parse_mutability(); let (ident, ty, expr) = self.parse_item_global(Some(m))?; - (ident, ItemKind::Static(Box::new(StaticItem { ty, mutability: m, expr }))) + let defines_opaque_types = self.parse_defines(attrs)?; + ( + ident, + ItemKind::Static(Box::new(StaticItem { + ty, + mutability: m, + expr, + defines_opaque_types, + })), + ) } else if let Const::Yes(const_span) = self.parse_constness(Case::Sensitive) { // CONST ITEM if self.token.is_keyword(kw::Impl) { @@ -237,7 +246,16 @@ impl<'a> Parser<'a> { } else { self.recover_const_mut(const_span); let (ident, ty, expr) = self.parse_item_global(None)?; - (ident, ItemKind::Const(Box::new(ConstItem { defaultness: def_(), ty, expr }))) + let defines_opaque_types = self.parse_defines(attrs)?; + ( + ident, + ItemKind::Const(Box::new(ConstItem { + defaultness: def_(), + ty, + expr, + defines_opaque_types, + })), + ) } } else if self.check_keyword(kw::Trait) || self.check_auto_or_unsafe_trait_item() { // TRAIT ITEM @@ -254,17 +272,17 @@ impl<'a> Parser<'a> { self.parse_item_mod(attrs)? } else if self.eat_keyword(kw::Type) { // TYPE ITEM - self.parse_type_alias(def_())? + self.parse_type_alias(def_(), attrs)? } else if self.eat_keyword(kw::Enum) { // ENUM ITEM - self.parse_item_enum()? + self.parse_item_enum(attrs)? } else if self.eat_keyword(kw::Struct) { // STRUCT ITEM - self.parse_item_struct()? + self.parse_item_struct(attrs)? } else if self.is_kw_followed_by_ident(kw::Union) { // UNION ITEM self.bump(); // `union` - self.parse_item_union()? + self.parse_item_union(attrs)? } else if self.eat_keyword(kw::Macro) { // MACROS 2.0 ITEM self.parse_item_decl_macro(lo)? @@ -537,13 +555,11 @@ impl<'a> Parser<'a> { // First, parse generic parameters if necessary. let mut generics = if self.choose_generics_over_qpath(0) { - self.parse_generics()? + self.parse_generics(&attrs[..])? } else { - let mut generics = Generics::default(); // impl A for B {} // /\ this is where `generics.span` should point when there are no type params. - generics.span = self.prev_token.span.shrink_to_hi(); - generics + Generics::new(self.prev_token.span.shrink_to_hi(), self.parse_defines(attrs)?) }; let constness = self.parse_constness(Case::Sensitive); @@ -790,7 +806,7 @@ impl<'a> Parser<'a> { self.expect_keyword(kw::Trait)?; let ident = self.parse_ident()?; - let mut generics = self.parse_generics()?; + let mut generics = self.parse_generics(&attrs[..])?; // Parse optional colon and supertrait bounds. let had_colon = self.eat(&token::Colon); @@ -863,12 +879,18 @@ impl<'a> Parser<'a> { let kind = match AssocItemKind::try_from(kind) { Ok(kind) => kind, Err(kind) => match kind { - ItemKind::Static(box StaticItem { ty, mutability: _, expr }) => { + ItemKind::Static(box StaticItem { + ty, + mutability: _, + expr, + defines_opaque_types, + }) => { self.sess.emit_err(errors::AssociatedStaticItemNotAllowed { span }); AssocItemKind::Const(Box::new(ConstItem { defaultness: Defaultness::Final, ty, expr, + defines_opaque_types, })) } _ => return self.error_bad_item_kind(span, &kind, "`trait`s or `impl`s"), @@ -884,9 +906,13 @@ impl<'a> Parser<'a> { /// TypeAlias = "type" Ident Generics {":" GenericBounds}? {"=" Ty}? ";" ; /// ``` /// The `"type"` has already been eaten. - fn parse_type_alias(&mut self, defaultness: Defaultness) -> PResult<'a, ItemInfo> { + fn parse_type_alias( + &mut self, + defaultness: Defaultness, + attrs: &[Attribute], + ) -> PResult<'a, ItemInfo> { let ident = self.parse_ident()?; - let mut generics = self.parse_generics()?; + let mut generics = self.parse_generics(attrs)?; // Parse optional colon and param bounds. let bounds = @@ -1270,7 +1296,7 @@ impl<'a> Parser<'a> { } /// Parses an enum declaration. - fn parse_item_enum(&mut self) -> PResult<'a, ItemInfo> { + fn parse_item_enum(&mut self, attrs: &[Attribute]) -> PResult<'a, ItemInfo> { if self.token.is_keyword(kw::Struct) { let span = self.prev_token.span.to(self.token.span); let err = errors::EnumStructMutuallyExclusive { span }; @@ -1283,7 +1309,7 @@ impl<'a> Parser<'a> { } let id = self.parse_ident()?; - let mut generics = self.parse_generics()?; + let mut generics = self.parse_generics(attrs)?; generics.where_clause = self.parse_where_clause()?; // Possibly recover `enum Foo;` instead of `enum Foo {}` @@ -1355,10 +1381,10 @@ impl<'a> Parser<'a> { } /// Parses `struct Foo { ... }`. - fn parse_item_struct(&mut self) -> PResult<'a, ItemInfo> { + fn parse_item_struct(&mut self, attrs: &[Attribute]) -> PResult<'a, ItemInfo> { let class_name = self.parse_ident()?; - let mut generics = self.parse_generics()?; + let mut generics = self.parse_generics(attrs)?; // There is a special case worth noting here, as reported in issue #17904. // If we are parsing a tuple struct it is the case that the where clause @@ -1423,10 +1449,10 @@ impl<'a> Parser<'a> { } /// Parses `union Foo { ... }`. - fn parse_item_union(&mut self) -> PResult<'a, ItemInfo> { + fn parse_item_union(&mut self, attrs: &[Attribute]) -> PResult<'a, ItemInfo> { let class_name = self.parse_ident()?; - let mut generics = self.parse_generics()?; + let mut generics = self.parse_generics(attrs)?; let vdata = if self.token.is_keyword(kw::Where) { generics.where_clause = self.parse_where_clause()?; @@ -1785,7 +1811,7 @@ impl<'a> Parser<'a> { } } } else if self.eat_keyword(kw::Struct) { - match self.parse_item_struct() { + match self.parse_item_struct(&[]) { Ok((ident, _)) => { let mut err = self.struct_span_err( lo.with_hi(ident.span.hi()), @@ -2083,7 +2109,7 @@ impl<'a> Parser<'a> { let fn_span = self.token.span; let header = self.parse_fn_front_matter(vis, case)?; // `const ... fn` let ident = self.parse_ident()?; // `foo` - let mut generics = self.parse_generics()?; // `<'a, T, ...>` + let mut generics = self.parse_generics(&attrs[..])?; // `<'a, T, ...>` let decl = match self.parse_fn_decl( fn_parse_mode.req_name, AllowPlus::Yes, diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 400c8dbe9bc6b..c86760dc74c64 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -548,7 +548,7 @@ impl<'a> Parser<'a> { params: &mut ThinVec, param_insertion_point: Option, ) -> PResult<'a, ()> { - let generics = self.parse_generics()?; + let generics = self.parse_generics(&[])?; let arity = generics.params.len(); let mut lifetimes: ThinVec<_> = generics diff --git a/compiler/rustc_parse/src/validate_attr.rs b/compiler/rustc_parse/src/validate_attr.rs index 72402a200907a..8c5af8a04683c 100644 --- a/compiler/rustc_parse/src/validate_attr.rs +++ b/compiler/rustc_parse/src/validate_attr.rs @@ -21,8 +21,8 @@ pub fn check_attr(sess: &ParseSess, attr: &Attribute) { // Check input tokens for built-in and key-value attributes. match attr_info { - // `rustc_dummy` doesn't have any restrictions specific to built-in attributes. - Some(BuiltinAttribute { name, template, .. }) if *name != sym::rustc_dummy => { + // `rustc_dummy` and `defines` doesn't have any restrictions specific to built-in attributes. + Some(BuiltinAttribute { name, template, .. }) if *name != sym::rustc_dummy && *name != sym::defines => { check_builtin_attribute(sess, attr, *name, *template) } _ if let AttrArgs::Eq(..) = attr.get_normal_item().args => { diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index a5f7b07fe5211..382bb71356ec6 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -236,7 +236,7 @@ impl<'tcx> ReachableContext<'tcx> { // Reachable constants will be inlined into other crates // unconditionally, so we need to make sure that their // contents are also reachable. - hir::ItemKind::Const(_, init) | hir::ItemKind::Static(_, _, init) => { + hir::ItemKind::Const(_, init, _) | hir::ItemKind::Static(_, _, init, _) => { self.visit_nested_body(init); } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 19f46d45af678..243415f9fe63c 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -973,6 +973,10 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast, for p in &generics.where_clause.predicates { self.visit_where_predicate(p); } + for (id, path) in &generics.defines_opaque_types { + self.smart_resolve_path(*id, &None, path, PathSource::Type); + self.visit_path(path, *id) + } } fn visit_closure_binder(&mut self, b: &'ast ClosureBinder) { @@ -2346,12 +2350,27 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { }); } - ItemKind::Static(box ast::StaticItem { ref ty, ref expr, .. }) - | ItemKind::Const(box ast::ConstItem { ref ty, ref expr, .. }) => { + ItemKind::Static(box ast::StaticItem { + ref ty, + ref expr, + ref defines_opaque_types, + .. + }) + | ItemKind::Const(box ast::ConstItem { + ref ty, + ref expr, + ref defines_opaque_types, + .. + }) => { self.with_static_rib(|this| { this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| { this.visit_ty(ty); }); + + for (id, path) in defines_opaque_types { + this.smart_resolve_path(*id, &None, path, PathSource::Type); + this.visit_path(path, *id) + } this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Infer), |this| { if let Some(expr) = expr { let constant_item_kind = match item.kind { diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 0e55e81143de4..e5fa3c1117873 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -595,6 +595,7 @@ symbols! { default_method_body_is_const, default_type_parameter_fallback, default_type_params, + defines, delay_span_bug_from_inside_query, deny, deprecated, diff --git a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs index cff3d277a78fb..a1ab3103ac050 100644 --- a/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs +++ b/compiler/rustc_trait_selection/src/traits/outlives_bounds.rs @@ -104,6 +104,18 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> { output } + #[cfg(bootstrap)] + fn implied_bounds_tys( + &'a self, + param_env: ParamEnv<'tcx>, + body_id: LocalDefId, + tys: FxIndexSet>, + ) -> Bounds<'a, 'tcx> { + tys.into_iter().flat_map(move |ty| self.implied_outlives_bounds(param_env, body_id, ty)) + } + + #[cfg(not(bootstrap))] + #[defines(Bounds<'a, 'tcx>)] fn implied_bounds_tys( &'a self, param_env: ParamEnv<'tcx>, diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index de1e1a527d5a9..d819fbd6373ae 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -336,6 +336,7 @@ fn associated_type_for_impl_trait_in_trait( param_def_id_to_index, has_self: false, has_late_bound_regions: opaque_ty_generics.has_late_bound_regions, + defines_opaque_types: vec![], } }); @@ -420,6 +421,7 @@ fn associated_type_for_impl_trait_in_impl( param_def_id_to_index, has_self: false, has_late_bound_regions: trait_assoc_generics.has_late_bound_regions, + defines_opaque_types: vec![], } }); diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 1c57cd7a9461c..4d39a2dabaee2 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2305,10 +2305,10 @@ fn clean_maybe_renamed_item<'tcx>( let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id())); cx.with_param_env(def_id, |cx| { let kind = match item.kind { - ItemKind::Static(ty, mutability, body_id) => { + ItemKind::Static(ty, mutability, body_id, _) => { StaticItem(Static { type_: clean_ty(ty, cx), mutability, expr: Some(body_id) }) } - ItemKind::Const(ty, body_id) => ConstantItem(Constant { + ItemKind::Const(ty, body_id, _) => ConstantItem(Constant { type_: clean_ty(ty, cx), kind: ConstantKind::Local { body: body_id, def_id }, }), diff --git a/src/tools/clippy/clippy_lints/src/large_const_arrays.rs b/src/tools/clippy/clippy_lints/src/large_const_arrays.rs index 4dc750c03b488..22203c2305f0a 100644 --- a/src/tools/clippy/clippy_lints/src/large_const_arrays.rs +++ b/src/tools/clippy/clippy_lints/src/large_const_arrays.rs @@ -50,7 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if_chain! { if !item.span.from_expansion(); - if let ItemKind::Const(hir_ty, _) = &item.kind; + if let ItemKind::Const(hir_ty, _, _) = &item.kind; let ty = hir_ty_to_ty(cx.tcx, hir_ty); if let ty::Array(element_type, cst) = ty.kind(); if let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind(); diff --git a/src/tools/clippy/clippy_lints/src/non_copy_const.rs b/src/tools/clippy/clippy_lints/src/non_copy_const.rs index 0bedab05eec61..bd8156bd15914 100644 --- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs +++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs @@ -252,7 +252,7 @@ declare_lint_pass!(NonCopyConst => [DECLARE_INTERIOR_MUTABLE_CONST, BORROW_INTER impl<'tcx> LateLintPass<'tcx> for NonCopyConst { fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx Item<'_>) { - if let ItemKind::Const(hir_ty, body_id) = it.kind { + if let ItemKind::Const(hir_ty, body_id, _) = it.kind { let ty = hir_ty_to_ty(cx.tcx, hir_ty); if !ignored_macro(cx, it) && is_unfrozen(cx, ty) && is_value_unfrozen_poly(cx, body_id, ty) { lint(cx, Source::Item { item: it.span }); diff --git a/src/tools/clippy/clippy_lints/src/types/mod.rs b/src/tools/clippy/clippy_lints/src/types/mod.rs index c1f228d5f90a9..44002468c8f9d 100644 --- a/src/tools/clippy/clippy_lints/src/types/mod.rs +++ b/src/tools/clippy/clippy_lints/src/types/mod.rs @@ -349,7 +349,7 @@ impl<'tcx> LateLintPass<'tcx> for Types { let is_exported = cx.effective_visibilities.is_exported(item.owner_id.def_id); match item.kind { - ItemKind::Static(ty, _, _) | ItemKind::Const(ty, _) => self.check_ty( + ItemKind::Static(ty, _, _, _) | ItemKind::Const(ty, _, _) => self.check_ty( cx, ty, CheckTyContext { diff --git a/src/tools/clippy/clippy_lints/src/undocumented_unsafe_blocks.rs b/src/tools/clippy/clippy_lints/src/undocumented_unsafe_blocks.rs index 2920684ade33c..8ccc1a6f9e02a 100644 --- a/src/tools/clippy/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/src/tools/clippy/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -217,7 +217,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks { }, (hir::ItemKind::Impl(_), _) => {}, // const and static items only need a safety comment if their body is an unsafe block, lint otherwise - (&hir::ItemKind::Const(.., body) | &hir::ItemKind::Static(.., body), HasSafetyComment::Yes(pos)) => { + (&hir::ItemKind::Const(.., body, _) | &hir::ItemKind::Static(.., body, _), HasSafetyComment::Yes(pos)) => { if !is_lint_allowed(cx, UNNECESSARY_SAFETY_COMMENT, body.hir_id) { let body = cx.tcx.hir().body(body); if !matches!( diff --git a/src/tools/clippy/clippy_utils/src/ast_utils.rs b/src/tools/clippy/clippy_utils/src/ast_utils.rs index c5b58b0c060c0..6c39b5231f3c1 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils.rs @@ -286,8 +286,8 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { match (l, r) { (ExternCrate(l), ExternCrate(r)) => l == r, (Use(l), Use(r)) => eq_use_tree(l, r), - (Static(box ast::StaticItem { ty: lt, mutability: lm, expr: le}), Static(box ast::StaticItem { ty: rt, mutability: rm, expr: re})) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), - (Const(box ast::ConstItem { defaultness: ld, ty: lt, expr: le}), Const(box ast::ConstItem { defaultness: rd, ty: rt, expr: re} )) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), + (Static(box ast::StaticItem { ty: lt, mutability: lm, expr: le, ..}), Static(box ast::StaticItem { ty: rt, mutability: rm, expr: re, ..})) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), + (Const(box ast::ConstItem { defaultness: ld, ty: lt, expr: le, ..}), Const(box ast::ConstItem { defaultness: rd, ty: rt, expr: re, ..} )) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), ( Fn(box ast::Fn { defaultness: ld, @@ -451,7 +451,7 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool { pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { use AssocItemKind::*; match (l, r) { - (Const(box ast::ConstItem { defaultness: ld, ty: lt, expr: le}), Const(box ast::ConstItem { defaultness: rd, ty: rt, expr: re})) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), + (Const(box ast::ConstItem { defaultness: ld, ty: lt, expr: le, ..}), Const(box ast::ConstItem { defaultness: rd, ty: rt, expr: re, ..})) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), ( Fn(box ast::Fn { defaultness: ld, diff --git a/src/tools/clippy/clippy_utils/src/consts.rs b/src/tools/clippy/clippy_utils/src/consts.rs index bb8890dcaf988..1373138f297fd 100644 --- a/src/tools/clippy/clippy_utils/src/consts.rs +++ b/src/tools/clippy/clippy_utils/src/consts.rs @@ -428,7 +428,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { // which is NOT constant for our purposes. if let Some(node) = self.lcx.tcx.hir().get_if_local(def_id) && let Node::Item(&Item { - kind: ItemKind::Const(_, body_id), + kind: ItemKind::Const(_, body_id, _), .. }) = node && let Node::Expr(&Expr { diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 619aa9f4bf6fa..1ec8d135cc490 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -2322,7 +2322,7 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalDefId, f: impl Fn(&[Symbol for id in tcx.hir().module_items(module) { if matches!(tcx.def_kind(id.owner_id), DefKind::Const) && let item = tcx.hir().item(id) - && let ItemKind::Const(ty, _body) = item.kind { + && let ItemKind::Const(ty, _body, _) = item.kind { if let TyKind::Path(QPath::Resolved(_, path)) = ty.kind { // We could also check for the type name `test::TestDescAndFn` if let Res::Def(DefKind::Struct, _) = path.res { diff --git a/tests/codegen/sanitizer-cfi-emit-type-metadata-id-itanium-cxx-abi.rs b/tests/codegen/sanitizer-cfi-emit-type-metadata-id-itanium-cxx-abi.rs index b9c33914360ba..82236503691ba 100644 --- a/tests/codegen/sanitizer-cfi-emit-type-metadata-id-itanium-cxx-abi.rs +++ b/tests/codegen/sanitizer-cfi-emit-type-metadata-id-itanium-cxx-abi.rs @@ -3,7 +3,7 @@ // needs-sanitizer-cfi // compile-flags: -Clto -Cno-prepopulate-passes -Ctarget-feature=-crt-static -Zsanitizer=cfi -#![crate_type="lib"] +#![crate_type = "lib"] #![allow(dead_code)] #![allow(incomplete_features)] #![allow(unused_must_use)] @@ -29,23 +29,23 @@ pub union Union1 { } // Extern type -extern { +extern "C" { pub type type1; } // Trait pub trait Trait1 { - fn foo(&self) { } + fn foo(&self) {} } // Trait implementation impl Trait1 for i32 { - fn foo(&self) { } + fn foo(&self) {} } // Trait implementation impl Trait1 for Struct1 { - fn foo(&self) { } + fn foo(&self) {} } // impl Trait type aliases for helping with defining other types (see below) @@ -61,9 +61,19 @@ pub type Type9 = impl Send; pub type Type10 = impl Send; pub type Type11 = impl Send; +#[defines(Type1)] +#[defines(Type2)] +#[defines(Type3)] +#[defines(Type4)] +#[defines(Type6)] +#[defines(Type7)] +#[defines(Type8)] +#[defines(Type9)] +#[defines(Type10)] +#[defines(Type11)] pub fn fn1<'a>() { // Closure - let closure1 = || { }; + let closure1 = || {}; let _: Type1 = closure1; // Constructor @@ -71,7 +81,7 @@ pub fn fn1<'a>() { let _: Type2 = Foo; // Type in extern path - extern { + extern "C" { fn foo(); } let _: Type3 = foo; @@ -85,12 +95,15 @@ pub fn fn1<'a>() { // Type in const path const { pub struct Foo; - fn foo() -> Type5 { Foo } + #[defines(Type5)] + fn foo() -> Type5 { + Foo + } }; // Type in impl path impl Struct1 { - fn foo(&self) { } + fn foo(&self) {} } let _: Type6 = >::foo; @@ -138,305 +151,305 @@ pub struct Bar; #[repr(transparent)] pub struct Type14(T); -pub fn foo0(_: ()) { } +pub fn foo0(_: ()) {} // CHECK: define{{.*}}foo0{{.*}}!type ![[TYPE0:[0-9]+]] -pub fn foo1(_: c_void, _: ()) { } +pub fn foo1(_: c_void, _: ()) {} // CHECK: define{{.*}}foo1{{.*}}!type ![[TYPE1:[0-9]+]] -pub fn foo2(_: (), _: c_void, _: c_void) { } +pub fn foo2(_: (), _: c_void, _: c_void) {} // CHECK: define{{.*}}foo2{{.*}}!type ![[TYPE2:[0-9]+]] -pub fn foo3(_: *mut c_void) { } +pub fn foo3(_: *mut c_void) {} // CHECK: define{{.*}}foo3{{.*}}!type ![[TYPE3:[0-9]+]] -pub fn foo4(_: *mut c_void, _: *mut ()) { } +pub fn foo4(_: *mut c_void, _: *mut ()) {} // CHECK: define{{.*}}foo4{{.*}}!type ![[TYPE4:[0-9]+]] -pub fn foo5(_: *mut (), _: *mut c_void, _: *mut c_void) { } +pub fn foo5(_: *mut (), _: *mut c_void, _: *mut c_void) {} // CHECK: define{{.*}}foo5{{.*}}!type ![[TYPE5:[0-9]+]] -pub fn foo6(_: *const c_void) { } +pub fn foo6(_: *const c_void) {} // CHECK: define{{.*}}foo6{{.*}}!type ![[TYPE6:[0-9]+]] -pub fn foo7(_: *const c_void, _: *const ()) { } +pub fn foo7(_: *const c_void, _: *const ()) {} // CHECK: define{{.*}}foo7{{.*}}!type ![[TYPE7:[0-9]+]] -pub fn foo8(_: *const (), _: *const c_void, _: *const c_void) { } +pub fn foo8(_: *const (), _: *const c_void, _: *const c_void) {} // CHECK: define{{.*}}foo8{{.*}}!type ![[TYPE8:[0-9]+]] -pub fn foo9(_: bool) { } +pub fn foo9(_: bool) {} // CHECK: define{{.*}}foo9{{.*}}!type ![[TYPE9:[0-9]+]] -pub fn foo10(_: bool, _: bool) { } +pub fn foo10(_: bool, _: bool) {} // CHECK: define{{.*}}foo10{{.*}}!type ![[TYPE10:[0-9]+]] -pub fn foo11(_: bool, _: bool, _: bool) { } +pub fn foo11(_: bool, _: bool, _: bool) {} // CHECK: define{{.*}}foo11{{.*}}!type ![[TYPE11:[0-9]+]] -pub fn foo12(_: i8) { } +pub fn foo12(_: i8) {} // CHECK: define{{.*}}foo12{{.*}}!type ![[TYPE12:[0-9]+]] -pub fn foo13(_: i8, _: i8) { } +pub fn foo13(_: i8, _: i8) {} // CHECK: define{{.*}}foo13{{.*}}!type ![[TYPE13:[0-9]+]] -pub fn foo14(_: i8, _: i8, _: i8) { } +pub fn foo14(_: i8, _: i8, _: i8) {} // CHECK: define{{.*}}foo14{{.*}}!type ![[TYPE14:[0-9]+]] -pub fn foo15(_: i16) { } +pub fn foo15(_: i16) {} // CHECK: define{{.*}}foo15{{.*}}!type ![[TYPE15:[0-9]+]] -pub fn foo16(_: i16, _: i16) { } +pub fn foo16(_: i16, _: i16) {} // CHECK: define{{.*}}foo16{{.*}}!type ![[TYPE16:[0-9]+]] -pub fn foo17(_: i16, _: i16, _: i16) { } +pub fn foo17(_: i16, _: i16, _: i16) {} // CHECK: define{{.*}}foo17{{.*}}!type ![[TYPE17:[0-9]+]] -pub fn foo18(_: i32) { } +pub fn foo18(_: i32) {} // CHECK: define{{.*}}foo18{{.*}}!type ![[TYPE18:[0-9]+]] -pub fn foo19(_: i32, _: i32) { } +pub fn foo19(_: i32, _: i32) {} // CHECK: define{{.*}}foo19{{.*}}!type ![[TYPE19:[0-9]+]] -pub fn foo20(_: i32, _: i32, _: i32) { } +pub fn foo20(_: i32, _: i32, _: i32) {} // CHECK: define{{.*}}foo20{{.*}}!type ![[TYPE20:[0-9]+]] -pub fn foo21(_: i64) { } +pub fn foo21(_: i64) {} // CHECK: define{{.*}}foo21{{.*}}!type ![[TYPE21:[0-9]+]] -pub fn foo22(_: i64, _: i64) { } +pub fn foo22(_: i64, _: i64) {} // CHECK: define{{.*}}foo22{{.*}}!type ![[TYPE22:[0-9]+]] -pub fn foo23(_: i64, _: i64, _: i64) { } +pub fn foo23(_: i64, _: i64, _: i64) {} // CHECK: define{{.*}}foo23{{.*}}!type ![[TYPE23:[0-9]+]] -pub fn foo24(_: i128) { } +pub fn foo24(_: i128) {} // CHECK: define{{.*}}foo24{{.*}}!type ![[TYPE24:[0-9]+]] -pub fn foo25(_: i128, _: i128) { } +pub fn foo25(_: i128, _: i128) {} // CHECK: define{{.*}}foo25{{.*}}!type ![[TYPE25:[0-9]+]] -pub fn foo26(_: i128, _: i128, _: i128) { } +pub fn foo26(_: i128, _: i128, _: i128) {} // CHECK: define{{.*}}foo26{{.*}}!type ![[TYPE26:[0-9]+]] -pub fn foo27(_: isize) { } +pub fn foo27(_: isize) {} // CHECK: define{{.*}}foo27{{.*}}!type ![[TYPE27:[0-9]+]] -pub fn foo28(_: isize, _: isize) { } +pub fn foo28(_: isize, _: isize) {} // CHECK: define{{.*}}foo28{{.*}}!type ![[TYPE28:[0-9]+]] -pub fn foo29(_: isize, _: isize, _: isize) { } +pub fn foo29(_: isize, _: isize, _: isize) {} // CHECK: define{{.*}}foo29{{.*}}!type ![[TYPE29:[0-9]+]] -pub fn foo30(_: u8) { } +pub fn foo30(_: u8) {} // CHECK: define{{.*}}foo30{{.*}}!type ![[TYPE30:[0-9]+]] -pub fn foo31(_: u8, _: u8) { } +pub fn foo31(_: u8, _: u8) {} // CHECK: define{{.*}}foo31{{.*}}!type ![[TYPE31:[0-9]+]] -pub fn foo32(_: u8, _: u8, _: u8) { } +pub fn foo32(_: u8, _: u8, _: u8) {} // CHECK: define{{.*}}foo32{{.*}}!type ![[TYPE32:[0-9]+]] -pub fn foo33(_: u16) { } +pub fn foo33(_: u16) {} // CHECK: define{{.*}}foo33{{.*}}!type ![[TYPE33:[0-9]+]] -pub fn foo34(_: u16, _: u16) { } +pub fn foo34(_: u16, _: u16) {} // CHECK: define{{.*}}foo34{{.*}}!type ![[TYPE34:[0-9]+]] -pub fn foo35(_: u16, _: u16, _: u16) { } +pub fn foo35(_: u16, _: u16, _: u16) {} // CHECK: define{{.*}}foo35{{.*}}!type ![[TYPE35:[0-9]+]] -pub fn foo36(_: u32) { } +pub fn foo36(_: u32) {} // CHECK: define{{.*}}foo36{{.*}}!type ![[TYPE36:[0-9]+]] -pub fn foo37(_: u32, _: u32) { } +pub fn foo37(_: u32, _: u32) {} // CHECK: define{{.*}}foo37{{.*}}!type ![[TYPE37:[0-9]+]] -pub fn foo38(_: u32, _: u32, _: u32) { } +pub fn foo38(_: u32, _: u32, _: u32) {} // CHECK: define{{.*}}foo38{{.*}}!type ![[TYPE38:[0-9]+]] -pub fn foo39(_: u64) { } +pub fn foo39(_: u64) {} // CHECK: define{{.*}}foo39{{.*}}!type ![[TYPE39:[0-9]+]] -pub fn foo40(_: u64, _: u64) { } +pub fn foo40(_: u64, _: u64) {} // CHECK: define{{.*}}foo40{{.*}}!type ![[TYPE40:[0-9]+]] -pub fn foo41(_: u64, _: u64, _: u64) { } +pub fn foo41(_: u64, _: u64, _: u64) {} // CHECK: define{{.*}}foo41{{.*}}!type ![[TYPE41:[0-9]+]] -pub fn foo42(_: u128) { } +pub fn foo42(_: u128) {} // CHECK: define{{.*}}foo42{{.*}}!type ![[TYPE42:[0-9]+]] -pub fn foo43(_: u128, _: u128) { } +pub fn foo43(_: u128, _: u128) {} // CHECK: define{{.*}}foo43{{.*}}!type ![[TYPE43:[0-9]+]] -pub fn foo44(_: u128, _: u128, _: u128) { } +pub fn foo44(_: u128, _: u128, _: u128) {} // CHECK: define{{.*}}foo44{{.*}}!type ![[TYPE44:[0-9]+]] -pub fn foo45(_: usize) { } +pub fn foo45(_: usize) {} // CHECK: define{{.*}}foo45{{.*}}!type ![[TYPE45:[0-9]+]] -pub fn foo46(_: usize, _: usize) { } +pub fn foo46(_: usize, _: usize) {} // CHECK: define{{.*}}foo46{{.*}}!type ![[TYPE46:[0-9]+]] -pub fn foo47(_: usize, _: usize, _: usize) { } +pub fn foo47(_: usize, _: usize, _: usize) {} // CHECK: define{{.*}}foo47{{.*}}!type ![[TYPE47:[0-9]+]] -pub fn foo48(_: f32) { } +pub fn foo48(_: f32) {} // CHECK: define{{.*}}foo48{{.*}}!type ![[TYPE48:[0-9]+]] -pub fn foo49(_: f32, _: f32) { } +pub fn foo49(_: f32, _: f32) {} // CHECK: define{{.*}}foo49{{.*}}!type ![[TYPE49:[0-9]+]] -pub fn foo50(_: f32, _: f32, _: f32) { } +pub fn foo50(_: f32, _: f32, _: f32) {} // CHECK: define{{.*}}foo50{{.*}}!type ![[TYPE50:[0-9]+]] -pub fn foo51(_: f64) { } +pub fn foo51(_: f64) {} // CHECK: define{{.*}}foo51{{.*}}!type ![[TYPE51:[0-9]+]] -pub fn foo52(_: f64, _: f64) { } +pub fn foo52(_: f64, _: f64) {} // CHECK: define{{.*}}foo52{{.*}}!type ![[TYPE52:[0-9]+]] -pub fn foo53(_: f64, _: f64, _: f64) { } +pub fn foo53(_: f64, _: f64, _: f64) {} // CHECK: define{{.*}}foo53{{.*}}!type ![[TYPE53:[0-9]+]] -pub fn foo54(_: char) { } +pub fn foo54(_: char) {} // CHECK: define{{.*}}foo54{{.*}}!type ![[TYPE54:[0-9]+]] -pub fn foo55(_: char, _: char) { } +pub fn foo55(_: char, _: char) {} // CHECK: define{{.*}}foo55{{.*}}!type ![[TYPE55:[0-9]+]] -pub fn foo56(_: char, _: char, _: char) { } +pub fn foo56(_: char, _: char, _: char) {} // CHECK: define{{.*}}foo56{{.*}}!type ![[TYPE56:[0-9]+]] -pub fn foo57(_: &str) { } +pub fn foo57(_: &str) {} // CHECK: define{{.*}}foo57{{.*}}!type ![[TYPE57:[0-9]+]] -pub fn foo58(_: &str, _: &str) { } +pub fn foo58(_: &str, _: &str) {} // CHECK: define{{.*}}foo58{{.*}}!type ![[TYPE58:[0-9]+]] -pub fn foo59(_: &str, _: &str, _: &str) { } +pub fn foo59(_: &str, _: &str, _: &str) {} // CHECK: define{{.*}}foo59{{.*}}!type ![[TYPE59:[0-9]+]] -pub fn foo60(_: (i32, i32)) { } +pub fn foo60(_: (i32, i32)) {} // CHECK: define{{.*}}foo60{{.*}}!type ![[TYPE60:[0-9]+]] -pub fn foo61(_: (i32, i32), _: (i32, i32)) { } +pub fn foo61(_: (i32, i32), _: (i32, i32)) {} // CHECK: define{{.*}}foo61{{.*}}!type ![[TYPE61:[0-9]+]] -pub fn foo62(_: (i32, i32), _: (i32, i32), _: (i32, i32)) { } +pub fn foo62(_: (i32, i32), _: (i32, i32), _: (i32, i32)) {} // CHECK: define{{.*}}foo62{{.*}}!type ![[TYPE62:[0-9]+]] -pub fn foo63(_: [i32; 32]) { } +pub fn foo63(_: [i32; 32]) {} // CHECK: define{{.*}}foo63{{.*}}!type ![[TYPE63:[0-9]+]] -pub fn foo64(_: [i32; 32], _: [i32; 32]) { } +pub fn foo64(_: [i32; 32], _: [i32; 32]) {} // CHECK: define{{.*}}foo64{{.*}}!type ![[TYPE64:[0-9]+]] -pub fn foo65(_: [i32; 32], _: [i32; 32], _: [i32; 32]) { } +pub fn foo65(_: [i32; 32], _: [i32; 32], _: [i32; 32]) {} // CHECK: define{{.*}}foo65{{.*}}!type ![[TYPE65:[0-9]+]] -pub fn foo66(_: &[i32]) { } +pub fn foo66(_: &[i32]) {} // CHECK: define{{.*}}foo66{{.*}}!type ![[TYPE66:[0-9]+]] -pub fn foo67(_: &[i32], _: &[i32]) { } +pub fn foo67(_: &[i32], _: &[i32]) {} // CHECK: define{{.*}}foo67{{.*}}!type ![[TYPE67:[0-9]+]] -pub fn foo68(_: &[i32], _: &[i32], _: &[i32]) { } +pub fn foo68(_: &[i32], _: &[i32], _: &[i32]) {} // CHECK: define{{.*}}foo68{{.*}}!type ![[TYPE68:[0-9]+]] -pub fn foo69(_: &Struct1::) { } +pub fn foo69(_: &Struct1) {} // CHECK: define{{.*}}foo69{{.*}}!type ![[TYPE69:[0-9]+]] -pub fn foo70(_: &Struct1::, _: &Struct1::) { } +pub fn foo70(_: &Struct1, _: &Struct1) {} // CHECK: define{{.*}}foo70{{.*}}!type ![[TYPE70:[0-9]+]] -pub fn foo71(_: &Struct1::, _: &Struct1::, _: &Struct1::) { } +pub fn foo71(_: &Struct1, _: &Struct1, _: &Struct1) {} // CHECK: define{{.*}}foo71{{.*}}!type ![[TYPE71:[0-9]+]] -pub fn foo72(_: &Enum1::) { } +pub fn foo72(_: &Enum1) {} // CHECK: define{{.*}}foo72{{.*}}!type ![[TYPE72:[0-9]+]] -pub fn foo73(_: &Enum1::, _: &Enum1::) { } +pub fn foo73(_: &Enum1, _: &Enum1) {} // CHECK: define{{.*}}foo73{{.*}}!type ![[TYPE73:[0-9]+]] -pub fn foo74(_: &Enum1::, _: &Enum1::, _: &Enum1::) { } +pub fn foo74(_: &Enum1, _: &Enum1, _: &Enum1) {} // CHECK: define{{.*}}foo74{{.*}}!type ![[TYPE74:[0-9]+]] -pub fn foo75(_: &Union1::) { } +pub fn foo75(_: &Union1) {} // CHECK: define{{.*}}foo75{{.*}}!type ![[TYPE75:[0-9]+]] -pub fn foo76(_: &Union1::, _: &Union1::) { } +pub fn foo76(_: &Union1, _: &Union1) {} // CHECK: define{{.*}}foo76{{.*}}!type ![[TYPE76:[0-9]+]] -pub fn foo77(_: &Union1::, _: &Union1::, _: &Union1::) { } +pub fn foo77(_: &Union1, _: &Union1, _: &Union1) {} // CHECK: define{{.*}}foo77{{.*}}!type ![[TYPE77:[0-9]+]] -pub fn foo78(_: *mut type1) { } +pub fn foo78(_: *mut type1) {} // CHECK: define{{.*}}foo78{{.*}}!type ![[TYPE78:[0-9]+]] -pub fn foo79(_: *mut type1, _: *mut type1) { } +pub fn foo79(_: *mut type1, _: *mut type1) {} // CHECK: define{{.*}}foo79{{.*}}!type ![[TYPE79:[0-9]+]] -pub fn foo80(_: *mut type1, _: *mut type1, _: *mut type1) { } +pub fn foo80(_: *mut type1, _: *mut type1, _: *mut type1) {} // CHECK: define{{.*}}foo80{{.*}}!type ![[TYPE80:[0-9]+]] -pub fn foo81(_: &mut i32) { } +pub fn foo81(_: &mut i32) {} // CHECK: define{{.*}}foo81{{.*}}!type ![[TYPE81:[0-9]+]] -pub fn foo82(_: &mut i32, _: &i32) { } +pub fn foo82(_: &mut i32, _: &i32) {} // CHECK: define{{.*}}foo82{{.*}}!type ![[TYPE82:[0-9]+]] -pub fn foo83(_: &mut i32, _: &i32, _: &i32) { } +pub fn foo83(_: &mut i32, _: &i32, _: &i32) {} // CHECK: define{{.*}}foo83{{.*}}!type ![[TYPE83:[0-9]+]] -pub fn foo84(_: &i32) { } +pub fn foo84(_: &i32) {} // CHECK: define{{.*}}foo84{{.*}}!type ![[TYPE84:[0-9]+]] -pub fn foo85(_: &i32, _: &mut i32) { } +pub fn foo85(_: &i32, _: &mut i32) {} // CHECK: define{{.*}}foo85{{.*}}!type ![[TYPE85:[0-9]+]] -pub fn foo86(_: &i32, _: &mut i32, _: &mut i32) { } +pub fn foo86(_: &i32, _: &mut i32, _: &mut i32) {} // CHECK: define{{.*}}foo86{{.*}}!type ![[TYPE86:[0-9]+]] -pub fn foo87(_: *mut i32) { } +pub fn foo87(_: *mut i32) {} // CHECK: define{{.*}}foo87{{.*}}!type ![[TYPE87:[0-9]+]] -pub fn foo88(_: *mut i32, _: *const i32) { } +pub fn foo88(_: *mut i32, _: *const i32) {} // CHECK: define{{.*}}foo88{{.*}}!type ![[TYPE88:[0-9]+]] -pub fn foo89(_: *mut i32, _: *const i32, _: *const i32) { } +pub fn foo89(_: *mut i32, _: *const i32, _: *const i32) {} // CHECK: define{{.*}}foo89{{.*}}!type ![[TYPE89:[0-9]+]] -pub fn foo90(_: *const i32) { } +pub fn foo90(_: *const i32) {} // CHECK: define{{.*}}foo90{{.*}}!type ![[TYPE90:[0-9]+]] -pub fn foo91(_: *const i32, _: *mut i32) { } +pub fn foo91(_: *const i32, _: *mut i32) {} // CHECK: define{{.*}}foo91{{.*}}!type ![[TYPE91:[0-9]+]] -pub fn foo92(_: *const i32, _: *mut i32, _: *mut i32) { } +pub fn foo92(_: *const i32, _: *mut i32, _: *mut i32) {} // CHECK: define{{.*}}foo92{{.*}}!type ![[TYPE92:[0-9]+]] -pub fn foo93(_: fn(i32) -> i32) { } +pub fn foo93(_: fn(i32) -> i32) {} // CHECK: define{{.*}}foo93{{.*}}!type ![[TYPE93:[0-9]+]] -pub fn foo94(_: fn(i32) -> i32, _: fn(i32) -> i32) { } +pub fn foo94(_: fn(i32) -> i32, _: fn(i32) -> i32) {} // CHECK: define{{.*}}foo94{{.*}}!type ![[TYPE94:[0-9]+]] -pub fn foo95(_: fn(i32) -> i32, _: fn(i32) -> i32, _: fn(i32) -> i32) { } +pub fn foo95(_: fn(i32) -> i32, _: fn(i32) -> i32, _: fn(i32) -> i32) {} // CHECK: define{{.*}}foo95{{.*}}!type ![[TYPE95:[0-9]+]] -pub fn foo96(_: &dyn Fn(i32) -> i32) { } +pub fn foo96(_: &dyn Fn(i32) -> i32) {} // CHECK: define{{.*}}foo96{{.*}}!type ![[TYPE96:[0-9]+]] -pub fn foo97(_: &dyn Fn(i32) -> i32, _: &dyn Fn(i32) -> i32) { } +pub fn foo97(_: &dyn Fn(i32) -> i32, _: &dyn Fn(i32) -> i32) {} // CHECK: define{{.*}}foo97{{.*}}!type ![[TYPE97:[0-9]+]] -pub fn foo98(_: &dyn Fn(i32) -> i32, _: &dyn Fn(i32) -> i32, _: &dyn Fn(i32) -> i32) { } +pub fn foo98(_: &dyn Fn(i32) -> i32, _: &dyn Fn(i32) -> i32, _: &dyn Fn(i32) -> i32) {} // CHECK: define{{.*}}foo98{{.*}}!type ![[TYPE98:[0-9]+]] -pub fn foo99(_: &dyn FnMut(i32) -> i32) { } +pub fn foo99(_: &dyn FnMut(i32) -> i32) {} // CHECK: define{{.*}}foo99{{.*}}!type ![[TYPE99:[0-9]+]] -pub fn foo100(_: &dyn FnMut(i32) -> i32, _: &dyn FnMut(i32) -> i32) { } +pub fn foo100(_: &dyn FnMut(i32) -> i32, _: &dyn FnMut(i32) -> i32) {} // CHECK: define{{.*}}foo100{{.*}}!type ![[TYPE100:[0-9]+]] -pub fn foo101(_: &dyn FnMut(i32) -> i32, _: &dyn FnMut(i32) -> i32, _: &dyn FnMut(i32) -> i32) { } +pub fn foo101(_: &dyn FnMut(i32) -> i32, _: &dyn FnMut(i32) -> i32, _: &dyn FnMut(i32) -> i32) {} // CHECK: define{{.*}}foo101{{.*}}!type ![[TYPE101:[0-9]+]] -pub fn foo102(_: &dyn FnOnce(i32) -> i32) { } +pub fn foo102(_: &dyn FnOnce(i32) -> i32) {} // CHECK: define{{.*}}foo102{{.*}}!type ![[TYPE102:[0-9]+]] -pub fn foo103(_: &dyn FnOnce(i32) -> i32, _: &dyn FnOnce(i32) -> i32) { } +pub fn foo103(_: &dyn FnOnce(i32) -> i32, _: &dyn FnOnce(i32) -> i32) {} // CHECK: define{{.*}}foo103{{.*}}!type ![[TYPE103:[0-9]+]] pub fn foo104(_: &dyn FnOnce(i32) -> i32, _: &dyn FnOnce(i32) -> i32, _: &dyn FnOnce(i32) -> i32) {} // CHECK: define{{.*}}foo104{{.*}}!type ![[TYPE104:[0-9]+]] -pub fn foo105(_: &dyn Send) { } +pub fn foo105(_: &dyn Send) {} // CHECK: define{{.*}}foo105{{.*}}!type ![[TYPE105:[0-9]+]] -pub fn foo106(_: &dyn Send, _: &dyn Send) { } +pub fn foo106(_: &dyn Send, _: &dyn Send) {} // CHECK: define{{.*}}foo106{{.*}}!type ![[TYPE106:[0-9]+]] -pub fn foo107(_: &dyn Send, _: &dyn Send, _: &dyn Send) { } +pub fn foo107(_: &dyn Send, _: &dyn Send, _: &dyn Send) {} // CHECK: define{{.*}}foo107{{.*}}!type ![[TYPE107:[0-9]+]] -pub fn foo108(_: Type1) { } +pub fn foo108(_: Type1) {} // CHECK: define{{.*}}foo108{{.*}}!type ![[TYPE108:[0-9]+]] -pub fn foo109(_: Type1, _: Type1) { } +pub fn foo109(_: Type1, _: Type1) {} // CHECK: define{{.*}}foo109{{.*}}!type ![[TYPE109:[0-9]+]] -pub fn foo110(_: Type1, _: Type1, _: Type1) { } +pub fn foo110(_: Type1, _: Type1, _: Type1) {} // CHECK: define{{.*}}foo110{{.*}}!type ![[TYPE110:[0-9]+]] -pub fn foo111(_: Type2) { } +pub fn foo111(_: Type2) {} // CHECK: define{{.*}}foo111{{.*}}!type ![[TYPE111:[0-9]+]] -pub fn foo112(_: Type2, _: Type2) { } +pub fn foo112(_: Type2, _: Type2) {} // CHECK: define{{.*}}foo112{{.*}}!type ![[TYPE112:[0-9]+]] -pub fn foo113(_: Type2, _: Type2, _: Type2) { } +pub fn foo113(_: Type2, _: Type2, _: Type2) {} // CHECK: define{{.*}}foo113{{.*}}!type ![[TYPE113:[0-9]+]] -pub fn foo114(_: Type3) { } +pub fn foo114(_: Type3) {} // CHECK: define{{.*}}foo114{{.*}}!type ![[TYPE114:[0-9]+]] -pub fn foo115(_: Type3, _: Type3) { } +pub fn foo115(_: Type3, _: Type3) {} // CHECK: define{{.*}}foo115{{.*}}!type ![[TYPE115:[0-9]+]] -pub fn foo116(_: Type3, _: Type3, _: Type3) { } +pub fn foo116(_: Type3, _: Type3, _: Type3) {} // CHECK: define{{.*}}foo116{{.*}}!type ![[TYPE116:[0-9]+]] -pub fn foo117(_: Type4) { } +pub fn foo117(_: Type4) {} // CHECK: define{{.*}}foo117{{.*}}!type ![[TYPE117:[0-9]+]] -pub fn foo118(_: Type4, _: Type4) { } +pub fn foo118(_: Type4, _: Type4) {} // CHECK: define{{.*}}foo118{{.*}}!type ![[TYPE118:[0-9]+]] -pub fn foo119(_: Type4, _: Type4, _: Type4) { } +pub fn foo119(_: Type4, _: Type4, _: Type4) {} // CHECK: define{{.*}}foo119{{.*}}!type ![[TYPE119:[0-9]+]] -pub fn foo120(_: Type5) { } +pub fn foo120(_: Type5) {} // CHECK: define{{.*}}foo120{{.*}}!type ![[TYPE120:[0-9]+]] -pub fn foo121(_: Type5, _: Type5) { } +pub fn foo121(_: Type5, _: Type5) {} // CHECK: define{{.*}}foo121{{.*}}!type ![[TYPE121:[0-9]+]] -pub fn foo122(_: Type5, _: Type5, _: Type5) { } +pub fn foo122(_: Type5, _: Type5, _: Type5) {} // CHECK: define{{.*}}foo122{{.*}}!type ![[TYPE122:[0-9]+]] -pub fn foo123(_: Type6) { } +pub fn foo123(_: Type6) {} // CHECK: define{{.*}}foo123{{.*}}!type ![[TYPE123:[0-9]+]] -pub fn foo124(_: Type6, _: Type6) { } +pub fn foo124(_: Type6, _: Type6) {} // CHECK: define{{.*}}foo124{{.*}}!type ![[TYPE124:[0-9]+]] -pub fn foo125(_: Type6, _: Type6, _: Type6) { } +pub fn foo125(_: Type6, _: Type6, _: Type6) {} // CHECK: define{{.*}}foo125{{.*}}!type ![[TYPE125:[0-9]+]] -pub fn foo126(_: Type7) { } +pub fn foo126(_: Type7) {} // CHECK: define{{.*}}foo126{{.*}}!type ![[TYPE126:[0-9]+]] -pub fn foo127(_: Type7, _: Type7) { } +pub fn foo127(_: Type7, _: Type7) {} // CHECK: define{{.*}}foo127{{.*}}!type ![[TYPE127:[0-9]+]] -pub fn foo128(_: Type7, _: Type7, _: Type7) { } +pub fn foo128(_: Type7, _: Type7, _: Type7) {} // CHECK: define{{.*}}foo128{{.*}}!type ![[TYPE128:[0-9]+]] -pub fn foo129(_: Type8) { } +pub fn foo129(_: Type8) {} // CHECK: define{{.*}}foo129{{.*}}!type ![[TYPE129:[0-9]+]] -pub fn foo130(_: Type8, _: Type8) { } +pub fn foo130(_: Type8, _: Type8) {} // CHECK: define{{.*}}foo130{{.*}}!type ![[TYPE130:[0-9]+]] -pub fn foo131(_: Type8, _: Type8, _: Type8) { } +pub fn foo131(_: Type8, _: Type8, _: Type8) {} // CHECK: define{{.*}}foo131{{.*}}!type ![[TYPE131:[0-9]+]] -pub fn foo132(_: Type9) { } +pub fn foo132(_: Type9) {} // CHECK: define{{.*}}foo132{{.*}}!type ![[TYPE132:[0-9]+]] -pub fn foo133(_: Type9, _: Type9) { } +pub fn foo133(_: Type9, _: Type9) {} // CHECK: define{{.*}}foo133{{.*}}!type ![[TYPE133:[0-9]+]] -pub fn foo134(_: Type9, _: Type9, _: Type9) { } +pub fn foo134(_: Type9, _: Type9, _: Type9) {} // CHECK: define{{.*}}foo134{{.*}}!type ![[TYPE134:[0-9]+]] -pub fn foo135(_: Type10) { } +pub fn foo135(_: Type10) {} // CHECK: define{{.*}}foo135{{.*}}!type ![[TYPE135:[0-9]+]] -pub fn foo136(_: Type10, _: Type10) { } +pub fn foo136(_: Type10, _: Type10) {} // CHECK: define{{.*}}foo136{{.*}}!type ![[TYPE136:[0-9]+]] -pub fn foo137(_: Type10, _: Type10, _: Type10) { } +pub fn foo137(_: Type10, _: Type10, _: Type10) {} // CHECK: define{{.*}}foo137{{.*}}!type ![[TYPE137:[0-9]+]] -pub fn foo138(_: Type11) { } +pub fn foo138(_: Type11) {} // CHECK: define{{.*}}foo138{{.*}}!type ![[TYPE138:[0-9]+]] -pub fn foo139(_: Type11, _: Type11) { } +pub fn foo139(_: Type11, _: Type11) {} // CHECK: define{{.*}}foo139{{.*}}!type ![[TYPE139:[0-9]+]] -pub fn foo140(_: Type11, _: Type11, _: Type11) { } +pub fn foo140(_: Type11, _: Type11, _: Type11) {} // CHECK: define{{.*}}foo140{{.*}}!type ![[TYPE140:[0-9]+]] -pub fn foo141(_: Type12) { } +pub fn foo141(_: Type12) {} // CHECK: define{{.*}}foo141{{.*}}!type ![[TYPE141:[0-9]+]] -pub fn foo142(_: Type12, _: Type12) { } +pub fn foo142(_: Type12, _: Type12) {} // CHECK: define{{.*}}foo142{{.*}}!type ![[TYPE142:[0-9]+]] -pub fn foo143(_: Type12, _: Type12, _: Type12) { } +pub fn foo143(_: Type12, _: Type12, _: Type12) {} // CHECK: define{{.*}}foo143{{.*}}!type ![[TYPE143:[0-9]+]] -pub fn foo144(_: Type13) { } +pub fn foo144(_: Type13) {} // CHECK: define{{.*}}foo144{{.*}}!type ![[TYPE144:[0-9]+]] -pub fn foo145(_: Type13, _: Type13) { } +pub fn foo145(_: Type13, _: Type13) {} // CHECK: define{{.*}}foo145{{.*}}!type ![[TYPE145:[0-9]+]] -pub fn foo146(_: Type13, _: Type13, _: Type13) { } +pub fn foo146(_: Type13, _: Type13, _: Type13) {} // CHECK: define{{.*}}foo146{{.*}}!type ![[TYPE146:[0-9]+]] -pub fn foo147(_: Type14) { } +pub fn foo147(_: Type14) {} // CHECK: define{{.*}}foo147{{.*}}!type ![[TYPE147:[0-9]+]] -pub fn foo148(_: Type14, _: Type14) { } +pub fn foo148(_: Type14, _: Type14) {} // CHECK: define{{.*}}foo148{{.*}}!type ![[TYPE148:[0-9]+]] -pub fn foo149(_: Type14, _: Type14, _: Type14) { } +pub fn foo149(_: Type14, _: Type14, _: Type14) {} // CHECK: define{{.*}}foo149{{.*}}!type ![[TYPE149:[0-9]+]] // CHECK: ![[TYPE0]] = !{i64 0, !"_ZTSFvvE"} diff --git a/tests/ui/associated-type-bounds/dyn-impl-trait-type.rs b/tests/ui/associated-type-bounds/dyn-impl-trait-type.rs index a8d00803a534a..4e26344d33e98 100644 --- a/tests/ui/associated-type-bounds/dyn-impl-trait-type.rs +++ b/tests/ui/associated-type-bounds/dyn-impl-trait-type.rs @@ -1,35 +1,61 @@ // run-pass -#![feature(associated_type_bounds)] +#![feature(associated_type_bounds, type_alias_impl_trait)] use std::ops::Add; -trait Tr1 { type As1; fn mk(&self) -> Self::As1; } -trait Tr2<'a> { fn tr2(self) -> &'a Self; } +trait Tr1 { + type As1; + fn mk(&self) -> Self::As1; +} +trait Tr2<'a> { + fn tr2(self) -> &'a Self; +} -fn assert_copy(x: T) { let _x = x; let _x = x; } +fn assert_copy(x: T) { + let _x = x; + let _x = x; +} fn assert_static(_: T) {} fn assert_forall_tr2 Tr2<'a>>(_: T) {} struct S1; #[derive(Copy, Clone)] struct S2; -impl Tr1 for S1 { type As1 = S2; fn mk(&self) -> Self::As1 { S2 } } +impl Tr1 for S1 { + type As1 = S2; + fn mk(&self) -> Self::As1 { + S2 + } +} type Et1 = Box>; -fn def_et1() -> Et1 { Box::new(S1) } -pub fn use_et1() { assert_copy(def_et1().mk()); } +#[defines(Et1)] +fn def_et1() -> Et1 { + Box::new(S1) +} +pub fn use_et1() { + assert_copy(def_et1().mk()); +} type Et2 = Box>; -fn def_et2() -> Et2 { Box::new(S1) } -pub fn use_et2() { assert_static(def_et2().mk()); } +#[defines(Et2)] +fn def_et2() -> Et2 { + Box::new(S1) +} +pub fn use_et2() { + assert_static(def_et2().mk()); +} type Et3 = Box>>>>; +#[defines(Et3)] fn def_et3() -> Et3 { struct A; impl Tr1 for A { type As1 = core::ops::Range; - fn mk(&self) -> Self::As1 { 0..10 } + fn mk(&self) -> Self::As1 { + 0..10 + } } Box::new(A) } @@ -44,19 +70,26 @@ pub fn use_et3() { } type Et4 = Box Tr2<'a>>>; +#[defines(Et4)] fn def_et4() -> Et4 { #[derive(Copy, Clone)] struct A; impl Tr1 for A { type As1 = A; - fn mk(&self) -> A { A } + fn mk(&self) -> A { + A + } } impl<'a> Tr2<'a> for A { - fn tr2(self) -> &'a Self { &A } + fn tr2(self) -> &'a Self { + &A + } } Box::new(A) } -pub fn use_et4() { assert_forall_tr2(def_et4().mk()); } +pub fn use_et4() { + assert_forall_tr2(def_et4().mk()); +} fn main() { let _ = use_et1(); 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 e223a89574170..0ca1b0ab609c3 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/issues/issue-60655-latebound-regions.rs b/tests/ui/async-await/issues/issue-60655-latebound-regions.rs index 66a3b07c3bd96..ef0c6235eb826 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 generator witness type here. +#[defines(ServeFut)] fn serve() -> ServeFut { async move { let x = 5; diff --git a/tests/ui/attributes/collapse-debuginfo-invalid.rs b/tests/ui/attributes/collapse-debuginfo-invalid.rs index 42d8982c11861..a9e827bf28c2a 100644 --- a/tests/ui/attributes/collapse-debuginfo-invalid.rs +++ b/tests/ui/attributes/collapse-debuginfo-invalid.rs @@ -23,25 +23,25 @@ const BAR: u32 = 3; #[collapse_debuginfo] //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions +#[rustfmt::skip] fn foo() { let _ = #[collapse_debuginfo] || { }; -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions #[collapse_debuginfo] -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions let _ = 3; let _ = #[collapse_debuginfo] 3; -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions match (3, 4) { #[collapse_debuginfo] -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions _ => (), } } #[collapse_debuginfo] //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions -mod bar { -} +mod bar {} #[collapse_debuginfo] //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions @@ -51,7 +51,7 @@ type Map = HashMap; //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions enum Foo { #[collapse_debuginfo] -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions Variant, } @@ -59,7 +59,7 @@ enum Foo { //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions struct Bar { #[collapse_debuginfo] -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions field: u32, } @@ -67,14 +67,14 @@ struct Bar { //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions union Qux { a: u32, - b: u16 + b: u16, } #[collapse_debuginfo] //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions trait Foobar { #[collapse_debuginfo] -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions type Bar; } @@ -86,6 +86,7 @@ impl Foobar for Bar { type Bar = u32; } +#[defines(AFoobar)] fn constraining() -> AFoobar { Bar { field: 3 } } @@ -94,17 +95,19 @@ fn constraining() -> AFoobar { //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions impl Bar { #[collapse_debuginfo] -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions const FOO: u32 = 3; #[collapse_debuginfo] -//~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions + //~^ ERROR `collapse_debuginfo` attribute should be applied to macro definitions fn bar(&self) {} } #[collapse_debuginfo] macro_rules! finally { - ($e:expr) => { $e } + ($e:expr) => { + $e + }; } fn main() {} diff --git a/tests/ui/attributes/collapse-debuginfo-invalid.stderr b/tests/ui/attributes/collapse-debuginfo-invalid.stderr index 01c476091082f..b974ab555f376 100644 --- a/tests/ui/attributes/collapse-debuginfo-invalid.stderr +++ b/tests/ui/attributes/collapse-debuginfo-invalid.stderr @@ -39,7 +39,7 @@ error: `collapse_debuginfo` attribute should be applied to macro definitions | LL | #[collapse_debuginfo] | ^^^^^^^^^^^^^^^^^^^^^ -LL | +... LL | / fn foo() { LL | | let _ = #[collapse_debuginfo] || { }; LL | | @@ -50,13 +50,13 @@ LL | | } | |_- not a macro definition error: `collapse_debuginfo` attribute should be applied to macro definitions - --> $DIR/collapse-debuginfo-invalid.rs:27:13 + --> $DIR/collapse-debuginfo-invalid.rs:28:13 | LL | let _ = #[collapse_debuginfo] || { }; | ^^^^^^^^^^^^^^^^^^^^^ ------ not a macro definition error: `collapse_debuginfo` attribute should be applied to macro definitions - --> $DIR/collapse-debuginfo-invalid.rs:29:5 + --> $DIR/collapse-debuginfo-invalid.rs:30:5 | LL | #[collapse_debuginfo] | ^^^^^^^^^^^^^^^^^^^^^ @@ -65,13 +65,13 @@ LL | let _ = 3; | ---------- not a macro definition error: `collapse_debuginfo` attribute should be applied to macro definitions - --> $DIR/collapse-debuginfo-invalid.rs:32:13 + --> $DIR/collapse-debuginfo-invalid.rs:33:13 | LL | let _ = #[collapse_debuginfo] 3; | ^^^^^^^^^^^^^^^^^^^^^ - not a macro definition error: `collapse_debuginfo` attribute should be applied to macro definitions - --> $DIR/collapse-debuginfo-invalid.rs:35:9 + --> $DIR/collapse-debuginfo-invalid.rs:36:9 | LL | #[collapse_debuginfo] | ^^^^^^^^^^^^^^^^^^^^^ @@ -80,14 +80,13 @@ LL | _ => (), | ------- not a macro definition error: `collapse_debuginfo` attribute should be applied to macro definitions - --> $DIR/collapse-debuginfo-invalid.rs:41:1 + --> $DIR/collapse-debuginfo-invalid.rs:42:1 | -LL | #[collapse_debuginfo] - | ^^^^^^^^^^^^^^^^^^^^^ +LL | #[collapse_debuginfo] + | ^^^^^^^^^^^^^^^^^^^^^ LL | -LL | / mod bar { -LL | | } - | |_- not a macro definition +LL | mod bar {} + | ---------- not a macro definition error: `collapse_debuginfo` attribute should be applied to macro definitions --> $DIR/collapse-debuginfo-invalid.rs:46:1 @@ -150,7 +149,7 @@ LL | #[collapse_debuginfo] LL | LL | / union Qux { LL | | a: u32, -LL | | b: u16 +LL | | b: u16, LL | | } | |_- not a macro definition @@ -177,7 +176,7 @@ LL | type AFoobar = impl Foobar; | --------------------------- not a macro definition error: `collapse_debuginfo` attribute should be applied to macro definitions - --> $DIR/collapse-debuginfo-invalid.rs:93:1 + --> $DIR/collapse-debuginfo-invalid.rs:94:1 | LL | #[collapse_debuginfo] | ^^^^^^^^^^^^^^^^^^^^^ @@ -201,7 +200,7 @@ LL | type Bar; | --------- not a macro definition error: `collapse_debuginfo` attribute should be applied to macro definitions - --> $DIR/collapse-debuginfo-invalid.rs:96:5 + --> $DIR/collapse-debuginfo-invalid.rs:97:5 | LL | #[collapse_debuginfo] | ^^^^^^^^^^^^^^^^^^^^^ @@ -210,7 +209,7 @@ LL | const FOO: u32 = 3; | ------------------- not a macro definition error: `collapse_debuginfo` attribute should be applied to macro definitions - --> $DIR/collapse-debuginfo-invalid.rs:100:5 + --> $DIR/collapse-debuginfo-invalid.rs:101:5 | LL | #[collapse_debuginfo] | ^^^^^^^^^^^^^^^^^^^^^ 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 431108e14d7d8..0cc1ed124913a 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-generator.rs b/tests/ui/coherence/coherence-with-generator.rs index 5eb8dc2a4687f..c218fcb97b18d 100644 --- a/tests/ui/coherence/coherence-with-generator.rs +++ b/tests/ui/coherence/coherence-with-generator.rs @@ -7,6 +7,7 @@ // [specialized]check-pass type OpaqueGenerator = impl Sized; +#[defines(OpaqueGenerator)] fn defining_use() -> OpaqueGenerator { || { for i in 0..10 { diff --git a/tests/ui/coherence/coherence-with-generator.stock.stderr b/tests/ui/coherence/coherence-with-generator.stock.stderr index 478ac4912646d..eb42dd7623410 100644 --- a/tests/ui/coherence/coherence-with-generator.stock.stderr +++ b/tests/ui/coherence/coherence-with-generator.stock.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `Trait` for type `Wrapper` - --> $DIR/coherence-with-generator.rs:21:1 + --> $DIR/coherence-with-generator.rs:22: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 10a0a568849bf..dc0168f36d284 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 a2d4d398ce1d5..4372471492e04 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/entry-point/imported_main_const_fn_item_type_forbidden.rs b/tests/ui/entry-point/imported_main_const_fn_item_type_forbidden.rs index 405d6e2a9f560..cd59c097c5a07 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 @@ -5,6 +5,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 fabb6ffb02f77..effc2f35e8bc1 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:11:22 + --> $DIR/imported_main_const_fn_item_type_forbidden.rs:12: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 6dfd7f6840f1b..230ca93908217 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 @@ -1,33 +1,36 @@ // ignore-compare-mode-chalk -// check-pass -#![feature(type_alias_impl_trait)] + use std::fmt::Debug; type Foo = impl Debug; +//~^ ERROR: `impl Trait` in type aliases is unstable struct Bar(Foo); + +#[defines(Foo)] +//~^ ERROR: is an experimental feature fn define() -> Bar { Bar(42) } -type Foo2 = impl Debug; - fn define2() { + type Foo2 = impl Debug; + //~^ ERROR: `impl Trait` in type aliases is unstable let x = || -> Foo2 { 42 }; } type Foo3 = impl Debug; +//~^ ERROR: `impl Trait` in type aliases is unstable +#[defines(Foo3)] +//~^ ERROR: is an experimental feature fn define3(x: Foo3) { let y: i32 = x; } -fn define3_1() { - define3(42) -} - -type Foo4 = impl Debug; fn define4() { + type Foo4 = impl Debug; + //~^ ERROR: `impl Trait` in type aliases is unstable let y: Foo4 = 42; } diff --git a/tests/ui/feature-gates/feature-gate-type_alias_impl_trait.stderr b/tests/ui/feature-gates/feature-gate-type_alias_impl_trait.stderr new file mode 100644 index 0000000000000..a8c296e5e83b4 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-type_alias_impl_trait.stderr @@ -0,0 +1,57 @@ +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/feature-gate-type_alias_impl_trait.rs:5:12 + | +LL | type Foo = impl Debug; + | ^^^^^^^^^^ + | + = note: see issue #63063 for more information + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error[E0658]: the `#[type_alias_impl_trait]` attribute is an experimental feature + --> $DIR/feature-gate-type_alias_impl_trait.rs:10:1 + | +LL | #[defines(Foo)] + | ^^^^^^^^^^^^^^^ + | + = note: see issue #63063 for more information + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/feature-gate-type_alias_impl_trait.rs:17:17 + | +LL | type Foo2 = impl Debug; + | ^^^^^^^^^^ + | + = note: see issue #63063 for more information + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/feature-gate-type_alias_impl_trait.rs:22:13 + | +LL | type Foo3 = impl Debug; + | ^^^^^^^^^^ + | + = note: see issue #63063 for more information + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error[E0658]: the `#[type_alias_impl_trait]` attribute is an experimental feature + --> $DIR/feature-gate-type_alias_impl_trait.rs:25:1 + | +LL | #[defines(Foo3)] + | ^^^^^^^^^^^^^^^^ + | + = note: see issue #63063 for more information + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error[E0658]: `impl Trait` in type aliases is unstable + --> $DIR/feature-gate-type_alias_impl_trait.rs:32:17 + | +LL | type Foo4 = impl Debug; + | ^^^^^^^^^^ + | + = note: see issue #63063 for more information + = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/generator/layout-error.rs b/tests/ui/generator/layout-error.rs index 7c3d187409a2f..60303538a0e62 100644 --- a/tests/ui/generator/layout-error.rs +++ b/tests/ui/generator/layout-error.rs @@ -23,6 +23,7 @@ fn main() { type F = impl Future; // Check that statics are inhabited computes they layout. + #[defines(F)] static POOL: Task = Task::new(); Task::spawn(&POOL, || cb()); } diff --git a/tests/ui/generator/metadata-sufficient-for-layout.rs b/tests/ui/generator/metadata-sufficient-for-layout.rs index d0e648ee775fa..36c397fe45100 100644 --- a/tests/ui/generator/metadata-sufficient-for-layout.rs +++ b/tests/ui/generator/metadata-sufficient-for-layout.rs @@ -17,6 +17,7 @@ type F = impl Generator<(), Yield = (), Return = ()>; // Static queries the layout of the generator. static A: Option = None; +#[defines(F)] fn f() -> F { metadata_sufficient_for_layout::g() } diff --git a/tests/ui/generator/metadata-sufficient-for-layout.stderr b/tests/ui/generator/metadata-sufficient-for-layout.stderr index 3488b04f2267e..b0aa5c9ce526c 100644 --- a/tests/ui/generator/metadata-sufficient-for-layout.stderr +++ b/tests/ui/generator/metadata-sufficient-for-layout.stderr @@ -1,5 +1,5 @@ error: fatal error triggered by #[rustc_error] - --> $DIR/metadata-sufficient-for-layout.rs:25:1 + --> $DIR/metadata-sufficient-for-layout.rs:26:1 | LL | fn main() {} | ^^^^^^^^^ diff --git a/tests/ui/generic-associated-types/issue-87258_b.rs b/tests/ui/generic-associated-types/issue-87258_b.rs index 7b7610b21c7dc..b2e9150da7d15 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<'c, 'a, S>)] fn foo<'a>() -> Self::FooFuture<'a> { Struct(unimplemented!()) } diff --git a/tests/ui/generic-associated-types/issue-88287.rs b/tests/ui/generic-associated-types/issue-88287.rs index 82188493d52bd..c6be1f698766c 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<'c, T, Criteria>)] 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 1b84cce622929..5207115fbdf78 100644 --- a/tests/ui/generic-associated-types/issue-88287.stderr +++ b/tests/ui/generic-associated-types/issue-88287.stderr @@ -1,5 +1,5 @@ error[E0277]: the size for values of type `A` cannot be known at compilation time - --> $DIR/issue-88287.rs:34:9 + --> $DIR/issue-88287.rs:35:9 | LL | type SearchFutureTy<'f, A, B: 'f> | - this type parameter needs to be `std::marker::Sized` diff --git a/tests/ui/impl-trait/async_scope_creep.rs b/tests/ui/impl-trait/async_scope_creep.rs index 7a9d64d339feb..ece73ff0eac47 100644 --- a/tests/ui/impl-trait/async_scope_creep.rs +++ b/tests/ui/impl-trait/async_scope_creep.rs @@ -12,14 +12,16 @@ impl AsyncRead for i32 {} type PendingReader<'a> = impl AsyncRead + 'a; -type OpeningReadFuture<'a> = - impl std::future::Future, CantOpen>>; +#[defines(PendingReader<'a>)] +type OpeningReadFuture<'a> = impl std::future::Future, CantOpen>>; impl Pending { async fn read(&mut self) -> Result { Ok(42) } + #[defines(OpeningReadFuture<'_>)] + #[defines(PendingReader<'_>)] fn read_fut(&mut self) -> OpeningReadFuture<'_> { self.read() } diff --git a/tests/ui/impl-trait/auto-trait.rs b/tests/ui/impl-trait/auto-trait.rs index 35994e4a5ba3f..a45ba7f845d28 100644 --- a/tests/ui/impl-trait/auto-trait.rs +++ b/tests/ui/impl-trait/auto-trait.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.stderr b/tests/ui/impl-trait/auto-trait.stderr index 81009413c9a26..2e825bedbc7f9 100644 --- a/tests/ui/impl-trait/auto-trait.stderr +++ b/tests/ui/impl-trait/auto-trait.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `AnotherTrait` for type `D` - --> $DIR/auto-trait.rs:21:1 + --> $DIR/auto-trait.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 5613c1916c6cd..8a0f2c37c2db3 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/deduce-signature-from-supertrait.rs b/tests/ui/impl-trait/deduce-signature-from-supertrait.rs index d2c3479203573..2465ff34f3d75 100644 --- a/tests/ui/impl-trait/deduce-signature-from-supertrait.rs +++ b/tests/ui/impl-trait/deduce-signature-from-supertrait.rs @@ -8,8 +8,11 @@ impl SuperExpectation for T {} type Foo = impl SuperExpectation; -fn main() { +#[defines(Foo)] +fn foo() { let _: Foo = |x| { let _ = x.to_string(); }; } + +fn main() {} 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 970d84120e07e..ba5450492ec84 100644 --- a/tests/ui/impl-trait/hidden-type-is-opaque-2.rs +++ b/tests/ui/impl-trait/hidden-type-is-opaque-2.rs @@ -13,6 +13,7 @@ fn reify_as() -> Thunk Continuation> { type Tait = impl FnOnce(Continuation) -> Continuation; +#[defines(Tait)] fn reify_as_tait() -> Thunk { Thunk::new(|mut cont| { cont.reify_as(); //~ ERROR type annotations needed diff --git a/tests/ui/impl-trait/hidden-type-is-opaque-2.stderr b/tests/ui/impl-trait/hidden-type-is-opaque-2.stderr index 957052feba95b..5298020129c54 100644 --- a/tests/ui/impl-trait/hidden-type-is-opaque-2.stderr +++ b/tests/ui/impl-trait/hidden-type-is-opaque-2.stderr @@ -5,7 +5,7 @@ LL | cont.reify_as(); | ^^^^ cannot infer type error[E0282]: type annotations needed - --> $DIR/hidden-type-is-opaque-2.rs:18:9 + --> $DIR/hidden-type-is-opaque-2.rs:19:9 | LL | cont.reify_as(); | ^^^^ cannot infer type diff --git a/tests/ui/impl-trait/hidden-type-is-opaque.rs b/tests/ui/impl-trait/hidden-type-is-opaque.rs index 72b4028d854f8..35a985d6c8928 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/issue-55872-2.stderr b/tests/ui/impl-trait/issue-55872-2.stderr deleted file mode 100644 index 477c964bd40fd..0000000000000 --- a/tests/ui/impl-trait/issue-55872-2.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias - --> $DIR/issue-55872-2.rs:17:9 - | -LL | async {} - | ^^^^^^^^ - -error: aborting due to previous error - diff --git a/tests/ui/impl-trait/issue-86465.rs b/tests/ui/impl-trait/issue-86465.rs index 8c7b41d73b7c6..be224e7efa7fb 100644 --- a/tests/ui/impl-trait/issue-86465.rs +++ b/tests/ui/impl-trait/issue-86465.rs @@ -6,6 +6,8 @@ impl<'a, T: ?Sized> Captures<'a> for T {} type X<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +#[defines(X<'t, 'u>)] +#[defines(X<'u, 't>)] fn f<'t, 'u>(a: &'t u32, b: &'u u32) -> (X<'t, 'u>, X<'u, 't>) { (a, a) //~^ ERROR concrete type differs from previous defining opaque type use diff --git a/tests/ui/impl-trait/issue-86465.stderr b/tests/ui/impl-trait/issue-86465.stderr index b949b2b4245d8..418e160e0f4ac 100644 --- a/tests/ui/impl-trait/issue-86465.stderr +++ b/tests/ui/impl-trait/issue-86465.stderr @@ -1,5 +1,5 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/issue-86465.rs:10:5 + --> $DIR/issue-86465.rs:12:5 | LL | (a, a) | ^^^^^^ diff --git a/tests/ui/impl-trait/issue-99642-2.rs b/tests/ui/impl-trait/issue-99642-2.rs index 0e88b363338a9..0b6f0168377e3 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 7b9c2c53aad4f..19a0bd1f8469a 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 8169cfafac711..5440d7c052ef5 100644 --- a/tests/ui/impl-trait/issues/issue-70877.rs +++ b/tests/ui/impl-trait/issues/issue-70877.rs @@ -17,14 +17,18 @@ impl Iterator for Bar { } } +#[defines(FooRet)] fn quux(st: FooArg) -> FooRet { Some(st.to_string()) } +#[defines(Foo)] fn ham() -> Foo { Bar(1) } +#[defines(FooRet)] +#[defines(Foo)] fn oof() -> impl std::fmt::Debug { let mut bar = ham(); let func = bar.next().unwrap(); diff --git a/tests/ui/impl-trait/issues/issue-70877.stderr b/tests/ui/impl-trait/issues/issue-70877.stderr index 8813bff3c353e..f22f2f41e3270 100644 --- a/tests/ui/impl-trait/issues/issue-70877.stderr +++ b/tests/ui/impl-trait/issues/issue-70877.stderr @@ -1,11 +1,11 @@ error: opaque type's hidden type cannot be another opaque type from the same scope - --> $DIR/issue-70877.rs:31:12 + --> $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:28:13 + --> $DIR/issue-70877.rs:32:13 | LL | fn oof() -> impl std::fmt::Debug { | ^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/impl-trait/issues/issue-74282.rs b/tests/ui/impl-trait/issues/issue-74282.rs index 654de0cd0253c..00c5cc723ac87 100644 --- a/tests/ui/impl-trait/issues/issue-74282.rs +++ b/tests/ui/impl-trait/issues/issue-74282.rs @@ -1,11 +1,12 @@ #![feature(type_alias_impl_trait)] -type Closure = impl Fn() -> u64; -struct Anonymous(Closure); - fn main() { + type Closure = impl Fn() -> u64; + struct Anonymous(Closure); let y = || -> Closure { || 3 }; - Anonymous(|| { //~ ERROR mismatched types - 3 //~^ ERROR mismatched types + Anonymous(|| { + //~^ ERROR mismatched types + //~| ERROR mismatched types + 3 }) } diff --git a/tests/ui/impl-trait/issues/issue-74282.stderr b/tests/ui/impl-trait/issues/issue-74282.stderr index 724f3c5d6747c..9316588ff0050 100644 --- a/tests/ui/impl-trait/issues/issue-74282.stderr +++ b/tests/ui/impl-trait/issues/issue-74282.stderr @@ -1,34 +1,38 @@ error[E0308]: mismatched types - --> $DIR/issue-74282.rs:8:15 + --> $DIR/issue-74282.rs:7:15 | -LL | type Closure = impl Fn() -> u64; - | ---------------- the expected opaque type +LL | type Closure = impl Fn() -> u64; + | ---------------- the expected opaque type ... LL | Anonymous(|| { | _____---------_^ | | | | | arguments to this struct are incorrect +LL | | +LL | | LL | | 3 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:7:15: 7: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 - --> $DIR/issue-74282.rs:4:8 + --> $DIR/issue-74282.rs:5:12 | -LL | struct Anonymous(Closure); - | ^^^^^^^^^ +LL | struct Anonymous(Closure); + | ^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/issue-74282.rs:8:5 + --> $DIR/issue-74282.rs:7:5 | LL | fn main() { | - expected `()` because of default return type -LL | let y = || -> Closure { || 3 }; +... LL | / Anonymous(|| { +LL | | +LL | | LL | | 3 LL | | }) | | ^- help: consider using a semicolon here: `;` diff --git a/tests/ui/impl-trait/issues/issue-77987.rs b/tests/ui/impl-trait/issues/issue-77987.rs index d29710b6f54ca..d78ff1dbebefb 100644 --- a/tests/ui/impl-trait/issues/issue-77987.rs +++ b/tests/ui/impl-trait/issues/issue-77987.rs @@ -8,13 +8,14 @@ impl Foo for U {} type Scope = impl Foo<()>; #[allow(unused)] +#[defines(Scope)] fn infer_scope() -> Scope { () } #[allow(unused)] -fn ice() -> impl Foo -{ +#[defines(Scope)] +fn ice() -> impl Foo { loop {} } diff --git a/tests/ui/impl-trait/issues/issue-78722.rs b/tests/ui/impl-trait/issues/issue-78722.rs index 7b5ab5f229835..3b5e4b9db2848 100644 --- a/tests/ui/impl-trait/issues/issue-78722.rs +++ b/tests/ui/impl-trait/issues/issue-78722.rs @@ -2,10 +2,10 @@ #![feature(type_alias_impl_trait)] -type F = impl core::future::Future; - 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_global.rs b/tests/ui/impl-trait/issues/issue-78722_global.rs new file mode 100644 index 0000000000000..e5b1655fce564 --- /dev/null +++ b/tests/ui/impl-trait/issues/issue-78722_global.rs @@ -0,0 +1,21 @@ +// edition:2018 + +#![feature(type_alias_impl_trait)] + +type F = impl core::future::Future; + +// FIXME(type_alias_impl_trait): this attribute can be added, but is useless +#[defines(F)] +struct Bug { + V1: [(); { + #[defines(F)] + fn concrete_use() -> F { + async {} + } + let f: F = async { 1 }; + //~^ ERROR: mismatched types + 1 + }], +} + +fn main() {} diff --git a/tests/ui/impl-trait/issues/issue-78722_global.stderr b/tests/ui/impl-trait/issues/issue-78722_global.stderr new file mode 100644 index 0000000000000..9028f1430566c --- /dev/null +++ b/tests/ui/impl-trait/issues/issue-78722_global.stderr @@ -0,0 +1,29 @@ +error[E0308]: mismatched types + --> $DIR/issue-78722_global.rs:15:20 + | +LL | type F = impl core::future::Future; + | -------------------------------------- the expected future +... +LL | let f: F = async { 1 }; + | - ^^^^^^^^^^^ expected future, found `async` block + | | + | expected due to this + | + = note: expected opaque type `F` + found `async` block `[async block@$DIR/issue-78722_global.rs:15:20: 15:31]` +note: this item cannot register hidden type without a `#[defines(F)]` attribute + --> $DIR/issue-78722_global.rs:10:14 + | +LL | V1: [(); { + | ______________^ +LL | | #[defines(F)] +LL | | fn concrete_use() -> F { +LL | | async {} +... | +LL | | 1 +LL | | }], + | |_____^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/impl-trait/issues/issue-86201.rs b/tests/ui/impl-trait/issues/issue-86201.rs index 0786e66ca8b06..4304620a0dae5 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-89312.rs b/tests/ui/impl-trait/issues/issue-89312.rs index d685a6f120109..6ac4d1441c77e 100644 --- a/tests/ui/impl-trait/issues/issue-89312.rs +++ b/tests/ui/impl-trait/issues/issue-89312.rs @@ -11,6 +11,7 @@ impl<'a> T for &'a S { type Item = &'a (); } +#[defines(Alias<'a>)] fn filter_positive<'a>() -> Alias<'a> { &S } 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/issues/issue-99348-impl-compatibility.stderr b/tests/ui/impl-trait/issues/issue-99348-impl-compatibility.stderr index f0dceb1b11a5d..30205e9741d79 100644 --- a/tests/ui/impl-trait/issues/issue-99348-impl-compatibility.stderr +++ b/tests/ui/impl-trait/issues/issue-99348-impl-compatibility.stderr @@ -14,6 +14,11 @@ LL | type Other = Tait; | ^^^^ = note: expected struct `Concrete` found opaque type `Tait` +note: this item cannot register hidden type without a `#[defines(Tait)]` attribute + --> $DIR/issue-99348-impl-compatibility.rs:8:5 + | +LL | type Item = Concrete; + | ^^^^^^^^^ note: required by a bound in `Foo::Item` --> $DIR/issue-99348-impl-compatibility.rs:17:20 | 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..c7386d29d8f5a 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<'a, 'b>)] 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 5b0b1cc5e426f..be819816d6a6c 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..17611290219ff 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<'a, 'b>)] 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 01d9f506a0c58..88b6fa4e2b26a 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 e363fdb36e3ae..893daacc9df8e 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<'a, 'b>)] fn upper_bounds<'a, 'b>(a: &'a u8, b: &'b u8) -> Foo<'a, 'b> { // In this simple case, you have a hidden type `(&'0 u8, &'1 u8)` and constraints like // diff --git a/tests/ui/impl-trait/nested-return-type2-tait.rs b/tests/ui/impl-trait/nested-return-type2-tait.rs index 089018a1cdf01..45db1c7b728fe 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 a8eb69cfcb736..0742ed2cd04bd 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 af8e066305471..531fc9c41a245 100644 --- a/tests/ui/impl-trait/nested-return-type2-tait2.rs +++ b/tests/ui/impl-trait/nested-return-type2-tait2.rs @@ -23,10 +23,11 @@ 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)] +#[defines(Sendable)] fn foo() -> Traitable { || 42 //~^ ERROR `Sendable: Duh` is not satisfied } -fn main() { -} +fn main() {} diff --git a/tests/ui/impl-trait/nested-return-type2-tait2.stderr b/tests/ui/impl-trait/nested-return-type2-tait2.stderr index b85bb5efd100a..bcebca5b7cdd0 100644 --- a/tests/ui/impl-trait/nested-return-type2-tait2.stderr +++ b/tests/ui/impl-trait/nested-return-type2-tait2.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `Sendable: Duh` is not satisfied - --> $DIR/nested-return-type2-tait2.rs:27:5 + --> $DIR/nested-return-type2-tait2.rs:29:5 | LL | || 42 | ^^^^^ the trait `Duh` is not implemented for `Sendable` | = help: the trait `Duh` is implemented for `i32` -note: required for `[closure@$DIR/nested-return-type2-tait2.rs:27:5: 27:7]` to implement `Trait` +note: required for `[closure@$DIR/nested-return-type2-tait2.rs:29:5: 29:7]` to implement `Trait` --> $DIR/nested-return-type2-tait2.rs:14:31 | LL | impl R> Trait for F { diff --git a/tests/ui/impl-trait/nested-return-type2-tait3.rs b/tests/ui/impl-trait/nested-return-type2-tait3.rs index 74fd8a9dda0bf..2092fdadc2e1c 100644 --- a/tests/ui/impl-trait/nested-return-type2-tait3.rs +++ b/tests/ui/impl-trait/nested-return-type2-tait3.rs @@ -22,10 +22,10 @@ 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 //~^ ERROR `impl Send: Duh` is not satisfied } -fn main() { -} +fn main() {} diff --git a/tests/ui/impl-trait/nested-return-type2-tait3.stderr b/tests/ui/impl-trait/nested-return-type2-tait3.stderr index 19fd3c134acda..1a7605b5c89dc 100644 --- a/tests/ui/impl-trait/nested-return-type2-tait3.stderr +++ b/tests/ui/impl-trait/nested-return-type2-tait3.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `impl Send: Duh` is not satisfied - --> $DIR/nested-return-type2-tait3.rs:26:5 + --> $DIR/nested-return-type2-tait3.rs:27:5 | LL | || 42 | ^^^^^ the trait `Duh` is not implemented for `impl Send` | = help: the trait `Duh` is implemented for `i32` -note: required for `[closure@$DIR/nested-return-type2-tait3.rs:26:5: 26:7]` to implement `Trait` +note: required for `[closure@$DIR/nested-return-type2-tait3.rs:27:5: 27:7]` to implement `Trait` --> $DIR/nested-return-type2-tait3.rs:14:31 | LL | impl R> Trait for F { diff --git a/tests/ui/impl-trait/nested-return-type3-tait.rs b/tests/ui/impl-trait/nested-return-type3-tait.rs index 3a97e35b4c400..722d6c042b186 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 5f58c8dca4ad4..424134ebce89a 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 5b6f78a989687..ead94c2ba9e22 100644 --- a/tests/ui/impl-trait/nested-return-type3-tait2.rs +++ b/tests/ui/impl-trait/nested-return-type3-tait2.rs @@ -15,12 +15,14 @@ impl Trait for F { } type Sendable = impl Send; +#[defines(Sendable)] type Traitable = impl Trait; //~^ WARN opaque type `Traitable` does not satisfy its associated type bounds +#[defines(Traitable)] +#[defines(Sendable)] fn foo() -> Traitable { 42 } -fn main() { -} +fn main() {} diff --git a/tests/ui/impl-trait/nested-return-type3-tait2.stderr b/tests/ui/impl-trait/nested-return-type3-tait2.stderr index c07f6ead75028..4bf2b9aa5499c 100644 --- a/tests/ui/impl-trait/nested-return-type3-tait2.stderr +++ b/tests/ui/impl-trait/nested-return-type3-tait2.stderr @@ -1,5 +1,5 @@ warning: opaque type `Traitable` does not satisfy its associated type bounds - --> $DIR/nested-return-type3-tait2.rs:18:29 + --> $DIR/nested-return-type3-tait2.rs:19:29 | LL | type Assoc: Duh; | --- this associated type bound is unsatisfied for `Sendable` diff --git a/tests/ui/impl-trait/nested-return-type3-tait3.rs b/tests/ui/impl-trait/nested-return-type3-tait3.rs index 394d8f581102f..464c69c1dd93d 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.rs b/tests/ui/impl-trait/normalize-tait-in-const.rs index d2e34c00b6422..7693038ee1c8f 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.rs +++ b/tests/ui/impl-trait/normalize-tait-in-const.rs @@ -23,6 +23,7 @@ impl<'a> T for &'a S { type Item = &'a (); } +#[defines(Alias<'a>)] const fn filter_positive<'a>() -> &'a Alias<'a> { &&S } 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 af9dfe25bb4ce..886b0f9d67fe4 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 @@ -10,6 +10,7 @@ impl PartialEq<(Foo, i32)> for Bar { } } +#[defines(Foo)] fn foo() -> Foo { //~^ ERROR can't compare `Bar` with `(Bar, i32)` Bar diff --git a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle-2.stderr b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle-2.stderr index 7b63a3d0b9f10..8e5a2b5bddecf 100644 --- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle-2.stderr +++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle-2.stderr @@ -1,5 +1,5 @@ error[E0277]: can't compare `Bar` with `(Bar, i32)` - --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle-2.rs:13:13 + --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle-2.rs:14:13 | LL | fn foo() -> Foo { | ^^^ no implementation for `Bar == (Bar, i32)` 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 f7aff41954445..5dde1d1b942c7 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 @@ -20,6 +20,11 @@ LL | fn eq(&self, _other: &(Foo, i32)) -> bool { | = note: expected signature `fn(&a::Bar, &(a::Bar, i32)) -> _` found signature `fn(&a::Bar, &(a::Foo, i32)) -> _` +note: this item cannot register hidden type without a `#[defines(a::Foo)]` attribute + --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:10:9 + | +LL | fn eq(&self, _other: &(Foo, i32)) -> bool { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: unconstrained opaque type --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:18:16 @@ -43,6 +48,11 @@ LL | fn eq(&self, _other: &(Bar, i32)) -> bool { | = note: expected signature `fn(&b::Bar, &(b::Foo, i32)) -> _` found signature `fn(&b::Bar, &(b::Bar, i32)) -> _` +note: this item cannot register hidden type without a `#[defines(b::Foo)]` attribute + --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:24:9 + | +LL | fn eq(&self, _other: &(Bar, i32)) -> bool { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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 ad0a003e87948..68674a80fe978 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 @@ -12,6 +12,7 @@ impl PartialEq<(Bar, i32)> for Bar { } } +#[defines(Foo)] fn foo() -> Foo { Bar } 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 6eb2a11b22c5f..189b430715a01 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other.rs +++ b/tests/ui/impl-trait/two_tait_defining_each_other.rs @@ -5,6 +5,8 @@ type B = impl Foo; trait Foo {} +#[defines(A)] +#[defines(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_other.stderr b/tests/ui/impl-trait/two_tait_defining_each_other.stderr index 1a42ac525a6a8..6c150539fc12a 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other.stderr +++ b/tests/ui/impl-trait/two_tait_defining_each_other.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:12:5 + --> $DIR/two_tait_defining_each_other.rs:14: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_other2.rs b/tests/ui/impl-trait/two_tait_defining_each_other2.rs index 05b09668016c4..45ed3aa30def2 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other2.rs +++ b/tests/ui/impl-trait/two_tait_defining_each_other2.rs @@ -5,6 +5,8 @@ type B = impl Foo; trait Foo {} +#[defines(A)] +#[defines(B)] fn muh(x: A) -> B { x // B's hidden type is A (opaquely) //~^ ERROR opaque type's hidden type cannot be another opaque type diff --git a/tests/ui/impl-trait/two_tait_defining_each_other2.stderr b/tests/ui/impl-trait/two_tait_defining_each_other2.stderr index 4d8f96de1626c..be4f47f540b07 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other2.stderr +++ b/tests/ui/impl-trait/two_tait_defining_each_other2.stderr @@ -7,7 +7,7 @@ LL | type A = impl Foo; = note: `A` must be used in combination with a concrete type within the same module error: opaque type's hidden type cannot be another opaque type from the same scope - --> $DIR/two_tait_defining_each_other2.rs:9:5 + --> $DIR/two_tait_defining_each_other2.rs:11: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_other3.rs b/tests/ui/impl-trait/two_tait_defining_each_other3.rs index 37f8ae1b84b55..f6fcfd61383ac 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other3.rs +++ b/tests/ui/impl-trait/two_tait_defining_each_other3.rs @@ -5,6 +5,8 @@ type B = impl Foo; trait Foo {} +#[defines(A)] +#[defines(B)] fn muh(x: A) -> B { if false { return x; // B's hidden type is A (opaquely) diff --git a/tests/ui/impl-trait/two_tait_defining_each_other3.stderr b/tests/ui/impl-trait/two_tait_defining_each_other3.stderr index b06dc16d5e700..253ccc7c25764 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other3.stderr +++ b/tests/ui/impl-trait/two_tait_defining_each_other3.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:10:16 + --> $DIR/two_tait_defining_each_other3.rs:12: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/type-alias-impl-trait-in-fn-body.rs b/tests/ui/impl-trait/type-alias-impl-trait-in-fn-body.rs index 91be4efd56a15..9bb39de4600f0 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 @@ -7,6 +7,7 @@ use std::fmt::Debug; fn main() { type Existential = impl Debug; + #[defines(Existential)] fn f() -> Existential {} println!("{:?}", f()); } diff --git a/tests/ui/layout/debug.rs b/tests/ui/layout/debug.rs index a282e71235c31..3d2e5b95af1ad 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/lazy-type-alias-impl-trait/branches.rs b/tests/ui/lazy-type-alias-impl-trait/branches.rs index 95239e2e341c8..6b1693bff172f 100644 --- a/tests/ui/lazy-type-alias-impl-trait/branches.rs +++ b/tests/ui/lazy-type-alias-impl-trait/branches.rs @@ -2,16 +2,14 @@ type Foo = impl 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() } } 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 0b206f31e7b6e..b205a3f0c6165 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:17: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 04218f5643d1c..a559e9f30bae5 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..493c3ca3df1b3 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,7 @@ 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..05cfdada11116 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:17: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:25: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:32: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 cf7cd5d26ca2f..9e0f695dbda02 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 6b3d9ff4cdec8..87fbdf12cd331 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 616eb935e93d4..efab90be52264 100644 --- a/tests/ui/lint/issue-99387.rs +++ b/tests/ui/lint/issue-99387.rs @@ -5,6 +5,7 @@ pub type Successors<'a> = impl Iterator; +#[defines(Successors<'a>)] pub fn f<'a>() -> Successors<'a> { None.into_iter() } @@ -17,6 +18,7 @@ impl<'a> Tr for &'a () { type Item = Successors<'a>; } +#[defines(Successors<'a>)] pub fn ohno<'a>() -> <&'a () as Tr>::Item { None.into_iter() } diff --git a/tests/ui/lint/lint-ctypes-73249-2.rs b/tests/ui/lint/lint-ctypes-73249-2.rs index 691047c8a405b..405ba71064a4b 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 {} pub trait Foo { diff --git a/tests/ui/lint/lint-ctypes-73249-2.stderr b/tests/ui/lint/lint-ctypes-73249-2.stderr index 8073c33dd4631..2ebc6c73896ad 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:25 + --> $DIR/lint-ctypes-73249-2.rs:27:25 | LL | pub 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 c41ce666db872..3e44751be8012 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 98245c4f144ae..5eef0c9efbe6c 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 145ba784f7c66..55aab8316f457 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 9f43576ad7353..ae0176fcbe492 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:25 + --> $DIR/lint-ctypes-73251-1.rs:24:25 | LL | pub 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 df71a94579624..dc70916733536 100644 --- a/tests/ui/lint/lint-ctypes-73251-2.rs +++ b/tests/ui/lint/lint-ctypes-73251-2.rs @@ -22,12 +22,16 @@ where type AliasA = impl TraitA; +#[defines(AliasA)] type AliasB = impl TraitB; +#[defines(AliasA)] fn use_of_a() -> AliasA { 3 } +#[defines(AliasB)] +#[defines(AliasA)] 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 0b3de379c19d5..3ab01f9225605 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:25 + --> $DIR/lint-ctypes-73251-2.rs:40:25 | LL | pub 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 ebc2ca77b67a1..bfc445e77ba08 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 e8d696477ada1..e033bf42dbcf5 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 b7cc38e99fc37..937456ef3a8b3 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 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 33aa95854e306..a8c3a5bc579d4 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:17 + --> $DIR/opaque-ty-ffi-unsafe.rs:12:17 | LL | pub fn a(_: A); | ^ not FFI-safe diff --git a/tests/ui/mir/issue-75053.rs b/tests/ui/mir/issue-75053.rs index cb56eaa0b13d9..e1554ed5d1d21 100644 --- a/tests/ui/mir/issue-75053.rs +++ b/tests/ui/mir/issue-75053.rs @@ -16,6 +16,7 @@ trait MyFrom: Sized { trait F {} impl F for () {} type DummyT = impl F; +#[defines(DummyT)] fn _dummy_t() -> DummyT {} struct Phantom1(PhantomData); diff --git a/tests/ui/mir/issue-75053.stderr b/tests/ui/mir/issue-75053.stderr index 64e59e6c44825..d109643a6a99b 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:46: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 78cc83bdbfadb..1927d1187fef2 100644 --- a/tests/ui/never_type/impl_trait_fallback2.stderr +++ b/tests/ui/never_type/impl_trait_fallback2.stderr @@ -7,7 +7,7 @@ LL | fn should_ret_unit() -> impl T { = 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 5d5d216fb9bcc..b4212e2c8fa8d 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/privacy/private-in-public-type-alias-impl-trait.rs b/tests/ui/privacy/private-in-public-type-alias-impl-trait.rs index c7df31529bcf3..a7b5377fc0661 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/stats/hir-stats.stderr b/tests/ui/stats/hir-stats.stderr index d723ff538a886..7cb4ad4860792 100644 --- a/tests/ui/stats/hir-stats.stderr +++ b/tests/ui/stats/hir-stats.stderr @@ -5,55 +5,55 @@ ast-stats-1 GenericArgs 40 ( 0.6%) 1 40 ast-stats-1 - AngleBracketed 40 ( 0.6%) 1 ast-stats-1 Crate 40 ( 0.6%) 1 40 ast-stats-1 ExprField 48 ( 0.7%) 1 48 -ast-stats-1 WherePredicate 56 ( 0.9%) 1 56 -ast-stats-1 - BoundPredicate 56 ( 0.9%) 1 +ast-stats-1 WherePredicate 56 ( 0.8%) 1 56 +ast-stats-1 - BoundPredicate 56 ( 0.8%) 1 ast-stats-1 Attribute 64 ( 1.0%) 2 32 ast-stats-1 - Normal 32 ( 0.5%) 1 ast-stats-1 - DocComment 32 ( 0.5%) 1 ast-stats-1 Local 72 ( 1.1%) 1 72 -ast-stats-1 Arm 96 ( 1.5%) 2 48 -ast-stats-1 ForeignItem 96 ( 1.5%) 1 96 -ast-stats-1 - Fn 96 ( 1.5%) 1 +ast-stats-1 Arm 96 ( 1.4%) 2 48 +ast-stats-1 ForeignItem 96 ( 1.4%) 1 96 +ast-stats-1 - Fn 96 ( 1.4%) 1 ast-stats-1 FnDecl 120 ( 1.8%) 5 24 -ast-stats-1 FieldDef 160 ( 2.5%) 2 80 -ast-stats-1 Stmt 160 ( 2.5%) 5 32 +ast-stats-1 FieldDef 160 ( 2.4%) 2 80 +ast-stats-1 Stmt 160 ( 2.4%) 5 32 ast-stats-1 - Local 32 ( 0.5%) 1 ast-stats-1 - MacCall 32 ( 0.5%) 1 -ast-stats-1 - Expr 96 ( 1.5%) 3 -ast-stats-1 Param 160 ( 2.5%) 4 40 -ast-stats-1 Block 192 ( 3.0%) 6 32 -ast-stats-1 Variant 208 ( 3.2%) 2 104 -ast-stats-1 GenericBound 224 ( 3.5%) 4 56 -ast-stats-1 - Trait 224 ( 3.5%) 4 -ast-stats-1 AssocItem 352 ( 5.4%) 4 88 +ast-stats-1 - Expr 96 ( 1.4%) 3 +ast-stats-1 Param 160 ( 2.4%) 4 40 +ast-stats-1 Block 192 ( 2.9%) 6 32 +ast-stats-1 Variant 208 ( 3.1%) 2 104 +ast-stats-1 GenericBound 224 ( 3.4%) 4 56 +ast-stats-1 - Trait 224 ( 3.4%) 4 +ast-stats-1 AssocItem 352 ( 5.3%) 4 88 ast-stats-1 - Type 176 ( 2.7%) 2 ast-stats-1 - Fn 176 ( 2.7%) 2 -ast-stats-1 GenericParam 480 ( 7.4%) 5 96 -ast-stats-1 Pat 504 ( 7.8%) 7 72 +ast-stats-1 GenericParam 480 ( 7.2%) 5 96 +ast-stats-1 Pat 504 ( 7.6%) 7 72 ast-stats-1 - Struct 72 ( 1.1%) 1 ast-stats-1 - Wild 72 ( 1.1%) 1 -ast-stats-1 - Ident 360 ( 5.5%) 5 -ast-stats-1 Expr 576 ( 8.9%) 8 72 +ast-stats-1 - Ident 360 ( 5.4%) 5 +ast-stats-1 Expr 576 ( 8.7%) 8 72 ast-stats-1 - Path 72 ( 1.1%) 1 ast-stats-1 - Match 72 ( 1.1%) 1 ast-stats-1 - Struct 72 ( 1.1%) 1 ast-stats-1 - Lit 144 ( 2.2%) 2 ast-stats-1 - Block 216 ( 3.3%) 3 -ast-stats-1 PathSegment 720 (11.1%) 30 24 -ast-stats-1 Ty 896 (13.8%) 14 64 +ast-stats-1 PathSegment 720 (10.9%) 30 24 +ast-stats-1 Ty 896 (13.5%) 14 64 ast-stats-1 - Ptr 64 ( 1.0%) 1 ast-stats-1 - Ref 64 ( 1.0%) 1 -ast-stats-1 - ImplicitSelf 128 ( 2.0%) 2 -ast-stats-1 - Path 640 ( 9.9%) 10 -ast-stats-1 Item 1_224 (18.9%) 9 136 -ast-stats-1 - Trait 136 ( 2.1%) 1 -ast-stats-1 - Enum 136 ( 2.1%) 1 -ast-stats-1 - ForeignMod 136 ( 2.1%) 1 -ast-stats-1 - Impl 136 ( 2.1%) 1 -ast-stats-1 - Fn 272 ( 4.2%) 2 -ast-stats-1 - Use 408 ( 6.3%) 3 +ast-stats-1 - ImplicitSelf 128 ( 1.9%) 2 +ast-stats-1 - Path 640 ( 9.7%) 10 +ast-stats-1 Item 1_368 (20.6%) 9 152 +ast-stats-1 - Trait 152 ( 2.3%) 1 +ast-stats-1 - Enum 152 ( 2.3%) 1 +ast-stats-1 - ForeignMod 152 ( 2.3%) 1 +ast-stats-1 - Impl 152 ( 2.3%) 1 +ast-stats-1 - Fn 304 ( 4.6%) 2 +ast-stats-1 - Use 456 ( 6.9%) 3 ast-stats-1 ---------------------------------------------------------------- -ast-stats-1 Total 6_488 +ast-stats-1 Total 6_632 ast-stats-1 ast-stats-2 POST EXPANSION AST STATS ast-stats-2 Name Accumulated Size Count Item Size @@ -65,114 +65,114 @@ ast-stats-2 ExprField 48 ( 0.7%) 1 48 ast-stats-2 WherePredicate 56 ( 0.8%) 1 56 ast-stats-2 - BoundPredicate 56 ( 0.8%) 1 ast-stats-2 Local 72 ( 1.0%) 1 72 -ast-stats-2 Arm 96 ( 1.4%) 2 48 -ast-stats-2 ForeignItem 96 ( 1.4%) 1 96 -ast-stats-2 - Fn 96 ( 1.4%) 1 +ast-stats-2 Arm 96 ( 1.3%) 2 48 +ast-stats-2 ForeignItem 96 ( 1.3%) 1 96 +ast-stats-2 - Fn 96 ( 1.3%) 1 ast-stats-2 InlineAsm 120 ( 1.7%) 1 120 ast-stats-2 FnDecl 120 ( 1.7%) 5 24 ast-stats-2 Attribute 128 ( 1.8%) 4 32 -ast-stats-2 - DocComment 32 ( 0.5%) 1 -ast-stats-2 - Normal 96 ( 1.4%) 3 -ast-stats-2 FieldDef 160 ( 2.3%) 2 80 -ast-stats-2 Stmt 160 ( 2.3%) 5 32 -ast-stats-2 - Local 32 ( 0.5%) 1 -ast-stats-2 - Semi 32 ( 0.5%) 1 -ast-stats-2 - Expr 96 ( 1.4%) 3 -ast-stats-2 Param 160 ( 2.3%) 4 40 -ast-stats-2 Block 192 ( 2.7%) 6 32 +ast-stats-2 - DocComment 32 ( 0.4%) 1 +ast-stats-2 - Normal 96 ( 1.3%) 3 +ast-stats-2 FieldDef 160 ( 2.2%) 2 80 +ast-stats-2 Stmt 160 ( 2.2%) 5 32 +ast-stats-2 - Local 32 ( 0.4%) 1 +ast-stats-2 - Semi 32 ( 0.4%) 1 +ast-stats-2 - Expr 96 ( 1.3%) 3 +ast-stats-2 Param 160 ( 2.2%) 4 40 +ast-stats-2 Block 192 ( 2.6%) 6 32 ast-stats-2 Variant 208 ( 2.9%) 2 104 -ast-stats-2 GenericBound 224 ( 3.2%) 4 56 -ast-stats-2 - Trait 224 ( 3.2%) 4 -ast-stats-2 AssocItem 352 ( 5.0%) 4 88 -ast-stats-2 - Type 176 ( 2.5%) 2 -ast-stats-2 - Fn 176 ( 2.5%) 2 -ast-stats-2 GenericParam 480 ( 6.8%) 5 96 -ast-stats-2 Pat 504 ( 7.1%) 7 72 +ast-stats-2 GenericBound 224 ( 3.1%) 4 56 +ast-stats-2 - Trait 224 ( 3.1%) 4 +ast-stats-2 AssocItem 352 ( 4.8%) 4 88 +ast-stats-2 - Type 176 ( 2.4%) 2 +ast-stats-2 - Fn 176 ( 2.4%) 2 +ast-stats-2 GenericParam 480 ( 6.6%) 5 96 +ast-stats-2 Pat 504 ( 6.9%) 7 72 ast-stats-2 - Struct 72 ( 1.0%) 1 ast-stats-2 - Wild 72 ( 1.0%) 1 -ast-stats-2 - Ident 360 ( 5.1%) 5 -ast-stats-2 Expr 648 ( 9.1%) 9 72 +ast-stats-2 - Ident 360 ( 5.0%) 5 +ast-stats-2 Expr 648 ( 8.9%) 9 72 ast-stats-2 - Path 72 ( 1.0%) 1 ast-stats-2 - Match 72 ( 1.0%) 1 ast-stats-2 - Struct 72 ( 1.0%) 1 ast-stats-2 - InlineAsm 72 ( 1.0%) 1 ast-stats-2 - Lit 144 ( 2.0%) 2 ast-stats-2 - Block 216 ( 3.0%) 3 -ast-stats-2 PathSegment 792 (11.2%) 33 24 -ast-stats-2 Ty 896 (12.6%) 14 64 +ast-stats-2 PathSegment 792 (10.9%) 33 24 +ast-stats-2 Ty 896 (12.3%) 14 64 ast-stats-2 - Ptr 64 ( 0.9%) 1 ast-stats-2 - Ref 64 ( 0.9%) 1 ast-stats-2 - ImplicitSelf 128 ( 1.8%) 2 -ast-stats-2 - Path 640 ( 9.0%) 10 -ast-stats-2 Item 1_496 (21.1%) 11 136 -ast-stats-2 - Trait 136 ( 1.9%) 1 -ast-stats-2 - Enum 136 ( 1.9%) 1 -ast-stats-2 - ExternCrate 136 ( 1.9%) 1 -ast-stats-2 - ForeignMod 136 ( 1.9%) 1 -ast-stats-2 - Impl 136 ( 1.9%) 1 -ast-stats-2 - Fn 272 ( 3.8%) 2 -ast-stats-2 - Use 544 ( 7.7%) 4 +ast-stats-2 - Path 640 ( 8.8%) 10 +ast-stats-2 Item 1_672 (23.0%) 11 152 +ast-stats-2 - Trait 152 ( 2.1%) 1 +ast-stats-2 - Enum 152 ( 2.1%) 1 +ast-stats-2 - ExternCrate 152 ( 2.1%) 1 +ast-stats-2 - ForeignMod 152 ( 2.1%) 1 +ast-stats-2 - Impl 152 ( 2.1%) 1 +ast-stats-2 - Fn 304 ( 4.2%) 2 +ast-stats-2 - Use 608 ( 8.4%) 4 ast-stats-2 ---------------------------------------------------------------- -ast-stats-2 Total 7_088 +ast-stats-2 Total 7_264 ast-stats-2 hir-stats HIR STATS hir-stats Name Accumulated Size Count Item Size hir-stats ---------------------------------------------------------------- hir-stats ForeignItemRef 24 ( 0.3%) 1 24 hir-stats Lifetime 24 ( 0.3%) 1 24 -hir-stats Mod 32 ( 0.4%) 1 32 +hir-stats Mod 32 ( 0.3%) 1 32 hir-stats ExprField 40 ( 0.4%) 1 40 hir-stats TraitItemRef 56 ( 0.6%) 2 28 hir-stats Local 64 ( 0.7%) 1 64 hir-stats Param 64 ( 0.7%) 2 32 hir-stats InlineAsm 72 ( 0.8%) 1 72 hir-stats ImplItemRef 72 ( 0.8%) 2 36 -hir-stats Body 96 ( 1.1%) 3 32 -hir-stats FieldDef 96 ( 1.1%) 2 48 -hir-stats Arm 96 ( 1.1%) 2 48 -hir-stats Stmt 96 ( 1.1%) 3 32 -hir-stats - Local 32 ( 0.4%) 1 -hir-stats - Semi 32 ( 0.4%) 1 -hir-stats - Expr 32 ( 0.4%) 1 +hir-stats Body 96 ( 1.0%) 3 32 +hir-stats FieldDef 96 ( 1.0%) 2 48 +hir-stats Arm 96 ( 1.0%) 2 48 +hir-stats Stmt 96 ( 1.0%) 3 32 +hir-stats - Local 32 ( 0.3%) 1 +hir-stats - Semi 32 ( 0.3%) 1 +hir-stats - Expr 32 ( 0.3%) 1 hir-stats FnDecl 120 ( 1.3%) 3 40 hir-stats Attribute 128 ( 1.4%) 4 32 hir-stats GenericArg 128 ( 1.4%) 4 32 -hir-stats - Type 32 ( 0.4%) 1 -hir-stats - Lifetime 96 ( 1.1%) 3 +hir-stats - Type 32 ( 0.3%) 1 +hir-stats - Lifetime 96 ( 1.0%) 3 hir-stats GenericArgs 144 ( 1.6%) 3 48 hir-stats Variant 176 ( 1.9%) 2 88 hir-stats GenericBound 192 ( 2.1%) 4 48 hir-stats - Trait 192 ( 2.1%) 4 hir-stats WherePredicate 192 ( 2.1%) 3 64 hir-stats - BoundPredicate 192 ( 2.1%) 3 -hir-stats Block 288 ( 3.2%) 6 48 -hir-stats Pat 360 ( 4.0%) 5 72 +hir-stats Block 288 ( 3.1%) 6 48 +hir-stats Pat 360 ( 3.9%) 5 72 hir-stats - Wild 72 ( 0.8%) 1 hir-stats - Struct 72 ( 0.8%) 1 -hir-stats - Binding 216 ( 2.4%) 3 -hir-stats GenericParam 400 ( 4.4%) 5 80 -hir-stats Generics 560 ( 6.2%) 10 56 -hir-stats Ty 720 ( 8.0%) 15 48 +hir-stats - Binding 216 ( 2.3%) 3 +hir-stats GenericParam 400 ( 4.3%) 5 80 +hir-stats Ty 720 ( 7.8%) 15 48 hir-stats - Ptr 48 ( 0.5%) 1 hir-stats - Ref 48 ( 0.5%) 1 -hir-stats - Path 624 ( 6.9%) 13 -hir-stats Expr 768 ( 8.5%) 12 64 +hir-stats - Path 624 ( 6.8%) 13 +hir-stats Generics 720 ( 7.8%) 10 72 +hir-stats Expr 768 ( 8.3%) 12 64 hir-stats - Path 64 ( 0.7%) 1 hir-stats - Struct 64 ( 0.7%) 1 hir-stats - Match 64 ( 0.7%) 1 hir-stats - InlineAsm 64 ( 0.7%) 1 hir-stats - Lit 128 ( 1.4%) 2 hir-stats - Block 384 ( 4.2%) 6 -hir-stats Item 880 ( 9.7%) 11 80 +hir-stats Item 880 ( 9.6%) 11 80 hir-stats - Trait 80 ( 0.9%) 1 hir-stats - Enum 80 ( 0.9%) 1 hir-stats - ExternCrate 80 ( 0.9%) 1 hir-stats - ForeignMod 80 ( 0.9%) 1 hir-stats - Impl 80 ( 0.9%) 1 -hir-stats - Fn 160 ( 1.8%) 2 +hir-stats - Fn 160 ( 1.7%) 2 hir-stats - Use 320 ( 3.5%) 4 -hir-stats Path 1_240 (13.7%) 31 40 -hir-stats PathSegment 1_920 (21.2%) 40 48 +hir-stats Path 1_240 (13.5%) 31 40 +hir-stats PathSegment 1_920 (20.9%) 40 48 hir-stats ---------------------------------------------------------------- -hir-stats Total 9_048 +hir-stats Total 9_208 hir-stats diff --git a/tests/ui/traits/alias/issue-83613.rs b/tests/ui/traits/alias/issue-83613.rs index 2462e703a7165..3c86a7b805ebc 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 a78294da6c140..89095ef5b978f 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` for type `OpaqueType` - --> $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/pointee-tail-is-generic-errors.rs b/tests/ui/traits/pointee-tail-is-generic-errors.rs index 28bc1da964dbc..3e4f944cee20a 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 e0da0fc38613d..3f0e40d150281 100644 --- a/tests/ui/traits/pointee-tail-is-generic.rs +++ b/tests/ui/traits/pointee-tail-is-generic.rs @@ -6,6 +6,7 @@ type Opaque = impl std::future::Future; +#[defines(Opaque)] fn opaque() -> Opaque { async {} } diff --git a/tests/ui/type-alias-impl-trait/almost_in_scope.rs b/tests/ui/type-alias-impl-trait/almost_in_scope.rs new file mode 100644 index 0000000000000..c45949dc00ff5 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/almost_in_scope.rs @@ -0,0 +1,18 @@ +#![feature(type_alias_impl_trait)] + +type Foo = impl std::fmt::Debug; + +trait Blah { + type Output; + fn method(); +} + +impl Blah for u32 { + type Output = Foo; + fn method() { + let x: Foo = 22_u32; + //~^ ERROR: mismatched types + } +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/almost_in_scope.stderr b/tests/ui/type-alias-impl-trait/almost_in_scope.stderr new file mode 100644 index 0000000000000..0354de3c2fd40 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/almost_in_scope.stderr @@ -0,0 +1,22 @@ +error[E0308]: mismatched types + --> $DIR/almost_in_scope.rs:13:22 + | +LL | type Foo = impl std::fmt::Debug; + | -------------------- the expected opaque type +... +LL | let x: Foo = 22_u32; + | --- ^^^^^^ expected opaque type, found `u32` + | | + | expected due to this + | + = note: expected opaque type `Foo` + found type `u32` +note: this item cannot register hidden type without a `#[defines(Foo)]` attribute + --> $DIR/almost_in_scope.rs:12:5 + | +LL | fn method() { + | ^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/argument-types.rs b/tests/ui/type-alias-impl-trait/argument-types.rs index 185207b9800bb..6461b90896658 100644 --- a/tests/ui/type-alias-impl-trait/argument-types.rs +++ b/tests/ui/type-alias-impl-trait/argument-types.rs @@ -5,22 +5,27 @@ use std::fmt::Debug; type Foo = impl Debug; +#[defines(Foo)] fn foo1(mut x: Foo) { x = 22_u32; } +#[defines(Foo)] fn foo2(mut x: Foo) { // no constraint on x } +#[defines(Foo)] fn foo3(x: Foo) { println!("{:?}", x); } +#[defines(Foo)] fn foo_value() -> Foo { 11_u32 } +#[defines(Foo)] fn main() { foo3(foo_value()); } 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 703e3e8693e8e..381da2e1a0d79 100644 --- a/tests/ui/type-alias-impl-trait/assoc-projection-ice.rs +++ b/tests/ui/type-alias-impl-trait/assoc-projection-ice.rs @@ -11,6 +11,7 @@ impl<'a> T for &'a S { type Item = &'a (); } +#[defines(Alias<'a>)] fn filter_positive<'a>() -> Alias<'a> { &S } 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 42f07d49ffe25..0faf42c4ea8eb 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/associated-type-impl-trait-lifetime.rs b/tests/ui/type-alias-impl-trait/associated-type-impl-trait-lifetime.rs index 962606508be7a..09b67b18449b7 100644 --- a/tests/ui/type-alias-impl-trait/associated-type-impl-trait-lifetime.rs +++ b/tests/ui/type-alias-impl-trait/associated-type-impl-trait-lifetime.rs @@ -5,15 +5,14 @@ trait Trait { type Opaque1; type Opaque2; - fn constrain(self); + fn constrain(self) -> (Self::Opaque1, Self::Opaque2); } impl<'a> Trait for &'a () { type Opaque1 = impl Sized; type Opaque2 = impl Sized + 'a; - fn constrain(self) { - let _: Self::Opaque1 = (); - let _: Self::Opaque2 = self; + fn constrain(self) -> (Self::Opaque1, Self::Opaque2) { + ((), self) } } 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 a1584581e6c45..79fd4280d16c8 100644 --- a/tests/ui/type-alias-impl-trait/auto-trait-leakage.rs +++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage.rs @@ -6,6 +6,7 @@ mod m { type Foo = impl std::fmt::Debug; + #[defines(Foo)] pub fn foo() -> Foo { 22_u32 } 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..4d07605e0786c 100644 --- a/tests/ui/type-alias-impl-trait/auto-trait-leakage2.rs +++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage2.rs @@ -8,6 +8,7 @@ mod m { //~^ within this `Foo` //~| expansion of desugaring + #[defines(Foo)] pub fn foo() -> Foo { Rc::new(22_u32) } 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 d7247302dd1e0..5afdaa98599ec 100644 --- a/tests/ui/type-alias-impl-trait/auto-trait-leakage2.stderr +++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage2.stderr @@ -1,5 +1,5 @@ error[E0277]: `Rc` cannot be sent between threads safely - --> $DIR/auto-trait-leakage2.rs:21:13 + --> $DIR/auto-trait-leakage2.rs:22:13 | LL | type Foo = impl std::fmt::Debug; | -------------------- within this `Foo` @@ -16,7 +16,7 @@ note: required because it appears within the type `Foo` 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:17: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 5fb7a9473d3df..469ab863c2726 100644 --- a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.rs +++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.rs @@ -7,6 +7,7 @@ mod m { type Foo = impl std::fmt::Debug; //~^ ERROR: cycle detected when computing type of `m::Foo::{opaque#0}` [E0391] + #[defines(Foo)] pub fn foo() -> Foo { 22_u32 } 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 1e9a45aac79e9..24be9cd86ad9e 100644 --- a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr +++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr @@ -5,7 +5,7 @@ LL | type Foo = impl std::fmt::Debug; | ^^^^^^^^^^^^^^^^^^^^ | note: ...which requires type-checking `m::bar`... - --> $DIR/auto-trait-leakage3.rs:15:9 + --> $DIR/auto-trait-leakage3.rs:16:9 | LL | is_send(foo()); | ^^^^^^^ 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/bound_reduction.rs b/tests/ui/type-alias-impl-trait/bound_reduction.rs index b9b50f0b77aa3..8dc61e773b9d6 100644 --- a/tests/ui/type-alias-impl-trait/bound_reduction.rs +++ b/tests/ui/type-alias-impl-trait/bound_reduction.rs @@ -3,17 +3,23 @@ #![allow(warnings)] #![feature(type_alias_impl_trait)] -fn main() { -} +fn main() {} type Foo = impl std::fmt::Debug; trait Trait {} -fn foo_desugared>(_: T) -> Foo { +#[defines(Foo)] +fn foo_desugared< + T: Trait< + [u32; { + #[no_mangle] + static FOO: usize = 42; + 3 + }], + >, +>( + _: T, +) -> Foo { (42, std::marker::PhantomData::) } diff --git a/tests/ui/type-alias-impl-trait/bound_reduction2.rs b/tests/ui/type-alias-impl-trait/bound_reduction2.rs index 0bcc9e002ca04..5d6f0535d5c10 100644 --- a/tests/ui/type-alias-impl-trait/bound_reduction2.rs +++ b/tests/ui/type-alias-impl-trait/bound_reduction2.rs @@ -12,6 +12,7 @@ trait Trait {} impl Trait for () {} +#[defines(Foo)] fn foo_desugared(_: T) -> Foo { () //~^ 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 3c259bd9e97cc..4f3a8bdab0f1a 100644 --- a/tests/ui/type-alias-impl-trait/bound_reduction2.stderr +++ b/tests/ui/type-alias-impl-trait/bound_reduction2.stderr @@ -1,5 +1,5 @@ error[E0792]: expected generic type parameter, found `::Assoc` - --> $DIR/bound_reduction2.rs:16:5 + --> $DIR/bound_reduction2.rs:17:5 | LL | type Foo = impl Trait; | - this generic parameter must be used with a generic type parameter 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 55b4dc8dc232b..6d7f6e680741f 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 @@ -5,6 +5,7 @@ type X = impl Clone; +#[defines(X)] fn f(t: T) -> X { t //~^ ERROR the trait bound `T: Clone` is not satisfied 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 8678e9b33b5ea..b5b9993755ea3 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,5 +1,5 @@ error[E0277]: the trait bound `T: Clone` is not satisfied - --> $DIR/bounds-are-checked-2.rs:9:5 + --> $DIR/bounds-are-checked-2.rs:10:5 | LL | t | ^ the trait `Clone` is not implemented for `T` 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..43abe52cf104e 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<'a>)] 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 962dedde09a52..66f7a041f471b 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/closure_args.rs b/tests/ui/type-alias-impl-trait/closure_args.rs index c5e7af81d3dd0..de3e1cfacf7c8 100644 --- a/tests/ui/type-alias-impl-trait/closure_args.rs +++ b/tests/ui/type-alias-impl-trait/closure_args.rs @@ -11,6 +11,16 @@ fn run ()>(f: F, i: Input) { f(i); } +#[defines(Input)] +fn foo() { + run( + |x: u32| { + println!("{x}"); + }, + 0, + ); +} + fn main() { - run(|x: u32| {println!("{x}");}, 0); + foo(); } diff --git a/tests/ui/type-alias-impl-trait/closure_args2.rs b/tests/ui/type-alias-impl-trait/closure_args2.rs index 82386c280a8e3..fa99bc77ac4df 100644 --- a/tests/ui/type-alias-impl-trait/closure_args2.rs +++ b/tests/ui/type-alias-impl-trait/closure_args2.rs @@ -4,7 +4,9 @@ trait Foo { // This was reachable in https://github.com/rust-lang/rust/issues/100800 - fn foo(&self) { unreachable!() } + fn foo(&self) { + unreachable!() + } } impl Foo for T {} @@ -14,10 +16,19 @@ impl B { } type Input = impl Foo; -fn run1(f: F, i: Input) {f(i)} -fn run2(f: F, i: B) {f(i)} +fn run1(f: F, i: Input) { + f(i) +} +fn run2(f: F, i: B) { + f(i) +} + +#[defines(Input)] +fn foo() { + run1(|x: B| x.foo(), B); + run2(|x: B| x.foo(), B); +} fn main() { - run1(|x: B| {x.foo()}, B); - run2(|x: B| {x.foo()}, B); + foo(); } 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 475f4724ff28f..c87b3f0d60b1c 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['_#0r] type Opaque = impl Sized; + #[defines(Opaque)] fn define<'a: 'a>() -> Opaque { || {} } @@ -31,6 +32,7 @@ mod test2 { &'a (): Trait, = impl Sized + 'a; + #[defines(Opaque<'a>)] 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<'a, 'b>)] 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 53974dbb36bdf..5ae9c5c75a5a8 100644 --- a/tests/ui/type-alias-impl-trait/closure_wf_outlives.rs +++ b/tests/ui/type-alias-impl-trait/closure_wf_outlives.rs @@ -14,6 +14,7 @@ mod test1 { type Opaque<'a, 'b> = impl Sized + 'a + 'b; //~^ ERROR lifetime bound not satisfied + #[defines(Opaque<'a, 'b>)] fn define<'a, 'b>() -> Opaque<'a, 'b> where 'a: 'b, @@ -27,6 +28,7 @@ mod test2 { type Opaque<'a, 'b> = impl Sized + 'a + 'b; //~^ ERROR cannot infer an appropriate lifetime + #[defines(Opaque<'a, 'b>)] 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<'a, 'b>)] fn define<'a, 'b, 'x>() -> Opaque<'a, 'b> where 'a: 'x, @@ -54,6 +57,7 @@ mod test3 { type Opaque = impl Sized; //~^ ERROR the parameter type `T` may not live long enough + #[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 ae6462bb62ce5..ba1bf5fa654a4 100644 --- a/tests/ui/type-alias-impl-trait/closure_wf_outlives.stderr +++ b/tests/ui/type-alias-impl-trait/closure_wf_outlives.stderr @@ -16,40 +16,40 @@ 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:27:27 + --> $DIR/closure_wf_outlives.rs:28:27 | 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:27:27 + --> $DIR/closure_wf_outlives.rs:28:27 | 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:27:27 + --> $DIR/closure_wf_outlives.rs:28:27 | 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:54:22 + --> $DIR/closure_wf_outlives.rs:57:22 | LL | type Opaque = impl Sized; | ^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds... | note: ...that is required by this bound - --> $DIR/closure_wf_outlives.rs:59:12 + --> $DIR/closure_wf_outlives.rs:63: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_generalization.rs b/tests/ui/type-alias-impl-trait/coherence_generalization.rs index 5c9ad9498b6de..ed20f4256bbe1 100644 --- a/tests/ui/type-alias-impl-trait/coherence_generalization.rs +++ b/tests/ui/type-alias-impl-trait/coherence_generalization.rs @@ -3,6 +3,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/declared_but_not_defined_in_scope.stderr b/tests/ui/type-alias-impl-trait/declared_but_not_defined_in_scope.stderr index fbfa0ccf1e8d9..8a9d4abf6c707 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 @@ -19,6 +19,11 @@ LL | "" | = note: expected opaque type `Boo` found reference `&'static str` +note: this item cannot register hidden type without a `#[defines(Boo)]` attribute + --> $DIR/declared_but_not_defined_in_scope.rs:10:1 + | +LL | fn bomp() -> boo::Boo { + | ^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/type-alias-impl-trait/defining-scope-self.rs b/tests/ui/type-alias-impl-trait/defining-scope-self.rs new file mode 100644 index 0000000000000..16117eec19c5a --- /dev/null +++ b/tests/ui/type-alias-impl-trait/defining-scope-self.rs @@ -0,0 +1,19 @@ +#![feature(type_alias_impl_trait)] + +// edition: 2021 +// check-pass + +type MyIter = impl Iterator; + +struct Foo { + iter: MyIter, +} + +impl Foo { + #[defines(MyIter)] + fn set_iter(&mut self) { + self.iter = [1, 2, 3].into_iter(); + } +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/defining-scopes-in_type.rs b/tests/ui/type-alias-impl-trait/defining-scopes-in_type.rs new file mode 100644 index 0000000000000..5ac29bc59dd9a --- /dev/null +++ b/tests/ui/type-alias-impl-trait/defining-scopes-in_type.rs @@ -0,0 +1,17 @@ +#![feature(type_alias_impl_trait)] + +// check that we don't allow defining hidden types of TAITs in +// const generic defaults. +type Foo = impl Send; +//~^ ERROR unconstrained opaque type + +#[rustfmt::skip] +#[defines(Foo)] +struct Struct< + const C: usize = { + let _: Foo = (); + 0 + }, +>; + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/defining-scopes-in_type.stderr b/tests/ui/type-alias-impl-trait/defining-scopes-in_type.stderr new file mode 100644 index 0000000000000..6497af1f187e8 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/defining-scopes-in_type.stderr @@ -0,0 +1,10 @@ +error: unconstrained opaque type + --> $DIR/defining-scopes-in_type.rs:5:12 + | +LL | type Foo = impl Send; + | ^^^^^^^^^ + | + = note: `Foo` must be used in combination with a concrete type within the same module + +error: aborting due to previous error + diff --git a/tests/ui/type-alias-impl-trait/defining-scopes-semantic.rs b/tests/ui/type-alias-impl-trait/defining-scopes-semantic.rs new file mode 100644 index 0000000000000..f05473c3a1c36 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/defining-scopes-semantic.rs @@ -0,0 +1,15 @@ +#![feature(type_alias_impl_trait)] + +// check-pass + +type Foo = impl std::fmt::Debug; + +struct Wrap(Foo); + +// Check that fields work +#[defines(Foo)] +fn h() -> Wrap { + Wrap(42) +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/defining-scopes-syntactic.rs b/tests/ui/type-alias-impl-trait/defining-scopes-syntactic.rs new file mode 100644 index 0000000000000..7356ad76cf156 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/defining-scopes-syntactic.rs @@ -0,0 +1,19 @@ +#![feature(type_alias_impl_trait)] + +// Check that we cannot syntactically mention a TAIT without +// it also being part of the type. + +type DropType = (); +//~^ ERROR type parameter `T` is unused + +type Foo = impl std::fmt::Debug; + +// Check that, even though `Foo` is not part +// of the return type, we do allow this to be a defining scope +#[defines(Foo)] +fn g() -> DropType { + let _: Foo = 42; + () +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/defining-scopes-syntactic.stderr b/tests/ui/type-alias-impl-trait/defining-scopes-syntactic.stderr new file mode 100644 index 0000000000000..c266d619520b6 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/defining-scopes-syntactic.stderr @@ -0,0 +1,9 @@ +error[E0091]: type parameter `T` is unused + --> $DIR/defining-scopes-syntactic.rs:6:15 + | +LL | type DropType = (); + | ^ unused type parameter + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0091`. diff --git a/tests/ui/type-alias-impl-trait/defining-scopes-syntacticish.rs b/tests/ui/type-alias-impl-trait/defining-scopes-syntacticish.rs new file mode 100644 index 0000000000000..bbd400096538a --- /dev/null +++ b/tests/ui/type-alias-impl-trait/defining-scopes-syntacticish.rs @@ -0,0 +1,19 @@ +#![feature(type_alias_impl_trait)] + +// check-pass + +// Check that we cannot syntactically mention a TAIT without +// it also being part of the type. + +struct DropType(std::marker::PhantomData); + +type Foo = impl std::fmt::Debug; +// Check that, even though `Foo` is not part +// of the actual type, we do allow this to be a defining scope +#[defines(Foo)] +fn g() -> DropType { + let _: Foo = 42; + DropType(std::marker::PhantomData) +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/defining-use-item-child.rs b/tests/ui/type-alias-impl-trait/defining-use-item-child.rs new file mode 100644 index 0000000000000..9656d4a149099 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/defining-use-item-child.rs @@ -0,0 +1,33 @@ +#![feature(type_alias_impl_trait)] + +fn main() {} + +type Foo = impl std::fmt::Display; + +#[defines(Foo)] +fn bar() { + pub fn foo() -> Foo { + "foo" + //~^ ERROR: mismatched types + } +} + +#[defines(Foo)] +fn baz() -> Foo { + pub fn foo() -> Foo { + "foo" + //~^ ERROR: mismatched types + } + "baz" +} + +#[defines(Foo)] +struct Bak { + x: [u8; { + fn blob() -> Foo { + "blob" + //~^ ERROR: mismatched types + } + 5 + }], +} diff --git a/tests/ui/type-alias-impl-trait/defining-use-item-child.stderr b/tests/ui/type-alias-impl-trait/defining-use-item-child.stderr new file mode 100644 index 0000000000000..ae893f1d51420 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/defining-use-item-child.stderr @@ -0,0 +1,60 @@ +error[E0308]: mismatched types + --> $DIR/defining-use-item-child.rs:10:9 + | +LL | type Foo = impl std::fmt::Display; + | ---------------------- the expected opaque type +... +LL | pub fn foo() -> Foo { + | --- expected `Foo` because of return type +LL | "foo" + | ^^^^^ expected opaque type, found `&str` + | + = note: expected opaque type `Foo` + found reference `&'static str` +note: this item cannot register hidden type without a `#[defines(Foo)]` attribute + --> $DIR/defining-use-item-child.rs:9:5 + | +LL | pub fn foo() -> Foo { + | ^^^^^^^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/defining-use-item-child.rs:18:9 + | +LL | type Foo = impl std::fmt::Display; + | ---------------------- the expected opaque type +... +LL | pub fn foo() -> Foo { + | --- expected `Foo` because of return type +LL | "foo" + | ^^^^^ expected opaque type, found `&str` + | + = note: expected opaque type `Foo` + found reference `&'static str` +note: this item cannot register hidden type without a `#[defines(Foo)]` attribute + --> $DIR/defining-use-item-child.rs:17:5 + | +LL | pub fn foo() -> Foo { + | ^^^^^^^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/defining-use-item-child.rs:28:13 + | +LL | type Foo = impl std::fmt::Display; + | ---------------------- the expected opaque type +... +LL | fn blob() -> Foo { + | --- expected `Foo` because of return type +LL | "blob" + | ^^^^^^ expected opaque type, found `&str` + | + = note: expected opaque type `Foo` + found reference `&'static str` +note: this item cannot register hidden type without a `#[defines(Foo)]` attribute + --> $DIR/defining-use-item-child.rs:27:9 + | +LL | fn blob() -> Foo { + | ^^^^^^^^^^^^^^^^ + +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/defining-use-item-child2.rs b/tests/ui/type-alias-impl-trait/defining-use-item-child2.rs new file mode 100644 index 0000000000000..b73bffd553930 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/defining-use-item-child2.rs @@ -0,0 +1,35 @@ +#![feature(type_alias_impl_trait)] + +// check-pass + +// FIXME(type_alias_impl_trait): only `baz` and its nested `foo` should compile. + +fn main() {} + +type Foo = impl std::fmt::Display; + +fn bar() { + #[defines(Foo)] + pub fn foo() -> Foo { + "foo" + } +} + +#[defines(Foo)] +fn baz() -> Foo { + #[defines(Foo)] + pub fn foo() -> Foo { + "foo" + } + "baz" +} + +struct Bak { + x: [u8; { + #[defines(Foo)] + fn blob() -> Foo { + "blob" + } + 5 + }], +} 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 8b51f55715e91..360a76d1ddd91 100644 --- a/tests/ui/type-alias-impl-trait/defining-use-submodule.rs +++ b/tests/ui/type-alias-impl-trait/defining-use-submodule.rs @@ -11,11 +11,13 @@ type Foo = impl std::fmt::Display; type Bar = impl std::fmt::Display; mod foo { + #[defines(super::Foo)] pub fn foo() -> super::Foo { "foo" } pub mod bar { + #[defines(crate::Bar)] pub fn bar() -> crate::Bar { 1 } 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 a8b4cd7afe8a9..5f7e54df9507e 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.rs b/tests/ui/type-alias-impl-trait/different_defining_uses_never_type.rs index 0b8157fe33dd7..cb47b5925bc3a 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,18 @@ fn main() {} // two definitions with different types type Foo = impl std::fmt::Debug; +#[defines(Foo)] fn foo() -> Foo { "" } -fn bar() -> Foo { //~ ERROR: concrete type differs from previous defining opaque type use +#[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 09dadb0afcef5..35acc6a757023 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 8549687ea7814..5ff58a97df9be 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 @@ -1,44 +1,33 @@ -// build-pass (FIXME(62277): could be check-pass?) +// check-pass #![feature(type_alias_impl_trait)] fn main() {} -// two definitions with different types +// all defininions have the same type type Foo = impl std::fmt::Debug; +#[defines(Foo)] fn foo() -> Foo { "" } +#[defines(Foo)] fn bar(arg: bool) -> Foo { - if arg { - panic!() - } else { - "bar" - } + if arg { panic!() } else { "bar" } } +#[defines(Foo)] fn boo(arg: bool) -> Foo { - if arg { - loop {} - } else { - "boo" - } + if arg { loop {} } else { "boo" } } +#[defines(Foo)] fn bar2(arg: bool) -> Foo { - if arg { - "bar2" - } else { - panic!() - } + if arg { "bar2" } else { panic!() } } +#[defines(Foo)] fn boo2(arg: bool) -> Foo { - if arg { - "boo2" - } else { - loop {} - } + if arg { "boo2" } else { loop {} } } 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..68cdd1e63e02d 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,10 +3,16 @@ type Tait = impl Sized; struct One; -fn one() -> Tait { One } +#[defines(Tait)] +fn one() -> Tait { + One +} struct Two(T); -fn two() -> Tait { Two::<()>(todo!()) } -//~^ ERROR concrete type differs from previous defining opaque type use +#[defines(Tait)] +fn two() -> Tait { + //~^ ERROR concrete type differs from previous defining opaque type use + Two::<()>(todo!()) +} fn main() {} 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 146a57cbb7e05..04fd138f9b198 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,14 +1,14 @@ 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:13:13 | -LL | fn two() -> Tait { Two::<()>(todo!()) } +LL | fn two() -> Tait { | ^^^^ expected `One`, got `Two<()>` | note: previous use here - --> $DIR/different_defining_uses_never_type3.rs:6:20 + --> $DIR/different_defining_uses_never_type3.rs:8:5 | -LL | fn one() -> Tait { One } - | ^^^ +LL | One + | ^^^ error: aborting due to previous error 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 5f75fdc716efd..8a84315a6fa33 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 @@ -7,10 +7,12 @@ impl<'a, T: ?Sized> Captures<'a> for T {} type OneLifetime<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +#[defines(OneLifetime<'a, 'b>)] fn foo<'a, 'b>(a: &'a u32, b: &'b u32) -> OneLifetime<'a, 'b> { a } +#[defines(OneLifetime<'a, 'b>)] 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 546598e8a5c99..2eb6510d4738c 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:15:5 + --> $DIR/different_lifetimes_defining_uses.rs:17:5 | LL | b | ^ expected `&'a u32`, got `&'b u32` | note: previous use here - --> $DIR/different_lifetimes_defining_uses.rs:11:5 + --> $DIR/different_lifetimes_defining_uses.rs:12:5 | LL | a | ^ 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 e767bfdb08b6b..0c289ca565811 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 d99ed58127bd4..d481fd5c9b25d 100644 --- a/tests/ui/type-alias-impl-trait/field-types.rs +++ b/tests/ui/type-alias-impl-trait/field-types.rs @@ -11,6 +11,7 @@ struct Bar { foo: Foo, } +#[defines(Foo)] 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 56323216effa4..088e6856b89b9 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 7e76c120a2566..d321945861d96 100644 --- a/tests/ui/type-alias-impl-trait/future.stderr +++ b/tests/ui/type-alias-impl-trait/future.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `B: Bar` is not satisfied - --> $DIR/future.rs:15:5 + --> $DIR/future.rs:16:5 | LL | async move { bar.bar() } | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `B` | note: required by a bound in `foo` - --> $DIR/future.rs:14:11 + --> $DIR/future.rs:15:11 | LL | fn foo(bar: B) -> FooFuture { | ^^^ required by this bound in `foo` diff --git a/tests/ui/type-alias-impl-trait/generic_different_defining_uses.rs b/tests/ui/type-alias-impl-trait/generic_different_defining_uses.rs index 8b683ad282883..60a9948456f48 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 47ac3346259e9..e18fa0521e68c 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 9d938a61600f5..524320b7b1a93 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 @@ -8,6 +8,7 @@ impl<'a, T: ?Sized> Captures<'a> for T {} type Two<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +#[defines(Two<'a, 'a>)] fn one<'a>(t: &'a ()) -> Two<'a, 'a> { 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 72e1ef4b4923b..5f9218c7e0322 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,5 +1,5 @@ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_lifetime_param.rs:12:5 + --> $DIR/generic_duplicate_lifetime_param.rs:13:5 | LL | t | ^ 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 80462f8ac046c..51efc3eb17b2f 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 @@ -7,7 +7,6 @@ fn main() {} // test that unused generic parameters are ok type TwoTys = impl Debug; - pub trait Captures<'a> {} impl<'a, T: ?Sized> Captures<'a> for T {} @@ -16,17 +15,19 @@ type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>; type TwoConsts = impl Debug; - +#[defines(TwoTys)] fn one_ty(t: T) -> TwoTys { t //~^ ERROR non-defining opaque type use in defining scope } +#[defines(TwoLifetimes<'a, 'a>)] fn one_lifetime<'a>(t: &'a u32) -> TwoLifetimes<'a, 'a> { t //~^ ERROR non-defining opaque type use in defining scope } +#[defines(TwoConsts)] fn one_const(t: *mut [u8; N]) -> TwoConsts { 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 98e4bfea10d63..fb012d7913b93 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,5 +1,5 @@ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:21:5 + --> $DIR/generic_duplicate_param_use.rs:20:5 | LL | t | ^ @@ -17,19 +17,19 @@ LL | t | ^ | note: lifetime used multiple times - --> $DIR/generic_duplicate_param_use.rs:15:19 + --> $DIR/generic_duplicate_param_use.rs:14:19 | LL | type TwoLifetimes<'a, 'b> = impl Debug + Captures<'a> + Captures<'b>; | ^^ ^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:31:5 + --> $DIR/generic_duplicate_param_use.rs:32:5 | LL | t | ^ | note: constant used multiple times - --> $DIR/generic_duplicate_param_use.rs:17:16 + --> $DIR/generic_duplicate_param_use.rs:16:16 | LL | type TwoConsts = impl Debug; | ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ 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 c17d595dbb3ad..243a30c21160e 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..4d28bcaf73a55 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 3dbfff7453fd0..115604d46ec8d 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use2.stderr +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use2.stderr @@ -1,5 +1,5 @@ error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use2.rs:11:5 + --> $DIR/generic_duplicate_param_use2.rs:12:5 | LL | t | ^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` 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 e7a25fc724005..3b33f1babfae4 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,11 +7,13 @@ 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` } +#[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_use3.stderr b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use3.stderr index 7bec3822071f3..cd919f1ef9993 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,5 +1,5 @@ error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use3.rs:11:5 + --> $DIR/generic_duplicate_param_use3.rs:12:5 | LL | t | ^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` @@ -10,7 +10,7 @@ LL | type Two = impl Debug; | +++++++++++++++++ error[E0277]: `U` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use3.rs:16:5 + --> $DIR/generic_duplicate_param_use3.rs:18:5 | LL | u | ^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` 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..3219ebef67b0c 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 21a5369d9fff9..4a755729740e8 100644 --- a/tests/ui/type-alias-impl-trait/generic_duplicate_param_use4.stderr +++ b/tests/ui/type-alias-impl-trait/generic_duplicate_param_use4.stderr @@ -1,5 +1,5 @@ error[E0277]: `U` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use4.rs:11:5 + --> $DIR/generic_duplicate_param_use4.rs:12:5 | LL | u | ^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` 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 3bd1dda63314a..5791f1e646e5e 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,12 +7,14 @@ fn main() {} // test that unused generic parameters are ok type Two = impl Debug; +#[defines(Two)] fn two(t: T, u: U) -> Two { (t, u) //~^ ERROR `T` doesn't implement `Debug` //~| ERROR `U` doesn't implement `Debug` } +#[defines(Two)] fn three(t: T, u: U) -> Two { (u, t) //~^ ERROR `T` doesn't implement `Debug` 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 586ea82342a8f..b22ea86fd19e9 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,5 +1,5 @@ error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use5.rs:11:5 + --> $DIR/generic_duplicate_param_use5.rs:12:5 | LL | (t, u) | ^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` @@ -11,7 +11,7 @@ LL | type Two = impl Debug; | +++++++++++++++++ error[E0277]: `U` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use5.rs:11:5 + --> $DIR/generic_duplicate_param_use5.rs:12:5 | LL | (t, u) | ^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` @@ -23,7 +23,7 @@ LL | type Two = impl Debug; | +++++++++++++++++ error[E0277]: `U` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use5.rs:17:5 + --> $DIR/generic_duplicate_param_use5.rs:19:5 | LL | (u, t) | ^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` @@ -35,7 +35,7 @@ LL | type Two = impl Debug; | +++++++++++++++++ error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use5.rs:17:5 + --> $DIR/generic_duplicate_param_use5.rs:19:5 | LL | (u, t) | ^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` 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 5120925e5a4a5..5b285f1779304 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,11 +7,13 @@ fn main() {} // test that unused generic parameters are ok type Two = impl Debug; +#[defines(Two)] fn two(t: T, u: U) -> Two { (t, t) //~^ ERROR `T` doesn't implement `Debug` } +#[defines(Two)] fn three(t: T, u: U) -> Two { (u, t) //~^ ERROR `T` doesn't implement `Debug` 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 cb162d382b6b5..f3458bef73eff 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,5 +1,5 @@ error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use6.rs:11:5 + --> $DIR/generic_duplicate_param_use6.rs:12:5 | LL | (t, t) | ^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` @@ -11,7 +11,7 @@ LL | type Two = impl Debug; | +++++++++++++++++ error[E0277]: `U` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use6.rs:16:5 + --> $DIR/generic_duplicate_param_use6.rs:18:5 | LL | (u, t) | ^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` @@ -23,7 +23,7 @@ LL | type Two = impl Debug; | +++++++++++++++++ error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use6.rs:16:5 + --> $DIR/generic_duplicate_param_use6.rs:18:5 | LL | (u, t) | ^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` 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 feebf81eef2a7..e24da3cc67850 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 3a4b5047b41e2..cf2a7183f1cba 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,11 +6,13 @@ fn main() {} type Two = impl Debug; +#[defines(Two)] fn two(t: T, _: U) -> Two { (t, 4u32) //~^ ERROR `T` doesn't implement `Debug` } +#[defines(Two)] fn three(_: T, u: U) -> Two { (u, 4u32) //~^ ERROR `U` doesn't implement `Debug` 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 14cbfb3806f84..d8c23e281c15f 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,5 +1,5 @@ error[E0277]: `T` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use8.rs:10:5 + --> $DIR/generic_duplicate_param_use8.rs:11:5 | LL | (t, 4u32) | ^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` @@ -11,7 +11,7 @@ LL | type Two = impl Debug; | +++++++++++++++++ error[E0277]: `U` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use8.rs:15:5 + --> $DIR/generic_duplicate_param_use8.rs:17:5 | LL | (u, 4u32) | ^^^^^^^^^ `U` cannot be formatted using `{:?}` because it doesn't implement `Debug` 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 6afcdfe4d1c3d..f6f0b85810017 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,6 +11,7 @@ trait Foo { const BAR: Self::Bar; } +#[defines(Two)] fn two(t: T, u: U) -> Two { (t, u, T::BAR) //~^ ERROR the trait bound `A: Foo` is not satisfied @@ -18,6 +19,7 @@ fn two(t: T, u: U) -> Two { //~| ERROR `B` doesn't implement `Debug` } +#[defines(Two)] fn three(t: T, u: U) -> Two { (t, u, 42) //~^ ERROR `A` doesn't implement `Debug` 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 722693e42669c..aa1eca0e81d78 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,5 +1,5 @@ error[E0277]: the trait bound `A: Foo` is not satisfied - --> $DIR/generic_duplicate_param_use9.rs:15:5 + --> $DIR/generic_duplicate_param_use9.rs:16:5 | LL | (t, u, T::BAR) | ^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `A` @@ -10,7 +10,7 @@ LL | type Two = impl Debug; | +++++ error[E0277]: `A` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use9.rs:15:5 + --> $DIR/generic_duplicate_param_use9.rs:16:5 | LL | (t, u, T::BAR) | ^^^^^^^^^^^^^^ `A` cannot be formatted using `{:?}` because it doesn't implement `Debug` @@ -22,7 +22,7 @@ LL | type Two = impl Debug; | +++++++++++++++++ error[E0277]: `B` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use9.rs:15:5 + --> $DIR/generic_duplicate_param_use9.rs:16:5 | LL | (t, u, T::BAR) | ^^^^^^^^^^^^^^ `B` cannot be formatted using `{:?}` because it doesn't implement `Debug` @@ -34,7 +34,7 @@ LL | type Two = impl Debug; | +++++++++++++++++ error[E0277]: `A` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use9.rs:22:5 + --> $DIR/generic_duplicate_param_use9.rs:24:5 | LL | (t, u, 42) | ^^^^^^^^^^ `A` cannot be formatted using `{:?}` because it doesn't implement `Debug` @@ -46,7 +46,7 @@ LL | type Two = impl Debug; | +++++++++++++++++ error[E0277]: `B` doesn't implement `Debug` - --> $DIR/generic_duplicate_param_use9.rs:22:5 + --> $DIR/generic_duplicate_param_use9.rs:24:5 | LL | (t, u, 42) | ^^^^^^^^^^ `B` cannot be formatted using `{:?}` because it doesn't implement `Debug` 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 106efefbaf278..dc4f2c714d186 100644 --- a/tests/ui/type-alias-impl-trait/generic_lifetime_param.rs +++ b/tests/ui/type-alias-impl-trait/generic_lifetime_param.rs @@ -6,7 +6,7 @@ fn main() {} type Region<'a> = impl std::fmt::Debug + 'a; - +#[defines(Region<'b>)] 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 e7b8567b9a217..1ba000377999b 100644 --- a/tests/ui/type-alias-impl-trait/generic_nondefining_use.rs +++ b/tests/ui/type-alias-impl-trait/generic_nondefining_use.rs @@ -12,16 +12,19 @@ type OneConst = impl Debug; // Not defining uses, because they doesn't define *all* possible generics. +#[defines(OneTy)] fn concrete_ty() -> OneTy { 5u32 //~^ ERROR expected generic type parameter, found `u32` } +#[defines(OneLifetime<'static>)] fn concrete_lifetime() -> OneLifetime<'static> { 6u32 //~^ ERROR expected generic lifetime parameter, found `'static` } +#[defines(OneConst<{123}>)] fn concrete_const() -> OneConst<{ 123 }> { 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 966fe823f024d..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,5 +1,5 @@ error[E0792]: expected generic type parameter, found `u32` - --> $DIR/generic_nondefining_use.rs:16:5 + --> $DIR/generic_nondefining_use.rs:17:5 | LL | type OneTy = impl Debug; | - this generic parameter must be used with a generic type parameter @@ -8,7 +8,7 @@ LL | 5u32 | ^^^^ error[E0792]: expected generic lifetime parameter, found `'static` - --> $DIR/generic_nondefining_use.rs:21:5 + --> $DIR/generic_nondefining_use.rs:23:5 | LL | type OneLifetime<'a> = impl Debug; | -- cannot use static lifetime; use a bound lifetime instead or remove the lifetime parameter from the opaque type @@ -17,7 +17,7 @@ LL | 6u32 | ^^^^ error[E0792]: expected generic constant parameter, found `123` - --> $DIR/generic_nondefining_use.rs:26:5 + --> $DIR/generic_nondefining_use.rs:29:5 | LL | type OneConst = impl Debug; | -------------- this generic parameter must be used with a generic constant parameter 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..1c2558b70c696 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 cdd8f6f1976a5..265f585984009 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 @@ -1,6 +1,10 @@ #![feature(type_alias_impl_trait)] -fn main() { +#[defines(WrongGeneric)] +fn foo() +where + WrongGeneric: 'static, +{ let y = 42; let x = wrong_generic(&y); let z: i32 = x; @@ -10,7 +14,12 @@ 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 } + +fn main() { + foo(); +} 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 fa79e51e9f79f..bf5c065cb485b 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 @@ -1,11 +1,11 @@ error: at least one trait must be specified - --> $DIR/generic_type_does_not_live_long_enough.rs:10:24 + --> $DIR/generic_type_does_not_live_long_enough.rs:14:24 | LL | type WrongGeneric = impl 'static; | ^^^^^^^^^^^^ error[E0792]: expected generic type parameter, found `&i32` - --> $DIR/generic_type_does_not_live_long_enough.rs:6:18 + --> $DIR/generic_type_does_not_live_long_enough.rs:10:18 | LL | let z: i32 = x; | ^ @@ -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:14:5 + --> $DIR/generic_type_does_not_live_long_enough.rs:19:5 | LL | t | ^ ...so that the type `T` will meet its required lifetime bounds 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 0efbd1c2bd5fd..831a165fe2a12 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_tait.rs b/tests/ui/type-alias-impl-trait/impl_trait_for_tait.rs index 9f32c5d888b5f..2786ef0024ea0 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..0f564ea74e4e5 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,20 @@ use std::fmt::Debug; type Foo = impl Debug; -pub trait Yay { } -impl Yay for Foo { } +pub trait Yay {} +impl Yay for Foo {} -fn foo() { - is_yay::(); //~ ERROR: the trait bound `u32: Yay` is not satisfied +fn foo() +where + Foo: Debug, +{ + 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 1c83105a18aff..fbcf863e9c5ee 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:13: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:19:14 | -LL | fn is_yay() { } +LL | fn is_yay() {} | ^^^ required by this bound in `is_yay` error: aborting due to 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..d83c65093779b 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 @@ -2,15 +2,14 @@ use std::fmt::Debug; -type Foo = impl Debug; - -pub trait Yay { } -impl Yay for u32 { } +pub trait Yay {} +impl Yay for u32 {} fn foo() { + type Foo = impl Debug; 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 a6440f02c27d8..cae8b2246b5d9 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:10: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:13:14 | -LL | fn is_yay() { } +LL | fn is_yay() {} | ^^^ required by this bound in `is_yay` error: aborting due to previous error diff --git a/tests/ui/type-alias-impl-trait/implied_bounds.rs b/tests/ui/type-alias-impl-trait/implied_bounds.rs index 53cbf8d229006..fbbd820114d8d 100644 --- a/tests/ui/type-alias-impl-trait/implied_bounds.rs +++ b/tests/ui/type-alias-impl-trait/implied_bounds.rs @@ -1,6 +1,7 @@ #![feature(type_alias_impl_trait)] type WithLifetime<'a> = impl Equals; +#[defines(WithLifetime<'a>)] fn _defining_use<'a>() -> WithLifetime<'a> {} trait Convert<'a> { diff --git a/tests/ui/type-alias-impl-trait/implied_bounds.stderr b/tests/ui/type-alias-impl-trait/implied_bounds.stderr index 6f11b66634b29..ef9dc64e62026 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:17: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 b4c4c013cd251..666f8b6cf76c5 100644 --- a/tests/ui/type-alias-impl-trait/implied_bounds2.rs +++ b/tests/ui/type-alias-impl-trait/implied_bounds2.rs @@ -3,8 +3,14 @@ #![feature(type_alias_impl_trait)] type Ty<'a, A> = impl Sized + 'a; +#[defines(Ty<'a, A>)] fn defining<'a, A>() -> Ty<'a, A> {} fn assert_static() {} -fn test<'a, A>() where Ty<'a, A>: 'static, { assert_static::>() } +fn test<'a, A>() +where + Ty<'a, A>: 'static, +{ + assert_static::>() +} fn main() {} 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 8023cd24f0bf6..d48ce0fd9e7c0 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,6 +1,7 @@ #![feature(type_alias_impl_trait)] type WithLifetime = impl Equals; +#[defines(WithLifetime)] fn _defining_use() -> WithLifetime {} trait Convert<'a> { 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 cbc5e60731815..2b37b3fd6ee46 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:17: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.rs b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check.rs index b6a7264a529fd..236c29f1e9d0f 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 @@ -6,6 +6,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 6f9434255a802..8087b717039cb 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 @@ -1,37 +1,46 @@ #![feature(type_alias_impl_trait)] +#[rustfmt::skip] mod test_lifetime_param { type Ty<'a> = impl Sized + 'a; - fn defining(a: &str) -> Ty<'_> { a } + #[defines(Ty<'a>)] + fn defining<'a>(a: &'a str) -> Ty<'a> { a } fn assert_static<'a: 'static>() {} fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() } //~^ ERROR: lifetime may not live long enough } +#[rustfmt::skip] mod test_higher_kinded_lifetime_param { type Ty<'a> = impl Sized + 'a; - fn defining(a: &str) -> Ty<'_> { a } + #[defines(Ty<'a>)] + fn defining<'a>(a: &'a str) -> Ty<'a> { a } fn assert_static<'a: 'static>() {} fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() } //~^ ERROR: lifetime may not live long enough } +#[rustfmt::skip] mod test_higher_kinded_lifetime_param2 { fn assert_static<'a: 'static>() {} fn test<'a>() { assert_static::<'a>() } //~^ ERROR: lifetime may not live long enough } +#[rustfmt::skip] mod test_type_param { type Ty = impl Sized; + #[defines(Ty)] fn defining(s: A) -> Ty { s } fn assert_static() {} fn test() where Ty: 'static { assert_static::() } //~^ ERROR: parameter type `A` may not live long enough } +#[rustfmt::skip] mod test_implied_from_fn_sig { type Opaque = impl Sized; + #[defines(Opaque)] fn defining() -> Opaque {} fn assert_static() {} 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 399775641f8a3..6a6c1919e5251 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,17 +1,17 @@ error: lifetime may not live long enough - --> $DIR/implied_lifetime_wf_check3.rs:7:43 + --> $DIR/implied_lifetime_wf_check3.rs:9:43 | LL | fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() } | -- lifetime `'a` defined here ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` error: lifetime may not live long enough - --> $DIR/implied_lifetime_wf_check3.rs:15:46 + --> $DIR/implied_lifetime_wf_check3.rs:19:46 | LL | fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() } | -- lifetime `'a` defined here ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` error: lifetime may not live long enough - --> $DIR/implied_lifetime_wf_check3.rs:21:21 + --> $DIR/implied_lifetime_wf_check3.rs:26:21 | LL | fn test<'a>() { assert_static::<'a>() } | -- ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` @@ -19,7 +19,7 @@ LL | fn test<'a>() { assert_static::<'a>() } | lifetime `'a` defined here error[E0310]: the parameter type `A` may not live long enough - --> $DIR/implied_lifetime_wf_check3.rs:29:41 + --> $DIR/implied_lifetime_wf_check3.rs:36:41 | LL | fn test() where Ty: 'static { assert_static::() } | ^^^^^^^^^^^^^^^^^^ ...so that the type `A` will meet its required lifetime bounds 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 ac32dbde04b1c..d68adf26a2f79 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 @@ -3,9 +3,17 @@ mod test_type_param_static { type Ty = impl Sized + 'static; //~^ ERROR: the parameter type `A` may not live long enough - fn defining(s: A) -> Ty { s } + #[defines(Ty)] + fn defining(s: A) -> Ty { + s + } fn assert_static() {} - fn test() where Ty: 'static { assert_static::() } + fn test() + where + Ty: 'static, + { + assert_static::() + } } fn main() {} 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 9a0e71b4eed90..7395435662f38 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 79caddf791320..bab3905ba7cf6 100644 --- a/tests/ui/type-alias-impl-trait/inference-cycle.rs +++ b/tests/ui/type-alias-impl-trait/inference-cycle.rs @@ -5,17 +5,28 @@ mod m { type Foo = impl std::fmt::Debug; //~^ ERROR cycle detected - // Cycle: error today, but it'd be nice if it eventually worked - + #[defines(Foo)] pub fn foo() -> Foo { is_send(bar()) } + // Cycle: this function is not defining, but marked as such. + // trying to prove `Foo: Send` within it will reveal the hidden type + // to check `u32: Send`, but that revealing will look at all functions + // with a `defines(Foo)` attribute, including this one, causing the cycle. + #[defines(Foo)] pub fn bar() { is_send(foo()); // Today: error } - fn baz() { + #[defines(Foo)] + fn baz() -> Foo { + let f: Foo = 22_u32; + f + } + + #[defines(Foo)] + fn bak() { let f: Foo = 22_u32; } diff --git a/tests/ui/type-alias-impl-trait/inference-cycle.stderr b/tests/ui/type-alias-impl-trait/inference-cycle.stderr index b9d646b927a6f..cd77ac5891789 100644 --- a/tests/ui/type-alias-impl-trait/inference-cycle.stderr +++ b/tests/ui/type-alias-impl-trait/inference-cycle.stderr @@ -5,7 +5,7 @@ LL | type Foo = impl std::fmt::Debug; | ^^^^^^^^^^^^^^^^^^^^ | note: ...which requires type-checking `m::bar`... - --> $DIR/inference-cycle.rs:15:9 + --> $DIR/inference-cycle.rs:19:9 | LL | is_send(foo()); // Today: error | ^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/issue-101750.rs b/tests/ui/type-alias-impl-trait/issue-101750.rs index f564f4fa702cb..46adab908780a 100644 --- a/tests/ui/type-alias-impl-trait/issue-101750.rs +++ b/tests/ui/type-alias-impl-trait/issue-101750.rs @@ -9,6 +9,7 @@ type TAIT = impl Trait; struct Concrete; impl Trait for Concrete {} +#[defines(TAIT)] fn tait() -> TAIT { Concrete } @@ -24,9 +25,7 @@ impl OuterTrait for Dummy { } fn tait_and_impl_trait() -> impl OuterTrait { - Dummy { - t: (tait(), Concrete), - } + Dummy { t: (tait(), Concrete) } } fn tait_and_dyn_trait() -> impl OuterTrait)> { diff --git a/tests/ui/type-alias-impl-trait/issue-104817.rs b/tests/ui/type-alias-impl-trait/issue-104817.rs index 0d3bace4db1f4..a3b5a1f83328a 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 47bae8bd12b6b..dfebe4aaf450e 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` for type `OpaqueType` - --> $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-52843-closure-constrain.rs b/tests/ui/type-alias-impl-trait/issue-52843-closure-constrain.rs index 50eeff0b18fd4..651580d6c0c8b 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 @@ -6,7 +6,10 @@ use std::fmt::Debug; fn main() { type Opaque = impl Debug; - fn _unused() -> Opaque { String::new() } + #[defines(Opaque)] + fn _unused() -> Opaque { + String::new() + } let null = || -> 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 4c5fd22556aae..40150a5b4d558 100644 --- a/tests/ui/type-alias-impl-trait/issue-52843-closure-constrain.stderr +++ b/tests/ui/type-alias-impl-trait/issue-52843-closure-constrain.stderr @@ -1,14 +1,14 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/issue-52843-closure-constrain.rs:10:31 + --> $DIR/issue-52843-closure-constrain.rs:13:31 | LL | let null = || -> Opaque { 0 }; | ^ expected `String`, got `i32` | note: previous use here - --> $DIR/issue-52843-closure-constrain.rs:9:30 + --> $DIR/issue-52843-closure-constrain.rs:11:9 | -LL | fn _unused() -> Opaque { String::new() } - | ^^^^^^^^^^^^^ +LL | String::new() + | ^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/type-alias-impl-trait/issue-52843.rs b/tests/ui/type-alias-impl-trait/issue-52843.rs index 159d3ccd27e01..83717ff8a8276 100644 --- a/tests/ui/type-alias-impl-trait/issue-52843.rs +++ b/tests/ui/type-alias-impl-trait/issue-52843.rs @@ -3,6 +3,7 @@ type Foo = impl Default; #[allow(unused)] +#[defines(Foo)] fn foo(t: T) -> Foo { t //~^ ERROR: the trait bound `T: Default` is not satisfied diff --git a/tests/ui/type-alias-impl-trait/issue-52843.stderr b/tests/ui/type-alias-impl-trait/issue-52843.stderr index acd40f9804ea0..a5a40a1480bd9 100644 --- a/tests/ui/type-alias-impl-trait/issue-52843.stderr +++ b/tests/ui/type-alias-impl-trait/issue-52843.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `T: Default` is not satisfied - --> $DIR/issue-52843.rs:7:5 + --> $DIR/issue-52843.rs:8:5 | LL | t | ^ the trait `Default` is not implemented for `T` 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 057930f0c1ce7..87aa65fb0e610 100644 --- a/tests/ui/type-alias-impl-trait/issue-53092-2.rs +++ b/tests/ui/type-alias-impl-trait/issue-53092-2.rs @@ -5,6 +5,7 @@ type Bug = impl Fn(T) -> U + Copy; //~ ERROR cycle detected const CONST_BUG: Bug = unsafe { std::mem::transmute(|_: u8| ()) }; +#[defines(Bug)] fn make_bug>() -> Bug { |x| x.into() //~ ERROR the trait bound `U: From` is not satisfied } 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 2565a28b49354..0255e3c911f7b 100644 --- a/tests/ui/type-alias-impl-trait/issue-53092-2.stderr +++ b/tests/ui/type-alias-impl-trait/issue-53092-2.stderr @@ -25,13 +25,13 @@ LL | | } | |_^ error[E0277]: the trait bound `U: From` is not satisfied - --> $DIR/issue-53092-2.rs:9:5 + --> $DIR/issue-53092-2.rs:10:5 | LL | |x| x.into() | ^^^^^^^^^^^^ the trait `From` is not implemented for `U` | note: required by a bound in `make_bug` - --> $DIR/issue-53092-2.rs:8:19 + --> $DIR/issue-53092-2.rs:9:19 | LL | fn make_bug>() -> Bug { | ^^^^^^^ required by this bound in `make_bug` diff --git a/tests/ui/type-alias-impl-trait/issue-53092.rs b/tests/ui/type-alias-impl-trait/issue-53092.rs index 1be5b46d6df68..b72acf7517f4e 100644 --- a/tests/ui/type-alias-impl-trait/issue-53092.rs +++ b/tests/ui/type-alias-impl-trait/issue-53092.rs @@ -10,6 +10,7 @@ union Moo { const CONST_BUG: Bug = unsafe { Moo { y: () }.x }; +#[defines(Bug)] fn make_bug>() -> Bug { |x| x.into() //~ ERROR the trait bound `U: From` is not satisfied } diff --git a/tests/ui/type-alias-impl-trait/issue-53092.stderr b/tests/ui/type-alias-impl-trait/issue-53092.stderr index 2109cf8a784dc..97db288fe94aa 100644 --- a/tests/ui/type-alias-impl-trait/issue-53092.stderr +++ b/tests/ui/type-alias-impl-trait/issue-53092.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `U: From` is not satisfied - --> $DIR/issue-53092.rs:14:5 + --> $DIR/issue-53092.rs:15:5 | LL | |x| x.into() | ^^^^^^^^^^^^ the trait `From` is not implemented for `U` | note: required by a bound in `make_bug` - --> $DIR/issue-53092.rs:13:19 + --> $DIR/issue-53092.rs:14:19 | LL | fn make_bug>() -> Bug { | ^^^^^^^ required by this bound in `make_bug` diff --git a/tests/ui/type-alias-impl-trait/issue-53096.rs b/tests/ui/type-alias-impl-trait/issue-53096.rs index 007dcf3bcb680..275d6c8f77ce8 100644 --- a/tests/ui/type-alias-impl-trait/issue-53096.rs +++ b/tests/ui/type-alias-impl-trait/issue-53096.rs @@ -2,6 +2,7 @@ #![feature(type_alias_impl_trait)] type Foo = impl Fn() -> usize; +#[defines(Foo)] const fn bar() -> Foo { || 0usize } diff --git a/tests/ui/type-alias-impl-trait/issue-53096.stderr b/tests/ui/type-alias-impl-trait/issue-53096.stderr index 0af3a75f8532e..9786f58995f9d 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:11:1 + --> $DIR/issue-53096.rs:12:1 | LL | fn main() {} | ^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.rs b/tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.rs index 4a11bb5020e6d..827c3a361b8a5 100644 --- a/tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.rs +++ b/tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.rs @@ -2,8 +2,9 @@ type Foo = impl Fn() -> Foo; +#[defines(Foo)] fn foo() -> Foo { -//~^ ERROR: overflow evaluating the requirement + //~^ ERROR: overflow evaluating the requirement foo } diff --git a/tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr b/tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr index 0a34e8486a551..d66e12c608fcc 100644 --- a/tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr +++ b/tests/ui/type-alias-impl-trait/issue-53398-cyclic-types.stderr @@ -1,5 +1,5 @@ error[E0275]: overflow evaluating the requirement `Foo: Sized` - --> $DIR/issue-53398-cyclic-types.rs:5:13 + --> $DIR/issue-53398-cyclic-types.rs:6:13 | LL | fn foo() -> Foo { | ^^^ diff --git a/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.rs b/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.rs index a3f126d56cf20..374d3bd8892b7 100644 --- a/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.rs +++ b/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.rs @@ -1,10 +1,13 @@ #![feature(generators, generator_trait, rustc_attrs)] #![feature(type_alias_impl_trait)] +// check-pass + use std::ops::Generator; type GenOnce = impl Generator; +#[defines(GenOnce)] const fn const_generator(yielding: Y, returning: R) -> GenOnce { move || { yield yielding; @@ -13,7 +16,7 @@ const fn const_generator(yielding: Y, returning: R) -> GenOnce { } } +#[defines(GenOnce)] const FOO: GenOnce = const_generator(10, 100); -#[rustc_error] -fn main() {} //~ ERROR +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.stderr b/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.stderr deleted file mode 100644 index eb1c9603a60d6..0000000000000 --- a/tests/ui/type-alias-impl-trait/issue-53678-generator-and-const-fn.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: fatal error triggered by #[rustc_error] - --> $DIR/issue-53678-generator-and-const-fn.rs:19:1 - | -LL | fn main() {} - | ^^^^^^^^^ - -error: aborting due to previous error - 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 af0780ab0b998..3b8d134d31cd1 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 4aa5966ff25d4..400864a39e822 100644 --- a/tests/ui/type-alias-impl-trait/issue-57961.rs +++ b/tests/ui/type-alias-impl-trait/issue-57961.rs @@ -11,8 +11,9 @@ impl Foo for () { //~^ ERROR expected `IntoIter` to be an iterator that yields `X`, but it yields `u32` } -fn incoherent() { - let f: X = 22_i32; +#[defines(X)] +fn incoherent() -> X { + 22_i32; } fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-57961.stderr b/tests/ui/type-alias-impl-trait/issue-57961.stderr index 8d11b48888947..f936cef3845fb 100644 --- a/tests/ui/type-alias-impl-trait/issue-57961.stderr +++ b/tests/ui/type-alias-impl-trait/issue-57961.stderr @@ -9,6 +9,11 @@ LL | type Bar = std::vec::IntoIter; | = note: expected opaque type `X` found type `u32` +note: this item cannot register hidden type without a `#[defines(X)]` attribute + --> $DIR/issue-57961.rs:10:5 + | +LL | type Bar = std::vec::IntoIter; + | ^^^^^^^^ note: required by a bound in `Foo::Bar` --> $DIR/issue-57961.rs:6:24 | diff --git a/tests/ui/type-alias-impl-trait/issue-58662-generator-with-lifetime.rs b/tests/ui/type-alias-impl-trait/issue-58662-generator-with-lifetime.rs index 477b61390ed46..b6df0dd96f708 100644 --- a/tests/ui/type-alias-impl-trait/issue-58662-generator-with-lifetime.rs +++ b/tests/ui/type-alias-impl-trait/issue-58662-generator-with-lifetime.rs @@ -7,6 +7,7 @@ use std::ops::{Generator, GeneratorState}; use std::pin::Pin; type RandGenerator<'a> = impl Generator + 'a; +#[defines(RandGenerator<'a>)] fn rand_generator<'a>(rng: &'a ()) -> RandGenerator<'a> { move || { let _rng = rng; @@ -17,6 +18,7 @@ fn rand_generator<'a>(rng: &'a ()) -> RandGenerator<'a> { } pub type RandGeneratorWithIndirection<'c> = impl Generator + 'c; +#[defines(RandGeneratorWithIndirection<'a>)] pub fn rand_generator_with_indirection<'a>(rng: &'a ()) -> RandGeneratorWithIndirection<'a> { fn helper<'b>(rng: &'b ()) -> impl 'b + Generator { move || { 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 27ca7d0fdc9fa..f15be13bb993d 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,7 @@ trait Trait {} impl Trait for T {} type Foo<'c> = impl Trait + 'c; +#[defines(Foo<'a>)] fn foo<'a>(rng: &'a ()) -> Foo<'a> { fn helper<'b>(rng: &'b ()) -> impl 'b + Trait { rng @@ -16,5 +17,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 deleted file mode 100644 index e4ba7f8e2a623..0000000000000 --- a/tests/ui/type-alias-impl-trait/issue-58951-2.rs +++ /dev/null @@ -1,18 +0,0 @@ -// check-pass - -#![feature(type_alias_impl_trait)] - -mod defining_use_scope { - pub type A = impl Iterator; - - pub fn def_a() -> A { - 0..1 - } -} -use defining_use_scope::*; - -pub fn use_a() { - def_a().map(|x| x); -} - -fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-58951.rs b/tests/ui/type-alias-impl-trait/issue-58951.rs index 7303cbab4a813..b15f47c458882 100644 --- a/tests/ui/type-alias-impl-trait/issue-58951.rs +++ b/tests/ui/type-alias-impl-trait/issue-58951.rs @@ -4,6 +4,7 @@ type A = impl Iterator; +#[defines(A)] fn def_a() -> A { 0..1 } diff --git a/tests/ui/type-alias-impl-trait/issue-60371.rs b/tests/ui/type-alias-impl-trait/issue-60371.rs index 9a40f3d9b64ea..2fa34f62f00f5 100644 --- a/tests/ui/type-alias-impl-trait/issue-60371.rs +++ b/tests/ui/type-alias-impl-trait/issue-60371.rs @@ -1,3 +1,5 @@ +#![feature(type_alias_impl_trait)] + trait Bug { type Item: Bug; @@ -5,7 +7,7 @@ trait Bug { } impl Bug for &() { - type Item = impl Bug; //~ ERROR `impl Trait` in type aliases is unstable + type Item = impl Bug; const FUN: fn() -> Self::Item = || (); //~^ ERROR the trait bound `(): Bug` is not satisfied diff --git a/tests/ui/type-alias-impl-trait/issue-60371.stderr b/tests/ui/type-alias-impl-trait/issue-60371.stderr index d0c04371bd793..5d96204fb5e65 100644 --- a/tests/ui/type-alias-impl-trait/issue-60371.stderr +++ b/tests/ui/type-alias-impl-trait/issue-60371.stderr @@ -1,21 +1,11 @@ -error[E0658]: `impl Trait` in type aliases is unstable - --> $DIR/issue-60371.rs:8:17 - | -LL | type Item = impl Bug; - | ^^^^^^^^ - | - = note: see issue #63063 for more information - = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable - error[E0277]: the trait bound `(): Bug` is not satisfied - --> $DIR/issue-60371.rs:10:40 + --> $DIR/issue-60371.rs:12:40 | LL | const FUN: fn() -> Self::Item = || (); | ^^ the trait `Bug` is not implemented for `()` | = help: the trait `Bug` is implemented for `&()` -error: aborting due to 2 previous errors +error: aborting due to previous error -Some errors have detailed explanations: E0277, E0658. -For more information about an error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/type-alias-impl-trait/issue-60407.rs b/tests/ui/type-alias-impl-trait/issue-60407.rs index b833429c76922..ddce83d25ffa1 100644 --- a/tests/ui/type-alias-impl-trait/issue-60407.rs +++ b/tests/ui/type-alias-impl-trait/issue-60407.rs @@ -10,6 +10,7 @@ fn main() { unsafe { TEST = Some(foo()) } } +#[defines(Debuggable)] fn foo() -> Debuggable { 0u32 } diff --git a/tests/ui/type-alias-impl-trait/issue-60564.rs b/tests/ui/type-alias-impl-trait/issue-60564.rs index c2f4c37080746..88db456618d4a 100644 --- a/tests/ui/type-alias-impl-trait/issue-60564.rs +++ b/tests/ui/type-alias-impl-trait/issue-60564.rs @@ -16,6 +16,7 @@ where E: std::fmt::Debug, { type BitsIter = IterBitsIter; + #[defines(IterBitsIter)] fn iter_bits(self, n: u8) -> Self::BitsIter { (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 f8fdb004d0989..f25202da2a951 100644 --- a/tests/ui/type-alias-impl-trait/issue-60564.stderr +++ b/tests/ui/type-alias-impl-trait/issue-60564.stderr @@ -1,5 +1,5 @@ error[E0792]: expected generic type parameter, found `u8` - --> $DIR/issue-60564.rs:20:9 + --> $DIR/issue-60564.rs:21:9 | LL | type IterBitsIter = impl std::iter::Iterator; | - this generic parameter must be used with a generic type parameter diff --git a/tests/ui/type-alias-impl-trait/issue-63263-anon-const-fail.rs b/tests/ui/type-alias-impl-trait/issue-63263-anon-const-fail.rs new file mode 100644 index 0000000000000..ed10330d147c5 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/issue-63263-anon-const-fail.rs @@ -0,0 +1,16 @@ +// Regression test for issue #63263. +// Tests that we properly handle closures with an explicit return type +// that return an opaque type. + +// check-pass + +#![feature(type_alias_impl_trait, inline_const)] + +pub type Closure = impl FnOnce(); + +#[defines(Closure)] +fn main() { + const { + let x: Closure = || {}; + } +} diff --git a/tests/ui/type-alias-impl-trait/issue-63263-anon-const.rs b/tests/ui/type-alias-impl-trait/issue-63263-anon-const.rs new file mode 100644 index 0000000000000..5954ec93b965a --- /dev/null +++ b/tests/ui/type-alias-impl-trait/issue-63263-anon-const.rs @@ -0,0 +1,14 @@ +// Regression test for issue #63263. +// Tests that we properly handle closures with an explicit return type +// that return an opaque type. + +// check-pass + +#![feature(type_alias_impl_trait, inline_const)] + +fn main() { + pub type Closure = impl FnOnce(); + const { + let x: Closure = || {}; + } +} diff --git a/tests/ui/type-alias-impl-trait/issue-63263-closure-return-fail.attr.stderr b/tests/ui/type-alias-impl-trait/issue-63263-closure-return-fail.attr.stderr new file mode 100644 index 0000000000000..b3c218b8cb420 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/issue-63263-closure-return-fail.attr.stderr @@ -0,0 +1,20 @@ +error[E0308]: mismatched types + --> $DIR/issue-63263-closure-return-fail.rs:10:21 + | +LL | pub type Closure = impl FnOnce(); + | ------------- the expected opaque type +... +LL | || -> Closure { || () }; + | ^^^^^ expected opaque type, found closure + | + = note: expected opaque type `Closure` + found closure `[closure@$DIR/issue-63263-closure-return-fail.rs:10:21: 10:23]` +note: this item cannot register hidden type without a `#[defines(Closure)]` attribute + --> $DIR/issue-63263-closure-return-fail.rs:10:5 + | +LL | || -> Closure { || () }; + | ^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/issue-63263-closure-return-fail.none.stderr b/tests/ui/type-alias-impl-trait/issue-63263-closure-return-fail.none.stderr new file mode 100644 index 0000000000000..b3c218b8cb420 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/issue-63263-closure-return-fail.none.stderr @@ -0,0 +1,20 @@ +error[E0308]: mismatched types + --> $DIR/issue-63263-closure-return-fail.rs:10:21 + | +LL | pub type Closure = impl FnOnce(); + | ------------- the expected opaque type +... +LL | || -> Closure { || () }; + | ^^^^^ expected opaque type, found closure + | + = note: expected opaque type `Closure` + found closure `[closure@$DIR/issue-63263-closure-return-fail.rs:10:21: 10:23]` +note: this item cannot register hidden type without a `#[defines(Closure)]` attribute + --> $DIR/issue-63263-closure-return-fail.rs:10:5 + | +LL | || -> Closure { || () }; + | ^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/type-alias-impl-trait/issue-63263-closure-return-fail.rs b/tests/ui/type-alias-impl-trait/issue-63263-closure-return-fail.rs new file mode 100644 index 0000000000000..af16e15236abc --- /dev/null +++ b/tests/ui/type-alias-impl-trait/issue-63263-closure-return-fail.rs @@ -0,0 +1,12 @@ +#![feature(type_alias_impl_trait)] + +// revisions: attr none + +pub type Closure = impl FnOnce(); + +// FIXME(type_alias_impl_trait): cfg_attr doesn't work for `defines` at all yet. +#[cfg_attr(attr, defines(Closure))] +fn main() { + || -> Closure { || () }; + //~^ ERROR: mismatched types +} 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 7414611a74893..5bd674cc6a0b6 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 @@ -6,8 +6,7 @@ #![feature(type_alias_impl_trait)] -pub type Closure = impl FnOnce(); - fn main() { + pub type Closure = impl FnOnce(); || -> Closure { || () }; } diff --git a/tests/ui/type-alias-impl-trait/issue-63279.rs b/tests/ui/type-alias-impl-trait/issue-63279.rs index 0e46745c65cd6..02de4f2de9d95 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 a4f6359b904c6..08155f23e2dbe 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 7066a0535e184..6aa72e045736d 100644 --- a/tests/ui/type-alias-impl-trait/issue-63355.rs +++ b/tests/ui/type-alias-impl-trait/issue-63355.rs @@ -22,6 +22,7 @@ impl Foo for () {} impl Bar for () { type Foo = FooImpl; + #[defines(FooImpl)] fn foo() -> Self::Foo { () } @@ -34,10 +35,13 @@ impl Baz for () { type Foo = FooImpl; type Bar = BarImpl; + #[defines(FooImpl)] fn foo() -> Self::Foo { () } + #[defines(BarImpl)] + #[defines(FooImpl)] fn bar() -> Self::Bar { () } 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 28f4a85c9f290..8d57ecd75066b 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-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 b91cbce3727f6..0d44298f85c61 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 @@ -11,7 +11,10 @@ type T = impl Sized; fn take(_: fn() -> T) {} -fn main() { +#[defines(T)] +fn foo() { take(|| {}); take(|| {}); } + +fn main() {} 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 d97270c3124d1..b1ff2bc89c59d 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 cd219328a995a..3032c95b04853 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 5e0a82a72868a..cffdf2d5b44c7 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,6 +6,7 @@ trait Trait {} type Alias<'a, U> = impl Trait; +#[defines(Alias<'a, ()>)] fn f<'a>() -> Alias<'a, ()> {} //~^ ERROR expected generic type parameter, found `()` 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 271743a4010c8..04bb9a67f6f0b 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,9 +1,9 @@ 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, ()> {} | ^^ 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 3b32260c96fe1..9325f7c13f45d 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,6 +6,7 @@ trait Trait {} type Alias<'a, U> = impl Trait; +#[defines(Alias<'a, ()>)] fn f<'a>() -> Alias<'a, ()> {} //~^ ERROR expected generic type parameter, found `()` 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 4d9a8d6eef915..b78b41169ed52 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,9 +1,9 @@ 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, ()> {} | ^^ 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 7657fe2fb1aee..e39f4e487517b 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 @@ -17,6 +17,7 @@ impl WithAssoc for () { type Return = impl WithAssoc; //~^ ERROR use of undeclared lifetime name `'a` +#[defines(Return<()>)] fn my_fun() -> Return<()> {} //~^ ERROR expected generic type parameter, found `()` diff --git a/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.stderr b/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.stderr index d1250786d938c..82e45047aa480 100644 --- a/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.stderr +++ b/tests/ui/type-alias-impl-trait/issue-69136-inner-lifetime-resolve-error.stderr @@ -15,7 +15,7 @@ LL | type Return<'a, A> = impl WithAssoc; | +++ error[E0792]: expected generic type parameter, found `()` - --> $DIR/issue-69136-inner-lifetime-resolve-error.rs:20:27 + --> $DIR/issue-69136-inner-lifetime-resolve-error.rs:21:27 | LL | type Return = impl WithAssoc; | - this generic parameter must be used with a generic type parameter 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 a6916eda8b093..eb05b76d10a46 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<'a>)] 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 a9bd6daf2acf7..4b17f365318e2 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 dff0d89d465dd..b77c609fda6b7 100644 --- a/tests/ui/type-alias-impl-trait/issue-70121.rs +++ b/tests/ui/type-alias-impl-trait/issue-70121.rs @@ -4,6 +4,7 @@ pub type Successors<'a> = impl Iterator; +#[defines(Successors<'a>)] pub fn f<'a>() -> Successors<'a> { None.into_iter() } @@ -16,6 +17,7 @@ impl<'a> Tr for &'a () { type Item = Successors<'a>; } +#[defines(Successors<'a>)] pub fn kazusa<'a>() -> <&'a () as Tr>::Item { None.into_iter() } diff --git a/tests/ui/type-alias-impl-trait/issue-72793.rs b/tests/ui/type-alias-impl-trait/issue-72793.rs index 828c871143ad5..b99e988afee2c 100644 --- a/tests/ui/type-alias-impl-trait/issue-72793.rs +++ b/tests/ui/type-alias-impl-trait/issue-72793.rs @@ -3,7 +3,9 @@ #![feature(type_alias_impl_trait)] -trait T { type Item; } +trait T { + type Item; +} type Alias<'a> = impl T; @@ -12,6 +14,7 @@ impl<'a> T for &'a S { type Item = &'a (); } +#[defines(Alias<'a>)] fn filter_positive<'a>() -> Alias<'a> { &S } 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 66886db6eb946..e0dcccbfa4d05 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 b97e444c6d0e0..3d19c6cf9919e 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 @@ -9,6 +9,7 @@ trait Dummy {} impl Dummy for () {} type F = impl Dummy; +#[defines(F)] fn f() -> F {} trait Test { diff --git a/tests/ui/type-alias-impl-trait/issue-77179.rs b/tests/ui/type-alias-impl-trait/issue-77179.rs index 8d818d4a387a6..854eef39b5d09 100644 --- a/tests/ui/type-alias-impl-trait/issue-77179.rs +++ b/tests/ui/type-alias-impl-trait/issue-77179.rs @@ -2,8 +2,9 @@ #![feature(type_alias_impl_trait)] -type Pointer = impl std::ops::Deref; +type Pointer = impl std::ops::Deref; +#[defines(Pointer<_>)] fn test() -> Pointer<_> { //~^ ERROR: the placeholder `_` is not allowed within types Box::new(1) diff --git a/tests/ui/type-alias-impl-trait/issue-77179.stderr b/tests/ui/type-alias-impl-trait/issue-77179.stderr index 053546e4b9285..c9b160239f012 100644 --- a/tests/ui/type-alias-impl-trait/issue-77179.stderr +++ b/tests/ui/type-alias-impl-trait/issue-77179.stderr @@ -1,5 +1,5 @@ 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<_> { | --------^- 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 2ba4befea2a39..2c3f9579184c9 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-89686.rs b/tests/ui/type-alias-impl-trait/issue-89686.rs index 058417bdb8048..aefd802863f90 100644 --- a/tests/ui/type-alias-impl-trait/issue-89686.rs +++ b/tests/ui/type-alias-impl-trait/issue-89686.rs @@ -11,6 +11,7 @@ trait Trait { fn f(&self) -> Self::F; + #[defines(G<'a, Self>)] fn g<'a>(&'a self) -> G<'a, Self> where Self: Sized, diff --git a/tests/ui/type-alias-impl-trait/issue-89686.stderr b/tests/ui/type-alias-impl-trait/issue-89686.stderr index 3b95a575ac22d..bb78a530a0657 100644 --- a/tests/ui/type-alias-impl-trait/issue-89686.stderr +++ b/tests/ui/type-alias-impl-trait/issue-89686.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `T: Trait` is not satisfied - --> $DIR/issue-89686.rs:18:9 + --> $DIR/issue-89686.rs:19:9 | LL | async move { self.f().await } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T` diff --git a/tests/ui/type-alias-impl-trait/issue-93411.rs b/tests/ui/type-alias-impl-trait/issue-93411.rs index 1f8c789267d1b..02e585e050907 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<'a>)] 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 2c740ccc1aed4..50f619bfcaf59 100644 --- a/tests/ui/type-alias-impl-trait/issue-96572-unconstrained.rs +++ b/tests/ui/type-alias-impl-trait/issue-96572-unconstrained.rs @@ -24,11 +24,10 @@ fn upvar() { fn enum_upvar() { type T = impl Copy; let foo: T = Some((1u32, 2u32)); - let x = move || { - match foo { - None => (), - Some((a, b)) => (), - } + #[defines(T)] + let x = move || match foo { + None => (), + Some((a, b)) => (), }; } @@ -44,6 +43,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 +52,7 @@ mod only_pattern { type U = impl Copy; + #[defines(U)] fn bar(bar: Option) { match bar { Some((mut x, mut y)) => { @@ -69,11 +70,7 @@ mod only_pattern_rpit { let (mut x, mut y) = foo(false); x = 42; y = "foo"; - if b { - panic!() - } else { - foo(true) - } + if b { panic!() } else { foo(true) } } fn bar(b: bool) -> Option { 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 01d1f5db13265..0f6da684cb484 100644 --- a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.rs +++ b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.rs @@ -1,7 +1,10 @@ #![feature(type_alias_impl_trait)] type Opaque<'a, T> = impl Sized; -fn defining<'a, T>(x: &'a i32) -> Opaque { x } -//~^ ERROR: hidden type for `Opaque<'a, T>` captures lifetime that does not appear in bounds +#[defines(Opaque<'a, T>)] +fn defining<'a, T>(x: &'a i32) -> Opaque { + x + //~^ ERROR: hidden type for `Opaque<'a, T>` captures lifetime that does not appear in bounds +} fn main() {} 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 d666e668d3655..61177058278fb 100644 --- a/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr +++ b/tests/ui/type-alias-impl-trait/missing_lifetime_bound.stderr @@ -1,12 +1,13 @@ error[E0700]: hidden type for `Opaque<'a, T>` captures lifetime that does not appear in bounds - --> $DIR/missing_lifetime_bound.rs:4:47 + --> $DIR/missing_lifetime_bound.rs:6:5 | LL | type Opaque<'a, T> = impl Sized; | ---------- opaque type defined here -LL | fn defining<'a, T>(x: &'a i32) -> Opaque { x } - | -- ^ - | | - | hidden type `&'a i32` captures the lifetime `'a` as defined here +LL | #[defines(Opaque<'a, T>)] +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 previous error 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..1d2b3f19450ab 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,8 @@ type Y = impl std::fmt::Debug; +#[defines(Y)] +#[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 2781170091245..bf03619343e44 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:12: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 65eb2952e0ff0..916e878ca7797 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 @@ -6,6 +6,8 @@ impl<'a, T: ?Sized> Captures<'a> for T {} type Foo<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +#[defines(Foo<'x, 'y>)] +#[defines(Foo<'y, 'x>)] fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) { (i, i) //~ ERROR concrete type differs from previous } 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 d7676b8e9b1b1..25ef2466f4477 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: concrete type differs from previous defining opaque type use - --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:10:5 + --> $DIR/multiple-def-uses-in-one-fn-lifetimes.rs:12:5 | LL | (i, i) | ^^^^^^ 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 21fca047a3c92..010fd23ef0db7 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,6 +3,8 @@ type X = impl ToString; +#[defines(X)] +#[defines(X)] fn f(a: A, b: B) -> (X, X) { (a.clone(), a) } @@ -13,6 +15,8 @@ impl<'a, T: ?Sized> Captures<'a> for T {} type Foo<'a, 'b> = impl std::fmt::Debug + Captures<'a> + Captures<'b>; +#[defines(Foo<'x, 'y>)] +#[defines(Foo<'y, 'x>)] fn foo<'x, 'y>(i: &'x i32, j: &'y i32) -> (Foo<'x, 'y>, Foo<'y, 'x>) { (i, j) } 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..78a7491747771 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,8 @@ type X = impl Into<&'static A>; +#[defines(X)] +#[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 66a6b0bbf7431..ff213b20827ff 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:11: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..9d2f09a10417c 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,8 @@ type X = impl ToString; +#[defines(X)] +#[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 0f752212ac9c6..a02d6e6df832a 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:12: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..f0d6afcf56a68 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,14 @@ type X = impl ToString; +#[defines(X)] +#[defines(X)] fn f(a: A, b: B) -> (X, X) { (a, b) } +#[defines(X)] +#[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 bbe709dccab4e..4782b13a9211a 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:18:9 | LL | fn g(a: A, b: B) -> (X, X) { | - - found type parameter diff --git a/tests/ui/type-alias-impl-trait/nested.rs b/tests/ui/type-alias-impl-trait/nested.rs index 6b866be7d173f..f6b1ada6f84bd 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 { 42 } diff --git a/tests/ui/type-alias-impl-trait/nested.stderr b/tests/ui/type-alias-impl-trait/nested.stderr index 732af5c0b561f..c4ec4d2353d13 100644 --- a/tests/ui/type-alias-impl-trait/nested.stderr +++ b/tests/ui/type-alias-impl-trait/nested.stderr @@ -1,5 +1,5 @@ error[E0277]: `Bar` doesn't implement `Debug` - --> $DIR/nested.rs:15:22 + --> $DIR/nested.rs:16: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_type_alias_impl_trait.rs b/tests/ui/type-alias-impl-trait/nested_type_alias_impl_trait.rs index 60b6e1aac6281..8a89ca731b0f9 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 @@ -6,10 +6,14 @@ mod my_mod { pub type Foo = impl Debug; pub type Foot = impl Debug; + #[defines(Foo)] pub fn get_foo() -> Foo { 5i32 } + // remove the `defines(Foo)` to make it unambiguous and pass + #[defines(Foo)] + #[defines(Foot)] pub fn get_foot() -> Foot { get_foo() //~ ERROR opaque type's hidden type cannot be another opaque type } 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 fa6ecf68d28f3..27e4234fc6e65 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,5 +1,5 @@ error: opaque type's hidden type cannot be another opaque type from the same scope - --> $DIR/nested_type_alias_impl_trait.rs:14:9 + --> $DIR/nested_type_alias_impl_trait.rs:18:9 | LL | get_foo() | ^^^^^^^^^ one of the two opaque types used here has to be outside its defining scope 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 fed5ac07c901e..ea6bab7e8e367 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_revealing_outside_defining_module.rs b/tests/ui/type-alias-impl-trait/no_revealing_outside_defining_module.rs index 61153b1e17141..516140eaf68e0 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 @@ -4,6 +4,7 @@ fn main() {} mod boo { pub type Boo = impl ::std::fmt::Debug; + #[defines(Boo)] fn bomp() -> Boo { "" } 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 ae03a5b3e37bf..165026213c5c7 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,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/no_revealing_outside_defining_module.rs:15:19 + --> $DIR/no_revealing_outside_defining_module.rs:16:19 | LL | pub type Boo = impl ::std::fmt::Debug; | ---------------------- the found opaque type @@ -11,9 +11,14 @@ LL | let _: &str = bomp(); | = note: expected reference `&str` found opaque type `Boo` +note: this item cannot register hidden type without a `#[defines(Boo)]` attribute + --> $DIR/no_revealing_outside_defining_module.rs:15:1 + | +LL | fn bomp2() { + | ^^^^^^^^^^ error[E0308]: mismatched types - --> $DIR/no_revealing_outside_defining_module.rs:19:5 + --> $DIR/no_revealing_outside_defining_module.rs:20:5 | LL | pub type Boo = impl ::std::fmt::Debug; | ---------------------- the expected opaque type @@ -25,6 +30,11 @@ LL | "" | = note: expected opaque type `Boo` found reference `&'static str` +note: this item cannot register hidden type without a `#[defines(Boo)]` attribute + --> $DIR/no_revealing_outside_defining_module.rs:19:1 + | +LL | fn bomp() -> boo::Boo { + | ^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors 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 fa47d13f5164c..6b2db309ea4fa 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) //~^ ERROR `T` doesn't implement `Debug` @@ -21,6 +22,7 @@ impl Bar for u32 { const FOO: i32 = 42; } +#[defines(Two)] fn four(t: T) -> Two { (t, ::FOO) //~^ ERROR `U: Bar` is not satisfied 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 b11198c584c0d..e71b3131750a1 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,5 +1,5 @@ error[E0277]: `T` doesn't implement `Debug` - --> $DIR/not_a_defining_use.rs:10:5 + --> $DIR/not_a_defining_use.rs:11:5 | LL | (t, 5i8) | ^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` @@ -11,7 +11,7 @@ LL | type Two = impl Debug; | +++++++++++++++++ error[E0277]: the trait bound `U: Bar` is not satisfied - --> $DIR/not_a_defining_use.rs:25:5 + --> $DIR/not_a_defining_use.rs:27:5 | LL | (t, ::FOO) | ^^^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `U` @@ -22,7 +22,7 @@ LL | type Two = impl Debug; | +++++ error[E0277]: `T` doesn't implement `Debug` - --> $DIR/not_a_defining_use.rs:25:5 + --> $DIR/not_a_defining_use.rs:27:5 | LL | (t, ::FOO) | ^^^^^^^^^^^^^^^^^^^^ `T` cannot be formatted using `{:?}` because it doesn't implement `Debug` 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 b8fac45b76db7..1f90c74bb917b 100644 --- a/tests/ui/type-alias-impl-trait/outlives-bound-var.rs +++ b/tests/ui/type-alias-impl-trait/outlives-bound-var.rs @@ -6,6 +6,7 @@ #![feature(type_alias_impl_trait)] type Ty<'a> = impl Sized + 'a; +#[defines(Ty<'a>)] fn define<'a>() -> Ty<'a> {} // Ty<'^0>: 'static diff --git a/tests/ui/type-alias-impl-trait/reveal_local.rs b/tests/ui/type-alias-impl-trait/reveal_local.rs index 7ecb553530106..1a91bb52d7b68 100644 --- a/tests/ui/type-alias-impl-trait/reveal_local.rs +++ b/tests/ui/type-alias-impl-trait/reveal_local.rs @@ -5,14 +5,16 @@ use std::fmt::Debug; type Foo = impl Debug; //~^ ERROR cycle detected -fn is_send() { } +fn is_send() {} +#[defines(Foo)] fn not_good() { // Error: this function does not constrain `Foo` to any particular // hidden type, so it cannot rely on `Send` being true. is_send::(); } +#[defines(Foo)] fn not_gooder() { // 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 27fded3332921..ea3ac72f48a1a 100644 --- a/tests/ui/type-alias-impl-trait/reveal_local.stderr +++ b/tests/ui/type-alias-impl-trait/reveal_local.stderr @@ -5,7 +5,7 @@ LL | type Foo = impl Debug; | ^^^^^^^^^^ | note: ...which requires type-checking `not_good`... - --> $DIR/reveal_local.rs:13:5 + --> $DIR/reveal_local.rs:14:5 | LL | is_send::(); | ^^^^^^^^^^^^^^ 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 8781196c39fa1..092f1719ba7e3 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-2.rs +++ b/tests/ui/type-alias-impl-trait/self-referential-2.rs @@ -3,6 +3,8 @@ type Foo = impl std::fmt::Debug; type Bar = impl PartialEq; +#[defines(Bar)] +#[defines(Foo)] fn bar() -> Bar { 42_i32 //~^ ERROR can't compare `i32` with `Foo` } diff --git a/tests/ui/type-alias-impl-trait/self-referential-2.stderr b/tests/ui/type-alias-impl-trait/self-referential-2.stderr index c2cf70687fd20..8e23f92c96014 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-2.stderr +++ b/tests/ui/type-alias-impl-trait/self-referential-2.stderr @@ -1,5 +1,5 @@ error[E0277]: can't compare `i32` with `Foo` - --> $DIR/self-referential-2.rs:6:13 + --> $DIR/self-referential-2.rs:8:13 | LL | fn bar() -> Bar { | ^^^ no implementation for `i32 == 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 d40715717d49d..5fbc88f169435 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-3.rs +++ b/tests/ui/type-alias-impl-trait/self-referential-3.rs @@ -3,6 +3,7 @@ type Bar<'a, 'b> = impl PartialEq> + std::fmt::Debug; +#[defines(Bar<'a, 'b>)] fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { i } 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 36742c8ad57fc..60166701cd7c6 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-4.rs +++ b/tests/ui/type-alias-impl-trait/self-referential-4.rs @@ -2,18 +2,21 @@ type Bar<'a, 'b> = impl PartialEq> + std::fmt::Debug; +#[defines(Bar<'a, 'b>)] 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<'a, 'b>)] 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<'a, 'b>)] 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 98c762e3d3820..92534981eb94f 100644 --- a/tests/ui/type-alias-impl-trait/self-referential-4.stderr +++ b/tests/ui/type-alias-impl-trait/self-referential-4.stderr @@ -1,5 +1,5 @@ error[E0277]: can't compare `&i32` with `Bar<'b, 'static>` - --> $DIR/self-referential-4.rs:5:31 + --> $DIR/self-referential-4.rs:6:31 | LL | fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { | ^^^^^^^^^^^ no implementation for `&i32 == Bar<'b, 'static>` @@ -10,7 +10,7 @@ LL | i = help: the trait `PartialEq` is implemented for `i32` error[E0277]: can't compare `&i32` with `Foo<'static, 'b>` - --> $DIR/self-referential-4.rs:11:31 + --> $DIR/self-referential-4.rs:13:31 | LL | fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> { | ^^^^^^^^^^^ no implementation for `&i32 == Foo<'static, 'b>` @@ -21,7 +21,7 @@ LL | i = help: the trait `PartialEq` is implemented for `i32` error[E0277]: can't compare `&i32` with `Moo<'static, 'a>` - --> $DIR/self-referential-4.rs:17:31 + --> $DIR/self-referential-4.rs:20:31 | LL | fn moo<'a, 'b>(i: &'a i32) -> Moo<'a, 'b> { | ^^^^^^^^^^^ no implementation for `&i32 == Moo<'static, 'a>` diff --git a/tests/ui/type-alias-impl-trait/self-referential.rs b/tests/ui/type-alias-impl-trait/self-referential.rs index 3ff5406a38270..044fd2ba9b681 100644 --- a/tests/ui/type-alias-impl-trait/self-referential.rs +++ b/tests/ui/type-alias-impl-trait/self-referential.rs @@ -2,6 +2,7 @@ type Bar<'a, 'b> = impl PartialEq> + std::fmt::Debug; +#[defines(Bar<'a, 'b>)] fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { //~^ ERROR can't compare `&i32` with `Bar<'b, 'a>` i @@ -9,6 +10,7 @@ fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { type Foo<'a, 'b> = (i32, impl PartialEq> + std::fmt::Debug); +#[defines(Foo<'a, 'b>)] fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> { //~^ ERROR can't compare `&i32` with `(i32, &i32)` (42, i) @@ -16,6 +18,7 @@ fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> { type Moo<'a, 'b> = (i32, impl PartialEq> + std::fmt::Debug); +#[defines(Moo<'a, 'b>)] fn moo<'a, 'b>(i: &'a i32) -> Moo<'a, 'b> { //~^ ERROR can't compare `&i32` with `(i32, Moo<'b, 'a>::{opaque#0})` (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 aff489d70e389..68ff9fbb2eb57 100644 --- a/tests/ui/type-alias-impl-trait/self-referential.stderr +++ b/tests/ui/type-alias-impl-trait/self-referential.stderr @@ -1,5 +1,5 @@ error[E0277]: can't compare `&i32` with `Bar<'b, 'a>` - --> $DIR/self-referential.rs:5:31 + --> $DIR/self-referential.rs:6:31 | LL | fn bar<'a, 'b>(i: &'a i32) -> Bar<'a, 'b> { | ^^^^^^^^^^^ no implementation for `&i32 == Bar<'b, 'a>` @@ -11,7 +11,7 @@ LL | i = help: the trait `PartialEq` is implemented for `i32` error[E0277]: can't compare `&i32` with `(i32, &i32)` - --> $DIR/self-referential.rs:12:31 + --> $DIR/self-referential.rs:14:31 | LL | fn foo<'a, 'b>(i: &'a i32) -> Foo<'a, 'b> { | ^^^^^^^^^^^ no implementation for `&i32 == (i32, &i32)` @@ -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})` - --> $DIR/self-referential.rs:19:31 + --> $DIR/self-referential.rs:22:31 | LL | fn moo<'a, 'b>(i: &'a i32) -> Moo<'a, 'b> { | ^^^^^^^^^^^ no implementation for `&i32 == (i32, Moo<'b, 'a>::{opaque#0})` diff --git a/tests/ui/type-alias-impl-trait/self_implication.rs b/tests/ui/type-alias-impl-trait/self_implication.rs index 4e805ee308f4d..dd4731f24e046 100644 --- a/tests/ui/type-alias-impl-trait/self_implication.rs +++ b/tests/ui/type-alias-impl-trait/self_implication.rs @@ -24,6 +24,7 @@ fn bar() { // desugared type FooX<'a> = impl Sized; impl<'a> Foo<'a> { + #[defines(FooX<'a>)] fn foo(&self) -> FooX<'a> {} } 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 748a279e43989..8dad9b57d5a7b 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 c2ab6a9d10aa6..31589b0a7651b 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 @@ -4,6 +4,7 @@ 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) +#[defines(Bar)] const fn leak_free() -> Bar { 7i32 } diff --git a/tests/ui/type-alias-impl-trait/structural-match-no-leak.stderr b/tests/ui/type-alias-impl-trait/structural-match-no-leak.stderr index dbc183f54f46b..aacc0cc7aa69b 100644 --- a/tests/ui/type-alias-impl-trait/structural-match-no-leak.stderr +++ b/tests/ui/type-alias-impl-trait/structural-match-no-leak.stderr @@ -1,5 +1,5 @@ error: `Bar` cannot be used in patterns - --> $DIR/structural-match-no-leak.rs:14:9 + --> $DIR/structural-match-no-leak.rs:15:9 | LL | 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 7cc9ccaabdca4..31740b86cbdc3 100644 --- a/tests/ui/type-alias-impl-trait/structural-match.rs +++ b/tests/ui/type-alias-impl-trait/structural-match.rs @@ -5,6 +5,7 @@ type Foo = impl Send; // This is not structural-match struct A; +#[defines(Foo)] const fn value() -> Foo { A } diff --git a/tests/ui/type-alias-impl-trait/structural-match.stderr b/tests/ui/type-alias-impl-trait/structural-match.stderr index 61287f268066e..28ae9c212d979 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` cannot be used in patterns - --> $DIR/structural-match.rs:15:9 + --> $DIR/structural-match.rs:16:9 | LL | VALUE => (), | ^^^^^ 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 f6a8302967060..fe4a31c96a04b 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 fddecfcacf680..613b66db61066 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,13 +5,17 @@ type Foo = impl Iterator; +#[defines(Foo)] fn make_foo() -> Foo { vec![1, 2].into_iter() } type Bar = impl Send; +#[defines(Bar)] type Baz = impl Iterator; +#[defines(Bar)] +#[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 5630e036be34b..de4c00952cdc6 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 07c891f0638c7..701a47305404d 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 @@ -13,6 +13,7 @@ pub struct MyStruct { impl MyTrait for MyStruct {} +#[defines(TE)] pub fn bla() -> TE { return MyStruct { v: 1 }; } 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 c5e8068e5c8e9..d47114738bdd8 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 1a4064055db65..4609ad29e00a1 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 1f2d0e47ea3b2..32bfefd640486 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 @@ -23,6 +23,7 @@ impl Blah { } } +#[defines(Foo)] fn make_foo() -> Foo { true } 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..884adfb18395f 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,11 +3,13 @@ type Foo = impl 'static; //~^ ERROR: at least one trait must be specified +#[defines(Foo)] fn foo() -> Foo { "foo" } -fn bar() -> impl 'static { //~ ERROR: at least one trait must be specified +fn bar() -> impl 'static { + //~^ ERROR: at least one trait must be specified "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 70c2ee4278ca2..76af8b2917336 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,6 +70,7 @@ fn my_other_iter(u: U) -> MyOtherIter { trait Trait {} type GenericBound<'a, T: Trait + 'a> = impl Sized + 'a; +#[defines(GenericBound<'a, T>)] fn generic_bound<'a, T: Trait + 'a>(t: T) -> GenericBound<'a, T> { t } @@ -69,6 +78,7 @@ fn generic_bound<'a, T: Trait + 'a>(t: T) -> GenericBound<'a, T> { mod pass_through { pub type Passthrough = impl Sized + 'static; + #[defines(Passthrough)] fn define_passthrough(t: T) -> Passthrough { t } 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 67f56bcde939a..6a79a6c54e2bc 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 @@ -20,6 +20,7 @@ mod defining_use_scope { // single definition pub type Foo = impl std::fmt::Display; + #[defines(Foo)] pub fn foo() -> Foo { "foo" } @@ -27,29 +28,35 @@ mod defining_use_scope { // two definitions pub type Bar = impl std::fmt::Display; + #[defines(Bar)] pub fn bar1() -> Bar { "bar1" } + #[defines(Bar)] pub fn bar2() -> Bar { "bar2" } pub type MyIter = impl Iterator; + #[defines(MyIter)] pub fn my_iter(t: T) -> MyIter { std::iter::once(t) } + #[defines(MyIter)] fn my_iter2(t: T) -> MyIter { std::iter::once(t) } + #[defines(MyIter)] // param names should not have an effect! fn my_iter3(u: U) -> MyIter { std::iter::once(u) } + #[defines(MyIter)] // param position should not have an effect! fn my_iter4(_: U, v: V) -> MyIter { std::iter::once(v) @@ -58,6 +65,7 @@ mod defining_use_scope { // param names should not have an effect! type MyOtherIter = impl Iterator; + #[defines(MyOtherIter)] fn my_other_iter(u: U) -> MyOtherIter { std::iter::once(u) } @@ -65,6 +73,7 @@ mod defining_use_scope { trait Trait {} type GenericBound<'a, T: Trait + 'a> = impl Sized + 'a; + #[defines(GenericBound<'a, T>)] fn generic_bound<'a, T: Trait + 'a>(t: T) -> GenericBound<'a, T> { t } @@ -72,6 +81,7 @@ mod defining_use_scope { mod pass_through { pub type Passthrough = impl Sized + 'static; + #[defines(Passthrough)] fn define_passthrough(t: T) -> Passthrough { t } @@ -80,5 +90,4 @@ mod defining_use_scope { fn use_passthrough(x: pass_through::Passthrough) -> pass_through::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 fd954801dc047..ca5cce8d770ac 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,8 @@ 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.rs b/tests/ui/type-alias-impl-trait/type_of_a_let.rs index 4e9d1788b94d8..4c9f2ab36bdca 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 @@ -5,11 +5,13 @@ use std::fmt::Debug; type Foo = impl Debug; +#[defines(Foo)] fn foo1() -> u32 { let x: Foo = 22_u32; x } +#[defines(Foo)] fn foo2() -> u32 { let x: Foo = 22_u32; let y: Foo = x; diff --git a/tests/ui/type-alias-impl-trait/type_of_a_let.stderr b/tests/ui/type-alias-impl-trait/type_of_a_let.stderr index 1dabe4586c5b9..8ecd1e8f17fca 100644 --- a/tests/ui/type-alias-impl-trait/type_of_a_let.stderr +++ b/tests/ui/type-alias-impl-trait/type_of_a_let.stderr @@ -1,5 +1,5 @@ error[E0382]: use of moved value: `x` - --> $DIR/type_of_a_let.rs:16:16 + --> $DIR/type_of_a_let.rs:18: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:17:5 + --> $DIR/type_of_a_let.rs:19:5 | 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/unbounded_opaque_type.rs b/tests/ui/type-alias-impl-trait/unbounded_opaque_type.rs index f43ad7dce1d40..a6cfc7a4e2052 100644 --- a/tests/ui/type-alias-impl-trait/unbounded_opaque_type.rs +++ b/tests/ui/type-alias-impl-trait/unbounded_opaque_type.rs @@ -2,10 +2,10 @@ #![feature(type_alias_impl_trait)] type Opaque = impl Sized; +#[defines(Opaque)] fn defining() -> Opaque {} struct Ss<'a, T>(&'a Opaque); - fn test<'a, T>(_: Ss<'a, T>) { // test that we have an implied bound `Opaque: 'a` from fn signature None::<&'a Opaque>; diff --git a/tests/ui/type-alias-impl-trait/underconstrained_generic.rs b/tests/ui/type-alias-impl-trait/underconstrained_generic.rs index aa537dfc9176c..895cbf6544887 100644 --- a/tests/ui/type-alias-impl-trait/underconstrained_generic.rs +++ b/tests/ui/type-alias-impl-trait/underconstrained_generic.rs @@ -18,11 +18,10 @@ impl ProofForConversion for () { type Converter = impl ProofForConversion; +#[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 103636b6cdde2..9dd8a6ea65edc 100644 --- a/tests/ui/type-alias-impl-trait/underconstrained_generic.stderr +++ b/tests/ui/type-alias-impl-trait/underconstrained_generic.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `T: Trait` is not satisfied - --> $DIR/underconstrained_generic.rs:22:5 + --> $DIR/underconstrained_generic.rs:23:5 | LL | () | ^^ the trait `Trait` is not implemented for `T` diff --git a/tests/ui/type-alias-impl-trait/underconstrained_lifetime.rs b/tests/ui/type-alias-impl-trait/underconstrained_lifetime.rs index c5b2e8a1c5eed..55e6d7886a352 100644 --- a/tests/ui/type-alias-impl-trait/underconstrained_lifetime.rs +++ b/tests/ui/type-alias-impl-trait/underconstrained_lifetime.rs @@ -16,6 +16,7 @@ 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<'a, 'b>)] fn _defining_use<'a, 'b>(x: &'b &'a ()) -> Converter<'a, 'b> { x } diff --git a/tests/ui/type-alias-impl-trait/unnameable_type.stderr b/tests/ui/type-alias-impl-trait/unnameable_type.stderr index e9032433494a6..2ab91089a7806 100644 --- a/tests/ui/type-alias-impl-trait/unnameable_type.stderr +++ b/tests/ui/type-alias-impl-trait/unnameable_type.stderr @@ -25,6 +25,11 @@ LL | fn dont_define_this(_private: Private) {} | ^^^^^^^ = note: expected signature `fn(Private)` found signature `fn(MyPrivate)` +note: this item cannot register hidden type without a `#[defines(MyPrivate)]` attribute + --> $DIR/unnameable_type.rs:20:5 + | +LL | fn dont_define_this(_private: MyPrivate) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors 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 ad5e4918ccac5..22bb50ade12be 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/weird-return-types.rs b/tests/ui/type-alias-impl-trait/weird-return-types.rs index faad5ee956a1d..681f3c39b067b 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-fn-def.rs b/tests/ui/type-alias-impl-trait/wf-check-fn-def.rs index 449e9fbd0d847..b75b04e5748cd 100644 --- a/tests/ui/type-alias-impl-trait/wf-check-fn-def.rs +++ b/tests/ui/type-alias-impl-trait/wf-check-fn-def.rs @@ -6,6 +6,7 @@ trait Bar { type FooFn = impl FnOnce(B); +#[defines(FooFn)] fn foo() -> FooFn { fn mop(bar: B) { bar.bar() } mop // NOTE: no function pointer, but function zst item 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 e0005489d1e7c..a487d5d4406d0 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,11 +1,11 @@ error[E0277]: the trait bound `B: Bar` is not satisfied - --> $DIR/wf-check-fn-def.rs:11:5 + --> $DIR/wf-check-fn-def.rs:12:5 | LL | mop // NOTE: no function pointer, but function zst item | ^^^ the trait `Bar` is not implemented for `B` | note: required by a bound in `mop` - --> $DIR/wf-check-fn-def.rs:10:15 + --> $DIR/wf-check-fn-def.rs:11:15 | LL | fn mop(bar: B) { bar.bar() } | ^^^ required by this bound in `mop` 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 3b8470e4ae628..d7c6932de799a 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_check_closures.rs b/tests/ui/type-alias-impl-trait/wf_check_closures.rs index 2c70696ffcf48..9da6942160409 100644 --- a/tests/ui/type-alias-impl-trait/wf_check_closures.rs +++ b/tests/ui/type-alias-impl-trait/wf_check_closures.rs @@ -6,8 +6,9 @@ trait Bar { type FooFn = impl FnOnce(); +#[defines(FooFn)] fn foo(bar: B) -> FooFn { - move || { bar.bar() } + move || bar.bar() //~^ ERROR the trait bound `B: Bar` is not satisfied } diff --git a/tests/ui/type-alias-impl-trait/wf_check_closures.stderr b/tests/ui/type-alias-impl-trait/wf_check_closures.stderr index 58ae8617b9bd9..b64ec94cf7f1b 100644 --- a/tests/ui/type-alias-impl-trait/wf_check_closures.stderr +++ b/tests/ui/type-alias-impl-trait/wf_check_closures.stderr @@ -1,11 +1,11 @@ error[E0277]: the trait bound `B: Bar` is not satisfied - --> $DIR/wf_check_closures.rs:10:5 + --> $DIR/wf_check_closures.rs:11:5 | -LL | move || { bar.bar() } - | ^^^^^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `B` +LL | move || bar.bar() + | ^^^^^^^^^^^^^^^^^ the trait `Bar` is not implemented for `B` | note: required by a bound in `foo` - --> $DIR/wf_check_closures.rs:9:11 + --> $DIR/wf_check_closures.rs:10:11 | LL | fn foo(bar: B) -> FooFn { | ^^^ required by this bound in `foo`