jiebi/CodeConvo huggingface dataset:
Change:
Uninhabited variants should ideally be irrelevant to the representation, just like in enums. As a test, this prints out 0 instead of 8: This happens because rustc considers unions more like structs than enums, and the sees a single variant with two fields, one of which is uninhabited. I have a fix for this, but it's slightly easier to bundle it with some other changes I'm working on.
This becomes a problem when making an array of unions: The above code represents a regression (prints 42 on stable, garbage on beta/nightly).
I didn't realize it was a regression to beta - in that case I'll put up an independent fix so that it can be backported if desired.
Although I can't trigger it on the playground, you code is actually triggering an ICE for me: EDIT: I bisected the ICE to somewhere between "rust 1.23.0-nightly ( 2017-11-25)" and "rust 1.23.0-nightly ( 2017-11-26)".
cc
I put up a PR to fix this, but I'm still confused about the ICE (which I moved to ).

Discussion:
}).collect::<Result<Vec<_>, _>>() }).collect::<Result<Vec<_>, _>>()?; <del> let (inh_first, inh_second) = { let mut inh_variants = (0..variants.len()).filter(|&v| { variants[v].iter().all(|f| f.abi != Abi::Uninhabited) }); (inh_variants.next(), inh_variants.next()) }; if inh_first.is_none() { // Uninhabited because it has no variants, or only uninhabited ones. return Ok(tcx.intern_layout(LayoutDetails::uninhabited(0))); } </del> if def.is_union() { let packed = def.repr.packed(); if packed && def.repr.align > 0 {

})); } <ins> let (inh_first, inh_second) = { let mut inh_variants = (0..variants.len()).filter(|&v| { variants[v].iter().all(|f| f.abi != Abi::Uninhabited) }); (inh_variants.next(), inh_variants.next()) }; if inh_first.is_none() { // Uninhabited because it has no variants, or only uninhabited ones. return Ok(tcx.intern_layout(LayoutDetails::uninhabited(0))); } </ins> let is_struct = !def.is_enum() || // Only one variant is inhabited. (inh_second.is_none() &&

<ins> // Copyright 2017 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. // To work around #46855 // compile-flags: -Z mir-opt-level=0 // Regression test for the inhabitedness of unions with uninhabited variants, issue #46845 use std::mem; #[derive(Copy, Clone)] enum Never { } // A single uninhabited variant shouldn't make the whole union uninhabited. union Foo { a: u64, _b: Never } // If all the variants are uninhabited, however, the union should be uninhabited. union Bar { _a: (Never, u64), _b: (u64, Never) } fn main() { assert_eq!(mem::size_of::<Foo>(), 8); assert_eq!(mem::size_of::<Bar>(), 0); let f = [Foo { a: 42 }, Foo { a: 10 }]; println!("{}", unsafe { f[0].a }); assert_eq!(unsafe { f[1].a }, 10); } </ins>
Change:
The documentation of the macros says: I find "not the invocation of the  macro itself" a bit misleading, because it is totally possible and expected for the return value to be the line of the invocation of the line macro itself when not being called from another macro. It may be clearer as "not necessarily the line of the  invocation itself".
This has been fixed.

Discussion:
/// The expanded expression has type `u32` and is 1-based, so the first line /// in each file evaluates to 1, the second to 2, etc. This is consistent /// with error messages by common compilers or popular editors. <del> /// The returned line is not the invocation of the `line!` macro itself, </del> <ins> /// The returned line is *not necessarily* the line of the `line!` invocation itself, </ins> /// but rather the first macro invocation leading up to the invocation /// of the `line!` macro. ///
Change:
The documentation of the macros says: I find "not the invocation of the  macro itself" a bit misleading, because it is totally possible and expected for the return value to be the line of the invocation of the line macro itself when not being called from another macro. It may be clearer as "not necessarily the line of the  invocation itself".
This has been fixed.

Discussion:
/// The expanded expression has type `u32` and is 1-based, so the first column /// in each line evaluates to 1, the second to 2, etc. This is consistent /// with error messages by common compilers or popular editors. <del> /// The returned column is not the invocation of the `column!` macro itself, </del> <ins> /// The returned column is *not necessarily* the line of the `column!` invocation itself, </ins> /// but rather the first macro invocation leading up to the invocation /// of the `column!` macro. ///
Change:
It's true that you can expect this behavior from the method signature, but this is too important a detail to leave out. What was the rustdoc syntax to document a particular impl of a trait?
You just write doc comments on the impl block as usual.

Discussion:
{ type Output = V; <ins> /// Returns a reference to the value corresponding to the supplied key. /// /// # Panics /// /// Panics if the key is not present in the `BTreeMap`. </ins> #[inline] fn index(&self, key: &Q) -> &V { self.get(key).expect("no entry found for key")

{ type Output = V; <ins> /// Returns a reference to the value corresponding to the supplied key. /// /// # Panics /// /// Panics if the key is not present in the `HashMap`. </ins> #[inline] <del> fn index(&self, index: &Q) -> &V { self.get(index).expect("no entry found for key") </del> <ins> fn index(&self, key: &Q) -> &V { self.get(key).expect("no entry found for key") </ins> } }
Change:
currently requires . It would be nice if we could remove this restriction. I'm not sure how to do it with the current implementation using though.
Doesn't seem possible until we get by-value DSTs
care to explain why?
Ah, nevermind. It would just need to make unsized, too.
The and methods can keep could keep their bounds, we just need to relax the bound on the struct itself, and make sure . Then the following code would be possible:
I guess this would be possible by allowing types to be when there is only one variant. I was worried that would be unsound, but then I realized, the only way to create a DST type would be from an unsize coercion, and then way you know what the erased type is and can get the vtable/slice length then, just like any other unsize coercion.
See

Discussion:
#[stable(feature = "manually_drop", since = "1.20.0")] #[lang = "manually_drop"] #[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] <del> pub struct ManuallyDrop<T> { </del> <ins> #[repr(transparent)] pub struct ManuallyDrop<T: ?Sized> { </ins> value: T, }

pub fn into_inner(slot: ManuallyDrop<T>) -> T { slot.value } <ins> } impl<T: ?Sized> ManuallyDrop<T> { </ins> /// Manually drops the contained value. /// /// # Safety

} #[stable(feature = "manually_drop", since = "1.20.0")] <del> impl<T> Deref for ManuallyDrop<T> { </del> <ins> impl<T: ?Sized> Deref for ManuallyDrop<T> { </ins> type Target = T; #[inline] fn deref(&self) -> &Self::Target {

} #[stable(feature = "manually_drop", since = "1.20.0")] <del> impl<T> DerefMut for ManuallyDrop<T> { </del> <ins> impl<T: ?Sized> DerefMut for ManuallyDrop<T> { </ins> #[inline] fn deref_mut(&mut self) -> &mut Self::Target { &mut self.value

let x = ManuallyDrop::new(TypeWithDrop); drop(x); <ins> // also test unsizing let x : Box<ManuallyDrop<[TypeWithDrop]>> = Box::new(ManuallyDrop::new([TypeWithDrop, TypeWithDrop])); drop(x); </ins> }
Change:
In fact, as the second example shows, is allowed. The phrase "out of bounds" is used in the docs of other methods ( and ) to mean so it should not be used to mean here. Suggest changing the wording to match : Panics if .
thanks for pointing this out! i just opened a pull request

Discussion:
/// /// # Panics /// <del> /// Panics if `index` is out of bounds. </del> <ins> /// Panics if `index > len`. </ins> /// /// # Examples ///
Change:
The documentation for is incorrect. Checks if the value is an ASCII graphic character: U+0021 ' ... U+007E '~'. For strings, true if all characters in the string are ASCII punctuation. This seems like an accidental copy-paste error from Also, the isascii_punctuation`, and could be fixed, but that's a minor issue
The quoting issue in the nightly version of the docs.

Discussion:
/// Checks if the value is an ASCII graphic character: /// U+0021 '@' ... U+007E '~'. /// For strings, true if all characters in the string are <del> /// ASCII punctuation. </del> <ins> /// ASCII graphic characters. </ins> /// /// # Note ///
Change:
The following compiles, but I think it shouldn't?
The field name is converted to a number too eagerly. This doesn't happen in struct expressions and patterns.

Discussion:
token::Ident(..) => { e = self.parse_dot_suffix(e, lo)?; } <del> token::Literal(token::Integer(n), suf) => { </del> <ins> token::Literal(token::Integer(index_ident), suf) => { </ins> let sp = self.span; // A tuple index may not have a suffix

hi = self.span; self.bump(); <del> let index = n.as_str().parse::<usize>().ok(); </del> <ins> let invalid_msg = "invalid tuple or struct index"; let index = index_ident.as_str().parse::<usize>().ok(); </ins> match index { Some(n) => { <ins> if n.to_string() != index_ident.as_str() { let mut err = self.struct_span_err(self.prev_span, invalid_msg); err.span_suggestion(self.prev_span, "try simplifying the index", n.to_string()); err.emit(); } </ins> let id = respan(dot_span.to(hi), n); let field = self.mk_tup_field(e, id); e = self.mk_expr(lo.to(hi), field, ThinVec::new()); } None => { let prev_span = self.prev_span; <del> self.span_err(prev_span, "invalid tuple or tuple struct index"); </del> <ins> self.span_err(prev_span, invalid_msg); </ins> } } }

<ins> // Copyright 2017 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. type Guilty = bool; type FineDollars = u32; struct Verdict(Guilty, Option<FineDollars>); fn main() { let justice = Verdict(true, Some(2718)); let _condemned = justice.00; //~^ ERROR invalid tuple or struct index let _punishment = justice.001; //~^ ERROR invalid tuple or struct index } </ins>

<ins> error: invalid tuple or struct index --> $DIR/issue-47073-zero-padded-tuple-struct-indices.rs:18:30 | 18 |     let _condemned = justice.00; |                              ^^ help: try simplifying the index: `0` error: invalid tuple or struct index --> $DIR/issue-47073-zero-padded-tuple-struct-indices.rs:20:31 | 20 |     let _punishment = justice.001; |                               ^^^ help: try simplifying the index: `1` error: aborting due to 2 previous errors </ins>
Change:
In the documentation for , there are two examples. The first is This is not a closure, as it never moves out of a variable in a way that would prevent it from calling again.
As a technical point, all closures are closures, because they may be called at least once. implies which implies . However, closures that modify their environment are only and (not ) and closures that move out of their environment are only .
Fair point. But as someone new to the documentation, I feel there's an implication in a few places (including the book, but unfortunately that section is frozen) that any closure is only and neither or , which isn't true.
Yes, it needs to be made more clear that those are totally orthogonal issues.
I personally think that the first example is better to be removed from the page, since (in my opinion) it causes more confusion then that it actually helps. I guess that most people looking up FnOnce already know a bit about closures and might already know about the syntax. The page also references the book on closures, so I don't think its necessary to provide an example for calling by-value. The second example also includes the calling by value part. I can imagine that users think the first example can only be called once (because they are on the FnOnce page), but this code also works: What do you think about this? I can pick this up if you agree.
Sounds good to me!

Discussion:
/// /// # Examples /// <del> /// ## Calling a by-value closure /// /// ``` /// let x = 5; /// let square_x = move || x * x; /// assert_eq!(square_x(), 25); /// ``` /// </del> /// ## Using a `FnOnce` parameter /// /// ```
Change:
As reported in the core test for atexit seems to be failing sometimes. It's failing because the atexit registration function expects to be passed the same pointer on each call but apparently isn't. I can imagine this could be because of the way coretest works, so coretest ends up using a different function than core. I can't though explain why this isn't showing up on the bots or in my tests.
is this still relevant? I'm not even sure which of the two at_exit tests this is referring to.
There appears to no longer be any at_exit function in the new runtime, except for a possible TLS destructor which will be removed in

Discussion:
assert(!at_exit_started && "registering at_exit function after exit"); if (at_exit_runner) { <del> assert(runner == at_exit_runner && "there can be only one at_exit_runner"); </del> <ins> // FIXME #2912 Would be very nice to assert this but we can't because // of the way coretest works (the test case ends up using its own // function) //assert(runner == at_exit_runner //       && "there can be only one at_exit_runner"); </ins> } at_exit_runner = runner;
Change:
Valgrind reports use of uninitialized memory in the following program, which was reduced from and
Here is a reduced test case: It turns out that trans never stores the discriminant for the constructor here, and it remains uninitialized.
Relevant LLVM IR: cc
That's because is optimized in that case to the same size as (where is the generator state, I assume), which makes the identity function (relying on a valid ). I guess generator fields don't have struct semantics but rather union/maybe-uninitialized semantics?

Discussion:
}, niche_start)) }; <ins> // Locals variables which live across yields are stored // in the generator type as fields. These may be uninitialized // so we don't look for niches there. if let ty::TyGenerator(..) = self.ty.sty { return Ok(None); } </ins> match self.abi { Abi::Scalar(ref scalar) => { return Ok(scalar_component(scalar, Size::from_bytes(0)));
Change:
This code, when compiled for , results in an ICE: Putting smaller integers in does not trigger this, even if you use a ton of them. Edit: It also does not occur when taking it only as argument, or when only returning it. Panic message and backtrace: Rust version: cc
Looks like this could be caused by this common skipping of padding arguments: Combined with this call (which internally also skips padding arguments): When the latter gets used, each padding argument is skipped twice. I assume this is fallout.
triage: P-high Beta regression. Has pending fix.

Discussion:
} pub fn store_fn_arg(&self, bx: &Builder<'a, 'tcx>, idx: &mut usize, dst: PlaceRef<'tcx>) { <del> if self.pad.is_some() { *idx += 1; } </del> let mut next = || { let val = llvm::get_param(bx.llfn(), *idx as c_uint); *idx += 1;

for i in 0..tupled_arg_tys.len() { let arg = &fx.fn_ty.args[idx]; idx += 1; <ins> if arg.pad.is_some() { llarg_idx += 1; } </ins> arg.store_fn_arg(bx, &mut llarg_idx, place.project_field(bx, i)); }

<ins> // Copyright 2018 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. // -C no-prepopulate-passes #![crate_type="staticlib"] #[repr(C)] pub struct Foo(u64); // CHECK: define {{.*}} @foo( #[no_mangle] pub extern fn foo(_: Foo) -> Foo { loop {} } </ins>
Change:
Leaks.
this got worse; it now ICEs with an 'assertion failed: adt::is_newtypeish(repr)'
non-critical for 0.6, de-milestoning
Works now; I'll check in the test case.
Test case checked in in . Closing

Discussion:
} <del> fn test_X() { </del> <ins> pub fn main() { </ins> constants!(); }
Change:
Follow up to . Instead of calling and then , do and then . In my tests on macOS this is significantly faster.
Quick microbenchmark which demonstrates the performance difference; it's not in Rust, but I believe it demonstrates the underlying idea here. Measured on macOS 10.13.2:

Discussion:
recursive: bool, } <del> /// How large a buffer to pre-allocate before reading the entire file at `path`. fn initial_buffer_size<P: AsRef<Path>>(path: P) -> usize { </del> <ins> /// How large a buffer to pre-allocate before reading the entire file. fn initial_buffer_size(file: &File) -> usize { </ins> // Allocate one extra byte so the buffer doesn't need to grow before the // final `read` call at the end of the file.  Don't worry about `usize` // overflow because reading will fail regardless in that case. <del> metadata(path).map(|m| m.len() as usize + 1).unwrap_or(0) </del> <ins> file.metadata().map(|m| m.len() as usize + 1).unwrap_or(0) </ins> } /// Read the entire contents of a file into a bytes vector.

/// ``` #[unstable(feature = "fs_read_write", issue = "46588")] pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> { <del> let mut bytes = Vec::with_capacity(initial_buffer_size(&path)); File::open(path)?.read_to_end(&mut bytes)?; </del> <ins> let mut file = File::open(path)?; let mut bytes = Vec::with_capacity(initial_buffer_size(&file)); file.read_to_end(&mut bytes)?; </ins> Ok(bytes) }

/// ``` #[unstable(feature = "fs_read_write", issue = "46588")] pub fn read_string<P: AsRef<Path>>(path: P) -> io::Result<String> { <del> let mut string = String::with_capacity(initial_buffer_size(&path)); File::open(path)?.read_to_string(&mut string)?; </del> <ins> let mut file = File::open(path)?; let mut string = String::with_capacity(initial_buffer_size(&file)); file.read_to_string(&mut string)?; </ins> Ok(string) }
Change:
For compatibility with clang and for debugging convenience, should disassemble the bitcode.

Discussion:
fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt, output: str, amap: ast_map::map, mut_map: mut::mut_map, copy_map: alias::copy_map) -> ModuleRef { <del> let llmod = str::as_buf("rust_out", {|buf| </del> <ins> let sha = std::sha1::mk_sha1(); let link_meta = link::build_link_meta(sess, *crate, output, sha); let llmod = str::as_buf(link_meta.name, {|buf| </ins> llvm::LLVMModuleCreateWithNameInContext (buf, llvm::LLVMGetGlobalContext()) });

let lltypes = map::mk_hashmap::<ty::t, TypeRef>(hasher, eqer); let sha1s = map::mk_hashmap::<ty::t, str>(hasher, eqer); let short_names = map::mk_hashmap::<ty::t, str>(hasher, eqer); <del> let sha = std::sha1::mk_sha1(); let link_meta = link::build_link_meta(sess, *crate, output, sha); </del> let crate_map = decl_crate_map(sess, link_meta.name, llmod); let ccx = @{sess: sess,
Change:
It seems to me that returning a Result would be more appropriate than failing.
See discussion on -- the right thing to do here would be to use conditions, I think.
This should be pretty simple -- working on it.
Fixed pending
fixes.

Discussion:
#[cfg(not(test))] use cmp::{Eq, Ord, Equiv, TotalEq}; /* <ins> Section: Conditions */ condition! { not_utf8: (~str) -> ~str; } /* </ins> Section: Creating a string */

* * # Failure * <del> * Fails if invalid UTF-8 </del> <ins> * Raises the `not_utf8` condition if invalid UTF-8 </ins> */ <del> pub fn from_bytes(vv: &const [u8]) -> ~str { assert!(is_utf8(vv)); return unsafe { raw::from_bytes(vv) }; </del> <ins> pub fn from_bytes(vv: &[u8]) -> ~str { use str::not_utf8::cond; if !is_utf8(vv) { let first_bad_byte = vec::find(vv, |b| !is_utf8([*b])).get(); cond.raise(fmt!("from_bytes: input is not UTF-8; first bad byte is %u", first_bad_byte as uint)) } else { return unsafe { raw::from_bytes(vv) } } </ins> } /**

} #[test] <del> #[should_fail] </del> #[ignore(cfg(windows))] fn test_from_bytes_fail() { <ins> use str::not_utf8::cond; </ins> let bb = ~[0xff_u8, 0xb8_u8, 0xa8_u8, 0xe0_u8, 0xb9_u8, 0x84_u8, 0xe0_u8, 0xb8_u8, 0x97_u8,

0x20_u8, 0x4e_u8, 0x61_u8, 0x6d_u8]; <del> let _x = from_bytes(bb); </del> <ins> let mut error_happened = false; let _x = do cond.trap(|err| { assert_eq!(err, ~"from_bytes: input is not UTF-8; first bad byte is 255"); error_happened = true; ~"" }).in { from_bytes(bb) }; assert!(error_happened); </ins> } #[test]
Change:
I will like to fix this. What should be the better warning message here? Or I just need to remove the last sentence?
It seems fine to just remove the sentence.
Fixed by

Discussion:
("thread_local", Whitelisted, Gated(Stability::Unstable, "thread_local", "`#[thread_local]` is an experimental feature, and does  <del> not currently handle destructors. There is no  corresponding `#[task_local]` mapping to the task  model", </del> <ins> not currently handle destructors.", </ins> cfg_fn!(thread_local))), ("rustc_on_unimplemented", Normal, Gated(Stability::Unstable,

<del> error[E0658]: `#[thread_local]` is an experimental feature, and does not currently handle destructors. There is no corresponding `#[task_local]` mapping to the task model (see issue #29594) </del> <ins> error[E0658]: `#[thread_local]` is an experimental feature, and does not currently handle destructors. (see issue #29594) </ins> --> $DIR/feature-gate-thread_local.rs:18:1 | 18 | #[thread_local] //~ ERROR `#[thread_local]` is an experimental feature
Change:
This code fails to link: with this nice linker error message Here's a playground link:
Looks like a simple case of lazy inline function instantiation applying in a case where it shouldn't. The fix should be just marking the function as "used" for the sake of instantiating it. cc

Discussion:
match *self.as_mono_item() { MonoItem::Fn(ref instance) => { <ins> let entry_def_id = tcx.sess.entry_fn.borrow().map(|(id, _)| tcx.hir.local_def_id(id)); </ins> // If this function isn't inlined or otherwise has explicit // linkage, then we'll be creating a globally shared version. if self.explicit_linkage(tcx).is_some() || <del> !instance.def.requires_local(tcx) </del> <ins> !instance.def.requires_local(tcx) || Some(instance.def_id()) == entry_def_id </ins> { return InstantiationMode::GloballyShared  { may_conflict: false } }

<ins> // Copyright 2018 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. #[inline(always)] fn main() {} </ins>