Skip to content

'attempt to use non-constant in a constant' should point to the constant #79919

Closed
@jyn514

Description

@jyn514

(playground)

extern crate reqwest; // 0.10.9

fn main() {
    let s = String::from("http://example.com");
    const response = reqwest::get(&s);
}
error[E0435]: attempt to use a non-constant value in a constant
 --> src/main.rs:5:36
  |
5 |     const response = reqwest::get(&s);
  |                                    ^ non-constant value

I had const response = self.request(...) when I should have had let response = self.request(...) ... too much Javascript.
I don't think I equated "a constant" with const foo = ... in my head, because I'm used to doing const foo = bar(...) in Javascript all the time

It would be nice for the error to point to response as the constant:

5 |     const response = reqwest::get(&s);
  |           ^^^^^^^^ constant        ^ non-constant value

Metadata

Metadata

Assignees

Labels

A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions