granite-rust/src
Matthias Krüger 32d85c0b5a
Rollup merge of #92164 - WaffleLapkin:rustc_must_implement_one_of_attr, r=Aaron1011
Implement `#[rustc_must_implement_one_of]` attribute

This PR adds a new attribute — `#[rustc_must_implement_one_of]` that allows changing the "minimal complete definition" of a trait. It's similar to GHC's minimal `{-# MINIMAL #-}` pragma, though `#[rustc_must_implement_one_of]` is weaker atm.

Such attribute was long wanted. It can be, for example, used in `Read` trait to make transitions to recently added `read_buf` easier:
```rust
#[rustc_must_implement_one_of(read, read_buf)]
pub trait Read {
    fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
        let mut buf = ReadBuf::new(buf);
        self.read_buf(&mut buf)?;
        Ok(buf.filled_len())
    }

    fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<()> {
        default_read_buf(|b| self.read(b), buf)
    }
}

impl Read for Ty0 {}
//^ This will fail to compile even though all `Read` methods have default implementations

// Both of these will compile just fine
impl Read for Ty1 {
    fn read(&mut self, buf: &mut [u8]) -> Result<usize> { /* ... */ }
}
impl Read for Ty2 {
    fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<()> { /* ... */ }
}
```

For now, this is implemented as an internal attribute to start experimenting on the design of this feature. In the future we may want to extend it:
- Allow arbitrary requirements like `a | (b & c)`
- Allow multiple requirements like
  - ```rust
    #[rustc_must_implement_one_of(a, b)]
    #[rustc_must_implement_one_of(c, d)]
    ```
- Make it appear in rustdoc documentation
- Change the syntax?
- Etc

Eventually, we should make an RFC and make this (or rather similar) attribute public.

---

I'm fairly new to compiler development and not at all sure if the implementation makes sense, but at least it passes tests :)
2022-01-17 20:07:02 +01:00
..
bootstrap Rollup merge of #92589 - ChrisDenton:break-loop, r=Mark-Simulacrum 2022-01-06 23:15:20 +01:00
build_helper
ci Add note about upstream commit musl-patch-configure.diff is derived from 2022-01-10 10:41:31 -05:00
doc Rollup merge of #90498 - joshtriplett:target-tier-policy-draft-updates, r=Mark-Simulacrum 2022-01-17 20:07:01 +01:00
etc Implement @snapshot check for htmldocck 2021-12-01 15:12:10 -08:00
librustdoc Auto merge of #90986 - camsteffen:nested-filter, r=cjgillot 2022-01-17 14:50:50 +00:00
llvm-project@2abffbf977 Use the new language identifier for Rust in the PDB debug format 2022-01-11 07:41:27 -08:00
rustdoc-json-types
test Rollup merge of #92164 - WaffleLapkin:rustc_must_implement_one_of_attr, r=Aaron1011 2022-01-17 20:07:02 +01:00
tools Auto merge of #90986 - camsteffen:nested-filter, r=cjgillot 2022-01-17 14:50:50 +00:00
README.md
stage0.json Bump bootstrap compiler 2021-11-30 10:44:21 -05:00
version bump version to 1.60.0 2022-01-07 10:04:15 +01:00

This directory contains the source code of the rust project, including:

  • The test suite
  • The bootstrapping build system
  • Various submodules for tools, like rustdoc, rls, etc.

For more information on how various parts of the compiler work, see the rustc dev guide.