Skip to content

Const asm type fix single commit #128069

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

Conversation

folkertdev
Copy link
Contributor

No description provided.

Amanieu and others added 3 commits July 21, 2024 17:10
Previously these would be treated like integer literals and default to
`i32` if a type could not be determined. To allow for
forward-compatibility with `str` constants in the future, this PR
changes type inference to use an unbound type variable instead.

The actual type checking is deferred until after typeck where we still
ensure that the final type for the `const` operand is an integer type.
@rustbot
Copy link
Collaborator

rustbot commented Jul 22, 2024

r? @jieyouxu

rustbot has assigned @jieyouxu.
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 rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 22, 2024
@folkertdev folkertdev closed this Jul 22, 2024
@rust-log-analyzer
Copy link
Collaborator

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)
------
 > importing cache manifest from ghcr.io/rust-lang/rust-ci-cache:3aacb9c90579defe09351ac5e8ee504359f8054da6326ff19038f1b7c90e3cb2aafe33685c6d9b76ee8d2ccbd187ca80c46ab5380485abdd8c0ce7d69cd8d8fd:
------
##[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', '--set', 'rust.lld=false', '--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
---
41 
+ error: invalid type for `const` operand
+   --> $DIR/type-check-1.rs:76:19
+    |
+ LL | global_asm!("{}", const 0f32);
+    |                         |
+    |                         is an `f32`
+    |
+    = help: `const` operands must be of an integer type
+    = help: `const` operands must be of an integer type
+ 
+ error: invalid type for `const` operand
+   --> $DIR/type-check-1.rs:78:19
+    |
+ LL | global_asm!("{}", const 0 as *mut u8);
+    |                         |
+    |                         is a `*mut u8`
+    |
+    = help: `const` operands must be of an integer type
---
- 
- error: invalid type for `const` operand
-   --> $DIR/type-check-1.rs:76:19
-    |
- LL | global_asm!("{}", const 0f32);
-    |                         |
-    |                         is an `f32`
-    |
-    = help: `const` operands must be of an integer type
-    = help: `const` operands must be of an integer type
- 
- error: invalid type for `const` operand
-   --> $DIR/type-check-1.rs:78:19
-    |
- LL | global_asm!("{}", const 0 as *mut u8);
-    |                         |
-    |                         is a `*mut u8`
152    |
153    = help: `const` operands must be of an integer type
153    = help: `const` operands must be of an integer type
154 


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/asm/type-check-1/type-check-1.stderr
To only update this specific test, also pass `--test-args asm/type-check-1.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/asm/type-check-1.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/asm/type-check-1" "-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/asm/type-check-1/auxiliary"
--- stderr -------------------------------
error[E0435]: attempt to use a non-constant value in a constant
##[error]  --> /checkout/tests/ui/asm/type-check-1.rs:41:26
   |
   |
LL |         asm!("{}", const x);
   |                          ^ non-constant value
   |
help: consider using `const` instead of `let`
   |
LL |         const x: /* Type */ = 0;
   |         ~~~~~  ++++++++++++
error[E0435]: attempt to use a non-constant value in a constant
##[error]  --> /checkout/tests/ui/asm/type-check-1.rs:44:36
   |
   |
LL |         asm!("{}", const const_foo(x));
   |                                    ^ non-constant value
help: consider using `const` instead of `let`
   |
   |
LL |         const x: /* Type */ = 0;
   |         ~~~~~  ++++++++++++
error[E0435]: attempt to use a non-constant value in a constant
##[error]  --> /checkout/tests/ui/asm/type-check-1.rs:47:36
   |
   |
LL |         asm!("{}", const const_bar(x));
   |                                    ^ non-constant value
help: consider using `const` instead of `let`
   |
   |
LL |         const x: /* Type */ = 0;
   |         ~~~~~  ++++++++++++

error: invalid `sym` operand
   |
   |
LL |         asm!("{}", sym x);
   |                        ^ is a local variable
   = help: `sym` operands must refer to either a function or a static

error: invalid type for `const` operand
##[error]  --> /checkout/tests/ui/asm/type-check-1.rs:76:19
##[error]  --> /checkout/tests/ui/asm/type-check-1.rs:76:19
   |
LL | global_asm!("{}", const 0f32);
   |                         |
   |                         is an `f32`
   |
   = help: `const` operands must be of an integer type
   = help: `const` operands must be of an integer type

error: invalid type for `const` operand
##[error]  --> /checkout/tests/ui/asm/type-check-1.rs:78:19
   |
LL | global_asm!("{}", const 0 as *mut u8);
   |                         |
   |                         is a `*mut u8`
   |
   = help: `const` operands must be of an integer type
   = help: `const` operands must be of an integer type

error: invalid asm output
##[error]  --> /checkout/tests/ui/asm/type-check-1.rs:14:29
   |
LL |         asm!("{}", out(reg) 1 + 2);

error: invalid asm output
##[error]  --> /checkout/tests/ui/asm/type-check-1.rs:16:31
   |
   |
LL |         asm!("{}", inout(reg) 1 + 2);

error[E0277]: the size for values of type `[u64]` cannot be known at compilation time
##[error]  --> /checkout/tests/ui/asm/type-check-1.rs:22:28
   |
   |
LL |         asm!("{}", in(reg) v[..]);
   |
   = help: the trait `Sized` is not implemented for `[u64]`
   = note: all inline asm arguments must have a statically known size


error[E0277]: the size for values of type `[u64]` cannot be known at compilation time
##[error]  --> /checkout/tests/ui/asm/type-check-1.rs:25:29
   |
LL |         asm!("{}", out(reg) v[..]);
   |
   = help: the trait `Sized` is not implemented for `[u64]`
   = note: all inline asm arguments must have a statically known size


error[E0277]: the size for values of type `[u64]` cannot be known at compilation time
##[error]  --> /checkout/tests/ui/asm/type-check-1.rs:28:31
   |
LL |         asm!("{}", inout(reg) v[..]);
   |
   = help: the trait `Sized` is not implemented for `[u64]`
   = note: all inline asm arguments must have a statically known size


error: cannot use value of type `[u64]` for inline assembly
##[error]  --> /checkout/tests/ui/asm/type-check-1.rs:22:28
   |
LL |         asm!("{}", in(reg) v[..]);
   |
   = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly

error: cannot use value of type `[u64]` for inline assembly
error: cannot use value of type `[u64]` for inline assembly
##[error]  --> /checkout/tests/ui/asm/type-check-1.rs:25:29
   |
LL |         asm!("{}", out(reg) v[..]);
   |
   = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly

error: cannot use value of type `[u64]` for inline assembly
error: cannot use value of type `[u64]` for inline assembly
##[error]  --> /checkout/tests/ui/asm/type-check-1.rs:28:31
   |
LL |         asm!("{}", inout(reg) v[..]);
   |
   = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly

error: invalid type for `const` operand
---

6    |
7    = help: `sym` operands must refer to either a function or a static
8 
+ error: invalid `sym` operand
+    |
+    |
+ LL | global_asm!("{}", sym C);
+    |                   ^^^^^ is an `i32`
+    = help: `sym` operands must refer to either a function or a static
+ 
+ 
+ error: invalid `sym` operand
+    |
+    |
+ LL |         asm!("{}", sym C);
+    |                    ^^^^^ is an `i32`
+    = help: `sym` operands must refer to either a function or a static
+ 
9 error: arguments for inline assembly must be copyable
10   --> $DIR/type-check-2.rs:43:32
10   --> $DIR/type-check-2.rs:43:32
11    |

63    |
64    = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
65 
- error: invalid `sym` operand
-    |
-    |
- LL |         asm!("{}", sym C);
-    |                    ^^^^^ is an `i32`
-    = help: `sym` operands must refer to either a function or a static
- 
74 error[E0381]: used binding `x` isn't initialized
75   --> $DIR/type-check-2.rs:15:28
75   --> $DIR/type-check-2.rs:15:28
76    |

112    |
113 LL |         let mut v: Vec<u64> = vec![0, 1, 2];
- 
- 
- error: invalid `sym` operand
-    |
-    |
- LL | global_asm!("{}", sym C);
-    |                   ^^^^^ is an `i32`
-    = help: `sym` operands must refer to either a function or a static
123 
124 error: aborting due to 13 previous errors
125 
125 


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/asm/x86_64/type-check-2/type-check-2.stderr
To only update this specific test, also pass `--test-args asm/x86_64/type-check-2.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/asm/x86_64/type-check-2.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/asm/x86_64/type-check-2" "-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/asm/x86_64/type-check-2/auxiliary"
--- stderr -------------------------------
--- stderr -------------------------------
error: invalid `sym` operand
   |
   |
LL |         asm!("{}", sym x);
   |                        ^ is a local variable
   = help: `sym` operands must refer to either a function or a static


error: invalid `sym` operand
   |
   |
LL | global_asm!("{}", sym C);
   |                   ^^^^^ is an `i32`
   = help: `sym` operands must refer to either a function or a static


error: invalid `sym` operand
   |
   |
LL |         asm!("{}", sym C);
   |                    ^^^^^ is an `i32`
   = help: `sym` operands must refer to either a function or a static

error: arguments for inline assembly must be copyable
##[error]  --> /checkout/tests/ui/asm/x86_64/type-check-2.rs:43:32
##[error]  --> /checkout/tests/ui/asm/x86_64/type-check-2.rs:43:32
   |
LL |         asm!("{}", in(xmm_reg) SimdNonCopy(0.0, 0.0, 0.0, 0.0));
   |
   = note: `SimdNonCopy` does not implement the Copy trait


error: cannot use value of type `{closure@/checkout/tests/ui/asm/x86_64/type-check-2.rs:55:28: 55:36}` for inline assembly
   |
   |
LL |         asm!("{}", in(reg) |x: i32| x);
   |
   = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly

error: cannot use value of type `Vec<i32>` for inline assembly
error: cannot use value of type `Vec<i32>` for inline assembly
##[error]  --> /checkout/tests/ui/asm/x86_64/type-check-2.rs:57:28
   |
LL |         asm!("{}", in(reg) vec![0]);
   |
   = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly
   = note: this error originates in the macro `vec` (in Nightly builds, run with -Z macro-backtrace for more info)


error: cannot use value of type `(i32, i32, i32)` for inline assembly
##[error]  --> /checkout/tests/ui/asm/x86_64/type-check-2.rs:59:28
   |
LL |         asm!("{}", in(reg) (1, 2, 3));
   |
   = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly


error: cannot use value of type `[i32; 3]` for inline assembly
   |
   |
LL |         asm!("{}", in(reg) [1, 2, 3]);
   |
   = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly


error: cannot use value of type `fn() {main}` for inline assembly
   |
   |
LL |         asm!("{}", inout(reg) f);
   |
   = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly

error: cannot use value of type `&mut i32` for inline assembly
error: cannot use value of type `&mut i32` for inline assembly
##[error]  --> /checkout/tests/ui/asm/x86_64/type-check-2.rs:72:31
   |
LL |         asm!("{}", inout(reg) r);
   |
   = note: only integers, floats, SIMD vectors, pointers and function pointers can be used as arguments for inline assembly

error[E0381]: used binding `x` isn't initialized
error[E0381]: used binding `x` isn't initialized
##[error]  --> /checkout/tests/ui/asm/x86_64/type-check-2.rs:15:28
   |
LL |         let x: u64;
   |             - binding declared here but left uninitialized
LL |         asm!("{}", in(reg) x);
   |                            ^ `x` used here but it isn't initialized
help: consider assigning a value
   |
LL |         let x: u64 = 42;
   |                    ++++
   |                    ++++

error[E0381]: used binding `y` isn't initialized
##[error]  --> /checkout/tests/ui/asm/x86_64/type-check-2.rs:18:9
   |
LL |         let mut y: u64;
   |             ----- binding declared here but left uninitialized
LL |         asm!("{}", inout(reg) y);
   |         ^^^^^^^^^^^^^^^^^^^^^^^^ `y` used here but it isn't initialized
help: consider assigning a value
   |
LL |         let mut y: u64 = 42;
   |                        ++++
   |                        ++++

error[E0596]: cannot borrow `v` as mutable, as it is not declared as mutable
   |
   |
LL |         let v: Vec<u64> = vec![0, 1, 2];
...
...
LL |         asm!("{}", out(reg) v[0]);
   |                             - cannot borrow as mutable
LL |         asm!("{}", inout(reg) v[0]);
   |                               - cannot borrow as mutable
help: consider changing this to be mutable
   |
   |
LL |         let mut v: Vec<u64> = vec![0, 1, 2];

error: aborting due to 13 previous errors

Some errors have detailed explanations: E0381, E0596.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants