Skip to content

Commit 5080b9f

Browse files
committed
Auto merge of #24349 - Manishearth:rollup, r=Manishearth
- Successful merges: #24072, #24233, #24321, #24339, #24341, #24342, #24347 - Failed merges:
2 parents a1e3c25 + dd82599 commit 5080b9f

File tree

14 files changed

+130
-26
lines changed

14 files changed

+130
-26
lines changed

src/doc/trpl/traits.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ not, because both the trait and the type aren't in our crate.
273273

274274
One last thing about traits: generic functions with a trait bound use
275275
*monomorphization* (*mono*: one, *morph*: form), so they are statically
276-
dispatched. What's that mean? Check out the chapter on [static and dynamic
277-
dispatch](static-and-dynamic-dispatch.html) for more.
276+
dispatched. What's that mean? Check out the chapter on [trait
277+
objects](trait-objects.html) for more.
278278

279279
## Multiple trait bounds
280280

src/libcore/iter.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,13 +2197,9 @@ impl<I> Iterator for Fuse<I> where I: Iterator {
21972197
if self.done {
21982198
None
21992199
} else {
2200-
match self.iter.next() {
2201-
None => {
2202-
self.done = true;
2203-
None
2204-
}
2205-
x => x
2206-
}
2200+
let next = self.iter.next();
2201+
self.done = next.is_none();
2202+
next
22072203
}
22082204
}
22092205

@@ -2224,13 +2220,9 @@ impl<I> DoubleEndedIterator for Fuse<I> where I: DoubleEndedIterator {
22242220
if self.done {
22252221
None
22262222
} else {
2227-
match self.iter.next_back() {
2228-
None => {
2229-
self.done = true;
2230-
None
2231-
}
2232-
x => x
2233-
}
2223+
let next = self.iter.next_back();
2224+
self.done = next.is_none();
2225+
next
22342226
}
22352227
}
22362228
}

src/libcore/num/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,7 +2705,7 @@ macro_rules! from_str_radix_float_impl {
27052705
///
27062706
/// # Return value
27072707
///
2708-
/// `Err(ParseIntError)` if the string did not represent a valid number. Otherwise,
2708+
/// `Err(ParseFloatError)` if the string did not represent a valid number.
27092709
/// Otherwise, `Ok(n)` where `n` is the floating-point number represented by `src`.
27102710
#[inline]
27112711
#[allow(deprecated)]
@@ -2734,7 +2734,7 @@ macro_rules! from_str_radix_float_impl {
27342734
///
27352735
/// # Return value
27362736
///
2737-
/// `Err(ParseIntError)` if the string did not represent a valid number. Otherwise,
2737+
/// `Err(ParseFloatError)` if the string did not represent a valid number.
27382738
/// Otherwise, `Ok(n)` where `n` is the floating-point number represented by `src`.
27392739
fn from_str_radix(src: &str, radix: u32)
27402740
-> Result<$T, ParseFloatError> {

src/librustc/middle/infer/error_reporting.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,8 +373,9 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
373373
fn report_and_explain_type_error(&self,
374374
trace: TypeTrace<'tcx>,
375375
terr: &ty::type_err<'tcx>) {
376+
let span = trace.origin.span();
376377
self.report_type_error(trace, terr);
377-
ty::note_and_explain_type_err(self.tcx, terr);
378+
ty::note_and_explain_type_err(self.tcx, terr, span);
378379
}
379380

380381
/// Returns a string of the form "expected `{}`, found `{}`", or None if this is a derived
@@ -812,7 +813,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
812813
}
813814
self.give_suggestion(same_regions);
814815
for &(ref trace, terr) in trace_origins {
815-
self.report_type_error(trace.clone(), &terr);
816+
self.report_and_explain_type_error(trace.clone(), &terr);
816817
}
817818
}
818819

src/librustc/middle/infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
987987
error_str));
988988

989989
if let Some(err) = err {
990-
ty::note_and_explain_type_err(self.tcx, err)
990+
ty::note_and_explain_type_err(self.tcx, err, sp)
991991
}
992992
}
993993
}

src/librustc/middle/ty.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5103,7 +5103,7 @@ pub fn type_err_to_str<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>) -> String {
51035103
}
51045104
}
51055105

5106-
pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) {
5106+
pub fn note_and_explain_type_err<'tcx>(cx: &ctxt<'tcx>, err: &type_err<'tcx>, sp: Span) {
51075107
match *err {
51085108
terr_regions_does_not_outlive(subregion, superregion) => {
51095109
note_and_explain_region(cx, "", subregion, "...");
@@ -5134,6 +5134,16 @@ pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) {
51345134
"expected concrete lifetime is ",
51355135
conc_region, "");
51365136
}
5137+
terr_sorts(values) => {
5138+
let expected_str = ty_sort_string(cx, values.expected);
5139+
let found_str = ty_sort_string(cx, values.found);
5140+
if expected_str == found_str && expected_str == "closure" {
5141+
cx.sess.span_note(sp, &format!("no two closures, even if identical, have the same \
5142+
type"));
5143+
cx.sess.span_help(sp, &format!("consider boxing your closure and/or \
5144+
using it as a trait object"));
5145+
}
5146+
}
51375147
_ => {}
51385148
}
51395149
}

src/librustc/session/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl Session {
163163
self.diagnostic().handler().note(msg)
164164
}
165165
pub fn help(&self, msg: &str) {
166-
self.diagnostic().handler().note(msg)
166+
self.diagnostic().handler().help(msg)
167167
}
168168
pub fn opt_span_bug(&self, opt_sp: Option<Span>, msg: &str) -> ! {
169169
match opt_sp {

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3575,7 +3575,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
35753575
.ty_to_string(
35763576
actual_structure_type),
35773577
type_error_description);
3578-
ty::note_and_explain_type_err(tcx, &type_error);
3578+
ty::note_and_explain_type_err(tcx, &type_error, path.span);
35793579
}
35803580
}
35813581
}

src/librustc_typeck/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ fn require_same_types<'a, 'tcx, M>(tcx: &ty::ctxt<'tcx>,
200200
msg(),
201201
ty::type_err_to_str(tcx,
202202
terr));
203-
ty::note_and_explain_type_err(tcx, terr);
203+
ty::note_and_explain_type_err(tcx, terr, span);
204204
false
205205
}
206206
}

src/libstd/path.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,8 @@ impl Path {
15741574
///
15751575
/// let path = Path::new("/tmp/foo.rs");
15761576
///
1577-
/// let new_path = path.with_extension("foo.txt");
1577+
/// let new_path = path.with_extension("txt");
1578+
/// assert_eq!(new_path, Path::new("/tmp/foo.txt"));
15781579
/// ```
15791580
#[stable(feature = "rust1", since = "1.0.0")]
15801581
pub fn with_extension<S: AsRef<OsStr>>(&self, extension: S) -> PathBuf {

src/test/compile-fail/issue-24036.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
fn closure_to_loc() {
12+
let mut x = |c| c + 1;
13+
x = |c| c + 1;
14+
//~^ ERROR mismatched types
15+
//~| NOTE no two closures, even if identical, have the same type
16+
//~| HELP consider boxing your closure and/or using it as a trait object
17+
}
18+
19+
fn closure_from_match() {
20+
let x = match 1usize {
21+
1 => |c| c + 1,
22+
2 => |c| c - 1,
23+
_ => |c| c - 1
24+
};
25+
//~^^^^^ ERROR match arms have incompatible types
26+
//~| NOTE no two closures, even if identical, have the same type
27+
//~| HELP consider boxing your closure and/or using it as a trait object
28+
}
29+
30+
fn main() { }

src/test/run-pass/issue-16602-1.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
fn main() {
12+
let mut t = [1; 2];
13+
t = [t[1] * 2, t[0] * 2];
14+
assert_eq!(&t[..], &[2, 2]);
15+
}

src/test/run-pass/issue-16602-2.rs

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 A {
12+
pub x: u32,
13+
pub y: u32,
14+
}
15+
16+
fn main() {
17+
let mut a = A { x: 1, y: 1 };
18+
a = A { x: a.y * 2, y: a.x * 2 };
19+
assert_eq!(a.x, 2);
20+
assert_eq!(a.y, 2);
21+
}

src/test/run-pass/issue-16602-3.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
#[derive(Debug)]
12+
enum Foo {
13+
Bar(u32, u32),
14+
Baz(&'static u32, &'static u32)
15+
}
16+
17+
static NUM: u32 = 100;
18+
19+
fn main () {
20+
let mut b = Foo::Baz(&NUM, &NUM);
21+
b = Foo::Bar(f(&b), g(&b));
22+
}
23+
24+
static FNUM: u32 = 1;
25+
26+
fn f (b: &Foo) -> u32 {
27+
FNUM
28+
}
29+
30+
static GNUM: u32 = 2;
31+
32+
fn g (b: &Foo) -> u32 {
33+
GNUM
34+
}

0 commit comments

Comments
 (0)