Skip to content

Commit a66fa96

Browse files
authored
Auto merge of #35951 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 6 pull requests - Successful merges: #35910, #35912, #35913, #35936, #35939, #35949 - Failed merges: #35395
2 parents 012f45e + 16d459f commit a66fa96

File tree

8 files changed

+64
-18
lines changed

8 files changed

+64
-18
lines changed

src/doc/book/macros.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ Here are some common macros you’ll see in Rust code.
662662
This macro causes the current thread to panic. You can give it a message
663663
to panic with:
664664

665-
```rust,no_run
665+
```rust,should_panic
666666
panic!("oh no!");
667667
```
668668

@@ -688,7 +688,7 @@ These two macros are used in tests. `assert!` takes a boolean. `assert_eq!`
688688
takes two values and checks them for equality. `true` passes, `false` `panic!`s.
689689
Like this:
690690

691-
```rust,no_run
691+
```rust,should_panic
692692
// A-ok!
693693
694694
assert!(true);

src/libcore/default.rs

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ use marker::Sized;
3838
/// bar: f32,
3939
/// }
4040
///
41-
///
4241
/// fn main() {
4342
/// let options: SomeOptions = Default::default();
4443
/// }

src/libcore/ops.rs

+52-9
Original file line numberDiff line numberDiff line change
@@ -421,25 +421,68 @@ mul_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
421421
///
422422
/// # Examples
423423
///
424-
/// A trivial implementation of `Div`. When `Foo / Foo` happens, it ends up
425-
/// calling `div`, and therefore, `main` prints `Dividing!`.
424+
/// Implementing a `Div`idable rational number struct:
426425
///
427426
/// ```
428427
/// use std::ops::Div;
429428
///
430-
/// struct Foo;
429+
/// // The uniqueness of rational numbers in lowest terms is a consequence of
430+
/// // the fundamental theorem of arithmetic.
431+
/// #[derive(Eq)]
432+
/// #[derive(PartialEq, Debug)]
433+
/// struct Rational {
434+
/// nominator: usize,
435+
/// denominator: usize,
436+
/// }
431437
///
432-
/// impl Div for Foo {
433-
/// type Output = Foo;
438+
/// impl Rational {
439+
/// fn new(nominator: usize, denominator: usize) -> Self {
440+
/// if denominator == 0 {
441+
/// panic!("Zero is an invalid denominator!");
442+
/// }
434443
///
435-
/// fn div(self, _rhs: Foo) -> Foo {
436-
/// println!("Dividing!");
437-
/// self
444+
/// // Reduce to lowest terms by dividing by the greatest common
445+
/// // divisor.
446+
/// let gcd = gcd(nominator, denominator);
447+
/// Rational {
448+
/// nominator: nominator / gcd,
449+
/// denominator: denominator / gcd,
450+
/// }
451+
/// }
452+
/// }
453+
///
454+
/// impl Div for Rational {
455+
/// // The division of rational numbers is a closed operation.
456+
/// type Output = Self;
457+
///
458+
/// fn div(self, rhs: Self) -> Self {
459+
/// if rhs.nominator == 0 {
460+
/// panic!("Cannot divide by zero-valued `Rational`!");
461+
/// }
462+
///
463+
/// let nominator = self.nominator * rhs.denominator;
464+
/// let denominator = self.denominator * rhs.nominator;
465+
/// Rational::new(nominator, denominator)
466+
/// }
467+
/// }
468+
///
469+
/// // Euclid's two-thousand-year-old algorithm for finding the greatest common
470+
/// // divisor.
471+
/// fn gcd(x: usize, y: usize) -> usize {
472+
/// let mut x = x;
473+
/// let mut y = y;
474+
/// while y != 0 {
475+
/// let t = y;
476+
/// y = x % y;
477+
/// x = t;
438478
/// }
479+
/// x
439480
/// }
440481
///
441482
/// fn main() {
442-
/// Foo / Foo;
483+
/// assert_eq!(Rational::new(1, 2), Rational::new(2, 4));
484+
/// assert_eq!(Rational::new(1, 2) / Rational::new(3, 4),
485+
/// Rational::new(2, 3));
443486
/// }
444487
/// ```
445488
///

src/libcore/str/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,9 @@ pub fn next_code_point<'a, I: Iterator<Item = &'a u8>>(bytes: &mut I) -> Option<
388388
/// Reads the last code point out of a byte iterator (assuming a
389389
/// UTF-8-like encoding).
390390
#[inline]
391-
fn next_code_point_reverse<'a,
392-
I: DoubleEndedIterator<Item = &'a u8>>(bytes: &mut I) -> Option<u32> {
391+
fn next_code_point_reverse<'a, I>(bytes: &mut I) -> Option<u32>
392+
where I: DoubleEndedIterator<Item = &'a u8>,
393+
{
393394
// Decode UTF-8
394395
let w = match bytes.next_back() {
395396
None => return None,

src/librustc_typeck/check/compare_method.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -469,10 +469,11 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
469469
// are zero. Since I don't quite know how to phrase things at
470470
// the moment, give a kind of vague error message.
471471
if trait_params.len() != impl_params.len() {
472-
span_err!(ccx.tcx.sess, span, E0195,
472+
struct_span_err!(ccx.tcx.sess, span, E0195,
473473
"lifetime parameters or bounds on method `{}` do \
474-
not match the trait declaration",
475-
impl_m.name);
474+
not match the trait declaration",impl_m.name)
475+
.span_label(span, &format!("lifetimes do not match trait"))
476+
.emit();
476477
return false;
477478
}
478479

src/test/compile-fail/E0195.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct Foo;
1616

1717
impl Trait for Foo {
1818
fn bar<'a,'b>(x: &'a str, y: &'b str) { //~ ERROR E0195
19+
//~^ lifetimes do not match trait
1920
}
2021
}
2122

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

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ impl<'a> Test<'a> for Foo<'a> {
2929
impl<'a> NoLifetime for Foo<'a> {
3030
fn get<'p, T : Test<'a>>(&self) -> T {
3131
//~^ ERROR E0195
32+
//~| lifetimes do not match trait
3233
return *self as T;
3334
}
3435
}

0 commit comments

Comments
 (0)