From c37eee38584ac6bfd83f19a29c640fea96e02c3f Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 3 Oct 2024 17:16:03 -0400 Subject: [PATCH] Suppress redundant/wrong error when RTN bound fails to resolve --- .../src/hir_ty_lowering/bounds.rs | 9 +++++++++ .../return-type-notation/not-a-method.rs | 2 -- .../return-type-notation/not-a-method.stderr | 20 ++++--------------- tests/ui/error-codes/E0801.rs | 1 - tests/ui/error-codes/E0801.stderr | 8 +------- 5 files changed, 14 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs index 45cd46e3df296..6b2d5f63370df 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs @@ -558,6 +558,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { Err(guar) => Ty::new_error(tcx, guar), } } + hir::QPath::Resolved( + _, + hir::Path { res: Res::Err, segments: [.., item_segment], .. }, + ) if item_segment.args.is_some_and(|args| { + matches!(args.parenthesized, hir::GenericArgsParentheses::ReturnTypeNotation) + }) => + { + Ty::new_error_with_message(tcx, hir_ty.span, "bad resolution for RTN") + } _ => self.lower_ty(hir_ty), } } diff --git a/tests/ui/associated-type-bounds/return-type-notation/not-a-method.rs b/tests/ui/associated-type-bounds/return-type-notation/not-a-method.rs index 2f3fe115e1093..d0aa2e872ce1a 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/not-a-method.rs +++ b/tests/ui/associated-type-bounds/return-type-notation/not-a-method.rs @@ -6,7 +6,6 @@ fn not_a_method() where function(..): Send, //~^ ERROR expected associated function, found function `function` - //~| ERROR return type notation not allowed in this position yet { } @@ -26,7 +25,6 @@ fn maybe_method_overlaps() where method(..): Send, //~^ ERROR cannot find associated function `method` in this scope - //~| ERROR return type notation not allowed in this position yet { } diff --git a/tests/ui/associated-type-bounds/return-type-notation/not-a-method.stderr b/tests/ui/associated-type-bounds/return-type-notation/not-a-method.stderr index dfddd73912ab6..7840d706a31e2 100644 --- a/tests/ui/associated-type-bounds/return-type-notation/not-a-method.stderr +++ b/tests/ui/associated-type-bounds/return-type-notation/not-a-method.stderr @@ -5,36 +5,24 @@ LL | function(..): Send, | ^^^^^^^^^^^^ not a associated function error[E0573]: expected type, found function `function` - --> $DIR/not-a-method.rs:15:5 + --> $DIR/not-a-method.rs:14:5 | LL | function(): Send, | ^^^^^^^^^^ not a type error[E0802]: cannot find associated function `method` in this scope - --> $DIR/not-a-method.rs:27:5 + --> $DIR/not-a-method.rs:26:5 | LL | method(..): Send, | ^^^^^^ not found in this scope error[E0412]: cannot find type `method` in this scope - --> $DIR/not-a-method.rs:36:5 + --> $DIR/not-a-method.rs:34:5 | LL | method(): Send, | ^^^^^^ not found in this scope -error: return type notation not allowed in this position yet - --> $DIR/not-a-method.rs:7:5 - | -LL | function(..): Send, - | ^^^^^^^^^^^^ - -error: return type notation not allowed in this position yet - --> $DIR/not-a-method.rs:27:5 - | -LL | method(..): Send, - | ^^^^^^^^^^ - -error: aborting due to 6 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0412, E0573, E0801, E0802. For more information about an error, try `rustc --explain E0412`. diff --git a/tests/ui/error-codes/E0801.rs b/tests/ui/error-codes/E0801.rs index 6cba6c0027313..eab1064c6bf5d 100644 --- a/tests/ui/error-codes/E0801.rs +++ b/tests/ui/error-codes/E0801.rs @@ -4,7 +4,6 @@ fn test() where test(..): Send, //~^ ERROR expected associated function, found function `test` - //~| ERROR return type notation not allowed in this position yet { } diff --git a/tests/ui/error-codes/E0801.stderr b/tests/ui/error-codes/E0801.stderr index 7a5b7ecd488d9..de5a6766b5917 100644 --- a/tests/ui/error-codes/E0801.stderr +++ b/tests/ui/error-codes/E0801.stderr @@ -4,12 +4,6 @@ error[E0801]: expected associated function, found function `test` LL | test(..): Send, | ^^^^^^^^ not a associated function -error: return type notation not allowed in this position yet - --> $DIR/E0801.rs:5:5 - | -LL | test(..): Send, - | ^^^^^^^^ - -error: aborting due to 2 previous errors +error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0801`.