Use token::Lit in ast::ExprKind::Lit.#102944
Conversation
|
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
|
Another alternative to the literal changes in #101562 and #101885. I don't feel entirely happy with this approach. Various things:
|
|
Also, it's not yet complete. I haven't updated |
This comment has been minimized.
This comment has been minimized.
The literal lowering logic, including error reporting, is independent of the rest of the parser and can be moved to some common dependency of AST->HIR lowering and Attribute -> MetaItem lowering, or passed through a function pointer like
I'd expect it to be renamed to something like |
|
Change description for the lang team. This PR changes some errors related to literals from syntactic-but-not-in-macros to semantic. InvalidSuffix,
InvalidIntSuffix,
InvalidFloatSuffix,
NonDecimalFloat(u32),
IntTooLarge,Examples: "string"any_suffix
10u123
10.0f123
0b10f32
999340282366920938463463374607431768211455999All these examples are valid tokens, that can be passed to macros without errors, but previously they were reported as errors when parsing proper Rust code, including code that will be later removed by // Before
sink! {
"string"any_suffix // OK
10u123 // OK
10.0f123 // OK
0b10f32 // OK
999340282366920938463463374607431768211455999 // OK
}
#[cfg(FALSE)]
fn configured_out() {
"string"any_suffix // ERROR
10u123 // ERROR
10.0f123 // ERROR
0b10f32 // ERROR
999340282366920938463463374607431768211455999 // ERROR
}
fn main() {
"string"any_suffix // ERROR
10u123 // ERROR
10.0f123 // ERROR
0b10f32 // ERROR
999340282366920938463463374607431768211455999 // ERROR
}This PR makes them fully semantic errors so they are only reported after all macros are expanded. // After
sink! {
"string"any_suffix // OK
10u123 // OK
10.0f123 // OK
0b10f32 // OK
999340282366920938463463374607431768211455999 // OK
}
#[cfg(FALSE)]
fn configured_out() {
"string"any_suffix // OK
10u123 // OK
10.0f123 // OK
0b10f32 // OK
999340282366920938463463374607431768211455999 // OK
}
fn main() {
"string"any_suffix // ERROR
10u123 // ERROR
10.0f123 // ERROR
0b10f32 // ERROR
999340282366920938463463374607431768211455999 // ERROR
}This way
|
Floats are stored as |
This is currently not accepted by the compiler: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=316edfc43c4ad955ee7b667883a10287 |
|
@y86-dev |
|
@scottmcm: The meeting notes indicate some support for this, but also that a firm conclusion wasn't reached. Should we do an FCP? |
This comment was marked as resolved.
This comment was marked as resolved.
|
@nnethercote I've been trying to distill my thoughts here into something less fuzzy. I think I see three different situations here.
For example, decimal literals that are obviously lexically fine, like #[cfg(nope)]
pub fn foo() {
let x = 1111111111222222222233333333334444444444;
}For that kind, I think we had lang consensus that they definitely shouldn't be a tokenizing nor parsing time error, but rather a semantic error later. So making those work for macros and cfg'd-out code as I understand this PR would do makes great sense to me.
I don't think we're likely to add I think lang also felt positive about supporting these, though I don't think we talked about them as much. Personally I'm definitely in favour.
This is where I'm not so confident about things. When it explicitly rejects hexadecimal and binary floating point, it's not at all obvious to me that Hopefully that's understandable 🤞 How do you feel about those distinctions? Is the line between cases 1&2 and case 3 something that you think is meaningful? How obnoxious would it be to separate those cases in the code? Am I missing something about how Rust is set up lexically/syntactically? cc @rust-lang/lang for comments in hopes this makes more sense than my rambling in the meeting. |
|
I have no strong opinions about the language design issues here. I'm just interested in shrinking the size of @petrochenkov: what do think about Scott's comments? |
I wouldn't make any of these distinctions.
|
|
We discussed this in today's @rust-lang/lang meeting, and we decided that we're willing to evaluate this via FCP. We're not thrilled that these were handled in the first place, but given that they work in macros, we should let them work in |
|
@rfcbot merge |
|
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Instead of `ast::Lit`. Literal lowering now happens at two different times. Expression literals are lowered when HIR is crated. Attribute literals are lowered during parsing. This commit changes the language very slightly. Some programs that used to not compile now will compile. This is because some invalid literals that are removed by `cfg` or attribute macros will no longer trigger errors. See this comment for more details: rust-lang#102944 (comment)
38e4045 to
358a603
Compare
|
I rebased. @bors r=petrochenkov |
|
@bors p=1 |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (bebd57a): comparison URL. Overall result: ❌✅ regressions and improvements - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesThis benchmark run did not return any relevant results for this metric. |
|
As above:
@rustbot label: +perf-regression-triaged |
|
Note from perf triage: the regressions are largely concentrated in primary benchmarks while the improvements are in secondary. So while the regressions and improvements balance out when treating all benchmarks equally, I do think that primary regressions should be considered to have more weight than secondary improvements. |
Instead of
ast::Lit.Literal lowering now happens at two different times. Expression literals are lowered when HIR is crated. Attribute literals are lowered during parsing.
r? @petrochenkov