From: Muhammad Mahad Date: Thu, 6 Jul 2023 12:37:46 +0000 (+0500) Subject: gccrs: [E0425] Use of unresolved name X-Git-Tag: basepoints/gcc-15~2398 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f34d65dde655310a7a24bb290052d5180d49ce6d;p=thirdparty%2Fgcc.git gccrs: [E0425] Use of unresolved name Refactored error message similiar to rustc. gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): called error function and changed error message similiar to rustc. gcc/testsuite/ChangeLog: * rust/compile/break-rust2.rs: Updated comment to pass testcase. * rust/compile/const_generics_3.rs: likewise. * rust/compile/const_generics_4.rs: likewise. * rust/compile/not_find_value_in_scope.rs: New test. Signed-off-by: Muhammad Mahad --- diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc b/gcc/rust/resolve/rust-ast-resolve-expr.cc index a67fa307ed7e..de93843e32f1 100644 --- a/gcc/rust/resolve/rust-ast-resolve-expr.cc +++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc @@ -173,7 +173,8 @@ ResolveExpr::visit (AST::IdentifierExpr &expr) } else { - rust_error_at (expr.get_locus (), "failed to find name: %s", + rust_error_at (expr.get_locus (), ErrorCode ("E0425"), + "cannot find value %qs in this scope", expr.as_string ().c_str ()); } } diff --git a/gcc/testsuite/rust/compile/break-rust2.rs b/gcc/testsuite/rust/compile/break-rust2.rs index d02589e6bccd..8a6218a4bd1a 100644 --- a/gcc/testsuite/rust/compile/break-rust2.rs +++ b/gcc/testsuite/rust/compile/break-rust2.rs @@ -1,4 +1,4 @@ fn main() { break (rust); - // { dg-error "failed to find name: rust" "" { target *-*-* } .-1 } + // { dg-error "cannot find value .rust. in this scope" "" { target *-*-* } .-1 } } diff --git a/gcc/testsuite/rust/compile/const_generics_3.rs b/gcc/testsuite/rust/compile/const_generics_3.rs index 6a3a0fe27bf3..e4e9008c4a69 100644 --- a/gcc/testsuite/rust/compile/const_generics_3.rs +++ b/gcc/testsuite/rust/compile/const_generics_3.rs @@ -4,7 +4,7 @@ const M: usize = 4; struct Foo { // FIXME: This error is bogus. But having it means parsing is valid! - value: [i32; N], // { dg-error "failed to find name: N" } + value: [i32; N], // { dg-error "cannot find value .N. in this scope" } } fn main() { diff --git a/gcc/testsuite/rust/compile/const_generics_4.rs b/gcc/testsuite/rust/compile/const_generics_4.rs index 8a3754da433f..b364d3bb738a 100644 --- a/gcc/testsuite/rust/compile/const_generics_4.rs +++ b/gcc/testsuite/rust/compile/const_generics_4.rs @@ -2,6 +2,6 @@ const P: usize = 14; -struct Foo; // { dg-error "failed to find name: M" } +struct Foo; // { dg-error "cannot find value .M. in this scope" } struct Bar; struct Baz; // { dg-error "failed to resolve TypePath: NotAType in this scope" } diff --git a/gcc/testsuite/rust/compile/not_find_value_in_scope.rs b/gcc/testsuite/rust/compile/not_find_value_in_scope.rs new file mode 100644 index 000000000000..f9f7eae66f17 --- /dev/null +++ b/gcc/testsuite/rust/compile/not_find_value_in_scope.rs @@ -0,0 +1,7 @@ +// https://doc.rust-lang.org/error_codes/E0425.html +fn main() { + let f = x * x * 3; // { dg-error "cannot find value .x. in this scope" } + let a = f(); // invalid, too few parameters + let b = f(4); // this works! + let c = f(2, 3); // invalid, too many parameters +}