Skip to content

Commit ef3bed8

Browse files
author
Ariel Ben-Yehuda
committed
---
yaml --- r: 211707 b: refs/heads/auto c: 080311d h: refs/heads/master i: 211705: ef49f6d 211703: 96ac605 v: v3
1 parent 7093c6e commit ef3bed8

File tree

19 files changed

+163
-210
lines changed

19 files changed

+163
-210
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 1a3cffbddfa21aac6fabd2f07f86703fbf1f26a5
13+
refs/heads/auto: 080311d1f9919fe877414b2e0c9e8260ae157ccf
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustc/diagnostics.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,8 @@ register_diagnostics! {
892892
E0316, // nested quantification of lifetimes
893893
E0370, // discriminant overflow
894894
E0378, // method calls limited to constant inherent methods
895-
E0394 // cannot refer to other statics by value, use the address-of
895+
E0394, // cannot refer to other statics by value, use the address-of
896896
// operator or a constant instead
897+
E0395, // pointer comparison in const-expr
898+
E0396 // pointer dereference in const-expr
897899
}

branches/auto/src/librustc/metadata/decoder.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,6 @@ fn doc_type<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, cdata: Cmd) -> Ty<'tcx>
252252
|_, did| translate_def_id(cdata, did))
253253
}
254254

255-
fn maybe_doc_type<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, cdata: Cmd) -> Option<Ty<'tcx>> {
256-
reader::maybe_get_doc(doc, tag_items_data_item_type).map(|tp| {
257-
parse_ty_data(tp.data, cdata.cnum, tp.start, tcx,
258-
|_, did| translate_def_id(cdata, did))
259-
})
260-
}
261-
262255
fn doc_method_fty<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>,
263256
cdata: Cmd) -> ty::BareFnTy<'tcx> {
264257
let tp = reader::get_doc(doc, tag_item_method_fty);
@@ -882,24 +875,24 @@ pub fn get_impl_or_trait_item<'tcx>(intr: Rc<IdentInterner>,
882875
id: ast::NodeId,
883876
tcx: &ty::ctxt<'tcx>)
884877
-> ty::ImplOrTraitItem<'tcx> {
885-
let item_doc = lookup_item(id, cdata.data());
878+
let method_doc = lookup_item(id, cdata.data());
886879

887-
let def_id = item_def_id(item_doc, cdata);
880+
let def_id = item_def_id(method_doc, cdata);
888881

889-
let container_id = item_require_parent_item(cdata, item_doc);
882+
let container_id = item_require_parent_item(cdata, method_doc);
890883
let container_doc = lookup_item(container_id.node, cdata.data());
891884
let container = match item_family(container_doc) {
892885
Trait => TraitContainer(container_id),
893886
_ => ImplContainer(container_id),
894887
};
895888

896-
let name = item_name(&*intr, item_doc);
897-
let vis = item_visibility(item_doc);
889+
let name = item_name(&*intr, method_doc);
890+
let vis = item_visibility(method_doc);
898891

899-
match item_sort(item_doc) {
892+
match item_sort(method_doc) {
900893
Some('C') => {
901-
let ty = doc_type(item_doc, tcx, cdata);
902-
let default = get_provided_source(item_doc, cdata);
894+
let ty = doc_type(method_doc, tcx, cdata);
895+
let default = get_provided_source(method_doc, cdata);
903896
ty::ConstTraitItem(Rc::new(ty::AssociatedConst {
904897
name: name,
905898
ty: ty,
@@ -910,11 +903,11 @@ pub fn get_impl_or_trait_item<'tcx>(intr: Rc<IdentInterner>,
910903
}))
911904
}
912905
Some('r') | Some('p') => {
913-
let generics = doc_generics(item_doc, tcx, cdata, tag_method_ty_generics);
914-
let predicates = doc_predicates(item_doc, tcx, cdata, tag_method_ty_generics);
915-
let fty = doc_method_fty(item_doc, tcx, cdata);
916-
let explicit_self = get_explicit_self(item_doc);
917-
let provided_source = get_provided_source(item_doc, cdata);
906+
let generics = doc_generics(method_doc, tcx, cdata, tag_method_ty_generics);
907+
let predicates = doc_predicates(method_doc, tcx, cdata, tag_method_ty_generics);
908+
let fty = doc_method_fty(method_doc, tcx, cdata);
909+
let explicit_self = get_explicit_self(method_doc);
910+
let provided_source = get_provided_source(method_doc, cdata);
918911

919912
ty::MethodTraitItem(Rc::new(ty::Method::new(name,
920913
generics,
@@ -927,10 +920,8 @@ pub fn get_impl_or_trait_item<'tcx>(intr: Rc<IdentInterner>,
927920
provided_source)))
928921
}
929922
Some('t') => {
930-
let ty = maybe_doc_type(item_doc, tcx, cdata);
931923
ty::TypeTraitItem(Rc::new(ty::AssociatedType {
932924
name: name,
933-
ty: ty,
934925
vis: vis,
935926
def_id: def_id,
936927
container: container,

branches/auto/src/librustc/metadata/encoder.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -894,12 +894,12 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
894894
rbml_w.end_tag();
895895
}
896896

897-
fn encode_info_for_associated_type<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
898-
rbml_w: &mut Encoder,
899-
associated_type: &ty::AssociatedType<'tcx>,
900-
impl_path: PathElems,
901-
parent_id: NodeId,
902-
impl_item_opt: Option<&ast::ImplItem>) {
897+
fn encode_info_for_associated_type(ecx: &EncodeContext,
898+
rbml_w: &mut Encoder,
899+
associated_type: &ty::AssociatedType,
900+
impl_path: PathElems,
901+
parent_id: NodeId,
902+
impl_item_opt: Option<&ast::ImplItem>) {
903903
debug!("encode_info_for_associated_type({:?},{:?})",
904904
associated_type.def_id,
905905
token::get_name(associated_type.name));
@@ -913,6 +913,8 @@ fn encode_info_for_associated_type<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
913913
encode_parent_item(rbml_w, local_def(parent_id));
914914
encode_item_sort(rbml_w, 't');
915915

916+
encode_bounds_and_type_for_item(rbml_w, ecx, associated_type.def_id.local_id());
917+
916918
let stab = stability::lookup(ecx.tcx, associated_type.def_id);
917919
encode_stability(rbml_w, stab);
918920

@@ -921,14 +923,7 @@ fn encode_info_for_associated_type<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
921923

922924
if let Some(ii) = impl_item_opt {
923925
encode_attributes(rbml_w, &ii.attrs);
924-
} else {
925-
encode_predicates(rbml_w, ecx,
926-
&ty::lookup_predicates(ecx.tcx, associated_type.def_id),
927-
tag_item_generics);
928-
}
929-
930-
if let Some(ty) = associated_type.ty {
931-
encode_type(ecx, rbml_w, ty);
926+
encode_type(ecx, rbml_w, ty::node_id_to_type(ecx.tcx, ii.id));
932927
}
933928

934929
rbml_w.end_tag();

branches/auto/src/librustc/middle/check_const.rs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,32 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
536536
"allocations are not allowed in {}s", v.msg());
537537
}
538538
}
539-
ast::ExprUnary(ast::UnDeref, ref ptr) => {
540-
match ty::node_id_to_type(v.tcx, ptr.id).sty {
539+
ast::ExprUnary(op, ref inner) => {
540+
match ty::node_id_to_type(v.tcx, inner.id).sty {
541541
ty::ty_ptr(_) => {
542-
// This shouldn't be allowed in constants at all.
542+
assert!(op == ast::UnDeref);
543+
544+
v.add_qualif(ConstQualif::NOT_CONST);
545+
if v.mode != Mode::Var {
546+
span_err!(v.tcx.sess, e.span, E0396,
547+
"raw pointers cannot be dereferenced in {}s", v.msg());
548+
}
549+
}
550+
_ => {}
551+
}
552+
}
553+
ast::ExprBinary(op, ref lhs, _) => {
554+
match ty::node_id_to_type(v.tcx, lhs.id).sty {
555+
ty::ty_ptr(_) => {
556+
assert!(op.node == ast::BiEq || op.node == ast::BiNe ||
557+
op.node == ast::BiLe || op.node == ast::BiLt ||
558+
op.node == ast::BiGe || op.node == ast::BiGt);
559+
543560
v.add_qualif(ConstQualif::NOT_CONST);
561+
if v.mode != Mode::Var {
562+
span_err!(v.tcx.sess, e.span, E0395,
563+
"raw pointers cannot be compared in {}s", v.msg());
564+
}
544565
}
545566
_ => {}
546567
}
@@ -553,7 +574,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
553574
v.add_qualif(ConstQualif::NOT_CONST);
554575
if v.mode != Mode::Var {
555576
span_err!(v.tcx.sess, e.span, E0018,
556-
"can't cast a pointer to an integer in {}s", v.msg());
577+
"raw pointers cannot be cast to integers in {}s", v.msg());
557578
}
558579
}
559580
_ => {}
@@ -695,8 +716,6 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>,
695716
}
696717

697718
ast::ExprBlock(_) |
698-
ast::ExprUnary(..) |
699-
ast::ExprBinary(..) |
700719
ast::ExprIndex(..) |
701720
ast::ExprField(..) |
702721
ast::ExprTupField(..) |

branches/auto/src/librustc/middle/traits/project.rs

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -857,41 +857,37 @@ fn confirm_impl_candidate<'cx,'tcx>(
857857
-> (Ty<'tcx>, Vec<PredicateObligation<'tcx>>)
858858
{
859859
// there don't seem to be nicer accessors to these:
860+
let impl_items_map = selcx.tcx().impl_items.borrow();
860861
let impl_or_trait_items_map = selcx.tcx().impl_or_trait_items.borrow();
861862

862-
// Look for the associated type in the impl
863-
for impl_item in &selcx.tcx().impl_items.borrow()[&impl_vtable.impl_def_id] {
864-
if let ty::TypeTraitItem(ref assoc_ty) = impl_or_trait_items_map[&impl_item.def_id()] {
865-
if assoc_ty.name == obligation.predicate.item_name {
866-
return (assoc_ty.ty.unwrap().subst(selcx.tcx(), &impl_vtable.substs),
867-
impl_vtable.nested.into_vec());
868-
}
863+
let impl_items = impl_items_map.get(&impl_vtable.impl_def_id).unwrap();
864+
let mut impl_ty = None;
865+
for impl_item in impl_items {
866+
let assoc_type = match *impl_or_trait_items_map.get(&impl_item.def_id()).unwrap() {
867+
ty::TypeTraitItem(ref assoc_type) => assoc_type.clone(),
868+
ty::ConstTraitItem(..) | ty::MethodTraitItem(..) => { continue; }
869+
};
870+
871+
if assoc_type.name != obligation.predicate.item_name {
872+
continue;
869873
}
874+
875+
let impl_poly_ty = ty::lookup_item_type(selcx.tcx(), assoc_type.def_id);
876+
impl_ty = Some(impl_poly_ty.ty.subst(selcx.tcx(), &impl_vtable.substs));
877+
break;
870878
}
871879

872-
// It is not in the impl - get the default from the trait.
873-
let trait_ref = obligation.predicate.trait_ref;
874-
for trait_item in ty::trait_items(selcx.tcx(), trait_ref.def_id).iter() {
875-
if let &ty::TypeTraitItem(ref assoc_ty) = trait_item {
876-
if assoc_ty.name == obligation.predicate.item_name {
877-
if let Some(ty) = assoc_ty.ty {
878-
return (ty.subst(selcx.tcx(), trait_ref.substs),
879-
impl_vtable.nested.into_vec());
880-
} else {
881-
// This means that the impl is missing a
882-
// definition for the associated type. This error
883-
// ought to be reported by the type checker method
884-
// `check_impl_items_against_trait`, so here we
885-
// just return ty_err.
886-
return (selcx.tcx().types.err, vec!());
887-
}
888-
}
880+
match impl_ty {
881+
Some(ty) => (ty, impl_vtable.nested.into_vec()),
882+
None => {
883+
// This means that the impl is missing a
884+
// definition for the associated type. This error
885+
// ought to be reported by the type checker method
886+
// `check_impl_items_against_trait`, so here we
887+
// just return ty_err.
888+
(selcx.tcx().types.err, vec!())
889889
}
890890
}
891-
892-
selcx.tcx().sess.span_bug(obligation.cause.span,
893-
&format!("No associated type for {}",
894-
trait_ref.repr(selcx.tcx())));
895891
}
896892

897893
impl<'tcx> Repr<'tcx> for ProjectionTyError<'tcx> {

branches/auto/src/librustc/middle/ty.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl ImplOrTraitItemContainer {
136136
pub enum ImplOrTraitItem<'tcx> {
137137
ConstTraitItem(Rc<AssociatedConst<'tcx>>),
138138
MethodTraitItem(Rc<Method<'tcx>>),
139-
TypeTraitItem(Rc<AssociatedType<'tcx>>),
139+
TypeTraitItem(Rc<AssociatedType>),
140140
}
141141

142142
impl<'tcx> ImplOrTraitItem<'tcx> {
@@ -267,9 +267,8 @@ pub struct AssociatedConst<'tcx> {
267267
}
268268

269269
#[derive(Clone, Copy, Debug)]
270-
pub struct AssociatedType<'tcx> {
270+
pub struct AssociatedType {
271271
pub name: ast::Name,
272-
pub ty: Option<Ty<'tcx>>,
273272
pub vis: ast::Visibility,
274273
pub def_id: ast::DefId,
275274
pub container: ImplOrTraitItemContainer,

branches/auto/src/librustc/util/ppaux.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ impl<'tcx> Repr<'tcx> for ty::AssociatedConst<'tcx> {
10771077
}
10781078
}
10791079

1080-
impl<'tcx> Repr<'tcx> for ty::AssociatedType<'tcx> {
1080+
impl<'tcx> Repr<'tcx> for ty::AssociatedType {
10811081
fn repr(&self, tcx: &ctxt<'tcx>) -> String {
10821082
format!("AssociatedType(name: {}, vis: {}, def_id: {})",
10831083
self.name.repr(tcx),

branches/auto/src/librustc_typeck/check/mod.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
10701070
// Check for missing items from trait
10711071
let provided_methods = ty::provided_trait_methods(tcx, impl_trait_ref.def_id);
10721072
let associated_consts = ty::associated_consts(tcx, impl_trait_ref.def_id);
1073-
let mut missing_items = Vec::new();
1073+
let mut missing_methods = Vec::new();
10741074
for trait_item in &*trait_items {
10751075
match *trait_item {
10761076
ty::ConstTraitItem(ref associated_const) => {
@@ -1086,8 +1086,8 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
10861086
associated_consts.iter().any(|ac| ac.default.is_some() &&
10871087
ac.name == associated_const.name);
10881088
if !is_implemented && !is_provided {
1089-
missing_items.push(format!("`{}`",
1090-
token::get_name(associated_const.name)));
1089+
missing_methods.push(format!("`{}`",
1090+
token::get_name(associated_const.name)));
10911091
}
10921092
}
10931093
ty::MethodTraitItem(ref trait_method) => {
@@ -1103,7 +1103,7 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
11031103
let is_provided =
11041104
provided_methods.iter().any(|m| m.name == trait_method.name);
11051105
if !is_implemented && !is_provided {
1106-
missing_items.push(format!("`{}`", token::get_name(trait_method.name)));
1106+
missing_methods.push(format!("`{}`", token::get_name(trait_method.name)));
11071107
}
11081108
}
11091109
ty::TypeTraitItem(ref associated_type) => {
@@ -1115,18 +1115,17 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
11151115
_ => false,
11161116
}
11171117
});
1118-
let is_provided = associated_type.ty.is_some();
1119-
if !is_implemented && !is_provided {
1120-
missing_items.push(format!("`{}`", token::get_name(associated_type.name)));
1118+
if !is_implemented {
1119+
missing_methods.push(format!("`{}`", token::get_name(associated_type.name)));
11211120
}
11221121
}
11231122
}
11241123
}
11251124

1126-
if !missing_items.is_empty() {
1125+
if !missing_methods.is_empty() {
11271126
span_err!(tcx.sess, impl_span, E0046,
11281127
"not all trait items implemented, missing: {}",
1129-
missing_items.connect(", "));
1128+
missing_methods.connect(", "));
11301129
}
11311130
}
11321131

0 commit comments

Comments
 (0)