Repository: rust
Issue: Reached the recursion limit while instantiating <the type> in `pub` functions
Labels: A-trait-system,T-compiler,C-bug

This issue was reported in [quick-xml](https://github.com/tafia/quick-xml/issues/540) repo, but I think, this is a bug in `rustc`. After minification I ended with that code:

```rust
pub fn main() {// removing "pub" eliminates error
    use serde::ser::{SerializeStructVariant, Serializer};

    let serializer = quick_xml::se::Serializer::new(String::new());

    let mut state = serializer.serialize_map(None).unwrap();
    serde::__private::ser::FlatMapSerializer(&mut state)
        .serialize_struct_variant("Enum", 0u32, "Variant", 0)
        .unwrap().end() // Commenting this line eliminates error
        .unwrap();
}
```
Used libraries:
```toml
[dependencies]
quick-xml = { version = "0.27.1", features = ["serialize"] }
serde = "1.0.152"
```

I expected to see this happen: this code should compile

Instead, this happened:
```
$ cargo build
   Compiling hk_modlinks v0.1.0 (/home/mingun/Projects/hk_modlinks)
error: reached the recursion limit while instantiating `<serde::__private::ser::content:... &mut &mut std::string::String>>`
   --> /home/mingun/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.152/src/ser/impls.rs:433:1
    |
433 | deref_impl!(<'a, T: ?Sized> Serialize for &'a T where T: Serialize);
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: `<serde::__private::ser::content::Content as Serialize>::serialize` defined here
   --> /home/mingun/.cargo/registry/src/github.com-1ecc6299db9ec823/serde-1.0.152/src/private/ser.rs:472:9
    |
472 | /         fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
473 | |         where
474 | |             S: Serializer,
    | |__________________________^
    = note: the full type name has been written to '/home/mingun/Projects/hk_modlinks/target/debug/deps/hk_modlinks-59717a86221e1ac9.long-type.txt'
    = note: this error originates in the macro `deref_impl` (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile `hk_modlinks` due to previous error
$
```

### Meta

I've tries several compilers (the first I had, then I've updated and checked again):
`rustc --version --verbose`:
```
rustc 1.66.1 (90743e729 2023-01-10)
binary: rustc
commit-hash: 90743e7298aca107ddaa0c202a4d3604e29bfeb6
commit-date: 2023-01-10
host: x86_64-unknown-linux-gnu
release: 1.66.1
LLVM version: 15.0.2
```
```
rustc 1.67.0 (fc594f156 2023-01-24)
binary: rustc
commit-hash: fc594f15669680fa70d255faec3ca3fb507c3405
commit-date: 2023-01-24
host: x86_64-unknown-linux-gnu
release: 1.67.0
LLVM version: 15.0.6
```
```
rustc 1.69.0-nightly (ef934d9b6 2023-02-08)
binary: rustc
commit-hash: ef934d9b632b8ac00276558824664c104b92b5f0
commit-date: 2023-02-08
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7
```

Content of hk_modlinks-59717a86221e1ac9.long-type.txt (`&mut ...128...String`):
```
<serde::__private::ser::content::Content as Serialize>::serialize::<se::element::ElementSerializer<'_, &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut &mut std::string::String>>
```

The strange thing here is that the compilation succeed if I remove `pub` modifier from the function, this is why I think this is a bug in `rustc` and not in my code. Moreover, the compiled code never create 128 `&mut` references

Backtrace is not generated with `RUST_BACKTRACE=1 cargo build`.