diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 7b9f61d7ab213..334e0541c765d 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -56,6 +56,7 @@ pub fn provide(providers: &mut Providers) { resolve_bound_vars::provide(providers); *providers = Providers { type_of: type_of::type_of, + type_of_opaque: type_of::type_of_opaque, item_bounds: item_bounds::item_bounds, explicit_item_bounds: item_bounds::explicit_item_bounds, generics_of: generics_of::generics_of, diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 2bbdbe3a1f624..d12337687e2e1 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -1,7 +1,8 @@ use rustc_errors::{Applicability, StashKey}; use rustc_hir as hir; -use rustc_hir::def_id::LocalDefId; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::HirId; +use rustc_middle::query::plumbing::CyclePlaceholder; use rustc_middle::ty::print::with_forced_trimmed_paths; use rustc_middle::ty::util::IntTypeExt; use rustc_middle::ty::{self, ImplTraitInTraitData, IsSuggestable, Ty, TyCtxt, TypeVisitableExt}; @@ -388,86 +389,62 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder { - match item.kind { - ItemKind::Static(ty, .., body_id) => { - if is_suggestable_infer_ty(ty) { - infer_placeholder_type( - tcx, - def_id, - body_id, - ty.span, - item.ident, - "static variable", - ) - } else { - icx.to_ty(ty) - } - } - ItemKind::Const(ty, _, body_id) => { - if is_suggestable_infer_ty(ty) { - infer_placeholder_type( - tcx, def_id, body_id, ty.span, item.ident, "constant", - ) - } else { - icx.to_ty(ty) - } - } - ItemKind::TyAlias(self_ty, _) => icx.to_ty(self_ty), - ItemKind::Impl(hir::Impl { self_ty, .. }) => match self_ty.find_self_aliases() { - spans if spans.len() > 0 => { - let guar = tcx.sess.emit_err(crate::errors::SelfInImplSelf { - span: spans.into(), - note: (), - }); - Ty::new_error(tcx, guar) - } - _ => icx.to_ty(*self_ty), - }, - ItemKind::Fn(..) => { - let args = ty::GenericArgs::identity_for_item(tcx, def_id); - Ty::new_fn_def(tcx, def_id.to_def_id(), args) - } - ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => { - let def = tcx.adt_def(def_id); - let args = ty::GenericArgs::identity_for_item(tcx, def_id); - Ty::new_adt(tcx, def, args) + Node::Item(item) => match item.kind { + ItemKind::Static(ty, .., body_id) => { + if is_suggestable_infer_ty(ty) { + infer_placeholder_type( + tcx, + def_id, + body_id, + ty.span, + item.ident, + "static variable", + ) + } else { + icx.to_ty(ty) } - ItemKind::OpaqueTy(OpaqueTy { - origin: hir::OpaqueTyOrigin::TyAlias { .. }, - .. - }) => opaque::find_opaque_ty_constraints_for_tait(tcx, def_id), - // Opaque types desugared from `impl Trait`. - ItemKind::OpaqueTy(&OpaqueTy { - origin: - hir::OpaqueTyOrigin::FnReturn(owner) | hir::OpaqueTyOrigin::AsyncFn(owner), - in_trait, - .. - }) => { - if in_trait && !tcx.defaultness(owner).has_value() { - span_bug!( - tcx.def_span(def_id), - "tried to get type of this RPITIT with no definition" - ); - } - opaque::find_opaque_ty_constraints_for_rpit(tcx, def_id, owner) + } + ItemKind::Const(ty, _, body_id) => { + if is_suggestable_infer_ty(ty) { + infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident, "constant") + } else { + icx.to_ty(ty) } - ItemKind::Trait(..) - | ItemKind::TraitAlias(..) - | ItemKind::Macro(..) - | ItemKind::Mod(..) - | ItemKind::ForeignMod { .. } - | ItemKind::GlobalAsm(..) - | ItemKind::ExternCrate(..) - | ItemKind::Use(..) => { - span_bug!( - item.span, - "compute_type_of_item: unexpected item type: {:?}", - item.kind - ); + } + ItemKind::TyAlias(self_ty, _) => icx.to_ty(self_ty), + ItemKind::Impl(hir::Impl { self_ty, .. }) => match self_ty.find_self_aliases() { + spans if spans.len() > 0 => { + let guar = tcx + .sess + .emit_err(crate::errors::SelfInImplSelf { span: spans.into(), note: () }); + Ty::new_error(tcx, guar) } + _ => icx.to_ty(*self_ty), + }, + ItemKind::Fn(..) => { + let args = ty::GenericArgs::identity_for_item(tcx, def_id); + Ty::new_fn_def(tcx, def_id.to_def_id(), args) } - } + ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => { + let def = tcx.adt_def(def_id); + let args = ty::GenericArgs::identity_for_item(tcx, def_id); + Ty::new_adt(tcx, def, args) + } + ItemKind::OpaqueTy(..) => tcx.type_of_opaque(def_id).map_or_else( + |CyclePlaceholder(guar)| Ty::new_error(tcx, guar), + |ty| ty.instantiate_identity(), + ), + ItemKind::Trait(..) + | ItemKind::TraitAlias(..) + | ItemKind::Macro(..) + | ItemKind::Mod(..) + | ItemKind::ForeignMod { .. } + | ItemKind::GlobalAsm(..) + | ItemKind::ExternCrate(..) + | ItemKind::Use(..) => { + span_bug!(item.span, "compute_type_of_item: unexpected item type: {:?}", item.kind); + } + }, Node::ForeignItem(foreign_item) => match foreign_item.kind { ForeignItemKind::Fn(..) => { @@ -514,6 +491,51 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder, + def_id: DefId, +) -> Result>, CyclePlaceholder> { + if let Some(def_id) = def_id.as_local() { + use rustc_hir::*; + + let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); + Ok(ty::EarlyBinder::bind(match tcx.hir().get(hir_id) { + Node::Item(item) => match item.kind { + ItemKind::OpaqueTy(OpaqueTy { + origin: hir::OpaqueTyOrigin::TyAlias { .. }, + .. + }) => opaque::find_opaque_ty_constraints_for_tait(tcx, def_id), + // Opaque types desugared from `impl Trait`. + ItemKind::OpaqueTy(&OpaqueTy { + origin: + hir::OpaqueTyOrigin::FnReturn(owner) | hir::OpaqueTyOrigin::AsyncFn(owner), + in_trait, + .. + }) => { + if in_trait && !tcx.defaultness(owner).has_value() { + span_bug!( + tcx.def_span(def_id), + "tried to get type of this RPITIT with no definition" + ); + } + opaque::find_opaque_ty_constraints_for_rpit(tcx, def_id, owner) + } + _ => { + span_bug!(item.span, "type_of_opaque: unexpected item type: {:?}", item.kind); + } + }, + + x => { + bug!("unexpected sort of node in type_of_opaque(): {:?}", x); + } + })) + } else { + // Foreign opaque type will go through the foreign provider + // and load the type from metadata. + Ok(tcx.type_of(def_id)) + } +} + fn infer_placeholder_type<'a>( tcx: TyCtxt<'a>, def_id: LocalDefId, diff --git a/compiler/rustc_middle/src/query/erase.rs b/compiler/rustc_middle/src/query/erase.rs index 348f79ed6a800..9b666222ad09e 100644 --- a/compiler/rustc_middle/src/query/erase.rs +++ b/compiler/rustc_middle/src/query/erase.rs @@ -1,4 +1,5 @@ use crate::mir; +use crate::query::CyclePlaceholder; use crate::traits; use crate::ty::{self, Ty}; use std::mem::{size_of, transmute_copy, MaybeUninit}; @@ -142,6 +143,10 @@ impl EraseType for Result<&'_ ty::List>, ty::util::AlwaysRequiresDrop> { [u8; size_of::>, ty::util::AlwaysRequiresDrop>>()]; } +impl EraseType for Result>, CyclePlaceholder> { + type Result = [u8; size_of::>, CyclePlaceholder>>()]; +} + impl EraseType for Option<&'_ T> { type Result = [u8; size_of::>()]; } diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 94ae0dcb51728..bf340846f108c 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -26,7 +26,7 @@ use crate::mir::interpret::{ use crate::mir::interpret::{LitToConstError, LitToConstInput}; use crate::mir::mono::CodegenUnit; use crate::query::erase::{erase, restore, Erase}; -use crate::query::plumbing::{query_ensure, query_get_at, DynamicQuery}; +use crate::query::plumbing::{query_ensure, query_get_at, CyclePlaceholder, DynamicQuery}; use crate::thir; use crate::traits::query::{ CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal, @@ -243,6 +243,16 @@ rustc_queries! { feedable } + /// Specialized instance of `type_of` that detects cycles that are due to + /// revealing opaque because of an auto trait bound. Unless `CyclePlaceholder` needs + /// to be handled separately, call `type_of` instead. + query type_of_opaque(key: DefId) -> Result>, CyclePlaceholder> { + desc { |tcx| + "computing type of opaque `{path}`", + path = tcx.def_path_str(key), + } + } + query collect_return_position_impl_trait_in_trait_tys(key: DefId) -> Result<&'tcx FxHashMap>>, ErrorGuaranteed> { diff --git a/compiler/rustc_middle/src/query/plumbing.rs b/compiler/rustc_middle/src/query/plumbing.rs index a1aac2846210d..a342b5231e9a5 100644 --- a/compiler/rustc_middle/src/query/plumbing.rs +++ b/compiler/rustc_middle/src/query/plumbing.rs @@ -19,7 +19,7 @@ use rustc_query_system::dep_graph::SerializedDepNodeIndex; pub(crate) use rustc_query_system::query::QueryJobId; use rustc_query_system::query::*; use rustc_query_system::HandleCycleError; -use rustc_span::{Span, DUMMY_SP}; +use rustc_span::{ErrorGuaranteed, Span, DUMMY_SP}; use std::ops::Deref; pub struct QueryKeyStringCache { @@ -52,7 +52,8 @@ pub struct DynamicQuery<'tcx, C: QueryCache> { pub loadable_from_disk: fn(tcx: TyCtxt<'tcx>, key: &C::Key, index: SerializedDepNodeIndex) -> bool, pub hash_result: HashResult, - pub value_from_cycle_error: fn(tcx: TyCtxt<'tcx>, cycle: &[QueryInfo]) -> C::Value, + pub value_from_cycle_error: + fn(tcx: TyCtxt<'tcx>, cycle: &[QueryInfo], guar: ErrorGuaranteed) -> C::Value, pub format_value: fn(&C::Value) -> String, } @@ -629,3 +630,6 @@ impl<'tcx> TyCtxtAt<'tcx> { .unwrap_or_else(|| bug!("def_kind: unsupported node: {:?}", def_id)) } } + +#[derive(Copy, Clone, Debug, HashStable)] +pub struct CyclePlaceholder(pub ErrorGuaranteed); diff --git a/compiler/rustc_middle/src/values.rs b/compiler/rustc_middle/src/values.rs index 384a368434a23..962faf56cb87d 100644 --- a/compiler/rustc_middle/src/values.rs +++ b/compiler/rustc_middle/src/values.rs @@ -1,4 +1,5 @@ use crate::dep_graph::DepKind; +use crate::query::plumbing::CyclePlaceholder; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{pluralize, struct_span_err, Applicability, MultiSpan}; use rustc_hir as hir; @@ -8,20 +9,38 @@ use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_query_system::query::QueryInfo; use rustc_query_system::Value; use rustc_span::def_id::LocalDefId; -use rustc_span::Span; +use rustc_span::{ErrorGuaranteed, Span}; use std::fmt::Write; impl<'tcx> Value, DepKind> for Ty<'_> { - fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &[QueryInfo]) -> Self { + fn from_cycle_error( + tcx: TyCtxt<'tcx>, + _: &[QueryInfo], + guar: ErrorGuaranteed, + ) -> Self { // SAFETY: This is never called when `Self` is not `Ty<'tcx>`. // FIXME: Represent the above fact in the trait system somehow. - unsafe { std::mem::transmute::, Ty<'_>>(Ty::new_misc_error(tcx)) } + unsafe { std::mem::transmute::, Ty<'_>>(Ty::new_error(tcx, guar)) } + } +} + +impl<'tcx> Value, DepKind> for Result>, CyclePlaceholder> { + fn from_cycle_error( + _tcx: TyCtxt<'tcx>, + _: &[QueryInfo], + guar: ErrorGuaranteed, + ) -> Self { + Err(CyclePlaceholder(guar)) } } impl<'tcx> Value, DepKind> for ty::SymbolName<'_> { - fn from_cycle_error(tcx: TyCtxt<'tcx>, _: &[QueryInfo]) -> Self { + fn from_cycle_error( + tcx: TyCtxt<'tcx>, + _: &[QueryInfo], + _guar: ErrorGuaranteed, + ) -> Self { // SAFETY: This is never called when `Self` is not `SymbolName<'tcx>`. // FIXME: Represent the above fact in the trait system somehow. unsafe { @@ -33,8 +52,12 @@ impl<'tcx> Value, DepKind> for ty::SymbolName<'_> { } impl<'tcx> Value, DepKind> for ty::Binder<'_, ty::FnSig<'_>> { - fn from_cycle_error(tcx: TyCtxt<'tcx>, stack: &[QueryInfo]) -> Self { - let err = Ty::new_misc_error(tcx); + fn from_cycle_error( + tcx: TyCtxt<'tcx>, + stack: &[QueryInfo], + guar: ErrorGuaranteed, + ) -> Self { + let err = Ty::new_error(tcx, guar); let arity = if let Some(frame) = stack.get(0) && frame.query.dep_kind == DepKind::fn_sig @@ -63,7 +86,11 @@ impl<'tcx> Value, DepKind> for ty::Binder<'_, ty::FnSig<'_>> { } impl<'tcx> Value, DepKind> for Representability { - fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle: &[QueryInfo]) -> Self { + fn from_cycle_error( + tcx: TyCtxt<'tcx>, + cycle: &[QueryInfo], + _guar: ErrorGuaranteed, + ) -> Self { let mut item_and_field_ids = Vec::new(); let mut representable_ids = FxHashSet::default(); for info in cycle { @@ -95,22 +122,35 @@ impl<'tcx> Value, DepKind> for Representability { } impl<'tcx> Value, DepKind> for ty::EarlyBinder> { - fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle: &[QueryInfo]) -> Self { - ty::EarlyBinder::bind(Ty::from_cycle_error(tcx, cycle)) + fn from_cycle_error( + tcx: TyCtxt<'tcx>, + cycle: &[QueryInfo], + guar: ErrorGuaranteed, + ) -> Self { + ty::EarlyBinder::bind(Ty::from_cycle_error(tcx, cycle, guar)) } } impl<'tcx> Value, DepKind> for ty::EarlyBinder>> { - fn from_cycle_error(tcx: TyCtxt<'tcx>, cycle: &[QueryInfo]) -> Self { - ty::EarlyBinder::bind(ty::Binder::from_cycle_error(tcx, cycle)) + fn from_cycle_error( + tcx: TyCtxt<'tcx>, + cycle: &[QueryInfo], + guar: ErrorGuaranteed, + ) -> Self { + ty::EarlyBinder::bind(ty::Binder::from_cycle_error(tcx, cycle, guar)) } } impl<'tcx, T> Value, DepKind> for Result> { - fn from_cycle_error(_tcx: TyCtxt<'tcx>, _cycle: &[QueryInfo]) -> Self { + fn from_cycle_error( + _tcx: TyCtxt<'tcx>, + _cycle: &[QueryInfo], + _guar: ErrorGuaranteed, + ) -> Self { // tcx.arena.alloc cannot be used because we are not allowed to use &'tcx LayoutError under // min_specialization. Since this is an error path anyways, leaking doesn't matter (and really, // tcx.arena.alloc is pretty much equal to leaking). + // FIXME: `Cycle` should carry the ErrorGuaranteed Err(Box::leak(Box::new(ty::layout::LayoutError::Cycle))) } } diff --git a/compiler/rustc_query_impl/src/lib.rs b/compiler/rustc_query_impl/src/lib.rs index 775870106b199..9a0fcbb37a724 100644 --- a/compiler/rustc_query_impl/src/lib.rs +++ b/compiler/rustc_query_impl/src/lib.rs @@ -41,7 +41,7 @@ use rustc_query_system::query::{ }; use rustc_query_system::HandleCycleError; use rustc_query_system::Value; -use rustc_span::Span; +use rustc_span::{ErrorGuaranteed, Span}; #[macro_use] mod plumbing; @@ -146,8 +146,9 @@ where self, tcx: TyCtxt<'tcx>, cycle: &[QueryInfo], + guar: ErrorGuaranteed, ) -> Self::Value { - (self.dynamic.value_from_cycle_error)(tcx, cycle) + (self.dynamic.value_from_cycle_error)(tcx, cycle, guar) } #[inline(always)] diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index def6ac280b804..a30ea7c1ddcaf 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -605,8 +605,8 @@ macro_rules! define_queries { } { |_tcx, _key, _prev_index, _index| None }), - value_from_cycle_error: |tcx, cycle| { - let result: queries::$name::Value<'tcx> = Value::from_cycle_error(tcx, cycle); + value_from_cycle_error: |tcx, cycle, guar| { + let result: queries::$name::Value<'tcx> = Value::from_cycle_error(tcx, cycle, guar); erase(result) }, loadable_from_disk: |_tcx, _key, _index| { diff --git a/compiler/rustc_query_system/src/query/config.rs b/compiler/rustc_query_system/src/query/config.rs index 7e47d70120544..d14c6315dc10d 100644 --- a/compiler/rustc_query_system/src/query/config.rs +++ b/compiler/rustc_query_system/src/query/config.rs @@ -8,6 +8,7 @@ use crate::query::DepNodeIndex; use crate::query::{QueryContext, QueryInfo, QueryState}; use rustc_data_structures::fingerprint::Fingerprint; +use rustc_span::ErrorGuaranteed; use std::fmt::Debug; use std::hash::Hash; @@ -57,6 +58,7 @@ pub trait QueryConfig: Copy { self, tcx: Qcx::DepContext, cycle: &[QueryInfo], + guar: ErrorGuaranteed, ) -> Self::Value; fn anon(self) -> bool; diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index 575921b333701..85c9b72730820 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -148,8 +148,8 @@ where use HandleCycleError::*; match query.handle_cycle_error() { Error => { - error.emit(); - query.value_from_cycle_error(*qcx.dep_context(), &cycle_error.cycle) + let guar = error.emit(); + query.value_from_cycle_error(*qcx.dep_context(), &cycle_error.cycle, guar) } Fatal => { error.emit(); @@ -157,8 +157,8 @@ where unreachable!() } DelayBug => { - error.delay_as_bug(); - query.value_from_cycle_error(*qcx.dep_context(), &cycle_error.cycle) + let guar = error.delay_as_bug(); + query.value_from_cycle_error(*qcx.dep_context(), &cycle_error.cycle, guar) } } } diff --git a/compiler/rustc_query_system/src/values.rs b/compiler/rustc_query_system/src/values.rs index ce551078cc028..07c28fdb73b2e 100644 --- a/compiler/rustc_query_system/src/values.rs +++ b/compiler/rustc_query_system/src/values.rs @@ -1,12 +1,14 @@ +use rustc_span::ErrorGuaranteed; + use crate::dep_graph::{DepContext, DepKind}; use crate::query::QueryInfo; pub trait Value: Sized { - fn from_cycle_error(tcx: Tcx, cycle: &[QueryInfo]) -> Self; + fn from_cycle_error(tcx: Tcx, cycle: &[QueryInfo], guar: ErrorGuaranteed) -> Self; } impl Value for T { - default fn from_cycle_error(tcx: Tcx, cycle: &[QueryInfo]) -> T { + default fn from_cycle_error(tcx: Tcx, cycle: &[QueryInfo], _guar: ErrorGuaranteed) -> T { tcx.sess().abort_if_errors(); // Ideally we would use `bug!` here. But bug! is only defined in rustc_middle, and it's // non-trivial to define it earlier. diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 19385e2d7f260..7e4d926dc8dad 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2346,14 +2346,15 @@ impl<'tcx> SelectionContext<'_, 'tcx> { } ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { - let ty = self.tcx().type_of(def_id); - if ty.skip_binder().references_error() { - return Err(SelectionError::OpaqueTypeAutoTraitLeakageUnknown(def_id)); - } // We can resolve the `impl Trait` to its concrete type, // which enforces a DAG between the functions requiring // the auto trait bounds in question. - t.rebind(vec![ty.instantiate(self.tcx(), args)]) + match self.tcx().type_of_opaque(def_id) { + Ok(ty) => t.rebind(vec![ty.instantiate(self.tcx(), args)]), + Err(_) => { + return Err(SelectionError::OpaqueTypeAutoTraitLeakageUnknown(def_id)); + } + } } }) } diff --git a/tests/ui/async-await/future-contains-err-issue-115188.rs b/tests/ui/async-await/future-contains-err-issue-115188.rs new file mode 100644 index 0000000000000..bf643c9267173 --- /dev/null +++ b/tests/ui/async-await/future-contains-err-issue-115188.rs @@ -0,0 +1,17 @@ +// edition: 2021 + +// Makes sure we don't spew a bunch of unrelated opaque errors when the reason +// for this error is just a missing struct field in `foo`. + +async fn foo() { + let y = Wrapper { }; + //~^ ERROR missing field `t` in initializer of `Wrapper<_>` +} + +struct Wrapper { t: T } + +fn is_send(_: T) {} + +fn main() { + is_send(foo()); +} diff --git a/tests/ui/async-await/future-contains-err-issue-115188.stderr b/tests/ui/async-await/future-contains-err-issue-115188.stderr new file mode 100644 index 0000000000000..8fd2550c1c77a --- /dev/null +++ b/tests/ui/async-await/future-contains-err-issue-115188.stderr @@ -0,0 +1,9 @@ +error[E0063]: missing field `t` in initializer of `Wrapper<_>` + --> $DIR/future-contains-err-issue-115188.rs:7:13 + | +LL | let y = Wrapper { }; + | ^^^^^^^ missing `t` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0063`. diff --git a/tests/ui/generator/layout-error.rs b/tests/ui/generator/layout-error.rs index 44cfc1d70ddc0..7c3d187409a2f 100644 --- a/tests/ui/generator/layout-error.rs +++ b/tests/ui/generator/layout-error.rs @@ -24,6 +24,5 @@ fn main() { type F = impl Future; // Check that statics are inhabited computes they layout. static POOL: Task = Task::new(); - //~^ ERROR: cannot check whether the hidden type of `layout_error[b009]::main::F::{opaque#0}` satisfies auto traits Task::spawn(&POOL, || cb()); } diff --git a/tests/ui/generator/layout-error.stderr b/tests/ui/generator/layout-error.stderr index ea3b25551c429..b1a258f4f2ca7 100644 --- a/tests/ui/generator/layout-error.stderr +++ b/tests/ui/generator/layout-error.stderr @@ -4,24 +4,6 @@ error[E0425]: cannot find value `Foo` in this scope LL | let a = Foo; | ^^^ not found in this scope -error: cannot check whether the hidden type of `layout_error[b009]::main::F::{opaque#0}` satisfies auto traits - --> $DIR/layout-error.rs:26:18 - | -LL | static POOL: Task = Task::new(); - | ^^^^^^^ - | -note: opaque type is declared here - --> $DIR/layout-error.rs:24:14 - | -LL | type F = impl Future; - | ^^^^^^^^^^^ -note: required because it appears within the type `Task` - --> $DIR/layout-error.rs:9:12 - | -LL | pub struct Task(F); - | ^^^^ - = note: shared static variables must have a type that implements `Sync` - -error: aborting due to 2 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/impl-trait/auto-trait-leak.rs b/tests/ui/impl-trait/auto-trait-leak.rs index d71c0987935ad..1f90292f45790 100644 --- a/tests/ui/impl-trait/auto-trait-leak.rs +++ b/tests/ui/impl-trait/auto-trait-leak.rs @@ -12,7 +12,6 @@ fn cycle1() -> impl Clone { //~^ ERROR cycle detected //~| ERROR cycle detected send(cycle2().clone()); - //~^ ERROR: cannot check whether the hidden type of opaque type satisfies auto traits Rc::new(Cell::new(5)) } diff --git a/tests/ui/impl-trait/auto-trait-leak.stderr b/tests/ui/impl-trait/auto-trait-leak.stderr index a024cff0b8da6..62341f6de0cb2 100644 --- a/tests/ui/impl-trait/auto-trait-leak.stderr +++ b/tests/ui/impl-trait/auto-trait-leak.stderr @@ -1,4 +1,4 @@ -error[E0391]: cycle detected when computing type of `cycle1::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `cycle1::{opaque#0}` --> $DIR/auto-trait-leak.rs:11:16 | LL | fn cycle1() -> impl Clone { @@ -10,32 +10,26 @@ note: ...which requires type-checking `cycle1`... LL | send(cycle2().clone()); | ^^^^ = note: ...which requires evaluating trait selection obligation `cycle2::{opaque#0}: core::marker::Send`... -note: ...which requires computing type of `cycle2::{opaque#0}`... - --> $DIR/auto-trait-leak.rs:20:16 +note: ...which requires computing type of opaque `cycle2::{opaque#0}`... + --> $DIR/auto-trait-leak.rs:19:16 | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^ note: ...which requires type-checking `cycle2`... - --> $DIR/auto-trait-leak.rs:21:5 + --> $DIR/auto-trait-leak.rs:20:5 | LL | send(cycle1().clone()); | ^^^^ = note: ...which requires evaluating trait selection obligation `cycle1::{opaque#0}: core::marker::Send`... - = note: ...which again requires computing type of `cycle1::{opaque#0}`, completing the cycle -note: cycle used when checking item types in top-level module - --> $DIR/auto-trait-leak.rs:1:1 - | -LL | / use std::cell::Cell; -LL | | use std::rc::Rc; -LL | | -LL | | fn send(_: T) {} -... | -LL | | Rc::new(String::from("foo")) -LL | | } - | |_^ + = note: ...which again requires computing type of opaque `cycle1::{opaque#0}`, completing the cycle +note: cycle used when computing type of `cycle1::{opaque#0}` + --> $DIR/auto-trait-leak.rs:11:16 + | +LL | fn cycle1() -> impl Clone { + | ^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information -error[E0391]: cycle detected when computing type of `cycle1::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `cycle1::{opaque#0}` --> $DIR/auto-trait-leak.rs:11:16 | LL | fn cycle1() -> impl Clone { @@ -47,32 +41,26 @@ note: ...which requires type-checking `cycle1`... LL | send(cycle2().clone()); | ^^^^ = note: ...which requires evaluating trait selection obligation `cycle2::{opaque#0}: core::marker::Send`... -note: ...which requires computing type of `cycle2::{opaque#0}`... - --> $DIR/auto-trait-leak.rs:20:16 +note: ...which requires computing type of opaque `cycle2::{opaque#0}`... + --> $DIR/auto-trait-leak.rs:19:16 | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^ note: ...which requires type-checking `cycle2`... - --> $DIR/auto-trait-leak.rs:20:1 + --> $DIR/auto-trait-leak.rs:19:1 | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ - = note: ...which again requires computing type of `cycle1::{opaque#0}`, completing the cycle -note: cycle used when checking item types in top-level module - --> $DIR/auto-trait-leak.rs:1:1 - | -LL | / use std::cell::Cell; -LL | | use std::rc::Rc; -LL | | -LL | | fn send(_: T) {} -... | -LL | | Rc::new(String::from("foo")) -LL | | } - | |_^ + = note: ...which again requires computing type of opaque `cycle1::{opaque#0}`, completing the cycle +note: cycle used when computing type of `cycle1::{opaque#0}` + --> $DIR/auto-trait-leak.rs:11:16 + | +LL | fn cycle1() -> impl Clone { + | ^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: cannot check whether the hidden type of opaque type satisfies auto traits - --> $DIR/auto-trait-leak.rs:21:10 + --> $DIR/auto-trait-leak.rs:20:10 | LL | send(cycle1().clone()); | ---- ^^^^^^^^^^^^^^^^ @@ -85,7 +73,7 @@ note: opaque type is declared here LL | fn cycle1() -> impl Clone { | ^^^^^^^^^^ note: this item depends on auto traits of the hidden type, but may also be registering the hidden type. This is not supported right now. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule - --> $DIR/auto-trait-leak.rs:20:4 + --> $DIR/auto-trait-leak.rs:19:4 | LL | fn cycle2() -> impl Clone { | ^^^^^^ @@ -95,30 +83,6 @@ note: required by a bound in `send` LL | fn send(_: T) {} | ^^^^ required by this bound in `send` -error: cannot check whether the hidden type of opaque type satisfies auto traits - --> $DIR/auto-trait-leak.rs:14:10 - | -LL | send(cycle2().clone()); - | ---- ^^^^^^^^^^^^^^^^ - | | - | required by a bound introduced by this call - | -note: opaque type is declared here - --> $DIR/auto-trait-leak.rs:20:16 - | -LL | fn cycle2() -> impl Clone { - | ^^^^^^^^^^ -note: this item depends on auto traits of the hidden type, but may also be registering the hidden type. This is not supported right now. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule - --> $DIR/auto-trait-leak.rs:11:4 - | -LL | fn cycle1() -> impl Clone { - | ^^^^^^ -note: required by a bound in `send` - --> $DIR/auto-trait-leak.rs:4:12 - | -LL | fn send(_: T) {} - | ^^^^ required by this bound in `send` - -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/impl-trait/issue-103181-2.rs b/tests/ui/impl-trait/issue-103181-2.rs index 34deb98beefe8..b43ac45075e2b 100644 --- a/tests/ui/impl-trait/issue-103181-2.rs +++ b/tests/ui/impl-trait/issue-103181-2.rs @@ -24,8 +24,6 @@ where B: Send, // <- a second bound { normalize(broken_fut(), ()); - //~^ ERROR: cannot check whether the hidden type of opaque type satisfies auto traits - //~| ERROR: cannot check whether the hidden type of opaque type satisfies auto traits } fn main() {} diff --git a/tests/ui/impl-trait/issue-103181-2.stderr b/tests/ui/impl-trait/issue-103181-2.stderr index cb5253ea6cd88..5eb2dd9184bec 100644 --- a/tests/ui/impl-trait/issue-103181-2.stderr +++ b/tests/ui/impl-trait/issue-103181-2.stderr @@ -4,61 +4,6 @@ error[E0425]: cannot find value `ident_error` in this scope LL | ident_error; | ^^^^^^^^^^^ not found in this scope -error: cannot check whether the hidden type of opaque type satisfies auto traits - --> $DIR/issue-103181-2.rs:26:15 - | -LL | normalize(broken_fut(), ()); - | --------- ^^^^^^^^^^^^ - | | - | required by a bound introduced by this call - | -note: opaque type is declared here - --> $DIR/issue-103181-2.rs:11:23 - | -LL | async fn broken_fut() { - | ^ -note: this item depends on auto traits of the hidden type, but may also be registering the hidden type. This is not supported right now. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule - --> $DIR/issue-103181-2.rs:20:10 - | -LL | async fn iceice() - | ^^^^^^ -note: required for `impl Future` to implement `SendFuture` - --> $DIR/issue-103181-2.rs:7:17 - | -LL | impl SendFuture for Fut { - | ---- ^^^^^^^^^^ ^^^ - | | - | unsatisfied trait bound introduced here -note: required by a bound in `normalize` - --> $DIR/issue-103181-2.rs:18:19 - | -LL | fn normalize(_: Fut, _: Fut::Output) {} - | ^^^^^^^^^^ required by this bound in `normalize` - -error: cannot check whether the hidden type of opaque type satisfies auto traits - --> $DIR/issue-103181-2.rs:26:5 - | -LL | normalize(broken_fut(), ()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: opaque type is declared here - --> $DIR/issue-103181-2.rs:11:23 - | -LL | async fn broken_fut() { - | ^ -note: this item depends on auto traits of the hidden type, but may also be registering the hidden type. This is not supported right now. You can try moving the opaque type and the item that actually registers a hidden type into a new submodule - --> $DIR/issue-103181-2.rs:20:10 - | -LL | async fn iceice() - | ^^^^^^ -note: required for `impl Future` to implement `SendFuture` - --> $DIR/issue-103181-2.rs:7:17 - | -LL | impl SendFuture for Fut { - | ---- ^^^^^^^^^^ ^^^ - | | - | unsatisfied trait bound introduced here - -error: aborting due to 3 previous errors +error: aborting due to previous error For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/impl-trait/issues/issue-86800.stderr b/tests/ui/impl-trait/issues/issue-86800.stderr index facab390d1524..8228f8ace9d67 100644 --- a/tests/ui/impl-trait/issues/issue-86800.stderr +++ b/tests/ui/impl-trait/issues/issue-86800.stderr @@ -7,6 +7,6 @@ LL | type TransactionFuture<'__, O> = impl '__ + Future Foo { 22_u32 diff --git a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr index 5bd0f76c31fb4..d8698826660f4 100644 --- a/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr +++ b/tests/ui/type-alias-impl-trait/auto-trait-leakage3.stderr @@ -1,4 +1,4 @@ -error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `m::Foo::{opaque#0}` --> $DIR/auto-trait-leakage3.rs:7:20 | LL | pub type Foo = impl std::fmt::Debug; @@ -10,15 +10,15 @@ note: ...which requires type-checking `m::bar`... LL | is_send(foo()); | ^^^^^^^ = note: ...which requires evaluating trait selection obligation `m::Foo: core::marker::Send`... - = note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle -note: cycle used when checking item types in module `m` - --> $DIR/auto-trait-leakage3.rs:6:1 + = note: ...which again requires computing type of opaque `m::Foo::{opaque#0}`, completing the cycle +note: cycle used when computing type of `m::Foo::{opaque#0}` + --> $DIR/auto-trait-leakage3.rs:7:20 | -LL | mod m { - | ^^^^^ +LL | pub type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information -error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `m::Foo::{opaque#0}` --> $DIR/auto-trait-leakage3.rs:7:20 | LL | pub type Foo = impl std::fmt::Debug; @@ -29,12 +29,12 @@ note: ...which requires type-checking `m::bar`... | LL | pub fn bar() { | ^^^^^^^^^^^^ - = note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle -note: cycle used when checking item types in module `m` - --> $DIR/auto-trait-leakage3.rs:6:1 + = note: ...which again requires computing type of opaque `m::Foo::{opaque#0}`, completing the cycle +note: cycle used when computing type of `m::Foo::{opaque#0}` + --> $DIR/auto-trait-leakage3.rs:7:20 | -LL | mod m { - | ^^^^^ +LL | pub type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: cannot check whether the hidden type of `auto_trait_leakage3[211d]::m::Foo::{opaque#0}` satisfies auto traits diff --git a/tests/ui/type-alias-impl-trait/inference-cycle.stderr b/tests/ui/type-alias-impl-trait/inference-cycle.stderr index 41530dda983a8..4ab059d054be5 100644 --- a/tests/ui/type-alias-impl-trait/inference-cycle.stderr +++ b/tests/ui/type-alias-impl-trait/inference-cycle.stderr @@ -1,4 +1,4 @@ -error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `m::Foo::{opaque#0}` --> $DIR/inference-cycle.rs:5:20 | LL | pub type Foo = impl std::fmt::Debug; @@ -10,15 +10,15 @@ note: ...which requires type-checking `m::bar`... LL | is_send(foo()); // Today: error | ^^^^^^^ = note: ...which requires evaluating trait selection obligation `m::Foo: core::marker::Send`... - = note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle -note: cycle used when checking item types in module `m` - --> $DIR/inference-cycle.rs:4:1 + = note: ...which again requires computing type of opaque `m::Foo::{opaque#0}`, completing the cycle +note: cycle used when computing type of `m::Foo::{opaque#0}` + --> $DIR/inference-cycle.rs:5:20 | -LL | mod m { - | ^^^^^ +LL | pub type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information -error[E0391]: cycle detected when computing type of `m::Foo::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `m::Foo::{opaque#0}` --> $DIR/inference-cycle.rs:5:20 | LL | pub type Foo = impl std::fmt::Debug; @@ -29,12 +29,12 @@ note: ...which requires type-checking `m::bar`... | LL | pub fn bar() { | ^^^^^^^^^^^^ - = note: ...which again requires computing type of `m::Foo::{opaque#0}`, completing the cycle -note: cycle used when checking item types in module `m` - --> $DIR/inference-cycle.rs:4:1 + = note: ...which again requires computing type of opaque `m::Foo::{opaque#0}`, completing the cycle +note: cycle used when computing type of `m::Foo::{opaque#0}` + --> $DIR/inference-cycle.rs:5:20 | -LL | mod m { - | ^^^^^ +LL | pub type Foo = impl std::fmt::Debug; + | ^^^^^^^^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: cannot check whether the hidden type of `inference_cycle[4ecc]::m::Foo::{opaque#0}` satisfies auto traits diff --git a/tests/ui/type-alias-impl-trait/issue-53092-2.stderr b/tests/ui/type-alias-impl-trait/issue-53092-2.stderr index 6148131b491f5..e4054e14abef1 100644 --- a/tests/ui/type-alias-impl-trait/issue-53092-2.stderr +++ b/tests/ui/type-alias-impl-trait/issue-53092-2.stderr @@ -4,6 +4,11 @@ error[E0391]: cycle detected when computing type of `Bug::{opaque#0}` LL | type Bug = impl Fn(T) -> U + Copy; | ^^^^^^^^^^^^^^^^^^^^^^ | +note: ...which requires computing type of opaque `Bug::{opaque#0}`... + --> $DIR/issue-53092-2.rs:4:18 + | +LL | type Bug = impl Fn(T) -> U + Copy; + | ^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires type-checking `CONST_BUG`... --> $DIR/issue-53092-2.rs:6:1 | diff --git a/tests/ui/type-alias-impl-trait/reveal_local.stderr b/tests/ui/type-alias-impl-trait/reveal_local.stderr index 813185c137795..c62fd88f4e22b 100644 --- a/tests/ui/type-alias-impl-trait/reveal_local.stderr +++ b/tests/ui/type-alias-impl-trait/reveal_local.stderr @@ -1,4 +1,4 @@ -error[E0391]: cycle detected when computing type of `Foo::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `Foo::{opaque#0}` --> $DIR/reveal_local.rs:5:12 | LL | type Foo = impl Debug; @@ -10,21 +10,15 @@ note: ...which requires type-checking `not_good`... LL | is_send::(); | ^^^^^^^^^^^^^^ = note: ...which requires evaluating trait selection obligation `Foo: core::marker::Send`... - = note: ...which again requires computing type of `Foo::{opaque#0}`, completing the cycle -note: cycle used when checking item types in top-level module - --> $DIR/reveal_local.rs:1:1 - | -LL | / #![feature(type_alias_impl_trait)] -LL | | -LL | | use std::fmt::Debug; -LL | | -... | -LL | | -LL | | fn main() {} - | |____________^ + = note: ...which again requires computing type of opaque `Foo::{opaque#0}`, completing the cycle +note: cycle used when computing type of `Foo::{opaque#0}` + --> $DIR/reveal_local.rs:5:12 + | +LL | type Foo = impl Debug; + | ^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information -error[E0391]: cycle detected when computing type of `Foo::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `Foo::{opaque#0}` --> $DIR/reveal_local.rs:5:12 | LL | type Foo = impl Debug; @@ -35,18 +29,12 @@ note: ...which requires type-checking `not_good`... | LL | fn not_good() { | ^^^^^^^^^^^^^ - = note: ...which again requires computing type of `Foo::{opaque#0}`, completing the cycle -note: cycle used when checking item types in top-level module - --> $DIR/reveal_local.rs:1:1 - | -LL | / #![feature(type_alias_impl_trait)] -LL | | -LL | | use std::fmt::Debug; -LL | | -... | -LL | | -LL | | fn main() {} - | |____________^ + = note: ...which again requires computing type of opaque `Foo::{opaque#0}`, completing the cycle +note: cycle used when computing type of `Foo::{opaque#0}` + --> $DIR/reveal_local.rs:5:12 + | +LL | type Foo = impl Debug; + | ^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: cannot check whether the hidden type of `reveal_local[9507]::Foo::{opaque#0}` satisfies auto traits @@ -71,7 +59,7 @@ note: required by a bound in `is_send` LL | fn is_send() {} | ^^^^ required by this bound in `is_send` -error[E0391]: cycle detected when computing type of `Foo::{opaque#0}` +error[E0391]: cycle detected when computing type of opaque `Foo::{opaque#0}` --> $DIR/reveal_local.rs:5:12 | LL | type Foo = impl Debug; @@ -82,18 +70,12 @@ note: ...which requires type-checking `not_gooder`... | LL | fn not_gooder() -> Foo { | ^^^^^^^^^^^^^^^^^^^^^^ - = note: ...which again requires computing type of `Foo::{opaque#0}`, completing the cycle -note: cycle used when checking item types in top-level module - --> $DIR/reveal_local.rs:1:1 - | -LL | / #![feature(type_alias_impl_trait)] -LL | | -LL | | use std::fmt::Debug; -LL | | -... | -LL | | -LL | | fn main() {} - | |____________^ + = note: ...which again requires computing type of opaque `Foo::{opaque#0}`, completing the cycle +note: cycle used when computing type of `Foo::{opaque#0}` + --> $DIR/reveal_local.rs:5:12 + | +LL | type Foo = impl Debug; + | ^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information error: cannot check whether the hidden type of `reveal_local[9507]::Foo::{opaque#0}` satisfies auto traits