Auto merge of #151924 - JonathanBrouwer:rollup-Pqp8PIn, r=JonathanBrouwer
Rollup of 5 pull requests Successful merges: - rust-lang/rust#151886 (Skip unused_allocation lint when method takes &Box<Self>) - rust-lang/rust#150300 (Constify `fmt::from_fn`) - rust-lang/rust#151102 (Feature-gate `mut ref` patterns in struct pattern field shorthand) - rust-lang/rust#151866 (Reorganizing `tests/ui/issues` 10 tests [4/N] ) - rust-lang/rust#151890 (Re-export `hashbrown::hash_table` from `rustc_data_structures`)
This commit is contained in:
commit
a1db344c08
29 changed files with 114 additions and 30 deletions
|
|
@ -4354,7 +4354,6 @@ name = "rustc_mir_transform"
|
|||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"either",
|
||||
"hashbrown 0.16.1",
|
||||
"itertools",
|
||||
"rustc_abi",
|
||||
"rustc_arena",
|
||||
|
|
@ -4565,7 +4564,6 @@ dependencies = [
|
|||
name = "rustc_query_system"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"hashbrown 0.16.1",
|
||||
"parking_lot",
|
||||
"rustc_abi",
|
||||
"rustc_ast",
|
||||
|
|
|
|||
|
|
@ -49,6 +49,10 @@ pub use std::{assert_matches, debug_assert_matches};
|
|||
|
||||
pub use atomic_ref::AtomicRef;
|
||||
pub use ena::{snapshot_vec, undo_log, unify};
|
||||
// Re-export `hashbrown::hash_table`, because it's part of our API
|
||||
// (via `ShardedHashMap`), and because it lets other compiler crates use the
|
||||
// lower-level `HashTable` API without a tricky `hashbrown` dependency.
|
||||
pub use hashbrown::hash_table;
|
||||
pub use rustc_index::static_assert_size;
|
||||
// Re-export some data-structure crates which are part of our public API.
|
||||
pub use {either, indexmap, smallvec, thin_vec};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::hash::{Hash, Hasher};
|
|||
use std::{iter, mem};
|
||||
|
||||
use either::Either;
|
||||
use hashbrown::hash_table::{Entry, HashTable};
|
||||
use hashbrown::hash_table::{self, Entry, HashTable};
|
||||
|
||||
use crate::fx::FxHasher;
|
||||
use crate::sync::{CacheAligned, Lock, LockGuard, Mode, is_dyn_thread_safe};
|
||||
|
|
@ -140,7 +140,7 @@ pub fn shards() -> usize {
|
|||
1
|
||||
}
|
||||
|
||||
pub type ShardedHashMap<K, V> = Sharded<HashTable<(K, V)>>;
|
||||
pub type ShardedHashMap<K, V> = Sharded<hash_table::HashTable<(K, V)>>;
|
||||
|
||||
impl<K: Eq, V> ShardedHashMap<K, V> {
|
||||
pub fn with_capacity(cap: usize) -> Self {
|
||||
|
|
|
|||
|
|
@ -1785,7 +1785,7 @@ declare_lint! {
|
|||
declare_lint_pass!(UnusedAllocation => [UNUSED_ALLOCATION]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for UnusedAllocation {
|
||||
fn check_expr(&mut self, cx: &LateContext<'_>, e: &hir::Expr<'_>) {
|
||||
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &hir::Expr<'_>) {
|
||||
match e.kind {
|
||||
hir::ExprKind::Call(path_expr, [_])
|
||||
if let hir::ExprKind::Path(qpath) = &path_expr.kind
|
||||
|
|
@ -1796,6 +1796,12 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAllocation {
|
|||
|
||||
for adj in cx.typeck_results().expr_adjustments(e) {
|
||||
if let adjustment::Adjust::Borrow(adjustment::AutoBorrow::Ref(m)) = adj.kind {
|
||||
if let ty::Ref(_, inner_ty, _) = adj.target.kind()
|
||||
&& inner_ty.is_box()
|
||||
{
|
||||
// If the target type is `&Box<T>` or `&mut Box<T>`, the allocation is necessary
|
||||
continue;
|
||||
}
|
||||
match m {
|
||||
adjustment::AutoBorrowMutability::Not => {
|
||||
cx.emit_span_lint(UNUSED_ALLOCATION, e.span, UnusedAllocationDiag);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ edition = "2024"
|
|||
[dependencies]
|
||||
# tidy-alphabetical-start
|
||||
either = "1"
|
||||
hashbrown = { version = "0.16.1", default-features = false }
|
||||
itertools = "0.12"
|
||||
rustc_abi = { path = "../rustc_abi" }
|
||||
rustc_arena = { path = "../rustc_arena" }
|
||||
|
|
|
|||
|
|
@ -88,7 +88,6 @@ use std::borrow::Cow;
|
|||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use either::Either;
|
||||
use hashbrown::hash_table::{Entry, HashTable};
|
||||
use itertools::Itertools as _;
|
||||
use rustc_abi::{self as abi, BackendRepr, FIRST_VARIANT, FieldIdx, Primitive, Size, VariantIdx};
|
||||
use rustc_arena::DroplessArena;
|
||||
|
|
@ -99,6 +98,7 @@ use rustc_const_eval::interpret::{
|
|||
};
|
||||
use rustc_data_structures::fx::FxHasher;
|
||||
use rustc_data_structures::graph::dominators::Dominators;
|
||||
use rustc_data_structures::hash_table::{Entry, HashTable};
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_index::bit_set::DenseBitSet;
|
||||
use rustc_index::{IndexVec, newtype_index};
|
||||
|
|
|
|||
|
|
@ -1749,6 +1749,12 @@ impl<'a> Parser<'a> {
|
|||
hi = self.prev_token.span;
|
||||
let ann = BindingMode(by_ref, mutability);
|
||||
let fieldpat = self.mk_pat_ident(boxed_span.to(hi), ann, fieldname);
|
||||
if matches!(
|
||||
fieldpat.kind,
|
||||
PatKind::Ident(BindingMode(ByRef::Yes(..), Mutability::Mut), ..)
|
||||
) {
|
||||
self.psess.gated_spans.gate(sym::mut_ref, fieldpat.span);
|
||||
}
|
||||
let subpat = if is_box {
|
||||
self.mk_pat(lo.to(hi), PatKind::Box(Box::new(fieldpat)))
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -23,8 +23,3 @@ rustc_thread_pool = { path = "../rustc_thread_pool" }
|
|||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||
tracing = "0.1"
|
||||
# tidy-alphabetical-end
|
||||
|
||||
[dependencies.hashbrown]
|
||||
version = "0.16.1"
|
||||
default-features = false
|
||||
features = ["nightly"] # for may_dangle
|
||||
|
|
|
|||
|
|
@ -7,9 +7,8 @@ use std::fmt::Debug;
|
|||
use std::hash::Hash;
|
||||
use std::mem;
|
||||
|
||||
use hashbrown::HashTable;
|
||||
use hashbrown::hash_table::Entry;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::hash_table::{self, Entry, HashTable};
|
||||
use rustc_data_structures::sharded::{self, Sharded};
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_data_structures::sync::LockGuard;
|
||||
|
|
@ -35,7 +34,7 @@ fn equivalent_key<K: Eq, V>(k: &K) -> impl Fn(&(K, V)) -> bool + '_ {
|
|||
}
|
||||
|
||||
pub struct QueryState<'tcx, K> {
|
||||
active: Sharded<hashbrown::HashTable<(K, QueryResult<'tcx>)>>,
|
||||
active: Sharded<hash_table::HashTable<(K, QueryResult<'tcx>)>>,
|
||||
}
|
||||
|
||||
/// Indicates the state of a query for a given key in a query map.
|
||||
|
|
|
|||
|
|
@ -1227,8 +1227,9 @@ impl<'a, 'b: 'a> DebugMap<'a, 'b> {
|
|||
/// assert_eq!(format!("{:?}", wrapped), "'a'");
|
||||
/// ```
|
||||
#[stable(feature = "fmt_from_fn", since = "1.93.0")]
|
||||
#[rustc_const_stable(feature = "const_fmt_from_fn", since = "CURRENT_RUSTC_VERSION")]
|
||||
#[must_use = "returns a type implementing Debug and Display, which do not have any effects unless they are used"]
|
||||
pub fn from_fn<F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result>(f: F) -> FromFn<F> {
|
||||
pub const fn from_fn<F: Fn(&mut fmt::Formatter<'_>) -> fmt::Result>(f: F) -> FromFn<F> {
|
||||
FromFn(f)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//! regression test for <https://github.com/rust-lang/rust/issues/31267>
|
||||
//@ run-pass
|
||||
// Regression test for issue #31267
|
||||
|
||||
|
||||
struct Foo;
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
//! regression test for <https://github.com/rust-lang/rust/issues/49824>
|
||||
fn main() {
|
||||
let mut x = 0;
|
||||
|| {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
error: captured variable cannot escape `FnMut` closure body
|
||||
--> $DIR/issue-49824.rs:4:9
|
||||
--> $DIR/nested-closure-escape-borrow.rs:5:9
|
||||
|
|
||||
LL | let mut x = 0;
|
||||
| ----- variable defined here
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
//! regression test for <https://github.com/rust-lang/rust/issues/17651>
|
||||
// Test that moves of unsized values within closures are caught
|
||||
// and rejected.
|
||||
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0277]: the size for values of type `[{integer}]` cannot be known at compilation time
|
||||
--> $DIR/issue-17651.rs:5:18
|
||||
--> $DIR/unsized_value_move.rs:6:18
|
||||
|
|
||||
LL | (|| Box::new(*(&[0][..])))();
|
||||
| -------- ^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
//! regression test for <https://github.com/rust-lang/rust/issues/18767>
|
||||
//@ run-pass
|
||||
// Test that regionck uses the right memcat for patterns in for loops
|
||||
// and doesn't ICE.
|
||||
|
|
@ -10,4 +10,7 @@ fn main() {
|
|||
let mut ref x = 10; //~ ERROR [E0658]
|
||||
#[cfg(false)]
|
||||
let mut ref mut y = 10; //~ ERROR [E0658]
|
||||
|
||||
struct Foo { x: i32 }
|
||||
let Foo { mut ref x } = Foo { x: 10 }; //~ ERROR [E0658]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,16 @@ LL | let mut ref mut y = 10;
|
|||
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error[E0658]: mutable by-reference bindings are experimental
|
||||
--> $DIR/feature-gate-mut-ref.rs:15:15
|
||||
|
|
||||
LL | let Foo { mut ref x } = Foo { x: 10 };
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
= note: see issue #123076 <https://github.com/rust-lang/rust/issues/123076> for more information
|
||||
= help: add `#![feature(mut_ref)]` to the crate attributes to enable
|
||||
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
//@ check-pass
|
||||
// Test for issue #151846: unused_allocation warning should ignore
|
||||
// allocations to pass Box to things taking self: &Box
|
||||
|
||||
#![deny(unused_allocation)]
|
||||
|
||||
struct MyStruct;
|
||||
|
||||
trait TraitTakesBoxRef {
|
||||
fn trait_takes_box_ref(&self);
|
||||
}
|
||||
|
||||
impl TraitTakesBoxRef for Box<MyStruct> {
|
||||
fn trait_takes_box_ref(&self) {}
|
||||
}
|
||||
|
||||
impl MyStruct {
|
||||
fn inherent_takes_box_ref(self: &Box<Self>) {}
|
||||
}
|
||||
|
||||
fn takes_box_ref(_: &Box<MyStruct>) {}
|
||||
|
||||
trait TraitTakesBoxVal {
|
||||
fn trait_takes_box_val(self);
|
||||
}
|
||||
|
||||
impl TraitTakesBoxVal for Box<MyStruct> {
|
||||
fn trait_takes_box_val(self) {}
|
||||
}
|
||||
|
||||
impl MyStruct {
|
||||
fn inherent_takes_box_val(self: Box<Self>) {}
|
||||
}
|
||||
|
||||
fn takes_box_val(_: Box<MyStruct>) {}
|
||||
|
||||
pub fn foo() {
|
||||
// These should NOT warn - the allocation is necessary because
|
||||
// the method takes &Box<Self>
|
||||
Box::new(MyStruct).trait_takes_box_ref();
|
||||
Box::new(MyStruct).inherent_takes_box_ref();
|
||||
takes_box_ref(&Box::new(MyStruct));
|
||||
|
||||
// These already don't warn - the allocation is necessary
|
||||
Box::new(MyStruct).trait_takes_box_val();
|
||||
Box::new(MyStruct).inherent_takes_box_val();
|
||||
takes_box_val(Box::new(MyStruct));
|
||||
|
||||
// Fully-qualified syntax also does not warn:
|
||||
<Box<MyStruct> as TraitTakesBoxRef>::trait_takes_box_ref(&Box::new(MyStruct));
|
||||
MyStruct::inherent_takes_box_ref(&Box::new(MyStruct));
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
//! regression test for <https://github.com/rust-lang/rust/issues/34569>
|
||||
//@ run-pass
|
||||
//@ compile-flags:-g
|
||||
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
//! regression test for <https://github.com/rust-lang/rust/issues/29740>
|
||||
//@ check-pass
|
||||
#![allow(dead_code)]
|
||||
// Regression test for #29740. Inefficient MIR matching algorithms
|
||||
// generated way too much code for this sort of case, leading to OOM.
|
||||
// Inefficient MIR matching algorithms generated way
|
||||
// too much code for this sort of case, leading to OOM.
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
pub mod KeyboardEventConstants {
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
//! regression test for <https://github.com/rust-lang/rust/issues/32004>
|
||||
enum Foo {
|
||||
Bar(i32),
|
||||
Baz
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0532]: expected unit struct, unit variant or constant, found tuple variant `Foo::Bar`
|
||||
--> $DIR/issue-32004.rs:10:9
|
||||
--> $DIR/constructor-type-mismatch.rs:11:9
|
||||
|
|
||||
LL | Bar(i32),
|
||||
| -------- `Foo::Bar` defined here
|
||||
|
|
@ -20,7 +20,7 @@ LL + Foo::Baz => {}
|
|||
|
|
||||
|
||||
error[E0532]: expected tuple struct or tuple variant, found unit struct `S`
|
||||
--> $DIR/issue-32004.rs:16:9
|
||||
--> $DIR/constructor-type-mismatch.rs:17:9
|
||||
|
|
||||
LL | struct S;
|
||||
| --------- `S` defined here
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
//! regression test for <https://github.com/rust-lang/rust/issues/3038>
|
||||
enum F { G(isize, isize) }
|
||||
|
||||
enum H { I(J, K) }
|
||||
|
|
@ -1,17 +1,17 @@
|
|||
error[E0416]: identifier `x` is bound more than once in the same pattern
|
||||
--> $DIR/issue-3038.rs:12:15
|
||||
--> $DIR/multiple-bindings-on-var.rs:13:15
|
||||
|
|
||||
LL | F::G(x, x) => { println!("{}", x + x); }
|
||||
| ^ used in a pattern more than once
|
||||
|
||||
error[E0416]: identifier `x` is bound more than once in the same pattern
|
||||
--> $DIR/issue-3038.rs:17:32
|
||||
--> $DIR/multiple-bindings-on-var.rs:18:32
|
||||
|
|
||||
LL | H::I(J::L(x, _), K::M(_, x))
|
||||
| ^ used in a pattern more than once
|
||||
|
||||
error[E0416]: identifier `x` is bound more than once in the same pattern
|
||||
--> $DIR/issue-3038.rs:23:13
|
||||
--> $DIR/multiple-bindings-on-var.rs:24:13
|
||||
|
|
||||
LL | (x, x) => { x }
|
||||
| ^ used in a pattern more than once
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
//! regression test for <https://github.com/rust-lang/rust/issues/2849>
|
||||
enum Foo { Alpha, Beta(isize) }
|
||||
|
||||
fn main() {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0408]: variable `i` is not bound in all patterns
|
||||
--> $DIR/issue-2849.rs:5:7
|
||||
--> $DIR/or-pattern-binding-mismatch.rs:6:7
|
||||
|
|
||||
LL | Foo::Alpha | Foo::Beta(i) => {}
|
||||
| ^^^^^^^^^^ - variable not in all patterns
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
//! regression test for <https://github.com/rust-lang/rust/issues/2848>
|
||||
#[allow(non_camel_case_types)]
|
||||
|
||||
mod bar {
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0408]: variable `beta` is not bound in all patterns
|
||||
--> $DIR/issue-2848.rs:14:7
|
||||
--> $DIR/or-pattern-mismatched-variable-and-variant.rs:15:7
|
||||
|
|
||||
LL | alpha | beta => {}
|
||||
| ^^^^^ ---- variable not in all patterns
|
||||
|
|
@ -7,7 +7,7 @@ LL | alpha | beta => {}
|
|||
| pattern doesn't bind `beta`
|
||||
|
||||
error[E0170]: pattern binding `beta` is named the same as one of the variants of the type `bar::foo`
|
||||
--> $DIR/issue-2848.rs:14:15
|
||||
--> $DIR/or-pattern-mismatched-variable-and-variant.rs:15:15
|
||||
|
|
||||
LL | alpha | beta => {}
|
||||
| ^^^^ help: to match on the variant, qualify the path: `bar::foo::beta`
|
||||
Loading…
Add table
Add a link
Reference in a new issue