diff --git a/NEWS.md b/NEWS.md index 7fed73e627ab8..b30277f1a3c4b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -758,10 +758,14 @@ Deprecated or removed in the new `Unicode` standard library module ([#25021]). * The aliases `Complex32`, `Complex64` and `Complex128` have been deprecated in favor of `ComplexF16`, - `ComplexF32` and `ComplexF64` respectively (#24647). + `ComplexF32` and `ComplexF64` respectively ([#24647]). * `Associative` has been deprecated in favor of `AbstractDict` ([#25012]). + * `copy!` is deprecated for `AbstractSet` and `AbstractDict`, with the intention to re-enable + it with a cleaner meaning in a future version ([#24844]). + +>>>>>>> deprecate copy! for sets and dicts (part of #24808) Command-line option changes --------------------------- diff --git a/base/abstractdict.jl b/base/abstractdict.jl index e8f42bb2c5a53..5264f002a9e99 100644 --- a/base/abstractdict.jl +++ b/base/abstractdict.jl @@ -230,15 +230,6 @@ function merge!(combine::Function, d::AbstractDict, others::AbstractDict...) return d end -# very similar to `merge!`, but accepts any iterable and extends code -# that would otherwise only use `copy!` with arrays. -function copy!(dest::Union{AbstractDict,AbstractSet}, src) - for x in src - push!(dest, x) - end - return dest -end - """ keytype(type) diff --git a/base/array.jl b/base/array.jl index 76a19b0665aa8..5c8fa9188d2c6 100644 --- a/base/array.jl +++ b/base/array.jl @@ -585,7 +585,12 @@ function grow_to!(dest, itr, st) push!(dest, el::T) else new = similar(dest, typejoin(T, S)) - copy!(new, dest) + if new isa AbstractSet + # TODO: merge back these two branches when copy! is re-enabled for sets + union!(new, dest) + else + copy!(new, dest) + end push!(new, el) return grow_to!(new, itr, st) end diff --git a/base/deprecated.jl b/base/deprecated.jl index 5f48ad7e237e3..dd6c403c02824 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -2984,6 +2984,10 @@ end @deprecate merge!(repo::LibGit2.GitRepo, args...; kwargs...) LibGit2.merge!(repo, args...; kwargs...) +# #24844 +@deprecate copy!(dest::AbstractSet, src) union!(dest, src) +@deprecate copy!(dest::AbstractDict, src) foldl(push!, dest, src) + # issue #24019 @deprecate similar(a::AbstractDict) empty(a) @deprecate similar(a::AbstractDict, ::Type{Pair{K,V}}) where {K, V} empty(a, K, V) diff --git a/base/dict.jl b/base/dict.jl index 692d5377ae08e..840077d9e51fa 100644 --- a/base/dict.jl +++ b/base/dict.jl @@ -180,7 +180,7 @@ function grow_to!(dest::AbstractDict{K,V}, itr, st) where V where K dest[k] = v else new = empty(dest, typejoin(K,typeof(k)), typejoin(V,typeof(v))) - copy!(new, dest) + merge!(new, dest) new[k] = v return grow_to!(new, itr, st) end