rust icon indicating copy to clipboard operation
rust copied to clipboard

Use ordinal number in argument error

Open long-long-float opened this issue 9 months ago • 1 comments

Add an ordinal number to two argument errors ("unexpected" and "missing") for ease of understanding error.

error[E0061]: this function takes 3 arguments but 2 arguments were supplied
  --> test.rs:11:5
   |
11 |     f(42, 'a');
   |     ^     --- 2nd argument of type `f32` is missing
   |
(snip)

error[E0061]: this function takes 3 arguments but 4 arguments were supplied
  --> test.rs:12:5
   |
12 |     f(42, 42, 1.0, 'a');
   |     ^   ----
   |         | |
   |         | unexpected 2nd argument of type `{integer}`
   |         help: remove the extra argument

To get an ordinal number, I copied ordinalize from other crate rustc_resolve because I think it is too much to link rustc_resolve for this small function. Please let me know if there is a better way.

long-long-float avatar May 12 '24 08:05 long-long-float

r? @wesleywiser

rustbot has assigned @wesleywiser. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

rustbot avatar May 12 '24 08:05 rustbot

The job x86_64-gnu-llvm-17 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#17 exporting to docker image format
#17 sending tarball 29.4s done
#17 DONE 34.7s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-17]
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-17', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-17/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
diff of stderr:

39   --> $DIR/ice-cast-type-with-error-124848.rs:12:24
40    |
41 LL |     let mut unpinned = MyType(Cell::new(None));
+    |                        ^^^^^^----------------- 2nd argument is missing
43    |
44 note: tuple struct defined here
45   --> $DIR/ice-cast-type-with-error-124848.rs:7:8
45   --> $DIR/ice-cast-type-with-error-124848.rs:7:8


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/cast/ice-cast-type-with-error-124848/ice-cast-type-with-error-124848.stderr
To only update this specific test, also pass `--test-args cast/ice-cast-type-with-error-124848.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/cast/ice-cast-type-with-error-124848.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/cast/ice-cast-type-with-error-124848" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/cast/ice-cast-type-with-error-124848/auxiliary"
--- stderr -------------------------------
--- stderr -------------------------------
error[E0261]: use of undeclared lifetime name `'unpinned`
   |
   |
LL | struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
   |               -                ^^^^^^^^^ undeclared lifetime
   |               |
   |               help: consider introducing lifetime `'unpinned` here: `'unpinned,`
error[E0261]: use of undeclared lifetime name `'a`
##[error]  --> /checkout/tests/ui/cast/ice-cast-type-with-error-124848.rs:14:53
   |
LL | fn main() {
LL | fn main() {
   |        - help: consider introducing lifetime `'a` here: `<'a>`
...
LL |     let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;
   |                                                     ^^ undeclared lifetime
error[E0261]: use of undeclared lifetime name `'a`
##[error]  --> /checkout/tests/ui/cast/ice-cast-type-with-error-124848.rs:14:67
   |
LL | fn main() {
LL | fn main() {
   |        - help: consider introducing lifetime `'a` here: `<'a>`
...
LL |     let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;
   |                                                                   ^^ undeclared lifetime
error[E0412]: cannot find type `Pin` in this scope
##[error]  --> /checkout/tests/ui/cast/ice-cast-type-with-error-124848.rs:7:60
   |
   |
LL | struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
   |
help: consider importing this struct
   |
LL + use std::pin::Pin;
LL + use std::pin::Pin;
   |

error[E0061]: this struct takes 2 arguments but 1 argument was supplied
##[error]  --> /checkout/tests/ui/cast/ice-cast-type-with-error-124848.rs:12:24
   |
LL |     let mut unpinned = MyType(Cell::new(None));
   |                        ^^^^^^----------------- 2nd argument is missing
note: tuple struct defined here
  --> /checkout/tests/ui/cast/ice-cast-type-with-error-124848.rs:7:8
   |
   |
LL | struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
help: provide the argument
   |
   |
LL |     let mut unpinned = MyType(Cell::new(None), /* value */);


error[E0606]: casting `&MyType<'_>` as `*const Cell<Option<&mut MyType<'_>>>` is invalid
   |
   |
LL |     let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0061, E0261, E0412, E0606.

rust-log-analyzer avatar May 15 '24 15:05 rust-log-analyzer

I think using #n instead of the ordinal number is better, as in #125105 :)

nnethercote avatar May 16 '24 03:05 nnethercote

I think using #n instead of the ordinal number is better, as in #125105 :)

Yes, I will fix to use #n format because I don't have a strong reason to use ordinalize.

long-long-float avatar May 22 '24 14:05 long-long-float

The job x86_64-gnu-llvm-17 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#16 exporting to docker image format
#16 sending tarball 29.1s done
#16 DONE 41.8s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-17]
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-17', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-17/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
diff of stderr:

39   --> $DIR/ice-cast-type-with-error-124848.rs:12:24
40    |
41 LL |     let mut unpinned = MyType(Cell::new(None));
+    |                        ^^^^^^----------------- #2 argument is missing
43    |
44 note: tuple struct defined here
45   --> $DIR/ice-cast-type-with-error-124848.rs:7:8
45   --> $DIR/ice-cast-type-with-error-124848.rs:7:8


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/cast/ice-cast-type-with-error-124848/ice-cast-type-with-error-124848.stderr
To only update this specific test, also pass `--test-args cast/ice-cast-type-with-error-124848.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/cast/ice-cast-type-with-error-124848.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/cast/ice-cast-type-with-error-124848" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/cast/ice-cast-type-with-error-124848/auxiliary"
--- stderr -------------------------------
--- stderr -------------------------------
error[E0261]: use of undeclared lifetime name `'unpinned`
   |
   |
LL | struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
   |               -                ^^^^^^^^^ undeclared lifetime
   |               |
   |               help: consider introducing lifetime `'unpinned` here: `'unpinned,`
error[E0261]: use of undeclared lifetime name `'a`
##[error]  --> /checkout/tests/ui/cast/ice-cast-type-with-error-124848.rs:14:53
   |
LL | fn main() {
LL | fn main() {
   |        - help: consider introducing lifetime `'a` here: `<'a>`
...
LL |     let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;
   |                                                     ^^ undeclared lifetime
error[E0261]: use of undeclared lifetime name `'a`
##[error]  --> /checkout/tests/ui/cast/ice-cast-type-with-error-124848.rs:14:67
   |
LL | fn main() {
LL | fn main() {
   |        - help: consider introducing lifetime `'a` here: `<'a>`
...
LL |     let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;
   |                                                                   ^^ undeclared lifetime
error[E0412]: cannot find type `Pin` in this scope
##[error]  --> /checkout/tests/ui/cast/ice-cast-type-with-error-124848.rs:7:60
   |
   |
LL | struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
   |
help: consider importing this struct
   |
LL + use std::pin::Pin;
LL + use std::pin::Pin;
   |

error[E0061]: this struct takes 2 arguments but 1 argument was supplied
##[error]  --> /checkout/tests/ui/cast/ice-cast-type-with-error-124848.rs:12:24
   |
LL |     let mut unpinned = MyType(Cell::new(None));
   |                        ^^^^^^----------------- #2 argument is missing
note: tuple struct defined here
  --> /checkout/tests/ui/cast/ice-cast-type-with-error-124848.rs:7:8
   |
   |
LL | struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
help: provide the argument
   |
   |
LL |     let mut unpinned = MyType(Cell::new(None), /* value */);


error[E0606]: casting `&MyType<'_>` as `*const Cell<Option<&mut MyType<'_>>>` is invalid
   |
   |
LL |     let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0061, E0261, E0412, E0606.

rust-log-analyzer avatar May 22 '24 15:05 rust-log-analyzer

r? compiler

apiraino avatar Jun 26 '24 14:06 apiraino

@fmease I fixed the messages. Thank you!

@rustbot ready

long-long-float avatar Jul 14 '24 05:07 long-long-float

@bors r+ rollup

fmease avatar Jul 17 '24 14:07 fmease

:pushpin: Commit 332b41dbce936647232311a51b0febcd3615d731 has been approved by fmease

It is now in the queue for this repository.

bors avatar Jul 17 '24 14:07 bors