From 98f40672a617f2ba9bf22cc9252a8f743da809e7 Mon Sep 17 00:00:00 2001 From: rabindra789 Date: Thu, 6 Aug 2026 21:09:28 +0530 Subject: [PATCH 01/11] mir: validate Move call arguments are locals or box derefs --- compiler/rustc_mir_transform/src/validate.rs | 20 ++++++++++++++ tests/ui/mir/validate/call-move-arg.rs | 28 ++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/ui/mir/validate/call-move-arg.rs diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs index b9c55439f0597..6602a69549ed2 100644 --- a/compiler/rustc_mir_transform/src/validate.rs +++ b/compiler/rustc_mir_transform/src/validate.rs @@ -431,6 +431,26 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> { ), ); } + + // Call arguments are moved by reference, so they must be plain locals + // or the contents of a box; other moved places violate MIR invariants. + if self.tcx.sess.opts.unstable_opts.validate_mir + && self.body.phase < MirPhase::Runtime(RuntimePhase::Initial) + { + let is_plain_local = place.projection.is_empty(); + let is_box_deref = + matches!(place.projection.as_ref(), [ProjectionElem::Deref]) + && self.body.local_decls[place.local].ty.is_box(); + if !is_plain_local && !is_box_deref { + self.fail( + location, + format!( + "encountered `Move` of a non-local, non-box place in `Call` terminator: {:?}", + terminator.kind, + ), + ); + } + } } } diff --git a/tests/ui/mir/validate/call-move-arg.rs b/tests/ui/mir/validate/call-move-arg.rs new file mode 100644 index 0000000000000..a6e01f264a986 --- /dev/null +++ b/tests/ui/mir/validate/call-move-arg.rs @@ -0,0 +1,28 @@ +// Check that validation rejects moving a non-local, non-box place as a +// `Call` argument. +// +//@ failure-status: 101 +//@ dont-check-compiler-stderr +//@ compile-flags: -Zvalidate-mir + +#![feature(custom_mir, core_intrinsics)] +extern crate core; +use core::intrinsics::mir::*; + +fn bar(_x: i32) {} + +#[custom_mir(dialect = "built")] +pub fn main() { + mir! { + let a: (i32, i32); + { + a = (1, 2); + Call(RET = bar(Move(a.0)), ReturnTo(retblock), UnwindContinue()) + //~^ ERROR broken MIR in + //~| ERROR encountered `Move` of a non-local, non-box place in `Call` terminator + } + retblock = { + Return() + } + } +} From 84963f87e68007ad1adbd331661f6e0d28b55395 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Fri, 28 Aug 2026 13:04:20 +0200 Subject: [PATCH 02/11] run `extern "tail"` with `byval` argument test --- .../tailcc-no-signature-restriction.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/ui/explicit-tail-calls/tailcc-no-signature-restriction.rs b/tests/ui/explicit-tail-calls/tailcc-no-signature-restriction.rs index 9c9085ca1daca..64cea66c1d565 100644 --- a/tests/ui/explicit-tail-calls/tailcc-no-signature-restriction.rs +++ b/tests/ui/explicit-tail-calls/tailcc-no-signature-restriction.rs @@ -1,9 +1,9 @@ //@ run-pass //@ ignore-backends: gcc -//@ min-llvm-version: 22 -//@ revisions: x86_64 aarch64 +//@ min-llvm-version: 23 +//@ revisions: x86 x86_64 aarch64 // -// FIXME: enable x86 on LLVM 23. +//@ [x86] only-x86 //@ [x86_64] only-x86_64 //@ [aarch64] only-aarch64 #![feature(explicit_tail_calls, rust_tail_cc)] @@ -18,6 +18,7 @@ pub extern "tail" fn add() -> u64 { become add(1, 2); } +#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), not(windows)))] #[inline(never)] pub extern "tail" fn pass_struct(a: u64, d: u64) -> u64 { #[derive(Clone, Copy)] @@ -42,8 +43,7 @@ pub extern "tail" fn pass_struct(a: u64, d: u64) -> u64 { fn main() { assert_eq!(add(), 3); - // FIXME: LLVM 22 has a bug which makes this miscompile. - if false { - assert_eq!(pass_struct(5, 6), 5 + 6); - } + // Windows and Aarch64 in LLVM 23 does not support byval arguments. + #[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), not(windows)))] + assert_eq!(pass_struct(5, 6), 5 + 6); } From 38e3714a7a7bedb70a5a2a2a20ba3a0c2c4710ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Miku=C5=82a?= Date: Mon, 7 Sep 2026 17:13:35 +0200 Subject: [PATCH 03/11] windows-gnu: document libgcc requirement --- src/doc/rustc/src/platform-support/windows-gnu.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/doc/rustc/src/platform-support/windows-gnu.md b/src/doc/rustc/src/platform-support/windows-gnu.md index d7aec5af21dec..595c2a42c81a4 100644 --- a/src/doc/rustc/src/platform-support/windows-gnu.md +++ b/src/doc/rustc/src/platform-support/windows-gnu.md @@ -34,6 +34,7 @@ The targets are built and tested using a reasonably modern C toolchain, and it s * GCC 14.2 * mingw-w64 12.0.0 * MSVCRT library as the default +* Libgcc with DWARF-2 exception handling for i686 and SEH for x86_64 Using older tools (especially Binutils) may not work properly, due to the number of issues plaguing older versions of Binutils. The supported toolchain versions are subject to change. From 9dee1dc06af405502f88fd2d162024802d9b85b1 Mon Sep 17 00:00:00 2001 From: rustbot <47979223+rustbot@users.noreply.github.com> Date: Mon, 7 Sep 2026 19:00:47 +0200 Subject: [PATCH 04/11] Update books --- src/doc/book | 2 +- src/doc/edition-guide | 2 +- src/doc/reference | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/doc/book b/src/doc/book index 917544888a55e..1500248d8f230 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 917544888a55e4da7109bdba8c88c893c0da70f4 +Subproject commit 1500248d8f230566e4ec9f27fcbb8fe9e2898ab1 diff --git a/src/doc/edition-guide b/src/doc/edition-guide index f5abcf137698e..ab8544aeed7b7 160000 --- a/src/doc/edition-guide +++ b/src/doc/edition-guide @@ -1 +1 @@ -Subproject commit f5abcf137698e5ad6ebed359d69654ff705346af +Subproject commit ab8544aeed7b792984366aa122ac19bd47ad9a2f diff --git a/src/doc/reference b/src/doc/reference index 3b38834b39f73..e24eecf97b0c9 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit 3b38834b39f732c64686f7c64aa29dcf3cd83ba5 +Subproject commit e24eecf97b0c9a6dbac67191098204dc8a190aaa From fa2850ebe725abe8aa786e514a5b0ffcae57ba07 Mon Sep 17 00:00:00 2001 From: Ada Alakbarova Date: Mon, 24 Aug 2026 11:43:21 +0200 Subject: [PATCH 05/11] misc typo fixes --- .../src/solve/sharing-crates-with-rust-analyzer.md | 10 +++++----- src/doc/rustc-dev-guide/src/solve/the-solver.md | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/doc/rustc-dev-guide/src/solve/sharing-crates-with-rust-analyzer.md b/src/doc/rustc-dev-guide/src/solve/sharing-crates-with-rust-analyzer.md index 110fd1331bc44..bf9655c866ee0 100644 --- a/src/doc/rustc-dev-guide/src/solve/sharing-crates-with-rust-analyzer.md +++ b/src/doc/rustc-dev-guide/src/solve/sharing-crates-with-rust-analyzer.md @@ -115,7 +115,7 @@ For rust-analyzer, the corresponding implementations are located across several These two traits correspond to the role of [`InferCtxt`][rustc inferctxt] in rustc. [`InferCtxtLike`][ir inferctxtlike] must be defined in `rustc_infer` due to coherence -constraints(orphan rules). +constraints (orphan rules). As a result, it cannot provide functionality that lives in `rustc_trait_selection`. Instead, behavior that depends on trait-solving logic is abstracted into a separate trait, [`SolverDelegate`][ir solverdelegate]. @@ -214,9 +214,9 @@ non-obvious considerations: 1. The generic parameters `I` and `J` are reserved for `I: Interner` and `J` being the interner it is being lifted to. -2. `PhantomData` is handled automatically, creating a new `PhantomData` but - _has_ to be included in the file through; `use std::marker::PhantomData;` - you cannot use `std::marker::PhantomData` directly on the field of a struct. +2. `PhantomData` is handled automatically, creating a new `PhantomData`. But it + _has_ to be used in the fully unqualified form -- you cannot use + `std::marker::PhantomData` directly in the field. 3. The bounds are deliberately written as associated type bounds on the `Interner` trait rather than as `where` clauses on `LiftInto`. Given only `I: LiftInto`, Rust can then treat bounds such as the following as implied: @@ -310,4 +310,4 @@ There are still duplicated implementations between rustc and rust-analyzer—suc [r-a coerce]: https://github.com/rust-lang/rust-analyzer/blob/34f47d9298c478c12c6c4c0348771d1b05706e09/crates/hir-ty/src/infer/coerce.rs [rustc_lift]: https://github.com/rust-lang/rust/blob/0913b18e489ac1011b580e31fa5559654be12bfc/compiler/rustc_type_ir/src/lift.rs#L18 [rustc_typevisitable]: https://github.com/rust-lang/rust/blob/0913b18e489ac1011b580e31fa5559654be12bfc/compiler/rustc_type_ir/src/visit.rs#L62 -[rustc_typefoldable]: https://github.com/rust-lang/rust/blob/0913b18e489ac1011b580e31fa5559654be12bfc/compiler/rustc_type_ir/src/fold.rs#L71 \ No newline at end of file +[rustc_typefoldable]: https://github.com/rust-lang/rust/blob/0913b18e489ac1011b580e31fa5559654be12bfc/compiler/rustc_type_ir/src/fold.rs#L71 diff --git a/src/doc/rustc-dev-guide/src/solve/the-solver.md b/src/doc/rustc-dev-guide/src/solve/the-solver.md index 0151c0482d109..3d66ec272698d 100644 --- a/src/doc/rustc-dev-guide/src/solve/the-solver.md +++ b/src/doc/rustc-dev-guide/src/solve/the-solver.md @@ -7,7 +7,7 @@ as it is very similar to this implementation and also talks about limitations of ## A rough walkthrough -The entry-point of the solver is `InferCtxtEvalExt::evaluate_root_goal`. +The entry-point of the solver is `SolverDelegateEvalExt::evaluate_root_goal`. This function sets up the root `EvalCtxt` and then calls `EvalCtxt::evaluate_goal`, to actually enter the trait solver. From 2827a304fe7ce27405a6edae347c61e967409972 Mon Sep 17 00:00:00 2001 From: Ada Alakbarova Date: Mon, 24 Aug 2026 11:55:40 +0200 Subject: [PATCH 06/11] remove outdated docs I ended up deciding not to add docs about `bounds` as it seems like a relatively minor feature of the derive, and there are docs at [1]. [1]: https://github.com/rust-lang/rust/blob/3ffb26fbf5bf232cf59e314e75ea325973f4f583/compiler/rustc_type_ir_macros/src/lib.rs#L21-L55 --- .../src/solve/sharing-crates-with-rust-analyzer.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/doc/rustc-dev-guide/src/solve/sharing-crates-with-rust-analyzer.md b/src/doc/rustc-dev-guide/src/solve/sharing-crates-with-rust-analyzer.md index bf9655c866ee0..2b06f5b414c1b 100644 --- a/src/doc/rustc-dev-guide/src/solve/sharing-crates-with-rust-analyzer.md +++ b/src/doc/rustc-dev-guide/src/solve/sharing-crates-with-rust-analyzer.md @@ -255,12 +255,6 @@ There is intentionally no ignore attribute. The traversal must visit every field. This is a soundness requirement for rust-analyzer's use of the traversal when tracing and garbage-collecting interned types. -When the macro crate's `nightly` feature is enabled, the derive macro remains -registered but emits no tokens. The `GenericTypeVisitable` trait and its -traversal module are also excluded from the nightly configuration of -`rustc_type_ir`; they exist only in its non-nightly configuration. - - ## Long-term plans for supporting rust-analyzer In general, we aim to support rust-analyzer just as well as rustc in these shared crates—provided From 0db592d2919c1ca9cc3c1773005989df0e90ae75 Mon Sep 17 00:00:00 2001 From: Ada Alakbarova Date: Mon, 24 Aug 2026 12:51:58 +0200 Subject: [PATCH 07/11] realize that `bounds` works a bit differently than advertised Just specifying `T: GenericTypeVisitable` doesn't work, as the trait has a generic: `V`, the visitor. `T: GenericTypeVisitable<__V>` is what actually works, as `__V` is the generic added to the impl generated by the derive macro. We discussed[1] different ways of making this nicer, but settled on not doing anything, as we don't expect people to need to specify any actual bounds. [1]: https://rust-lang.zulipchat.com/#narrow/channel/185405-t-compiler.2Frust-analyzer/topic/Updating.20next-solver/near/618331780 and below --- compiler/rustc_type_ir_macros/src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_type_ir_macros/src/lib.rs b/compiler/rustc_type_ir_macros/src/lib.rs index e1d2b53366066..8a437c4995724 100644 --- a/compiler/rustc_type_ir_macros/src/lib.rs +++ b/compiler/rustc_type_ir_macros/src/lib.rs @@ -48,11 +48,15 @@ decl_derive!( /// struct Foo { /// #[generic_type_visitable(bounds())] /// just_self: Box, - /// #[generic_type_visitable(bounds(Bar: GenericTypeVisitable))] + /// #[generic_type_visitable(bounds(Bar: GenericTypeVisitable<__V>))] /// contains_self: (Box, Bar), /// } /// struct Bar; /// ``` + /// + /// Note: the `__V` lifetime is an implementation detail of the derive macro. + /// We could probably handle this in a nicer way, but we don't expect this form + /// to really be necessary any time soon, so for now we don't. customizable_type_visitable_derive ); @@ -461,7 +465,7 @@ mod kw { /// Parses a bound like: /// /// ```ignore (would need to import GenericTypeVisitable to get this to compile) -/// #[generic_type_visitable(bounds(Foo: GenericTypeVisitable, Bar: GenericTypeVisitable))] +/// #[generic_type_visitable(bounds(Foo: GenericTypeVisitable<__V>, Bar: GenericTypeVisitable<__V>))] /// ``` fn parse_generic_type_visitable_bound( attr: &Attribute, From ada4f67f8aefa8707a65f87c4f9501e109b22333 Mon Sep 17 00:00:00 2001 From: Ada Alakbarova Date: Mon, 7 Sep 2026 21:31:33 +0200 Subject: [PATCH 08/11] add tests for `#[derive(GenericTypeVisitable)]` and `bounds` --- ...ve-generic-type-visitable-missing-bound.rs | 19 +++ ...eneric-type-visitable-missing-bound.stderr | 18 +++ .../derive-generic-type-visitable.rs | 119 ++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 tests/ui-fulldeps/derive-generic-type-visitable-missing-bound.rs create mode 100644 tests/ui-fulldeps/derive-generic-type-visitable-missing-bound.stderr create mode 100644 tests/ui-fulldeps/derive-generic-type-visitable.rs diff --git a/tests/ui-fulldeps/derive-generic-type-visitable-missing-bound.rs b/tests/ui-fulldeps/derive-generic-type-visitable-missing-bound.rs new file mode 100644 index 0000000000000..af44ff7e92252 --- /dev/null +++ b/tests/ui-fulldeps/derive-generic-type-visitable-missing-bound.rs @@ -0,0 +1,19 @@ +//@ edition: 2024 +//@ check-fail + +#![crate_type = "rlib"] +#![feature(rustc_private)] + +extern crate rustc_type_ir; +extern crate rustc_type_ir_macros; + +use rustc_type_ir_macros::GenericTypeVisitable; + +#[derive(GenericTypeVisitable)] +struct MissingBound { + // This should fail, as `T: GenericTypeVisitable<__V>` wasn't specified + #[generic_type_visitable(bounds())] + //~^ ERROR: the trait bound `T: GenericTypeVisitable<__V>` is not satisfied + partially_rec: (Vec, T), + other: u32, +} diff --git a/tests/ui-fulldeps/derive-generic-type-visitable-missing-bound.stderr b/tests/ui-fulldeps/derive-generic-type-visitable-missing-bound.stderr new file mode 100644 index 0000000000000..44433984e4a7f --- /dev/null +++ b/tests/ui-fulldeps/derive-generic-type-visitable-missing-bound.stderr @@ -0,0 +1,18 @@ +error[E0277]: the trait bound `T: GenericTypeVisitable<__V>` is not satisfied + --> $DIR/derive-generic-type-visitable-missing-bound.rs:15:5 + | +LL | #[derive(GenericTypeVisitable)] + | -------------------- + | | + | required by a bound introduced by this call + | in this derive macro expansion +... +LL | #[generic_type_visitable(bounds())] + | ^ the nightly-only, unstable trait `GenericTypeVisitable<__V>` is not implemented for `T` + | + = note: required for `(Vec>, T)` to implement `GenericTypeVisitable<__V>` + = note: this error originates in the derive macro `GenericTypeVisitable` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui-fulldeps/derive-generic-type-visitable.rs b/tests/ui-fulldeps/derive-generic-type-visitable.rs new file mode 100644 index 0000000000000..91c7a502a87d8 --- /dev/null +++ b/tests/ui-fulldeps/derive-generic-type-visitable.rs @@ -0,0 +1,119 @@ +//@ edition: 2024 +//@ run-pass + +#![feature(rustc_private)] + +extern crate rustc_type_ir; +extern crate rustc_type_ir_macros; + +use rustc_type_ir::GenericTypeVisitable; +use rustc_type_ir_macros::GenericTypeVisitable; + +// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta +// files. +#[expect(unused_extern_crates)] +extern crate rustc_driver; + +#[derive(GenericTypeVisitable)] +struct DerivesGenericTypeVisitable; + +#[derive(GenericTypeVisitable)] +struct Foo { + one: Incrementer, + two: Vec, +} + +#[derive(GenericTypeVisitable)] +enum Enum { + A, + B(Incrementer), + C { one: Incrementer, two: Vec }, +} + +#[derive(GenericTypeVisitable)] +struct Generic(Vec); + +#[derive(GenericTypeVisitable)] +struct Recursive { + #[generic_type_visitable(bounds())] + rec: Vec, + other: Incrementer, +} + +#[derive(GenericTypeVisitable)] +struct PartiallyRecursiveField { + #[generic_type_visitable(bounds(T: GenericTypeVisitable<__V>))] + partially_rec: (Vec, T), + other: Incrementer, +} + +// start testing setup + +use std::sync::atomic::{AtomicU8, Ordering}; + +static COUNT: AtomicU8 = AtomicU8::new(0); + +/// A type that, when visited, increments a global counter. +/// +/// Used to (weakly) test the correctness of the derive by making sure that +/// it traverses all the fields, and thus reaches all the incrementers. +#[derive(Clone)] +struct Incrementer; + +unsafe impl GenericTypeVisitable for Incrementer { + fn generic_visit_with(&self, _visitor: &mut V) { + COUNT.fetch_add(1, Ordering::Relaxed); + } +} + +// end testing setup + +fn main() { + use Incrementer as Inc; // for brevity + + #[track_caller] + fn check>(item: T, count: u8) { + let mut v = (); + item.generic_visit_with(&mut v); + assert_eq!(COUNT.swap(0, Ordering::Relaxed), count); + } + + check(DerivesGenericTypeVisitable, 0); + check(Foo { one: Inc, two: vec![] }, 1); + check(Foo { one: Inc, two: vec![Inc; 2] }, 1 + 2); + check(Enum::A, 0); + check(Enum::B(Inc), 1); + check(Enum::C { one: Inc, two: vec![] }, 1); + check(Enum::C { one: Inc, two: vec![Inc; 3] }, 1 + 3); + check(Generic::(vec![]), 0); + // visits each of the nested `Inc`s + check(Generic(vec![Inc; 5]), 5); + + // Every (nested) `rec!` adds another `Recursive`, and thus 1 more visited `Inc`. + macro_rules! rec { + [$($i:expr),* $(,)?] => { + Recursive { rec: vec![$($i),*], other: Inc } + } + } + check(rec![], 1); + check(rec![rec![]], 2); + check(rec![rec![], rec![]], 3); + check(rec![rec![rec![]]], 3); + + // Every (nested) `prec!` adds another `PartiallyRecursiveField`, and thus 1 more visited `Inc`. + macro_rules! prec { + ([$($i:expr),* $(,)?], $o:expr) => { + PartiallyRecursiveField { partially_rec: (vec![$($i),*], $o), other: Inc } + } + } + // Every nested `a()`, `b()`, and `c()` adds 0, 1, and 2 more visited `Inc`s, respectively. + let a = || Enum::A; + let b = || Enum::B(Inc); + let c = || Enum::C { one: Inc, two: vec![Inc] }; + check(prec!([], a()), 1 + 0); + check(prec!([], b()), 1 + 1); + check(prec!([], c()), 1 + 2); + check(prec!([prec!([], a())], a()), 1 + (1 + 0) + 0); + check(prec!([prec!([], b())], a()), 1 + (1 + 1) + 0); + check(prec!([prec!([], b())], b()), 1 + (1 + 1) + 1); +} From 2c4265a2764f262aa94a7034fee5885e1472d69d Mon Sep 17 00:00:00 2001 From: aerooneqq Date: Tue, 8 Sep 2026 09:27:16 +0300 Subject: [PATCH 09/11] Supporting delegations to inherent functions --- compiler/rustc_ast/src/ast.rs | 8 + .../src/delegation/generics.rs | 93 +++- .../rustc_ast_lowering/src/delegation/mod.rs | 37 +- .../src/delegation/resolution.rs | 274 +++++++++-- .../rustc_ast_lowering/src/diagnostics.rs | 21 + compiler/rustc_ast_lowering/src/lib.rs | 4 + compiler/rustc_hir_analysis/src/delegation.rs | 212 ++++++-- compiler/rustc_hir_typeck/src/method/probe.rs | 25 +- compiler/rustc_middle/src/middle/resolve.rs | 44 +- compiler/rustc_middle/src/queries.rs | 6 + compiler/rustc_middle/src/ty/context.rs | 4 + compiler/rustc_resolve/src/late.rs | 94 +++- compiler/rustc_resolve/src/lib.rs | 7 +- tests/ui/delegation/bad-resolve.rs | 8 +- tests/ui/delegation/bad-resolve.stderr | 75 ++- tests/ui/delegation/explicit-paths.rs | 5 +- tests/ui/delegation/explicit-paths.stderr | 69 +-- tests/ui/delegation/glob-non-fn.rs | 4 +- tests/ui/delegation/glob-non-fn.stderr | 51 +- .../delegation/impl-reuse-non-reuse-items.rs | 6 +- .../impl-reuse-non-reuse-items.stderr | 50 +- tests/ui/delegation/inherent-impls-ambig.rs | 22 +- .../ui/delegation/inherent-impls-ambig.stderr | 170 ++++--- tests/ui/delegation/inherent-impls-enums.rs | 30 +- .../ui/delegation/inherent-impls-enums.stderr | 185 ++----- .../ui/delegation/inherent-impls-glob-list.rs | 2 - .../inherent-impls-glob-list.stderr | 17 +- .../inherent-impls-mixed-generics.rs | 3 +- .../inherent-impls-mixed-generics.stderr | 24 +- .../inherent-impls-non-local-crate.rs | 14 +- .../inherent-impls-non-local-crate.stderr | 50 +- .../inherent-impls-parent-generics.rs | 61 +-- .../inherent-impls-parent-generics.stderr | 459 +++++++++++++++--- .../inherent-impls-receiver-mapping.rs | 21 +- .../inherent-impls-receiver-mapping.stderr | 280 +++-------- .../inherent-impls-recursive-cycle.rs | 20 +- .../inherent-impls-recursive-cycle.stderr | 118 +++-- .../ui/delegation/inherent-impls-recursive.rs | 9 +- .../inherent-impls-recursive.stderr | 61 --- tests/ui/delegation/inherent-impls-rename.rs | 3 +- .../delegation/inherent-impls-rename.stderr | 9 - .../delegation/inherent-impls-self-mapping.rs | 4 +- .../inherent-impls-self-mapping.stderr | 40 +- .../inherent-impls-self-replacement.rs | 23 +- .../inherent-impls-self-replacement.stderr | 201 ++++++-- tests/ui/delegation/inherent-impls-structs.rs | 30 +- .../delegation/inherent-impls-structs.stderr | 185 ++----- .../inherent-impls-wrong-header-args-ice.rs | 4 +- ...nherent-impls-wrong-header-args-ice.stderr | 26 +- ...ult-trait-shadow-cycle-issue-151358.stderr | 2 + .../query-cycle-printing-issue-151358.stderr | 2 + .../resolve/query-cycle-issue-124901.stderr | 2 + 52 files changed, 1968 insertions(+), 1206 deletions(-) delete mode 100644 tests/ui/delegation/inherent-impls-recursive.stderr delete mode 100644 tests/ui/delegation/inherent-impls-rename.stderr diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index bc8753f4dcaa7..c14ad62e9a60b 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -294,6 +294,14 @@ impl GenericArg { GenericArg::Const(ct) => ct.value.span, } } + + pub fn is_maybe_parenthesised_infer(&self) -> bool { + match self { + GenericArg::Lifetime(lt) => lt.ident.name == kw::UnderscoreLifetime, + GenericArg::Type(ty) => ty.is_maybe_parenthesised_infer(), + GenericArg::Const(_) => false, + } + } } /// A path like `Foo<'a, T>`. diff --git a/compiler/rustc_ast_lowering/src/delegation/generics.rs b/compiler/rustc_ast_lowering/src/delegation/generics.rs index 867ed364433e7..7cb904ab5c353 100644 --- a/compiler/rustc_ast_lowering/src/delegation/generics.rs +++ b/compiler/rustc_ast_lowering/src/delegation/generics.rs @@ -1,3 +1,5 @@ +use std::assert_matches; + use hir::HirId; use hir::def::{DefKind, Res}; use rustc_ast::*; @@ -11,7 +13,10 @@ use rustc_span::{ErrorGuaranteed, Ident, Span, sym}; use crate::LoweringContext; use crate::delegation::resolution::resolver::DelegationResolver; -use crate::diagnostics::DelegationInfersMismatch; +use crate::diagnostics::{ + DelegationInfersMismatch, DelegationToInherentImplMustContainParentGenerics, + DelegationToInherentImplParentContainsInfer, +}; #[derive(Debug, Clone, Copy, Eq, PartialEq)] pub(super) enum GenericsPosition { @@ -25,6 +30,7 @@ pub(super) enum GenericArgSlot { Generate(T, Option /* Infer arg index from AST */), } +#[derive(Debug)] pub(super) struct DelegationGenerics { data: T, pos: GenericsPosition, @@ -57,11 +63,13 @@ impl<'hir> DelegationGenerics> { /// meaning we did not propagate them and thus we do not need to generate generic params /// (i.e., method call scenarios), in such a case this approach helps /// a lot as if `into_hir_generics` will not be called then uplifting will not happen. +#[derive(Debug)] pub(super) enum HirOrTyGenerics<'hir> { Ty(DelegationGenerics>), Hir(DelegationGenerics<&'hir hir::Generics<'hir>>), } +#[derive(Debug)] pub(super) struct GenericsGenerationResult<'hir> { pub(super) generics: HirOrTyGenerics<'hir>, pub(super) args_segment_id: HirId, @@ -80,6 +88,7 @@ pub(super) struct GenericsGenerationResults<'hir> { pub(super) self_ty_propagation_kind: Option, } +#[derive(Debug)] pub(super) struct DelegationGenericArgsIterator<'hir> { index: usize = Default::default(), params: &'hir [hir::GenericParam<'hir>], @@ -145,6 +154,7 @@ impl<'hir> DelegationGenericArgsIterator<'hir> { ctx: &mut LoweringContext<'_, 'hir>, ) -> Vec> { let mut args = vec![]; + while let Some(arg) = self.next(ctx, |ctx| ctx.next_id()) { args.push(arg); } @@ -238,6 +248,7 @@ impl<'hir> GenericsGenerationResult<'hir> { } } +#[derive(Debug)] enum ParentSegmentArgs<'a> { /// Parent segment is valid and generic args are specified: /// `reuse Trait::<'static, ()>::foo;`. @@ -273,7 +284,7 @@ struct GenericsResolution<'a, 'tcx> { /// `reuse <_ as Trait>::foo;`. qself_is_infer: bool, /// Whether we should generate `Self` generic param. - generate_self: bool, + generate_free_to_trait_self: bool, } impl<'hir> DelegationResolver<'_, 'hir> { @@ -288,8 +299,7 @@ impl<'hir> DelegationResolver<'_, 'hir> { let delegation_in_free_ctx = !matches!(delegation_parent_kind, DefKind::Trait | DefKind::Impl { .. }); - let sig_parent = tcx.parent(sig_id); - let sig_in_trait = matches!(tcx.def_kind(sig_parent), DefKind::Trait); + let sig_in_trait = matches!(tcx.def_kind(tcx.parent(sig_id)), DefKind::Trait); let free_to_trait_delegation = delegation_in_free_ctx && sig_in_trait; let mut sig_parent_params: &[ty::GenericParamDef] = &[]; @@ -301,8 +311,13 @@ impl<'hir> DelegationResolver<'_, 'hir> { let parent_args = if let [.., parent_segment, _] = &delegation.path.segments[..] { let res = self.get_resolution_id(parent_segment.id)?; - if matches!(tcx.def_kind(res), DefKind::Trait | DefKind::TraitAlias) { - sig_parent_params = &tcx.generics_of(sig_parent).own_params; + if !matches!(tcx.def_kind(res), DefKind::Mod) { + assert_matches!( + tcx.def_kind(res), + DefKind::Trait | DefKind::Struct | DefKind::Enum + ); + + sig_parent_params = &tcx.generics_of(res).own_params; self.get_user_args(parent_segment) .map(|args| ParentSegmentArgs::Specified(args)) .unwrap_or(ParentSegmentArgs::NotSpecified) @@ -319,7 +334,8 @@ impl<'hir> DelegationResolver<'_, 'hir> { qself_is_none, qself_is_infer, free_to_trait_delegation, - generate_self: free_to_trait_delegation && (qself_is_none || qself_is_infer), + generate_free_to_trait_self: free_to_trait_delegation + && (qself_is_none || qself_is_infer), trait_impl: matches!(delegation_parent_kind, DefKind::Impl { of_trait: true }), sig_child_params: &tcx.generics_of(sig_id).own_params, child_args: self.get_user_args( @@ -349,10 +365,11 @@ impl<'hir> DelegationResolver<'_, 'hir> { &self, delegation: &Delegation, sig_id: DefId, + span: Span, ) -> Result, ErrorGuaranteed> { let res @ GenericsResolution { trait_impl, - generate_self, + generate_free_to_trait_self, sig_child_params, sig_parent_params, .. @@ -376,20 +393,27 @@ impl<'hir> DelegationResolver<'_, 'hir> { return Ok(GenericsGenerationResults { parent, child, self_ty_propagation_kind: None }); } + self.check_delegation_to_inherent_impl(&res.parent_args, sig_id, span)?; + let tcx = self.tcx(); + + // If parent is inherent impl then there is no `Self` param to skip, so add additional check. + let skip_self = + !generate_free_to_trait_self && tcx.def_kind(tcx.parent(sig_id)) == DefKind::Trait; + let parent_generics = match res.parent_args { ParentSegmentArgs::Specified(args) => DelegationGenerics { data: Self::create_slots_from_args( tcx, args, - &sig_parent_params[usize::from(!generate_self)..], - generate_self, + &sig_parent_params[usize::from(skip_self)..], + generate_free_to_trait_self, ), pos: GenericsPosition::Parent, trait_impl, }, ParentSegmentArgs::NotSpecified => DelegationGenerics::generate_all( - &sig_parent_params[usize::from(!generate_self)..], + &sig_parent_params[usize::from(skip_self)..], GenericsPosition::Parent, trait_impl, ), @@ -437,6 +461,46 @@ impl<'hir> DelegationResolver<'_, 'hir> { }) } + fn check_delegation_to_inherent_impl( + &self, + parent_args: &ParentSegmentArgs<'_>, + sig_id: DefId, + span: Span, + ) -> Result<(), ErrorGuaranteed> { + let tcx = self.tcx(); + + if !(tcx.def_kind(sig_id) == DefKind::AssocFn + && matches!(tcx.def_kind(tcx.parent(sig_id)), DefKind::Impl { of_trait: false })) + { + return Ok(()); + } + + let ty::Adt(def, _) = tcx.type_of(tcx.parent(sig_id)).skip_binder().kind() else { + unreachable!("parent of inherent function can be only struct or enum") + }; + + match parent_args { + ParentSegmentArgs::Invalid => unreachable!(), + ParentSegmentArgs::Specified(args) => args + .args + .iter() + .all(|arg| { + let AngleBracketedArg::Arg(arg) = arg else { return false }; + !arg.is_maybe_parenthesised_infer() + }) + .ok_or_else(|| { + self.tcx().dcx().emit_err(DelegationToInherentImplParentContainsInfer { span }) + }), + ParentSegmentArgs::NotSpecified => match tcx.generics_of(def.did()).own_params.len() { + 0 => Ok(()), + _ => Err(self + .tcx() + .dcx() + .emit_err(DelegationToInherentImplMustContainParentGenerics { span })), + }, + } + } + /// Generates generic argument slots for user-specified `args` and /// generic `params` of the signature function. This function checks whether /// there are infers (`kw::UnderscoreLifetime` or `kw::Underscore`) in @@ -459,12 +523,7 @@ impl<'hir> DelegationResolver<'_, 'hir> { let params = ¶ms[usize::from(add_first_self)..]; for (idx, (arg, param)) in args.args.iter().zip(params).enumerate() { let AngleBracketedArg::Arg(arg) = arg else { continue }; - - let is_infer = match arg { - GenericArg::Lifetime(lt) => lt.ident.name == kw::UnderscoreLifetime, - GenericArg::Type(ty) => ty.is_maybe_parenthesised_infer(), - GenericArg::Const(_) => false, - }; + let is_infer = arg.is_maybe_parenthesised_infer(); // If `'_` is used instead of `_` (or vice versa) we emit a meaningful // error instead of processing this infer or leaving it as is for signature diff --git a/compiler/rustc_ast_lowering/src/delegation/mod.rs b/compiler/rustc_ast_lowering/src/delegation/mod.rs index a92b62517e61d..0e94016963c78 100644 --- a/compiler/rustc_ast_lowering/src/delegation/mod.rs +++ b/compiler/rustc_ast_lowering/src/delegation/mod.rs @@ -47,7 +47,7 @@ use rustc_ast as ast; use rustc_ast::*; use rustc_hir::attrs::lang_items::LangItem; use rustc_hir::def::DefKind; -use rustc_hir::{self as hir, FnDeclFlags}; +use rustc_hir::{self as hir, FnDeclFlags, QPath}; use rustc_middle::ty::Asyncness; use rustc_span::def_id::DefId; use rustc_span::symbol::kw; @@ -62,7 +62,7 @@ use crate::{ mod attributes; mod generics; -mod resolution; +pub(crate) mod resolution; pub(crate) struct DelegationResults<'hir> { pub body_id: hir::BodyId, @@ -416,7 +416,37 @@ impl<'hir> LoweringContext<'_, 'hir> { hir::QPath::Resolved(ty, self.arena.alloc(new_path)) } - hir::QPath::TypeRelative(..) => unreachable!("until inherent methods are supported"), + hir::QPath::TypeRelative(mut ty, segment) => { + let mut segment = self.process_segment(span, segment, &mut generics.child); + segment.res = Res::Def(self.tcx.def_kind(res.call_path_res), res.call_path_res); + + let ty_hir_id = ty.hir_id; + + // Propagating child generics if needed. + ty = if let hir::TyKind::Path(QPath::Resolved(ty, path)) = ty.kind { + let mut new_path = path.clone(); + + new_path.segments = self.arena.alloc_from_iter( + new_path.segments.iter().enumerate().map(|(idx, segment)| { + if idx + 1 == new_path.segments.len() { + self.process_segment(span, segment, &mut generics.parent) + } else { + segment.clone() + } + }), + ); + + self.arena.alloc(hir::Ty { + hir_id: ty_hir_id, + span, + kind: hir::TyKind::Path(QPath::Resolved(ty, self.arena.alloc(new_path))), + }) + } else { + ty + }; + + hir::QPath::TypeRelative(ty, self.arena.alloc(segment)) + } }; if let Some(hir::DelegationSelfTyPropagationKind::SelfTy(id)) = @@ -491,6 +521,7 @@ impl<'hir> LoweringContext<'_, 'hir> { result.generics.into_hir_generics(self, span); let mut segment = segment.clone(); + let mut args_iter = result.generics.create_args_iterator(); let new_args = segment diff --git a/compiler/rustc_ast_lowering/src/delegation/resolution.rs b/compiler/rustc_ast_lowering/src/delegation/resolution.rs index 85604223c8509..0e4992267b250 100644 --- a/compiler/rustc_ast_lowering/src/delegation/resolution.rs +++ b/compiler/rustc_ast_lowering/src/delegation/resolution.rs @@ -2,22 +2,143 @@ use std::ops::ControlFlow; use ast::visit::Visitor; use hir::def::DefKind; -use rustc_ast::{self as ast, Delegation, DelegationSource, NodeId}; -use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; +use rustc_ast::{self as ast, AssocItemKind, Delegation, DelegationSource, Item, ItemKind, NodeId}; +use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; +use rustc_data_structures::steal::Steal; use rustc_hir as hir; -use rustc_middle::ty::{Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor}; -use rustc_middle::{span_bug, ty}; +use rustc_middle::middle::resolve::{ + self as mid_res, AstOwner, DelegationInherentFnKind, TypeRelativeDelegationRes, +}; +use rustc_middle::ty::{ + self as ty, AssocKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, +}; use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::{ErrorGuaranteed, Span}; use crate::delegation::generics::GenericsGenerationResults; use crate::delegation::resolution::resolver::DelegationResolver; use crate::diagnostics::{ - CycleInDelegationSignatureResolution, DelegationAttemptedBlockWithDefsDeletion, - DelegationAttemptedBlockWithDefsRelowering, DelegationBlockSpecifiedWhenNoParams, - UnresolvedDelegationCallee, + AmbiguousDelegationToInherentImpl, CycleInDelegationSignatureResolution, + DelegationAttemptedBlockWithDefsDeletion, DelegationAttemptedBlockWithDefsRelowering, + DelegationBlockSpecifiedWhenNoParams, UnresolvedDelegationCallee, }; +/// Simple (hack or heuristic) resolution of some delegations to inherent impls +/// while correct resolution through `ProbeContext` is not available +/// during AST -> HIR lowering due to query cycles. +/// Successful resolutions from this heuristics are not a subset of +/// successful resolutions from the correct approach, if we want to stabilize +/// delegations to inherent impls with this approach we need a second pass in type checking +/// (i.e., when there's no cycles) that makes sure that resolutions from +/// the heuristic match the correct resolutions, or report errors otherwise. +/// FIXME(fn_delegation): correct resolution through `ProbeContext` engine +pub(crate) fn resolve_type_relative_delegations( + tcx: TyCtxt<'_>, + _: (), +) -> FxIndexMap { + let ast_index = tcx.index_ast(()); + let resolutions = tcx.resolutions(()); + + let infos = &resolutions.delegation_infos; + let inh_fns = &resolutions.delegation_inherent_fn_map; + + let mut type_relative_resolutions: FxIndexMap = + Default::default(); + + for (&def_id, res) in infos { + match res.resolution { + mid_res::DelegationResolution::Error(..) | mid_res::DelegationResolution::Full(_) => { + continue; + } + // Also record resolutions for cases when signature is resolved but call path is not. + mid_res::DelegationResolution::Partial + | mid_res::DelegationResolution::PartialCall(_) => { + let Some(r_and_owner) = ast_index.get(def_id).map(Steal::borrow) else { + unreachable!("ast index must contain delegations"); + }; + + let (r, owner) = &*r_and_owner; + + let delegation = match owner { + AstOwner::Item(Item { kind: ItemKind::Delegation(d), .. }) + | AstOwner::TraitItem(Item { kind: AssocItemKind::Delegation(d), .. }) + | AstOwner::ImplItem(Item { kind: AssocItemKind::Delegation(d), .. }) => d, + _ => unreachable!("we are processing only delegations"), + }; + + let res = r.partial_res_map.get(&delegation.id); + let res = res.and_then(|res| res.base_res().opt_def_id()); + let ident = delegation.path.segments.last().map(|s| s.ident); + + let span = delegation.last_segment_span(); + + let ambig_error_res = || { + TypeRelativeDelegationRes::Ambig( + tcx.dcx().span_delayed_bug(span, "ambiguous delegation to inherent impl"), + ) + }; + + let default_error_res = + || { + TypeRelativeDelegationRes::Error(tcx.dcx().span_delayed_bug( + span, + "failed to resolve delegation to inherent impl", + )) + }; + + let res = if let Some(res) = res + && let Some(ident) = ident + { + match res.as_local() { + Some(local_def_id) => { + let res = inh_fns.get(&local_def_id).and_then(|map| map.get(&ident)); + + match res { + Some(res) => match res { + DelegationInherentFnKind::Ambig => ambig_error_res(), + DelegationInherentFnKind::Single(res) => { + TypeRelativeDelegationRes::Ok(res.to_def_id()) + } + }, + _ => default_error_res(), + } + } + None => { + let mut sig_res = None; + 'inh_loop: for inh_impl_id in tcx.inherent_impls(res) { + let assoc_items = tcx.associated_items(*inh_impl_id); + + // FIXME(fn_delegation): use correct identifier hygiene + let mut candidates = assoc_items + .filter_by_name_unhygienic(ident.name) + .filter(|it| matches!(it.kind, AssocKind::Fn { .. })); + + while let Some(candidate) = candidates.next() { + if sig_res.is_some() { + sig_res = Some(ambig_error_res()); + break 'inh_loop; + } else { + sig_res = + Some(TypeRelativeDelegationRes::Ok(candidate.def_id)); + } + } + } + + sig_res.unwrap_or_else(default_error_res) + } + } + } else { + default_error_res() + }; + + type_relative_resolutions.insert(def_id, res); + } + } + } + + type_relative_resolutions +} + /// Summary info about function parameters. #[derive(Debug, Clone, Copy, Eq, PartialEq)] pub(super) struct ParamInfo { @@ -114,26 +235,34 @@ impl<'tcx> DelegationResolver<'_, 'tcx> { // Delegation can be missing from the `delegations_resolutions` table // in illegal places such as function bodies in extern blocks (see #151356). - let sig_id = tcx - .resolutions(()) - .delegation_infos - .get(&def_id) - .map(|info| { - info.resolution_id.and_then(|id| self.check_for_cycles(id, span).map(|_| id)) - }) - .unwrap_or_else(|| { - Err(tcx.dcx().span_delayed_bug( - span, - format!("delegation resolution record was not found for {:?}", def_id), - )) - })?; - - let is_method = match tcx.def_kind(sig_id) { - DefKind::Fn => false, - DefKind::AssocFn => tcx.associated_item(sig_id).is_method(), - _ => span_bug!(span, "unexpected DefKind for delegation item"), - }; + let sig_id = self.resolve_delegation_sig(def_id, span)?; + + let create_invalid_path_error = + || tcx.dcx().span_delayed_bug(span, "invalid delegation path"); + match &delegation.path.segments[..] { + [] => return Err(create_invalid_path_error()), + [child] => { + let res = self.get_resolution_id(child.id)?; + if tcx.def_kind(res) != DefKind::Fn { + return Err(create_invalid_path_error()); + } + } + [.., parent, _] => { + let child_res = self.get_call_path_res(delegation, span)?; + let parent_res = self.get_resolution_id(parent.id)?; + + match (tcx.def_kind(child_res), tcx.def_kind(parent_res)) { + (DefKind::Fn, DefKind::Mod) => {} + (DefKind::AssocFn, DefKind::Trait | DefKind::Struct | DefKind::Enum) => {} + _ => return Err(create_invalid_path_error()), + } + } + } + + self.check_for_cycles(sig_id, span)?; + + let is_method = tcx.is_method(sig_id); let sig = tcx.fn_sig(sig_id).skip_binder().skip_binder(); let param_count = sig.inputs().len() + usize::from(sig.c_variadic()); let parent = tcx.local_parent(def_id); @@ -149,7 +278,7 @@ impl<'tcx> DelegationResolver<'_, 'tcx> { // FIXME(splat): use `sig.splatted()` once FnSig has it param_info: ParamInfo { param_count, c_variadic: sig.c_variadic(), splatted: None }, source: delegation.source, - call_path_res: self.get_resolution_id(delegation.id)?, + call_path_res: self.get_call_path_res(delegation, span)?, sig_mapping: self.create_sig_mapping( delegation, span, @@ -160,12 +289,73 @@ impl<'tcx> DelegationResolver<'_, 'tcx> { )?, }; - Ok((res, self.resolve_and_generate_generics(delegation, sig_id)?)) + Ok((res, self.resolve_and_generate_generics(delegation, sig_id, span)?)) + } + + fn get_call_path_res( + &self, + delegation: &Delegation, + span: Span, + ) -> Result { + let def_id = self.owner_id(); + + match self.tcx().resolutions(()).delegation_infos[&def_id].resolution { + mid_res::DelegationResolution::Full(_) => self.get_resolution_id(delegation.id), + mid_res::DelegationResolution::Partial + | mid_res::DelegationResolution::PartialCall(_) => { + self.resolve_type_relative_delegation_sig(def_id, span) + } + mid_res::DelegationResolution::Error(err) => Err(err), + } + } + + fn resolve_delegation_sig( + &self, + def_id: LocalDefId, + span: Span, + ) -> Result { + let tcx = self.tcx(); + + match tcx.resolutions(()).delegation_infos.get(&def_id) { + Some(res) => match res.resolution { + mid_res::DelegationResolution::Error(err) => Err(err), + mid_res::DelegationResolution::Full(def_id) + | mid_res::DelegationResolution::PartialCall(def_id) => Ok(def_id), + mid_res::DelegationResolution::Partial => { + self.resolve_type_relative_delegation_sig(def_id, span) + } + }, + None => Err(self.create_unresolved_error(def_id, span)), + } + } + + fn create_unresolved_error(&self, def_id: LocalDefId, span: Span) -> ErrorGuaranteed { + self.tcx().dcx().span_delayed_bug(span, format!("unresolved delegation {def_id:?}")) + } + + fn resolve_type_relative_delegation_sig( + &self, + def_id: LocalDefId, + span: Span, + ) -> Result { + let tcx = self.tcx(); + + match tcx.resolve_type_relative_delegations(()).get(&def_id) { + Some(res) => match *res { + TypeRelativeDelegationRes::Ok(sig_id) => Ok(sig_id), + TypeRelativeDelegationRes::Error(err) => Err(err), + TypeRelativeDelegationRes::Ambig(_) => { + Err(tcx.dcx().emit_err(AmbiguousDelegationToInherentImpl { span })) + } + }, + None => Err(self.create_unresolved_error(def_id, span)), + } } fn check_for_cycles(&self, mut def_id: DefId, span: Span) -> Result<(), ErrorGuaranteed> { let tcx = self.tcx(); let mut visited: FxHashSet = Default::default(); + let delegation_infos = &tcx.resolutions(()).delegation_infos; loop { visited.insert(def_id); @@ -174,8 +364,8 @@ impl<'tcx> DelegationResolver<'_, 'tcx> { // 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(info) = tcx.resolutions(()).delegation_infos.get(&local_id) - && let Ok(id) = info.resolution_id + && delegation_infos.contains_key(&local_id) + && let Ok(id) = self.resolve_delegation_sig(local_id, span) { def_id = id; if visited.contains(&def_id) { @@ -253,7 +443,7 @@ impl<'tcx> DelegationResolver<'_, 'tcx> { mapping.arguments_to_map.insert(0); } - if self.can_perform_self_mapping(delegation, parent)? { + if self.can_perform_self_mapping(delegation, parent, span) { /// Finds `Self` generic param only in ADT or references, so we avoid cases like /// `Self::Item` which will return true if `output.contains(...)` will be used. struct SelfFinder; @@ -307,10 +497,9 @@ impl<'tcx> DelegationResolver<'_, 'tcx> { // We can't yet map more than one argument if there are definitions inside. // FIXME(fn_delegation): support relowering with defs inside if contains_defs && mapping.arguments_to_map.len() > 1 { - return Err(self - .tcx() - .dcx() - .emit_err(DelegationAttemptedBlockWithDefsRelowering { span })); + let err = DelegationAttemptedBlockWithDefsRelowering { span }; + let err = self.tcx().dcx().emit_err(err); + return Err(err); } Ok(mapping) @@ -320,10 +509,11 @@ impl<'tcx> DelegationResolver<'_, 'tcx> { &self, delegation: &Delegation, parent: LocalDefId, - ) -> Result { + span: Span, + ) -> bool { // Heuristic: don't do wrapping if there is no target expression. if delegation.body.is_none() { - return Ok(false); + return false; } let tcx = self.tcx(); @@ -339,13 +529,17 @@ impl<'tcx> DelegationResolver<'_, 'tcx> { // 2) Inherent methods when delegating to trait, as we change the type of // `Self` to type of struct or enum we delegate from. if !matches!(tcx.def_kind(parent), DefKind::Impl { .. }) { - return Ok(false); + return false; } // Check that delegation path resolves to a trait AssocFn, not to a free method. // After previous check we are sure that `sig_id` and `delegation.id` // point to the same function. - let id = self.get_resolution_id(delegation.id)?; - Ok(tcx.def_kind(id) == DefKind::AssocFn && tcx.def_kind(tcx.parent(id)) == DefKind::Trait) + let id = self + .get_call_path_res(delegation, span) + .ok() + .expect("invalid paths are filtered out earlier"); + + tcx.def_kind(id) == DefKind::AssocFn && tcx.def_kind(tcx.parent(id)) == DefKind::Trait } } diff --git a/compiler/rustc_ast_lowering/src/diagnostics.rs b/compiler/rustc_ast_lowering/src/diagnostics.rs index b0fada9d3cd9e..2542268712f98 100644 --- a/compiler/rustc_ast_lowering/src/diagnostics.rs +++ b/compiler/rustc_ast_lowering/src/diagnostics.rs @@ -609,3 +609,24 @@ pub(crate) struct RestrictionAncestorOnly { pub(crate) span: Span, pub(crate) kind: ResolvingRestrictionKind, } + +#[derive(Diagnostic)] +#[diag("ambiguous delegation to inherent impl function")] +pub(crate) struct AmbiguousDelegationToInherentImpl { + #[primary_span] + pub span: Span, +} + +#[derive(Diagnostic)] +#[diag("delegation to inherent impl must contain parent generics")] +pub(crate) struct DelegationToInherentImplMustContainParentGenerics { + #[primary_span] + pub span: Span, +} + +#[derive(Diagnostic)] +#[diag("parent segment of delegation to inherent impl can not contain infers")] +pub(crate) struct DelegationToInherentImplParentContainsInfer { + #[primary_span] + pub span: Span, +} diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index ef6995d9c11d6..ac79703e63c01 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -102,6 +102,8 @@ pub mod stability; pub fn provide(providers: &mut Providers) { providers.index_ast = index_ast; providers.lower_to_hir = lower_to_hir; + providers.resolve_type_relative_delegations = + delegation::resolution::resolve_type_relative_delegations; } #[cfg(debug_assertions)] @@ -739,6 +741,8 @@ fn index_ast<'tcx>( #[instrument(level = "trace", skip(tcx))] fn lower_to_hir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::MaybeOwner<'_> { + tcx.ensure_done().resolve_type_relative_delegations(()); + let ast_index = tcx.index_ast(()); let resolver_and_node = ast_index.get(def_id).map(Steal::steal); diff --git a/compiler/rustc_hir_analysis/src/delegation.rs b/compiler/rustc_hir_analysis/src/delegation.rs index 1ae3fecf92096..2ffd335fb67b9 100644 --- a/compiler/rustc_hir_analysis/src/delegation.rs +++ b/compiler/rustc_hir_analysis/src/delegation.rs @@ -2,12 +2,15 @@ //! //! For more information about delegation design, see the tracking issue #118212. +use std::assert_matches; + use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{DelegationSelfTyPropagationKind, PathSegment}; use rustc_middle::ty::{ - self, EarlyBinder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, + self, ConstKind, EarlyBinder, GenericArg, GenericArgKind, RegionKind, Ty, TyCtxt, TypeFoldable, + TypeFolder, TypeSuperFoldable, TypeVisitableExt, }; use rustc_span::{ErrorGuaranteed, Span, kw}; @@ -121,8 +124,6 @@ fn fn_kinds(tcx: TyCtxt<'_>, def_id: LocalDefId, sig_id: DefId) -> (FnKind, FnKi // For trait impl's `sig_id` is always equal to the corresponding trait method. assert!(!matches!(kinds, (_, FnKind::AssocTraitImpl))); - // Delegation to inherent impls is not yet supported. - assert!(!matches!(kinds, (_, FnKind::AssocInherentImpl))); kinds } @@ -176,20 +177,80 @@ fn create_mapping<'tcx>( args_index += is_self_at_zero as usize; args_index += get_delegation_parent_args_count_without_self(tcx, def_id, sig_id); - let sig_generics = tcx.generics_of(sig_id); - let process_sig_parent_generics = matches!(fn_kind(tcx, sig_id), FnKind::AssocTrait); + let parent_kind = fn_kind(tcx, sig_id); + let process_parent = matches!(parent_kind, FnKind::AssocTrait | FnKind::AssocInherentImpl); + let parent_generics = process_parent.then(|| tcx.generics_of(tcx.parent(sig_id))); + + // In case of delegations to inherent impls indices of generic params which are passed + // to ADT can be random numbers not from range 0..parent_params_count, so we need to + // use original indices in mapping: + // impl<'a, 'b, 'c, A: 'a, const C: usize> S<'a, A, C> { + // fn foo_static<'d: 'd, 'e, T, const B: bool>() {} + // fn foo_self<'d: 'd, 'e, T, const B: bool>(self) {} + // }, + // 'a has index 0, A index 3, C index 4. If we encounter not a generic param as generic arg, + // then we do not need to map it (i.e. consts like `1`, `2`, `3`; `'static`, etc.). + let parent_params = match parent_kind { + FnKind::AssocInherentImpl => { + let ty::Adt(_, args) = tcx.type_of(tcx.parent(sig_id)).skip_binder().kind() else { + unreachable!("parent of inherent function in delegation can be only struct or enum") + }; + + let opt_param_info = |arg: GenericArg<'_>| match arg.kind() { + GenericArgKind::Lifetime(r) => ( + match r.kind() { + RegionKind::ReEarlyParam(p) => Some(p.index), + _ => None, + }, + false, + ), + GenericArgKind::Type(t) => ( + match t.kind() { + ty::Param(p) => Some(p.index), + _ => None, + }, + true, + ), + GenericArgKind::Const(c) => ( + match c.kind() { + ConstKind::Param(p) => Some(p.index), + _ => None, + }, + true, + ), + }; + + args.iter().map(opt_param_info).collect::>() + } + FnKind::AssocTrait => parent_generics + .expect("trait must have generics") + .own_params + .iter() + .map(|p| (Some(p.index as u32), p.kind.is_ty_or_const())) + .collect::>(), + _ => vec![], + }; + + let has_self = match parent_kind { + FnKind::AssocTrait => parent_generics.expect("trait must have generics").has_self, + _ => false, + }; + + if process_parent { + for i in (has_self as usize)..parent_params.len() { + let (index, is_ty_or_const) = parent_params[i]; + if !is_ty_or_const { + if let Some(index) = index { + mapping.insert(index, args_index as u32); + } - if process_sig_parent_generics { - for i in (sig_generics.has_self as usize)..sig_generics.parent_count { - let param = sig_generics.param_at(i, tcx); - if !param.kind.is_ty_or_const() { - mapping.insert(param.index, args_index as u32); args_index += 1; } } } - for param in &sig_generics.own_params { + let child_generics = tcx.generics_of(sig_id); + for param in &child_generics.own_params { if !param.kind.is_ty_or_const() { mapping.insert(param.index, args_index as u32); args_index += 1; @@ -204,17 +265,20 @@ fn create_mapping<'tcx>( args_index += 1; } - if process_sig_parent_generics { - for i in (sig_generics.has_self as usize)..sig_generics.parent_count { - let param = sig_generics.param_at(i, tcx); - if param.kind.is_ty_or_const() { - mapping.insert(param.index, args_index as u32); + if process_parent { + for i in (has_self as usize)..parent_params.len() { + let (index, is_ty_or_const) = parent_params[i]; + if is_ty_or_const { + if let Some(index) = index { + mapping.insert(index, args_index as u32); + } + args_index += 1; } } } - for param in &sig_generics.own_params { + for param in &child_generics.own_params { if param.kind.is_ty_or_const() { mapping.insert(param.index, args_index as u32); args_index += 1; @@ -339,7 +403,7 @@ fn create_generic_args<'tcx>( let delegation_args = &delegation_args[delegation_generics.parent_count..]; - let kinds = fn_kinds(tcx, def_id, sig_id); + let kinds @ (_, parent_kind) = fn_kinds(tcx, def_id, sig_id); if matches!(kinds, (FnKind::AssocTraitImpl, FnKind::AssocTrait)) { // Special case, as user specifies Trait args in trait impl header, we want to treat // them as parent args. We always generate a function whose generics match @@ -357,10 +421,14 @@ fn create_generic_args<'tcx>( let self_type = get_delegation_self_ty(tcx, def_id).map(ty::GenericArg::from); - // Remove `Self` from parent args (it is always at the `0th` index) as it is - // added manually. if self_type.is_some() && !parent_args.is_empty() { - parent_args = &parent_args[1..]; + parent_args = match parent_kind { + FnKind::AssocInherentImpl => parent_args, + // Remove `Self` from parent args (it is always at the `0th` index) as it is + // added manually. + FnKind::AssocTrait => &parent_args[1..], + _ => unreachable!("if parent args are non-empty then the parent must exist"), + } } let (zero_self, after_lifetimes_self) = @@ -582,8 +650,66 @@ pub(crate) fn inherit_sig_for_delegation_item<'tcx>( let caller_sig = EarlyBinder::bind(tcx, caller_sig.skip_binder().fold_with(&mut folder)); let sig = caller_sig.instantiate(tcx, args.as_slice()).skip_binder(); - let sig_iter = sig.inputs().iter().cloned().chain(std::iter::once(sig.output())); - tcx.arena.alloc_from_iter(sig_iter) + let output = std::iter::once(sig.output()); + let mut sig = sig.inputs().iter().cloned().chain(output).collect::>(); + + adjust_sig_in_inherent_impl_cases(tcx, sig_id, def_id, parent_args, &mut sig); + + tcx.arena.alloc_from_iter(sig) +} + +/// We need to replace `Self` type of the signature function parent with +/// either type of parent of delegation (which is either `Self` param in case of trait) +/// and other ADT in case of inherent impl. We do the same thing when delegating to trait, +/// in this case replacement happens during signature instantiation (as we can replace `Self` +/// generic param with other type from `args` when instantiating). +fn adjust_sig_in_inherent_impl_cases<'tcx>( + tcx: TyCtxt<'tcx>, + sig_id: DefId, + def_id: LocalDefId, + parent_args: &[ty::GenericArg<'tcx>], + sig: &mut [Ty<'tcx>], +) { + if !tcx.is_method(sig_id) { + return; + } + + let kinds @ (def_kind, _) = fn_kinds(tcx, def_id, sig_id); + if def_kind == FnKind::Free || !matches!(kinds, (_, FnKind::AssocInherentImpl)) { + return; + } + + let ty::Adt(def, _) = tcx.type_of(tcx.parent(sig_id)).skip_binder().kind() else { + unreachable!("delegation is supported only to struct or enums") + }; + + for i in 0..sig.len() { + let to_replace = Ty::new_adt(tcx, *def, tcx.mk_args(parent_args)); + let replacement = match def_kind { + FnKind::Free => unreachable!(), + + FnKind::AssocTrait => Ty::new_param(tcx, 0, kw::SelfUpper), + _ => tcx.type_of(tcx.parent(def_id.to_def_id())).instantiate_identity().skip_norm_wip(), + }; + + struct Replacer<'tcx> { + tcx: TyCtxt<'tcx>, + to_replace: Ty<'tcx>, + replacement: Ty<'tcx>, + } + + impl<'tcx> TypeFolder> for Replacer<'tcx> { + fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { + if t == self.to_replace { self.replacement } else { t.super_fold_with(self) } + } + + fn cx(&self) -> TyCtxt<'tcx> { + self.tcx + } + } + + sig[i] = sig[i].fold_with(&mut Replacer { tcx, to_replace, replacement }) + } } // Creates user-specified generic arguments from delegation path, @@ -603,11 +729,16 @@ pub(crate) fn delegation_user_specified_args<'tcx>( let ctx = ItemCtxt::new_for_delegation(tcx, def_id); let lowerer = ctx.lowerer(); + let parent_args = info .parent_seg_id_for_sig .and_then(get_segment) - .filter(|(_, def_id)| matches!(tcx.def_kind(*def_id), DefKind::Trait)) + .filter(|(_, def_id)| !matches!(tcx.def_kind(*def_id), DefKind::Mod)) .map(|(segment, def_id)| { + // After lowering parent segment can be resolved only to those variants (and `DefKind::Mod`), + // which we do not process here. + assert_matches!(tcx.def_kind(def_id), DefKind::Trait | DefKind::Struct | DefKind::Enum); + let self_ty = (tcx.def_kind(def_id) == DefKind::Trait) .then(|| Ty::new_param(tcx, 0, kw::SelfUpper)); @@ -617,29 +748,26 @@ pub(crate) fn delegation_user_specified_args<'tcx>( .as_slice() }); - let child_args = info - .child_seg_id_for_sig - .and_then(get_segment) - .filter(|(_, def_id)| matches!(tcx.def_kind(*def_id), DefKind::Fn | DefKind::AssocFn)) - .map(|(segment, def_id)| { - let parent_args = if let Some(parent_args) = parent_args { + let child_args = info.child_seg_id_for_sig.and_then(get_segment).map(|(segment, def_id)| { + assert_matches!(tcx.def_kind(def_id), DefKind::Fn | DefKind::AssocFn); + let parent = tcx.parent(def_id); + + let parent_args = + if matches!(tcx.def_kind(parent), DefKind::Impl { of_trait: false } | DefKind::Trait) { + ty::GenericArgs::identity_for_item(tcx, parent).as_slice() + } else if let Some(parent_args) = parent_args { parent_args } else { - let parent = tcx.parent(def_id); - if matches!(tcx.def_kind(parent), DefKind::Trait) { - ty::GenericArgs::identity_for_item(tcx, parent).as_slice() - } else { - &[] - } + &[] }; - let args = lowerer - .lower_generic_args_of_path(segment.ident.span, def_id, parent_args, segment, None) - .0; + let args = lowerer + .lower_generic_args_of_path(segment.ident.span, def_id, parent_args, segment, None) + .0; - let synth_params_count = tcx.generics_of(def_id).own_synthetic_params_count(); - &args[parent_args.len()..args.len() - synth_params_count] - }); + let synth_params_count = tcx.generics_of(def_id).own_synthetic_params_count(); + &args[parent_args.len()..args.len() - synth_params_count] + }); (parent_args.unwrap_or_default(), child_args.unwrap_or_default()) } diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 40bf435e6d110..6e6ded6c59ea1 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -1,7 +1,7 @@ use std::cell::{Cell, RefCell}; use std::cmp::max; -use std::debug_assert_matches; use std::ops::Deref; +use std::{assert_matches, debug_assert_matches}; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sso::SsoHashSet; @@ -595,8 +595,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } ProbeScope::Single(def_id, self_ty_override) => { let item = self.tcx.associated_item(def_id); - // FIXME(fn_delegation): Delegation to inherent methods is not yet supported. - assert_eq!(item.container, AssocContainer::Trait); + assert_matches!( + item.container, + AssocContainer::Trait | AssocContainer::InherentImpl + ); let trait_def_id = self.tcx.parent(def_id); let trait_span = self.tcx.def_span(trait_def_id); @@ -608,10 +610,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { probe_cx.push_candidate( Candidate { item, - kind: CandidateKind::TraitCandidate( - ty::Binder::dummy(trait_ref), - false, - ), + kind: match item.container { + AssocContainer::Trait => CandidateKind::TraitCandidate( + ty::Binder::dummy(trait_ref), + false, + ), + AssocContainer::InherentImpl => { + CandidateKind::InherentImplCandidate { + impl_def_id: self.tcx.parent(def_id), + receiver_steps: 0, + } + } + _ => unreachable!(), + }, import_ids: &[], }, false, diff --git a/compiler/rustc_middle/src/middle/resolve.rs b/compiler/rustc_middle/src/middle/resolve.rs index 2958048103320..8267cde89ad27 100644 --- a/compiler/rustc_middle/src/middle/resolve.rs +++ b/compiler/rustc_middle/src/middle/resolve.rs @@ -190,6 +190,8 @@ pub struct ResolverGlobalCtxt { // Information about delegations which is used when handling recursive delegations // and ensures easy access to delegation-only `LocalDefId`s. pub delegation_infos: FxIndexMap, + pub delegation_inherent_fn_map: + FxIndexMap>, } #[derive(Debug)] @@ -261,14 +263,44 @@ pub struct ResolverAstLowering<'tcx> { pub disambiguators: LocalDefIdMap>, } +#[derive(Debug, Clone, Copy, StableHash)] +pub enum DelegationResolution { + /// Corresponds to paths that are fully resolved by resolver (i.e., `reuse Trait::foo`). + Full(DefId /* Signature and call path resolutions are the same */), + + /// We can encounter cases like delegation to inherent impl function from trait impl, + /// in this case we will have resolved signature id, but the call-path itself will + /// not be resolved, so we will need to use type-relative resolution routine during + /// AST -> HIR lowering. + PartialCall(DefId /* Signature resolution, call path is unresolved */), + + /// Corresponds to paths that are partially resolved by resolver (i.e., `reuse Struct::foo`). + Partial, + + Error(ErrorGuaranteed), +} + #[derive(Debug, StableHash)] 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. - /// 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: Result, + // `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 + /// 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: DelegationResolution, +} + +#[derive(Debug, StableHash)] +pub enum TypeRelativeDelegationRes { + Ok(DefId), + Ambig(ErrorGuaranteed), + Error(ErrorGuaranteed), +} + +#[derive(Debug, StableHash)] +pub enum DelegationInherentFnKind { + Single(LocalDefId), + Ambig, } #[derive(Clone, Copy, Debug, StableHash)] diff --git a/compiler/rustc_middle/src/queries.rs b/compiler/rustc_middle/src/queries.rs index e127693a2e231..aa354e1ab8df0 100644 --- a/compiler/rustc_middle/src/queries.rs +++ b/compiler/rustc_middle/src/queries.rs @@ -71,6 +71,7 @@ use rustc_hir::{ItemLocalId, PreciseCapturingArgKind}; use rustc_index::{IndexSlice, IndexVec}; use rustc_lint_defs::{LintId, StableLintExpectationId}; use rustc_macros::rustc_queries; +use rustc_middle::middle::resolve::TypeRelativeDelegationRes; use rustc_session::Limits; use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion}; use rustc_span::def_id::{LOCAL_CRATE, ModId}; @@ -227,6 +228,11 @@ rustc_queries! { desc { "getting the source span" } } + query resolve_type_relative_delegations(_: ()) -> &'tcx FxIndexMap { + arena_cache + desc { "resolving type relative delegations" } + } + query lower_to_hir(def_id: LocalDefId) -> hir::MaybeOwner<'tcx> { eval_always desc { "lowering HIR for `{}`", tcx.def_path_str(def_id) } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 5ff5c05de734a..93e407570f04c 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1283,6 +1283,10 @@ impl<'tcx> TyCtxt<'tcx> { None => Err(VarError::NotPresent), } } + + pub fn is_method(self, id: DefId) -> bool { + self.opt_associated_item(id).is_some_and(|item| item.is_method()) + } } impl<'tcx> TyCtxtAt<'tcx> { diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 2966e3ad24a07..9b879d9a443fa 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -29,7 +29,9 @@ use rustc_hir::def::{CtorKind, DefKind, NonMacroAttrKind, PerNS}; use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE, LocalDefId}; use rustc_hir::{MissingLifetimeKind, PrimTy}; use rustc_lint_defs::builtin::{ELIDED_LIFETIMES_IN_PATHS, UNUSED_LABELS}; -use rustc_middle::middle::resolve::{DelegationInfo, LifetimeRes, PartialRes}; +use rustc_middle::middle::resolve::{ + DelegationInfo, DelegationInherentFnKind, DelegationResolution, LifetimeRes, PartialRes, +}; use rustc_middle::middle::resolve_bound_vars::Set1; use rustc_middle::ty::{AssocTag, Visibility}; use rustc_middle::{bug, span_bug}; @@ -501,11 +503,11 @@ impl PathSource<'_, '_, '_> { | PathSource::Pat | PathSource::Struct(_) | PathSource::TupleStruct(..) + | PathSource::Delegation | PathSource::ReturnTypeNotation => true, PathSource::Trait(_) | PathSource::TraitItem(..) | PathSource::DefineOpaques - | PathSource::Delegation | PathSource::ExternItemImpl | PathSource::PreciseCapturingArg(..) | PathSource::Macro @@ -3603,7 +3605,13 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { let mut seen_trait_items = Default::default(); for item in impl_items { with_owner(this, item.id, |this| { - this.resolve_impl_item(&**item, &mut seen_trait_items, trait_id, of_trait.is_some()); + this.resolve_impl_item( + &**item, + &mut seen_trait_items, + trait_id, + of_trait.is_some(), + self_type.id, + ); }) } }); @@ -3646,6 +3654,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { seen_trait_items: &mut FxHashMap, trait_id: Option, is_in_trait_impl: bool, + self_type_id: NodeId, ) { use crate::ResolutionError::*; self.resolve_doc_links(&item.attrs, MaybeExported::ImplItem(trait_id.ok_or(&item.vis))); @@ -3747,6 +3756,10 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { }, ); + if !is_in_trait_impl { + self.fill_delegation_inherent_fn_map(self_type_id, ident); + } + self.resolve_define_opaques(define_opaque); } AssocItemKind::Type(TyAlias { ident, generics, .. }) => { @@ -3789,6 +3802,14 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { LifetimeBinderKind::Function, delegation.path.segments.last().unwrap().ident.span, |this| { + if !is_in_trait_impl { + this.fill_delegation_inherent_fn_map( + self_type_id, + // If rename is specified then ident equals rename. + &delegation.ident, + ); + } + this.check_trait_item( item.id, delegation.ident, @@ -3813,6 +3834,34 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { self.diag_metadata.current_impl_item = prev; } + /// A heuristic to resolve delegations to inherent impls during AST -> HIR lowering. + /// Ideally we would do it through `ProbeContext`, however now it is impossible due to + /// query cycles even in the code without errors. + /// Not all paths will be properly resolved this way (i.e., type aliases). + /// FIXME(fn_delegation): remove it when resolution through `ProbeContext` will be ready + fn fill_delegation_inherent_fn_map(&mut self, self_type_id: NodeId, ident: &Ident) { + let res = self.r.partial_res_map.get(&self_type_id); + + let Some(self_type_def_id) = res.and_then(|res| { + res.full_res().and_then(|r| r.opt_def_id()).and_then(|id| id.as_local()) + }) else { + return; + }; + + // FIXME(fn_delegation): use correct identifier hygiene + let map = self.r.delegation_inherent_fn_map.entry(self_type_def_id).or_default(); + + match map.get(ident) { + None => { + map.insert(*ident, DelegationInherentFnKind::Single(self.r.current_owner.def_id)); + } + Some(DelegationInherentFnKind::Single(..)) => { + map.insert(*ident, DelegationInherentFnKind::Ambig); + } + _ => {} + }; + } + fn check_trait_item( &mut self, id: NodeId, @@ -3985,22 +4034,39 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { }); let resolution_node_id = if is_in_trait_impl { item_id } else { delegation.id }; - let def_id = self + let resolution = self .r .partial_res_map .get(&resolution_node_id) - .and_then(|r| r.expect_full_res().opt_def_id()); + .map(|r| match r.full_res().and_then(|r| r.opt_def_id()) { + None => { + // If we are inside trait impl delegation is either resolved or not. + assert!(!is_in_trait_impl); + DelegationResolution::Partial + } + Some(def_id) => { + // If we are inside trait impl do additional check if call path is resolved, + // this will later be used to decide if we should apply type-relative resolution + // routine during call path resolution in AST -> HIR lowering. + if is_in_trait_impl { + let path_res = self.r.partial_res_map[&delegation.id]; + + if path_res.full_res().and_then(|r| r.opt_def_id()).is_none() { + return DelegationResolution::PartialCall(def_id); + } + } - 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", - ), - ) - }); + DelegationResolution::Full(def_id) + } + }) + .unwrap_or_else(|| { + DelegationResolution::Error(self.r.tcx.dcx().span_delayed_bug( + delegation.path.span, + format!("bad resolution for delegation {item_id:?}"), + )) + }); - let info = DelegationInfo { resolution_id }; + let info = DelegationInfo { resolution }; self.r.delegation_infos.insert(self.r.current_owner.def_id, info); let Some(body) = &delegation.body else { return }; diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index d5b1457865891..baadbc644582b 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -62,8 +62,8 @@ use rustc_lint_defs::builtin::PRIVATE_MACRO_USE; use rustc_metadata::creader::CStore; use rustc_middle::middle::privacy::EffectiveVisibilities; use rustc_middle::middle::resolve::{ - AmbigModChild, DelegationInfo, DocLinkResMap, MainDefinition, ModChild, PartialRes, - PerOwnerResolverData, Reexport, ResolverAstLowering, ResolverGlobalCtxt, + AmbigModChild, DelegationInfo, DelegationInherentFnKind, DocLinkResMap, MainDefinition, + ModChild, PartialRes, PerOwnerResolverData, Reexport, ResolverAstLowering, ResolverGlobalCtxt, }; use rustc_middle::query::Providers; use rustc_middle::ty::{self, RegisteredTools, TyCtxt, TyCtxtFeed, Visibility}; @@ -1515,6 +1515,7 @@ pub struct Resolver<'ra, 'tcx> { item_required_generic_args_suggestions: FxHashMap = default::fx_hash_map(), delegation_fn_sigs: LocalDefIdMap = Default::default(), delegation_infos: FxIndexMap, + delegation_inherent_fn_map: FxIndexMap>, main_def: Option = None, trait_impls: FxIndexMap>, @@ -1887,6 +1888,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { current_crate_outer_attr_insert_span, disambiguators: Default::default(), delegation_infos: Default::default(), + delegation_inherent_fn_map: Default::default(), features: tcx.features(), .. }; @@ -1991,6 +1993,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { all_macro_rules: self.all_macro_rules, stripped_cfg_items, delegation_infos: self.delegation_infos, + delegation_inherent_fn_map: self.delegation_inherent_fn_map, }; let ast_lowering = ResolverAstLowering { partial_res_map: self.partial_res_map, diff --git a/tests/ui/delegation/bad-resolve.rs b/tests/ui/delegation/bad-resolve.rs index eb31c20081461..0864776ab49fd 100644 --- a/tests/ui/delegation/bad-resolve.rs +++ b/tests/ui/delegation/bad-resolve.rs @@ -33,10 +33,12 @@ impl Trait for S { reuse foo { &self.0 } //~^ ERROR cannot find function `foo` in this scope - //~| ERROR: method `foo` has a `&self` declaration in the trait, but not in the impl + //~| ERROR method `foo` has a `&self` declaration in the trait, but not in the impl reuse Trait::foo2 { self.0 } - //~^ ERROR cannot find function `foo2` in trait `Trait` - //~| ERROR method `foo2` is not a member of trait `Trait` + //~^ ERROR: method `foo2` is not a member of trait `Trait` + //~| WARN: trait objects without an explicit `dyn` are deprecated [bare_trait_objects] + //~| WARN: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + //~| ERROR: the trait `Trait` is not dyn compatible [E0038] } mod prefix {} diff --git a/tests/ui/delegation/bad-resolve.stderr b/tests/ui/delegation/bad-resolve.stderr index 44cf5149d08dd..9740442e4b9f3 100644 --- a/tests/ui/delegation/bad-resolve.stderr +++ b/tests/ui/delegation/bad-resolve.stderr @@ -71,25 +71,8 @@ error[E0425]: cannot find function `foo` in this scope LL | reuse foo { &self.0 } | ^^^ not found in this scope -error[E0425]: cannot find function `foo2` in trait `Trait` - --> $DIR/bad-resolve.rs:37:18 - | -LL | reuse Trait::foo2 { self.0 } - | ^^^^ not found in `Trait` - | -note: similarly named associated function `foo` defined here - --> $DIR/bad-resolve.rs:7:5 - | -LL | fn foo(&self, x: i32) -> i32 { x } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: an associated function with a similar name exists - | -LL - reuse Trait::foo2 { self.0 } -LL + reuse Trait::foo { self.0 } - | - error[E0423]: cannot find function `self` in module `prefix` - --> $DIR/bad-resolve.rs:44:16 + --> $DIR/bad-resolve.rs:46:16 | LL | reuse prefix::{self, super, crate}; | ^^^^ not found in `prefix` @@ -114,8 +97,54 @@ LL | type Type; LL | impl Trait for S { | ^^^^^^^^^^^^^^^^ missing `Type` in implementation +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/bad-resolve.rs:37:11 + | +LL | reuse Trait::foo2 { self.0 } + | ^^^^^ + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see + = note: `#[warn(bare_trait_objects)]` (part of `#[warn(rust_2021_compatibility)]`) on by default +help: if this is a dyn-compatible trait, use `dyn` + | +LL | reuse ::foo2 { self.0 } + | ++++ + + +error[E0038]: the trait `Trait` is not dyn compatible + --> $DIR/bad-resolve.rs:37:11 + | +LL | reuse Trait::foo2 { self.0 } + | ^^^^^ `Trait` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $DIR/bad-resolve.rs:4:11 + | +LL | trait Trait { + | ----- this trait is not dyn compatible... +LL | const C: u32 = 0; + | ^ ...because it contains associated const `C` +LL | type Type; +LL | fn bar() {} + | ^^^ ...because associated function `bar` has no `self` parameter + = help: consider moving `C` to another trait + = help: the following types implement `Trait`: + F + S + consider defining an enum where each variant holds one of these types, + implementing `Trait` for this new enum and using it instead +help: consider turning `bar` into a method by giving it a `&self` argument, so that it is accessible through the trait object's vtable + | +LL | fn bar(&self) {} + | +++++ +help: alternatively, consider constraining `bar` so it is explicitly marked as not applying to trait objects + | +LL | fn bar() where Self: Sized {} + | +++++++++++++++++ + error[E0433]: cannot find module or crate `unresolved_prefix` in this scope - --> $DIR/bad-resolve.rs:43:7 + --> $DIR/bad-resolve.rs:45:7 | LL | reuse unresolved_prefix::{a, b, c}; | ^^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `unresolved_prefix` @@ -123,12 +152,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:44:29 + --> $DIR/bad-resolve.rs:46:29 | LL | reuse prefix::{self, super, crate}; | ^^^^^ can only be used in path start position -error: aborting due to 14 previous errors +error: aborting due to 14 previous errors; 1 warning emitted -Some errors have detailed explanations: E0046, E0186, E0324, E0407, E0423, E0425, E0433, E0575, E0576. -For more information about an error, try `rustc --explain E0046`. +Some errors have detailed explanations: E0038, E0046, E0186, E0324, E0407, E0423, E0425, E0433, E0575... +For more information about an error, try `rustc --explain E0038`. diff --git a/tests/ui/delegation/explicit-paths.rs b/tests/ui/delegation/explicit-paths.rs index 2592d3d2698fc..e9530ec9d2314 100644 --- a/tests/ui/delegation/explicit-paths.rs +++ b/tests/ui/delegation/explicit-paths.rs @@ -25,7 +25,7 @@ mod fn_to_other { reuse ::foo2; reuse to_reuse::foo3; reuse S::foo4; - //~^ ERROR cannot find function `foo4` in `S` + //~^ ERROR: method `foo4` is private } mod inherent_impl_assoc_fn_to_other { @@ -36,7 +36,6 @@ mod inherent_impl_assoc_fn_to_other { reuse ::foo2; reuse to_reuse::foo3; reuse F::foo4 { &self.0 } - //~^ ERROR cannot find function `foo4` in `F` } } @@ -50,7 +49,6 @@ mod trait_impl_assoc_fn_to_other { //~^ ERROR method `foo3` is not a member of trait `Trait` reuse F::foo4 { &self.0 } //~^ ERROR method `foo4` is not a member of trait `Trait` - //~| ERROR cannot find function `foo4` in `F` } } @@ -63,7 +61,6 @@ mod trait_assoc_fn_to_other { reuse ::foo2; reuse to_reuse::foo3; reuse F::foo4 { &F } - //~^ ERROR cannot find function `foo4` in `F` } } diff --git a/tests/ui/delegation/explicit-paths.stderr b/tests/ui/delegation/explicit-paths.stderr index 30239f3648a53..f92bfd73266c3 100644 --- a/tests/ui/delegation/explicit-paths.stderr +++ b/tests/ui/delegation/explicit-paths.stderr @@ -1,5 +1,5 @@ error[E0407]: method `foo3` is not a member of trait `Trait` - --> $DIR/explicit-paths.rs:49:9 + --> $DIR/explicit-paths.rs:48:9 | LL | reuse to_reuse::foo3; | ^^^^^^^^^^^^^^^^----^ @@ -8,7 +8,7 @@ LL | reuse to_reuse::foo3; | not a member of trait `Trait` error[E0407]: method `foo4` is not a member of trait `Trait` - --> $DIR/explicit-paths.rs:51:9 + --> $DIR/explicit-paths.rs:50:9 | LL | reuse F::foo4 { &self.0 } | ^^^^^^^^^----^^^^^^^^^^^^ @@ -16,50 +16,8 @@ LL | reuse F::foo4 { &self.0 } | | help: there is an associated function with a similar name: `foo1` | not a member of trait `Trait` -error[E0425]: cannot find function `foo4` in `S` - --> $DIR/explicit-paths.rs:27:14 - | -LL | reuse S::foo4; - | ^^^^ not found in `S` - -error[E0425]: cannot find function `foo4` in `F` - --> $DIR/explicit-paths.rs:38:18 - | -LL | reuse F::foo4 { &self.0 } - | ^^^^ not found in `F` - | -note: function `fn_to_other::foo4` exists but is inaccessible - --> $DIR/explicit-paths.rs:27:5 - | -LL | reuse S::foo4; - | ^^^^^^^^^^^^^^ not accessible - -error[E0425]: cannot find function `foo4` in `F` - --> $DIR/explicit-paths.rs:51:18 - | -LL | reuse F::foo4 { &self.0 } - | ^^^^ not found in `F` - | -note: function `fn_to_other::foo4` exists but is inaccessible - --> $DIR/explicit-paths.rs:27:5 - | -LL | reuse S::foo4; - | ^^^^^^^^^^^^^^ not accessible - -error[E0425]: cannot find function `foo4` in `F` - --> $DIR/explicit-paths.rs:65:18 - | -LL | reuse F::foo4 { &F } - | ^^^^ not found in `F` - | -note: function `fn_to_other::foo4` exists but is inaccessible - --> $DIR/explicit-paths.rs:27:5 - | -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:71:5 | LL | impl Trait for S { | ---------------- first implementation here @@ -67,8 +25,17 @@ LL | impl Trait for S { LL | impl Trait for S { | ^^^^^^^^^^^^^^^^ conflicting implementation for `S` +error[E0624]: method `foo4` is private + --> $DIR/explicit-paths.rs:27:14 + | +LL | reuse S::foo4; + | ^^^^ private method +... +LL | reuse F::foo4 { &self.0 } + | ---- private method defined here + error[E0308]: mismatched types - --> $DIR/explicit-paths.rs:61:36 + --> $DIR/explicit-paths.rs:59:36 | LL | trait Trait2 : Trait { | -------------------- found this type parameter @@ -86,13 +53,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:73: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:70:5 | LL | struct S2; | ^^^^^^^^^ @@ -109,7 +76,7 @@ LL | impl Trait for S { | ^^^^^^^^^^^^^^^^ `S` error[E0308]: mismatched types - --> $DIR/explicit-paths.rs:76:30 + --> $DIR/explicit-paths.rs:73:30 | LL | reuse ::foo1; | ^^^^ @@ -125,7 +92,7 @@ note: method defined here LL | fn foo1(&self, x: i32) -> i32 { x } | ^^^^ ----- -error: aborting due to 10 previous errors +error: aborting due to 7 previous errors -Some errors have detailed explanations: E0119, E0277, E0308, E0407, E0425. +Some errors have detailed explanations: E0119, E0277, E0308, E0407, E0624. For more information about an error, try `rustc --explain E0119`. diff --git a/tests/ui/delegation/glob-non-fn.rs b/tests/ui/delegation/glob-non-fn.rs index 939c5db6a0e8f..72111fc81d7f0 100644 --- a/tests/ui/delegation/glob-non-fn.rs +++ b/tests/ui/delegation/glob-non-fn.rs @@ -31,7 +31,9 @@ impl Trait for Bad { //~ ERROR not all trait items implemented, missing: `CONST` //~| ERROR item `Type` is an associated method, which doesn't match its trait `Trait` //~| ERROR duplicate definitions with name `method` //~| ERROR expected function, found associated constant `Trait::CONST` - //~| ERROR cannot find function `Type` in trait `Trait` + //~| ERROR the trait `Trait` is not dyn compatible + //~| WARN trait objects without an explicit `dyn` are deprecated [bare_trait_objects] + //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! } fn main() {} diff --git a/tests/ui/delegation/glob-non-fn.stderr b/tests/ui/delegation/glob-non-fn.stderr index 6f7010d43d8ae..e1a4ffce5ac17 100644 --- a/tests/ui/delegation/glob-non-fn.stderr +++ b/tests/ui/delegation/glob-non-fn.stderr @@ -34,14 +34,6 @@ error[E0423]: expected function, found associated constant `Trait::CONST` LL | reuse Trait::* { &self.0 } | ^^^^^ not a function -error[E0423]: cannot find function `Type` in trait `Trait` - --> $DIR/glob-non-fn.rs:29:18 - | -LL | reuse Trait::* { &self.0 } - | ^ not found in `Trait` - | - = note: an associated type named `Trait::Type` exists in another namespace - error[E0046]: not all trait items implemented, missing: `CONST`, `Type`, `method` --> $DIR/glob-non-fn.rs:28:1 | @@ -56,7 +48,44 @@ LL | type method; LL | impl Trait for Bad { | ^^^^^^^^^^^^^^^^^^ missing `CONST`, `Type`, `method` in implementation -error: aborting due to 6 previous errors +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/glob-non-fn.rs:29:11 + | +LL | reuse Trait::* { &self.0 } + | ^^^^^ + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see + = note: `#[warn(bare_trait_objects)]` (part of `#[warn(rust_2021_compatibility)]`) on by default +help: if this is a dyn-compatible trait, use `dyn` + | +LL | reuse ::* { &self.0 } + | ++++ + + +error[E0038]: the trait `Trait` is not dyn compatible + --> $DIR/glob-non-fn.rs:29:11 + | +LL | reuse Trait::* { &self.0 } + | ^^^^^ `Trait` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $DIR/glob-non-fn.rs:5:11 + | +LL | trait Trait { + | ----- this trait is not dyn compatible... +LL | fn method(&self); +LL | const CONST: u8; + | ^^^^^ ...because it contains associated const `CONST` + = help: consider moving `CONST` to another trait + = help: the following types implement `Trait`: + u8 + Good + Bad + consider defining an enum where each variant holds one of these types, + implementing `Trait` for this new enum and using it instead + +error: aborting due to 6 previous errors; 1 warning emitted -Some errors have detailed explanations: E0046, E0201, E0324, E0423. -For more information about an error, try `rustc --explain E0046`. +Some errors have detailed explanations: E0038, E0046, E0201, E0324, E0423. +For more information about an error, try `rustc --explain E0038`. diff --git a/tests/ui/delegation/impl-reuse-non-reuse-items.rs b/tests/ui/delegation/impl-reuse-non-reuse-items.rs index 23c22a61cbb0a..517e2b26a36f9 100644 --- a/tests/ui/delegation/impl-reuse-non-reuse-items.rs +++ b/tests/ui/delegation/impl-reuse-non-reuse-items.rs @@ -23,9 +23,11 @@ mod non_delegatable_items { //~^ ERROR item `CONST` is an associated method, which doesn't match its trait `Trait` //~| ERROR item `Type` is an associated method, which doesn't match its trait `Trait` //~| ERROR duplicate definitions with name `method` - //~| ERROR expected function, found associated constant `Trait::CONST` - //~| ERROR cannot find function `Type` in trait `Trait` //~| ERROR not all trait items implemented, missing: `CONST`, `Type`, `method` + //~| ERROR expected function, found associated constant `Trait::CONST` + //~| WARN trait objects without an explicit `dyn` are deprecated [bare_trait_objects] + //~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + //~| ERROR the trait `non_delegatable_items::Trait` is not dyn compatible } 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 2bd488e9fb3d8..2a33982cc6730 100644 --- a/tests/ui/delegation/impl-reuse-non-reuse-items.stderr +++ b/tests/ui/delegation/impl-reuse-non-reuse-items.stderr @@ -34,14 +34,6 @@ error[E0423]: expected function, found associated constant `Trait::CONST` LL | reuse impl Trait for S { &self.0 } | ^^^^^ not a function -error[E0423]: cannot find function `Type` in trait `Trait` - --> $DIR/impl-reuse-non-reuse-items.rs:22:5 - | -LL | reuse impl Trait for S { &self.0 } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in `Trait` - | - = note: an associated type named `Trait::Type` exists in another namespace - error[E0046]: not all trait items implemented, missing: `CONST`, `Type`, `method` --> $DIR/impl-reuse-non-reuse-items.rs:22:5 | @@ -56,7 +48,43 @@ LL | type method; LL | reuse impl Trait for S { &self.0 } | ^^^^^^^^^^^^^^^^^^^^^^ missing `CONST`, `Type`, `method` in implementation -error: aborting due to 6 previous errors +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/impl-reuse-non-reuse-items.rs:22:16 + | +LL | reuse impl Trait for S { &self.0 } + | ^^^^^ + | + = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! + = note: for more information, see + = note: `#[warn(bare_trait_objects)]` (part of `#[warn(rust_2021_compatibility)]`) on by default +help: if this is a dyn-compatible trait, use `dyn` + | +LL | reuse impl for S { &self.0 } + | ++++ + + +error[E0038]: the trait `non_delegatable_items::Trait` is not dyn compatible + --> $DIR/impl-reuse-non-reuse-items.rs:22:16 + | +LL | reuse impl Trait for S { &self.0 } + | ^^^^^ `non_delegatable_items::Trait` is not dyn compatible + | +note: for a trait to be dyn compatible it needs to allow building a vtable + for more information, visit + --> $DIR/impl-reuse-non-reuse-items.rs:6:15 + | +LL | trait Trait { + | ----- this trait is not dyn compatible... +LL | fn method(&self); +LL | const CONST: u8; + | ^^^^^ ...because it contains associated const `CONST` + = help: consider moving `CONST` to another trait + = help: the following types implement `non_delegatable_items::Trait`: + non_delegatable_items::F + non_delegatable_items::S + consider defining an enum where each variant holds one of these types, + implementing `non_delegatable_items::Trait` for this new enum and using it instead + +error: aborting due to 6 previous errors; 1 warning emitted -Some errors have detailed explanations: E0046, E0201, E0324, E0423. -For more information about an error, try `rustc --explain E0046`. +Some errors have detailed explanations: E0038, E0046, E0201, E0324, E0423. +For more information about an error, try `rustc --explain E0038`. diff --git a/tests/ui/delegation/inherent-impls-ambig.rs b/tests/ui/delegation/inherent-impls-ambig.rs index 1c419034d2446..1b7c9a6fcef0f 100644 --- a/tests/ui/delegation/inherent-impls-ambig.rs +++ b/tests/ui/delegation/inherent-impls-ambig.rs @@ -14,16 +14,19 @@ mod test_1 { } reuse X::foo; - //~^ ERROR: cannot find function `foo` in `X` + //~^ ERROR: ambiguous delegation to inherent impl function + //~| ERROR: multiple applicable items in scope [E0034] reuse X::foo_self; - //~^ ERROR: cannot find function `foo_self` in `X` + //~^ ERROR: ambiguous delegation to inherent impl function + //~| ERROR: multiple applicable items in scope [E0034] reuse X::<()>::foo as foo1; - //~^ ERROR: cannot find function `foo` in `X` + //~^ ERROR: ambiguous delegation to inherent impl function reuse X::::foo_self as foo_self1; - //~^ ERROR: cannot find function `foo_self` in `X` + //~^ ERROR: ambiguous delegation to inherent impl function + //~| ERROR: this function takes 1 argument but 0 arguments were supplied } mod test_2 { @@ -47,16 +50,19 @@ mod test_2 { impl Marker2 for M2 {} reuse X::foo; - //~^ ERROR: cannot find function `foo` in `X` + //~^ ERROR: ambiguous delegation to inherent impl function + //~| ERROR: multiple applicable items in scope [E0034] reuse X::foo_self; - //~^ ERROR: cannot find function `foo_self` in `X` + //~^ ERROR: ambiguous delegation to inherent impl function + //~| ERROR: multiple applicable items in scope [E0034] reuse X::::foo as foo1; - //~^ ERROR: cannot find function `foo` in `X` + //~^ ERROR: ambiguous delegation to inherent impl function reuse X::::foo_self as foo_self1; - //~^ ERROR: cannot find function `foo_self` in `X` + //~^ ERROR: ambiguous delegation to inherent impl function + //~| ERROR: no associated function or constant named `foo_self` found for struct `test_2::X` in the current scope } fn main() {} diff --git a/tests/ui/delegation/inherent-impls-ambig.stderr b/tests/ui/delegation/inherent-impls-ambig.stderr index 0be82bcdd6f74..a15fc0f2af268 100644 --- a/tests/ui/delegation/inherent-impls-ambig.stderr +++ b/tests/ui/delegation/inherent-impls-ambig.stderr @@ -1,99 +1,145 @@ -error[E0425]: cannot find function `foo` in `X` +error: ambiguous delegation to inherent impl function --> $DIR/inherent-impls-ambig.rs:16:14 | LL | reuse X::foo; - | ^^^ not found in `X` - | -note: function `test_2::foo` exists but is inaccessible - --> $DIR/inherent-impls-ambig.rs:49:5 - | -LL | reuse X::foo; - | ^^^^^^^^^^^^^ not accessible + | ^^^ -error[E0425]: cannot find function `foo_self` in `X` - --> $DIR/inherent-impls-ambig.rs:19:14 - | -LL | reuse X::foo_self; - | ^^^^^^^^ not found in `X` - | -note: function `test_2::foo_self` exists but is inaccessible - --> $DIR/inherent-impls-ambig.rs:52:5 +error: ambiguous delegation to inherent impl function + --> $DIR/inherent-impls-ambig.rs:20:14 | LL | reuse X::foo_self; - | ^^^^^^^^^^^^^^^^^^ not accessible + | ^^^^^^^^ -error[E0425]: cannot find function `foo` in `X` - --> $DIR/inherent-impls-ambig.rs:22:20 +error: ambiguous delegation to inherent impl function + --> $DIR/inherent-impls-ambig.rs:24:20 | LL | reuse X::<()>::foo as foo1; - | ^^^ not found in `X` + | ^^^ + +error: ambiguous delegation to inherent impl function + --> $DIR/inherent-impls-ambig.rs:27:23 | -note: function `test_2::foo` exists but is inaccessible - --> $DIR/inherent-impls-ambig.rs:49:5 +LL | reuse X::::foo_self as foo_self1; + | ^^^^^^^^ + +error: ambiguous delegation to inherent impl function + --> $DIR/inherent-impls-ambig.rs:52:14 | LL | reuse X::foo; - | ^^^^^^^^^^^^^ not accessible + | ^^^ -error[E0425]: cannot find function `foo_self` in `X` - --> $DIR/inherent-impls-ambig.rs:25:23 +error: ambiguous delegation to inherent impl function + --> $DIR/inherent-impls-ambig.rs:56:14 | -LL | reuse X::::foo_self as foo_self1; - | ^^^^^^^^ not found in `X` +LL | reuse X::foo_self; + | ^^^^^^^^ + +error: ambiguous delegation to inherent impl function + --> $DIR/inherent-impls-ambig.rs:60:27 | -note: function `test_2::foo_self` exists but is inaccessible - --> $DIR/inherent-impls-ambig.rs:52:5 +LL | reuse X::::foo as foo1; + | ^^^ + +error: ambiguous delegation to inherent impl function + --> $DIR/inherent-impls-ambig.rs:63:28 | -LL | reuse X::foo_self; - | ^^^^^^^^^^^^^^^^^^ not accessible +LL | reuse X::::foo_self as foo_self1; + | ^^^^^^^^ -error[E0425]: cannot find function `foo` in `X` - --> $DIR/inherent-impls-ambig.rs:49:14 +error[E0034]: multiple applicable items in scope + --> $DIR/inherent-impls-ambig.rs:16:14 | LL | reuse X::foo; - | ^^^ not found in `X` + | ^^^ multiple `foo` found | -note: function `test_1::foo` exists but is inaccessible - --> $DIR/inherent-impls-ambig.rs:16:5 +note: candidate #1 is defined in an impl for the type `test_1::X<()>` + --> $DIR/inherent-impls-ambig.rs:7:9 | -LL | reuse X::foo; - | ^^^^^^^^^^^^^ not accessible +LL | fn foo() {} + | ^^^^^^^^ +note: candidate #2 is defined in an impl for the type `test_1::X` + --> $DIR/inherent-impls-ambig.rs:12:9 + | +LL | fn foo() {} + | ^^^^^^^^ -error[E0425]: cannot find function `foo_self` in `X` - --> $DIR/inherent-impls-ambig.rs:52:14 +error[E0034]: multiple applicable items in scope + --> $DIR/inherent-impls-ambig.rs:20:14 | LL | reuse X::foo_self; - | ^^^^^^^^ not found in `X` + | ^^^^^^^^ multiple `foo_self` found | -note: function `test_1::foo_self` exists but is inaccessible - --> $DIR/inherent-impls-ambig.rs:19:5 +note: candidate #1 is defined in an impl for the type `test_1::X<()>` + --> $DIR/inherent-impls-ambig.rs:8:9 | -LL | reuse X::foo_self; - | ^^^^^^^^^^^^^^^^^^ not accessible +LL | fn foo_self(self) {} + | ^^^^^^^^^^^^^^^^^ +note: candidate #2 is defined in an impl for the type `test_1::X` + --> $DIR/inherent-impls-ambig.rs:13:9 + | +LL | fn foo_self(self) {} + | ^^^^^^^^^^^^^^^^^ -error[E0425]: cannot find function `foo` in `X` - --> $DIR/inherent-impls-ambig.rs:55:27 +error[E0061]: this function takes 1 argument but 0 arguments were supplied + --> $DIR/inherent-impls-ambig.rs:27:23 | -LL | reuse X::::foo as foo1; - | ^^^ not found in `X` +LL | reuse X::::foo_self as foo_self1; + | ^^^^^^^^ argument #1 of type `test_1::X` is missing | -note: function `test_1::foo` exists but is inaccessible - --> $DIR/inherent-impls-ambig.rs:16:5 +note: method defined here + --> $DIR/inherent-impls-ambig.rs:13:12 | -LL | reuse X::foo; - | ^^^^^^^^^^^^^ not accessible +LL | fn foo_self(self) {} + | ^^^^^^^^ ---- +help: provide the argument + | +LL | reuse X::::foo_self(/* X */) as foo_self1; + | ++++++++++++++++ -error[E0425]: cannot find function `foo_self` in `X` - --> $DIR/inherent-impls-ambig.rs:58:28 +error[E0034]: multiple applicable items in scope + --> $DIR/inherent-impls-ambig.rs:52:14 | -LL | reuse X::::foo_self as foo_self1; - | ^^^^^^^^ not found in `X` +LL | reuse X::foo; + | ^^^ multiple `foo` found | -note: function `test_1::foo_self` exists but is inaccessible - --> $DIR/inherent-impls-ambig.rs:19:5 +note: candidate #1 is defined in an impl for the type `test_2::X` + --> $DIR/inherent-impls-ambig.rs:43:9 + | +LL | fn foo() {} + | ^^^^^^^^ +note: candidate #2 is defined in an impl for the type `test_2::X` + --> $DIR/inherent-impls-ambig.rs:38:9 + | +LL | fn foo() {} + | ^^^^^^^^ + +error[E0034]: multiple applicable items in scope + --> $DIR/inherent-impls-ambig.rs:56:14 | LL | reuse X::foo_self; - | ^^^^^^^^^^^^^^^^^^ not accessible + | ^^^^^^^^ multiple `foo_self` found + | +note: candidate #1 is defined in an impl for the type `test_2::X` + --> $DIR/inherent-impls-ambig.rs:44:9 + | +LL | fn foo_self(self) {} + | ^^^^^^^^^^^^^^^^^ +note: candidate #2 is defined in an impl for the type `test_2::X` + --> $DIR/inherent-impls-ambig.rs:39:9 + | +LL | fn foo_self(self) {} + | ^^^^^^^^^^^^^^^^^ + +error[E0599]: no associated function or constant named `foo_self` found for struct `test_2::X` in the current scope + --> $DIR/inherent-impls-ambig.rs:63:28 + | +LL | struct X(T, U); + | -------------- associated function or constant `foo_self` not found for this struct +... +LL | reuse X::::foo_self as foo_self1; + | ^^^^^^^^ associated function or constant not found in `test_2::X` -error: aborting due to 8 previous errors +error: aborting due to 14 previous errors -For more information about this error, try `rustc --explain E0425`. +Some errors have detailed explanations: E0034, E0061, E0599. +For more information about an error, try `rustc --explain E0034`. diff --git a/tests/ui/delegation/inherent-impls-enums.rs b/tests/ui/delegation/inherent-impls-enums.rs index 301cbe32b6f88..e8c7ba891b5ef 100644 --- a/tests/ui/delegation/inherent-impls-enums.rs +++ b/tests/ui/delegation/inherent-impls-enums.rs @@ -11,80 +11,58 @@ impl<'a, 'b, 'c, A: 'a, const C: usize> S<'a, A, C> { } reuse S::<'static, (), 1>::foo_static::<'static, (), true> as foo_static_1; -//~^ ERROR: cannot find function `foo_static` in enum `S` reuse S::<'static, (), 1>::foo_static as foo_static_3; -//~^ ERROR: cannot find function `foo_static` in enum `S` reuse S::<'static, (), 1>::foo_static::<'static, _, _> as foo_static_4; -//~^ ERROR: cannot find function `foo_static` in enum `S` reuse S::<'static, (), 1>::foo_self::<'static, (), true> as foo_self_1; -//~^ ERROR: cannot find function `foo_self` in enum `S` reuse S::<'static, (), 1>::foo_self as foo_self_3; -//~^ ERROR: cannot find function `foo_self` in enum `S` reuse S::<'static, (), 1>::foo_self::<'static, _, _> as foo_self_4; -//~^ ERROR: cannot find function `foo_self` in enum `S` trait Trait<'a, AA, BB> where Self: Sized, { reuse S::<'static, (), 1>::foo_static::<'static, (), true> as foo_static_1; - //~^ ERROR: cannot find function `foo_static` in enum `S` reuse S::<'static, (), 1>::foo_static as foo_static_3; - //~^ ERROR: cannot find function `foo_static` in enum `S` reuse S::<'static, (), 1>::foo_static::<'static, _, _> as foo_static_4; - //~^ ERROR: cannot find function `foo_static` in enum `S` fn get_s(self) -> S<'static, (), 1> { panic!(); } reuse S::<'static, (), 1>::foo_self::<'static, (), true> as foo_self_1 { self.get_s() } - //~^ ERROR: cannot find function `foo_self` in enum `S` reuse S::<'static, (), 1>::foo_self as foo_self_3 { self.get_s() } - //~^ ERROR: cannot find function `foo_self` in enum `S` reuse S::<'static, (), 1>::foo_self::<'static, _, _> as foo_self_4; - //~^ ERROR: cannot find function `foo_self` in enum `S` + //~^ ERROR: mismatched types [E0308] } struct X; impl<'a, A, B> Trait<'a, A, B> for X { reuse S::<'static, (), 1>::foo_static::<'static, (), true> as foo_static_1; - //~^ ERROR: cannot find function `foo_static` in enum `S` reuse S::<'static, (), 1>::foo_static as foo_static_3; - //~^ ERROR: cannot find function `foo_static` in enum `S` reuse S::<'static, (), 1>::foo_static::<'static, _, _> as foo_static_4; - //~^ ERROR: cannot find function `foo_static` in enum `S` + //~^ ERROR: type annotations needed [E0284] reuse S::<'static, (), 1>::foo_self::<'static, (), true> as foo_self_1 { self.get_s() } - //~^ ERROR: cannot find function `foo_self` in enum `S` - //~| ERROR: delegation's target expression is specified for function with no params reuse S::<'static, (), 1>::foo_self as foo_self_3 { self.get_s() } - //~^ ERROR: cannot find function `foo_self` in enum `S` - //~| ERROR: delegation's target expression is specified for function with no params reuse S::<'static, (), 1>::foo_self::<'static, _, _> as foo_self_4; - //~^ ERROR: cannot find function `foo_self` in enum `S` + //~^ ERROR: mismatched types [E0308] } impl X { reuse S::<'static, (), 1>::foo_static::<'static, (), true> as foo_static_1; - //~^ ERROR: cannot find function `foo_static` in enum `S` reuse S::<'static, (), 1>::foo_static as foo_static_3; - //~^ ERROR: cannot find function `foo_static` in enum `S` reuse S::<'static, (), 1>::foo_static::<'static, _, _> as foo_static_4; - //~^ ERROR: cannot find function `foo_static` in enum `S` fn get_s(self) -> S<'static, (), 1> { panic!(); } reuse S::<'static, (), 1>::foo_self::<'static, (), true> as foo_self_1 { self.get_s() } - //~^ ERROR: cannot find function `foo_self` in enum `S` reuse S::<'static, (), 1>::foo_self as foo_self_3 { self.get_s() } - //~^ ERROR: cannot find function `foo_self` in enum `S` reuse S::<'static, (), 1>::foo_self::<'static, _, _> as foo_self_4; - //~^ ERROR: cannot find function `foo_self` in enum `S` + //~^ ERROR: mismatched types [E0308] } fn main() {} diff --git a/tests/ui/delegation/inherent-impls-enums.stderr b/tests/ui/delegation/inherent-impls-enums.stderr index 0016488386017..d76aba9517ee4 100644 --- a/tests/ui/delegation/inherent-impls-enums.stderr +++ b/tests/ui/delegation/inherent-impls-enums.stderr @@ -1,159 +1,70 @@ -error[E0425]: cannot find function `foo_static` in enum `S` - --> $DIR/inherent-impls-enums.rs:13:28 - | -LL | reuse S::<'static, (), 1>::foo_static::<'static, (), true> as foo_static_1; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in enum `S` - --> $DIR/inherent-impls-enums.rs:15:28 - | -LL | reuse S::<'static, (), 1>::foo_static as foo_static_3; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in enum `S` - --> $DIR/inherent-impls-enums.rs:17:28 - | -LL | reuse S::<'static, (), 1>::foo_static::<'static, _, _> as foo_static_4; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in enum `S` - --> $DIR/inherent-impls-enums.rs:20:28 - | -LL | reuse S::<'static, (), 1>::foo_self::<'static, (), true> as foo_self_1; - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in enum `S` - --> $DIR/inherent-impls-enums.rs:22:28 - | -LL | reuse S::<'static, (), 1>::foo_self as foo_self_3; - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in enum `S` - --> $DIR/inherent-impls-enums.rs:24:28 - | -LL | reuse S::<'static, (), 1>::foo_self::<'static, _, _> as foo_self_4; - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in enum `S` - --> $DIR/inherent-impls-enums.rs:31:32 - | -LL | reuse S::<'static, (), 1>::foo_static::<'static, (), true> as foo_static_1; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in enum `S` - --> $DIR/inherent-impls-enums.rs:33:32 - | -LL | reuse S::<'static, (), 1>::foo_static as foo_static_3; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in enum `S` +error[E0308]: mismatched types --> $DIR/inherent-impls-enums.rs:35:32 | -LL | reuse S::<'static, (), 1>::foo_static::<'static, _, _> as foo_static_4; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in enum `S` - --> $DIR/inherent-impls-enums.rs:42:32 - | -LL | reuse S::<'static, (), 1>::foo_self::<'static, (), true> as foo_self_1 { self.get_s() } - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in enum `S` - --> $DIR/inherent-impls-enums.rs:44:32 - | -LL | reuse S::<'static, (), 1>::foo_self as foo_self_3 { self.get_s() } - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in enum `S` - --> $DIR/inherent-impls-enums.rs:46:32 - | +LL | trait Trait<'a, AA, BB> + | ----------------------- found this type parameter +... LL | reuse S::<'static, (), 1>::foo_self::<'static, _, _> as foo_self_4; - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in enum `S` - --> $DIR/inherent-impls-enums.rs:53:32 + | ^^^^^^^^ + | | + | expected `S<'_, (), 1>`, found type parameter `Self` + | arguments to this function are incorrect | -LL | reuse S::<'static, (), 1>::foo_static::<'static, (), true> as foo_static_1; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in enum `S` - --> $DIR/inherent-impls-enums.rs:55:32 + = note: expected enum `S<'_, (), 1>` + found type parameter `Self` +note: method defined here + --> $DIR/inherent-impls-enums.rs:10:8 | -LL | reuse S::<'static, (), 1>::foo_static as foo_static_3; - | ^^^^^^^^^^ not found in `S` +LL | fn foo_self<'d: 'd, 'e, T, const B: bool>(self) {} + | ^^^^^^^^ ---- -error[E0425]: cannot find function `foo_static` in enum `S` - --> $DIR/inherent-impls-enums.rs:57:32 +error[E0284]: type annotations needed + --> $DIR/inherent-impls-enums.rs:44:32 | LL | reuse S::<'static, (), 1>::foo_static::<'static, _, _> as foo_static_4; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in enum `S` - --> $DIR/inherent-impls-enums.rs:60:32 + | ^^^^^^^^^^ cannot infer the value of const parameter `B` declared on the associated function `foo_static` | -LL | reuse S::<'static, (), 1>::foo_self::<'static, (), true> as foo_self_1 { self.get_s() } - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in enum `S` - --> $DIR/inherent-impls-enums.rs:63:32 +note: required by a const generic parameter in `S::<'a, A, C>::foo_static` + --> $DIR/inherent-impls-enums.rs:9:34 | -LL | reuse S::<'static, (), 1>::foo_self as foo_self_3 { self.get_s() } - | ^^^^^^^^ not found in `S` +LL | fn foo_static<'d: 'd, 'e, T, const B: bool>() {} + | ^^^^^^^^^^^^^ required by this const generic parameter in `S::<'a, A, C>::foo_static` -error[E0425]: cannot find function `foo_self` in enum `S` - --> $DIR/inherent-impls-enums.rs:66:32 +error[E0308]: mismatched types + --> $DIR/inherent-impls-enums.rs:49:32 | LL | reuse S::<'static, (), 1>::foo_self::<'static, _, _> as foo_self_4; - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in enum `S` - --> $DIR/inherent-impls-enums.rs:71:32 + | ^^^^^^^^ + | | + | expected `S<'_, (), 1>`, found `X` + | arguments to this function are incorrect | -LL | reuse S::<'static, (), 1>::foo_static::<'static, (), true> as foo_static_1; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in enum `S` - --> $DIR/inherent-impls-enums.rs:73:32 - | -LL | reuse S::<'static, (), 1>::foo_static as foo_static_3; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in enum `S` - --> $DIR/inherent-impls-enums.rs:75:32 - | -LL | reuse S::<'static, (), 1>::foo_static::<'static, _, _> as foo_static_4; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in enum `S` - --> $DIR/inherent-impls-enums.rs:82:32 - | -LL | reuse S::<'static, (), 1>::foo_self::<'static, (), true> as foo_self_1 { self.get_s() } - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in enum `S` - --> $DIR/inherent-impls-enums.rs:84:32 + = note: expected enum `S<'_, (), 1>` + found struct `X` +note: method defined here + --> $DIR/inherent-impls-enums.rs:10:8 | -LL | reuse S::<'static, (), 1>::foo_self as foo_self_3 { self.get_s() } - | ^^^^^^^^ not found in `S` +LL | fn foo_self<'d: 'd, 'e, T, const B: bool>(self) {} + | ^^^^^^^^ ---- -error[E0425]: cannot find function `foo_self` in enum `S` - --> $DIR/inherent-impls-enums.rs:86:32 +error[E0308]: mismatched types + --> $DIR/inherent-impls-enums.rs:64:32 | LL | reuse S::<'static, (), 1>::foo_self::<'static, _, _> as foo_self_4; - | ^^^^^^^^ not found in `S` - -error: delegation's target expression is specified for function with no params - --> $DIR/inherent-impls-enums.rs:60:76 + | ^^^^^^^^ + | | + | expected `S<'_, (), 1>`, found `X` + | arguments to this function are incorrect | -LL | reuse S::<'static, (), 1>::foo_self::<'static, (), true> as foo_self_1 { self.get_s() } - | ^^^^^^^^^^^^^^^^ - -error: delegation's target expression is specified for function with no params - --> $DIR/inherent-impls-enums.rs:63:55 + = note: expected enum `S<'_, (), 1>` + found struct `X` +note: method defined here + --> $DIR/inherent-impls-enums.rs:10:8 | -LL | reuse S::<'static, (), 1>::foo_self as foo_self_3 { self.get_s() } - | ^^^^^^^^^^^^^^^^ +LL | fn foo_self<'d: 'd, 'e, T, const B: bool>(self) {} + | ^^^^^^^^ ---- -error: aborting due to 26 previous errors +error: aborting due to 4 previous errors -For more information about this error, try `rustc --explain E0425`. +Some errors have detailed explanations: E0284, E0308. +For more information about an error, try `rustc --explain E0284`. diff --git a/tests/ui/delegation/inherent-impls-glob-list.rs b/tests/ui/delegation/inherent-impls-glob-list.rs index 51d24e6838df0..d983711102dde 100644 --- a/tests/ui/delegation/inherent-impls-glob-list.rs +++ b/tests/ui/delegation/inherent-impls-glob-list.rs @@ -11,8 +11,6 @@ struct Y; impl Y { reuse X::{foo, foo2} { X } - //~^ ERROR: cannot find function `foo` in `X` - //~| ERROR: cannot find function `foo2` in `X` } impl Y { diff --git a/tests/ui/delegation/inherent-impls-glob-list.stderr b/tests/ui/delegation/inherent-impls-glob-list.stderr index d2dfce86f860a..7972e598e1853 100644 --- a/tests/ui/delegation/inherent-impls-glob-list.stderr +++ b/tests/ui/delegation/inherent-impls-glob-list.stderr @@ -1,21 +1,8 @@ error: expected trait, found struct `X` - --> $DIR/inherent-impls-glob-list.rs:19:11 + --> $DIR/inherent-impls-glob-list.rs:17:11 | LL | reuse X::*; | ^ not a trait -error[E0425]: cannot find function `foo` in `X` - --> $DIR/inherent-impls-glob-list.rs:13:15 - | -LL | reuse X::{foo, foo2} { X } - | ^^^ not found in `X` - -error[E0425]: cannot find function `foo2` in `X` - --> $DIR/inherent-impls-glob-list.rs:13:20 - | -LL | reuse X::{foo, foo2} { X } - | ^^^^ not found in `X` - -error: aborting due to 3 previous errors +error: aborting due to 1 previous error -For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/delegation/inherent-impls-mixed-generics.rs b/tests/ui/delegation/inherent-impls-mixed-generics.rs index 027dcace3ab0d..b24acff6187eb 100644 --- a/tests/ui/delegation/inherent-impls-mixed-generics.rs +++ b/tests/ui/delegation/inherent-impls-mixed-generics.rs @@ -10,7 +10,8 @@ impl<'a, 'b, 'c, A, const C: usize> S<'static, A, usize, C> { trait Trait<'a, AA, BB> where Self: Sized { reuse S::foo_self; - //~^ ERROR: cannot find function `foo_self` in `S` + //~^ ERROR: delegation to inherent impl must contain parent generics + //~| ERROR: this function takes 1 argument but 0 arguments were supplied } fn main() {} diff --git a/tests/ui/delegation/inherent-impls-mixed-generics.stderr b/tests/ui/delegation/inherent-impls-mixed-generics.stderr index f515b52ca45ab..f730d5360eef7 100644 --- a/tests/ui/delegation/inherent-impls-mixed-generics.stderr +++ b/tests/ui/delegation/inherent-impls-mixed-generics.stderr @@ -1,9 +1,25 @@ -error[E0425]: cannot find function `foo_self` in `S` +error: delegation to inherent impl must contain parent generics --> $DIR/inherent-impls-mixed-generics.rs:12:14 | LL | reuse S::foo_self; - | ^^^^^^^^ not found in `S` + | ^^^^^^^^ -error: aborting due to 1 previous error +error[E0061]: this function takes 1 argument but 0 arguments were supplied + --> $DIR/inherent-impls-mixed-generics.rs:12:14 + | +LL | reuse S::foo_self; + | ^^^^^^^^ argument #1 of type `S<'static, _, usize, _>` is missing + | +note: method defined here + --> $DIR/inherent-impls-mixed-generics.rs:8:8 + | +LL | fn foo_self<'d: 'd, 'e, T, const B: bool>(self) {} + | ^^^^^^^^ ---- +help: provide the argument + | +LL | reuse S::foo_self(/* value */); + | +++++++++++++ + +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0425`. +For more information about this error, try `rustc --explain E0061`. diff --git a/tests/ui/delegation/inherent-impls-non-local-crate.rs b/tests/ui/delegation/inherent-impls-non-local-crate.rs index c2f07fd8e7ae7..27b8d387a7e63 100644 --- a/tests/ui/delegation/inherent-impls-non-local-crate.rs +++ b/tests/ui/delegation/inherent-impls-non-local-crate.rs @@ -3,23 +3,21 @@ #![feature(fn_delegation)] reuse inherent_impl::S::foo; -//~^ ERROR: cannot find function `foo` in `inherent_impl::S` reuse inherent_impl::S::not_existing; -//~^ ERROR: cannot find function `not_existing` in `inherent_impl::S` - +//~^ ERROR: no associated function or constant named `not_existing` found for struct `S` in the current scope reuse inherent_impl::S::TYPE; -//~^ ERROR: cannot find function `TYPE` in `inherent_impl::S` - +//~^ ERROR: no associated function or constant named `TYPE` found for struct `S` in the current scope reuse inherent_impl::S::CONST; -//~^ ERROR: cannot find function `CONST` in `inherent_impl::S` +//~^ ERROR: expected function, found `usize` [E0618] reuse inherent_impl::S::bar; -//~^ ERROR: cannot find function `bar` in `inherent_impl::S` +//~^ ERROR: no associated function or constant named `bar` found for struct `S` in the current scope reuse ::bar as trait_bar; reuse inherent_impl::X::foo as x_foo; -//~^ ERROR: cannot find function `foo` in `inherent_impl::X` +//~^ ERROR: ambiguous delegation to inherent impl function +//~| ERROR: multiple applicable items in scope fn main() {} diff --git a/tests/ui/delegation/inherent-impls-non-local-crate.stderr b/tests/ui/delegation/inherent-impls-non-local-crate.stderr index 983c8b8f3cb9b..31358b1d7144e 100644 --- a/tests/ui/delegation/inherent-impls-non-local-crate.stderr +++ b/tests/ui/delegation/inherent-impls-non-local-crate.stderr @@ -1,39 +1,49 @@ -error[E0425]: cannot find function `foo` in `inherent_impl::S` - --> $DIR/inherent-impls-non-local-crate.rs:5:25 +error: ambiguous delegation to inherent impl function + --> $DIR/inherent-impls-non-local-crate.rs:19:25 | -LL | reuse inherent_impl::S::foo; - | ^^^ not found in `inherent_impl::S` +LL | reuse inherent_impl::X::foo as x_foo; + | ^^^ -error[E0425]: cannot find function `not_existing` in `inherent_impl::S` - --> $DIR/inherent-impls-non-local-crate.rs:8:25 +error[E0599]: no associated function or constant named `not_existing` found for struct `S` in the current scope + --> $DIR/inherent-impls-non-local-crate.rs:7:25 | LL | reuse inherent_impl::S::not_existing; - | ^^^^^^^^^^^^ not found in `inherent_impl::S` + | ^^^^^^^^^^^^ associated function or constant not found in `S` -error[E0425]: cannot find function `TYPE` in `inherent_impl::S` - --> $DIR/inherent-impls-non-local-crate.rs:11:25 +error[E0599]: no associated function or constant named `TYPE` found for struct `S` in the current scope + --> $DIR/inherent-impls-non-local-crate.rs:9:25 | LL | reuse inherent_impl::S::TYPE; - | ^^^^ not found in `inherent_impl::S` + | ^^^^ associated function or constant not found in `S` -error[E0425]: cannot find function `CONST` in `inherent_impl::S` - --> $DIR/inherent-impls-non-local-crate.rs:14:25 +error[E0618]: expected function, found `usize` + --> $DIR/inherent-impls-non-local-crate.rs:11:25 | LL | reuse inherent_impl::S::CONST; - | ^^^^^ not found in `inherent_impl::S` + | ^^^^^ call expression requires function -error[E0425]: cannot find function `bar` in `inherent_impl::S` - --> $DIR/inherent-impls-non-local-crate.rs:17:25 +error[E0599]: no associated function or constant named `bar` found for struct `S` in the current scope + --> $DIR/inherent-impls-non-local-crate.rs:14:25 | LL | reuse inherent_impl::S::bar; - | ^^^ not found in `inherent_impl::S` + | ^^^ associated function or constant not found in `S` + | + = help: items from traits can only be used if the trait is in scope +help: trait `Trait` which provides `bar` is implemented but not in scope; perhaps you want to import it + | +LL + use inherent_impl::Trait; + | -error[E0425]: cannot find function `foo` in `inherent_impl::X` - --> $DIR/inherent-impls-non-local-crate.rs:22:25 +error[E0034]: multiple applicable items in scope + --> $DIR/inherent-impls-non-local-crate.rs:19:25 | LL | reuse inherent_impl::X::foo as x_foo; - | ^^^ not found in `inherent_impl::X` + | ^^^ multiple `foo` found + | + = note: candidate #1 is defined in an impl for the type `X` + = note: candidate #2 is defined in an impl for the type `X` error: aborting due to 6 previous errors -For more information about this error, try `rustc --explain E0425`. +Some errors have detailed explanations: E0034, E0599, E0618. +For more information about an error, try `rustc --explain E0034`. diff --git a/tests/ui/delegation/inherent-impls-parent-generics.rs b/tests/ui/delegation/inherent-impls-parent-generics.rs index 0f95540643bd7..1c303e16a0272 100644 --- a/tests/ui/delegation/inherent-impls-parent-generics.rs +++ b/tests/ui/delegation/inherent-impls-parent-generics.rs @@ -12,32 +12,36 @@ impl<'a, 'b, 'c, A: 'a, const C: usize> E<'a, A, C> { } reuse E::foo_static as e; -//~^ ERROR: cannot find function `foo_static` in enum `E` - +//~^ ERROR: delegation to inherent impl must contain parent generics +//~| ERROR: type annotations needed +//~| ERROR: type annotations needed +//~| ERROR: type annotations needed reuse E::foo_self as e1; -//~^ ERROR: cannot find function `foo_self` in enum `E` +//~^ ERROR: delegation to inherent impl must contain parent generics +//~| ERROR: this function takes 1 argument but 0 arguments were supplied reuse E::foo_static::<'static, (), true> as e2; -//~^ ERROR: cannot find function `foo_static` in enum `E` - +//~^ ERROR: delegation to inherent impl must contain parent generics +//~| ERROR: type annotations needed +//~| ERROR: type annotations needed reuse E::foo_self::<'static, (), true> as e3; -//~^ ERROR: cannot find function `foo_self` in enum `E` +//~^ ERROR: delegation to inherent impl must contain parent generics +//~| ERROR: this function takes 1 argument but 0 arguments were supplied reuse E::<'static, (), 123>::foo_static as e4; -//~^ ERROR: cannot find function `foo_static` in enum `E` reuse E::<'static, (), 123>::foo_self as e5; -//~^ ERROR: cannot find function `foo_self` in enum `E` reuse E::<'static, (), 123>::foo_static::<'static, (), true> as e6; -//~^ ERROR: cannot find function `foo_static` in enum `E` reuse E::<'static, (), 123>::foo_self::<'static, (), true> as e7; -//~^ ERROR: cannot find function `foo_self` in enum `E` reuse E::<'_, (), _>::foo_static as e8; -//~^ ERROR: cannot find function `foo_static` in enum `E` - +//~^ ERROR: parent segment of delegation to inherent impl can not contain infers +//~| ERROR: type annotations needed +//~| ERROR: type annotations needed +//~| ERROR: type annotations needed reuse E::<'_, _, _>::foo_self as e9; -//~^ ERROR: cannot find function `foo_self` in enum `E` +//~^ ERROR: parent segment of delegation to inherent impl can not contain infers +//~| ERROR: this function takes 1 argument but 0 arguments were supplied struct S { xd: [A; C], @@ -49,32 +53,35 @@ impl<'a, 'b, 'c, A, const C: usize> S { } reuse S::foo_static as s; -//~^ ERROR: cannot find function `foo_static` in `S` - +//~^ ERROR: delegation to inherent impl must contain parent generics +//~| ERROR: type annotations needed +//~| ERROR: type annotations needed +//~| ERROR: type annotations needed reuse S::foo_self as s1; -//~^ ERROR: cannot find function `foo_self` in `S` +//~^ ERROR: delegation to inherent impl must contain parent generics +//~| ERROR: this function takes 1 argument but 0 arguments were supplied reuse S::foo_static::<'static, (), true> as s2; -//~^ ERROR: cannot find function `foo_static` in `S` - +//~^ ERROR: delegation to inherent impl must contain parent generics +//~| ERROR: type annotations needed +//~| ERROR: type annotations needed reuse S::foo_self::<'static, (), true> as s3; -//~^ ERROR: cannot find function `foo_self` in `S` +//~^ ERROR: delegation to inherent impl must contain parent generics +//~| ERROR: this function takes 1 argument but 0 arguments were supplied reuse S::<(), 123>::foo_static as s4; -//~^ ERROR: cannot find function `foo_static` in `S` reuse S::<(), 123>::foo_self as s5; -//~^ ERROR: cannot find function `foo_self` in `S` reuse S::<(), 123>::foo_static::<'static, (), true> as s6; -//~^ ERROR: cannot find function `foo_static` in `S` reuse S::<(), 123>::foo_self::<'static, (), true> as s7; -//~^ ERROR: cannot find function `foo_self` in `S` reuse S::<(), _>::foo_static as s8; -//~^ ERROR: cannot find function `foo_static` in `S` - +//~^ ERROR: parent segment of delegation to inherent impl can not contain infers +//~| ERROR: type annotations needed +//~| ERROR: type annotations needed +//~| ERROR: type annotations needed reuse S::<_, 123>::foo_self as s9; -//~^ ERROR: cannot find function `foo_self` in `S` - +//~^ ERROR: parent segment of delegation to inherent impl can not contain infers +//~| ERROR: this function takes 1 argument but 0 arguments were supplied fn main() {} diff --git a/tests/ui/delegation/inherent-impls-parent-generics.stderr b/tests/ui/delegation/inherent-impls-parent-generics.stderr index 508ca65316457..b1001e193a9cd 100644 --- a/tests/ui/delegation/inherent-impls-parent-generics.stderr +++ b/tests/ui/delegation/inherent-impls-parent-generics.stderr @@ -1,123 +1,440 @@ -error[E0425]: cannot find function `foo_static` in enum `E` +error: delegation to inherent impl must contain parent generics --> $DIR/inherent-impls-parent-generics.rs:14:10 | LL | reuse E::foo_static as e; - | ^^^^^^^^^^ not found in `E` + | ^^^^^^^^^^ -error[E0425]: cannot find function `foo_self` in enum `E` - --> $DIR/inherent-impls-parent-generics.rs:17:10 +error: delegation to inherent impl must contain parent generics + --> $DIR/inherent-impls-parent-generics.rs:19:10 | LL | reuse E::foo_self as e1; - | ^^^^^^^^ not found in `E` + | ^^^^^^^^ -error[E0425]: cannot find function `foo_static` in enum `E` - --> $DIR/inherent-impls-parent-generics.rs:20:10 +error: delegation to inherent impl must contain parent generics + --> $DIR/inherent-impls-parent-generics.rs:23:10 | LL | reuse E::foo_static::<'static, (), true> as e2; - | ^^^^^^^^^^ not found in `E` + | ^^^^^^^^^^ -error[E0425]: cannot find function `foo_self` in enum `E` - --> $DIR/inherent-impls-parent-generics.rs:23:10 +error: delegation to inherent impl must contain parent generics + --> $DIR/inherent-impls-parent-generics.rs:27:10 | LL | reuse E::foo_self::<'static, (), true> as e3; - | ^^^^^^^^ not found in `E` + | ^^^^^^^^ + +error: parent segment of delegation to inherent impl can not contain infers + --> $DIR/inherent-impls-parent-generics.rs:37:23 + | +LL | reuse E::<'_, (), _>::foo_static as e8; + | ^^^^^^^^^^ -error[E0425]: cannot find function `foo_static` in enum `E` - --> $DIR/inherent-impls-parent-generics.rs:26:30 +error: parent segment of delegation to inherent impl can not contain infers + --> $DIR/inherent-impls-parent-generics.rs:42:22 + | +LL | reuse E::<'_, _, _>::foo_self as e9; + | ^^^^^^^^ + +error: delegation to inherent impl must contain parent generics + --> $DIR/inherent-impls-parent-generics.rs:55:10 + | +LL | reuse S::foo_static as s; + | ^^^^^^^^^^ + +error: delegation to inherent impl must contain parent generics + --> $DIR/inherent-impls-parent-generics.rs:60:10 + | +LL | reuse S::foo_self as s1; + | ^^^^^^^^ + +error: delegation to inherent impl must contain parent generics + --> $DIR/inherent-impls-parent-generics.rs:64:10 + | +LL | reuse S::foo_static::<'static, (), true> as s2; + | ^^^^^^^^^^ + +error: delegation to inherent impl must contain parent generics + --> $DIR/inherent-impls-parent-generics.rs:68:10 + | +LL | reuse S::foo_self::<'static, (), true> as s3; + | ^^^^^^^^ + +error: parent segment of delegation to inherent impl can not contain infers + --> $DIR/inherent-impls-parent-generics.rs:78:19 + | +LL | reuse S::<(), _>::foo_static as s8; + | ^^^^^^^^^^ + +error: parent segment of delegation to inherent impl can not contain infers + --> $DIR/inherent-impls-parent-generics.rs:83:20 + | +LL | reuse S::<_, 123>::foo_self as s9; + | ^^^^^^^^ + +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:14:10 + | +LL | reuse E::foo_static as e; + | - ^^^^^^^^^^ cannot infer the value of the const parameter `C` declared on the enum `E` + | | + | type must be known at this point + | +note: required by a const generic parameter in `E` + --> $DIR/inherent-impls-parent-generics.rs:4:23 + | +LL | enum E<'a: 'a, A: 'a, const C: usize> { + | ^^^^^^^^^^^^^^ required by this const generic parameter in `E` +help: consider specifying the generic arguments + | +LL - reuse E::foo_static as e; +LL + reuse E:: as e; + | + +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:14:10 + | +LL | reuse E::foo_static as e; + | ^^^^^^^^^^ cannot infer the value of the const parameter `C` declared on the enum `E` + | +note: required by a const generic parameter in `E::<'a, A, C>::foo_static` + --> $DIR/inherent-impls-parent-generics.rs:9:25 + | +LL | impl<'a, 'b, 'c, A: 'a, const C: usize> E<'a, A, C> { + | ^^^^^^^^^^^^^^ required by this const generic parameter in `E::<'a, A, C>::foo_static` +LL | fn foo_static<'d: 'd, 'e, T, const B: bool>() {} + | ---------- required by a bound in this associated function +help: consider specifying the generic arguments + | +LL - reuse E::foo_static as e; +LL + reuse E:: as e; + | + +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:14:10 + | +LL | reuse E::foo_static as e; + | ^^^^^^^^^^ cannot infer the value of the const parameter `B` declared on the associated function `foo_static` + | +note: required by a const generic parameter in `E::<'a, A, C>::foo_static` + --> $DIR/inherent-impls-parent-generics.rs:10:34 + | +LL | fn foo_static<'d: 'd, 'e, T, const B: bool>() {} + | ^^^^^^^^^^^^^ required by this const generic parameter in `E::<'a, A, C>::foo_static` +help: consider specifying the generic arguments + | +LL | reuse E::foo_static:: as e; + | ++++++++ + +error[E0061]: this function takes 1 argument but 0 arguments were supplied + --> $DIR/inherent-impls-parent-generics.rs:19:10 + | +LL | reuse E::foo_self as e1; + | ^^^^^^^^ argument #1 of type `E<'_, _, _>` is missing + | +note: method defined here + --> $DIR/inherent-impls-parent-generics.rs:11:8 + | +LL | fn foo_self<'d: 'd, 'e, T, const B: bool>(self) {} + | ^^^^^^^^ ---- +help: provide the argument + | +LL | reuse E::foo_self(/* value */) as e1; + | +++++++++++++ + +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:23:10 + | +LL | reuse E::foo_static::<'static, (), true> as e2; + | - ^^^^^^^^^^ cannot infer the value of the const parameter `C` declared on the enum `E` + | | + | type must be known at this point + | +note: required by a const generic parameter in `E` + --> $DIR/inherent-impls-parent-generics.rs:4:23 + | +LL | enum E<'a: 'a, A: 'a, const C: usize> { + | ^^^^^^^^^^^^^^ required by this const generic parameter in `E` +help: consider specifying the generic arguments + | +LL - reuse E::foo_static::<'static, (), true> as e2; +LL + reuse E:: as e2; + | + +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:23:10 + | +LL | reuse E::foo_static::<'static, (), true> as e2; + | ^^^^^^^^^^ cannot infer the value of the const parameter `C` declared on the enum `E` + | +note: required by a const generic parameter in `E::<'a, A, C>::foo_static` + --> $DIR/inherent-impls-parent-generics.rs:9:25 + | +LL | impl<'a, 'b, 'c, A: 'a, const C: usize> E<'a, A, C> { + | ^^^^^^^^^^^^^^ required by this const generic parameter in `E::<'a, A, C>::foo_static` +LL | fn foo_static<'d: 'd, 'e, T, const B: bool>() {} + | ---------- required by a bound in this associated function +help: consider specifying the generic arguments + | +LL - reuse E::foo_static::<'static, (), true> as e2; +LL + reuse E:: as e2; | -LL | reuse E::<'static, (), 123>::foo_static as e4; - | ^^^^^^^^^^ not found in `E` -error[E0425]: cannot find function `foo_self` in enum `E` - --> $DIR/inherent-impls-parent-generics.rs:28:30 +error[E0061]: this function takes 1 argument but 0 arguments were supplied + --> $DIR/inherent-impls-parent-generics.rs:27:10 + | +LL | reuse E::foo_self::<'static, (), true> as e3; + | ^^^^^^^^ argument #1 of type `E<'_, _, _>` is missing + | +note: method defined here + --> $DIR/inherent-impls-parent-generics.rs:11:8 + | +LL | fn foo_self<'d: 'd, 'e, T, const B: bool>(self) {} + | ^^^^^^^^ ---- +help: provide the argument | -LL | reuse E::<'static, (), 123>::foo_self as e5; - | ^^^^^^^^ not found in `E` +LL | reuse E::foo_self(/* value */)::<'static, (), true> as e3; + | +++++++++++++ -error[E0425]: cannot find function `foo_static` in enum `E` - --> $DIR/inherent-impls-parent-generics.rs:31:30 +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:37:23 | -LL | reuse E::<'static, (), 123>::foo_static::<'static, (), true> as e6; - | ^^^^^^^^^^ not found in `E` +LL | reuse E::<'_, (), _>::foo_static as e8; + | -------------- ^^^^^^^^^^ cannot infer the value of the const parameter `C` declared on the enum `E` + | | + | type must be known at this point + | +note: required by a const generic parameter in `E` + --> $DIR/inherent-impls-parent-generics.rs:4:23 + | +LL | enum E<'a: 'a, A: 'a, const C: usize> { + | ^^^^^^^^^^^^^^ required by this const generic parameter in `E` -error[E0425]: cannot find function `foo_self` in enum `E` - --> $DIR/inherent-impls-parent-generics.rs:33:30 +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:37:23 + | +LL | reuse E::<'_, (), _>::foo_static as e8; + | ^^^^^^^^^^ cannot infer the value of the const parameter `C` declared on the enum `E` + | +note: required by a const generic parameter in `E::<'a, A, C>::foo_static` + --> $DIR/inherent-impls-parent-generics.rs:9:25 | -LL | reuse E::<'static, (), 123>::foo_self::<'static, (), true> as e7; - | ^^^^^^^^ not found in `E` +LL | impl<'a, 'b, 'c, A: 'a, const C: usize> E<'a, A, C> { + | ^^^^^^^^^^^^^^ required by this const generic parameter in `E::<'a, A, C>::foo_static` +LL | fn foo_static<'d: 'd, 'e, T, const B: bool>() {} + | ---------- required by a bound in this associated function -error[E0425]: cannot find function `foo_static` in enum `E` - --> $DIR/inherent-impls-parent-generics.rs:36:23 +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:37:23 | LL | reuse E::<'_, (), _>::foo_static as e8; - | ^^^^^^^^^^ not found in `E` + | ^^^^^^^^^^ cannot infer the value of the const parameter `B` declared on the associated function `foo_static` + | +note: required by a const generic parameter in `E::<'a, A, C>::foo_static` + --> $DIR/inherent-impls-parent-generics.rs:10:34 + | +LL | fn foo_static<'d: 'd, 'e, T, const B: bool>() {} + | ^^^^^^^^^^^^^ required by this const generic parameter in `E::<'a, A, C>::foo_static` +help: consider specifying the generic arguments + | +LL | reuse E::<'_, (), _>::foo_static:: as e8; + | ++++++++ -error[E0425]: cannot find function `foo_self` in enum `E` - --> $DIR/inherent-impls-parent-generics.rs:39:22 +error[E0061]: this function takes 1 argument but 0 arguments were supplied + --> $DIR/inherent-impls-parent-generics.rs:42:22 | LL | reuse E::<'_, _, _>::foo_self as e9; - | ^^^^^^^^ not found in `E` + | ^^^^^^^^ argument #1 of type `E<'_, _, _>` is missing + | +note: method defined here + --> $DIR/inherent-impls-parent-generics.rs:11:8 + | +LL | fn foo_self<'d: 'd, 'e, T, const B: bool>(self) {} + | ^^^^^^^^ ---- +help: provide the argument + | +LL | reuse E::<'_, _, _>::foo_self(/* value */) as e9; + | +++++++++++++ -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-parent-generics.rs:51:10 +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:55:10 | LL | reuse S::foo_static as s; - | ^^^^^^^^^^ not found in `S` + | - ^^^^^^^^^^ cannot infer the value of the const parameter `C` declared on the struct `S` + | | + | type must be known at this point + | +note: required by a const generic parameter in `S` + --> $DIR/inherent-impls-parent-generics.rs:46:13 + | +LL | struct S { + | ^^^^^^^^^^^^^^ required by this const generic parameter in `S` +help: consider specifying the generic arguments + | +LL | reuse S::::foo_static as s; + | ++++++++ -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-parent-generics.rs:54:10 +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:55:10 | -LL | reuse S::foo_self as s1; - | ^^^^^^^^ not found in `S` +LL | reuse S::foo_static as s; + | ^^^^^^^^^^ cannot infer the value of the const parameter `C` declared on the struct `S` + | +note: required by a const generic parameter in `S::::foo_static` + --> $DIR/inherent-impls-parent-generics.rs:50:21 + | +LL | impl<'a, 'b, 'c, A, const C: usize> S { + | ^^^^^^^^^^^^^^ required by this const generic parameter in `S::::foo_static` +LL | fn foo_static<'d: 'd, 'e, T, const B: bool>() {} + | ---------- required by a bound in this associated function +help: consider specifying the generic arguments + | +LL | reuse S::::foo_static as s; + | ++++++++ -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-parent-generics.rs:57:10 +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:55:10 | -LL | reuse S::foo_static::<'static, (), true> as s2; - | ^^^^^^^^^^ not found in `S` +LL | reuse S::foo_static as s; + | ^^^^^^^^^^ cannot infer the value of the const parameter `B` declared on the associated function `foo_static` + | +note: required by a const generic parameter in `S::::foo_static` + --> $DIR/inherent-impls-parent-generics.rs:51:34 + | +LL | fn foo_static<'d: 'd, 'e, T, const B: bool>() {} + | ^^^^^^^^^^^^^ required by this const generic parameter in `S::::foo_static` +help: consider specifying the generic arguments + | +LL | reuse S::foo_static:: as s; + | ++++++++ -error[E0425]: cannot find function `foo_self` in `S` +error[E0061]: this function takes 1 argument but 0 arguments were supplied --> $DIR/inherent-impls-parent-generics.rs:60:10 | -LL | reuse S::foo_self::<'static, (), true> as s3; - | ^^^^^^^^ not found in `S` +LL | reuse S::foo_self as s1; + | ^^^^^^^^ argument #1 of type `S<_, _>` is missing + | +note: method defined here + --> $DIR/inherent-impls-parent-generics.rs:52:8 + | +LL | fn foo_self<'d: 'd, 'e, T, const B: bool>(self) {} + | ^^^^^^^^ ---- +help: provide the argument + | +LL | reuse S::foo_self(/* value */) as s1; + | +++++++++++++ + +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:64:10 + | +LL | reuse S::foo_static::<'static, (), true> as s2; + | - ^^^^^^^^^^ cannot infer the value of the const parameter `C` declared on the struct `S` + | | + | type must be known at this point + | +note: required by a const generic parameter in `S` + --> $DIR/inherent-impls-parent-generics.rs:46:13 + | +LL | struct S { + | ^^^^^^^^^^^^^^ required by this const generic parameter in `S` +help: consider specifying the generic arguments + | +LL | reuse S::::foo_static::<'static, (), true> as s2; + | ++++++++ -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-parent-generics.rs:63:21 +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:64:10 + | +LL | reuse S::foo_static::<'static, (), true> as s2; + | ^^^^^^^^^^ cannot infer the value of the const parameter `C` declared on the struct `S` + | +note: required by a const generic parameter in `S::::foo_static` + --> $DIR/inherent-impls-parent-generics.rs:50:21 + | +LL | impl<'a, 'b, 'c, A, const C: usize> S { + | ^^^^^^^^^^^^^^ required by this const generic parameter in `S::::foo_static` +LL | fn foo_static<'d: 'd, 'e, T, const B: bool>() {} + | ---------- required by a bound in this associated function +help: consider specifying the generic arguments | -LL | reuse S::<(), 123>::foo_static as s4; - | ^^^^^^^^^^ not found in `S` +LL | reuse S::::foo_static::<'static, (), true> as s2; + | ++++++++ -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-parent-generics.rs:65:21 +error[E0061]: this function takes 1 argument but 0 arguments were supplied + --> $DIR/inherent-impls-parent-generics.rs:68:10 | -LL | reuse S::<(), 123>::foo_self as s5; - | ^^^^^^^^ not found in `S` +LL | reuse S::foo_self::<'static, (), true> as s3; + | ^^^^^^^^ argument #1 of type `S<_, _>` is missing + | +note: method defined here + --> $DIR/inherent-impls-parent-generics.rs:52:8 + | +LL | fn foo_self<'d: 'd, 'e, T, const B: bool>(self) {} + | ^^^^^^^^ ---- +help: provide the argument + | +LL | reuse S::foo_self(/* value */)::<'static, (), true> as s3; + | +++++++++++++ -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-parent-generics.rs:68:21 +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:78:19 | -LL | reuse S::<(), 123>::foo_static::<'static, (), true> as s6; - | ^^^^^^^^^^ not found in `S` +LL | reuse S::<(), _>::foo_static as s8; + | ---------- ^^^^^^^^^^ cannot infer the value of the const parameter `C` declared on the struct `S` + | | + | type must be known at this point + | +note: required by a const generic parameter in `S` + --> $DIR/inherent-impls-parent-generics.rs:46:13 + | +LL | struct S { + | ^^^^^^^^^^^^^^ required by this const generic parameter in `S` -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-parent-generics.rs:70:21 +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:78:19 + | +LL | reuse S::<(), _>::foo_static as s8; + | ^^^^^^^^^^ cannot infer the value of the const parameter `C` declared on the struct `S` + | +note: required by a const generic parameter in `S::::foo_static` + --> $DIR/inherent-impls-parent-generics.rs:50:21 | -LL | reuse S::<(), 123>::foo_self::<'static, (), true> as s7; - | ^^^^^^^^ not found in `S` +LL | impl<'a, 'b, 'c, A, const C: usize> S { + | ^^^^^^^^^^^^^^ required by this const generic parameter in `S::::foo_static` +LL | fn foo_static<'d: 'd, 'e, T, const B: bool>() {} + | ---------- required by a bound in this associated function -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-parent-generics.rs:73:19 +error[E0284]: type annotations needed + --> $DIR/inherent-impls-parent-generics.rs:78:19 | LL | reuse S::<(), _>::foo_static as s8; - | ^^^^^^^^^^ not found in `S` + | ^^^^^^^^^^ cannot infer the value of the const parameter `B` declared on the associated function `foo_static` + | +note: required by a const generic parameter in `S::::foo_static` + --> $DIR/inherent-impls-parent-generics.rs:51:34 + | +LL | fn foo_static<'d: 'd, 'e, T, const B: bool>() {} + | ^^^^^^^^^^^^^ required by this const generic parameter in `S::::foo_static` +help: consider specifying the generic arguments + | +LL | reuse S::<(), _>::foo_static:: as s8; + | ++++++++ -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-parent-generics.rs:76:20 +error[E0061]: this function takes 1 argument but 0 arguments were supplied + --> $DIR/inherent-impls-parent-generics.rs:83:20 | LL | reuse S::<_, 123>::foo_self as s9; - | ^^^^^^^^ not found in `S` + | ^^^^^^^^ argument #1 of type `S<_, 123>` is missing + | +note: method defined here + --> $DIR/inherent-impls-parent-generics.rs:52:8 + | +LL | fn foo_self<'d: 'd, 'e, T, const B: bool>(self) {} + | ^^^^^^^^ ---- +help: provide the argument + | +LL | reuse S::<_, 123>::foo_self(/* value */) as s9; + | +++++++++++++ -error: aborting due to 20 previous errors +error: aborting due to 34 previous errors -For more information about this error, try `rustc --explain E0425`. +Some errors have detailed explanations: E0061, E0284. +For more information about an error, try `rustc --explain E0061`. diff --git a/tests/ui/delegation/inherent-impls-receiver-mapping.rs b/tests/ui/delegation/inherent-impls-receiver-mapping.rs index 05a9c350af746..d4678134e5de1 100644 --- a/tests/ui/delegation/inherent-impls-receiver-mapping.rs +++ b/tests/ui/delegation/inherent-impls-receiver-mapping.rs @@ -15,36 +15,27 @@ mod receiver_mapping { impl Y { fn get_x(&self) -> X { X } reuse X::{static_f, by_value, by_ref, by_mut_ref} { self.get_x() } - //~^ ERROR: cannot find function `by_mut_ref` in `X` - //~| ERROR: cannot find function `by_ref` in `X` - //~| ERROR: cannot find function `by_value` in `X` - //~| ERROR: cannot find function `static_f` in `X` } fn check() { let y = Y; y.by_ref(); - //~^ ERROR: no method named `by_ref` found for struct `Y` in the current scope y.by_mut_ref(); - //~^ ERROR: no method named `by_mut_ref` found for struct `Y` in the current scope + //~^ ERROR: cannot borrow `y` as mutable, as it is not declared as mutable y.by_value(); - //~^ ERROR: no method named `by_value` found for struct `Y` in the current scope let y = &Y; y.by_value(); - //~^ ERROR: no method named `by_value` found for reference `&Y` in the current scope + //~^ ERROR: cannot move out of `*y` which is behind a shared reference y.by_ref(); - //~^ ERROR: no method named `by_ref` found for reference `&Y` in the current scope y.by_mut_ref(); - //~^ ERROR: no method named `by_mut_ref` found for reference `&Y` in the current scope + //~^ ERROR: cannot borrow `*y` as mutable, as it is behind a `&` reference let y = &mut Y; y.by_value(); - //~^ ERROR: no method named `by_value` found for mutable reference `&mut Y` in the current scope + //~^ ERROR: cannot move out of `*y` which is behind a mutable reference y.by_ref(); - //~^ ERROR: the method `by_ref` exists for mutable reference `&mut Y`, but its trait bounds were not satisfied y.by_mut_ref(); - //~^ ERROR: no method named `by_mut_ref` found for mutable reference `&mut Y` in the current scope } } @@ -59,12 +50,12 @@ mod self_type_mapping { struct W(X); impl W { reuse X::add { self.0 } - //~^ ERROR: cannot find function `add` in `X` + //~^ ERROR: mismatched types + //~| ERROR: mismatched types } fn check() { W(X).add(W(X)); - //~^ ERROR: no method named `add` found for struct `W` in the current scope } } diff --git a/tests/ui/delegation/inherent-impls-receiver-mapping.stderr b/tests/ui/delegation/inherent-impls-receiver-mapping.stderr index 92baa5ff53ed0..60982076f4acd 100644 --- a/tests/ui/delegation/inherent-impls-receiver-mapping.stderr +++ b/tests/ui/delegation/inherent-impls-receiver-mapping.stderr @@ -1,256 +1,90 @@ -error[E0425]: cannot find function `static_f` in `X` - --> $DIR/inherent-impls-receiver-mapping.rs:17:19 +error[E0308]: mismatched types + --> $DIR/inherent-impls-receiver-mapping.rs:52:18 | -LL | reuse X::{static_f, by_value, by_ref, by_mut_ref} { self.get_x() } - | ^^^^^^^^ not found in `X` - -error[E0425]: cannot find function `by_value` in `X` - --> $DIR/inherent-impls-receiver-mapping.rs:17:29 - | -LL | reuse X::{static_f, by_value, by_ref, by_mut_ref} { self.get_x() } - | ^^^^^^^^ not found in `X` - -error[E0425]: cannot find function `by_ref` in `X` - --> $DIR/inherent-impls-receiver-mapping.rs:17:39 +LL | reuse X::add { self.0 } + | ^^^ + | | + | expected `X`, found `W` + | arguments to this function are incorrect | -LL | reuse X::{static_f, by_value, by_ref, by_mut_ref} { self.get_x() } - | ^^^^^^ not found in `X` - -error[E0425]: cannot find function `by_mut_ref` in `X` - --> $DIR/inherent-impls-receiver-mapping.rs:17:47 +note: method defined here + --> $DIR/inherent-impls-receiver-mapping.rs:45:12 | -LL | reuse X::{static_f, by_value, by_ref, by_mut_ref} { self.get_x() } - | ^^^^^^^^^^ not found in `X` +LL | fn add(self, other: Self) -> Self { + | ^^^ ----------- -error[E0425]: cannot find function `add` in `X` - --> $DIR/inherent-impls-receiver-mapping.rs:61:18 +error[E0308]: mismatched types + --> $DIR/inherent-impls-receiver-mapping.rs:52:18 | LL | reuse X::add { self.0 } - | ^^^ not found in `X` - -error[E0599]: no method named `by_ref` found for struct `Y` in the current scope - --> $DIR/inherent-impls-receiver-mapping.rs:26:11 - | -LL | struct Y; - | -------- method `by_ref` not found for this struct -... -LL | y.by_ref(); - | ^^^^^^ this is an associated function, not a method - | - = note: found the following associated functions; to be used as methods, functions must have a `self` parameter -note: the candidate is defined in an impl for the type `Y` - --> $DIR/inherent-impls-receiver-mapping.rs:17:39 - | -LL | reuse X::{static_f, by_value, by_ref, by_mut_ref} { self.get_x() } - | ^^^^^^ - = help: items from traits can only be used if the trait is implemented and in scope - = note: the following traits define an item `by_ref`, perhaps you need to implement one of them: - candidate #1: `Iterator` - candidate #2: `std::io::Read` - candidate #3: `std::io::Write` -help: use associated function syntax instead + | ^^^ + | | + | expected `W`, found `X` + | expected `W` because of return type | -LL - y.by_ref(); -LL + Y::by_ref(); +help: try wrapping the expression in `self_type_mapping::W` | +LL | reuse X::self_type_mapping::W(add) { self.0 } + | +++++++++++++++++++++ + -error[E0599]: no method named `by_mut_ref` found for struct `Y` in the current scope - --> $DIR/inherent-impls-receiver-mapping.rs:28:11 +error[E0596]: cannot borrow `y` as mutable, as it is not declared as mutable + --> $DIR/inherent-impls-receiver-mapping.rs:23:9 | -LL | struct Y; - | -------- method `by_mut_ref` not found for this struct -... LL | y.by_mut_ref(); - | ^^^^^^^^^^ this is an associated function, not a method - | - = note: found the following associated functions; to be used as methods, functions must have a `self` parameter -note: the candidate is defined in an impl for the type `Y` - --> $DIR/inherent-impls-receiver-mapping.rs:17:47 + | ^ cannot borrow as mutable | -LL | reuse X::{static_f, by_value, by_ref, by_mut_ref} { self.get_x() } - | ^^^^^^^^^^ -help: use associated function syntax instead - | -LL - y.by_mut_ref(); -LL + Y::by_mut_ref(); +help: consider changing this to be mutable | +LL | let mut y = Y; + | +++ -error[E0599]: no method named `by_value` found for struct `Y` in the current scope - --> $DIR/inherent-impls-receiver-mapping.rs:30:11 +error[E0507]: cannot move out of `*y` which is behind a shared reference + --> $DIR/inherent-impls-receiver-mapping.rs:28:9 | -LL | struct Y; - | -------- method `by_value` not found for this struct -... LL | y.by_value(); - | ^^^^^^^^ this is an associated function, not a method - | - = note: found the following associated functions; to be used as methods, functions must have a `self` parameter -note: the candidate is defined in an impl for the type `Y` - --> $DIR/inherent-impls-receiver-mapping.rs:17:29 + | ^ ---------- `*y` moved due to this method call + | | + | move occurs because `*y` has type `Y`, which does not implement the `Copy` trait | -LL | reuse X::{static_f, by_value, by_ref, by_mut_ref} { self.get_x() } - | ^^^^^^^^ -help: use associated function syntax instead - | -LL - y.by_value(); -LL + Y::by_value(); - | - -error[E0599]: no method named `by_value` found for reference `&Y` in the current scope - --> $DIR/inherent-impls-receiver-mapping.rs:34:11 + = note: `receiver_mapping::Y::by_value` takes ownership of the receiver `self`, which moves `*y` +note: if `Y` implemented `Clone`, you could clone the value + --> $DIR/inherent-impls-receiver-mapping.rs:13:5 | +LL | struct Y; + | ^^^^^^^^ consider implementing `Clone` for this type +... LL | y.by_value(); - | ^^^^^^^^ this is an associated function, not a method - | - = note: found the following associated functions; to be used as methods, functions must have a `self` parameter -note: the candidate is defined in an impl for the type `Y` - --> $DIR/inherent-impls-receiver-mapping.rs:17:29 - | -LL | reuse X::{static_f, by_value, by_ref, by_mut_ref} { self.get_x() } - | ^^^^^^^^ -help: use associated function syntax instead - | -LL - y.by_value(); -LL + Y::by_value(); - | + | - you could clone this value -error[E0599]: no method named `by_ref` found for reference `&Y` in the current scope - --> $DIR/inherent-impls-receiver-mapping.rs:36:11 - | -LL | y.by_ref(); - | ^^^^^^ this is an associated function, not a method - | - = note: found the following associated functions; to be used as methods, functions must have a `self` parameter -note: the candidate is defined in an impl for the type `Y` - --> $DIR/inherent-impls-receiver-mapping.rs:17:39 - | -LL | reuse X::{static_f, by_value, by_ref, by_mut_ref} { self.get_x() } - | ^^^^^^ - = help: items from traits can only be used if the trait is implemented and in scope - = note: the following traits define an item `by_ref`, perhaps you need to implement one of them: - candidate #1: `std::io::Read` - candidate #2: `std::io::Write` - = note: the trait `Iterator` defines an item `by_ref`, but is explicitly unimplemented -help: use associated function syntax instead - | -LL - y.by_ref(); -LL + Y::by_ref(); - | - -error[E0599]: no method named `by_mut_ref` found for reference `&Y` in the current scope - --> $DIR/inherent-impls-receiver-mapping.rs:38:11 +error[E0596]: cannot borrow `*y` as mutable, as it is behind a `&` reference + --> $DIR/inherent-impls-receiver-mapping.rs:31:9 | LL | y.by_mut_ref(); - | ^^^^^^^^^^ this is an associated function, not a method - | - = note: found the following associated functions; to be used as methods, functions must have a `self` parameter -note: the candidate is defined in an impl for the type `Y` - --> $DIR/inherent-impls-receiver-mapping.rs:17:47 + | ^ `y` is a `&` reference, so it cannot be borrowed as mutable | -LL | reuse X::{static_f, by_value, by_ref, by_mut_ref} { self.get_x() } - | ^^^^^^^^^^ -help: use associated function syntax instead - | -LL - y.by_mut_ref(); -LL + Y::by_mut_ref(); +help: consider changing this to be a mutable reference | +LL | let y = &mut Y; + | +++ -error[E0599]: no method named `by_value` found for mutable reference `&mut Y` in the current scope - --> $DIR/inherent-impls-receiver-mapping.rs:42:11 +error[E0507]: cannot move out of `*y` which is behind a mutable reference + --> $DIR/inherent-impls-receiver-mapping.rs:35:9 | LL | y.by_value(); - | ^^^^^^^^ this is an associated function, not a method - | - = note: found the following associated functions; to be used as methods, functions must have a `self` parameter -note: the candidate is defined in an impl for the type `Y` - --> $DIR/inherent-impls-receiver-mapping.rs:17:29 - | -LL | reuse X::{static_f, by_value, by_ref, by_mut_ref} { self.get_x() } - | ^^^^^^^^ -help: use associated function syntax instead - | -LL - y.by_value(); -LL + Y::by_value(); + | ^ ---------- `*y` moved due to this method call + | | + | move occurs because `*y` has type `Y`, which does not implement the `Copy` trait | - -error[E0599]: the method `by_ref` exists for mutable reference `&mut Y`, but its trait bounds were not satisfied - --> $DIR/inherent-impls-receiver-mapping.rs:44:11 +note: if `Y` implemented `Clone`, you could clone the value + --> $DIR/inherent-impls-receiver-mapping.rs:13:5 | LL | struct Y; - | -------- doesn't satisfy `Y: Iterator` + | ^^^^^^^^ consider implementing `Clone` for this type ... -LL | y.by_ref(); - | ^^^^^^ this is an associated function, not a method - | - = note: found the following associated functions; to be used as methods, functions must have a `self` parameter -note: the candidate is defined in an impl for the type `Y` - --> $DIR/inherent-impls-receiver-mapping.rs:17:39 - | -LL | reuse X::{static_f, by_value, by_ref, by_mut_ref} { self.get_x() } - | ^^^^^^ - = note: the following trait bounds were not satisfied: - `Y: Iterator` - which is required by `&mut Y: Iterator` -note: the trait `Iterator` must be implemented - --> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL - = help: items from traits can only be used if the trait is implemented and in scope - = note: the following traits define an item `by_ref`, perhaps you need to implement one of them: - candidate #1: `std::io::Read` - candidate #2: `std::io::Write` - = note: the trait `Iterator` defines an item `by_ref`, but is explicitly unimplemented -help: use associated function syntax instead - | -LL - y.by_ref(); -LL + Y::by_ref(); - | - -error[E0599]: no method named `by_mut_ref` found for mutable reference `&mut Y` in the current scope - --> $DIR/inherent-impls-receiver-mapping.rs:46:11 - | -LL | y.by_mut_ref(); - | ^^^^^^^^^^ this is an associated function, not a method - | - = note: found the following associated functions; to be used as methods, functions must have a `self` parameter -note: the candidate is defined in an impl for the type `Y` - --> $DIR/inherent-impls-receiver-mapping.rs:17:47 - | -LL | reuse X::{static_f, by_value, by_ref, by_mut_ref} { self.get_x() } - | ^^^^^^^^^^ -help: use associated function syntax instead - | -LL - y.by_mut_ref(); -LL + Y::by_mut_ref(); - | - -error[E0599]: no method named `add` found for struct `W` in the current scope - --> $DIR/inherent-impls-receiver-mapping.rs:66:14 - | -LL | struct W(X); - | -------- method `add` not found for this struct -... -LL | W(X).add(W(X)); - | ^^^ this is an associated function, not a method - | - = note: found the following associated functions; to be used as methods, functions must have a `self` parameter -note: the candidate is defined in an impl for the type `W` - --> $DIR/inherent-impls-receiver-mapping.rs:61:18 - | -LL | reuse X::add { self.0 } - | ^^^ - = help: items from traits can only be used if the trait is implemented and in scope - = note: the following trait defines an item `add`, perhaps you need to implement it: - candidate #1: `Add` -help: use associated function syntax instead - | -LL - W(X).add(W(X)); -LL + W::add(W(X)); - | -help: one of the expressions' fields has a method of the same name - | -LL | W(X).0.add(W(X)); - | ++ +LL | y.by_value(); + | - you could clone this value -error: aborting due to 15 previous errors +error: aborting due to 6 previous errors -Some errors have detailed explanations: E0425, E0599. -For more information about an error, try `rustc --explain E0425`. +Some errors have detailed explanations: E0308, E0507, E0596. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/delegation/inherent-impls-recursive-cycle.rs b/tests/ui/delegation/inherent-impls-recursive-cycle.rs index 0860ff39f51ee..81a59b63874fb 100644 --- a/tests/ui/delegation/inherent-impls-recursive-cycle.rs +++ b/tests/ui/delegation/inherent-impls-recursive-cycle.rs @@ -2,6 +2,7 @@ trait Trait1 { reuse trait_foo_reused as foo; + //~^ ERROR: encountered a cycle during delegation signature resolution } impl Trait1 for () {} @@ -9,44 +10,49 @@ impl Trait1 for () {} struct S1(T); impl S1 { reuse Trait1::foo { self.0 } - //~^ ERROR: delegation's target expression is specified for function with no params + //~^ ERROR: encountered a cycle during delegation signature resolution //~| ERROR: this function takes 0 arguments but 1 argument was supplied } struct S2(S1<()>); impl S2 { reuse S1::<()>::foo { self.0 } - //~^ ERROR: cannot find function `foo` in `S1` + //~^ ERROR: encountered a cycle during delegation signature resolution + //~| ERROR: this function takes 0 arguments but 1 argument was supplied } reuse S2::foo; -//~^ ERROR: cannot find function `foo` in `S2` +//~^ ERROR: encountered a cycle during delegation signature resolution struct S3; impl S3 { reuse foo; + //~^ ERROR: encountered a cycle during delegation signature resolution } impl Trait1 for S3 { reuse S2::foo { S2(S1(())) } - //~^ ERROR: delegation's target expression is specified for function with no params - //~| ERROR: cannot find function `foo` in `S2` + //~^ ERROR: encountered a cycle during delegation signature resolution + //~| ERROR: this function takes 0 arguments but 1 argument was supplied } trait Trait2 { reuse ::foo { S3 } - //~^ ERROR: delegation's target expression is specified for function with no params + //~^ ERROR: encountered a cycle during delegation signature resolution //~| ERROR: this function takes 0 arguments but 1 argument was supplied } reuse Trait2::foo as trait_foo; +//~^ ERROR: encountered a cycle during delegation signature resolution +//~| ERROR: type annotations needed struct S4; impl S4 { reuse trait_foo; + //~^ ERROR: encountered a cycle during delegation signature resolution } reuse S4::trait_foo as trait_foo_reused; -//~^ ERROR: cannot find function `trait_foo` in `S4` +//~^ ERROR: encountered a cycle during delegation signature resolution fn main() {} diff --git a/tests/ui/delegation/inherent-impls-recursive-cycle.stderr b/tests/ui/delegation/inherent-impls-recursive-cycle.stderr index a68931f8abce7..9c88b8e7cacc4 100644 --- a/tests/ui/delegation/inherent-impls-recursive-cycle.stderr +++ b/tests/ui/delegation/inherent-impls-recursive-cycle.stderr @@ -1,47 +1,65 @@ -error[E0425]: cannot find function `foo` in `S1` - --> $DIR/inherent-impls-recursive-cycle.rs:18:21 +error: encountered a cycle during delegation signature resolution + --> $DIR/inherent-impls-recursive-cycle.rs:4:11 + | +LL | reuse trait_foo_reused as foo; + | ^^^^^^^^^^^^^^^^ + +error: encountered a cycle during delegation signature resolution + --> $DIR/inherent-impls-recursive-cycle.rs:12:19 + | +LL | reuse Trait1::foo { self.0 } + | ^^^ + +error: encountered a cycle during delegation signature resolution + --> $DIR/inherent-impls-recursive-cycle.rs:19:21 | LL | reuse S1::<()>::foo { self.0 } - | ^^^ not found in `S1` + | ^^^ -error[E0425]: cannot find function `foo` in `S2` - --> $DIR/inherent-impls-recursive-cycle.rs:22:11 +error: encountered a cycle during delegation signature resolution + --> $DIR/inherent-impls-recursive-cycle.rs:24:11 | LL | reuse S2::foo; - | ^^^ not found in `S2` + | ^^^ + +error: encountered a cycle during delegation signature resolution + --> $DIR/inherent-impls-recursive-cycle.rs:29:11 + | +LL | reuse foo; + | ^^^ -error[E0425]: cannot find function `foo` in `S2` - --> $DIR/inherent-impls-recursive-cycle.rs:31:15 +error: encountered a cycle during delegation signature resolution + --> $DIR/inherent-impls-recursive-cycle.rs:34:15 | LL | reuse S2::foo { S2(S1(())) } - | ^^^ not found in `S2` + | ^^^ -error[E0425]: cannot find function `trait_foo` in `S4` - --> $DIR/inherent-impls-recursive-cycle.rs:49:11 +error: encountered a cycle during delegation signature resolution + --> $DIR/inherent-impls-recursive-cycle.rs:40:27 | -LL | reuse S4::trait_foo as trait_foo_reused; - | ^^^^^^^^^ not found in `S4` +LL | reuse ::foo { S3 } + | ^^^ -error: delegation's target expression is specified for function with no params - --> $DIR/inherent-impls-recursive-cycle.rs:11:23 +error: encountered a cycle during delegation signature resolution + --> $DIR/inherent-impls-recursive-cycle.rs:45:15 | -LL | reuse Trait1::foo { self.0 } - | ^^^^^^^^^^ +LL | reuse Trait2::foo as trait_foo; + | ^^^ -error: delegation's target expression is specified for function with no params - --> $DIR/inherent-impls-recursive-cycle.rs:31:19 +error: encountered a cycle during delegation signature resolution + --> $DIR/inherent-impls-recursive-cycle.rs:51:11 | -LL | reuse S2::foo { S2(S1(())) } - | ^^^^^^^^^^^^^^ +LL | reuse trait_foo; + | ^^^^^^^^^ -error: delegation's target expression is specified for function with no params - --> $DIR/inherent-impls-recursive-cycle.rs:37:31 +error: encountered a cycle during delegation signature resolution + --> $DIR/inherent-impls-recursive-cycle.rs:55:11 | -LL | reuse ::foo { S3 } - | ^^^^^^ +LL | reuse S4::trait_foo as trait_foo_reused; + | ^^^^^^^^^ error[E0061]: this function takes 0 arguments but 1 argument was supplied - --> $DIR/inherent-impls-recursive-cycle.rs:11:19 + --> $DIR/inherent-impls-recursive-cycle.rs:12:19 | LL | reuse Trait1::foo { self.0 } | ^^^ ---------- unexpected argument @@ -58,7 +76,41 @@ LL + reuse Trait1::fo{ self.0 } | error[E0061]: this function takes 0 arguments but 1 argument was supplied - --> $DIR/inherent-impls-recursive-cycle.rs:37:27 + --> $DIR/inherent-impls-recursive-cycle.rs:19:21 + | +LL | reuse S1::<()>::foo { self.0 } + | ^^^ ---------- unexpected argument + | +note: associated function defined here + --> $DIR/inherent-impls-recursive-cycle.rs:12:19 + | +LL | reuse Trait1::foo { self.0 } + | ^^^ +help: remove the extra argument + | +LL - reuse S1::<()>::foo { self.0 } +LL + reuse S1::<()>::fo{ self.0 } + | + +error[E0061]: this function takes 0 arguments but 1 argument was supplied + --> $DIR/inherent-impls-recursive-cycle.rs:34:15 + | +LL | reuse S2::foo { S2(S1(())) } + | ^^^ -------------- unexpected argument of type `S2` + | +note: associated function defined here + --> $DIR/inherent-impls-recursive-cycle.rs:19:21 + | +LL | reuse S1::<()>::foo { self.0 } + | ^^^ +help: remove the extra argument + | +LL - reuse S2::foo { S2(S1(())) } +LL + reuse S2::fo{ S2(S1(())) } + | + +error[E0061]: this function takes 0 arguments but 1 argument was supplied + --> $DIR/inherent-impls-recursive-cycle.rs:40:27 | LL | reuse ::foo { S3 } | ^^^ ------ unexpected argument of type `S3` @@ -74,7 +126,15 @@ LL - reuse ::foo { S3 } LL + reuse ::fo{ S3 } | -error: aborting due to 9 previous errors +error[E0283]: type annotations needed + --> $DIR/inherent-impls-recursive-cycle.rs:45:15 + | +LL | reuse Trait2::foo as trait_foo; + | ^^^ cannot infer type + | + = note: the type must implement `Trait2` + +error: aborting due to 15 previous errors -Some errors have detailed explanations: E0061, E0425. +Some errors have detailed explanations: E0061, E0283. For more information about an error, try `rustc --explain E0061`. diff --git a/tests/ui/delegation/inherent-impls-recursive.rs b/tests/ui/delegation/inherent-impls-recursive.rs index c57ef40642346..7d86cf93a4660 100644 --- a/tests/ui/delegation/inherent-impls-recursive.rs +++ b/tests/ui/delegation/inherent-impls-recursive.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![feature(fn_delegation)] mod test_1 { @@ -9,13 +11,11 @@ mod test_1 { struct S2; impl S2 { reuse S1::foo; - //~^ ERROR: cannot find function `foo` in `S1` } struct S3; impl S3 { reuse S2::foo; - //~^ ERROR: cannot find function `foo` in `S2` } } @@ -34,11 +34,9 @@ mod test_2 { struct S2(S1<()>); impl S2 { reuse S1::<()>::foo { self.0 } - //~^ ERROR: cannot find function `foo` in `S1` } reuse S2::foo; - //~^ ERROR: cannot find function `foo` in `S2` struct S3; impl S3 { @@ -47,8 +45,6 @@ mod test_2 { impl Trait1 for S3 { reuse S2::foo { &S2(S1(())) } - //~^ ERROR: method `foo` has a `&self` declaration in the trait, but not in the impl - //~| ERROR: cannot find function `foo` in `S2` } trait Trait2 { @@ -63,7 +59,6 @@ mod test_2 { } reuse S4::trait_foo as trait_foo_reused; - //~^ ERROR: cannot find function `trait_foo` in `S4` } fn main() {} diff --git a/tests/ui/delegation/inherent-impls-recursive.stderr b/tests/ui/delegation/inherent-impls-recursive.stderr deleted file mode 100644 index f80d9d3b84097..0000000000000 --- a/tests/ui/delegation/inherent-impls-recursive.stderr +++ /dev/null @@ -1,61 +0,0 @@ -error[E0425]: cannot find function `foo` in `S1` - --> $DIR/inherent-impls-recursive.rs:11:19 - | -LL | reuse S1::foo; - | ^^^ not found in `S1` - | -note: function `test_2::foo` exists but is inaccessible - --> $DIR/inherent-impls-recursive.rs:40:5 - | -LL | reuse S2::foo; - | ^^^^^^^^^^^^^^ not accessible - -error[E0425]: cannot find function `foo` in `S2` - --> $DIR/inherent-impls-recursive.rs:17:19 - | -LL | reuse S2::foo; - | ^^^ not found in `S2` - | -note: function `test_2::foo` exists but is inaccessible - --> $DIR/inherent-impls-recursive.rs:40:5 - | -LL | reuse S2::foo; - | ^^^^^^^^^^^^^^ not accessible - -error[E0425]: cannot find function `foo` in `S1` - --> $DIR/inherent-impls-recursive.rs:36:25 - | -LL | reuse S1::<()>::foo { self.0 } - | ^^^ not found in `S1` - -error[E0425]: cannot find function `foo` in `S2` - --> $DIR/inherent-impls-recursive.rs:40:15 - | -LL | reuse S2::foo; - | ^^^ not found in `S2` - -error[E0425]: cannot find function `foo` in `S2` - --> $DIR/inherent-impls-recursive.rs:49:19 - | -LL | reuse S2::foo { &S2(S1(())) } - | ^^^ not found in `S2` - -error[E0425]: cannot find function `trait_foo` in `S4` - --> $DIR/inherent-impls-recursive.rs:65:15 - | -LL | reuse S4::trait_foo as trait_foo_reused; - | ^^^^^^^^^ not found in `S4` - -error[E0186]: method `foo` has a `&self` declaration in the trait, but not in the impl - --> $DIR/inherent-impls-recursive.rs:49:19 - | -LL | fn foo(&self) {} - | ------------- `&self` used in trait -... -LL | reuse S2::foo { &S2(S1(())) } - | ^^^ expected `&self` in impl - -error: aborting due to 7 previous errors - -Some errors have detailed explanations: E0186, E0425. -For more information about an error, try `rustc --explain E0186`. diff --git a/tests/ui/delegation/inherent-impls-rename.rs b/tests/ui/delegation/inherent-impls-rename.rs index 7b6e1e4b7cddc..6a0fd672cf8e5 100644 --- a/tests/ui/delegation/inherent-impls-rename.rs +++ b/tests/ui/delegation/inherent-impls-rename.rs @@ -1,3 +1,5 @@ +//@ check-pass + #![feature(fn_delegation)] struct X; @@ -9,6 +11,5 @@ impl X { } reuse X::bar; -//~^ ERROR: cannot find function `bar` in `X` fn main() {} diff --git a/tests/ui/delegation/inherent-impls-rename.stderr b/tests/ui/delegation/inherent-impls-rename.stderr deleted file mode 100644 index e2e8946412e93..0000000000000 --- a/tests/ui/delegation/inherent-impls-rename.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0425]: cannot find function `bar` in `X` - --> $DIR/inherent-impls-rename.rs:11:10 - | -LL | reuse X::bar; - | ^^^ not found in `X` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0425`. diff --git a/tests/ui/delegation/inherent-impls-self-mapping.rs b/tests/ui/delegation/inherent-impls-self-mapping.rs index 36aef3a7bc7d8..9c13c13786fa7 100644 --- a/tests/ui/delegation/inherent-impls-self-mapping.rs +++ b/tests/ui/delegation/inherent-impls-self-mapping.rs @@ -11,10 +11,10 @@ impl X { trait Trait { reuse X::foo; - //~^ ERROR: cannot find function `foo` in `X` + //~^ ERROR: arguments to this function are incorrect + //~| ERROR: mismatched types } reuse X::foo; -//~^ ERROR: cannot find function `foo` in `X` fn main() {} diff --git a/tests/ui/delegation/inherent-impls-self-mapping.stderr b/tests/ui/delegation/inherent-impls-self-mapping.stderr index 9ecf04626d29c..82ea263a8513b 100644 --- a/tests/ui/delegation/inherent-impls-self-mapping.stderr +++ b/tests/ui/delegation/inherent-impls-self-mapping.stderr @@ -1,15 +1,41 @@ -error[E0425]: cannot find function `foo` in `X` +error[E0308]: arguments to this function are incorrect --> $DIR/inherent-impls-self-mapping.rs:13:14 | +LL | trait Trait { + | ----------- + | | + | found this type parameter + | found this type parameter LL | reuse X::foo; - | ^^^ not found in `X` + | ^^^ + | | + | expected `Rc>`, found `Rc>` + | expected `Box>`, found `Box>` + | + = note: expected struct `Rc>` + found struct `Rc>` + = note: expected struct `Box>` + found struct `Box>` +note: method defined here + --> $DIR/inherent-impls-self-mapping.rs:7:8 + | +LL | fn foo(self: Rc>, other: Box>) -> Option> { + | ^^^ ---- -------------------- -error[E0425]: cannot find function `foo` in `X` - --> $DIR/inherent-impls-self-mapping.rs:17:10 +error[E0308]: mismatched types + --> $DIR/inherent-impls-self-mapping.rs:13:14 + | +LL | trait Trait { + | ----------- expected this type parameter +LL | reuse X::foo; + | ^^^ + | | + | expected `Option>`, found `Option>` + | expected `Option>` because of return type | -LL | reuse X::foo; - | ^^^ not found in `X` + = note: expected enum `Option>` + found enum `Option>` error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0425`. +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/delegation/inherent-impls-self-replacement.rs b/tests/ui/delegation/inherent-impls-self-replacement.rs index e6aa7458993fd..65ecccf766719 100644 --- a/tests/ui/delegation/inherent-impls-self-replacement.rs +++ b/tests/ui/delegation/inherent-impls-self-replacement.rs @@ -20,37 +20,36 @@ trait Trait: Sized { fn get_s(self) -> S<(), 123>; reuse S::<(), 123>::by_value { self.get_s() } - //~^ ERROR: cannot find function `by_value` in `S` reuse S::<(), 123>::by_ref { self.get_s() } - //~^ ERROR: cannot find function `by_ref` in `S` + //~^ ERROR: cannot move out of `*self` which is behind a shared reference reuse S::<(), 123>::by_mut_ref { self.get_s() } - //~^ ERROR: cannot find function `by_mut_ref` in `S` + //~^ ERROR: cannot move out of `*self` which is behind a mutable reference reuse S::<(), 123>::by_box { self.get_s() } - //~^ ERROR: cannot find function `by_box` in `S` + //~^ ERROR: mismatched types reuse S::<(), 123>::by_rc { self.get_s() } - //~^ ERROR: cannot find function `by_rc` in `S` + //~^ ERROR: mismatched types reuse S::<(), 123>::by_pin { self.get_s() } - //~^ ERROR: cannot find function `by_pin` in `S` + //~^ ERROR: mismatched types } trait Trait2: Sized { reuse S::<(), 123>::by_value { self.get_s() } - //~^ ERROR: cannot find function `by_value` in `S` + //~^ ERROR: no method named `get_s` found for type parameter `Self` in the current scope reuse S::<(), 123>::by_ref { self.get_s() } - //~^ ERROR: cannot find function `by_ref` in `S` + //~^ ERROR: no method named `get_s` found for reference `&Self` in the current scope reuse S::<(), 123>::by_mut_ref { self.get_s() } - //~^ ERROR: cannot find function `by_mut_ref` in `S` + //~^ ERROR: no method named `get_s` found for mutable reference `&mut Self` in the current scope reuse S::<(), 123>::by_box { self.get_s() } - //~^ ERROR: cannot find function `by_box` in `S` + //~^ ERROR: no method named `get_s` found for struct `Box` in the current scope reuse S::<(), 123>::by_rc { self.get_s() } - //~^ ERROR: cannot find function `by_rc` in `S` + //~^ ERROR: no method named `get_s` found for struct `Rc` in the current scope reuse S::<(), 123>::by_pin { self.get_s() } - //~^ ERROR: cannot find function `by_pin` in `S` + //~^ ERROR: no method named `get_s` found for struct `Pin>` in the current scope } fn main() {} diff --git a/tests/ui/delegation/inherent-impls-self-replacement.stderr b/tests/ui/delegation/inherent-impls-self-replacement.stderr index e293635e4a1ea..e017bee8af540 100644 --- a/tests/ui/delegation/inherent-impls-self-replacement.stderr +++ b/tests/ui/delegation/inherent-impls-self-replacement.stderr @@ -1,75 +1,186 @@ -error[E0425]: cannot find function `by_value` in `S` - --> $DIR/inherent-impls-self-replacement.rs:22:25 +error[E0308]: mismatched types + --> $DIR/inherent-impls-self-replacement.rs:30:34 | -LL | reuse S::<(), 123>::by_value { self.get_s() } - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `by_ref` in `S` - --> $DIR/inherent-impls-self-replacement.rs:25:25 +LL | reuse S::<(), 123>::by_box { self.get_s() } + | ------ ^^^^^^^^^^^^ expected `Box>`, found `S<(), 123>` + | | + | arguments to this function are incorrect | -LL | reuse S::<(), 123>::by_ref { self.get_s() } - | ^^^^^^ not found in `S` - -error[E0425]: cannot find function `by_mut_ref` in `S` - --> $DIR/inherent-impls-self-replacement.rs:28:25 + = note: expected struct `Box>` + found struct `S<_, _>` + = note: for more on the distinction between the stack and the heap, read https://doc.rust-lang.org/book/ch15-01-box.html, https://doc.rust-lang.org/rust-by-example/std/box.html, and https://doc.rust-lang.org/std/boxed/index.html +note: method defined here + --> $DIR/inherent-impls-self-replacement.rs:14:8 | -LL | reuse S::<(), 123>::by_mut_ref { self.get_s() } - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `by_box` in `S` - --> $DIR/inherent-impls-self-replacement.rs:31:25 +LL | fn by_box<'d: 'd, 'e, T, const B: bool>(self: Box) {} + | ^^^^^^ ---- +help: store this in the heap by calling `Box::new` | -LL | reuse S::<(), 123>::by_box { self.get_s() } - | ^^^^^^ not found in `S` +LL | reuse S::<(), 123>::by_box { Box::new(self.get_s()) } + | +++++++++ + -error[E0425]: cannot find function `by_rc` in `S` - --> $DIR/inherent-impls-self-replacement.rs:34:25 +error[E0308]: mismatched types + --> $DIR/inherent-impls-self-replacement.rs:33:33 | LL | reuse S::<(), 123>::by_rc { self.get_s() } - | ^^^^^ not found in `S` + | ----- ^^^^^^^^^^^^ expected `Rc>`, found `S<(), 123>` + | | + | arguments to this function are incorrect + | + = note: expected struct `Rc>` + found struct `S<_, _>` +note: method defined here + --> $DIR/inherent-impls-self-replacement.rs:15:8 + | +LL | fn by_rc<'d: 'd, 'e, T, const B: bool>(self: Rc) {} + | ^^^^^ ---- +help: call `Into::into` on this expression to convert `S<(), 123>` into `Rc>` + | +LL | reuse S::<(), 123>::by_rc { self.get_s().into() } + | +++++++ -error[E0425]: cannot find function `by_pin` in `S` - --> $DIR/inherent-impls-self-replacement.rs:37:25 +error[E0308]: mismatched types + --> $DIR/inherent-impls-self-replacement.rs:36:34 | LL | reuse S::<(), 123>::by_pin { self.get_s() } - | ^^^^^^ not found in `S` + | ------ ^^^^^^^^^^^^ expected `Pin>>`, found `S<(), 123>` + | | + | arguments to this function are incorrect + | + = note: expected struct `Pin>>` + found struct `S<(), 123>` +note: method defined here + --> $DIR/inherent-impls-self-replacement.rs:16:8 + | +LL | fn by_pin<'d: 'd, 'e, T, const B: bool>(self: Pin>) {} + | ^^^^^^ ---- +help: you need to pin and box this expression + | +LL | reuse S::<(), 123>::by_pin { Box::pin(self.get_s()) } + | +++++++++ + -error[E0425]: cannot find function `by_value` in `S` - --> $DIR/inherent-impls-self-replacement.rs:42:25 +error[E0599]: no method named `get_s` found for type parameter `Self` in the current scope + --> $DIR/inherent-impls-self-replacement.rs:41:41 | +LL | trait Trait2: Sized { + | ------------------- method `get_s` not found for this type parameter LL | reuse S::<(), 123>::by_value { self.get_s() } - | ^^^^^^^^ not found in `S` + | ^^^^^ method not found in `Self` + | + = help: items from traits can only be used if the type parameter is bounded by the trait +help: the following trait defines an item `get_s`, perhaps you need to add another supertrait for it: + | +LL | trait Trait2: Sized + Trait { + | +++++++ -error[E0425]: cannot find function `by_ref` in `S` - --> $DIR/inherent-impls-self-replacement.rs:44:25 +error[E0599]: no method named `get_s` found for reference `&Self` in the current scope + --> $DIR/inherent-impls-self-replacement.rs:43:39 | LL | reuse S::<(), 123>::by_ref { self.get_s() } - | ^^^^^^ not found in `S` + | ^^^^^ method not found in `&Self` + | + = help: items from traits can only be used if the type parameter is bounded by the trait +help: the following trait defines an item `get_s`, perhaps you need to add another supertrait for it: + | +LL | trait Trait2: Sized + Trait { + | +++++++ -error[E0425]: cannot find function `by_mut_ref` in `S` - --> $DIR/inherent-impls-self-replacement.rs:46:25 +error[E0599]: no method named `get_s` found for mutable reference `&mut Self` in the current scope + --> $DIR/inherent-impls-self-replacement.rs:45:43 | LL | reuse S::<(), 123>::by_mut_ref { self.get_s() } - | ^^^^^^^^^^ not found in `S` + | ^^^^^ method not found in `&mut Self` + | + = help: items from traits can only be used if the type parameter is bounded by the trait +help: the following trait defines an item `get_s`, perhaps you need to add another supertrait for it: + | +LL | trait Trait2: Sized + Trait { + | +++++++ -error[E0425]: cannot find function `by_box` in `S` - --> $DIR/inherent-impls-self-replacement.rs:48:25 +error[E0599]: no method named `get_s` found for struct `Box` in the current scope + --> $DIR/inherent-impls-self-replacement.rs:47:39 | LL | reuse S::<(), 123>::by_box { self.get_s() } - | ^^^^^^ not found in `S` + | ^^^^^ method not found in `Box` + | + = help: items from traits can only be used if the trait is implemented and in scope +note: `Trait` defines an item `get_s`, perhaps you need to implement it + --> $DIR/inherent-impls-self-replacement.rs:19:1 + | +LL | trait Trait: Sized { + | ^^^^^^^^^^^^^^^^^^ -error[E0425]: cannot find function `by_rc` in `S` - --> $DIR/inherent-impls-self-replacement.rs:50:25 +error[E0599]: no method named `get_s` found for struct `Rc` in the current scope + --> $DIR/inherent-impls-self-replacement.rs:49:38 | LL | reuse S::<(), 123>::by_rc { self.get_s() } - | ^^^^^ not found in `S` + | ^^^^^ method not found in `Rc` + | + = help: items from traits can only be used if the trait is implemented and in scope +note: `Trait` defines an item `get_s`, perhaps you need to implement it + --> $DIR/inherent-impls-self-replacement.rs:19:1 + | +LL | trait Trait: Sized { + | ^^^^^^^^^^^^^^^^^^ -error[E0425]: cannot find function `by_pin` in `S` - --> $DIR/inherent-impls-self-replacement.rs:52:25 +error[E0599]: no method named `get_s` found for struct `Pin>` in the current scope + --> $DIR/inherent-impls-self-replacement.rs:51:39 | LL | reuse S::<(), 123>::by_pin { self.get_s() } - | ^^^^^^ not found in `S` + | ^^^^^ method not found in `Pin>` + | + = help: items from traits can only be used if the trait is implemented and in scope +note: `Trait` defines an item `get_s`, perhaps you need to implement it + --> $DIR/inherent-impls-self-replacement.rs:19:1 + | +LL | trait Trait: Sized { + | ^^^^^^^^^^^^^^^^^^ + +error[E0507]: cannot move out of `*self` which is behind a shared reference + --> $DIR/inherent-impls-self-replacement.rs:24:34 + | +LL | reuse S::<(), 123>::by_ref { self.get_s() } + | ^^^^ ------- `*self` moved due to this method call + | | + | move occurs because `*self` has type `Self`, which does not implement the `Copy` trait + | +note: `Trait::get_s` takes ownership of the receiver `self`, which moves `*self` + --> $DIR/inherent-impls-self-replacement.rs:20:14 + | +LL | fn get_s(self) -> S<(), 123>; + | ^^^^ +help: if `Self` implemented `Clone`, you could clone the value + --> $DIR/inherent-impls-self-replacement.rs:19:1 + | +LL | trait Trait: Sized { + | ^^^^^^^^^^^^^^^^^^ consider constraining this type parameter with `Clone` +... +LL | reuse S::<(), 123>::by_ref { self.get_s() } + | ---- you could clone this value + +error[E0507]: cannot move out of `*self` which is behind a mutable reference + --> $DIR/inherent-impls-self-replacement.rs:27:38 + | +LL | reuse S::<(), 123>::by_mut_ref { self.get_s() } + | ^^^^ ------- `*self` moved due to this method call + | | + | move occurs because `*self` has type `Self`, which does not implement the `Copy` trait + | +note: `Trait::get_s` takes ownership of the receiver `self`, which moves `*self` + --> $DIR/inherent-impls-self-replacement.rs:20:14 + | +LL | fn get_s(self) -> S<(), 123>; + | ^^^^ +help: if `Self` implemented `Clone`, you could clone the value + --> $DIR/inherent-impls-self-replacement.rs:19:1 + | +LL | trait Trait: Sized { + | ^^^^^^^^^^^^^^^^^^ consider constraining this type parameter with `Clone` +... +LL | reuse S::<(), 123>::by_mut_ref { self.get_s() } + | ---- you could clone this value -error: aborting due to 12 previous errors +error: aborting due to 11 previous errors -For more information about this error, try `rustc --explain E0425`. +Some errors have detailed explanations: E0308, E0507, E0599. +For more information about an error, try `rustc --explain E0308`. diff --git a/tests/ui/delegation/inherent-impls-structs.rs b/tests/ui/delegation/inherent-impls-structs.rs index a5950185b6dad..f7a9d362dd9ca 100644 --- a/tests/ui/delegation/inherent-impls-structs.rs +++ b/tests/ui/delegation/inherent-impls-structs.rs @@ -10,77 +10,55 @@ impl<'a, 'b, 'c, A, const C: usize> S { } reuse S::<(), 1>::foo_static::<'static, (), true> as foo_static_1; -//~^ ERROR: cannot find function `foo_static` in `S` reuse S::<(), 1>::foo_static as foo_static_3; -//~^ ERROR: cannot find function `foo_static` in `S` reuse S::::foo_static::<'static, _, _> as foo_static_4; -//~^ ERROR: cannot find function `foo_static` in `S` reuse S::<(), 1>::foo_self::<'static, (), true> as foo_self_1; -//~^ ERROR: cannot find function `foo_self` in `S` reuse S::<(), 1>::foo_self as foo_self_3; -//~^ ERROR: cannot find function `foo_self` in `S` reuse S::::foo_self::<'static, _, _> as foo_self_4; -//~^ ERROR: cannot find function `foo_self` in `S` trait Trait<'a, AA, BB> where Self: Sized { reuse S::<(), 1>::foo_static::<'static, (), true> as foo_static_1; - //~^ ERROR: cannot find function `foo_static` in `S` reuse S::<(), 1>::foo_static as foo_static_3; - //~^ ERROR: cannot find function `foo_static` in `S` reuse S::<(), 1>::foo_static::<'static, _, _> as foo_static_4; - //~^ ERROR: cannot find function `foo_static` in `S` fn get_s(self) -> S<(), 1> { panic!(); } reuse S::<(), 1>::foo_self::<'static, (), true> as foo_self_1 { self.get_s() } - //~^ ERROR: cannot find function `foo_self` in `S` reuse S::<(), 1>::foo_self as foo_self_3 { self.get_s() } - //~^ ERROR: cannot find function `foo_self` in `S` reuse S::<(), 1>::foo_self::<'static, _, _> as foo_self_4; - //~^ ERROR: cannot find function `foo_self` in `S` + //~^ ERROR: mismatched types [E0308] } struct X; impl<'a, A, B> Trait<'a, A, B> for X { reuse S::<(), 1>::foo_static::<'static, (), true> as foo_static_1; - //~^ ERROR: cannot find function `foo_static` in `S` reuse S::<(), 1>::foo_static as foo_static_3; - //~^ ERROR: cannot find function `foo_static` in `S` reuse S::<(), 1>::foo_static::<'static, _, _> as foo_static_4; - //~^ ERROR: cannot find function `foo_static` in `S` + //~^ ERROR: type annotations needed [E0284] reuse S::<(), 1>::foo_self::<'static, (), true> as foo_self_1 { self.get_s() } - //~^ ERROR: cannot find function `foo_self` in `S` - //~| ERROR: delegation's target expression is specified for function with no params reuse S::<(), 1>::foo_self as foo_self_3 { self.get_s() } - //~^ ERROR: cannot find function `foo_self` in `S` - //~| ERROR: delegation's target expression is specified for function with no params reuse S::<(), 1>::foo_self::<'static, _, _> as foo_self_4; - //~^ ERROR: cannot find function `foo_self` in `S` + //~^ ERROR: mismatched types [E0308] } impl X { reuse S::<(), 1>::foo_static::<'static, (), true> as foo_static_1; - //~^ ERROR: cannot find function `foo_static` in `S` reuse S::<(), 1>::foo_static as foo_static_3; - //~^ ERROR: cannot find function `foo_static` in `S` reuse S::<(), 1>::foo_static::<'static, _, _> as foo_static_4; - //~^ ERROR: cannot find function `foo_static` in `S` fn get_s(self) -> S<(), 1> { panic!(); } reuse S::<(), 1>::foo_self::<'static, (), true> as foo_self_1 { self.get_s() } - //~^ ERROR: cannot find function `foo_self` in `S` reuse S::<(), 1>::foo_self as foo_self_3 { self.get_s() } - //~^ ERROR: cannot find function `foo_self` in `S` reuse S::<(), 1>::foo_self::<'static, _, _> as foo_self_4; - //~^ ERROR: cannot find function `foo_self` in `S` + //~^ ERROR: mismatched types [E0308] } fn main() {} diff --git a/tests/ui/delegation/inherent-impls-structs.stderr b/tests/ui/delegation/inherent-impls-structs.stderr index 6a426564a6e3a..29963431b1451 100644 --- a/tests/ui/delegation/inherent-impls-structs.stderr +++ b/tests/ui/delegation/inherent-impls-structs.stderr @@ -1,159 +1,70 @@ -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-structs.rs:12:19 - | -LL | reuse S::<(), 1>::foo_static::<'static, (), true> as foo_static_1; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-structs.rs:14:19 - | -LL | reuse S::<(), 1>::foo_static as foo_static_3; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-structs.rs:16:22 - | -LL | reuse S::::foo_static::<'static, _, _> as foo_static_4; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-structs.rs:19:19 - | -LL | reuse S::<(), 1>::foo_self::<'static, (), true> as foo_self_1; - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-structs.rs:21:19 - | -LL | reuse S::<(), 1>::foo_self as foo_self_3; - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-structs.rs:23:23 - | -LL | reuse S::::foo_self::<'static, _, _> as foo_self_4; - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-structs.rs:27:23 - | -LL | reuse S::<(), 1>::foo_static::<'static, (), true> as foo_static_1; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-structs.rs:29:23 - | -LL | reuse S::<(), 1>::foo_static as foo_static_3; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in `S` +error[E0308]: mismatched types --> $DIR/inherent-impls-structs.rs:31:23 | -LL | reuse S::<(), 1>::foo_static::<'static, _, _> as foo_static_4; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-structs.rs:38:23 - | -LL | reuse S::<(), 1>::foo_self::<'static, (), true> as foo_self_1 { self.get_s() } - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-structs.rs:40:23 - | -LL | reuse S::<(), 1>::foo_self as foo_self_3 { self.get_s() } - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-structs.rs:42:23 - | +LL | trait Trait<'a, AA, BB> where Self: Sized { + | ----------------------- found this type parameter +... LL | reuse S::<(), 1>::foo_self::<'static, _, _> as foo_self_4; - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-structs.rs:49:23 + | ^^^^^^^^ + | | + | expected `S<(), 1>`, found type parameter `Self` + | arguments to this function are incorrect | -LL | reuse S::<(), 1>::foo_static::<'static, (), true> as foo_static_1; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-structs.rs:51:23 + = note: expected struct `S<(), 1>` + found type parameter `Self` +note: method defined here + --> $DIR/inherent-impls-structs.rs:9:8 | -LL | reuse S::<(), 1>::foo_static as foo_static_3; - | ^^^^^^^^^^ not found in `S` +LL | fn foo_self<'d: 'd, 'e, T, const B: bool>(self) {} + | ^^^^^^^^ ---- -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-structs.rs:53:23 +error[E0284]: type annotations needed + --> $DIR/inherent-impls-structs.rs:40:23 | LL | reuse S::<(), 1>::foo_static::<'static, _, _> as foo_static_4; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-structs.rs:56:23 + | ^^^^^^^^^^ cannot infer the value of const parameter `B` declared on the associated function `foo_static` | -LL | reuse S::<(), 1>::foo_self::<'static, (), true> as foo_self_1 { self.get_s() } - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-structs.rs:59:23 +note: required by a const generic parameter in `S::::foo_static` + --> $DIR/inherent-impls-structs.rs:8:34 | -LL | reuse S::<(), 1>::foo_self as foo_self_3 { self.get_s() } - | ^^^^^^^^ not found in `S` +LL | fn foo_static<'d: 'd, 'e, T, const B: bool>() {} + | ^^^^^^^^^^^^^ required by this const generic parameter in `S::::foo_static` -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-structs.rs:62:23 +error[E0308]: mismatched types + --> $DIR/inherent-impls-structs.rs:45:23 | LL | reuse S::<(), 1>::foo_self::<'static, _, _> as foo_self_4; - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-structs.rs:67:23 + | ^^^^^^^^ + | | + | expected `S<(), 1>`, found `X` + | arguments to this function are incorrect | -LL | reuse S::<(), 1>::foo_static::<'static, (), true> as foo_static_1; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-structs.rs:69:23 - | -LL | reuse S::<(), 1>::foo_static as foo_static_3; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_static` in `S` - --> $DIR/inherent-impls-structs.rs:71:23 - | -LL | reuse S::<(), 1>::foo_static::<'static, _, _> as foo_static_4; - | ^^^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-structs.rs:78:23 - | -LL | reuse S::<(), 1>::foo_self::<'static, (), true> as foo_self_1 { self.get_s() } - | ^^^^^^^^ not found in `S` - -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-structs.rs:80:23 + = note: expected struct `S<(), 1>` + found struct `X` +note: method defined here + --> $DIR/inherent-impls-structs.rs:9:8 | -LL | reuse S::<(), 1>::foo_self as foo_self_3 { self.get_s() } - | ^^^^^^^^ not found in `S` +LL | fn foo_self<'d: 'd, 'e, T, const B: bool>(self) {} + | ^^^^^^^^ ---- -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-structs.rs:82:23 +error[E0308]: mismatched types + --> $DIR/inherent-impls-structs.rs:60:23 | LL | reuse S::<(), 1>::foo_self::<'static, _, _> as foo_self_4; - | ^^^^^^^^ not found in `S` - -error: delegation's target expression is specified for function with no params - --> $DIR/inherent-impls-structs.rs:56:67 + | ^^^^^^^^ + | | + | expected `S<(), 1>`, found `X` + | arguments to this function are incorrect | -LL | reuse S::<(), 1>::foo_self::<'static, (), true> as foo_self_1 { self.get_s() } - | ^^^^^^^^^^^^^^^^ - -error: delegation's target expression is specified for function with no params - --> $DIR/inherent-impls-structs.rs:59:46 + = note: expected struct `S<(), 1>` + found struct `X` +note: method defined here + --> $DIR/inherent-impls-structs.rs:9:8 | -LL | reuse S::<(), 1>::foo_self as foo_self_3 { self.get_s() } - | ^^^^^^^^^^^^^^^^ +LL | fn foo_self<'d: 'd, 'e, T, const B: bool>(self) {} + | ^^^^^^^^ ---- -error: aborting due to 26 previous errors +error: aborting due to 4 previous errors -For more information about this error, try `rustc --explain E0425`. +Some errors have detailed explanations: E0284, E0308. +For more information about an error, try `rustc --explain E0284`. diff --git a/tests/ui/delegation/inherent-impls-wrong-header-args-ice.rs b/tests/ui/delegation/inherent-impls-wrong-header-args-ice.rs index 8375df5f26587..90c329ea6a69c 100644 --- a/tests/ui/delegation/inherent-impls-wrong-header-args-ice.rs +++ b/tests/ui/delegation/inherent-impls-wrong-header-args-ice.rs @@ -11,7 +11,9 @@ impl<'a, 'b, 'c, A, const C: usize> S { trait Trait<'a, AA, BB> where Self: Sized { reuse S::<(), ()>::foo_self; - //~^ ERROR: cannot find function `foo_self` in `S` + //~^ ERROR: inferred lifetimes are not allowed in delegations as we need to inherit signature + //~| ERROR: type provided when a constant was expected + //~| ERROR: type provided when a constant was expected } fn main() {} diff --git a/tests/ui/delegation/inherent-impls-wrong-header-args-ice.stderr b/tests/ui/delegation/inherent-impls-wrong-header-args-ice.stderr index bfa377dcc2db6..bda4c7ceab9e8 100644 --- a/tests/ui/delegation/inherent-impls-wrong-header-args-ice.stderr +++ b/tests/ui/delegation/inherent-impls-wrong-header-args-ice.stderr @@ -9,13 +9,27 @@ help: indicate the anonymous lifetime LL | impl<'a, 'b, 'c, A, const C: usize> S<'_, A, C> { | +++ -error[E0425]: cannot find function `foo_self` in `S` - --> $DIR/inherent-impls-wrong-header-args-ice.rs:13:24 +error: inferred lifetimes are not allowed in delegations as we need to inherit signature + --> $DIR/inherent-impls-wrong-header-args-ice.rs:13:15 | LL | reuse S::<(), ()>::foo_self; - | ^^^^^^^^ not found in `S` + | ^ -error: aborting due to 2 previous errors +error[E0747]: type provided when a constant was expected + --> $DIR/inherent-impls-wrong-header-args-ice.rs:13:19 + | +LL | reuse S::<(), ()>::foo_self; + | ^^ + +error[E0747]: type provided when a constant was expected + --> $DIR/inherent-impls-wrong-header-args-ice.rs:13:19 + | +LL | reuse S::<(), ()>::foo_self; + | ^^ + | + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` + +error: aborting due to 4 previous errors -Some errors have detailed explanations: E0425, E0726. -For more information about an error, try `rustc --explain E0425`. +Some errors have detailed explanations: E0726, E0747. +For more information about an error, try `rustc --explain E0726`. diff --git a/tests/ui/parallel-rustc/default-trait-shadow-cycle-issue-151358.stderr b/tests/ui/parallel-rustc/default-trait-shadow-cycle-issue-151358.stderr index 594f6cc66690e..da16e49a777eb 100644 --- a/tests/ui/parallel-rustc/default-trait-shadow-cycle-issue-151358.stderr +++ b/tests/ui/parallel-rustc/default-trait-shadow-cycle-issue-151358.stderr @@ -2,6 +2,7 @@ error: internal compiler error: query cycle when printing cycle detected | = note: ...when getting owner for `Default` = note: ...which requires lowering HIR for `Default`... + = note: ...which requires resolving type relative delegations... = note: ...which requires getting the AST for lowering... = note: ...which requires perform lints prior to AST lowering... = note: ...which requires looking up span for `Default`... @@ -13,6 +14,7 @@ error[E0391]: cycle detected when getting the resolver for lowering | = note: ...which requires getting owner for `Default`... = note: ...which requires lowering HIR for `Default`... + = note: ...which requires resolving type relative delegations... = note: ...which requires getting the AST for lowering... = note: ...which requires perform lints prior to AST lowering... = note: ...which again requires getting the resolver for lowering, completing the cycle diff --git a/tests/ui/query-system/query-cycle-printing-issue-151358.stderr b/tests/ui/query-system/query-cycle-printing-issue-151358.stderr index 594f6cc66690e..da16e49a777eb 100644 --- a/tests/ui/query-system/query-cycle-printing-issue-151358.stderr +++ b/tests/ui/query-system/query-cycle-printing-issue-151358.stderr @@ -2,6 +2,7 @@ error: internal compiler error: query cycle when printing cycle detected | = note: ...when getting owner for `Default` = note: ...which requires lowering HIR for `Default`... + = note: ...which requires resolving type relative delegations... = note: ...which requires getting the AST for lowering... = note: ...which requires perform lints prior to AST lowering... = note: ...which requires looking up span for `Default`... @@ -13,6 +14,7 @@ error[E0391]: cycle detected when getting the resolver for lowering | = note: ...which requires getting owner for `Default`... = note: ...which requires lowering HIR for `Default`... + = note: ...which requires resolving type relative delegations... = note: ...which requires getting the AST for lowering... = note: ...which requires perform lints prior to AST lowering... = note: ...which again requires getting the resolver for lowering, completing the cycle diff --git a/tests/ui/resolve/query-cycle-issue-124901.stderr b/tests/ui/resolve/query-cycle-issue-124901.stderr index 594f6cc66690e..da16e49a777eb 100644 --- a/tests/ui/resolve/query-cycle-issue-124901.stderr +++ b/tests/ui/resolve/query-cycle-issue-124901.stderr @@ -2,6 +2,7 @@ error: internal compiler error: query cycle when printing cycle detected | = note: ...when getting owner for `Default` = note: ...which requires lowering HIR for `Default`... + = note: ...which requires resolving type relative delegations... = note: ...which requires getting the AST for lowering... = note: ...which requires perform lints prior to AST lowering... = note: ...which requires looking up span for `Default`... @@ -13,6 +14,7 @@ error[E0391]: cycle detected when getting the resolver for lowering | = note: ...which requires getting owner for `Default`... = note: ...which requires lowering HIR for `Default`... + = note: ...which requires resolving type relative delegations... = note: ...which requires getting the AST for lowering... = note: ...which requires perform lints prior to AST lowering... = note: ...which again requires getting the resolver for lowering, completing the cycle From 8463342e91b9b0b19e97ebbf34e248564f333f28 Mon Sep 17 00:00:00 2001 From: Shun Sakai Date: Tue, 8 Sep 2026 17:18:39 +0900 Subject: [PATCH 10/11] docs(time): replace "method" with "function" --- library/core/src/time.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/core/src/time.rs b/library/core/src/time.rs index f9e2dc6b7f849..c123c66ee3bc0 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -345,7 +345,7 @@ impl Duration { /// Creates a new `Duration` from the specified number of weeks. /// - /// For this method, one week is defined as 7 days, or 604,800 seconds. + /// For this function, one week is defined as 7 days, or 604,800 seconds. /// /// # Panics /// @@ -375,7 +375,7 @@ impl Duration { /// Creates a new `Duration` from the specified number of days. /// - /// For this method, one day is defined as 24 hours, or 86,400 seconds. + /// For this function, one day is defined as 24 hours, or 86,400 seconds. /// /// # Panics /// @@ -405,7 +405,7 @@ impl Duration { /// Creates a new `Duration` from the specified number of hours. /// - /// For this method, one hour is defined as 60 minutes, or 3,600 seconds. + /// For this function, one hour is defined as 60 minutes, or 3,600 seconds. /// /// # Panics /// @@ -435,7 +435,7 @@ impl Duration { /// Creates a new `Duration` from the specified number of minutes. /// - /// For this method, one minute is defined as 60 seconds. + /// For this function, one minute is defined as 60 seconds. /// /// # Panics /// From 9bf6ad895ea4fea16d29722961974478c65d47f3 Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Tue, 8 Sep 2026 12:04:57 +0200 Subject: [PATCH 11/11] Fix duplicate thanks entry --- .mailmap | 1 + 1 file changed, 1 insertion(+) diff --git a/.mailmap b/.mailmap index 2f7254ac7131c..037994875398a 100644 --- a/.mailmap +++ b/.mailmap @@ -351,6 +351,7 @@ John Van Enk Jon Gjengset Jonas Tepe Jonathan Bailey +Jonathan Brouwer Jonathan Chan Kwan Yin Jonathan L Jonathan S Jonathan S