rust/src/test/ui/privacy/restricted
Aaron Hill e3cd43eb00
Use smaller def span for functions
Currently, the def span of a funtion encompasses the entire function
signature and body. However, this is usually unnecessarily verbose - when we are
pointing at an entire function in a diagnostic, we almost always want to
point at the signature. The actual contents of the body tends to be
irrelevant to the diagnostic we are emitting, and just takes up
additional screen space.

This commit changes the `def_span` of all function items (freestanding
functions, `impl`-block methods, and `trait`-block methods) to be the
span of the signature. For example, the function

```rust
pub fn foo<T>(val: T) -> T { val }
```

now has a `def_span` corresponding to `pub fn foo<T>(val: T) -> T`
(everything before the opening curly brace).

Trait methods without a body have a `def_span` which includes the
trailing semicolon. For example:

```rust
trait Foo {
    fn bar();
}```

the function definition `Foo::bar` has a `def_span` of `fn bar();`

This makes our diagnostic output much shorter, and emphasizes
information that is relevant to whatever diagnostic we are reporting.

We continue to use the full span (including the body) in a few of
places:

* MIR building uses the full span when building source scopes.
* 'Outlives suggestions' use the full span to sort the diagnostics being
  emitted.
* The `#[rustc_on_unimplemented(enclosing_scope="in this scope")]`
attribute points the entire scope body.
* The 'unconditional recursion' lint uses the full span to show
  additional context for the recursive call.

All of these cases work only with local items, so we don't need to
add anything extra to crate metadata.
2020-08-22 18:41:49 -04:00
..
auxiliary Remove licenses 2018-12-25 21:08:33 -07:00
lookup-ignores-private.rs Migrate compile-pass annotations to build-pass 2019-07-03 06:30:28 +09:00
private-in-public.rs Remove licenses 2018-12-25 21:08:33 -07:00
private-in-public.stderr Use smaller def span for functions 2020-08-22 18:41:49 -04:00
relative-2018.rs resolve: Prohibit relative paths in visibilities on 2018 edition 2018-11-25 16:40:03 +03:00
relative-2018.stderr Change E0741 into E0742 2019-10-29 13:59:40 +01:00
struct-literal-field.rs Remove licenses 2018-12-25 21:08:33 -07:00
struct-literal-field.stderr Normalize wording of privacy access labels 2020-03-22 15:36:54 -07:00
test.rs Don't recommend extern crate syntax 2019-08-05 18:19:01 +01:00
test.stderr Use more targetted span for error label 2020-03-22 16:09:42 -07:00