Skip to content

Commit 64e97d9

Browse files
Remove BuiltinBound and BuiltinBounds.
1 parent 607af72 commit 64e97d9

31 files changed

+138
-333
lines changed

src/librustc/infer/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use middle::free_region::FreeRegionMap;
2424
use middle::mem_categorization as mc;
2525
use middle::mem_categorization::McResult;
2626
use middle::region::CodeExtent;
27+
use middle::lang_items;
2728
use mir::tcx::LvalueTy;
2829
use ty::subst::{Kind, Subst, Substs};
2930
use ty::adjustment;
@@ -1492,11 +1493,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
14921493
}
14931494
}
14941495

1496+
let copy_def_id = self.tcx.lang_items.require(lang_items::CopyTraitLangItem)
1497+
.unwrap_or_else(|msg| self.tcx.sess.fatal(&msg[..]));
1498+
14951499
// this can get called from typeck (by euv), and moves_by_default
14961500
// rightly refuses to work with inference variables, but
14971501
// moves_by_default has a cache, which we want to use in other
14981502
// cases.
1499-
!traits::type_known_to_meet_builtin_bound(self, ty, ty::BoundCopy, span)
1503+
!traits::type_known_to_meet_bound(self, ty, copy_def_id, span)
15001504
}
15011505

15021506
pub fn node_method_ty(&self, method_call: ty::MethodCall)

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#![feature(const_fn)]
3333
#![feature(core_intrinsics)]
3434
#![cfg_attr(stage0, feature(dotdot_in_tuple_patterns))]
35-
#![feature(enumset)]
3635
#![cfg_attr(stage0, feature(item_like_imports))]
3736
#![feature(libc)]
3837
#![feature(nonzero)]

src/librustc/middle/lang_items.rs

-25
Original file line numberDiff line numberDiff line change
@@ -90,31 +90,6 @@ impl LanguageItems {
9090
self.require(OwnedBoxLangItem)
9191
}
9292

93-
pub fn from_builtin_kind(&self, bound: ty::BuiltinBound)
94-
-> Result<DefId, String>
95-
{
96-
match bound {
97-
ty::BoundSend => self.require(SendTraitLangItem),
98-
ty::BoundSized => self.require(SizedTraitLangItem),
99-
ty::BoundCopy => self.require(CopyTraitLangItem),
100-
ty::BoundSync => self.require(SyncTraitLangItem),
101-
}
102-
}
103-
104-
pub fn to_builtin_kind(&self, id: DefId) -> Option<ty::BuiltinBound> {
105-
if Some(id) == self.send_trait() {
106-
Some(ty::BoundSend)
107-
} else if Some(id) == self.sized_trait() {
108-
Some(ty::BoundSized)
109-
} else if Some(id) == self.copy_trait() {
110-
Some(ty::BoundCopy)
111-
} else if Some(id) == self.sync_trait() {
112-
Some(ty::BoundSync)
113-
} else {
114-
None
115-
}
116-
}
117-
11893
pub fn fn_trait_kind(&self, id: DefId) -> Option<ty::ClosureKind> {
11994
let def_id_kinds = [
12095
(self.fn_trait(), ty::ClosureKind::Fn),

src/librustc/traits/error_reporting.rs

-10
Original file line numberDiff line numberDiff line change
@@ -905,16 +905,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
905905
ObligationCauseCode::StructInitializerSized => {
906906
err.note("structs must have a statically known size to be initialized");
907907
}
908-
ObligationCauseCode::ClosureCapture(var_id, _, builtin_bound) => {
909-
let def_id = tcx.lang_items.from_builtin_kind(builtin_bound).unwrap();
910-
let trait_name = tcx.item_path_str(def_id);
911-
let name = tcx.local_var_name_str(var_id);
912-
err.note(
913-
&format!("the closure that captures `{}` requires that all captured variables \
914-
implement the trait `{}`",
915-
name,
916-
trait_name));
917-
}
918908
ObligationCauseCode::FieldSized => {
919909
err.note("only the last field of a struct may have a dynamically sized type");
920910
}

src/librustc/traits/fulfill.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use rustc_data_structures::obligation_forest::{ForestObligation, ObligationProce
1717
use std::marker::PhantomData;
1818
use std::mem;
1919
use syntax::ast;
20-
use util::common::ErrorReported;
2120
use util::nodemap::{FxHashSet, NodeMap};
21+
use hir::def_id::DefId;
2222

2323
use super::CodeAmbiguity;
2424
use super::CodeProjectionError;
@@ -230,18 +230,21 @@ impl<'a, 'gcx, 'tcx> FulfillmentContext<'tcx> {
230230
normalized.value
231231
}
232232

233-
pub fn register_builtin_bound(&mut self,
233+
pub fn register_bound(&mut self,
234234
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
235235
ty: Ty<'tcx>,
236-
builtin_bound: ty::BuiltinBound,
236+
def_id: DefId,
237237
cause: ObligationCause<'tcx>)
238238
{
239-
match infcx.tcx.predicate_for_builtin_bound(cause, builtin_bound, 0, ty) {
240-
Ok(predicate) => {
241-
self.register_predicate_obligation(infcx, predicate);
242-
}
243-
Err(ErrorReported) => { }
244-
}
239+
let trait_ref = ty::TraitRef {
240+
def_id: def_id,
241+
substs: infcx.tcx.mk_substs_trait(ty, &[]),
242+
};
243+
self.register_predicate_obligation(infcx, Obligation {
244+
cause: cause,
245+
recursion_depth: 0,
246+
predicate: trait_ref.to_predicate()
247+
});
245248
}
246249

247250
pub fn register_region_obligation(&mut self,

src/librustc/traits/mod.rs

+22-23
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use hir;
1919
use hir::def_id::DefId;
2020
use middle::free_region::FreeRegionMap;
2121
use ty::subst::Substs;
22-
use ty::{self, Ty, TyCtxt, TypeFoldable};
22+
use ty::{self, Ty, TyCtxt, TypeFoldable, ToPredicate};
2323
use infer::InferCtxt;
2424

2525
use std::rc::Rc;
@@ -125,10 +125,6 @@ pub enum ObligationCauseCode<'tcx> {
125125
ReturnType, // Return type must be Sized
126126
RepeatVec, // [T,..n] --> T must be Copy
127127

128-
// Captures of variable the given id by a closure (span is the
129-
// span of the closure)
130-
ClosureCapture(ast::NodeId, Span, ty::BuiltinBound),
131-
132128
// Types of fields (other than the last) in a struct must be sized.
133129
FieldSized,
134130

@@ -369,27 +365,30 @@ pub fn predicates_for_generics<'tcx>(cause: ObligationCause<'tcx>,
369365
/// `bound` or is not known to meet bound (note that this is
370366
/// conservative towards *no impl*, which is the opposite of the
371367
/// `evaluate` methods).
372-
pub fn type_known_to_meet_builtin_bound<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
368+
pub fn type_known_to_meet_bound<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>,
373369
ty: Ty<'tcx>,
374-
bound: ty::BuiltinBound,
370+
def_id: DefId,
375371
span: Span)
376372
-> bool
377373
{
378-
debug!("type_known_to_meet_builtin_bound(ty={:?}, bound={:?})",
374+
debug!("type_known_to_meet_bound(ty={:?}, bound={:?})",
379375
ty,
380-
bound);
381-
382-
let cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID);
383-
let obligation =
384-
infcx.tcx.predicate_for_builtin_bound(cause, bound, 0, ty);
385-
let obligation = match obligation {
386-
Ok(o) => o,
387-
Err(..) => return false
376+
infcx.tcx.item_path_str(def_id));
377+
378+
let trait_ref = ty::TraitRef {
379+
def_id: def_id,
380+
substs: infcx.tcx.mk_substs_trait(ty, &[]),
388381
};
382+
let obligation = Obligation {
383+
cause: ObligationCause::misc(span, ast::DUMMY_NODE_ID),
384+
recursion_depth: 0,
385+
predicate: trait_ref.to_predicate(),
386+
};
387+
389388
let result = SelectionContext::new(infcx)
390389
.evaluate_obligation_conservatively(&obligation);
391-
debug!("type_known_to_meet_builtin_bound: ty={:?} bound={:?} => {:?}",
392-
ty, bound, result);
390+
debug!("type_known_to_meet_ty={:?} bound={} => {:?}",
391+
ty, infcx.tcx.item_path_str(def_id), result);
393392

394393
if result && (ty.has_infer_types() || ty.has_closure_types()) {
395394
// Because of inference "guessing", selection can sometimes claim
@@ -404,22 +403,22 @@ pub fn type_known_to_meet_builtin_bound<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'g
404403
// anyhow).
405404
let cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID);
406405

407-
fulfill_cx.register_builtin_bound(infcx, ty, bound, cause);
406+
fulfill_cx.register_bound(infcx, ty, def_id, cause);
408407

409408
// Note: we only assume something is `Copy` if we can
410409
// *definitively* show that it implements `Copy`. Otherwise,
411410
// assume it is move; linear is always ok.
412411
match fulfill_cx.select_all_or_error(infcx) {
413412
Ok(()) => {
414-
debug!("type_known_to_meet_builtin_bound: ty={:?} bound={:?} success",
413+
debug!("type_known_to_meet_bound: ty={:?} bound={} success",
415414
ty,
416-
bound);
415+
infcx.tcx.item_path_str(def_id));
417416
true
418417
}
419418
Err(e) => {
420-
debug!("type_known_to_meet_builtin_bound: ty={:?} bound={:?} errors={:?}",
419+
debug!("type_known_to_meet_bound: ty={:?} bound={} errors={:?}",
421420
ty,
422-
bound,
421+
infcx.tcx.item_path_str(def_id),
423422
e);
424423
false
425424
}

src/librustc/traits/select.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1093,8 +1093,9 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
10931093
// Other bounds. Consider both in-scope bounds from fn decl
10941094
// and applicable impls. There is a certain set of precedence rules here.
10951095

1096-
match self.tcx().lang_items.to_builtin_kind(obligation.predicate.def_id()) {
1097-
Some(ty::BoundCopy) => {
1096+
let def_id = obligation.predicate.def_id();
1097+
match obligation.predicate.def_id() {
1098+
_ if self.tcx().lang_items.copy_trait() == Some(def_id) => {
10981099
debug!("obligation self ty is {:?}",
10991100
obligation.predicate.0.self_ty());
11001101

@@ -1106,22 +1107,20 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
11061107
let copy_conditions = self.copy_conditions(obligation);
11071108
self.assemble_builtin_bound_candidates(copy_conditions, &mut candidates)?;
11081109
}
1109-
Some(ty::BoundSized) => {
1110+
_ if self.tcx().lang_items.sized_trait() == Some(def_id) => {
11101111
// Sized is never implementable by end-users, it is
11111112
// always automatically computed.
11121113
let sized_conditions = self.sized_conditions(obligation);
11131114
self.assemble_builtin_bound_candidates(sized_conditions,
11141115
&mut candidates)?;
11151116
}
11161117

1117-
None if self.tcx().lang_items.unsize_trait() ==
1118-
Some(obligation.predicate.def_id()) => {
1118+
_ if self.tcx().lang_items.unsize_trait() == Some(def_id) => {
11191119
self.assemble_candidates_for_unsizing(obligation, &mut candidates);
11201120
}
11211121

1122-
Some(ty::BoundSend) |
1123-
Some(ty::BoundSync) |
1124-
None => {
1122+
// For non-builtins and Send/Sync
1123+
_ => {
11251124
self.assemble_closure_candidates(obligation, &mut candidates)?;
11261125
self.assemble_fn_pointer_candidates(obligation, &mut candidates)?;
11271126
self.assemble_candidates_from_impls(obligation, &mut candidates)?;
@@ -2483,7 +2482,6 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
24832482
data_b.auto_traits().collect(),
24842483
data_a.projection_bounds.clone(),
24852484
));
2486-
let origin = TypeOrigin::Misc(obligation.cause.span);
24872485
let InferOk { obligations, .. } =
24882486
self.infcx.sub_types(false, &obligation.cause, new_trait, target)
24892487
.map_err(|_| Unimplemented)?;

src/librustc/traits/structural_impls.rs

-5
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@ impl<'a, 'tcx> Lift<'tcx> for traits::ObligationCauseCode<'a> {
190190
super::VariableType(id) => Some(super::VariableType(id)),
191191
super::ReturnType => Some(super::ReturnType),
192192
super::RepeatVec => Some(super::RepeatVec),
193-
super::ClosureCapture(node_id, span, bound) => {
194-
Some(super::ClosureCapture(node_id, span, bound))
195-
}
196193
super::FieldSized => Some(super::FieldSized),
197194
super::ConstSized => Some(super::ConstSized),
198195
super::SharedStatic => Some(super::SharedStatic),
@@ -507,7 +504,6 @@ impl<'tcx> TypeFoldable<'tcx> for traits::ObligationCauseCode<'tcx> {
507504
super::VariableType(_) |
508505
super::ReturnType |
509506
super::RepeatVec |
510-
super::ClosureCapture(..) |
511507
super::FieldSized |
512508
super::ConstSized |
513509
super::SharedStatic |
@@ -552,7 +548,6 @@ impl<'tcx> TypeFoldable<'tcx> for traits::ObligationCauseCode<'tcx> {
552548
super::VariableType(_) |
553549
super::ReturnType |
554550
super::RepeatVec |
555-
super::ClosureCapture(..) |
556551
super::FieldSized |
557552
super::ConstSized |
558553
super::SharedStatic |

src/librustc/traits/util.rs

-31
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use hir::def_id::DefId;
1212
use ty::subst::{Subst, Substs};
1313
use ty::{self, Ty, TyCtxt, ToPredicate, ToPolyTraitRef};
1414
use ty::outlives::Component;
15-
use util::common::ErrorReported;
1615
use util::nodemap::FxHashSet;
1716

1817
use super::{Obligation, ObligationCause, PredicateObligation, SelectionContext, Normalized};
@@ -408,25 +407,6 @@ pub fn predicate_for_trait_ref<'tcx>(
408407
}
409408

410409
impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
411-
pub fn trait_ref_for_builtin_bound(self,
412-
builtin_bound: ty::BuiltinBound,
413-
param_ty: Ty<'tcx>)
414-
-> Result<ty::TraitRef<'tcx>, ErrorReported>
415-
{
416-
match self.lang_items.from_builtin_kind(builtin_bound) {
417-
Ok(def_id) => {
418-
Ok(ty::TraitRef {
419-
def_id: def_id,
420-
substs: self.mk_substs_trait(param_ty, &[])
421-
})
422-
}
423-
Err(e) => {
424-
self.sess.err(&e);
425-
Err(ErrorReported)
426-
}
427-
}
428-
}
429-
430410
pub fn predicate_for_trait_def(self,
431411
cause: ObligationCause<'tcx>,
432412
trait_def_id: DefId,
@@ -442,17 +422,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
442422
predicate_for_trait_ref(cause, trait_ref, recursion_depth)
443423
}
444424

445-
pub fn predicate_for_builtin_bound(self,
446-
cause: ObligationCause<'tcx>,
447-
builtin_bound: ty::BuiltinBound,
448-
recursion_depth: usize,
449-
param_ty: Ty<'tcx>)
450-
-> Result<PredicateObligation<'tcx>, ErrorReported>
451-
{
452-
let trait_ref = self.trait_ref_for_builtin_bound(builtin_bound, param_ty)?;
453-
Ok(predicate_for_trait_ref(cause, trait_ref, recursion_depth))
454-
}
455-
456425
/// Cast a trait reference into a reference to one of its super
457426
/// traits; returns `None` if `target_trait_def_id` is not a
458427
/// supertrait.

src/librustc/ty/error.rs

-14
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ pub enum TypeError<'tcx> {
4545
IntMismatch(ExpectedFound<ty::IntVarValue>),
4646
FloatMismatch(ExpectedFound<ast::FloatTy>),
4747
Traits(ExpectedFound<DefId>),
48-
BuiltinBoundsMismatch(ExpectedFound<ty::BuiltinBounds>),
4948
VariadicMismatch(ExpectedFound<bool>),
5049
CyclicTy,
5150
ProjectionNameMismatched(ExpectedFound<Name>),
@@ -135,19 +134,6 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
135134
format!("trait `{}`",
136135
tcx.item_path_str(values.found)))
137136
}),
138-
BuiltinBoundsMismatch(values) => {
139-
if values.expected.is_empty() {
140-
write!(f, "expected no bounds, found `{}`",
141-
values.found)
142-
} else if values.found.is_empty() {
143-
write!(f, "expected bounds `{}`, found no bounds",
144-
values.expected)
145-
} else {
146-
write!(f, "expected bounds `{}`, found bounds `{}`",
147-
values.expected,
148-
values.found)
149-
}
150-
}
151137
IntMismatch(ref values) => {
152138
write!(f, "expected `{:?}`, found `{:?}`",
153139
values.expected,

src/librustc/ty/mod.rs

-6
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ use hir;
5353
use hir::itemlikevisit::ItemLikeVisitor;
5454

5555
pub use self::sty::{Binder, DebruijnIndex};
56-
pub use self::sty::{BuiltinBound, BuiltinBounds};
5756
pub use self::sty::{BareFnTy, FnSig, PolyFnSig};
5857
pub use self::sty::{ClosureTy, InferTy, ParamTy, ProjectionTy, TraitObject};
5958
pub use self::sty::{ClosureSubsts, TypeAndMut};
@@ -68,11 +67,6 @@ pub use self::sty::InferTy::*;
6867
pub use self::sty::Region::*;
6968
pub use self::sty::TypeVariants::*;
7069

71-
pub use self::sty::BuiltinBound::Send as BoundSend;
72-
pub use self::sty::BuiltinBound::Sized as BoundSized;
73-
pub use self::sty::BuiltinBound::Copy as BoundCopy;
74-
pub use self::sty::BuiltinBound::Sync as BoundSync;
75-
7670
pub use self::contents::TypeContents;
7771
pub use self::context::{TyCtxt, tls};
7872
pub use self::context::{CtxtArenas, Lift, Tables};

0 commit comments

Comments
 (0)