Auto merge of #127382 - estebank:const-let, r=compiler-errors
Use verbose style when suggesting changing `const` with `let`
This commit is contained in:
commit
4a31a6c32a
25 changed files with 245 additions and 129 deletions
|
@ -810,7 +810,7 @@ impl<'a> Parser<'a> {
|
||||||
self.dcx().struct_span_err(non_item_span, "non-item in item list");
|
self.dcx().struct_span_err(non_item_span, "non-item in item list");
|
||||||
self.consume_block(Delimiter::Brace, ConsumeClosingDelim::Yes);
|
self.consume_block(Delimiter::Brace, ConsumeClosingDelim::Yes);
|
||||||
if is_let {
|
if is_let {
|
||||||
err.span_suggestion(
|
err.span_suggestion_verbose(
|
||||||
non_item_span,
|
non_item_span,
|
||||||
"consider using `const` instead of `let` for associated const",
|
"consider using `const` instead of `let` for associated const",
|
||||||
"const",
|
"const",
|
||||||
|
|
|
@ -819,7 +819,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
ResolutionError::CannotCaptureDynamicEnvironmentInFnItem => {
|
ResolutionError::CannotCaptureDynamicEnvironmentInFnItem => {
|
||||||
self.dcx().create_err(errs::CannotCaptureDynamicEnvironmentInFnItem { span })
|
self.dcx().create_err(errs::CannotCaptureDynamicEnvironmentInFnItem { span })
|
||||||
}
|
}
|
||||||
ResolutionError::AttemptToUseNonConstantValueInConstant(ident, suggestion, current) => {
|
ResolutionError::AttemptToUseNonConstantValueInConstant {
|
||||||
|
ident,
|
||||||
|
suggestion,
|
||||||
|
current,
|
||||||
|
type_span,
|
||||||
|
} => {
|
||||||
// let foo =...
|
// let foo =...
|
||||||
// ^^^ given this Span
|
// ^^^ given this Span
|
||||||
// ------- get this Span to have an applicable suggestion
|
// ------- get this Span to have an applicable suggestion
|
||||||
|
@ -836,13 +841,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
let ((with, with_label), without) = match sp {
|
let ((with, with_label), without) = match sp {
|
||||||
Some(sp) if !self.tcx.sess.source_map().is_multiline(sp) => {
|
Some(sp) if !self.tcx.sess.source_map().is_multiline(sp) => {
|
||||||
let sp = sp.with_lo(BytePos(sp.lo().0 - (current.len() as u32)));
|
let sp = sp
|
||||||
|
.with_lo(BytePos(sp.lo().0 - (current.len() as u32)))
|
||||||
|
.until(ident.span);
|
||||||
(
|
(
|
||||||
(Some(errs::AttemptToUseNonConstantValueInConstantWithSuggestion {
|
(Some(errs::AttemptToUseNonConstantValueInConstantWithSuggestion {
|
||||||
span: sp,
|
span: sp,
|
||||||
ident,
|
|
||||||
suggestion,
|
suggestion,
|
||||||
current,
|
current,
|
||||||
|
type_span,
|
||||||
}), Some(errs::AttemptToUseNonConstantValueInConstantLabelWithSuggestion {span})),
|
}), Some(errs::AttemptToUseNonConstantValueInConstantLabelWithSuggestion {span})),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
|
|
@ -240,16 +240,18 @@ pub(crate) struct AttemptToUseNonConstantValueInConstant<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
#[suggestion(
|
#[multipart_suggestion(
|
||||||
resolve_attempt_to_use_non_constant_value_in_constant_with_suggestion,
|
resolve_attempt_to_use_non_constant_value_in_constant_with_suggestion,
|
||||||
code = "{suggestion} {ident}",
|
style = "verbose",
|
||||||
applicability = "maybe-incorrect"
|
applicability = "has-placeholders"
|
||||||
)]
|
)]
|
||||||
pub(crate) struct AttemptToUseNonConstantValueInConstantWithSuggestion<'a> {
|
pub(crate) struct AttemptToUseNonConstantValueInConstantWithSuggestion<'a> {
|
||||||
#[primary_span]
|
// #[primary_span]
|
||||||
|
#[suggestion_part(code = "{suggestion} ")]
|
||||||
pub(crate) span: Span,
|
pub(crate) span: Span,
|
||||||
pub(crate) ident: Ident,
|
|
||||||
pub(crate) suggestion: &'a str,
|
pub(crate) suggestion: &'a str,
|
||||||
|
#[suggestion_part(code = ": /* Type */")]
|
||||||
|
pub(crate) type_span: Option<Span>,
|
||||||
pub(crate) current: &'a str,
|
pub(crate) current: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1178,21 +1178,41 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
if let Some(span) = finalize {
|
if let Some(span) = finalize {
|
||||||
let (span, resolution_error) = match item {
|
let (span, resolution_error) = match item {
|
||||||
None if rib_ident.as_str() == "self" => (span, LowercaseSelf),
|
None if rib_ident.as_str() == "self" => (span, LowercaseSelf),
|
||||||
None => (
|
None => {
|
||||||
|
// If we have a `let name = expr;`, we have the span for
|
||||||
|
// `name` and use that to see if it is followed by a type
|
||||||
|
// specifier. If not, then we know we need to suggest
|
||||||
|
// `const name: Ty = expr;`. This is a heuristic, it will
|
||||||
|
// break down in the presence of macros.
|
||||||
|
let sm = self.tcx.sess.source_map();
|
||||||
|
let type_span = match sm.span_look_ahead(
|
||||||
|
original_rib_ident_def.span,
|
||||||
|
":",
|
||||||
|
None,
|
||||||
|
) {
|
||||||
|
None => {
|
||||||
|
Some(original_rib_ident_def.span.shrink_to_hi())
|
||||||
|
}
|
||||||
|
Some(_) => None,
|
||||||
|
};
|
||||||
|
(
|
||||||
rib_ident.span,
|
rib_ident.span,
|
||||||
AttemptToUseNonConstantValueInConstant(
|
AttemptToUseNonConstantValueInConstant {
|
||||||
original_rib_ident_def,
|
ident: original_rib_ident_def,
|
||||||
"const",
|
suggestion: "const",
|
||||||
"let",
|
current: "let",
|
||||||
),
|
type_span,
|
||||||
),
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
Some((ident, kind)) => (
|
Some((ident, kind)) => (
|
||||||
span,
|
span,
|
||||||
AttemptToUseNonConstantValueInConstant(
|
AttemptToUseNonConstantValueInConstant {
|
||||||
ident,
|
ident,
|
||||||
"let",
|
suggestion: "let",
|
||||||
kind.as_str(),
|
current: kind.as_str(),
|
||||||
),
|
type_span: None,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
self.report_error(span, resolution_error);
|
self.report_error(span, resolution_error);
|
||||||
|
|
|
@ -236,11 +236,12 @@ enum ResolutionError<'a> {
|
||||||
/// Error E0434: can't capture dynamic environment in a fn item.
|
/// Error E0434: can't capture dynamic environment in a fn item.
|
||||||
CannotCaptureDynamicEnvironmentInFnItem,
|
CannotCaptureDynamicEnvironmentInFnItem,
|
||||||
/// Error E0435: attempt to use a non-constant value in a constant.
|
/// Error E0435: attempt to use a non-constant value in a constant.
|
||||||
AttemptToUseNonConstantValueInConstant(
|
AttemptToUseNonConstantValueInConstant {
|
||||||
Ident,
|
ident: Ident,
|
||||||
/* suggestion */ &'static str,
|
suggestion: &'static str,
|
||||||
/* current */ &'static str,
|
current: &'static str,
|
||||||
),
|
type_span: Option<Span>,
|
||||||
|
},
|
||||||
/// Error E0530: `X` bindings cannot shadow `Y`s.
|
/// Error E0530: `X` bindings cannot shadow `Y`s.
|
||||||
BindingShadowsSomethingUnacceptable {
|
BindingShadowsSomethingUnacceptable {
|
||||||
shadowing_binding: PatternSource,
|
shadowing_binding: PatternSource,
|
||||||
|
|
|
@ -313,74 +313,90 @@ LL | global_asm!("{1}", format!("{{{}}}", 0), const FOO, const BAR);
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/parse-error.rs:39:37
|
--> $DIR/parse-error.rs:39:37
|
||||||
|
|
|
|
||||||
LL | let mut foo = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const foo`
|
|
||||||
...
|
|
||||||
LL | asm!("{}", options(), const foo);
|
LL | asm!("{}", options(), const foo);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const foo: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/parse-error.rs:47:44
|
--> $DIR/parse-error.rs:47:44
|
||||||
|
|
|
|
||||||
LL | let mut foo = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const foo`
|
|
||||||
...
|
|
||||||
LL | asm!("{}", clobber_abi("C"), const foo);
|
LL | asm!("{}", clobber_abi("C"), const foo);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const foo: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/parse-error.rs:50:55
|
--> $DIR/parse-error.rs:50:55
|
||||||
|
|
|
|
||||||
LL | let mut foo = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const foo`
|
|
||||||
...
|
|
||||||
LL | asm!("{}", options(), clobber_abi("C"), const foo);
|
LL | asm!("{}", options(), clobber_abi("C"), const foo);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const foo: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/parse-error.rs:52:31
|
--> $DIR/parse-error.rs:52:31
|
||||||
|
|
|
|
||||||
LL | let mut foo = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const foo`
|
|
||||||
...
|
|
||||||
LL | asm!("{a}", a = const foo, a = const bar);
|
LL | asm!("{a}", a = const foo, a = const bar);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const foo: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/parse-error.rs:52:46
|
--> $DIR/parse-error.rs:52:46
|
||||||
|
|
|
|
||||||
LL | let mut bar = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const bar`
|
|
||||||
...
|
|
||||||
LL | asm!("{a}", a = const foo, a = const bar);
|
LL | asm!("{a}", a = const foo, a = const bar);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const bar: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/parse-error.rs:59:45
|
--> $DIR/parse-error.rs:59:45
|
||||||
|
|
|
|
||||||
LL | let mut bar = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const bar`
|
|
||||||
...
|
|
||||||
LL | asm!("{a}", in("x0") foo, a = const bar);
|
LL | asm!("{a}", in("x0") foo, a = const bar);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const bar: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/parse-error.rs:61:45
|
--> $DIR/parse-error.rs:61:45
|
||||||
|
|
|
|
||||||
LL | let mut bar = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const bar`
|
|
||||||
...
|
|
||||||
LL | asm!("{a}", in("x0") foo, a = const bar);
|
LL | asm!("{a}", in("x0") foo, a = const bar);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const bar: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/parse-error.rs:63:41
|
--> $DIR/parse-error.rs:63:41
|
||||||
|
|
|
|
||||||
LL | let mut bar = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const bar`
|
|
||||||
...
|
|
||||||
LL | asm!("{1}", in("x0") foo, const bar);
|
LL | asm!("{1}", in("x0") foo, const bar);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const bar: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error: aborting due to 57 previous errors
|
error: aborting due to 57 previous errors
|
||||||
|
|
||||||
|
|
|
@ -371,47 +371,57 @@ LL | global_asm!("{}", label {});
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/parse-error.rs:39:37
|
--> $DIR/parse-error.rs:39:37
|
||||||
|
|
|
|
||||||
LL | let mut foo = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const foo`
|
|
||||||
...
|
|
||||||
LL | asm!("{}", options(), const foo);
|
LL | asm!("{}", options(), const foo);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const foo: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/parse-error.rs:71:44
|
--> $DIR/parse-error.rs:71:44
|
||||||
|
|
|
|
||||||
LL | let mut foo = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const foo`
|
|
||||||
...
|
|
||||||
LL | asm!("{}", clobber_abi("C"), const foo);
|
LL | asm!("{}", clobber_abi("C"), const foo);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const foo: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/parse-error.rs:74:55
|
--> $DIR/parse-error.rs:74:55
|
||||||
|
|
|
|
||||||
LL | let mut foo = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const foo`
|
|
||||||
...
|
|
||||||
LL | asm!("{}", options(), clobber_abi("C"), const foo);
|
LL | asm!("{}", options(), clobber_abi("C"), const foo);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const foo: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/parse-error.rs:76:31
|
--> $DIR/parse-error.rs:76:31
|
||||||
|
|
|
|
||||||
LL | let mut foo = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const foo`
|
|
||||||
...
|
|
||||||
LL | asm!("{a}", a = const foo, a = const bar);
|
LL | asm!("{a}", a = const foo, a = const bar);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const foo: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/parse-error.rs:76:46
|
--> $DIR/parse-error.rs:76:46
|
||||||
|
|
|
|
||||||
LL | let mut bar = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const bar`
|
|
||||||
...
|
|
||||||
LL | asm!("{a}", a = const foo, a = const bar);
|
LL | asm!("{a}", a = const foo, a = const bar);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const bar: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error: aborting due to 64 previous errors
|
error: aborting due to 64 previous errors
|
||||||
|
|
||||||
|
|
|
@ -1,29 +1,35 @@
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/type-check-1.rs:41:26
|
--> $DIR/type-check-1.rs:41:26
|
||||||
|
|
|
|
||||||
LL | let x = 0;
|
|
||||||
| ----- help: consider using `const` instead of `let`: `const x`
|
|
||||||
...
|
|
||||||
LL | asm!("{}", const x);
|
LL | asm!("{}", const x);
|
||||||
| ^ non-constant value
|
| ^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const x: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/type-check-1.rs:44:36
|
--> $DIR/type-check-1.rs:44:36
|
||||||
|
|
|
|
||||||
LL | let x = 0;
|
|
||||||
| ----- help: consider using `const` instead of `let`: `const x`
|
|
||||||
...
|
|
||||||
LL | asm!("{}", const const_foo(x));
|
LL | asm!("{}", const const_foo(x));
|
||||||
| ^ non-constant value
|
| ^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const x: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/type-check-1.rs:47:36
|
--> $DIR/type-check-1.rs:47:36
|
||||||
|
|
|
|
||||||
LL | let x = 0;
|
|
||||||
| ----- help: consider using `const` instead of `let`: `const x`
|
|
||||||
...
|
|
||||||
LL | asm!("{}", const const_bar(x));
|
LL | asm!("{}", const const_bar(x));
|
||||||
| ^ non-constant value
|
| ^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const x: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error: invalid `sym` operand
|
error: invalid `sym` operand
|
||||||
--> $DIR/type-check-1.rs:49:24
|
--> $DIR/type-check-1.rs:49:24
|
||||||
|
|
|
@ -15,29 +15,35 @@ LL | asm!("{1}", in("eax") foo, const bar);
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/x86_64_parse_error.rs:13:46
|
--> $DIR/x86_64_parse_error.rs:13:46
|
||||||
|
|
|
|
||||||
LL | let mut bar = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const bar`
|
|
||||||
...
|
|
||||||
LL | asm!("{a}", in("eax") foo, a = const bar);
|
LL | asm!("{a}", in("eax") foo, a = const bar);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const bar: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/x86_64_parse_error.rs:15:46
|
--> $DIR/x86_64_parse_error.rs:15:46
|
||||||
|
|
|
|
||||||
LL | let mut bar = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const bar`
|
|
||||||
...
|
|
||||||
LL | asm!("{a}", in("eax") foo, a = const bar);
|
LL | asm!("{a}", in("eax") foo, a = const bar);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const bar: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/x86_64_parse_error.rs:17:42
|
--> $DIR/x86_64_parse_error.rs:17:42
|
||||||
|
|
|
|
||||||
LL | let mut bar = 0;
|
|
||||||
| ----------- help: consider using `const` instead of `let`: `const bar`
|
|
||||||
...
|
|
||||||
LL | asm!("{1}", in("eax") foo, const bar);
|
LL | asm!("{1}", in("eax") foo, const bar);
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const bar: /* Type */ = 0;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/legacy-const-generics-bad.rs:7:35
|
--> $DIR/legacy-const-generics-bad.rs:7:35
|
||||||
|
|
|
|
||||||
LL | let a = 1;
|
|
||||||
| ----- help: consider using `const` instead of `let`: `const a`
|
|
||||||
LL | legacy_const_generics::foo(0, a, 2);
|
LL | legacy_const_generics::foo(0, a, 2);
|
||||||
| ^ non-constant value
|
| ^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const a: /* Type */ = 1;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error: generic parameters may not be used in const operations
|
error: generic parameters may not be used in const operations
|
||||||
--> $DIR/legacy-const-generics-bad.rs:12:35
|
--> $DIR/legacy-const-generics-bad.rs:12:35
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/issue-3521.rs:8:15
|
--> $DIR/issue-3521.rs:8:15
|
||||||
|
|
|
|
||||||
LL | let foo: isize = 100;
|
|
||||||
| ------- help: consider using `const` instead of `let`: `const foo`
|
|
||||||
...
|
|
||||||
LL | Bar = foo
|
LL | Bar = foo
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const foo: isize = 100;
|
||||||
|
| ~~~~~
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,24 @@
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/issue-91560.rs:10:19
|
--> $DIR/issue-91560.rs:10:19
|
||||||
|
|
|
|
||||||
LL | let mut length: usize = 2;
|
|
||||||
| -------------- help: consider using `const` instead of `let`: `const length`
|
|
||||||
LL |
|
|
||||||
LL | let arr = [0; length];
|
LL | let arr = [0; length];
|
||||||
| ^^^^^^ non-constant value
|
| ^^^^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const length: usize = 2;
|
||||||
|
| ~~~~~
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/issue-91560.rs:17:19
|
--> $DIR/issue-91560.rs:17:19
|
||||||
|
|
|
|
||||||
LL | let length: usize = 2;
|
|
||||||
| ------------ help: consider using `const` instead of `let`: `const length`
|
|
||||||
LL |
|
|
||||||
LL | let arr = [0; length];
|
LL | let arr = [0; length];
|
||||||
| ^^^^^^ non-constant value
|
| ^^^^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const length: usize = 2;
|
||||||
|
| ~~~~~
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -2,18 +2,23 @@ error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/non-const-value-in-const.rs:3:20
|
--> $DIR/non-const-value-in-const.rs:3:20
|
||||||
|
|
|
|
||||||
LL | const Y: i32 = x;
|
LL | const Y: i32 = x;
|
||||||
| ------- ^ non-constant value
|
| ^ non-constant value
|
||||||
| |
|
|
|
||||||
| help: consider using `let` instead of `const`: `let Y`
|
help: consider using `let` instead of `const`
|
||||||
|
|
|
||||||
|
LL | let Y: i32 = x;
|
||||||
|
| ~~~
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/non-const-value-in-const.rs:6:17
|
--> $DIR/non-const-value-in-const.rs:6:17
|
||||||
|
|
|
|
||||||
LL | let x = 5;
|
|
||||||
| ----- help: consider using `const` instead of `let`: `const x`
|
|
||||||
...
|
|
||||||
LL | let _ = [0; x];
|
LL | let _ = [0; x];
|
||||||
| ^ non-constant value
|
| ^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const x: /* Type */ = 5;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/E0435.rs:5:17
|
--> $DIR/E0435.rs:5:17
|
||||||
|
|
|
|
||||||
LL | let foo: usize = 42;
|
|
||||||
| ------- help: consider using `const` instead of `let`: `const foo`
|
|
||||||
LL | let _: [u8; foo];
|
LL | let _: [u8; foo];
|
||||||
| ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const foo: usize = 42;
|
||||||
|
| ~~~~~
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,12 @@ error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/issue-27433.rs:5:23
|
--> $DIR/issue-27433.rs:5:23
|
||||||
|
|
|
|
||||||
LL | const FOO : u32 = foo;
|
LL | const FOO : u32 = foo;
|
||||||
| --------- ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
| |
|
|
|
||||||
| help: consider using `let` instead of `const`: `let FOO`
|
help: consider using `let` instead of `const`
|
||||||
|
|
|
||||||
|
LL | let FOO : u32 = foo;
|
||||||
|
| ~~~
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,12 @@ error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/issue-3521-2.rs:5:23
|
--> $DIR/issue-3521-2.rs:5:23
|
||||||
|
|
|
|
||||||
LL | static y: isize = foo + 1;
|
LL | static y: isize = foo + 1;
|
||||||
| -------- ^^^ non-constant value
|
| ^^^ non-constant value
|
||||||
| |
|
|
|
||||||
| help: consider using `let` instead of `static`: `let y`
|
help: consider using `let` instead of `static`
|
||||||
|
|
|
||||||
|
LL | let y: isize = foo + 1;
|
||||||
|
| ~~~
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,12 @@ error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/issue-3668-2.rs:4:27
|
--> $DIR/issue-3668-2.rs:4:27
|
||||||
|
|
|
|
||||||
LL | static child: isize = x + 1;
|
LL | static child: isize = x + 1;
|
||||||
| ------------ ^ non-constant value
|
| ^ non-constant value
|
||||||
| |
|
|
|
||||||
| help: consider using `let` instead of `static`: `let child`
|
help: consider using `let` instead of `static`
|
||||||
|
|
|
||||||
|
LL | let child: isize = x + 1;
|
||||||
|
| ~~~
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,12 @@ error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/issue-3668.rs:8:34
|
--> $DIR/issue-3668.rs:8:34
|
||||||
|
|
|
|
||||||
LL | static childVal: Box<P> = self.child.get();
|
LL | static childVal: Box<P> = self.child.get();
|
||||||
| --------------- ^^^^ non-constant value
|
| ^^^^ non-constant value
|
||||||
| |
|
|
|
||||||
| help: consider using `let` instead of `static`: `let childVal`
|
help: consider using `let` instead of `static`
|
||||||
|
|
|
||||||
|
LL | let childVal: Box<P> = self.child.get();
|
||||||
|
| ~~~
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/issue-44239.rs:8:26
|
--> $DIR/issue-44239.rs:8:26
|
||||||
|
|
|
|
||||||
LL | let n: usize = 0;
|
|
||||||
| ----- help: consider using `const` instead of `let`: `const n`
|
|
||||||
...
|
|
||||||
LL | const N: usize = n;
|
LL | const N: usize = n;
|
||||||
| ^ non-constant value
|
| ^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const n: usize = 0;
|
||||||
|
| ~~~~~
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,12 @@ error: non-item in item list
|
||||||
--> $DIR/suggest-assoc-const.rs:5:5
|
--> $DIR/suggest-assoc-const.rs:5:5
|
||||||
|
|
|
|
||||||
LL | let _X: i32;
|
LL | let _X: i32;
|
||||||
| ^^^ help: consider using `const` instead of `let` for associated const: `const`
|
| ^^^
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let` for associated const
|
||||||
|
|
|
||||||
|
LL | const _X: i32;
|
||||||
|
| ~~~~~
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/repeat_count.rs:5:17
|
--> $DIR/repeat_count.rs:5:17
|
||||||
|
|
|
|
||||||
LL | let n = 1;
|
|
||||||
| ----- help: consider using `const` instead of `let`: `const n`
|
|
||||||
LL | let a = [0; n];
|
LL | let a = [0; n];
|
||||||
| ^ non-constant value
|
| ^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const n: /* Type */ = 1;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/repeat_count.rs:7:17
|
--> $DIR/repeat_count.rs:7:17
|
||||||
|
|
|
@ -2,9 +2,12 @@ error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/type-dependent-def-issue-49241.rs:3:22
|
--> $DIR/type-dependent-def-issue-49241.rs:3:22
|
||||||
|
|
|
|
||||||
LL | const l: usize = v.count();
|
LL | const l: usize = v.count();
|
||||||
| ------- ^ non-constant value
|
| ^ non-constant value
|
||||||
| |
|
|
|
||||||
| help: consider using `let` instead of `const`: `let l`
|
help: consider using `let` instead of `const`
|
||||||
|
|
|
||||||
|
LL | let l: usize = v.count();
|
||||||
|
| ~~~
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,24 @@
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/issue-42060.rs:3:23
|
--> $DIR/issue-42060.rs:3:23
|
||||||
|
|
|
|
||||||
LL | let thing = ();
|
|
||||||
| --------- help: consider using `const` instead of `let`: `const thing`
|
|
||||||
LL | let other: typeof(thing) = thing;
|
LL | let other: typeof(thing) = thing;
|
||||||
| ^^^^^ non-constant value
|
| ^^^^^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const thing: /* Type */ = ();
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0435]: attempt to use a non-constant value in a constant
|
error[E0435]: attempt to use a non-constant value in a constant
|
||||||
--> $DIR/issue-42060.rs:9:13
|
--> $DIR/issue-42060.rs:9:13
|
||||||
|
|
|
|
||||||
LL | let q = 1;
|
|
||||||
| ----- help: consider using `const` instead of `let`: `const q`
|
|
||||||
LL | <typeof(q)>::N
|
LL | <typeof(q)>::N
|
||||||
| ^ non-constant value
|
| ^ non-constant value
|
||||||
|
|
|
||||||
|
help: consider using `const` instead of `let`
|
||||||
|
|
|
||||||
|
LL | const q: /* Type */ = 1;
|
||||||
|
| ~~~~~ ++++++++++++
|
||||||
|
|
||||||
error[E0516]: `typeof` is a reserved keyword but unimplemented
|
error[E0516]: `typeof` is a reserved keyword but unimplemented
|
||||||
--> $DIR/issue-42060.rs:3:16
|
--> $DIR/issue-42060.rs:3:16
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue