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

Rollup of 6 pull requests #35951

Merged
merged 12 commits into from
Aug 24, 2016
Merged
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
4 changes: 2 additions & 2 deletions src/doc/book/macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ Here are some common macros you’ll see in Rust code.
This macro causes the current thread to panic. You can give it a message
to panic with:

```rust,no_run
```rust,should_panic
panic!("oh no!");
```

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

```rust,no_run
```rust,should_panic
// A-ok!

assert!(true);
Expand Down
1 change: 0 additions & 1 deletion src/libcore/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use marker::Sized;
/// bar: f32,
/// }
///
///
/// fn main() {
/// let options: SomeOptions = Default::default();
/// }
Expand Down
61 changes: 52 additions & 9 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,25 +421,68 @@ mul_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
///
/// # Examples
///
/// A trivial implementation of `Div`. When `Foo / Foo` happens, it ends up
/// calling `div`, and therefore, `main` prints `Dividing!`.
/// Implementing a `Div`idable rational number struct:
///
/// ```
/// use std::ops::Div;
///
/// struct Foo;
/// // The uniqueness of rational numbers in lowest terms is a consequence of
/// // the fundamental theorem of arithmetic.
/// #[derive(Eq)]
/// #[derive(PartialEq, Debug)]
/// struct Rational {
/// nominator: usize,
/// denominator: usize,
/// }
///
/// impl Div for Foo {
/// type Output = Foo;
/// impl Rational {
/// fn new(nominator: usize, denominator: usize) -> Self {
/// if denominator == 0 {
/// panic!("Zero is an invalid denominator!");
/// }
///
/// fn div(self, _rhs: Foo) -> Foo {
/// println!("Dividing!");
/// self
/// // Reduce to lowest terms by dividing by the greatest common
/// // divisor.
/// let gcd = gcd(nominator, denominator);
/// Rational {
/// nominator: nominator / gcd,
/// denominator: denominator / gcd,
/// }
/// }
/// }
///
/// impl Div for Rational {
/// // The division of rational numbers is a closed operation.
/// type Output = Self;
///
/// fn div(self, rhs: Self) -> Self {
/// if rhs.nominator == 0 {
/// panic!("Cannot divide by zero-valued `Rational`!");
/// }
///
/// let nominator = self.nominator * rhs.denominator;
/// let denominator = self.denominator * rhs.nominator;
/// Rational::new(nominator, denominator)
/// }
/// }
///
/// // Euclid's two-thousand-year-old algorithm for finding the greatest common
/// // divisor.
/// fn gcd(x: usize, y: usize) -> usize {
/// let mut x = x;
/// let mut y = y;
/// while y != 0 {
/// let t = y;
/// y = x % y;
/// x = t;
/// }
/// x
/// }
///
/// fn main() {
/// Foo / Foo;
/// assert_eq!(Rational::new(1, 2), Rational::new(2, 4));
/// assert_eq!(Rational::new(1, 2) / Rational::new(3, 4),
/// Rational::new(2, 3));
/// }
/// ```
///
Expand Down
5 changes: 3 additions & 2 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,9 @@ pub fn next_code_point<'a, I: Iterator<Item = &'a u8>>(bytes: &mut I) -> Option<
/// Reads the last code point out of a byte iterator (assuming a
/// UTF-8-like encoding).
#[inline]
fn next_code_point_reverse<'a,
I: DoubleEndedIterator<Item = &'a u8>>(bytes: &mut I) -> Option<u32> {
fn next_code_point_reverse<'a, I>(bytes: &mut I) -> Option<u32>
where I: DoubleEndedIterator<Item = &'a u8>,
{
// Decode UTF-8
let w = match bytes.next_back() {
None => return None,
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_typeck/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,11 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
// are zero. Since I don't quite know how to phrase things at
// the moment, give a kind of vague error message.
if trait_params.len() != impl_params.len() {
span_err!(ccx.tcx.sess, span, E0195,
struct_span_err!(ccx.tcx.sess, span, E0195,
"lifetime parameters or bounds on method `{}` do \
not match the trait declaration",
impl_m.name);
not match the trait declaration",impl_m.name)
.span_label(span, &format!("lifetimes do not match trait"))
.emit();
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/rust-installer
1 change: 1 addition & 0 deletions src/test/compile-fail/E0195.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct Foo;

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

Expand Down
1 change: 1 addition & 0 deletions src/test/compile-fail/issue-16048.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ impl<'a> Test<'a> for Foo<'a> {
impl<'a> NoLifetime for Foo<'a> {
fn get<'p, T : Test<'a>>(&self) -> T {
//~^ ERROR E0195
//~| lifetimes do not match trait
return *self as T;
}
}
Expand Down