Skip to content

Conversation

Ezrashaw
Copy link
Contributor

Fixes #106883

Matches on slices, String and str. It would be nice to do this with something like Deref<Target=str> as well, but AFAIK it's not possible in this part of the compiler.

@rustbot
Copy link
Collaborator

rustbot commented Jan 15, 2023

r? @WaffleLapkin

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 15, 2023
@compiler-errors
Copy link
Member

It would be nice to do this with something like Deref<Target=str> as well, but AFAIK it's not possible in this part of the compiler.

This is definitely possible -- see Autoderef. Since you're in FnCtxt, you can just do self.autoderef(ty).silence_errors().any(...)

@Ezrashaw Ezrashaw force-pushed the str-cast-bool-emptyness branch from 9f915fb to 0229535 Compare January 15, 2023 08:02
@Ezrashaw
Copy link
Contributor Author

Ezrashaw commented Jan 15, 2023

@compiler-errors I've applied your suggestions. Now we show this error if we can deref to a slice or str. It's really interesting because that is the sort of thing (Autoderef) I just wouldn't know about, except with prior experience.

@Ezrashaw Ezrashaw force-pushed the str-cast-bool-emptyness branch from 0229535 to 42910a7 Compare January 15, 2023 08:32
@rust-log-analyzer

This comment has been minimized.

@Ezrashaw Ezrashaw force-pushed the str-cast-bool-emptyness branch from 42910a7 to 92ced4a Compare January 15, 2023 09:19
@Ezrashaw
Copy link
Contributor Author

@compiler-errors Forgot to re--bless. I think that we're good to go?

@compiler-errors
Copy link
Member

r? @compiler-errors @bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jan 15, 2023

📌 Commit 92ced4a 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 Jan 15, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 15, 2023
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#106888 (Add tidy check to ensure that rustdoc GUI tests start with a small description)
 - rust-lang#106896 (suggest `is_empty` for collections when casting to `bool`)
 - rust-lang#106900 (Fix regression in `unused_braces` with macros)
 - rust-lang#106906 (remove redundant clones)
 - rust-lang#106909 (Only suggest adding type param if path being resolved was a type)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 5610231 into rust-lang:master Jan 16, 2023
@rustbot rustbot added this to the 1.68.0 milestone Jan 16, 2023
@Ezrashaw Ezrashaw deleted the str-cast-bool-emptyness branch January 16, 2023 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

E0606 "hello" as bool could suggest is_empty()
6 participants