Skip to content

Commit 99a1293

Browse files
jroeschJared Roesch
authored and
Jared Roesch
committed
Rework cross crate error messages
1 parent ed3fbba commit 99a1293

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
@@ -1061,11 +1061,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10611061

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

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
@@ -79,6 +79,7 @@ use std::ops;
7979
use std::rc::Rc;
8080
use std::vec::IntoIter;
8181
use collections::enum_set::{self, EnumSet, CLike};
82+
use collections::slice::SliceConcatExt;
8283
use std::collections::{HashMap, HashSet};
8384
use syntax::abi;
8485
use syntax::ast::{CrateNum, DefId, ItemImpl, ItemTrait, LOCAL_CRATE};
@@ -5448,17 +5449,47 @@ impl<'tcx> ctxt<'tcx> {
54485449
let expected = values.expected;
54495450
let found = values.found;
54505451
self.sess.span_note(sp,
5451-
&format!("conflicting type parameter defaults {} and {}",
5452-
expected.ty,
5453-
found.ty));
5454-
self.sess.span_note(expected.definition_span,
5455-
&format!("a default was defined here..."));
5452+
&format!("conflicting type parameter defaults `{}` and `{}`",
5453+
expected.ty,
5454+
found.ty));
5455+
5456+
match (expected.def_id.krate == ast::LOCAL_CRATE, self.map.opt_span(expected.def_id.node)) {
5457+
(true, Some(span)) => {
5458+
self.sess.span_note(span,
5459+
&format!("a default was defined here..."));
5460+
}
5461+
(_, _) => {
5462+
let elems = csearch::get_item_path(self, expected.def_id)
5463+
.into_iter()
5464+
.map(|p| p.to_string())
5465+
.collect::<Vec<_>>();
5466+
self.sess.note(
5467+
&format!("a default is defined on `{}`",
5468+
elems.join("::")));
5469+
}
5470+
}
5471+
54565472
self.sess.span_note(expected.origin_span,
5457-
&format!("...that was applied to an unconstrained type variable here"));
5458-
self.sess.span_note(found.definition_span,
5459-
&format!("a second default was defined here..."));
5473+
&format!("...that was applied to an unconstrained type variable here"));
5474+
5475+
match (found.def_id.krate == ast::LOCAL_CRATE, self.map.opt_span(found.def_id.node)) {
5476+
(true, Some(span)) => {
5477+
self.sess.span_note(span,
5478+
&format!("a second default was defined here..."));
5479+
}
5480+
(_, _) => {
5481+
let elems = csearch::get_item_path(self, found.def_id)
5482+
.into_iter()
5483+
.map(|p| p.to_string())
5484+
.collect::<Vec<_>>();
5485+
5486+
self.sess.note(
5487+
&format!("a second default is defined on `{}`", elems.join(" ")));
5488+
}
5489+
}
5490+
54605491
self.sess.span_note(found.origin_span,
5461-
&format!("...that also applies to the same type variable here"));
5492+
&format!("...that also applies to the same type variable here"));
54625493
}
54635494
_ => {}
54645495
}

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,14 +1146,10 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
11461146
span: Span) -> Ty<'tcx> {
11471147
// Grab the default doing subsitution
11481148
let default = ty_param_def.and_then(|def| {
1149-
let definition_span = self.tcx()
1150-
.map
1151-
.opt_span(def.def_id.node);
1152-
11531149
def.default.map(|ty| type_variable::Default {
11541150
ty: ty.subst_spanned(self.tcx(), substs.as_ref().unwrap(), Some(span)),
11551151
origin_span: span,
1156-
definition_span: definition_span.unwrap_or(codemap::DUMMY_SP)
1152+
def_id: def.default_def_id
11571153
})
11581154
});
11591155

@@ -1850,7 +1846,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18501846
.unwrap_or(type_variable::Default {
18511847
ty: self.infcx().next_ty_var(),
18521848
origin_span: codemap::DUMMY_SP,
1853-
definition_span: codemap::DUMMY_SP
1849+
def_id: local_def(0) // what do I put here?
18541850
});
18551851

18561852
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
@@ -1647,12 +1647,14 @@ fn ty_generics_for_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
16471647
// the node id for the Self type parameter.
16481648
let param_id = trait_id;
16491649

1650+
let parent = ccx.tcx.map.get_parent(param_id);
1651+
16501652
let def = ty::TypeParameterDef {
16511653
space: SelfSpace,
16521654
index: 0,
16531655
name: special_idents::type_self.name,
16541656
def_id: local_def(param_id),
1655-
default_def_id: local_def(param_id),
1657+
default_def_id: local_def(parent),
16561658
default: None,
16571659
object_lifetime_default: ty::ObjectLifetimeDefault::BaseDefault,
16581660
};
@@ -1921,13 +1923,15 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
19211923
compute_object_lifetime_default(ccx, param.id,
19221924
&param.bounds, &ast_generics.where_clause);
19231925

1926+
let parent = tcx.map.get_parent(param.id);
1927+
19241928
let def = ty::TypeParameterDef {
19251929
space: space,
19261930
index: index,
19271931
name: param.ident.name,
19281932
def_id: local_def(param.id),
19291933
// what do I return? should this be an option as well
1930-
default_def_id: local_def(param.default.as_ref().map(|d| d.id).unwrap_or(param.id)),
1934+
default_def_id: local_def(parent),
19311935
default: default,
19321936
object_lifetime_default: object_lifetime_default,
19331937
};

0 commit comments

Comments
 (0)