# Pre-RFC: usagetimes (partial mutability)

**URL:** <https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486>\
**Category:** language design\
**Created:** [September 5, 2023, 12:27pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486 "2023-09-05T12:27:40Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Helltraitor](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/helltraitor/32/10504_2.png) [@Helltraitor](https://internals.rust-lang.org/u/Helltraitor)\
**Post date:** [September 5, 2023, 12:27pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/1 "2023-09-05T12:27:40Z")

</div>

So, in [recent topic](https://internals.rust-lang.org/t/is-there-any-update-on-cross-function-partial-borrow/19419), I wrote, that I develop my idea about how we can achieve partial mutability, here is results:

> **[GitHub - helltraitor/rust-rfcs at usagetimes](https://github.com/helltraitor/rust-rfcs/tree/usagetimes)**
>
> usagetimes

Here I want to gather some opinion about draft document, resolve some related question, gather more critic and, maybe, try to push this to rust rfc repository.

I've worked on this for a while and it's not perfect, but in general I think all is good. Maybe, proposed syntax is not that you expected, but I hope that you will not hate this, at least.

If you interested in, please, read, ask about it, critic it, or guide me through some edge cases. Thanks for attention

P.S. Okay, maybe I'm worried to much, sorry

UPD: Changes moved to branch `usagetimes` of fork

---

<div class="post-metadata">

**Author:** ![dlight](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dlight/32/8462_2.png) [@dlight](https://internals.rust-lang.org/u/dlight)\
**Post date:** [September 5, 2023, 2:07pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/2 "2023-09-05T14:07:43Z")

</div>

Is there a reason for lifetime syntax to be written `&`a` instead of `&'a`? (with backtick rather than single quote)

edit: just noticed that `a isn't a lifetime but an usagetime specificier. That's wayyy too subtle. Anyway, maybe combine both in an example? (would it be, like, `&'a `b X`?)

---

<div class="post-metadata">

**Author:** ![Helltraitor](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/helltraitor/32/10504_2.png) [@Helltraitor](https://internals.rust-lang.org/u/Helltraitor)\
**Post date:** [September 5, 2023, 6:01pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/3 "2023-09-05T18:01:40Z")

</div>

I glad that you notice the difference. Usagetimes and lifetimes are orthogonal features that doesn't affect each other.

I can add examples with lifetimes (I will thinking about this), but the thing is partial mutability must work in the same was as borrowing does. Value \ field cannot be used, when it (or parent) doesn't live long enough.

So, it's trivial, I guess. Thank you for reading

---

<div class="post-metadata">

**Author:** ![pitaj](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/pitaj/32/11262_2.png) [@pitaj](https://internals.rust-lang.org/u/pitaj)\
**Post date:** [September 5, 2023, 7:32pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/4 "2023-09-05T19:32:43Z")

</div>

This seems like a feature that won't be used as often as normal lifetimes, so I'd rather not spend one of few remaining free characters we have on it.

Can we use a keyword instead?

```rust
struct Point<usage'x, usage'y, usage'color> {
    x: usage'x f64,
    y: usage'y f64,
    // 8u - alpha, 8u - red, 8u - green, 8u - blue
    c: usage'color u32
}

```

It's also not clear too me why they should be in the generic parameter brackets `<>` instead of somewhere else.

---

<div class="post-metadata">

**Author:** ![winksaville](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/winksaville/32/4321_2.png) [@winksaville](https://internals.rust-lang.org/u/winksaville)\
**Post date:** [September 5, 2023, 9:28pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/5 "2023-09-05T21:28:48Z")

</div>

I like this idea if nothing more than ' and ` are so close to looking the same. To save a few key strokes I suggest: use'

---

<div class="post-metadata">

**Author:** ![Helltraitor](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/helltraitor/32/10504_2.png) [@Helltraitor](https://internals.rust-lang.org/u/Helltraitor)\
**Post date:** [September 6, 2023, 10:27am UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/6 "2023-09-06T10:27:06Z")

</div>

> [@winksaville](#):
>
> I like this idea if nothing more than ' and ` are so close to looking the same. To save a few key strokes I suggest: use'

I think we must not to mix lifetimes and usagetimes. In my keyboard this can be done with one key (above `[tab]`, left to `[1]`), so I disagree here.

> [@pitaj](#):
>
> Can we use a keyword instead?

We can, but this is much verbose. You should notice, that lifetimes recommended to have length as less as possible, in contrast to usagetimes that stands for meaning. They don't positional based.

If we talking about your example, do we need `'` symbol?

```rust
struct Point<usage x, usage y, usage color> {
    x: usage x f64,
    y: usage y f64,
    c: usage color u32
}

```

Or we can try this...

```rust
struct Point<usage (x, y, color)> {
    x: usage x f64,
    y: usage y f64,
    c: usage color u32
}

```

I don't see the difference.

Also, I'm not interested in syntax discussion, to be honest. Here I would like to discuss about weak places of my idea. Syntax can be adjusted later (but I'm still ready to discuss this, of course)

---

<div class="post-metadata">

**Author:** ![jdahlstrom](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jdahlstrom/32/3351_2.png) [@jdahlstrom](https://internals.rust-lang.org/u/jdahlstrom)\
**Post date:** [September 6, 2023, 11:11am UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/7 "2023-09-06T11:11:01Z")

</div>

> [@Helltraitor](#):
>
> In my keyboard

In many (most?) European layouts ` is a dead key, so it's annoying to type (for instance on my keyboard it's first shift-[key to the left of backspace] and then space, in order to get it by itself and not as a modifier (grave accent) of another key.

---

<div class="post-metadata">

**Author:** ![mpol](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/mpol/32/4056_2.png) [@mpol](https://internals.rust-lang.org/u/mpol)\
**Post date:** [September 6, 2023, 11:55am UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/9 "2023-09-06T11:55:25Z")

</div>

Is this a joke to you? [Finnish - Keyboard Layout Info](http://kbdlayout.info/KBDFI)

Or this? [Polish (214) - Keyboard Layout Info](http://kbdlayout.info/KBDPL)

To be honest I don't think I've ever seen anybody using a Polish-layout keyboard with a Windows or Linux computer, but I think in many European countries these local layouts are indeed in use.

---

<div class="post-metadata">

**Author:** ![jdahlstrom](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jdahlstrom/32/3351_2.png) [@jdahlstrom](https://internals.rust-lang.org/u/jdahlstrom)\
**Post date:** [September 6, 2023, 12:11pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/10 "2023-09-06T12:11:44Z")

</div>

> [@Helltraitor](#):
>
> I need to ask first, did you tried to push tilda key (between `[esc]` and `[tab]`)? Almost all keyboards have this key, so I don't see a problem for now. This key literally exists in any keyboard. So this sound like a joke for me, sorry

Do you have any idea how keyboard layouts work? The button between tab and esc only gives the backtick in US and UK keyboard layouts (and possibly some others). On my keyboard it gives the section sign §.

---

<div class="post-metadata">

**Author:** ![Helltraitor](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/helltraitor/32/10504_2.png) [@Helltraitor](https://internals.rust-lang.org/u/Helltraitor)\
**Post date:** [September 6, 2023, 12:18pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/11 "2023-09-06T12:18:32Z")

</div>

@jdahlstromI rely on most common keyboard layouts: [Keyboard layout - Wikipedia](https://en.wikipedia.org/wiki/Keyboard_layout)

---

<div class="post-metadata">

**Author:** ![Vorpal](https://avatars.discourse-cdn.com/v4/letter/v/aca169/32.png) [@Vorpal](https://internals.rust-lang.org/u/Vorpal)\
**Post date:** [September 6, 2023, 6:08pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/12 "2023-09-06T18:08:31Z")

</div>

That page only list keyboard layouts that differ for the main letter area. There are loads of variants of qwerty that move special symbols around or replace some symbols with extra letters. Consider looking at [QWERTY - Wikipedia](https://en.m.wikipedia.org/wiki/QWERTY) as well, both under language variants and multi-lingual variants.

---

<div class="post-metadata">

**Author:** ![jhpratt](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jhpratt/32/11640_2.png) [@jhpratt](https://internals.rust-lang.org/u/jhpratt)\
**Post date:** [September 6, 2023, 6:50pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/13 "2023-09-06T18:50:45Z")

</div>

Can we not argue about keyboard layouts?

---

<div class="post-metadata">

**Author:** ![Vorpal](https://avatars.discourse-cdn.com/v4/letter/v/aca169/32.png) [@Vorpal](https://internals.rust-lang.org/u/Vorpal)\
**Post date:** [September 6, 2023, 8:36pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/14 "2023-09-06T20:36:34Z")

</div>

Usability of the feature _does_ matter. It is about syntax, sure. But back tick is plain bad for three reasons:

- Too similar to ' (visually).
- Really annoying to type on many keyboards (the world is not US centric).
- It conflicts with inline code blocks in markdown. Since markdown is used in many places, including rustdoc, this forum, the official mdbook docs etc, that seems pretty important.

---

<div class="post-metadata">

**Author:** ![Helltraitor](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/helltraitor/32/10504_2.png) [@Helltraitor](https://internals.rust-lang.org/u/Helltraitor)\
**Post date:** [September 6, 2023, 8:52pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/15 "2023-09-06T20:52:11Z")

</div>

It's about personal taste, I think.

- I chose ``` by special, since it similar, but very different, from `'`
- We need gather statistic of keyboard usage, I'm from Russia, but I have this key
- Markdown support double backtricks: ``` ` ```

We can try something from this list: `@#%^`

Nobody have said something about feature itself - this is very sad

P.S. A keyboard can be adjusted for this key if it doesn't exist for some reason

---

<div class="post-metadata">

**Author:** ![trentj](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/trentj/32/8551_2.png) [@trentj](https://internals.rust-lang.org/u/trentj)\
**Post date:** [September 7, 2023, 5:39pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/16 "2023-09-07T17:39:25Z")

</div>

Linking [directly to the RFC text](https://github.com/helltraitor/rust-rfcs/blob/usagetimes/text/0000-usagetimes.md) would probably help.

Personally I found the RFC rather long and hard to read. I also think not enough consideration is given to what should always be considered as the primary alternative to adding any new feature: _doing nothing_. Is there perhaps a minimal subset of this idea that could be discussed in isolation? I see 5 places the RFC suggests adding usagetimes should be allowed: structs, traits, enums, trait `impl`s, and function argument types that are references, not to mention what's going on with `as` and `!` and the clever idea of _not_ declaring them when the struct has public fields, which makes a degree of sense but also made some of the examples hard to follow. Imagine a "usagetimes MVP" that just focuses on methods and structs with private fields. Would that be worth implementing even with none of the other stuff (enums, traits etc.)? Or is it all or nothing?

---

<div class="post-metadata">

**Author:** ![dlight](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dlight/32/8462_2.png) [@dlight](https://internals.rust-lang.org/u/dlight)\
**Post date:** [September 7, 2023, 7:37pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/17 "2023-09-07T19:37:14Z")

</div>

The feature itself is honestly very very important and, since it was covered multiple times in Niko Matsakis' blog [\*], I assumed this would eventually become a RFC; but it appears there's always _something else_ that is more important than making the borrow checker more expressive in this way.

[\*] Well at least one time, in 2021, [View types for Rust](https://smallcultfollowing.com/babysteps/blog/2021/11/05/view-types/). Here the syntax is `&{field} T`. (You're right the specifics of the syntax is unimportant at this stage), but I remember this has been covered before. Well in 2018 there was [After NLL: Interprocedural conflicts](https://smallcultfollowing.com/babysteps/blog/2018/11/01/after-nll-interprocedural-conflicts/) which sketches the problem.

I also want to link to this issue [Partial borrowing (for fun and profit)](https://github.com/rust-lang/rfcs/issues/1215) which also features another syntax,

```rust
pub fn x_mut<'a>(&mut self)
    -> &'a f64
    where 'a: &mut self.x
{
    &mut self.x
}

```

---

<div class="post-metadata">

**Author:** ![Helltraitor](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/helltraitor/32/10504_2.png) [@Helltraitor](https://internals.rust-lang.org/u/Helltraitor)\
**Post date:** [September 8, 2023, 5:24pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/18 "2023-09-08T17:24:18Z")

</div>

This can be done with `regions` or patterns in methods (mentioned by dlight and in my rfc).

Of course, we can shrink this feature, but I think it will not worth to be implemented in that way

---

<div class="post-metadata">

**Author:** ![piegames](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/piegames/32/9140_2.png) [@piegames](https://internals.rust-lang.org/u/piegames)\
**Post date:** [September 12, 2023, 2:46pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/19 "2023-09-12T14:46:45Z")

</div>

Regardless of the keyboard layout, the backtick character should be forbidden to be used in any language at this point. Like it or not, but Markdown has won and is used everywhere, and any inline code snippet which uses it inside is going to be a pain to escape.

We actually even have a precedent here, the Nickel language used to use them for a short period of time, before switching away. Have a look how horrible writing documentation was before: ``` `"tag with space" ``` → ``'"tag with space"``

> <https://github.com/tweag/nickel/pull/1279/files#diff-097dccd87da0dccb6c1ab2e809e533995125c8f66e6954a0fa852de53e14eaabL677-R680>
>
> Change the enum tag syntax from \`\` \`Foo\`\` to \`'Foo\` as suggested in #671. This i…s a mostly mechanical change fixing failing tests after changing the syntax. It also changes printing to conform with the new syntax in \`Term::shallow\_repr\` and the pretty printer.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [December 11, 2023, 2:46pm UTC](https://internals.rust-lang.org/t/pre-rfc-usagetimes-partial-mutability/19486/20 "2023-12-11T14:46:46Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
