From 8bbaeee6f982dfbfa72ad226ed3c19e29e65257b Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 16 Apr 2024 15:56:48 -0400 Subject: Don't proceed into parent bodies when collecting stmts for possible return suggestion --- .../dont-collect-stmts-from-parent-body.rs | 15 ++++++++++++++ .../dont-collect-stmts-from-parent-body.stderr | 24 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/ui/inference/dont-collect-stmts-from-parent-body.rs create mode 100644 tests/ui/inference/dont-collect-stmts-from-parent-body.stderr (limited to 'tests/ui/inference') diff --git a/tests/ui/inference/dont-collect-stmts-from-parent-body.rs b/tests/ui/inference/dont-collect-stmts-from-parent-body.rs new file mode 100644 index 00000000000..635fe74b867 --- /dev/null +++ b/tests/ui/inference/dont-collect-stmts-from-parent-body.rs @@ -0,0 +1,15 @@ +// issue: rust-lang/rust#124022 + +struct Type; +//~^ ERROR type parameter `T` is never used + +fn main() { + { + impl Type { + fn new() -> Type { + Type + //~^ ERROR type annotations needed + } + } + }; +} diff --git a/tests/ui/inference/dont-collect-stmts-from-parent-body.stderr b/tests/ui/inference/dont-collect-stmts-from-parent-body.stderr new file mode 100644 index 00000000000..f82527273fb --- /dev/null +++ b/tests/ui/inference/dont-collect-stmts-from-parent-body.stderr @@ -0,0 +1,24 @@ +error[E0392]: type parameter `T` is never used + --> $DIR/dont-collect-stmts-from-parent-body.rs:3:13 + | +LL | struct Type; + | ^ unused type parameter + | + = help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` + = help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead + +error[E0282]: type annotations needed + --> $DIR/dont-collect-stmts-from-parent-body.rs:10:17 + | +LL | Type + | ^^^^ cannot infer type of the type parameter `T` declared on the struct `Type` + | +help: consider specifying the generic argument + | +LL | Type:: + | +++++ + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0282, E0392. +For more information about an error, try `rustc --explain E0282`. -- cgit 1.4.1-3-g733a5