jiebi/CodeConvo huggingface dataset:
Change:
Using Google I can find lots of old arguments over how integer division should work in Rust, but I cannot find anything in the reference, the API docs for the integer types, or the API docs for the trait that says what was actually decided. (And the documentation seems to imply that , , and may not all do the same thing.) This is further confused by the integer type documentation apparently sometimes using to refer to integer division and sometimes to mathematical division. (I can't come up with out any other reasonable interpretation of in the documentation.) It would be nice if this were clearly documented somewhere, since this varies between languages and is one of the main confusions with integer arithmetic.
talks about 'overflow' and mentions wrapping, but you're right that we can surface this better.
This is about rounding, not wrapping. We use LLVM's , which rounds towards zero (and has the same sign as the dividend). We should document this (the documentation for currently lies_, claiming that it rounds towards negative infinite).
This should also leave a warning, because integer / integer is not always desired and happens by accident. Just a thought if anyone is reading this.

Discussion:
} } <del> /// Wrapping (modular) division. Computes `floor(self / other)`, </del> <ins> /// Wrapping (modular) division. Computes `self / other`, </ins> /// wrapping around at the boundary of the type. /// /// The only case where such wrapping can occur is when one

/// negative minimal value for the type); this is equivalent /// to `-MIN`, a positive value that is too large to represent /// in the type. In such a case, this function returns `MIN` <del> /// itself.. </del> <ins> /// itself. </ins> #[stable(feature = "num_wrapping", since = "1.2.0")] #[inline(always)] pub fn wrapping_div(self, rhs: Self) -> Self {

fn div(self, rhs: RHS) -> Self::Output; } <del> macro_rules! div_impl { </del> <ins> macro_rules! div_impl_integer { </ins> ($($t:ty)*) => ($( <ins> /// This operation rounds towards zero, truncating any /// fractional part of the exact result. </ins> #[stable(feature = "rust1", since = "1.0.0")] impl Div for $t { type Output = $t;

)*) } <del> div_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } </del> <ins> div_impl_integer! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 } macro_rules! div_impl_float { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] impl Div for $t { type Output = $t; #[inline] fn div(self, other: $t) -> $t { self / other } } forward_ref_binop! { impl Div, div for $t, $t } )*) } div_impl_float! { f32 f64 } </ins> /// The `Rem` trait is used to specify the functionality of `%`. ///

macro_rules! rem_impl { ($($t:ty)*) => ($( <ins> /// This operation satisfies `n % d == n - (n / d) * d`.  The /// result has the same sign as the left operand. </ins> #[stable(feature = "rust1", since = "1.0.0")] impl Rem for $t { type Output = $t;
Change:
Currently, takes as . Why is that? The implementation simply locks and calls on the guard, and locking doesn't need a mutable . So this is unnecessary, and the doc doesn't say why this was done. (Nor does the source.) So I propose for this to be changed to . Looks like an oversight of some refactoring to me.
I imagine it's like that because the signature was copied off of the trait - changing it to take seems fine to me personally. cc
Yeah I think it'd be fine to switch to
Is it quicker for one of you to just do that, or should I submit a PR?
Go for it!
See .

Discussion:
//    in which case it will wait for the Enter key to be pressed before ///   continuing #[stable(feature = "rust1", since = "1.0.0")] <del> pub fn read_line(&mut self, buf: &mut String) -> io::Result<usize> { </del> <ins> pub fn read_line(&self, buf: &mut String) -> io::Result<usize> { </ins> self.lock().read_line(buf) } }
Change:
Currently, the only documentation of the rules for object safety I could find is in . However, this should also become part of the official documentation, for example .
It is currently defined in but having it in the book would be nice too.

Discussion:
// y.method(); (y.vtable.method)(y.data); ``` <ins> ## Object Safety Not every trait can be used to make a trait object. For example, vectors implement `Clone`, but if we try to make a trait object: ```ignore let v = vec![1, 2, 3]; let o = &v as &Clone; ``` We get an error: ```text error: cannot convert to a trait object because trait `core::clone::Clone` is not object-safe [E0038] let o = &v as &Clone; ^~ note: the trait cannot require that `Self : Sized` let o = &v as &Clone; ^~ ``` The error says that `Clone` is not ‘object-safe’. Only traits that are object-safe can be made into trait objects. A trait is object-safe if both of these are true: * the trait does not require that `Self: Sized` * all of its methods are object-safe So what makes a method object-safe? Each method must require that `Self: Sized` or all of the following: * must not have any type parameters * must not use `Self` Whew! As we can see, almost all of these rules talk about `Self`. A good intuition is “except in special circumstances, if your trait’s method uses `Self`, it is not object-safe.” </ins>
Change:
produces: Note: omitting the field before the yields a "missing field" error. (I can't find anything this would be a dupe of.)
I really don't see how this could work. This should give an error rather than an ICE through.

Discussion:
let def = lookup_full_def(tcx, path.span, id); let struct_id = match def { def::DefVariant(enum_id, variant_id, true) => { <ins> if let &Some(ref base_expr) = base_expr { span_err!(tcx.sess, base_expr.span, E0401, "functional record update syntax requires a struct"); fcx.write_error(base_expr.id); } </ins> check_struct_enum_variant(fcx, id, expr.span, enum_id, variant_id, &fields[..]); enum_id

E0392, // parameter `{}` is never used E0393, // the type parameter `{}` must be explicitly specified in an object // type because its default value `{}` references the type `Self`" <del> E0399  // trait items need to be implemented because the associated </del> <ins> E0399, // trait items need to be implemented because the associated </ins> // type `{}` was overridden <ins> E0401  // functional record update requires a struct </ins> }

<ins> // Copyright 2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. fn main() { enum Foo { A { x: u32 } } let orig = Foo::A { x: 5 }; Foo::A { x: 6, ..orig }; //~^ ERROR functional record update syntax requires a struct } </ins>
Change:
CString should escape its contents like a byte string, not trying to show it as utf-8. Right now it does the latter via
For example, if the CString contains the byte , I would expect that to be visible in the Debug output.

Discussion:
// option. This file may not be copied, modified, or distributed // except according to those terms. <ins> use ascii; </ins> use borrow::{Cow, ToOwned, Borrow}; use boxed::Box; use clone::Clone; use convert::{Into, From}; use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering}; use error::Error; <del> use fmt; </del> <ins> use fmt::{self, Write}; </ins> use io; use iter::Iterator; use libc;

#[stable(feature = "rust1", since = "1.0.0")] impl fmt::Debug for CString { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { <del> fmt::Debug::fmt(&String::from_utf8_lossy(self.as_bytes()), f) </del> <ins> fmt::Debug::fmt(&**self, f) } } #[stable(feature = "cstr_debug", since = "1.3.0")] impl fmt::Debug for CStr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, """)); for byte in self.to_bytes().iter().flat_map(|&b| ascii::escape_default(b)) { try!(f.write_char(byte as char)); } write!(f, """) </ins> } }

#[test] fn formatted() { <del> let s = CString::new(&b"12"[..]).unwrap(); assert_eq!(format!("{:?}", s), ""12""); </del> <ins> let s = CString::new(&b"abcx01x02nxE2x80xA6xFF"[..]).unwrap(); assert_eq!(format!("{:?}", s), r#""abcx01x02nxe2x80xa6xff""#); </ins> } #[test]
Change:
When reading the book, specifically the in Patterns, I found it unclear that in a pattern can match multiple fields. Thus couldn't figure out what made it differ from , without playing with code. This is because of: the phrasing, specifically "the value and type in the variant" the example not expressing the difference between and.

Discussion:
} ``` <del> # Ignoring variants </del> <ins> # Ignoring bindings </ins> <del> If you’re matching on an enum which has variants, you can use `..` to ignore the value and type in the variant: </del> <ins> You can use `_` in a pattern to disregard the type and value. For example, here’s a `match` against a `Result<T, E>`: </ins> ```rust <del> enum OptionalInt { Value(i32), </del> <ins> # let some_value: Result<i32, &'static str> = Err("There was an error"); match some_value { Ok(value) => println!("got a value: {}", value), Err(_) => println!("an error occurred"), } ``` In the first arm, we bind the value inside the `Ok` variant to `value`. But in the `Err` arm, we use `_` to disregard the specific error, and just print a general error message. `_` is valid in any pattern that creates a binding. This can be useful to ignore parts of a larger structure: ```rust fn coordinate() -> (i32, i32, i32) { // generate and return some sort of triple tuple # (1, 2, 3) } let (x, _, z) = coordinate(); ``` Here, we bind the first and last element of the tuple to `x` and `z`, but ignore the middle element. Similarly, you can use `..` in a pattern to disregard multiple values. ```rust enum OptionalTuple { Value(i32, i32, i32), </ins> Missing, } <del> let x = OptionalInt::Value(5); </del> <ins> let x = OptionalTuple::Value(5, -2, 3); </ins> match x { <del> OptionalInt::Value(..) => println!("Got an int!"), OptionalInt::Missing => println!("No such luck."), </del> <ins> OptionalTuple::Value(..) => println!("Got a tuple!"), OptionalTuple::Missing => println!("No such luck."), </ins> } ``` <del> This prints `Got an int!`. </del> <ins> This prints `Got a tuple!`. </ins> # Guards

[tuples]: primitive-types.html#tuples [enums]: enums.html <del> # Ignoring bindings You can use `_` in a pattern to disregard the value. For example, here’s a `match` against a `Result<T, E>`: ```rust # let some_value: Result<i32, &'static str> = Err("There was an error"); match some_value { Ok(value) => println!("got a value: {}", value), Err(_) => println!("an error occurred"), } ``` In the first arm, we bind the value inside the `Ok` variant to `value`. But in the `Err` arm, we use `_` to disregard the specific error, and just print a general error message. `_` is valid in any pattern that creates a binding. This can be useful to ignore parts of a larger structure: ```rust fn coordinate() -> (i32, i32, i32) { // generate and return some sort of triple tuple # (1, 2, 3) } let (x, _, z) = coordinate(); ``` Here, we bind the first and last element of the tuple to `x` and `z`, but ignore the middle element. </del> # Mix and Match Whew! That’s a lot of different ways to match things, and they can all be
Change:
Per fixme in rust_util.h.
right to me? But then I think I wrote it. This isn't actionable, I'm going to open a PR to remove the FIXME.
Fixed by

Discussion:
#[inline] pub fn get_box_size(body_size: uint, body_align: uint) -> uint { let header_size = size_of::<raw::Box<()>>(); <del> // FIXME (#2699): This alignment calculation is suspicious. Is it right? </del> let total_size = align_to(header_size, body_align) + body_size; total_size }
Change:
yields the expected while thinks that is a variable
I hope this can help you
This is due to the fact that while is a path expression, it doesn't refer to a constant, so the relevant code fails, and the check that produces the error assumes that is a variable.
What would be the proper way to fix this (rustc newbie here)? Is it possible to check if a non-constant path expression refers to an integer or to a struct, or should the error message just be changed to contain the two possibilities?
It's probably necessary to change to account for unit-struct-names

Discussion:
Some(def::DefVariant(enum_def, variant_def, _)) => { (lookup_variant_by_id(tcx, enum_def, variant_def), None) } <ins> Some(def::DefStruct(_)) => { return Ok(ConstVal::Struct(e.id)) } </ins> _ => (None, None) }; let const_expr = match const_expr {

<ins> // Copyright 2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. struct S; fn main() { let b = [0; S]; //~^ ERROR mismatched types //~| expected `usize` //~| found `S` //~| expected usize //~| found struct `S` //~| ERROR expected positive integer for repeat count, found struct } </ins>
Change:
This appears to be false from reading the source; it looks like it actually returns the value of the closure if no panic occurs.

Discussion:
/// Invokes a closure, capturing the cause of panic if one occurs. /// <del> /// This function will return `Ok(())` if the closure does not panic, and will /// return `Err(cause)` if the closure panics. The `cause` returned is the /// object with which panic was originally invoked. </del> <ins> /// This function will return `Ok` with the closure's result if the closure /// does not panic, and will return `Err(cause)` if the closure panics. The /// `cause` returned is the object with which panic was originally invoked. </ins> /// /// It is currently undefined behavior to unwind from Rust code into foreign /// code, so this function is particularly useful when Rust is called from
Change:
This is accepted, but probably shouldn't be. (A normal declaration of a variable named None is rejected.)
Related testcase:
That second case is unrelated. (And really weird, I'm not even sure how that's happening!)

Discussion:
let pat_id = pattern.id; walk_pat(pattern, |pattern| { match pattern.node { <del> PatIdent(binding_mode, ref path1, _) => { // The meaning of pat_ident with no type parameters </del> <ins> PatIdent(binding_mode, ref path1, ref at_rhs) => { // The meaning of PatIdent with no type parameters </ins> // depends on whether an enum variant or unit-like struct // with that name is in scope. The probing lookup has to // be careful not to emit spurious errors. Only matching // patterns (match) can match nullary variants or <del> // unit-like structs. For binding patterns (let), matching // such a value is simply disallowed (since it's rarely // what you want). </del> <ins> // unit-like structs. For binding patterns (let // and the LHS of @-patterns), matching such a value is // simply disallowed (since it's rarely what you want). let const_ok = mode == RefutableMode && at_rhs.is_none(); </ins> let ident = path1.node; let renamed = mtwt::resolve(ident); match self.resolve_bare_identifier_pattern(ident.name, pattern.span) { <del> FoundStructOrEnumVariant(def, lp) if mode == RefutableMode => { </del> <ins> FoundStructOrEnumVariant(def, lp) if const_ok => { </ins> debug!("(resolving pattern) resolving `{}` to  struct or enum variant", renamed);

renamed) ); } <del> FoundConst(def, lp) if mode == RefutableMode => { </del> <ins> FoundConst(def, lp) if const_ok => { </ins> debug!("(resolving pattern) resolving `{}` to  constant", renamed);

<ins> // Copyright 2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. fn main() { match Some(1) { None @ _ => {} //~ ERROR declaration of `None` shadows an enum variant }; const C: u8 = 1; match 1 { C @ 2 => { //~ ERROR only irrefutable patterns allowed here println!("{}", C); } _ => {} }; } </ins>
Change:
There are hidden assumptions around that don’t appear to be included in any of the documentation that I can find. Most notably, ’s use of requires that and () hash the same; if they don’t, your will be mysteriously broken when you try indexing it by . I’d suggest making an unsafe trait, but unsafe doesn’t mean <subblah blah <submumble mumble memory safety mumble</sub</sub Anyway, we need some serious warnings on at least the documentation. Something including things like “if you are implementing and both and implement , they must produce the same result, for HashMap’s sake.”
: : However I agree it could be more prominent.

Discussion:
/// type can be borrowed as multiple different types. In particular, `Vec<T>: /// Borrow<Vec<T>>` and `Vec<T>: Borrow<[T]>`. /// <ins> /// If you are implementing `Borrow` and both `Self` and `Borrowed` implement /// `Hash`, `Eq`, and/or `Ord`, they must produce the same result. /// </ins> /// `Borrow` is very similar to, but different than, `AsRef`. See /// [the book][book] for more. ///
Change:
LLVM cannot build with python 3 but tries anyway. This has caused confusion a number of times.
This was fixed by the pull req. Closing.
Turns out this didn't actually fix the problem. At the time I had (wrongly) assumed that the Python version detected during Rust's configure phase was being somehow communicated to LLVM. Looking a bit more closely, I'm not sure that Rust does anything at all with the detected version of Python; perhaps an artifact of an era when Rust had a Python dependency? bbrittain (who rediscovered this bug) and I discussed some hacky workarounds and finally decided that the best thing to do is to send a patch upstream to LLVM (which, despite having a hard dependency on Python 2, never bothers to check for Python 3 and just fails with cryptic errors). Once the fix is accepted we can integrate it into Rust's fork of LLVM.
(I'm bbrittain) LLVM assumes, and has hardcoded, that means a python2.x. Bleeding-edge linux distros, such as arch, now have 'python' mean python3. It's easy to symlink around, but it really would be better to just fix it.
Reopening. you have a pull request on brson/llvm that I completely forgot about. Is it still appropriate to merge? Do you know if llvm has the fix upstream yet? Sorry I lost your patch. Feel free to contact me privately if that happens again.
This does continue to come up. Would be nice to fix definitively.
LLVM has not fixed it upstream. frankly, I couldn't find a way to submit the bug fix due to them using SVN...
erickt has rebased us onto LLVM HEAD and I rebased your patch on top of that. Hopefully this will get in today.
sweet, thanks!
The fix is on incoming.

Discussion:
step_msg "looking for build programs" probe_need CFG_PERL        perl <del> probe_need CFG_PYTHON      python python2.6 python2 python3 </del> probe_need CFG_CURL        curl <ins> probe_need CFG_PYTHON      python2.7 python2.6 python2 python python_version=$($CFG_PYTHON -V 2>&1) if [ $(echo $python_version | grep -c '^Python 2.[4567]') -ne 1 ]; then err "Found $python_version, but LLVM requires Python 2.4-2.7" fi </ins> # If we have no git directory then we are probably a tarball distribution # and shouldn't attempt to load submodules
Change:
Formatting a string containing special characters with usually prints them escaped i.e.. This snippet runs as expected in the . However on Windows, using both and , the is printed unescaped : From what I can gather,  only concerns itself with faulty surrogates and completely ignores special characters.

Discussion:
fn fmt(&self, f: &mut Formatter) -> Result { try!(write!(f, """)); for c in self.chars().flat_map(|c| c.escape_default()) { <del> try!(write!(f, "{}", c)); </del> <ins> try!(f.write_char(c)) </ins> } write!(f, """) }

use char::CharExt; try!(write!(f, "'")); for c in self.escape_default() { <del> try!(write!(f, "{}", c)); </del> <ins> try!(f.write_char(c)) </ins> } write!(f, "'") }

/// and surrogates as `u` followed by four hexadecimal digits. /// Example: `"au{D800}"` for a slice with code points [U+0061, U+D800] impl fmt::Debug for Wtf8 { <del> fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { </del> <ins> fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { fn write_str_escaped(f: &mut fmt::Formatter, s: &str) -> fmt::Result { use fmt::Write; for c in s.chars().flat_map(|c| c.escape_default()) { try!(f.write_char(c)) } Ok(()) } </ins> try!(formatter.write_str(""")); let mut pos = 0; loop { match self.next_surrogate(pos) { None => break, Some((surrogate_pos, surrogate)) => { <del> try!(formatter.write_str(unsafe { // the data in this slice is valid UTF-8, transmute to &str mem::transmute(&self.bytes[pos .. surrogate_pos]) })); </del> <ins> try!(write_str_escaped( formatter, unsafe { str::from_utf8_unchecked( &self.bytes[pos .. surrogate_pos] )}, )); </ins> try!(write!(formatter, "u{{{:X}}}", surrogate)); pos = surrogate_pos + 3; } } } <del> try!(formatter.write_str(unsafe { // the data in this slice is valid UTF-8, transmute to &str mem::transmute(&self.bytes[pos..]) })); </del> <ins> try!(write_str_escaped( formatter, unsafe { str::from_utf8_unchecked(&self.bytes[pos..]) }, )); </ins> formatter.write_str(""") } }

#[test] fn wtf8buf_show() { <del> let mut string = Wtf8Buf::from_str("aé 💩"); </del> <ins> let mut string = Wtf8Buf::from_str("até 💩r"); </ins> string.push(CodePoint::from_u32(0xD800).unwrap()); <del> assert_eq!(format!("{:?}", string), r#""aé 💩u{D800}""#); </del> <ins> assert_eq!(format!("{:?}", string), r#""atu{e9} u{1f4a9}ru{D800}""#); </ins> } #[test]

} #[test] <del> fn wtf8_show() { let mut string = Wtf8Buf::from_str("aé 💩"); string.push(CodePoint::from_u32(0xD800).unwrap()); assert_eq!(format!("{:?}", string), r#""aé 💩u{D800}""#); </del> <ins> fn wtf8buf_show_str() { let text = "até 💩r"; let mut string = Wtf8Buf::from_str(text); assert_eq!(format!("{:?}", text), format!("{:?}", string)); </ins> } #[test]