mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Make error messages great again (and fix clippy and add test)
This commit is contained in:
parent
191d3b76db
commit
898c76cd82
@ -366,7 +366,7 @@ fn typeck_with_fallback<'tcx>(
|
||||
|
||||
let typeck_results = Inherited::build(tcx, def_id).enter(|inh| {
|
||||
let param_env = tcx.param_env(def_id);
|
||||
let fcx = if let Some(hir::FnSig { header, decl, .. }) = fn_sig {
|
||||
let mut fcx = if let Some(hir::FnSig { header, decl, .. }) = fn_sig {
|
||||
let fn_sig = if crate::collect::get_infer_ret_ty(&decl.output).is_some() {
|
||||
let fcx = FnCtxt::new(&inh, param_env, body.value.hir_id);
|
||||
<dyn AstConv<'_>>::ty_of_fn(&fcx, id, header.unsafety, header.abi, decl, None, None)
|
||||
@ -459,7 +459,11 @@ fn typeck_with_fallback<'tcx>(
|
||||
|
||||
// Closure and generator analysis may run after fallback
|
||||
// because they don't constrain other type variables.
|
||||
// Closure analysis only runs on closures. Therefore they only need to fulfill non-const predicates (as of now)
|
||||
let prev_constness = fcx.param_env.constness();
|
||||
fcx.param_env = fcx.param_env.without_const();
|
||||
fcx.closure_analyze(body);
|
||||
fcx.param_env = fcx.param_env.with_constness(prev_constness);
|
||||
assert!(fcx.deferred_call_resolutions.borrow().is_empty());
|
||||
// Before the generator analysis, temporary scopes shall be marked to provide more
|
||||
// precise information on types to be captured.
|
||||
|
@ -1,6 +1,6 @@
|
||||
struct X<const N: usize = {
|
||||
(||1usize)()
|
||||
//~^ ERROR the trait bound
|
||||
//~^ ERROR cannot call non-const closure
|
||||
}>;
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,17 +1,12 @@
|
||||
error[E0277]: the trait bound `[closure@$DIR/issue-93647.rs:2:6: 2:8]: Fn<()>` is not satisfied
|
||||
--> $DIR/issue-93647.rs:2:5
|
||||
|
|
||||
LL | (||1usize)()
|
||||
| ^^^^^^^^^^^^ expected an `Fn<()>` closure, found `[closure@$DIR/issue-93647.rs:2:6: 2:8]`
|
||||
|
|
||||
= help: the trait `~const Fn<()>` is not implemented for closure `[closure@$DIR/issue-93647.rs:2:6: 2:8]`
|
||||
note: the trait `Fn<()>` is implemented for `[closure@$DIR/issue-93647.rs:2:6: 2:8]`, but that implementation is not `const`
|
||||
error[E0015]: cannot call non-const closure in constants
|
||||
--> $DIR/issue-93647.rs:2:5
|
||||
|
|
||||
LL | (||1usize)()
|
||||
| ^^^^^^^^^^^^
|
||||
= note: wrap the `[closure@$DIR/issue-93647.rs:2:6: 2:8]` in a closure with no arguments: `|| { /* code */ }`
|
||||
|
|
||||
= note: closures need an RFC before allowed to be called in constants
|
||||
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
For more information about this error, try `rustc --explain E0015`.
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
const X: u8 =
|
||||
|| -> u8 { 5 }()
|
||||
//~^ ERROR the trait bound
|
||||
//~^ ERROR cannot call non-const closure
|
||||
;
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,17 +1,12 @@
|
||||
error[E0277]: the trait bound `[closure@$DIR/issue-28113.rs:4:5: 4:13]: Fn<()>` is not satisfied
|
||||
--> $DIR/issue-28113.rs:4:5
|
||||
|
|
||||
LL | || -> u8 { 5 }()
|
||||
| ^^^^^^^^^^^^^^^^ expected an `Fn<()>` closure, found `[closure@$DIR/issue-28113.rs:4:5: 4:13]`
|
||||
|
|
||||
= help: the trait `~const Fn<()>` is not implemented for closure `[closure@$DIR/issue-28113.rs:4:5: 4:13]`
|
||||
note: the trait `Fn<()>` is implemented for `[closure@$DIR/issue-28113.rs:4:5: 4:13]`, but that implementation is not `const`
|
||||
error[E0015]: cannot call non-const closure in constants
|
||||
--> $DIR/issue-28113.rs:4:5
|
||||
|
|
||||
LL | || -> u8 { 5 }()
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
= note: wrap the `[closure@$DIR/issue-28113.rs:4:5: 4:13]` in a closure with no arguments: `|| { /* code */ }`
|
||||
|
|
||||
= note: closures need an RFC before allowed to be called in constants
|
||||
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
For more information about this error, try `rustc --explain E0015`.
|
||||
|
@ -1,8 +1,11 @@
|
||||
const fn foo() { (||{})() }
|
||||
//~^ ERROR the trait bound
|
||||
//~^ ERROR cannot call non-const closure
|
||||
//~| ERROR erroneous constant
|
||||
//~| WARN this was previously accepted
|
||||
|
||||
const fn bad(input: fn()) {
|
||||
input()
|
||||
//~^ ERROR function pointer calls are not allowed
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
@ -1,17 +1,39 @@
|
||||
error[E0277]: the trait bound `[closure@$DIR/issue-56164.rs:1:19: 1:21]: Fn<()>` is not satisfied
|
||||
--> $DIR/issue-56164.rs:1:18
|
||||
|
|
||||
LL | const fn foo() { (||{})() }
|
||||
| ^^^^^^^^ expected an `Fn<()>` closure, found `[closure@$DIR/issue-56164.rs:1:19: 1:21]`
|
||||
|
|
||||
= help: the trait `~const Fn<()>` is not implemented for closure `[closure@$DIR/issue-56164.rs:1:19: 1:21]`
|
||||
note: the trait `Fn<()>` is implemented for `[closure@$DIR/issue-56164.rs:1:19: 1:21]`, but that implementation is not `const`
|
||||
error[E0015]: cannot call non-const closure in constant functions
|
||||
--> $DIR/issue-56164.rs:1:18
|
||||
|
|
||||
LL | const fn foo() { (||{})() }
|
||||
| ^^^^^^^^
|
||||
= note: wrap the `[closure@$DIR/issue-56164.rs:1:19: 1:21]` in a closure with no arguments: `|| { /* code */ }`
|
||||
|
|
||||
= note: closures need an RFC before allowed to be called in constant functions
|
||||
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||
|
||||
error: aborting due to previous error
|
||||
error: function pointer calls are not allowed in constant functions
|
||||
--> $DIR/issue-56164.rs:7:5
|
||||
|
|
||||
LL | input()
|
||||
| ^^^^^^^
|
||||
|
||||
error: erroneous constant used
|
||||
--> $DIR/issue-56164.rs:1:18
|
||||
|
|
||||
LL | const fn foo() { (||{})() }
|
||||
| ^^^^^^ referenced constant has errors
|
||||
|
|
||||
= note: `#[deny(const_err)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0015`.
|
||||
Future incompatibility report: Future breakage diagnostic:
|
||||
error: erroneous constant used
|
||||
--> $DIR/issue-56164.rs:1:18
|
||||
|
|
||||
LL | const fn foo() { (||{})() }
|
||||
| ^^^^^^ referenced constant has errors
|
||||
|
|
||||
= note: `#[deny(const_err)]` on by default
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800>
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
@ -3,7 +3,7 @@
|
||||
// in the length part of an array.
|
||||
|
||||
struct Bug {
|
||||
a: [(); (|| { 0 })()] //~ ERROR the trait bound
|
||||
a: [(); (|| { 0 })()] //~ ERROR cannot call non-const closure
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
@ -1,17 +1,12 @@
|
||||
error[E0277]: the trait bound `[closure@$DIR/issue-68542-closure-in-array-len.rs:6:14: 6:16]: Fn<()>` is not satisfied
|
||||
--> $DIR/issue-68542-closure-in-array-len.rs:6:13
|
||||
|
|
||||
LL | a: [(); (|| { 0 })()]
|
||||
| ^^^^^^^^^^^^ expected an `Fn<()>` closure, found `[closure@$DIR/issue-68542-closure-in-array-len.rs:6:14: 6:16]`
|
||||
|
|
||||
= help: the trait `~const Fn<()>` is not implemented for closure `[closure@$DIR/issue-68542-closure-in-array-len.rs:6:14: 6:16]`
|
||||
note: the trait `Fn<()>` is implemented for `[closure@$DIR/issue-68542-closure-in-array-len.rs:6:14: 6:16]`, but that implementation is not `const`
|
||||
error[E0015]: cannot call non-const closure in constants
|
||||
--> $DIR/issue-68542-closure-in-array-len.rs:6:13
|
||||
|
|
||||
LL | a: [(); (|| { 0 })()]
|
||||
| ^^^^^^^^^^^^
|
||||
= note: wrap the `[closure@$DIR/issue-68542-closure-in-array-len.rs:6:14: 6:16]` in a closure with no arguments: `|| { /* code */ }`
|
||||
|
|
||||
= note: closures need an RFC before allowed to be called in constants
|
||||
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
For more information about this error, try `rustc --explain E0015`.
|
||||
|
12
src/test/ui/rfc-2632-const-trait-impl/nested-closure.rs
Normal file
12
src/test/ui/rfc-2632-const-trait-impl/nested-closure.rs
Normal file
@ -0,0 +1,12 @@
|
||||
// check-pass
|
||||
|
||||
#![feature(const_trait_impl, once_cell)]
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
static EXTERN_FLAGS: LazyLock<String> = LazyLock::new(|| {
|
||||
let x = || String::new();
|
||||
x()
|
||||
});
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user