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

Document lang items #1119

Merged
merged 5 commits into from
Jul 5, 2021
Merged

Document lang items #1119

merged 5 commits into from
Jul 5, 2021

Conversation

jyn514
Copy link
Member

@jyn514 jyn514 commented Apr 29, 2021

This is mostly the text from #978 with the exhaustive list of lang items removed.

cc @MikailBag, @nikomatsakis, @camelid

@jyn514 jyn514 added the S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content label Apr 29, 2021
@nikomatsakis
Copy link
Contributor

nikomatsakis commented Apr 29, 2021

This is nice. I want to cc @roxelo who recently had to add lang-items and so forth. Would this text have been helpful? Are there things you had to figure out that are worth including?

One thing I would like to see:

  • Document how you get the def-id for a lang-item with a small example
  • Talk more about why it returns Option and what you should do if the result is None -- the answer is typically not unwrap but try to recover in some sensible way.

@jyn514 jyn514 added S-waiting-on-author Status: this PR is waiting for additional action by the OP and removed S-waiting-on-review Status: this PR is waiting for a reviewer to verify its content labels Apr 29, 2021
Copy link
Member

@camelid camelid left a comment

Choose a reason for hiding this comment

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

I left a few copy edits and clarifications of things that seemed ambiguous.

src/lang-items.md Outdated Show resolved Hide resolved
src/lang-items.md Outdated Show resolved Hide resolved
src/lang-items.md Outdated Show resolved Hide resolved
src/lang-items.md Outdated Show resolved Hide resolved

You can find language items in the following places:
- An exhaustive reference in the compiler documentation: [`rustc_hir::LangItem`]
- An auto-generated list with source locations by using ripgrep: `rg '#\[.*lang =' library/`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- An auto-generated list with source locations by using ripgrep: `rg '#\[.*lang =' library/`
- An auto-generated list with source locations in the standard library by using ripgrep: `rg '#\[.*lang =' library/`

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 don't think this is more clear. I could say "A list of items in the standard library, along with their sources, by using ripgrep" if you like.

Copy link
Member

Choose a reason for hiding this comment

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

I suggested that just to make it clear that language items can be defined outside of the standard library, and that these source locations are specifically the ones defined by the standard library.

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 think that's too much nuance to pack into 4 words. Defining lang-items outside the standard library is pretty rare - I can add a section if you like, but I don't think it belongs here.

src/lang-items.md Outdated Show resolved Hide resolved
Co-authored-by: Camelid <camelidcamel@gmail.com>
@jyn514
Copy link
Member Author

jyn514 commented Apr 30, 2021

@nikomatsakis when should someone create a lang item instead of using a rustc_diagnostic_item? The only difference I can see is that diagnostic items use symbols and lang items use struct fields, is that it?

@camelid
Copy link
Member

camelid commented Apr 30, 2021

nikomatsakis when should someone create a lang item instead of using a rustc_diagnostic_item? The only difference I can see is that diagnostic items use symbols and lang items use struct fields, is that it?

I don't know, but just guessing, I would say that the compiler may give special behavior for a lang item (e.g., for add or sized), whereas a diagnostic item is just used to give better error messages.

Also, lang items can be used by the standard library or by user libraries, whereas rustc_diagnostic_item is an internal attribute that is not intended for use outside of the standard library:

error[E0658]: diagnostic items compiler internal support for linting
 --> src/lib.rs:1:1
  |
1 | #[rustc_diagnostic_item = "foo"] fn foo() {}
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

src/lang-items.md Outdated Show resolved Hide resolved

You can find language items in the following places:
- An exhaustive reference in the compiler documentation: [`rustc_hir::LangItem`]
- An auto-generated list with source locations by using ripgrep: `rg '#\[.*lang =' library/`
Copy link
Member

Choose a reason for hiding this comment

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

I suggested that just to make it clear that language items can be defined outside of the standard library, and that these source locations are specifically the ones defined by the standard library.

@roxelo
Copy link
Member

roxelo commented Apr 30, 2021

@nikomatsakis Yes, this would have been useful. The only other thing that I think could have helped would have been a basic example of how to add a new lang item, but at the same time that didn't take me too long to figure out with a quick grep.

@jyn514
Copy link
Member Author

jyn514 commented May 9, 2021

I won't have time to follow up on this for at least a month. If @camelid or someone wants to work on this I'm happy for them to do so :)

@rylev
Copy link
Member

rylev commented Jul 4, 2021

@jyn514 @camelid this seems pretty good for now even if not 100% complete. Considering it's been sitting for a while, shall we merge it, and just make a quick issue(s) with remaining todos?

src/lang-items.md Outdated Show resolved Hide resolved
@camelid
Copy link
Member

camelid commented Jul 5, 2021

this seems pretty good for now even if not 100% complete. Considering it's been sitting for a while, shall we merge it, and just make a quick issue(s) with remaining todos?

That seems good to me!

@jyn514
Copy link
Member Author

jyn514 commented Jul 5, 2021

Somewhere I had written up a partial answer to Niko's questions, but I seem to have lost it ... anyway, if you're happy with how it is now, could you approve it so I can merge?

Copy link
Member

@rylev rylev left a comment

Choose a reason for hiding this comment

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

🎉

@rylev rylev merged commit 33c1eff into rust-lang:master Jul 5, 2021
@jyn514 jyn514 deleted the lang-items branch July 5, 2021 10:40
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jul 7, 2021
Update books

## nomicon

8 commits in b9ca313e687c991223e23e5520529815dc281205..7a13537f96af4b9b8e3ea296d6e5c3c7ab72ce9f
2021-06-22 12:02:20 -0400 to 2021-07-05 23:34:47 -0400
- Apply review comments
- Fix some style issues
- Move the list of coercions to the reference
- Add an example that shows the null-pointer opt does not happen
- Remove casting list from the nomicon (rust-lang/nomicon#287)
- Audit `ignore` annotations (rust-lang/nomicon#288)
- rename typo "lifetime" to "reference" (rust-lang/nomicon#286)
- Add an incomplete warning to the top page (rust-lang/nomicon#274)

## reference

7 commits in d9699fa8f3186440fdaadd703d63d8d42322c176..ab60513a3a5a0591e237fddff5d027a982648392
2021-06-21 12:23:10 -0700 to 2021-07-05 08:27:31 -0700
- fix grammar in Expressions (rust-lang/reference#1057)
- fix comment in function parameter drop scope example (rust-lang/reference#1056)
- fix typo in macro-ambiguity.md (rust-lang/reference#1058)
- Mention (negative) infinity values on float-to-int casting (rust-lang/reference#1054)
-  (rust-lang/reference#841)
- Missing TypeParamBounds in TypeAlias (rust-lang/reference#1036)
- Be more precise about array offset in type layouts (rust-lang/reference#1034)

## book

34 commits in 55a26488ddefc8433e73a2e8352d70f7a5c7fc2b..a90f07f1e9a7fc75dc9105a6c6f16d5c13edceb0
2021-05-09 12:03:18 -0500 to 2021-07-05 14:43:12 -0400
- Clarify ?Sized syntax. Fixes rust-lang/book#2422.
- Add some notes that macros are different than functions
- Break up a long sentence. Fixes rust-lang/book#2329.
- Further clarify and make consistent the reference to deref coercion
- Update ch04-03-slices.md
- add usage for `String` reference
- Update ch15-02-deref.md (rust-lang/book#2780)
- Remove claim about performance of i32
- Reword to avoid awkward pluralization
- Make the link to the reference relative
- Merge remote-tracking branch 'origin/pr/2753'
- Reword number of library crates a package contains (rust-lang/book#2750)
- Clarify explanation of why you can test private functions; add link
- Merge remote-tracking branch 'origin/pr/2743'
- Fix code hiding that I broke in eb60fedc9
- Link to the exact later section we're talking about
- improve cross-references for newtype pattern
- ch12-05, listing 12-20: Add missing "does not compile" warning (rust-lang/book#2731)
- cargo format
- Merge remote-tracking branch 'origin/pr/2724'
- Remove ordinal numbers and only refer to indexes to avoid confusion
- Let's mention the former and current authors of tlborm.
- Update tlborm link to point to Veykril's up-to-date version (rust-lang/book#2722)
- Merge remote-tracking branch 'origin/pr/2720'
- Describe the ferris pictures in the alt text
- Merge remote-tracking branch 'origin/pr/2707'
- Reword ... explanation to include the word deprecated, list that first
- Precise that the `...` inclusive range pattern has been replaces (rust-lang/book#2714)
-  (rust-lang/book#2696)
- fix typo: missing "type" after generic (rust-lang/book#2777)
-  (rust-lang/book#2709)
- Remove sentence about how Rust used to be
- Fix a potentially confusing statement about static lifetimes of static variables. (rust-lang/book#2692)
- Replace 'which'. (rust-lang/book#2663)

## rust-by-example

2 commits in 805e016c5792ad2adabb66e348233067d5ea9f10..028f93a61500fe8f746ee7cc6b204ea6c9f42935
2021-05-20 17:08:34 -0300 to 2021-07-06 06:28:53 -0300
- Fix a couple of typos in the `integration_testing.md` file (rust-lang/rust-by-example#1448)
- Fix Structures type list (rust-lang/rust-by-example#1446)

## rustc-dev-guide

13 commits in fe34bed..60e2825
2021-06-21 21:50:12 +0200 to 2021-07-05 11:21:03 -0400
- Fixed typos in inline code
- Document lang items (rust-lang/rustc-dev-guide#1119)
- More specifics on what future-incompatible lints are used for
- Fix line lens
- Update information on lints particularly on future-incompatible
- Update section of lint store
- Update around half of the January 2021 date references (rust-lang/rustc-dev-guide#1155)
- Create issues for many TODOs (rust-lang/rustc-dev-guide#1163)
- Links from rustc-dev-guide to std-dev-guide (rust-lang/rustc-dev-guide#1152)
- Document how to mark features as incomplete (rust-lang/rustc-dev-guide#1151)
- Remove requests or suggestions about rebase and fixup contradictory to rust-highfive bot comment (rust-lang/rustc-dev-guide#1111)
- Generate glossary table correctly (rust-lang/rustc-dev-guide#1146)
- Correct the wrong serial number (rust-lang/rustc-dev-guide#1147)

## edition-guide

3 commits in c74b2a0d6bf55774cf15d69f05dfe05408b8f81a..5d57b3832f8d308a9f478ce0a69799548f27ad4d
2021-06-14 10:48:27 -0700 to 2021-07-05 10:33:32 +0200
- Add more info for warnings promoted to errors (rust-lang/edition-guide#247)
- Create triagebot.toml
- Clarify snippets in 2021 panic docs. (rust-lang/edition-guide#245)

## embedded-book

1 commits in cbec77fbd8eea0c13e390dd9eded1ae200e811d1..506840eb73b0749336e1d5274e16d6393892ee82
2021-06-10 06:26:32 +0000 to 2021-06-24 00:01:32 +0000
- Update book to track quickstart changes  (rust-embedded/book#296)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: this PR is waiting for additional action by the OP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants