diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index e4ed48d4b530..e7e82e651bb0 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -2068,7 +2068,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { hir::GenericParam { hir_id, name, - span: self.lower_span(param.ident.span), + span: self.lower_span(param.span()), pure_wrt_drop: self.sess.contains_name(¶m.attrs, sym::may_dangle), bounds: self.arena.alloc_from_iter(bounds), kind, diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index aa2ddada3502..b945d687043b 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -772,14 +772,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { Some((issued_span, span)), ); - self.suggest_using_local_if_applicable( - &mut err, - location, - (place, span), - gen_borrow_kind, - issued_borrow, - explanation, - ); + self.suggest_using_local_if_applicable(&mut err, location, issued_borrow, explanation); err } @@ -789,8 +782,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { &self, err: &mut Diagnostic, location: Location, - (place, span): (Place<'tcx>, Span), - gen_borrow_kind: BorrowKind, issued_borrow: &BorrowData<'tcx>, explanation: BorrowExplanation, ) { @@ -822,7 +813,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { return; }; let inner_param_uses = find_all_local_uses::find(self.body, inner_param.local); - let Some((inner_call_loc,inner_call_term)) = inner_param_uses.into_iter().find_map(|loc| { + let Some((inner_call_loc, inner_call_term)) = inner_param_uses.into_iter().find_map(|loc| { let Either::Right(term) = self.body.stmt_at(loc) else { debug!("{:?} is a statement, so it can't be a call", loc); return None; @@ -833,7 +824,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { }; debug!("checking call args for uses of inner_param: {:?}", args); if args.contains(&Operand::Move(inner_param)) { - Some((loc,term)) + Some((loc, term)) } else { None } diff --git a/compiler/rustc_codegen_cranelift/src/common.rs b/compiler/rustc_codegen_cranelift/src/common.rs index 89fd0bfa8bbf..ffa629ca16c8 100644 --- a/compiler/rustc_codegen_cranelift/src/common.rs +++ b/compiler/rustc_codegen_cranelift/src/common.rs @@ -21,7 +21,7 @@ pub(crate) fn pointer_ty(tcx: TyCtxt<'_>) -> types::Type { } pub(crate) fn scalar_to_clif_type(tcx: TyCtxt<'_>, scalar: Scalar) -> Type { - match scalar.value { + match scalar.primitive() { Primitive::Int(int, _sign) => match int { Integer::I8 => types::I8, Integer::I16 => types::I16, diff --git a/compiler/rustc_codegen_cranelift/src/discriminant.rs b/compiler/rustc_codegen_cranelift/src/discriminant.rs index 6b2893fdaeb2..357cb4a6d246 100644 --- a/compiler/rustc_codegen_cranelift/src/discriminant.rs +++ b/compiler/rustc_codegen_cranelift/src/discriminant.rs @@ -105,7 +105,7 @@ pub(crate) fn codegen_get_discriminant<'tcx>( // Decode the discriminant (specifically if it's niche-encoded). match *tag_encoding { TagEncoding::Direct => { - let signed = match tag_scalar.value { + let signed = match tag_scalar.primitive() { Int(_, signed) => signed, _ => false, }; diff --git a/compiler/rustc_codegen_cranelift/src/value_and_place.rs b/compiler/rustc_codegen_cranelift/src/value_and_place.rs index afe8797a0300..8f80b02ae0d4 100644 --- a/compiler/rustc_codegen_cranelift/src/value_and_place.rs +++ b/compiler/rustc_codegen_cranelift/src/value_and_place.rs @@ -50,7 +50,7 @@ fn codegen_field<'tcx>( } fn scalar_pair_calculate_b_offset(tcx: TyCtxt<'_>, a_scalar: Scalar, b_scalar: Scalar) -> Offset32 { - let b_offset = a_scalar.value.size(&tcx).align_to(b_scalar.value.align(&tcx).abi); + let b_offset = a_scalar.size(&tcx).align_to(b_scalar.align(&tcx).abi); Offset32::new(b_offset.bytes().try_into().unwrap()) } diff --git a/compiler/rustc_codegen_gcc/src/builder.rs b/compiler/rustc_codegen_gcc/src/builder.rs index 21c7d420b204..41f88f119e2a 100644 --- a/compiler/rustc_codegen_gcc/src/builder.rs +++ b/compiler/rustc_codegen_gcc/src/builder.rs @@ -694,11 +694,11 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { } fn scalar_load_metadata<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>, load: RValue<'gcc>, scalar: &abi::Scalar) { - let vr = scalar.valid_range.clone(); - match scalar.value { + let vr = scalar.valid_range(bx); + match scalar.primitive() { abi::Int(..) => { if !scalar.is_always_valid(bx) { - bx.range_metadata(load, scalar.valid_range); + bx.range_metadata(load, vr); } } abi::Pointer if vr.start < vr.end && !vr.contains(0) => { @@ -720,7 +720,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { OperandValue::Immediate(self.to_immediate(load, place.layout)) } else if let abi::Abi::ScalarPair(ref a, ref b) = place.layout.abi { - let b_offset = a.value.size(self).align_to(b.value.align(self).abi); + let b_offset = a.size(self).align_to(b.align(self).abi); let pair_type = place.layout.gcc_type(self, false); let mut load = |i, scalar: &abi::Scalar, align| { diff --git a/compiler/rustc_codegen_gcc/src/common.rs b/compiler/rustc_codegen_gcc/src/common.rs index 19127c7612d8..b056b6d47304 100644 --- a/compiler/rustc_codegen_gcc/src/common.rs +++ b/compiler/rustc_codegen_gcc/src/common.rs @@ -158,14 +158,14 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> { } fn scalar_to_backend(&self, cv: Scalar, layout: abi::Scalar, ty: Type<'gcc>) -> RValue<'gcc> { - let bitsize = if layout.is_bool() { 1 } else { layout.value.size(self).bits() }; + let bitsize = if layout.is_bool() { 1 } else { layout.size(self).bits() }; match cv { Scalar::Int(ScalarInt::ZST) => { - assert_eq!(0, layout.value.size(self).bytes()); + assert_eq!(0, layout.size(self).bytes()); self.const_undef(self.type_ix(0)) } Scalar::Int(int) => { - let data = int.assert_bits(layout.value.size(self)); + let data = int.assert_bits(layout.size(self)); // FIXME(antoyo): there's some issues with using the u128 code that follows, so hard-code // the paths for floating-point values. @@ -209,7 +209,7 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> { let base_addr = self.const_bitcast(base_addr, self.usize_type); let offset = self.context.new_rvalue_from_long(self.usize_type, offset.bytes() as i64); let ptr = self.const_bitcast(base_addr + offset, ptr_type); - if layout.value != Pointer { + if layout.primitive() != Pointer { self.const_bitcast(ptr.dereference(None).to_rvalue(), ty) } else { diff --git a/compiler/rustc_codegen_gcc/src/consts.rs b/compiler/rustc_codegen_gcc/src/consts.rs index de52f3ea2255..3dc456f1aa0e 100644 --- a/compiler/rustc_codegen_gcc/src/consts.rs +++ b/compiler/rustc_codegen_gcc/src/consts.rs @@ -328,7 +328,7 @@ pub fn const_alloc_to_gcc<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, alloc: ConstAl interpret::Pointer::new(alloc_id, Size::from_bytes(ptr_offset)), &cx.tcx, ), - abi::Scalar { value: Primitive::Pointer, valid_range: WrappingRange { start: 0, end: !0 } }, + abi::Scalar::Initialized { value: Primitive::Pointer, valid_range: WrappingRange::full(dl.pointer_size) }, cx.type_i8p(), )); next_offset = offset + pointer_size; diff --git a/compiler/rustc_codegen_gcc/src/type_of.rs b/compiler/rustc_codegen_gcc/src/type_of.rs index ed8f0445ca3e..2c042ba4e3a9 100644 --- a/compiler/rustc_codegen_gcc/src/type_of.rs +++ b/compiler/rustc_codegen_gcc/src/type_of.rs @@ -224,7 +224,7 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> { } fn scalar_gcc_type_at<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>, scalar: &abi::Scalar, offset: Size) -> Type<'gcc> { - match scalar.value { + match scalar.primitive() { Int(i, true) => cx.type_from_integer(i), Int(i, false) => cx.type_from_unsigned_integer(i), F32 => cx.type_f32(), @@ -282,7 +282,7 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> { Size::ZERO } else { - a.value.size(cx).align_to(b.value.align(cx).abi) + a.size(cx).align_to(b.align(cx).abi) }; self.scalar_gcc_type_at(cx, scalar, offset) } diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index b14a4f28c756..b9baa87bac7c 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -510,9 +510,9 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> { // If the value is a boolean, the range is 0..2 and that ultimately // become 0..0 when the type becomes i1, which would be rejected // by the LLVM verifier. - if let Int(..) = scalar.value { + if let Int(..) = scalar.primitive() { if !scalar.is_bool() && !scalar.is_always_valid(bx) { - bx.range_metadata(callsite, scalar.valid_range); + bx.range_metadata(callsite, scalar.valid_range(bx)); } } } diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index 96c7d884b7b2..03c390b4bd42 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -753,7 +753,7 @@ fn dummy_output_type<'ll>(cx: &CodegenCx<'ll, '_>, reg: InlineAsmRegClass) -> &' /// Helper function to get the LLVM type for a Scalar. Pointers are returned as /// the equivalent integer type. fn llvm_asm_scalar_type<'ll>(cx: &CodegenCx<'ll, '_>, scalar: Scalar) -> &'ll Type { - match scalar.value { + match scalar.primitive() { Primitive::Int(Integer::I8, _) => cx.type_i8(), Primitive::Int(Integer::I16, _) => cx.type_i16(), Primitive::Int(Integer::I32, _) => cx.type_i32(), @@ -774,7 +774,7 @@ fn llvm_fixup_input<'ll, 'tcx>( ) -> &'ll Value { match (reg, layout.abi) { (InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg), Abi::Scalar(s)) => { - if let Primitive::Int(Integer::I8, _) = s.value { + if let Primitive::Int(Integer::I8, _) = s.primitive() { let vec_ty = bx.cx.type_vector(bx.cx.type_i8(), 8); bx.insert_element(bx.const_undef(vec_ty), value, bx.const_i32(0)) } else { @@ -785,7 +785,7 @@ fn llvm_fixup_input<'ll, 'tcx>( let elem_ty = llvm_asm_scalar_type(bx.cx, s); let count = 16 / layout.size.bytes(); let vec_ty = bx.cx.type_vector(elem_ty, count); - if let Primitive::Pointer = s.value { + if let Primitive::Pointer = s.primitive() { value = bx.ptrtoint(value, bx.cx.type_isize()); } bx.insert_element(bx.const_undef(vec_ty), value, bx.const_i32(0)) @@ -800,7 +800,7 @@ fn llvm_fixup_input<'ll, 'tcx>( bx.shuffle_vector(value, bx.const_undef(vec_ty), bx.const_vector(&indices)) } (InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd), Abi::Scalar(s)) - if s.value == Primitive::F64 => + if s.primitive() == Primitive::F64 => { bx.bitcast(value, bx.cx.type_i64()) } @@ -812,7 +812,7 @@ fn llvm_fixup_input<'ll, 'tcx>( InlineAsmRegClass::Arm(ArmInlineAsmRegClass::sreg | ArmInlineAsmRegClass::sreg_low16), Abi::Scalar(s), ) => { - if let Primitive::Int(Integer::I32, _) = s.value { + if let Primitive::Int(Integer::I32, _) = s.primitive() { bx.bitcast(value, bx.cx.type_f32()) } else { value @@ -826,19 +826,21 @@ fn llvm_fixup_input<'ll, 'tcx>( ), Abi::Scalar(s), ) => { - if let Primitive::Int(Integer::I64, _) = s.value { + if let Primitive::Int(Integer::I64, _) = s.primitive() { bx.bitcast(value, bx.cx.type_f64()) } else { value } } - (InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg), Abi::Scalar(s)) => match s.value { - // MIPS only supports register-length arithmetics. - Primitive::Int(Integer::I8 | Integer::I16, _) => bx.zext(value, bx.cx.type_i32()), - Primitive::F32 => bx.bitcast(value, bx.cx.type_i32()), - Primitive::F64 => bx.bitcast(value, bx.cx.type_i64()), - _ => value, - }, + (InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg), Abi::Scalar(s)) => { + match s.primitive() { + // MIPS only supports register-length arithmetics. + Primitive::Int(Integer::I8 | Integer::I16, _) => bx.zext(value, bx.cx.type_i32()), + Primitive::F32 => bx.bitcast(value, bx.cx.type_i32()), + Primitive::F64 => bx.bitcast(value, bx.cx.type_i64()), + _ => value, + } + } _ => value, } } @@ -852,7 +854,7 @@ fn llvm_fixup_output<'ll, 'tcx>( ) -> &'ll Value { match (reg, layout.abi) { (InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg), Abi::Scalar(s)) => { - if let Primitive::Int(Integer::I8, _) = s.value { + if let Primitive::Int(Integer::I8, _) = s.primitive() { bx.extract_element(value, bx.const_i32(0)) } else { value @@ -860,7 +862,7 @@ fn llvm_fixup_output<'ll, 'tcx>( } (InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg_low16), Abi::Scalar(s)) => { value = bx.extract_element(value, bx.const_i32(0)); - if let Primitive::Pointer = s.value { + if let Primitive::Pointer = s.primitive() { value = bx.inttoptr(value, layout.llvm_type(bx.cx)); } value @@ -875,7 +877,7 @@ fn llvm_fixup_output<'ll, 'tcx>( bx.shuffle_vector(value, bx.const_undef(vec_ty), bx.const_vector(&indices)) } (InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd), Abi::Scalar(s)) - if s.value == Primitive::F64 => + if s.primitive() == Primitive::F64 => { bx.bitcast(value, bx.cx.type_f64()) } @@ -887,7 +889,7 @@ fn llvm_fixup_output<'ll, 'tcx>( InlineAsmRegClass::Arm(ArmInlineAsmRegClass::sreg | ArmInlineAsmRegClass::sreg_low16), Abi::Scalar(s), ) => { - if let Primitive::Int(Integer::I32, _) = s.value { + if let Primitive::Int(Integer::I32, _) = s.primitive() { bx.bitcast(value, bx.cx.type_i32()) } else { value @@ -901,20 +903,22 @@ fn llvm_fixup_output<'ll, 'tcx>( ), Abi::Scalar(s), ) => { - if let Primitive::Int(Integer::I64, _) = s.value { + if let Primitive::Int(Integer::I64, _) = s.primitive() { bx.bitcast(value, bx.cx.type_i64()) } else { value } } - (InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg), Abi::Scalar(s)) => match s.value { - // MIPS only supports register-length arithmetics. - Primitive::Int(Integer::I8, _) => bx.trunc(value, bx.cx.type_i8()), - Primitive::Int(Integer::I16, _) => bx.trunc(value, bx.cx.type_i16()), - Primitive::F32 => bx.bitcast(value, bx.cx.type_f32()), - Primitive::F64 => bx.bitcast(value, bx.cx.type_f64()), - _ => value, - }, + (InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg), Abi::Scalar(s)) => { + match s.primitive() { + // MIPS only supports register-length arithmetics. + Primitive::Int(Integer::I8, _) => bx.trunc(value, bx.cx.type_i8()), + Primitive::Int(Integer::I16, _) => bx.trunc(value, bx.cx.type_i16()), + Primitive::F32 => bx.bitcast(value, bx.cx.type_f32()), + Primitive::F64 => bx.bitcast(value, bx.cx.type_f64()), + _ => value, + } + } _ => value, } } @@ -927,7 +931,7 @@ fn llvm_fixup_output_type<'ll, 'tcx>( ) -> &'ll Type { match (reg, layout.abi) { (InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg), Abi::Scalar(s)) => { - if let Primitive::Int(Integer::I8, _) = s.value { + if let Primitive::Int(Integer::I8, _) = s.primitive() { cx.type_vector(cx.type_i8(), 8) } else { layout.llvm_type(cx) @@ -946,7 +950,7 @@ fn llvm_fixup_output_type<'ll, 'tcx>( cx.type_vector(elem_ty, count * 2) } (InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd), Abi::Scalar(s)) - if s.value == Primitive::F64 => + if s.primitive() == Primitive::F64 => { cx.type_i64() } @@ -958,7 +962,7 @@ fn llvm_fixup_output_type<'ll, 'tcx>( InlineAsmRegClass::Arm(ArmInlineAsmRegClass::sreg | ArmInlineAsmRegClass::sreg_low16), Abi::Scalar(s), ) => { - if let Primitive::Int(Integer::I32, _) = s.value { + if let Primitive::Int(Integer::I32, _) = s.primitive() { cx.type_f32() } else { layout.llvm_type(cx) @@ -972,19 +976,21 @@ fn llvm_fixup_output_type<'ll, 'tcx>( ), Abi::Scalar(s), ) => { - if let Primitive::Int(Integer::I64, _) = s.value { + if let Primitive::Int(Integer::I64, _) = s.primitive() { cx.type_f64() } else { layout.llvm_type(cx) } } - (InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg), Abi::Scalar(s)) => match s.value { - // MIPS only supports register-length arithmetics. - Primitive::Int(Integer::I8 | Integer::I16, _) => cx.type_i32(), - Primitive::F32 => cx.type_i32(), - Primitive::F64 => cx.type_i64(), - _ => layout.llvm_type(cx), - }, + (InlineAsmRegClass::Mips(MipsInlineAsmRegClass::reg), Abi::Scalar(s)) => { + match s.primitive() { + // MIPS only supports register-length arithmetics. + Primitive::Int(Integer::I8 | Integer::I16, _) => cx.type_i32(), + Primitive::F32 => cx.type_i32(), + Primitive::F64 => cx.type_i64(), + _ => layout.llvm_type(cx), + } + } _ => layout.llvm_type(cx), } } diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 1bbfc13e05e7..88b87951ecd3 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -484,14 +484,14 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { bx.noundef_metadata(load); } - match scalar.value { + match scalar.primitive() { abi::Int(..) => { if !scalar.is_always_valid(bx) { - bx.range_metadata(load, scalar.valid_range); + bx.range_metadata(load, scalar.valid_range(bx)); } } abi::Pointer => { - if !scalar.valid_range.contains(0) { + if !scalar.valid_range(bx).contains(0) { bx.nonnull_metadata(load); } @@ -525,7 +525,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { }); OperandValue::Immediate(self.to_immediate(llval, place.layout)) } else if let abi::Abi::ScalarPair(a, b) = place.layout.abi { - let b_offset = a.value.size(self).align_to(b.value.align(self).abi); + let b_offset = a.size(self).align_to(b.align(self).abi); let pair_ty = place.layout.llvm_type(self); let mut load = |i, scalar: abi::Scalar, layout, align, offset| { diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index a85b2e6141b5..b69d7a000ee9 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -221,16 +221,16 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { } fn scalar_to_backend(&self, cv: Scalar, layout: abi::Scalar, llty: &'ll Type) -> &'ll Value { - let bitsize = if layout.is_bool() { 1 } else { layout.value.size(self).bits() }; + let bitsize = if layout.is_bool() { 1 } else { layout.size(self).bits() }; match cv { Scalar::Int(ScalarInt::ZST) => { - assert_eq!(0, layout.value.size(self).bytes()); + assert_eq!(0, layout.size(self).bytes()); self.const_undef(self.type_ix(0)) } Scalar::Int(int) => { - let data = int.assert_bits(layout.value.size(self)); + let data = int.assert_bits(layout.size(self)); let llval = self.const_uint_big(self.type_ix(bitsize), data); - if layout.value == Pointer { + if layout.primitive() == Pointer { unsafe { llvm::LLVMConstIntToPtr(llval, llty) } } else { self.const_bitcast(llval, llty) @@ -269,7 +269,7 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { 1, ) }; - if layout.value != Pointer { + if layout.primitive() != Pointer { unsafe { llvm::LLVMConstPtrToInt(llval, llty) } } else { self.const_bitcast(llval, llty) diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index 413ef0ba7646..cb4073528e10 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -109,7 +109,10 @@ pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: ConstAllocation< Pointer::new(alloc_id, Size::from_bytes(ptr_offset)), &cx.tcx, ), - Scalar { value: Primitive::Pointer, valid_range: WrappingRange { start: 0, end: !0 } }, + Scalar::Initialized { + value: Primitive::Pointer, + valid_range: WrappingRange::full(dl.pointer_size), + }, cx.type_i8p_ext(address_space), )); next_offset = offset + pointer_size; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs index 1eafa9501c47..73e01d0453b2 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -118,7 +118,7 @@ fn tag_base_type<'ll, 'tcx>( Variants::Multiple { tag_encoding: TagEncoding::Niche { .. }, tag, .. } => { // Niche tags are always normalized to unsized integers of the correct size. - match tag.value { + match tag.primitive() { Primitive::Int(t, _) => t, Primitive::F32 => Integer::I32, Primitive::F64 => Integer::I64, @@ -136,7 +136,7 @@ fn tag_base_type<'ll, 'tcx>( Variants::Multiple { tag_encoding: TagEncoding::Direct, tag, .. } => { // Direct tags preserve the sign. - tag.value.to_ty(cx.tcx) + tag.primitive().to_ty(cx.tcx) } } } @@ -425,7 +425,7 @@ fn compute_discriminant_value<'ll, 'tcx>( let value = (variant_index.as_u32() as u128) .wrapping_sub(niche_variants.start().as_u32() as u128) .wrapping_add(niche_start); - let value = tag.value.size(cx).truncate(value); + let value = tag.size(cx).truncate(value); // NOTE(eddyb) do *NOT* remove this assert, until // we pass the full 128-bit value to LLVM, otherwise // truncation will be silent and remain undetected. diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index f4dc33452d15..48840c76cac8 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -134,7 +134,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> { sym::va_arg => { match fn_abi.ret.layout.abi { abi::Abi::Scalar(scalar) => { - match scalar.value { + match scalar.primitive() { Primitive::Int(..) => { if self.cx().size_of(ret_ty).bytes() < 4 { // `va_arg` should not be called on an integer type diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs index 757aa9a10116..862805236311 100644 --- a/compiler/rustc_codegen_llvm/src/type_of.rs +++ b/compiler/rustc_codegen_llvm/src/type_of.rs @@ -309,7 +309,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { scalar: Scalar, offset: Size, ) -> &'a Type { - match scalar.value { + match scalar.primitive() { Int(i, _) => cx.type_from_integer(i), F32 => cx.type_f32(), F64 => cx.type_f64(), @@ -362,8 +362,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> { return cx.type_i1(); } - let offset = - if index == 0 { Size::ZERO } else { a.value.size(cx).align_to(b.value.align(cx).abi) }; + let offset = if index == 0 { Size::ZERO } else { a.size(cx).align_to(b.align(cx).abi) }; self.scalar_llvm_type_at(cx, scalar, offset) } diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index ffc8f55bc0cb..369ca950e87b 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -464,13 +464,13 @@ fn push_debuginfo_type_name<'tcx>( // calculate the range of values for the dataful variant let dataful_discriminant_range = - dataful_variant_layout.largest_niche().unwrap().scalar.valid_range; + dataful_variant_layout.largest_niche().unwrap().valid_range; let min = dataful_discriminant_range.start; - let min = tag.value.size(&tcx).truncate(min); + let min = tag.size(&tcx).truncate(min); let max = dataful_discriminant_range.end; - let max = tag.value.size(&tcx).truncate(max); + let max = tag.size(&tcx).truncate(max); let dataful_variant_name = variant_name(*dataful_variant); write!(output, ", {}, {}, {}", min, max, dataful_variant_name).unwrap(); diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index a87daa8d6b80..b7d760bfbabe 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -1572,7 +1572,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { match (src.layout.abi, dst.layout.abi) { (abi::Abi::Scalar(src_scalar), abi::Abi::Scalar(dst_scalar)) => { // HACK(eddyb) LLVM doesn't like `bitcast`s between pointers and non-pointers. - if (src_scalar.value == abi::Pointer) == (dst_scalar.value == abi::Pointer) { + if (src_scalar.primitive() == abi::Pointer) + == (dst_scalar.primitive() == abi::Pointer) + { assert_eq!(src.layout.size, dst.layout.size); // NOTE(eddyb) the `from_immediate` and `to_immediate_scalar` diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index 858f71ebc393..08be4c0a7b62 100644 --- a/compiler/rustc_codegen_ssa/src/mir/operand.rs +++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs @@ -207,11 +207,11 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> { // Extract a scalar component from a pair. (OperandValue::Pair(a_llval, b_llval), Abi::ScalarPair(a, b)) => { if offset.bytes() == 0 { - assert_eq!(field.size, a.value.size(bx.cx())); + assert_eq!(field.size, a.size(bx.cx())); OperandValue::Immediate(a_llval) } else { - assert_eq!(offset, a.value.size(bx.cx()).align_to(b.value.align(bx.cx()).abi)); - assert_eq!(field.size, b.value.size(bx.cx())); + assert_eq!(offset, a.size(bx.cx()).align_to(b.align(bx.cx()).abi)); + assert_eq!(field.size, b.size(bx.cx())); OperandValue::Immediate(b_llval) } } @@ -316,7 +316,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue { bug!("store_with_flags: invalid ScalarPair layout: {:#?}", dest.layout); }; let ty = bx.backend_type(dest.layout); - let b_offset = a_scalar.value.size(bx).align_to(b_scalar.value.align(bx).abi); + let b_offset = a_scalar.size(bx).align_to(b_scalar.align(bx).abi); let llptr = bx.struct_gep(ty, dest.llval, 0); let val = bx.from_immediate(a); diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index 17cfb6c5dfb5..cf69c8fd8fda 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -100,7 +100,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { self.llval } Abi::ScalarPair(a, b) - if offset == a.value.size(bx.cx()).align_to(b.value.align(bx.cx()).abi) => + if offset == a.size(bx.cx()).align_to(b.align(bx.cx()).abi) => { // Offset matches second field. let ty = bx.backend_type(self.layout); @@ -234,7 +234,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { // Decode the discriminant (specifically if it's niche-encoded). match *tag_encoding { TagEncoding::Direct => { - let signed = match tag_scalar.value { + let signed = match tag_scalar.primitive() { // We use `i1` for bytes that are always `0` or `1`, // e.g., `#[repr(i8)] enum E { A, B }`, but we can't // let LLVM interpret the `i1` as signed, because diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 68decce82ab5..fd29c9e281b9 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -299,7 +299,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let mut signed = false; if let Abi::Scalar(scalar) = operand.layout.abi { - if let Int(_, s) = scalar.value { + if let Int(_, s) = scalar.primitive() { // We use `i1` for bytes that are always `0` or `1`, // e.g., `#[repr(i8)] enum E { A, B }`, but we can't // let LLVM interpret the `i1` as signed, because @@ -307,15 +307,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { signed = !scalar.is_bool() && s; if !scalar.is_always_valid(bx.cx()) - && scalar.valid_range.end >= scalar.valid_range.start + && scalar.valid_range(bx.cx()).end + >= scalar.valid_range(bx.cx()).start { // We want `table[e as usize ± k]` to not // have bound checks, and this is the most // convenient place to put the `assume`s. - if scalar.valid_range.start > 0 { - let enum_value_lower_bound = bx - .cx() - .const_uint_big(ll_t_in, scalar.valid_range.start); + if scalar.valid_range(bx.cx()).start > 0 { + let enum_value_lower_bound = bx.cx().const_uint_big( + ll_t_in, + scalar.valid_range(bx.cx()).start, + ); let cmp_start = bx.icmp( IntPredicate::IntUGE, llval, @@ -324,8 +326,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { bx.assume(cmp_start); } - let enum_value_upper_bound = - bx.cx().const_uint_big(ll_t_in, scalar.valid_range.end); + let enum_value_upper_bound = bx + .cx() + .const_uint_big(ll_t_in, scalar.valid_range(bx.cx()).end); let cmp_end = bx.icmp( IntPredicate::IntULE, llval, diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index b81a4bfe149d..b856d1708abc 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -15,7 +15,7 @@ use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{self, subst::Subst, TyCtxt}; use rustc_span::source_map::Span; -use rustc_target::abi::Abi; +use rustc_target::abi::{self, Abi}; use std::borrow::Cow; use std::convert::TryInto; @@ -118,7 +118,7 @@ pub(super) fn op_to_const<'tcx>( // the usual cases of extracting e.g. a `usize`, without there being a real use case for the // `Undef` situation. let try_as_immediate = match op.layout.abi { - Abi::Scalar(..) => true, + Abi::Scalar(abi::Scalar::Initialized { .. }) => true, Abi::ScalarPair(..) => match op.layout.ty.kind() { ty::Ref(_, inner, _) => match *inner.kind() { ty::Slice(elem) => elem == ecx.tcx.types.u8, diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index a956a478cef9..3cc237faf695 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -188,7 +188,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let val = self.read_scalar(&args[0])?.check_init()?; let bits = val.to_bits(layout_of.size)?; let kind = match layout_of.abi { - Abi::Scalar(scalar) => scalar.value, + Abi::Scalar(scalar) => scalar.primitive(), _ => span_bug!( self.cur_span(), "{} called on invalid type {:?}", diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 3012f763b80c..ee1ba6082931 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -10,7 +10,7 @@ use rustc_middle::ty::layout::{LayoutOf, PrimitiveExt, TyAndLayout}; use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Printer}; use rustc_middle::ty::{ConstInt, DelaySpanBugEmitted, Ty}; use rustc_middle::{mir, ty}; -use rustc_target::abi::{Abi, HasDataLayout, Size, TagEncoding}; +use rustc_target::abi::{self, Abi, HasDataLayout, Size, TagEncoding}; use rustc_target::abi::{VariantIdx, Variants}; use super::{ @@ -265,16 +265,24 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { })); }; + // It may seem like all types with `Scalar` or `ScalarPair` ABI are fair game at this point. + // However, `MaybeUninit` is considered a `Scalar` as far as its layout is concerned -- + // and yet cannot be represented by an interpreter `Scalar`, since we have to handle the + // case where some of the bytes are initialized and others are not. So, we need an extra + // check that walks over the type of `mplace` to make sure it is truly correct to treat this + // like a `Scalar` (or `ScalarPair`). match mplace.layout.abi { - Abi::Scalar(..) => { + Abi::Scalar(abi::Scalar::Initialized { .. }) => { let scalar = alloc.read_scalar(alloc_range(Size::ZERO, mplace.layout.size))?; Ok(Some(ImmTy { imm: scalar.into(), layout: mplace.layout })) } - Abi::ScalarPair(a, b) => { + Abi::ScalarPair( + abi::Scalar::Initialized { value: a, .. }, + abi::Scalar::Initialized { value: b, .. }, + ) => { // We checked `ptr_align` above, so all fields will have the alignment they need. // We would anyway check against `ptr_align.restrict_for_offset(b_offset)`, // which `ptr.offset(b_offset)` cannot possibly fail to satisfy. - let (a, b) = (a.value, b.value); let (a_size, b_size) = (a.size(self), b.size(self)); let b_offset = a_size.align_to(b.align(self).abi); assert!(b_offset.bytes() > 0); // we later use the offset to tell apart the fields @@ -676,7 +684,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // may be a pointer. This is `tag_val.layout`; we just use it for sanity checks. // Get layout for tag. - let tag_layout = self.layout_of(tag_scalar_layout.value.to_int_ty(*self.tcx))?; + let tag_layout = self.layout_of(tag_scalar_layout.primitive().to_int_ty(*self.tcx))?; // Read tag and sanity-check `tag_layout`. let tag_val = self.read_immediate(&self.operand_field(op, tag_field)?)?; diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index c37973bd1663..5f7f52ef9e9f 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -772,13 +772,11 @@ where // We checked `ptr_align` above, so all fields will have the alignment they need. // We would anyway check against `ptr_align.restrict_for_offset(b_offset)`, // which `ptr.offset(b_offset)` cannot possibly fail to satisfy. - let (a, b) = match dest.layout.abi { - Abi::ScalarPair(a, b) => (a.value, b.value), - _ => span_bug!( + let Abi::ScalarPair(a, b) = dest.layout.abi else { span_bug!( self.cur_span(), "write_immediate_to_mplace: invalid ScalarPair layout: {:#?}", dest.layout - ), + ) }; let (a_size, b_size) = (a.size(&tcx), b.size(&tcx)); let b_offset = a_size.align_to(b.align(&tcx).abi); @@ -1046,7 +1044,7 @@ where // raw discriminants for enums are isize or bigger during // their computation, but the in-memory tag is the smallest possible // representation - let size = tag_layout.value.size(self); + let size = tag_layout.size(self); let tag_val = size.truncate(discr_val); let tag_dest = self.place_field(dest, tag_field)?; @@ -1070,7 +1068,7 @@ where .expect("overflow computing relative variant idx"); // We need to use machine arithmetic when taking into account `niche_start`: // tag_val = variant_index_relative + niche_start_val - let tag_layout = self.layout_of(tag_layout.value.to_int_ty(*self.tcx))?; + let tag_layout = self.layout_of(tag_layout.primitive().to_int_ty(*self.tcx))?; let niche_start_val = ImmTy::from_uint(niche_start, tag_layout); let variant_index_relative_val = ImmTy::from_uint(variant_index_relative, tag_layout); diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs index a7587652114b..c2a38c6978bf 100644 --- a/compiler/rustc_const_eval/src/interpret/terminator.rs +++ b/compiler/rustc_const_eval/src/interpret/terminator.rs @@ -189,12 +189,15 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // that will take care to make it UB to leave the range, just // like for transmute). (abi::Abi::Scalar(caller), abi::Abi::Scalar(callee)) => { - caller.value == callee.value + caller.primitive() == callee.primitive() } ( abi::Abi::ScalarPair(caller1, caller2), abi::Abi::ScalarPair(callee1, callee2), - ) => caller1.value == callee1.value && caller2.value == callee2.value, + ) => { + caller1.primitive() == callee1.primitive() + && caller2.primitive() == callee2.primitive() + } // Be conservative _ => false, } diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index 42ff7b194591..e5fd182f8b3a 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -629,12 +629,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' op: &OpTy<'tcx, M::PointerTag>, scalar_layout: ScalarAbi, ) -> InterpResult<'tcx> { - if scalar_layout.valid_range.is_full_for(op.layout.size) { + if scalar_layout.valid_range(self.ecx).is_full_for(op.layout.size) { // Nothing to check return Ok(()); } // At least one value is excluded. - let valid_range = scalar_layout.valid_range; + let valid_range = scalar_layout.valid_range(self.ecx); let WrappingRange { start, end } = valid_range; let max_value = op.layout.size.unsigned_int_max(); assert!(end <= max_value); diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 556b2c6fbf36..06a90ab05ac8 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -1047,6 +1047,12 @@ impl<'a> ExtCtxt<'a> { self.current_expansion.id.expn_data().call_site } + /// Returns the current expansion kind's description. + pub(crate) fn expansion_descr(&self) -> String { + let expn_data = self.current_expansion.id.expn_data(); + expn_data.kind.descr() + } + /// Equivalent of `Span::def_site` from the proc macro API, /// except that the location is taken from the span passed as an argument. pub fn with_def_site_ctxt(&self, span: Span) -> Span { diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs index a5afb7aa4fa4..b4bae8ce5fbe 100644 --- a/compiler/rustc_expand/src/proc_macro.rs +++ b/compiler/rustc_expand/src/proc_macro.rs @@ -24,6 +24,8 @@ impl base::ProcMacro for BangProcMacro { span: Span, input: TokenStream, ) -> Result { + let _timer = + ecx.sess.prof.generic_activity_with_arg("expand_proc_macro", ecx.expansion_descr()); let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace; let server = proc_macro_server::Rustc::new(ecx); self.client.run(&EXEC_STRATEGY, server, input, proc_macro_backtrace).map_err(|e| { @@ -48,6 +50,8 @@ impl base::AttrProcMacro for AttrProcMacro { annotation: TokenStream, annotated: TokenStream, ) -> Result { + let _timer = + ecx.sess.prof.generic_activity_with_arg("expand_proc_macro", ecx.expansion_descr()); let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace; let server = proc_macro_server::Rustc::new(ecx); self.client @@ -97,17 +101,21 @@ impl MultiItemModifier for ProcMacroDerive { nt_to_tokenstream(&item, &ecx.sess.parse_sess, CanSynthesizeMissingTokens::No) }; - let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace; - let server = proc_macro_server::Rustc::new(ecx); - let stream = match self.client.run(&EXEC_STRATEGY, server, input, proc_macro_backtrace) { - Ok(stream) => stream, - Err(e) => { - let mut err = ecx.struct_span_err(span, "proc-macro derive panicked"); - if let Some(s) = e.as_str() { - err.help(&format!("message: {}", s)); + let stream = { + let _timer = + ecx.sess.prof.generic_activity_with_arg("expand_proc_macro", ecx.expansion_descr()); + let proc_macro_backtrace = ecx.ecfg.proc_macro_backtrace; + let server = proc_macro_server::Rustc::new(ecx); + match self.client.run(&EXEC_STRATEGY, server, input, proc_macro_backtrace) { + Ok(stream) => stream, + Err(e) => { + let mut err = ecx.struct_span_err(span, "proc-macro derive panicked"); + if let Some(s) = e.as_str() { + err.help(&format!("message: {}", s)); + } + err.emit(); + return ExpandResult::Ready(vec![]); } - err.emit(); - return ExpandResult::Ready(vec![]); } }; diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 14ac30987b35..437104d1aaf5 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -12,7 +12,7 @@ use rustc_middle::ty::{self, AdtKind, DefIdTree, Ty, TyCtxt, TypeFoldable}; use rustc_span::source_map; use rustc_span::symbol::sym; use rustc_span::{Span, Symbol, DUMMY_SP}; -use rustc_target::abi::Abi; +use rustc_target::abi::{Abi, WrappingRange}; use rustc_target::abi::{Integer, TagEncoding, Variants}; use rustc_target::spec::abi::Abi as SpecAbi; @@ -796,14 +796,18 @@ crate fn repr_nullable_ptr<'tcx>( // Return the nullable type this Option-like enum can be safely represented with. let field_ty_abi = &cx.layout_of(field_ty).unwrap().abi; if let Abi::Scalar(field_ty_scalar) = field_ty_abi { - match (field_ty_scalar.valid_range.start, field_ty_scalar.valid_range.end) { - (0, x) if x == field_ty_scalar.value.size(&cx.tcx).unsigned_int_max() - 1 => { + match field_ty_scalar.valid_range(cx) { + WrappingRange { start: 0, end } + if end == field_ty_scalar.size(&cx.tcx).unsigned_int_max() - 1 => + { return Some(get_nullable_type(cx, field_ty).unwrap()); } - (1, _) => { + WrappingRange { start: 1, .. } => { return Some(get_nullable_type(cx, field_ty).unwrap()); } - (start, end) => unreachable!("Unhandled start and end range: ({}, {})", start, end), + WrappingRange { start, end } => { + unreachable!("Unhandled start and end range: ({}, {})", start, end) + } }; } } @@ -1342,7 +1346,7 @@ impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences { return }; - let tag_size = tag.value.size(&cx.tcx).bytes(); + let tag_size = tag.size(&cx.tcx).bytes(); debug!( "enum `{}` is {} bytes large with layout:\n{:#?}", diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 0c1ab67cc4ac..e278efa3d8b1 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -305,10 +305,10 @@ fn invert_mapping(map: &[u32]) -> Vec { impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { fn scalar_pair(&self, a: Scalar, b: Scalar) -> LayoutS<'tcx> { let dl = self.data_layout(); - let b_align = b.value.align(dl); - let align = a.value.align(dl).max(b_align).max(dl.aggregate_align); - let b_offset = a.value.size(dl).align_to(b_align.abi); - let size = (b_offset + b.value.size(dl)).align_to(align.abi); + let b_align = b.align(dl); + let align = a.align(dl).max(b_align).max(dl.aggregate_align); + let b_offset = a.size(dl).align_to(b_align.abi); + let size = (b_offset + b.size(dl)).align_to(align.abi); // HACK(nox): We iter on `b` and then `a` because `max_by_key` // returns the last maximum. @@ -567,7 +567,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let scalar_unit = |value: Primitive| { let size = value.size(dl); assert!(size.bits() <= 128); - Scalar { value, valid_range: WrappingRange { start: 0, end: size.unsigned_int_max() } } + Scalar::Initialized { value, valid_range: WrappingRange::full(size) } }; let scalar = |value: Primitive| tcx.intern_layout(LayoutS::scalar(self, scalar_unit(value))); @@ -581,11 +581,14 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // Basic scalars. ty::Bool => tcx.intern_layout(LayoutS::scalar( self, - Scalar { value: Int(I8, false), valid_range: WrappingRange { start: 0, end: 1 } }, + Scalar::Initialized { + value: Int(I8, false), + valid_range: WrappingRange { start: 0, end: 1 }, + }, )), ty::Char => tcx.intern_layout(LayoutS::scalar( self, - Scalar { + Scalar::Initialized { value: Int(I32, false), valid_range: WrappingRange { start: 0, end: 0x10FFFF }, }, @@ -598,7 +601,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { }), ty::FnPtr(_) => { let mut ptr = scalar_unit(Pointer); - ptr.valid_range = ptr.valid_range.with_start(1); + ptr.valid_range_mut().start = 1; tcx.intern_layout(LayoutS::scalar(self, ptr)) } @@ -616,7 +619,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { ty::Ref(_, pointee, _) | ty::RawPtr(ty::TypeAndMut { ty: pointee, .. }) => { let mut data_ptr = scalar_unit(Pointer); if !ty.is_unsafe_ptr() { - data_ptr.valid_range = data_ptr.valid_range.with_start(1); + data_ptr.valid_range_mut().start = 1; } let pointee = tcx.normalize_erasing_regions(param_env, pointee); @@ -632,7 +635,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { ty::Slice(_) | ty::Str => scalar_unit(Int(dl.ptr_sized_integer(), false)), ty::Dynamic(..) => { let mut vtable = scalar_unit(Pointer); - vtable.valid_range = vtable.valid_range.with_start(1); + vtable.valid_range_mut().start = 1; vtable } _ => return Err(LayoutError::Unknown(unsized_part)), @@ -889,14 +892,14 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // If all non-ZST fields have the same ABI, forward this ABI if optimize && !field.is_zst() { - // Normalize scalar_unit to the maximal valid range + // Discard valid range information and allow undef let field_abi = match field.abi { - Abi::Scalar(x) => Abi::Scalar(scalar_unit(x.value)), + Abi::Scalar(x) => Abi::Scalar(x.to_union()), Abi::ScalarPair(x, y) => { - Abi::ScalarPair(scalar_unit(x.value), scalar_unit(y.value)) + Abi::ScalarPair(x.to_union(), y.to_union()) } Abi::Vector { element: x, count } => { - Abi::Vector { element: scalar_unit(x.value), count } + Abi::Vector { element: x.to_union(), count } } Abi::Uninhabited | Abi::Aggregate { .. } => { Abi::Aggregate { sized: true } @@ -1000,14 +1003,16 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { if let Bound::Included(start) = start { // FIXME(eddyb) this might be incorrect - it doesn't // account for wrap-around (end < start) ranges. - assert!(scalar.valid_range.start <= start); - scalar.valid_range.start = start; + let valid_range = scalar.valid_range_mut(); + assert!(valid_range.start <= start); + valid_range.start = start; } if let Bound::Included(end) = end { // FIXME(eddyb) this might be incorrect - it doesn't // account for wrap-around (end < start) ranges. - assert!(scalar.valid_range.end >= end); - scalar.valid_range.end = end; + let valid_range = scalar.valid_range_mut(); + assert!(valid_range.end >= end); + valid_range.end = end; } // Update `largest_niche` if we have introduced a larger niche. @@ -1133,9 +1138,15 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // guaranteed to be initialised, not the // other primitive. if offset.bytes() == 0 { - Abi::ScalarPair(niche_scalar, scalar_unit(second.value)) + Abi::ScalarPair( + niche_scalar, + scalar_unit(second.primitive()), + ) } else { - Abi::ScalarPair(scalar_unit(first.value), niche_scalar) + Abi::ScalarPair( + scalar_unit(first.primitive()), + niche_scalar, + ) } } _ => Abi::Aggregate { sized: true }, @@ -1314,7 +1325,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { } let tag_mask = ity.size().unsigned_int_max(); - let tag = Scalar { + let tag = Scalar::Initialized { value: Int(ity, signed), valid_range: WrappingRange { start: (min as u128 & tag_mask), @@ -1325,7 +1336,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { // Without latter check aligned enums with custom discriminant values // Would result in ICE see the issue #92464 for more info - if tag.value.size(dl) == size || variants.iter().all(|layout| layout.is_empty()) { + if tag.size(dl) == size || variants.iter().all(|layout| layout.is_empty()) { abi = Abi::Scalar(tag); } else { // Try to use a ScalarPair for all tagged enums. @@ -1345,7 +1356,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { } }; let prim = match field.abi { - Abi::Scalar(scalar) => scalar.value, + Abi::Scalar(scalar) => scalar.primitive(), _ => { common_prim = None; break; @@ -1599,7 +1610,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let max_discr = (info.variant_fields.len() - 1) as u128; let discr_int = Integer::fit_unsigned(max_discr); let discr_int_ty = discr_int.to_ty(tcx, false); - let tag = Scalar { + let tag = Scalar::Initialized { value: Primitive::Int(discr_int, false), valid_range: WrappingRange { start: 0, end: max_discr }, }; @@ -1898,7 +1909,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { adt_kind.into(), adt_packed, match tag_encoding { - TagEncoding::Direct => Some(tag.value.size(self)), + TagEncoding::Direct => Some(tag.size(self)), _ => None, }, variant_infos, @@ -2304,7 +2315,7 @@ where let tag_layout = |tag: Scalar| -> TyAndLayout<'tcx> { TyAndLayout { layout: tcx.intern_layout(LayoutS::scalar(cx, tag)), - ty: tag.value.to_ty(tcx), + ty: tag.primitive().to_ty(tcx), } }; @@ -3079,11 +3090,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { } // Only pointer types handled below. - if scalar.value != Pointer { - return; - } + let Scalar::Initialized { value: Pointer, valid_range} = scalar else { return }; - if !scalar.valid_range.contains(0) { + if !valid_range.contains(0) { attrs.set(ArgAttribute::NonNull); } diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 3e6772778265..0c7d2f7b4e5e 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -3298,7 +3298,9 @@ impl<'a> Resolver<'a> { PathResult::NonModule(path_res) if path_res.unresolved_segments() == 0 => { Some(path_res.base_res()) } - PathResult::NonModule(..) | PathResult::Failed { .. } => None, + PathResult::Module(ModuleOrUniformRoot::ExternPrelude) + | PathResult::NonModule(..) + | PathResult::Failed { .. } => None, PathResult::Module(..) | PathResult::Indeterminate => unreachable!(), } } diff --git a/compiler/rustc_target/src/abi/call/mips64.rs b/compiler/rustc_target/src/abi/call/mips64.rs index 1ac454be5e9a..cd54167aa7f8 100644 --- a/compiler/rustc_target/src/abi/call/mips64.rs +++ b/compiler/rustc_target/src/abi/call/mips64.rs @@ -6,7 +6,7 @@ use crate::abi::{self, HasDataLayout, Size, TyAbiInterface}; fn extend_integer_width_mips(arg: &mut ArgAbi<'_, Ty>, bits: u64) { // Always sign extend u32 values on 64-bit mips if let abi::Abi::Scalar(scalar) = arg.layout.abi { - if let abi::Int(i, signed) = scalar.value { + if let abi::Int(i, signed) = scalar.primitive() { if !signed && i.size().bits() == 32 { if let PassMode::Direct(ref mut attrs) = arg.mode { attrs.ext(ArgExtension::Sext); @@ -25,7 +25,7 @@ where C: HasDataLayout, { match ret.layout.field(cx, i).abi { - abi::Abi::Scalar(scalar) => match scalar.value { + abi::Abi::Scalar(scalar) => match scalar.primitive() { abi::F32 => Some(Reg::f32()), abi::F64 => Some(Reg::f64()), _ => None, @@ -110,7 +110,7 @@ where // We only care about aligned doubles if let abi::Abi::Scalar(scalar) = field.abi { - if let abi::F64 = scalar.value { + if let abi::F64 = scalar.primitive() { if offset.is_aligned(dl.f64_align.abi) { // Insert enough integers to cover [last_offset, offset) assert!(last_offset.is_aligned(dl.f64_align.abi)); diff --git a/compiler/rustc_target/src/abi/call/mod.rs b/compiler/rustc_target/src/abi/call/mod.rs index 34324a582977..ce564d1455bf 100644 --- a/compiler/rustc_target/src/abi/call/mod.rs +++ b/compiler/rustc_target/src/abi/call/mod.rs @@ -348,7 +348,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { // The primitive for this algorithm. Abi::Scalar(scalar) => { - let kind = match scalar.value { + let kind = match scalar.primitive() { abi::Int(..) | abi::Pointer => RegKind::Integer, abi::F32 | abi::F64 => RegKind::Float, }; @@ -482,7 +482,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> { Abi::Scalar(scalar) => PassMode::Direct(scalar_attrs(&layout, scalar, Size::ZERO)), Abi::ScalarPair(a, b) => PassMode::Pair( scalar_attrs(&layout, a, Size::ZERO), - scalar_attrs(&layout, b, a.value.size(cx).align_to(b.value.align(cx).abi)), + scalar_attrs(&layout, b, a.size(cx).align_to(b.align(cx).abi)), ), Abi::Vector { .. } => PassMode::Direct(ArgAttributes::new()), Abi::Aggregate { .. } => PassMode::Direct(ArgAttributes::new()), @@ -534,7 +534,7 @@ impl<'a, Ty> ArgAbi<'a, Ty> { pub fn extend_integer_width_to(&mut self, bits: u64) { // Only integers have signedness if let Abi::Scalar(scalar) = self.layout.abi { - if let abi::Int(i, signed) = scalar.value { + if let abi::Int(i, signed) = scalar.primitive() { if i.size().bits() < bits { if let PassMode::Direct(ref mut attrs) = self.mode { if signed { diff --git a/compiler/rustc_target/src/abi/call/riscv.rs b/compiler/rustc_target/src/abi/call/riscv.rs index bbefc73a076d..752b44f6434c 100644 --- a/compiler/rustc_target/src/abi/call/riscv.rs +++ b/compiler/rustc_target/src/abi/call/riscv.rs @@ -44,7 +44,7 @@ where Ty: TyAbiInterface<'a, C> + Copy, { match arg_layout.abi { - Abi::Scalar(scalar) => match scalar.value { + Abi::Scalar(scalar) => match scalar.primitive() { abi::Int(..) | abi::Pointer => { if arg_layout.size.bits() > xlen { return Err(CannotUseFpConv); @@ -298,7 +298,7 @@ fn classify_arg<'a, Ty, C>( fn extend_integer_width<'a, Ty>(arg: &mut ArgAbi<'a, Ty>, xlen: u64) { if let Abi::Scalar(scalar) = arg.layout.abi { - if let abi::Int(i, _) = scalar.value { + if let abi::Int(i, _) = scalar.primitive() { // 32-bit integers are always sign-extended if i.size().bits() == 32 && xlen > 32 { if let PassMode::Direct(ref mut attrs) = arg.mode { diff --git a/compiler/rustc_target/src/abi/call/sparc64.rs b/compiler/rustc_target/src/abi/call/sparc64.rs index 72709d31021b..5a92ebdd9e84 100644 --- a/compiler/rustc_target/src/abi/call/sparc64.rs +++ b/compiler/rustc_target/src/abi/call/sparc64.rs @@ -20,7 +20,7 @@ where { let dl = cx.data_layout(); - if scalar.value != abi::F32 && scalar.value != abi::F64 { + if !scalar.primitive().is_float() { return data; } @@ -56,7 +56,7 @@ where return data; } - if scalar.value == abi::F32 { + if scalar.primitive() == abi::F32 { data.arg_attribute = ArgAttribute::InReg; data.prefix[data.prefix_index] = Some(Reg::f32()); data.last_offset = offset + Reg::f32().size; @@ -79,17 +79,15 @@ where C: HasDataLayout, { data = arg_scalar(cx, &scalar1, offset, data); - if scalar1.value == abi::F32 { - offset += Reg::f32().size; - } else if scalar2.value == abi::F64 { - offset += Reg::f64().size; - } else if let abi::Int(i, _signed) = scalar1.value { - offset += i.size(); - } else if scalar1.value == abi::Pointer { - offset = offset + Reg::i64().size; + match (scalar1.primitive(), scalar2.primitive()) { + (abi::F32, _) => offset += Reg::f32().size, + (_, abi::F64) => offset += Reg::f64().size, + (abi::Int(i, _signed), _) => offset += i.size(), + (abi::Pointer, _) => offset += Reg::i64().size, + _ => {} } - if (offset.raw % 4) != 0 && (scalar2.value == abi::F32 || scalar2.value == abi::F64) { + if (offset.raw % 4) != 0 && scalar2.primitive().is_float() { offset.raw += 4 - (offset.raw % 4); } data = arg_scalar(cx, &scalar2, offset, data); diff --git a/compiler/rustc_target/src/abi/call/x86_64.rs b/compiler/rustc_target/src/abi/call/x86_64.rs index fae3c3af61bf..a52e01a495a5 100644 --- a/compiler/rustc_target/src/abi/call/x86_64.rs +++ b/compiler/rustc_target/src/abi/call/x86_64.rs @@ -49,7 +49,7 @@ where let mut c = match layout.abi { Abi::Uninhabited => return Ok(()), - Abi::Scalar(scalar) => match scalar.value { + Abi::Scalar(scalar) => match scalar.primitive() { abi::Int(..) | abi::Pointer => Class::Int, abi::F32 | abi::F64 => Class::Sse, }, diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index 52fce7c05530..c46726b767bf 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -752,6 +752,10 @@ pub struct WrappingRange { } impl WrappingRange { + pub fn full(size: Size) -> Self { + Self { start: 0, end: size.unsigned_int_max() } + } + /// Returns `true` if `v` is contained in the range. #[inline(always)] pub fn contains(&self, v: u128) -> bool { @@ -799,13 +803,23 @@ impl fmt::Debug for WrappingRange { /// Information about one scalar component of a Rust type. #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] #[derive(HashStable_Generic)] -pub struct Scalar { - pub value: Primitive, +pub enum Scalar { + Initialized { + value: Primitive, - // FIXME(eddyb) always use the shortest range, e.g., by finding - // the largest space between two consecutive valid values and - // taking everything else as the (shortest) valid range. - pub valid_range: WrappingRange, + // FIXME(eddyb) always use the shortest range, e.g., by finding + // the largest space between two consecutive valid values and + // taking everything else as the (shortest) valid range. + valid_range: WrappingRange, + }, + Union { + /// Even for unions, we need to use the correct registers for the kind of + /// values inside the union, so we keep the `Primitive` type around. We + /// also use it to compute the size of the scalar. + /// However, unions never have niches and even allow undef, + /// so there is no `valid_range`. + value: Primitive, + }, } impl Scalar { @@ -813,14 +827,58 @@ impl Scalar { pub fn is_bool(&self) -> bool { matches!( self, - Scalar { value: Int(I8, false), valid_range: WrappingRange { start: 0, end: 1 } } + Scalar::Initialized { + value: Int(I8, false), + valid_range: WrappingRange { start: 0, end: 1 } + } ) } + /// Get the primitive representation of this type, ignoring the valid range and whether the + /// value is allowed to be undefined (due to being a union). + pub fn primitive(&self) -> Primitive { + match *self { + Scalar::Initialized { value, .. } | Scalar::Union { value } => value, + } + } + + pub fn align(self, cx: &impl HasDataLayout) -> AbiAndPrefAlign { + self.primitive().align(cx) + } + + pub fn size(self, cx: &impl HasDataLayout) -> Size { + self.primitive().size(cx) + } + + #[inline] + pub fn to_union(&self) -> Self { + Self::Union { value: self.primitive() } + } + + #[inline] + pub fn valid_range(&self, cx: &impl HasDataLayout) -> WrappingRange { + match *self { + Scalar::Initialized { valid_range, .. } => valid_range, + Scalar::Union { value } => WrappingRange::full(value.size(cx)), + } + } + + #[inline] + /// Allows the caller to mutate the valid range. This operation will panic if attempted on a union. + pub fn valid_range_mut(&mut self) -> &mut WrappingRange { + match self { + Scalar::Initialized { valid_range, .. } => valid_range, + Scalar::Union { .. } => panic!("cannot change the valid range of a union"), + } + } + /// Returns `true` if all possible numbers are valid, i.e `valid_range` covers the whole layout #[inline] pub fn is_always_valid(&self, cx: &C) -> bool { - self.valid_range.is_full_for(self.value.size(cx)) + match *self { + Scalar::Initialized { valid_range, .. } => valid_range.is_full_for(self.size(cx)), + Scalar::Union { .. } => true, + } } } @@ -988,7 +1046,7 @@ impl Abi { #[inline] pub fn is_signed(&self) -> bool { match self { - Abi::Scalar(scal) => match scal.value { + Abi::Scalar(scal) => match scal.primitive() { Primitive::Int(_, signed) => signed, _ => false, }, @@ -1060,17 +1118,19 @@ pub enum TagEncoding { #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable_Generic)] pub struct Niche { pub offset: Size, - pub scalar: Scalar, + pub value: Primitive, + pub valid_range: WrappingRange, } impl Niche { pub fn from_scalar(cx: &C, offset: Size, scalar: Scalar) -> Option { - let niche = Niche { offset, scalar }; + let Scalar::Initialized { value, valid_range } = scalar else { return None }; + let niche = Niche { offset, value, valid_range }; if niche.available(cx) > 0 { Some(niche) } else { None } } pub fn available(&self, cx: &C) -> u128 { - let Scalar { value, valid_range: v } = self.scalar; + let Self { value, valid_range: v, .. } = *self; let size = value.size(cx); assert!(size.bits() <= 128); let max_value = size.unsigned_int_max(); @@ -1083,7 +1143,7 @@ impl Niche { pub fn reserve(&self, cx: &C, count: u128) -> Option<(u128, Scalar)> { assert!(count > 0); - let Scalar { value, valid_range: v } = self.scalar; + let Self { value, valid_range: v, .. } = *self; let size = value.size(cx); assert!(size.bits() <= 128); let max_value = size.unsigned_int_max(); @@ -1107,12 +1167,12 @@ impl Niche { // If niche zero is already reserved, the selection of bounds are of little interest. let move_start = |v: WrappingRange| { let start = v.start.wrapping_sub(count) & max_value; - Some((start, Scalar { value, valid_range: v.with_start(start) })) + Some((start, Scalar::Initialized { value, valid_range: v.with_start(start) })) }; let move_end = |v: WrappingRange| { let start = v.end.wrapping_add(1) & max_value; let end = v.end.wrapping_add(count) & max_value; - Some((start, Scalar { value, valid_range: v.with_end(end) })) + Some((start, Scalar::Initialized { value, valid_range: v.with_end(end) })) }; let distance_end_zero = max_value - v.end; if v.start > v.end { @@ -1172,8 +1232,8 @@ pub struct LayoutS<'a> { impl<'a> LayoutS<'a> { pub fn scalar(cx: &C, scalar: Scalar) -> Self { let largest_niche = Niche::from_scalar(cx, Size::ZERO, scalar); - let size = scalar.value.size(cx); - let align = scalar.value.align(cx); + let size = scalar.size(cx); + let align = scalar.align(cx); LayoutS { variants: Variants::Single { index: VariantIdx::new(0) }, fields: FieldsShape::Primitive, @@ -1325,7 +1385,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { C: HasDataLayout, { match self.abi { - Abi::Scalar(scalar) => scalar.value.is_float(), + Abi::Scalar(scalar) => scalar.primitive().is_float(), Abi::Aggregate { .. } => { if self.fields.count() == 1 && self.fields.offset(0).bytes() == 0 { self.field(cx, 0).is_single_fp_element(cx) @@ -1371,7 +1431,7 @@ impl<'a, Ty> TyAndLayout<'a, Ty> { let scalar_allows_raw_init = move |s: Scalar| -> bool { if zero { // The range must contain 0. - s.valid_range.contains(0) + s.valid_range(cx).contains(0) } else { // The range must include all values. s.is_always_valid(cx) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index ff3488b7b769..9998c5bb087e 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -540,6 +540,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ); self.note_version_mismatch(&mut err, &trait_ref); self.suggest_remove_await(&obligation, &mut err); + self.suggest_derive(&obligation, &mut err, trait_predicate); if Some(trait_ref.def_id()) == tcx.lang_items().try_trait() { self.suggest_await_before_try( diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs index d2b1fe2e0df9..31b92d52bebc 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs @@ -208,6 +208,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { flags.push((sym::_Self, Some("&[]".to_owned()))); } + if self_ty.is_fn() { + let fn_sig = self_ty.fn_sig(self.tcx); + let shortname = match fn_sig.unsafety() { + hir::Unsafety::Normal => "fn", + hir::Unsafety::Unsafe => "unsafe fn", + }; + flags.push((sym::_Self, Some(shortname.to_owned()))); + } + if let ty::Array(aty, len) = self_ty.kind() { flags.push((sym::_Self, Some("[]".to_owned()))); flags.push((sym::_Self, Some(format!("[{}]", aty)))); diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 8dac56120e66..7c3f306717a6 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -189,6 +189,13 @@ pub trait InferCtxtExt<'tcx> { err: &mut Diagnostic, trait_ref: &ty::PolyTraitRef<'tcx>, ); + + fn suggest_derive( + &self, + obligation: &PredicateObligation<'tcx>, + err: &mut Diagnostic, + trait_pred: ty::PolyTraitPredicate<'tcx>, + ); } fn predicate_constraint(generics: &hir::Generics<'_>, pred: String) -> (Span, String) { @@ -2651,6 +2658,68 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { _ => {} } } + + fn suggest_derive( + &self, + obligation: &PredicateObligation<'tcx>, + err: &mut Diagnostic, + trait_pred: ty::PolyTraitPredicate<'tcx>, + ) { + let Some(diagnostic_name) = self.tcx.get_diagnostic_name(trait_pred.def_id()) else { + return; + }; + let (adt, substs) = match trait_pred.skip_binder().self_ty().kind() { + ty::Adt(adt, substs) if adt.did().is_local() => (adt, substs), + _ => return, + }; + let can_derive = { + let is_derivable_trait = match diagnostic_name { + sym::Default => !adt.is_enum(), + sym::PartialEq | sym::PartialOrd => { + let rhs_ty = trait_pred.skip_binder().trait_ref.substs.type_at(1); + trait_pred.skip_binder().self_ty() == rhs_ty + } + sym::Eq | sym::Ord | sym::Clone | sym::Copy | sym::Hash | sym::Debug => true, + _ => false, + }; + is_derivable_trait && + // Ensure all fields impl the trait. + adt.all_fields().all(|field| { + let field_ty = field.ty(self.tcx, substs); + let trait_substs = match diagnostic_name { + sym::PartialEq | sym::PartialOrd => { + self.tcx.mk_substs_trait(field_ty, &[field_ty.into()]) + } + _ => self.tcx.mk_substs_trait(field_ty, &[]), + }; + let trait_pred = trait_pred.map_bound_ref(|tr| ty::TraitPredicate { + trait_ref: ty::TraitRef { + substs: trait_substs, + ..trait_pred.skip_binder().trait_ref + }, + ..*tr + }); + let field_obl = Obligation::new( + obligation.cause.clone(), + obligation.param_env, + trait_pred.to_predicate(self.tcx), + ); + self.predicate_must_hold_modulo_regions(&field_obl) + }) + }; + if can_derive { + err.span_suggestion_verbose( + self.tcx.def_span(adt.did()).shrink_to_lo(), + &format!( + "consider annotating `{}` with `#[derive({})]`", + trait_pred.skip_binder().self_ty(), + diagnostic_name.to_string(), + ), + format!("#[derive({})]\n", diagnostic_name.to_string()), + Applicability::MaybeIncorrect, + ); + } + } } /// Collect all the returned expressions within the input expression. diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs index 00bc16452b9b..83e535b3c324 100644 --- a/compiler/rustc_typeck/src/check/demand.rs +++ b/compiler/rustc_typeck/src/check/demand.rs @@ -40,6 +40,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.suggest_boxing_when_appropriate(err, expr, expected, expr_ty); self.suggest_missing_parentheses(err, expr); self.suggest_block_to_brackets_peeling_refs(err, expr, expr_ty, expected); + self.note_type_is_not_clone(err, expected, expr_ty, expr); self.note_need_for_fn_pointer(err, expected, expr_ty); self.note_internal_mutation_in_method(err, expr, expected, expr_ty); self.report_closure_inferred_return_type(err, expected); @@ -630,7 +631,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Applicability::MachineApplicable, true, )); - } } _ => {} diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs index 1ccdbb0aa500..93a0900c7e80 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs @@ -2,8 +2,6 @@ use super::FnCtxt; use crate::astconv::AstConv; use rustc_ast::util::parser::ExprPrecedence; -use rustc_span::{self, Span}; - use rustc_errors::{Applicability, Diagnostic, MultiSpan}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind}; @@ -13,12 +11,14 @@ use rustc_hir::{ WherePredicate, }; use rustc_infer::infer::{self, TyCtxtInferExt}; - +use rustc_infer::traits; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, Binder, Ty}; -use rustc_span::symbol::{kw, sym}; - use rustc_middle::ty::subst::GenericArgKind; +use rustc_middle::ty::{self, Binder, ToPredicate, Ty}; +use rustc_span::symbol::{kw, sym}; +use rustc_span::Span; +use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; + use std::iter; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { @@ -846,4 +846,53 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let node = self.tcx.hir().get(id); matches!(node, Node::Stmt(Stmt { kind: StmtKind::Local(..), .. })) } + + /// Suggest that `&T` was cloned instead of `T` because `T` does not implement `Clone`, + /// which is a side-effect of autoref. + pub(crate) fn note_type_is_not_clone( + &self, + diag: &mut Diagnostic, + expected_ty: Ty<'tcx>, + found_ty: Ty<'tcx>, + expr: &hir::Expr<'_>, + ) { + let hir::ExprKind::MethodCall(segment, &[ref callee_expr], _) = expr.kind else { return; }; + let Some(clone_trait_did) = self.tcx.lang_items().clone_trait() else { return; }; + let ty::Ref(_, pointee_ty, _) = found_ty.kind() else { return }; + let results = self.typeck_results.borrow(); + // First, look for a `Clone::clone` call + if segment.ident.name == sym::clone + && results.type_dependent_def_id(expr.hir_id).map_or( + false, + |did| { + self.tcx.associated_item(did).container + == ty::AssocItemContainer::TraitContainer(clone_trait_did) + }, + ) + // If that clone call hasn't already dereferenced the self type (i.e. don't give this + // diagnostic in cases where we have `(&&T).clone()` and we expect `T`). + && !results.expr_adjustments(callee_expr).iter().any(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(..))) + // Check that we're in fact trying to clone into the expected type + && self.can_coerce(*pointee_ty, expected_ty) + // And the expected type doesn't implement `Clone` + && !self.predicate_must_hold_considering_regions(&traits::Obligation { + cause: traits::ObligationCause::dummy(), + param_env: self.param_env, + recursion_depth: 0, + predicate: ty::Binder::dummy(ty::TraitRef { + def_id: clone_trait_did, + substs: self.tcx.mk_substs([expected_ty.into()].iter()), + }) + .without_const() + .to_predicate(self.tcx), + }) + { + diag.span_note( + callee_expr.span, + &format!( + "`{expected_ty}` does not implement `Clone`, so `{found_ty}` was cloned instead" + ), + ); + } + } } diff --git a/library/core/src/intrinsics.rs b/library/core/src/intrinsics.rs index 0744e9cf4269..27063952adba 100644 --- a/library/core/src/intrinsics.rs +++ b/library/core/src/intrinsics.rs @@ -991,6 +991,16 @@ extern "rust-intrinsic" { /// let ptr_num_cast = ptr as *const i32 as usize; /// ``` /// + /// Note that using `transmute` to turn a pointer to a `usize` is (as noted above) [undefined + /// behavior][ub] in `const` contexts. Also outside of consts, this operation might not behave + /// as expected -- this is touching on many unspecified aspects of the Rust memory model. + /// Depending on what the code is doing, the following alternatives are preferrable to + /// pointer-to-integer transmutation: + /// - If the code just wants to store data of arbitrary type in some buffer and needs to pick a + /// type for that buffer, it can use [`MaybeUninit`][mem::MaybeUninit]. + /// - If the code actually wants to work on the address the pointer points to, it can use `as` + /// casts or [`ptr.addr()`][pointer::addr]. + /// /// Turning a `*mut T` into an `&mut T`: /// /// ``` diff --git a/library/core/src/macros/panic.md b/library/core/src/macros/panic.md index 5127a16bbfd8..d8206e789311 100644 --- a/library/core/src/macros/panic.md +++ b/library/core/src/macros/panic.md @@ -1,8 +1,7 @@ Panics the current thread. This allows a program to terminate immediately and provide feedback -to the caller of the program. `panic!` should be used when a program reaches -an unrecoverable state. +to the caller of the program. This macro is the perfect way to assert conditions in example code and in tests. `panic!` is closely tied with the `unwrap` method of both @@ -21,13 +20,25 @@ Inside the hook a panic can be accessed as a `&dyn Any + Send`, which contains either a `&str` or `String` for regular `panic!()` invocations. To panic with a value of another other type, [`panic_any`] can be used. -[`Result`] enum is often a better solution for recovering from errors than -using the `panic!` macro. This macro should be used to avoid proceeding using -incorrect values, such as from external sources. Detailed information about -error handling is found in the [book]. - See also the macro [`compile_error!`], for raising errors during compilation. +# When to use `panic!` vs `Result` + +The Rust model of error handling groups errors into two major categories: +recoverable and unrecoverable errors. For a recoverable error, such as a file +not found error, it’s reasonable to report the problem to the user and retry +the operation. Unrecoverable errors are always symptoms of bugs, like trying to +access a location beyond the end of an array. + +The Rust language and standard library provides `Result` and `panic!` as parts +of two complementary systems for representing, reporting, propagating, reacting +to, and discarding errors for in these two categories. + +The `panic!` macro is provided to represent unrecoverable errors, whereas the +`Result` enum is provided to represent recoverable errors. For more detailed +information about error handling check out the [book] or the [`std::result`] +module docs. + [ounwrap]: Option::unwrap [runwrap]: Result::unwrap [`std::panic::set_hook()`]: ../std/panic/fn.set_hook.html @@ -36,6 +47,7 @@ See also the macro [`compile_error!`], for raising errors during compilation. [`Any`]: crate::any::Any [`format!`]: ../std/macro.format.html [book]: ../book/ch09-00-error-handling.html +[`std::result`]: ../std/result/index.html # Current implementation diff --git a/library/core/src/ops/function.rs b/library/core/src/ops/function.rs index 8383f9264355..c5a194b7d0a4 100644 --- a/library/core/src/ops/function.rs +++ b/library/core/src/ops/function.rs @@ -60,6 +60,12 @@ Args = "()", note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`" ), + on( + _Self = "unsafe fn", + note = "unsafe function cannot be called generically without an unsafe block", + // SAFETY: tidy is not smart enough to tell that the below unsafe block is a string + label = "call the function in a closure: `|| unsafe {{ /* code */ }}`" + ), message = "expected a `{Fn}<{Args}>` closure, found `{Self}`", label = "expected an `Fn<{Args}>` closure, found `{Self}`" )] @@ -141,6 +147,12 @@ pub trait Fn: FnMut { Args = "()", note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`" ), + on( + _Self = "unsafe fn", + note = "unsafe function cannot be called generically without an unsafe block", + // SAFETY: tidy is not smart enough to tell that the below unsafe block is a string + label = "call the function in a closure: `|| unsafe {{ /* code */ }}`" + ), message = "expected a `{FnMut}<{Args}>` closure, found `{Self}`", label = "expected an `FnMut<{Args}>` closure, found `{Self}`" )] @@ -214,6 +226,12 @@ pub trait FnMut: FnOnce { Args = "()", note = "wrap the `{Self}` in a closure with no arguments: `|| {{ /* code */ }}`" ), + on( + _Self = "unsafe fn", + note = "unsafe function cannot be called generically without an unsafe block", + // SAFETY: tidy is not smart enough to tell that the below unsafe block is a string + label = "call the function in a closure: `|| unsafe {{ /* code */ }}`" + ), message = "expected a `{FnOnce}<{Args}>` closure, found `{Self}`", label = "expected an `FnOnce<{Args}>` closure, found `{Self}`" )] diff --git a/library/std/src/os/unix/net/ancillary.rs b/library/std/src/os/unix/net/ancillary.rs index fb1ff4b725ce..658c79896eb2 100644 --- a/library/std/src/os/unix/net/ancillary.rs +++ b/library/std/src/os/unix/net/ancillary.rs @@ -10,7 +10,7 @@ use crate::slice::from_raw_parts; use crate::sys::net::Socket; // FIXME(#43348): Make libc adapt #[doc(cfg(...))] so we don't need these fake definitions here? -#[cfg(all(doc, not(target_os = "linux"), not(target_os = "android")))] +#[cfg(all(doc, not(target_os = "linux"), not(target_os = "android"), not(target_os = "netbsd")))] #[allow(non_camel_case_types)] mod libc { pub use libc::c_int; @@ -177,13 +177,24 @@ impl<'a, T> Iterator for AncillaryDataIter<'a, T> { } } +#[cfg(all(doc, not(target_os = "android"), not(target_os = "linux"), not(target_os = "netbsd")))] +#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] +#[derive(Clone)] +pub struct SocketCred(()); + /// Unix credential. -#[cfg(any(doc, target_os = "android", target_os = "linux",))] +#[cfg(any(target_os = "android", target_os = "linux",))] #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] #[derive(Clone)] pub struct SocketCred(libc::ucred); -#[cfg(any(doc, target_os = "android", target_os = "linux",))] +#[cfg(target_os = "netbsd")] +#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] +#[derive(Clone)] +pub struct SocketCred(libc::sockcred); + +#[doc(cfg(any(target_os = "android", target_os = "linux")))] +#[cfg(any(target_os = "android", target_os = "linux"))] impl SocketCred { /// Create a Unix credential struct. /// @@ -234,6 +245,61 @@ impl SocketCred { } } +#[cfg(target_os = "netbsd")] +impl SocketCred { + /// Create a Unix credential struct. + /// + /// PID, UID and GID is set to 0. + #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] + pub fn new() -> SocketCred { + SocketCred(libc::sockcred { + sc_pid: 0, + sc_uid: 0, + sc_euid: 0, + sc_gid: 0, + sc_egid: 0, + sc_ngroups: 0, + sc_groups: [0u32; 1], + }) + } + + /// Set the PID. + #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] + pub fn set_pid(&mut self, pid: libc::pid_t) { + self.0.sc_pid = pid; + } + + /// Get the current PID. + #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] + pub fn get_pid(&self) -> libc::pid_t { + self.0.sc_pid + } + + /// Set the UID. + #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] + pub fn set_uid(&mut self, uid: libc::uid_t) { + self.0.sc_uid = uid; + } + + /// Get the current UID. + #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] + pub fn get_uid(&self) -> libc::uid_t { + self.0.sc_uid + } + + /// Set the GID. + #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] + pub fn set_gid(&mut self, gid: libc::gid_t) { + self.0.sc_gid = gid; + } + + /// Get the current GID. + #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] + pub fn get_gid(&self) -> libc::gid_t { + self.0.sc_gid + } +} + /// This control message contains file descriptors. /// /// The level is equal to `SOL_SOCKET` and the type is equal to `SCM_RIGHTS`. @@ -249,14 +315,22 @@ impl<'a> Iterator for ScmRights<'a> { } } +#[cfg(all(doc, not(target_os = "android"), not(target_os = "linux"), not(target_os = "netbsd")))] +#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] +pub struct ScmCredentials<'a>(AncillaryDataIter<'a, ()>); + /// This control message contains unix credentials. /// /// The level is equal to `SOL_SOCKET` and the type is equal to `SCM_CREDENTIALS` or `SCM_CREDS`. -#[cfg(any(doc, target_os = "android", target_os = "linux",))] +#[cfg(any(target_os = "android", target_os = "linux",))] #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub struct ScmCredentials<'a>(AncillaryDataIter<'a, libc::ucred>); -#[cfg(any(doc, target_os = "android", target_os = "linux",))] +#[cfg(target_os = "netbsd")] +#[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] +pub struct ScmCredentials<'a>(AncillaryDataIter<'a, libc::sockcred>); + +#[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "netbsd",))] #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] impl<'a> Iterator for ScmCredentials<'a> { type Item = SocketCred; @@ -278,7 +352,7 @@ pub enum AncillaryError { #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub enum AncillaryData<'a> { ScmRights(ScmRights<'a>), - #[cfg(any(doc, target_os = "android", target_os = "linux",))] + #[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "netbsd",))] ScmCredentials(ScmCredentials<'a>), } @@ -300,8 +374,8 @@ impl<'a> AncillaryData<'a> { /// # Safety /// /// `data` must contain a valid control message and the control message must be type of - /// `SOL_SOCKET` and level of `SCM_CREDENTIALS` or `SCM_CREDENTIALS`. - #[cfg(any(doc, target_os = "android", target_os = "linux",))] + /// `SOL_SOCKET` and level of `SCM_CREDENTIALS` or `SCM_CREDS`. + #[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "netbsd",))] unsafe fn as_credentials(data: &'a [u8]) -> Self { let ancillary_data_iter = AncillaryDataIter::new(data); let scm_credentials = ScmCredentials(ancillary_data_iter); @@ -320,6 +394,8 @@ impl<'a> AncillaryData<'a> { libc::SCM_RIGHTS => Ok(AncillaryData::as_rights(data)), #[cfg(any(target_os = "android", target_os = "linux",))] libc::SCM_CREDENTIALS => Ok(AncillaryData::as_credentials(data)), + #[cfg(target_os = "netbsd")] + libc::SCM_CREDS => Ok(AncillaryData::as_credentials(data)), cmsg_type => { Err(AncillaryError::Unknown { cmsg_level: libc::SOL_SOCKET, cmsg_type }) } @@ -531,7 +607,7 @@ impl<'a> SocketAncillary<'a> { /// Technically, that means this operation adds a control message with the level `SOL_SOCKET` /// and type `SCM_CREDENTIALS` or `SCM_CREDS`. /// - #[cfg(any(doc, target_os = "android", target_os = "linux",))] + #[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "netbsd",))] #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub fn add_creds(&mut self, creds: &[SocketCred]) -> bool { self.truncated = false; @@ -540,7 +616,10 @@ impl<'a> SocketAncillary<'a> { &mut self.length, creds, libc::SOL_SOCKET, + #[cfg(not(target_os = "netbsd"))] libc::SCM_CREDENTIALS, + #[cfg(target_os = "netbsd")] + libc::SCM_CREDS, ) } diff --git a/library/std/src/os/unix/net/datagram.rs b/library/std/src/os/unix/net/datagram.rs index 59c91e9a82e1..872058b36e62 100644 --- a/library/std/src/os/unix/net/datagram.rs +++ b/library/std/src/os/unix/net/datagram.rs @@ -865,7 +865,7 @@ impl UnixDatagram { /// Ok(()) /// } /// ``` - #[cfg(any(doc, target_os = "android", target_os = "linux",))] + #[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "netbsd",))] #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub fn set_passcred(&self, passcred: bool) -> io::Result<()> { self.0.set_passcred(passcred) @@ -877,7 +877,7 @@ impl UnixDatagram { /// Get the socket option `SO_PASSCRED`. /// /// [`set_passcred`]: UnixDatagram::set_passcred - #[cfg(any(doc, target_os = "android", target_os = "linux",))] + #[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "netbsd",))] #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub fn passcred(&self) -> io::Result { self.0.passcred() diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index 3943b4fed094..cd1aa01fa0f1 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -415,7 +415,7 @@ impl UnixStream { /// Ok(()) /// } /// ``` - #[cfg(any(doc, target_os = "android", target_os = "linux",))] + #[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "netbsd",))] #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub fn set_passcred(&self, passcred: bool) -> io::Result<()> { self.0.set_passcred(passcred) @@ -427,7 +427,7 @@ impl UnixStream { /// Get the socket option `SO_PASSCRED`. /// /// [`set_passcred`]: UnixStream::set_passcred - #[cfg(any(doc, target_os = "android", target_os = "linux",))] + #[cfg(any(doc, target_os = "android", target_os = "linux", target_os = "netbsd",))] #[unstable(feature = "unix_socket_ancillary_data", issue = "76915")] pub fn passcred(&self) -> io::Result { self.0.passcred() diff --git a/library/std/src/sync/condvar/tests.rs b/library/std/src/sync/condvar/tests.rs index 6757707cd951..f7a00676daae 100644 --- a/library/std/src/sync/condvar/tests.rs +++ b/library/std/src/sync/condvar/tests.rs @@ -191,7 +191,7 @@ fn wait_timeout_wake() { #[test] #[should_panic] -#[cfg_attr(not(unix), ignore)] +#[cfg(all(unix, not(target_os = "linux"), not(target_os = "android")))] fn two_mutexes() { let m = Arc::new(Mutex::new(())); let m2 = m.clone(); diff --git a/library/std/src/sys/unix/futex.rs b/library/std/src/sys/unix/futex.rs index 42ddc1d514ec..c61d948fb601 100644 --- a/library/std/src/sys/unix/futex.rs +++ b/library/std/src/sys/unix/futex.rs @@ -4,31 +4,46 @@ all(target_os = "emscripten", target_feature = "atomics") ))] -#[cfg(any(target_os = "linux", target_os = "android"))] -use crate::convert::TryInto; -#[cfg(any(target_os = "linux", target_os = "android"))] -use crate::ptr::null; use crate::sync::atomic::AtomicI32; use crate::time::Duration; #[cfg(any(target_os = "linux", target_os = "android"))] -pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option) { - let timespec = timeout.and_then(|d| { - Some(libc::timespec { - // Sleep forever if the timeout is longer than fits in a timespec. - tv_sec: d.as_secs().try_into().ok()?, - // This conversion never truncates, as subsec_nanos is always <1e9. - tv_nsec: d.subsec_nanos() as _, - }) - }); - unsafe { - libc::syscall( - libc::SYS_futex, - futex as *const AtomicI32, - libc::FUTEX_WAIT | libc::FUTEX_PRIVATE_FLAG, - expected, - timespec.as_ref().map_or(null(), |d| d as *const libc::timespec), - ); +pub fn futex_wait(futex: &AtomicI32, expected: i32, timeout: Option) -> bool { + use super::time::Timespec; + use crate::ptr::null; + use crate::sync::atomic::Ordering::Relaxed; + + // Calculate the timeout as an absolute timespec. + // + // Overflows are rounded up to an infinite timeout (None). + let timespec = + timeout.and_then(|d| Some(Timespec::now(libc::CLOCK_MONOTONIC).checked_add_duration(&d)?)); + + loop { + // No need to wait if the value already changed. + if futex.load(Relaxed) != expected { + return true; + } + + // Use FUTEX_WAIT_BITSET rather than FUTEX_WAIT to be able to give an + // absolute time rather than a relative time. + let r = unsafe { + libc::syscall( + libc::SYS_futex, + futex as *const AtomicI32, + libc::FUTEX_WAIT_BITSET | libc::FUTEX_PRIVATE_FLAG, + expected, + timespec.as_ref().map_or(null(), |t| &t.t as *const libc::timespec), + null::(), // This argument is unused for FUTEX_WAIT_BITSET. + !0u32, // A full bitmask, to make it behave like a regular FUTEX_WAIT. + ) + }; + + match (r < 0).then(super::os::errno) { + Some(libc::ETIMEDOUT) => return false, + Some(libc::EINTR) => continue, + _ => return true, + } } } @@ -65,6 +80,18 @@ pub fn futex_wake(futex: &AtomicI32) { } } +#[cfg(any(target_os = "linux", target_os = "android"))] +pub fn futex_wake_all(futex: &AtomicI32) { + unsafe { + libc::syscall( + libc::SYS_futex, + futex as *const AtomicI32, + libc::FUTEX_WAKE | libc::FUTEX_PRIVATE_FLAG, + i32::MAX, + ); + } +} + #[cfg(target_os = "emscripten")] pub fn futex_wake(futex: &AtomicI32) { extern "C" { diff --git a/library/std/src/sys/unix/locks/futex.rs b/library/std/src/sys/unix/locks/futex.rs new file mode 100644 index 000000000000..630351d0dc27 --- /dev/null +++ b/library/std/src/sys/unix/locks/futex.rs @@ -0,0 +1,164 @@ +use crate::sync::atomic::{ + AtomicI32, + Ordering::{Acquire, Relaxed, Release}, +}; +use crate::sys::futex::{futex_wait, futex_wake, futex_wake_all}; +use crate::time::Duration; + +pub type MovableMutex = Mutex; +pub type MovableCondvar = Condvar; + +pub struct Mutex { + /// 0: unlocked + /// 1: locked, no other threads waiting + /// 2: locked, and other threads waiting (contended) + futex: AtomicI32, +} + +impl Mutex { + #[inline] + pub const fn new() -> Self { + Self { futex: AtomicI32::new(0) } + } + + #[inline] + pub unsafe fn init(&mut self) {} + + #[inline] + pub unsafe fn destroy(&self) {} + + #[inline] + pub unsafe fn try_lock(&self) -> bool { + self.futex.compare_exchange(0, 1, Acquire, Relaxed).is_ok() + } + + #[inline] + pub unsafe fn lock(&self) { + if self.futex.compare_exchange(0, 1, Acquire, Relaxed).is_err() { + self.lock_contended(); + } + } + + #[cold] + fn lock_contended(&self) { + // Spin first to speed things up if the lock is released quickly. + let mut state = self.spin(); + + // If it's unlocked now, attempt to take the lock + // without marking it as contended. + if state == 0 { + match self.futex.compare_exchange(0, 1, Acquire, Relaxed) { + Ok(_) => return, // Locked! + Err(s) => state = s, + } + } + + loop { + // Put the lock in contended state. + // We avoid an unnecessary write if it as already set to 2, + // to be friendlier for the caches. + if state != 2 && self.futex.swap(2, Acquire) == 0 { + // We changed it from 0 to 2, so we just succesfully locked it. + return; + } + + // Wait for the futex to change state, assuming it is still 2. + futex_wait(&self.futex, 2, None); + + // Spin again after waking up. + state = self.spin(); + } + } + + fn spin(&self) -> i32 { + let mut spin = 100; + loop { + // We only use `load` (and not `swap` or `compare_exchange`) + // while spinning, to be easier on the caches. + let state = self.futex.load(Relaxed); + + // We stop spinning when the mutex is unlocked (0), + // but also when it's contended (2). + if state != 1 || spin == 0 { + return state; + } + + crate::hint::spin_loop(); + spin -= 1; + } + } + + #[inline] + pub unsafe fn unlock(&self) { + if self.futex.swap(0, Release) == 2 { + // We only wake up one thread. When that thread locks the mutex, it + // will mark the mutex as contended (2) (see lock_contended above), + // which makes sure that any other waiting threads will also be + // woken up eventually. + self.wake(); + } + } + + #[cold] + fn wake(&self) { + futex_wake(&self.futex); + } +} + +pub struct Condvar { + // The value of this atomic is simply incremented on every notification. + // This is used by `.wait()` to not miss any notifications after + // unlocking the mutex and before waiting for notifications. + futex: AtomicI32, +} + +impl Condvar { + #[inline] + pub const fn new() -> Self { + Self { futex: AtomicI32::new(0) } + } + + #[inline] + pub unsafe fn init(&mut self) {} + + #[inline] + pub unsafe fn destroy(&self) {} + + // All the memory orderings here are `Relaxed`, + // because synchronization is done by unlocking and locking the mutex. + + pub unsafe fn notify_one(&self) { + self.futex.fetch_add(1, Relaxed); + futex_wake(&self.futex); + } + + pub unsafe fn notify_all(&self) { + self.futex.fetch_add(1, Relaxed); + futex_wake_all(&self.futex); + } + + pub unsafe fn wait(&self, mutex: &Mutex) { + self.wait_optional_timeout(mutex, None); + } + + pub unsafe fn wait_timeout(&self, mutex: &Mutex, timeout: Duration) -> bool { + self.wait_optional_timeout(mutex, Some(timeout)) + } + + unsafe fn wait_optional_timeout(&self, mutex: &Mutex, timeout: Option) -> bool { + // Examine the notification counter _before_ we unlock the mutex. + let futex_value = self.futex.load(Relaxed); + + // Unlock the mutex before going to sleep. + mutex.unlock(); + + // Wait, but only if there hasn't been any + // notification since we unlocked the mutex. + let r = futex_wait(&self.futex, futex_value, timeout); + + // Lock the mutex again. + mutex.lock(); + + r + } +} diff --git a/library/std/src/sys/unix/locks/mod.rs b/library/std/src/sys/unix/locks/mod.rs index f07a9f93b79a..30e9f407eec4 100644 --- a/library/std/src/sys/unix/locks/mod.rs +++ b/library/std/src/sys/unix/locks/mod.rs @@ -1,8 +1,24 @@ -mod pthread_condvar; -mod pthread_mutex; -mod pthread_remutex; -mod pthread_rwlock; -pub use pthread_condvar::{Condvar, MovableCondvar}; -pub use pthread_mutex::{MovableMutex, Mutex}; -pub use pthread_remutex::ReentrantMutex; -pub use pthread_rwlock::{MovableRWLock, RWLock}; +cfg_if::cfg_if! { + if #[cfg(any( + target_os = "linux", + target_os = "android", + ))] { + mod futex; + #[allow(dead_code)] + mod pthread_mutex; // Only used for PthreadMutexAttr, needed by pthread_remutex. + mod pthread_remutex; // FIXME: Implement this using a futex + mod pthread_rwlock; // FIXME: Implement this using a futex + pub use futex::{Mutex, MovableMutex, Condvar, MovableCondvar}; + pub use pthread_remutex::ReentrantMutex; + pub use pthread_rwlock::{RWLock, MovableRWLock}; + } else { + mod pthread_mutex; + mod pthread_remutex; + mod pthread_rwlock; + mod pthread_condvar; + pub use pthread_mutex::{Mutex, MovableMutex}; + pub use pthread_remutex::ReentrantMutex; + pub use pthread_rwlock::{RWLock, MovableRWLock}; + pub use pthread_condvar::{Condvar, MovableCondvar}; + } +} diff --git a/library/std/src/sys/unix/net.rs b/library/std/src/sys/unix/net.rs index e6fd9a0c827e..9bf9607a63e4 100644 --- a/library/std/src/sys/unix/net.rs +++ b/library/std/src/sys/unix/net.rs @@ -419,6 +419,17 @@ impl Socket { Ok(passcred != 0) } + #[cfg(target_os = "netbsd")] + pub fn set_passcred(&self, passcred: bool) -> io::Result<()> { + setsockopt(self, 0 as libc::c_int, libc::LOCAL_CREDS, passcred as libc::c_int) + } + + #[cfg(target_os = "netbsd")] + pub fn passcred(&self) -> io::Result { + let passcred: libc::c_int = getsockopt(self, 0 as libc::c_int, libc::LOCAL_CREDS)?; + Ok(passcred != 0) + } + #[cfg(not(any(target_os = "solaris", target_os = "illumos")))] pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { let mut nonblocking = nonblocking as libc::c_int; diff --git a/library/std/src/sys/unix/time.rs b/library/std/src/sys/unix/time.rs index 59ddd1aa92f8..498c94d0cdcb 100644 --- a/library/std/src/sys/unix/time.rs +++ b/library/std/src/sys/unix/time.rs @@ -9,8 +9,8 @@ use crate::convert::TryInto; const NSEC_PER_SEC: u64 = 1_000_000_000; #[derive(Copy, Clone)] -struct Timespec { - t: libc::timespec, +pub(in crate::sys::unix) struct Timespec { + pub t: libc::timespec, } impl Timespec { @@ -18,7 +18,7 @@ impl Timespec { Timespec { t: libc::timespec { tv_sec: 0, tv_nsec: 0 } } } - fn sub_timespec(&self, other: &Timespec) -> Result { + pub fn sub_timespec(&self, other: &Timespec) -> Result { if self >= other { // NOTE(eddyb) two aspects of this `if`-`else` are required for LLVM // to optimize it into a branchless form (see also #75545): @@ -51,7 +51,7 @@ impl Timespec { } } - fn checked_add_duration(&self, other: &Duration) -> Option { + pub fn checked_add_duration(&self, other: &Duration) -> Option { let mut secs = other .as_secs() .try_into() // <- target type would be `libc::time_t` @@ -68,7 +68,7 @@ impl Timespec { Some(Timespec { t: libc::timespec { tv_sec: secs, tv_nsec: nsec as _ } }) } - fn checked_sub_duration(&self, other: &Duration) -> Option { + pub fn checked_sub_duration(&self, other: &Duration) -> Option { let mut secs = other .as_secs() .try_into() // <- target type would be `libc::time_t` @@ -266,6 +266,7 @@ mod inner { #[cfg(not(any(target_os = "macos", target_os = "ios")))] mod inner { use crate::fmt; + use crate::mem::MaybeUninit; use crate::sys::cvt; use crate::time::Duration; @@ -285,7 +286,7 @@ mod inner { impl Instant { pub fn now() -> Instant { - Instant { t: now(libc::CLOCK_MONOTONIC) } + Instant { t: Timespec::now(libc::CLOCK_MONOTONIC) } } pub fn checked_sub_instant(&self, other: &Instant) -> Option { @@ -312,7 +313,7 @@ mod inner { impl SystemTime { pub fn now() -> SystemTime { - SystemTime { t: now(libc::CLOCK_REALTIME) } + SystemTime { t: Timespec::now(libc::CLOCK_REALTIME) } } pub fn sub_time(&self, other: &SystemTime) -> Result { @@ -348,9 +349,11 @@ mod inner { #[cfg(any(target_os = "dragonfly", target_os = "espidf"))] pub type clock_t = libc::c_ulong; - fn now(clock: clock_t) -> Timespec { - let mut t = Timespec { t: libc::timespec { tv_sec: 0, tv_nsec: 0 } }; - cvt(unsafe { libc::clock_gettime(clock, &mut t.t) }).unwrap(); - t + impl Timespec { + pub fn now(clock: clock_t) -> Timespec { + let mut t = MaybeUninit::uninit(); + cvt(unsafe { libc::clock_gettime(clock, t.as_mut_ptr()) }).unwrap(); + Timespec { t: unsafe { t.assume_init() } } + } } } diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 3ad376b8a2ca..99d7475da339 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1769,7 +1769,7 @@ fn document_type_layout(w: &mut Buffer, cx: &Context<'_>, ty_def_id: DefId) { let tag_size = if let TagEncoding::Niche { .. } = tag_encoding { 0 - } else if let Primitive::Int(i, _) = tag.value { + } else if let Primitive::Int(i, _) = tag.primitive() { i.size().bytes() } else { span_bug!(tcx.def_span(ty_def_id), "tag is neither niche nor int") diff --git a/src/test/mir-opt/const_prop/invalid_constant.main.ConstProp.diff b/src/test/mir-opt/const_prop/invalid_constant.main.ConstProp.diff index f2a1b9d69e1a..cf6d8a52a766 100644 --- a/src/test/mir-opt/const_prop/invalid_constant.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/invalid_constant.main.ConstProp.diff @@ -3,56 +3,70 @@ fn main() -> () { let mut _0: (); // return place in scope 0 at $DIR/invalid_constant.rs:15:11: 15:11 - let _1: main::InvalidChar; // in scope 0 at $DIR/invalid_constant.rs:21:9: 21:22 - let mut _3: main::InvalidTag; // in scope 0 at $DIR/invalid_constant.rs:28:25: 28:46 - let mut _5: main::NoVariants; // in scope 0 at $DIR/invalid_constant.rs:35:35: 35:56 + let _1: char; // in scope 0 at $DIR/invalid_constant.rs:21:9: 21:22 + let mut _2: main::InvalidChar; // in scope 0 at $DIR/invalid_constant.rs:21:34: 21:63 + let mut _4: E; // in scope 0 at $DIR/invalid_constant.rs:28:25: 28:59 + let mut _5: main::InvalidTag; // in scope 0 at $DIR/invalid_constant.rs:28:34: 28:55 + let mut _7: Empty; // in scope 0 at $DIR/invalid_constant.rs:35:35: 35:73 + let mut _8: main::NoVariants; // in scope 0 at $DIR/invalid_constant.rs:35:44: 35:65 scope 1 { debug _invalid_char => _1; // in scope 1 at $DIR/invalid_constant.rs:21:9: 21:22 - let _2: [main::InvalidTag; 1]; // in scope 1 at $DIR/invalid_constant.rs:28:9: 28:21 - scope 2 { - debug _invalid_tag => _2; // in scope 2 at $DIR/invalid_constant.rs:28:9: 28:21 - let _4: [main::NoVariants; 1]; // in scope 2 at $DIR/invalid_constant.rs:35:9: 35:31 - scope 3 { - debug _enum_without_variants => _4; // in scope 3 at $DIR/invalid_constant.rs:35:9: 35:31 - let _6: main::Str<"���">; // in scope 3 at $DIR/invalid_constant.rs:39:9: 39:22 - scope 4 { - debug _non_utf8_str => _6; // in scope 4 at $DIR/invalid_constant.rs:39:9: 39:22 + let _3: [E; 1]; // in scope 1 at $DIR/invalid_constant.rs:28:9: 28:21 + scope 3 { + debug _invalid_tag => _3; // in scope 3 at $DIR/invalid_constant.rs:28:9: 28:21 + let _6: [Empty; 1]; // in scope 3 at $DIR/invalid_constant.rs:35:9: 35:31 + scope 5 { + debug _enum_without_variants => _6; // in scope 5 at $DIR/invalid_constant.rs:35:9: 35:31 + let _9: main::Str<"���">; // in scope 5 at $DIR/invalid_constant.rs:39:9: 39:22 + scope 7 { + debug _non_utf8_str => _9; // in scope 7 at $DIR/invalid_constant.rs:39:9: 39:22 } } + scope 6 { + } } + scope 4 { + } + } + scope 2 { } bb0: { StorageLive(_1); // scope 0 at $DIR/invalid_constant.rs:21:9: 21:22 -- _1 = const { InvalidChar { int: 0x110001 } }; // scope 0 at $DIR/invalid_constant.rs:21:25: 21:64 -+ _1 = const InvalidChar { int: 1114113_u32, chr: {transmute(0x00110001): char} }; // scope 0 at $DIR/invalid_constant.rs:21:25: 21:64 - // mir::Constant - // + span: $DIR/invalid_constant.rs:21:25: 21:64 -- // + literal: Const { ty: InvalidChar, val: Unevaluated(main::{constant#0}, [main::InvalidChar], None) } -+ // + literal: Const { ty: InvalidChar, val: Value(Scalar(0x00110001)) } - StorageLive(_2); // scope 1 at $DIR/invalid_constant.rs:28:9: 28:21 - StorageLive(_3); // scope 1 at $DIR/invalid_constant.rs:28:25: 28:46 - (_3.0: u32) = const 4_u32; // scope 1 at $DIR/invalid_constant.rs:28:25: 28:46 -- _2 = [move _3]; // scope 1 at $DIR/invalid_constant.rs:28:24: 28:47 -+ _2 = [const InvalidTag { int: 4_u32, e: Scalar(0x00000004): E }]; // scope 1 at $DIR/invalid_constant.rs:28:24: 28:47 + StorageLive(_2); // scope 2 at $DIR/invalid_constant.rs:21:34: 21:63 + (_2.0: u32) = const 1114113_u32; // scope 2 at $DIR/invalid_constant.rs:21:34: 21:63 +- _1 = (_2.1: char); // scope 2 at $DIR/invalid_constant.rs:21:34: 21:67 ++ _1 = const {transmute(0x00110001): char}; // scope 2 at $DIR/invalid_constant.rs:21:34: 21:67 + StorageDead(_2); // scope 0 at $DIR/invalid_constant.rs:21:69: 21:70 + StorageLive(_3); // scope 1 at $DIR/invalid_constant.rs:28:9: 28:21 + StorageLive(_4); // scope 1 at $DIR/invalid_constant.rs:28:25: 28:59 + StorageLive(_5); // scope 4 at $DIR/invalid_constant.rs:28:34: 28:55 + (_5.0: u32) = const 4_u32; // scope 4 at $DIR/invalid_constant.rs:28:34: 28:55 +- _4 = (_5.1: E); // scope 4 at $DIR/invalid_constant.rs:28:34: 28:57 +- _3 = [move _4]; // scope 1 at $DIR/invalid_constant.rs:28:24: 28:60 ++ _4 = const Scalar(0x00000004): E; // scope 4 at $DIR/invalid_constant.rs:28:34: 28:57 + // mir::Constant -+ // + span: $DIR/invalid_constant.rs:28:24: 28:47 -+ // + literal: Const { ty: InvalidTag, val: Value(Scalar(0x00000004)) } - StorageDead(_3); // scope 1 at $DIR/invalid_constant.rs:28:46: 28:47 - StorageLive(_4); // scope 2 at $DIR/invalid_constant.rs:35:9: 35:31 - StorageLive(_5); // scope 2 at $DIR/invalid_constant.rs:35:35: 35:56 - (_5.0: u32) = const 0_u32; // scope 2 at $DIR/invalid_constant.rs:35:35: 35:56 -- _4 = [move _5]; // scope 2 at $DIR/invalid_constant.rs:35:34: 35:57 -+ _4 = [const NoVariants { int: 0_u32, empty: Scalar(): Empty }]; // scope 2 at $DIR/invalid_constant.rs:35:34: 35:57 ++ // + span: $DIR/invalid_constant.rs:28:34: 28:57 ++ // + literal: Const { ty: E, val: Value(Scalar(0x00000004)) } ++ _3 = [const Scalar(0x00000004): E]; // scope 1 at $DIR/invalid_constant.rs:28:24: 28:60 + // mir::Constant -+ // + span: $DIR/invalid_constant.rs:35:34: 35:57 -+ // + literal: Const { ty: NoVariants, val: Value(Scalar(0x00000000)) } - StorageDead(_5); // scope 2 at $DIR/invalid_constant.rs:35:56: 35:57 - StorageLive(_6); // scope 3 at $DIR/invalid_constant.rs:39:9: 39:22 ++ // + span: $DIR/invalid_constant.rs:28:24: 28:60 ++ // + literal: Const { ty: E, val: Value(Scalar(0x00000004)) } + StorageDead(_4); // scope 1 at $DIR/invalid_constant.rs:28:59: 28:60 + StorageDead(_5); // scope 1 at $DIR/invalid_constant.rs:28:60: 28:61 + StorageLive(_6); // scope 3 at $DIR/invalid_constant.rs:35:9: 35:31 + StorageLive(_7); // scope 3 at $DIR/invalid_constant.rs:35:35: 35:73 + StorageLive(_8); // scope 6 at $DIR/invalid_constant.rs:35:44: 35:65 + (_8.0: u32) = const 0_u32; // scope 6 at $DIR/invalid_constant.rs:35:44: 35:65 + nop; // scope 6 at $DIR/invalid_constant.rs:35:44: 35:71 + nop; // scope 3 at $DIR/invalid_constant.rs:35:34: 35:74 + StorageDead(_7); // scope 3 at $DIR/invalid_constant.rs:35:73: 35:74 + StorageDead(_8); // scope 3 at $DIR/invalid_constant.rs:35:74: 35:75 + StorageLive(_9); // scope 5 at $DIR/invalid_constant.rs:39:9: 39:22 nop; // scope 0 at $DIR/invalid_constant.rs:15:11: 42:2 + StorageDead(_9); // scope 5 at $DIR/invalid_constant.rs:42:1: 42:2 StorageDead(_6); // scope 3 at $DIR/invalid_constant.rs:42:1: 42:2 - StorageDead(_4); // scope 2 at $DIR/invalid_constant.rs:42:1: 42:2 - StorageDead(_2); // scope 1 at $DIR/invalid_constant.rs:42:1: 42:2 + StorageDead(_3); // scope 1 at $DIR/invalid_constant.rs:42:1: 42:2 StorageDead(_1); // scope 0 at $DIR/invalid_constant.rs:42:1: 42:2 return; // scope 0 at $DIR/invalid_constant.rs:42:2: 42:2 } diff --git a/src/test/mir-opt/const_prop/invalid_constant.rs b/src/test/mir-opt/const_prop/invalid_constant.rs index 492ef404916d..0337a7ca8511 100644 --- a/src/test/mir-opt/const_prop/invalid_constant.rs +++ b/src/test/mir-opt/const_prop/invalid_constant.rs @@ -18,21 +18,21 @@ fn main() { int: u32, chr: char, } - let _invalid_char = const { InvalidChar { int: 0x110001 } }; + let _invalid_char = unsafe { InvalidChar { int: 0x110001 }.chr }; // An enum with an invalid tag. Regression test for #93688. union InvalidTag { int: u32, e: E, } - let _invalid_tag = [InvalidTag { int: 4 }]; + let _invalid_tag = [unsafe { InvalidTag { int: 4 }.e }]; // An enum without variants. Regression test for #94073. union NoVariants { int: u32, empty: Empty, } - let _enum_without_variants = [NoVariants { int: 0 }]; + let _enum_without_variants = [unsafe { NoVariants { int: 0 }.empty }]; // A non-UTF-8 string slice. Regression test for #75763 and #78520. struct Str; diff --git a/src/test/rustdoc-ui/intra-doc/global-path.rs b/src/test/rustdoc-ui/intra-doc/global-path.rs new file mode 100644 index 000000000000..cc7a5fa1c737 --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/global-path.rs @@ -0,0 +1,8 @@ +// Doc link path with empty prefix that resolves to "extern prelude" instead of a module. + +// check-pass +// edition:2018 + +/// [::Unresolved] +//~^ WARN unresolved link to `::Unresolved` +pub struct Item; diff --git a/src/test/rustdoc-ui/intra-doc/global-path.stderr b/src/test/rustdoc-ui/intra-doc/global-path.stderr new file mode 100644 index 000000000000..02379cd6cdf6 --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/global-path.stderr @@ -0,0 +1,10 @@ +warning: unresolved link to `::Unresolved` + --> $DIR/global-path.rs:6:6 + | +LL | /// [::Unresolved] + | ^^^^^^^^^^^^ no item named `` in scope + | + = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default + +warning: 1 warning emitted + diff --git a/src/test/ui/array-slice-vec/repeat_empty_ok.stderr b/src/test/ui/array-slice-vec/repeat_empty_ok.stderr index 85baa1268bf0..eba1a8e2278b 100644 --- a/src/test/ui/array-slice-vec/repeat_empty_ok.stderr +++ b/src/test/ui/array-slice-vec/repeat_empty_ok.stderr @@ -5,6 +5,10 @@ LL | let headers = [Header{value: &[]}; 128]; | ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Header<'_>` | = note: the `Copy` trait is required because the repeated element will be copied +help: consider annotating `Header<'_>` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error[E0277]: the trait bound `Header<'_>: Copy` is not satisfied --> $DIR/repeat_empty_ok.rs:13:19 @@ -13,6 +17,10 @@ LL | let headers = [Header{value: &[0]}; 128]; | ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Header<'_>` | = note: the `Copy` trait is required because the repeated element will be copied +help: consider annotating `Header<'_>` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to 2 previous errors diff --git a/src/test/ui/associated-types/defaults-suitability.stderr b/src/test/ui/associated-types/defaults-suitability.stderr index 6c63c01e2c2f..43541c5dfbcb 100644 --- a/src/test/ui/associated-types/defaults-suitability.stderr +++ b/src/test/ui/associated-types/defaults-suitability.stderr @@ -9,6 +9,10 @@ note: required by a bound in `Tr::Ty` | LL | type Ty: Clone = NotClone; | ^^^^^ required by this bound in `Tr::Ty` +help: consider annotating `NotClone` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error[E0277]: the trait bound `NotClone: Clone` is not satisfied --> $DIR/defaults-suitability.rs:22:15 @@ -24,6 +28,10 @@ LL | Self::Ty: Clone, LL | { LL | type Ty = NotClone; | -- required by a bound in this +help: consider annotating `NotClone` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error[E0277]: the trait bound `T: Clone` is not satisfied --> $DIR/defaults-suitability.rs:28:23 diff --git a/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr b/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr index 558b0f5c8a36..0edc9a556b7f 100644 --- a/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr +++ b/src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr @@ -8,7 +8,7 @@ note: required by a bound in `Add` --> $SRC_DIR/core/src/ops/arith.rs:LL:COL | LL | pub trait Add { - | ^^^ required by this bound in `Add` + | ^^^^^^^^^^ required by this bound in `Add` help: consider further restricting `Self` | LL | trait ArithmeticOps: Add + Sub + Mul + Div + Sized {} diff --git a/src/test/ui/async-await/issues/issue-78654.full.stderr b/src/test/ui/async-await/issues/issue-78654.full.stderr index a9208ade7406..0d12a948c68b 100644 --- a/src/test/ui/async-await/issues/issue-78654.full.stderr +++ b/src/test/ui/async-await/issues/issue-78654.full.stderr @@ -5,10 +5,10 @@ LL | impl Foo { | ^^^^^^^ not a type error[E0207]: the const parameter `H` is not constrained by the impl trait, self type, or predicates - --> $DIR/issue-78654.rs:9:12 + --> $DIR/issue-78654.rs:9:6 | LL | impl Foo { - | ^ unconstrained const parameter + | ^^^^^^^^^^^^^^^^ unconstrained const parameter | = note: expressions using a const parameter must map each value to a distinct output value = note: proving the result of expressions other than the parameter are unique is not supported diff --git a/src/test/ui/async-await/issues/issue-78654.min.stderr b/src/test/ui/async-await/issues/issue-78654.min.stderr index a9208ade7406..0d12a948c68b 100644 --- a/src/test/ui/async-await/issues/issue-78654.min.stderr +++ b/src/test/ui/async-await/issues/issue-78654.min.stderr @@ -5,10 +5,10 @@ LL | impl Foo { | ^^^^^^^ not a type error[E0207]: the const parameter `H` is not constrained by the impl trait, self type, or predicates - --> $DIR/issue-78654.rs:9:12 + --> $DIR/issue-78654.rs:9:6 | LL | impl Foo { - | ^ unconstrained const parameter + | ^^^^^^^^^^^^^^^^ unconstrained const parameter | = note: expressions using a const parameter must map each value to a distinct output value = note: proving the result of expressions other than the parameter are unique is not supported diff --git a/src/test/ui/closures/coerce-unsafe-to-closure.stderr b/src/test/ui/closures/coerce-unsafe-to-closure.stderr index 883348eb98c7..bd095c2d83d8 100644 --- a/src/test/ui/closures/coerce-unsafe-to-closure.stderr +++ b/src/test/ui/closures/coerce-unsafe-to-closure.stderr @@ -2,11 +2,12 @@ error[E0277]: expected a `FnOnce<(&str,)>` closure, found `unsafe extern "rust-i --> $DIR/coerce-unsafe-to-closure.rs:2:44 | LL | let x: Option<&[u8]> = Some("foo").map(std::mem::transmute); - | --- ^^^^^^^^^^^^^^^^^^^ expected an `FnOnce<(&str,)>` closure, found `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}` + | --- ^^^^^^^^^^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` | | | required by a bound introduced by this call | = help: the trait `FnOnce<(&str,)>` is not implemented for `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}` + = note: unsafe function cannot be called generically without an unsafe block note: required by a bound in `Option::::map` --> $SRC_DIR/core/src/option.rs:LL:COL | diff --git a/src/test/ui/const-generics/defaults/default-on-impl.stderr b/src/test/ui/const-generics/defaults/default-on-impl.stderr index ddfc0ead8ad8..4b2b05742538 100644 --- a/src/test/ui/const-generics/defaults/default-on-impl.stderr +++ b/src/test/ui/const-generics/defaults/default-on-impl.stderr @@ -1,8 +1,8 @@ error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions - --> $DIR/default-on-impl.rs:3:12 + --> $DIR/default-on-impl.rs:3:6 | LL | impl Foo {} - | ^ + | ^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/const-generics/generic_const_exprs/issue-76595.stderr b/src/test/ui/const-generics/generic_const_exprs/issue-76595.stderr index 3b69a4066a9e..c587a7e153fe 100644 --- a/src/test/ui/const-generics/generic_const_exprs/issue-76595.stderr +++ b/src/test/ui/const-generics/generic_const_exprs/issue-76595.stderr @@ -10,7 +10,7 @@ note: function defined here, with 2 generic parameters: `T`, `P` --> $DIR/issue-76595.rs:10:4 | LL | fn test() where Bool<{core::mem::size_of::() > 4}>: True { - | ^^^^ - - + | ^^^^ - -------------- help: add missing generic argument | LL | test::<2, P>(); diff --git a/src/test/ui/const-generics/incorrect-number-of-const-args.stderr b/src/test/ui/const-generics/incorrect-number-of-const-args.stderr index bf873dacd98e..a845454f762c 100644 --- a/src/test/ui/const-generics/incorrect-number-of-const-args.stderr +++ b/src/test/ui/const-generics/incorrect-number-of-const-args.stderr @@ -10,7 +10,7 @@ note: function defined here, with 2 generic parameters: `X`, `Y` --> $DIR/incorrect-number-of-const-args.rs:1:4 | LL | fn foo() -> usize { - | ^^^ - - + | ^^^ -------------- -------------- help: add missing generic argument | LL | foo::<0, Y>(); @@ -28,7 +28,7 @@ note: function defined here, with 2 generic parameters: `X`, `Y` --> $DIR/incorrect-number-of-const-args.rs:1:4 | LL | fn foo() -> usize { - | ^^^ - - + | ^^^ -------------- -------------- error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/issues/issue-68366.full.stderr b/src/test/ui/const-generics/issues/issue-68366.full.stderr index 4015fb090b93..ca9eb801dfce 100644 --- a/src/test/ui/const-generics/issues/issue-68366.full.stderr +++ b/src/test/ui/const-generics/issues/issue-68366.full.stderr @@ -1,17 +1,17 @@ error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates - --> $DIR/issue-68366.rs:11:13 + --> $DIR/issue-68366.rs:11:7 | LL | impl Collatz<{Some(N)}> {} - | ^ unconstrained const parameter + | ^^^^^^^^^^^^^^ unconstrained const parameter | = note: expressions using a const parameter must map each value to a distinct output value = note: proving the result of expressions other than the parameter are unique is not supported error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates - --> $DIR/issue-68366.rs:17:12 + --> $DIR/issue-68366.rs:17:6 | LL | impl Foo {} - | ^ unconstrained const parameter + | ^^^^^^^^^^^^^^ unconstrained const parameter | = note: expressions using a const parameter must map each value to a distinct output value = note: proving the result of expressions other than the parameter are unique is not supported diff --git a/src/test/ui/const-generics/issues/issue-68366.min.stderr b/src/test/ui/const-generics/issues/issue-68366.min.stderr index 9f370b0f510f..3740ced90b1d 100644 --- a/src/test/ui/const-generics/issues/issue-68366.min.stderr +++ b/src/test/ui/const-generics/issues/issue-68366.min.stderr @@ -8,19 +8,19 @@ LL | impl Collatz<{Some(N)}> {} = help: use `#![feature(generic_const_exprs)]` to allow generic const expressions error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates - --> $DIR/issue-68366.rs:11:13 + --> $DIR/issue-68366.rs:11:7 | LL | impl Collatz<{Some(N)}> {} - | ^ unconstrained const parameter + | ^^^^^^^^^^^^^^ unconstrained const parameter | = note: expressions using a const parameter must map each value to a distinct output value = note: proving the result of expressions other than the parameter are unique is not supported error[E0207]: the const parameter `N` is not constrained by the impl trait, self type, or predicates - --> $DIR/issue-68366.rs:17:12 + --> $DIR/issue-68366.rs:17:6 | LL | impl Foo {} - | ^ unconstrained const parameter + | ^^^^^^^^^^^^^^ unconstrained const parameter | = note: expressions using a const parameter must map each value to a distinct output value = note: proving the result of expressions other than the parameter are unique is not supported diff --git a/src/test/ui/const-generics/issues/issue-86820.stderr b/src/test/ui/const-generics/issues/issue-86820.stderr index f4396f2f2b0a..f7b8d80eeca7 100644 --- a/src/test/ui/const-generics/issues/issue-86820.stderr +++ b/src/test/ui/const-generics/issues/issue-86820.stderr @@ -1,14 +1,14 @@ error[E0053]: method `bit` has an incompatible const parameter type for trait - --> $DIR/issue-86820.rs:17:18 + --> $DIR/issue-86820.rs:17:12 | LL | fn bit(self) -> bool { - | ^ + | ^^^^^^^^^^^^^^^ | note: the const parameter `I` has type `usize`, but the declaration in trait `Bits::bit` has type `u8` - --> $DIR/issue-86820.rs:12:18 + --> $DIR/issue-86820.rs:12:12 | LL | fn bit(self) -> bool; - | ^ + | ^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/const-generics/min_const_generics/default_function_param.stderr b/src/test/ui/const-generics/min_const_generics/default_function_param.stderr index 07dcd57dab8c..dedad2880c9e 100644 --- a/src/test/ui/const-generics/min_const_generics/default_function_param.stderr +++ b/src/test/ui/const-generics/min_const_generics/default_function_param.stderr @@ -1,8 +1,8 @@ error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions - --> $DIR/default_function_param.rs:3:14 + --> $DIR/default_function_param.rs:3:8 | LL | fn foo() {} - | ^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/const-generics/parser-error-recovery/issue-89013-no-kw.stderr b/src/test/ui/const-generics/parser-error-recovery/issue-89013-no-kw.stderr index 59ba054aa112..acfdde8e1a01 100644 --- a/src/test/ui/const-generics/parser-error-recovery/issue-89013-no-kw.stderr +++ b/src/test/ui/const-generics/parser-error-recovery/issue-89013-no-kw.stderr @@ -17,7 +17,7 @@ note: trait defined here, with 1 generic parameter: `N` --> $DIR/issue-89013-no-kw.rs:1:7 | LL | trait Foo { - | ^^^ - + | ^^^ -------------- help: add missing generic argument | LL | impl Foo for Bar { diff --git a/src/test/ui/const-generics/parser-error-recovery/issue-89013.stderr b/src/test/ui/const-generics/parser-error-recovery/issue-89013.stderr index 9d4739926700..d2d58c496df2 100644 --- a/src/test/ui/const-generics/parser-error-recovery/issue-89013.stderr +++ b/src/test/ui/const-generics/parser-error-recovery/issue-89013.stderr @@ -29,7 +29,7 @@ note: trait defined here, with 1 generic parameter: `N` --> $DIR/issue-89013.rs:1:7 | LL | trait Foo { - | ^^^ - + | ^^^ -------------- help: add missing generic argument | LL | impl Foo for Bar { diff --git a/src/test/ui/consts/issue-69488.rs b/src/test/ui/consts/issue-69488.rs new file mode 100644 index 000000000000..46546eada7aa --- /dev/null +++ b/src/test/ui/consts/issue-69488.rs @@ -0,0 +1,34 @@ +// run-pass + +#![feature(const_ptr_write)] +#![feature(const_mut_refs)] + +// Or, equivalently: `MaybeUninit`. +pub union BagOfBits { + uninit: (), + _storage: T, +} + +pub const fn make_1u8_bag() -> BagOfBits { + assert!(core::mem::size_of::() >= 1); + let mut bag = BagOfBits { uninit: () }; + unsafe { (&mut bag as *mut _ as *mut u8).write(1); }; + bag +} + +pub fn check_bag(bag: &BagOfBits) { + let val = unsafe { (bag as *const _ as *const u8).read() }; + assert_eq!(val, 1); +} + +fn main() { + check_bag(&make_1u8_bag::<[usize; 1]>()); // Fine + check_bag(&make_1u8_bag::()); // Fine + + const CONST_ARRAY_BAG: BagOfBits<[usize; 1]> = make_1u8_bag(); + check_bag(&CONST_ARRAY_BAG); // Fine. + const CONST_USIZE_BAG: BagOfBits = make_1u8_bag(); + + // Used to panic since CTFE would make the entire `BagOfBits` uninit + check_bag(&CONST_USIZE_BAG); +} diff --git a/src/test/ui/consts/issue-94371.rs b/src/test/ui/consts/issue-94371.rs new file mode 100644 index 000000000000..de9ff730b66f --- /dev/null +++ b/src/test/ui/consts/issue-94371.rs @@ -0,0 +1,16 @@ +// check-pass + +#![feature(const_swap)] +#![feature(const_mut_refs)] + +#[repr(C)] +struct Demo(u64, bool, u64, u32, u64, u64, u64); + +const C: (Demo, Demo) = { + let mut x = Demo(1, true, 3, 4, 5, 6, 7); + let mut y = Demo(10, false, 12, 13, 14, 15, 16); + std::mem::swap(&mut x, &mut y); + (x, y) +}; + +fn main() {} diff --git a/src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr index cc874576cb7b..7326324b03cc 100644 --- a/src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr +++ b/src/test/ui/derives/derives-span-Clone-enum-struct-variant.stderr @@ -8,6 +8,10 @@ LL | x: Error | ^^^^^^^^ the trait `Clone` is not implemented for `Error` | = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Clone-enum.stderr b/src/test/ui/derives/derives-span-Clone-enum.stderr index a4870635de87..229a4f7d9ff9 100644 --- a/src/test/ui/derives/derives-span-Clone-enum.stderr +++ b/src/test/ui/derives/derives-span-Clone-enum.stderr @@ -8,6 +8,10 @@ LL | Error | ^^^^^ the trait `Clone` is not implemented for `Error` | = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Clone-struct.stderr b/src/test/ui/derives/derives-span-Clone-struct.stderr index 4507eeccc3ae..96bad9edad94 100644 --- a/src/test/ui/derives/derives-span-Clone-struct.stderr +++ b/src/test/ui/derives/derives-span-Clone-struct.stderr @@ -8,6 +8,10 @@ LL | x: Error | ^^^^^^^^ the trait `Clone` is not implemented for `Error` | = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Clone-tuple-struct.stderr b/src/test/ui/derives/derives-span-Clone-tuple-struct.stderr index a79be7f574d6..b61341e57e67 100644 --- a/src/test/ui/derives/derives-span-Clone-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-Clone-tuple-struct.stderr @@ -8,6 +8,10 @@ LL | Error | ^^^^^ the trait `Clone` is not implemented for `Error` | = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Debug-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Debug-enum-struct-variant.stderr index bdcbbf0c7578..58a64a4f53bf 100644 --- a/src/test/ui/derives/derives-span-Debug-enum-struct-variant.stderr +++ b/src/test/ui/derives/derives-span-Debug-enum-struct-variant.stderr @@ -10,6 +10,10 @@ LL | x: Error = help: the trait `Debug` is not implemented for `Error` = note: add `#[derive(Debug)]` to `Error` or manually `impl Debug for Error` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Debug-enum.stderr b/src/test/ui/derives/derives-span-Debug-enum.stderr index 4ffb75935af9..e9bb5f960b04 100644 --- a/src/test/ui/derives/derives-span-Debug-enum.stderr +++ b/src/test/ui/derives/derives-span-Debug-enum.stderr @@ -10,6 +10,10 @@ LL | Error = help: the trait `Debug` is not implemented for `Error` = note: add `#[derive(Debug)]` to `Error` or manually `impl Debug for Error` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Debug-struct.stderr b/src/test/ui/derives/derives-span-Debug-struct.stderr index 74d2460bb690..0a117c060ff3 100644 --- a/src/test/ui/derives/derives-span-Debug-struct.stderr +++ b/src/test/ui/derives/derives-span-Debug-struct.stderr @@ -10,6 +10,10 @@ LL | x: Error = help: the trait `Debug` is not implemented for `Error` = note: add `#[derive(Debug)]` to `Error` or manually `impl Debug for Error` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Debug-tuple-struct.stderr b/src/test/ui/derives/derives-span-Debug-tuple-struct.stderr index 34ddb4e59437..f2e90a418455 100644 --- a/src/test/ui/derives/derives-span-Debug-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-Debug-tuple-struct.stderr @@ -10,6 +10,10 @@ LL | Error = help: the trait `Debug` is not implemented for `Error` = note: add `#[derive(Debug)]` to `Error` or manually `impl Debug for Error` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Default-struct.stderr b/src/test/ui/derives/derives-span-Default-struct.stderr index dd2cfaf89bb8..d4affd535eef 100644 --- a/src/test/ui/derives/derives-span-Default-struct.stderr +++ b/src/test/ui/derives/derives-span-Default-struct.stderr @@ -8,6 +8,10 @@ LL | x: Error | ^^^^^^^^ the trait `Default` is not implemented for `Error` | = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Default)]` + | +LL | #[derive(Default)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Default-tuple-struct.stderr b/src/test/ui/derives/derives-span-Default-tuple-struct.stderr index 0674d635d3d0..129351f59989 100644 --- a/src/test/ui/derives/derives-span-Default-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-Default-tuple-struct.stderr @@ -8,6 +8,10 @@ LL | Error | ^^^^^ the trait `Default` is not implemented for `Error` | = note: this error originates in the derive macro `Default` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Default)]` + | +LL | #[derive(Default)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Eq-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Eq-enum-struct-variant.stderr index 277454a1140e..e3fb234b96e4 100644 --- a/src/test/ui/derives/derives-span-Eq-enum-struct-variant.stderr +++ b/src/test/ui/derives/derives-span-Eq-enum-struct-variant.stderr @@ -13,6 +13,10 @@ note: required by a bound in `AssertParamIsEq` LL | pub struct AssertParamIsEq { | ^^ required by this bound in `AssertParamIsEq` = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Eq-enum.stderr b/src/test/ui/derives/derives-span-Eq-enum.stderr index 6a48ad24561e..4e10c3f69e73 100644 --- a/src/test/ui/derives/derives-span-Eq-enum.stderr +++ b/src/test/ui/derives/derives-span-Eq-enum.stderr @@ -13,6 +13,10 @@ note: required by a bound in `AssertParamIsEq` LL | pub struct AssertParamIsEq { | ^^ required by this bound in `AssertParamIsEq` = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Eq-struct.stderr b/src/test/ui/derives/derives-span-Eq-struct.stderr index 7bf83e8eae2d..bfdab052a2ed 100644 --- a/src/test/ui/derives/derives-span-Eq-struct.stderr +++ b/src/test/ui/derives/derives-span-Eq-struct.stderr @@ -13,6 +13,10 @@ note: required by a bound in `AssertParamIsEq` LL | pub struct AssertParamIsEq { | ^^ required by this bound in `AssertParamIsEq` = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Eq-tuple-struct.stderr b/src/test/ui/derives/derives-span-Eq-tuple-struct.stderr index 13e2a55319eb..26b8be343336 100644 --- a/src/test/ui/derives/derives-span-Eq-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-Eq-tuple-struct.stderr @@ -13,6 +13,10 @@ note: required by a bound in `AssertParamIsEq` LL | pub struct AssertParamIsEq { | ^^ required by this bound in `AssertParamIsEq` = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr index 7f24be959f01..fe5e0e96ac7a 100644 --- a/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr +++ b/src/test/ui/derives/derives-span-Hash-enum-struct-variant.stderr @@ -8,6 +8,10 @@ LL | x: Error | ^^^^^^^^ the trait `Hash` is not implemented for `Error` | = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Hash)]` + | +LL | #[derive(Hash)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Hash-enum.stderr b/src/test/ui/derives/derives-span-Hash-enum.stderr index ae2921a16b31..99785b87ca83 100644 --- a/src/test/ui/derives/derives-span-Hash-enum.stderr +++ b/src/test/ui/derives/derives-span-Hash-enum.stderr @@ -8,6 +8,10 @@ LL | Error | ^^^^^ the trait `Hash` is not implemented for `Error` | = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Hash)]` + | +LL | #[derive(Hash)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Hash-struct.stderr b/src/test/ui/derives/derives-span-Hash-struct.stderr index 37b3af702a0c..4db83dd13001 100644 --- a/src/test/ui/derives/derives-span-Hash-struct.stderr +++ b/src/test/ui/derives/derives-span-Hash-struct.stderr @@ -8,6 +8,10 @@ LL | x: Error | ^^^^^^^^ the trait `Hash` is not implemented for `Error` | = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Hash)]` + | +LL | #[derive(Hash)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr b/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr index 18624667d25e..8660c97e69e1 100644 --- a/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-Hash-tuple-struct.stderr @@ -8,6 +8,10 @@ LL | Error | ^^^^^ the trait `Hash` is not implemented for `Error` | = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Hash)]` + | +LL | #[derive(Hash)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Ord-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-Ord-enum-struct-variant.stderr index b52c5a0d6a50..6e48332c2506 100644 --- a/src/test/ui/derives/derives-span-Ord-enum-struct-variant.stderr +++ b/src/test/ui/derives/derives-span-Ord-enum-struct-variant.stderr @@ -8,6 +8,10 @@ LL | x: Error | ^^^^^^^^ the trait `Ord` is not implemented for `Error` | = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Ord)]` + | +LL | #[derive(Ord)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Ord-enum.stderr b/src/test/ui/derives/derives-span-Ord-enum.stderr index 2ea0496ea0db..b05cf0a057b2 100644 --- a/src/test/ui/derives/derives-span-Ord-enum.stderr +++ b/src/test/ui/derives/derives-span-Ord-enum.stderr @@ -8,6 +8,10 @@ LL | Error | ^^^^^ the trait `Ord` is not implemented for `Error` | = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Ord)]` + | +LL | #[derive(Ord)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Ord-struct.stderr b/src/test/ui/derives/derives-span-Ord-struct.stderr index 52cf0cf8cd75..c4def34a83da 100644 --- a/src/test/ui/derives/derives-span-Ord-struct.stderr +++ b/src/test/ui/derives/derives-span-Ord-struct.stderr @@ -8,6 +8,10 @@ LL | x: Error | ^^^^^^^^ the trait `Ord` is not implemented for `Error` | = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Ord)]` + | +LL | #[derive(Ord)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-Ord-tuple-struct.stderr b/src/test/ui/derives/derives-span-Ord-tuple-struct.stderr index ecdf8d8cb593..a3b288d0fb9c 100644 --- a/src/test/ui/derives/derives-span-Ord-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-Ord-tuple-struct.stderr @@ -8,6 +8,10 @@ LL | Error | ^^^^^ the trait `Ord` is not implemented for `Error` | = note: this error originates in the derive macro `Ord` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(Ord)]` + | +LL | #[derive(Ord)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-PartialOrd-enum-struct-variant.stderr b/src/test/ui/derives/derives-span-PartialOrd-enum-struct-variant.stderr index fc8eb1ebfd3e..2d19aaf68afb 100644 --- a/src/test/ui/derives/derives-span-PartialOrd-enum-struct-variant.stderr +++ b/src/test/ui/derives/derives-span-PartialOrd-enum-struct-variant.stderr @@ -9,6 +9,10 @@ LL | x: Error | = help: the trait `PartialOrd` is not implemented for `Error` = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialOrd)]` + | +LL | #[derive(PartialOrd)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-PartialOrd-enum.stderr b/src/test/ui/derives/derives-span-PartialOrd-enum.stderr index 38053495a057..dfbb8060ffa1 100644 --- a/src/test/ui/derives/derives-span-PartialOrd-enum.stderr +++ b/src/test/ui/derives/derives-span-PartialOrd-enum.stderr @@ -9,6 +9,10 @@ LL | Error | = help: the trait `PartialOrd` is not implemented for `Error` = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialOrd)]` + | +LL | #[derive(PartialOrd)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-PartialOrd-struct.stderr b/src/test/ui/derives/derives-span-PartialOrd-struct.stderr index 1c07b98f983d..ba63d86e8e46 100644 --- a/src/test/ui/derives/derives-span-PartialOrd-struct.stderr +++ b/src/test/ui/derives/derives-span-PartialOrd-struct.stderr @@ -9,6 +9,10 @@ LL | x: Error | = help: the trait `PartialOrd` is not implemented for `Error` = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialOrd)]` + | +LL | #[derive(PartialOrd)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/derives-span-PartialOrd-tuple-struct.stderr b/src/test/ui/derives/derives-span-PartialOrd-tuple-struct.stderr index bf01252b07b8..7686ed8064e7 100644 --- a/src/test/ui/derives/derives-span-PartialOrd-tuple-struct.stderr +++ b/src/test/ui/derives/derives-span-PartialOrd-tuple-struct.stderr @@ -9,6 +9,10 @@ LL | Error | = help: the trait `PartialOrd` is not implemented for `Error` = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Error` with `#[derive(PartialOrd)]` + | +LL | #[derive(PartialOrd)] + | error: aborting due to previous error diff --git a/src/test/ui/derives/deriving-no-inner-impl-error-message.stderr b/src/test/ui/derives/deriving-no-inner-impl-error-message.stderr index d64b4509b260..451058cd0ee0 100644 --- a/src/test/ui/derives/deriving-no-inner-impl-error-message.stderr +++ b/src/test/ui/derives/deriving-no-inner-impl-error-message.stderr @@ -48,6 +48,10 @@ LL | x: NoCloneOrEq | ^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `NoCloneOrEq` | = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `NoCloneOrEq` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to 3 previous errors diff --git a/src/test/ui/error-codes/E0277-3.rs b/src/test/ui/error-codes/E0277-3.rs new file mode 100644 index 000000000000..428be79617d7 --- /dev/null +++ b/src/test/ui/error-codes/E0277-3.rs @@ -0,0 +1,8 @@ +fn foo(_: T) {} + +struct S; + +fn main() { + foo(S); + //~^ ERROR can't compare `S` with `S` +} diff --git a/src/test/ui/error-codes/E0277-3.stderr b/src/test/ui/error-codes/E0277-3.stderr new file mode 100644 index 000000000000..0127e1ccc81e --- /dev/null +++ b/src/test/ui/error-codes/E0277-3.stderr @@ -0,0 +1,22 @@ +error[E0277]: can't compare `S` with `S` + --> $DIR/E0277-3.rs:6:9 + | +LL | foo(S); + | --- ^ no implementation for `S == S` + | | + | required by a bound introduced by this call + | + = help: the trait `PartialEq` is not implemented for `S` +note: required by a bound in `foo` + --> $DIR/E0277-3.rs:1:11 + | +LL | fn foo(_: T) {} + | ^^^^^^^^^ required by this bound in `foo` +help: consider annotating `S` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/feature-gates/feature-gate-default_type_parameter_fallback.stderr b/src/test/ui/feature-gates/feature-gate-default_type_parameter_fallback.stderr index 5cd38ebab370..a7d5c7ac39b0 100644 --- a/src/test/ui/feature-gates/feature-gate-default_type_parameter_fallback.stderr +++ b/src/test/ui/feature-gates/feature-gate-default_type_parameter_fallback.stderr @@ -2,7 +2,7 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type` --> $DIR/feature-gate-default_type_parameter_fallback.rs:3:8 | LL | fn avg(_: T) {} - | ^ + | ^^^^^ | = note: `#[deny(invalid_type_param_default)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -12,7 +12,7 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type` --> $DIR/feature-gate-default_type_parameter_fallback.rs:8:6 | LL | impl S {} - | ^ + | ^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #36887 diff --git a/src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr b/src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr index e5db2f1b7c35..c6fa02cb9a6b 100644 --- a/src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr +++ b/src/test/ui/generic-associated-types/issue-87429-associated-type-default.stderr @@ -10,6 +10,10 @@ note: required by a bound in `Family2::Member` | LL | type Member<'a>: for<'b> PartialEq> = Foo; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Family2::Member` +help: consider annotating `Foo` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | error: aborting due to previous error diff --git a/src/test/ui/generic-associated-types/issue-87429-specialization.stderr b/src/test/ui/generic-associated-types/issue-87429-specialization.stderr index ca44ecfdb537..015e0c7792fe 100644 --- a/src/test/ui/generic-associated-types/issue-87429-specialization.stderr +++ b/src/test/ui/generic-associated-types/issue-87429-specialization.stderr @@ -20,6 +20,10 @@ note: required by a bound in `Family::Member` | LL | type Member<'a>: for<'b> PartialEq>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Family::Member` +help: consider annotating `Foo` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/generics/generic-impl-more-params-with-defaults.stderr b/src/test/ui/generics/generic-impl-more-params-with-defaults.stderr index 059289533dad..fe9b670da799 100644 --- a/src/test/ui/generics/generic-impl-more-params-with-defaults.stderr +++ b/src/test/ui/generics/generic-impl-more-params-with-defaults.stderr @@ -10,7 +10,7 @@ note: struct defined here, with at most 2 generic parameters: `T`, `A` --> $DIR/generic-impl-more-params-with-defaults.rs:5:8 | LL | struct Vec( - | ^^^ - - + | ^^^ - -------- error: aborting due to previous error diff --git a/src/test/ui/generics/generic-type-more-params-with-defaults.stderr b/src/test/ui/generics/generic-type-more-params-with-defaults.stderr index 500880cfb867..7f0198f0e842 100644 --- a/src/test/ui/generics/generic-type-more-params-with-defaults.stderr +++ b/src/test/ui/generics/generic-type-more-params-with-defaults.stderr @@ -10,7 +10,7 @@ note: struct defined here, with at most 2 generic parameters: `T`, `A` --> $DIR/generic-type-more-params-with-defaults.rs:5:8 | LL | struct Vec( - | ^^^ - - + | ^^^ - -------- error: aborting due to previous error diff --git a/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr b/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr index 2c397d80b013..6791182238c7 100644 --- a/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr +++ b/src/test/ui/generics/issue-61631-default-type-param-can-reference-self-in-trait.stderr @@ -9,7 +9,7 @@ note: required by a bound in `Tsized` --> $DIR/issue-61631-default-type-param-can-reference-self-in-trait.rs:17:14 | LL | trait Tsized {} - | ^ required by this bound in `Tsized` + | ^^^^^^^^^^^^^^^^^ required by this bound in `Tsized` error: aborting due to previous error diff --git a/src/test/ui/generics/wrong-number-of-args.stderr b/src/test/ui/generics/wrong-number-of-args.stderr index 22da0dffbf29..3b0834a5f51b 100644 --- a/src/test/ui/generics/wrong-number-of-args.stderr +++ b/src/test/ui/generics/wrong-number-of-args.stderr @@ -287,7 +287,7 @@ note: struct defined here, with at most 3 generic parameters: `A`, `B`, `C` --> $DIR/wrong-number-of-args.rs:78:12 | LL | struct Ty; - | ^^ - - - + | ^^ - - ---------------- error[E0107]: this struct takes at least 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:96:14 @@ -922,7 +922,7 @@ note: struct defined here, with at most 3 generic parameters: `K`, `V`, `S` --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL | LL | pub struct HashMap { - | ^^^^^^^ - - - + | ^^^^^^^ - - --------------- error[E0107]: this struct takes at least 2 generic arguments but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:319:18 diff --git a/src/test/ui/impl-trait/where-allowed.stderr b/src/test/ui/impl-trait/where-allowed.stderr index eef20c2de94b..58a2f79efb4c 100644 --- a/src/test/ui/impl-trait/where-allowed.stderr +++ b/src/test/ui/impl-trait/where-allowed.stderr @@ -293,7 +293,7 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type` --> $DIR/where-allowed.rs:234:7 | LL | impl T {} - | ^ + | ^^^^^^^^^^^^^^ | = note: `#[deny(invalid_type_param_default)]` on by default = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! @@ -303,7 +303,7 @@ error: defaults for type parameters are only allowed in `struct`, `enum`, `type` --> $DIR/where-allowed.rs:241:36 | LL | fn in_method_generic_param_default(_: T) {} - | ^ + | ^^^^^^^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #36887 diff --git a/src/test/ui/issues/issue-20162.stderr b/src/test/ui/issues/issue-20162.stderr index 6848c3f0d8a5..d70bf6e1d921 100644 --- a/src/test/ui/issues/issue-20162.stderr +++ b/src/test/ui/issues/issue-20162.stderr @@ -9,6 +9,10 @@ note: required by a bound in `slice::::sort` | LL | T: Ord, | ^^^ required by this bound in `slice::::sort` +help: consider annotating `X` with `#[derive(Ord)]` + | +LL | #[derive(Ord)] + | error: aborting due to previous error diff --git a/src/test/ui/issues/issue-21160.stderr b/src/test/ui/issues/issue-21160.stderr index 300c1272ef6c..266749376eb0 100644 --- a/src/test/ui/issues/issue-21160.stderr +++ b/src/test/ui/issues/issue-21160.stderr @@ -7,6 +7,10 @@ LL | struct Foo(Bar); | ^^^ the trait `Hash` is not implemented for `Bar` | = note: this error originates in the derive macro `Hash` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Bar` with `#[derive(Hash)]` + | +LL | #[derive(Hash)] + | error: aborting due to previous error diff --git a/src/test/ui/issues/issue-34229.stderr b/src/test/ui/issues/issue-34229.stderr index 71e02f2fd86c..69ef876d2550 100644 --- a/src/test/ui/issues/issue-34229.stderr +++ b/src/test/ui/issues/issue-34229.stderr @@ -8,6 +8,10 @@ LL | #[derive(PartialEq, PartialOrd)] struct Nope(Comparable); | = help: the trait `PartialOrd` is not implemented for `Comparable` = note: this error originates in the derive macro `PartialOrd` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Comparable` with `#[derive(PartialOrd)]` + | +LL | #[derive(PartialEq)] #[derive(PartialOrd)] + | +++++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-78957.stderr b/src/test/ui/issues/issue-78957.stderr index 703d272dc988..fa2eaab5b417 100644 --- a/src/test/ui/issues/issue-78957.stderr +++ b/src/test/ui/issues/issue-78957.stderr @@ -2,13 +2,13 @@ error[E0518]: attribute should be applied to function or closure --> $DIR/issue-78957.rs:5:16 | LL | pub struct Foo<#[inline] const N: usize>; - | ^^^^^^^^^ - not a function or closure + | ^^^^^^^^^ -------------- not a function or closure error: attribute should be applied to a function --> $DIR/issue-78957.rs:7:16 | LL | pub struct Bar<#[cold] const N: usize>; - | ^^^^^^^ - not a function + | ^^^^^^^ -------------- not a function | note: the lint level is defined here --> $DIR/issue-78957.rs:1:9 @@ -21,7 +21,7 @@ error[E0517]: attribute should be applied to a struct, enum, or union --> $DIR/issue-78957.rs:10:23 | LL | pub struct Baz<#[repr(C)] const N: usize>; - | ^ - not a struct, enum, or union + | ^ -------------- not a struct, enum, or union error[E0518]: attribute should be applied to function or closure --> $DIR/issue-78957.rs:13:17 diff --git a/src/test/ui/kindck/kindck-impl-type-params.nll.stderr b/src/test/ui/kindck/kindck-impl-type-params.nll.stderr index 94f802620a30..1772d353fe42 100644 --- a/src/test/ui/kindck/kindck-impl-type-params.nll.stderr +++ b/src/test/ui/kindck/kindck-impl-type-params.nll.stderr @@ -93,6 +93,10 @@ note: required because of the requirements on the impl of `Gettable` for `S LL | impl Gettable for S {} | ^^^^^^^^^^^ ^^^^ = note: required for the cast to the object type `dyn Gettable` +help: consider annotating `Foo` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to 6 previous errors diff --git a/src/test/ui/kindck/kindck-impl-type-params.stderr b/src/test/ui/kindck/kindck-impl-type-params.stderr index 64bbc841b330..f227ac2477e6 100644 --- a/src/test/ui/kindck/kindck-impl-type-params.stderr +++ b/src/test/ui/kindck/kindck-impl-type-params.stderr @@ -101,6 +101,10 @@ note: required because of the requirements on the impl of `Gettable` for `S LL | impl Gettable for S {} | ^^^^^^^^^^^ ^^^^ = note: required for the cast to the object type `dyn Gettable` +help: consider annotating `Foo` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to 7 previous errors diff --git a/src/test/ui/layout/debug.stderr b/src/test/ui/layout/debug.stderr index 418f780d62c9..25f7febfef9d 100644 --- a/src/test/ui/layout/debug.stderr +++ b/src/test/ui/layout/debug.stderr @@ -10,7 +10,7 @@ error: layout_of(E) = Layout { ], }, variants: Multiple { - tag: Scalar { + tag: Initialized { value: Int( I32, false, @@ -86,13 +86,11 @@ error: layout_of(E) = Layout { offset: Size { raw: 0, }, - scalar: Scalar { - value: Int( - I32, - false, - ), - valid_range: 0..=0, - }, + value: Int( + I32, + false, + ), + valid_range: 0..=0, }, ), align: AbiAndPrefAlign { @@ -133,14 +131,14 @@ error: layout_of(S) = Layout { index: 0, }, abi: ScalarPair( - Scalar { + Initialized { value: Int( I32, true, ), valid_range: 0..=4294967295, }, - Scalar { + Initialized { value: Int( I32, true, @@ -202,7 +200,7 @@ error: layout_of(std::result::Result) = Layout { ], }, variants: Multiple { - tag: Scalar { + tag: Initialized { value: Int( I32, false, @@ -271,14 +269,14 @@ error: layout_of(std::result::Result) = Layout { ], }, abi: ScalarPair( - Scalar { + Initialized { value: Int( I32, false, ), valid_range: 0..=1, }, - Scalar { + Initialized { value: Int( I32, true, @@ -291,13 +289,11 @@ error: layout_of(std::result::Result) = Layout { offset: Size { raw: 0, }, - scalar: Scalar { - value: Int( - I32, - false, - ), - valid_range: 0..=1, - }, + value: Int( + I32, + false, + ), + valid_range: 0..=1, }, ), align: AbiAndPrefAlign { @@ -321,7 +317,7 @@ error: layout_of(i32) = Layout { index: 0, }, abi: Scalar( - Scalar { + Initialized { value: Int( I32, true, diff --git a/src/test/ui/layout/hexagon-enum.stderr b/src/test/ui/layout/hexagon-enum.stderr index 39b23cb4b572..4db8162b16bb 100644 --- a/src/test/ui/layout/hexagon-enum.stderr +++ b/src/test/ui/layout/hexagon-enum.stderr @@ -10,7 +10,7 @@ error: layout_of(A) = Layout { ], }, variants: Multiple { - tag: Scalar { + tag: Initialized { value: Int( I8, false, @@ -47,7 +47,7 @@ error: layout_of(A) = Layout { ], }, abi: Scalar( - Scalar { + Initialized { value: Int( I8, false, @@ -60,13 +60,11 @@ error: layout_of(A) = Layout { offset: Size { raw: 0, }, - scalar: Scalar { - value: Int( - I8, - false, - ), - valid_range: 0..=0, - }, + value: Int( + I8, + false, + ), + valid_range: 0..=0, }, ), align: AbiAndPrefAlign { @@ -98,7 +96,7 @@ error: layout_of(B) = Layout { ], }, variants: Multiple { - tag: Scalar { + tag: Initialized { value: Int( I8, false, @@ -135,7 +133,7 @@ error: layout_of(B) = Layout { ], }, abi: Scalar( - Scalar { + Initialized { value: Int( I8, false, @@ -148,13 +146,11 @@ error: layout_of(B) = Layout { offset: Size { raw: 0, }, - scalar: Scalar { - value: Int( - I8, - false, - ), - valid_range: 255..=255, - }, + value: Int( + I8, + false, + ), + valid_range: 255..=255, }, ), align: AbiAndPrefAlign { @@ -186,7 +182,7 @@ error: layout_of(C) = Layout { ], }, variants: Multiple { - tag: Scalar { + tag: Initialized { value: Int( I16, false, @@ -223,7 +219,7 @@ error: layout_of(C) = Layout { ], }, abi: Scalar( - Scalar { + Initialized { value: Int( I16, false, @@ -236,13 +232,11 @@ error: layout_of(C) = Layout { offset: Size { raw: 0, }, - scalar: Scalar { - value: Int( - I16, - false, - ), - valid_range: 256..=256, - }, + value: Int( + I16, + false, + ), + valid_range: 256..=256, }, ), align: AbiAndPrefAlign { @@ -274,7 +268,7 @@ error: layout_of(P) = Layout { ], }, variants: Multiple { - tag: Scalar { + tag: Initialized { value: Int( I32, false, @@ -311,7 +305,7 @@ error: layout_of(P) = Layout { ], }, abi: Scalar( - Scalar { + Initialized { value: Int( I32, false, @@ -324,13 +318,11 @@ error: layout_of(P) = Layout { offset: Size { raw: 0, }, - scalar: Scalar { - value: Int( - I32, - false, - ), - valid_range: 268435456..=268435456, - }, + value: Int( + I32, + false, + ), + valid_range: 268435456..=268435456, }, ), align: AbiAndPrefAlign { @@ -362,7 +354,7 @@ error: layout_of(T) = Layout { ], }, variants: Multiple { - tag: Scalar { + tag: Initialized { value: Int( I32, true, @@ -399,7 +391,7 @@ error: layout_of(T) = Layout { ], }, abi: Scalar( - Scalar { + Initialized { value: Int( I32, true, @@ -412,13 +404,11 @@ error: layout_of(T) = Layout { offset: Size { raw: 0, }, - scalar: Scalar { - value: Int( - I32, - true, - ), - valid_range: 2164260864..=2164260864, - }, + value: Int( + I32, + true, + ), + valid_range: 2164260864..=2164260864, }, ), align: AbiAndPrefAlign { diff --git a/src/test/ui/layout/thumb-enum.stderr b/src/test/ui/layout/thumb-enum.stderr index 144ab02792e5..9d1f234f31ad 100644 --- a/src/test/ui/layout/thumb-enum.stderr +++ b/src/test/ui/layout/thumb-enum.stderr @@ -10,7 +10,7 @@ error: layout_of(A) = Layout { ], }, variants: Multiple { - tag: Scalar { + tag: Initialized { value: Int( I8, false, @@ -47,7 +47,7 @@ error: layout_of(A) = Layout { ], }, abi: Scalar( - Scalar { + Initialized { value: Int( I8, false, @@ -60,13 +60,11 @@ error: layout_of(A) = Layout { offset: Size { raw: 0, }, - scalar: Scalar { - value: Int( - I8, - false, - ), - valid_range: 0..=0, - }, + value: Int( + I8, + false, + ), + valid_range: 0..=0, }, ), align: AbiAndPrefAlign { @@ -98,7 +96,7 @@ error: layout_of(B) = Layout { ], }, variants: Multiple { - tag: Scalar { + tag: Initialized { value: Int( I8, false, @@ -135,7 +133,7 @@ error: layout_of(B) = Layout { ], }, abi: Scalar( - Scalar { + Initialized { value: Int( I8, false, @@ -148,13 +146,11 @@ error: layout_of(B) = Layout { offset: Size { raw: 0, }, - scalar: Scalar { - value: Int( - I8, - false, - ), - valid_range: 255..=255, - }, + value: Int( + I8, + false, + ), + valid_range: 255..=255, }, ), align: AbiAndPrefAlign { @@ -186,7 +182,7 @@ error: layout_of(C) = Layout { ], }, variants: Multiple { - tag: Scalar { + tag: Initialized { value: Int( I16, false, @@ -223,7 +219,7 @@ error: layout_of(C) = Layout { ], }, abi: Scalar( - Scalar { + Initialized { value: Int( I16, false, @@ -236,13 +232,11 @@ error: layout_of(C) = Layout { offset: Size { raw: 0, }, - scalar: Scalar { - value: Int( - I16, - false, - ), - valid_range: 256..=256, - }, + value: Int( + I16, + false, + ), + valid_range: 256..=256, }, ), align: AbiAndPrefAlign { @@ -274,7 +268,7 @@ error: layout_of(P) = Layout { ], }, variants: Multiple { - tag: Scalar { + tag: Initialized { value: Int( I32, false, @@ -311,7 +305,7 @@ error: layout_of(P) = Layout { ], }, abi: Scalar( - Scalar { + Initialized { value: Int( I32, false, @@ -324,13 +318,11 @@ error: layout_of(P) = Layout { offset: Size { raw: 0, }, - scalar: Scalar { - value: Int( - I32, - false, - ), - valid_range: 268435456..=268435456, - }, + value: Int( + I32, + false, + ), + valid_range: 268435456..=268435456, }, ), align: AbiAndPrefAlign { @@ -362,7 +354,7 @@ error: layout_of(T) = Layout { ], }, variants: Multiple { - tag: Scalar { + tag: Initialized { value: Int( I32, true, @@ -399,7 +391,7 @@ error: layout_of(T) = Layout { ], }, abi: Scalar( - Scalar { + Initialized { value: Int( I32, true, @@ -412,13 +404,11 @@ error: layout_of(T) = Layout { offset: Size { raw: 0, }, - scalar: Scalar { - value: Int( - I32, - true, - ), - valid_range: 2164260864..=2164260864, - }, + value: Int( + I32, + true, + ), + valid_range: 2164260864..=2164260864, }, ), align: AbiAndPrefAlign { diff --git a/src/test/ui/malformed/malformed-derive-entry.stderr b/src/test/ui/malformed/malformed-derive-entry.stderr index 0ddce1be476c..803883460f08 100644 --- a/src/test/ui/malformed/malformed-derive-entry.stderr +++ b/src/test/ui/malformed/malformed-derive-entry.stderr @@ -28,6 +28,10 @@ note: required by a bound in `Copy` LL | pub trait Copy: Clone { | ^^^^^ required by this bound in `Copy` = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Test1` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error[E0277]: the trait bound `Test2: Clone` is not satisfied --> $DIR/malformed-derive-entry.rs:6:10 @@ -41,6 +45,10 @@ note: required by a bound in `Copy` LL | pub trait Copy: Clone { | ^^^^^ required by this bound in `Copy` = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Test2` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to 5 previous errors diff --git a/src/test/ui/mir/thir-constparam-temp.stderr b/src/test/ui/mir/thir-constparam-temp.stderr index 297102e657ef..ed2766c000ec 100644 --- a/src/test/ui/mir/thir-constparam-temp.stderr +++ b/src/test/ui/mir/thir-constparam-temp.stderr @@ -13,10 +13,10 @@ note: mutable reference created due to call to this method LL | fn mut_self(&mut self) {} | ^^^^^^^^^^^^^^^^^^^^^^ note: `const` item defined here - --> $DIR/thir-constparam-temp.rs:13:14 + --> $DIR/thir-constparam-temp.rs:13:8 | LL | fn foo() { - | ^^^^^ + | ^^^^^^^^^^^^^^^^^^ warning: 1 warning emitted diff --git a/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr b/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr index dc73bcd6e4d0..c2515c40b1d7 100644 --- a/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr +++ b/src/test/ui/mismatched_types/method-help-unsatisfied-bound.stderr @@ -11,6 +11,10 @@ note: required by a bound in `Result::::unwrap` | LL | E: fmt::Debug, | ^^^^^^^^^^ required by this bound in `Result::::unwrap` +help: consider annotating `Foo` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | error: aborting due to previous error diff --git a/src/test/ui/missing/missing-items/missing-type-parameter2.stderr b/src/test/ui/missing/missing-items/missing-type-parameter2.stderr index 3b930d7e4ec1..cbceec58eb1e 100644 --- a/src/test/ui/missing/missing-items/missing-type-parameter2.stderr +++ b/src/test/ui/missing/missing-items/missing-type-parameter2.stderr @@ -99,10 +99,10 @@ LL | impl X<{ N }> {} | + + error: defaults for const parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions - --> $DIR/missing-type-parameter2.rs:6:15 + --> $DIR/missing-type-parameter2.rs:6:9 | LL | impl X {} - | ^ + | ^^^^^^^^^^^^^^^ error[E0747]: unresolved item provided when a constant was expected --> $DIR/missing-type-parameter2.rs:6:28 diff --git a/src/test/ui/nll/issue-50716.stderr b/src/test/ui/nll/issue-50716.base.stderr similarity index 88% rename from src/test/ui/nll/issue-50716.stderr rename to src/test/ui/nll/issue-50716.base.stderr index be68d252f32f..0dcf06481427 100644 --- a/src/test/ui/nll/issue-50716.stderr +++ b/src/test/ui/nll/issue-50716.base.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-50716.rs:14:9 + --> $DIR/issue-50716.rs:18:9 | LL | let _x = *s; | ^^ lifetime mismatch @@ -7,7 +7,7 @@ LL | let _x = *s; = note: expected type `<<&'a T as A>::X as Sized>` found type `<<&'static T as A>::X as Sized>` note: the lifetime `'a` as defined here... - --> $DIR/issue-50716.rs:9:8 + --> $DIR/issue-50716.rs:13:8 | LL | fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>) | ^^ diff --git a/src/test/ui/nll/issue-50716.nll.stderr b/src/test/ui/nll/issue-50716.nll.stderr index 38dd1b5f6fe7..a8f4d694ba7d 100644 --- a/src/test/ui/nll/issue-50716.nll.stderr +++ b/src/test/ui/nll/issue-50716.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/issue-50716.rs:14:14 + --> $DIR/issue-50716.rs:18:14 | LL | fn foo<'a, T: 'static>(s: Box<<&'a T as A>::X>) | -- lifetime `'a` defined here diff --git a/src/test/ui/nll/issue-50716.rs b/src/test/ui/nll/issue-50716.rs index c2fc345fa2ba..bd44d3eff9fc 100644 --- a/src/test/ui/nll/issue-50716.rs +++ b/src/test/ui/nll/issue-50716.rs @@ -2,6 +2,10 @@ // Regression test for the issue #50716: NLL ignores lifetimes bounds // derived from `Sized` requirements +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait A { type X: ?Sized; } diff --git a/src/test/ui/nll/issue-52742.stderr b/src/test/ui/nll/issue-52742.base.stderr similarity index 85% rename from src/test/ui/nll/issue-52742.stderr rename to src/test/ui/nll/issue-52742.base.stderr index 67bac14b6e4e..259f378f70b5 100644 --- a/src/test/ui/nll/issue-52742.stderr +++ b/src/test/ui/nll/issue-52742.base.stderr @@ -1,16 +1,16 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... - --> $DIR/issue-52742.rs:12:18 + --> $DIR/issue-52742.rs:17:18 | LL | self.y = b.z | ^^^ | note: ...the reference is valid for the lifetime `'_` as defined here... - --> $DIR/issue-52742.rs:10:10 + --> $DIR/issue-52742.rs:15:10 | LL | impl Foo<'_, '_> { | ^^ note: ...but the borrowed content is only valid for the anonymous lifetime defined here - --> $DIR/issue-52742.rs:11:31 + --> $DIR/issue-52742.rs:16:31 | LL | fn take_bar(&mut self, b: Bar<'_>) { | ^^^^^^^ diff --git a/src/test/ui/nll/issue-52742.nll.stderr b/src/test/ui/nll/issue-52742.nll.stderr index 0f6d6cd4fa18..6828418a78ec 100644 --- a/src/test/ui/nll/issue-52742.nll.stderr +++ b/src/test/ui/nll/issue-52742.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/issue-52742.rs:12:9 + --> $DIR/issue-52742.rs:17:9 | LL | fn take_bar(&mut self, b: Bar<'_>) { | --------- -- let's call this `'1` diff --git a/src/test/ui/nll/issue-52742.rs b/src/test/ui/nll/issue-52742.rs index d3e201b8ae8e..5ec5770c5c20 100644 --- a/src/test/ui/nll/issue-52742.rs +++ b/src/test/ui/nll/issue-52742.rs @@ -1,3 +1,8 @@ +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + + struct Foo<'a, 'b> { x: &'a u32, y: &'b u32, diff --git a/src/test/ui/nll/issue-55394.stderr b/src/test/ui/nll/issue-55394.base.stderr similarity index 83% rename from src/test/ui/nll/issue-55394.stderr rename to src/test/ui/nll/issue-55394.base.stderr index 197f8dfa2abe..cc87954732c4 100644 --- a/src/test/ui/nll/issue-55394.stderr +++ b/src/test/ui/nll/issue-55394.base.stderr @@ -1,26 +1,26 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'s` due to conflicting requirements - --> $DIR/issue-55394.rs:9:9 + --> $DIR/issue-55394.rs:13:9 | LL | Foo { bar } | ^^^ | note: first, the lifetime cannot outlive the anonymous lifetime defined here... - --> $DIR/issue-55394.rs:8:17 + --> $DIR/issue-55394.rs:12:17 | LL | fn new(bar: &mut Bar) -> Self { | ^^^^^^^^ note: ...so that reference does not outlive borrowed content - --> $DIR/issue-55394.rs:9:15 + --> $DIR/issue-55394.rs:13:15 | LL | Foo { bar } | ^^^ note: but, the lifetime must be valid for the lifetime `'_` as defined here... - --> $DIR/issue-55394.rs:7:10 + --> $DIR/issue-55394.rs:11:10 | LL | impl Foo<'_> { | ^^ note: ...so that the types are compatible - --> $DIR/issue-55394.rs:9:9 + --> $DIR/issue-55394.rs:13:9 | LL | Foo { bar } | ^^^^^^^^^^^ diff --git a/src/test/ui/nll/issue-55394.nll.stderr b/src/test/ui/nll/issue-55394.nll.stderr index 24b8c84b4a96..c166c458c501 100644 --- a/src/test/ui/nll/issue-55394.nll.stderr +++ b/src/test/ui/nll/issue-55394.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/issue-55394.rs:9:9 + --> $DIR/issue-55394.rs:13:9 | LL | fn new(bar: &mut Bar) -> Self { | - ---- return type is Foo<'2> diff --git a/src/test/ui/nll/issue-55394.rs b/src/test/ui/nll/issue-55394.rs index f813d1c915cf..9c4fcdf64190 100644 --- a/src/test/ui/nll/issue-55394.rs +++ b/src/test/ui/nll/issue-55394.rs @@ -1,3 +1,7 @@ +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + struct Bar; struct Foo<'s> { diff --git a/src/test/ui/nll/issue-55401.stderr b/src/test/ui/nll/issue-55401.base.stderr similarity index 89% rename from src/test/ui/nll/issue-55401.stderr rename to src/test/ui/nll/issue-55401.base.stderr index 55c51d532e77..d4e9f2b4154e 100644 --- a/src/test/ui/nll/issue-55401.stderr +++ b/src/test/ui/nll/issue-55401.base.stderr @@ -1,12 +1,12 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... - --> $DIR/issue-55401.rs:3:5 + --> $DIR/issue-55401.rs:7:5 | LL | *y | ^^ | = note: ...the reference is valid for the static lifetime... note: ...but the borrowed content is only valid for the lifetime `'a` as defined here - --> $DIR/issue-55401.rs:1:47 + --> $DIR/issue-55401.rs:5:47 | LL | fn static_to_a_to_static_through_ref_in_tuple<'a>(x: &'a u32) -> &'static u32 { | ^^ diff --git a/src/test/ui/nll/issue-55401.nll.stderr b/src/test/ui/nll/issue-55401.nll.stderr index 4f797f26a1a7..1318dc676571 100644 --- a/src/test/ui/nll/issue-55401.nll.stderr +++ b/src/test/ui/nll/issue-55401.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/issue-55401.rs:3:5 + --> $DIR/issue-55401.rs:7:5 | LL | fn static_to_a_to_static_through_ref_in_tuple<'a>(x: &'a u32) -> &'static u32 { | -- lifetime `'a` defined here diff --git a/src/test/ui/nll/issue-55401.rs b/src/test/ui/nll/issue-55401.rs index fc45824e903c..10f38c53dfdc 100644 --- a/src/test/ui/nll/issue-55401.rs +++ b/src/test/ui/nll/issue-55401.rs @@ -1,3 +1,7 @@ +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + fn static_to_a_to_static_through_ref_in_tuple<'a>(x: &'a u32) -> &'static u32 { let (ref y, _z): (&'a u32, u32) = (&22, 44); *y //~ ERROR diff --git a/src/test/ui/nll/lub-if.stderr b/src/test/ui/nll/lub-if.base.stderr similarity index 88% rename from src/test/ui/nll/lub-if.stderr rename to src/test/ui/nll/lub-if.base.stderr index a12c48582c79..ea9f5d4b2b1a 100644 --- a/src/test/ui/nll/lub-if.stderr +++ b/src/test/ui/nll/lub-if.base.stderr @@ -1,25 +1,25 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... - --> $DIR/lub-if.rs:28:9 + --> $DIR/lub-if.rs:32:9 | LL | s | ^ | = note: ...the reference is valid for the static lifetime... note: ...but the borrowed content is only valid for the lifetime `'a` as defined here - --> $DIR/lub-if.rs:23:17 + --> $DIR/lub-if.rs:27:17 | LL | pub fn opt_str2<'a>(maybestr: &'a Option) -> &'static str { | ^^ error[E0312]: lifetime of reference outlives lifetime of borrowed content... - --> $DIR/lub-if.rs:35:9 + --> $DIR/lub-if.rs:41:9 | LL | s | ^ | = note: ...the reference is valid for the static lifetime... note: ...but the borrowed content is only valid for the lifetime `'a` as defined here - --> $DIR/lub-if.rs:32:17 + --> $DIR/lub-if.rs:38:17 | LL | pub fn opt_str3<'a>(maybestr: &'a Option) -> &'static str { | ^^ diff --git a/src/test/ui/nll/lub-if.nll.stderr b/src/test/ui/nll/lub-if.nll.stderr index 832688f5162b..2fd6e69628d4 100644 --- a/src/test/ui/nll/lub-if.nll.stderr +++ b/src/test/ui/nll/lub-if.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/lub-if.rs:28:9 + --> $DIR/lub-if.rs:32:9 | LL | pub fn opt_str2<'a>(maybestr: &'a Option) -> &'static str { | -- lifetime `'a` defined here @@ -8,7 +8,7 @@ LL | s | ^ returning this value requires that `'a` must outlive `'static` error: lifetime may not live long enough - --> $DIR/lub-if.rs:35:9 + --> $DIR/lub-if.rs:41:9 | LL | pub fn opt_str3<'a>(maybestr: &'a Option) -> &'static str { | -- lifetime `'a` defined here diff --git a/src/test/ui/nll/lub-if.rs b/src/test/ui/nll/lub-if.rs index 132b83810ead..18561d63935e 100644 --- a/src/test/ui/nll/lub-if.rs +++ b/src/test/ui/nll/lub-if.rs @@ -2,6 +2,10 @@ // of the various arms, particularly in the case where regions are // involved. +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + pub fn opt_str0<'a>(maybestr: &'a Option) -> &'a str { if maybestr.is_none() { "(none)" @@ -25,14 +29,18 @@ pub fn opt_str2<'a>(maybestr: &'a Option) -> &'static str { "(none)" } else { let s: &'a str = maybestr.as_ref().unwrap(); - s //~ ERROR E0312 + s + //[base]~^ ERROR E0312 + //[nll]~^^ ERROR lifetime may not live long enough } } pub fn opt_str3<'a>(maybestr: &'a Option) -> &'static str { if maybestr.is_some() { let s: &'a str = maybestr.as_ref().unwrap(); - s //~ ERROR E0312 + s + //[base]~^ ERROR E0312 + //[nll]~^^ ERROR lifetime may not live long enough } else { "(none)" } diff --git a/src/test/ui/nll/lub-match.stderr b/src/test/ui/nll/lub-match.base.stderr similarity index 87% rename from src/test/ui/nll/lub-match.stderr rename to src/test/ui/nll/lub-match.base.stderr index 04d50f5ebf47..38952133160e 100644 --- a/src/test/ui/nll/lub-match.stderr +++ b/src/test/ui/nll/lub-match.base.stderr @@ -1,25 +1,25 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... - --> $DIR/lub-match.rs:30:13 + --> $DIR/lub-match.rs:34:13 | LL | s | ^ | = note: ...the reference is valid for the static lifetime... note: ...but the borrowed content is only valid for the lifetime `'a` as defined here - --> $DIR/lub-match.rs:25:17 + --> $DIR/lub-match.rs:29:17 | LL | pub fn opt_str2<'a>(maybestr: &'a Option) -> &'static str { | ^^ error[E0312]: lifetime of reference outlives lifetime of borrowed content... - --> $DIR/lub-match.rs:39:13 + --> $DIR/lub-match.rs:45:13 | LL | s | ^ | = note: ...the reference is valid for the static lifetime... note: ...but the borrowed content is only valid for the lifetime `'a` as defined here - --> $DIR/lub-match.rs:35:17 + --> $DIR/lub-match.rs:41:17 | LL | pub fn opt_str3<'a>(maybestr: &'a Option) -> &'static str { | ^^ diff --git a/src/test/ui/nll/lub-match.nll.stderr b/src/test/ui/nll/lub-match.nll.stderr index 3a344a77d2c2..c78d0cb641dc 100644 --- a/src/test/ui/nll/lub-match.nll.stderr +++ b/src/test/ui/nll/lub-match.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/lub-match.rs:30:13 + --> $DIR/lub-match.rs:34:13 | LL | pub fn opt_str2<'a>(maybestr: &'a Option) -> &'static str { | -- lifetime `'a` defined here @@ -8,7 +8,7 @@ LL | s | ^ returning this value requires that `'a` must outlive `'static` error: lifetime may not live long enough - --> $DIR/lub-match.rs:39:13 + --> $DIR/lub-match.rs:45:13 | LL | pub fn opt_str3<'a>(maybestr: &'a Option) -> &'static str { | -- lifetime `'a` defined here diff --git a/src/test/ui/nll/lub-match.rs b/src/test/ui/nll/lub-match.rs index 1cd4a02a3ef5..084d8b95f589 100644 --- a/src/test/ui/nll/lub-match.rs +++ b/src/test/ui/nll/lub-match.rs @@ -2,6 +2,10 @@ // of the various arms, particularly in the case where regions are // involved. +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + pub fn opt_str0<'a>(maybestr: &'a Option) -> &'a str { match *maybestr { Some(ref s) => { @@ -27,7 +31,9 @@ pub fn opt_str2<'a>(maybestr: &'a Option) -> &'static str { None => "(none)", Some(ref s) => { let s: &'a str = s; - s //~ ERROR E0312 + s + //[base]~^ ERROR E0312 + //[nll]~^^ ERROR lifetime may not live long enough } } } @@ -36,7 +42,9 @@ pub fn opt_str3<'a>(maybestr: &'a Option) -> &'static str { match *maybestr { Some(ref s) => { let s: &'a str = s; - s //~ ERROR E0312 + s + //[base]~^ ERROR E0312 + //[nll]~^^ ERROR lifetime may not live long enough } None => "(none)", } diff --git a/src/test/ui/nll/type-alias-free-regions.stderr b/src/test/ui/nll/type-alias-free-regions.base.stderr similarity index 79% rename from src/test/ui/nll/type-alias-free-regions.stderr rename to src/test/ui/nll/type-alias-free-regions.base.stderr index 71f5f8fb1766..010535fec6dd 100644 --- a/src/test/ui/nll/type-alias-free-regions.stderr +++ b/src/test/ui/nll/type-alias-free-regions.base.stderr @@ -1,28 +1,28 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements - --> $DIR/type-alias-free-regions.rs:17:9 + --> $DIR/type-alias-free-regions.rs:21:9 | LL | C { f: b } | ^ | note: first, the lifetime cannot outlive the anonymous lifetime defined here... - --> $DIR/type-alias-free-regions.rs:16:24 + --> $DIR/type-alias-free-regions.rs:20:24 | LL | fn from_box(b: Box) -> Self { | ^ note: ...so that the expression is assignable - --> $DIR/type-alias-free-regions.rs:17:16 + --> $DIR/type-alias-free-regions.rs:21:16 | LL | C { f: b } | ^ = note: expected `Box>` found `Box>` note: but, the lifetime must be valid for the lifetime `'a` as defined here... - --> $DIR/type-alias-free-regions.rs:15:6 + --> $DIR/type-alias-free-regions.rs:19:6 | LL | impl<'a> FromBox<'a> for C<'a> { | ^^ note: ...so that the types are compatible - --> $DIR/type-alias-free-regions.rs:17:9 + --> $DIR/type-alias-free-regions.rs:21:9 | LL | C { f: b } | ^^^^^^^^^^ @@ -30,30 +30,30 @@ LL | C { f: b } found `C<'_>` error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements - --> $DIR/type-alias-free-regions.rs:27:16 + --> $DIR/type-alias-free-regions.rs:31:16 | LL | C { f: Box::new(b.0) } | ^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the anonymous lifetime defined here... - --> $DIR/type-alias-free-regions.rs:26:23 + --> $DIR/type-alias-free-regions.rs:30:23 | LL | fn from_tuple(b: (B,)) -> Self { | ^ note: ...so that the expression is assignable - --> $DIR/type-alias-free-regions.rs:27:25 + --> $DIR/type-alias-free-regions.rs:31:25 | LL | C { f: Box::new(b.0) } | ^^^ = note: expected `Box<&isize>` found `Box<&isize>` note: but, the lifetime must be valid for the lifetime `'a` as defined here... - --> $DIR/type-alias-free-regions.rs:25:6 + --> $DIR/type-alias-free-regions.rs:29:6 | LL | impl<'a> FromTuple<'a> for C<'a> { | ^^ note: ...so that the types are compatible - --> $DIR/type-alias-free-regions.rs:27:9 + --> $DIR/type-alias-free-regions.rs:31:9 | LL | C { f: Box::new(b.0) } | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/nll/type-alias-free-regions.nll.stderr b/src/test/ui/nll/type-alias-free-regions.nll.stderr index 45fd5a2f1d65..6b746602d7ff 100644 --- a/src/test/ui/nll/type-alias-free-regions.nll.stderr +++ b/src/test/ui/nll/type-alias-free-regions.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/type-alias-free-regions.rs:17:9 + --> $DIR/type-alias-free-regions.rs:21:9 | LL | impl<'a> FromBox<'a> for C<'a> { | -- lifetime `'a` defined here @@ -9,7 +9,7 @@ LL | C { f: b } | ^^^^^^^^^^ associated function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1` error: lifetime may not live long enough - --> $DIR/type-alias-free-regions.rs:27:9 + --> $DIR/type-alias-free-regions.rs:31:9 | LL | impl<'a> FromTuple<'a> for C<'a> { | -- lifetime `'a` defined here diff --git a/src/test/ui/nll/type-alias-free-regions.rs b/src/test/ui/nll/type-alias-free-regions.rs index fd5566f35d51..59ef03449377 100644 --- a/src/test/ui/nll/type-alias-free-regions.rs +++ b/src/test/ui/nll/type-alias-free-regions.rs @@ -1,6 +1,10 @@ // Test that we don't assume that type aliases have the same type parameters // as the type they alias and then panic when we see this. +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + type A<'a> = &'a isize; type B<'a> = Box>; diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.base.stderr similarity index 90% rename from src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.stderr rename to src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.base.stderr index 4a6378b84f1e..ba17994b4376 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.stderr +++ b/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.base.stderr @@ -1,5 +1,5 @@ error[E0759]: `fn` parameter has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/constant-in-expr-inherent-1.rs:8:5 + --> $DIR/constant-in-expr-inherent-1.rs:12:5 | LL | fn foo<'a>(_: &'a u32) -> &'static u32 { | ------- this data with lifetime `'a`... diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.nll.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.nll.stderr index c39301588acf..0399d5f893d8 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.nll.stderr +++ b/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/constant-in-expr-inherent-1.rs:8:5 + --> $DIR/constant-in-expr-inherent-1.rs:12:5 | LL | fn foo<'a>(_: &'a u32) -> &'static u32 { | -- lifetime `'a` defined here diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.rs b/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.rs index e3a8a5f58dfd..0bd316aa84cf 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.rs +++ b/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.rs @@ -1,3 +1,7 @@ +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + struct Foo<'a> { x: &'a u32 } impl<'a> Foo<'a> { diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-normalize.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-normalize.base.stderr similarity index 83% rename from src/test/ui/nll/user-annotations/constant-in-expr-normalize.stderr rename to src/test/ui/nll/user-annotations/constant-in-expr-normalize.base.stderr index d33c45842140..61efa879fc04 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-normalize.stderr +++ b/src/test/ui/nll/user-annotations/constant-in-expr-normalize.base.stderr @@ -1,12 +1,12 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... - --> $DIR/constant-in-expr-normalize.rs:18:5 + --> $DIR/constant-in-expr-normalize.rs:22:5 | LL | <() as Foo<'a>>::C | ^^^^^^^^^^^^^^^^^^ | = note: ...the reference is valid for the static lifetime... note: ...but the borrowed content is only valid for the lifetime `'a` as defined here - --> $DIR/constant-in-expr-normalize.rs:17:8 + --> $DIR/constant-in-expr-normalize.rs:21:8 | LL | fn foo<'a>(_: &'a u32) -> &'static u32 { | ^^ diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-normalize.nll.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-normalize.nll.stderr index 541a2cfaf299..4c1e6bee2aa0 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-normalize.nll.stderr +++ b/src/test/ui/nll/user-annotations/constant-in-expr-normalize.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/constant-in-expr-normalize.rs:18:5 + --> $DIR/constant-in-expr-normalize.rs:22:5 | LL | fn foo<'a>(_: &'a u32) -> &'static u32 { | -- lifetime `'a` defined here diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-normalize.rs b/src/test/ui/nll/user-annotations/constant-in-expr-normalize.rs index b7095430d8bd..262f0ae318f8 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-normalize.rs +++ b/src/test/ui/nll/user-annotations/constant-in-expr-normalize.rs @@ -1,3 +1,7 @@ +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait Mirror { type Me; } diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.base.stderr similarity index 82% rename from src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.stderr rename to src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.base.stderr index 3ec3a2af8cab..93f7156e5575 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.stderr +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.base.stderr @@ -1,12 +1,12 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... - --> $DIR/constant-in-expr-trait-item-1.rs:10:5 + --> $DIR/constant-in-expr-trait-item-1.rs:14:5 | LL | <() as Foo<'a>>::C | ^^^^^^^^^^^^^^^^^^ | = note: ...the reference is valid for the static lifetime... note: ...but the borrowed content is only valid for the lifetime `'a` as defined here - --> $DIR/constant-in-expr-trait-item-1.rs:9:8 + --> $DIR/constant-in-expr-trait-item-1.rs:13:8 | LL | fn foo<'a>(_: &'a u32) -> &'static u32 { | ^^ diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.nll.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.nll.stderr index ea0fcb6d634c..990d0ae385fc 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.nll.stderr +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/constant-in-expr-trait-item-1.rs:10:5 + --> $DIR/constant-in-expr-trait-item-1.rs:14:5 | LL | fn foo<'a>(_: &'a u32) -> &'static u32 { | -- lifetime `'a` defined here diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.rs b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.rs index e0400b2cc026..512edb501c4e 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.rs +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.rs @@ -1,3 +1,7 @@ +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait Foo<'a> { const C: &'a u32; } diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.base.stderr similarity index 82% rename from src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.stderr rename to src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.base.stderr index b36bc3bdd9cd..f43ade38937d 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.stderr +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.base.stderr @@ -1,12 +1,12 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... - --> $DIR/constant-in-expr-trait-item-2.rs:10:5 + --> $DIR/constant-in-expr-trait-item-2.rs:14:5 | LL | >::C | ^^^^^^^^^^^^^^^^^ | = note: ...the reference is valid for the static lifetime... note: ...but the borrowed content is only valid for the lifetime `'a` as defined here - --> $DIR/constant-in-expr-trait-item-2.rs:9:8 + --> $DIR/constant-in-expr-trait-item-2.rs:13:8 | LL | fn foo<'a, T: Foo<'a>>() -> &'static u32 { | ^^ diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.nll.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.nll.stderr index ff549f1d88bd..8c0430f1e092 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.nll.stderr +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/constant-in-expr-trait-item-2.rs:10:5 + --> $DIR/constant-in-expr-trait-item-2.rs:14:5 | LL | fn foo<'a, T: Foo<'a>>() -> &'static u32 { | -- lifetime `'a` defined here diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.rs b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.rs index 73c4e577b05c..b3dfbd984ebb 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.rs +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.rs @@ -1,3 +1,7 @@ +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait Foo<'a> { const C: &'a u32; } diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.base.stderr similarity index 78% rename from src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.stderr rename to src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.base.stderr index 806492b71f44..e9393aa05ab3 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.stderr +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.base.stderr @@ -1,16 +1,16 @@ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements - --> $DIR/constant-in-expr-trait-item-3.rs:10:5 + --> $DIR/constant-in-expr-trait-item-3.rs:14:5 | LL | T::C | ^^^^ | note: first, the lifetime cannot outlive the lifetime `'a` as defined here... - --> $DIR/constant-in-expr-trait-item-3.rs:9:8 + --> $DIR/constant-in-expr-trait-item-3.rs:13:8 | LL | fn foo<'a, T: Foo<'a>>() -> &'static u32 { | ^^ note: ...so that the types are compatible - --> $DIR/constant-in-expr-trait-item-3.rs:10:5 + --> $DIR/constant-in-expr-trait-item-3.rs:14:5 | LL | T::C | ^^^^ @@ -18,7 +18,7 @@ LL | T::C found `Foo<'a>` = note: but, the lifetime must be valid for the static lifetime... note: ...so that reference does not outlive borrowed content - --> $DIR/constant-in-expr-trait-item-3.rs:10:5 + --> $DIR/constant-in-expr-trait-item-3.rs:14:5 | LL | T::C | ^^^^ diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.nll.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.nll.stderr index 7f160d8e398b..cbcaf042f053 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.nll.stderr +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/constant-in-expr-trait-item-3.rs:10:5 + --> $DIR/constant-in-expr-trait-item-3.rs:14:5 | LL | fn foo<'a, T: Foo<'a>>() -> &'static u32 { | -- lifetime `'a` defined here diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.rs b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.rs index 567e31ef9363..6e78d94c2f63 100644 --- a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.rs +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.rs @@ -1,3 +1,7 @@ +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait Foo<'a> { const C: &'a u32; } diff --git a/src/test/ui/not-clone-closure.stderr b/src/test/ui/not-clone-closure.stderr index a62c21f2ee97..92909797c967 100644 --- a/src/test/ui/not-clone-closure.stderr +++ b/src/test/ui/not-clone-closure.stderr @@ -11,6 +11,10 @@ LL | let hello = hello.clone(); | ^^^^^ within `[closure@$DIR/not-clone-closure.rs:7:17: 9:6]`, the trait `Clone` is not implemented for `S` | = note: required because it appears within the type `[closure@$DIR/not-clone-closure.rs:7:17: 9:6]` +help: consider annotating `S` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to previous error diff --git a/src/test/ui/on-unimplemented/no-debug.stderr b/src/test/ui/on-unimplemented/no-debug.stderr index b17c1d4c2520..417e01e491b4 100644 --- a/src/test/ui/on-unimplemented/no-debug.stderr +++ b/src/test/ui/on-unimplemented/no-debug.stderr @@ -7,6 +7,10 @@ LL | println!("{:?} {:?}", Foo, Bar); = help: the trait `Debug` is not implemented for `Foo` = note: add `#[derive(Debug)]` to `Foo` or manually `impl Debug for Foo` = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Foo` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | error[E0277]: `Bar` doesn't implement `Debug` --> $DIR/no-debug.rs:10:32 diff --git a/src/test/ui/polymorphization/const_parameters/closures.stderr b/src/test/ui/polymorphization/const_parameters/closures.stderr index d0ee89329965..f174215f257e 100644 --- a/src/test/ui/polymorphization/const_parameters/closures.stderr +++ b/src/test/ui/polymorphization/const_parameters/closures.stderr @@ -11,7 +11,7 @@ error: item has unused generic parameters --> $DIR/closures.rs:19:19 | LL | pub fn unused() -> usize { - | - generic parameter `T` is unused + | -------------- generic parameter `T` is unused LL | LL | let add_one = |x: usize| x + 1; | ^^^^^^^^^^^^^^^^ @@ -20,13 +20,13 @@ error: item has unused generic parameters --> $DIR/closures.rs:17:8 | LL | pub fn unused() -> usize { - | ^^^^^^ - generic parameter `T` is unused + | ^^^^^^ -------------- generic parameter `T` is unused error: item has unused generic parameters --> $DIR/closures.rs:28:19 | LL | pub fn used_parent() -> usize { - | - generic parameter `T` is unused + | -------------- generic parameter `T` is unused LL | let x: usize = T; LL | let add_one = |x: usize| x + 1; | ^^^^^^^^^^^^^^^^ @@ -35,7 +35,7 @@ error: item has unused generic parameters --> $DIR/closures.rs:48:13 | LL | pub fn unused_upvar() -> usize { - | - generic parameter `T` is unused + | -------------- generic parameter `T` is unused LL | let x: usize = T; LL | let y = || x; | ^^^^ diff --git a/src/test/ui/polymorphization/const_parameters/functions.stderr b/src/test/ui/polymorphization/const_parameters/functions.stderr index 03d0bbb6afe6..f2b5a7307389 100644 --- a/src/test/ui/polymorphization/const_parameters/functions.stderr +++ b/src/test/ui/polymorphization/const_parameters/functions.stderr @@ -11,7 +11,7 @@ error: item has unused generic parameters --> $DIR/functions.rs:15:8 | LL | pub fn unused() { - | ^^^^^^ - generic parameter `T` is unused + | ^^^^^^ -------------- generic parameter `T` is unused error: aborting due to previous error; 1 warning emitted diff --git a/src/test/ui/polymorphization/generators.stderr b/src/test/ui/polymorphization/generators.stderr index 1152bcb0734a..9cabb21e784a 100644 --- a/src/test/ui/polymorphization/generators.stderr +++ b/src/test/ui/polymorphization/generators.stderr @@ -23,7 +23,7 @@ error: item has unused generic parameters --> $DIR/generators.rs:60:5 | LL | pub fn unused_const() -> impl Generator<(), Yield = u32, Return = u32> + Unpin { - | - generic parameter `T` is unused + | ------------ generic parameter `T` is unused LL | / || { LL | | LL | | yield 1; diff --git a/src/test/ui/repeat-to-run-dtor-twice.stderr b/src/test/ui/repeat-to-run-dtor-twice.stderr index f07bbe3b9f3f..904413712cde 100644 --- a/src/test/ui/repeat-to-run-dtor-twice.stderr +++ b/src/test/ui/repeat-to-run-dtor-twice.stderr @@ -5,6 +5,10 @@ LL | let _ = [ a; 5 ]; | ^^^^^^^^ the trait `Copy` is not implemented for `Foo` | = note: the `Copy` trait is required because the repeated element will be copied +help: consider annotating `Foo` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to previous error diff --git a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr index 3cdab6541e7d..ea1f66d78a37 100644 --- a/src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr +++ b/src/test/ui/rfc-2361-dbg-macro/dbg-macro-requires-debug.stderr @@ -7,6 +7,10 @@ LL | let _: NotDebug = dbg!(NotDebug); = help: the trait `Debug` is not implemented for `NotDebug` = note: add `#[derive(Debug)]` to `NotDebug` or manually `impl Debug for NotDebug` = note: this error originates in the macro `$crate::format_args_nl` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `NotDebug` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | error: aborting due to previous error diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr index b0af45acda1e..0a2a5f0f2457 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/call-generic-method-nonconst.stderr @@ -17,6 +17,10 @@ note: required by a bound in `equals_self` | LL | const fn equals_self(t: &T) -> bool { | ^^^^^^^^^^^^^^^^ required by this bound in `equals_self` +help: consider annotating `S` with `#[derive(PartialEq)]` + | +LL | #[derive(PartialEq)] + | error: aborting due to previous error diff --git a/src/test/ui/rfc1623.stderr b/src/test/ui/rfc1623.base.stderr similarity index 93% rename from src/test/ui/rfc1623.stderr rename to src/test/ui/rfc1623.base.stderr index 16829b5caa0b..6d389a1317a9 100644 --- a/src/test/ui/rfc1623.stderr +++ b/src/test/ui/rfc1623.base.stderr @@ -1,5 +1,5 @@ error: implementation of `FnOnce` is not general enough - --> $DIR/rfc1623.rs:28:8 + --> $DIR/rfc1623.rs:36:8 | LL | f: &id, | ^^^ implementation of `FnOnce` is not general enough diff --git a/src/test/ui/rfc1623.nll.stderr b/src/test/ui/rfc1623.nll.stderr index 86513b6064d2..f85b6ff8ff75 100644 --- a/src/test/ui/rfc1623.nll.stderr +++ b/src/test/ui/rfc1623.nll.stderr @@ -1,11 +1,12 @@ error[E0308]: mismatched types - --> $DIR/rfc1623.rs:25:35 + --> $DIR/rfc1623.rs:29:35 | LL | static SOME_STRUCT: &SomeStruct = &SomeStruct { | ___________________________________^ -LL | | foo: &Foo { bools: &[false, true] }, -LL | | bar: &Bar { bools: &[true, true] }, -LL | | f: &id, +LL | | +LL | | +LL | | +... | LL | | LL | | }; | |_^ one type is more general than the other @@ -14,13 +15,14 @@ LL | | }; found type `Fn<(&Foo<'_>,)>` error[E0308]: mismatched types - --> $DIR/rfc1623.rs:25:35 + --> $DIR/rfc1623.rs:29:35 | LL | static SOME_STRUCT: &SomeStruct = &SomeStruct { | ___________________________________^ -LL | | foo: &Foo { bools: &[false, true] }, -LL | | bar: &Bar { bools: &[true, true] }, -LL | | f: &id, +LL | | +LL | | +LL | | +... | LL | | LL | | }; | |_^ one type is more general than the other @@ -29,13 +31,14 @@ LL | | }; found type `Fn<(&Foo<'_>,)>` error: implementation of `FnOnce` is not general enough - --> $DIR/rfc1623.rs:25:35 + --> $DIR/rfc1623.rs:29:35 | LL | static SOME_STRUCT: &SomeStruct = &SomeStruct { | ___________________________________^ -LL | | foo: &Foo { bools: &[false, true] }, -LL | | bar: &Bar { bools: &[true, true] }, -LL | | f: &id, +LL | | +LL | | +LL | | +... | LL | | LL | | }; | |_^ implementation of `FnOnce` is not general enough @@ -44,13 +47,14 @@ LL | | }; = note: ...but it actually implements `FnOnce<(&'2 Foo<'_>,)>`, for some specific lifetime `'2` error: implementation of `FnOnce` is not general enough - --> $DIR/rfc1623.rs:25:35 + --> $DIR/rfc1623.rs:29:35 | LL | static SOME_STRUCT: &SomeStruct = &SomeStruct { | ___________________________________^ -LL | | foo: &Foo { bools: &[false, true] }, -LL | | bar: &Bar { bools: &[true, true] }, -LL | | f: &id, +LL | | +LL | | +LL | | +... | LL | | LL | | }; | |_^ implementation of `FnOnce` is not general enough diff --git a/src/test/ui/rfc1623.rs b/src/test/ui/rfc1623.rs index 32e00f9cb76c..0e9d21403242 100644 --- a/src/test/ui/rfc1623.rs +++ b/src/test/ui/rfc1623.rs @@ -1,3 +1,7 @@ +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + #![allow(dead_code)] fn non_elidable<'a, 'b>(a: &'a u8, b: &'b u8) -> &'a u8 { @@ -23,10 +27,14 @@ fn id(t: T) -> T { } static SOME_STRUCT: &SomeStruct = &SomeStruct { + //[nll]~^ ERROR mismatched types + //[nll]~| ERROR mismatched types + //[nll]~| ERROR implementation of `FnOnce` is not general enough + //[nll]~| ERROR implementation of `FnOnce` is not general enough foo: &Foo { bools: &[false, true] }, bar: &Bar { bools: &[true, true] }, f: &id, - //~^ ERROR implementation of `FnOnce` is not general enough + //[base]~^ ERROR implementation of `FnOnce` is not general enough }; // very simple test for a 'static static with default lifetime diff --git a/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-traits.stderr b/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-traits.stderr index ea22d1c89b1c..94a90a568548 100644 --- a/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-traits.stderr +++ b/src/test/ui/rfcs/rfc-2396-target_feature-11/fn-traits.stderr @@ -53,7 +53,7 @@ error[E0277]: expected a `Fn<()>` closure, found `unsafe fn() {foo_unsafe}` --> $DIR/fn-traits.rs:28:10 | LL | call(foo_unsafe); - | ---- ^^^^^^^^^^ expected an `Fn<()>` closure, found `unsafe fn() {foo_unsafe}` + | ---- ^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` | | | required by a bound introduced by this call | @@ -70,7 +70,7 @@ error[E0277]: expected a `FnMut<()>` closure, found `unsafe fn() {foo_unsafe}` --> $DIR/fn-traits.rs:30:14 | LL | call_mut(foo_unsafe); - | -------- ^^^^^^^^^^ expected an `FnMut<()>` closure, found `unsafe fn() {foo_unsafe}` + | -------- ^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` | | | required by a bound introduced by this call | @@ -87,7 +87,7 @@ error[E0277]: expected a `FnOnce<()>` closure, found `unsafe fn() {foo_unsafe}` --> $DIR/fn-traits.rs:32:15 | LL | call_once(foo_unsafe); - | --------- ^^^^^^^^^^ expected an `FnOnce<()>` closure, found `unsafe fn() {foo_unsafe}` + | --------- ^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` | | | required by a bound introduced by this call | diff --git a/src/test/ui/save-analysis/issue-89066.stderr b/src/test/ui/save-analysis/issue-89066.stderr index a3ff1c02b2a0..5ef04936ea24 100644 --- a/src/test/ui/save-analysis/issue-89066.stderr +++ b/src/test/ui/save-analysis/issue-89066.stderr @@ -31,7 +31,7 @@ note: struct defined here, with 2 generic parameters: `T`, `N` --> $DIR/issue-89066.rs:8:8 | LL | struct All<'a, T, const N: usize> { - | ^^^ - - + | ^^^ - -------------- error: aborting due to 4 previous errors diff --git a/src/test/ui/specialization/issue-59435.stderr b/src/test/ui/specialization/issue-59435.stderr index bb5d90f001ee..211459406686 100644 --- a/src/test/ui/specialization/issue-59435.stderr +++ b/src/test/ui/specialization/issue-59435.stderr @@ -9,6 +9,10 @@ note: required by a bound in `MyTrait::MyType` | LL | type MyType: Default; | ^^^^^^^ required by this bound in `MyTrait::MyType` +help: consider annotating `MyStruct` with `#[derive(Default)]` + | +LL | #[derive(Default)] + | error: aborting due to previous error diff --git a/src/test/ui/structs/struct-path-alias-bounds.stderr b/src/test/ui/structs/struct-path-alias-bounds.stderr index 7a80e7270ba3..266291f62b45 100644 --- a/src/test/ui/structs/struct-path-alias-bounds.stderr +++ b/src/test/ui/structs/struct-path-alias-bounds.stderr @@ -9,6 +9,10 @@ note: required by a bound in `S` | LL | struct S { a: T } | ^^^^^ required by this bound in `S` +help: consider annotating `NoClone` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to previous error diff --git a/src/test/ui/suggestions/derive-macro-missing-bounds.stderr b/src/test/ui/suggestions/derive-macro-missing-bounds.stderr index 7a4f7e209c19..75658f58c8a1 100644 --- a/src/test/ui/suggestions/derive-macro-missing-bounds.stderr +++ b/src/test/ui/suggestions/derive-macro-missing-bounds.stderr @@ -9,6 +9,10 @@ LL | struct Outer(Inner); = help: the trait `Debug` is not implemented for `a::Inner` = note: add `#[derive(Debug)]` to `a::Inner` or manually `impl Debug for a::Inner` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `a::Inner` with `#[derive(Debug)]` + | +LL | #[derive(Debug)] + | help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement | LL | struct Outer(Inner) where a::Inner: Debug; diff --git a/src/test/ui/suggestions/issue-84973-blacklist.stderr b/src/test/ui/suggestions/issue-84973-blacklist.stderr index ae55c96702ad..5d8d688a073c 100644 --- a/src/test/ui/suggestions/issue-84973-blacklist.stderr +++ b/src/test/ui/suggestions/issue-84973-blacklist.stderr @@ -25,6 +25,10 @@ note: required by a bound in `f_clone` | LL | fn f_clone(t: T) {} | ^^^^^ required by this bound in `f_clone` +help: consider annotating `S` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error[E0277]: `[static generator@$DIR/issue-84973-blacklist.rs:17:13: 17:33]` cannot be unpinned --> $DIR/issue-84973-blacklist.rs:17:5 diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-before-const.fixed b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-before-const.fixed new file mode 100644 index 000000000000..3c06f4f88c1f --- /dev/null +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-before-const.fixed @@ -0,0 +1,10 @@ +// run-rustfix +// https://github.com/rust-lang/rust/issues/95616 + +fn buggy_const<'a, const N: usize>(_a: &'a Option<[u8; N]>, _f: &'a str) -> &'a str { //~ERROR [E0106] + return ""; +} + +fn main() { + buggy_const(&Some([69,69,69,69,0]), "test"); +} diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-before-const.rs b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-before-const.rs new file mode 100644 index 000000000000..110468cbbc52 --- /dev/null +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-before-const.rs @@ -0,0 +1,10 @@ +// run-rustfix +// https://github.com/rust-lang/rust/issues/95616 + +fn buggy_const(_a: &Option<[u8; N]>, _f: &str) -> &str { //~ERROR [E0106] + return ""; +} + +fn main() { + buggy_const(&Some([69,69,69,69,0]), "test"); +} diff --git a/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-before-const.stderr b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-before-const.stderr new file mode 100644 index 000000000000..7b126c90ee79 --- /dev/null +++ b/src/test/ui/suggestions/lifetimes/missing-lifetimes-in-signature-before-const.stderr @@ -0,0 +1,15 @@ +error[E0106]: missing lifetime specifier + --> $DIR/missing-lifetimes-in-signature-before-const.rs:4:67 + | +LL | fn buggy_const(_a: &Option<[u8; N]>, _f: &str) -> &str { + | ---------------- ---- ^ expected named lifetime parameter + | + = help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from `_a` or `_f` +help: consider introducing a named lifetime parameter + | +LL | fn buggy_const<'a, const N: usize>(_a: &'a Option<[u8; N]>, _f: &'a str) -> &'a str { + | +++ ++ ++ ++ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0106`. diff --git a/src/test/ui/traits/inductive-overflow/supertrait-auto-trait.stderr b/src/test/ui/traits/inductive-overflow/supertrait-auto-trait.stderr index 9ceeea4872fb..d7697dcc6405 100644 --- a/src/test/ui/traits/inductive-overflow/supertrait-auto-trait.stderr +++ b/src/test/ui/traits/inductive-overflow/supertrait-auto-trait.stderr @@ -24,6 +24,10 @@ note: required by a bound in `copy` | LL | fn copy(x: T) -> (T, T) { (x, x) } | ^^^^^ required by this bound in `copy` +help: consider annotating `NoClone` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to 2 previous errors diff --git a/src/test/ui/traits/issue-71136.stderr b/src/test/ui/traits/issue-71136.stderr index 45b1e1095c7d..62a2a64ed142 100644 --- a/src/test/ui/traits/issue-71136.stderr +++ b/src/test/ui/traits/issue-71136.stderr @@ -9,6 +9,10 @@ LL | the_foos: Vec, | = note: required because of the requirements on the impl of `Clone` for `Vec` = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `Foo` with `#[derive(Clone)]` + | +LL | #[derive(Clone)] + | error: aborting due to previous error diff --git a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr index 922e41e0f688..b2edcc5526a4 100644 --- a/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_duplicate_param_use.stderr @@ -29,10 +29,10 @@ LL | t | ^ | note: constant used multiple times - --> $DIR/generic_duplicate_param_use.rs:12:22 + --> $DIR/generic_duplicate_param_use.rs:12:16 | LL | type TwoConsts = impl Debug; - | ^ ^ + | ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr b/src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr index 36694900c17b..6c82d31e18d8 100644 --- a/src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_nondefining_use.stderr @@ -26,10 +26,10 @@ LL | 7u32 | ^^^^ | note: used non-generic constant `123_usize` for generic parameter - --> $DIR/generic_nondefining_use.rs:11:21 + --> $DIR/generic_nondefining_use.rs:11:15 | LL | type OneConst = impl Debug; - | ^ + | ^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.base.stderr similarity index 77% rename from src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr rename to src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.base.stderr index 15ec2eed3da4..a3b410c2cfb8 100644 --- a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.base.stderr @@ -1,23 +1,23 @@ error: at least one trait must be specified - --> $DIR/generic_type_does_not_live_long_enough.rs:10:24 + --> $DIR/generic_type_does_not_live_long_enough.rs:14:24 | LL | type WrongGeneric = impl 'static; | ^^^^^^^^^^^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_type_does_not_live_long_enough.rs:6:18 + --> $DIR/generic_type_does_not_live_long_enough.rs:10:18 | LL | let z: i32 = x; | ^ | note: used non-generic type `&'static i32` for generic parameter - --> $DIR/generic_type_does_not_live_long_enough.rs:10:19 + --> $DIR/generic_type_does_not_live_long_enough.rs:14:19 | LL | type WrongGeneric = impl 'static; | ^ error[E0310]: the parameter type `T` may not live long enough - --> $DIR/generic_type_does_not_live_long_enough.rs:14:5 + --> $DIR/generic_type_does_not_live_long_enough.rs:18:5 | LL | fn wrong_generic(t: T) -> WrongGeneric { | - help: consider adding an explicit lifetime bound...: `T: 'static` diff --git a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr index dc85db66d32b..db771d211322 100644 --- a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr +++ b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.nll.stderr @@ -1,23 +1,23 @@ error: at least one trait must be specified - --> $DIR/generic_type_does_not_live_long_enough.rs:10:24 + --> $DIR/generic_type_does_not_live_long_enough.rs:14:24 | LL | type WrongGeneric = impl 'static; | ^^^^^^^^^^^^ error: non-defining opaque type use in defining scope - --> $DIR/generic_type_does_not_live_long_enough.rs:6:18 + --> $DIR/generic_type_does_not_live_long_enough.rs:10:18 | LL | let z: i32 = x; | ^ | note: used non-generic type `&'static i32` for generic parameter - --> $DIR/generic_type_does_not_live_long_enough.rs:10:19 + --> $DIR/generic_type_does_not_live_long_enough.rs:14:19 | LL | type WrongGeneric = impl 'static; | ^ error[E0310]: the parameter type `T` may not live long enough - --> $DIR/generic_type_does_not_live_long_enough.rs:14:5 + --> $DIR/generic_type_does_not_live_long_enough.rs:18:5 | LL | t | ^ diff --git a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs index cb90776472b5..2ad7e615e19c 100644 --- a/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs +++ b/src/test/ui/type-alias-impl-trait/generic_type_does_not_live_long_enough.rs @@ -1,5 +1,9 @@ #![feature(type_alias_impl_trait)] +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + fn main() { let y = 42; let x = wrong_generic(&y); diff --git a/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr b/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.base.stderr similarity index 90% rename from src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr rename to src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.base.stderr index 45329ea292dc..be77b60ca8ff 100644 --- a/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.base.stderr @@ -1,5 +1,5 @@ error: implementation of `FnOnce` is not general enough - --> $DIR/issue-57611-trait-alias.rs:20:9 + --> $DIR/issue-57611-trait-alias.rs:25:9 | LL | |x| x | ^^^^^ implementation of `FnOnce` is not general enough diff --git a/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.nll.stderr b/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.nll.stderr index 91daa65d6563..f5b91567ff53 100644 --- a/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.nll.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.nll.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-57611-trait-alias.rs:20:9 + --> $DIR/issue-57611-trait-alias.rs:25:9 | LL | |x| x | ^^^^^ one type is more general than the other @@ -7,13 +7,13 @@ LL | |x| x = note: expected type `for<'r> Fn<(&'r X,)>` found type `Fn<(&X,)>` note: this closure does not fulfill the lifetime requirements - --> $DIR/issue-57611-trait-alias.rs:20:9 + --> $DIR/issue-57611-trait-alias.rs:25:9 | LL | |x| x | ^^^^^ error: implementation of `FnOnce` is not general enough - --> $DIR/issue-57611-trait-alias.rs:20:9 + --> $DIR/issue-57611-trait-alias.rs:25:9 | LL | |x| x | ^^^^^ implementation of `FnOnce` is not general enough diff --git a/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.rs b/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.rs index 7c6e76424847..e95ddab75bee 100644 --- a/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.rs +++ b/src/test/ui/type-alias-impl-trait/issue-57611-trait-alias.rs @@ -1,6 +1,11 @@ // Regression test for issue #57611 // Ensures that we don't ICE // FIXME: This should compile, but it currently doesn't +// known-bug + +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir #![feature(trait_alias)] #![feature(type_alias_impl_trait)] @@ -18,7 +23,6 @@ impl Foo for X { fn bar(&self) -> Self::Bar { |x| x - //~^ ERROR implementation of `FnOnce` is not general enough } } diff --git a/src/test/ui/type/type-check-defaults.stderr b/src/test/ui/type/type-check-defaults.stderr index f292877f30ea..56a9b5317f76 100644 --- a/src/test/ui/type/type-check-defaults.stderr +++ b/src/test/ui/type/type-check-defaults.stderr @@ -2,7 +2,7 @@ error[E0277]: a value of type `i32` cannot be built from an iterator over elemen --> $DIR/type-check-defaults.rs:6:19 | LL | struct WellFormed>(Z); - | ^ value of type `i32` cannot be built from `std::iter::Iterator` + | ^^^^^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator` is not implemented for `i32` note: required by a bound in `Foo` @@ -15,7 +15,7 @@ error[E0277]: a value of type `i32` cannot be built from an iterator over elemen --> $DIR/type-check-defaults.rs:8:27 | LL | struct WellFormedNoBounds>(Z); - | ^ value of type `i32` cannot be built from `std::iter::Iterator` + | ^^^^^^^^^^^^^^^^^^^^^^^^ value of type `i32` cannot be built from `std::iter::Iterator` | = help: the trait `FromIterator` is not implemented for `i32` note: required by a bound in `Foo` diff --git a/src/test/ui/typeck/explain_clone_autoref.rs b/src/test/ui/typeck/explain_clone_autoref.rs new file mode 100644 index 000000000000..9279e4c3901d --- /dev/null +++ b/src/test/ui/typeck/explain_clone_autoref.rs @@ -0,0 +1,13 @@ +struct NotClone; + +fn main() { + clone_thing(&NotClone); +} + +fn clone_thing(nc: &NotClone) -> NotClone { + //~^ NOTE expected `NotClone` because of return type + nc.clone() + //~^ ERROR mismatched type + //~| NOTE `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead + //~| NOTE expected struct `NotClone`, found `&NotClone` +} diff --git a/src/test/ui/typeck/explain_clone_autoref.stderr b/src/test/ui/typeck/explain_clone_autoref.stderr new file mode 100644 index 000000000000..faac680ea193 --- /dev/null +++ b/src/test/ui/typeck/explain_clone_autoref.stderr @@ -0,0 +1,18 @@ +error[E0308]: mismatched types + --> $DIR/explain_clone_autoref.rs:9:5 + | +LL | fn clone_thing(nc: &NotClone) -> NotClone { + | -------- expected `NotClone` because of return type +LL | +LL | nc.clone() + | ^^^^^^^^^^ expected struct `NotClone`, found `&NotClone` + | +note: `NotClone` does not implement `Clone`, so `&NotClone` was cloned instead + --> $DIR/explain_clone_autoref.rs:9:5 + | +LL | nc.clone() + | ^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/unboxed-closures/issue-30906.stderr b/src/test/ui/unboxed-closures/issue-30906.base.stderr similarity index 92% rename from src/test/ui/unboxed-closures/issue-30906.stderr rename to src/test/ui/unboxed-closures/issue-30906.base.stderr index 35b1e454c02b..5d555a9c5e45 100644 --- a/src/test/ui/unboxed-closures/issue-30906.stderr +++ b/src/test/ui/unboxed-closures/issue-30906.base.stderr @@ -1,5 +1,5 @@ error: implementation of `FnOnce` is not general enough - --> $DIR/issue-30906.rs:18:5 + --> $DIR/issue-30906.rs:22:5 | LL | test(Compose(f, |_| {})); | ^^^^ implementation of `FnOnce` is not general enough diff --git a/src/test/ui/unboxed-closures/issue-30906.nll.stderr b/src/test/ui/unboxed-closures/issue-30906.nll.stderr index 147a20974732..333e8e178217 100644 --- a/src/test/ui/unboxed-closures/issue-30906.nll.stderr +++ b/src/test/ui/unboxed-closures/issue-30906.nll.stderr @@ -1,5 +1,5 @@ error: implementation of `FnOnce` is not general enough - --> $DIR/issue-30906.rs:18:5 + --> $DIR/issue-30906.rs:22:5 | LL | test(Compose(f, |_| {})); | ^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough diff --git a/src/test/ui/unboxed-closures/issue-30906.rs b/src/test/ui/unboxed-closures/issue-30906.rs index e2d219e47038..1fd3a7f97dea 100644 --- a/src/test/ui/unboxed-closures/issue-30906.rs +++ b/src/test/ui/unboxed-closures/issue-30906.rs @@ -1,5 +1,9 @@ #![feature(fn_traits, unboxed_closures)] +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + fn test FnOnce<(&'x str,)>>(_: F) {} struct Compose(F, G); diff --git a/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.stderr b/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.base.stderr similarity index 92% rename from src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.stderr rename to src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.base.stderr index d7813338f68c..ebd14c642982 100644 --- a/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.stderr +++ b/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.base.stderr @@ -1,23 +1,27 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... - --> $DIR/unboxed-closures-infer-argument-types-two-region-pointers.rs:17:15 + --> $DIR/unboxed-closures-infer-argument-types-two-region-pointers.rs:21:15 | LL | x.set(y); | ^ | note: ...the reference is valid for the anonymous lifetime #2 defined here... - --> $DIR/unboxed-closures-infer-argument-types-two-region-pointers.rs:16:14 + --> $DIR/unboxed-closures-infer-argument-types-two-region-pointers.rs:20:14 | LL | doit(0, &|x, y| { | ______________^ LL | | x.set(y); +LL | | +LL | | LL | | }); | |_____^ note: ...but the borrowed content is only valid for the anonymous lifetime #3 defined here - --> $DIR/unboxed-closures-infer-argument-types-two-region-pointers.rs:16:14 + --> $DIR/unboxed-closures-infer-argument-types-two-region-pointers.rs:20:14 | LL | doit(0, &|x, y| { | ______________^ LL | | x.set(y); +LL | | +LL | | LL | | }); | |_____^ diff --git a/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.nll.stderr b/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.nll.stderr index e97157b83980..aeeee6e5003e 100644 --- a/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.nll.stderr +++ b/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/unboxed-closures-infer-argument-types-two-region-pointers.rs:17:9 + --> $DIR/unboxed-closures-infer-argument-types-two-region-pointers.rs:21:9 | LL | doit(0, &|x, y| { | - - has type `&'1 i32` diff --git a/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.rs b/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.rs index a1364b93fa4c..288349e44561 100644 --- a/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.rs +++ b/src/test/ui/unboxed-closures/unboxed-closures-infer-argument-types-two-region-pointers.rs @@ -3,6 +3,10 @@ // That a closure whose expected argument types include two distinct // bound regions. +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + use std::cell::Cell; fn doit(val: T, f: &F) @@ -14,6 +18,8 @@ fn doit(val: T, f: &F) pub fn main() { doit(0, &|x, y| { - x.set(y); //~ ERROR E0312 + x.set(y); + //[base]~^ ERROR E0312 + //[nll]~^^ lifetime may not live long enough }); } diff --git a/src/test/ui/unboxed-closures/unboxed-closures-unsafe-extern-fn.stderr b/src/test/ui/unboxed-closures/unboxed-closures-unsafe-extern-fn.stderr index c9a20232f350..18e133957ba3 100644 --- a/src/test/ui/unboxed-closures/unboxed-closures-unsafe-extern-fn.stderr +++ b/src/test/ui/unboxed-closures/unboxed-closures-unsafe-extern-fn.stderr @@ -2,11 +2,12 @@ error[E0277]: expected a `Fn<(&isize,)>` closure, found `for<'r> unsafe fn(&'r i --> $DIR/unboxed-closures-unsafe-extern-fn.rs:20:21 | LL | let x = call_it(&square, 22); - | ------- ^^^^^^^ expected an `Fn<(&isize,)>` closure, found `for<'r> unsafe fn(&'r isize) -> isize {square}` + | ------- ^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` | | | required by a bound introduced by this call | = help: the trait `for<'r> Fn<(&'r isize,)>` is not implemented for `for<'r> unsafe fn(&'r isize) -> isize {square}` + = note: unsafe function cannot be called generically without an unsafe block note: required by a bound in `call_it` --> $DIR/unboxed-closures-unsafe-extern-fn.rs:9:15 | @@ -17,11 +18,12 @@ error[E0277]: expected a `FnMut<(&isize,)>` closure, found `for<'r> unsafe fn(&' --> $DIR/unboxed-closures-unsafe-extern-fn.rs:25:25 | LL | let y = call_it_mut(&mut square, 22); - | ----------- ^^^^^^^^^^^ expected an `FnMut<(&isize,)>` closure, found `for<'r> unsafe fn(&'r isize) -> isize {square}` + | ----------- ^^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` | | | required by a bound introduced by this call | = help: the trait `for<'r> FnMut<(&'r isize,)>` is not implemented for `for<'r> unsafe fn(&'r isize) -> isize {square}` + = note: unsafe function cannot be called generically without an unsafe block note: required by a bound in `call_it_mut` --> $DIR/unboxed-closures-unsafe-extern-fn.rs:12:19 | @@ -32,11 +34,12 @@ error[E0277]: expected a `FnOnce<(&isize,)>` closure, found `for<'r> unsafe fn(& --> $DIR/unboxed-closures-unsafe-extern-fn.rs:30:26 | LL | let z = call_it_once(square, 22); - | ------------ ^^^^^^ expected an `FnOnce<(&isize,)>` closure, found `for<'r> unsafe fn(&'r isize) -> isize {square}` + | ------------ ^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` | | | required by a bound introduced by this call | = help: the trait `for<'r> FnOnce<(&'r isize,)>` is not implemented for `for<'r> unsafe fn(&'r isize) -> isize {square}` + = note: unsafe function cannot be called generically without an unsafe block note: required by a bound in `call_it_once` --> $DIR/unboxed-closures-unsafe-extern-fn.rs:15:20 | diff --git a/src/test/ui/unboxed-closures/unboxed-closures-wrong-arg-type-extern-fn.stderr b/src/test/ui/unboxed-closures/unboxed-closures-wrong-arg-type-extern-fn.stderr index 64d57773d708..c826af3c4c38 100644 --- a/src/test/ui/unboxed-closures/unboxed-closures-wrong-arg-type-extern-fn.stderr +++ b/src/test/ui/unboxed-closures/unboxed-closures-wrong-arg-type-extern-fn.stderr @@ -2,11 +2,12 @@ error[E0277]: expected a `Fn<(&isize,)>` closure, found `unsafe fn(isize) -> isi --> $DIR/unboxed-closures-wrong-arg-type-extern-fn.rs:21:21 | LL | let x = call_it(&square, 22); - | ------- ^^^^^^^ expected an `Fn<(&isize,)>` closure, found `unsafe fn(isize) -> isize {square}` + | ------- ^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` | | | required by a bound introduced by this call | = help: the trait `for<'r> Fn<(&'r isize,)>` is not implemented for `unsafe fn(isize) -> isize {square}` + = note: unsafe function cannot be called generically without an unsafe block note: required by a bound in `call_it` --> $DIR/unboxed-closures-wrong-arg-type-extern-fn.rs:10:15 | @@ -17,11 +18,12 @@ error[E0277]: expected a `FnMut<(&isize,)>` closure, found `unsafe fn(isize) -> --> $DIR/unboxed-closures-wrong-arg-type-extern-fn.rs:26:25 | LL | let y = call_it_mut(&mut square, 22); - | ----------- ^^^^^^^^^^^ expected an `FnMut<(&isize,)>` closure, found `unsafe fn(isize) -> isize {square}` + | ----------- ^^^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` | | | required by a bound introduced by this call | = help: the trait `for<'r> FnMut<(&'r isize,)>` is not implemented for `unsafe fn(isize) -> isize {square}` + = note: unsafe function cannot be called generically without an unsafe block note: required by a bound in `call_it_mut` --> $DIR/unboxed-closures-wrong-arg-type-extern-fn.rs:13:19 | @@ -32,11 +34,12 @@ error[E0277]: expected a `FnOnce<(&isize,)>` closure, found `unsafe fn(isize) -> --> $DIR/unboxed-closures-wrong-arg-type-extern-fn.rs:31:26 | LL | let z = call_it_once(square, 22); - | ------------ ^^^^^^ expected an `FnOnce<(&isize,)>` closure, found `unsafe fn(isize) -> isize {square}` + | ------------ ^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` | | | required by a bound introduced by this call | = help: the trait `for<'r> FnOnce<(&'r isize,)>` is not implemented for `unsafe fn(isize) -> isize {square}` + = note: unsafe function cannot be called generically without an unsafe block note: required by a bound in `call_it_once` --> $DIR/unboxed-closures-wrong-arg-type-extern-fn.rs:16:20 | diff --git a/src/test/ui/underscore-lifetime/dyn-trait-underscore.stderr b/src/test/ui/underscore-lifetime/dyn-trait-underscore.base.stderr similarity index 93% rename from src/test/ui/underscore-lifetime/dyn-trait-underscore.stderr rename to src/test/ui/underscore-lifetime/dyn-trait-underscore.base.stderr index f4285a0f98e7..07357795010b 100644 --- a/src/test/ui/underscore-lifetime/dyn-trait-underscore.stderr +++ b/src/test/ui/underscore-lifetime/dyn-trait-underscore.base.stderr @@ -1,5 +1,5 @@ error[E0759]: `items` has an anonymous lifetime `'_` but it needs to satisfy a `'static` lifetime requirement - --> $DIR/dyn-trait-underscore.rs:8:20 + --> $DIR/dyn-trait-underscore.rs:12:20 | LL | fn a(items: &[T]) -> Box> { | ---- this data with an anonymous lifetime `'_`... @@ -10,7 +10,7 @@ LL | Box::new(items.iter()) | ...is used and required to live as long as `'static` here | note: `'static` lifetime requirement introduced by the return type - --> $DIR/dyn-trait-underscore.rs:6:29 + --> $DIR/dyn-trait-underscore.rs:10:29 | LL | fn a(items: &[T]) -> Box> { | ^^^^^^^^^^^^^^^^^^^^^ `'static` requirement introduced here diff --git a/src/test/ui/underscore-lifetime/dyn-trait-underscore.nll.stderr b/src/test/ui/underscore-lifetime/dyn-trait-underscore.nll.stderr index 8ed48bda26e8..53d45f6a8f22 100644 --- a/src/test/ui/underscore-lifetime/dyn-trait-underscore.nll.stderr +++ b/src/test/ui/underscore-lifetime/dyn-trait-underscore.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/dyn-trait-underscore.rs:8:5 + --> $DIR/dyn-trait-underscore.rs:12:5 | LL | fn a(items: &[T]) -> Box> { | - let's call the lifetime of this reference `'1` diff --git a/src/test/ui/underscore-lifetime/dyn-trait-underscore.rs b/src/test/ui/underscore-lifetime/dyn-trait-underscore.rs index e951adf030f5..7110d4322108 100644 --- a/src/test/ui/underscore-lifetime/dyn-trait-underscore.rs +++ b/src/test/ui/underscore-lifetime/dyn-trait-underscore.rs @@ -3,9 +3,15 @@ // // cc #48468 +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + fn a(items: &[T]) -> Box> { // ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static` - Box::new(items.iter()) //~ ERROR E0759 + Box::new(items.iter()) + //[base]~^ ERROR E0759 + //[nll]~^^ ERROR lifetime may not live long enough } fn b(items: &[T]) -> Box + '_> { diff --git a/src/test/ui/underscore-lifetime/underscore-lifetime-elison-mismatch.stderr b/src/test/ui/underscore-lifetime/underscore-lifetime-elison-mismatch.base.stderr similarity index 92% rename from src/test/ui/underscore-lifetime/underscore-lifetime-elison-mismatch.stderr rename to src/test/ui/underscore-lifetime/underscore-lifetime-elison-mismatch.base.stderr index 8976da01e739..2581911f5ce2 100644 --- a/src/test/ui/underscore-lifetime/underscore-lifetime-elison-mismatch.stderr +++ b/src/test/ui/underscore-lifetime/underscore-lifetime-elison-mismatch.base.stderr @@ -1,5 +1,5 @@ error[E0623]: lifetime mismatch - --> $DIR/underscore-lifetime-elison-mismatch.rs:1:49 + --> $DIR/underscore-lifetime-elison-mismatch.rs:5:49 | LL | fn foo(x: &mut Vec<&'_ u8>, y: &'_ u8) { x.push(y); } | ------ ------ ^ ...but data from `y` flows into `x` here diff --git a/src/test/ui/underscore-lifetime/underscore-lifetime-elison-mismatch.nll.stderr b/src/test/ui/underscore-lifetime/underscore-lifetime-elison-mismatch.nll.stderr index e1d57b8ba1ed..8e10242cb133 100644 --- a/src/test/ui/underscore-lifetime/underscore-lifetime-elison-mismatch.nll.stderr +++ b/src/test/ui/underscore-lifetime/underscore-lifetime-elison-mismatch.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/underscore-lifetime-elison-mismatch.rs:1:42 + --> $DIR/underscore-lifetime-elison-mismatch.rs:5:42 | LL | fn foo(x: &mut Vec<&'_ u8>, y: &'_ u8) { x.push(y); } | - - ^^^^^^^^^ argument requires that `'1` must outlive `'2` diff --git a/src/test/ui/underscore-lifetime/underscore-lifetime-elison-mismatch.rs b/src/test/ui/underscore-lifetime/underscore-lifetime-elison-mismatch.rs index f465a804283a..6d495138da9e 100644 --- a/src/test/ui/underscore-lifetime/underscore-lifetime-elison-mismatch.rs +++ b/src/test/ui/underscore-lifetime/underscore-lifetime-elison-mismatch.rs @@ -1,3 +1,9 @@ -fn foo(x: &mut Vec<&'_ u8>, y: &'_ u8) { x.push(y); } //~ ERROR lifetime mismatch +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + +fn foo(x: &mut Vec<&'_ u8>, y: &'_ u8) { x.push(y); } +//[base]~^ ERROR lifetime mismatch +//[nll]~^^ ERROR lifetime may not live long enough fn main() {} diff --git a/src/test/ui/union/union-derive-clone.mirunsafeck.stderr b/src/test/ui/union/union-derive-clone.mirunsafeck.stderr index de0bc7830b73..c242a7de7abf 100644 --- a/src/test/ui/union/union-derive-clone.mirunsafeck.stderr +++ b/src/test/ui/union/union-derive-clone.mirunsafeck.stderr @@ -38,6 +38,10 @@ note: required by a bound in `AssertParamIsCopy` LL | pub struct AssertParamIsCopy { | ^^^^ required by this bound in `AssertParamIsCopy` = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `U1` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to 2 previous errors diff --git a/src/test/ui/union/union-derive-clone.thirunsafeck.stderr b/src/test/ui/union/union-derive-clone.thirunsafeck.stderr index de0bc7830b73..c242a7de7abf 100644 --- a/src/test/ui/union/union-derive-clone.thirunsafeck.stderr +++ b/src/test/ui/union/union-derive-clone.thirunsafeck.stderr @@ -38,6 +38,10 @@ note: required by a bound in `AssertParamIsCopy` LL | pub struct AssertParamIsCopy { | ^^^^ required by this bound in `AssertParamIsCopy` = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `U1` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to 2 previous errors diff --git a/src/test/ui/union/union-derive-eq.mirunsafeck.stderr b/src/test/ui/union/union-derive-eq.mirunsafeck.stderr index ff4dfcd29176..99505f316396 100644 --- a/src/test/ui/union/union-derive-eq.mirunsafeck.stderr +++ b/src/test/ui/union/union-derive-eq.mirunsafeck.stderr @@ -13,6 +13,10 @@ note: required by a bound in `AssertParamIsEq` LL | pub struct AssertParamIsEq { | ^^ required by this bound in `AssertParamIsEq` = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `PartialEqNotEq` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error diff --git a/src/test/ui/union/union-derive-eq.thirunsafeck.stderr b/src/test/ui/union/union-derive-eq.thirunsafeck.stderr index ff4dfcd29176..99505f316396 100644 --- a/src/test/ui/union/union-derive-eq.thirunsafeck.stderr +++ b/src/test/ui/union/union-derive-eq.thirunsafeck.stderr @@ -13,6 +13,10 @@ note: required by a bound in `AssertParamIsEq` LL | pub struct AssertParamIsEq { | ^^ required by this bound in `AssertParamIsEq` = note: this error originates in the derive macro `Eq` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider annotating `PartialEqNotEq` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error diff --git a/src/test/ui/variance/variance-associated-types2.stderr b/src/test/ui/variance/variance-associated-types2.base.stderr similarity index 85% rename from src/test/ui/variance/variance-associated-types2.stderr rename to src/test/ui/variance/variance-associated-types2.base.stderr index af4f2a7c2a06..c8ace0848719 100644 --- a/src/test/ui/variance/variance-associated-types2.stderr +++ b/src/test/ui/variance/variance-associated-types2.base.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/variance-associated-types2.rs:13:42 + --> $DIR/variance-associated-types2.rs:17:42 | LL | let _: Box> = make(); | ^^^^^^ lifetime mismatch @@ -7,7 +7,7 @@ LL | let _: Box> = make(); = note: expected trait object `dyn Foo` found trait object `dyn Foo` note: the lifetime `'a` as defined here... - --> $DIR/variance-associated-types2.rs:12:9 + --> $DIR/variance-associated-types2.rs:16:9 | LL | fn take<'a>(_: &'a u32) { | ^^ diff --git a/src/test/ui/variance/variance-associated-types2.nll.stderr b/src/test/ui/variance/variance-associated-types2.nll.stderr index 35871c1236fa..b74c40096923 100644 --- a/src/test/ui/variance/variance-associated-types2.nll.stderr +++ b/src/test/ui/variance/variance-associated-types2.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/variance-associated-types2.rs:13:12 + --> $DIR/variance-associated-types2.rs:17:12 | LL | fn take<'a>(_: &'a u32) { | -- lifetime `'a` defined here diff --git a/src/test/ui/variance/variance-associated-types2.rs b/src/test/ui/variance/variance-associated-types2.rs index 6a095fce7abf..e3c8e6d7ca24 100644 --- a/src/test/ui/variance/variance-associated-types2.rs +++ b/src/test/ui/variance/variance-associated-types2.rs @@ -1,6 +1,10 @@ // Test that dyn Foo is invariant with respect to T. // Failure to enforce invariance here can be weaponized, see #71550 for details. +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait Foo { type Bar; } @@ -11,7 +15,8 @@ fn make() -> Box> { fn take<'a>(_: &'a u32) { let _: Box> = make(); - //~^ ERROR mismatched types [E0308] + //[base]~^ ERROR mismatched types [E0308] + //[nll]~^^ ERROR lifetime may not live long enough } fn main() {} diff --git a/src/test/ui/variance/variance-btree-invariant-types.stderr b/src/test/ui/variance/variance-btree-invariant-types.base.stderr similarity index 84% rename from src/test/ui/variance/variance-btree-invariant-types.stderr rename to src/test/ui/variance/variance-btree-invariant-types.base.stderr index df519e25641c..5b78f4252b3d 100644 --- a/src/test/ui/variance/variance-btree-invariant-types.stderr +++ b/src/test/ui/variance/variance-btree-invariant-types.base.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/variance-btree-invariant-types.rs:4:5 + --> $DIR/variance-btree-invariant-types.rs:8:5 | LL | v | ^ lifetime mismatch @@ -7,164 +7,164 @@ LL | v = note: expected struct `std::collections::btree_map::IterMut<'_, &'new (), _>` found struct `std::collections::btree_map::IterMut<'_, &'static (), _>` note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:3:21 + --> $DIR/variance-btree-invariant-types.rs:7:21 | LL | fn iter_cov_key<'a, 'new>(v: IterMut<'a, &'static (), ()>) -> IterMut<'a, &'new (), ()> { | ^^^^ = note: ...does not necessarily outlive the static lifetime -error[E0308]: mismatched types - --> $DIR/variance-btree-invariant-types.rs:7:5 - | -LL | v - | ^ lifetime mismatch - | - = note: expected struct `std::collections::btree_map::IterMut<'_, _, &'new ()>` - found struct `std::collections::btree_map::IterMut<'_, _, &'static ()>` -note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:6:21 - | -LL | fn iter_cov_val<'a, 'new>(v: IterMut<'a, (), &'static ()>) -> IterMut<'a, (), &'new ()> { - | ^^^^ - = note: ...does not necessarily outlive the static lifetime - -error[E0308]: mismatched types - --> $DIR/variance-btree-invariant-types.rs:10:5 - | -LL | v - | ^ lifetime mismatch - | - = note: expected struct `std::collections::btree_map::IterMut<'_, &'static (), _>` - found struct `std::collections::btree_map::IterMut<'_, &'new (), _>` -note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:9:24 - | -LL | fn iter_contra_key<'a, 'new>(v: IterMut<'a, &'new (), ()>) -> IterMut<'a, &'static (), ()> { - | ^^^^ - = note: ...does not necessarily outlive the static lifetime - error[E0308]: mismatched types --> $DIR/variance-btree-invariant-types.rs:13:5 | LL | v | ^ lifetime mismatch | - = note: expected struct `std::collections::btree_map::IterMut<'_, _, &'static ()>` - found struct `std::collections::btree_map::IterMut<'_, _, &'new ()>` + = note: expected struct `std::collections::btree_map::IterMut<'_, _, &'new ()>` + found struct `std::collections::btree_map::IterMut<'_, _, &'static ()>` note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:12:24 + --> $DIR/variance-btree-invariant-types.rs:12:21 | -LL | fn iter_contra_val<'a, 'new>(v: IterMut<'a, (), &'new ()>) -> IterMut<'a, (), &'static ()> { +LL | fn iter_cov_val<'a, 'new>(v: IterMut<'a, (), &'static ()>) -> IterMut<'a, (), &'new ()> { + | ^^^^ + = note: ...does not necessarily outlive the static lifetime + +error[E0308]: mismatched types + --> $DIR/variance-btree-invariant-types.rs:18:5 + | +LL | v + | ^ lifetime mismatch + | + = note: expected struct `std::collections::btree_map::IterMut<'_, &'static (), _>` + found struct `std::collections::btree_map::IterMut<'_, &'new (), _>` +note: the lifetime `'new` as defined here... + --> $DIR/variance-btree-invariant-types.rs:17:24 + | +LL | fn iter_contra_key<'a, 'new>(v: IterMut<'a, &'new (), ()>) -> IterMut<'a, &'static (), ()> { | ^^^^ = note: ...does not necessarily outlive the static lifetime -error[E0308]: mismatched types - --> $DIR/variance-btree-invariant-types.rs:17:5 - | -LL | v - | ^ lifetime mismatch - | - = note: expected struct `RangeMut<'_, &'new (), _>` - found struct `RangeMut<'_, &'static (), _>` -note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:16:22 - | -LL | fn range_cov_key<'a, 'new>(v: RangeMut<'a, &'static (), ()>) -> RangeMut<'a, &'new (), ()> { - | ^^^^ - = note: ...does not necessarily outlive the static lifetime - -error[E0308]: mismatched types - --> $DIR/variance-btree-invariant-types.rs:20:5 - | -LL | v - | ^ lifetime mismatch - | - = note: expected struct `RangeMut<'_, _, &'new ()>` - found struct `RangeMut<'_, _, &'static ()>` -note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:19:22 - | -LL | fn range_cov_val<'a, 'new>(v: RangeMut<'a, (), &'static ()>) -> RangeMut<'a, (), &'new ()> { - | ^^^^ - = note: ...does not necessarily outlive the static lifetime - error[E0308]: mismatched types --> $DIR/variance-btree-invariant-types.rs:23:5 | LL | v | ^ lifetime mismatch | - = note: expected struct `RangeMut<'_, &'static (), _>` - found struct `RangeMut<'_, &'new (), _>` + = note: expected struct `std::collections::btree_map::IterMut<'_, _, &'static ()>` + found struct `std::collections::btree_map::IterMut<'_, _, &'new ()>` note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:22:25 + --> $DIR/variance-btree-invariant-types.rs:22:24 | -LL | fn range_contra_key<'a, 'new>(v: RangeMut<'a, &'new (), ()>) -> RangeMut<'a, &'static (), ()> { - | ^^^^ +LL | fn iter_contra_val<'a, 'new>(v: IterMut<'a, (), &'new ()>) -> IterMut<'a, (), &'static ()> { + | ^^^^ = note: ...does not necessarily outlive the static lifetime error[E0308]: mismatched types - --> $DIR/variance-btree-invariant-types.rs:26:5 + --> $DIR/variance-btree-invariant-types.rs:29:5 | LL | v | ^ lifetime mismatch | - = note: expected struct `RangeMut<'_, _, &'static ()>` - found struct `RangeMut<'_, _, &'new ()>` + = note: expected struct `RangeMut<'_, &'new (), _>` + found struct `RangeMut<'_, &'static (), _>` note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:25:25 + --> $DIR/variance-btree-invariant-types.rs:28:22 | -LL | fn range_contra_val<'a, 'new>(v: RangeMut<'a, (), &'new ()>) -> RangeMut<'a, (), &'static ()> { - | ^^^^ +LL | fn range_cov_key<'a, 'new>(v: RangeMut<'a, &'static (), ()>) -> RangeMut<'a, &'new (), ()> { + | ^^^^ = note: ...does not necessarily outlive the static lifetime error[E0308]: mismatched types - --> $DIR/variance-btree-invariant-types.rs:31:5 + --> $DIR/variance-btree-invariant-types.rs:34:5 | LL | v | ^ lifetime mismatch | - = note: expected struct `std::collections::btree_map::OccupiedEntry<'_, &'new (), _>` - found struct `std::collections::btree_map::OccupiedEntry<'_, &'static (), _>` + = note: expected struct `RangeMut<'_, _, &'new ()>` + found struct `RangeMut<'_, _, &'static ()>` note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:29:20 + --> $DIR/variance-btree-invariant-types.rs:33:22 | -LL | fn occ_cov_key<'a, 'new>(v: OccupiedEntry<'a, &'static (), ()>) - | ^^^^ - = note: ...does not necessarily outlive the static lifetime - -error[E0308]: mismatched types - --> $DIR/variance-btree-invariant-types.rs:35:5 - | -LL | v - | ^ lifetime mismatch - | - = note: expected struct `std::collections::btree_map::OccupiedEntry<'_, _, &'new ()>` - found struct `std::collections::btree_map::OccupiedEntry<'_, _, &'static ()>` -note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:33:20 - | -LL | fn occ_cov_val<'a, 'new>(v: OccupiedEntry<'a, (), &'static ()>) - | ^^^^ +LL | fn range_cov_val<'a, 'new>(v: RangeMut<'a, (), &'static ()>) -> RangeMut<'a, (), &'new ()> { + | ^^^^ = note: ...does not necessarily outlive the static lifetime error[E0308]: mismatched types --> $DIR/variance-btree-invariant-types.rs:39:5 | +LL | v + | ^ lifetime mismatch + | + = note: expected struct `RangeMut<'_, &'static (), _>` + found struct `RangeMut<'_, &'new (), _>` +note: the lifetime `'new` as defined here... + --> $DIR/variance-btree-invariant-types.rs:38:25 + | +LL | fn range_contra_key<'a, 'new>(v: RangeMut<'a, &'new (), ()>) -> RangeMut<'a, &'static (), ()> { + | ^^^^ + = note: ...does not necessarily outlive the static lifetime + +error[E0308]: mismatched types + --> $DIR/variance-btree-invariant-types.rs:44:5 + | +LL | v + | ^ lifetime mismatch + | + = note: expected struct `RangeMut<'_, _, &'static ()>` + found struct `RangeMut<'_, _, &'new ()>` +note: the lifetime `'new` as defined here... + --> $DIR/variance-btree-invariant-types.rs:43:25 + | +LL | fn range_contra_val<'a, 'new>(v: RangeMut<'a, (), &'new ()>) -> RangeMut<'a, (), &'static ()> { + | ^^^^ + = note: ...does not necessarily outlive the static lifetime + +error[E0308]: mismatched types + --> $DIR/variance-btree-invariant-types.rs:51:5 + | +LL | v + | ^ lifetime mismatch + | + = note: expected struct `std::collections::btree_map::OccupiedEntry<'_, &'new (), _>` + found struct `std::collections::btree_map::OccupiedEntry<'_, &'static (), _>` +note: the lifetime `'new` as defined here... + --> $DIR/variance-btree-invariant-types.rs:49:20 + | +LL | fn occ_cov_key<'a, 'new>(v: OccupiedEntry<'a, &'static (), ()>) + | ^^^^ + = note: ...does not necessarily outlive the static lifetime + +error[E0308]: mismatched types + --> $DIR/variance-btree-invariant-types.rs:57:5 + | +LL | v + | ^ lifetime mismatch + | + = note: expected struct `std::collections::btree_map::OccupiedEntry<'_, _, &'new ()>` + found struct `std::collections::btree_map::OccupiedEntry<'_, _, &'static ()>` +note: the lifetime `'new` as defined here... + --> $DIR/variance-btree-invariant-types.rs:55:20 + | +LL | fn occ_cov_val<'a, 'new>(v: OccupiedEntry<'a, (), &'static ()>) + | ^^^^ + = note: ...does not necessarily outlive the static lifetime + +error[E0308]: mismatched types + --> $DIR/variance-btree-invariant-types.rs:63:5 + | LL | v | ^ lifetime mismatch | = note: expected struct `std::collections::btree_map::OccupiedEntry<'_, &'static (), _>` found struct `std::collections::btree_map::OccupiedEntry<'_, &'new (), _>` note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:37:23 + --> $DIR/variance-btree-invariant-types.rs:61:23 | LL | fn occ_contra_key<'a, 'new>(v: OccupiedEntry<'a, &'new (), ()>) | ^^^^ = note: ...does not necessarily outlive the static lifetime error[E0308]: mismatched types - --> $DIR/variance-btree-invariant-types.rs:43:5 + --> $DIR/variance-btree-invariant-types.rs:69:5 | LL | v | ^ lifetime mismatch @@ -172,14 +172,14 @@ LL | v = note: expected struct `std::collections::btree_map::OccupiedEntry<'_, _, &'static ()>` found struct `std::collections::btree_map::OccupiedEntry<'_, _, &'new ()>` note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:41:23 + --> $DIR/variance-btree-invariant-types.rs:67:23 | LL | fn occ_contra_val<'a, 'new>(v: OccupiedEntry<'a, (), &'new ()>) | ^^^^ = note: ...does not necessarily outlive the static lifetime error[E0308]: mismatched types - --> $DIR/variance-btree-invariant-types.rs:48:5 + --> $DIR/variance-btree-invariant-types.rs:76:5 | LL | v | ^ lifetime mismatch @@ -187,14 +187,14 @@ LL | v = note: expected struct `std::collections::btree_map::VacantEntry<'_, &'new (), _>` found struct `std::collections::btree_map::VacantEntry<'_, &'static (), _>` note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:46:20 + --> $DIR/variance-btree-invariant-types.rs:74:20 | LL | fn vac_cov_key<'a, 'new>(v: VacantEntry<'a, &'static (), ()>) | ^^^^ = note: ...does not necessarily outlive the static lifetime error[E0308]: mismatched types - --> $DIR/variance-btree-invariant-types.rs:52:5 + --> $DIR/variance-btree-invariant-types.rs:82:5 | LL | v | ^ lifetime mismatch @@ -202,14 +202,14 @@ LL | v = note: expected struct `std::collections::btree_map::VacantEntry<'_, _, &'new ()>` found struct `std::collections::btree_map::VacantEntry<'_, _, &'static ()>` note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:50:20 + --> $DIR/variance-btree-invariant-types.rs:80:20 | LL | fn vac_cov_val<'a, 'new>(v: VacantEntry<'a, (), &'static ()>) | ^^^^ = note: ...does not necessarily outlive the static lifetime error[E0308]: mismatched types - --> $DIR/variance-btree-invariant-types.rs:56:5 + --> $DIR/variance-btree-invariant-types.rs:88:5 | LL | v | ^ lifetime mismatch @@ -217,14 +217,14 @@ LL | v = note: expected struct `std::collections::btree_map::VacantEntry<'_, &'static (), _>` found struct `std::collections::btree_map::VacantEntry<'_, &'new (), _>` note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:54:23 + --> $DIR/variance-btree-invariant-types.rs:86:23 | LL | fn vac_contra_key<'a, 'new>(v: VacantEntry<'a, &'new (), ()>) | ^^^^ = note: ...does not necessarily outlive the static lifetime error[E0308]: mismatched types - --> $DIR/variance-btree-invariant-types.rs:60:5 + --> $DIR/variance-btree-invariant-types.rs:94:5 | LL | v | ^ lifetime mismatch @@ -232,7 +232,7 @@ LL | v = note: expected struct `std::collections::btree_map::VacantEntry<'_, _, &'static ()>` found struct `std::collections::btree_map::VacantEntry<'_, _, &'new ()>` note: the lifetime `'new` as defined here... - --> $DIR/variance-btree-invariant-types.rs:58:23 + --> $DIR/variance-btree-invariant-types.rs:92:23 | LL | fn vac_contra_val<'a, 'new>(v: VacantEntry<'a, (), &'new ()>) | ^^^^ diff --git a/src/test/ui/variance/variance-btree-invariant-types.nll.stderr b/src/test/ui/variance/variance-btree-invariant-types.nll.stderr index 0d9815cf788a..991a7b0cdf07 100644 --- a/src/test/ui/variance/variance-btree-invariant-types.nll.stderr +++ b/src/test/ui/variance/variance-btree-invariant-types.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:4:5 + --> $DIR/variance-btree-invariant-types.rs:8:5 | LL | fn iter_cov_key<'a, 'new>(v: IterMut<'a, &'static (), ()>) -> IterMut<'a, &'new (), ()> { | ---- lifetime `'new` defined here @@ -11,7 +11,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:7:5 + --> $DIR/variance-btree-invariant-types.rs:13:5 | LL | fn iter_cov_val<'a, 'new>(v: IterMut<'a, (), &'static ()>) -> IterMut<'a, (), &'new ()> { | ---- lifetime `'new` defined here @@ -23,7 +23,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:10:5 + --> $DIR/variance-btree-invariant-types.rs:18:5 | LL | fn iter_contra_key<'a, 'new>(v: IterMut<'a, &'new (), ()>) -> IterMut<'a, &'static (), ()> { | ---- lifetime `'new` defined here @@ -35,7 +35,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:13:5 + --> $DIR/variance-btree-invariant-types.rs:23:5 | LL | fn iter_contra_val<'a, 'new>(v: IterMut<'a, (), &'new ()>) -> IterMut<'a, (), &'static ()> { | ---- lifetime `'new` defined here @@ -47,7 +47,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:17:5 + --> $DIR/variance-btree-invariant-types.rs:29:5 | LL | fn range_cov_key<'a, 'new>(v: RangeMut<'a, &'static (), ()>) -> RangeMut<'a, &'new (), ()> { | ---- lifetime `'new` defined here @@ -59,7 +59,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:20:5 + --> $DIR/variance-btree-invariant-types.rs:34:5 | LL | fn range_cov_val<'a, 'new>(v: RangeMut<'a, (), &'static ()>) -> RangeMut<'a, (), &'new ()> { | ---- lifetime `'new` defined here @@ -71,7 +71,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:23:5 + --> $DIR/variance-btree-invariant-types.rs:39:5 | LL | fn range_contra_key<'a, 'new>(v: RangeMut<'a, &'new (), ()>) -> RangeMut<'a, &'static (), ()> { | ---- lifetime `'new` defined here @@ -83,7 +83,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:26:5 + --> $DIR/variance-btree-invariant-types.rs:44:5 | LL | fn range_contra_val<'a, 'new>(v: RangeMut<'a, (), &'new ()>) -> RangeMut<'a, (), &'static ()> { | ---- lifetime `'new` defined here @@ -95,7 +95,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:31:5 + --> $DIR/variance-btree-invariant-types.rs:51:5 | LL | fn occ_cov_key<'a, 'new>(v: OccupiedEntry<'a, &'static (), ()>) | ---- lifetime `'new` defined here @@ -108,7 +108,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:35:5 + --> $DIR/variance-btree-invariant-types.rs:57:5 | LL | fn occ_cov_val<'a, 'new>(v: OccupiedEntry<'a, (), &'static ()>) | ---- lifetime `'new` defined here @@ -121,7 +121,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:39:5 + --> $DIR/variance-btree-invariant-types.rs:63:5 | LL | fn occ_contra_key<'a, 'new>(v: OccupiedEntry<'a, &'new (), ()>) | ---- lifetime `'new` defined here @@ -134,7 +134,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:43:5 + --> $DIR/variance-btree-invariant-types.rs:69:5 | LL | fn occ_contra_val<'a, 'new>(v: OccupiedEntry<'a, (), &'new ()>) | ---- lifetime `'new` defined here @@ -147,7 +147,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:48:5 + --> $DIR/variance-btree-invariant-types.rs:76:5 | LL | fn vac_cov_key<'a, 'new>(v: VacantEntry<'a, &'static (), ()>) | ---- lifetime `'new` defined here @@ -160,7 +160,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:52:5 + --> $DIR/variance-btree-invariant-types.rs:82:5 | LL | fn vac_cov_val<'a, 'new>(v: VacantEntry<'a, (), &'static ()>) | ---- lifetime `'new` defined here @@ -173,7 +173,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:56:5 + --> $DIR/variance-btree-invariant-types.rs:88:5 | LL | fn vac_contra_key<'a, 'new>(v: VacantEntry<'a, &'new (), ()>) | ---- lifetime `'new` defined here @@ -186,7 +186,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-btree-invariant-types.rs:60:5 + --> $DIR/variance-btree-invariant-types.rs:94:5 | LL | fn vac_contra_val<'a, 'new>(v: VacantEntry<'a, (), &'new ()>) | ---- lifetime `'new` defined here diff --git a/src/test/ui/variance/variance-btree-invariant-types.rs b/src/test/ui/variance/variance-btree-invariant-types.rs index 4549622f24ac..7ddf6b294a5a 100644 --- a/src/test/ui/variance/variance-btree-invariant-types.rs +++ b/src/test/ui/variance/variance-btree-invariant-types.rs @@ -1,63 +1,99 @@ use std::collections::btree_map::{IterMut, OccupiedEntry, RangeMut, VacantEntry}; +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + fn iter_cov_key<'a, 'new>(v: IterMut<'a, &'static (), ()>) -> IterMut<'a, &'new (), ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } fn iter_cov_val<'a, 'new>(v: IterMut<'a, (), &'static ()>) -> IterMut<'a, (), &'new ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } fn iter_contra_key<'a, 'new>(v: IterMut<'a, &'new (), ()>) -> IterMut<'a, &'static (), ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } fn iter_contra_val<'a, 'new>(v: IterMut<'a, (), &'new ()>) -> IterMut<'a, (), &'static ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } fn range_cov_key<'a, 'new>(v: RangeMut<'a, &'static (), ()>) -> RangeMut<'a, &'new (), ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } fn range_cov_val<'a, 'new>(v: RangeMut<'a, (), &'static ()>) -> RangeMut<'a, (), &'new ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } fn range_contra_key<'a, 'new>(v: RangeMut<'a, &'new (), ()>) -> RangeMut<'a, &'static (), ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } fn range_contra_val<'a, 'new>(v: RangeMut<'a, (), &'new ()>) -> RangeMut<'a, (), &'static ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } fn occ_cov_key<'a, 'new>(v: OccupiedEntry<'a, &'static (), ()>) -> OccupiedEntry<'a, &'new (), ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } fn occ_cov_val<'a, 'new>(v: OccupiedEntry<'a, (), &'static ()>) -> OccupiedEntry<'a, (), &'new ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } fn occ_contra_key<'a, 'new>(v: OccupiedEntry<'a, &'new (), ()>) -> OccupiedEntry<'a, &'static (), ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } fn occ_contra_val<'a, 'new>(v: OccupiedEntry<'a, (), &'new ()>) -> OccupiedEntry<'a, (), &'static ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } fn vac_cov_key<'a, 'new>(v: VacantEntry<'a, &'static (), ()>) -> VacantEntry<'a, &'new (), ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } fn vac_cov_val<'a, 'new>(v: VacantEntry<'a, (), &'static ()>) -> VacantEntry<'a, (), &'new ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } fn vac_contra_key<'a, 'new>(v: VacantEntry<'a, &'new (), ()>) -> VacantEntry<'a, &'static (), ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } fn vac_contra_val<'a, 'new>(v: VacantEntry<'a, (), &'new ()>) -> VacantEntry<'a, (), &'static ()> { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ lifetime may not live long enough } diff --git a/src/test/ui/variance/variance-cell-is-invariant.stderr b/src/test/ui/variance/variance-cell-is-invariant.base.stderr similarity index 92% rename from src/test/ui/variance/variance-cell-is-invariant.stderr rename to src/test/ui/variance/variance-cell-is-invariant.base.stderr index 6fcd6460fe30..e3180b6d9847 100644 --- a/src/test/ui/variance/variance-cell-is-invariant.stderr +++ b/src/test/ui/variance/variance-cell-is-invariant.base.stderr @@ -1,5 +1,5 @@ error[E0623]: lifetime mismatch - --> $DIR/variance-cell-is-invariant.rs:14:25 + --> $DIR/variance-cell-is-invariant.rs:18:25 | LL | fn use_<'short,'long>(c: Foo<'short>, | ----------- these two types are declared with different lifetimes... diff --git a/src/test/ui/variance/variance-cell-is-invariant.nll.stderr b/src/test/ui/variance/variance-cell-is-invariant.nll.stderr index ab5435d1656d..c2e93d99c43f 100644 --- a/src/test/ui/variance/variance-cell-is-invariant.nll.stderr +++ b/src/test/ui/variance/variance-cell-is-invariant.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/variance-cell-is-invariant.rs:14:12 + --> $DIR/variance-cell-is-invariant.rs:18:12 | LL | fn use_<'short,'long>(c: Foo<'short>, | ------ ----- lifetime `'long` defined here diff --git a/src/test/ui/variance/variance-cell-is-invariant.rs b/src/test/ui/variance/variance-cell-is-invariant.rs index ff9ad66fb0bc..b8b73147d0ee 100644 --- a/src/test/ui/variance/variance-cell-is-invariant.rs +++ b/src/test/ui/variance/variance-cell-is-invariant.rs @@ -1,6 +1,10 @@ // Test that Cell is considered invariant with respect to its // type. +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + use std::cell::Cell; struct Foo<'a> { @@ -11,7 +15,9 @@ fn use_<'short,'long>(c: Foo<'short>, s: &'short isize, l: &'long isize, _where:Option<&'short &'long ()>) { - let _: Foo<'long> = c; //~ ERROR E0623 + let _: Foo<'long> = c; + //[base]~^ ERROR E0623 + //[nll]~^^ ERROR lifetime may not live long enough } fn main() { diff --git a/src/test/ui/variance/variance-contravariant-arg-object.stderr b/src/test/ui/variance/variance-contravariant-arg-object.base.stderr similarity index 78% rename from src/test/ui/variance/variance-contravariant-arg-object.stderr rename to src/test/ui/variance/variance-contravariant-arg-object.base.stderr index 16583fa79310..19b8b9d5aa05 100644 --- a/src/test/ui/variance/variance-contravariant-arg-object.stderr +++ b/src/test/ui/variance/variance-contravariant-arg-object.base.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/variance-contravariant-arg-object.rs:14:5 + --> $DIR/variance-contravariant-arg-object.rs:18:5 | LL | v | ^ lifetime mismatch @@ -7,18 +7,18 @@ LL | v = note: expected trait object `dyn Get<&'min i32>` found trait object `dyn Get<&'max i32>` note: the lifetime `'min` as defined here... - --> $DIR/variance-contravariant-arg-object.rs:10:21 + --> $DIR/variance-contravariant-arg-object.rs:14:21 | LL | fn get_min_from_max<'min, 'max>(v: Box>) | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-contravariant-arg-object.rs:10:27 + --> $DIR/variance-contravariant-arg-object.rs:14:27 | LL | fn get_min_from_max<'min, 'max>(v: Box>) | ^^^^ error[E0308]: mismatched types - --> $DIR/variance-contravariant-arg-object.rs:22:5 + --> $DIR/variance-contravariant-arg-object.rs:28:5 | LL | v | ^ lifetime mismatch @@ -26,12 +26,12 @@ LL | v = note: expected trait object `dyn Get<&'max i32>` found trait object `dyn Get<&'min i32>` note: the lifetime `'min` as defined here... - --> $DIR/variance-contravariant-arg-object.rs:17:21 + --> $DIR/variance-contravariant-arg-object.rs:23:21 | LL | fn get_max_from_min<'min, 'max, G>(v: Box>) | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-contravariant-arg-object.rs:17:27 + --> $DIR/variance-contravariant-arg-object.rs:23:27 | LL | fn get_max_from_min<'min, 'max, G>(v: Box>) | ^^^^ diff --git a/src/test/ui/variance/variance-contravariant-arg-object.nll.stderr b/src/test/ui/variance/variance-contravariant-arg-object.nll.stderr index 3315eaaf1c00..4071a41703e2 100644 --- a/src/test/ui/variance/variance-contravariant-arg-object.nll.stderr +++ b/src/test/ui/variance/variance-contravariant-arg-object.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/variance-contravariant-arg-object.rs:14:5 + --> $DIR/variance-contravariant-arg-object.rs:18:5 | LL | fn get_min_from_max<'min, 'max>(v: Box>) | ---- ---- lifetime `'max` defined here @@ -12,7 +12,7 @@ LL | v = help: consider adding the following bound: `'min: 'max` error: lifetime may not live long enough - --> $DIR/variance-contravariant-arg-object.rs:22:5 + --> $DIR/variance-contravariant-arg-object.rs:28:5 | LL | fn get_max_from_min<'min, 'max, G>(v: Box>) | ---- ---- lifetime `'max` defined here diff --git a/src/test/ui/variance/variance-contravariant-arg-object.rs b/src/test/ui/variance/variance-contravariant-arg-object.rs index 947f4cd8b8f4..dab42c35218b 100644 --- a/src/test/ui/variance/variance-contravariant-arg-object.rs +++ b/src/test/ui/variance/variance-contravariant-arg-object.rs @@ -3,6 +3,10 @@ // Test that even when `T` is only used in contravariant position, it // is treated as invariant. +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait Get : 'static { fn get(&self, t: T); } @@ -11,7 +15,9 @@ fn get_min_from_max<'min, 'max>(v: Box>) -> Box> where 'max : 'min { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn get_max_from_min<'min, 'max, G>(v: Box>) @@ -19,7 +25,9 @@ fn get_max_from_min<'min, 'max, G>(v: Box>) where 'max : 'min { // Previously OK: - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn main() { } diff --git a/src/test/ui/variance/variance-contravariant-arg-trait-match.stderr b/src/test/ui/variance/variance-contravariant-arg-trait-match.base.stderr similarity index 75% rename from src/test/ui/variance/variance-contravariant-arg-trait-match.stderr rename to src/test/ui/variance/variance-contravariant-arg-trait-match.base.stderr index 370e57f73df1..56cf84590107 100644 --- a/src/test/ui/variance/variance-contravariant-arg-trait-match.stderr +++ b/src/test/ui/variance/variance-contravariant-arg-trait-match.base.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/variance-contravariant-arg-trait-match.rs:13:5 + --> $DIR/variance-contravariant-arg-trait-match.rs:17:5 | LL | impls_get::() | ^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch @@ -7,18 +7,18 @@ LL | impls_get::() = note: expected type `Get<&'min i32>` found type `Get<&'max i32>` note: the lifetime `'min` as defined here... - --> $DIR/variance-contravariant-arg-trait-match.rs:10:21 + --> $DIR/variance-contravariant-arg-trait-match.rs:14:21 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-contravariant-arg-trait-match.rs:10:27 + --> $DIR/variance-contravariant-arg-trait-match.rs:14:27 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ error[E0308]: mismatched types - --> $DIR/variance-contravariant-arg-trait-match.rs:21:5 + --> $DIR/variance-contravariant-arg-trait-match.rs:27:5 | LL | impls_get::() | ^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch @@ -26,12 +26,12 @@ LL | impls_get::() = note: expected type `Get<&'max i32>` found type `Get<&'min i32>` note: the lifetime `'min` as defined here... - --> $DIR/variance-contravariant-arg-trait-match.rs:16:21 + --> $DIR/variance-contravariant-arg-trait-match.rs:22:21 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-contravariant-arg-trait-match.rs:16:27 + --> $DIR/variance-contravariant-arg-trait-match.rs:22:27 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ diff --git a/src/test/ui/variance/variance-contravariant-arg-trait-match.nll.stderr b/src/test/ui/variance/variance-contravariant-arg-trait-match.nll.stderr index 6f136750ee13..6ca8f5ed4cce 100644 --- a/src/test/ui/variance/variance-contravariant-arg-trait-match.nll.stderr +++ b/src/test/ui/variance/variance-contravariant-arg-trait-match.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/variance-contravariant-arg-trait-match.rs:13:5 + --> $DIR/variance-contravariant-arg-trait-match.rs:17:5 | LL | fn get_min_from_max<'min, 'max, G>() | ---- ---- lifetime `'max` defined here @@ -12,7 +12,7 @@ LL | impls_get::() = help: consider adding the following bound: `'min: 'max` error: lifetime may not live long enough - --> $DIR/variance-contravariant-arg-trait-match.rs:21:5 + --> $DIR/variance-contravariant-arg-trait-match.rs:27:5 | LL | fn get_max_from_min<'min, 'max, G>() | ---- ---- lifetime `'max` defined here diff --git a/src/test/ui/variance/variance-contravariant-arg-trait-match.rs b/src/test/ui/variance/variance-contravariant-arg-trait-match.rs index 904d93124c98..11513d5411cf 100644 --- a/src/test/ui/variance/variance-contravariant-arg-trait-match.rs +++ b/src/test/ui/variance/variance-contravariant-arg-trait-match.rs @@ -3,6 +3,10 @@ // Test that even when `T` is only used in contravariant position, it // is treated as invariant. +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait Get { fn get(&self, t: T); } @@ -10,7 +14,9 @@ trait Get { fn get_min_from_max<'min, 'max, G>() where 'max : 'min, G : Get<&'max i32> { - impls_get::() //~ ERROR mismatched types + impls_get::() + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn get_max_from_min<'min, 'max, G>() @@ -18,7 +24,9 @@ fn get_max_from_min<'min, 'max, G>() { // Previously OK, but now an error because traits are invariant: - impls_get::() //~ ERROR mismatched types + impls_get::() + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn impls_get() where G : Get { } diff --git a/src/test/ui/variance/variance-contravariant-self-trait-match.stderr b/src/test/ui/variance/variance-contravariant-self-trait-match.base.stderr similarity index 75% rename from src/test/ui/variance/variance-contravariant-self-trait-match.stderr rename to src/test/ui/variance/variance-contravariant-self-trait-match.base.stderr index ab14faaa5072..2ccab2ee5f08 100644 --- a/src/test/ui/variance/variance-contravariant-self-trait-match.stderr +++ b/src/test/ui/variance/variance-contravariant-self-trait-match.base.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/variance-contravariant-self-trait-match.rs:13:5 + --> $DIR/variance-contravariant-self-trait-match.rs:17:5 | LL | impls_get::<&'min G>(); | ^^^^^^^^^^^^^^^^^^^^ lifetime mismatch @@ -7,18 +7,18 @@ LL | impls_get::<&'min G>(); = note: expected type `<&'min G as Get>` found type `<&'max G as Get>` note: the lifetime `'min` as defined here... - --> $DIR/variance-contravariant-self-trait-match.rs:10:21 + --> $DIR/variance-contravariant-self-trait-match.rs:14:21 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-contravariant-self-trait-match.rs:10:27 + --> $DIR/variance-contravariant-self-trait-match.rs:14:27 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ error[E0308]: mismatched types - --> $DIR/variance-contravariant-self-trait-match.rs:22:5 + --> $DIR/variance-contravariant-self-trait-match.rs:28:5 | LL | impls_get::<&'max G>(); | ^^^^^^^^^^^^^^^^^^^^ lifetime mismatch @@ -26,12 +26,12 @@ LL | impls_get::<&'max G>(); = note: expected type `<&'max G as Get>` found type `<&'min G as Get>` note: the lifetime `'min` as defined here... - --> $DIR/variance-contravariant-self-trait-match.rs:16:21 + --> $DIR/variance-contravariant-self-trait-match.rs:22:21 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-contravariant-self-trait-match.rs:16:27 + --> $DIR/variance-contravariant-self-trait-match.rs:22:27 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ diff --git a/src/test/ui/variance/variance-contravariant-self-trait-match.nll.stderr b/src/test/ui/variance/variance-contravariant-self-trait-match.nll.stderr index fe08ce0b84d2..d2c549b1f715 100644 --- a/src/test/ui/variance/variance-contravariant-self-trait-match.nll.stderr +++ b/src/test/ui/variance/variance-contravariant-self-trait-match.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/variance-contravariant-self-trait-match.rs:13:5 + --> $DIR/variance-contravariant-self-trait-match.rs:17:5 | LL | fn get_min_from_max<'min, 'max, G>() | ---- ---- lifetime `'max` defined here @@ -12,7 +12,7 @@ LL | impls_get::<&'min G>(); = help: consider adding the following bound: `'min: 'max` error: lifetime may not live long enough - --> $DIR/variance-contravariant-self-trait-match.rs:22:5 + --> $DIR/variance-contravariant-self-trait-match.rs:28:5 | LL | fn get_max_from_min<'min, 'max, G>() | ---- ---- lifetime `'max` defined here diff --git a/src/test/ui/variance/variance-contravariant-self-trait-match.rs b/src/test/ui/variance/variance-contravariant-self-trait-match.rs index e17375841b81..f8d7c68fafe7 100644 --- a/src/test/ui/variance/variance-contravariant-self-trait-match.rs +++ b/src/test/ui/variance/variance-contravariant-self-trait-match.rs @@ -3,6 +3,10 @@ // Test that even when `Self` is only used in contravariant position, it // is treated as invariant. +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait Get { fn get(&self); } @@ -10,7 +14,9 @@ trait Get { fn get_min_from_max<'min, 'max, G>() where 'max : 'min, G : 'max, &'max G : Get { - impls_get::<&'min G>(); //~ ERROR mismatched types + impls_get::<&'min G>(); + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn get_max_from_min<'min, 'max, G>() @@ -19,7 +25,9 @@ fn get_max_from_min<'min, 'max, G>() // Previously OK, but now error because traits are invariant with // respect to all inputs. - impls_get::<&'max G>(); //~ ERROR mismatched types + impls_get::<&'max G>(); + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn impls_get() where G : Get { } diff --git a/src/test/ui/variance/variance-invariant-arg-object.stderr b/src/test/ui/variance/variance-covariant-arg-object.base.stderr similarity index 79% rename from src/test/ui/variance/variance-invariant-arg-object.stderr rename to src/test/ui/variance/variance-covariant-arg-object.base.stderr index 6c1b07e6677e..3a97875fe0ec 100644 --- a/src/test/ui/variance/variance-invariant-arg-object.stderr +++ b/src/test/ui/variance/variance-covariant-arg-object.base.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/variance-invariant-arg-object.rs:11:5 + --> $DIR/variance-covariant-arg-object.rs:19:5 | LL | v | ^ lifetime mismatch @@ -7,18 +7,18 @@ LL | v = note: expected trait object `dyn Get<&'min i32>` found trait object `dyn Get<&'max i32>` note: the lifetime `'min` as defined here... - --> $DIR/variance-invariant-arg-object.rs:7:21 + --> $DIR/variance-covariant-arg-object.rs:14:21 | LL | fn get_min_from_max<'min, 'max>(v: Box>) | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-invariant-arg-object.rs:7:27 + --> $DIR/variance-covariant-arg-object.rs:14:27 | LL | fn get_min_from_max<'min, 'max>(v: Box>) | ^^^^ error[E0308]: mismatched types - --> $DIR/variance-invariant-arg-object.rs:18:5 + --> $DIR/variance-covariant-arg-object.rs:28:5 | LL | v | ^ lifetime mismatch @@ -26,12 +26,12 @@ LL | v = note: expected trait object `dyn Get<&'max i32>` found trait object `dyn Get<&'min i32>` note: the lifetime `'min` as defined here... - --> $DIR/variance-invariant-arg-object.rs:14:21 + --> $DIR/variance-covariant-arg-object.rs:24:21 | LL | fn get_max_from_min<'min, 'max, G>(v: Box>) | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-invariant-arg-object.rs:14:27 + --> $DIR/variance-covariant-arg-object.rs:24:27 | LL | fn get_max_from_min<'min, 'max, G>(v: Box>) | ^^^^ diff --git a/src/test/ui/variance/variance-covariant-arg-object.nll.stderr b/src/test/ui/variance/variance-covariant-arg-object.nll.stderr index b116b8e263fd..1b2ec61825f8 100644 --- a/src/test/ui/variance/variance-covariant-arg-object.nll.stderr +++ b/src/test/ui/variance/variance-covariant-arg-object.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/variance-covariant-arg-object.rs:15:5 + --> $DIR/variance-covariant-arg-object.rs:19:5 | LL | fn get_min_from_max<'min, 'max>(v: Box>) | ---- ---- lifetime `'max` defined here @@ -12,7 +12,7 @@ LL | v = help: consider adding the following bound: `'min: 'max` error: lifetime may not live long enough - --> $DIR/variance-covariant-arg-object.rs:22:5 + --> $DIR/variance-covariant-arg-object.rs:28:5 | LL | fn get_max_from_min<'min, 'max, G>(v: Box>) | ---- ---- lifetime `'max` defined here diff --git a/src/test/ui/variance/variance-covariant-arg-object.rs b/src/test/ui/variance/variance-covariant-arg-object.rs index 7cbf65ae3d92..20f74a3987e1 100644 --- a/src/test/ui/variance/variance-covariant-arg-object.rs +++ b/src/test/ui/variance/variance-covariant-arg-object.rs @@ -3,6 +3,10 @@ // Test that even when `T` is only used in covariant position, it // is treated as invariant. +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait Get : 'static { fn get(&self) -> T; } @@ -12,14 +16,18 @@ fn get_min_from_max<'min, 'max>(v: Box>) where 'max : 'min { // Previously OK, now an error as traits are invariant. - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn get_max_from_min<'min, 'max, G>(v: Box>) -> Box> where 'max : 'min { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn main() { } diff --git a/src/test/ui/variance/variance-invariant-arg-trait-match.stderr b/src/test/ui/variance/variance-covariant-arg-trait-match.base.stderr similarity index 76% rename from src/test/ui/variance/variance-invariant-arg-trait-match.stderr rename to src/test/ui/variance/variance-covariant-arg-trait-match.base.stderr index 0328496546eb..1749a871230c 100644 --- a/src/test/ui/variance/variance-invariant-arg-trait-match.stderr +++ b/src/test/ui/variance/variance-covariant-arg-trait-match.base.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/variance-invariant-arg-trait-match.rs:10:5 + --> $DIR/variance-covariant-arg-trait-match.rs:18:5 | LL | impls_get::() | ^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch @@ -7,18 +7,18 @@ LL | impls_get::() = note: expected type `Get<&'min i32>` found type `Get<&'max i32>` note: the lifetime `'min` as defined here... - --> $DIR/variance-invariant-arg-trait-match.rs:7:21 + --> $DIR/variance-covariant-arg-trait-match.rs:14:21 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-invariant-arg-trait-match.rs:7:27 + --> $DIR/variance-covariant-arg-trait-match.rs:14:27 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ error[E0308]: mismatched types - --> $DIR/variance-invariant-arg-trait-match.rs:16:5 + --> $DIR/variance-covariant-arg-trait-match.rs:26:5 | LL | impls_get::() | ^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch @@ -26,12 +26,12 @@ LL | impls_get::() = note: expected type `Get<&'max i32>` found type `Get<&'min i32>` note: the lifetime `'min` as defined here... - --> $DIR/variance-invariant-arg-trait-match.rs:13:21 + --> $DIR/variance-covariant-arg-trait-match.rs:23:21 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-invariant-arg-trait-match.rs:13:27 + --> $DIR/variance-covariant-arg-trait-match.rs:23:27 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ diff --git a/src/test/ui/variance/variance-covariant-arg-trait-match.nll.stderr b/src/test/ui/variance/variance-covariant-arg-trait-match.nll.stderr index a982a29d499c..870af48b3e92 100644 --- a/src/test/ui/variance/variance-covariant-arg-trait-match.nll.stderr +++ b/src/test/ui/variance/variance-covariant-arg-trait-match.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/variance-covariant-arg-trait-match.rs:14:5 + --> $DIR/variance-covariant-arg-trait-match.rs:18:5 | LL | fn get_min_from_max<'min, 'max, G>() | ---- ---- lifetime `'max` defined here @@ -12,7 +12,7 @@ LL | impls_get::() = help: consider adding the following bound: `'min: 'max` error: lifetime may not live long enough - --> $DIR/variance-covariant-arg-trait-match.rs:20:5 + --> $DIR/variance-covariant-arg-trait-match.rs:26:5 | LL | fn get_max_from_min<'min, 'max, G>() | ---- ---- lifetime `'max` defined here diff --git a/src/test/ui/variance/variance-covariant-arg-trait-match.rs b/src/test/ui/variance/variance-covariant-arg-trait-match.rs index 2d4f0ea15827..d3d66d3fc4ba 100644 --- a/src/test/ui/variance/variance-covariant-arg-trait-match.rs +++ b/src/test/ui/variance/variance-covariant-arg-trait-match.rs @@ -3,6 +3,10 @@ // Test that even when `T` is only used in covariant position, it // is treated as invariant. +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait Get { fn get(&self) -> T; } @@ -11,13 +15,17 @@ fn get_min_from_max<'min, 'max, G>() where 'max : 'min, G : Get<&'max i32> { // Previously OK, now an error as traits are invariant. - impls_get::() //~ ERROR mismatched types + impls_get::() + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn get_max_from_min<'min, 'max, G>() where 'max : 'min, G : Get<&'min i32> { - impls_get::() //~ ERROR mismatched types + impls_get::() + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn impls_get() where G : Get { } diff --git a/src/test/ui/variance/variance-covariant-self-trait-match.stderr b/src/test/ui/variance/variance-covariant-self-trait-match.base.stderr similarity index 76% rename from src/test/ui/variance/variance-covariant-self-trait-match.stderr rename to src/test/ui/variance/variance-covariant-self-trait-match.base.stderr index b0bcb2e8422e..94afc010e213 100644 --- a/src/test/ui/variance/variance-covariant-self-trait-match.stderr +++ b/src/test/ui/variance/variance-covariant-self-trait-match.base.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/variance-covariant-self-trait-match.rs:14:5 + --> $DIR/variance-covariant-self-trait-match.rs:18:5 | LL | impls_get::<&'min G>(); | ^^^^^^^^^^^^^^^^^^^^ lifetime mismatch @@ -7,18 +7,18 @@ LL | impls_get::<&'min G>(); = note: expected type `<&'min G as Get>` found type `<&'max G as Get>` note: the lifetime `'min` as defined here... - --> $DIR/variance-covariant-self-trait-match.rs:10:21 + --> $DIR/variance-covariant-self-trait-match.rs:14:21 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-covariant-self-trait-match.rs:10:27 + --> $DIR/variance-covariant-self-trait-match.rs:14:27 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ error[E0308]: mismatched types - --> $DIR/variance-covariant-self-trait-match.rs:20:5 + --> $DIR/variance-covariant-self-trait-match.rs:26:5 | LL | impls_get::<&'max G>(); | ^^^^^^^^^^^^^^^^^^^^ lifetime mismatch @@ -26,12 +26,12 @@ LL | impls_get::<&'max G>(); = note: expected type `<&'max G as Get>` found type `<&'min G as Get>` note: the lifetime `'min` as defined here... - --> $DIR/variance-covariant-self-trait-match.rs:17:21 + --> $DIR/variance-covariant-self-trait-match.rs:23:21 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-covariant-self-trait-match.rs:17:27 + --> $DIR/variance-covariant-self-trait-match.rs:23:27 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ diff --git a/src/test/ui/variance/variance-covariant-self-trait-match.nll.stderr b/src/test/ui/variance/variance-covariant-self-trait-match.nll.stderr index 81b25e38ec6d..14da2d2a552d 100644 --- a/src/test/ui/variance/variance-covariant-self-trait-match.nll.stderr +++ b/src/test/ui/variance/variance-covariant-self-trait-match.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/variance-covariant-self-trait-match.rs:14:5 + --> $DIR/variance-covariant-self-trait-match.rs:18:5 | LL | fn get_min_from_max<'min, 'max, G>() | ---- ---- lifetime `'max` defined here @@ -12,7 +12,7 @@ LL | impls_get::<&'min G>(); = help: consider adding the following bound: `'min: 'max` error: lifetime may not live long enough - --> $DIR/variance-covariant-self-trait-match.rs:20:5 + --> $DIR/variance-covariant-self-trait-match.rs:26:5 | LL | fn get_max_from_min<'min, 'max, G>() | ---- ---- lifetime `'max` defined here diff --git a/src/test/ui/variance/variance-covariant-self-trait-match.rs b/src/test/ui/variance/variance-covariant-self-trait-match.rs index e86a5fc630bd..ece450173ca8 100644 --- a/src/test/ui/variance/variance-covariant-self-trait-match.rs +++ b/src/test/ui/variance/variance-covariant-self-trait-match.rs @@ -3,6 +3,10 @@ // Test that even when `Self` is only used in covariant position, it // is treated as invariant. +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait Get { fn get() -> Self; } @@ -11,13 +15,17 @@ fn get_min_from_max<'min, 'max, G>() where 'max : 'min, G : 'max, &'max G : Get { // Previously OK, now an error as traits are invariant. - impls_get::<&'min G>(); //~ ERROR mismatched types + impls_get::<&'min G>(); + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn get_max_from_min<'min, 'max, G>() where 'max : 'min, G : 'max, &'min G : Get { - impls_get::<&'max G>(); //~ ERROR mismatched types + impls_get::<&'max G>(); + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn impls_get() where G : Get { } diff --git a/src/test/ui/variance/variance-covariant-arg-object.stderr b/src/test/ui/variance/variance-invariant-arg-object.base.stderr similarity index 79% rename from src/test/ui/variance/variance-covariant-arg-object.stderr rename to src/test/ui/variance/variance-invariant-arg-object.base.stderr index d590a4dc2d9d..ec9271e902fe 100644 --- a/src/test/ui/variance/variance-covariant-arg-object.stderr +++ b/src/test/ui/variance/variance-invariant-arg-object.base.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/variance-covariant-arg-object.rs:15:5 + --> $DIR/variance-invariant-arg-object.rs:15:5 | LL | v | ^ lifetime mismatch @@ -7,18 +7,18 @@ LL | v = note: expected trait object `dyn Get<&'min i32>` found trait object `dyn Get<&'max i32>` note: the lifetime `'min` as defined here... - --> $DIR/variance-covariant-arg-object.rs:10:21 + --> $DIR/variance-invariant-arg-object.rs:11:21 | LL | fn get_min_from_max<'min, 'max>(v: Box>) | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-covariant-arg-object.rs:10:27 + --> $DIR/variance-invariant-arg-object.rs:11:27 | LL | fn get_min_from_max<'min, 'max>(v: Box>) | ^^^^ error[E0308]: mismatched types - --> $DIR/variance-covariant-arg-object.rs:22:5 + --> $DIR/variance-invariant-arg-object.rs:24:5 | LL | v | ^ lifetime mismatch @@ -26,12 +26,12 @@ LL | v = note: expected trait object `dyn Get<&'max i32>` found trait object `dyn Get<&'min i32>` note: the lifetime `'min` as defined here... - --> $DIR/variance-covariant-arg-object.rs:18:21 + --> $DIR/variance-invariant-arg-object.rs:20:21 | LL | fn get_max_from_min<'min, 'max, G>(v: Box>) | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-covariant-arg-object.rs:18:27 + --> $DIR/variance-invariant-arg-object.rs:20:27 | LL | fn get_max_from_min<'min, 'max, G>(v: Box>) | ^^^^ diff --git a/src/test/ui/variance/variance-invariant-arg-object.nll.stderr b/src/test/ui/variance/variance-invariant-arg-object.nll.stderr index 303c7f3388a7..47364f426566 100644 --- a/src/test/ui/variance/variance-invariant-arg-object.nll.stderr +++ b/src/test/ui/variance/variance-invariant-arg-object.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/variance-invariant-arg-object.rs:11:5 + --> $DIR/variance-invariant-arg-object.rs:15:5 | LL | fn get_min_from_max<'min, 'max>(v: Box>) | ---- ---- lifetime `'max` defined here @@ -12,7 +12,7 @@ LL | v = help: consider adding the following bound: `'min: 'max` error: lifetime may not live long enough - --> $DIR/variance-invariant-arg-object.rs:18:5 + --> $DIR/variance-invariant-arg-object.rs:24:5 | LL | fn get_max_from_min<'min, 'max, G>(v: Box>) | ---- ---- lifetime `'max` defined here diff --git a/src/test/ui/variance/variance-invariant-arg-object.rs b/src/test/ui/variance/variance-invariant-arg-object.rs index 886d263c4576..cc8820fbac69 100644 --- a/src/test/ui/variance/variance-invariant-arg-object.rs +++ b/src/test/ui/variance/variance-invariant-arg-object.rs @@ -1,5 +1,9 @@ #![allow(dead_code)] +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait Get : 'static { fn get(&self, t: T) -> T; } @@ -8,14 +12,18 @@ fn get_min_from_max<'min, 'max>(v: Box>) -> Box> where 'max : 'min { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn get_max_from_min<'min, 'max, G>(v: Box>) -> Box> where 'max : 'min { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn main() { } diff --git a/src/test/ui/variance/variance-covariant-arg-trait-match.stderr b/src/test/ui/variance/variance-invariant-arg-trait-match.base.stderr similarity index 76% rename from src/test/ui/variance/variance-covariant-arg-trait-match.stderr rename to src/test/ui/variance/variance-invariant-arg-trait-match.base.stderr index eb1766b096c0..fe2846821539 100644 --- a/src/test/ui/variance/variance-covariant-arg-trait-match.stderr +++ b/src/test/ui/variance/variance-invariant-arg-trait-match.base.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/variance-covariant-arg-trait-match.rs:14:5 + --> $DIR/variance-invariant-arg-trait-match.rs:14:5 | LL | impls_get::() | ^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch @@ -7,18 +7,18 @@ LL | impls_get::() = note: expected type `Get<&'min i32>` found type `Get<&'max i32>` note: the lifetime `'min` as defined here... - --> $DIR/variance-covariant-arg-trait-match.rs:10:21 + --> $DIR/variance-invariant-arg-trait-match.rs:11:21 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-covariant-arg-trait-match.rs:10:27 + --> $DIR/variance-invariant-arg-trait-match.rs:11:27 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ error[E0308]: mismatched types - --> $DIR/variance-covariant-arg-trait-match.rs:20:5 + --> $DIR/variance-invariant-arg-trait-match.rs:22:5 | LL | impls_get::() | ^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch @@ -26,12 +26,12 @@ LL | impls_get::() = note: expected type `Get<&'max i32>` found type `Get<&'min i32>` note: the lifetime `'min` as defined here... - --> $DIR/variance-covariant-arg-trait-match.rs:17:21 + --> $DIR/variance-invariant-arg-trait-match.rs:19:21 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-covariant-arg-trait-match.rs:17:27 + --> $DIR/variance-invariant-arg-trait-match.rs:19:27 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ diff --git a/src/test/ui/variance/variance-invariant-arg-trait-match.nll.stderr b/src/test/ui/variance/variance-invariant-arg-trait-match.nll.stderr index 2909e81fcbf7..74d2745cbbea 100644 --- a/src/test/ui/variance/variance-invariant-arg-trait-match.nll.stderr +++ b/src/test/ui/variance/variance-invariant-arg-trait-match.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/variance-invariant-arg-trait-match.rs:10:5 + --> $DIR/variance-invariant-arg-trait-match.rs:14:5 | LL | fn get_min_from_max<'min, 'max, G>() | ---- ---- lifetime `'max` defined here @@ -12,7 +12,7 @@ LL | impls_get::() = help: consider adding the following bound: `'min: 'max` error: lifetime may not live long enough - --> $DIR/variance-invariant-arg-trait-match.rs:16:5 + --> $DIR/variance-invariant-arg-trait-match.rs:22:5 | LL | fn get_max_from_min<'min, 'max, G>() | ---- ---- lifetime `'max` defined here diff --git a/src/test/ui/variance/variance-invariant-arg-trait-match.rs b/src/test/ui/variance/variance-invariant-arg-trait-match.rs index 97d0fdd98e46..498dd574bb38 100644 --- a/src/test/ui/variance/variance-invariant-arg-trait-match.rs +++ b/src/test/ui/variance/variance-invariant-arg-trait-match.rs @@ -1,5 +1,9 @@ #![allow(dead_code)] +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait Get { fn get(&self, t: T) -> T; } @@ -7,13 +11,17 @@ trait Get { fn get_min_from_max<'min, 'max, G>() where 'max : 'min, G : Get<&'max i32> { - impls_get::() //~ ERROR mismatched types + impls_get::() + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn get_max_from_min<'min, 'max, G>() where 'max : 'min, G : Get<&'min i32> { - impls_get::() //~ ERROR mismatched types + impls_get::() + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn impls_get() where G : Get { } diff --git a/src/test/ui/variance/variance-invariant-self-trait-match.stderr b/src/test/ui/variance/variance-invariant-self-trait-match.base.stderr similarity index 76% rename from src/test/ui/variance/variance-invariant-self-trait-match.stderr rename to src/test/ui/variance/variance-invariant-self-trait-match.base.stderr index c553581b564a..a2589f0ceee9 100644 --- a/src/test/ui/variance/variance-invariant-self-trait-match.stderr +++ b/src/test/ui/variance/variance-invariant-self-trait-match.base.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/variance-invariant-self-trait-match.rs:10:5 + --> $DIR/variance-invariant-self-trait-match.rs:14:5 | LL | impls_get::<&'min G>(); | ^^^^^^^^^^^^^^^^^^^^ lifetime mismatch @@ -7,18 +7,18 @@ LL | impls_get::<&'min G>(); = note: expected type `<&'min G as Get>` found type `<&'max G as Get>` note: the lifetime `'min` as defined here... - --> $DIR/variance-invariant-self-trait-match.rs:7:21 + --> $DIR/variance-invariant-self-trait-match.rs:11:21 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-invariant-self-trait-match.rs:7:27 + --> $DIR/variance-invariant-self-trait-match.rs:11:27 | LL | fn get_min_from_max<'min, 'max, G>() | ^^^^ error[E0308]: mismatched types - --> $DIR/variance-invariant-self-trait-match.rs:16:5 + --> $DIR/variance-invariant-self-trait-match.rs:22:5 | LL | impls_get::<&'max G>(); | ^^^^^^^^^^^^^^^^^^^^ lifetime mismatch @@ -26,12 +26,12 @@ LL | impls_get::<&'max G>(); = note: expected type `<&'max G as Get>` found type `<&'min G as Get>` note: the lifetime `'min` as defined here... - --> $DIR/variance-invariant-self-trait-match.rs:13:21 + --> $DIR/variance-invariant-self-trait-match.rs:19:21 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-invariant-self-trait-match.rs:13:27 + --> $DIR/variance-invariant-self-trait-match.rs:19:27 | LL | fn get_max_from_min<'min, 'max, G>() | ^^^^ diff --git a/src/test/ui/variance/variance-invariant-self-trait-match.nll.stderr b/src/test/ui/variance/variance-invariant-self-trait-match.nll.stderr index 01b2c8803ae7..9d16e89450d7 100644 --- a/src/test/ui/variance/variance-invariant-self-trait-match.nll.stderr +++ b/src/test/ui/variance/variance-invariant-self-trait-match.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/variance-invariant-self-trait-match.rs:10:5 + --> $DIR/variance-invariant-self-trait-match.rs:14:5 | LL | fn get_min_from_max<'min, 'max, G>() | ---- ---- lifetime `'max` defined here @@ -12,7 +12,7 @@ LL | impls_get::<&'min G>(); = help: consider adding the following bound: `'min: 'max` error: lifetime may not live long enough - --> $DIR/variance-invariant-self-trait-match.rs:16:5 + --> $DIR/variance-invariant-self-trait-match.rs:22:5 | LL | fn get_max_from_min<'min, 'max, G>() | ---- ---- lifetime `'max` defined here diff --git a/src/test/ui/variance/variance-invariant-self-trait-match.rs b/src/test/ui/variance/variance-invariant-self-trait-match.rs index 678eefa634bb..0f3176b14b44 100644 --- a/src/test/ui/variance/variance-invariant-self-trait-match.rs +++ b/src/test/ui/variance/variance-invariant-self-trait-match.rs @@ -1,5 +1,9 @@ #![allow(dead_code)] +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait Get { fn get(&self) -> Self; } @@ -7,13 +11,17 @@ trait Get { fn get_min_from_max<'min, 'max, G>() where 'max : 'min, &'max G : Get, G : 'max { - impls_get::<&'min G>(); //~ ERROR mismatched types + impls_get::<&'min G>(); + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn get_max_from_min<'min, 'max, G>() where 'max : 'min, &'min G : Get, G : 'min { - impls_get::<&'max G>(); //~ ERROR mismatched types + impls_get::<&'max G>(); + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn impls_get() where G : Get { } diff --git a/src/test/ui/variance/variance-trait-matching.stderr b/src/test/ui/variance/variance-trait-matching.base.stderr similarity index 89% rename from src/test/ui/variance/variance-trait-matching.stderr rename to src/test/ui/variance/variance-trait-matching.base.stderr index 514153103bea..8872620e38ae 100644 --- a/src/test/ui/variance/variance-trait-matching.stderr +++ b/src/test/ui/variance/variance-trait-matching.base.stderr @@ -1,5 +1,5 @@ error[E0621]: explicit lifetime required in the type of `get` - --> $DIR/variance-trait-matching.rs:24:5 + --> $DIR/variance-trait-matching.rs:28:5 | LL | fn get<'a, G>(get: &G) -> i32 | -- help: add explicit lifetime `'a` to the type of `get`: `&'a G` diff --git a/src/test/ui/variance/variance-trait-matching.nll.stderr b/src/test/ui/variance/variance-trait-matching.nll.stderr index 3308cc6d2501..52c5eed3167c 100644 --- a/src/test/ui/variance/variance-trait-matching.nll.stderr +++ b/src/test/ui/variance/variance-trait-matching.nll.stderr @@ -1,5 +1,5 @@ error[E0621]: explicit lifetime required in the type of `get` - --> $DIR/variance-trait-matching.rs:24:5 + --> $DIR/variance-trait-matching.rs:28:5 | LL | fn get<'a, G>(get: &G) -> i32 | -- help: add explicit lifetime `'a` to the type of `get`: `&'a G` diff --git a/src/test/ui/variance/variance-trait-matching.rs b/src/test/ui/variance/variance-trait-matching.rs index b4efee7d6040..993db93533e2 100644 --- a/src/test/ui/variance/variance-trait-matching.rs +++ b/src/test/ui/variance/variance-trait-matching.rs @@ -1,5 +1,9 @@ #![allow(dead_code)] +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + // Get is covariant in T trait Get { fn get(&self) -> T; diff --git a/src/test/ui/variance/variance-use-contravariant-struct-1.stderr b/src/test/ui/variance/variance-use-contravariant-struct-1.base.stderr similarity index 76% rename from src/test/ui/variance/variance-use-contravariant-struct-1.stderr rename to src/test/ui/variance/variance-use-contravariant-struct-1.base.stderr index ec0cb22cdb6b..a354aa52b5c7 100644 --- a/src/test/ui/variance/variance-use-contravariant-struct-1.stderr +++ b/src/test/ui/variance/variance-use-contravariant-struct-1.base.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/variance-use-contravariant-struct-1.rs:12:5 + --> $DIR/variance-use-contravariant-struct-1.rs:14:5 | LL | v | ^ lifetime mismatch @@ -7,12 +7,12 @@ LL | v = note: expected struct `SomeStruct<&'min ()>` found struct `SomeStruct<&'max ()>` note: the lifetime `'min` as defined here... - --> $DIR/variance-use-contravariant-struct-1.rs:8:8 + --> $DIR/variance-use-contravariant-struct-1.rs:10:8 | LL | fn foo<'min,'max>(v: SomeStruct<&'max ()>) | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-use-contravariant-struct-1.rs:8:13 + --> $DIR/variance-use-contravariant-struct-1.rs:10:13 | LL | fn foo<'min,'max>(v: SomeStruct<&'max ()>) | ^^^^ diff --git a/src/test/ui/variance/variance-use-contravariant-struct-1.nll.stderr b/src/test/ui/variance/variance-use-contravariant-struct-1.nll.stderr index 837c70ca3136..9549a8c08af6 100644 --- a/src/test/ui/variance/variance-use-contravariant-struct-1.nll.stderr +++ b/src/test/ui/variance/variance-use-contravariant-struct-1.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/variance-use-contravariant-struct-1.rs:12:5 + --> $DIR/variance-use-contravariant-struct-1.rs:14:5 | LL | fn foo<'min,'max>(v: SomeStruct<&'max ()>) | ---- ---- lifetime `'max` defined here diff --git a/src/test/ui/variance/variance-use-contravariant-struct-1.rs b/src/test/ui/variance/variance-use-contravariant-struct-1.rs index 8a02ef4ec85f..b55f5e76775e 100644 --- a/src/test/ui/variance/variance-use-contravariant-struct-1.rs +++ b/src/test/ui/variance/variance-use-contravariant-struct-1.rs @@ -1,7 +1,9 @@ // Test various uses of structs with distint variances to make sure // they permit lifetimes to be approximated as expected. - +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir struct SomeStruct(fn(T)); @@ -9,7 +11,9 @@ fn foo<'min,'max>(v: SomeStruct<&'max ()>) -> SomeStruct<&'min ()> where 'max : 'min { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } diff --git a/src/test/ui/variance/variance-use-covariant-struct-1.stderr b/src/test/ui/variance/variance-use-covariant-struct-1.base.stderr similarity index 78% rename from src/test/ui/variance/variance-use-covariant-struct-1.stderr rename to src/test/ui/variance/variance-use-covariant-struct-1.base.stderr index 0c0071cf9e16..542d44c27093 100644 --- a/src/test/ui/variance/variance-use-covariant-struct-1.stderr +++ b/src/test/ui/variance/variance-use-covariant-struct-1.base.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/variance-use-covariant-struct-1.rs:10:5 + --> $DIR/variance-use-covariant-struct-1.rs:14:5 | LL | v | ^ lifetime mismatch @@ -7,12 +7,12 @@ LL | v = note: expected struct `SomeStruct<&'max ()>` found struct `SomeStruct<&'min ()>` note: the lifetime `'min` as defined here... - --> $DIR/variance-use-covariant-struct-1.rs:6:8 + --> $DIR/variance-use-covariant-struct-1.rs:10:8 | LL | fn foo<'min,'max>(v: SomeStruct<&'min ()>) | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-use-covariant-struct-1.rs:6:13 + --> $DIR/variance-use-covariant-struct-1.rs:10:13 | LL | fn foo<'min,'max>(v: SomeStruct<&'min ()>) | ^^^^ diff --git a/src/test/ui/variance/variance-use-covariant-struct-1.nll.stderr b/src/test/ui/variance/variance-use-covariant-struct-1.nll.stderr index bab858c5acb3..2fac827a0fb1 100644 --- a/src/test/ui/variance/variance-use-covariant-struct-1.nll.stderr +++ b/src/test/ui/variance/variance-use-covariant-struct-1.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/variance-use-covariant-struct-1.rs:10:5 + --> $DIR/variance-use-covariant-struct-1.rs:14:5 | LL | fn foo<'min,'max>(v: SomeStruct<&'min ()>) | ---- ---- lifetime `'max` defined here diff --git a/src/test/ui/variance/variance-use-covariant-struct-1.rs b/src/test/ui/variance/variance-use-covariant-struct-1.rs index e19a35bdfacf..3e3e76d9792c 100644 --- a/src/test/ui/variance/variance-use-covariant-struct-1.rs +++ b/src/test/ui/variance/variance-use-covariant-struct-1.rs @@ -1,13 +1,19 @@ // Test that a covariant struct does not permit the lifetime of a // reference to be enlarged. +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + struct SomeStruct(T); fn foo<'min,'max>(v: SomeStruct<&'min ()>) -> SomeStruct<&'max ()> where 'max : 'min { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn main() { } diff --git a/src/test/ui/variance/variance-use-invariant-struct-1.stderr b/src/test/ui/variance/variance-use-invariant-struct-1.base.stderr similarity index 76% rename from src/test/ui/variance/variance-use-invariant-struct-1.stderr rename to src/test/ui/variance/variance-use-invariant-struct-1.base.stderr index 76e4bd76b998..02b4e91f781e 100644 --- a/src/test/ui/variance/variance-use-invariant-struct-1.stderr +++ b/src/test/ui/variance/variance-use-invariant-struct-1.base.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/variance-use-invariant-struct-1.rs:12:5 + --> $DIR/variance-use-invariant-struct-1.rs:14:5 | LL | v | ^ lifetime mismatch @@ -7,18 +7,18 @@ LL | v = note: expected struct `SomeStruct<&'min ()>` found struct `SomeStruct<&'max ()>` note: the lifetime `'min` as defined here... - --> $DIR/variance-use-invariant-struct-1.rs:8:8 + --> $DIR/variance-use-invariant-struct-1.rs:10:8 | LL | fn foo<'min,'max>(v: SomeStruct<&'max ()>) | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-use-invariant-struct-1.rs:8:13 + --> $DIR/variance-use-invariant-struct-1.rs:10:13 | LL | fn foo<'min,'max>(v: SomeStruct<&'max ()>) | ^^^^ error[E0308]: mismatched types - --> $DIR/variance-use-invariant-struct-1.rs:19:5 + --> $DIR/variance-use-invariant-struct-1.rs:23:5 | LL | v | ^ lifetime mismatch @@ -26,12 +26,12 @@ LL | v = note: expected struct `SomeStruct<&'max ()>` found struct `SomeStruct<&'min ()>` note: the lifetime `'min` as defined here... - --> $DIR/variance-use-invariant-struct-1.rs:15:8 + --> $DIR/variance-use-invariant-struct-1.rs:19:8 | LL | fn bar<'min,'max>(v: SomeStruct<&'min ()>) | ^^^^ note: ...does not necessarily outlive the lifetime `'max` as defined here - --> $DIR/variance-use-invariant-struct-1.rs:15:13 + --> $DIR/variance-use-invariant-struct-1.rs:19:13 | LL | fn bar<'min,'max>(v: SomeStruct<&'min ()>) | ^^^^ diff --git a/src/test/ui/variance/variance-use-invariant-struct-1.nll.stderr b/src/test/ui/variance/variance-use-invariant-struct-1.nll.stderr index 600b245c1f7f..e8460a388fca 100644 --- a/src/test/ui/variance/variance-use-invariant-struct-1.nll.stderr +++ b/src/test/ui/variance/variance-use-invariant-struct-1.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/variance-use-invariant-struct-1.rs:12:5 + --> $DIR/variance-use-invariant-struct-1.rs:14:5 | LL | fn foo<'min,'max>(v: SomeStruct<&'max ()>) | ---- ---- lifetime `'max` defined here @@ -15,7 +15,7 @@ LL | v = help: see for more information about variance error: lifetime may not live long enough - --> $DIR/variance-use-invariant-struct-1.rs:19:5 + --> $DIR/variance-use-invariant-struct-1.rs:23:5 | LL | fn bar<'min,'max>(v: SomeStruct<&'min ()>) | ---- ---- lifetime `'max` defined here diff --git a/src/test/ui/variance/variance-use-invariant-struct-1.rs b/src/test/ui/variance/variance-use-invariant-struct-1.rs index 4772a9fb8782..7be03514e01a 100644 --- a/src/test/ui/variance/variance-use-invariant-struct-1.rs +++ b/src/test/ui/variance/variance-use-invariant-struct-1.rs @@ -1,7 +1,9 @@ // Test various uses of structs with distint variances to make sure // they permit lifetimes to be approximated as expected. - +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir struct SomeStruct(*mut T); @@ -9,14 +11,18 @@ fn foo<'min,'max>(v: SomeStruct<&'max ()>) -> SomeStruct<&'min ()> where 'max : 'min { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } fn bar<'min,'max>(v: SomeStruct<&'min ()>) -> SomeStruct<&'max ()> where 'max : 'min { - v //~ ERROR mismatched types + v + //[base]~^ ERROR mismatched types + //[nll]~^^ ERROR lifetime may not live long enough } diff --git a/src/test/ui/wf/wf-const-type.stderr b/src/test/ui/wf/wf-const-type.stderr index 5a6d66ee7fa7..e47920d3dfcf 100644 --- a/src/test/ui/wf/wf-const-type.stderr +++ b/src/test/ui/wf/wf-const-type.stderr @@ -10,6 +10,10 @@ note: required by a bound in `IsCopy` | LL | struct IsCopy { t: T } | ^^^^ required by this bound in `IsCopy` +help: consider annotating `NotCopy` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to previous error diff --git a/src/test/ui/wf/wf-static-method.stderr b/src/test/ui/wf/wf-static-method.base.stderr similarity index 81% rename from src/test/ui/wf/wf-static-method.stderr rename to src/test/ui/wf/wf-static-method.base.stderr index c663931c5d60..186ab2790a39 100644 --- a/src/test/ui/wf/wf-static-method.stderr +++ b/src/test/ui/wf/wf-static-method.base.stderr @@ -1,131 +1,131 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content... - --> $DIR/wf-static-method.rs:17:9 + --> $DIR/wf-static-method.rs:21:9 | LL | u | ^ | note: ...the reference is valid for the lifetime `'a` as defined here... - --> $DIR/wf-static-method.rs:14:6 + --> $DIR/wf-static-method.rs:18:6 | LL | impl<'a, 'b> Foo<'a, 'b, Evil<'a, 'b>> for () { | ^^ note: ...but the borrowed content is only valid for the lifetime `'b` as defined here - --> $DIR/wf-static-method.rs:14:10 + --> $DIR/wf-static-method.rs:18:10 | LL | impl<'a, 'b> Foo<'a, 'b, Evil<'a, 'b>> for () { | ^^ error[E0478]: lifetime bound not satisfied - --> $DIR/wf-static-method.rs:26:18 + --> $DIR/wf-static-method.rs:32:18 | LL | let me = Self::make_me(); | ^^^^ | note: lifetime parameter instantiated with the lifetime `'b` as defined here - --> $DIR/wf-static-method.rs:23:10 + --> $DIR/wf-static-method.rs:29:10 | LL | impl<'a, 'b> Foo<'a, 'b, ()> for IndirectEvil<'a, 'b> { | ^^ note: but lifetime parameter must outlive the lifetime `'a` as defined here - --> $DIR/wf-static-method.rs:23:6 + --> $DIR/wf-static-method.rs:29:6 | LL | impl<'a, 'b> Foo<'a, 'b, ()> for IndirectEvil<'a, 'b> { | ^^ error[E0312]: lifetime of reference outlives lifetime of borrowed content... - --> $DIR/wf-static-method.rs:33:9 + --> $DIR/wf-static-method.rs:41:9 | LL | u | ^ | note: ...the reference is valid for the lifetime `'a` as defined here... - --> $DIR/wf-static-method.rs:31:6 + --> $DIR/wf-static-method.rs:39:6 | LL | impl<'a, 'b> Evil<'a, 'b> { | ^^ note: ...but the borrowed content is only valid for the lifetime `'b` as defined here - --> $DIR/wf-static-method.rs:31:10 + --> $DIR/wf-static-method.rs:39:10 | LL | impl<'a, 'b> Evil<'a, 'b> { | ^^ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting requirements - --> $DIR/wf-static-method.rs:41:5 + --> $DIR/wf-static-method.rs:51:5 | LL | <()>::static_evil(b) | ^^^^^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the lifetime `'b` as defined here... - --> $DIR/wf-static-method.rs:40:13 + --> $DIR/wf-static-method.rs:50:13 | LL | fn evil<'a, 'b>(b: &'b u32) -> &'a u32 { | ^^ note: ...so that reference does not outlive borrowed content - --> $DIR/wf-static-method.rs:41:23 + --> $DIR/wf-static-method.rs:51:23 | LL | <()>::static_evil(b) | ^ note: but, the lifetime must be valid for the lifetime `'a` as defined here... - --> $DIR/wf-static-method.rs:40:9 + --> $DIR/wf-static-method.rs:50:9 | LL | fn evil<'a, 'b>(b: &'b u32) -> &'a u32 { | ^^ note: ...so that reference does not outlive borrowed content - --> $DIR/wf-static-method.rs:41:5 + --> $DIR/wf-static-method.rs:51:5 | LL | <()>::static_evil(b) | ^^^^^^^^^^^^^^^^^^^^ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting requirements - --> $DIR/wf-static-method.rs:45:5 + --> $DIR/wf-static-method.rs:57:5 | LL | ::static_evil(b) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the lifetime `'b` as defined here... - --> $DIR/wf-static-method.rs:44:22 + --> $DIR/wf-static-method.rs:56:22 | LL | fn indirect_evil<'a, 'b>(b: &'b u32) -> &'a u32 { | ^^ note: ...so that reference does not outlive borrowed content - --> $DIR/wf-static-method.rs:45:33 + --> $DIR/wf-static-method.rs:57:33 | LL | ::static_evil(b) | ^ note: but, the lifetime must be valid for the lifetime `'a` as defined here... - --> $DIR/wf-static-method.rs:44:18 + --> $DIR/wf-static-method.rs:56:18 | LL | fn indirect_evil<'a, 'b>(b: &'b u32) -> &'a u32 { | ^^ note: ...so that reference does not outlive borrowed content - --> $DIR/wf-static-method.rs:45:5 + --> $DIR/wf-static-method.rs:57:5 | LL | ::static_evil(b) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'b` due to conflicting requirements - --> $DIR/wf-static-method.rs:50:5 + --> $DIR/wf-static-method.rs:63:5 | LL | ::inherent_evil(b) | ^^^^^^^^^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the lifetime `'b` as defined here... - --> $DIR/wf-static-method.rs:49:22 + --> $DIR/wf-static-method.rs:62:22 | LL | fn inherent_evil<'a, 'b>(b: &'b u32) -> &'a u32 { | ^^ note: ...so that reference does not outlive borrowed content - --> $DIR/wf-static-method.rs:50:27 + --> $DIR/wf-static-method.rs:63:27 | LL | ::inherent_evil(b) | ^ note: but, the lifetime must be valid for the lifetime `'a` as defined here... - --> $DIR/wf-static-method.rs:49:18 + --> $DIR/wf-static-method.rs:62:18 | LL | fn inherent_evil<'a, 'b>(b: &'b u32) -> &'a u32 { | ^^ note: ...so that reference does not outlive borrowed content - --> $DIR/wf-static-method.rs:50:5 + --> $DIR/wf-static-method.rs:63:5 | LL | ::inherent_evil(b) | ^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/wf/wf-static-method.nll.stderr b/src/test/ui/wf/wf-static-method.nll.stderr index 265043111956..7556d8e694d5 100644 --- a/src/test/ui/wf/wf-static-method.nll.stderr +++ b/src/test/ui/wf/wf-static-method.nll.stderr @@ -1,5 +1,5 @@ error: lifetime may not live long enough - --> $DIR/wf-static-method.rs:17:9 + --> $DIR/wf-static-method.rs:21:9 | LL | impl<'a, 'b> Foo<'a, 'b, Evil<'a, 'b>> for () { | -- -- lifetime `'b` defined here @@ -12,7 +12,7 @@ LL | u = help: consider adding the following bound: `'b: 'a` error: lifetime may not live long enough - --> $DIR/wf-static-method.rs:26:18 + --> $DIR/wf-static-method.rs:32:18 | LL | impl<'a, 'b> Foo<'a, 'b, ()> for IndirectEvil<'a, 'b> { | -- -- lifetime `'b` defined here @@ -25,7 +25,7 @@ LL | let me = Self::make_me(); = help: consider adding the following bound: `'b: 'a` error: lifetime may not live long enough - --> $DIR/wf-static-method.rs:33:9 + --> $DIR/wf-static-method.rs:41:9 | LL | impl<'a, 'b> Evil<'a, 'b> { | -- -- lifetime `'b` defined here @@ -38,7 +38,7 @@ LL | u = help: consider adding the following bound: `'b: 'a` error: lifetime may not live long enough - --> $DIR/wf-static-method.rs:41:5 + --> $DIR/wf-static-method.rs:51:5 | LL | fn evil<'a, 'b>(b: &'b u32) -> &'a u32 { | -- -- lifetime `'b` defined here @@ -50,7 +50,7 @@ LL | <()>::static_evil(b) = help: consider adding the following bound: `'b: 'a` error: lifetime may not live long enough - --> $DIR/wf-static-method.rs:45:5 + --> $DIR/wf-static-method.rs:57:5 | LL | fn indirect_evil<'a, 'b>(b: &'b u32) -> &'a u32 { | -- -- lifetime `'b` defined here @@ -62,7 +62,7 @@ LL | ::static_evil(b) = help: consider adding the following bound: `'b: 'a` error: lifetime may not live long enough - --> $DIR/wf-static-method.rs:50:5 + --> $DIR/wf-static-method.rs:63:5 | LL | fn inherent_evil<'a, 'b>(b: &'b u32) -> &'a u32 { | -- -- lifetime `'b` defined here diff --git a/src/test/ui/wf/wf-static-method.rs b/src/test/ui/wf/wf-static-method.rs index 6e805d61265a..83557ce667bf 100644 --- a/src/test/ui/wf/wf-static-method.rs +++ b/src/test/ui/wf/wf-static-method.rs @@ -4,6 +4,10 @@ // static inherent methods isn't quite working - need to // fix that before removing the check. +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + trait Foo<'a, 'b, T>: Sized { fn make_me() -> Self { loop {} } fn static_evil(u: &'b u32) -> &'a u32; @@ -14,7 +18,9 @@ struct Evil<'a, 'b: 'a>(Option<&'a &'b ()>); impl<'a, 'b> Foo<'a, 'b, Evil<'a, 'b>> for () { fn make_me() -> Self { } fn static_evil(u: &'b u32) -> &'a u32 { - u //~ ERROR E0312 + u + //[base]~^ ERROR E0312 + //[nll]~^^ ERROR lifetime may not live long enough } } @@ -23,14 +29,18 @@ struct IndirectEvil<'a, 'b: 'a>(Option<&'a &'b ()>); impl<'a, 'b> Foo<'a, 'b, ()> for IndirectEvil<'a, 'b> { fn make_me() -> Self { IndirectEvil(None) } fn static_evil(u: &'b u32) -> &'a u32 { - let me = Self::make_me(); //~ ERROR lifetime bound not satisfied + let me = Self::make_me(); + //[base]~^ ERROR lifetime bound not satisfied + //[nll]~^^ ERROR lifetime may not live long enough loop {} // (`me` could be used for the lifetime transmute). } } impl<'a, 'b> Evil<'a, 'b> { fn inherent_evil(u: &'b u32) -> &'a u32 { - u //~ ERROR E0312 + u + //[base]~^ ERROR E0312 + //[nll]~^^ ERROR lifetime may not live long enough } } @@ -38,17 +48,21 @@ impl<'a, 'b> Evil<'a, 'b> { // *check* that they hold. fn evil<'a, 'b>(b: &'b u32) -> &'a u32 { - <()>::static_evil(b) //~ ERROR cannot infer an appropriate lifetime + <()>::static_evil(b) + //[base]~^ ERROR cannot infer an appropriate lifetime + //[nll]~^^ ERROR lifetime may not live long enough } fn indirect_evil<'a, 'b>(b: &'b u32) -> &'a u32 { ::static_evil(b) - //~^ ERROR cannot infer an appropriate lifetime + //[base]~^ ERROR cannot infer an appropriate lifetime + //[nll]~^^ ERROR lifetime may not live long enough } fn inherent_evil<'a, 'b>(b: &'b u32) -> &'a u32 { ::inherent_evil(b) - //~^ ERROR cannot infer an appropriate lifetime + //[base]~^ ERROR cannot infer an appropriate lifetime + //[nll]~^^ ERROR lifetime may not live long enough } diff --git a/src/test/ui/wf/wf-static-type.stderr b/src/test/ui/wf/wf-static-type.stderr index c45bd5777620..4ae69cf2e1ff 100644 --- a/src/test/ui/wf/wf-static-type.stderr +++ b/src/test/ui/wf/wf-static-type.stderr @@ -10,6 +10,10 @@ note: required by a bound in `IsCopy` | LL | struct IsCopy { t: T } | ^^^^ required by this bound in `IsCopy` +help: consider annotating `NotCopy` with `#[derive(Copy)]` + | +LL | #[derive(Copy)] + | error: aborting due to previous error diff --git a/src/test/ui/where-clauses/where-clauses-method-unsatisfied.stderr b/src/test/ui/where-clauses/where-clauses-method-unsatisfied.stderr index 3a4cbb62d559..c13552bc26ee 100644 --- a/src/test/ui/where-clauses/where-clauses-method-unsatisfied.stderr +++ b/src/test/ui/where-clauses/where-clauses-method-unsatisfied.stderr @@ -11,6 +11,10 @@ note: required by a bound in `Foo::::equals` | LL | fn equals(&self, u: &Foo) -> bool where T : Eq { | ^^ required by this bound in `Foo::::equals` +help: consider annotating `Bar` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error diff --git a/src/test/ui/where-clauses/where-clauses-unsatisfied.stderr b/src/test/ui/where-clauses/where-clauses-unsatisfied.stderr index ba18119ff1b4..b1805a4522f4 100644 --- a/src/test/ui/where-clauses/where-clauses-unsatisfied.stderr +++ b/src/test/ui/where-clauses/where-clauses-unsatisfied.stderr @@ -9,6 +9,10 @@ note: required by a bound in `equal` | LL | fn equal(a: &T, b: &T) -> bool where T : Eq { a == b } | ^^ required by this bound in `equal` +help: consider annotating `Struct` with `#[derive(Eq)]` + | +LL | #[derive(Eq)] + | error: aborting due to previous error diff --git a/src/test/ui/where-clauses/where-for-self-2.stderr b/src/test/ui/where-clauses/where-for-self-2.base.stderr similarity index 90% rename from src/test/ui/where-clauses/where-for-self-2.stderr rename to src/test/ui/where-clauses/where-for-self-2.base.stderr index 6da46e20c09c..c09610cd6968 100644 --- a/src/test/ui/where-clauses/where-for-self-2.stderr +++ b/src/test/ui/where-clauses/where-for-self-2.base.stderr @@ -1,5 +1,5 @@ error: implementation of `Bar` is not general enough - --> $DIR/where-for-self-2.rs:23:5 + --> $DIR/where-for-self-2.rs:27:5 | LL | foo(&X); | ^^^ implementation of `Bar` is not general enough diff --git a/src/test/ui/where-clauses/where-for-self-2.nll.stderr b/src/test/ui/where-clauses/where-for-self-2.nll.stderr index f65db78fc899..92d1b2121a6b 100644 --- a/src/test/ui/where-clauses/where-for-self-2.nll.stderr +++ b/src/test/ui/where-clauses/where-for-self-2.nll.stderr @@ -1,5 +1,5 @@ error: implementation of `Bar` is not general enough - --> $DIR/where-for-self-2.rs:23:5 + --> $DIR/where-for-self-2.rs:27:5 | LL | foo(&X); | ^^^^^^^ implementation of `Bar` is not general enough diff --git a/src/test/ui/where-clauses/where-for-self-2.rs b/src/test/ui/where-clauses/where-for-self-2.rs index 37c6954fd52e..4e4e0ec912ea 100644 --- a/src/test/ui/where-clauses/where-for-self-2.rs +++ b/src/test/ui/where-clauses/where-for-self-2.rs @@ -3,6 +3,10 @@ // specific lifetime is not enough to satisfy the `for<'a> ...` constraint, which // should require *all* lifetimes. +// revisions: base nll +// ignore-compare-mode-nll +//[nll] compile-flags: -Z borrowck=mir + static X: &'static u32 = &42; trait Bar { diff --git a/src/tools/rust-analyzer b/src/tools/rust-analyzer index bc08b8eff3f8..46d7ee68f262 160000 --- a/src/tools/rust-analyzer +++ b/src/tools/rust-analyzer @@ -1 +1 @@ -Subproject commit bc08b8eff3f8e4da7c448d7b7f6461938c817a60 +Subproject commit 46d7ee68f26285db26b2640f2c07d6332380c756