diff --git a/compiler/rustc_data_structures/src/obligation_forest/mod.rs b/compiler/rustc_data_structures/src/obligation_forest/mod.rs index a47908648ba16..f77d0aeed43c8 100644 --- a/compiler/rustc_data_structures/src/obligation_forest/mod.rs +++ b/compiler/rustc_data_structures/src/obligation_forest/mod.rs @@ -146,8 +146,6 @@ pub enum ProcessResult { #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] struct ObligationTreeId(usize); -type ObligationTreeIdGenerator = impl Iterator; - pub struct ObligationForest { /// The list of obligations. In between calls to [Self::process_obligations], /// this list only contains nodes in the `Pending` or `Waiting` state. @@ -310,18 +308,25 @@ pub struct Error { pub backtrace: Vec, } -impl ObligationForest { - 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(), +mod helper { + use super::*; + pub type ObligationTreeIdGenerator = impl Iterator; + impl ObligationForest { + 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(), + } } } +} +use helper::*; +impl ObligationForest { /// Returns the total number of nodes in the forest that have not /// yet been fully resolved. pub fn len(&self) -> usize { diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index e8d9918be22d2..b38d75df66138 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -340,6 +340,10 @@ hir_analysis_substs_on_overridden_impl = could not resolve substs on overridden hir_analysis_tait_forward_compat = item constrains opaque type that is not in its signature .note = this item must mention the opaque type in its signature in order to be able to register hidden types +hir_analysis_tait_forward_compat2 = item does not constrain `{$opaque_type}`, but has it in its signature + .note = consider moving the opaque type's declaration and defining uses into a separate module + .opaque = this opaque type is in the signature + hir_analysis_target_feature_on_main = `main` function is not allowed to have `#[target_feature]` hir_analysis_too_large_static = extern static is too large for the current architecture diff --git a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs index e8d5264c2b8fe..a4a500d3e3134 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs @@ -7,7 +7,7 @@ use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt}; use rustc_span::{sym, DUMMY_SP}; -use crate::errors::{TaitForwardCompat, TypeOf, UnconstrainedOpaqueType}; +use crate::errors::{TaitForwardCompat, TaitForwardCompat2, TypeOf, UnconstrainedOpaqueType}; pub fn test_opaque_hidden_types(tcx: TyCtxt<'_>) { if tcx.has_attr(CRATE_DEF_ID, sym::rustc_hidden_type_of_opaques) { @@ -151,13 +151,17 @@ impl TaitConstraintLocator<'_> { return; } + let opaques = self.tcx.opaque_types_defined_by(item_def_id); + let opaque_type_must_be_defined = opaques.in_signature.contains(&self.def_id); + let opaque_type_may_be_defined = opaques.in_body.contains(&self.def_id); + let mut constrained = false; for (&opaque_type_key, &hidden_type) in &tables.concrete_opaque_types { if opaque_type_key.def_id != self.def_id { continue; } constrained = true; - if !self.tcx.opaque_types_defined_by(item_def_id).contains(&self.def_id) { + if !opaque_type_must_be_defined && !opaque_type_may_be_defined { self.tcx.sess.emit_err(TaitForwardCompat { span: hidden_type.span, item_span: self @@ -179,6 +183,16 @@ impl TaitConstraintLocator<'_> { if !constrained { debug!("no constraints in typeck results"); + if opaque_type_must_be_defined { + self.tcx.sess.emit_err(TaitForwardCompat2 { + span: self + .tcx + .def_ident_span(item_def_id) + .unwrap_or_else(|| self.tcx.def_span(item_def_id)), + opaque_type_span: self.tcx.def_span(self.def_id), + opaque_type: self.tcx.def_path_str(self.def_id), + }); + } return; }; diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 6a2db1d06276c..2e10f744a7d9b 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -194,6 +194,17 @@ pub struct TaitForwardCompat { pub item_span: Span, } +#[derive(Diagnostic)] +#[diag(hir_analysis_tait_forward_compat2)] +#[note] +pub struct TaitForwardCompat2 { + #[primary_span] + pub span: Span, + #[note(hir_analysis_opaque)] + pub opaque_type_span: Span, + pub opaque_type: String, +} + pub struct MissingTypeParams { pub span: Span, pub def_span: Span, 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 00289f9bfb411..5484e56eda01b 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 @@ -289,9 +289,10 @@ impl Trait for X { ) => { if tcx.is_type_alias_impl_trait(alias.def_id) { - if !tcx + let opaques = tcx .opaque_types_defined_by(body_owner_def_id.expect_local()) - .contains(&alias.def_id.expect_local()) + ; + if !opaques.in_body.contains(&alias.def_id.expect_local()) && !opaques.in_signature.contains(&alias.def_id.expect_local()) { let sp = tcx .def_ident_span(body_owner_def_id) diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index e1a14ed0faf6c..7da4af3bb6c50 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -387,7 +387,12 @@ impl<'tcx> InferCtxt<'tcx> { // Named `type Foo = impl Bar;` hir::OpaqueTyOrigin::TyAlias { in_assoc_ty } => { if in_assoc_ty { - self.tcx.opaque_types_defined_by(parent_def_id).contains(&def_id) + self.tcx.opaque_types_defined_by(parent_def_id).in_body.contains(&def_id) + || self + .tcx + .opaque_types_defined_by(parent_def_id) + .in_signature + .contains(&def_id) } else { may_define_opaque_type(self.tcx, parent_def_id, opaque_hir_id) } diff --git a/compiler/rustc_middle/src/mir/terminator.rs b/compiler/rustc_middle/src/mir/terminator.rs index affa83fa34858..f98d43500eb2a 100644 --- a/compiler/rustc_middle/src/mir/terminator.rs +++ b/compiler/rustc_middle/src/mir/terminator.rs @@ -291,7 +291,6 @@ pub struct Terminator<'tcx> { pub kind: TerminatorKind<'tcx>, } -pub type Successors<'a> = impl DoubleEndedIterator + 'a; pub type SuccessorsMut<'a> = iter::Chain, slice::IterMut<'a, BasicBlock>>; @@ -317,47 +316,57 @@ impl<'tcx> TerminatorKind<'tcx> { pub fn if_(cond: Operand<'tcx>, t: BasicBlock, f: BasicBlock) -> TerminatorKind<'tcx> { TerminatorKind::SwitchInt { discr: cond, targets: SwitchTargets::static_if(0, f, t) } } +} - pub fn successors(&self) -> Successors<'_> { - use self::TerminatorKind::*; - match *self { - Call { target: Some(t), unwind: UnwindAction::Cleanup(ref u), .. } - | Yield { resume: t, drop: Some(ref u), .. } - | Drop { target: t, unwind: UnwindAction::Cleanup(ref u), .. } - | Assert { target: t, unwind: UnwindAction::Cleanup(ref u), .. } - | FalseUnwind { real_target: t, unwind: UnwindAction::Cleanup(ref u) } - | InlineAsm { destination: Some(t), unwind: UnwindAction::Cleanup(ref u), .. } => { - Some(t).into_iter().chain(slice::from_ref(u).into_iter().copied()) - } - Goto { target: t } - | Call { target: None, unwind: UnwindAction::Cleanup(t), .. } - | Call { target: Some(t), unwind: _, .. } - | Yield { resume: t, drop: None, .. } - | Drop { target: t, unwind: _, .. } - | Assert { target: t, unwind: _, .. } - | FalseUnwind { real_target: t, unwind: _ } - | InlineAsm { destination: None, unwind: UnwindAction::Cleanup(t), .. } - | InlineAsm { destination: Some(t), unwind: _, .. } => { - Some(t).into_iter().chain((&[]).into_iter().copied()) - } - UnwindResume - | UnwindTerminate(_) - | CoroutineDrop - | Return - | Unreachable - | Call { target: None, unwind: _, .. } - | InlineAsm { destination: None, unwind: _, .. } => { - None.into_iter().chain((&[]).into_iter().copied()) - } - SwitchInt { ref targets, .. } => { - None.into_iter().chain(targets.targets.iter().copied()) +pub use helper::*; + +mod helper { + use super::*; + pub type Successors<'a> = impl DoubleEndedIterator + 'a; + impl<'tcx> TerminatorKind<'tcx> { + pub fn successors(&self) -> Successors<'_> { + use self::TerminatorKind::*; + match *self { + Call { target: Some(t), unwind: UnwindAction::Cleanup(ref u), .. } + | Yield { resume: t, drop: Some(ref u), .. } + | Drop { target: t, unwind: UnwindAction::Cleanup(ref u), .. } + | Assert { target: t, unwind: UnwindAction::Cleanup(ref u), .. } + | FalseUnwind { real_target: t, unwind: UnwindAction::Cleanup(ref u) } + | InlineAsm { + destination: Some(t), unwind: UnwindAction::Cleanup(ref u), .. + } => Some(t).into_iter().chain(slice::from_ref(u).into_iter().copied()), + Goto { target: t } + | Call { target: None, unwind: UnwindAction::Cleanup(t), .. } + | Call { target: Some(t), unwind: _, .. } + | Yield { resume: t, drop: None, .. } + | Drop { target: t, unwind: _, .. } + | Assert { target: t, unwind: _, .. } + | FalseUnwind { real_target: t, unwind: _ } + | InlineAsm { destination: None, unwind: UnwindAction::Cleanup(t), .. } + | InlineAsm { destination: Some(t), unwind: _, .. } => { + Some(t).into_iter().chain((&[]).into_iter().copied()) + } + UnwindResume + | UnwindTerminate(_) + | CoroutineDrop + | Return + | Unreachable + | Call { target: None, unwind: _, .. } + | InlineAsm { destination: None, unwind: _, .. } => { + None.into_iter().chain((&[]).into_iter().copied()) + } + SwitchInt { ref targets, .. } => { + None.into_iter().chain(targets.targets.iter().copied()) + } + FalseEdge { real_target, ref imaginary_target } => Some(real_target) + .into_iter() + .chain(slice::from_ref(imaginary_target).into_iter().copied()), } - FalseEdge { real_target, ref imaginary_target } => Some(real_target) - .into_iter() - .chain(slice::from_ref(imaginary_target).into_iter().copied()), } } +} +impl<'tcx> TerminatorKind<'tcx> { pub fn successors_mut(&mut self) -> SuccessorsMut<'_> { use self::TerminatorKind::*; match *self { diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index e20e9d9312c1b..8f63ca51fdba7 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -158,6 +158,10 @@ impl EraseType for Option> { type Result = [u8; size_of::>>()]; } +impl EraseType for ty::OpaqueTypes<'_> { + type Result = [u8; size_of::>()]; +} + impl EraseType for Option>> { type Result = [u8; size_of::>>>()]; } diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 23d77a1ebe49e..e7f46920d5228 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -341,7 +341,7 @@ rustc_queries! { query opaque_types_defined_by( key: LocalDefId - ) -> &'tcx [LocalDefId] { + ) -> ty::OpaqueTypes<'tcx> { desc { |tcx| "computing the opaque types defined by `{}`", tcx.def_path_str(key.to_def_id()) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index cc0db39ac5719..205e2cd972219 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -30,6 +30,7 @@ pub use adt::*; pub use assoc::*; pub use generic_args::*; pub use generics::*; +pub use opaque_types::OpaqueTypes; use rustc_ast as ast; use rustc_ast::node_id::NodeMap; use rustc_attr as attr; diff --git a/compiler/rustc_middle/src/ty/opaque_types.rs b/compiler/rustc_middle/src/ty/opaque_types.rs index 8d895732dff20..893eeafd724f5 100644 --- a/compiler/rustc_middle/src/ty/opaque_types.rs +++ b/compiler/rustc_middle/src/ty/opaque_types.rs @@ -3,7 +3,7 @@ use crate::ty::fold::{TypeFolder, TypeSuperFoldable}; use crate::ty::{self, Ty, TyCtxt, TypeFoldable}; use crate::ty::{GenericArg, GenericArgKind}; use rustc_data_structures::fx::FxHashMap; -use rustc_span::def_id::DefId; +use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::Span; /// Converts generic params of a TypeFoldable from one @@ -223,3 +223,13 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { } } } + +/// The opaque types defined by an item. +#[derive(Copy, Clone, Debug, HashStable)] +pub struct OpaqueTypes<'tcx> { + /// Opaque types in the signature *must* be defined by the item itself. + pub in_signature: &'tcx [LocalDefId], + /// Opaque types declared in the body are not required to be defined by + /// the item itself, they could be defined by other nested items. + pub in_body: &'tcx [LocalDefId], +} diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 90a939c86444a..87bd2884e991a 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -106,7 +106,8 @@ impl<'tcx> OpaqueTypeCollector<'tcx> { let id = id.owner_id.def_id; if let DefKind::TyAlias = self.collector.tcx.def_kind(id) { let items = self.collector.tcx.opaque_types_defined_by(id); - self.collector.opaques.extend(items); + assert_eq!(items.in_body, []); + self.collector.opaques.extend(items.in_signature); } } #[instrument(level = "trace", skip(self))] @@ -264,11 +265,12 @@ impl<'tcx> TypeVisitor> for OpaqueTypeCollector<'tcx> { } } -fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [LocalDefId] { +fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> ty::OpaqueTypes<'tcx> { let kind = tcx.def_kind(item); trace!(?kind); - let mut collector = OpaqueTypeCollector::new(tcx, item); - super::sig_types::walk_types(tcx, item, &mut collector); + let mut in_signature = OpaqueTypeCollector::new(tcx, item); + let mut in_body = OpaqueTypeCollector::new(tcx, item); + super::sig_types::walk_types(tcx, item, &mut in_signature); match kind { DefKind::AssocFn | DefKind::Fn @@ -276,7 +278,7 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [ | DefKind::Const | DefKind::AssocConst | DefKind::AnonConst => { - collector.collect_taits_declared_in_body(); + in_body.collect_taits_declared_in_body(); } DefKind::OpaqueTy | DefKind::TyAlias @@ -303,10 +305,15 @@ fn opaque_types_defined_by<'tcx>(tcx: TyCtxt<'tcx>, item: LocalDefId) -> &'tcx [ // Closures and coroutines are type checked with their parent, so we need to allow all // opaques from the closure signature *and* from the parent body. DefKind::Closure | DefKind::Coroutine | DefKind::InlineConst => { - collector.opaques.extend(tcx.opaque_types_defined_by(tcx.local_parent(item))); + let nested = tcx.opaque_types_defined_by(tcx.local_parent(item)); + in_signature.opaques.extend(nested.in_signature); + in_body.opaques.extend(nested.in_body); } } - tcx.arena.alloc_from_iter(collector.opaques) + ty::OpaqueTypes { + in_signature: tcx.arena.alloc_from_iter(in_signature.opaques), + in_body: tcx.arena.alloc_from_iter(in_body.opaques), + } } pub(super) fn provide(providers: &mut Providers) { diff --git a/library/std/src/backtrace.rs b/library/std/src/backtrace.rs index e7110aebdea16..efe786cdac4b8 100644 --- a/library/std/src/backtrace.rs +++ b/library/std/src/backtrace.rs @@ -428,39 +428,43 @@ impl fmt::Display for Backtrace { } } -type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe; - -fn lazy_resolve(mut capture: Capture) -> LazyResolve { - move || { - // Use the global backtrace lock to synchronize this as it's a - // requirement of the `backtrace` crate, and then actually resolve - // everything. - let _lock = lock(); - for frame in capture.frames.iter_mut() { - let symbols = &mut frame.symbols; - let frame = match &frame.frame { - RawFrame::Actual(frame) => frame, - #[cfg(test)] - RawFrame::Fake => unimplemented!(), - }; - unsafe { - backtrace_rs::resolve_frame_unsynchronized(frame, |symbol| { - symbols.push(BacktraceSymbol { - name: symbol.name().map(|m| m.as_bytes().to_vec()), - filename: symbol.filename_raw().map(|b| match b { - BytesOrWideString::Bytes(b) => BytesOrWide::Bytes(b.to_owned()), - BytesOrWideString::Wide(b) => BytesOrWide::Wide(b.to_owned()), - }), - lineno: symbol.lineno(), - colno: symbol.colno(), +mod helper { + use super::*; + pub(super) type LazyResolve = impl (FnOnce() -> Capture) + Send + Sync + UnwindSafe; + + pub(super) fn lazy_resolve(mut capture: Capture) -> LazyResolve { + move || { + // Use the global backtrace lock to synchronize this as it's a + // requirement of the `backtrace` crate, and then actually resolve + // everything. + let _lock = lock(); + for frame in capture.frames.iter_mut() { + let symbols = &mut frame.symbols; + let frame = match &frame.frame { + RawFrame::Actual(frame) => frame, + #[cfg(test)] + RawFrame::Fake => unimplemented!(), + }; + unsafe { + backtrace_rs::resolve_frame_unsynchronized(frame, |symbol| { + symbols.push(BacktraceSymbol { + name: symbol.name().map(|m| m.as_bytes().to_vec()), + filename: symbol.filename_raw().map(|b| match b { + BytesOrWideString::Bytes(b) => BytesOrWide::Bytes(b.to_owned()), + BytesOrWideString::Wide(b) => BytesOrWide::Wide(b.to_owned()), + }), + lineno: symbol.lineno(), + colno: symbol.colno(), + }); }); - }); + } } - } - capture + capture + } } } +use helper::*; impl RawFrame { fn ip(&self) -> *mut c_void { 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 4ed7c27fc4e84..11d346a56ba70 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 @@ -48,81 +48,85 @@ impl Trait1 for Struct1 { fn foo(&self) { } } -// impl Trait type aliases for helping with defining other types (see below) -pub type Type1 = impl Send; -pub type Type2 = impl Send; -pub type Type3 = impl Send; -pub type Type4 = impl Send; -pub type Type5 = impl Send; -pub type Type6 = impl Send; -pub type Type7 = impl Send; -pub type Type8 = impl Send; -pub type Type9 = impl Send; -pub type Type10 = impl Send; -pub type Type11 = impl Send; +use opaques::*; +mod opaques { + use super::*; + // impl Trait type aliases for helping with defining other types (see below) + pub type Type1 = impl Send; + pub type Type2 = impl Send; + pub type Type3 = impl Send; + pub type Type4 = impl Send; + pub type Type5 = impl Send; + pub type Type6 = impl Send; + pub type Type7 = impl Send; + pub type Type8 = impl Send; + pub type Type9 = impl Send; + pub type Type10 = impl Send; + pub type Type11 = impl Send; -pub fn fn1<'a>() where - Type1: 'static, - Type2: 'static, - Type3: 'static, - Type4: 'static, - Type5: 'static, - Type6: 'static, - Type7: 'static, - Type8: 'static, - Type9: 'static, - Type10: 'static, - Type11: 'static, -{ - // Closure - let closure1 = || { }; - let _: Type1 = closure1; + pub fn fn1<'a>() where + Type1: 'static, + Type2: 'static, + Type3: 'static, + Type4: 'static, + Type5: 'static, + Type6: 'static, + Type7: 'static, + Type8: 'static, + Type9: 'static, + Type10: 'static, + Type11: 'static, + { + // Closure + let closure1 = || { }; + let _: Type1 = closure1; - // Constructor - pub struct Foo(i32); - let _: Type2 = Foo; + // Constructor + pub struct Foo(i32); + let _: Type2 = Foo; - // Type in extern path - extern { - fn foo(); - } - let _: Type3 = foo; + // Type in extern path + extern { + fn foo(); + } + let _: Type3 = foo; - // Type in closure path - || { - pub struct Foo; - let _: Type4 = Foo; - }; + // Type in closure path + || { + pub struct Foo; + let _: Type4 = Foo; + }; - // Type in const path - const { - pub struct Foo; - fn foo() -> Type5 { Foo } - }; + // Type in const path + const { + pub struct Foo; + fn foo() -> Type5 { Foo } + }; - // Type in impl path - impl Struct1 { - fn foo(&self) { } - } - let _: Type6 = >::foo; + // Type in impl path + impl Struct1 { + fn foo(&self) { } + } + let _: Type6 = >::foo; - // Trait method - let _: Type7 = >::foo; + // Trait method + let _: Type7 = >::foo; - // Trait method - let _: Type8 = >::foo; + // Trait method + let _: Type8 = >::foo; - // Trait method - let _: Type9 = as Trait1>::foo; + // Trait method + let _: Type9 = as Trait1>::foo; - // Const generics - pub struct Qux([T; N]); - let _: Type10 = Qux([0; 32]); + // Const generics + pub struct Qux([T; N]); + let _: Type10 = Qux([0; 32]); - // Lifetimes/regions - pub struct Quux<'a>(&'a i32); - pub struct Quuux<'a, 'b>(&'a i32, &'b Quux<'b>); - let _: Type11 = Quuux; + // Lifetimes/regions + pub struct Quux<'a>(&'a i32); + pub struct Quuux<'a, 'b>(&'a i32, &'b Quux<'b>); + let _: Type11 = Quuux; + } } // Helper type to make Type12 have an unique id @@ -560,24 +564,24 @@ pub fn foo149(_: Type14, _: Type14, _: Type14) { } // CHECK: ![[TYPE105]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker4Sendu6regionEEE"} // CHECK: ![[TYPE106]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker4Sendu6regionEES2_E"} // CHECK: ![[TYPE107]] = !{i64 0, !"_ZTSFvu3refIu3dynIu{{[0-9]+}}NtNtC{{[[:print:]]+}}_4core6marker4Sendu6regionEES2_S2_E"} -// CHECK: ![[TYPE108]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NCNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn111{{[{}][{}]}}closure{{[}][}]}}Iu2i8PFvvEvEE"} -// CHECK: ![[TYPE109]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NCNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn111{{[{}][{}]}}closure{{[}][}]}}Iu2i8PFvvEvES1_E"} -// CHECK: ![[TYPE110]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NCNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn111{{[{}][{}]}}closure{{[}][}]}}Iu2i8PFvvEvES1_S1_E"} -// CHECK: ![[TYPE111]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn13Foo15{{[{}][{}]}}constructor{{[}][}]}}E"} -// CHECK: ![[TYPE112]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn13Foo15{{[{}][{}]}}constructor{{[}][}]}}S_E"} -// CHECK: ![[TYPE113]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn13Foo15{{[{}][{}]}}constructor{{[}][}]}}S_S_E"} -// CHECK: ![[TYPE114]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNFNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn110{{[{}][{}]}}extern{{[}][}]}}3fooE"} -// CHECK: ![[TYPE115]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNFNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn110{{[{}][{}]}}extern{{[}][}]}}3fooS_E"} -// CHECK: ![[TYPE116]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNFNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn110{{[{}][{}]}}extern{{[}][}]}}3fooS_S_E"} -// CHECK: ![[TYPE117]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn1s0_11{{[{}][{}]}}closure{{[}][}]}}3FooE"} -// CHECK: ![[TYPE118]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn1s0_11{{[{}][{}]}}closure{{[}][}]}}3FooS_E"} -// CHECK: ![[TYPE119]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNCNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn1s0_11{{[{}][{}]}}closure{{[}][}]}}3FooS_S_E"} -// CHECK: ![[TYPE120]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn112{{[{}][{}]}}constant{{[}][}]}}3FooE"} -// CHECK: ![[TYPE121]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn112{{[{}][{}]}}constant{{[}][}]}}3FooS_E"} -// CHECK: ![[TYPE122]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNkNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn112{{[{}][{}]}}constant{{[}][}]}}3FooS_S_E"} -// CHECK: ![[TYPE123]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn18{{[{}][{}]}}impl{{[}][}]}}3fooIu3i32EE"} -// CHECK: ![[TYPE124]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn18{{[{}][{}]}}impl{{[}][}]}}3fooIu3i32ES0_E"} -// CHECK: ![[TYPE125]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNINvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn18{{[{}][{}]}}impl{{[}][}]}}3fooIu3i32ES0_S0_E"} +// CHECK: ![[TYPE108]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NCNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn111{{[{}][{}]}}closure{{[}][}]}}Iu2i8PFvvEvEE"} +// CHECK: ![[TYPE109]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NCNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn111{{[{}][{}]}}closure{{[}][}]}}Iu2i8PFvvEvES1_E"} +// CHECK: ![[TYPE110]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NCNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn111{{[{}][{}]}}closure{{[}][}]}}Iu2i8PFvvEvES1_S1_E"} +// CHECK: ![[TYPE111]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn13Foo15{{[{}][{}]}}constructor{{[}][}]}}E"} +// CHECK: ![[TYPE112]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn13Foo15{{[{}][{}]}}constructor{{[}][}]}}S_E"} +// CHECK: ![[TYPE113]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn13Foo15{{[{}][{}]}}constructor{{[}][}]}}S_S_E"} +// CHECK: ![[TYPE114]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNFNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn110{{[{}][{}]}}extern{{[}][}]}}3fooE"} +// CHECK: ![[TYPE115]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNFNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn110{{[{}][{}]}}extern{{[}][}]}}3fooS_E"} +// CHECK: ![[TYPE116]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNFNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn110{{[{}][{}]}}extern{{[}][}]}}3fooS_S_E"} +// CHECK: ![[TYPE117]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNCNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn1s0_11{{[{}][{}]}}closure{{[}][}]}}3FooE"} +// CHECK: ![[TYPE118]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNCNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn1s0_11{{[{}][{}]}}closure{{[}][}]}}3FooS_E"} +// CHECK: ![[TYPE119]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNCNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn1s0_11{{[{}][{}]}}closure{{[}][}]}}3FooS_S_E"} +// CHECK: ![[TYPE120]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNkNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn112{{[{}][{}]}}constant{{[}][}]}}3FooE"} +// CHECK: ![[TYPE121]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNkNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn112{{[{}][{}]}}constant{{[}][}]}}3FooS_E"} +// CHECK: ![[TYPE122]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNkNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn112{{[{}][{}]}}constant{{[}][}]}}3FooS_S_E"} +// CHECK: ![[TYPE123]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNINvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn18{{[{}][{}]}}impl{{[}][}]}}3fooIu3i32EE"} +// CHECK: ![[TYPE124]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNINvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn18{{[{}][{}]}}impl{{[}][}]}}3fooIu3i32ES0_E"} +// CHECK: ![[TYPE125]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNINvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn18{{[{}][{}]}}impl{{[}][}]}}3fooIu3i32ES0_S0_E"} // CHECK: ![[TYPE126]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait13fooIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait1Iu5paramEu6regionEu3i32EE"} // CHECK: ![[TYPE127]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait13fooIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait1Iu5paramEu6regionEu3i32ES4_E"} // CHECK: ![[TYPE128]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait13fooIu3dynIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait1Iu5paramEu6regionEu3i32ES4_S4_E"} @@ -587,12 +591,12 @@ pub fn foo149(_: Type14, _: Type14, _: Type14) { } // CHECK: ![[TYPE132]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait13fooIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7Struct1Iu3i32ES_EE"} // CHECK: ![[TYPE133]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait13fooIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7Struct1Iu3i32ES_ES1_E"} // CHECK: ![[TYPE134]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NvNtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]6Trait13fooIu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7Struct1Iu3i32ES_ES1_S1_E"} -// CHECK: ![[TYPE135]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn13QuxIu3i32Lu5usize32EEE"} -// CHECK: ![[TYPE136]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn13QuxIu3i32Lu5usize32EES2_E"} -// CHECK: ![[TYPE137]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn13QuxIu3i32Lu5usize32EES2_S2_E"} -// CHECK: ![[TYPE138]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn15Quuux15{{[{}][{}]}}constructor{{[}][}]}}Iu6regionS_EE"} -// CHECK: ![[TYPE139]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn15Quuux15{{[{}][{}]}}constructor{{[}][}]}}Iu6regionS_ES0_E"} -// CHECK: ![[TYPE140]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3fn15Quuux15{{[{}][{}]}}constructor{{[}][}]}}Iu6regionS_ES0_S0_E"} +// CHECK: ![[TYPE135]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn13QuxIu3i32Lu5usize32EEE"} +// CHECK: ![[TYPE136]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn13QuxIu3i32Lu5usize32EES2_E"} +// CHECK: ![[TYPE137]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn13QuxIu3i32Lu5usize32EES2_S2_E"} +// CHECK: ![[TYPE138]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn15Quuux15{{[{}][{}]}}constructor{{[}][}]}}Iu6regionS_EE"} +// CHECK: ![[TYPE139]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn15Quuux15{{[{}][{}]}}constructor{{[}][}]}}Iu6regionS_ES0_E"} +// CHECK: ![[TYPE140]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NcNtNvN{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]7opaques3fn15Quuux15{{[{}][{}]}}constructor{{[}][}]}}Iu6regionS_ES0_S0_E"} // CHECK: ![[TYPE141]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3FooE"} // CHECK: ![[TYPE142]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3FooS_E"} // CHECK: ![[TYPE143]] = !{i64 0, !"_ZTSFvu{{[0-9]+}}NtC{{[[:print:]]+}}_[[ITANIUMED_FILENAME]]3FooS_S_E"} diff --git a/tests/ui/coroutine/layout-error.rs b/tests/ui/coroutine/layout-error.rs index 87da60700a4be..5973faf1a70d4 100644 --- a/tests/ui/coroutine/layout-error.rs +++ b/tests/ui/coroutine/layout-error.rs @@ -16,13 +16,22 @@ impl Task { } } -fn main() { - async fn cb() { - let a = Foo; //~ ERROR cannot find value `Foo` in this scope - } +mod helper { + use super::*; + pub type F = impl Future; + fn foo() + where + F:, + { + async fn cb() { + let a = Foo; //~ ERROR cannot find value `Foo` in this scope + } - type F = impl Future; - // Check that statics are inhabited computes they layout. - static POOL: Task = Task::new(); - Task::spawn(&POOL, || cb()); + Task::spawn(&POOL, || cb()); + } } + +// Check that statics are inhabited computes they layout. +static POOL: Task = Task::new(); + +fn main() {} diff --git a/tests/ui/coroutine/layout-error.stderr b/tests/ui/coroutine/layout-error.stderr index b1a258f4f2ca7..b90456cb6685d 100644 --- a/tests/ui/coroutine/layout-error.stderr +++ b/tests/ui/coroutine/layout-error.stderr @@ -1,8 +1,8 @@ error[E0425]: cannot find value `Foo` in this scope - --> $DIR/layout-error.rs:21:17 + --> $DIR/layout-error.rs:27:21 | -LL | let a = Foo; - | ^^^ not found in this scope +LL | let a = Foo; + | ^^^ not found in this scope error: aborting due to previous error diff --git a/tests/ui/coroutine/metadata-sufficient-for-layout.rs b/tests/ui/coroutine/metadata-sufficient-for-layout.rs index 434a2801597af..d881cfc47fc25 100644 --- a/tests/ui/coroutine/metadata-sufficient-for-layout.rs +++ b/tests/ui/coroutine/metadata-sufficient-for-layout.rs @@ -4,22 +4,23 @@ // Regression test for #80998. // // aux-build:metadata-sufficient-for-layout.rs +// check-pass #![feature(type_alias_impl_trait, rustc_attrs)] #![feature(coroutine_trait)] extern crate metadata_sufficient_for_layout; -use std::ops::Coroutine; +mod helper { + use std::ops::Coroutine; + pub type F = impl Coroutine<(), Yield = (), Return = ()>; -type F = impl Coroutine<(), Yield = (), Return = ()>; + fn f() -> F { + metadata_sufficient_for_layout::g() + } +} // Static queries the layout of the coroutine. -static A: Option = None; - -fn f() -> F { - metadata_sufficient_for_layout::g() -} +static A: Option = None; -#[rustc_error] -fn main() {} //~ ERROR +fn main() {} diff --git a/tests/ui/coroutine/metadata-sufficient-for-layout.stderr b/tests/ui/coroutine/metadata-sufficient-for-layout.stderr deleted file mode 100644 index 3488b04f2267e..0000000000000 --- a/tests/ui/coroutine/metadata-sufficient-for-layout.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: fatal error triggered by #[rustc_error] - --> $DIR/metadata-sufficient-for-layout.rs:25:1 - | -LL | fn main() {} - | ^^^^^^^^^ - -error: aborting due to previous error - diff --git a/tests/ui/impl-trait/issue-108592.rs b/tests/ui/impl-trait/issue-108592.rs index 953fffc4898f4..b372806b66d45 100644 --- a/tests/ui/impl-trait/issue-108592.rs +++ b/tests/ui/impl-trait/issue-108592.rs @@ -11,9 +11,13 @@ fn test_closure() { closure(&opaque()); } -type Opaque2 = impl Sized; -type Opaque<'a> = Opaque2; -fn define<'a>() -> Opaque<'a> {} +mod helper { + pub type Opaque2 = impl Sized; + pub type Opaque<'a> = Opaque2; + fn define<'a>() -> Opaque<'a> {} +} + +use helper::*; fn test_tait(_: &Opaque<'_>) { None::<&'static Opaque<'_>>; diff --git a/tests/ui/impl-trait/issues/issue-70877.rs b/tests/ui/impl-trait/issues/issue-70877.rs index df7722986744d..6ced0bbba8b36 100644 --- a/tests/ui/impl-trait/issues/issue-70877.rs +++ b/tests/ui/impl-trait/issues/issue-70877.rs @@ -1,10 +1,8 @@ #![feature(type_alias_impl_trait)] type FooArg<'a> = &'a dyn ToString; -type FooRet = impl std::fmt::Debug; type FooItem = Box FooRet>; -type Foo = impl Iterator; #[repr(C)] struct Bar(u8); @@ -17,19 +15,26 @@ impl Iterator for Bar { } } -fn quux(st: FooArg) -> FooRet { - Some(st.to_string()) -} - -fn ham() -> Foo { - Bar(1) +mod ret { + pub type FooRet = impl std::fmt::Debug; + pub fn quux(st: super::FooArg) -> FooRet { + Some(st.to_string()) + } } - -fn oof(_: Foo) -> impl std::fmt::Debug { - let mut bar = ham(); - let func = bar.next().unwrap(); - return func(&"oof"); //~ ERROR opaque type's hidden type cannot be another opaque type +use ret::*; +mod foo { + pub type Foo = impl Iterator; + pub fn ham() -> Foo { + super::Bar(1) + } + pub fn oof(_: Foo) -> impl std::fmt::Debug { + //~^ ERROR: item does not constrain `Foo::{opaque#0}`, but has it in its signature + let mut bar = ham(); + let func = bar.next().unwrap(); + return func(&"oof"); + } } +use foo::*; fn main() { let _ = oof(ham()); diff --git a/tests/ui/impl-trait/issues/issue-70877.stderr b/tests/ui/impl-trait/issues/issue-70877.stderr index ee140e6f6c43d..4f9010d7b23e4 100644 --- a/tests/ui/impl-trait/issues/issue-70877.stderr +++ b/tests/ui/impl-trait/issues/issue-70877.stderr @@ -1,19 +1,15 @@ -error: opaque type's hidden type cannot be another opaque type from the same scope - --> $DIR/issue-70877.rs:31:12 +error: item does not constrain `Foo::{opaque#0}`, but has it in its signature + --> $DIR/issue-70877.rs:30:12 | -LL | return func(&"oof"); - | ^^^^^^^^^^^^ one of the two opaque types used here has to be outside its defining scope +LL | pub fn oof(_: Foo) -> impl std::fmt::Debug { + | ^^^ | -note: opaque type whose hidden type is being assigned - --> $DIR/issue-70877.rs:28:19 + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/issue-70877.rs:26:20 | -LL | fn oof(_: Foo) -> impl std::fmt::Debug { - | ^^^^^^^^^^^^^^^^^^^^ -note: opaque type being used as hidden type - --> $DIR/issue-70877.rs:4:15 - | -LL | type FooRet = impl std::fmt::Debug; - | ^^^^^^^^^^^^^^^^^^^^ +LL | pub type Foo = impl Iterator; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/tests/ui/impl-trait/issues/issue-77987.rs b/tests/ui/impl-trait/issues/issue-77987.rs index d29710b6f54ca..5d455efa00493 100644 --- a/tests/ui/impl-trait/issues/issue-77987.rs +++ b/tests/ui/impl-trait/issues/issue-77987.rs @@ -2,19 +2,20 @@ // check-pass -trait Foo {} +pub trait Foo {} impl Foo for U {} -type Scope = impl Foo<()>; +mod scope { + pub type Scope = impl super::Foo<()>; -#[allow(unused)] -fn infer_scope() -> Scope { - () + #[allow(unused)] + fn infer_scope() -> Scope { + () + } } #[allow(unused)] -fn ice() -> impl Foo -{ +fn ice() -> impl Foo { loop {} } diff --git a/tests/ui/impl-trait/issues/issue-86800.rs b/tests/ui/impl-trait/issues/issue-86800.rs index df70b324c5ec7..17a035fd25896 100644 --- a/tests/ui/impl-trait/issues/issue-86800.rs +++ b/tests/ui/impl-trait/issues/issue-86800.rs @@ -2,7 +2,7 @@ // edition:2021 // compile-flags:-Z treat-err-as-bug=1 -// error-pattern: aborting due to `-Z treat-err-as-bug=1` +// error-pattern: due to `-Z treat-err-as-bug=1` // failure-status:101 // normalize-stderr-test ".*note: .*\n\n" -> "" // normalize-stderr-test "thread 'rustc' panicked.*:\n.*\n" -> "" @@ -10,44 +10,44 @@ use std::future::Future; -struct Connection { -} +struct Connection {} -trait Transaction { -} +trait Transaction {} struct TestTransaction<'conn> { - conn: &'conn Connection + conn: &'conn Connection, } -impl<'conn> Transaction for TestTransaction<'conn> { -} +impl<'conn> Transaction for TestTransaction<'conn> {} -struct Context { -} +struct Context {} type TransactionResult = Result; -type TransactionFuture<'__, O> = impl '__ + Future>; - fn execute_transaction_fut<'f, F, O>( f: F, ) -> impl FnOnce(&mut dyn Transaction) -> TransactionFuture<'_, O> where - F: FnOnce(&mut dyn Transaction) -> TransactionFuture<'_, O> + 'f + F: FnOnce(&mut dyn Transaction) -> TransactionFuture<'_, O> + 'f, { f } -impl Context { - async fn do_transaction( - &self, f: impl FnOnce(&mut dyn Transaction) -> TransactionFuture<'_, O> - ) -> TransactionResult - { - let mut conn = Connection {}; - let mut transaction = TestTransaction { conn: &mut conn }; - f(&mut transaction).await +mod foo { + use super::*; + pub type TransactionFuture<'__, O> = impl '__ + Future>; + + impl Context { + async fn do_transaction( + &self, + f: impl FnOnce(&mut dyn Transaction) -> TransactionFuture<'_, O>, + ) -> TransactionResult { + let mut conn = Connection {}; + let mut transaction = TestTransaction { conn: &mut conn }; + f(&mut transaction).await + } } } +use foo::TransactionFuture; fn main() {} diff --git a/tests/ui/impl-trait/issues/issue-86800.stderr b/tests/ui/impl-trait/issues/issue-86800.stderr index 8228f8ace9d67..5ed6e67f383f0 100644 --- a/tests/ui/impl-trait/issues/issue-86800.stderr +++ b/tests/ui/impl-trait/issues/issue-86800.stderr @@ -1,12 +1,19 @@ -error: unconstrained opaque type - --> $DIR/issue-86800.rs:31:34 +error: item does not constrain `TransactionFuture::{opaque#0}`, but has it in its signature + --> $DIR/issue-86800.rs:41:18 | -LL | type TransactionFuture<'__, O> = impl '__ + Future>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | async fn do_transaction( + | ^^^^^^^^^^^^^^ | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/issue-86800.rs:38:42 + | +LL | pub type TransactionFuture<'__, O> = impl '__ + Future>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: the compiler unexpectedly panicked. this is a bug. query stack during panic: -#0 [type_of_opaque] computing type of opaque `TransactionFuture::{opaque#0}` -#1 [type_of] computing type of `TransactionFuture::{opaque#0}` +#0 [type_of_opaque] computing type of opaque `foo::TransactionFuture::{opaque#0}` +#1 [type_of] computing type of `foo::TransactionFuture::{opaque#0}` end of query stack diff --git a/tests/ui/impl-trait/issues/issue-89312.rs b/tests/ui/impl-trait/issues/issue-89312.rs index d685a6f120109..5de83549b7154 100644 --- a/tests/ui/impl-trait/issues/issue-89312.rs +++ b/tests/ui/impl-trait/issues/issue-89312.rs @@ -2,18 +2,23 @@ // check-pass -trait T { type Item; } +mod helper { + pub trait T { + type Item; + } -type Alias<'a> = impl T; + pub type Alias<'a> = impl T; -struct S; -impl<'a> T for &'a S { - type Item = &'a (); -} + struct S; + impl<'a> T for &'a S { + type Item = &'a (); + } -fn filter_positive<'a>() -> Alias<'a> { - &S + pub fn filter_positive<'a>() -> Alias<'a> { + &S + } } +use helper::*; fn with_positive(fun: impl Fn(Alias<'_>)) { fun(filter_positive()); diff --git a/tests/ui/impl-trait/normalize-tait-in-const.rs b/tests/ui/impl-trait/normalize-tait-in-const.rs index dd03fd3f754d4..9ce9b8f211ed4 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.rs +++ b/tests/ui/impl-trait/normalize-tait-in-const.rs @@ -7,20 +7,23 @@ use std::marker::Destruct; -trait T { - type Item; -} +mod foo { + trait T { + type Item; + } -type Alias<'a> = impl T; + pub type Alias<'a> = impl T; -struct S; -impl<'a> T for &'a S { - type Item = &'a (); -} + struct S; + impl<'a> T for &'a S { + type Item = &'a (); + } -const fn filter_positive<'a>() -> &'a Alias<'a> { - &&S + pub const fn filter_positive<'a>() -> &'a Alias<'a> { + &&S + } } +use foo::*; const fn with_positive Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { fun(filter_positive()); diff --git a/tests/ui/impl-trait/normalize-tait-in-const.stderr b/tests/ui/impl-trait/normalize-tait-in-const.stderr index ada8fd7fa50ee..348c7796cdbc8 100644 --- a/tests/ui/impl-trait/normalize-tait-in-const.stderr +++ b/tests/ui/impl-trait/normalize-tait-in-const.stderr @@ -1,5 +1,5 @@ error: ~const can only be applied to `#[const_trait]` traits - --> $DIR/normalize-tait-in-const.rs:25:42 + --> $DIR/normalize-tait-in-const.rs:28:42 | LL | const fn with_positive Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) { | ^^^^^^^^^^^^^^^^^ 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 01c933473ea71..582da0363b4f4 100644 --- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle-2.rs +++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle-2.rs @@ -2,7 +2,14 @@ // check-pass -type Foo = impl PartialEq<(Foo, i32)>; +mod foo { + pub type Foo = impl PartialEq<(Foo, i32)>; + + fn foo() -> Foo { + super::Bar + } +} +use foo::Foo; struct Bar; @@ -12,8 +19,4 @@ impl PartialEq<(Foo, i32)> for Bar { } } -fn foo() -> Foo { - Bar -} - fn main() {} diff --git a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.rs b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.rs index 91f1ed48133f5..dc9424c3ca7ab 100644 --- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.rs +++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.rs @@ -9,6 +9,7 @@ mod a { impl PartialEq<(Bar, i32)> for Bar { fn eq(&self, _other: &(Foo, i32)) -> bool { //~^ ERROR: `eq` has an incompatible type for trait + //~| ERROR: item does not constrain `a::Foo::{opaque#0}` true } } 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 fe765271bd2fe..0b68eb0a1f6b4 100644 --- a/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr +++ b/tests/ui/impl-trait/recursive-type-alias-impl-trait-declaration-too-subtle.stderr @@ -1,3 +1,16 @@ +error: item does not constrain `a::Foo::{opaque#0}`, but has it in its signature + --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:10:12 + | +LL | fn eq(&self, _other: &(Foo, i32)) -> bool { + | ^^ + | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:4:16 + | +LL | type Foo = impl PartialEq<(Foo, i32)>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + error: unconstrained opaque type --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:4:16 | @@ -22,7 +35,7 @@ LL | fn eq(&self, _other: &(Foo, i32)) -> bool { found signature `fn(&a::Bar, &(a::Foo, i32)) -> _` error: unconstrained opaque type - --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:18:16 + --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:19:16 | LL | type Foo = impl PartialEq<(Foo, i32)>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -30,7 +43,7 @@ LL | type Foo = impl PartialEq<(Foo, i32)>; = note: `Foo` must be used in combination with a concrete type within the same module error[E0053]: method `eq` has an incompatible type for trait - --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:24:30 + --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:25:30 | LL | type Foo = impl PartialEq<(Foo, i32)>; | -------------------------- the expected opaque type @@ -44,11 +57,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 must have the opaque type in its signature in order to be able to register hidden types - --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:24:12 + --> $DIR/recursive-type-alias-impl-trait-declaration-too-subtle.rs:25:12 | LL | fn eq(&self, _other: &(Bar, i32)) -> bool { | ^^ -error: aborting due to 4 previous errors +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0053`. 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..3f3f719e6f981 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other2.rs +++ b/tests/ui/impl-trait/two_tait_defining_each_other2.rs @@ -6,6 +6,7 @@ type B = impl Foo; trait Foo {} fn muh(x: A) -> B { + //~^ ERROR: item does not constrain `A::{opaque#0}` 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..ecb6fc3100c27 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other2.stderr +++ b/tests/ui/impl-trait/two_tait_defining_each_other2.stderr @@ -1,3 +1,16 @@ +error: item does not constrain `A::{opaque#0}`, but has it in its signature + --> $DIR/two_tait_defining_each_other2.rs:8:4 + | +LL | fn muh(x: A) -> B { + | ^^^ + | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/two_tait_defining_each_other2.rs:3:10 + | +LL | type A = impl Foo; + | ^^^^^^^^ + error: unconstrained opaque type --> $DIR/two_tait_defining_each_other2.rs:3:10 | @@ -7,7 +20,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:10: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 @@ -23,5 +36,5 @@ note: opaque type being used as hidden type LL | type A = impl Foo; | ^^^^^^^^ -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors diff --git a/tests/ui/mir/issue-75053.rs b/tests/ui/mir/issue-75053.rs index cb56eaa0b13d9..72b8c82c584de 100644 --- a/tests/ui/mir/issue-75053.rs +++ b/tests/ui/mir/issue-75053.rs @@ -13,10 +13,13 @@ trait MyFrom: Sized { fn my_from(value: T) -> Result; } -trait F {} -impl F for () {} -type DummyT = impl F; -fn _dummy_t() -> DummyT {} +mod f { + pub trait F {} + impl F for () {} + pub type DummyT = impl F; + fn _dummy_t() -> DummyT {} +} +use f::*; struct Phantom1(PhantomData); struct Phantom2(PhantomData); diff --git a/tests/ui/mir/issue-75053.stderr b/tests/ui/mir/issue-75053.stderr index 64e59e6c44825..c533275c99a79 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:49:1 | LL | fn main() { | ^^^^^^^^^ diff --git a/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.is_send.stderr b/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.is_send.stderr new file mode 100644 index 0000000000000..3af49089bd3d7 --- /dev/null +++ b/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.is_send.stderr @@ -0,0 +1,15 @@ +error: item does not constrain `Foo::{opaque#0}`, but has it in its signature + --> $DIR/dont-type_of-tait-in-defining-scope.rs:14:4 + | +LL | fn test(_: Foo) { + | ^^^^ + | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/dont-type_of-tait-in-defining-scope.rs:7:12 + | +LL | type Foo = impl Send; + | ^^^^^^^^^ + +error: aborting due to previous error + diff --git a/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.not_send.stderr b/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.not_send.stderr index a31bfd9589b3b..9449fc82c2547 100644 --- a/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.not_send.stderr +++ b/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.not_send.stderr @@ -6,7 +6,7 @@ LL | needs_send::(); | = note: cannot satisfy `Foo: Send` note: required by a bound in `needs_send` - --> $DIR/dont-type_of-tait-in-defining-scope.rs:13:18 + --> $DIR/dont-type_of-tait-in-defining-scope.rs:12:18 | LL | fn needs_send() {} | ^^^^ required by this bound in `needs_send` diff --git a/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.rs b/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.rs index 08f14d7494d79..0ea9e3f1f8010 100644 --- a/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.rs +++ b/tests/ui/traits/new-solver/dont-type_of-tait-in-defining-scope.rs @@ -1,6 +1,5 @@ // revisions: is_send not_send // compile-flags: -Ztrait-solver=next -//[is_send] check-pass #![feature(type_alias_impl_trait)] @@ -13,6 +12,7 @@ type Foo = impl Sized; fn needs_send() {} fn test(_: Foo) { + //[is_send]~^ ERROR: item does not constrain `Foo needs_send::(); //[not_send]~^ ERROR type annotations needed: cannot satisfy `Foo: Send` } diff --git a/tests/ui/type-alias-impl-trait/argument-types.rs b/tests/ui/type-alias-impl-trait/argument-types.rs index 185207b9800bb..78547e6326068 100644 --- a/tests/ui/type-alias-impl-trait/argument-types.rs +++ b/tests/ui/type-alias-impl-trait/argument-types.rs @@ -1,13 +1,21 @@ #![feature(type_alias_impl_trait)] #![allow(dead_code)] // check-pass -use std::fmt::Debug; -type Foo = impl Debug; +mod foo { + use std::fmt::Debug; -fn foo1(mut x: Foo) { - x = 22_u32; + pub type Foo = impl Debug; + + fn foo1(mut x: Foo) { + x = 22_u32; + } + + pub fn foo_value() -> Foo { + 11_u32 + } } +use foo::*; fn foo2(mut x: Foo) { // no constraint on x @@ -17,10 +25,6 @@ fn foo3(x: Foo) { println!("{:?}", x); } -fn foo_value() -> Foo { - 11_u32 -} - 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..6f6e464ddb90d 100644 --- a/tests/ui/type-alias-impl-trait/assoc-projection-ice.rs +++ b/tests/ui/type-alias-impl-trait/assoc-projection-ice.rs @@ -2,18 +2,23 @@ // build-pass -trait T { type Item; } +mod helper { + pub trait T { + type Item; + } -type Alias<'a> = impl T; + pub type Alias<'a> = impl T; -struct S; -impl<'a> T for &'a S { - type Item = &'a (); -} + struct S; + impl<'a> T for &'a S { + type Item = &'a (); + } -fn filter_positive<'a>() -> Alias<'a> { - &S + pub fn filter_positive<'a>() -> Alias<'a> { + &S + } } +use helper::*; fn with_positive(fun: impl Fn(Alias<'_>)) { fun(filter_positive()); diff --git a/tests/ui/type-alias-impl-trait/bounds-are-checked-2.rs b/tests/ui/type-alias-impl-trait/bounds-are-checked-2.rs index 55b4dc8dc232b..45f54266014d6 100644 --- a/tests/ui/type-alias-impl-trait/bounds-are-checked-2.rs +++ b/tests/ui/type-alias-impl-trait/bounds-are-checked-2.rs @@ -3,12 +3,15 @@ #![feature(type_alias_impl_trait)] -type X = impl Clone; +mod foo { + pub type X = impl Clone; -fn f(t: T) -> X { - t - //~^ ERROR the trait bound `T: Clone` is not satisfied + fn f(t: T) -> X { + t + //~^ ERROR the trait bound `T: Clone` is not satisfied + } } +use foo::X; fn g(o: Option>) -> Option> { o.clone() diff --git a/tests/ui/type-alias-impl-trait/bounds-are-checked-2.stderr b/tests/ui/type-alias-impl-trait/bounds-are-checked-2.stderr index 8678e9b33b5ea..2bf3d97934628 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,13 +1,13 @@ 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:9 | -LL | t - | ^ the trait `Clone` is not implemented for `T` +LL | t + | ^ the trait `Clone` is not implemented for `T` | help: consider restricting type parameter `T` | -LL | type X = impl Clone; - | +++++++++++++++++++ +LL | pub type X = impl Clone; + | +++++++++++++++++++ error: aborting due to previous error diff --git a/tests/ui/type-alias-impl-trait/closure_args.rs b/tests/ui/type-alias-impl-trait/closure_args.rs index 243f9cd6d4f4c..b3f5ff08298c0 100644 --- a/tests/ui/type-alias-impl-trait/closure_args.rs +++ b/tests/ui/type-alias-impl-trait/closure_args.rs @@ -4,20 +4,24 @@ #![feature(type_alias_impl_trait)] -trait Anything {} -impl Anything for T {} -type Input = impl Anything; -fn run ()>(f: F, i: Input) { - f(i); +mod foo { + pub trait Anything {} + impl Anything for T {} + pub type Input = impl Anything; + + fn bop(_: Input) { + super::run( + |x: u32| { + println!("{x}"); + }, + 0, + ); + } } +use foo::Input; -fn bop(_: Input) { - run( - |x: u32| { - println!("{x}"); - }, - 0, - ); +fn run ()>(f: F, i: Input) { + f(i); } fn main() {} diff --git a/tests/ui/type-alias-impl-trait/closure_args2.rs b/tests/ui/type-alias-impl-trait/closure_args2.rs index 1dd5c3e40cda6..c32a6729a7a32 100644 --- a/tests/ui/type-alias-impl-trait/closure_args2.rs +++ b/tests/ui/type-alias-impl-trait/closure_args2.rs @@ -2,20 +2,28 @@ #![feature(type_alias_impl_trait)] -trait Foo { - // This was reachable in https://github.com/rust-lang/rust/issues/100800 - fn foo(&self) { - unreachable!() +mod foo { + pub trait Foo { + // This was reachable in https://github.com/rust-lang/rust/issues/100800 + fn foo(&self) { + unreachable!() + } } -} -impl Foo for T {} + impl Foo for T {} -struct B; -impl B { - fn foo(&self) {} + pub struct B; + impl B { + fn foo(&self) {} + } + pub type Input = impl Foo; + fn bop() -> Input { + super::run1(|x: B| x.foo(), B); + super::run2(|x: B| x.foo(), B); + panic!() + } } +use foo::*; -type Input = impl Foo; fn run1(f: F, i: Input) { f(i) } @@ -23,10 +31,4 @@ fn run2(f: F, i: B) { f(i) } -fn bop() -> Input { - run1(|x: B| x.foo(), B); - run2(|x: B| x.foo(), B); - panic!() -} - fn main() {} diff --git a/tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs b/tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs index 44158349fdd64..88d950a42131a 100644 --- a/tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs +++ b/tests/ui/type-alias-impl-trait/debug-ty-with-weak.rs @@ -3,10 +3,12 @@ #![feature(type_alias_impl_trait)] -type Debuggable = impl core::fmt::Debug; +mod bar { + pub type Debuggable = impl core::fmt::Debug; + fn foo() -> Debuggable { + 0u32 + } +} +use bar::Debuggable; static mut TEST: Option = None; - -fn foo() -> Debuggable { - 0u32 -} 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 495308a6cace1..73570de53266f 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 @@ -34,18 +34,6 @@ note: for this opaque type LL | type TwoLifetimes<'a, 'b> = impl Debug; | ^^^^^^^^^^ -error: non-defining opaque type use in defining scope - --> $DIR/generic_duplicate_param_use.rs:29:5 - | -LL | t - | ^ - | -note: lifetime used multiple times - --> $DIR/generic_duplicate_param_use.rs:17:19 - | -LL | type TwoLifetimes<'a, 'b> = impl Debug; - | ^^ ^^ - error: non-defining opaque type use in defining scope --> $DIR/generic_duplicate_param_use.rs:33:50 | @@ -58,6 +46,18 @@ note: for this opaque type LL | type TwoConsts = impl Debug; | ^^^^^^^^^^ +error: non-defining opaque type use in defining scope + --> $DIR/generic_duplicate_param_use.rs:29:5 + | +LL | t + | ^ + | +note: lifetime used multiple times + --> $DIR/generic_duplicate_param_use.rs:17:19 + | +LL | type TwoLifetimes<'a, 'b> = impl Debug; + | ^^ ^^ + error: non-defining opaque type use in defining scope --> $DIR/generic_duplicate_param_use.rs:35:5 | 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 e3b7b1a76b09d..bd68b4e3ea469 100644 --- a/tests/ui/type-alias-impl-trait/generic_nondefining_use.stderr +++ b/tests/ui/type-alias-impl-trait/generic_nondefining_use.stderr @@ -31,15 +31,6 @@ note: for this opaque type LL | type OneLifetime<'a> = impl Debug; | ^^^^^^^^^^ -error[E0792]: expected generic lifetime parameter, found `'static` - --> $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 -... -LL | 6u32 - | ^^^^ - error[E0792]: non-defining opaque type use in defining scope --> $DIR/generic_nondefining_use.rs:27:24 | @@ -52,6 +43,15 @@ note: for this opaque type LL | type OneConst = impl Debug; | ^^^^^^^^^^ +error[E0792]: expected generic lifetime parameter, found `'static` + --> $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 +... +LL | 6u32 + | ^^^^ + error[E0792]: expected generic constant parameter, found `123` --> $DIR/generic_nondefining_use.rs:29:5 | diff --git a/tests/ui/type-alias-impl-trait/implied_bounds.rs b/tests/ui/type-alias-impl-trait/implied_bounds.rs index 53cbf8d229006..269c0eff025d2 100644 --- a/tests/ui/type-alias-impl-trait/implied_bounds.rs +++ b/tests/ui/type-alias-impl-trait/implied_bounds.rs @@ -1,7 +1,11 @@ #![feature(type_alias_impl_trait)] -type WithLifetime<'a> = impl Equals; -fn _defining_use<'a>() -> WithLifetime<'a> {} +mod foo { + use super::Equals; + pub type WithLifetime<'a> = impl Equals; + fn _defining_use<'a>() -> WithLifetime<'a> {} +} +use foo::WithLifetime; trait Convert<'a> { type Witness; diff --git a/tests/ui/type-alias-impl-trait/implied_bounds.stderr b/tests/ui/type-alias-impl-trait/implied_bounds.stderr index 6f11b66634b29..eafe65c15dd36 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:21: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..c3d01a1035986 100644 --- a/tests/ui/type-alias-impl-trait/implied_bounds2.rs +++ b/tests/ui/type-alias-impl-trait/implied_bounds2.rs @@ -2,9 +2,17 @@ #![feature(type_alias_impl_trait)] -type Ty<'a, A> = impl Sized + 'a; -fn defining<'a, A>() -> Ty<'a, A> {} -fn assert_static() {} -fn test<'a, A>() where Ty<'a, A>: 'static, { assert_static::>() } +mod helper { + pub type Ty<'a, A> = impl Sized + 'a; + fn defining<'a, A>() -> Ty<'a, A> {} + pub fn assert_static() {} +} +use helper::*; +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..76a63741e18e5 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,7 +1,11 @@ #![feature(type_alias_impl_trait)] -type WithLifetime = impl Equals; -fn _defining_use() -> WithLifetime {} +mod foo { + use super::Equals; + pub type WithLifetime = impl Equals; + fn _defining_use() -> WithLifetime {} +} +use foo::WithLifetime; trait Convert<'a> { type Witness; diff --git a/tests/ui/type-alias-impl-trait/implied_bounds_from_types.stderr b/tests/ui/type-alias-impl-trait/implied_bounds_from_types.stderr index cbc5e60731815..69dfed3ba4539 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:21:9 | LL | impl<'a> Convert<'a> for () { | -- lifetime `'a` defined here 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 469a493b0b353..fb251e9bde155 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,40 +1,68 @@ #![feature(type_alias_impl_trait)] mod test_lifetime_param { - type Ty<'a> = impl Sized; - fn defining(a: &str) -> Ty<'_> { a } - fn assert_static<'a: 'static>() {} - fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() } + pub type Ty<'a> = impl Sized; + fn defining(a: &str) -> Ty<'_> { + a + } + pub fn assert_static<'a: 'static>() {} +} +fn test_lifetime_param_test<'a>() +where + test_lifetime_param::Ty<'a>: 'static, +{ + test_lifetime_param::assert_static::<'a>() //~^ ERROR: lifetime may not live long enough } mod test_higher_kinded_lifetime_param { - type Ty<'a> = impl Sized; - fn defining(a: &str) -> Ty<'_> { a } - fn assert_static<'a: 'static>() {} - fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() } + pub type Ty<'a> = impl Sized + 'a; + fn defining(a: &str) -> Ty<'_> { + a + } + pub fn assert_static<'a: 'static>() {} +} +fn test_higher_kinded_lifetime_param_test<'a>() +where + for<'b> test_higher_kinded_lifetime_param::Ty<'b>: 'a, +{ + test_higher_kinded_lifetime_param::assert_static::<'a>() //~^ ERROR: lifetime may not live long enough } mod test_higher_kinded_lifetime_param2 { fn assert_static<'a: 'static>() {} - fn test<'a>() { assert_static::<'a>() } - //~^ ERROR: lifetime may not live long enough + fn test<'a>() { + assert_static::<'a>() + //~^ ERROR: lifetime may not live long enough + } } mod test_type_param { - type Ty = impl Sized; - fn defining(s: A) -> Ty { s } - fn assert_static() {} - fn test() where Ty: 'static { assert_static::() } + pub type Ty = impl Sized; + fn defining(s: A) -> Ty { + s + } + pub fn assert_static() {} +} +fn test_type_param_test() +where + test_type_param::Ty: 'static, +{ + test_type_param::assert_static::() //~^ ERROR: parameter type `A` may not live long enough } mod test_implied_from_fn_sig { - type Opaque = impl Sized; - fn defining() -> Opaque {} + mod foo { + pub type Opaque = impl Sized; + fn defining() -> Opaque {} + } fn assert_static() {} - fn test(_: Opaque) { assert_static::(); } + + fn test(_: foo::Opaque) { + assert_static::(); + } } fn main() {} 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 d6dd20739b7af..b7c9c131c7d1a 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,36 +1,42 @@ error: lifetime may not live long enough - --> $DIR/implied_lifetime_wf_check3.rs:7:43 + --> $DIR/implied_lifetime_wf_check3.rs:14:5 | -LL | fn test<'a>() where Ty<'a>: 'static { assert_static::<'a>() } - | -- lifetime `'a` defined here ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` +LL | fn test_lifetime_param_test<'a>() + | -- lifetime `'a` defined here +... +LL | test_lifetime_param::assert_static::<'a>() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` error: lifetime may not live long enough - --> $DIR/implied_lifetime_wf_check3.rs:15:46 + --> $DIR/implied_lifetime_wf_check3.rs:29:5 | -LL | fn test<'a>() where for<'b> Ty<'b>: 'a { assert_static::<'a>() } - | -- lifetime `'a` defined here ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` +LL | fn test_higher_kinded_lifetime_param_test<'a>() + | -- lifetime `'a` defined here +... +LL | test_higher_kinded_lifetime_param::assert_static::<'a>() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` error: lifetime may not live long enough - --> $DIR/implied_lifetime_wf_check3.rs:21:21 + --> $DIR/implied_lifetime_wf_check3.rs:36:9 | -LL | fn test<'a>() { assert_static::<'a>() } - | -- ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` - | | - | lifetime `'a` defined here +LL | fn test<'a>() { + | -- lifetime `'a` defined here +LL | assert_static::<'a>() + | ^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static` error[E0310]: the parameter type `A` may not live long enough - --> $DIR/implied_lifetime_wf_check3.rs:29:41 + --> $DIR/implied_lifetime_wf_check3.rs:52:5 | -LL | fn test() where Ty: 'static { assert_static::() } - | ^^^^^^^^^^^^^^^^^^ - | | - | the parameter type `A` must be valid for the static lifetime... - | ...so that the type `A` will meet its required lifetime bounds +LL | test_type_param::assert_static::() + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the parameter type `A` must be valid for the static lifetime... + | ...so that the type `A` will meet its required lifetime bounds | help: consider adding an explicit lifetime bound | -LL | fn test() where Ty: 'static { assert_static::() } - | +++++++++ +LL | fn test_type_param_test() + | +++++++++ error: aborting due to 4 previous errors 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..c4d328622bd75 100644 --- a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs +++ b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.rs @@ -1,11 +1,20 @@ #![feature(type_alias_impl_trait)] mod test_type_param_static { - type Ty = impl Sized + 'static; + pub type Ty = impl Sized + 'static; //~^ ERROR: the parameter type `A` may not live long enough - fn defining(s: A) -> Ty { s } - fn assert_static() {} - fn test() where Ty: 'static { assert_static::() } + fn defining(s: A) -> Ty { + s + } + pub fn assert_static() {} +} +use test_type_param_static::*; + +fn test() +where + Ty: 'static, +{ + assert_static::() } fn main() {} diff --git a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr index 81bc64bc32c63..95f35b4313d10 100644 --- a/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr +++ b/tests/ui/type-alias-impl-trait/implied_lifetime_wf_check4_static.stderr @@ -1,16 +1,16 @@ error[E0310]: the parameter type `A` may not live long enough - --> $DIR/implied_lifetime_wf_check4_static.rs:4:18 + --> $DIR/implied_lifetime_wf_check4_static.rs:4:22 | -LL | type Ty = impl Sized + 'static; - | ^^^^^^^^^^^^^^^^^^^^ - | | - | the parameter type `A` must be valid for the static lifetime... - | ...so that the type `A` will meet its required lifetime bounds +LL | pub type Ty = impl Sized + 'static; + | ^^^^^^^^^^^^^^^^^^^^ + | | + | the parameter type `A` must be valid for the static lifetime... + | ...so that the type `A` will meet its required lifetime bounds | help: consider adding an explicit lifetime bound | -LL | type Ty = impl Sized + 'static; - | +++++++++ +LL | pub type Ty = impl Sized + 'static; + | +++++++++ error: aborting due to previous 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..f7b02f2145e05 100644 --- a/tests/ui/type-alias-impl-trait/issue-101750.rs +++ b/tests/ui/type-alias-impl-trait/issue-101750.rs @@ -2,17 +2,21 @@ // check-pass -trait Trait {} +mod foo { + pub trait Trait {} -type TAIT = impl Trait; + pub type TAIT = impl Trait; -struct Concrete; -impl Trait for Concrete {} + pub struct Concrete; + impl Trait for Concrete {} -fn tait() -> TAIT { - Concrete + pub fn tait() -> TAIT { + Concrete + } } +use foo::*; + trait OuterTrait { type Item; } @@ -24,9 +28,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-109054.rs b/tests/ui/type-alias-impl-trait/issue-109054.rs index 1fbec47b14bcd..c57519b03599d 100644 --- a/tests/ui/type-alias-impl-trait/issue-109054.rs +++ b/tests/ui/type-alias-impl-trait/issue-109054.rs @@ -11,6 +11,7 @@ impl std::ops::Deref for CallMe { type Target = FnType; fn deref(&self) -> &Self::Target { + //~^ ERROR: item does not constrain `ReturnType fn inner(val: &u32) -> ReturnType { async move { *val * 2 } } diff --git a/tests/ui/type-alias-impl-trait/issue-109054.stderr b/tests/ui/type-alias-impl-trait/issue-109054.stderr index a611b9fe448e1..2a4aa63bb8ca1 100644 --- a/tests/ui/type-alias-impl-trait/issue-109054.stderr +++ b/tests/ui/type-alias-impl-trait/issue-109054.stderr @@ -1,5 +1,18 @@ +error: item does not constrain `ReturnType::{opaque#0}`, but has it in its signature + --> $DIR/issue-109054.rs:13:8 + | +LL | fn deref(&self) -> &Self::Target { + | ^^^^^ + | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/issue-109054.rs:7:23 + | +LL | type ReturnType<'a> = impl std::future::Future + 'a; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0792]: expected generic lifetime parameter, found `'_` - --> $DIR/issue-109054.rs:18:9 + --> $DIR/issue-109054.rs:19:9 | LL | type ReturnType<'a> = impl std::future::Future + 'a; | -- this generic parameter must be used with a generic lifetime parameter @@ -7,6 +20,6 @@ LL | type ReturnType<'a> = impl std::future::Future + 'a; LL | &inner | ^^^^^^ -error: aborting due to previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0792`. diff --git a/tests/ui/type-alias-impl-trait/issue-53092.rs b/tests/ui/type-alias-impl-trait/issue-53092.rs index 1be5b46d6df68..83b51227aaae9 100644 --- a/tests/ui/type-alias-impl-trait/issue-53092.rs +++ b/tests/ui/type-alias-impl-trait/issue-53092.rs @@ -1,7 +1,14 @@ #![feature(type_alias_impl_trait)] #![allow(dead_code)] -type Bug = impl Fn(T) -> U + Copy; +mod bug { + pub type Bug = impl Fn(T) -> U + Copy; + + fn make_bug>() -> Bug { + |x| x.into() //~ ERROR the trait bound `U: From` is not satisfied + } +} +use bug::Bug; union Moo { x: Bug, @@ -10,10 +17,6 @@ union Moo { const CONST_BUG: Bug = unsafe { Moo { y: () }.x }; -fn make_bug>() -> Bug { - |x| x.into() //~ ERROR the trait bound `U: From` is not satisfied -} - fn main() { CONST_BUG(0); } diff --git a/tests/ui/type-alias-impl-trait/issue-53092.stderr b/tests/ui/type-alias-impl-trait/issue-53092.stderr index 2109cf8a784dc..47ee36122e79f 100644 --- a/tests/ui/type-alias-impl-trait/issue-53092.stderr +++ b/tests/ui/type-alias-impl-trait/issue-53092.stderr @@ -1,18 +1,18 @@ error[E0277]: the trait bound `U: From` is not satisfied - --> $DIR/issue-53092.rs:14:5 + --> $DIR/issue-53092.rs:8:9 | -LL | |x| x.into() - | ^^^^^^^^^^^^ the trait `From` is not implemented for `U` +LL | |x| x.into() + | ^^^^^^^^^^^^ the trait `From` is not implemented for `U` | note: required by a bound in `make_bug` - --> $DIR/issue-53092.rs:13:19 + --> $DIR/issue-53092.rs:7:23 | -LL | fn make_bug>() -> Bug { - | ^^^^^^^ required by this bound in `make_bug` +LL | fn make_bug>() -> Bug { + | ^^^^^^^ required by this bound in `make_bug` help: consider restricting type parameter `U` | -LL | type Bug> = impl Fn(T) -> U + Copy; - | +++++++++++++++++++++++ +LL | pub type Bug> = impl Fn(T) -> U + Copy; + | +++++++++++++++++++++++ error: aborting due to previous error diff --git a/tests/ui/type-alias-impl-trait/issue-53096.rs b/tests/ui/type-alias-impl-trait/issue-53096.rs index 007dcf3bcb680..590fce84fc9f1 100644 --- a/tests/ui/type-alias-impl-trait/issue-53096.rs +++ b/tests/ui/type-alias-impl-trait/issue-53096.rs @@ -1,10 +1,13 @@ #![feature(rustc_attrs)] #![feature(type_alias_impl_trait)] -type Foo = impl Fn() -> usize; -const fn bar() -> Foo { - || 0usize +mod foo { + pub type Foo = impl Fn() -> usize; + pub const fn bar() -> Foo { + || 0usize + } } +use foo::*; const BAZR: Foo = bar(); #[rustc_error] diff --git a/tests/ui/type-alias-impl-trait/issue-53096.stderr b/tests/ui/type-alias-impl-trait/issue-53096.stderr index 0af3a75f8532e..4210d0c1cb17a 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:14:1 | LL | 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..f2da33b6da666 100644 --- a/tests/ui/type-alias-impl-trait/issue-58951.rs +++ b/tests/ui/type-alias-impl-trait/issue-58951.rs @@ -2,14 +2,16 @@ #![feature(type_alias_impl_trait)] -type A = impl Iterator; +mod helper { + pub type A = impl Iterator; -fn def_a() -> A { - 0..1 + pub fn def_a() -> A { + 0..1 + } } pub fn use_a() { - def_a().map(|x| x); + helper::def_a().map(|x| x); } fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-60407.rs b/tests/ui/type-alias-impl-trait/issue-60407.rs index b833429c76922..6c7c76b5ac728 100644 --- a/tests/ui/type-alias-impl-trait/issue-60407.rs +++ b/tests/ui/type-alias-impl-trait/issue-60407.rs @@ -1,6 +1,13 @@ #![feature(type_alias_impl_trait, rustc_attrs)] -type Debuggable = impl core::fmt::Debug; +mod bar { + pub type Debuggable = impl core::fmt::Debug; + + pub fn foo() -> Debuggable { + 0u32 + } +} +use bar::*; static mut TEST: Option = None; @@ -9,7 +16,3 @@ fn main() { //~^ ERROR unsafe { TEST = Some(foo()) } } - -fn foo() -> Debuggable { - 0u32 -} diff --git a/tests/ui/type-alias-impl-trait/issue-60407.stderr b/tests/ui/type-alias-impl-trait/issue-60407.stderr index fecee27797a54..4e2db652b3845 100644 --- a/tests/ui/type-alias-impl-trait/issue-60407.stderr +++ b/tests/ui/type-alias-impl-trait/issue-60407.stderr @@ -1,5 +1,5 @@ error: fatal error triggered by #[rustc_error] - --> $DIR/issue-60407.rs:8:1 + --> $DIR/issue-60407.rs:15:1 | LL | fn main() { | ^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/issue-63355.rs b/tests/ui/type-alias-impl-trait/issue-63355.rs index 7066a0535e184..a0d0355b5af5c 100644 --- a/tests/ui/type-alias-impl-trait/issue-63355.rs +++ b/tests/ui/type-alias-impl-trait/issue-63355.rs @@ -1,5 +1,4 @@ #![feature(type_alias_impl_trait)] -// check-pass pub trait Foo {} @@ -39,6 +38,7 @@ impl Baz for () { } fn bar() -> Self::Bar { + //~^ ERROR: item does not constrain `FooImpl::{opaque#0}` () } } diff --git a/tests/ui/type-alias-impl-trait/issue-63355.stderr b/tests/ui/type-alias-impl-trait/issue-63355.stderr new file mode 100644 index 0000000000000..54431cdde1cf7 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/issue-63355.stderr @@ -0,0 +1,15 @@ +error: item does not constrain `FooImpl::{opaque#0}`, but has it in its signature + --> $DIR/issue-63355.rs:40:8 + | +LL | fn bar() -> Self::Bar { + | ^^^ + | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/issue-63355.rs:29:20 + | +LL | pub type FooImpl = impl Foo; + | ^^^^^^^^ + +error: aborting due to previous error + 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 7b3e9e12405c7..8f79ee7852325 100644 --- a/tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs +++ b/tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs @@ -1,19 +1,21 @@ // check-pass #![feature(type_alias_impl_trait, rustc_attrs)] +mod foo { + pub type T = impl Sized; + // The concrete type referred by impl-trait-type-alias(`T`) is guaranteed + // to be the same as where it occurs, whereas `impl Trait`'s instance is location sensitive; + // so difference assertion should not be declared on impl-trait-type-alias's instances. + // for details, check RFC-2515: + // https://github.com/rust-lang/rfcs/blob/master/text/2515-type_alias_impl_trait.md -type T = impl Sized; -// The concrete type referred by impl-trait-type-alias(`T`) is guaranteed -// to be the same as where it occurs, whereas `impl Trait`'s instance is location sensitive; -// so difference assertion should not be declared on impl-trait-type-alias's instances. -// for details, check RFC-2515: -// https://github.com/rust-lang/rfcs/blob/master/text/2515-type_alias_impl_trait.md + fn bop(_: T) { + super::take(|| {}); + super::take(|| {}); + } +} +use foo::*; fn take(_: fn() -> T) {} -fn bop(_: T) { - take(|| {}); - take(|| {}); -} - fn main() {} diff --git a/tests/ui/type-alias-impl-trait/issue-65918.rs b/tests/ui/type-alias-impl-trait/issue-65918.rs index 82cc823e494c8..8464506ff0fce 100644 --- a/tests/ui/type-alias-impl-trait/issue-65918.rs +++ b/tests/ui/type-alias-impl-trait/issue-65918.rs @@ -15,10 +15,13 @@ trait MyFrom: Sized { } /* MCVE starts here */ -trait F {} -impl F for () {} -type DummyT = impl F; -fn _dummy_t() -> DummyT {} +mod f { + pub trait F {} + impl F for () {} + pub type DummyT = impl F; + fn _dummy_t() -> DummyT {} +} +use f::DummyT; struct Phantom1(PhantomData); struct Phantom2(PhantomData); diff --git a/tests/ui/type-alias-impl-trait/issue-72793.rs b/tests/ui/type-alias-impl-trait/issue-72793.rs index 828c871143ad5..134b126f7ea89 100644 --- a/tests/ui/type-alias-impl-trait/issue-72793.rs +++ b/tests/ui/type-alias-impl-trait/issue-72793.rs @@ -3,19 +3,25 @@ #![feature(type_alias_impl_trait)] -trait T { type Item; } +mod foo { + pub trait T { + type Item; + } -type Alias<'a> = impl T; + pub type Alias<'a> = impl T; -struct S; -impl<'a> T for &'a S { - type Item = &'a (); -} + struct S; + impl<'a> T for &'a S { + type Item = &'a (); + } -fn filter_positive<'a>() -> Alias<'a> { - &S + pub fn filter_positive<'a>() -> Alias<'a> { + &S + } } +use foo::*; + fn with_positive(fun: impl Fn(Alias<'_>)) { fun(filter_positive()); } 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 386b77d4d1618..0b25d12aa9947 100644 --- a/tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs +++ b/tests/ui/type-alias-impl-trait/issue-76202-trait-impl-for-tait.rs @@ -7,11 +7,13 @@ #![feature(type_alias_impl_trait)] -trait Dummy {} -impl Dummy for () {} - -type F = impl Dummy; -fn f() -> F {} +mod g { + pub trait Dummy {} + impl Dummy for () {} + pub type F = impl Dummy; + pub fn f() -> F {} +} +use g::*; trait Test { fn test(self); diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference3.rs b/tests/ui/type-alias-impl-trait/nested-tait-inference3.rs index b0ebdd1bfab7d..a7d824c5a6a0b 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-inference3.rs +++ b/tests/ui/type-alias-impl-trait/nested-tait-inference3.rs @@ -6,12 +6,13 @@ use std::fmt::Debug; type FooX = impl Debug; //~^ ERROR unconstrained opaque type -trait Foo { } +trait Foo {} -impl Foo for () { } +impl Foo for () {} fn foo() -> impl Foo { + //~^ ERROR: item does not constrain () } -fn main() { } +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference3.stderr b/tests/ui/type-alias-impl-trait/nested-tait-inference3.stderr index b1d947a9ccf4e..9ccd954489633 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-inference3.stderr +++ b/tests/ui/type-alias-impl-trait/nested-tait-inference3.stderr @@ -1,3 +1,16 @@ +error: item does not constrain `FooX::{opaque#0}`, but has it in its signature + --> $DIR/nested-tait-inference3.rs:13:4 + | +LL | fn foo() -> impl Foo { + | ^^^ + | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/nested-tait-inference3.rs:6:13 + | +LL | type FooX = impl Debug; + | ^^^^^^^^^^ + error: unconstrained opaque type --> $DIR/nested-tait-inference3.rs:6:13 | @@ -6,5 +19,5 @@ LL | type FooX = impl Debug; | = note: `FooX` must be used in combination with a concrete type within the same module -error: aborting due to previous error +error: aborting due to 2 previous errors diff --git a/tests/ui/type-alias-impl-trait/nested.rs b/tests/ui/type-alias-impl-trait/nested.rs index 6b866be7d173f..524703939f1dc 100644 --- a/tests/ui/type-alias-impl-trait/nested.rs +++ b/tests/ui/type-alias-impl-trait/nested.rs @@ -8,6 +8,7 @@ trait Trait {} impl Trait for U {} fn bar() -> Bar { + //~^ ERROR: item does not constrain 42 } diff --git a/tests/ui/type-alias-impl-trait/nested.stderr b/tests/ui/type-alias-impl-trait/nested.stderr index 732af5c0b561f..ca1cf6058ea95 100644 --- a/tests/ui/type-alias-impl-trait/nested.stderr +++ b/tests/ui/type-alias-impl-trait/nested.stderr @@ -1,5 +1,18 @@ +error: item does not constrain `Foo::{opaque#0}`, but has it in its signature + --> $DIR/nested.rs:10:4 + | +LL | fn bar() -> Bar { + | ^^^ + | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/nested.rs:3:12 + | +LL | type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ + 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` @@ -7,6 +20,6 @@ LL | println!("{:?}", bar()); = help: the trait `Debug` is not implemented for `Bar` = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. 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 07607516cc4bc..4def8948708fc 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 @@ -11,6 +11,7 @@ mod my_mod { } pub fn get_foot(_: Foo) -> Foot { + //~^ ERROR: item does not constrain `Foo::{opaque#0}`, but has it in its signature get_foo() //~ ERROR opaque type's hidden type cannot be another opaque type } } 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..889cff1ba09eb 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,18 @@ +error: item does not constrain `Foo::{opaque#0}`, but has it in its signature + --> $DIR/nested_type_alias_impl_trait.rs:13:12 + | +LL | pub fn get_foot(_: Foo) -> Foot { + | ^^^^^^^^ + | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/nested_type_alias_impl_trait.rs:6:20 + | +LL | pub type Foo = impl Debug; + | ^^^^^^^^^^ + error: opaque type's hidden type cannot be another opaque type from the same scope - --> $DIR/nested_type_alias_impl_trait.rs:14:9 + --> $DIR/nested_type_alias_impl_trait.rs:15:9 | LL | get_foo() | ^^^^^^^^^ one of the two opaque types used here has to be outside its defining scope @@ -15,5 +28,5 @@ note: opaque type being used as hidden type LL | pub type Foo = impl Debug; | ^^^^^^^^^^ -error: aborting due to previous error +error: aborting due to 2 previous errors diff --git a/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs b/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs index 0f0a02e97d82d..e754f696f692c 100644 --- a/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs +++ b/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.rs @@ -9,6 +9,7 @@ mod foo { // make compiler happy about using 'Foo' pub fn bar(x: Foo) -> Foo { + //~^ ERROR: item does not constrain `Foo::{opaque#0}` x } } diff --git a/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr b/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr index f3e8ae9c7dbae..d95a4a8a727ad 100644 --- a/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr +++ b/tests/ui/type-alias-impl-trait/no_inferrable_concrete_type.stderr @@ -1,3 +1,16 @@ +error: item does not constrain `Foo::{opaque#0}`, but has it in its signature + --> $DIR/no_inferrable_concrete_type.rs:11:12 + | +LL | pub fn bar(x: Foo) -> Foo { + | ^^^ + | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/no_inferrable_concrete_type.rs:7:20 + | +LL | pub type Foo = impl Copy; + | ^^^^^^^^^ + error: unconstrained opaque type --> $DIR/no_inferrable_concrete_type.rs:7:20 | @@ -6,5 +19,5 @@ LL | pub type Foo = impl Copy; | = note: `Foo` must be used in combination with a concrete type within the same module -error: aborting due to previous error +error: aborting due to 2 previous errors diff --git a/tests/ui/type-alias-impl-trait/normalize-alias-type.rs b/tests/ui/type-alias-impl-trait/normalize-alias-type.rs index 7c62002b931be..df241fbfe08c8 100644 --- a/tests/ui/type-alias-impl-trait/normalize-alias-type.rs +++ b/tests/ui/type-alias-impl-trait/normalize-alias-type.rs @@ -8,25 +8,32 @@ pub trait Tr { impl Tr for (u32,) { #[inline] - fn get(&self) -> u32 { self.0 } + fn get(&self) -> u32 { + self.0 + } } pub fn tr1() -> impl Tr { (32,) } -pub fn tr2() -> impl Tr { - struct Inner { - x: X, - } - type X = impl Tr; - impl Tr for Inner { - fn get(&self) -> u32 { - self.x.get() - } +struct Inner { + x: helper::X, +} +impl Tr for Inner { + fn get(&self) -> u32 { + self.x.get() } +} + +mod helper { + pub use super::*; + pub type X = impl Tr; - Inner { - x: tr1(), + pub fn tr2() -> impl Tr + where + X:, + { + Inner { x: tr1() } } } 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..097b78f7d03f5 100644 --- a/tests/ui/type-alias-impl-trait/outlives-bound-var.rs +++ b/tests/ui/type-alias-impl-trait/outlives-bound-var.rs @@ -5,8 +5,11 @@ // check-pass #![feature(type_alias_impl_trait)] -type Ty<'a> = impl Sized + 'a; -fn define<'a>() -> Ty<'a> {} +mod tait { + pub type Ty<'a> = impl Sized + 'a; + fn define<'a>() -> Ty<'a> {} +} +use tait::Ty; // Ty<'^0>: 'static fn test1(_: &'static fn(Ty<'_>)) {} @@ -15,4 +18,4 @@ fn test2() { None::<&fn(Ty<'_>)>; } -fn main() { } +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs index e221f4f3f55c8..38fb493b49893 100644 --- a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs +++ b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.rs @@ -9,26 +9,29 @@ struct A; impl Test for A {} struct B { - inner: T, + inner: T, } impl Test for B {} -type TestImpl = impl Test; +mod helper { + use super::*; + pub type TestImpl = impl Test; -fn test() -> TestImpl { - A -} + pub fn test() -> TestImpl { + A + } -fn make_option() -> Option { - Some(test()) -} + fn make_option2() -> Option { + let inner = make_option().unwrap(); -fn make_option2() -> Option { - let inner = make_option().unwrap(); + Some(B { inner }) + //~^ ERROR concrete type differs from previous defining opaque type use + } +} - Some(B { inner }) - //~^ ERROR concrete type differs from previous defining opaque type use +fn make_option() -> Option { + Some(helper::test()) } fn main() {} diff --git a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr index e4209643b7a3d..3a8e4c8310be3 100644 --- a/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr +++ b/tests/ui/type-alias-impl-trait/recursive-tait-conflicting-defn.stderr @@ -1,14 +1,14 @@ error: concrete type differs from previous defining opaque type use - --> $DIR/recursive-tait-conflicting-defn.rs:30:3 + --> $DIR/recursive-tait-conflicting-defn.rs:28:9 | -LL | Some(B { inner }) - | ^^^^^^^^^^^^^^^^^ expected `A`, got `B` +LL | Some(B { inner }) + | ^^^^^^^^^^^^^^^^^ expected `A`, got `B` | note: previous use here - --> $DIR/recursive-tait-conflicting-defn.rs:20:3 + --> $DIR/recursive-tait-conflicting-defn.rs:22:9 | -LL | A - | ^ +LL | A + | ^ error: aborting due to previous error diff --git a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.current.stderr b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.current.stderr index 844103d77a8ce..be18c2f7784df 100644 --- a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.current.stderr +++ b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.current.stderr @@ -1,21 +1,21 @@ error: internal compiler error: no errors encountered even though `delay_span_bug` issued -error: internal compiler error: {OpaqueTypeKey { def_id: DefId(get_rpit::{opaque#0}), args: [] }: OpaqueTypeDecl { hidden_type: OpaqueHiddenType { span: no-location (#0), ty: Alias(Opaque, AliasTy { args: [], def_id: DefId(Opaque::{opaque#0}) }) } }} +error: internal compiler error: {OpaqueTypeKey { def_id: DefId(helper::get_rpit::{opaque#0}), args: [] }: OpaqueTypeDecl { hidden_type: OpaqueHiddenType { span: no-location (#0), ty: Alias(Opaque, AliasTy { args: [], def_id: DefId(helper::Opaque::{opaque#0}) }) } }} | = -error: internal compiler error: error performing ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: ProvePredicate { predicate: Binder { value: ProjectionPredicate(AliasTy { args: [FnDef(DefId(get_rpit), []), ()], def_id: DefId(ops::function::FnOnce::Output) }, Term::Ty(Alias(Opaque, AliasTy { args: [], def_id: DefId(Opaque::{opaque#0}) }))), bound_vars: [] } } } - --> $DIR/rpit_tait_equality_in_canonical_query.rs:28:5 +error: internal compiler error: error performing ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing }, value: ProvePredicate { predicate: Binder { value: ProjectionPredicate(AliasTy { args: [FnDef(DefId(helper::get_rpit), []), ()], def_id: DefId(ops::function::FnOnce::Output) }, Term::Ty(Alias(Opaque, AliasTy { args: [], def_id: DefId(helper::Opaque::{opaque#0}) }))), bound_vars: [] } } } + --> $DIR/rpit_tait_equality_in_canonical_query.rs:27:9 | -LL | query(get_rpit); - | ^^^^^^^^^^^^^^^ +LL | super::query(get_rpit); + | ^^^^^^^^^^^^^^^^^^^^^^ | - --> $DIR/rpit_tait_equality_in_canonical_query.rs:28:5 + --> $DIR/rpit_tait_equality_in_canonical_query.rs:27:9 | -LL | query(get_rpit); - | ^^^^^^^^^^^^^^^ +LL | super::query(get_rpit); + | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs index 0f0002f7797e4..1cc1fc25144d3 100644 --- a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs +++ b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query.rs @@ -18,15 +18,19 @@ #![feature(type_alias_impl_trait)] -type Opaque = impl Sized; +mod helper { + pub type Opaque = impl Sized; -fn get_rpit() -> impl Clone {} + pub fn get_rpit() -> impl Clone {} -fn query(_: impl FnOnce() -> Opaque) {} - -fn test() -> Opaque { - query(get_rpit); - get_rpit() + fn test() -> Opaque { + super::query(get_rpit); + get_rpit() + } } +use helper::*; + +fn query(_: impl FnOnce() -> Opaque) {} + fn main() {} diff --git a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs index 9d7e647dd9434..1956f994a5429 100644 --- a/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs +++ b/tests/ui/type-alias-impl-trait/rpit_tait_equality_in_canonical_query_2.rs @@ -5,14 +5,17 @@ #![feature(type_alias_impl_trait)] -type Opaque = impl Sized; +mod helper { + pub type Opaque = impl Sized; -fn get_rpit() -> impl Sized {} + pub fn get_rpit() -> impl Sized {} -fn query(_: impl FnOnce() -> Opaque) {} - -fn test(_: Opaque) { - query(get_rpit); + fn test(_: Opaque) { + super::query(get_rpit); + } } +use helper::*; + +fn query(_: impl FnOnce() -> Opaque) {} 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..27f5799c38043 100644 --- a/tests/ui/type-alias-impl-trait/structural-match-no-leak.rs +++ b/tests/ui/type-alias-impl-trait/structural-match-no-leak.rs @@ -1,13 +1,15 @@ #![feature(type_alias_impl_trait)] -type Bar = impl Send; +mod bar { + pub type Bar = impl Send; -// While i32 is structural-match, we do not want to leak this information. -// (See https://github.com/rust-lang/rust/issues/72156) -const fn leak_free() -> Bar { - 7i32 + // While i32 is structural-match, we do not want to leak this information. + // (See https://github.com/rust-lang/rust/issues/72156) + pub const fn leak_free() -> Bar { + 7i32 + } } -const LEAK_FREE: Bar = leak_free(); +const LEAK_FREE: bar::Bar = bar::leak_free(); fn leak_free_test() { match LEAK_FREE { diff --git a/tests/ui/type-alias-impl-trait/structural-match-no-leak.stderr b/tests/ui/type-alias-impl-trait/structural-match-no-leak.stderr index dbc183f54f46b..86ef55d2f9421 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:16: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..5025959153976 100644 --- a/tests/ui/type-alias-impl-trait/structural-match.rs +++ b/tests/ui/type-alias-impl-trait/structural-match.rs @@ -1,19 +1,22 @@ #![feature(type_alias_impl_trait)] -type Foo = impl Send; +mod foo { + pub type Foo = impl Send; -// This is not structural-match -struct A; + // This is not structural-match + struct A; -const fn value() -> Foo { - A + pub const fn value() -> Foo { + A + } } +use foo::*; const VALUE: Foo = value(); fn test() { match VALUE { VALUE => (), - //~^ `Foo` cannot be used in patterns + //~^ `foo::Foo` cannot be used in patterns _ => (), } } diff --git a/tests/ui/type-alias-impl-trait/structural-match.stderr b/tests/ui/type-alias-impl-trait/structural-match.stderr index 61287f268066e..396072c53c9a3 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 +error: `foo::Foo` cannot be used in patterns + --> $DIR/structural-match.rs:18:9 | LL | VALUE => (), | ^^^^^ 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 4e7388517a5eb..cbd91066c49da 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 @@ -1,5 +1,3 @@ -// check-pass - #![feature(type_alias_impl_trait)] // Regression test for issue #61863 @@ -18,6 +16,7 @@ fn bla() -> TE { } fn bla2() -> TE { + //~^ ERROR: item does not constrain `TE::{opaque#0}`, but has it in its signature bla() } diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.stderr b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.stderr new file mode 100644 index 0000000000000..a00bc9c83f0f8 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-fns.stderr @@ -0,0 +1,15 @@ +error: item does not constrain `TE::{opaque#0}`, but has it in its signature + --> $DIR/type-alias-impl-trait-fns.rs:18:4 + | +LL | fn bla2() -> TE { + | ^^^^ + | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/type-alias-impl-trait-fns.rs:23:11 + | +LL | type TE = impl MyTrait; + | ^^^^^^^^^^^^ + +error: aborting due to previous error + 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..a04182eb9bc83 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 @@ -3,11 +3,19 @@ #![feature(type_alias_impl_trait)] #![allow(dead_code)] -pub trait MyTrait {} +mod foo { + pub trait MyTrait {} -impl MyTrait for bool {} + impl MyTrait for bool {} -type Foo = impl MyTrait; + pub type Foo = impl MyTrait; + + pub fn make_foo() -> Foo { + true + } +} + +use foo::*; struct Blah { my_foo: Foo, @@ -23,8 +31,4 @@ impl Blah { } } -fn make_foo() -> Foo { - true -} - fn main() {} diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.rs index e5e7fb677ede9..a1cc2d923eb4d 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.rs +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.rs @@ -4,9 +4,8 @@ type Foo = impl Fn() -> Foo; //~^ ERROR: unconstrained opaque type fn crash(x: Foo) -> Foo { + //~^ ERROR item does not constrain `Foo::{opaque#0}` x } -fn main() { - -} +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.stderr b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.stderr index a770eeac39b7d..d7cf0a01ef869 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.stderr +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error.stderr @@ -1,3 +1,16 @@ +error: item does not constrain `Foo::{opaque#0}`, but has it in its signature + --> $DIR/type-alias-impl-trait-with-cycle-error.rs:6:4 + | +LL | fn crash(x: Foo) -> Foo { + | ^^^^^ + | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/type-alias-impl-trait-with-cycle-error.rs:3:12 + | +LL | type Foo = impl Fn() -> Foo; + | ^^^^^^^^^^^^^^^^ + error: unconstrained opaque type --> $DIR/type-alias-impl-trait-with-cycle-error.rs:3:12 | @@ -6,5 +19,5 @@ LL | type Foo = impl Fn() -> Foo; | = note: `Foo` must be used in combination with a concrete type within the same module -error: aborting due to previous error +error: aborting due to 2 previous errors diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.rs b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.rs index 7c7a1b405bcdc..9e5bd47fe9b7f 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.rs +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.rs @@ -8,6 +8,7 @@ type Foo = impl Bar; //~^ ERROR: unconstrained opaque type fn crash(x: Foo) -> Foo { + //~^ ERROR: does not constrain `Foo::{opaque#0}`, but has it in its signature x } diff --git a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.stderr b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.stderr index 3f3699ce5324a..2842c20031a00 100644 --- a/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.stderr +++ b/tests/ui/type-alias-impl-trait/type-alias-impl-trait-with-cycle-error2.stderr @@ -1,3 +1,16 @@ +error: item does not constrain `Foo::{opaque#0}`, but has it in its signature + --> $DIR/type-alias-impl-trait-with-cycle-error2.rs:10:4 + | +LL | fn crash(x: Foo) -> Foo { + | ^^^^^ + | + = note: consider moving the opaque type's declaration and defining uses into a separate module +note: this opaque type is in the signature + --> $DIR/type-alias-impl-trait-with-cycle-error2.rs:7:12 + | +LL | type Foo = impl Bar; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + error: unconstrained opaque type --> $DIR/type-alias-impl-trait-with-cycle-error2.rs:7:12 | @@ -6,5 +19,5 @@ LL | type Foo = impl Bar; | = note: `Foo` must be used in combination with a concrete type within the same module -error: aborting due to previous error +error: aborting due to 2 previous errors 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..41facf28582d8 100644 --- a/tests/ui/type-alias-impl-trait/unbounded_opaque_type.rs +++ b/tests/ui/type-alias-impl-trait/unbounded_opaque_type.rs @@ -1,10 +1,15 @@ // check-pass #![feature(type_alias_impl_trait)] -type Opaque = impl Sized; -fn defining() -> Opaque {} -struct Ss<'a, T>(&'a Opaque); +mod opaque { + pub type Opaque = impl Sized; + fn defining() -> Opaque {} +} + +use opaque::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 diff --git a/tests/ui/type-alias-impl-trait/unnameable_type.rs b/tests/ui/type-alias-impl-trait/unnameable_type.rs index 1739ab0063fa9..5813f529dea19 100644 --- a/tests/ui/type-alias-impl-trait/unnameable_type.rs +++ b/tests/ui/type-alias-impl-trait/unnameable_type.rs @@ -15,10 +15,11 @@ use private::Trait; // downstream type MyPrivate = impl Sized; -//~^ ERROR: unconstrained opaque type impl Trait for u32 { - fn dont_define_this(_private: MyPrivate) {} - //~^ ERROR: incompatible type for trait + fn dont_define_this(private: MyPrivate) { + //~^ ERROR: incompatible type for trait + let _: () = private; + } } fn main() {} diff --git a/tests/ui/type-alias-impl-trait/unnameable_type.stderr b/tests/ui/type-alias-impl-trait/unnameable_type.stderr index e9032433494a6..4a7b0ba3f2756 100644 --- a/tests/ui/type-alias-impl-trait/unnameable_type.stderr +++ b/tests/ui/type-alias-impl-trait/unnameable_type.stderr @@ -1,22 +1,14 @@ -error: unconstrained opaque type - --> $DIR/unnameable_type.rs:17:18 - | -LL | type MyPrivate = impl Sized; - | ^^^^^^^^^^ - | - = note: `MyPrivate` must be used in combination with a concrete type within the same module - error[E0053]: method `dont_define_this` has an incompatible type for trait - --> $DIR/unnameable_type.rs:20:35 + --> $DIR/unnameable_type.rs:19:34 | LL | type MyPrivate = impl Sized; | ---------- the found opaque type -... -LL | fn dont_define_this(_private: MyPrivate) {} - | ^^^^^^^^^ - | | - | expected `Private`, found opaque type - | help: change the parameter type to match the trait: `Private` +LL | impl Trait for u32 { +LL | fn dont_define_this(private: MyPrivate) { + | ^^^^^^^^^ + | | + | expected `Private`, found opaque type + | help: change the parameter type to match the trait: `Private` | note: type in trait --> $DIR/unnameable_type.rs:10:39 @@ -26,6 +18,6 @@ LL | fn dont_define_this(_private: Private) {} = note: expected signature `fn(Private)` found signature `fn(MyPrivate)` -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0053`.