Skip to content

Commit

Permalink
Auto merge of rust-lang#135609 - cuviper:beta-next, r=cuviper
Browse files Browse the repository at this point in the history
[beta] backports

- do not in-place-iterate over flatmap/flatten rust-lang#135104
- Make sure to mark `IMPL_TRAIT_REDUNDANT_CAPTURES` as `Allow` in edition 2024 rust-lang#135441
- Update to LLVM 19.1.7 rust-lang#135484

r? cuviper
  • Loading branch information
bors committed Jan 17, 2025
2 parents d0d224d + 1c85981 commit 752fecf
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 64 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/impl_trait_overcaptures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ declare_lint! {
/// To fix this, remove the `use<'a>`, since the lifetime is already captured
/// since it is in scope.
pub IMPL_TRAIT_REDUNDANT_CAPTURES,
Warn,
Allow,
"redundant precise-capturing `use<...>` syntax on an `impl Trait`",
}

Expand Down
39 changes: 20 additions & 19 deletions library/alloc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,22 +1204,16 @@ fn test_from_iter_specialization_with_iterator_adapters() {
#[test]
fn test_in_place_specialization_step_up_down() {
fn assert_in_place_trait<T: InPlaceIterable>(_: &T) {}
let src = vec![[0u8; 4]; 256];
let srcptr = src.as_ptr();
let src_cap = src.capacity();
let iter = src.into_iter().flatten();
assert_in_place_trait(&iter);
let sink = iter.collect::<Vec<_>>();
let sinkptr = sink.as_ptr();
assert_eq!(srcptr as *const u8, sinkptr);
assert_eq!(src_cap * 4, sink.capacity());

let iter = sink.into_iter().array_chunks::<4>();
let src = vec![0u8; 1024];
let srcptr = src.as_ptr();
let src_bytes = src.capacity();
let iter = src.into_iter().array_chunks::<4>();
assert_in_place_trait(&iter);
let sink = iter.collect::<Vec<_>>();
let sinkptr = sink.as_ptr();
assert_eq!(srcptr, sinkptr);
assert_eq!(src_cap, sink.capacity());
assert_eq!(srcptr.addr(), sinkptr.addr());
assert_eq!(src_bytes, sink.capacity() * 4);

let mut src: Vec<u8> = Vec::with_capacity(17);
let src_bytes = src.capacity();
Expand All @@ -1236,13 +1230,6 @@ fn test_in_place_specialization_step_up_down() {
let sink: Vec<[u8; 2]> = iter.collect();
assert_eq!(sink.len(), 8);
assert!(sink.capacity() <= 25);

let src = vec![[0u8; 4]; 256];
let srcptr = src.as_ptr();
let iter = src.into_iter().flat_map(|a| a.into_iter().map(|b| b.wrapping_add(1)));
assert_in_place_trait(&iter);
let sink = iter.collect::<Vec<_>>();
assert_eq!(srcptr as *const u8, sink.as_ptr());
}

#[test]
Expand Down Expand Up @@ -1350,6 +1337,20 @@ fn test_collect_after_iterator_clone() {
assert_eq!(v, [1, 1, 1, 1, 1]);
assert!(v.len() <= v.capacity());
}

// regression test for #135103, similar to the one above Flatten/FlatMap had an unsound InPlaceIterable
// implementation.
#[test]
fn test_flatten_clone() {
const S: String = String::new();

let v = vec![[S, "Hello World!".into()], [S, S]];
let mut i = v.into_iter().flatten();
let _ = i.next();
let result: Vec<String> = i.clone().collect();
assert_eq!(result, ["Hello World!", "", ""]);
}

#[test]
fn test_cow_from() {
let borrowed: &[_] = &["borrowed", "(slice)"];
Expand Down
34 changes: 2 additions & 32 deletions library/core/src/iter/adapters/flatten.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::iter::adapters::SourceIter;
use crate::iter::{
Cloned, Copied, Empty, Filter, FilterMap, Fuse, FusedIterator, InPlaceIterable, Map, Once,
OnceWith, TrustedFused, TrustedLen,
Cloned, Copied, Empty, Filter, FilterMap, Fuse, FusedIterator, Map, Once, OnceWith,
TrustedFused, TrustedLen,
};
use crate::num::NonZero;
use crate::ops::{ControlFlow, Try};
Expand Down Expand Up @@ -157,21 +157,6 @@ where
{
}

#[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<I, U, F> InPlaceIterable for FlatMap<I, U, F>
where
I: InPlaceIterable,
U: BoundedSize + IntoIterator,
{
const EXPAND_BY: Option<NonZero<usize>> = const {
match (I::EXPAND_BY, U::UPPER_BOUND) {
(Some(m), Some(n)) => m.checked_mul(n),
_ => None,
}
};
const MERGE_BY: Option<NonZero<usize>> = I::MERGE_BY;
}

#[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<I, U, F> SourceIter for FlatMap<I, U, F>
where
Expand Down Expand Up @@ -386,21 +371,6 @@ where
{
}

#[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<I> InPlaceIterable for Flatten<I>
where
I: InPlaceIterable + Iterator,
<I as Iterator>::Item: IntoIterator + BoundedSize,
{
const EXPAND_BY: Option<NonZero<usize>> = const {
match (I::EXPAND_BY, I::Item::UPPER_BOUND) {
(Some(m), Some(n)) => m.checked_mul(n),
_ => None,
}
};
const MERGE_BY: Option<NonZero<usize>> = I::MERGE_BY;
}

#[unstable(issue = "none", feature = "inplace_iteration")]
unsafe impl<I> SourceIter for Flatten<I>
where
Expand Down
2 changes: 1 addition & 1 deletion src/llvm-project
Submodule llvm-project updated 36 files
+1 −1 .github/workflows/libclang-python-tests.yml
+8 −2 .github/workflows/llvm-project-tests.yml
+2 −1 clang/docs/ReleaseNotes.rst
+5 −0 clang/lib/Driver/Driver.cpp
+1 −1 clang/lib/Driver/ToolChains/Hexagon.cpp
+1 −1 clang/lib/Format/UnwrappedLineParser.cpp
+1 −1 clang/lib/Sema/SemaDeclCXX.cpp
+5 −5 clang/test/Driver/hexagon-toolchain-linux.c
+26 −0 clang/test/Driver/modules-print-library-module-manifest-path.cpp
+39 −0 clang/test/Modules/initializer-list-recognition-through-export-and-linkage-issue-118218.cpp
+18 −0 clang/unittests/Format/FormatTest.cpp
+19 −0 clang/unittests/Format/TokenAnnotatorTest.cpp
+1 −1 cmake/Modules/LLVMVersion.cmake
+1 −1 compiler-rt/lib/CMakeLists.txt
+2 −0 compiler-rt/lib/lsan/lsan_interceptors.cpp
+60 −0 compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c
+1 −1 libcxx/include/__config
+3 −2 llvm/cmake/modules/Findzstd.cmake
+1 −1 llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
+6 −2 llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
+4 −0 llvm/lib/Target/Hexagon/HexagonISelLowering.cpp
+7 −4 llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+7 −0 llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+8 −9 llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td
+1 −1 llvm/lib/Target/RISCV/RISCVInstrInfoXCV.td
+3 −2 llvm/lib/Target/RISCV/RISCVInstrInfoXSf.td
+4 −1 llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+46 −0 llvm/test/CodeGen/ARM/scalarize-assert-zext.ll
+22 −0 llvm/test/CodeGen/Hexagon/simple-types-mem.ll
+22 −0 llvm/test/CodeGen/RISCV/rvv/rv32-zve-bitcast-crash.ll
+1 −3 llvm/test/CodeGen/RISCV/rvv/sf_vfnrclip_x_f_qf.ll
+1 −3 llvm/test/CodeGen/RISCV/rvv/sf_vfnrclip_xu_f_qf.ll
+51 −0 llvm/test/Transforms/SLPVectorizer/slp-deleted-inst.ll
+1 −1 llvm/utils/gn/secondary/llvm/version.gni
+1 −1 llvm/utils/lit/lit/__init__.py
+1 −1 llvm/utils/mlgo-utils/mlgo/__init__.py
10 changes: 5 additions & 5 deletions tests/ui/impl-trait/precise-capturing/redundant.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
//@ edition: 2024
//@ check-pass

#![feature(precise_capturing_in_traits)]
#![deny(impl_trait_redundant_captures)]

fn hello<'a>() -> impl Sized + use<'a> {}
//~^ WARN all possible in-scope parameters are already captured
//~^ ERROR all possible in-scope parameters are already captured

struct Inherent;
impl Inherent {
fn inherent(&self) -> impl Sized + use<'_> {}
//~^ WARN all possible in-scope parameters are already captured
//~^ ERROR all possible in-scope parameters are already captured
}

trait Test<'a> {
fn in_trait() -> impl Sized + use<'a, Self>;
//~^ WARN all possible in-scope parameters are already captured
//~^ ERROR all possible in-scope parameters are already captured
}
impl<'a> Test<'a> for () {
fn in_trait() -> impl Sized + use<'a> {}
//~^ WARN all possible in-scope parameters are already captured
//~^ ERROR all possible in-scope parameters are already captured
}

fn main() {}
16 changes: 10 additions & 6 deletions tests/ui/impl-trait/precise-capturing/redundant.stderr
Original file line number Diff line number Diff line change
@@ -1,36 +1,40 @@
warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant
error: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant
--> $DIR/redundant.rs:6:19
|
LL | fn hello<'a>() -> impl Sized + use<'a> {}
| ^^^^^^^^^^^^^-------
| |
| help: remove the `use<...>` syntax
|
= note: `#[warn(impl_trait_redundant_captures)]` on by default
note: the lint level is defined here
--> $DIR/redundant.rs:4:9
|
LL | #![deny(impl_trait_redundant_captures)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant
error: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant
--> $DIR/redundant.rs:11:27
|
LL | fn inherent(&self) -> impl Sized + use<'_> {}
| ^^^^^^^^^^^^^-------
| |
| help: remove the `use<...>` syntax

warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant
error: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant
--> $DIR/redundant.rs:16:22
|
LL | fn in_trait() -> impl Sized + use<'a, Self>;
| ^^^^^^^^^^^^^-------------
| |
| help: remove the `use<...>` syntax

warning: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant
error: all possible in-scope parameters are already captured, so `use<...>` syntax is redundant
--> $DIR/redundant.rs:20:22
|
LL | fn in_trait() -> impl Sized + use<'a> {}
| ^^^^^^^^^^^^^-------
| |
| help: remove the `use<...>` syntax

warning: 4 warnings emitted
error: aborting due to 4 previous errors

0 comments on commit 752fecf

Please sign in to comment.