Skip to content

Commit 247d6fd

Browse files
committed
---
yaml --- r: 210424 b: refs/heads/try c: cf76e63 h: refs/heads/master v: v3
1 parent 7d93279 commit 247d6fd

File tree

12 files changed

+136
-47
lines changed

12 files changed

+136
-47
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: 3e561f05c00cd180ec02db4ccab2840a4aba93d2
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ba0e1cd8147d452c356aacb29fb87568ca26f111
5-
refs/heads/try: 7529bd60c3cbc4c7b635ee43a89d5b14f6fb8bf7
5+
refs/heads/try: cf76e637450a861e94ef583340b8f080379a159a
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
88
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try/src/libcollections/vec.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use core::intrinsics::assume;
6767
use core::iter::{repeat, FromIterator};
6868
use core::marker::PhantomData;
6969
use core::mem;
70-
use core::ops::{Index, IndexMut, Deref, Add};
70+
use core::ops::{Index, IndexMut, Deref};
7171
use core::ops;
7272
use core::ptr;
7373
use core::ptr::Unique;
@@ -1622,17 +1622,6 @@ impl<T: Ord> Ord for Vec<T> {
16221622
}
16231623
}
16241624

1625-
#[stable(feature = "rust1", since = "1.0.0")]
1626-
impl<'a, T: Clone> Add<&'a [T]> for Vec<T> {
1627-
type Output = Vec<T>;
1628-
1629-
#[inline]
1630-
fn add(mut self, rhs: &[T]) -> Vec<T> {
1631-
self.push_all(rhs);
1632-
self
1633-
}
1634-
}
1635-
16361625
#[stable(feature = "rust1", since = "1.0.0")]
16371626
impl<T> Drop for Vec<T> {
16381627
fn drop(&mut self) {

branches/try/src/libcore/slice.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -631,8 +631,14 @@ fn size_from_ptr<T>(_: *const T) -> usize {
631631
}
632632

633633

634-
// Use macro to be generic over const/mut
635-
macro_rules! slice_offset {
634+
// Use macros to be generic over const/mut
635+
//
636+
// They require non-negative `$by` because otherwise the expression
637+
// `(ptr as usize + $by)` would interpret `-1` as `usize::MAX` (and
638+
// thus trigger a panic when overflow checks are on).
639+
640+
// Use this to do `$ptr + $by`, where `$by` is non-negative.
641+
macro_rules! slice_add_offset {
636642
($ptr:expr, $by:expr) => {{
637643
let ptr = $ptr;
638644
if size_from_ptr(ptr) == 0 {
@@ -643,6 +649,18 @@ macro_rules! slice_offset {
643649
}};
644650
}
645651

652+
// Use this to do `$ptr - $by`, where `$by` is non-negative.
653+
macro_rules! slice_sub_offset {
654+
($ptr:expr, $by:expr) => {{
655+
let ptr = $ptr;
656+
if size_from_ptr(ptr) == 0 {
657+
transmute(ptr as usize - $by)
658+
} else {
659+
ptr.offset(-$by)
660+
}
661+
}};
662+
}
663+
646664
macro_rules! slice_ref {
647665
($ptr:expr) => {{
648666
let ptr = $ptr;
@@ -672,7 +690,7 @@ macro_rules! iterator {
672690
None
673691
} else {
674692
let old = self.ptr;
675-
self.ptr = slice_offset!(self.ptr, 1);
693+
self.ptr = slice_add_offset!(self.ptr, 1);
676694
Some(slice_ref!(old))
677695
}
678696
}
@@ -714,7 +732,7 @@ macro_rules! iterator {
714732
if self.end == self.ptr {
715733
None
716734
} else {
717-
self.end = slice_offset!(self.end, -1);
735+
self.end = slice_sub_offset!(self.end, 1);
718736
Some(slice_ref!(self.end))
719737
}
720738
}
@@ -776,7 +794,7 @@ impl<'a, T> Iter<'a, T> {
776794
fn iter_nth(&mut self, n: usize) -> Option<&'a T> {
777795
match self.as_slice().get(n) {
778796
Some(elem_ref) => unsafe {
779-
self.ptr = slice_offset!(elem_ref as *const _, 1);
797+
self.ptr = slice_add_offset!(elem_ref as *const _, 1);
780798
Some(slice_ref!(elem_ref))
781799
},
782800
None => {
@@ -849,7 +867,7 @@ impl<'a, T> IterMut<'a, T> {
849867
fn iter_nth(&mut self, n: usize) -> Option<&'a mut T> {
850868
match make_mut_slice!(T => &'a mut [T]: self.ptr, self.end).get_mut(n) {
851869
Some(elem_ref) => unsafe {
852-
self.ptr = slice_offset!(elem_ref as *mut _, 1);
870+
self.ptr = slice_add_offset!(elem_ref as *mut _, 1);
853871
Some(slice_ref!(elem_ref))
854872
},
855873
None => {

branches/try/src/librustc/middle/traits/error_reporting.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ pub fn report_projection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
5656
{
5757
let predicate =
5858
infcx.resolve_type_vars_if_possible(&obligation.predicate);
59-
if !predicate.references_error() {
59+
// The ty_err created by normalize_to_error can end up being unified
60+
// into all obligations: for example, if our obligation is something
61+
// like `$X = <() as Foo<$X>>::Out` and () does not implement Foo<_>,
62+
// then $X will be unified with ty_err, but the error still needs to be
63+
// reported.
64+
if !infcx.tcx.sess.has_errors() || !predicate.references_error() {
6065
span_err!(infcx.tcx.sess, obligation.cause.span, E0271,
6166
"type mismatch resolving `{}`: {}",
6267
predicate.user_string(infcx.tcx),
@@ -183,7 +188,8 @@ pub fn report_selection_error<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
183188
let trait_predicate =
184189
infcx.resolve_type_vars_if_possible(trait_predicate);
185190

186-
if !trait_predicate.references_error() {
191+
if !infcx.tcx.sess.has_errors() ||
192+
!trait_predicate.references_error() {
187193
let trait_ref = trait_predicate.to_poly_trait_ref();
188194
span_err!(infcx.tcx.sess, obligation.cause.span, E0277,
189195
"the trait `{}` is not implemented for the type `{}`",

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,10 @@ fn opt_normalize_projection_type<'a,'b,'tcx>(
408408
}
409409

410410
/// in various error cases, we just set ty_err and return an obligation
411-
/// that, when fulfilled, will lead to an error
411+
/// that, when fulfilled, will lead to an error.
412+
///
413+
/// FIXME: the ty_err created here can enter the obligation we create,
414+
/// leading to error messages involving ty_err.
412415
fn normalize_to_error<'a,'tcx>(selcx: &mut SelectionContext<'a,'tcx>,
413416
projection_ty: ty::ProjectionTy<'tcx>,
414417
cause: ObligationCause<'tcx>,

branches/try/src/librustdoc/html/render.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,9 @@ impl<'a> fmt::Display for Item<'a> {
14601460
try!(write!(fmt, "<span class='out-of-band'>"));
14611461
try!(write!(fmt,
14621462
r##"<span id='render-detail'>
1463-
<a id="toggle-all-docs" href="#" title="collapse all docs">[&minus;]</a>
1463+
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
1464+
[<span class='inner'>&#x2212;</span>]
1465+
</a>
14641466
</span>"##));
14651467

14661468
// Write `src` tag

branches/try/src/librustdoc/html/static/main.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ pre.rust { position: relative; }
581581

582582
.collapse-toggle > .inner {
583583
display: inline-block;
584-
width: 1ch;
584+
width: 1.2ch;
585585
text-align: center;
586586
}
587587

branches/try/src/librustdoc/html/static/main.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -806,22 +806,35 @@
806806
window.location = $('.srclink').attr('href');
807807
}
808808

809+
function labelForToggleButton(sectionIsCollapsed) {
810+
if (sectionIsCollapsed) {
811+
// button will expand the section
812+
return "+";
813+
} else {
814+
// button will collapse the section
815+
// note that this text is also set in the HTML template in render.rs
816+
return "\u2212"; // "\u2212" is '−' minus sign
817+
}
818+
}
819+
809820
$("#toggle-all-docs").on("click", function() {
810821
var toggle = $("#toggle-all-docs");
811-
if (toggle.html() == "[&minus;]") {
812-
toggle.html("[&plus;]");
813-
toggle.attr("title", "expand all docs");
814-
$(".docblock").hide();
815-
$(".toggle-label").show();
816-
$(".toggle-wrapper").addClass("collapsed");
817-
$(".collapse-toggle").children(".inner").html("&plus;");
818-
} else {
819-
toggle.html("[&minus;]");
822+
if (toggle.hasClass("will-expand")) {
823+
toggle.removeClass("will-expand");
824+
toggle.children(".inner").text(labelForToggleButton(false));
820825
toggle.attr("title", "collapse all docs");
821826
$(".docblock").show();
822827
$(".toggle-label").hide();
823828
$(".toggle-wrapper").removeClass("collapsed");
824-
$(".collapse-toggle").children(".inner").html("&minus;");
829+
$(".collapse-toggle").children(".inner").text(labelForToggleButton(false));
830+
} else {
831+
toggle.addClass("will-expand");
832+
toggle.children(".inner").text(labelForToggleButton(true));
833+
toggle.attr("title", "expand all docs");
834+
$(".docblock").hide();
835+
$(".toggle-label").show();
836+
$(".toggle-wrapper").addClass("collapsed");
837+
$(".collapse-toggle").children(".inner").text(labelForToggleButton(true));
825838
}
826839
});
827840

@@ -835,20 +848,21 @@
835848
if (relatedDoc.is(":visible")) {
836849
relatedDoc.slideUp({duration:'fast', easing:'linear'});
837850
toggle.parent(".toggle-wrapper").addClass("collapsed");
838-
toggle.children(".inner").html("&plus;");
851+
toggle.children(".inner").text(labelForToggleButton(true));
839852
toggle.children(".toggle-label").fadeIn();
840853
} else {
841854
relatedDoc.slideDown({duration:'fast', easing:'linear'});
842855
toggle.parent(".toggle-wrapper").removeClass("collapsed");
843-
toggle.children(".inner").html("&minus;");
856+
toggle.children(".inner").text(labelForToggleButton(false));
844857
toggle.children(".toggle-label").hide();
845858
}
846859
}
847860
});
848861

849862
$(function() {
850863
var toggle = $("<a/>", {'href': 'javascript:void(0)', 'class': 'collapse-toggle'})
851-
.html("[<span class='inner'>&minus;</span>]");
864+
.html("[<span class='inner'></span>]");
865+
toggle.children(".inner").text(labelForToggleButton(false));
852866

853867
$(".method").each(function() {
854868
if ($(this).next().is(".docblock") ||

branches/try/src/libsyntax/codemap.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -663,9 +663,22 @@ impl CodeMap {
663663
self.lookup_char_pos(sp.lo).file.name.to_string()
664664
}
665665

666-
pub fn span_to_lines(&self, sp: Span) -> FileLines {
666+
pub fn span_to_lines(&self, sp: Span) -> FileLinesResult {
667+
if sp.lo > sp.hi {
668+
return Err(SpanLinesError::IllFormedSpan(sp));
669+
}
670+
667671
let lo = self.lookup_char_pos(sp.lo);
668672
let hi = self.lookup_char_pos(sp.hi);
673+
674+
if lo.file.start_pos != hi.file.start_pos {
675+
return Err(SpanLinesError::DistinctSources(DistinctSources {
676+
begin: (lo.file.name.clone(), lo.file.start_pos),
677+
end: (hi.file.name.clone(), hi.file.start_pos),
678+
}));
679+
}
680+
assert!(hi.line >= lo.line);
681+
669682
let mut lines = Vec::with_capacity(hi.line - lo.line + 1);
670683

671684
// The span starts partway through the first line,
@@ -689,7 +702,7 @@ impl CodeMap {
689702
start_col: start_col,
690703
end_col: hi.col });
691704

692-
FileLines {file: lo.file, lines: lines}
705+
Ok(FileLines {file: lo.file, lines: lines})
693706
}
694707

695708
pub fn span_to_snippet(&self, sp: Span) -> Result<String, SpanSnippetError> {
@@ -914,9 +927,17 @@ impl CodeMap {
914927
}
915928

916929
// _____________________________________________________________________________
917-
// SpanSnippetError, DistinctSources, MalformedCodemapPositions
930+
// SpanLinesError, SpanSnippetError, DistinctSources, MalformedCodemapPositions
918931
//
919932

933+
pub type FileLinesResult = Result<FileLines, SpanLinesError>;
934+
935+
#[derive(Clone, PartialEq, Eq, Debug)]
936+
pub enum SpanLinesError {
937+
IllFormedSpan(Span),
938+
DistinctSources(DistinctSources),
939+
}
940+
920941
#[derive(Clone, PartialEq, Eq, Debug)]
921942
pub enum SpanSnippetError {
922943
IllFormedSpan(Span),
@@ -1082,7 +1103,7 @@ mod tests {
10821103
// Test span_to_lines for a span ending at the end of filemap
10831104
let cm = init_code_map();
10841105
let span = Span {lo: BytePos(12), hi: BytePos(23), expn_id: NO_EXPANSION};
1085-
let file_lines = cm.span_to_lines(span);
1106+
let file_lines = cm.span_to_lines(span).unwrap();
10861107

10871108
assert_eq!(file_lines.file.name, "blork.rs");
10881109
assert_eq!(file_lines.lines.len(), 1);
@@ -1127,7 +1148,7 @@ mod tests {
11271148
assert_eq!(&cm.span_to_snippet(span).unwrap(), "BB\nCCC\nDDDDD");
11281149

11291150
// check that span_to_lines gives us the complete result with the lines/cols we expected
1130-
let lines = cm.span_to_lines(span);
1151+
let lines = cm.span_to_lines(span).unwrap();
11311152
let expected = vec![
11321153
LineInfo { line_index: 1, start_col: CharPos(4), end_col: CharPos(6) },
11331154
LineInfo { line_index: 2, start_col: CharPos(0), end_col: CharPos(3) },

branches/try/src/libsyntax/diagnostic.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ fn highlight_suggestion(err: &mut EmitterWriter,
522522
suggestion: &str)
523523
-> io::Result<()>
524524
{
525-
let lines = cm.span_to_lines(sp);
525+
let lines = cm.span_to_lines(sp).unwrap();
526526
assert!(!lines.lines.is_empty());
527527

528528
// To build up the result, we want to take the snippet from the first
@@ -567,9 +567,17 @@ fn highlight_lines(err: &mut EmitterWriter,
567567
cm: &codemap::CodeMap,
568568
sp: Span,
569569
lvl: Level,
570-
lines: codemap::FileLines)
570+
lines: codemap::FileLinesResult)
571571
-> io::Result<()>
572572
{
573+
let lines = match lines {
574+
Ok(lines) => lines,
575+
Err(_) => {
576+
try!(write!(&mut err.dst, "(internal compiler error: unprintable span)\n"));
577+
return Ok(());
578+
}
579+
};
580+
573581
let fm = &*lines.file;
574582

575583
let line_strings: Option<Vec<&str>> =
@@ -690,8 +698,16 @@ fn end_highlight_lines(w: &mut EmitterWriter,
690698
cm: &codemap::CodeMap,
691699
sp: Span,
692700
lvl: Level,
693-
lines: codemap::FileLines)
701+
lines: codemap::FileLinesResult)
694702
-> io::Result<()> {
703+
let lines = match lines {
704+
Ok(lines) => lines,
705+
Err(_) => {
706+
try!(write!(&mut w.dst, "(internal compiler error: unprintable span)\n"));
707+
return Ok(());
708+
}
709+
};
710+
695711
let fm = &*lines.file;
696712

697713
let lines = &lines.lines[..];

branches/try/src/test/compile-fail/issue-23966.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
"".chars().fold(|_, _| (), ());
13-
//~^ ERROR cannot determine a type for this expression: unconstrained type
12+
"".chars().fold(|_, _| (), ()); //~ ERROR is not implemented for the type `()`
1413
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct S;
12+
13+
trait InOut<T> { type Out; }
14+
15+
fn do_fold<B, F: InOut<B, Out=B>>(init: B, f: F) {}
16+
17+
fn bot<T>() -> T { loop {} }
18+
19+
fn main() {
20+
do_fold(bot(), ()); //~ ERROR is not implemented for the type `()`
21+
}

0 commit comments

Comments
 (0)