Skip to content

Commit 2a56a37

Browse files
authored
make using A.B only for modules, using A: B only for single bindings (#25306)
part of #8000
1 parent bbc7b83 commit 2a56a37

24 files changed

+44
-26
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ Language changes
173173
by a character that will never be an allowed identifier character (currently
174174
operators, space/control characters, or common punctuation characters) ([#25231]).
175175

176+
* The syntax `using A.B` can now only be used when `A.B` is a module, and the syntax
177+
`using A: B` can only be used for adding single bindings ([#8000]).
178+
176179

177180
Breaking changes
178181
----------------

base/asyncmap.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
using Base.Iterators.Enumerate
3+
using Base.Iterators: Enumerate
44

55
"""
66
asyncmap(f, c...; ntasks=0, batch_size=nothing)

base/libgit2/libgit2.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module LibGit2
77

88
import Base: ==
99
using Base: coalesce, notnothing
10-
using Base.Printf.@printf
10+
using Base.Printf: @printf
1111

1212
export with, GitRepo, GitConfig
1313

base/math.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using Base: sign_mask, exponent_mask, exponent_one,
2525

2626
using Core.Intrinsics: sqrt_llvm
2727

28-
using Base.IEEEFloat
28+
using Base: IEEEFloat
2929

3030
@noinline function throw_complex_domainerror(f, x)
3131
throw(DomainError(x, string("$f will only return a complex result if called with a ",

base/pkg/entry.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ..Reqs, ..Read, ..Query, ..Resolve, ..Cache, ..Write, ..Dir
77
using ...LibGit2
88
import ...Pkg.PkgError
99
using ..Types
10-
using Base.Printf.@printf
10+
using Base.Printf: @printf
1111

1212
macro recover(ex)
1313
quote

base/printf.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
module Printf
4-
using Base: Grisu, GMP
4+
using Base.Grisu
5+
using Base.GMP
56
using Base.Unicode: lowercase, textwidth, isupper
67

78
### printf formatter generation ###

base/random/dSFMT.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module dSFMT
44

55
import Base: copy, copy!, ==, hash
6-
using Base.GMP: MPZ
6+
using Base.GMP.MPZ
77

88
export DSFMT_state, dsfmt_get_min_array_size, dsfmt_get_idstring,
99
dsfmt_init_gen_rand, dsfmt_init_by_array, dsfmt_gv_init_by_array,

base/random/random.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
module Random
44

55
using Base.dSFMT
6-
using Base.GMP: Limb, MPZ
6+
using Base.GMP.MPZ
7+
using Base.GMP: Limb
78
using Base: BitInteger, BitInteger_types, BitUnsigned, @gc_preserve
89

910
import Base: copymutable, copy, copy!, ==, hash

base/sort.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
module Sort
44

5-
using Base: Order, Checked, copymutable, linearindices, IndexStyle, viewindexing, IndexLinear, _length
5+
using Base.Order, Base.Checked
6+
using Base: copymutable, linearindices, IndexStyle, viewindexing, IndexLinear, _length
67

78
import
89
Base.sort,

base/stacktraces.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module StackTraces
88

99
import Base: hash, ==, show
1010
import Base.Serializer: serialize, deserialize
11-
using Base.Printf.@printf
11+
using Base.Printf: @printf
1212

1313
export StackTrace, StackFrame, stacktrace, catch_stacktrace
1414

doc/src/manual/modules.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ the system will search for it among variables exported by `Lib` and import it if
4242
This means that all uses of that global within the current module will resolve to the definition
4343
of that variable in `Lib`.
4444

45-
The statement `using BigLib: thing1, thing2` is a syntactic shortcut for `using BigLib.thing1, BigLib.thing2`.
45+
The statement `using BigLib: thing1, thing2` brings just the identifiers `thing1` and `thing2`
46+
into scope from module `BigLib`. If these names refer to functions, adding methods to them
47+
will not be allowed (you may only "use" them, not extend them).
4648

47-
The `import` keyword supports all the same syntax as `using`, but only operates on a single name
49+
The `import` keyword supports the same syntax as `using`, but only operates on a single name
4850
at a time. It does not add modules to be searched the way `using` does. `import` also differs
49-
from `using` in that functions must be imported using `import` to be extended with new methods.
51+
from `using` in that functions imported using `import` can be extended with new methods.
5052

5153
In `MyModule` above we wanted to add a method to the standard `show` function, so we had to write
5254
`import Base.show`. Functions whose names are only visible via `using` cannot be extended.
@@ -79,7 +81,6 @@ functions into the current workspace:
7981
| Import Command | What is brought into scope | Available for method extension |
8082
|:------------------------------- |:------------------------------------------------------------------------------- |:------------------------------------------- |
8183
| `using MyModule` | All `export`ed names (`x` and `y`), `MyModule.x`, `MyModule.y` and `MyModule.p` | `MyModule.x`, `MyModule.y` and `MyModule.p` |
82-
| `using MyModule.x, MyModule.p` | `x` and `p` |   |
8384
| `using MyModule: x, p` | `x` and `p` |   |
8485
| `import MyModule` | `MyModule.x`, `MyModule.y` and `MyModule.p` | `MyModule.x`, `MyModule.y` and `MyModule.p` |
8586
| `import MyModule.x, MyModule.p` | `x` and `p` | `x` and `p` |

src/toplevel.c

+10
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,11 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *m, jl_value_t *e, int fast, int e
638638
if (name != NULL)
639639
u = (jl_module_t*)jl_eval_global_var(import, name);
640640
if (jl_is_module(u)) {
641+
if (from) {
642+
jl_depwarn("`using A: B` will only be allowed for single bindings, not modules. Use "
643+
"`using A.B` instead",
644+
(jl_value_t*)jl_symbol("using"));
645+
}
641646
jl_module_using(m, u);
642647
if (m == jl_main_module && name == NULL) {
643648
// TODO: for now, `using A` in Main also creates an explicit binding for `A`
@@ -646,6 +651,11 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *m, jl_value_t *e, int fast, int e
646651
}
647652
}
648653
else {
654+
if (!from) {
655+
jl_depwarn("`using A.B` will only be allowed for modules, not single bindings. Use "
656+
"`using A: B` instead",
657+
(jl_value_t*)jl_symbol("using"));
658+
}
649659
jl_module_t *replacement = deprecation_replacement_module(import, name);
650660
if (replacement)
651661
jl_module_using(m, replacement);

stdlib/SuiteSparse/test/umfpack.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# based on deps/Suitesparse-4.0.2/UMFPACK/Demo/umfpack_di_demo.c
99

10-
using SuiteSparse.increment!
10+
using SuiteSparse: increment!
1111
using Base.LinAlg: Adjoint, Transpose
1212

1313
A0 = sparse(increment!([0,4,1,1,2,2,0,1,2,3,4,4]),

test/linalg/triangular.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ end
516516

517517
# dimensional correctness:
518518
isdefined(Main, :TestHelpers) || @eval Main include("../TestHelpers.jl")
519-
using Main.TestHelpers.Furlong
519+
using Main.TestHelpers: Furlong
520520
let A = UpperTriangular([Furlong(1) Furlong(4); Furlong(0) Furlong(1)])
521521
@test sqrt(A) == Furlong{1//2}.(UpperTriangular([1 2; 0 1]))
522522
end

test/llvmcall.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
using Base.llvmcall
3+
using Base: llvmcall
44

55
#function add1234(x::Tuple{Int32,Int32,Int32,Int32})
66
# llvmcall("""%3 = add <4 x i32> %1, %0
@@ -48,7 +48,7 @@ end
4848

4949
# Test whether llvmcall escapes the function name correctly
5050
baremodule PlusTest
51-
using Base.llvmcall
51+
using Base: llvmcall
5252
using Test
5353
using Base
5454

test/logging.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Base.CoreLogging: BelowMinLevel, Debug, Info, Warn, Error,
55
handle_message, shouldlog, min_enabled_level
66

77
import Test: collect_test_logs, TestLogger
8-
using Base.Printf.@sprintf
8+
using Base.Printf: @sprintf
99

1010
#-------------------------------------------------------------------------------
1111
@testset "Logging" begin

test/meta.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ end
4343
@test foundfunc(h_inlined(), :g_inlined)
4444
@test foundfunc(h_noinlined(), :g_noinlined)
4545

46-
using Base.pushmeta!, Base.popmeta!
46+
using Base: pushmeta!, popmeta!
4747

4848
macro attach(val, ex)
4949
esc(_attach(val, ex))

test/random.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
isdefined(Main, :TestHelpers) || @eval Main include(joinpath(dirname(@__FILE__), "TestHelpers.jl"))
44
using Main.TestHelpers.OAs
55

6-
using Base.Random: Sampler, SamplerRangeFast, SamplerRangeInt, dSFMT, MT_CACHE_F, MT_CACHE_I
6+
using Base.Random.dSFMT
7+
using Base.Random: Sampler, SamplerRangeFast, SamplerRangeInt, MT_CACHE_F, MT_CACHE_I
78

89
@testset "Issue #6573" begin
910
srand(0)

test/ranges.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ Base.isless(x, y::NotReal) = isless(x, y.val)
11981198
@test colon(1, NotReal(1), 5) isa StepRange{Int,NotReal}
11991199

12001200
isdefined(Main, :TestHelpers) || @eval Main include("TestHelpers.jl")
1201-
using Main.TestHelpers.Furlong
1201+
using Main.TestHelpers: Furlong
12021202
@testset "dimensional correctness" begin
12031203
@test length(collect(Furlong(2):Furlong(10))) == 9
12041204
@test length(range(Furlong(2), 9)) == 9

test/runtests.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
using Test
44
using Distributed
5-
using Base.Printf.@sprintf
5+
using Base.Printf: @sprintf
66

77
include("choosetests.jl")
88
include("testenv.jl")

test/sparse/sparse.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

33
using Base.LinAlg: mul!, ldiv!, rdiv!, Adjoint, Transpose
4-
using Base.Printf.@printf
4+
using Base.Printf: @printf
55

66
@testset "issparse" begin
77
@test issparse(sparse(ones(5,5)))

test/staged.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
using Base.Printf.@sprintf
3+
using Base.Printf: @sprintf
44

55
@generated function staged_t1(a,b)
66
if a == Int

test/statistics.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ end
408408

409409
# dimensional correctness
410410
isdefined(Main, :TestHelpers) || @eval Main include("TestHelpers.jl")
411-
using Main.TestHelpers.Furlong
411+
using Main.TestHelpers: Furlong
412412
@testset "Unitful elements" begin
413413
r = Furlong(1):Furlong(1):Furlong(2)
414414
a = collect(r)

test/subtype.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
using Base.Bottom
3+
using Base: Bottom
44
using Test
55

66
macro UnionAll(var, expr)

0 commit comments

Comments
 (0)