summary refs log tree commit diff
path: root/src/test/ui/panic-handler
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2020-08-12 17:02:14 -0400
committerAaron Hill <aa1ronham@gmail.com>2020-08-22 18:41:49 -0400
commite3cd43eb0093a59c4ba98e44c13a8dacc9f4f9b1 (patch)
tree06280830e2fdd857ced4a7b9174a56b06d0a3ef2 /src/test/ui/panic-handler
parent663d2f5cd3163f17eddb74ee1e028d542255f21a (diff)
downloadrust-e3cd43eb0093a59c4ba98e44c13a8dacc9f4f9b1.tar.gz
rust-e3cd43eb0093a59c4ba98e44c13a8dacc9f4f9b1.zip
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.
Diffstat (limited to 'src/test/ui/panic-handler')
-rw-r--r--src/test/ui/panic-handler/panic-handler-bad-signature-4.stderr7
-rw-r--r--src/test/ui/panic-handler/panic-handler-duplicate.stderr12
-rw-r--r--src/test/ui/panic-handler/panic-handler-std.stderr6
3 files changed, 8 insertions, 17 deletions
diff --git a/src/test/ui/panic-handler/panic-handler-bad-signature-4.stderr b/src/test/ui/panic-handler/panic-handler-bad-signature-4.stderr
index 3a5fc76efbb..5e46da12142 100644
--- a/src/test/ui/panic-handler/panic-handler-bad-signature-4.stderr
+++ b/src/test/ui/panic-handler/panic-handler-bad-signature-4.stderr
@@ -1,11 +1,8 @@
 error: should have no type parameters
   --> $DIR/panic-handler-bad-signature-4.rs:9:1
    |
-LL | / fn panic<T>(pi: &PanicInfo) -> ! {
-LL | |
-LL | |     loop {}
-LL | | }
-   | |_^
+LL | fn panic<T>(pi: &PanicInfo) -> ! {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/panic-handler/panic-handler-duplicate.stderr b/src/test/ui/panic-handler/panic-handler-duplicate.stderr
index 8603ef91bef..8cdc4888d02 100644
--- a/src/test/ui/panic-handler/panic-handler-duplicate.stderr
+++ b/src/test/ui/panic-handler/panic-handler-duplicate.stderr
@@ -1,18 +1,14 @@
 error[E0152]: found duplicate lang item `panic_impl`
   --> $DIR/panic-handler-duplicate.rs:15:1
    |
-LL | / fn panic2(info: &PanicInfo) -> ! {
-LL | |     loop {}
-LL | | }
-   | |_^
+LL | fn panic2(info: &PanicInfo) -> ! {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
 note: the lang item is first defined here
   --> $DIR/panic-handler-duplicate.rs:10:1
    |
-LL | / fn panic(info: &PanicInfo) -> ! {
-LL | |     loop {}
-LL | | }
-   | |_^
+LL | fn panic(info: &PanicInfo) -> ! {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/panic-handler/panic-handler-std.stderr b/src/test/ui/panic-handler/panic-handler-std.stderr
index bb656089bca..e4069b196ff 100644
--- a/src/test/ui/panic-handler/panic-handler-std.stderr
+++ b/src/test/ui/panic-handler/panic-handler-std.stderr
@@ -1,10 +1,8 @@
 error[E0152]: found duplicate lang item `panic_impl`
   --> $DIR/panic-handler-std.rs:8:1
    |
-LL | / fn panic(info: PanicInfo) -> ! {
-LL | |     loop {}
-LL | | }
-   | |_^
+LL | fn panic(info: PanicInfo) -> ! {
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: the lang item is first defined in crate `std` (which `panic_handler_std` depends on)
    = note: first definition in `std` loaded from SYSROOT/libstd-*.rlib