Skip to content

Commit 0943327

Browse files
committed
Rework cross crate error messages
1 parent 815f26c commit 0943327

File tree

6 files changed

+52
-20
lines changed

6 files changed

+52
-20
lines changed

src/librustc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#![feature(slice_splits)]
5757
#![feature(slice_patterns)]
5858
#![feature(slice_position_elem)]
59+
#![feature(slice_concat_ext)]
5960
#![feature(staged_api)]
6061
#![feature(str_char)]
6162
#![feature(str_match_indices)]

src/librustc/middle/infer/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,11 +1062,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10621062

10631063
for def in defs.iter() {
10641064
let default = def.default.map(|default| {
1065-
let definition_span = self.tcx.map.opt_span(def.def_id.node);
10661065
type_variable::Default {
10671066
ty: default.subst_spanned(self.tcx, substs, Some(span)),
10681067
origin_span: span,
1069-
definition_span: definition_span.unwrap_or(DUMMY_SP)
1068+
def_id: def.default_def_id
10701069
}
10711070
});
10721071

src/librustc/middle/infer/type_variable.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub use self::RelationDir::*;
1212
use self::TypeVariableValue::*;
1313
use self::UndoEntry::*;
1414
use middle::ty::{self, Ty};
15+
use syntax::ast::DefId;
1516
use syntax::codemap::Span;
1617

1718
use std::cmp::min;
@@ -45,7 +46,7 @@ pub struct Default<'tcx> {
4546
/// The span where the default was incurred
4647
pub origin_span: Span,
4748
/// The definition that the default originates from
48-
pub definition_span: Span
49+
pub def_id: DefId
4950
}
5051

5152
pub struct Snapshot {

src/librustc/middle/ty.rs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ use std::ops;
7878
use std::rc::Rc;
7979
use std::vec::IntoIter;
8080
use collections::enum_set::{self, EnumSet, CLike};
81+
use collections::slice::SliceConcatExt;
8182
use std::collections::{HashMap, HashSet};
8283
use syntax::abi;
8384
use syntax::ast::{CrateNum, DefId, ItemImpl, ItemTrait, LOCAL_CRATE};
@@ -5466,17 +5467,47 @@ impl<'tcx> ctxt<'tcx> {
54665467
let expected = values.expected;
54675468
let found = values.found;
54685469
self.sess.span_note(sp,
5469-
&format!("conflicting type parameter defaults {} and {}",
5470-
expected.ty,
5471-
found.ty));
5472-
self.sess.span_note(expected.definition_span,
5473-
&format!("a default was defined here..."));
5470+
&format!("conflicting type parameter defaults `{}` and `{}`",
5471+
expected.ty,
5472+
found.ty));
5473+
5474+
match (expected.def_id.krate == ast::LOCAL_CRATE, self.map.opt_span(expected.def_id.node)) {
5475+
(true, Some(span)) => {
5476+
self.sess.span_note(span,
5477+
&format!("a default was defined here..."));
5478+
}
5479+
(_, _) => {
5480+
let elems = csearch::get_item_path(self, expected.def_id)
5481+
.into_iter()
5482+
.map(|p| p.to_string())
5483+
.collect::<Vec<_>>();
5484+
self.sess.note(
5485+
&format!("a default is defined on `{}`",
5486+
elems.join("::")));
5487+
}
5488+
}
5489+
54745490
self.sess.span_note(expected.origin_span,
5475-
&format!("...that was applied to an unconstrained type variable here"));
5476-
self.sess.span_note(found.definition_span,
5477-
&format!("a second default was defined here..."));
5491+
&format!("...that was applied to an unconstrained type variable here"));
5492+
5493+
match (found.def_id.krate == ast::LOCAL_CRATE, self.map.opt_span(found.def_id.node)) {
5494+
(true, Some(span)) => {
5495+
self.sess.span_note(span,
5496+
&format!("a second default was defined here..."));
5497+
}
5498+
(_, _) => {
5499+
let elems = csearch::get_item_path(self, found.def_id)
5500+
.into_iter()
5501+
.map(|p| p.to_string())
5502+
.collect::<Vec<_>>();
5503+
5504+
self.sess.note(
5505+
&format!("a second default is defined on `{}`", elems.join(" ")));
5506+
}
5507+
}
5508+
54785509
self.sess.span_note(found.origin_span,
5479-
&format!("...that also applies to the same type variable here"));
5510+
&format!("...that also applies to the same type variable here"));
54805511
}
54815512
_ => {}
54825513
}

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,14 +1140,10 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
11401140
span: Span) -> Ty<'tcx> {
11411141
// Grab the default doing subsitution
11421142
let default = ty_param_def.and_then(|def| {
1143-
let definition_span = self.tcx()
1144-
.map
1145-
.opt_span(def.def_id.node);
1146-
11471143
def.default.map(|ty| type_variable::Default {
11481144
ty: ty.subst_spanned(self.tcx(), substs.as_ref().unwrap(), Some(span)),
11491145
origin_span: span,
1150-
definition_span: definition_span.unwrap_or(codemap::DUMMY_SP)
1146+
def_id: def.default_def_id
11511147
})
11521148
});
11531149

@@ -1844,7 +1840,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18441840
.unwrap_or(type_variable::Default {
18451841
ty: self.infcx().next_ty_var(),
18461842
origin_span: codemap::DUMMY_SP,
1847-
definition_span: codemap::DUMMY_SP
1843+
def_id: local_def(0) // what do I put here?
18481844
});
18491845

18501846
self.infcx().report_conflicting_default_types(

src/librustc_typeck/collect.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,12 +1634,14 @@ fn ty_generics_for_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
16341634
// the node id for the Self type parameter.
16351635
let param_id = trait_id;
16361636

1637+
let parent = ccx.tcx.map.get_parent(param_id);
1638+
16371639
let def = ty::TypeParameterDef {
16381640
space: SelfSpace,
16391641
index: 0,
16401642
name: special_idents::type_self.name,
16411643
def_id: local_def(param_id),
1642-
default_def_id: local_def(param_id),
1644+
default_def_id: local_def(parent),
16431645
default: None,
16441646
object_lifetime_default: ty::ObjectLifetimeDefault::BaseDefault,
16451647
};
@@ -1908,13 +1910,15 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
19081910
compute_object_lifetime_default(ccx, param.id,
19091911
&param.bounds, &ast_generics.where_clause);
19101912

1913+
let parent = tcx.map.get_parent(param.id);
1914+
19111915
let def = ty::TypeParameterDef {
19121916
space: space,
19131917
index: index,
19141918
name: param.ident.name,
19151919
def_id: local_def(param.id),
19161920
// what do I return? should this be an option as well
1917-
default_def_id: local_def(param.default.as_ref().map(|d| d.id).unwrap_or(param.id)),
1921+
default_def_id: local_def(parent),
19181922
default: default,
19191923
object_lifetime_default: object_lifetime_default,
19201924
};

0 commit comments

Comments
 (0)