Skip to content
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

#![feature(trivial_bounds)] incorrectly suggested, and then causing linker errors on Windows #128682

Open
kleinesfilmroellchen opened this issue Aug 5, 2024 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example F-trivial_bounds `#![feature(trivial_bounds)]` O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kleinesfilmroellchen
Copy link

kleinesfilmroellchen commented Aug 5, 2024

MWE (this does indeed require two separate crates and dynamic linking):

#### Workspace Cargo.toml
[workspace]
resolver = "2"               # Important! wgpu/Bevy needs this!
members = ["cmp", "client"]
default-members = ["client"]

[workspace.package]
version = "0.1.0"
edition = "2021"

[profile.dev]
opt-level = 1

[profile.dev.package."*"]
opt-level = 3

#### cmp/Cargo.toml
[package]
name = "cmp"
edition.workspace = true
version.workspace = true

[lib]
crate-type = ["dylib"]

[dependencies]
bevy = { version = "0.14", features = ["dynamic_linking"] }

#### client/Cargo.toml
[package]
name = "client"
version.workspace = true
edition.workspace = true

[dependencies]
cmp = { path = "../cmp" }
//// client/src/main.rs (minimal bin stub)
fn main() {}

//// cmp/src/lib.rs
#![feature(trivial_bounds)]

use bevy::prelude::*;

#[derive(Reflect)]
pub struct MweReflected {
	pub field: MweUnreflected,
}

pub struct MweUnreflected;

I expected to see this happen: The MweUnreflected field does not implement Reflect, which is a requirement of MweReflected. Therefore, Rust should show an error relating to unsatisfied trait bounds, like what happens if you don't add #![feature(trivial_bounds)].

Instead, this happened: Reflect has lots of generic implementations, including for lots of tuple types, and for some reason the compiler suggests to use #![feature(trivial_bounds)] (That's the first error). When using this feature, instead of giving the same (or a better) error message, Rust instead causes a linker error, where the various Reflect trait functions on MweUnreflected cannot be found by link.exe.

Meta

rustc --version --verbose:

rustc 1.82.0-nightly (612a33f20 2024-07-29)
binary: rustc
commit-hash: 612a33f20b9b2c27380edbc4b26a01433ed114bc
commit-date: 2024-07-29
host: x86_64-pc-windows-msvc
release: 1.82.0-nightly
LLVM version: 18.1.7
Linker errors

error: linking with `link.exe` failed: exit code: 1120
<long and sensitive linker invocation line omitted>

  = note: lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_108_$LT$impl$u20$bevy_reflect..type_registry..GetTypeRegistration$u20$for$u20$cmp..model..nav..NavComponent$GT$21get_type_registration17haeef134c9a08e10bE".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_108_$LT$impl$u20$bevy_reflect..type_registry..GetTypeRegistration$u20$for$u20$cmp..model..nav..NavComponent$GT$26register_type_dependencies17hd5b05f4b2184b1feE".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_90_$LT$impl$u20$bevy_reflect..reflect..Reflect$u20$for$u20$cmp..model..nav..NavComponent$GT$18reflect_partial_eq17h7193ed9efffbe4edE".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_90_$LT$impl$u20$bevy_reflect..type_info..Typed$u20$for$u20$cmp..model..nav..NavComponent$GT$9type_info17h1383952cb944e417E".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$11iter_fields17h374bad68a829126dE".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$12field_at_mut17ha33376bd44e99291E".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$13clone_dynamic17h76e402f00bd92585E".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$5field17hcd641fb8c9a404e5E".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$7name_at17h885325772a3bb243E".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$8field_at17h8b4d6a71a905aafaE".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$9field_len17hac564c17a54c82edE".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_94_$LT$impl$u20$bevy_reflect..struct_trait..Struct$u20$for$u20$cmp..model..nav..NavComponent$GT$9field_mut17h014f952078d75a88E".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp5model3nav1_99_$LT$impl$u20$bevy_reflect..from_reflect..FromReflect$u20$for$u20$cmp..model..nav..NavComponent$GT$12from_reflect17h0317fca958b30622E".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_81_$LT$impl$u20$bevy_reflect..reflect..Reflect$u20$for$u20$cmp..graphics..Sides$GT$18reflect_partial_eq17h895ddd3c776b4042E".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_81_$LT$impl$u20$bevy_reflect..type_info..Typed$u20$for$u20$cmp..graphics..Sides$GT$9type_info17h2d4f02562378d1b3E".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_90_$LT$impl$u20$bevy_reflect..from_reflect..FromReflect$u20$for$u20$cmp..graphics..Sides$GT$12from_reflect17h8373a3f9dd382b4fE".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_90_$LT$impl$u20$bevy_reflect..tuple_struct..TupleStruct$u20$for$u20$cmp..graphics..Sides$GT$13clone_dynamic17h3353cfaa8143ce63E".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_90_$LT$impl$u20$bevy_reflect..tuple_struct..TupleStruct$u20$for$u20$cmp..graphics..Sides$GT$5field17h13206a0d6892ed5eE".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_90_$LT$impl$u20$bevy_reflect..tuple_struct..TupleStruct$u20$for$u20$cmp..graphics..Sides$GT$9field_mut17h14a60af13883f93cE".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_99_$LT$impl$u20$bevy_reflect..type_registry..GetTypeRegistration$u20$for$u20$cmp..graphics..Sides$GT$21get_type_registration17hdec5b11f70576bd1E".␍
          lib.def : error LNK2001: Nicht aufgelöstes externes Symbol "_ZN3cmp8graphics1_99_$LT$impl$u20$bevy_reflect..type_registry..GetTypeRegistration$u20$for$u20$cmp..graphics..Sides$GT$26register_type_dependencies17ha68b80319c65fe54E".␍

This issue was previously discussed here (the origin of the Reflect macro and trait). Related to #48214.

@kleinesfilmroellchen kleinesfilmroellchen added the C-bug Category: This is a bug. label Aug 5, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 5, 2024
@jieyouxu jieyouxu added D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. F-trivial_bounds `#![feature(trivial_bounds)]` A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 5, 2024
@compiler-errors compiler-errors added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Aug 5, 2024
@jieyouxu jieyouxu added the O-windows-msvc Toolchain: MSVC, Operating system: Windows label Aug 13, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example F-trivial_bounds `#![feature(trivial_bounds)]` O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants