jiebi/CodeConvo huggingface dataset:
// If the first pattern is an or-pattern, expand it. if let Some(vs) = v.expand_or_pat() { <del> // We need to push the already-seen patterns into the matrix in order to detect redundant // branches like `Some(_) | Some(0)`. We also keep track of the unreachable subpatterns. let mut matrix = matrix.clone(); // `Vec` of all the unreachable branches of the current or-pattern. let mut unreachable_branches = Vec::new(); // Subpatterns that are unreachable from all branches. E.g. in the following case, the last // `true` is unreachable only from one branch, so it is overall reachable. </del> <ins> // We expand the or pattern, trying each of its branches in turn and keeping careful track // of possible unreachable sub-branches. // // If two branches have detected some unreachable sub-branches, we need to be careful. If // they were detected in columns that are not the current one, we want to keep only the // sub-branches that were unreachable in _all_ branches. Eg. in the following, the last // `true` is unreachable in the second branch of the first or-pattern, but not otherwise. // Therefore we don't want to lint that it is unreachable. </ins> // // ``` // match (true, true) {
hir::MatchSource::AwaitDesugar | hir::MatchSource::TryDesugar => {} } } <del> Useful(unreachable_subpatterns) => { for span in unreachable_subpatterns { </del> <ins> Useful(unreachables) => { let mut unreachables: Vec<_> = unreachables.into_iter().flatten().collect(); // Emit lints in the order in which they occur in the file. unreachables.sort_unstable(); for span in unreachables { </ins> unreachable_pattern(cx.tcx, span, id, None); } }
(false | true, false | true) => {} } match (true, true) { <del> (true, false) => {} (false, true) => {} </del> <ins> (true, true) => {} (false, false) => {} </ins> (false | true, false | true) => {} } <ins> // https://github.com/rust-lang/rust/issues/76836 match None { Some(false) => {} None | Some(true | false) => {} //~ ERROR unreachable } </ins> // A subpattern that is unreachable in all branches is overall unreachable. match (true, true) { (false, true) => {}
|              ^ error: unreachable pattern <del> --> $DIR/exhaustiveness-unreachable-pattern.rs:89:15 </del> <ins> --> $DIR/exhaustiveness-unreachable-pattern.rs:88:19 | LL |                 | false) => {} |                   ^^^^^ error: unreachable pattern --> $DIR/exhaustiveness-unreachable-pattern.rs:96:15 </ins> | LL |             | true) => {} |               ^^^^ error: unreachable pattern <del> --> $DIR/exhaustiveness-unreachable-pattern.rs:95:15 </del> <ins> --> $DIR/exhaustiveness-unreachable-pattern.rs:102:15 </ins> | LL |             | true, |               ^^^^ <del> error: aborting due to 18 previous errors </del> <ins> error: aborting due to 19 previous errors </ins>
// and about 2 * (len1 + len2) comparisons in the worst case // while `extend` takes O(len2 * log(len1)) operations // and about 1 * len2 * log_2(len1) comparisons in the worst case, <del> // assuming len1 >= len2. </del> <ins> // assuming len1 >= len2. For larger heaps, the crossover point // no longer follows this reasoning and was determined empirically. </ins> #[inline] fn better_to_rebuild(len1: usize, len2: usize) -> bool { <del> 2 * (len1 + len2) < len2 * log2_fast(len1) </del> <ins> let tot_len = len1 + len2; if tot_len <= 2048 { 2 * tot_len < len2 * log2_fast(len1) } else { 2 * tot_len < len2 * 11 } </ins> } if better_to_rebuild(self.len(), other.len()) {
} } hir::InlineAsmOperand::InOut { expr, .. } => { <del> succ = self.write_place(expr, succ, ACC_READ | ACC_WRITE); </del> <ins> succ = self.write_place(expr, succ, ACC_READ | ACC_WRITE | ACC_USE); </ins> } hir::InlineAsmOperand::SplitInOut { out_expr, .. } => { if let Some(expr) = out_expr {
<ins> // Ensure inout asm! operands are marked as used by the liveness pass // only-x86_64 // check-pass #![feature(asm)] #![allow(dead_code)] #![warn(unused_assignments)] #![warn(unused_variables)] // Test the single inout case unsafe fn f1(mut src: *const u8) { asm!("/*{0}*/", inout(reg) src); //~ WARN value assigned to `src` is never read } unsafe fn f2(mut src: *const u8) -> *const u8 { asm!("/*{0}*/", inout(reg) src); src } // Test the split inout case unsafe fn f3(mut src: *const u8) { asm!("/*{0}*/", inout(reg) src => src); //~ WARN value assigned to `src` is never read } unsafe fn f4(mut src: *const u8) -> *const u8 { asm!("/*{0}*/", inout(reg) src => src); src } // Tests the use of field projections struct S { field: *mut u8, } unsafe fn f5(src: &mut S) { asm!("/*{0}*/", inout(reg) src.field); } unsafe fn f6(src: &mut S) { asm!("/*{0}*/", inout(reg) src.field => src.field); } fn main() {} </ins>
<ins> warning: value assigned to `src` is never read --> $DIR/liveness-asm.rs:13:32 | LL |     asm!("/*{0}*/", inout(reg) src); |                                ^^^ | note: the lint level is defined here --> $DIR/liveness-asm.rs:8:9 | LL | #![warn(unused_assignments)] |         ^^^^^^^^^^^^^^^^^^ = help: maybe it is overwritten before being read? warning: value assigned to `src` is never read --> $DIR/liveness-asm.rs:23:39 | LL |     asm!("/*{0}*/", inout(reg) src => src); |                                       ^^^ | = help: maybe it is overwritten before being read? warning: 2 warnings emitted </ins>
let func_ty = func.ty(body, tcx); if let ty::FnDef(callee, substs) = *func_ty.kind() { <del> let (callee, call_substs) = if let Ok(Some(instance)) = Instance::resolve(tcx, param_env, callee, substs) { (instance.def_id(), instance.substs) } else { (callee, substs) }; </del> <ins> let normalized_substs = tcx.normalize_erasing_regions(param_env, substs); let (callee, call_substs) = if let Ok(Some(instance)) = Instance::resolve(tcx, param_env, callee, normalized_substs) { (instance.def_id(), instance.substs) } else { (callee, normalized_substs) }; </ins> // FIXME(#57965): Make this work across function boundaries
impl<T> Drop for InPlaceDrop<T> { #[inline] fn drop(&mut self) { <del> if mem::needs_drop::<T>() { unsafe { ptr::drop_in_place(slice::from_raw_parts_mut(self.inner, self.len())); } </del> <ins> unsafe { ptr::drop_in_place(slice::from_raw_parts_mut(self.inner, self.len())); </ins> } } }
let file = annotated_file.file.clone(); let line = &annotated_file.lines[line_idx]; if let Some(source_string) = file.get_line(line.line_index - 1) { <del> let leading_whitespace = source_string.chars().take_while(|c| c.is_whitespace()).count(); </del> <ins> let leading_whitespace = source_string .chars() .take_while(|c| c.is_whitespace()) .map(|c| { match c { // Tabs are displayed as 4 spaces 't' => 4, _ => 1, } }) .sum(); </ins> if source_string.chars().any(|c| !c.is_whitespace()) { whitespace_margin = min(whitespace_margin, leading_whitespace); }
StyledBuffer { text: vec![], styles: vec![] } } <del> fn replace_tabs(&mut self) { for (line_pos, line) in self.text.iter_mut().enumerate() { let mut tab_pos = vec![]; for (pos, c) in line.iter().enumerate() { if *c == 't' { tab_pos.push(pos); } } // start with the tabs at the end of the line to replace them with 4 space chars for pos in tab_pos.iter().rev() { assert_eq!(line.remove(*pos), 't'); // fix the position of the style to match up after replacing the tabs let s = self.styles[line_pos].remove(*pos); for _ in 0..4 { line.insert(*pos, ' '); self.styles[line_pos].insert(*pos, s); } } } } </del> <ins> pub fn render(&self) -> Vec<Vec<StyledString>> { // Tabs are assumed to have been replaced by spaces in calling code. assert!(self.text.iter().all(|r| !r.contains(&'t'))); </ins> <del> pub fn render(&mut self) -> Vec<Vec<StyledString>> { </del> let mut output: Vec<Vec<StyledString>> = vec![]; let mut styled_vec: Vec<StyledString> = vec![]; <del> // before we render, replace tabs with spaces self.replace_tabs(); </del> for (row, row_style) in self.text.iter().zip(&self.styles) { let mut current_style = Style::NoStyle; let mut current_text = String::new();
<ins> // Test for #78438: ensure underline alignment with many tabs on the left, long line on the right // ignore-tidy-linelength // ignore-tidy-tab fn main() { let money = 42i32; match money { v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT //~^ ERROR variable `v` is not bound in all patterns v => println!("Enough money {}", v), } } </ins>
<ins> error[E0408]: variable `v` is not bound in all patterns --> $DIR/tabs-trimming.rs:9:16 | LL | ...   v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT... |       -       ^   ^ pattern doesn't bind `v` |       |       | |       |       pattern doesn't bind `v` |       variable not in all patterns error: aborting due to previous error For more information about this error, try `rustc --explain E0408`. </ins>
return None; } <ins> // when the second place is a projection of the first one, it's not safe to calculate their discriminant values sequentially. // for example, this should not be optimized: // // ```rust // enum E<'a> { Empty, Some(&'a E<'a>), } // let Some(Some(_)) = e; // ``` // // ```mir // bb0: { //   _2 = discriminant(*_1) //   switchInt(_2) -> [...] // } // bb1: { //   _3 = discriminant(*(((*_1) as Some).0: &E)) //   switchInt(_3) -> [...] // } // ``` let discr_place = discr_info.place_of_adt_discr_read; let this_discr_place = this_bb_discr_info.place_of_adt_discr_read; if discr_place.local == this_discr_place.local && this_discr_place.projection.starts_with(discr_place.projection) { trace!("NO: one target is the projection of another"); return None; } </ins> // if we reach this point, the optimization applies, and we should be able to optimize this case // store the info that is needed to apply the optimization
<ins> // run-pass // compile-flags: -Z mir-opt-level=2 -C opt-level=0 // example from #78496 pub enum E<'a> { Empty, Some(&'a E<'a>), } fn f(e: &E) -> u32 { if let E::Some(E::Some(_)) = e { 1 } else { 2 } } fn main() { assert_eq!(f(&E::Empty), 2); } </ins>
<ins> // check-pass #![feature(type_alias_impl_trait)] pub trait Trait { type A; fn f() -> Self::A; } pub trait Tr2<'a, 'b> {} pub struct A<T>(T); pub trait Tr { type B; } impl<'a, 'b, T: Tr<B = dyn Tr2<'a, 'b>>> Trait for A<T> { type A = impl core::fmt::Debug; fn f() -> Self::A {} } fn main() {} </ins>
&o1(simplify_branches::SimplifyConstCondition::new("after-const-prop")), &early_otherwise_branch::EarlyOtherwiseBranch, &simplify_comparison_integral::SimplifyComparisonIntegral, <del> &simplify_try::SimplifyArmIdentity, &simplify_try::SimplifyBranchSame, </del> &dead_store_elimination::DeadStoreElimination, &dest_prop::DestinationPropagation, &o1(simplify_branches::SimplifyConstCondition::new("final")),
<del> - // MIR for `encode` before SimplifyBranchSame + // MIR for `encode` after SimplifyBranchSame fn encode(_1: Type) -> Type { debug v => _1;                       // in scope 0 at $DIR/76803_regression.rs:+0:15: +0:16 let mut _0: Type;                    // return place in scope 0 at $DIR/76803_regression.rs:+0:27: +0:31 let mut _2: isize;                   // in scope 0 at $DIR/76803_regression.rs:+2:9: +2:16 bb0: { _2 = discriminant(_1);           // scope 0 at $DIR/76803_regression.rs:+1:11: +1:12 switchInt(move _2) -> [0: bb2, otherwise: bb1]; // scope 0 at $DIR/76803_regression.rs:+1:5: +1:12 } bb1: { _0 = move _1;                    // scope 0 at $DIR/76803_regression.rs:+3:14: +3:15 goto -> bb3;                     // scope 0 at $DIR/76803_regression.rs:+3:14: +3:15 } bb2: { Deinit(_0);                      // scope 0 at $DIR/76803_regression.rs:+2:20: +2:27 discriminant(_0) = 1;            // scope 0 at $DIR/76803_regression.rs:+2:20: +2:27 goto -> bb3;                     // scope 0 at $DIR/76803_regression.rs:+2:20: +2:27 } bb3: { return;                          // scope 0 at $DIR/76803_regression.rs:+5:2: +5:2 } } </del>
<del> // compile-flags: -Z mir-opt-level=1 // EMIT_MIR 76803_regression.encode.SimplifyBranchSame.diff #[derive(Debug, Eq, PartialEq)] pub enum Type { A, B, } pub fn encode(v: Type) -> Type { match v { Type::A => Type::B, _ => v, } } fn main() { assert_eq!(Type::B, encode(Type::A)); } </del>
<ins> error[E0627]: yield expression outside of generator literal --> $DIR/yield-outside-generator-issue-78653.rs:4:5 | LL |     yield || for i in 0 { } |     ^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: `{integer}` is not an iterator --> $DIR/yield-outside-generator-issue-78653.rs:4:23 | LL |     yield || for i in 0 { } |                       ^ `{integer}` is not an iterator | = help: the trait `Iterator` is not implemented for `{integer}` = note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end` = note: required because of the requirements on the impl of `IntoIterator` for `{integer}` = note: required by `into_iter` error: aborting due to 2 previous errors Some errors have detailed explanations: E0277, E0627. For more information about an error, try `rustc --explain E0277`. </ins>
) -> PResult<'a, P<Pat>> { // Parse the first pattern (`p_0`). let first_pat = self.parse_pat(expected)?; <del> self.maybe_recover_unexpected_comma(first_pat.span, rc)?; </del> <ins> self.maybe_recover_unexpected_comma(first_pat.span, rc, gate_or)?; </ins> // If the next token is not a `|`, // this is not an or-pattern and we should exit here.
/// Some special error handling for the "top-level" patterns in a match arm, /// `for` loop, `let`, &c. (in contrast to subpatterns within such). <del> fn maybe_recover_unexpected_comma(&mut self, lo: Span, rc: RecoverComma) -> PResult<'a, ()> { </del> <ins> fn maybe_recover_unexpected_comma( &mut self, lo: Span, rc: RecoverComma, gate_or: GateOr, ) -> PResult<'a, ()> { </ins> if rc == RecoverComma::No || self.token != token::Comma { return Ok(()); }
let seq_span = lo.to(self.prev_token.span); let mut err = self.struct_span_err(comma_span, "unexpected `,` in pattern"); if let Ok(seq_snippet) = self.span_to_snippet(seq_span) { <ins> const MSG: &str = "try adding parentheses to match on a tuple..."; let or_suggestion = gate_or == GateOr::No || !self.sess.gated_spans.is_ungated(sym::or_patterns); </ins> err.span_suggestion( seq_span, <del> "try adding parentheses to match on a tuple...", </del> <ins> if or_suggestion { MSG } else { MSG.trim_end_matches('.') }, </ins> format!("({})", seq_snippet), Applicability::MachineApplicable, <del> ) .span_suggestion( seq_span, "...or a vertical bar to match on multiple alternatives", seq_snippet.replace(",", " |"), Applicability::MachineApplicable, </del> ); <ins> if or_suggestion { err.span_suggestion( seq_span, "...or a vertical bar to match on multiple alternatives", seq_snippet.replace(",", " |"), Applicability::MachineApplicable, ); } </ins> } Err(err) }
--> $DIR/issue-48492-tuple-destructure-missing-parens.rs:67:10 | LL |     for x, _barr_body in women.iter().map(|woman| woman.allosomes.clone()) { <del> |          ^ | help: try adding parentheses to match on a tuple... | LL |     for (x, _barr_body) in women.iter().map(|woman| woman.allosomes.clone()) { |         ^^^^^^^^^^^^^^^ help: ...or a vertical bar to match on multiple alternatives | LL |     for x | _barr_body in women.iter().map(|woman| woman.allosomes.clone()) { |         ^^^^^^^^^^^^^^ </del> <ins> |         -^----------- help: try adding parentheses to match on a tuple: `(x, _barr_body)` </ins> error: unexpected `,` in pattern --> $DIR/issue-48492-tuple-destructure-missing-parens.rs:75:10 | LL |     for x, y @ Allosome::Y(_) in men.iter().map(|man| man.allosomes.clone()) { <del> |          ^ | help: try adding parentheses to match on a tuple... | LL |     for (x, y @ Allosome::Y(_)) in men.iter().map(|man| man.allosomes.clone()) { |         ^^^^^^^^^^^^^^^^^^^^^^^ help: ...or a vertical bar to match on multiple alternatives | LL |     for x | y @ Allosome::Y(_) in men.iter().map(|man| man.allosomes.clone()) { |         ^^^^^^^^^^^^^^^^^^^^^^ </del> <ins> |         -^------------------- help: try adding parentheses to match on a tuple: `(x, y @ Allosome::Y(_))` </ins> error: unexpected `,` in pattern --> $DIR/issue-48492-tuple-destructure-missing-parens.rs:84:14 | LL |     let women, men: (Vec<Genome>, Vec<Genome>) = genomes.iter().cloned() <del> |              ^ | help: try adding parentheses to match on a tuple... | LL |     let (women, men): (Vec<Genome>, Vec<Genome>) = genomes.iter().cloned() |         ^^^^^^^^^^^^ help: ...or a vertical bar to match on multiple alternatives | LL |     let women | men: (Vec<Genome>, Vec<Genome>) = genomes.iter().cloned() |         ^^^^^^^^^^^ </del> <ins> |         -----^---- help: try adding parentheses to match on a tuple: `(women, men)` </ins> error: aborting due to 6 previous errors
Ok(true) } ty::Float(_) | ty::Int(_) | ty::Uint(_) => { <del> let value = self.ecx.read_scalar(value)?; </del> <ins> let value = try_validation!( self.ecx.read_scalar(value), self.path, err_unsup!(ReadPointerAsBytes) => { "read of part of a pointer" }, ); </ins> // NOTE: Keep this in sync with the array optimization for int/float // types below! if self.ctfe_mode.is_some() {
<ins> // ignore-32bit // This test gives a different error on 32-bit architectures. union Transmute<T: Copy, U: Copy> { t: T, u: U, } trait Bar { fn bar(&self) -> u32; } struct Foo { foo: u32, bar: bool, } impl Bar for Foo { fn bar(&self) -> u32 { self.foo } } #[derive(Copy, Clone)] struct Fat<'a>(&'a Foo, &'static VTable); struct VTable { size: Foo, } const FOO: &dyn Bar = &Foo { foo: 128, bar: false, }; const G: Fat = unsafe { Transmute { t: FOO }.u }; //~^ ERROR it is undefined behavior to use this value fn main() {} </ins>
<ins> error[E0080]: it is undefined behavior to use this value --> $DIR/issue-79690.rs:29:1 | LL | const G: Fat = unsafe { Transmute { t: FOO }.u }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered read of part of a pointer at .1.<deref>.size.foo | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. error: aborting due to previous error For more information about this error, try `rustc --explain E0080`. </ins>
value: OpTy<'tcx, M::PointerTag>, kind: &str, ) -> InterpResult<'tcx> { <del> let value = self.ecx.read_immediate(value)?; </del> <ins> let value = try_validation!( self.ecx.read_immediate(value), self.path, err_unsup!(ReadPointerAsBytes) => { "part of a pointer" } expected { "a proper pointer or integer value" }, ); </ins> // Handle wide pointers. // Check metadata early, for better diagnostics let place = try_validation!(
Ok(()) } <ins> fn read_scalar( &self, op: OpTy<'tcx, M::PointerTag>, ) -> InterpResult<'tcx, ScalarMaybeUninit<M::PointerTag>> { Ok(try_validation!( self.ecx.read_scalar(op), self.path, err_unsup!(ReadPointerAsBytes) => { "(potentially part of) a pointer" } expected { "plain (non-pointer) bytes" }, )) } </ins> /// Check if this is a value of primitive type, and if yes check the validity of the value /// at that type.  Return `true` if the type is indeed primitive. fn try_visit_primitive(
Ok(true) } ty::Float(_) | ty::Int(_) | ty::Uint(_) => { <del> let value = try_validation!( self.ecx.read_scalar(value), self.path, err_unsup!(ReadPointerAsBytes) => { "read of part of a pointer" }, ); </del> <ins> let value = self.read_scalar(value)?; </ins> // NOTE: Keep this in sync with the array optimization for int/float // types below! if self.ctfe_mode.is_some() {
// actually enforce the strict rules for raw pointers (mostly because // that lets us re-use `ref_to_mplace`). let place = try_validation!( <del> self.ecx.ref_to_mplace(self.ecx.read_immediate(value)?), </del> <ins> self.ecx.read_immediate(value).and_then(|i| self.ecx.ref_to_mplace(i)), </ins> self.path, err_ub!(InvalidUninitBytes(None)) => { "uninitialized raw pointer" }, <ins> err_unsup!(ReadPointerAsBytes) => { "part of a pointer" } expected { "a proper pointer or integer value" }, </ins> ); if place.layout.is_unsized() { self.check_wide_ptr_meta(place.meta, place.layout)?;
Ok(true) } ty::FnPtr(_sig) => { <del> let value = self.ecx.read_scalar(value)?; </del> <ins> let value = try_validation!( self.ecx.read_immediate(value), self.path, err_unsup!(ReadPointerAsBytes) => { "part of a pointer" } expected { "a proper pointer or integer value" }, ); </ins> let _fn = try_validation!( <del> value.check_init().and_then(|ptr| self.ecx.memory.get_fn(ptr)), </del> <ins> value.to_scalar().and_then(|ptr| self.ecx.memory.get_fn(ptr)), </ins> self.path, err_ub!(DanglingIntPointer(..)) | err_ub!(InvalidFunctionPointer(..)) |
op: OpTy<'tcx, M::PointerTag>, scalar_layout: &Scalar, ) -> InterpResult<'tcx> { <del> let value = self.ecx.read_scalar(op)?; </del> <ins> let value = self.read_scalar(op)?; </ins> let valid_range = &scalar_layout.valid_range; let (lo, hi) = valid_range.clone().into_inner(); // Determine the allowed range
--> $DIR/issue-79690.rs:29:1 | LL | const G: Fat = unsafe { Transmute { t: FOO }.u }; <del> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered read of part of a pointer at .1.<deref>.size.foo </del> <ins> | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered (potentially part of) a pointer at .1.<deref>.size.foo, but expected plain (non-pointer) bytes </ins> | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
CodeBlockKind::Fenced(ref lang) => { LangString::parse_without_check(&lang, self.check_error_codes, false) } <del> CodeBlockKind::Indented => LangString::all_false(), </del> <ins> CodeBlockKind::Indented => Default::default(), </ins> }; if !parse_result.rust { return Some(Event::Start(Tag::CodeBlock(kind)));
Some(Vec<String>), } <del> impl LangString { fn all_false() -> LangString { LangString { </del> <ins> impl Default for LangString { fn default() -> Self { Self { </ins> original: String::new(), should_panic: false, no_run: false, ignore: Ignore::None, <del> rust: true, // NB This used to be `notrust = false` </del> <ins> rust: true, </ins> test_harness: false, compile_fail: false, error_codes: Vec::new(),