diff --git a/compiler/rustc_error_codes/src/error_codes/E0801.md b/compiler/rustc_error_codes/src/error_codes/E0801.md new file mode 100644 index 0000000000000..46e74ba0a4d7f --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0801.md @@ -0,0 +1,19 @@ +Something other than an associated function has been used when one was +expected. + +Erroneous code example: + +```compile_fail,E0801 +#![feature(return_type_notation)] + +const FOO: i32 = 0; + +fn test() +where + FOO(..): Send, +{ +} +``` + +In the given example, within the where clause `FOO(..): Send`, `FOO` resolves +to a const when only trait methods are supported with return-type notation. diff --git a/compiler/rustc_error_codes/src/error_codes/E0802.md b/compiler/rustc_error_codes/src/error_codes/E0802.md new file mode 100644 index 0000000000000..c3f96049c805c --- /dev/null +++ b/compiler/rustc_error_codes/src/error_codes/E0802.md @@ -0,0 +1,19 @@ +An associated function of the given name is not in scope. + +Erroneous code examples: + +```compile_fail,E0802 +#![feature(return_type_notation)] + +trait Trait {} + +fn test() +where + ::method(..): Send, +{ +} +``` + +To fix this error, please verify you didn't misspell the associate function +name, or double-check if you forgot to declare the parameter in the list of +generics. diff --git a/compiler/rustc_error_codes/src/lib.rs b/compiler/rustc_error_codes/src/lib.rs index 27a34d6003dbe..0e4cb99b8aa0d 100644 --- a/compiler/rustc_error_codes/src/lib.rs +++ b/compiler/rustc_error_codes/src/lib.rs @@ -540,6 +540,8 @@ E0797: 0797, E0798: 0798, E0799: 0799, E0800: 0800, +E0801: 0801, +E0802: 0802, ); ) } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 66c1ff93ce1ce..cee16dbf482a7 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -475,7 +475,8 @@ impl<'a> PathSource<'a> { }, _ => "value", }, - PathSource::ReturnTypeNotation | PathSource::Delegation => "function", + PathSource::Delegation => "function", + PathSource::ReturnTypeNotation => "associated function", PathSource::PreciseCapturingArg(..) => "type or const parameter", } } @@ -573,10 +574,12 @@ impl<'a> PathSource<'a> { (PathSource::Expr(..), false) | (PathSource::Delegation, false) => E0425, (PathSource::Pat | PathSource::TupleStruct(..), true) => E0532, (PathSource::Pat | PathSource::TupleStruct(..), false) => E0531, - (PathSource::TraitItem(..), true) | (PathSource::ReturnTypeNotation, true) => E0575, - (PathSource::TraitItem(..), false) | (PathSource::ReturnTypeNotation, false) => E0576, + (PathSource::TraitItem(..), true) => E0575, + (PathSource::TraitItem(..), false) => E0576, (PathSource::PreciseCapturingArg(..), true) => E0799, (PathSource::PreciseCapturingArg(..), false) => E0800, + (PathSource::ReturnTypeNotation, true) => E0801, + (PathSource::ReturnTypeNotation, false) => E0802, } } } 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 89a414a3bc863..2f3fe115e1093 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 @@ -5,7 +5,7 @@ fn function() {} fn not_a_method() where function(..): Send, - //~^ ERROR expected function, found function `function` + //~^ ERROR expected associated function, found function `function` //~| ERROR return type notation not allowed in this position yet { } @@ -25,7 +25,7 @@ trait Tr { fn maybe_method_overlaps() where method(..): Send, - //~^ ERROR cannot find function `method` in this scope + //~^ 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 ab987ee48e6c8..dfddd73912ab6 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 @@ -1,8 +1,8 @@ -error[E0575]: expected function, found function `function` +error[E0801]: expected associated function, found function `function` --> $DIR/not-a-method.rs:7:5 | LL | function(..): Send, - | ^^^^^^^^^^^^ not a function + | ^^^^^^^^^^^^ not a associated function error[E0573]: expected type, found function `function` --> $DIR/not-a-method.rs:15:5 @@ -10,7 +10,7 @@ error[E0573]: expected type, found function `function` LL | function(): Send, | ^^^^^^^^^^ not a type -error[E0576]: cannot find function `method` in this scope +error[E0802]: cannot find associated function `method` in this scope --> $DIR/not-a-method.rs:27:5 | LL | method(..): Send, @@ -36,5 +36,5 @@ LL | method(..): Send, error: aborting due to 6 previous errors -Some errors have detailed explanations: E0412, E0573, E0575, E0576. +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 new file mode 100644 index 0000000000000..6cba6c0027313 --- /dev/null +++ b/tests/ui/error-codes/E0801.rs @@ -0,0 +1,11 @@ +#![feature(return_type_notation)] + +fn test() +where + test(..): Send, + //~^ ERROR expected associated function, found function `test` + //~| ERROR return type notation not allowed in this position yet +{ +} + +fn main() {} diff --git a/tests/ui/error-codes/E0801.stderr b/tests/ui/error-codes/E0801.stderr new file mode 100644 index 0000000000000..7a5b7ecd488d9 --- /dev/null +++ b/tests/ui/error-codes/E0801.stderr @@ -0,0 +1,15 @@ +error[E0801]: expected associated function, found function `test` + --> $DIR/E0801.rs:5:5 + | +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 + +For more information about this error, try `rustc --explain E0801`. diff --git a/tests/ui/error-codes/E0802.rs b/tests/ui/error-codes/E0802.rs new file mode 100644 index 0000000000000..8c4a46192ef1d --- /dev/null +++ b/tests/ui/error-codes/E0802.rs @@ -0,0 +1,12 @@ +#![feature(return_type_notation)] + +trait Trait {} + +fn test() +where + ::method(..): Send, + //~^ ERROR associated function `method` not found for `T` +{ +} + +fn main() {} diff --git a/tests/ui/error-codes/E0802.stderr b/tests/ui/error-codes/E0802.stderr new file mode 100644 index 0000000000000..54b4b9ef449b3 --- /dev/null +++ b/tests/ui/error-codes/E0802.stderr @@ -0,0 +1,9 @@ +error[E0220]: associated function `method` not found for `T` + --> $DIR/E0802.rs:7:8 + | +LL | T::method(..): Send, + | ^^^^^^ associated function `method` not found + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0220`.