Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal implementation of implicit deref patterns for Strings #98914

Merged
merged 6 commits into from
Nov 20, 2022

Conversation

fee1-dead
Copy link
Member

@fee1-dead fee1-dead commented Jul 5, 2022

cc @compiler-errors @BoxyUwU rust-lang/lang-team#88 #87121

I forgot to add a feature gate, will do so in a minute Done

@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 5, 2022
@rustbot
Copy link
Collaborator

rustbot commented Jul 5, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Collaborator

r? @michaelwoerister

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 5, 2022
@fee1-dead fee1-dead changed the title Minimal implementation of implicit deref patterns Minimal implementation of implicit deref patterns for Strings Jul 5, 2022
@rust-log-analyzer

This comment has been minimized.

@BoxyUwU
Copy link
Member

BoxyUwU commented Jul 5, 2022

lol. lmao. nice

@rust-log-analyzer

This comment has been minimized.

@michaelwoerister
Copy link
Member

@fee1-dead, do you know if there's a compiler-team sponsor for this feature?

@compiler-errors
Copy link
Member

i think @nikomatsakis originally was sponsoring the attached issue, at least from the lang perspective, though possibly from the compiler side too

@compiler-errors
Copy link
Member

ah, nvm, it was @cramertj from the lang side according to the issue

@BoxyUwU
Copy link
Member

BoxyUwU commented Jul 5, 2022

whats the exchange rate on "compiler-contributor member" to "compiler-team member". does 3 contributors interested count as a compiler team member sponsor? ;-)

@michaelwoerister
Copy link
Member

A compiler-contributor member can certainly take this too as long as they feel competent in the areas being modified. I'm mostly looking for someone who has the necessary context.

@rust-log-analyzer

This comment has been minimized.

@fee1-dead fee1-dead force-pushed the min-deref-patterns branch from bee390b to f9771d1 Compare July 5, 2022 13:41
@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Jul 5, 2022

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rust-log-analyzer

This comment has been minimized.

@fee1-dead fee1-dead force-pushed the min-deref-patterns branch from e3d3529 to 808ad13 Compare July 5, 2022 17:58
@rust-log-analyzer

This comment has been minimized.

&paths::SLICE_INTO,
&paths::VEC_DEQUE_ITER,
];
const ACCEPTABLE_METHODS: [&[&str]; 4] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't push formatting changes to Clippy.

I wonder why this is happening recently in every other PR 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why this is happening recently in every other PR thinking

vscode/rust-analyzer has format on save which might not respect clippy's config.

@fee1-dead fee1-dead force-pushed the min-deref-patterns branch from 50ea367 to e662969 Compare July 6, 2022 08:26
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still many Clippy formatting changes in this PR:

- src/tools/clippy/clippy_lints/src/strings.rs
- src/tools/clippy/clippy_lints/src/redundant_clone.rs
- src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs
- src/tools/clippy/clippy_lints/src/methods/string_extend_chars.rs
- src/tools/clippy/clippy_lints/src/methods/search_is_some.rs
- src/tools/clippy/clippy_lints/src/methods/manual_str_repeat.rs
- src/tools/clippy/clippy_lints/src/methods/inefficient_to_string.rs
- src/tools/clippy/clippy_lints/src/matches/match_str_case_mismatch.rs
- src/tools/clippy/clippy_lints/src/manual_retain.rs

@fee1-dead
Copy link
Member Author

yeah I was doing it incrementally

@fee1-dead fee1-dead force-pushed the min-deref-patterns branch 2 times, most recently from 5aeeda2 to 1e6f6a8 Compare July 6, 2022 08:40
@fee1-dead
Copy link
Member Author

fee1-dead commented Jul 6, 2022

so I reformatted it using clippy's rustfmt config which reverted everything back to normal. The only change it did was to reorder match arms in manual_retain.rs

@fee1-dead fee1-dead requested a review from flip1995 July 6, 2022 08:42
@fee1-dead
Copy link
Member Author

@rustbot ready

changed to -C panic=abort

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 18, 2022
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Nov 20, 2022

📌 Commit bc51f87 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 20, 2022
@bors
Copy link
Contributor

bors commented Nov 20, 2022

⌛ Testing commit bc51f87 with merge e07425d...

@bors
Copy link
Contributor

bors commented Nov 20, 2022

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing e07425d to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 20, 2022
@bors bors merged commit e07425d into rust-lang:master Nov 20, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 20, 2022
@fee1-dead fee1-dead deleted the min-deref-patterns branch November 20, 2022 10:32
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e07425d): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.7% [-1.0%, -0.5%] 7
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.7% [-1.0%, -0.5%] 7

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.7% [-2.7%, -2.7%] 1
Improvements ✅
(secondary)
-3.7% [-3.7%, -3.7%] 1
All ❌✅ (primary) -2.7% [-2.7%, -2.7%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

@lqd
Copy link
Member

lqd commented Nov 21, 2022

Note for weekly triage: bitmaps is currently noisy

flip1995 pushed a commit to flip1995/rust that referenced this pull request Nov 21, 2022
… r=compiler-errors

Minimal implementation of implicit deref patterns for Strings

cc `@compiler-errors` `@BoxyUwU` rust-lang/lang-team#88 rust-lang#87121

~~I forgot to add a feature gate, will do so in a minute~~ Done
@safinaskar
Copy link
Contributor

@fee1-dead . My expectation was that this PR will convert &T to &T::Target. But it seems that it converts T to &T::Target, this seems to be strange. I. e. with current PR this code works:

  match String::new() {
        "o" => (),
        _ => (),
    }

But this doesn't:

  match &String::new() {
        "o" => (),
        _ => (),
    }

I think that deref patterns should convert &T to &T::Target, because this is exactly thing we need in compilers/interpreters when we expect some deep structure. Say, we have this struct for representing Lisp value:

enum Value {
  Nil,
  Cons(Rc<Value>, Rc<Value>)
}

Then we want this:

let v: Value = ...
match &v {
  Cons(a, Cons(b, Cons(c, d))) => ...
  ...
}

You see? At every step we convert &T to &T::Target. And then again and again

@fee1-dead
Copy link
Member Author

If we have

enum Value {
  Foo, Bar(Option<String>, Vec<i32>),
}

And I want to get the Vec as an owned value when it is Value::Bar(Some("test"), x), then it would only work if we allow deref patterns for owned values.

I get why it might feel confusing, but in reality we are enabling more use cases instead of limiting more. In your case, you can just add & to the "o" pattern to match it.

@estebank
Copy link
Contributor

estebank commented Dec 5, 2022

In your case, you can just add & to the "o" pattern to match it.

It feels like under match ergonomics you shouldn't need to do that, at least once the implementation is more evolved.

Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
… r=compiler-errors

Minimal implementation of implicit deref patterns for Strings

cc `@compiler-errors` `@BoxyUwU` rust-lang/lang-team#88 rust-lang#87121

~~I forgot to add a feature gate, will do so in a minute~~ Done
@tgross35 tgross35 mentioned this pull request Feb 3, 2023
6 tasks
@Nadrieril Nadrieril added the F-deref_patterns `#![feature(deref_patterns)]` label Mar 8, 2024
@AlbertMarashi
Copy link

FYI, this doesn't appear to be working with rust-analyzer. Any workarounds?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-deref_patterns `#![feature(deref_patterns)]` merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.