Skip to content

Commit d3ae56d

Browse files
committed
Rollup merge of #34403 - jonathandturner:move_liberror, r=alexcrichton
This PR refactors the 'errors' part of libsyntax into its own crate (librustc_errors). This is the first part of a few refactorings to simplify error reporting and potentially support more output formats (like a standardized JSON output and possibly an --explain mode that can work with the user's code), though this PR stands on its own and doesn't assume further changes. As part of separating out the errors crate, I have also refactored the code position portion of codemap into its own crate (libsyntax_pos). While it's helpful to have the common code positions in a separate crate for the new errors crate, this may also enable further simplifications in the future.
2 parents 4e2e31c + bc14006 commit d3ae56d

File tree

271 files changed

+2325
-2069
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

271 files changed

+2325
-2069
lines changed

mk/crates.mk

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ TARGET_CRATES := libc std term \
5757
panic_abort panic_unwind unwind
5858
RUSTC_CRATES := rustc rustc_typeck rustc_mir rustc_borrowck rustc_resolve rustc_driver \
5959
rustc_trans rustc_back rustc_llvm rustc_privacy rustc_lint \
60-
rustc_data_structures rustc_platform_intrinsics \
60+
rustc_data_structures rustc_platform_intrinsics rustc_errors \
6161
rustc_plugin rustc_metadata rustc_passes rustc_save_analysis \
6262
rustc_const_eval rustc_const_math rustc_incremental
63-
HOST_CRATES := syntax syntax_ext $(RUSTC_CRATES) rustdoc fmt_macros \
63+
HOST_CRATES := syntax syntax_ext syntax_pos $(RUSTC_CRATES) rustdoc fmt_macros \
6464
flate arena graphviz rbml log serialize
6565
TOOLS := compiletest rustdoc rustc rustbook error_index_generator
6666

@@ -98,43 +98,45 @@ DEPS_serialize := std log
9898
DEPS_term := std
9999
DEPS_test := std getopts term native:rust_test_helpers
100100

101-
DEPS_syntax := std term serialize log arena libc rustc_bitflags rustc_unicode
102-
DEPS_syntax_ext := syntax fmt_macros
101+
DEPS_syntax := std term serialize log arena libc rustc_bitflags rustc_unicode rustc_errors syntax_pos
102+
DEPS_syntax_ext := syntax syntax_pos rustc_errors fmt_macros
103+
DEPS_syntax_pos := serialize
103104

104105
DEPS_rustc_const_math := std syntax log serialize
105106
DEPS_rustc_const_eval := rustc_const_math rustc syntax log serialize \
106-
rustc_back graphviz
107+
rustc_back graphviz syntax_pos
107108

108109
DEPS_rustc := syntax fmt_macros flate arena serialize getopts rbml \
109110
log graphviz rustc_llvm rustc_back rustc_data_structures\
110-
rustc_const_math
111+
rustc_const_math syntax_pos rustc_errors
111112
DEPS_rustc_back := std syntax flate log libc
112-
DEPS_rustc_borrowck := rustc log graphviz syntax rustc_mir
113+
DEPS_rustc_borrowck := rustc log graphviz syntax syntax_pos rustc_errors rustc_mir
113114
DEPS_rustc_data_structures := std log serialize
114115
DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back rustc_borrowck \
115116
rustc_typeck rustc_mir rustc_resolve log syntax serialize rustc_llvm \
116117
rustc_trans rustc_privacy rustc_lint rustc_plugin \
117118
rustc_metadata syntax_ext rustc_passes rustc_save_analysis rustc_const_eval \
118-
rustc_incremental
119-
DEPS_rustc_lint := rustc log syntax rustc_const_eval
119+
rustc_incremental syntax_pos rustc_errors
120+
DEPS_rustc_errors := log libc serialize syntax_pos
121+
DEPS_rustc_lint := rustc log syntax syntax_pos rustc_const_eval
120122
DEPS_rustc_llvm := native:rustllvm libc std rustc_bitflags
121-
DEPS_rustc_metadata := rustc syntax rbml rustc_const_math
122-
DEPS_rustc_passes := syntax rustc core rustc_const_eval
123-
DEPS_rustc_mir := rustc syntax rustc_const_math rustc_const_eval rustc_bitflags
124-
DEPS_rustc_resolve := arena rustc log syntax
123+
DEPS_rustc_metadata := rustc syntax syntax_pos rustc_errors rbml rustc_const_math
124+
DEPS_rustc_passes := syntax syntax_pos rustc core rustc_const_eval rustc_errors
125+
DEPS_rustc_mir := rustc syntax syntax_pos rustc_const_math rustc_const_eval rustc_bitflags
126+
DEPS_rustc_resolve := arena rustc log syntax syntax_pos rustc_errors
125127
DEPS_rustc_platform_intrinsics := std
126-
DEPS_rustc_plugin := rustc rustc_metadata syntax
127-
DEPS_rustc_privacy := rustc log syntax
128+
DEPS_rustc_plugin := rustc rustc_metadata syntax syntax_pos rustc_errors
129+
DEPS_rustc_privacy := rustc log syntax syntax_pos
128130
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back \
129131
log syntax serialize rustc_llvm rustc_platform_intrinsics \
130-
rustc_const_math rustc_const_eval rustc_incremental
131-
DEPS_rustc_incremental := rbml rustc serialize rustc_data_structures
132-
DEPS_rustc_save_analysis := rustc log syntax serialize
133-
DEPS_rustc_typeck := rustc syntax rustc_platform_intrinsics rustc_const_math \
134-
rustc_const_eval
132+
rustc_const_math rustc_const_eval rustc_incremental rustc_errors syntax_pos
133+
DEPS_rustc_incremental := rbml rustc syntax_pos serialize rustc_data_structures
134+
DEPS_rustc_save_analysis := rustc log syntax syntax_pos serialize
135+
DEPS_rustc_typeck := rustc syntax syntax_pos rustc_platform_intrinsics rustc_const_math \
136+
rustc_const_eval rustc_errors
135137

136138
DEPS_rustdoc := rustc rustc_driver native:hoedown serialize getopts \
137-
test rustc_lint rustc_const_eval
139+
test rustc_lint rustc_const_eval syntax_pos
138140

139141

140142
TOOL_DEPS_compiletest := test getopts log serialize

src/doc/book/compiler-plugins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ extern crate syntax;
4545
extern crate rustc;
4646
extern crate rustc_plugin;
4747
48-
use syntax::codemap::Span;
4948
use syntax::parse::token;
5049
use syntax::ast::TokenTree;
5150
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
5251
use syntax::ext::build::AstBuilder; // trait for expr_usize
52+
use syntax_pos::Span;
5353
use rustc_plugin::Registry;
5454
5555
fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])

src/grammar/verify.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ use std::rc::Rc;
3232
use syntax::ast;
3333
use syntax::ast::Name;
3434
use syntax::codemap;
35-
use syntax::codemap::Pos;
3635
use syntax::parse::token::{self, BinOpToken, DelimToken, Lit, Token};
3736
use syntax::parse::lexer::TokenAndSpan;
37+
use syntax_pos::Pos;
3838

3939
fn parse_token_list(file: &str) -> HashMap<String, token::Token> {
4040
fn id() -> token::Token {
@@ -233,10 +233,10 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, token::Token>, surrogate_
233233
lo -= surrogate_pairs_pos.binary_search(&(lo as usize)).unwrap_or_else(|x| x) as u32;
234234
hi -= surrogate_pairs_pos.binary_search(&(hi as usize)).unwrap_or_else(|x| x) as u32;
235235

236-
let sp = codemap::Span {
237-
lo: codemap::BytePos(lo),
238-
hi: codemap::BytePos(hi),
239-
expn_id: codemap::NO_EXPANSION
236+
let sp = syntax_pos::Span {
237+
lo: syntax_pos::BytePos(lo),
238+
hi: syntax_pos::BytePos(hi),
239+
expn_id: syntax_pos::NO_EXPANSION
240240
};
241241

242242
TokenAndSpan {

src/librustc/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ rustc_back = { path = "../librustc_back" }
1919
rustc_bitflags = { path = "../librustc_bitflags" }
2020
rustc_const_math = { path = "../librustc_const_math" }
2121
rustc_data_structures = { path = "../librustc_data_structures" }
22+
rustc_errors = { path = "../librustc_errors" }
2223
rustc_llvm = { path = "../librustc_llvm" }
2324
serialize = { path = "../libserialize" }
2425
syntax = { path = "../libsyntax" }
26+
syntax_pos = { path "../libsyntax_pos" }

src/librustc/hir/fold.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, Attribute, Attribute_, MetaItem};
1616
use syntax::ast::MetaItemKind;
1717
use syntax::attr::ThinAttributesExt;
1818
use hir;
19-
use syntax::codemap::{respan, Span, Spanned};
19+
use syntax_pos::Span;
20+
use syntax::codemap::{respan, Spanned};
2021
use syntax::ptr::P;
2122
use syntax::parse::token::keywords;
2223
use syntax::util::move_map::MoveMap;

src/librustc/hir/intravisit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
use syntax::abi::Abi;
2929
use syntax::ast::{NodeId, CRATE_NODE_ID, Name, Attribute};
3030
use syntax::attr::ThinAttributesExt;
31-
use syntax::codemap::{Span, Spanned};
31+
use syntax::codemap::Spanned;
32+
use syntax_pos::Span;
3233
use hir::*;
3334

3435
use std::cmp;

src/librustc/hir/lowering.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ use std::iter;
5252
use syntax::ast::*;
5353
use syntax::attr::{ThinAttributes, ThinAttributesExt};
5454
use syntax::ptr::P;
55-
use syntax::codemap::{respan, Spanned, Span};
55+
use syntax::codemap::{respan, Spanned};
5656
use syntax::parse::token;
5757
use syntax::std_inject;
5858
use syntax::visit::{self, Visitor};
59+
use syntax_pos::Span;
5960

6061
pub struct LoweringContext<'a> {
6162
crate_root: Option<&'static str>,

src/librustc/hir/map/blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use hir::{Block, FnDecl};
2929
use syntax::ast::{Attribute, Name, NodeId};
3030
use syntax::attr::ThinAttributesExt;
3131
use hir as ast;
32-
use syntax::codemap::Span;
32+
use syntax_pos::Span;
3333
use hir::intravisit::FnKind;
3434

3535
/// An FnLikeNode is a Node that is like a fn, in that it has a decl

src/librustc/hir/map/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use hir::def_id::DefId;
1717
use middle::cstore::InlinedItem;
1818
use std::iter::repeat;
1919
use syntax::ast::{NodeId, CRATE_NODE_ID};
20-
use syntax::codemap::Span;
20+
use syntax_pos::Span;
2121

2222
/// A Visitor that walks over the HIR and collects Nodes into a HIR map
2323
pub struct NodeCollector<'ast> {

src/librustc/hir/map/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ use hir::def_id::{CRATE_DEF_INDEX, DefId, DefIndex};
2424
use syntax::abi::Abi;
2525
use syntax::ast::{self, Name, NodeId, DUMMY_NODE_ID, };
2626
use syntax::attr::ThinAttributesExt;
27-
use syntax::codemap::{Span, Spanned};
27+
use syntax::codemap::Spanned;
2828
use syntax::visit;
29+
use syntax_pos::Span;
2930

3031
use hir::*;
3132
use hir::fold::Folder;

0 commit comments

Comments
 (0)