Skip to content

Commit

Permalink
Split out RTN resolver errors into new error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Oct 4, 2024
1 parent e1e3cac commit 7c9c9fb
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 9 deletions.
19 changes: 19 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0801.md
Original file line number Diff line number Diff line change
@@ -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.
19 changes: 19 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0802.md
Original file line number Diff line number Diff line change
@@ -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<T: Trait>()
where
<T as Trait>::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.
2 changes: 2 additions & 0 deletions compiler/rustc_error_codes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,8 @@ E0797: 0797,
E0798: 0798,
E0799: 0799,
E0800: 0800,
E0801: 0801,
E0802: 0802,
);
)
}
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}
Expand Down Expand Up @@ -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,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
Expand All @@ -25,7 +25,7 @@ trait Tr {
fn maybe_method_overlaps<T: Tr>()
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
{
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
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
|
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,
Expand All @@ -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`.
11 changes: 11 additions & 0 deletions tests/ui/error-codes/E0801.rs
Original file line number Diff line number Diff line change
@@ -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() {}
15 changes: 15 additions & 0 deletions tests/ui/error-codes/E0801.stderr
Original file line number Diff line number Diff line change
@@ -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`.
12 changes: 12 additions & 0 deletions tests/ui/error-codes/E0802.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![feature(return_type_notation)]

trait Trait {}

fn test<T: Trait>()
where
<T as Trait>::method(..): Send,
//~^ ERROR associated function `method` not found for `T`
{
}

fn main() {}
9 changes: 9 additions & 0 deletions tests/ui/error-codes/E0802.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 7c9c9fb

Please sign in to comment.