rust/src/librustc_ast
bors d5ba3efed1 Auto merge of #75465 - Aaron1011:feature/short-fn-def-span, r=estebank
Use smaller def span for functions

Currently, the def span of a function 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.

All of these cases work only with local items, so we don't need to
add anything extra to crate metadata.
2020-08-23 08:14:17 +00:00
..
ast Fix rustc_ast unit test 2020-08-14 17:34:32 +01:00
attr Eliminate the SessionGlobals from librustc_ast. 2020-08-08 12:03:42 +10:00
expand Eliminate the SessionGlobals from librustc_ast. 2020-08-08 12:03:42 +10:00
util Move doc comment parsing to rustc_lexer 2020-08-19 22:53:16 +02:00
ast.rs Use smaller def span for functions 2020-08-22 18:41:49 -04:00
Cargo.toml replaced log with tracing 2020-08-15 13:03:11 -07:00
crate_disambiguator.rs Rework rustc_serialize 2020-08-14 17:34:30 +01:00
entry.rs Eliminate the SessionGlobals from librustc_ast. 2020-08-08 12:03:42 +10:00
lib.rs rust_ast::ast => rustc_ast 2020-08-17 20:32:32 +00:00
mut_visit.rs Use smaller def span for functions 2020-08-22 18:41:49 -04:00
node_id.rs Rework rustc_serialize 2020-08-14 17:34:30 +01:00
ptr.rs Rework rustc_serialize 2020-08-14 17:34:30 +01:00
README.md rust-lang.github.io/rustc-dev-guide -> rustc-dev-guide.rust-lang.org 2020-03-10 17:08:18 -03:00
token.rs Add backwards-compat hack for certain '$name' tokens 2020-08-22 17:31:47 -04:00
tokenstream.rs Rework rustc_serialize 2020-08-14 17:34:30 +01:00
visit.rs Suggest adding &self when accessing self in static assoc fn 2020-08-13 18:00:56 -07:00

The rustc_ast crate contains those things concerned purely with syntax that is, the AST ("abstract syntax tree"), parser, pretty-printer, lexer, macro expander, and utilities for traversing ASTs.

For more information about how these things work in rustc, see the rustc dev guide: