Skip to content

Split out RTN resolver errors into new error codes #131218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 9 additions & 0 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
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,8 +5,7 @@ fn function() {}
fn not_a_method()
where
function(..): Send,
//~^ ERROR expected function, found function `function`
//~| ERROR return type notation not allowed in this position yet
//~^ ERROR expected associated function, found function `function`
{
}

Expand All @@ -25,8 +24,7 @@ trait Tr {
fn maybe_method_overlaps<T: Tr>()
where
method(..): Send,
//~^ ERROR cannot find function `method` in this scope
//~| ERROR return type notation not allowed in this position yet
//~^ ERROR cannot find associated function `method` in this scope
{
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,28 @@
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
--> $DIR/not-a-method.rs:14:5
|
LL | function(): Send,
| ^^^^^^^^^^ not a type

error[E0576]: cannot find function `method` in this scope
--> $DIR/not-a-method.rs:27:5
error[E0802]: cannot find associated function `method` in this scope
--> $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, E0575, E0576.
Some errors have detailed explanations: E0412, E0573, E0801, E0802.
For more information about an error, try `rustc --explain E0412`.
10 changes: 10 additions & 0 deletions tests/ui/error-codes/E0801.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![feature(return_type_notation)]

fn test()
where
test(..): Send,
//~^ ERROR expected associated function, found function `test`
{
}

fn main() {}
9 changes: 9 additions & 0 deletions tests/ui/error-codes/E0801.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0801]: expected associated function, found function `test`
--> $DIR/E0801.rs:5:5
|
LL | test(..): Send,
| ^^^^^^^^ not a associated function

error: aborting due to 1 previous error

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`.
Loading