Skip to content

Rollup of 6 pull requests #92518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Jan 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1b7f5a3
Remove NullOp::Box
nbdd0121 Sep 26, 2021
037e189
Remove `box_alloc` from `Machine` trait.
nbdd0121 Oct 20, 2021
44fdb98
Use field span in `rustc_macros` when emitting decode call
Aaron1011 Dec 16, 2021
874cd08
Suggest while let x = y when encountering while x = y
Dec 29, 2021
75d8339
Replace TDynBenchFn with Fn(&mut Bencher)
bjorn3 Dec 29, 2021
1ea4810
Remove #![crate_name] attribute from libtest
bjorn3 Dec 29, 2021
f710bc5
Remove unused feature gates from libtest
bjorn3 Dec 29, 2021
e015b9e
Remove unused allow deprecated
bjorn3 Dec 29, 2021
8d7cf1a
Fix spacing in pretty printed PatKind::Struct with no fields
dtolnay Dec 29, 2021
eda61d8
Move Result::as_deref
dtolnay Dec 30, 2021
5aa8f91
Move Result::as_deref_mut
dtolnay Dec 30, 2021
15f57a6
Move Result::expect and Result::unwrap
dtolnay Dec 30, 2021
aa2aca2
Move Result::unwrap_or_default
dtolnay Dec 30, 2021
06ea5eb
Move Result::expect_err and Result::unwrap_err
dtolnay Dec 30, 2021
778ca20
Move Result::into_ok
dtolnay Dec 30, 2021
b2df61f
Move Result::into_err
dtolnay Dec 30, 2021
e63e268
Consolidate impl Result<&T, E>
dtolnay Dec 30, 2021
b7a0ab1
Consolidate impl Result<&mut T, E>
dtolnay Dec 30, 2021
bbcf09f
Move Option::unwrap_or_default
dtolnay Dec 30, 2021
48a91a0
Move Option::as_deref
dtolnay Dec 30, 2021
9d65bc5
Move Option::as_deref_mut
dtolnay Dec 30, 2021
538fe4b
Consolidate impl Option<&T>
dtolnay Dec 30, 2021
dc32916
Consolidate impl Option<&mut T>
dtolnay Dec 30, 2021
5960f7a
UI test updates for Result and Option method moves
dtolnay Dec 30, 2021
57a4f4a
Rollup merge of #90102 - nbdd0121:box3, r=jonas-schievink
matthiaskrgr Jan 3, 2022
fd09f34
Rollup merge of #92011 - Aaron1011:decode-span, r=michaelwoerister
matthiaskrgr Jan 3, 2022
0335b7b
Rollup merge of #92402 - pr2502:while-let-typo, r=oli-obk
matthiaskrgr Jan 3, 2022
92f28bd
Rollup merge of #92409 - bjorn3:libtest_cleanups, r=m-ou-se
matthiaskrgr Jan 3, 2022
df92119
Rollup merge of #92418 - dtolnay:emptystructpat, r=michaelwoerister
matthiaskrgr Jan 3, 2022
13e2840
Rollup merge of #92444 - dtolnay:coremethods, r=joshtriplett
matthiaskrgr Jan 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2461,7 +2461,11 @@ impl<'a> State<'a> {
self.print_path(path, true, 0);
}
self.nbsp();
self.word_space("{");
self.word("{");
let empty = fields.is_empty() && !etc;
if !empty {
self.space();
}
self.commasep_cmnt(
Consistent,
&fields,
Expand All @@ -2482,7 +2486,9 @@ impl<'a> State<'a> {
}
self.word("..");
}
self.space();
if !empty {
self.space();
}
self.word("}");
}
PatKind::Tuple(ref elts) => {
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,10 +1394,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

Rvalue::NullaryOp(_op, _ty) => {
// nullary ops take no dynamic input; no borrowck effect.
//
// FIXME: is above actually true? Do we want to track
// the fact that uninitialized data can be created via
// `NullOp::Box`?
}

Rvalue::Aggregate(ref aggregate_kind, ref operands) => {
Expand Down
25 changes: 0 additions & 25 deletions compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,30 +715,6 @@ fn codegen_stmt<'tcx>(
let operand = operand.load_scalar(fx);
lval.write_cvalue(fx, CValue::by_val(operand, box_layout));
}
Rvalue::NullaryOp(NullOp::Box, content_ty) => {
let usize_type = fx.clif_type(fx.tcx.types.usize).unwrap();
let content_ty = fx.monomorphize(content_ty);
let layout = fx.layout_of(content_ty);
let llsize = fx.bcx.ins().iconst(usize_type, layout.size.bytes() as i64);
let llalign = fx.bcx.ins().iconst(usize_type, layout.align.abi.bytes() as i64);
let box_layout = fx.layout_of(fx.tcx.mk_box(content_ty));

// Allocate space:
let def_id =
match fx.tcx.lang_items().require(rustc_hir::LangItem::ExchangeMalloc) {
Ok(id) => id,
Err(s) => {
fx.tcx
.sess
.fatal(&format!("allocation of `{}` {}", box_layout.ty, s));
}
};
let instance = ty::Instance::mono(fx.tcx, def_id).polymorphize(fx.tcx);
let func_ref = fx.get_function_ref(instance);
let call = fx.bcx.ins().call(func_ref, &[llsize, llalign]);
let ptr = fx.bcx.inst_results(call)[0];
lval.write_cvalue(fx, CValue::by_val(ptr, box_layout));
}
Rvalue::NullaryOp(null_op, ty) => {
assert!(
lval.layout()
Expand All @@ -749,7 +725,6 @@ fn codegen_stmt<'tcx>(
let val = match null_op {
NullOp::SizeOf => layout.size.bytes(),
NullOp::AlignOf => layout.align.abi.bytes(),
NullOp::Box => unreachable!(),
};
let val = CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), val.into());
lval.write_cvalue(fx, val);
Expand Down
27 changes: 0 additions & 27 deletions compiler/rustc_codegen_ssa/src/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::traits::*;
use crate::MemFlags;

use rustc_apfloat::{ieee, Float, Round, Status};
use rustc_hir::lang_items::LangItem;
use rustc_middle::mir;
use rustc_middle::ty::cast::{CastTy, IntTy};
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf};
Expand Down Expand Up @@ -486,39 +485,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
)
}

mir::Rvalue::NullaryOp(mir::NullOp::Box, content_ty) => {
let content_ty = self.monomorphize(content_ty);
let content_layout = bx.cx().layout_of(content_ty);
let llsize = bx.cx().const_usize(content_layout.size.bytes());
let llalign = bx.cx().const_usize(content_layout.align.abi.bytes());
let box_layout = bx.cx().layout_of(bx.tcx().mk_box(content_ty));
let llty_ptr = bx.cx().backend_type(box_layout);

// Allocate space:
let def_id = match bx.tcx().lang_items().require(LangItem::ExchangeMalloc) {
Ok(id) => id,
Err(s) => {
bx.cx().sess().fatal(&format!("allocation of `{}` {}", box_layout.ty, s));
}
};
let instance = ty::Instance::mono(bx.tcx(), def_id);
let r = bx.cx().get_fn_addr(instance);
let ty = bx.type_func(&[bx.type_isize(), bx.type_isize()], bx.type_i8p());
let call = bx.call(ty, r, &[llsize, llalign], None);
let val = bx.pointercast(call, llty_ptr);

let operand = OperandRef { val: OperandValue::Immediate(val), layout: box_layout };
(bx, operand)
}

mir::Rvalue::NullaryOp(null_op, ty) => {
let ty = self.monomorphize(ty);
assert!(bx.cx().type_is_sized(ty));
let layout = bx.cx().layout_of(ty);
let val = match null_op {
mir::NullOp::SizeOf => layout.size.bytes(),
mir::NullOp::AlignOf => layout.align.abi.bytes(),
mir::NullOp::Box => unreachable!(),
};
let val = bx.cx().const_usize(val);
let tcx = self.cx.tcx();
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,6 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
Err(ConstEvalErrKind::NeedsRfc("pointer arithmetic or comparison".to_string()).into())
}

fn box_alloc(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
_dest: &PlaceTy<'tcx>,
) -> InterpResult<'tcx> {
Err(ConstEvalErrKind::NeedsRfc("heap allocations via `box` keyword".to_string()).into())
}

fn before_terminator(ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
// The step limit has already been hit in a previous call to `before_terminator`.
if ecx.machine.steps_remaining == 0 {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub enum StackPopCleanup {
/// `ret` stores the block we jump to on a normal return, while `unwind`
/// stores the block used for cleanup during unwinding.
Goto { ret: Option<mir::BasicBlock>, unwind: StackPopUnwind },
/// Just do nothing: Used by Main and for the `box_alloc` hook in miri.
/// Just do nothing: Used by Main and for TLS hooks in miri.
/// `cleanup` says whether locals are deallocated. Static computation
/// wants them leaked to intern what they need (and just throw away
/// the entire `ecx` when it is done).
Expand Down
6 changes: 0 additions & 6 deletions compiler/rustc_const_eval/src/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,6 @@ pub trait Machine<'mir, 'tcx>: Sized {
right: &ImmTy<'tcx, Self::PointerTag>,
) -> InterpResult<'tcx, (Scalar<Self::PointerTag>, bool, Ty<'tcx>)>;

/// Heap allocations via the `box` keyword.
fn box_alloc(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
dest: &PlaceTy<'tcx, Self::PointerTag>,
) -> InterpResult<'tcx>;

/// Called to read the specified `local` from the `frame`.
/// Since reading a ZST is not actually accessing memory or locals, this is never invoked
/// for ZST reads.
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_const_eval/src/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,10 +271,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.write_immediate(place.to_ref(self), &dest)?;
}

NullaryOp(mir::NullOp::Box, _) => {
M::box_alloc(self, &dest)?;
}

NullaryOp(null_op, ty) => {
let ty = self.subst_from_current_frame_and_normalize_erasing_regions(ty)?;
let layout = self.layout_of(ty)?;
Expand All @@ -289,7 +285,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let val = match null_op {
mir::NullOp::SizeOf => layout.size.bytes(),
mir::NullOp::AlignOf => layout.align.abi.bytes(),
mir::NullOp::Box => unreachable!(),
};
self.write_scalar(Scalar::from_machine_usize(val, self), &dest)?;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
}

Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) => {}
Rvalue::NullaryOp(NullOp::Box, _) => self.check_op(ops::HeapAllocation),
Rvalue::ShallowInitBox(_, _) => {}

Rvalue::UnaryOp(_, ref operand) => {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_const_eval/src/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ impl<'tcx> Validator<'_, 'tcx> {
}

Rvalue::NullaryOp(op, _) => match op {
NullOp::Box => return Err(Unpromotable),
NullOp::SizeOf => {}
NullOp::AlignOf => {}
},
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1874,7 +1874,11 @@ impl<'a> State<'a> {
PatKind::Struct(ref qpath, ref fields, etc) => {
self.print_qpath(qpath, true);
self.nbsp();
self.word_space("{");
self.word("{");
let empty = fields.is_empty() && !etc;
if !empty {
self.space();
}
self.commasep_cmnt(
Consistent,
&fields,
Expand All @@ -1895,7 +1899,9 @@ impl<'a> State<'a> {
}
self.word("..");
}
self.space();
if !empty {
self.space();
}
self.word("}");
}
PatKind::Or(ref pats) => {
Expand Down
26 changes: 15 additions & 11 deletions compiler/rustc_macros/src/serialize.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use proc_macro2::TokenStream;
use quote::quote;
use quote::{quote, quote_spanned};
use syn::parse_quote;
use syn::spanned::Spanned;

pub fn type_decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStream {
let decoder_ty = quote! { __D };
Expand Down Expand Up @@ -104,27 +105,30 @@ fn decodable_body(
}

fn decode_field(field: &syn::Field, index: usize, is_struct: bool) -> proc_macro2::TokenStream {
let field_span = field.ident.as_ref().map_or(field.ty.span(), |ident| ident.span());

let decode_inner_method = if let syn::Type::Reference(_) = field.ty {
quote! { ::rustc_middle::ty::codec::RefDecodable::decode }
} else {
quote! { ::rustc_serialize::Decodable::decode }
};
let (decode_method, opt_field_name) = if is_struct {
let field_name = field.ident.as_ref().map_or_else(|| index.to_string(), |i| i.to_string());
(
proc_macro2::Ident::new("read_struct_field", proc_macro2::Span::call_site()),
quote! { #field_name, },
)
(proc_macro2::Ident::new("read_struct_field", field_span), quote! { #field_name, })
} else {
(
proc_macro2::Ident::new("read_enum_variant_arg", proc_macro2::Span::call_site()),
quote! {},
)
(proc_macro2::Ident::new("read_enum_variant_arg", field_span), quote! {})
};

let __decoder = quote! { __decoder };
// Use the span of the field for the method call, so
// that backtraces will point to the field.
let decode_call = quote_spanned! {field_span=>
::rustc_serialize::Decoder::#decode_method(
#__decoder, #opt_field_name #decode_inner_method)
};

quote! {
match ::rustc_serialize::Decoder::#decode_method(
__decoder, #opt_field_name #decode_inner_method) {
match #decode_call {
::std::result::Result::Ok(__res) => __res,
::std::result::Result::Err(__err) => return ::std::result::Result::Err(__err),
}
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2336,8 +2336,6 @@ pub enum NullOp {
SizeOf,
/// Returns the minimum alignment of a type
AlignOf,
/// Creates a new uninitialized box for a value of that type
Box,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_middle/src/mir/tcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ impl<'tcx> Rvalue<'tcx> {
}
Rvalue::UnaryOp(UnOp::Not | UnOp::Neg, ref operand) => operand.ty(local_decls, tcx),
Rvalue::Discriminant(ref place) => place.ty(local_decls, tcx).ty.discriminant_ty(tcx),
Rvalue::NullaryOp(NullOp::Box, t) => tcx.mk_box(t),
Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) => tcx.types.usize,
Rvalue::Aggregate(ref ak, ref ops) => match **ak {
AggregateKind::Array(ty) => tcx.mk_array(ty, ops.len() as u64),
Expand All @@ -215,9 +214,7 @@ impl<'tcx> Rvalue<'tcx> {
/// whether its only shallowly initialized (`Rvalue::Box`).
pub fn initialization_state(&self) -> RvalueInitializationState {
match *self {
Rvalue::NullaryOp(NullOp::Box, _) | Rvalue::ShallowInitBox(_, _) => {
RvalueInitializationState::Shallow
}
Rvalue::ShallowInitBox(_, _) => RvalueInitializationState::Shallow,
_ => RvalueInitializationState::Deep,
}
}
Expand Down
14 changes: 1 addition & 13 deletions compiler/rustc_mir_dataflow/src/move_paths/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,19 +343,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
| Rvalue::AddressOf(..)
| Rvalue::Discriminant(..)
| Rvalue::Len(..)
| Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _)
| Rvalue::NullaryOp(NullOp::Box, _) => {
// This returns an rvalue with uninitialized contents. We can't
// move out of it here because it is an rvalue - assignments always
// completely initialize their place.
//
// However, this does not matter - MIR building is careful to
// only emit a shallow free for the partially-initialized
// temporary.
//
// In any case, if we want to fix this, we have to register a
// special move and change the `statement_effect` functions.
}
| Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) => {}
}
}

Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_mir_transform/src/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,6 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
throw_machine_stop_str!("pointer arithmetic or comparisons aren't supported in ConstProp")
}

fn box_alloc(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
_dest: &PlaceTy<'tcx>,
) -> InterpResult<'tcx> {
throw_machine_stop_str!("can't const prop heap allocations")
}

fn access_local(
_ecx: &InterpCx<'mir, 'tcx, Self>,
frame: &Frame<'mir, 'tcx, Self::PointerTag, Self::FrameExtra>,
Expand Down
9 changes: 0 additions & 9 deletions compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,15 +688,6 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
_ => bug!(),
}
}
mir::Rvalue::NullaryOp(mir::NullOp::Box, _) => {
let tcx = self.tcx;
let exchange_malloc_fn_def_id =
tcx.require_lang_item(LangItem::ExchangeMalloc, None);
let instance = Instance::mono(tcx, exchange_malloc_fn_def_id);
if should_codegen_locally(tcx, &instance) {
self.output.push(create_fn_mono_item(self.tcx, instance, span));
}
}
mir::Rvalue::ThreadLocalRef(def_id) => {
assert!(self.tcx.is_thread_local_static(def_id));
let instance = Instance::mono(self.tcx, def_id);
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2379,7 +2379,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
ExprKind::While(ref cond, ref block, label) => {
self.with_resolved_label(label, expr.id, |this| {
this.with_rib(ValueNS, NormalRibKind, |this| {
let old = this.diagnostic_metadata.in_if_condition.replace(cond);
this.visit_expr(cond);
this.diagnostic_metadata.in_if_condition = old;
this.visit_block(block);
})
});
Expand Down
Loading