Online compiler output vs. native compiler

Hello,
I entered following lines of code in the https://play.rust-lang.org/, but the output vs. my native compiler on the Debian:

fn main() {
    let x = ["a"];
    #[warn(unconditional_panic)]
    let _y = x[1];
    print!("End");
}

I can't see warning: this operation will panic at runtime in the output of the native compiler. Instead, it showed me warning: unknown lint: unconditional_panic.

Why?

Thank you.

When I copy your snippet to the playground, I see the same warning you see on your native system, not warning: unknown lint: unconditional_panic.

Playground.

Output
   Compiling playground v0.0.1 (/playground)
warning: this operation will panic at runtime
 --> src/main.rs:4:14
  |
4 |     let _y = x[1];
  |              ^^^^ index out of bounds: the length is 1 but the index is 1
  |
note: the lint level is defined here
 --> src/main.rs:3:12
  |
3 |     #[warn(unconditional_panic)]
  |            ^^^^^^^^^^^^^^^^^^^

warning: `playground` (bin "playground") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.71s
     Running `target/debug/playground`
thread 'main' panicked at 'index out of bounds: the len is 1 but the index is 1', src/main.rs:4:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Hello,
Thank you so much for your reply.
The complete output is:

warning: unknown lint: `unconditional_panic`
 --> example.rs:3:12
  |
3 |     #[warn(unconditional_panic)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unknown_lints)]` on by default

error: index out of bounds: the len is 1 but the index is 1
 --> example.rs:4:14
  |
4 |     let _y = x[1];
  |              ^^^^
  |
  = note: `#[deny(const_err)]` on by default

error: aborting due to previous error

Which version of Rust are you using? It might be that your local install is older and doesn't include that lint.

2 Likes

Like I said, I can't reproduce it. Could you please share a link to your playground? You can create links for sharing your playground code and the exact settings when you click the share button in the upper left hand corner. Then copy the "Permalink to the playground" and insert it here.


Or is the output you just posted from your native system? In which case I misunderstood your question assuming you get the warning: unknown lint: unconditional_panic on the playground.

My native Rust-Lang compiler version is:

$ rustc -V
rustc 1.41.1

No, I got warning: unknown lint: unconditional_panic error message on my system.

That's why. That version is over 3 years old (and Rust is still evolving relatively fast).

Seems that lint name was introduced (via rename) in 1.43.

https://github.com/rust-lang/rust/blob/master/RELEASES.md#misc-10

5 Likes

So, because of my Debian version.

No, because of the version of Rust that is shipped inside the package for your Debian distribution that you installed. Here's a post about why you shouldn't use the package:

Try installing the newest version of Rust via Rustup (after removing the package, probably by executing apt-get remove rustc or something similar).

4 Likes

But, why hasn't Debian updated the Rust-Lang version?

Inertia. Distros are generally lagging behind in packaging. I don't know if it's a lack of resources, laziness, or it's not a priority, but it's a general phenomenon.

2 Likes

Distros have different priorities and are largely based around long term support in a traditional dynamic linking environment for various reasons (including defensible ones IMO, but not everyone agrees).

Long story short,

  • Use Debian packages and library deps if you're making a Debian package
  • Otherwise (i.e. for general development) use a rustup managed installation
2 Likes

That really depends on the distro. Various rolling-release distros like Void, Arch, Tumbleweed and Rawhide all have 1.70. Arch, Void and Tumbleweed also offer rustup.

Debian is just one of the more slow-moving distros. Which is ok for servers where you don't want stuff to change frequently. But there you shouldn't be running rustc. So the package only serves to build other packages.

If you want to develop software under an up-to-date environment then you have to choose a distro that provides that.

3 Likes

If Debian includes a package for any program in their system they will also package the tools required to build it from source.

If they build that program package with version X of the tools used to build it then they package version X of the tools.

Now, if the tools are upgraded to version Y Debian cannot use ship a new package of the tools at version Y. Because if they do they risk something breaking. Perhaps version Y no longer builds that program. They would have to rebuild and ship new tools and new program ignorer to provide a stable system. That is a lot of work in testing and packaging etc.

Imagine they shipped a new version of the GCC compiler, that would risk breaking a huge amount of programs in the system. Breaking as in the compiler can no longer build everything reliably.

Presumably there are packages available in Debian that are built with Rust. So you get whatever old version of Rust they used to do that. With anew Debian release no doubt Rust will be updated and all those Rust packages rebuilt, retested etc.

It's all about stability. Not stability as in bug free and not crashing exactly, but stability of being able to build a working system. All parts work together.

For this reason one should never use the Debian package version of Rust for ones own development, it's there only to build Debian itself, it will likely be old. This also applies to other languages like Javascript (node.s) it even applies to the C++ compilers if you want the latest C++ standard features.

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.