# Scope of a use clause in the package spec

**URL:** https://forum.ada-lang.io/t/scope-of-a-use-clause-in-the-package-spec/4555
**Category:** General
**Created:** [July 7, 2026, 10:06pm UTC](https://forum.ada-lang.io/t/scope-of-a-use-clause-in-the-package-spec/4555 "2026-07-07T22:06:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![RREE](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/rree/32/34_2.png) [@RREE](https://forum.ada-lang.io/u/RREE)
#### Post date: [July 7, 2026, 10:06pm UTC](https://forum.ada-lang.io/t/scope-of-a-use-clause-in-the-package-spec/4555/1 "2026-07-07T22:06:11Z")

</div>

I have a (with and) use clause in a package spec of requests.ads. There is only a with clause in the package body. I know that it is redundant but I like to see the dependencies of the body without opening the spec file. In a declare block in the body I added the use clause. GNAT them generates the warning:

```ada
requests.adb:33:17: warning: "Str20s" is already use-visible through previous use_clause at requests.ads:3 [-gnatwr]

```

Does a use clause from the spec extend to the body? That is not how I interpret the RM §8.4: “For a use\_clause within a context\_clause of a library\_unit\_declaration or …, the scope is the entire declarative region of the declaration.”

---

<div class="post-metadata">

### Author: ![Nordic\_Dogsledding](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/nordic_dogsledding/32/547_2.png) [@Nordic\_Dogsledding](https://forum.ada-lang.io/u/Nordic_Dogsledding)
#### Post date: [July 8, 2026, 8:40am UTC](https://forum.ada-lang.io/t/scope-of-a-use-clause-in-the-package-spec/4555/2 "2026-07-08T08:40:16Z")

</div>

RM 8.1 definition of Declarative Ragion.  
This is not a simple read.  
The short answer:  
Everything declared in the spec is directly visible in the body and in all child units and their child units and so on… (if not hidden by more local declarations).  
Use clauses cannot be hidden, but there may be conflicts with other use clauses in which case you have to use the expanded name.

---

<div class="post-metadata">

### Author: ![RREE](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/rree/32/34_2.png) [@RREE](https://forum.ada-lang.io/u/RREE)
#### Post date: [July 8, 2026, 12:56pm UTC](https://forum.ada-lang.io/t/scope-of-a-use-clause-in-the-package-spec/4555/3 "2026-07-08T12:56:07Z")

</div>

Seems logical. I knew that the with clause in a spec is also valid in the body. However, I was under the impression that this rule did not apply to the use clause and that I had to repeat a use clause in the body if I wanted to make something visible. Obviously I was wrong and learned something, thank you

---

<div class="post-metadata">

### Author: ![OneWingedShark](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/onewingedshark/32/305_2.png) [@OneWingedShark](https://forum.ada-lang.io/u/OneWingedShark)
#### Post date: [July 8, 2026, 2:02pm UTC](https://forum.ada-lang.io/t/scope-of-a-use-clause-in-the-package-spec/4555/4 "2026-07-08T14:02:39Z")

</div>

> [@RREE](#):
>
> However, I was under the impression that this rule did not apply to the use clause and that I had to repeat a use clause in the body if I wanted to make something visible.

There is some stylistic arguments on the use of `use`, with some arguing that [package-level] `use` shouldn’t be used because it imports whole namespaces, and others that it _should_.

In many cases, there is a happy medium in using them locally (eg in a declare-block or in a subprogram’s declarative region). My rule of thumb is to go with the ‘smallest scope’ in general, only ‘promoting’ up-scope when there are multiple uses in view. This means that if I have a lot of string manipulation in the implementation of multiple subprograms I’d put ‘use’ in the `body`… thus the only time to put `use` in the specification is when essentially the whole package (spec interface) is dependent on that, intrinsically. (You can tell it is when the prefix appears in your parameters very repeatedly; it’s in this case that the `use` makes these dissapear.)

Another thing to keep in mind is `renames`; it is ridiculously easy to say something like  
`Package Text renames Ada.Strings.Fixed;` and then use _that_ as your prefix. (eg `Text.Index`.)

---

<div class="post-metadata">

### Author: ![dmitry-kazakov](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/dmitry-kazakov/32/522_2.png) [@dmitry-kazakov](https://forum.ada-lang.io/u/dmitry-kazakov)
#### Post date: [July 8, 2026, 3:47pm UTC](https://forum.ada-lang.io/t/scope-of-a-use-clause-in-the-package-spec/4555/5 "2026-07-08T15:47:42Z")

</div>

You can even place it among formal generic parameters:

```ada
generic
   use Ada.Text_IO; -- This is legal
package P is ...

```
