Skip to content

Stop parsing trailing + in trait bounds #14925

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

Closed
alexcrichton opened this issue Jun 16, 2014 · 1 comment · Fixed by #15062
Closed

Stop parsing trailing + in trait bounds #14925

alexcrichton opened this issue Jun 16, 2014 · 1 comment · Fixed by #15062
Labels
A-grammar Area: The grammar of Rust
Milestone

Comments

@alexcrichton
Copy link
Member

This was a remnant of just switching : to +. We should stop accepting code such as this:

fn foo(a: &Clone+) {
}

Nominating.

@brson brson added this to the 1.0 milestone Jun 19, 2014
@brson
Copy link
Contributor

brson commented Jun 19, 2014

1.0. P-backcompat-lang

pcwalton added a commit to pcwalton/rust that referenced this issue Jun 20, 2014
This will break code that looks like `Box<Trait+>`. Change that code to
`Box<Trait>` instead.

Closes rust-lang#14925.

[breaking-change]
bors added a commit that referenced this issue Jun 21, 2014
This will break code that looks like `Box<Trait+>`. Change that code to
`Box<Trait>` instead.

Closes #14925.

[breaking-change]

r? @brson
nrc pushed a commit to nrc/rust that referenced this issue Aug 22, 2014
This will break code that looks like `Box<Trait+>`. Change that code to
`Box<Trait>` instead.

Closes rust-lang#14925.

[breaking-change]
lnicola pushed a commit to lnicola/rust that referenced this issue Jun 19, 2023
…c-str, r=HKalbasi

feat: inline const as literal

Assist: inline_const_as_literal

Evaluate and inline const variable as literal.

```rust
const STRING: &str = "Hello, World!";

fn something() -> &'static str {
    STR$0ING
}
```
->
```rust
const STRING: &str = "Hello, World!";

fn something() -> &'static str {
    "Hello, World!"
}
```
lnicola pushed a commit to lnicola/rust that referenced this issue Sep 25, 2024
fix: Fix `inline_const_as_literal` error when the number >= 10

## Description

### The Bug

This PR fixes a small bug in the IDE assistence (`inline_const_as_literal`). When the being-inlined constant is a number and it is greater than or equal to 10, the assistence inserts unexpected string `(0x...)` after the number itself. A simple example is followed:

Current `inline_const_as_literal` changes

```rs
const A: usize = 16;

fn f() -> usize {
    A  // inline the constant
}
```

into

```rs
const A: usize = 16;

fn f() -> usize {
    16 (0x10)
}
```

The bug originates from rust-lang#14925 & rust-lang#15306 . rust-lang#14925 added some unittests, but it just tested the number-inlining behavior when the number is `0`.

https://github.com/rust-lang/rust-analyzer/blob/50882fbfa204027c84753e6d51a1a12884dc1b19/crates/ide-assists/src/handlers/inline_const_as_literal.rs#L124-L138

And rust-lang#15306 modified the behavior of `Const::render_eval` and added the `(0x...)` part after the number (if the number >= `10`). Because of insufficient unittests in rust-lang#14925, changes about `Const::render_eval` in rust-lang#15306 introduced this bug with no CI failure.

### The Fix

I think `Const::render_eval` is intended for user-facing value displaying (e.g. hover) and not designed for `inline_const_as_literal`. To fix the bug, I defined a new function named `Const::eval`, which evaluates the value itself faithfully and simply and does nothing else.

## Thanks

Thanks `@roife` for your kind help. Your guidance helped me better understand the code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-grammar Area: The grammar of Rust
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants