diff --git a/NEWS.md b/NEWS.md index 0f7da3162e200..46fa26c0721c7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -740,6 +740,9 @@ Deprecated or removed * `num2hex` and `hex2num` have been deprecated in favor of `reinterpret` combined with `parse`/`hex` ([#22088]). + * `copy!` is deprecated for `AbstractSet` and `AbstractDict`, with the intention to re-enable + it with a cleaner meaning in a future version ([#24844]). + * `a:b` is deprecated for constructing a `StepRange` when `a` and `b` have physical units (Dates and Times). Use `a:s:b`, where `s = Dates.Day(1)` or `s = Dates.Second(1)`. @@ -766,7 +769,7 @@ 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]). 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 0e1ffaa91a27f..04b3e90b37be6 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 860f839acce0a..b617ec96ff0dd 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -3184,6 +3184,10 @@ info(io::IO, err::Exception; prefix="ERROR: ", kw...) = info(err::Exception; prefix="ERROR: ", kw...) = info(STDERR, err, prefix=prefix; kw...) +# #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