3

The documentation notes:

assert_eq!(usize::max_value(), 18446744073709551615);

But when I run a simple test:

use std::usize;

fn main() {
    println!("{}", usize::max_value());
}

It prints: 4294967295

My project has only been initialised and had the 2 lines use std::usize; and println!("{}", usize::max_value()); added, nothing else has been changed.

My output of rustc --version --verbose:

rustc 1.41.1 (f3e1a954d 2020-02-24)
binary: rustc
commit-hash: f3e1a954d2ead4e2fc197c7da7d71e6c61bad196
commit-date: 2020-02-24
host: i686-pc-windows-msvc
release: 1.41.1
LLVM version: 9.0

After deleting Rust and reinstalling using the 64-bit Windows rustup installer, I get:

Current installation options:
  default host triple: x86_64-pc-windows-msvc
  default toolchain: stable
  profile: default
  modify PATH variable: yes

But when I run rustup toolchain list it prints a single item:

stable-i686-pc-windows-msvc (default)

What is happening here?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Jonathan Woollett-light
  • 2,813
  • 5
  • 30
  • 58
  • If your system really is 64 bit - and if you really want an answer about what is going on - you will need to provide sufficient information for someone to actually answer that question. i.e. system information and exactly how you are compiling and running this program. – Peter Hall Mar 04 '20 at 14:15
  • @PeterHall I'm not sure what information I would need to provide, drop a comment and I'll add it (and remember to add information as such in future when having similar questions). – Jonathan Woollett-light Mar 04 '20 at 14:18
  • Documentation may need an improvement, maybe examples can be written with `cfg` annotation – Ömer Erden Mar 04 '20 at 14:21
  • 1
    Also please show which commands you used to compile and run the program. – Peter Hall Mar 04 '20 at 14:24

1 Answers1

5

As the documentation for usize says:

The size of this primitive is how many bytes it takes to reference any location in memory. For example, on a 32 bit target, this is 4 bytes and on a 64 bit target, this is 8 bytes.

4294967295 is the maximum size of a 32-bit integer; thus indicating that you are compiling for a 32-bit platform.

This is corroborated by your rustc output:

host: i686-pc-windows-msvc

You have installed the 32-bit Windows compiler. The 64-bit compiler says x86_64-pc-windows-*.

You can change the default rustup host to 64-bit:

rustup set default-host x86_64-pc-windows-msvc

You will then probably need to uninstall and reinstall the stable toolchain to switch it to 64-bit.

See also:

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366