Skip to content

Commit d3ae56d

Browse files
committed
Rollup merge of rust-lang#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;

src/librustc/hir/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ use hir::def::Def;
3636
use hir::def_id::DefId;
3737
use util::nodemap::{NodeMap, FnvHashSet};
3838

39-
use syntax::codemap::{self, mk_sp, respan, Span, Spanned, ExpnId};
39+
use syntax_pos::{mk_sp, Span, ExpnId};
40+
use syntax::codemap::{self, respan, Spanned};
4041
use syntax::abi::Abi;
4142
use syntax::ast::{Name, NodeId, DUMMY_NODE_ID, TokenTree, AsmDialect};
4243
use syntax::ast::{Attribute, Lit, StrStyle, FloatTy, IntTy, UintTy, MetaItem};

src/librustc/hir/pat_util.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use hir::{self, PatKind};
1414
use ty::TyCtxt;
1515
use util::nodemap::FnvHashMap;
1616
use syntax::ast;
17-
use syntax::codemap::{Span, Spanned, DUMMY_SP};
17+
use syntax::codemap::Spanned;
18+
use syntax_pos::{Span, DUMMY_SP};
1819

1920
use std::iter::{Enumerate, ExactSizeIterator};
2021

src/librustc/hir/print.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ pub use self::AnnNode::*;
1212

1313
use syntax::abi::Abi;
1414
use syntax::ast;
15-
use syntax::codemap::{self, CodeMap, BytePos, Spanned};
16-
use syntax::errors;
15+
use syntax::codemap::{CodeMap, Spanned};
1716
use syntax::parse::token::{self, keywords, BinOpToken};
1817
use syntax::parse::lexer::comments;
1918
use syntax::print::pp::{self, break_offset, word, space, hardbreak};
2019
use syntax::print::pp::{Breaks, eof};
2120
use syntax::print::pp::Breaks::{Consistent, Inconsistent};
2221
use syntax::print::pprust::{self as ast_pp, PrintState};
2322
use syntax::ptr::P;
23+
use syntax_pos::{self, BytePos};
24+
use errors;
2425

2526
use hir;
2627
use hir::{Crate, PatKind, RegionTyParamBound, SelfKind, TraitTyParamBound, TraitBoundModifier};
@@ -368,11 +369,11 @@ impl<'a> State<'a> {
368369
self.end() // close the head-box
369370
}
370371

371-
pub fn bclose_(&mut self, span: codemap::Span, indented: usize) -> io::Result<()> {
372+
pub fn bclose_(&mut self, span: syntax_pos::Span, indented: usize) -> io::Result<()> {
372373
self.bclose_maybe_open(span, indented, true)
373374
}
374375
pub fn bclose_maybe_open(&mut self,
375-
span: codemap::Span,
376+
span: syntax_pos::Span,
376377
indented: usize,
377378
close_box: bool)
378379
-> io::Result<()> {
@@ -384,7 +385,7 @@ impl<'a> State<'a> {
384385
}
385386
Ok(())
386387
}
387-
pub fn bclose(&mut self, span: codemap::Span) -> io::Result<()> {
388+
pub fn bclose(&mut self, span: syntax_pos::Span) -> io::Result<()> {
388389
self.bclose_(span, indent_unit)
389390
}
390391

@@ -432,7 +433,7 @@ impl<'a> State<'a> {
432433
mut get_span: G)
433434
-> io::Result<()>
434435
where F: FnMut(&mut State, &T) -> io::Result<()>,
435-
G: FnMut(&T) -> codemap::Span
436+
G: FnMut(&T) -> syntax_pos::Span
436437
{
437438
self.rbox(0, b)?;
438439
let len = elts.len();
@@ -859,7 +860,7 @@ impl<'a> State<'a> {
859860
enum_definition: &hir::EnumDef,
860861
generics: &hir::Generics,
861862
name: ast::Name,
862-
span: codemap::Span,
863+
span: syntax_pos::Span,
863864
visibility: &hir::Visibility)
864865
-> io::Result<()> {
865866
self.head(&visibility_qualified(visibility, "enum"))?;
@@ -872,7 +873,7 @@ impl<'a> State<'a> {
872873

873874
pub fn print_variants(&mut self,
874875
variants: &[hir::Variant],
875-
span: codemap::Span)
876+
span: syntax_pos::Span)
876877
-> io::Result<()> {
877878
self.bopen()?;
878879
for v in variants {
@@ -902,7 +903,7 @@ impl<'a> State<'a> {
902903
struct_def: &hir::VariantData,
903904
generics: &hir::Generics,
904905
name: ast::Name,
905-
span: codemap::Span,
906+
span: syntax_pos::Span,
906907
print_finalizer: bool)
907908
-> io::Result<()> {
908909
self.print_name(name)?;
@@ -2237,7 +2238,7 @@ impl<'a> State<'a> {
22372238
}
22382239

22392240
pub fn maybe_print_trailing_comment(&mut self,
2240-
span: codemap::Span,
2241+
span: syntax_pos::Span,
22412242
next_pos: Option<BytePos>)
22422243
-> io::Result<()> {
22432244
let cm = match self.cm {

src/librustc/infer/combine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use ty::relate::{RelateResult, TypeRelation};
4949
use traits::PredicateObligations;
5050

5151
use syntax::ast;
52-
use syntax::codemap::Span;
52+
use syntax_pos::Span;
5353

5454
#[derive(Clone)]
5555
pub struct CombineFields<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {

src/librustc/infer/error_reporting.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ use std::cell::{Cell, RefCell};
9191
use std::char::from_u32;
9292
use std::fmt;
9393
use syntax::ast;
94-
use syntax::errors::{DiagnosticBuilder, check_old_skool};
95-
use syntax::codemap::{self, Pos, Span};
9694
use syntax::parse::token;
9795
use syntax::ptr::P;
96+
use syntax_pos::{self, Pos, Span};
97+
use errors::{DiagnosticBuilder, check_old_skool};
9898

9999
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
100100
pub fn note_and_explain_region(self,
@@ -1933,6 +1933,6 @@ impl LifeGiver {
19331933

19341934
fn name_to_dummy_lifetime(name: ast::Name) -> hir::Lifetime {
19351935
hir::Lifetime { id: ast::DUMMY_NODE_ID,
1936-
span: codemap::DUMMY_SP,
1936+
span: syntax_pos::DUMMY_SP,
19371937
name: name }
19381938
}

src/librustc/infer/higher_ranked/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use super::region_inference::{TaintDirections};
2323
use ty::{self, TyCtxt, Binder, TypeFoldable};
2424
use ty::error::TypeError;
2525
use ty::relate::{Relate, RelateResult, TypeRelation};
26-
use syntax::codemap::Span;
26+
use syntax_pos::Span;
2727
use util::nodemap::{FnvHashMap, FnvHashSet};
2828

2929
pub struct HrMatchResult<U> {

src/librustc/infer/mod.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ use rustc_data_structures::unify::{self, UnificationTable};
3939
use std::cell::{Cell, RefCell, Ref, RefMut};
4040
use std::fmt;
4141
use syntax::ast;
42-
use syntax::codemap;
43-
use syntax::codemap::{Span, DUMMY_SP};
44-
use syntax::errors::DiagnosticBuilder;
42+
use errors::DiagnosticBuilder;
43+
use syntax_pos::{self, Span, DUMMY_SP};
4544
use util::nodemap::{FnvHashMap, FnvHashSet, NodeMap};
4645

4746
use self::combine::CombineFields;
@@ -1036,7 +1035,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
10361035
-> UnitResult<'tcx>
10371036
{
10381037
self.probe(|_| {
1039-
let origin = TypeOrigin::Misc(codemap::DUMMY_SP);
1038+
let origin = TypeOrigin::Misc(syntax_pos::DUMMY_SP);
10401039
let trace = TypeTrace::types(origin, true, a, b);
10411040
self.sub(true, trace, &a, &b).map(|_| ())
10421041
})
@@ -1813,7 +1812,7 @@ impl<'a, 'gcx, 'tcx> TypeTrace<'tcx> {
18131812

18141813
pub fn dummy(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> TypeTrace<'tcx> {
18151814
TypeTrace {
1816-
origin: TypeOrigin::Misc(codemap::DUMMY_SP),
1815+
origin: TypeOrigin::Misc(syntax_pos::DUMMY_SP),
18171816
values: Types(ExpectedFound {
18181817
expected: tcx.types.err,
18191818
found: tcx.types.err,
@@ -1887,7 +1886,7 @@ impl RegionVariableOrigin {
18871886
Coercion(a) => a,
18881887
EarlyBoundRegion(a, _) => a,
18891888
LateBoundRegion(a, _, _) => a,
1890-
BoundRegionInCoherence(_) => codemap::DUMMY_SP,
1889+
BoundRegionInCoherence(_) => syntax_pos::DUMMY_SP,
18911890
UpvarRegion(_, a) => a
18921891
}
18931892
}

src/librustc/infer/type_variable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use self::TypeVariableValue::*;
1313
use self::UndoEntry::*;
1414
use hir::def_id::{DefId};
1515
use ty::{self, Ty};
16-
use syntax::codemap::Span;
16+
use syntax_pos::Span;
1717

1818
use std::cmp::min;
1919
use std::marker::PhantomData;

src/librustc/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ extern crate rustc_data_structures;
5555
extern crate serialize;
5656
extern crate collections;
5757
extern crate rustc_const_math;
58+
extern crate rustc_errors as errors;
5859
#[macro_use] extern crate log;
5960
#[macro_use] extern crate syntax;
61+
#[macro_use] extern crate syntax_pos;
6062
#[macro_use] #[no_link] extern crate rustc_bitflags;
6163

6264
extern crate serialize as rustc_serialize; // used by deriving

0 commit comments

Comments
 (0)