| Age | Commit message (Collapse) | Author | Lines |
|
This optimization can result in unsoundness, because it introduces
additional uses of a place holding the discriminant value without
ensuring that it is valid to do so.
|
|
|
|
|
|
This didn't have an effect in most cases, and is not trivially sound.
Let it bake at `mir-opt-level=2` for a while.
|
|
|
|
Bypass const_item_mutation if const's type has Drop impl
Follow-up to #75573. This PR disables the const_item_mutation lint in cases that the const has a Drop impl which observes the mutation.
```rust
struct Log { msg: &'static str }
const LOG: Log = Log { msg: "" };
impl Drop for Log {
fn drop(&mut self) { println!("{}", self.msg); }
}
LOG.msg = "wow"; // prints "wow"
```
r? @Aaron1011
|
|
Rollup of 12 pull requests
Successful merges:
- #76101 (Update RELEASES.md for 1.47.0)
- #76739 (resolve: prohibit anon const non-static lifetimes)
- #76811 (Doc alias name restriction)
- #77405 (Add tracking issue of iter_advance_by feature)
- #77409 (Add example for iter chain struct)
- #77415 (Better error message for `async` blocks in a const-context)
- #77423 (Add `-Zprecise-enum-drop-elaboration`)
- #77432 (Use posix_spawn on musl targets)
- #77441 (Fix AVR stack corruption bug)
- #77442 (Clean up on example doc fixes for ptr::copy)
- #77444 (Fix span for incorrect pattern field and add label)
- #77453 (Stop running macOS builds on Azure Pipelines)
Failed merges:
r? `@ghost`
|
|
Better error message for `async` blocks in a const-context
Improves the error message for the case in #77361.
r? @oli-obk
|
|
|
|
|
|
The optimization still has some bugs that need to be worked out
such as #77359.
We can try re-enabling this again after the known issues are resolved.
|
|
|
|
|
|
Implement multiple return terminator optimization
Closes #72022
|
|
|
|
Overhaul const-checking diagnostics
The primary purpose of this PR was to remove `NonConstOp::STOPS_CONST_CHECKING`, which causes any additional errors found by the const-checker to be silenced. I used this flag to preserve diagnostic parity with `qualify_min_const_fn.rs`, which has since been removed.
However, simply removing the flag caused a deluge of errors in some cases, since an error would be emitted any time a local or temporary had a wrong type. To remedy this, I added an alternative system (`DiagnosticImportance`) to silence additional error messages that were likely to distract the user from the underlying issue. When an error of the highest importance occurs, all less important errors are silenced. When no error of the highest importance occurs, all less important errors are emitted after checking is complete. Following the suggestions from the important error is usually enough to fix the less important errors, so this should lead to better UX most of the time.
There's also some unrelated diagnostics improvements in this PR isolated in their own commits. Splitting them out would be possible, but a bit of a pain. This isn't as tidy as some of my other PRs, but it should *only* affect diagnostics, never whether or not something passes const-checking. Note that there are a few trivial exceptions to this, like banning `Yield` in all const-contexts, not just `const fn`.
As always, meant to be reviewed commit-by-commit.
r? `@oli-obk`
|
|
|
|
adt_destructor by default also validates the Drop impl using
dropck::check_drop_impl, which contains an expect_local(). This
leads to ICE in check_const_item_mutation if the const's type is
not a local type.
thread 'rustc' panicked at 'DefId::expect_local: `DefId(5:4805 ~ alloc[d7e9]::vec::{impl#50})` isn't local', compiler/rustc_span/src/def_id.rs:174:43
stack backtrace:
0: rust_begin_unwind
1: rustc_span::def_id::DefId::expect_local::{{closure}}
2: rustc_typeck::check::dropck::check_drop_impl
3: rustc_middle::ty::util::<impl rustc_middle::ty::context::TyCtxt>::calculate_dtor::{{closure}}
4: rustc_middle::ty::trait_def::<impl rustc_middle::ty::context::TyCtxt>::for_each_relevant_impl
5: rustc_middle::ty::util::<impl rustc_middle::ty::context::TyCtxt>::calculate_dtor
6: rustc_typeck::check::adt_destructor
7: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::adt_destructor>::compute
8: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
9: rustc_query_system::query::plumbing::get_query_impl
10: rustc_mir::transform::check_const_item_mutation::ConstMutationChecker::is_const_item_without_destructor
|
|
|
|
|
|
|
|
Validate `rustc_args_required_const`
Fixes https://github.com/rust-lang/rust/issues/74608.
|
|
Don't fire `const_item_mutation` lint on writes through a pointer
Fixes #77321
|
|
more tiny clippy cleanups
commits stand alone and can be reviewed one by one
|
|
|
|
`def_span` has the same issues as `body.span`, so do it this way instead.
|
|
|
|
Now all structured errors must have their own error code
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This helper function was meant to reduce code duplication between
const-checking pre- and post-drop-elaboration. Most of the functionality
is only relevant for the pre-drop-elaboration pass.
|
|
The "otherwise" note is printed before the suggestion currently.
|
|
This ensures that `emit_error` will actually cause compilation to fail.
|
|
|
|
This errors during AST lowering. Any errors we emit here are just noise.
|
|
|
|
This doesn't change any UI test output
|
|
Fixes #77321
|
|
Rollup of 7 pull requests
Successful merges:
- #76454 (UI to unit test for those using Cell/RefCell/UnsafeCell)
- #76474 (Add option to pass a custom codegen backend from a driver)
- #76711 (diag: improve closure/generic parameter mismatch)
- #77170 (Remove `#[rustc_allow_const_fn_ptr]` and add `#![feature(const_fn_fn_ptr_basics)]`)
- #77194 (Add doc alias for iterator fold)
- #77288 (fix building libstd for Miri on macOS)
- #77295 (Update unstable-book: Fix ABNF in inline assembly docs)
Failed merges:
r? `@ghost`
|
|
Remove `#[rustc_allow_const_fn_ptr]` and add `#![feature(const_fn_fn_ptr_basics)]`
`rustc_allow_const_fn_ptr` was a hack to work around the lack of an escape hatch for the "min `const fn`" checks in const-stable functions. Now that we have co-opted `allow_internal_unstable` for this purpose, we no longer need a bespoke attribute.
Now this functionality is gated under `const_fn_fn_ptr_basics` (how concise!), and `#[allow_internal_unstable(const_fn_fn_ptr_basics)]` replaces `#[rustc_allow_const_fn_ptr]`. `const_fn_fn_ptr_basics` allows function pointer types to appear in the arguments and locals of a `const fn` as well as function pointer casts to be performed inside a `const fn`. Both of these were allowed in constants and statics already. Notably, this does **not** allow users to invoke function pointers in a const context. Presumably, we will use a nicer name for that (`const_fn_ptr`?).
r? @oli-obk
|
|
|
|
|
|
Check for missing const-stability attributes in `rustc_passes`
Currently, this happens as a side effect of `is_min_const_fn`, which is non-obvious. Also adds a test for this case, since we didn't seem to have one before.
|
|
Move helper function for `missing_const_for_fn` out of rustc to clippy
cc @rust-lang/clippy @ecstatic-morse #76618
r? @Manishearth
I also removed all support for suggesting a function could be `const fn` when that would require feature gates to actually work.
This means we'll now have to maintain this ourselves in clippy, but that's how most lints work anyway, so...
|
|
Enable const propagation into operands at mir_opt_level=2
Feature was added in #74507 but gated with `mir_opt_level>=3` because of compile time regressions. Let's see whether the LLVM 11 update solves that.
As the [perf results](https://github.com/rust-lang/rust/pull/77107#issuecomment-697668154) show, enabling this optimization results in a lot less regression as before.
cc @oli-obk
r? @ghost
|