From 08342bfa65c1262eb1d5b837a8b11cace2c6802a Mon Sep 17 00:00:00 2001 From: aerooneqq Date: Tue, 2 Jun 2026 12:31:36 +0300 Subject: [PATCH 1/6] Split delegation resolution and lowering --- compiler/rustc_ast/src/ast.rs | 6 + compiler/rustc_ast_lowering/src/delegation.rs | 105 +++++------------- compiler/rustc_ast_lowering/src/lib.rs | 90 +++++++++++++-- compiler/rustc_interface/src/passes.rs | 1 + compiler/rustc_middle/src/hir/map.rs | 2 + compiler/rustc_middle/src/queries.rs | 6 + 6 files changed, 125 insertions(+), 85 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 682ba78cddc5f..f8eafc3566c87 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -3921,6 +3921,12 @@ pub struct Delegation { pub from_glob: bool, } +impl Delegation { + pub fn span(&self) -> Span { + self.path.segments.last().unwrap().ident.span + } +} + #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum DelegationSuffixes { List(ThinVec<(Ident, Option)>), diff --git a/compiler/rustc_ast_lowering/src/delegation.rs b/compiler/rustc_ast_lowering/src/delegation.rs index 5ea62010c3135..d1a356ced0686 100644 --- a/compiler/rustc_ast_lowering/src/delegation.rs +++ b/compiler/rustc_ast_lowering/src/delegation.rs @@ -44,8 +44,6 @@ use hir::{BodyId, HirId}; use rustc_abi::ExternAbi; use rustc_ast as ast; use rustc_ast::*; -use rustc_data_structures::fx::FxHashSet; -use rustc_errors::ErrorGuaranteed; use rustc_hir::attrs::{AttributeKind, InlineAttr}; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, FnDeclFlags}; @@ -53,13 +51,10 @@ use rustc_middle::span_bug; use rustc_middle::ty::Asyncness; use rustc_span::symbol::kw; use rustc_span::{Ident, Span, Symbol}; -use smallvec::SmallVec; use crate::delegation::generics::{GenericsGenerationResult, GenericsGenerationResults}; -use crate::errors::{CycleInDelegationSignatureResolution, UnresolvedDelegationCallee}; use crate::{ AllowReturnTypeNotation, ImplTraitContext, ImplTraitPosition, LoweringContext, ParamMode, - ResolverAstLoweringExt, }; mod generics; @@ -119,13 +114,13 @@ impl<'hir> LoweringContext<'_, 'hir> { delegation: &Delegation, item_id: NodeId, ) -> DelegationResults<'hir> { - let span = self.lower_span(delegation.path.segments.last().unwrap().ident.span); + let span = self.lower_span(delegation.span()); + + let sig_id = + self.tcx.delegations_resolutions(()).get(&self.owner.def_id).copied().flatten(); // Delegation can be unresolved in illegal places such as function bodies in extern blocks (see #151356) - let sig_id = if let Some(delegation_info) = self.resolver.delegation_info(self.owner.def_id) - { - self.get_sig_id(delegation_info.resolution_id, span) - } else { + let Some(sig_id) = sig_id else { self.dcx().span_delayed_bug( span, format!("LoweringContext: the delegation {:?} is unresolved", item_id), @@ -134,49 +129,39 @@ impl<'hir> LoweringContext<'_, 'hir> { return self.generate_delegation_error(span, delegation); }; - match sig_id { - Ok(sig_id) => { - self.add_attrs_if_needed(span, sig_id); + self.add_attrs_if_needed(span, sig_id); - let is_method = self.is_method(sig_id, span); + let is_method = self.is_method(sig_id, span); - let (param_count, c_variadic) = self.param_count(sig_id); + let (param_count, c_variadic) = self.param_count(sig_id); - let mut generics = self.uplift_delegation_generics(delegation, sig_id, is_method); + let mut generics = self.uplift_delegation_generics(delegation, sig_id, is_method); - let (body_id, call_expr_id) = self.lower_delegation_body( - delegation, - is_method, - param_count, - &mut generics, - span, - ); + let (body_id, call_expr_id) = + self.lower_delegation_body(delegation, is_method, param_count, &mut generics, span); - let decl = self.lower_delegation_decl( - sig_id, - param_count, - c_variadic, - span, - &generics, - delegation.id, - call_expr_id, - ); + let decl = self.lower_delegation_decl( + sig_id, + param_count, + c_variadic, + span, + &generics, + delegation.id, + call_expr_id, + ); - let sig = self.lower_delegation_sig(sig_id, decl, span); - let ident = self.lower_ident(delegation.ident); + let sig = self.lower_delegation_sig(sig_id, decl, span); + let ident = self.lower_ident(delegation.ident); - let generics = self.arena.alloc(hir::Generics { - has_where_clause_predicates: false, - params: self.arena.alloc_from_iter(generics.all_params()), - predicates: self.arena.alloc_from_iter(generics.all_predicates()), - span, - where_clause_span: span, - }); + let generics = self.arena.alloc(hir::Generics { + has_where_clause_predicates: false, + params: self.arena.alloc_from_iter(generics.all_params()), + predicates: self.arena.alloc_from_iter(generics.all_predicates()), + span, + where_clause_span: span, + }); - DelegationResults { body_id, sig, ident, generics } - } - Err(_) => self.generate_delegation_error(span, delegation), - } + DelegationResults { body_id, sig, ident, generics } } fn add_attrs_if_needed(&mut self, span: Span, sig_id: DefId) { @@ -230,36 +215,6 @@ impl<'hir> LoweringContext<'_, 'hir> { .collect::>() } - fn get_sig_id(&self, mut def_id: DefId, span: Span) -> Result { - let mut visited: FxHashSet = Default::default(); - let mut path: SmallVec<[DefId; 1]> = Default::default(); - - loop { - visited.insert(def_id); - - path.push(def_id); - - // If def_id is in local crate and it corresponds to another delegation - // it means that we refer to another delegation as a callee, so in order to obtain - // a signature DefId we obtain NodeId of the callee delegation and try to get signature from it. - if let Some(local_id) = def_id.as_local() - && let Some(delegation_info) = self.resolver.delegation_info(local_id) - { - def_id = delegation_info.resolution_id; - if visited.contains(&def_id) { - // We encountered a cycle in the resolution, or delegation callee refers to non-existent - // entity, in this case emit an error. - return Err(match visited.len() { - 1 => self.dcx().emit_err(UnresolvedDelegationCallee { span }), - _ => self.dcx().emit_err(CycleInDelegationSignatureResolution { span }), - }); - } - } else { - return Ok(path[0]); - } - } - } - fn get_resolution_id(&self, node_id: NodeId) -> Option { self.get_partial_res(node_id).and_then(|r| r.expect_full_res().opt_def_id()) } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 4045f08c053ed..514007356f9ea 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -43,14 +43,14 @@ use rustc_ast::visit::Visitor; use rustc_ast::{self as ast, *}; use rustc_attr_parsing::{AttributeParser, OmitDoc, Recovery, ShouldEmit}; use rustc_data_structures::fingerprint::Fingerprint; -use rustc_data_structures::fx::FxIndexSet; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::sorted_map::SortedMap; use rustc_data_structures::stable_hash::{StableHash, StableHasher}; use rustc_data_structures::steal::Steal; use rustc_data_structures::tagged_ptr::TaggedRef; use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle}; use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res}; -use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId}; +use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE, LocalDefId}; use rustc_hir::definitions::PerParentDisambiguatorState; use rustc_hir::lints::DelayedLint; use rustc_hir::{ @@ -69,7 +69,10 @@ use smallvec::SmallVec; use thin_vec::ThinVec; use tracing::{debug, instrument, trace}; -use crate::errors::{AssocTyParentheses, AssocTyParenthesesSub, MisplacedImplTrait}; +use crate::errors::{ + AssocTyParentheses, AssocTyParenthesesSub, CycleInDelegationSignatureResolution, + MisplacedImplTrait, UnresolvedDelegationCallee, +}; use crate::item::Owners; macro_rules! arena_vec { @@ -541,13 +544,11 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> mid_hir::Crate<'_> { let mut delayed_ids: FxIndexSet = Default::default(); for def_id in ast_index.indices() { - match &ast_index[def_id] { - AstOwner::Item(Item { kind: ItemKind::Delegation { .. }, .. }) - | AstOwner::AssocItem(Item { kind: AssocItemKind::Delegation { .. }, .. }, _) => { - delayed_ids.insert(def_id); - } - _ => lowerer.lower_node(def_id), - }; + if opt_delegation(&ast_index[def_id]).is_some() { + delayed_ids.insert(def_id); + } else { + lowerer.lower_node(def_id); + } } // Don't hash unless necessary, because it's expensive. @@ -558,6 +559,16 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> mid_hir::Crate<'_> { mid_hir::Crate::new(owners, delayed_ids, delayed_resolver, opt_hir_hash) } +fn opt_delegation<'a>(ast_owner: &'a AstOwner<'a>) -> Option<&'a Delegation> { + match ast_owner { + AstOwner::Item(Item { kind: ItemKind::Delegation(d), .. }) + | AstOwner::AssocItem(Item { kind: AssocItemKind::Delegation(d), .. }, _) => { + Some(d.as_ref()) + } + _ => None, + } +} + /// Lowers an AST owner corresponding to `def_id`, now only delegations are lowered this way. pub fn lower_delayed_owner(tcx: TyCtxt<'_>, def_id: LocalDefId) { let krate = tcx.hir_crate(()); @@ -583,6 +594,65 @@ pub fn lower_delayed_owner(tcx: TyCtxt<'_>, def_id: LocalDefId) { } } +pub fn delegations_resolutions(tcx: TyCtxt<'_>, _: ()) -> FxIndexMap> { + let krate = tcx.hir_crate(()); + + let (resolver, ast_crate) = &*krate.delayed_resolver.borrow(); + + // FIXME!!!(fn_delegation): make ast index lifetime same as resolver, + // as it is too bad to reindex whole crate on each delegation lowering. + let ast_index = index_crate(resolver, ast_crate); + + let mut result = FxIndexMap::>::default(); + + for &def_id in &krate.delayed_ids { + let delegation = opt_delegation(&ast_index[def_id]).expect("processing delegations"); + let span = delegation.span(); + + let res_id = resolver + .delegation_info(def_id) + .and_then(|info| resolve_delegation(tcx, info.resolution_id, span)); + + result.insert(def_id, res_id); + } + + result +} + +fn resolve_delegation(tcx: TyCtxt<'_>, mut def_id: DefId, span: Span) -> Option { + let mut visited: FxHashSet = Default::default(); + let mut path: SmallVec<[DefId; 1]> = Default::default(); + + let (resolver, _) = &*tcx.hir_crate(()).delayed_resolver.borrow(); + + loop { + visited.insert(def_id); + + path.push(def_id); + + // If def_id is in local crate and it corresponds to another delegation + // it means that we refer to another delegation as a callee, so in order to obtain + // a signature DefId we obtain NodeId of the callee delegation and try to get signature from it. + if let Some(local_id) = def_id.as_local() + && let Some(delegation_info) = resolver.delegation_info(local_id) + { + def_id = delegation_info.resolution_id; + if visited.contains(&def_id) { + // We encountered a cycle in the resolution, or delegation callee refers to non-existent + // entity, in this case emit an error. + match visited.len() { + 1 => tcx.dcx().emit_err(UnresolvedDelegationCallee { span }), + _ => tcx.dcx().emit_err(CycleInDelegationSignatureResolution { span }), + }; + + return None; + } + } else { + return Some(path[0]); + } + } +} + #[derive(Copy, Clone, PartialEq, Debug)] enum ParamMode { /// Any path in a type context. diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 623fb4e2c6dd2..d4674b4bfb69e 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -879,6 +879,7 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock = LazyLock::new(|| { providers.queries.analysis = analysis; providers.queries.hir_crate = rustc_ast_lowering::lower_to_hir; providers.queries.lower_delayed_owner = rustc_ast_lowering::lower_delayed_owner; + providers.queries.delegations_resolutions = rustc_ast_lowering::delegations_resolutions; // `hir_delayed_owner` is fed during `lower_delayed_owner`, by default it returns phantom, // as if this query was not fed it means that `MaybeOwner` does not exist for provided LocalDefId. providers.queries.hir_delayed_owner = |_, _| MaybeOwner::Phantom; diff --git a/compiler/rustc_middle/src/hir/map.rs b/compiler/rustc_middle/src/hir/map.rs index 232a4e6c2f77b..177fc422611b2 100644 --- a/compiler/rustc_middle/src/hir/map.rs +++ b/compiler/rustc_middle/src/hir/map.rs @@ -1277,6 +1277,8 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod } fn force_delayed_owners_lowering(tcx: TyCtxt<'_>) { + tcx.ensure_done().delegations_resolutions(()); + let krate = tcx.hir_crate(()); for &id in &krate.delayed_ids { tcx.ensure_done().lower_delayed_owner(id); diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index 5add2cf09b7b8..e1268117f4fae 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -2065,6 +2065,12 @@ rustc_queries! { desc { "inheriting delegation signature" } } + query delegations_resolutions(_: ()) -> &'tcx FxIndexMap> { + arena_cache + eval_always + desc { "getting delegations resolutions" } + } + /// Does lifetime resolution on items. Importantly, we can't resolve /// lifetimes directly on things like trait methods, because of trait params. /// See `rustc_resolve::late::lifetimes` for details. From 7bdb059748a0bd31ff342ca209301a26fbea932e Mon Sep 17 00:00:00 2001 From: aerooneqq Date: Wed, 3 Jun 2026 10:35:56 +0300 Subject: [PATCH 2/6] Address review comments --- compiler/rustc_ast/src/ast.rs | 2 +- compiler/rustc_ast_lowering/src/delegation.rs | 77 +++++++++++++-- compiler/rustc_ast_lowering/src/errors.rs | 7 -- compiler/rustc_ast_lowering/src/lib.rs | 98 ++++--------------- compiler/rustc_interface/src/passes.rs | 3 +- compiler/rustc_middle/src/hir/map.rs | 2 - compiler/rustc_middle/src/queries.rs | 2 +- compiler/rustc_middle/src/ty/mod.rs | 4 +- compiler/rustc_resolve/src/errors.rs | 7 ++ compiler/rustc_resolve/src/late.rs | 17 +++- compiler/rustc_resolve/src/lib.rs | 2 +- tests/ui/delegation/bad-resolve.rs | 10 ++ tests/ui/delegation/bad-resolve.stderr | 82 +++++++++++++--- .../duplicate-definition-inside-trait-impl.rs | 1 + ...licate-definition-inside-trait-impl.stderr | 8 +- tests/ui/delegation/explicit-paths.rs | 5 + tests/ui/delegation/explicit-paths.stderr | 52 +++++++--- .../def-path-hash-collision-ice-153410.rs | 1 + .../def-path-hash-collision-ice-153410.stderr | 8 +- .../generics/synth-params-ice-143498.rs | 1 + .../generics/synth-params-ice-143498.stderr | 8 +- tests/ui/delegation/glob-glob-conflict.rs | 2 + tests/ui/delegation/glob-glob-conflict.stderr | 20 +++- tests/ui/delegation/glob-non-fn.rs | 3 + tests/ui/delegation/glob-non-fn.stderr | 24 ++++- tests/ui/delegation/ice-issue-124342.rs | 1 + tests/ui/delegation/ice-issue-124342.stderr | 8 +- .../ice-line-bounds-issue-148732.rs | 1 + .../ice-line-bounds-issue-148732.stderr | 15 +-- .../delegation/impl-reuse-non-reuse-items.rs | 3 + .../impl-reuse-non-reuse-items.stderr | 24 ++++- .../recursive-delegation-ice-150152.rs | 1 + .../recursive-delegation-ice-150152.stderr | 16 ++- .../ui/delegation/unused-import-ice-144594.rs | 1 + .../unused-import-ice-144594.stderr | 10 +- tests/ui/delegation/wrong-lifetime-rib.rs | 1 + tests/ui/delegation/wrong-lifetime-rib.stderr | 16 ++- 37 files changed, 387 insertions(+), 156 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index f8eafc3566c87..6e036e59b2349 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -3922,7 +3922,7 @@ pub struct Delegation { } impl Delegation { - pub fn span(&self) -> Span { + pub fn last_segment_span(&self) -> Span { self.path.segments.last().unwrap().ident.span } } diff --git a/compiler/rustc_ast_lowering/src/delegation.rs b/compiler/rustc_ast_lowering/src/delegation.rs index d1a356ced0686..7ec40b9ec0dbb 100644 --- a/compiler/rustc_ast_lowering/src/delegation.rs +++ b/compiler/rustc_ast_lowering/src/delegation.rs @@ -44,17 +44,21 @@ use hir::{BodyId, HirId}; use rustc_abi::ExternAbi; use rustc_ast as ast; use rustc_ast::*; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_hir::attrs::{AttributeKind, InlineAttr}; -use rustc_hir::def_id::DefId; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{self as hir, FnDeclFlags}; use rustc_middle::span_bug; -use rustc_middle::ty::Asyncness; +use rustc_middle::ty::{Asyncness, TyCtxt}; use rustc_span::symbol::kw; -use rustc_span::{Ident, Span, Symbol}; +use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol}; +use smallvec::SmallVec; use crate::delegation::generics::{GenericsGenerationResult, GenericsGenerationResults}; +use crate::errors::CycleInDelegationSignatureResolution; use crate::{ AllowReturnTypeNotation, ImplTraitContext, ImplTraitPosition, LoweringContext, ParamMode, + ResolverAstLoweringExt, index_crate, }; mod generics; @@ -100,6 +104,66 @@ static ATTRS_ADDITIONS: &[AttrAdditionInfo] = &[ }, ]; +pub fn delegations_resolutions( + tcx: TyCtxt<'_>, + _: (), +) -> FxIndexMap> { + let krate = tcx.hir_crate(()); + + let (resolver, ast_crate) = &*krate.delayed_resolver.borrow(); + + // FIXME!!!(fn_delegation): make ast index lifetime same as resolver, + // as it is too bad to reindex whole crate on each delegation lowering. + let ast_index = index_crate(resolver, ast_crate); + + let mut result = FxIndexMap::>::default(); + + for &def_id in &krate.delayed_ids { + let delegation = ast_index[def_id].delegation().expect("processing delegations"); + let span = delegation.last_segment_span(); + + if let Some(res_result) = resolver.delegation_info(def_id) { + let res = res_result.map(|info| check_for_cycles(tcx, info.resolution_id, span)); + result.insert(def_id, res.flatten()); + } + } + + result +} + +fn check_for_cycles( + tcx: TyCtxt<'_>, + mut def_id: DefId, + span: Span, +) -> Result { + let mut visited: FxHashSet = Default::default(); + let mut path: SmallVec<[DefId; 1]> = Default::default(); + + let (resolver, _) = &*tcx.hir_crate(()).delayed_resolver.borrow(); + + loop { + visited.insert(def_id); + + path.push(def_id); + + // If def_id is in local crate and it corresponds to another delegation + // it means that we refer to another delegation as a callee, so in order to obtain + // a signature DefId we obtain NodeId of the callee delegation and try to get signature from it. + if let Some(local_id) = def_id.as_local() + && let Some(Ok(delegation_info)) = resolver.delegation_info(local_id) + { + def_id = delegation_info.resolution_id; + if visited.contains(&def_id) { + // We encountered a cycle in the resolution, or delegation callee refers to non-existent + // entity, in this case emit an error. + return Err(tcx.dcx().emit_err(CycleInDelegationSignatureResolution { span })); + } + } else { + return Ok(path[0]); + } + } +} + impl<'hir> LoweringContext<'_, 'hir> { fn is_method(&self, def_id: DefId, span: Span) -> bool { match self.tcx.def_kind(def_id) { @@ -114,13 +178,12 @@ impl<'hir> LoweringContext<'_, 'hir> { delegation: &Delegation, item_id: NodeId, ) -> DelegationResults<'hir> { - let span = self.lower_span(delegation.span()); + let span = self.lower_span(delegation.last_segment_span()); - let sig_id = - self.tcx.delegations_resolutions(()).get(&self.owner.def_id).copied().flatten(); + let sig_id = self.tcx.delegations_resolutions(()).get(&self.owner.def_id).copied(); // Delegation can be unresolved in illegal places such as function bodies in extern blocks (see #151356) - let Some(sig_id) = sig_id else { + let Some(Ok(sig_id)) = sig_id else { self.dcx().span_delayed_bug( span, format!("LoweringContext: the delegation {:?} is unresolved", item_id), diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index a1c1d1e11d694..cd4505fde1fe7 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -522,13 +522,6 @@ pub(crate) struct UnionWithDefault { pub span: Span, } -#[derive(Diagnostic)] -#[diag("failed to resolve delegation callee")] -pub(crate) struct UnresolvedDelegationCallee { - #[primary_span] - pub span: Span, -} - #[derive(Diagnostic)] #[diag("encountered a cycle during delegation signature resolution")] pub(crate) struct CycleInDelegationSignatureResolution { diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 514007356f9ea..f6ab50af1e9da 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -43,14 +43,14 @@ use rustc_ast::visit::Visitor; use rustc_ast::{self as ast, *}; use rustc_attr_parsing::{AttributeParser, OmitDoc, Recovery, ShouldEmit}; use rustc_data_structures::fingerprint::Fingerprint; -use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; +use rustc_data_structures::fx::FxIndexSet; use rustc_data_structures::sorted_map::SortedMap; use rustc_data_structures::stable_hash::{StableHash, StableHasher}; use rustc_data_structures::steal::Steal; use rustc_data_structures::tagged_ptr::TaggedRef; use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle}; use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res}; -use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE, LocalDefId}; +use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId}; use rustc_hir::definitions::PerParentDisambiguatorState; use rustc_hir::lints::DelayedLint; use rustc_hir::{ @@ -64,15 +64,12 @@ use rustc_middle::span_bug; use rustc_middle::ty::{DelegationInfo, PerOwnerResolverData, ResolverAstLowering, TyCtxt}; use rustc_session::errors::add_feature_diagnostics; use rustc_span::symbol::{Ident, Symbol, kw, sym}; -use rustc_span::{DUMMY_SP, DesugaringKind, Span}; +use rustc_span::{DUMMY_SP, DesugaringKind, ErrorGuaranteed, Span}; use smallvec::SmallVec; use thin_vec::ThinVec; use tracing::{debug, instrument, trace}; -use crate::errors::{ - AssocTyParentheses, AssocTyParenthesesSub, CycleInDelegationSignatureResolution, - MisplacedImplTrait, UnresolvedDelegationCallee, -}; +use crate::errors::{AssocTyParentheses, AssocTyParenthesesSub, MisplacedImplTrait}; use crate::item::Owners; macro_rules! arena_vec { @@ -84,7 +81,7 @@ macro_rules! arena_vec { mod asm; mod block; mod contract; -mod delegation; +pub mod delegation; mod errors; mod expr; mod format; @@ -307,8 +304,8 @@ impl<'tcx> ResolverAstLowering<'tcx> { self.extra_lifetime_params_map.get(&id).map_or(&[], |v| &v[..]) } - fn delegation_info(&self, id: LocalDefId) -> Option<&DelegationInfo> { - self.delegation_infos.get(&id) + fn delegation_info(&self, id: LocalDefId) -> Option> { + self.delegation_infos.get(&id).copied() } fn owner_def_id(&self, id: NodeId) -> LocalDefId { @@ -441,6 +438,16 @@ enum AstOwner<'a> { ForeignItem(&'a ast::ForeignItem), } +impl AstOwner<'_> { + fn delegation(&self) -> Option<&ast::Delegation> { + match self { + AstOwner::Item(Item { kind: ItemKind::Delegation(d), .. }) + | AstOwner::AssocItem(Item { kind: AssocItemKind::Delegation(d), .. }, _) => Some(d), + _ => None, + } + } +} + #[derive(Copy, Clone, Debug)] enum TryBlockScope { /// There isn't a `try` block, so a `?` will use `return`. @@ -544,7 +551,7 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> mid_hir::Crate<'_> { let mut delayed_ids: FxIndexSet = Default::default(); for def_id in ast_index.indices() { - if opt_delegation(&ast_index[def_id]).is_some() { + if ast_index[def_id].delegation().is_some() { delayed_ids.insert(def_id); } else { lowerer.lower_node(def_id); @@ -559,16 +566,6 @@ pub fn lower_to_hir(tcx: TyCtxt<'_>, (): ()) -> mid_hir::Crate<'_> { mid_hir::Crate::new(owners, delayed_ids, delayed_resolver, opt_hir_hash) } -fn opt_delegation<'a>(ast_owner: &'a AstOwner<'a>) -> Option<&'a Delegation> { - match ast_owner { - AstOwner::Item(Item { kind: ItemKind::Delegation(d), .. }) - | AstOwner::AssocItem(Item { kind: AssocItemKind::Delegation(d), .. }, _) => { - Some(d.as_ref()) - } - _ => None, - } -} - /// Lowers an AST owner corresponding to `def_id`, now only delegations are lowered this way. pub fn lower_delayed_owner(tcx: TyCtxt<'_>, def_id: LocalDefId) { let krate = tcx.hir_crate(()); @@ -594,65 +591,6 @@ pub fn lower_delayed_owner(tcx: TyCtxt<'_>, def_id: LocalDefId) { } } -pub fn delegations_resolutions(tcx: TyCtxt<'_>, _: ()) -> FxIndexMap> { - let krate = tcx.hir_crate(()); - - let (resolver, ast_crate) = &*krate.delayed_resolver.borrow(); - - // FIXME!!!(fn_delegation): make ast index lifetime same as resolver, - // as it is too bad to reindex whole crate on each delegation lowering. - let ast_index = index_crate(resolver, ast_crate); - - let mut result = FxIndexMap::>::default(); - - for &def_id in &krate.delayed_ids { - let delegation = opt_delegation(&ast_index[def_id]).expect("processing delegations"); - let span = delegation.span(); - - let res_id = resolver - .delegation_info(def_id) - .and_then(|info| resolve_delegation(tcx, info.resolution_id, span)); - - result.insert(def_id, res_id); - } - - result -} - -fn resolve_delegation(tcx: TyCtxt<'_>, mut def_id: DefId, span: Span) -> Option { - let mut visited: FxHashSet = Default::default(); - let mut path: SmallVec<[DefId; 1]> = Default::default(); - - let (resolver, _) = &*tcx.hir_crate(()).delayed_resolver.borrow(); - - loop { - visited.insert(def_id); - - path.push(def_id); - - // If def_id is in local crate and it corresponds to another delegation - // it means that we refer to another delegation as a callee, so in order to obtain - // a signature DefId we obtain NodeId of the callee delegation and try to get signature from it. - if let Some(local_id) = def_id.as_local() - && let Some(delegation_info) = resolver.delegation_info(local_id) - { - def_id = delegation_info.resolution_id; - if visited.contains(&def_id) { - // We encountered a cycle in the resolution, or delegation callee refers to non-existent - // entity, in this case emit an error. - match visited.len() { - 1 => tcx.dcx().emit_err(UnresolvedDelegationCallee { span }), - _ => tcx.dcx().emit_err(CycleInDelegationSignatureResolution { span }), - }; - - return None; - } - } else { - return Some(path[0]); - } - } -} - #[derive(Copy, Clone, PartialEq, Debug)] enum ParamMode { /// Any path in a type context. diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index d4674b4bfb69e..702abf88fded4 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -879,7 +879,8 @@ pub static DEFAULT_QUERY_PROVIDERS: LazyLock = LazyLock::new(|| { providers.queries.analysis = analysis; providers.queries.hir_crate = rustc_ast_lowering::lower_to_hir; providers.queries.lower_delayed_owner = rustc_ast_lowering::lower_delayed_owner; - providers.queries.delegations_resolutions = rustc_ast_lowering::delegations_resolutions; + providers.queries.delegations_resolutions = + rustc_ast_lowering::delegation::delegations_resolutions; // `hir_delayed_owner` is fed during `lower_delayed_owner`, by default it returns phantom, // as if this query was not fed it means that `MaybeOwner` does not exist for provided LocalDefId. providers.queries.hir_delayed_owner = |_, _| MaybeOwner::Phantom; diff --git a/compiler/rustc_middle/src/hir/map.rs b/compiler/rustc_middle/src/hir/map.rs index 177fc422611b2..232a4e6c2f77b 100644 --- a/compiler/rustc_middle/src/hir/map.rs +++ b/compiler/rustc_middle/src/hir/map.rs @@ -1277,8 +1277,6 @@ pub(super) fn hir_module_items(tcx: TyCtxt<'_>, module_id: LocalModDefId) -> Mod } fn force_delayed_owners_lowering(tcx: TyCtxt<'_>) { - tcx.ensure_done().delegations_resolutions(()); - let krate = tcx.hir_crate(()); for &id in &krate.delayed_ids { tcx.ensure_done().lower_delayed_owner(id); diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index e1268117f4fae..d4dae16e016f8 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -2065,7 +2065,7 @@ rustc_queries! { desc { "inheriting delegation signature" } } - query delegations_resolutions(_: ()) -> &'tcx FxIndexMap> { + query delegations_resolutions(_: ()) -> &'tcx FxIndexMap> { arena_cache eval_always desc { "getting delegations resolutions" } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 9ea476c48b206..80199288fc551 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -257,12 +257,12 @@ pub struct ResolverAstLowering<'tcx> { pub lint_buffer: Steal, // Information about delegations which is used when handling recursive delegations - pub delegation_infos: LocalDefIdMap, + pub delegation_infos: LocalDefIdMap>, pub disambiguators: LocalDefIdMap>, } -#[derive(Debug)] +#[derive(Debug, Clone, Copy)] pub struct DelegationInfo { // `DefId` (either the resolution at delegation.id or item_id in case of a trait impl) for signature resolution, // for details see https://github.com/rust-lang/rust/issues/118212#issuecomment-2160686914 diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index 4bcc7a5eb02e8..8a2c289b6eafc 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -1776,3 +1776,10 @@ pub(crate) enum UnusedImportsSugg { num_to_remove: usize, }, } + +#[derive(Diagnostic)] +#[diag("failed to resolve delegation callee")] +pub(crate) struct UnresolvedDelegationCallee { + #[primary_span] + pub span: Span, +} diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 58899ffd53ab9..bd5615117b253 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -39,6 +39,7 @@ use smallvec::{SmallVec, smallvec}; use thin_vec::ThinVec; use tracing::{debug, instrument, trace}; +use crate::errors::UnresolvedDelegationCallee; use crate::{ BindingError, BindingKey, Decl, DelegationFnSig, Finalize, IdentKey, LateDecl, LocalModule, Module, ModuleOrUniformRoot, ParentScope, PathResult, Res, ResolutionError, Resolver, Segment, @@ -3905,10 +3906,13 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { .partial_res_map .get(&resolution_id) .and_then(|r| r.expect_full_res().opt_def_id()); - if let Some(resolution_id) = def_id { - self.r - .delegation_infos - .insert(self.r.current_owner.def_id, DelegationInfo { resolution_id }); + + let resolution = if let Some(resolution_id) = def_id + // If there is a single unresolved `reuse foo` in a mod it resolves to itself, + // in this case emit `UnresolvedDelegationCallee` error instead of cycle error. + && resolution_id != self.r.current_owner.def_id.to_def_id() + { + Ok(DelegationInfo { resolution_id }) } else { self.r.tcx.dcx().span_delayed_bug( delegation.path.span, @@ -3916,8 +3920,13 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { "LoweringContext: couldn't resolve node {resolution_id:?} in delegation item", ), ); + + let err = UnresolvedDelegationCallee { span: delegation.last_segment_span() }; + Err(self.r.tcx.dcx().emit_err(err)) }; + self.r.delegation_infos.insert(self.r.current_owner.def_id, resolution); + let Some(body) = &delegation.body else { return }; self.with_rib(ValueNS, RibKind::FnOrCoroutine, |this| { let ident = Ident::new(kw::SelfLower, body.span.normalize_to_macro_rules()); diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index ffb2181bae3a9..e5614111e48de 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1509,7 +1509,7 @@ pub struct Resolver<'ra, 'tcx> { /// Generic args to suggest for required params (e.g. `<'_>`, `<_, _>`), if any. item_required_generic_args_suggestions: FxHashMap = default::fx_hash_map(), delegation_fn_sigs: LocalDefIdMap = Default::default(), - delegation_infos: LocalDefIdMap = Default::default(), + delegation_infos: LocalDefIdMap> = Default::default(), main_def: Option = None, trait_impls: FxIndexMap>, diff --git a/tests/ui/delegation/bad-resolve.rs b/tests/ui/delegation/bad-resolve.rs index 2c2c622e09006..24b623cc3bdb6 100644 --- a/tests/ui/delegation/bad-resolve.rs +++ b/tests/ui/delegation/bad-resolve.rs @@ -23,12 +23,15 @@ impl Trait for S { reuse ::C; //~^ ERROR item `C` is an associated method, which doesn't match its trait `Trait` //~| ERROR expected function, found associated constant `Trait::C` + //~| ERROR: failed to resolve delegation callee reuse ::Type; //~^ ERROR item `Type` is an associated method, which doesn't match its trait `Trait` //~| ERROR expected method or associated constant, found associated type `Trait::Type` + //~| ERROR: failed to resolve delegation callee reuse ::baz; //~^ ERROR method `baz` is not a member of trait `Trait` //~| ERROR cannot find method or associated constant `baz` in trait `Trait` + //~| ERROR: failed to resolve delegation callee reuse ::bar; reuse foo { &self.0 } @@ -36,11 +39,18 @@ impl Trait for S { reuse Trait::foo2 { self.0 } //~^ ERROR cannot find function `foo2` in trait `Trait` //~| ERROR method `foo2` is not a member of trait `Trait` + //~| ERROR: failed to resolve delegation callee } mod prefix {} reuse unresolved_prefix::{a, b, c}; //~ ERROR cannot find module or crate `unresolved_prefix` +//~^ ERROR: failed to resolve delegation callee +//~| ERROR: failed to resolve delegation callee +//~| ERROR: failed to resolve delegation callee reuse prefix::{self, super, crate}; //~ ERROR `crate` in paths can only be used in start position //~^ ERROR expected function, found module `prefix::self` +//~| ERROR: failed to resolve delegation callee +//~| ERROR: failed to resolve delegation callee +//~| ERROR: failed to resolve delegation callee fn main() {} diff --git a/tests/ui/delegation/bad-resolve.stderr b/tests/ui/delegation/bad-resolve.stderr index d1b3974e77081..e6e1fe5bbc421 100644 --- a/tests/ui/delegation/bad-resolve.stderr +++ b/tests/ui/delegation/bad-resolve.stderr @@ -7,8 +7,14 @@ LL | const C: u32 = 0; LL | reuse ::C; | ^^^^^^^^^^^^^^^^^^^^^^ does not match trait +error: failed to resolve delegation callee + --> $DIR/bad-resolve.rs:23:25 + | +LL | reuse ::C; + | ^ + error[E0324]: item `Type` is an associated method, which doesn't match its trait `Trait` - --> $DIR/bad-resolve.rs:26:5 + --> $DIR/bad-resolve.rs:27:5 | LL | type Type; | ---------- item in trait @@ -16,8 +22,14 @@ LL | type Type; LL | reuse ::Type; | ^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait +error: failed to resolve delegation callee + --> $DIR/bad-resolve.rs:27:25 + | +LL | reuse ::Type; + | ^^^^ + error[E0407]: method `baz` is not a member of trait `Trait` - --> $DIR/bad-resolve.rs:29:5 + --> $DIR/bad-resolve.rs:31:5 | LL | reuse ::baz; | ^^^^^^^^^^^^^^^^^^^^---^ @@ -25,8 +37,14 @@ LL | reuse ::baz; | | help: there is an associated function with a similar name: `bar` | not a member of trait `Trait` +error: failed to resolve delegation callee + --> $DIR/bad-resolve.rs:31:25 + | +LL | reuse ::baz; + | ^^^ + error[E0407]: method `foo2` is not a member of trait `Trait` - --> $DIR/bad-resolve.rs:36:5 + --> $DIR/bad-resolve.rs:39:5 | LL | reuse Trait::foo2 { self.0 } | ^^^^^^^^^^^^^----^^^^^^^^^^^ @@ -34,6 +52,48 @@ LL | reuse Trait::foo2 { self.0 } | | help: there is an associated function with a similar name: `foo` | not a member of trait `Trait` +error: failed to resolve delegation callee + --> $DIR/bad-resolve.rs:39:18 + | +LL | reuse Trait::foo2 { self.0 } + | ^^^^ + +error: failed to resolve delegation callee + --> $DIR/bad-resolve.rs:46:27 + | +LL | reuse unresolved_prefix::{a, b, c}; + | ^ + +error: failed to resolve delegation callee + --> $DIR/bad-resolve.rs:46:30 + | +LL | reuse unresolved_prefix::{a, b, c}; + | ^ + +error: failed to resolve delegation callee + --> $DIR/bad-resolve.rs:46:33 + | +LL | reuse unresolved_prefix::{a, b, c}; + | ^ + +error: failed to resolve delegation callee + --> $DIR/bad-resolve.rs:50:16 + | +LL | reuse prefix::{self, super, crate}; + | ^^^^ + +error: failed to resolve delegation callee + --> $DIR/bad-resolve.rs:50:22 + | +LL | reuse prefix::{self, super, crate}; + | ^^^^^ + +error: failed to resolve delegation callee + --> $DIR/bad-resolve.rs:50:29 + | +LL | reuse prefix::{self, super, crate}; + | ^^^^^ + error[E0423]: expected function, found associated constant `Trait::C` --> $DIR/bad-resolve.rs:23:11 | @@ -41,13 +101,13 @@ LL | reuse ::C; | ^^^^^^^^^^^^^^^ not a function error[E0575]: expected method or associated constant, found associated type `Trait::Type` - --> $DIR/bad-resolve.rs:26:11 + --> $DIR/bad-resolve.rs:27:11 | LL | reuse ::Type; | ^^^^^^^^^^^^^^^^^^ not a method or associated constant error[E0576]: cannot find method or associated constant `baz` in trait `Trait` - --> $DIR/bad-resolve.rs:29:25 + --> $DIR/bad-resolve.rs:31:25 | LL | fn bar() {} | -------- similarly named associated function `bar` defined here @@ -62,13 +122,13 @@ LL + reuse ::bar; | error[E0425]: cannot find function `foo` in this scope - --> $DIR/bad-resolve.rs:34:11 + --> $DIR/bad-resolve.rs:37:11 | LL | reuse foo { &self.0 } | ^^^ not found in this scope error[E0425]: cannot find function `foo2` in trait `Trait` - --> $DIR/bad-resolve.rs:36:18 + --> $DIR/bad-resolve.rs:39:18 | LL | fn foo(&self, x: i32) -> i32 { x } | ---------------------------- similarly named associated function `foo` defined here @@ -83,7 +143,7 @@ LL + reuse Trait::foo { self.0 } | error[E0423]: expected function, found module `prefix::self` - --> $DIR/bad-resolve.rs:43:7 + --> $DIR/bad-resolve.rs:50:7 | LL | reuse prefix::{self, super, crate}; | ^^^^^^ not a function @@ -98,7 +158,7 @@ LL | impl Trait for S { | ^^^^^^^^^^^^^^^^ missing `Type` in implementation error[E0433]: cannot find module or crate `unresolved_prefix` in this scope - --> $DIR/bad-resolve.rs:42:7 + --> $DIR/bad-resolve.rs:46:7 | LL | reuse unresolved_prefix::{a, b, c}; | ^^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `unresolved_prefix` @@ -106,12 +166,12 @@ LL | reuse unresolved_prefix::{a, b, c}; = help: you might be missing a crate named `unresolved_prefix` error[E0433]: `crate` in paths can only be used in start position - --> $DIR/bad-resolve.rs:43:29 + --> $DIR/bad-resolve.rs:50:29 | LL | reuse prefix::{self, super, crate}; | ^^^^^ can only be used in path start position -error: aborting due to 13 previous errors +error: aborting due to 23 previous errors Some errors have detailed explanations: E0046, E0324, E0407, E0423, E0425, E0433, E0575, E0576. For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/delegation/duplicate-definition-inside-trait-impl.rs b/tests/ui/delegation/duplicate-definition-inside-trait-impl.rs index ecd47a7ccaa94..e0e8261795e61 100644 --- a/tests/ui/delegation/duplicate-definition-inside-trait-impl.rs +++ b/tests/ui/delegation/duplicate-definition-inside-trait-impl.rs @@ -19,6 +19,7 @@ impl Trait for S { //~^ ERROR duplicate definitions with name `foo` //~| ERROR: this function takes 1 argument but 0 arguments were supplied //~| ERROR: mismatched types + //~| ERROR: failed to resolve delegation callee } fn main() {} diff --git a/tests/ui/delegation/duplicate-definition-inside-trait-impl.stderr b/tests/ui/delegation/duplicate-definition-inside-trait-impl.stderr index 9e2dd8ea84ac9..ea7a30cbff898 100644 --- a/tests/ui/delegation/duplicate-definition-inside-trait-impl.stderr +++ b/tests/ui/delegation/duplicate-definition-inside-trait-impl.stderr @@ -9,6 +9,12 @@ LL | reuse to_reuse::foo { self } LL | reuse Trait::foo; | ^^^^^^^^^^^^^^^^^ duplicate definition +error: failed to resolve delegation callee + --> $DIR/duplicate-definition-inside-trait-impl.rs:18:18 + | +LL | reuse Trait::foo; + | ^^^ + error[E0061]: this function takes 1 argument but 0 arguments were supplied --> $DIR/duplicate-definition-inside-trait-impl.rs:18:18 | @@ -34,7 +40,7 @@ LL | reuse Trait::foo; | expected `()`, found `u32` | expected `()` because of default return type -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0061, E0201, E0308. For more information about an error, try `rustc --explain E0061`. diff --git a/tests/ui/delegation/explicit-paths.rs b/tests/ui/delegation/explicit-paths.rs index 2592d3d2698fc..99bc903ddeeb4 100644 --- a/tests/ui/delegation/explicit-paths.rs +++ b/tests/ui/delegation/explicit-paths.rs @@ -26,6 +26,7 @@ mod fn_to_other { reuse to_reuse::foo3; reuse S::foo4; //~^ ERROR cannot find function `foo4` in `S` + //~| ERROR: failed to resolve delegation callee } mod inherent_impl_assoc_fn_to_other { @@ -37,6 +38,7 @@ mod inherent_impl_assoc_fn_to_other { reuse to_reuse::foo3; reuse F::foo4 { &self.0 } //~^ ERROR cannot find function `foo4` in `F` + //~| ERROR: failed to resolve delegation callee } } @@ -48,9 +50,11 @@ mod trait_impl_assoc_fn_to_other { reuse ::foo2; reuse to_reuse::foo3; //~^ ERROR method `foo3` is not a member of trait `Trait` + //~| ERROR: failed to resolve delegation callee reuse F::foo4 { &self.0 } //~^ ERROR method `foo4` is not a member of trait `Trait` //~| ERROR cannot find function `foo4` in `F` + //~| ERROR: failed to resolve delegation callee } } @@ -64,6 +68,7 @@ mod trait_assoc_fn_to_other { reuse to_reuse::foo3; reuse F::foo4 { &F } //~^ ERROR cannot find function `foo4` in `F` + //~| ERROR: failed to resolve delegation callee } } diff --git a/tests/ui/delegation/explicit-paths.stderr b/tests/ui/delegation/explicit-paths.stderr index 30239f3648a53..fd225cc0cdf4a 100644 --- a/tests/ui/delegation/explicit-paths.stderr +++ b/tests/ui/delegation/explicit-paths.stderr @@ -1,5 +1,17 @@ +error: failed to resolve delegation callee + --> $DIR/explicit-paths.rs:27:14 + | +LL | reuse S::foo4; + | ^^^^ + +error: failed to resolve delegation callee + --> $DIR/explicit-paths.rs:39:18 + | +LL | reuse F::foo4 { &self.0 } + | ^^^^ + error[E0407]: method `foo3` is not a member of trait `Trait` - --> $DIR/explicit-paths.rs:49:9 + --> $DIR/explicit-paths.rs:51:9 | LL | reuse to_reuse::foo3; | ^^^^^^^^^^^^^^^^----^ @@ -7,8 +19,14 @@ LL | reuse to_reuse::foo3; | | help: there is an associated function with a similar name: `foo1` | not a member of trait `Trait` +error: failed to resolve delegation callee + --> $DIR/explicit-paths.rs:51:25 + | +LL | reuse to_reuse::foo3; + | ^^^^ + error[E0407]: method `foo4` is not a member of trait `Trait` - --> $DIR/explicit-paths.rs:51:9 + --> $DIR/explicit-paths.rs:54:9 | LL | reuse F::foo4 { &self.0 } | ^^^^^^^^^----^^^^^^^^^^^^ @@ -16,6 +34,18 @@ LL | reuse F::foo4 { &self.0 } | | help: there is an associated function with a similar name: `foo1` | not a member of trait `Trait` +error: failed to resolve delegation callee + --> $DIR/explicit-paths.rs:54:18 + | +LL | reuse F::foo4 { &self.0 } + | ^^^^ + +error: failed to resolve delegation callee + --> $DIR/explicit-paths.rs:69:18 + | +LL | reuse F::foo4 { &F } + | ^^^^ + error[E0425]: cannot find function `foo4` in `S` --> $DIR/explicit-paths.rs:27:14 | @@ -23,7 +53,7 @@ LL | reuse S::foo4; | ^^^^ not found in `S` error[E0425]: cannot find function `foo4` in `F` - --> $DIR/explicit-paths.rs:38:18 + --> $DIR/explicit-paths.rs:39:18 | LL | reuse F::foo4 { &self.0 } | ^^^^ not found in `F` @@ -35,7 +65,7 @@ LL | reuse S::foo4; | ^^^^^^^^^^^^^^ not accessible error[E0425]: cannot find function `foo4` in `F` - --> $DIR/explicit-paths.rs:51:18 + --> $DIR/explicit-paths.rs:54:18 | LL | reuse F::foo4 { &self.0 } | ^^^^ not found in `F` @@ -47,7 +77,7 @@ LL | reuse S::foo4; | ^^^^^^^^^^^^^^ not accessible error[E0425]: cannot find function `foo4` in `F` - --> $DIR/explicit-paths.rs:65:18 + --> $DIR/explicit-paths.rs:69:18 | LL | reuse F::foo4 { &F } | ^^^^ not found in `F` @@ -59,7 +89,7 @@ LL | reuse S::foo4; | ^^^^^^^^^^^^^^ not accessible error[E0119]: conflicting implementations of trait `Trait` for type `S` - --> $DIR/explicit-paths.rs:74:5 + --> $DIR/explicit-paths.rs:79:5 | LL | impl Trait for S { | ---------------- first implementation here @@ -68,7 +98,7 @@ LL | impl Trait for S { | ^^^^^^^^^^^^^^^^ conflicting implementation for `S` error[E0308]: mismatched types - --> $DIR/explicit-paths.rs:61:36 + --> $DIR/explicit-paths.rs:65:36 | LL | trait Trait2 : Trait { | -------------------- found this type parameter @@ -86,13 +116,13 @@ LL | fn foo1(&self, x: i32) -> i32 { x } | ^^^^ ----- error[E0277]: the trait bound `S2: Trait` is not satisfied - --> $DIR/explicit-paths.rs:76:16 + --> $DIR/explicit-paths.rs:81:16 | LL | reuse ::foo1; | ^^ unsatisfied trait bound | help: the trait `Trait` is not implemented for `S2` - --> $DIR/explicit-paths.rs:73:5 + --> $DIR/explicit-paths.rs:78:5 | LL | struct S2; | ^^^^^^^^^ @@ -109,7 +139,7 @@ LL | impl Trait for S { | ^^^^^^^^^^^^^^^^ `S` error[E0308]: mismatched types - --> $DIR/explicit-paths.rs:76:30 + --> $DIR/explicit-paths.rs:81:30 | LL | reuse ::foo1; | ^^^^ @@ -125,7 +155,7 @@ note: method defined here LL | fn foo1(&self, x: i32) -> i32 { x } | ^^^^ ----- -error: aborting due to 10 previous errors +error: aborting due to 15 previous errors Some errors have detailed explanations: E0119, E0277, E0308, E0407, E0425. For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.rs b/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.rs index 9276a0d220ad0..066ca64b21b99 100644 --- a/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.rs +++ b/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.rs @@ -21,6 +21,7 @@ impl Iterator { reuse< < fn()>::Output>::Item as Iterator>::*; //~^ ERROR: expected method or associated constant, found associated type `Iterator::Item` //~| ERROR: ambiguous associated type + //~| ERROR: failed to resolve delegation callee } fn main() {} diff --git a/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.stderr b/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.stderr index 4b4c1bc006632..7e4f8de34b21b 100644 --- a/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.stderr +++ b/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.stderr @@ -1,3 +1,9 @@ +error: failed to resolve delegation callee + --> $DIR/def-path-hash-collision-ice-153410.rs:21:58 + | +LL | reuse< < fn()>::Output>::Item as Iterator>::*; + | ^ + error[E0575]: expected method or associated constant, found associated type `Iterator::Item` --> $DIR/def-path-hash-collision-ice-153410.rs:21:10 | @@ -34,7 +40,7 @@ LL - reuse< < fn()>::Output>::Item as Iterator>::*; LL + reuse< < ::Output>::Item as Iterator>::*; | -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0223, E0575, E0782. For more information about an error, try `rustc --explain E0223`. diff --git a/tests/ui/delegation/generics/synth-params-ice-143498.rs b/tests/ui/delegation/generics/synth-params-ice-143498.rs index ca6d2d5c193b0..e5b7fb63592c9 100644 --- a/tests/ui/delegation/generics/synth-params-ice-143498.rs +++ b/tests/ui/delegation/generics/synth-params-ice-143498.rs @@ -21,6 +21,7 @@ impl X { reuse< std::fmt::Debug as Iterator >::*; //~^ ERROR: expected method or associated constant, found associated type `Iterator::Item` //~| ERROR: expected a type, found a trait + //~| ERROR: failed to resolve delegation callee } pub fn main() {} diff --git a/tests/ui/delegation/generics/synth-params-ice-143498.stderr b/tests/ui/delegation/generics/synth-params-ice-143498.stderr index 17154f9779475..60ea56f7abe7f 100644 --- a/tests/ui/delegation/generics/synth-params-ice-143498.stderr +++ b/tests/ui/delegation/generics/synth-params-ice-143498.stderr @@ -1,3 +1,9 @@ +error: failed to resolve delegation callee + --> $DIR/synth-params-ice-143498.rs:21:43 + | +LL | reuse< std::fmt::Debug as Iterator >::*; + | ^ + error[E0425]: cannot find type `X` in this scope --> $DIR/synth-params-ice-143498.rs:19:6 | @@ -21,7 +27,7 @@ help: you can add the `dyn` keyword if you want a trait object LL | reuse< dyn std::fmt::Debug as Iterator >::*; | +++ -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0425, E0575, E0782. For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/delegation/glob-glob-conflict.rs b/tests/ui/delegation/glob-glob-conflict.rs index beea96d167c39..df7192b3f947a 100644 --- a/tests/ui/delegation/glob-glob-conflict.rs +++ b/tests/ui/delegation/glob-glob-conflict.rs @@ -26,12 +26,14 @@ impl Trait for u8 { reuse Trait2::*; //~ ERROR duplicate definitions with name `method` //~^ ERROR: this function takes 1 argument but 0 arguments were supplied //~| ERROR: mismatched types + //~| ERROR: failed to resolve delegation callee } impl Trait for u16 { reuse Trait1::*; reuse Trait1::*; //~ ERROR duplicate definitions with name `method` //~^ ERROR: this function takes 1 argument but 0 arguments were supplied //~| ERROR: mismatched types + //~| ERROR: failed to resolve delegation callee } fn main() {} diff --git a/tests/ui/delegation/glob-glob-conflict.stderr b/tests/ui/delegation/glob-glob-conflict.stderr index 4ada3eb0efa69..5797e3c7c63cc 100644 --- a/tests/ui/delegation/glob-glob-conflict.stderr +++ b/tests/ui/delegation/glob-glob-conflict.stderr @@ -9,8 +9,14 @@ LL | reuse Trait1::*; LL | reuse Trait2::*; | ^^^^^^^^^^^^^^^^ duplicate definition +error: failed to resolve delegation callee + --> $DIR/glob-glob-conflict.rs:26:19 + | +LL | reuse Trait2::*; + | ^ + error[E0201]: duplicate definitions with name `method`: - --> $DIR/glob-glob-conflict.rs:32:5 + --> $DIR/glob-glob-conflict.rs:33:5 | LL | fn method(&self) -> u8; | ----------------------- item in trait @@ -20,6 +26,12 @@ LL | reuse Trait1::*; LL | reuse Trait1::*; | ^^^^^^^^^^^^^^^^ duplicate definition +error: failed to resolve delegation callee + --> $DIR/glob-glob-conflict.rs:33:19 + | +LL | reuse Trait1::*; + | ^ + error[E0061]: this function takes 1 argument but 0 arguments were supplied --> $DIR/glob-glob-conflict.rs:26:19 | @@ -46,7 +58,7 @@ LL | reuse Trait2::*; | expected `()` because of default return type error[E0061]: this function takes 1 argument but 0 arguments were supplied - --> $DIR/glob-glob-conflict.rs:32:19 + --> $DIR/glob-glob-conflict.rs:33:19 | LL | reuse Trait1::*; | ^ argument #1 of type `&_` is missing @@ -62,7 +74,7 @@ LL | reuse Trait1::*(/* value */); | +++++++++++++ error[E0308]: mismatched types - --> $DIR/glob-glob-conflict.rs:32:19 + --> $DIR/glob-glob-conflict.rs:33:19 | LL | reuse Trait1::*; | ^- help: consider using a semicolon here: `;` @@ -70,7 +82,7 @@ LL | reuse Trait1::*; | expected `()`, found `u8` | expected `()` because of default return type -error: aborting due to 6 previous errors +error: aborting due to 8 previous errors Some errors have detailed explanations: E0061, E0201, E0308. For more information about an error, try `rustc --explain E0061`. diff --git a/tests/ui/delegation/glob-non-fn.rs b/tests/ui/delegation/glob-non-fn.rs index 14a78e7b65e25..62ceeb2377d5d 100644 --- a/tests/ui/delegation/glob-non-fn.rs +++ b/tests/ui/delegation/glob-non-fn.rs @@ -32,6 +32,9 @@ impl Trait for Bad { //~ ERROR not all trait items implemented, missing: `CONST` //~| ERROR duplicate definitions with name `method` //~| ERROR expected function, found associated constant `Trait::CONST` //~| ERROR expected function, found associated type `Trait::Type` + //~| ERROR: failed to resolve delegation callee + //~| ERROR: failed to resolve delegation callee + //~| ERROR: failed to resolve delegation callee } fn main() {} diff --git a/tests/ui/delegation/glob-non-fn.stderr b/tests/ui/delegation/glob-non-fn.stderr index 3353290fc5b10..5592a31fa17f0 100644 --- a/tests/ui/delegation/glob-non-fn.stderr +++ b/tests/ui/delegation/glob-non-fn.stderr @@ -7,6 +7,12 @@ LL | const CONST: u8; LL | reuse Trait::* { &self.0 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait +error: failed to resolve delegation callee + --> $DIR/glob-non-fn.rs:29:18 + | +LL | reuse Trait::* { &self.0 } + | ^ + error[E0324]: item `Type` is an associated method, which doesn't match its trait `Trait` --> $DIR/glob-non-fn.rs:29:5 | @@ -16,6 +22,14 @@ LL | type Type; LL | reuse Trait::* { &self.0 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait +error: failed to resolve delegation callee + --> $DIR/glob-non-fn.rs:29:18 + | +LL | reuse Trait::* { &self.0 } + | ^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0201]: duplicate definitions with name `method`: --> $DIR/glob-non-fn.rs:29:5 | @@ -28,6 +42,14 @@ LL | reuse Trait::* { &self.0 } | duplicate definition | previous definition here +error: failed to resolve delegation callee + --> $DIR/glob-non-fn.rs:29:18 + | +LL | reuse Trait::* { &self.0 } + | ^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0423]: expected function, found associated constant `Trait::CONST` --> $DIR/glob-non-fn.rs:29:11 | @@ -54,7 +76,7 @@ LL | type method; LL | impl Trait for Bad { | ^^^^^^^^^^^^^^^^^^ missing `CONST`, `Type`, `method` in implementation -error: aborting due to 6 previous errors +error: aborting due to 9 previous errors Some errors have detailed explanations: E0046, E0201, E0324, E0423. For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/delegation/ice-issue-124342.rs b/tests/ui/delegation/ice-issue-124342.rs index b5e7d9386d33d..227d8db07db3b 100644 --- a/tests/ui/delegation/ice-issue-124342.rs +++ b/tests/ui/delegation/ice-issue-124342.rs @@ -6,6 +6,7 @@ trait Trait { reuse to_reuse::foo { foo } //~^ ERROR cannot find function `foo` in module `to_reuse` //~| ERROR cannot find value `foo` in this scope + //~| ERROR: failed to resolve delegation callee } fn main() {} diff --git a/tests/ui/delegation/ice-issue-124342.stderr b/tests/ui/delegation/ice-issue-124342.stderr index 19d75e494cafe..ab22bffbfbf52 100644 --- a/tests/ui/delegation/ice-issue-124342.stderr +++ b/tests/ui/delegation/ice-issue-124342.stderr @@ -1,3 +1,9 @@ +error: failed to resolve delegation callee + --> $DIR/ice-issue-124342.rs:6:21 + | +LL | reuse to_reuse::foo { foo } + | ^^^ + error[E0425]: cannot find function `foo` in module `to_reuse` --> $DIR/ice-issue-124342.rs:6:21 | @@ -15,6 +21,6 @@ help: you might have meant to refer to the associated function LL | reuse to_reuse::foo { Self::foo } | ++++++ -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/delegation/ice-line-bounds-issue-148732.rs b/tests/ui/delegation/ice-line-bounds-issue-148732.rs index 0123f0c8705b0..696fd42f5eb3b 100644 --- a/tests/ui/delegation/ice-line-bounds-issue-148732.rs +++ b/tests/ui/delegation/ice-line-bounds-issue-148732.rs @@ -1,6 +1,7 @@ reuse a as b { //~^ ERROR cannot find function `a` in this scope //~| ERROR functions delegation is not yet fully implemented + //~| ERROR: failed to resolve delegation callee dbg!(b); //~^ ERROR: `fn() {b}` doesn't implement `Debug` } diff --git a/tests/ui/delegation/ice-line-bounds-issue-148732.stderr b/tests/ui/delegation/ice-line-bounds-issue-148732.stderr index eb93655beb60d..d4d488edfd889 100644 --- a/tests/ui/delegation/ice-line-bounds-issue-148732.stderr +++ b/tests/ui/delegation/ice-line-bounds-issue-148732.stderr @@ -1,3 +1,9 @@ +error: failed to resolve delegation callee + --> $DIR/ice-line-bounds-issue-148732.rs:1:7 + | +LL | reuse a as b { + | ^ + error[E0425]: cannot find function `a` in this scope --> $DIR/ice-line-bounds-issue-148732.rs:1:7 | @@ -8,10 +14,7 @@ error[E0658]: functions delegation is not yet fully implemented --> $DIR/ice-line-bounds-issue-148732.rs:1:1 | LL | / reuse a as b { -LL | | -LL | | -LL | | dbg!(b); -LL | | +... | LL | | } | |_^ | @@ -20,7 +23,7 @@ LL | | } = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0277]: `fn() {b}` doesn't implement `Debug` - --> $DIR/ice-line-bounds-issue-148732.rs:4:5 + --> $DIR/ice-line-bounds-issue-148732.rs:5:5 | LL | reuse a as b { | - consider calling this function @@ -30,7 +33,7 @@ LL | dbg!(b); | = help: use parentheses to call this function: `b()` -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0277, E0425, E0658. For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/delegation/impl-reuse-non-reuse-items.rs b/tests/ui/delegation/impl-reuse-non-reuse-items.rs index 0dbe8016c1e8e..be8294a1280c4 100644 --- a/tests/ui/delegation/impl-reuse-non-reuse-items.rs +++ b/tests/ui/delegation/impl-reuse-non-reuse-items.rs @@ -26,6 +26,9 @@ mod non_delegatable_items { //~| ERROR expected function, found associated constant `Trait::CONST` //~| ERROR expected function, found associated type `Trait::Type` //~| ERROR not all trait items implemented, missing: `CONST`, `Type`, `method` + //~| ERROR: failed to resolve delegation callee + //~| ERROR: failed to resolve delegation callee + //~| ERROR: failed to resolve delegation callee } fn main() {} diff --git a/tests/ui/delegation/impl-reuse-non-reuse-items.stderr b/tests/ui/delegation/impl-reuse-non-reuse-items.stderr index 044c9aa5a7ab9..5b2c95e69e3b1 100644 --- a/tests/ui/delegation/impl-reuse-non-reuse-items.stderr +++ b/tests/ui/delegation/impl-reuse-non-reuse-items.stderr @@ -7,6 +7,12 @@ LL | const CONST: u8; LL | reuse impl Trait for S { &self.0 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait +error: failed to resolve delegation callee + --> $DIR/impl-reuse-non-reuse-items.rs:22:5 + | +LL | reuse impl Trait for S { &self.0 } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + error[E0324]: item `Type` is an associated method, which doesn't match its trait `Trait` --> $DIR/impl-reuse-non-reuse-items.rs:22:5 | @@ -16,6 +22,14 @@ LL | type Type; LL | reuse impl Trait for S { &self.0 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait +error: failed to resolve delegation callee + --> $DIR/impl-reuse-non-reuse-items.rs:22:5 + | +LL | reuse impl Trait for S { &self.0 } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0201]: duplicate definitions with name `method`: --> $DIR/impl-reuse-non-reuse-items.rs:22:5 | @@ -28,6 +42,14 @@ LL | reuse impl Trait for S { &self.0 } | duplicate definition | previous definition here +error: failed to resolve delegation callee + --> $DIR/impl-reuse-non-reuse-items.rs:22:5 + | +LL | reuse impl Trait for S { &self.0 } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + error[E0423]: expected function, found associated constant `Trait::CONST` --> $DIR/impl-reuse-non-reuse-items.rs:22:16 | @@ -54,7 +76,7 @@ LL | type method; LL | reuse impl Trait for S { &self.0 } | ^^^^^^^^^^^^^^^^^^^^^^ missing `CONST`, `Type`, `method` in implementation -error: aborting due to 6 previous errors +error: aborting due to 9 previous errors Some errors have detailed explanations: E0046, E0201, E0324, E0423. For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/delegation/recursive-delegation-ice-150152.rs b/tests/ui/delegation/recursive-delegation-ice-150152.rs index c4aaa7fd2d1f2..b2feafb5ef6ef 100644 --- a/tests/ui/delegation/recursive-delegation-ice-150152.rs +++ b/tests/ui/delegation/recursive-delegation-ice-150152.rs @@ -9,6 +9,7 @@ mod first_example { //~^ ERROR cannot find trait `Item` in this scope //~| ERROR missing generics for struct `S` reuse to_reuse::foo; + //~^ ERROR: failed to resolve delegation callee } } diff --git a/tests/ui/delegation/recursive-delegation-ice-150152.stderr b/tests/ui/delegation/recursive-delegation-ice-150152.stderr index b59b588f4968a..019e59cdeff12 100644 --- a/tests/ui/delegation/recursive-delegation-ice-150152.stderr +++ b/tests/ui/delegation/recursive-delegation-ice-150152.stderr @@ -1,3 +1,9 @@ +error: failed to resolve delegation callee + --> $DIR/recursive-delegation-ice-150152.rs:11:25 + | +LL | reuse to_reuse::foo; + | ^^^ + error[E0405]: cannot find trait `Item` in this scope --> $DIR/recursive-delegation-ice-150152.rs:8:10 | @@ -5,7 +11,7 @@ LL | impl Item for S { | ^^^^ not found in this scope error[E0425]: cannot find type `S` in this scope - --> $DIR/recursive-delegation-ice-150152.rs:23:20 + --> $DIR/recursive-delegation-ice-150152.rs:24:20 | LL | impl Trait for S { | ^ not found in this scope @@ -17,7 +23,7 @@ LL | struct S< S >; | ^^^^^^^^^^^^^^ not accessible error[E0425]: cannot find function `foo` in this scope - --> $DIR/recursive-delegation-ice-150152.rs:25:15 + --> $DIR/recursive-delegation-ice-150152.rs:26:15 | LL | reuse foo; | ^^^ not found in this scope @@ -32,13 +38,13 @@ LL | fn foo() {} | ^^^^^^^^ `second_example::to_reuse::foo`: not accessible error[E0603]: function `foo` is private - --> $DIR/recursive-delegation-ice-150152.rs:17:25 + --> $DIR/recursive-delegation-ice-150152.rs:18:25 | LL | reuse to_reuse::foo; | ^^^ private function | note: the function `foo` is defined here - --> $DIR/recursive-delegation-ice-150152.rs:21:9 + --> $DIR/recursive-delegation-ice-150152.rs:22:9 | LL | fn foo() {} | ^^^^^^^^ @@ -68,7 +74,7 @@ help: add missing generic argument LL | impl Item for S> { | +++ -error: aborting due to 6 previous errors +error: aborting due to 7 previous errors Some errors have detailed explanations: E0107, E0392, E0405, E0425, E0603. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/delegation/unused-import-ice-144594.rs b/tests/ui/delegation/unused-import-ice-144594.rs index fca67c6ee0b81..c9859c048bb02 100644 --- a/tests/ui/delegation/unused-import-ice-144594.rs +++ b/tests/ui/delegation/unused-import-ice-144594.rs @@ -2,6 +2,7 @@ reuse a as b { //~^ ERROR cannot find function `a` in this scope [E0425] + //~| ERROR: failed to resolve delegation callee || { use std::ops::Add; x.add diff --git a/tests/ui/delegation/unused-import-ice-144594.stderr b/tests/ui/delegation/unused-import-ice-144594.stderr index f09313aac21f4..d6e48e36edf1b 100644 --- a/tests/ui/delegation/unused-import-ice-144594.stderr +++ b/tests/ui/delegation/unused-import-ice-144594.stderr @@ -1,3 +1,9 @@ +error: failed to resolve delegation callee + --> $DIR/unused-import-ice-144594.rs:3:7 + | +LL | reuse a as b { + | ^ + error[E0425]: cannot find function `a` in this scope --> $DIR/unused-import-ice-144594.rs:3:7 | @@ -5,11 +11,11 @@ LL | reuse a as b { | ^ not found in this scope error[E0425]: cannot find value `x` in this scope - --> $DIR/unused-import-ice-144594.rs:7:9 + --> $DIR/unused-import-ice-144594.rs:8:9 | LL | x.add | ^ not found in this scope -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/delegation/wrong-lifetime-rib.rs b/tests/ui/delegation/wrong-lifetime-rib.rs index 01645f20bf7b1..e0d894a981945 100644 --- a/tests/ui/delegation/wrong-lifetime-rib.rs +++ b/tests/ui/delegation/wrong-lifetime-rib.rs @@ -10,6 +10,7 @@ mod ice_156342 { //~^ ERROR: cannot define inherent `impl` for a type outside of the crate where the type is defined reuse None::<&()>; //~^ ERROR: expected function, found unit variant `None` + //~| ERROR: failed to resolve delegation callee } fn foo() {} diff --git a/tests/ui/delegation/wrong-lifetime-rib.stderr b/tests/ui/delegation/wrong-lifetime-rib.stderr index 0c4499eec192d..7e4473151c63f 100644 --- a/tests/ui/delegation/wrong-lifetime-rib.stderr +++ b/tests/ui/delegation/wrong-lifetime-rib.stderr @@ -1,3 +1,9 @@ +error: failed to resolve delegation callee + --> $DIR/wrong-lifetime-rib.rs:11:15 + | +LL | reuse None::<&()>; + | ^^^^ + error[E0423]: expected function, found unit variant `None` --> $DIR/wrong-lifetime-rib.rs:11:15 | @@ -5,7 +11,7 @@ LL | reuse None::<&()>; | ^^^^^^^^^^^ not a function error[E0782]: expected a type, found a trait - --> $DIR/wrong-lifetime-rib.rs:26:10 + --> $DIR/wrong-lifetime-rib.rs:27:10 | LL | impl X { | ^ @@ -20,7 +26,7 @@ LL | impl X for /* Type */ { | ++++++++++++++ error[E0782]: expected a type, found a trait - --> $DIR/wrong-lifetime-rib.rs:35:10 + --> $DIR/wrong-lifetime-rib.rs:36:10 | LL | impl X { | ^ @@ -44,7 +50,7 @@ LL | impl Trait { = note: for more details about the orphan rules, see error[E0223]: ambiguous associated type - --> $DIR/wrong-lifetime-rib.rs:27:16 + --> $DIR/wrong-lifetime-rib.rs:28:16 | LL | reuse<<<&Project> :: Ty> :: Ty as Iterator>::next; | ^^^^^^^^^^^^^^^^ @@ -56,7 +62,7 @@ LL + reuse<<<&() as Example>::Ty> :: Ty as Iterator>::next; | error[E0782]: expected a type, found a trait - --> $DIR/wrong-lifetime-rib.rs:37:21 + --> $DIR/wrong-lifetime-rib.rs:38:21 | LL | let _: &X; | ^ @@ -66,7 +72,7 @@ help: you can add the `dyn` keyword if you want a trait object LL | let _: &dyn X; | +++ -error: aborting due to 6 previous errors +error: aborting due to 7 previous errors Some errors have detailed explanations: E0116, E0223, E0423, E0782. For more information about an error, try `rustc --explain E0116`. From 4c2c364833ca5932a09a4109854b2fb9debe6057 Mon Sep 17 00:00:00 2001 From: aerooneqq Date: Wed, 3 Jun 2026 10:59:35 +0300 Subject: [PATCH 3/6] Small cleanups --- compiler/rustc_ast_lowering/src/delegation.rs | 2 -- compiler/rustc_resolve/src/late.rs | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/delegation.rs b/compiler/rustc_ast_lowering/src/delegation.rs index 7ec40b9ec0dbb..4b52e4b1af698 100644 --- a/compiler/rustc_ast_lowering/src/delegation.rs +++ b/compiler/rustc_ast_lowering/src/delegation.rs @@ -154,8 +154,6 @@ fn check_for_cycles( { def_id = delegation_info.resolution_id; if visited.contains(&def_id) { - // We encountered a cycle in the resolution, or delegation callee refers to non-existent - // entity, in this case emit an error. return Err(tcx.dcx().emit_err(CycleInDelegationSignatureResolution { span })); } } else { diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index bd5615117b253..edccd8bfc59a4 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -3900,11 +3900,11 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { this.visit_path(&delegation.path); }); - let resolution_id = if is_in_trait_impl { item_id } else { delegation.id }; + let resolution_node_id = if is_in_trait_impl { item_id } else { delegation.id }; let def_id = self .r .partial_res_map - .get(&resolution_id) + .get(&resolution_node_id) .and_then(|r| r.expect_full_res().opt_def_id()); let resolution = if let Some(resolution_id) = def_id @@ -3917,7 +3917,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { self.r.tcx.dcx().span_delayed_bug( delegation.path.span, format!( - "LoweringContext: couldn't resolve node {resolution_id:?} in delegation item", + "LateResolutionVisitor: couldn't resolve node {resolution_node_id:?} in delegation item", ), ); From b19da8bd653079bba3ad5854f93b6283fcd1609b Mon Sep 17 00:00:00 2001 From: aerooneqq Date: Wed, 3 Jun 2026 15:37:15 +0300 Subject: [PATCH 4/6] Remove error reporting + move `Result<...>` in `DelegationInfo` --- compiler/rustc_ast_lowering/src/delegation.rs | 21 ++--- compiler/rustc_ast_lowering/src/lib.rs | 4 +- compiler/rustc_middle/src/ty/mod.rs | 4 +- compiler/rustc_resolve/src/errors.rs | 7 -- compiler/rustc_resolve/src/late.rs | 15 ++-- compiler/rustc_resolve/src/lib.rs | 2 +- tests/ui/delegation/bad-resolve.rs | 10 --- tests/ui/delegation/bad-resolve.stderr | 82 +++---------------- .../duplicate-definition-inside-trait-impl.rs | 1 - ...licate-definition-inside-trait-impl.stderr | 8 +- tests/ui/delegation/explicit-paths.rs | 5 -- tests/ui/delegation/explicit-paths.stderr | 52 +++--------- .../def-path-hash-collision-ice-153410.rs | 1 - .../def-path-hash-collision-ice-153410.stderr | 8 +- .../generics/synth-params-ice-143498.rs | 1 - .../generics/synth-params-ice-143498.stderr | 8 +- tests/ui/delegation/glob-glob-conflict.rs | 2 - tests/ui/delegation/glob-glob-conflict.stderr | 20 +---- tests/ui/delegation/glob-non-fn.rs | 3 - tests/ui/delegation/glob-non-fn.stderr | 24 +----- tests/ui/delegation/ice-issue-124342.rs | 1 - tests/ui/delegation/ice-issue-124342.stderr | 8 +- tests/ui/delegation/ice-issue-124347.rs | 6 +- tests/ui/delegation/ice-issue-124347.stderr | 16 +--- .../ice-line-bounds-issue-148732.rs | 1 - .../ice-line-bounds-issue-148732.stderr | 15 ++-- .../delegation/impl-reuse-non-reuse-items.rs | 3 - .../impl-reuse-non-reuse-items.stderr | 24 +----- .../delegation/recursive-delegation-errors.rs | 3 +- .../recursive-delegation-errors.stderr | 48 +++++------ .../recursive-delegation-ice-150152.rs | 1 - .../recursive-delegation-ice-150152.stderr | 16 ++-- .../delegation/unlowered-path-ice-154820.rs | 2 +- .../unlowered-path-ice-154820.stderr | 8 +- .../ui/delegation/unused-import-ice-144594.rs | 1 - .../unused-import-ice-144594.stderr | 10 +-- tests/ui/delegation/wrong-lifetime-rib.rs | 1 - tests/ui/delegation/wrong-lifetime-rib.stderr | 16 ++-- 38 files changed, 96 insertions(+), 362 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/delegation.rs b/compiler/rustc_ast_lowering/src/delegation.rs index 4b52e4b1af698..9610d766f8f27 100644 --- a/compiler/rustc_ast_lowering/src/delegation.rs +++ b/compiler/rustc_ast_lowering/src/delegation.rs @@ -52,7 +52,6 @@ use rustc_middle::span_bug; use rustc_middle::ty::{Asyncness, TyCtxt}; use rustc_span::symbol::kw; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol}; -use smallvec::SmallVec; use crate::delegation::generics::{GenericsGenerationResult, GenericsGenerationResults}; use crate::errors::CycleInDelegationSignatureResolution; @@ -122,8 +121,8 @@ pub fn delegations_resolutions( let delegation = ast_index[def_id].delegation().expect("processing delegations"); let span = delegation.last_segment_span(); - if let Some(res_result) = resolver.delegation_info(def_id) { - let res = res_result.map(|info| check_for_cycles(tcx, info.resolution_id, span)); + if let Some(info) = resolver.delegation_info(def_id) { + let res = info.resolution_id.map(|id| check_for_cycles(tcx, id, span).map(|_| id)); result.insert(def_id, res.flatten()); } } @@ -131,33 +130,27 @@ pub fn delegations_resolutions( result } -fn check_for_cycles( - tcx: TyCtxt<'_>, - mut def_id: DefId, - span: Span, -) -> Result { +fn check_for_cycles(tcx: TyCtxt<'_>, mut def_id: DefId, span: Span) -> Result<(), ErrorGuaranteed> { let mut visited: FxHashSet = Default::default(); - let mut path: SmallVec<[DefId; 1]> = Default::default(); let (resolver, _) = &*tcx.hir_crate(()).delayed_resolver.borrow(); loop { visited.insert(def_id); - path.push(def_id); - // If def_id is in local crate and it corresponds to another delegation // it means that we refer to another delegation as a callee, so in order to obtain // a signature DefId we obtain NodeId of the callee delegation and try to get signature from it. if let Some(local_id) = def_id.as_local() - && let Some(Ok(delegation_info)) = resolver.delegation_info(local_id) + && let Some(info) = resolver.delegation_info(local_id) + && let Ok(id) = info.resolution_id { - def_id = delegation_info.resolution_id; + def_id = id; if visited.contains(&def_id) { return Err(tcx.dcx().emit_err(CycleInDelegationSignatureResolution { span })); } } else { - return Ok(path[0]); + return Ok(()); } } } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index f6ab50af1e9da..3a0ac550d4b83 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -64,7 +64,7 @@ use rustc_middle::span_bug; use rustc_middle::ty::{DelegationInfo, PerOwnerResolverData, ResolverAstLowering, TyCtxt}; use rustc_session::errors::add_feature_diagnostics; use rustc_span::symbol::{Ident, Symbol, kw, sym}; -use rustc_span::{DUMMY_SP, DesugaringKind, ErrorGuaranteed, Span}; +use rustc_span::{DUMMY_SP, DesugaringKind, Span}; use smallvec::SmallVec; use thin_vec::ThinVec; use tracing::{debug, instrument, trace}; @@ -304,7 +304,7 @@ impl<'tcx> ResolverAstLowering<'tcx> { self.extra_lifetime_params_map.get(&id).map_or(&[], |v| &v[..]) } - fn delegation_info(&self, id: LocalDefId) -> Option> { + fn delegation_info(&self, id: LocalDefId) -> Option { self.delegation_infos.get(&id).copied() } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 80199288fc551..aebba4777e650 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -257,7 +257,7 @@ pub struct ResolverAstLowering<'tcx> { pub lint_buffer: Steal, // Information about delegations which is used when handling recursive delegations - pub delegation_infos: LocalDefIdMap>, + pub delegation_infos: LocalDefIdMap, pub disambiguators: LocalDefIdMap>, } @@ -269,7 +269,7 @@ pub struct DelegationInfo { /// Refers to the next element in a delegation resolution chain. /// Usually points to the final resolution, as most "chains" are just /// one step to a trait or an impl. - pub resolution_id: DefId, + pub resolution_id: Result, } #[derive(Clone, Copy, Debug, StableHash)] diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index 8a2c289b6eafc..4bcc7a5eb02e8 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -1776,10 +1776,3 @@ pub(crate) enum UnusedImportsSugg { num_to_remove: usize, }, } - -#[derive(Diagnostic)] -#[diag("failed to resolve delegation callee")] -pub(crate) struct UnresolvedDelegationCallee { - #[primary_span] - pub span: Span, -} diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index edccd8bfc59a4..08ae233f8c7f6 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -39,7 +39,6 @@ use smallvec::{SmallVec, smallvec}; use thin_vec::ThinVec; use tracing::{debug, instrument, trace}; -use crate::errors::UnresolvedDelegationCallee; use crate::{ BindingError, BindingKey, Decl, DelegationFnSig, Finalize, IdentKey, LateDecl, LocalModule, Module, ModuleOrUniformRoot, ParentScope, PathResult, Res, ResolutionError, Resolver, Segment, @@ -3907,25 +3906,23 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { .get(&resolution_node_id) .and_then(|r| r.expect_full_res().opt_def_id()); - let resolution = if let Some(resolution_id) = def_id + let resolution_id = if let Some(resolution_id) = def_id // If there is a single unresolved `reuse foo` in a mod it resolves to itself, // in this case emit `UnresolvedDelegationCallee` error instead of cycle error. && resolution_id != self.r.current_owner.def_id.to_def_id() { - Ok(DelegationInfo { resolution_id }) + Ok(resolution_id) } else { - self.r.tcx.dcx().span_delayed_bug( + Err(self.r.tcx.dcx().span_delayed_bug( delegation.path.span, format!( "LateResolutionVisitor: couldn't resolve node {resolution_node_id:?} in delegation item", ), - ); - - let err = UnresolvedDelegationCallee { span: delegation.last_segment_span() }; - Err(self.r.tcx.dcx().emit_err(err)) + )) }; - self.r.delegation_infos.insert(self.r.current_owner.def_id, resolution); + let info = DelegationInfo { resolution_id }; + self.r.delegation_infos.insert(self.r.current_owner.def_id, info); let Some(body) = &delegation.body else { return }; self.with_rib(ValueNS, RibKind::FnOrCoroutine, |this| { diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index e5614111e48de..ffb2181bae3a9 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -1509,7 +1509,7 @@ pub struct Resolver<'ra, 'tcx> { /// Generic args to suggest for required params (e.g. `<'_>`, `<_, _>`), if any. item_required_generic_args_suggestions: FxHashMap = default::fx_hash_map(), delegation_fn_sigs: LocalDefIdMap = Default::default(), - delegation_infos: LocalDefIdMap> = Default::default(), + delegation_infos: LocalDefIdMap = Default::default(), main_def: Option = None, trait_impls: FxIndexMap>, diff --git a/tests/ui/delegation/bad-resolve.rs b/tests/ui/delegation/bad-resolve.rs index 24b623cc3bdb6..2c2c622e09006 100644 --- a/tests/ui/delegation/bad-resolve.rs +++ b/tests/ui/delegation/bad-resolve.rs @@ -23,15 +23,12 @@ impl Trait for S { reuse ::C; //~^ ERROR item `C` is an associated method, which doesn't match its trait `Trait` //~| ERROR expected function, found associated constant `Trait::C` - //~| ERROR: failed to resolve delegation callee reuse ::Type; //~^ ERROR item `Type` is an associated method, which doesn't match its trait `Trait` //~| ERROR expected method or associated constant, found associated type `Trait::Type` - //~| ERROR: failed to resolve delegation callee reuse ::baz; //~^ ERROR method `baz` is not a member of trait `Trait` //~| ERROR cannot find method or associated constant `baz` in trait `Trait` - //~| ERROR: failed to resolve delegation callee reuse ::bar; reuse foo { &self.0 } @@ -39,18 +36,11 @@ impl Trait for S { reuse Trait::foo2 { self.0 } //~^ ERROR cannot find function `foo2` in trait `Trait` //~| ERROR method `foo2` is not a member of trait `Trait` - //~| ERROR: failed to resolve delegation callee } mod prefix {} reuse unresolved_prefix::{a, b, c}; //~ ERROR cannot find module or crate `unresolved_prefix` -//~^ ERROR: failed to resolve delegation callee -//~| ERROR: failed to resolve delegation callee -//~| ERROR: failed to resolve delegation callee reuse prefix::{self, super, crate}; //~ ERROR `crate` in paths can only be used in start position //~^ ERROR expected function, found module `prefix::self` -//~| ERROR: failed to resolve delegation callee -//~| ERROR: failed to resolve delegation callee -//~| ERROR: failed to resolve delegation callee fn main() {} diff --git a/tests/ui/delegation/bad-resolve.stderr b/tests/ui/delegation/bad-resolve.stderr index e6e1fe5bbc421..d1b3974e77081 100644 --- a/tests/ui/delegation/bad-resolve.stderr +++ b/tests/ui/delegation/bad-resolve.stderr @@ -7,14 +7,8 @@ LL | const C: u32 = 0; LL | reuse ::C; | ^^^^^^^^^^^^^^^^^^^^^^ does not match trait -error: failed to resolve delegation callee - --> $DIR/bad-resolve.rs:23:25 - | -LL | reuse ::C; - | ^ - error[E0324]: item `Type` is an associated method, which doesn't match its trait `Trait` - --> $DIR/bad-resolve.rs:27:5 + --> $DIR/bad-resolve.rs:26:5 | LL | type Type; | ---------- item in trait @@ -22,14 +16,8 @@ LL | type Type; LL | reuse ::Type; | ^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait -error: failed to resolve delegation callee - --> $DIR/bad-resolve.rs:27:25 - | -LL | reuse ::Type; - | ^^^^ - error[E0407]: method `baz` is not a member of trait `Trait` - --> $DIR/bad-resolve.rs:31:5 + --> $DIR/bad-resolve.rs:29:5 | LL | reuse ::baz; | ^^^^^^^^^^^^^^^^^^^^---^ @@ -37,14 +25,8 @@ LL | reuse ::baz; | | help: there is an associated function with a similar name: `bar` | not a member of trait `Trait` -error: failed to resolve delegation callee - --> $DIR/bad-resolve.rs:31:25 - | -LL | reuse ::baz; - | ^^^ - error[E0407]: method `foo2` is not a member of trait `Trait` - --> $DIR/bad-resolve.rs:39:5 + --> $DIR/bad-resolve.rs:36:5 | LL | reuse Trait::foo2 { self.0 } | ^^^^^^^^^^^^^----^^^^^^^^^^^ @@ -52,48 +34,6 @@ LL | reuse Trait::foo2 { self.0 } | | help: there is an associated function with a similar name: `foo` | not a member of trait `Trait` -error: failed to resolve delegation callee - --> $DIR/bad-resolve.rs:39:18 - | -LL | reuse Trait::foo2 { self.0 } - | ^^^^ - -error: failed to resolve delegation callee - --> $DIR/bad-resolve.rs:46:27 - | -LL | reuse unresolved_prefix::{a, b, c}; - | ^ - -error: failed to resolve delegation callee - --> $DIR/bad-resolve.rs:46:30 - | -LL | reuse unresolved_prefix::{a, b, c}; - | ^ - -error: failed to resolve delegation callee - --> $DIR/bad-resolve.rs:46:33 - | -LL | reuse unresolved_prefix::{a, b, c}; - | ^ - -error: failed to resolve delegation callee - --> $DIR/bad-resolve.rs:50:16 - | -LL | reuse prefix::{self, super, crate}; - | ^^^^ - -error: failed to resolve delegation callee - --> $DIR/bad-resolve.rs:50:22 - | -LL | reuse prefix::{self, super, crate}; - | ^^^^^ - -error: failed to resolve delegation callee - --> $DIR/bad-resolve.rs:50:29 - | -LL | reuse prefix::{self, super, crate}; - | ^^^^^ - error[E0423]: expected function, found associated constant `Trait::C` --> $DIR/bad-resolve.rs:23:11 | @@ -101,13 +41,13 @@ LL | reuse ::C; | ^^^^^^^^^^^^^^^ not a function error[E0575]: expected method or associated constant, found associated type `Trait::Type` - --> $DIR/bad-resolve.rs:27:11 + --> $DIR/bad-resolve.rs:26:11 | LL | reuse ::Type; | ^^^^^^^^^^^^^^^^^^ not a method or associated constant error[E0576]: cannot find method or associated constant `baz` in trait `Trait` - --> $DIR/bad-resolve.rs:31:25 + --> $DIR/bad-resolve.rs:29:25 | LL | fn bar() {} | -------- similarly named associated function `bar` defined here @@ -122,13 +62,13 @@ LL + reuse ::bar; | error[E0425]: cannot find function `foo` in this scope - --> $DIR/bad-resolve.rs:37:11 + --> $DIR/bad-resolve.rs:34:11 | LL | reuse foo { &self.0 } | ^^^ not found in this scope error[E0425]: cannot find function `foo2` in trait `Trait` - --> $DIR/bad-resolve.rs:39:18 + --> $DIR/bad-resolve.rs:36:18 | LL | fn foo(&self, x: i32) -> i32 { x } | ---------------------------- similarly named associated function `foo` defined here @@ -143,7 +83,7 @@ LL + reuse Trait::foo { self.0 } | error[E0423]: expected function, found module `prefix::self` - --> $DIR/bad-resolve.rs:50:7 + --> $DIR/bad-resolve.rs:43:7 | LL | reuse prefix::{self, super, crate}; | ^^^^^^ not a function @@ -158,7 +98,7 @@ LL | impl Trait for S { | ^^^^^^^^^^^^^^^^ missing `Type` in implementation error[E0433]: cannot find module or crate `unresolved_prefix` in this scope - --> $DIR/bad-resolve.rs:46:7 + --> $DIR/bad-resolve.rs:42:7 | LL | reuse unresolved_prefix::{a, b, c}; | ^^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `unresolved_prefix` @@ -166,12 +106,12 @@ LL | reuse unresolved_prefix::{a, b, c}; = help: you might be missing a crate named `unresolved_prefix` error[E0433]: `crate` in paths can only be used in start position - --> $DIR/bad-resolve.rs:50:29 + --> $DIR/bad-resolve.rs:43:29 | LL | reuse prefix::{self, super, crate}; | ^^^^^ can only be used in path start position -error: aborting due to 23 previous errors +error: aborting due to 13 previous errors Some errors have detailed explanations: E0046, E0324, E0407, E0423, E0425, E0433, E0575, E0576. For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/delegation/duplicate-definition-inside-trait-impl.rs b/tests/ui/delegation/duplicate-definition-inside-trait-impl.rs index e0e8261795e61..ecd47a7ccaa94 100644 --- a/tests/ui/delegation/duplicate-definition-inside-trait-impl.rs +++ b/tests/ui/delegation/duplicate-definition-inside-trait-impl.rs @@ -19,7 +19,6 @@ impl Trait for S { //~^ ERROR duplicate definitions with name `foo` //~| ERROR: this function takes 1 argument but 0 arguments were supplied //~| ERROR: mismatched types - //~| ERROR: failed to resolve delegation callee } fn main() {} diff --git a/tests/ui/delegation/duplicate-definition-inside-trait-impl.stderr b/tests/ui/delegation/duplicate-definition-inside-trait-impl.stderr index ea7a30cbff898..9e2dd8ea84ac9 100644 --- a/tests/ui/delegation/duplicate-definition-inside-trait-impl.stderr +++ b/tests/ui/delegation/duplicate-definition-inside-trait-impl.stderr @@ -9,12 +9,6 @@ LL | reuse to_reuse::foo { self } LL | reuse Trait::foo; | ^^^^^^^^^^^^^^^^^ duplicate definition -error: failed to resolve delegation callee - --> $DIR/duplicate-definition-inside-trait-impl.rs:18:18 - | -LL | reuse Trait::foo; - | ^^^ - error[E0061]: this function takes 1 argument but 0 arguments were supplied --> $DIR/duplicate-definition-inside-trait-impl.rs:18:18 | @@ -40,7 +34,7 @@ LL | reuse Trait::foo; | expected `()`, found `u32` | expected `()` because of default return type -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0061, E0201, E0308. For more information about an error, try `rustc --explain E0061`. diff --git a/tests/ui/delegation/explicit-paths.rs b/tests/ui/delegation/explicit-paths.rs index 99bc903ddeeb4..2592d3d2698fc 100644 --- a/tests/ui/delegation/explicit-paths.rs +++ b/tests/ui/delegation/explicit-paths.rs @@ -26,7 +26,6 @@ mod fn_to_other { reuse to_reuse::foo3; reuse S::foo4; //~^ ERROR cannot find function `foo4` in `S` - //~| ERROR: failed to resolve delegation callee } mod inherent_impl_assoc_fn_to_other { @@ -38,7 +37,6 @@ mod inherent_impl_assoc_fn_to_other { reuse to_reuse::foo3; reuse F::foo4 { &self.0 } //~^ ERROR cannot find function `foo4` in `F` - //~| ERROR: failed to resolve delegation callee } } @@ -50,11 +48,9 @@ mod trait_impl_assoc_fn_to_other { reuse ::foo2; reuse to_reuse::foo3; //~^ ERROR method `foo3` is not a member of trait `Trait` - //~| ERROR: failed to resolve delegation callee reuse F::foo4 { &self.0 } //~^ ERROR method `foo4` is not a member of trait `Trait` //~| ERROR cannot find function `foo4` in `F` - //~| ERROR: failed to resolve delegation callee } } @@ -68,7 +64,6 @@ mod trait_assoc_fn_to_other { reuse to_reuse::foo3; reuse F::foo4 { &F } //~^ ERROR cannot find function `foo4` in `F` - //~| ERROR: failed to resolve delegation callee } } diff --git a/tests/ui/delegation/explicit-paths.stderr b/tests/ui/delegation/explicit-paths.stderr index fd225cc0cdf4a..30239f3648a53 100644 --- a/tests/ui/delegation/explicit-paths.stderr +++ b/tests/ui/delegation/explicit-paths.stderr @@ -1,17 +1,5 @@ -error: failed to resolve delegation callee - --> $DIR/explicit-paths.rs:27:14 - | -LL | reuse S::foo4; - | ^^^^ - -error: failed to resolve delegation callee - --> $DIR/explicit-paths.rs:39:18 - | -LL | reuse F::foo4 { &self.0 } - | ^^^^ - error[E0407]: method `foo3` is not a member of trait `Trait` - --> $DIR/explicit-paths.rs:51:9 + --> $DIR/explicit-paths.rs:49:9 | LL | reuse to_reuse::foo3; | ^^^^^^^^^^^^^^^^----^ @@ -19,14 +7,8 @@ LL | reuse to_reuse::foo3; | | help: there is an associated function with a similar name: `foo1` | not a member of trait `Trait` -error: failed to resolve delegation callee - --> $DIR/explicit-paths.rs:51:25 - | -LL | reuse to_reuse::foo3; - | ^^^^ - error[E0407]: method `foo4` is not a member of trait `Trait` - --> $DIR/explicit-paths.rs:54:9 + --> $DIR/explicit-paths.rs:51:9 | LL | reuse F::foo4 { &self.0 } | ^^^^^^^^^----^^^^^^^^^^^^ @@ -34,18 +16,6 @@ LL | reuse F::foo4 { &self.0 } | | help: there is an associated function with a similar name: `foo1` | not a member of trait `Trait` -error: failed to resolve delegation callee - --> $DIR/explicit-paths.rs:54:18 - | -LL | reuse F::foo4 { &self.0 } - | ^^^^ - -error: failed to resolve delegation callee - --> $DIR/explicit-paths.rs:69:18 - | -LL | reuse F::foo4 { &F } - | ^^^^ - error[E0425]: cannot find function `foo4` in `S` --> $DIR/explicit-paths.rs:27:14 | @@ -53,7 +23,7 @@ LL | reuse S::foo4; | ^^^^ not found in `S` error[E0425]: cannot find function `foo4` in `F` - --> $DIR/explicit-paths.rs:39:18 + --> $DIR/explicit-paths.rs:38:18 | LL | reuse F::foo4 { &self.0 } | ^^^^ not found in `F` @@ -65,7 +35,7 @@ LL | reuse S::foo4; | ^^^^^^^^^^^^^^ not accessible error[E0425]: cannot find function `foo4` in `F` - --> $DIR/explicit-paths.rs:54:18 + --> $DIR/explicit-paths.rs:51:18 | LL | reuse F::foo4 { &self.0 } | ^^^^ not found in `F` @@ -77,7 +47,7 @@ LL | reuse S::foo4; | ^^^^^^^^^^^^^^ not accessible error[E0425]: cannot find function `foo4` in `F` - --> $DIR/explicit-paths.rs:69:18 + --> $DIR/explicit-paths.rs:65:18 | LL | reuse F::foo4 { &F } | ^^^^ not found in `F` @@ -89,7 +59,7 @@ LL | reuse S::foo4; | ^^^^^^^^^^^^^^ not accessible error[E0119]: conflicting implementations of trait `Trait` for type `S` - --> $DIR/explicit-paths.rs:79:5 + --> $DIR/explicit-paths.rs:74:5 | LL | impl Trait for S { | ---------------- first implementation here @@ -98,7 +68,7 @@ LL | impl Trait for S { | ^^^^^^^^^^^^^^^^ conflicting implementation for `S` error[E0308]: mismatched types - --> $DIR/explicit-paths.rs:65:36 + --> $DIR/explicit-paths.rs:61:36 | LL | trait Trait2 : Trait { | -------------------- found this type parameter @@ -116,13 +86,13 @@ LL | fn foo1(&self, x: i32) -> i32 { x } | ^^^^ ----- error[E0277]: the trait bound `S2: Trait` is not satisfied - --> $DIR/explicit-paths.rs:81:16 + --> $DIR/explicit-paths.rs:76:16 | LL | reuse ::foo1; | ^^ unsatisfied trait bound | help: the trait `Trait` is not implemented for `S2` - --> $DIR/explicit-paths.rs:78:5 + --> $DIR/explicit-paths.rs:73:5 | LL | struct S2; | ^^^^^^^^^ @@ -139,7 +109,7 @@ LL | impl Trait for S { | ^^^^^^^^^^^^^^^^ `S` error[E0308]: mismatched types - --> $DIR/explicit-paths.rs:81:30 + --> $DIR/explicit-paths.rs:76:30 | LL | reuse ::foo1; | ^^^^ @@ -155,7 +125,7 @@ note: method defined here LL | fn foo1(&self, x: i32) -> i32 { x } | ^^^^ ----- -error: aborting due to 15 previous errors +error: aborting due to 10 previous errors Some errors have detailed explanations: E0119, E0277, E0308, E0407, E0425. For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.rs b/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.rs index 066ca64b21b99..9276a0d220ad0 100644 --- a/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.rs +++ b/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.rs @@ -21,7 +21,6 @@ impl Iterator { reuse< < fn()>::Output>::Item as Iterator>::*; //~^ ERROR: expected method or associated constant, found associated type `Iterator::Item` //~| ERROR: ambiguous associated type - //~| ERROR: failed to resolve delegation callee } fn main() {} diff --git a/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.stderr b/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.stderr index 7e4f8de34b21b..4b4c1bc006632 100644 --- a/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.stderr +++ b/tests/ui/delegation/generics/def-path-hash-collision-ice-153410.stderr @@ -1,9 +1,3 @@ -error: failed to resolve delegation callee - --> $DIR/def-path-hash-collision-ice-153410.rs:21:58 - | -LL | reuse< < fn()>::Output>::Item as Iterator>::*; - | ^ - error[E0575]: expected method or associated constant, found associated type `Iterator::Item` --> $DIR/def-path-hash-collision-ice-153410.rs:21:10 | @@ -40,7 +34,7 @@ LL - reuse< < fn()>::Output>::Item as Iterator>::*; LL + reuse< < ::Output>::Item as Iterator>::*; | -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0223, E0575, E0782. For more information about an error, try `rustc --explain E0223`. diff --git a/tests/ui/delegation/generics/synth-params-ice-143498.rs b/tests/ui/delegation/generics/synth-params-ice-143498.rs index e5b7fb63592c9..ca6d2d5c193b0 100644 --- a/tests/ui/delegation/generics/synth-params-ice-143498.rs +++ b/tests/ui/delegation/generics/synth-params-ice-143498.rs @@ -21,7 +21,6 @@ impl X { reuse< std::fmt::Debug as Iterator >::*; //~^ ERROR: expected method or associated constant, found associated type `Iterator::Item` //~| ERROR: expected a type, found a trait - //~| ERROR: failed to resolve delegation callee } pub fn main() {} diff --git a/tests/ui/delegation/generics/synth-params-ice-143498.stderr b/tests/ui/delegation/generics/synth-params-ice-143498.stderr index 60ea56f7abe7f..17154f9779475 100644 --- a/tests/ui/delegation/generics/synth-params-ice-143498.stderr +++ b/tests/ui/delegation/generics/synth-params-ice-143498.stderr @@ -1,9 +1,3 @@ -error: failed to resolve delegation callee - --> $DIR/synth-params-ice-143498.rs:21:43 - | -LL | reuse< std::fmt::Debug as Iterator >::*; - | ^ - error[E0425]: cannot find type `X` in this scope --> $DIR/synth-params-ice-143498.rs:19:6 | @@ -27,7 +21,7 @@ help: you can add the `dyn` keyword if you want a trait object LL | reuse< dyn std::fmt::Debug as Iterator >::*; | +++ -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0425, E0575, E0782. For more information about an error, try `rustc --explain E0425`. diff --git a/tests/ui/delegation/glob-glob-conflict.rs b/tests/ui/delegation/glob-glob-conflict.rs index df7192b3f947a..beea96d167c39 100644 --- a/tests/ui/delegation/glob-glob-conflict.rs +++ b/tests/ui/delegation/glob-glob-conflict.rs @@ -26,14 +26,12 @@ impl Trait for u8 { reuse Trait2::*; //~ ERROR duplicate definitions with name `method` //~^ ERROR: this function takes 1 argument but 0 arguments were supplied //~| ERROR: mismatched types - //~| ERROR: failed to resolve delegation callee } impl Trait for u16 { reuse Trait1::*; reuse Trait1::*; //~ ERROR duplicate definitions with name `method` //~^ ERROR: this function takes 1 argument but 0 arguments were supplied //~| ERROR: mismatched types - //~| ERROR: failed to resolve delegation callee } fn main() {} diff --git a/tests/ui/delegation/glob-glob-conflict.stderr b/tests/ui/delegation/glob-glob-conflict.stderr index 5797e3c7c63cc..4ada3eb0efa69 100644 --- a/tests/ui/delegation/glob-glob-conflict.stderr +++ b/tests/ui/delegation/glob-glob-conflict.stderr @@ -9,14 +9,8 @@ LL | reuse Trait1::*; LL | reuse Trait2::*; | ^^^^^^^^^^^^^^^^ duplicate definition -error: failed to resolve delegation callee - --> $DIR/glob-glob-conflict.rs:26:19 - | -LL | reuse Trait2::*; - | ^ - error[E0201]: duplicate definitions with name `method`: - --> $DIR/glob-glob-conflict.rs:33:5 + --> $DIR/glob-glob-conflict.rs:32:5 | LL | fn method(&self) -> u8; | ----------------------- item in trait @@ -26,12 +20,6 @@ LL | reuse Trait1::*; LL | reuse Trait1::*; | ^^^^^^^^^^^^^^^^ duplicate definition -error: failed to resolve delegation callee - --> $DIR/glob-glob-conflict.rs:33:19 - | -LL | reuse Trait1::*; - | ^ - error[E0061]: this function takes 1 argument but 0 arguments were supplied --> $DIR/glob-glob-conflict.rs:26:19 | @@ -58,7 +46,7 @@ LL | reuse Trait2::*; | expected `()` because of default return type error[E0061]: this function takes 1 argument but 0 arguments were supplied - --> $DIR/glob-glob-conflict.rs:33:19 + --> $DIR/glob-glob-conflict.rs:32:19 | LL | reuse Trait1::*; | ^ argument #1 of type `&_` is missing @@ -74,7 +62,7 @@ LL | reuse Trait1::*(/* value */); | +++++++++++++ error[E0308]: mismatched types - --> $DIR/glob-glob-conflict.rs:33:19 + --> $DIR/glob-glob-conflict.rs:32:19 | LL | reuse Trait1::*; | ^- help: consider using a semicolon here: `;` @@ -82,7 +70,7 @@ LL | reuse Trait1::*; | expected `()`, found `u8` | expected `()` because of default return type -error: aborting due to 8 previous errors +error: aborting due to 6 previous errors Some errors have detailed explanations: E0061, E0201, E0308. For more information about an error, try `rustc --explain E0061`. diff --git a/tests/ui/delegation/glob-non-fn.rs b/tests/ui/delegation/glob-non-fn.rs index 62ceeb2377d5d..14a78e7b65e25 100644 --- a/tests/ui/delegation/glob-non-fn.rs +++ b/tests/ui/delegation/glob-non-fn.rs @@ -32,9 +32,6 @@ impl Trait for Bad { //~ ERROR not all trait items implemented, missing: `CONST` //~| ERROR duplicate definitions with name `method` //~| ERROR expected function, found associated constant `Trait::CONST` //~| ERROR expected function, found associated type `Trait::Type` - //~| ERROR: failed to resolve delegation callee - //~| ERROR: failed to resolve delegation callee - //~| ERROR: failed to resolve delegation callee } fn main() {} diff --git a/tests/ui/delegation/glob-non-fn.stderr b/tests/ui/delegation/glob-non-fn.stderr index 5592a31fa17f0..3353290fc5b10 100644 --- a/tests/ui/delegation/glob-non-fn.stderr +++ b/tests/ui/delegation/glob-non-fn.stderr @@ -7,12 +7,6 @@ LL | const CONST: u8; LL | reuse Trait::* { &self.0 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait -error: failed to resolve delegation callee - --> $DIR/glob-non-fn.rs:29:18 - | -LL | reuse Trait::* { &self.0 } - | ^ - error[E0324]: item `Type` is an associated method, which doesn't match its trait `Trait` --> $DIR/glob-non-fn.rs:29:5 | @@ -22,14 +16,6 @@ LL | type Type; LL | reuse Trait::* { &self.0 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait -error: failed to resolve delegation callee - --> $DIR/glob-non-fn.rs:29:18 - | -LL | reuse Trait::* { &self.0 } - | ^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - error[E0201]: duplicate definitions with name `method`: --> $DIR/glob-non-fn.rs:29:5 | @@ -42,14 +28,6 @@ LL | reuse Trait::* { &self.0 } | duplicate definition | previous definition here -error: failed to resolve delegation callee - --> $DIR/glob-non-fn.rs:29:18 - | -LL | reuse Trait::* { &self.0 } - | ^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - error[E0423]: expected function, found associated constant `Trait::CONST` --> $DIR/glob-non-fn.rs:29:11 | @@ -76,7 +54,7 @@ LL | type method; LL | impl Trait for Bad { | ^^^^^^^^^^^^^^^^^^ missing `CONST`, `Type`, `method` in implementation -error: aborting due to 9 previous errors +error: aborting due to 6 previous errors Some errors have detailed explanations: E0046, E0201, E0324, E0423. For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/delegation/ice-issue-124342.rs b/tests/ui/delegation/ice-issue-124342.rs index 227d8db07db3b..b5e7d9386d33d 100644 --- a/tests/ui/delegation/ice-issue-124342.rs +++ b/tests/ui/delegation/ice-issue-124342.rs @@ -6,7 +6,6 @@ trait Trait { reuse to_reuse::foo { foo } //~^ ERROR cannot find function `foo` in module `to_reuse` //~| ERROR cannot find value `foo` in this scope - //~| ERROR: failed to resolve delegation callee } fn main() {} diff --git a/tests/ui/delegation/ice-issue-124342.stderr b/tests/ui/delegation/ice-issue-124342.stderr index ab22bffbfbf52..19d75e494cafe 100644 --- a/tests/ui/delegation/ice-issue-124342.stderr +++ b/tests/ui/delegation/ice-issue-124342.stderr @@ -1,9 +1,3 @@ -error: failed to resolve delegation callee - --> $DIR/ice-issue-124342.rs:6:21 - | -LL | reuse to_reuse::foo { foo } - | ^^^ - error[E0425]: cannot find function `foo` in module `to_reuse` --> $DIR/ice-issue-124342.rs:6:21 | @@ -21,6 +15,6 @@ help: you might have meant to refer to the associated function LL | reuse to_reuse::foo { Self::foo } | ++++++ -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/delegation/ice-issue-124347.rs b/tests/ui/delegation/ice-issue-124347.rs index 56e3a21baf162..18eeca24bbea3 100644 --- a/tests/ui/delegation/ice-issue-124347.rs +++ b/tests/ui/delegation/ice-issue-124347.rs @@ -2,12 +2,10 @@ trait Trait { reuse Trait::foo { &self.0 } - //~^ ERROR failed to resolve delegation callee - //~| ERROR: this function takes 0 arguments but 1 argument was supplied + //~^ ERROR: this function takes 0 arguments but 1 argument was supplied } reuse foo; -//~^ ERROR failed to resolve delegation callee -//~| WARN: function cannot return without recursing +//~^ WARN: function cannot return without recursing fn main() {} diff --git a/tests/ui/delegation/ice-issue-124347.stderr b/tests/ui/delegation/ice-issue-124347.stderr index 9c0125d3a0852..1beaf63552c83 100644 --- a/tests/ui/delegation/ice-issue-124347.stderr +++ b/tests/ui/delegation/ice-issue-124347.stderr @@ -1,15 +1,3 @@ -error: failed to resolve delegation callee - --> $DIR/ice-issue-124347.rs:4:18 - | -LL | reuse Trait::foo { &self.0 } - | ^^^ - -error: failed to resolve delegation callee - --> $DIR/ice-issue-124347.rs:9:7 - | -LL | reuse foo; - | ^^^ - error[E0061]: this function takes 0 arguments but 1 argument was supplied --> $DIR/ice-issue-124347.rs:4:18 | @@ -28,7 +16,7 @@ LL + reuse Trait::fo&self.0 } | warning: function cannot return without recursing - --> $DIR/ice-issue-124347.rs:9:7 + --> $DIR/ice-issue-124347.rs:8:7 | LL | reuse foo; | ^^^ @@ -39,6 +27,6 @@ LL | reuse foo; = help: a `loop` may express intention better if this is on purpose = note: `#[warn(unconditional_recursion)]` on by default -error: aborting due to 3 previous errors; 1 warning emitted +error: aborting due to 1 previous error; 1 warning emitted For more information about this error, try `rustc --explain E0061`. diff --git a/tests/ui/delegation/ice-line-bounds-issue-148732.rs b/tests/ui/delegation/ice-line-bounds-issue-148732.rs index 696fd42f5eb3b..0123f0c8705b0 100644 --- a/tests/ui/delegation/ice-line-bounds-issue-148732.rs +++ b/tests/ui/delegation/ice-line-bounds-issue-148732.rs @@ -1,7 +1,6 @@ reuse a as b { //~^ ERROR cannot find function `a` in this scope //~| ERROR functions delegation is not yet fully implemented - //~| ERROR: failed to resolve delegation callee dbg!(b); //~^ ERROR: `fn() {b}` doesn't implement `Debug` } diff --git a/tests/ui/delegation/ice-line-bounds-issue-148732.stderr b/tests/ui/delegation/ice-line-bounds-issue-148732.stderr index d4d488edfd889..eb93655beb60d 100644 --- a/tests/ui/delegation/ice-line-bounds-issue-148732.stderr +++ b/tests/ui/delegation/ice-line-bounds-issue-148732.stderr @@ -1,9 +1,3 @@ -error: failed to resolve delegation callee - --> $DIR/ice-line-bounds-issue-148732.rs:1:7 - | -LL | reuse a as b { - | ^ - error[E0425]: cannot find function `a` in this scope --> $DIR/ice-line-bounds-issue-148732.rs:1:7 | @@ -14,7 +8,10 @@ error[E0658]: functions delegation is not yet fully implemented --> $DIR/ice-line-bounds-issue-148732.rs:1:1 | LL | / reuse a as b { -... | +LL | | +LL | | +LL | | dbg!(b); +LL | | LL | | } | |_^ | @@ -23,7 +20,7 @@ LL | | } = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0277]: `fn() {b}` doesn't implement `Debug` - --> $DIR/ice-line-bounds-issue-148732.rs:5:5 + --> $DIR/ice-line-bounds-issue-148732.rs:4:5 | LL | reuse a as b { | - consider calling this function @@ -33,7 +30,7 @@ LL | dbg!(b); | = help: use parentheses to call this function: `b()` -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0277, E0425, E0658. For more information about an error, try `rustc --explain E0277`. diff --git a/tests/ui/delegation/impl-reuse-non-reuse-items.rs b/tests/ui/delegation/impl-reuse-non-reuse-items.rs index be8294a1280c4..0dbe8016c1e8e 100644 --- a/tests/ui/delegation/impl-reuse-non-reuse-items.rs +++ b/tests/ui/delegation/impl-reuse-non-reuse-items.rs @@ -26,9 +26,6 @@ mod non_delegatable_items { //~| ERROR expected function, found associated constant `Trait::CONST` //~| ERROR expected function, found associated type `Trait::Type` //~| ERROR not all trait items implemented, missing: `CONST`, `Type`, `method` - //~| ERROR: failed to resolve delegation callee - //~| ERROR: failed to resolve delegation callee - //~| ERROR: failed to resolve delegation callee } fn main() {} diff --git a/tests/ui/delegation/impl-reuse-non-reuse-items.stderr b/tests/ui/delegation/impl-reuse-non-reuse-items.stderr index 5b2c95e69e3b1..044c9aa5a7ab9 100644 --- a/tests/ui/delegation/impl-reuse-non-reuse-items.stderr +++ b/tests/ui/delegation/impl-reuse-non-reuse-items.stderr @@ -7,12 +7,6 @@ LL | const CONST: u8; LL | reuse impl Trait for S { &self.0 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait -error: failed to resolve delegation callee - --> $DIR/impl-reuse-non-reuse-items.rs:22:5 - | -LL | reuse impl Trait for S { &self.0 } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - error[E0324]: item `Type` is an associated method, which doesn't match its trait `Trait` --> $DIR/impl-reuse-non-reuse-items.rs:22:5 | @@ -22,14 +16,6 @@ LL | type Type; LL | reuse impl Trait for S { &self.0 } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait -error: failed to resolve delegation callee - --> $DIR/impl-reuse-non-reuse-items.rs:22:5 - | -LL | reuse impl Trait for S { &self.0 } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - error[E0201]: duplicate definitions with name `method`: --> $DIR/impl-reuse-non-reuse-items.rs:22:5 | @@ -42,14 +28,6 @@ LL | reuse impl Trait for S { &self.0 } | duplicate definition | previous definition here -error: failed to resolve delegation callee - --> $DIR/impl-reuse-non-reuse-items.rs:22:5 - | -LL | reuse impl Trait for S { &self.0 } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - error[E0423]: expected function, found associated constant `Trait::CONST` --> $DIR/impl-reuse-non-reuse-items.rs:22:16 | @@ -76,7 +54,7 @@ LL | type method; LL | reuse impl Trait for S { &self.0 } | ^^^^^^^^^^^^^^^^^^^^^^ missing `CONST`, `Type`, `method` in implementation -error: aborting due to 9 previous errors +error: aborting due to 6 previous errors Some errors have detailed explanations: E0046, E0201, E0324, E0423. For more information about an error, try `rustc --explain E0046`. diff --git a/tests/ui/delegation/recursive-delegation-errors.rs b/tests/ui/delegation/recursive-delegation-errors.rs index 353a4e76d94ed..de5ebbbe3cd67 100644 --- a/tests/ui/delegation/recursive-delegation-errors.rs +++ b/tests/ui/delegation/recursive-delegation-errors.rs @@ -2,8 +2,7 @@ mod first_mod { reuse foo; - //~^ ERROR failed to resolve delegation callee - //~| WARN: function cannot return without recursing + //~^ WARN: function cannot return without recursing } mod second_mod { diff --git a/tests/ui/delegation/recursive-delegation-errors.stderr b/tests/ui/delegation/recursive-delegation-errors.stderr index aaa7d8b2d6b49..a73aa35e78afb 100644 --- a/tests/ui/delegation/recursive-delegation-errors.stderr +++ b/tests/ui/delegation/recursive-delegation-errors.stderr @@ -1,101 +1,95 @@ -error: failed to resolve delegation callee - --> $DIR/recursive-delegation-errors.rs:4:11 - | -LL | reuse foo; - | ^^^ - error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:10:11 + --> $DIR/recursive-delegation-errors.rs:9:11 | LL | reuse foo as bar; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:12:11 + --> $DIR/recursive-delegation-errors.rs:11:11 | LL | reuse bar as foo; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:17:11 + --> $DIR/recursive-delegation-errors.rs:16:11 | LL | reuse foo as foo1; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:19:11 + --> $DIR/recursive-delegation-errors.rs:18:11 | LL | reuse foo1 as foo2; | ^^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:21:11 + --> $DIR/recursive-delegation-errors.rs:20:11 | LL | reuse foo2 as foo3; | ^^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:23:11 + --> $DIR/recursive-delegation-errors.rs:22:11 | LL | reuse foo3 as foo4; | ^^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:25:11 + --> $DIR/recursive-delegation-errors.rs:24:11 | LL | reuse foo4 as foo5; | ^^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:27:11 + --> $DIR/recursive-delegation-errors.rs:26:11 | LL | reuse foo5 as foo; | ^^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:33:22 + --> $DIR/recursive-delegation-errors.rs:32:22 | LL | reuse Trait::foo as bar; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:36:22 + --> $DIR/recursive-delegation-errors.rs:35:22 | LL | reuse Trait::bar as foo; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:43:30 + --> $DIR/recursive-delegation-errors.rs:42:30 | LL | reuse super::fifth_mod::{bar as foo, foo as bar}; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:43:42 + --> $DIR/recursive-delegation-errors.rs:42:42 | LL | reuse super::fifth_mod::{bar as foo, foo as bar}; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:48:27 + --> $DIR/recursive-delegation-errors.rs:47:27 | LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:48:39 + --> $DIR/recursive-delegation-errors.rs:47:39 | LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:48:51 + --> $DIR/recursive-delegation-errors.rs:47:51 | LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; | ^^^ error[E0283]: type annotations needed - --> $DIR/recursive-delegation-errors.rs:33:22 + --> $DIR/recursive-delegation-errors.rs:32:22 | LL | reuse Trait::foo as bar; | ^^^ cannot infer type @@ -103,7 +97,7 @@ LL | reuse Trait::foo as bar; = note: the type must implement `fourth_mod::Trait` error[E0283]: type annotations needed - --> $DIR/recursive-delegation-errors.rs:36:22 + --> $DIR/recursive-delegation-errors.rs:35:22 | LL | reuse Trait::bar as foo; | ^^^ cannot infer type @@ -111,7 +105,7 @@ LL | reuse Trait::bar as foo; = note: the type must implement `fourth_mod::Trait` error[E0283]: type annotations needed - --> $DIR/recursive-delegation-errors.rs:48:27 + --> $DIR/recursive-delegation-errors.rs:47:27 | LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; | ^^^ cannot infer type @@ -119,7 +113,7 @@ LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; = note: the type must implement `GlobReuse` error[E0283]: type annotations needed - --> $DIR/recursive-delegation-errors.rs:48:39 + --> $DIR/recursive-delegation-errors.rs:47:39 | LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; | ^^^ cannot infer type @@ -127,7 +121,7 @@ LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; = note: the type must implement `GlobReuse` error[E0283]: type annotations needed - --> $DIR/recursive-delegation-errors.rs:48:51 + --> $DIR/recursive-delegation-errors.rs:47:51 | LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; | ^^^ cannot infer type @@ -146,6 +140,6 @@ LL | reuse foo; = help: a `loop` may express intention better if this is on purpose = note: `#[warn(unconditional_recursion)]` on by default -error: aborting due to 21 previous errors; 1 warning emitted +error: aborting due to 20 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/delegation/recursive-delegation-ice-150152.rs b/tests/ui/delegation/recursive-delegation-ice-150152.rs index b2feafb5ef6ef..c4aaa7fd2d1f2 100644 --- a/tests/ui/delegation/recursive-delegation-ice-150152.rs +++ b/tests/ui/delegation/recursive-delegation-ice-150152.rs @@ -9,7 +9,6 @@ mod first_example { //~^ ERROR cannot find trait `Item` in this scope //~| ERROR missing generics for struct `S` reuse to_reuse::foo; - //~^ ERROR: failed to resolve delegation callee } } diff --git a/tests/ui/delegation/recursive-delegation-ice-150152.stderr b/tests/ui/delegation/recursive-delegation-ice-150152.stderr index 019e59cdeff12..b59b588f4968a 100644 --- a/tests/ui/delegation/recursive-delegation-ice-150152.stderr +++ b/tests/ui/delegation/recursive-delegation-ice-150152.stderr @@ -1,9 +1,3 @@ -error: failed to resolve delegation callee - --> $DIR/recursive-delegation-ice-150152.rs:11:25 - | -LL | reuse to_reuse::foo; - | ^^^ - error[E0405]: cannot find trait `Item` in this scope --> $DIR/recursive-delegation-ice-150152.rs:8:10 | @@ -11,7 +5,7 @@ LL | impl Item for S { | ^^^^ not found in this scope error[E0425]: cannot find type `S` in this scope - --> $DIR/recursive-delegation-ice-150152.rs:24:20 + --> $DIR/recursive-delegation-ice-150152.rs:23:20 | LL | impl Trait for S { | ^ not found in this scope @@ -23,7 +17,7 @@ LL | struct S< S >; | ^^^^^^^^^^^^^^ not accessible error[E0425]: cannot find function `foo` in this scope - --> $DIR/recursive-delegation-ice-150152.rs:26:15 + --> $DIR/recursive-delegation-ice-150152.rs:25:15 | LL | reuse foo; | ^^^ not found in this scope @@ -38,13 +32,13 @@ LL | fn foo() {} | ^^^^^^^^ `second_example::to_reuse::foo`: not accessible error[E0603]: function `foo` is private - --> $DIR/recursive-delegation-ice-150152.rs:18:25 + --> $DIR/recursive-delegation-ice-150152.rs:17:25 | LL | reuse to_reuse::foo; | ^^^ private function | note: the function `foo` is defined here - --> $DIR/recursive-delegation-ice-150152.rs:22:9 + --> $DIR/recursive-delegation-ice-150152.rs:21:9 | LL | fn foo() {} | ^^^^^^^^ @@ -74,7 +68,7 @@ help: add missing generic argument LL | impl Item for S> { | +++ -error: aborting due to 7 previous errors +error: aborting due to 6 previous errors Some errors have detailed explanations: E0107, E0392, E0405, E0425, E0603. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/delegation/unlowered-path-ice-154820.rs b/tests/ui/delegation/unlowered-path-ice-154820.rs index b9246313a3f0a..892790f2bd538 100644 --- a/tests/ui/delegation/unlowered-path-ice-154820.rs +++ b/tests/ui/delegation/unlowered-path-ice-154820.rs @@ -1,6 +1,6 @@ #![feature(fn_delegation)] -reuse foo:: < { //~ ERROR: failed to resolve delegation callee +reuse foo:: < { //~^ ERROR: function takes 0 generic arguments but 1 generic argument was supplied fn foo() {} reuse foo; diff --git a/tests/ui/delegation/unlowered-path-ice-154820.stderr b/tests/ui/delegation/unlowered-path-ice-154820.stderr index b690237e3ac9e..0a220cfdc5ae2 100644 --- a/tests/ui/delegation/unlowered-path-ice-154820.stderr +++ b/tests/ui/delegation/unlowered-path-ice-154820.stderr @@ -8,12 +8,6 @@ LL | reuse foo; | = note: `foo` must be defined only once in the value namespace of this block -error: failed to resolve delegation callee - --> $DIR/unlowered-path-ice-154820.rs:3:7 - | -LL | reuse foo:: < { - | ^^^ - error[E0107]: function takes 0 generic arguments but 1 generic argument was supplied --> $DIR/unlowered-path-ice-154820.rs:3:7 | @@ -34,7 +28,7 @@ note: function defined here, with 0 generic parameters LL | reuse foo:: < { | ^^^ -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors Some errors have detailed explanations: E0107, E0428. For more information about an error, try `rustc --explain E0107`. diff --git a/tests/ui/delegation/unused-import-ice-144594.rs b/tests/ui/delegation/unused-import-ice-144594.rs index c9859c048bb02..fca67c6ee0b81 100644 --- a/tests/ui/delegation/unused-import-ice-144594.rs +++ b/tests/ui/delegation/unused-import-ice-144594.rs @@ -2,7 +2,6 @@ reuse a as b { //~^ ERROR cannot find function `a` in this scope [E0425] - //~| ERROR: failed to resolve delegation callee || { use std::ops::Add; x.add diff --git a/tests/ui/delegation/unused-import-ice-144594.stderr b/tests/ui/delegation/unused-import-ice-144594.stderr index d6e48e36edf1b..f09313aac21f4 100644 --- a/tests/ui/delegation/unused-import-ice-144594.stderr +++ b/tests/ui/delegation/unused-import-ice-144594.stderr @@ -1,9 +1,3 @@ -error: failed to resolve delegation callee - --> $DIR/unused-import-ice-144594.rs:3:7 - | -LL | reuse a as b { - | ^ - error[E0425]: cannot find function `a` in this scope --> $DIR/unused-import-ice-144594.rs:3:7 | @@ -11,11 +5,11 @@ LL | reuse a as b { | ^ not found in this scope error[E0425]: cannot find value `x` in this scope - --> $DIR/unused-import-ice-144594.rs:8:9 + --> $DIR/unused-import-ice-144594.rs:7:9 | LL | x.add | ^ not found in this scope -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/delegation/wrong-lifetime-rib.rs b/tests/ui/delegation/wrong-lifetime-rib.rs index e0d894a981945..01645f20bf7b1 100644 --- a/tests/ui/delegation/wrong-lifetime-rib.rs +++ b/tests/ui/delegation/wrong-lifetime-rib.rs @@ -10,7 +10,6 @@ mod ice_156342 { //~^ ERROR: cannot define inherent `impl` for a type outside of the crate where the type is defined reuse None::<&()>; //~^ ERROR: expected function, found unit variant `None` - //~| ERROR: failed to resolve delegation callee } fn foo() {} diff --git a/tests/ui/delegation/wrong-lifetime-rib.stderr b/tests/ui/delegation/wrong-lifetime-rib.stderr index 7e4473151c63f..0c4499eec192d 100644 --- a/tests/ui/delegation/wrong-lifetime-rib.stderr +++ b/tests/ui/delegation/wrong-lifetime-rib.stderr @@ -1,9 +1,3 @@ -error: failed to resolve delegation callee - --> $DIR/wrong-lifetime-rib.rs:11:15 - | -LL | reuse None::<&()>; - | ^^^^ - error[E0423]: expected function, found unit variant `None` --> $DIR/wrong-lifetime-rib.rs:11:15 | @@ -11,7 +5,7 @@ LL | reuse None::<&()>; | ^^^^^^^^^^^ not a function error[E0782]: expected a type, found a trait - --> $DIR/wrong-lifetime-rib.rs:27:10 + --> $DIR/wrong-lifetime-rib.rs:26:10 | LL | impl X { | ^ @@ -26,7 +20,7 @@ LL | impl X for /* Type */ { | ++++++++++++++ error[E0782]: expected a type, found a trait - --> $DIR/wrong-lifetime-rib.rs:36:10 + --> $DIR/wrong-lifetime-rib.rs:35:10 | LL | impl X { | ^ @@ -50,7 +44,7 @@ LL | impl Trait { = note: for more details about the orphan rules, see error[E0223]: ambiguous associated type - --> $DIR/wrong-lifetime-rib.rs:28:16 + --> $DIR/wrong-lifetime-rib.rs:27:16 | LL | reuse<<<&Project> :: Ty> :: Ty as Iterator>::next; | ^^^^^^^^^^^^^^^^ @@ -62,7 +56,7 @@ LL + reuse<<<&() as Example>::Ty> :: Ty as Iterator>::next; | error[E0782]: expected a type, found a trait - --> $DIR/wrong-lifetime-rib.rs:38:21 + --> $DIR/wrong-lifetime-rib.rs:37:21 | LL | let _: &X; | ^ @@ -72,7 +66,7 @@ help: you can add the `dyn` keyword if you want a trait object LL | let _: &dyn X; | +++ -error: aborting due to 7 previous errors +error: aborting due to 6 previous errors Some errors have detailed explanations: E0116, E0223, E0423, E0782. For more information about an error, try `rustc --explain E0116`. From 4d353834c57c65de1f09b32062f1a5d7eb57f2af Mon Sep 17 00:00:00 2001 From: aerooneqq Date: Wed, 3 Jun 2026 16:02:49 +0300 Subject: [PATCH 5/6] Place `UnresolvedDelegationCallee` in correct place --- compiler/rustc_ast_lowering/src/delegation.rs | 7 ++- compiler/rustc_ast_lowering/src/errors.rs | 7 +++ compiler/rustc_resolve/src/late.rs | 14 ++---- tests/ui/delegation/ice-issue-124347.rs | 2 + tests/ui/delegation/ice-issue-124347.stderr | 16 ++++++- .../delegation/recursive-delegation-errors.rs | 1 + .../recursive-delegation-errors.stderr | 48 +++++++++++-------- .../delegation/unlowered-path-ice-154820.rs | 2 +- .../unlowered-path-ice-154820.stderr | 8 +++- 9 files changed, 68 insertions(+), 37 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/delegation.rs b/compiler/rustc_ast_lowering/src/delegation.rs index 9610d766f8f27..753ced83b8559 100644 --- a/compiler/rustc_ast_lowering/src/delegation.rs +++ b/compiler/rustc_ast_lowering/src/delegation.rs @@ -54,7 +54,7 @@ use rustc_span::symbol::kw; use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol}; use crate::delegation::generics::{GenericsGenerationResult, GenericsGenerationResults}; -use crate::errors::CycleInDelegationSignatureResolution; +use crate::errors::{CycleInDelegationSignatureResolution, UnresolvedDelegationCallee}; use crate::{ AllowReturnTypeNotation, ImplTraitContext, ImplTraitPosition, LoweringContext, ParamMode, ResolverAstLoweringExt, index_crate, @@ -147,7 +147,10 @@ fn check_for_cycles(tcx: TyCtxt<'_>, mut def_id: DefId, span: Span) -> Result<() { def_id = id; if visited.contains(&def_id) { - return Err(tcx.dcx().emit_err(CycleInDelegationSignatureResolution { span })); + return Err(match visited.len() { + 1 => tcx.dcx().emit_err(UnresolvedDelegationCallee { span }), + _ => tcx.dcx().emit_err(CycleInDelegationSignatureResolution { span }), + }); } } else { return Ok(()); diff --git a/compiler/rustc_ast_lowering/src/errors.rs b/compiler/rustc_ast_lowering/src/errors.rs index cd4505fde1fe7..19c7a566a9609 100644 --- a/compiler/rustc_ast_lowering/src/errors.rs +++ b/compiler/rustc_ast_lowering/src/errors.rs @@ -528,3 +528,10 @@ pub(crate) struct CycleInDelegationSignatureResolution { #[primary_span] pub span: Span, } + +#[derive(Diagnostic)] +#[diag("failed to resolve delegation callee")] +pub(crate) struct UnresolvedDelegationCallee { + #[primary_span] + pub span: Span, +} diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 08ae233f8c7f6..233dc7a5913e2 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -3906,20 +3906,14 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { .get(&resolution_node_id) .and_then(|r| r.expect_full_res().opt_def_id()); - let resolution_id = if let Some(resolution_id) = def_id - // If there is a single unresolved `reuse foo` in a mod it resolves to itself, - // in this case emit `UnresolvedDelegationCallee` error instead of cycle error. - && resolution_id != self.r.current_owner.def_id.to_def_id() - { - Ok(resolution_id) - } else { - Err(self.r.tcx.dcx().span_delayed_bug( + let resolution_id = def_id.ok_or_else(|| { + self.r.tcx.dcx().span_delayed_bug( delegation.path.span, format!( "LateResolutionVisitor: couldn't resolve node {resolution_node_id:?} in delegation item", ), - )) - }; + ) + }); let info = DelegationInfo { resolution_id }; self.r.delegation_infos.insert(self.r.current_owner.def_id, info); diff --git a/tests/ui/delegation/ice-issue-124347.rs b/tests/ui/delegation/ice-issue-124347.rs index 18eeca24bbea3..2253425b7a2c9 100644 --- a/tests/ui/delegation/ice-issue-124347.rs +++ b/tests/ui/delegation/ice-issue-124347.rs @@ -3,9 +3,11 @@ trait Trait { reuse Trait::foo { &self.0 } //~^ ERROR: this function takes 0 arguments but 1 argument was supplied + //~| ERROR: failed to resolve delegation callee } reuse foo; //~^ WARN: function cannot return without recursing +//~| ERROR: failed to resolve delegation callee fn main() {} diff --git a/tests/ui/delegation/ice-issue-124347.stderr b/tests/ui/delegation/ice-issue-124347.stderr index 1beaf63552c83..9c0125d3a0852 100644 --- a/tests/ui/delegation/ice-issue-124347.stderr +++ b/tests/ui/delegation/ice-issue-124347.stderr @@ -1,3 +1,15 @@ +error: failed to resolve delegation callee + --> $DIR/ice-issue-124347.rs:4:18 + | +LL | reuse Trait::foo { &self.0 } + | ^^^ + +error: failed to resolve delegation callee + --> $DIR/ice-issue-124347.rs:9:7 + | +LL | reuse foo; + | ^^^ + error[E0061]: this function takes 0 arguments but 1 argument was supplied --> $DIR/ice-issue-124347.rs:4:18 | @@ -16,7 +28,7 @@ LL + reuse Trait::fo&self.0 } | warning: function cannot return without recursing - --> $DIR/ice-issue-124347.rs:8:7 + --> $DIR/ice-issue-124347.rs:9:7 | LL | reuse foo; | ^^^ @@ -27,6 +39,6 @@ LL | reuse foo; = help: a `loop` may express intention better if this is on purpose = note: `#[warn(unconditional_recursion)]` on by default -error: aborting due to 1 previous error; 1 warning emitted +error: aborting due to 3 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0061`. diff --git a/tests/ui/delegation/recursive-delegation-errors.rs b/tests/ui/delegation/recursive-delegation-errors.rs index de5ebbbe3cd67..5c5ff799af28c 100644 --- a/tests/ui/delegation/recursive-delegation-errors.rs +++ b/tests/ui/delegation/recursive-delegation-errors.rs @@ -3,6 +3,7 @@ mod first_mod { reuse foo; //~^ WARN: function cannot return without recursing + //~| ERROR: failed to resolve delegation callee } mod second_mod { diff --git a/tests/ui/delegation/recursive-delegation-errors.stderr b/tests/ui/delegation/recursive-delegation-errors.stderr index a73aa35e78afb..aaa7d8b2d6b49 100644 --- a/tests/ui/delegation/recursive-delegation-errors.stderr +++ b/tests/ui/delegation/recursive-delegation-errors.stderr @@ -1,95 +1,101 @@ +error: failed to resolve delegation callee + --> $DIR/recursive-delegation-errors.rs:4:11 + | +LL | reuse foo; + | ^^^ + error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:9:11 + --> $DIR/recursive-delegation-errors.rs:10:11 | LL | reuse foo as bar; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:11:11 + --> $DIR/recursive-delegation-errors.rs:12:11 | LL | reuse bar as foo; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:16:11 + --> $DIR/recursive-delegation-errors.rs:17:11 | LL | reuse foo as foo1; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:18:11 + --> $DIR/recursive-delegation-errors.rs:19:11 | LL | reuse foo1 as foo2; | ^^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:20:11 + --> $DIR/recursive-delegation-errors.rs:21:11 | LL | reuse foo2 as foo3; | ^^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:22:11 + --> $DIR/recursive-delegation-errors.rs:23:11 | LL | reuse foo3 as foo4; | ^^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:24:11 + --> $DIR/recursive-delegation-errors.rs:25:11 | LL | reuse foo4 as foo5; | ^^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:26:11 + --> $DIR/recursive-delegation-errors.rs:27:11 | LL | reuse foo5 as foo; | ^^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:32:22 + --> $DIR/recursive-delegation-errors.rs:33:22 | LL | reuse Trait::foo as bar; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:35:22 + --> $DIR/recursive-delegation-errors.rs:36:22 | LL | reuse Trait::bar as foo; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:42:30 + --> $DIR/recursive-delegation-errors.rs:43:30 | LL | reuse super::fifth_mod::{bar as foo, foo as bar}; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:42:42 + --> $DIR/recursive-delegation-errors.rs:43:42 | LL | reuse super::fifth_mod::{bar as foo, foo as bar}; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:47:27 + --> $DIR/recursive-delegation-errors.rs:48:27 | LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:47:39 + --> $DIR/recursive-delegation-errors.rs:48:39 | LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; | ^^^ error: encountered a cycle during delegation signature resolution - --> $DIR/recursive-delegation-errors.rs:47:51 + --> $DIR/recursive-delegation-errors.rs:48:51 | LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; | ^^^ error[E0283]: type annotations needed - --> $DIR/recursive-delegation-errors.rs:32:22 + --> $DIR/recursive-delegation-errors.rs:33:22 | LL | reuse Trait::foo as bar; | ^^^ cannot infer type @@ -97,7 +103,7 @@ LL | reuse Trait::foo as bar; = note: the type must implement `fourth_mod::Trait` error[E0283]: type annotations needed - --> $DIR/recursive-delegation-errors.rs:35:22 + --> $DIR/recursive-delegation-errors.rs:36:22 | LL | reuse Trait::bar as foo; | ^^^ cannot infer type @@ -105,7 +111,7 @@ LL | reuse Trait::bar as foo; = note: the type must implement `fourth_mod::Trait` error[E0283]: type annotations needed - --> $DIR/recursive-delegation-errors.rs:47:27 + --> $DIR/recursive-delegation-errors.rs:48:27 | LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; | ^^^ cannot infer type @@ -113,7 +119,7 @@ LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; = note: the type must implement `GlobReuse` error[E0283]: type annotations needed - --> $DIR/recursive-delegation-errors.rs:47:39 + --> $DIR/recursive-delegation-errors.rs:48:39 | LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; | ^^^ cannot infer type @@ -121,7 +127,7 @@ LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; = note: the type must implement `GlobReuse` error[E0283]: type annotations needed - --> $DIR/recursive-delegation-errors.rs:47:51 + --> $DIR/recursive-delegation-errors.rs:48:51 | LL | reuse GlobReuse::{foo as bar, bar as goo, goo as foo}; | ^^^ cannot infer type @@ -140,6 +146,6 @@ LL | reuse foo; = help: a `loop` may express intention better if this is on purpose = note: `#[warn(unconditional_recursion)]` on by default -error: aborting due to 20 previous errors; 1 warning emitted +error: aborting due to 21 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0283`. diff --git a/tests/ui/delegation/unlowered-path-ice-154820.rs b/tests/ui/delegation/unlowered-path-ice-154820.rs index 892790f2bd538..b9246313a3f0a 100644 --- a/tests/ui/delegation/unlowered-path-ice-154820.rs +++ b/tests/ui/delegation/unlowered-path-ice-154820.rs @@ -1,6 +1,6 @@ #![feature(fn_delegation)] -reuse foo:: < { +reuse foo:: < { //~ ERROR: failed to resolve delegation callee //~^ ERROR: function takes 0 generic arguments but 1 generic argument was supplied fn foo() {} reuse foo; diff --git a/tests/ui/delegation/unlowered-path-ice-154820.stderr b/tests/ui/delegation/unlowered-path-ice-154820.stderr index 0a220cfdc5ae2..b690237e3ac9e 100644 --- a/tests/ui/delegation/unlowered-path-ice-154820.stderr +++ b/tests/ui/delegation/unlowered-path-ice-154820.stderr @@ -8,6 +8,12 @@ LL | reuse foo; | = note: `foo` must be defined only once in the value namespace of this block +error: failed to resolve delegation callee + --> $DIR/unlowered-path-ice-154820.rs:3:7 + | +LL | reuse foo:: < { + | ^^^ + error[E0107]: function takes 0 generic arguments but 1 generic argument was supplied --> $DIR/unlowered-path-ice-154820.rs:3:7 | @@ -28,7 +34,7 @@ note: function defined here, with 0 generic parameters LL | reuse foo:: < { | ^^^ -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0107, E0428. For more information about an error, try `rustc --explain E0107`. From 9eb8e44dc67d24154766ce074c137207ca3f04ac Mon Sep 17 00:00:00 2001 From: aerooneqq Date: Wed, 3 Jun 2026 16:06:26 +0300 Subject: [PATCH 6/6] Remove unneeded changes --- tests/ui/delegation/ice-issue-124347.rs | 8 ++++---- tests/ui/delegation/recursive-delegation-errors.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/ui/delegation/ice-issue-124347.rs b/tests/ui/delegation/ice-issue-124347.rs index 2253425b7a2c9..56e3a21baf162 100644 --- a/tests/ui/delegation/ice-issue-124347.rs +++ b/tests/ui/delegation/ice-issue-124347.rs @@ -2,12 +2,12 @@ trait Trait { reuse Trait::foo { &self.0 } - //~^ ERROR: this function takes 0 arguments but 1 argument was supplied - //~| ERROR: failed to resolve delegation callee + //~^ ERROR failed to resolve delegation callee + //~| ERROR: this function takes 0 arguments but 1 argument was supplied } reuse foo; -//~^ WARN: function cannot return without recursing -//~| ERROR: failed to resolve delegation callee +//~^ ERROR failed to resolve delegation callee +//~| WARN: function cannot return without recursing fn main() {} diff --git a/tests/ui/delegation/recursive-delegation-errors.rs b/tests/ui/delegation/recursive-delegation-errors.rs index 5c5ff799af28c..353a4e76d94ed 100644 --- a/tests/ui/delegation/recursive-delegation-errors.rs +++ b/tests/ui/delegation/recursive-delegation-errors.rs @@ -2,8 +2,8 @@ mod first_mod { reuse foo; - //~^ WARN: function cannot return without recursing - //~| ERROR: failed to resolve delegation callee + //~^ ERROR failed to resolve delegation callee + //~| WARN: function cannot return without recursing } mod second_mod {