rust/compiler/rustc_middle/src
Matthias Krüger 3aa1a24799
Rollup merge of #132799 - zachs18:str-primitive-symbol, r=compiler-errors
Make `Ty::primitive_symbol` recognize `str`

Make `Ty::primitive_symbol` recognize `str`, which makes `str` eligible for the "expected primitive, found local type" (and vice versa) [diagnostic](https://github.com/rust-lang/rust/blob/master/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs#L1430-L1437) that already exists for other primitives.

<details><summary> diagnostic difference</summary>

```rs
#[allow(non_camel_case_types)]
struct str;

fn foo() {
    let _: &str = "hello";
    let _: &core::primitive::str = &str;
}
```

`rustc --crate-type lib --edition 2021 a.rs`

Current nightly:

```rs
error[E0308]: mismatched types
 --> a.rs:5:19
  |
5 |     let _: &str = "hello";
  |            ----   ^^^^^^^ expected `str`, found a different `str`
  |            |
  |            expected due to this
  |
  = note: expected reference `&str`
             found reference `&'static str`

error[E0308]: mismatched types
 --> a.rs:6:36
  |
6 |     let _: &core::primitive::str = &str;
  |            ---------------------   ^^^^ expected `str`, found a different `str`
  |            |
  |            expected due to this
  |
  = note: expected reference `&str` (`str`)
             found reference `&str` (`str`)

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
```

With this patch:

```rs
error[E0308]: mismatched types
 --> a.rs:5:19
  |
5 |     let _: &str = "hello";
  |            ----   ^^^^^^^ expected `str`, found a different `str`
  |            |
  |            expected due to this
  |
  = note: str and `str` have similar names, but are actually distinct types
  = note: str is a primitive defined by the language
note: `str` is defined in the current crate
 --> a.rs:2:1
  |
2 | struct str;
  | ^^^^^^^^^^

error[E0308]: mismatched types
 --> a.rs:6:36
  |
6 |     let _: &core::primitive::str = &str;
  |            ---------------------   ^^^^ expected `str`, found a different `str`
  |            |
  |            expected due to this
  |
  = note: str and `str` have similar names, but are actually distinct types
  = note: str is a primitive defined by the language
note: `str` is defined in the current crate
 --> a.rs:2:1
  |
2 | struct str;
  | ^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
```

</details>
2024-11-09 19:16:46 +01:00
..
dep_graph Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
hir compiler: Directly use rustc_abi in metadata and middle 2024-11-03 13:38:47 -08:00
hooks Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
infer Remove associated type based effects logic 2024-10-24 09:46:36 +00:00
middle Rollup merge of #132544 - dianne:unstable-library-feature-backticks, r=compiler-errors 2024-11-04 18:12:46 +01:00
mir ty::BrK -> ty::BoundRegionKind::K 2024-11-04 04:45:52 +00:00
query Rollup merge of #132131 - celinval:smir-crate-defs, r=compiler-errors 2024-11-07 18:48:22 -08:00
thir various fixes for naked_asm! implementation 2024-10-06 19:00:09 +02:00
traits Manually register some bounds for a better span 2024-11-08 04:56:08 +00:00
ty Rollup merge of #132799 - zachs18:str-primitive-symbol, r=compiler-errors 2024-11-09 19:16:46 +01:00
util ty::KContainer -> ty::AssocItemContainer::K 2024-11-04 04:45:52 +00:00
arena.rs compiler: Directly use rustc_abi in metadata and middle 2024-11-03 13:38:47 -08:00
error.rs Use bool in favor of Option<()> for diagnostics 2024-08-21 01:31:11 -04:00
lib.rs move strict provenance lints to new feature gate, remove old feature gates 2024-10-21 15:22:17 +01:00
lint.rs Remove module passes filtering 2024-10-19 16:20:51 +02:00
macros.rs Improve const traits diagnostics for new desugaring 2024-10-02 19:45:17 +08:00
metadata.rs Reformat use declarations. 2024-07-29 08:26:52 +10:00
tests.rs Give an item related to issue 27438 a more meaningful name 2024-04-30 22:27:19 +02:00
thir.rs compiler: Directly use rustc_abi in metadata and middle 2024-11-03 13:38:47 -08:00
values.rs compiler: Directly use rustc_abi in metadata and middle 2024-11-03 13:38:47 -08:00