Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Check more things for well-formedness #25701

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libcollections/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ impl<T: Ord> IntoIterator for BinaryHeap<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord {
impl<'a, T: 'a> IntoIterator for &'a BinaryHeap<T> where T: Ord {
type Item = &'a T;
type IntoIter = Iter<'a, T>;

Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ impl<K, V> IntoIterator for BTreeMap<K, V> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> IntoIterator for &'a BTreeMap<K, V> {
impl<'a, K: 'a, V: 'a> IntoIterator for &'a BTreeMap<K, V> {
type Item = (&'a K, &'a V);
type IntoIter = Iter<'a, K, V>;

Expand All @@ -510,7 +510,7 @@ impl<'a, K, V> IntoIterator for &'a BTreeMap<K, V> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, K, V> IntoIterator for &'a mut BTreeMap<K, V> {
impl<'a, K: 'a, V: 'a> IntoIterator for &'a mut BTreeMap<K, V> {
type Item = (&'a K, &'a mut V);
type IntoIter = IterMut<'a, K, V>;

Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ impl<T> IntoIterator for BTreeSet<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> IntoIterator for &'a BTreeSet<T> {
impl<'a, T: 'a> IntoIterator for &'a BTreeSet<T> {
type Item = &'a T;
type IntoIter = Iter<'a, T>;

Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/enum_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ impl<E:CLike> FromIterator<E> for EnumSet<E> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, E> IntoIterator for &'a EnumSet<E> where E: CLike {
impl<'a, E: 'a> IntoIterator for &'a EnumSet<E> where E: CLike {
type Item = E;
type IntoIter = Iter<E>;

Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ impl<T> IntoIterator for LinkedList<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> IntoIterator for &'a LinkedList<T> {
impl<'a, T: 'a> IntoIterator for &'a LinkedList<T> {
type Item = &'a T;
type IntoIter = Iter<'a, T>;

Expand All @@ -855,7 +855,7 @@ impl<'a, T> IntoIterator for &'a LinkedList<T> {
}
}

impl<'a, T> IntoIterator for &'a mut LinkedList<T> {
impl<'a, T: 'a> IntoIterator for &'a mut LinkedList<T> {
type Item = &'a mut T;
type IntoIter = IterMut<'a, T>;

Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1562,7 +1562,7 @@ impl<T> IntoIterator for Vec<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> IntoIterator for &'a Vec<T> {
impl<'a, T: 'a> IntoIterator for &'a Vec<T> {
type Item = &'a T;
type IntoIter = slice::Iter<'a, T>;

Expand All @@ -1572,7 +1572,7 @@ impl<'a, T> IntoIterator for &'a Vec<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> IntoIterator for &'a mut Vec<T> {
impl<'a, T: 'a> IntoIterator for &'a mut Vec<T> {
type Item = &'a mut T;
type IntoIter = slice::IterMut<'a, T>;

Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ impl<T> IntoIterator for VecDeque<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> IntoIterator for &'a VecDeque<T> {
impl<'a, T: 'a> IntoIterator for &'a VecDeque<T> {
type Item = &'a T;
type IntoIter = Iter<'a, T>;

Expand All @@ -1767,7 +1767,7 @@ impl<'a, T> IntoIterator for &'a VecDeque<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> IntoIterator for &'a mut VecDeque<T> {
impl<'a, T: 'a> IntoIterator for &'a mut VecDeque<T> {
type Item = &'a mut T;
type IntoIter = IterMut<'a, T>;

Expand Down
4 changes: 2 additions & 2 deletions src/libcollections/vec_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ impl<T> IntoIterator for VecMap<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> IntoIterator for &'a VecMap<T> {
impl<'a, T: 'a> IntoIterator for &'a VecMap<T> {
type Item = (usize, &'a T);
type IntoIter = Iter<'a, T>;

Expand All @@ -810,7 +810,7 @@ impl<'a, T> IntoIterator for &'a VecMap<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> IntoIterator for &'a mut VecMap<T> {
impl<'a, T: 'a> IntoIterator for &'a mut VecMap<T> {
type Item = (usize, &'a mut T);
type IntoIter = IterMut<'a, T>;

Expand Down
4 changes: 2 additions & 2 deletions src/libcore/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ macro_rules! array_impls {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> IntoIterator for &'a [T; $N] {
impl<'a, T: 'a> IntoIterator for &'a [T; $N] {
type Item = &'a T;
type IntoIter = Iter<'a, T>;

Expand All @@ -104,7 +104,7 @@ macro_rules! array_impls {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> IntoIterator for &'a mut [T; $N] {
impl<'a, T: 'a> IntoIterator for &'a mut [T; $N] {
type Item = &'a mut T;
type IntoIter = IterMut<'a, T>;

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ div_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
pub trait Rem<RHS=Self> {
/// The resulting type after applying the `%` operator
#[stable(feature = "rust1", since = "1.0.0")]
type Output = Self;
type Output;

/// The method for the `%` operator
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ impl<'a, T> Default for &'a [T] {
//

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> IntoIterator for &'a [T] {
impl<'a, T: 'a> IntoIterator for &'a [T] {
type Item = &'a T;
type IntoIter = Iter<'a, T>;

Expand All @@ -657,7 +657,7 @@ impl<'a, T> IntoIterator for &'a [T] {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, T> IntoIterator for &'a mut [T] {
impl<'a, T: 'a> IntoIterator for &'a mut [T] {
type Item = &'a mut T;
type IntoIter = IterMut<'a, T>;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ impl<T> IntoIterator for VecPerParamSpace<T> {
}
}

impl<'a,T> IntoIterator for &'a VecPerParamSpace<T> {
impl<'a, T: 'a> IntoIterator for &'a VecPerParamSpace<T> {
type Item = &'a T;
type IntoIter = Iter<'a, T>;

Expand Down
18 changes: 18 additions & 0 deletions src/librustc/middle/traits/error_reporting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,24 @@ fn note_obligation_cause_code<'a, 'tcx, T>(infcx: &InferCtxt<'a, 'tcx>,
"the return type of a function must have a \
statically known size");
}
ObligationCauseCode::ArgumentType => {
tcx.sess.span_note(
cause_span,
"the type of a function's argument must have a \
statically known size");
}
ObligationCauseCode::TupleElemSized => {
tcx.sess.span_note(
cause_span,
"tuples can only contain elements with a \
statically known size");
}
ObligationCauseCode::VecElemSized => {
tcx.sess.span_note(
cause_span,
"arrays can only contain elements with a \
statically known size");
}
ObligationCauseCode::AssignmentLhsSized => {
tcx.sess.span_note(
cause_span,
Expand Down
7 changes: 5 additions & 2 deletions src/librustc/middle/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,17 @@ pub enum ObligationCauseCode<'tcx> {
StructInitializerSized, // S { ... } must be Sized
VariableType(ast::NodeId), // Type of each variable must be Sized
ReturnType, // Return type must be Sized
ArgumentType, // Argument type must be Sized
VecElemSized, // Array element must be Sized
TupleElemSized, // Tuple element must be Sized
FieldSized, // Types of fields (other than the last)
// in a struct must be sized.
RepeatVec, // [T,..n] --> T must be Copy

// Captures of variable the given id by a closure (span is the
// span of the closure)
ClosureCapture(ast::NodeId, Span, ty::BuiltinBound),

// Types of fields (other than the last) in a struct must be sized.
FieldSized,

// static items must have `Sync` type
SharedStatic,
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2982,10 +2982,10 @@ impl<'o,'tcx> TraitObligationStackList<'o,'tcx> {
}
}

impl<'o,'tcx> Iterator for TraitObligationStackList<'o,'tcx>{
type Item = &'o TraitObligationStack<'o,'tcx>;
impl<'o, 'tcx: 'o> Iterator for TraitObligationStackList<'o, 'tcx> {
type Item = &'o TraitObligationStack<'o, 'tcx>;

fn next(&mut self) -> Option<&'o TraitObligationStack<'o,'tcx>> {
fn next(&mut self) -> Option<&'o TraitObligationStack<'o, 'tcx>> {
match self.head {
Some(o) => {
*self = o.previous;
Expand All @@ -2996,7 +2996,7 @@ impl<'o,'tcx> Iterator for TraitObligationStackList<'o,'tcx>{
}
}

impl<'o,'tcx> Repr<'tcx> for TraitObligationStack<'o,'tcx> {
impl<'o, 'tcx> Repr<'tcx> for TraitObligationStack<'o, 'tcx> {
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
format!("TraitObligationStack({})",
self.obligation.repr(tcx))
Expand Down
90 changes: 37 additions & 53 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2328,38 +2328,35 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
}
}

pub fn for_item(cx: &'a ctxt<'tcx>, id: NodeId) -> ParameterEnvironment<'a, 'tcx> {
pub fn for_item(cx: &'a ctxt<'tcx>, id: NodeId)
-> ParameterEnvironment<'a, 'tcx>
{
// TODO: use Self after a snapshot (or remove this comment)
ParameterEnvironment::for_item_inner(cx, id, construct_parameter_environment)
}

pub fn for_item_inner<T, F>(cx: &'a ctxt<'tcx>, id: NodeId, f: F) -> T
where F: FnOnce(&'a ctxt<'tcx>, Span, &Generics<'tcx>,
&GenericPredicates<'tcx>, NodeId) -> T {
match cx.map.find(id) {
Some(ast_map::NodeImplItem(ref impl_item)) => {
match impl_item.node {
ast::ConstImplItem(_, _) => {
let def_id = ast_util::local_def(id);
let scheme = lookup_item_type(cx, def_id);
let predicates = lookup_predicates(cx, def_id);
construct_parameter_environment(cx,
impl_item.span,
&scheme.generics,
&predicates,
id)
f(cx, impl_item.span, &scheme.generics, &predicates, id)
}
ast::MethodImplItem(_, ref body) => {
let method_def_id = ast_util::local_def(id);
match ty::impl_or_trait_item(cx, method_def_id) {
MethodTraitItem(ref method_ty) => {
let method_generics = &method_ty.generics;
let method_bounds = &method_ty.predicates;
construct_parameter_environment(
cx,
impl_item.span,
method_generics,
method_bounds,
body.id)
}
_ => {
cx.sess
.bug("ParameterEnvironment::for_item(): \
got non-method item from impl method?!")
}
MethodTraitItem(ref method_ty) => f(cx,
impl_item.span,
&method_ty.generics,
&method_ty.predicates,
body.id),
_ => cx.sess.bug("ParameterEnvironment::for_item(): \
got non-method item from impl method?!")
}
}
ast::TypeImplItem(_) => {
Expand All @@ -2378,11 +2375,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
let def_id = ast_util::local_def(id);
let scheme = lookup_item_type(cx, def_id);
let predicates = lookup_predicates(cx, def_id);
construct_parameter_environment(cx,
trait_item.span,
&scheme.generics,
&predicates,
id)
f(cx, trait_item.span, &scheme.generics, &predicates, id)
}
None => {
cx.sess.bug("ParameterEnvironment::from_item(): \
Expand All @@ -2401,22 +2394,14 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
ast::MethodTraitItem(_, Some(ref body)) => {
let method_def_id = ast_util::local_def(id);
match ty::impl_or_trait_item(cx, method_def_id) {
MethodTraitItem(ref method_ty) => {
let method_generics = &method_ty.generics;
let method_bounds = &method_ty.predicates;
construct_parameter_environment(
cx,
trait_item.span,
method_generics,
method_bounds,
body.id)
}
_ => {
cx.sess
.bug("ParameterEnvironment::for_item(): \
got non-method item from provided \
method?!")
}
MethodTraitItem(ref method_ty) => f(cx,
trait_item.span,
&method_ty.generics,
&method_ty.predicates,
body.id),
_ => cx.sess.bug("ParameterEnvironment::for_item(): \
got non-method item from provided \
method?!")
}
}
ast::TypeTraitItem(..) => {
Expand All @@ -2434,11 +2419,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
let fn_scheme = lookup_item_type(cx, fn_def_id);
let fn_predicates = lookup_predicates(cx, fn_def_id);

construct_parameter_environment(cx,
item.span,
&fn_scheme.generics,
&fn_predicates,
body.id)
f(cx, item.span, &fn_scheme.generics, &fn_predicates, body.id)
}
ast::ItemEnum(..) |
ast::ItemStruct(..) |
Expand All @@ -2448,11 +2429,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
let def_id = ast_util::local_def(id);
let scheme = lookup_item_type(cx, def_id);
let predicates = lookup_predicates(cx, def_id);
construct_parameter_environment(cx,
item.span,
&scheme.generics,
&predicates,
id)
f(cx, item.span, &scheme.generics, &predicates, id)
}
_ => {
cx.sess.span_bug(item.span,
Expand All @@ -2464,7 +2441,14 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> {
}
Some(ast_map::NodeExpr(..)) => {
// This is a convenience to allow closures to work.
ParameterEnvironment::for_item(cx, cx.map.get_parent(id))
ParameterEnvironment::for_item_inner(cx, cx.map.get_parent(id), f)
}
Some(ast_map::NodeForeignItem(ref item)) => {
let def_id = ast_util::local_def(id);
let scheme = lookup_item_type(cx, def_id);
let predicates = lookup_predicates(cx, def_id);

f(cx, item.span, &scheme.generics, &predicates, id)
}
_ => {
cx.sess.bug(&format!("ParameterEnvironment::from_item(): \
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_trans/trans/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub struct CrateContextIterator<'a, 'tcx: 'a> {
index: usize,
}

impl<'a, 'tcx> Iterator for CrateContextIterator<'a,'tcx> {
impl<'a, 'tcx: 'a> Iterator for CrateContextIterator<'a, 'tcx> {
type Item = CrateContext<'a, 'tcx>;

fn next(&mut self) -> Option<CrateContext<'a, 'tcx>> {
Expand All @@ -198,7 +198,7 @@ pub struct CrateContextMaybeIterator<'a, 'tcx: 'a> {
origin: usize,
}

impl<'a, 'tcx> Iterator for CrateContextMaybeIterator<'a, 'tcx> {
impl<'a, 'tcx: 'a> Iterator for CrateContextMaybeIterator<'a, 'tcx> {
type Item = (CrateContext<'a, 'tcx>, bool);

fn next(&mut self) -> Option<(CrateContext<'a, 'tcx>, bool)> {
Expand Down
Loading