diff --git a/base/deprecated.jl b/base/deprecated.jl index b478995522a58..096ceb311fce3 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -119,9 +119,7 @@ export __has_internal_change # and of exporting the function. # # For more complex cases, move the body of the deprecated method in this file, -# and call depwarn() directly from inside it. The symbol depwarn() expects is -# the name of the function, which is used to ensure that the deprecation warning -# is only printed the first time for each call place. +# and call depwarn() directly from inside it. """ @deprecate old new [export_old=true] @@ -131,6 +129,8 @@ with the specified signature in the process. To prevent `old` from being exported, set `export_old` to `false`. +See also [`Base.depwarn()`](@ref). + !!! compat "Julia 1.5" As of Julia 1.5, functions defined by `@deprecate` do not print warning when `julia` is run without the `--depwarn=yes` flag set, as the default value of `--depwarn` option @@ -227,6 +227,26 @@ macro deprecate(old, new, export_old=true) end end +""" + Base.depwarn(msg::String, funcsym::Symbol; force=false) + +Print `msg` as a deprecation warning. The symbol `funcsym` should be the name +of the calling function, which is used to ensure that the deprecation warning is +only printed the first time for each call place. Set `force=true` to force the +warning to always be shown, even if Julia was started with `--depwarn=no` (the +default). + +See also [`@deprecate`](@ref). + +# Examples +```julia +function deprecated_func() + Base.depwarn("Don't use `deprecated_func()`!", :deprecated_func) + + 1 + 1 +end +``` +""" @nospecializeinfer function depwarn(msg, funcsym; force::Bool=false) @nospecialize # N.B. With this use of `@invokelatest`, we're preventing the addition of backedges from diff --git a/base/public.jl b/base/public.jl index dce1223124856..c11c76c13053c 100644 --- a/base/public.jl +++ b/base/public.jl @@ -112,4 +112,5 @@ public # misc notnothing, runtests, - text_colors + text_colors, + depwarn diff --git a/doc/src/base/base.md b/doc/src/base/base.md index d7e7fff7cbda7..744c93f0d75cd 100644 --- a/doc/src/base/base.md +++ b/doc/src/base/base.md @@ -307,7 +307,12 @@ Base.@simd Base.@polly Base.@generated Base.@assume_effects +``` + +## Managing deprecations +```@docs Base.@deprecate +Base.depwarn ``` ## Missing Values