Skip to content

Commit 51f32e7

Browse files
committed
---
yaml --- r: 235854 b: refs/heads/stable c: 6232f95 h: refs/heads/master v: v3
1 parent d7fed51 commit 51f32e7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1346
-356
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: afae2ff723393b3ab4ccffef6ac7c6d1809e2da0
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: f859507de8c410b648d934d8f5ec1c52daac971d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: c20e3fc1e4186cc6c155b2d83b5e137195454b46
32+
refs/heads/stable: 6232f958cd42960f64456566dc56ed15470761f4
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/doc/reference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,6 +2368,8 @@ The currently implemented features of the reference compiler are:
23682368
internally without imposing on callers
23692369
(i.e. making them behave like function calls in
23702370
terms of encapsulation).
2371+
* - `default_type_parameter_fallback` - Allows type parameter defaults to
2372+
influence type inference.
23712373

23722374
If a feature is promoted to a language feature, then all existing programs will
23732375
start to receive compilation warnings about `#![feature]` directives which enabled

branches/stable/src/librustc/ast_map/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ pub enum Node<'ast> {
119119
NodeStructCtor(&'ast StructDef),
120120

121121
NodeLifetime(&'ast Lifetime),
122+
NodeTyParam(&'ast TyParam)
122123
}
123124

124125
/// Represents an entry and its parent NodeID.
@@ -142,6 +143,7 @@ enum MapEntry<'ast> {
142143
EntryBlock(NodeId, &'ast Block),
143144
EntryStructCtor(NodeId, &'ast StructDef),
144145
EntryLifetime(NodeId, &'ast Lifetime),
146+
EntryTyParam(NodeId, &'ast TyParam),
145147

146148
/// Roots for node trees.
147149
RootCrate,
@@ -175,7 +177,8 @@ impl<'ast> MapEntry<'ast> {
175177
NodePat(n) => EntryPat(p, n),
176178
NodeBlock(n) => EntryBlock(p, n),
177179
NodeStructCtor(n) => EntryStructCtor(p, n),
178-
NodeLifetime(n) => EntryLifetime(p, n)
180+
NodeLifetime(n) => EntryLifetime(p, n),
181+
NodeTyParam(n) => EntryTyParam(p, n),
179182
}
180183
}
181184

@@ -194,6 +197,7 @@ impl<'ast> MapEntry<'ast> {
194197
EntryBlock(id, _) => id,
195198
EntryStructCtor(id, _) => id,
196199
EntryLifetime(id, _) => id,
200+
EntryTyParam(id, _) => id,
197201
_ => return None
198202
})
199203
}
@@ -213,6 +217,7 @@ impl<'ast> MapEntry<'ast> {
213217
EntryBlock(_, n) => NodeBlock(n),
214218
EntryStructCtor(_, n) => NodeStructCtor(n),
215219
EntryLifetime(_, n) => NodeLifetime(n),
220+
EntryTyParam(_, n) => NodeTyParam(n),
216221
_ => return None
217222
})
218223
}
@@ -573,6 +578,7 @@ impl<'ast> Map<'ast> {
573578
Some(NodePat(pat)) => pat.span,
574579
Some(NodeBlock(block)) => block.span,
575580
Some(NodeStructCtor(_)) => self.expect_item(self.get_parent(id)).span,
581+
Some(NodeTyParam(ty_param)) => ty_param.span,
576582
_ => return None,
577583
};
578584
Some(sp)
@@ -815,6 +821,14 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
815821
self.parent_node = parent_node;
816822
}
817823

824+
fn visit_generics(&mut self, generics: &'ast Generics) {
825+
for ty_param in generics.ty_params.iter() {
826+
self.insert(ty_param.id, NodeTyParam(ty_param));
827+
}
828+
829+
visit::walk_generics(self, generics);
830+
}
831+
818832
fn visit_trait_item(&mut self, ti: &'ast TraitItem) {
819833
let parent_node = self.parent_node;
820834
self.parent_node = ti.id;
@@ -1015,7 +1029,7 @@ impl<'a> NodePrinter for pprust::State<'a> {
10151029
NodePat(a) => self.print_pat(&*a),
10161030
NodeBlock(a) => self.print_block(&*a),
10171031
NodeLifetime(a) => self.print_lifetime(&*a),
1018-
1032+
NodeTyParam(_) => panic!("cannot print TyParam"),
10191033
// these cases do not carry enough information in the
10201034
// ast_map to reconstruct their full structure for pretty
10211035
// printing.
@@ -1123,6 +1137,9 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
11231137
format!("lifetime {}{}",
11241138
pprust::lifetime_to_string(&**l), id_str)
11251139
}
1140+
Some(NodeTyParam(ref ty_param)) => {
1141+
format!("typaram {:?}{}", ty_param, id_str)
1142+
}
11261143
None => {
11271144
format!("unknown node{}", id_str)
11281145
}

branches/stable/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)]

branches/stable/src/librustc/metadata/tydecode.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ fn parse_type_param_def_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F)
833833
assert_eq!(next(st), '|');
834834
let index = parse_u32(st);
835835
assert_eq!(next(st), '|');
836+
let default_def_id = parse_def_(st, NominalType, conv);
836837
let default = parse_opt(st, |st| parse_ty_(st, conv));
837838
let object_lifetime_default = parse_object_lifetime_default(st, conv);
838839

@@ -841,6 +842,7 @@ fn parse_type_param_def_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F)
841842
def_id: def_id,
842843
space: space,
843844
index: index,
845+
default_def_id: default_def_id,
844846
default: default,
845847
object_lifetime_default: object_lifetime_default,
846848
}

branches/stable/src/librustc/metadata/tyencode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,9 @@ pub fn enc_region_bounds<'a, 'tcx>(w: &mut Encoder,
409409

410410
pub fn enc_type_param_def<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>,
411411
v: &ty::TypeParameterDef<'tcx>) {
412-
mywrite!(w, "{}:{}|{}|{}|",
412+
mywrite!(w, "{}:{}|{}|{}|{}|",
413413
token::get_name(v.name), (cx.ds)(v.def_id),
414-
v.space.to_uint(), v.index);
414+
v.space.to_uint(), v.index, (cx.ds)(v.default_def_id));
415415
enc_opt(w, v.default, |w, t| enc_ty(w, cx, t));
416416
enc_object_lifetime_default(w, cx, v.object_lifetime_default);
417417
}

branches/stable/src/librustc/middle/check_match.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,18 +1016,8 @@ pub fn specialize<'a>(cx: &MatchCheckCtxt, r: &[&'a Pat],
10161016
fn check_local(cx: &mut MatchCheckCtxt, loc: &ast::Local) {
10171017
visit::walk_local(cx, loc);
10181018

1019-
let name = match loc.source {
1020-
ast::LocalLet => "local",
1021-
ast::LocalFor => "`for` loop"
1022-
};
1023-
1024-
let mut static_inliner = StaticInliner::new(cx.tcx, None);
1025-
is_refutable(cx, &*static_inliner.fold_pat(loc.pat.clone()), |pat| {
1026-
span_err!(cx.tcx.sess, loc.pat.span, E0005,
1027-
"refutable pattern in {} binding: `{}` not covered",
1028-
name, pat_to_string(pat)
1029-
);
1030-
});
1019+
let pat = StaticInliner::new(cx.tcx, None).fold_pat(loc.pat.clone());
1020+
check_irrefutable(cx, &pat, false);
10311021

10321022
// Check legality of move bindings and `@` patterns.
10331023
check_legality_of_move_bindings(cx, false, slice::ref_slice(&loc.pat));
@@ -1048,17 +1038,28 @@ fn check_fn(cx: &mut MatchCheckCtxt,
10481038
visit::walk_fn(cx, kind, decl, body, sp);
10491039

10501040
for input in &decl.inputs {
1051-
is_refutable(cx, &*input.pat, |pat| {
1052-
span_err!(cx.tcx.sess, input.pat.span, E0005,
1053-
"refutable pattern in function argument: `{}` not covered",
1054-
pat_to_string(pat)
1055-
);
1056-
});
1041+
check_irrefutable(cx, &input.pat, true);
10571042
check_legality_of_move_bindings(cx, false, slice::ref_slice(&input.pat));
10581043
check_legality_of_bindings_in_at_patterns(cx, &*input.pat);
10591044
}
10601045
}
10611046

1047+
fn check_irrefutable(cx: &MatchCheckCtxt, pat: &Pat, is_fn_arg: bool) {
1048+
let origin = if is_fn_arg {
1049+
"function argument"
1050+
} else {
1051+
"local binding"
1052+
};
1053+
1054+
is_refutable(cx, pat, |uncovered_pat| {
1055+
span_err!(cx.tcx.sess, pat.span, E0005,
1056+
"refutable pattern in {}: `{}` not covered",
1057+
origin,
1058+
pat_to_string(uncovered_pat),
1059+
);
1060+
});
1061+
}
1062+
10621063
fn is_refutable<A, F>(cx: &MatchCheckCtxt, pat: &Pat, refutable: F) -> Option<A> where
10631064
F: FnOnce(&Pat) -> A,
10641065
{

branches/stable/src/librustc/middle/check_static_recursion.rs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// This compiler pass detects static items that refer to themselves
11+
// This compiler pass detects constants that refer to themselves
1212
// recursively.
1313

1414
use ast_map;
@@ -18,6 +18,7 @@ use util::nodemap::NodeMap;
1818

1919
use syntax::{ast, ast_util};
2020
use syntax::codemap::Span;
21+
use syntax::feature_gate::emit_feature_err;
2122
use syntax::visit::Visitor;
2223
use syntax::visit;
2324

@@ -125,8 +126,27 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
125126
}
126127
fn with_item_id_pushed<F>(&mut self, id: ast::NodeId, f: F)
127128
where F: Fn(&mut Self) {
128-
if self.idstack.iter().any(|x| *x == id) {
129-
span_err!(self.sess, *self.root_span, E0265, "recursive constant");
129+
if self.idstack.iter().any(|&x| x == id) {
130+
let any_static = self.idstack.iter().any(|&x| {
131+
if let ast_map::NodeItem(item) = self.ast_map.get(x) {
132+
if let ast::ItemStatic(..) = item.node {
133+
true
134+
} else {
135+
false
136+
}
137+
} else {
138+
false
139+
}
140+
});
141+
if any_static {
142+
if !self.sess.features.borrow().static_recursion {
143+
emit_feature_err(&self.sess.parse_sess.span_diagnostic,
144+
"static_recursion",
145+
*self.root_span, "recursive static");
146+
}
147+
} else {
148+
span_err!(self.sess, *self.root_span, E0265, "recursive constant");
149+
}
130150
return;
131151
}
132152
self.idstack.push(id);

branches/stable/src/librustc/middle/infer/error_reporting.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,8 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
893893
self.report_inference_failure(vo.clone());
894894
}
895895
self.give_suggestion(same_regions);
896-
for &(ref trace, terr) in trace_origins {
897-
self.report_and_explain_type_error(trace.clone(), &terr);
896+
for &(ref trace, ref terr) in trace_origins {
897+
self.report_and_explain_type_error(trace.clone(), terr);
898898
}
899899
}
900900

0 commit comments

Comments
 (0)