Repository: rust
Issue: wasm32-unknown-unknown stuck in infinite loop when compiling fluent-bundle at opt-level=3
Labels: P-medium,T-compiler,O-wasm,C-bug,I-hang,E-needs-mcve

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I failed to reproduce a minimum reproducible example for this bug, but the full steps to reproduce my scenario is found here: https://github.com/traffloat/traffloat/runs/4251506793

(Put simply: clone the repo, `cd client`, run `cargo build --target wasm32-unknown-unknown `)

Observation: when cargo compiles up to the `fluemt-bundle` crate, rustc keeps running for a few minutes on 100% CPU, using more and more RAM until the OOM killer from the OS stops it.

This only happens when I compile without the `--releade` flag. However, pay attention that I set `opt-level=3` in the workspace Cargo.toml.

Furthermore, this only happens in the build stage with `--target wasm32-unknown-unknown`. This does not happen on x86_64-unknown-linux-gnu.

The issue cannot be reproduced by compiling a dummy crate that only includes that dependency.

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
$ rustc --version --verbose                                                     rustc 1.58.0-nightly (d914f17ca 2021-11-16)
binary: rustc
commit-hash: d914f17ca71a33a89b2dc3436fca51b1a091559e
commit-date: 2021-11-16
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>

```
error: could not compile `fluent-bundle`                                        
Caused by:
  process didn't exit successfully: `CARGO=/home/sofe/.rustup/toolchains/nightly-2021-11-17-x86_64-unknown-linux-gnu/bin/cargo CARGO_CRATE_NAME=fluent_bundle CARGO_MANIFEST_DIR=/home/sofe/.cargo/registry/src/github.com-1ecc6299db9ec823/fluent-bundle-0.15.2 CARGO_PKG_AUTHORS='Zibi Braniecki <gandalf@mozilla.com>:Staś Małolepszy <stas@mozilla.com>' CARGO_PKG_DESCRIPTION='A localization system designed to unleash the entire expressive power of
  natural language translations.
  ' CARGO_PKG_HOMEPAGE='http://www.projectfluent.org' CARGO_PKG_LICENSE=Apache-2.0/MIT CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=fluent-bundle CARGO_PKG_REPOSITORY='https://github.com/projectfluent/fluent-rs' CARGO_PKG_VERSION=0.15.2 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=15 CARGO_PKG_VERSION_PATCH=2 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/home/sofe/proj/traffloat/target/debug/deps:/home/sofe/.rustup/toolchains/nightly-2021-11-17-x86_64-unknown-linux-gnu/lib:/home/sofe/.rustup/toolchains/nightly-2021-11-17-x86_64-unknown-linux-gnu/lib' rustc --crate-name fluent_bundle --edition=2018 /home/sofe/.cargo/registry/src/github.com-1ecc6299db9ec823/fluent-bundle-0.15.2/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C debuginfo=2 -C debug-assertions=on --cfg 'feature="default"' -C metadata=d64013c212ea53c9 -C extra-filename=-d64013c212ea53c9 --out-dir /home/sofe/proj/traffloat/target/wasm32-unknown-unknown/debug/deps --target wasm32-unknown-unknown -L dependency=/home/sofe/proj/traffloat/target/wasm32-unknown-unknown/debug/deps -L dependency=/home/sofe/proj/traffloat/target/debug/deps --extern fluent_langneg=/home/sofe/proj/traffloat/target/wasm32-unknown-unknown/debug/deps/libfluent_langneg-20e6de4d2a5c2f31.rmeta --extern fluent_syntax=/home/sofe/proj/traffloat/target/wasm32-unknown-unknown/debug/deps/libfluent_syntax-6330210a26c5ec71.rmeta --extern intl_memoizer=/home/sofe/proj/traffloat/target/wasm32-unknown-unknown/debug/deps/libintl_memoizer-be378e2b3f9d6ab2.rmeta --extern intl_pluralrules=/home/sofe/proj/traffloat/target/wasm32-unknown-unknown/debug/deps/libintl_pluralrules-d90b40ad54dbd6fe.rmeta --extern rustc_hash=/home/sofe/proj/traffloat/target/wasm32-unknown-unknown/debug/deps/librustc_hash-e990337399c22a21.rmeta --extern self_cell=/home/sofe/proj/traffloat/target/wasm32-unknown-unknown/debug/deps/libself_cell-b546eeb8cbdb720e.rmeta --extern smallvec=/home/sofe/proj/traffloat/target/wasm32-unknown-unknown/debug/deps/libsmallvec-982c24cfab604cb7.rmeta --extern unic_langid=/home/sofe/proj/traffloat/target/wasm32-unknown-unknown/debug/deps/libunic_langid-a07d0b70489807ae.rmeta --cap-lints warn` (signal: 9, SIGKILL: kill)
```

</p>
</details>