Skip to content

Add unstable Literal::subspan(). - #56120

Merged
bors merged 1 commit into
rust-lang:masterfrom
SergioBenitez:subspan
Nov 23, 2018
Merged

Add unstable Literal::subspan().#56120
bors merged 1 commit into
rust-lang:masterfrom
SergioBenitez:subspan

Conversation

@SergioBenitez

Copy link
Copy Markdown
Contributor

Take 2 of #55971. Still ~wrong, but now with a comment! (and less of a surface) Unblocks #49219.

r? @alexcrichton

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 21, 2018
@alexcrichton

Copy link
Copy Markdown
Member

@bors: r+

This is unstable, helps unblock other PRs, is within the ballpark of what we'd like to stabilize long-term, and looks solid enough for immediate use. Sounds good to me!

@bors

bors commented Nov 21, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit 09e7051 has been approved by alexcrichton

@borsbors 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 21, 2018
// `self.span()` actually maps to, so this method can currently only be
// called blindly. For example, `to_string()` for the character 'c' returns
// "'\u{63}'"; there is no way for the user to know whether the source text
// was 'c' or whether it was '\u{63}'.

Copy link
Copy Markdown
Contributor

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 correct. Literal::to_string should show the exact source contents, if the literal isn't synthetic.

@SergioBenitezSergioBenitezNov 22, 2018

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

This is correct. Try:

externcrate proc_macro;usecrate::proc_macro::Literal;usecrate::proc_macro::TokenStream;#[proc_macro]pubfngo(_:TokenStream) -> TokenStream{let literal = Literal::string("hel\u{6c}o");println!("literal: {}", literal.to_string());let literal = Literal::character('c');println!("literal: {}", literal.to_string());let literal = Literal::character(100aschar);println!("literal: {}", literal.to_string());let literal = Literal::byte_string(b"hello");println!("literal: {}", literal.to_string());let literal = Literal::byte_string(b"he\x42");println!("literal: {}", literal.to_string());let literal = Literal::byte_string(&['h'asu8,'e'asu8,]);println!("literal: {}", literal.to_string());let literal = Literal::f32_unsuffixed(1.0);println!("literal: {}", literal.to_string());let literal = Literal::f32_unsuffixed(1.134100000022);println!("literal: {}", literal.to_string());TokenStream::new()}

Edit: This may be different if the Literal comes from a TokenStream parsed from source. Nevertheless, this method needs to be correct regardless of where the Literal comes from.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If it's synthetic then the span doesn't matter, I was talking about Literals from the source. But also, we shouldn't be using escape_unicode like that.

kennytm added a commit to kennytm/rust that referenced this pull request Nov 23, 2018
Add unstable Literal::subspan().
Take 2 of rust-lang#55971. Still ~wrong, but now with a comment! (and less of a surface) Unblocks rust-lang#49219.
r? @alexcrichton
@kennytmkennytm mentioned this pull request Nov 23, 2018
bors added a commit that referenced this pull request Nov 23, 2018
Rollup of 14 pull requests
Successful merges:
- #55767 (Disable some pretty-printers when gdb is rust-enabled)
- #55838 (Fix #[cfg] for step impl on ranges)
- #55869 (Add std::iter::unfold)
- #55945 (Ensure that the argument to `static_assert` is a `bool`)
- #56022 (When popping in CTFE, perform validation before jumping to next statement to have a better span for the error)
- #56048 (Add rustc_codegen_ssa to sysroot)
- #56091 (Fix json output in the self-profiler)
- #56097 (Fix invalid bitcast taking bool out of a union represented as a scalar)
- #56116 (ci: Download clang/lldb from tarballs)
- #56120 (Add unstable Literal::subspan().)
- #56154 (Pass additional linker flags when targeting Fuchsia)
- #56162 (std::str Adapt documentation to reality)
- #56163 ([master] Backport 1.30.1 release notes)
- #56168 (Fix the tracking issue for hash_raw_entry)
Failed merges:
r? @ghost
@bors
bors merged commit 09e7051 into rust-lang:masterNov 23, 2018
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@SergioBenitez@alexcrichton@bors@eddyb@rust-highfive