Skip to content

Commit fb3ef19

Browse files
author
Jorge Aparicio
committed
---
yaml --- r: 191327 b: refs/heads/try c: 8570739 h: refs/heads/master i: 191325: 414bd68 191323: 5260ce4 191319: 35d5d25 191311: 9bab26b 191295: 83f7016 v: v3
1 parent ec9c092 commit fb3ef19

File tree

18 files changed

+508
-409
lines changed

18 files changed

+508
-409
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 809a554fca2d0ebc2ba50077016fe282a4064752
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: c64d671671aea2e44ee7fc6eb00ee75fc30ed7b9
5-
refs/heads/try: a2572885ab62512a2508868a27c22d615382174a
5+
refs/heads/try: 85707398809f8b56afc471f228bd4d0137ce0a32
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/compiletest/compiletest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#![feature(std_misc)]
2121
#![feature(test)]
2222
#![feature(core)]
23+
#![feature(net)]
2324
#![feature(path_ext)]
2425

2526
#![deny(warnings)]

branches/try/src/librustc/middle/lang_items.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,24 @@ pub fn collect_language_items(krate: &ast::Crate,
239239

240240
lets_do_this! {
241241
// Variant name, Name, Method name;
242+
CharImplItem, "char", char_impl;
243+
StrImplItem, "str", str_impl;
244+
SliceImplItem, "slice", slice_impl;
245+
ConstPtrImplItem, "const_ptr", const_ptr_impl;
246+
MutPtrImplItem, "mut_ptr", mut_ptr_impl;
247+
I8ImplItem, "i8", i8_impl;
248+
I16ImplItem, "i16", i16_impl;
249+
I32ImplItem, "i32", i32_impl;
250+
I64ImplItem, "i64", i64_impl;
251+
IsizeImplItem, "isize", isize_impl;
252+
U8ImplItem, "u8", u8_impl;
253+
U16ImplItem, "u16", u16_impl;
254+
U32ImplItem, "u32", u32_impl;
255+
U64ImplItem, "u64", u64_impl;
256+
UsizeImplItem, "usize", usize_impl;
257+
F32ImplItem, "f32", f32_impl;
258+
F64ImplItem, "f64", f64_impl;
259+
242260
SendTraitLangItem, "send", send_trait;
243261
SizedTraitLangItem, "sized", sized_trait;
244262
CopyTraitLangItem, "copy", copy_trait;

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,9 @@ pub struct ctxt<'tcx> {
788788
/// is used for lazy resolution of traits.
789789
pub populated_external_traits: RefCell<DefIdSet>,
790790

791+
/// The set of external primitive inherent implementations that have been read.
792+
pub populated_external_primitive_impls: RefCell<DefIdSet>,
793+
791794
/// Borrows
792795
pub upvar_capture_map: RefCell<UpvarCaptureMap>,
793796

@@ -2599,6 +2602,7 @@ pub fn mk_ctxt<'tcx>(s: Session,
25992602
used_mut_nodes: RefCell::new(NodeSet()),
26002603
populated_external_types: RefCell::new(DefIdSet()),
26012604
populated_external_traits: RefCell::new(DefIdSet()),
2605+
populated_external_primitive_impls: RefCell::new(DefIdSet()),
26022606
upvar_capture_map: RefCell::new(FnvHashMap()),
26032607
extern_const_statics: RefCell::new(DefIdMap()),
26042608
extern_const_variants: RefCell::new(DefIdMap()),
@@ -5988,6 +5992,25 @@ pub fn record_trait_implementation(tcx: &ctxt,
59885992
tcx.trait_impls.borrow_mut().insert(trait_def_id, Rc::new(RefCell::new(vec!(impl_def_id))));
59895993
}
59905994

5995+
/// Load primitive inherent implementations if necessary
5996+
pub fn populate_implementations_for_primitive_if_necessary(tcx: &ctxt, lang_def_id: ast::DefId) {
5997+
if lang_def_id.krate == LOCAL_CRATE {
5998+
return
5999+
}
6000+
if tcx.populated_external_primitive_impls.borrow().contains(&lang_def_id) {
6001+
return
6002+
}
6003+
6004+
debug!("populate_implementations_for_primitive_if_necessary: searching for {:?}", lang_def_id);
6005+
6006+
let impl_items = csearch::get_impl_items(&tcx.sess.cstore, lang_def_id);
6007+
6008+
// Store the implementation info.
6009+
tcx.impl_items.borrow_mut().insert(lang_def_id, impl_items);
6010+
6011+
tcx.populated_external_primitive_impls.borrow_mut().insert(lang_def_id);
6012+
}
6013+
59916014
/// Populates the type context with all the implementations for the given type
59926015
/// if necessary.
59936016
pub fn populate_implementations_for_type_if_necessary(tcx: &ctxt,

branches/try/src/librustc_typeck/check/method/probe.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,87 @@ impl<'a,'tcx> ProbeContext<'a,'tcx> {
289289
ty::ty_param(p) => {
290290
self.assemble_inherent_candidates_from_param(self_ty, p);
291291
}
292+
ty::ty_char => {
293+
let lang_def_id = self.tcx().lang_items.char_impl();
294+
self.assemble_inherent_impl_for_primitive(lang_def_id);
295+
}
296+
ty::ty_str => {
297+
let lang_def_id = self.tcx().lang_items.str_impl();
298+
self.assemble_inherent_impl_for_primitive(lang_def_id);
299+
}
300+
ty::ty_vec(_, None) => {
301+
let lang_def_id = self.tcx().lang_items.slice_impl();
302+
self.assemble_inherent_impl_for_primitive(lang_def_id);
303+
}
304+
ty::ty_ptr(ty::mt { ty: _, mutbl: ast::MutImmutable }) => {
305+
let lang_def_id = self.tcx().lang_items.const_ptr_impl();
306+
self.assemble_inherent_impl_for_primitive(lang_def_id);
307+
}
308+
ty::ty_ptr(ty::mt { ty: _, mutbl: ast::MutMutable }) => {
309+
let lang_def_id = self.tcx().lang_items.mut_ptr_impl();
310+
self.assemble_inherent_impl_for_primitive(lang_def_id);
311+
}
312+
ty::ty_int(ast::TyI8) => {
313+
let lang_def_id = self.tcx().lang_items.i8_impl();
314+
self.assemble_inherent_impl_for_primitive(lang_def_id);
315+
}
316+
ty::ty_int(ast::TyI16) => {
317+
let lang_def_id = self.tcx().lang_items.i16_impl();
318+
self.assemble_inherent_impl_for_primitive(lang_def_id);
319+
}
320+
ty::ty_int(ast::TyI32) => {
321+
let lang_def_id = self.tcx().lang_items.i32_impl();
322+
self.assemble_inherent_impl_for_primitive(lang_def_id);
323+
}
324+
ty::ty_int(ast::TyI64) => {
325+
let lang_def_id = self.tcx().lang_items.i64_impl();
326+
self.assemble_inherent_impl_for_primitive(lang_def_id);
327+
}
328+
ty::ty_int(ast::TyIs(_)) => {
329+
let lang_def_id = self.tcx().lang_items.isize_impl();
330+
self.assemble_inherent_impl_for_primitive(lang_def_id);
331+
}
332+
ty::ty_uint(ast::TyU8) => {
333+
let lang_def_id = self.tcx().lang_items.u8_impl();
334+
self.assemble_inherent_impl_for_primitive(lang_def_id);
335+
}
336+
ty::ty_uint(ast::TyU16) => {
337+
let lang_def_id = self.tcx().lang_items.u16_impl();
338+
self.assemble_inherent_impl_for_primitive(lang_def_id);
339+
}
340+
ty::ty_uint(ast::TyU32) => {
341+
let lang_def_id = self.tcx().lang_items.u32_impl();
342+
self.assemble_inherent_impl_for_primitive(lang_def_id);
343+
}
344+
ty::ty_uint(ast::TyU64) => {
345+
let lang_def_id = self.tcx().lang_items.u64_impl();
346+
self.assemble_inherent_impl_for_primitive(lang_def_id);
347+
}
348+
ty::ty_uint(ast::TyUs(_)) => {
349+
let lang_def_id = self.tcx().lang_items.usize_impl();
350+
self.assemble_inherent_impl_for_primitive(lang_def_id);
351+
}
352+
ty::ty_float(ast::TyF32) => {
353+
let lang_def_id = self.tcx().lang_items.f32_impl();
354+
self.assemble_inherent_impl_for_primitive(lang_def_id);
355+
}
356+
ty::ty_float(ast::TyF64) => {
357+
let lang_def_id = self.tcx().lang_items.f64_impl();
358+
self.assemble_inherent_impl_for_primitive(lang_def_id);
359+
}
292360
_ => {
293361
}
294362
}
295363
}
296364

365+
fn assemble_inherent_impl_for_primitive(&mut self, lang_def_id: Option<ast::DefId>) {
366+
if let Some(impl_def_id) = lang_def_id {
367+
ty::populate_implementations_for_primitive_if_necessary(self.tcx(), impl_def_id);
368+
369+
self.assemble_inherent_impl_probe(impl_def_id);
370+
}
371+
}
372+
297373
fn assemble_inherent_impl_candidates_for_type(&mut self, def_id: ast::DefId) {
298374
// Read the inherent implementation candidates for this type from the
299375
// metadata if necessary.

branches/try/src/librustc_typeck/coherence/orphan.rs

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use middle::ty;
1616
use syntax::ast::{Item, ItemImpl};
1717
use syntax::ast;
1818
use syntax::ast_util;
19+
use syntax::codemap::Span;
1920
use syntax::visit;
2021
use util::ppaux::{Repr, UserString};
2122

@@ -38,6 +39,23 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
3839
}
3940
}
4041

42+
fn check_primitive_impl(&self,
43+
impl_def_id: ast::DefId,
44+
lang_def_id: Option<ast::DefId>,
45+
lang: &str,
46+
ty: &str,
47+
span: Span) {
48+
match lang_def_id {
49+
Some(lang_def_id) if lang_def_id == impl_def_id => { /* OK */ },
50+
_ => {
51+
self.tcx.sess.span_err(
52+
span,
53+
&format!("only a single inherent implementation marked with `#[lang = \"{}\"]` \
54+
is allowed for the `{}` primitive", lang, ty));
55+
}
56+
}
57+
}
58+
4159
/// Checks exactly one impl for orphan rules and other such
4260
/// restrictions. In this fn, it can happen that multiple errors
4361
/// apply to a specific impl, so just return after reporting one
@@ -62,6 +80,125 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
6280
ty::ty_uniq(..) => {
6381
self.check_def_id(item, self.tcx.lang_items.owned_box().unwrap());
6482
}
83+
ty::ty_char => {
84+
self.check_primitive_impl(def_id,
85+
self.tcx.lang_items.char_impl(),
86+
"char",
87+
"char",
88+
item.span);
89+
}
90+
ty::ty_str => {
91+
self.check_primitive_impl(def_id,
92+
self.tcx.lang_items.str_impl(),
93+
"str",
94+
"str",
95+
item.span);
96+
}
97+
ty::ty_vec(_, None) => {
98+
self.check_primitive_impl(def_id,
99+
self.tcx.lang_items.slice_impl(),
100+
"slice",
101+
"[T]",
102+
item.span);
103+
}
104+
ty::ty_ptr(ty::mt { ty: _, mutbl: ast::MutImmutable }) => {
105+
self.check_primitive_impl(def_id,
106+
self.tcx.lang_items.const_ptr_impl(),
107+
"const_ptr",
108+
"*const T",
109+
item.span);
110+
}
111+
ty::ty_ptr(ty::mt { ty: _, mutbl: ast::MutMutable }) => {
112+
self.check_primitive_impl(def_id,
113+
self.tcx.lang_items.mut_ptr_impl(),
114+
"mut_ptr",
115+
"*mut T",
116+
item.span);
117+
}
118+
ty::ty_int(ast::TyI8) => {
119+
self.check_primitive_impl(def_id,
120+
self.tcx.lang_items.i8_impl(),
121+
"i8",
122+
"i8",
123+
item.span);
124+
}
125+
ty::ty_int(ast::TyI16) => {
126+
self.check_primitive_impl(def_id,
127+
self.tcx.lang_items.i16_impl(),
128+
"i16",
129+
"i16",
130+
item.span);
131+
}
132+
ty::ty_int(ast::TyI32) => {
133+
self.check_primitive_impl(def_id,
134+
self.tcx.lang_items.i32_impl(),
135+
"i32",
136+
"i32",
137+
item.span);
138+
}
139+
ty::ty_int(ast::TyI64) => {
140+
self.check_primitive_impl(def_id,
141+
self.tcx.lang_items.i64_impl(),
142+
"i64",
143+
"i64",
144+
item.span);
145+
}
146+
ty::ty_int(ast::TyIs(_)) => {
147+
self.check_primitive_impl(def_id,
148+
self.tcx.lang_items.isize_impl(),
149+
"isize",
150+
"isize",
151+
item.span);
152+
}
153+
ty::ty_uint(ast::TyU8) => {
154+
self.check_primitive_impl(def_id,
155+
self.tcx.lang_items.u8_impl(),
156+
"u8",
157+
"u8",
158+
item.span);
159+
}
160+
ty::ty_uint(ast::TyU16) => {
161+
self.check_primitive_impl(def_id,
162+
self.tcx.lang_items.u16_impl(),
163+
"u16",
164+
"u16",
165+
item.span);
166+
}
167+
ty::ty_uint(ast::TyU32) => {
168+
self.check_primitive_impl(def_id,
169+
self.tcx.lang_items.u32_impl(),
170+
"u32",
171+
"u32",
172+
item.span);
173+
}
174+
ty::ty_uint(ast::TyU64) => {
175+
self.check_primitive_impl(def_id,
176+
self.tcx.lang_items.u64_impl(),
177+
"u64",
178+
"u64",
179+
item.span);
180+
}
181+
ty::ty_uint(ast::TyUs(_)) => {
182+
self.check_primitive_impl(def_id,
183+
self.tcx.lang_items.usize_impl(),
184+
"usize",
185+
"usize",
186+
item.span);
187+
}
188+
ty::ty_float(ast::TyF32) => {
189+
self.check_primitive_impl(def_id,
190+
self.tcx.lang_items.f32_impl(),
191+
"f32",
192+
"f32",
193+
item.span);
194+
}
195+
ty::ty_float(ast::TyF64) => {
196+
self.check_primitive_impl(def_id,
197+
self.tcx.lang_items.f64_impl(),
198+
"f64",
199+
"f64",
200+
item.span);
201+
}
65202
_ => {
66203
span_err!(self.tcx.sess, item.span, E0118,
67204
"no base type found for inherent implementation; \

0 commit comments

Comments
 (0)