Reformat using the new identifier sorting from rustfmt
This commit is contained in:
parent
1173204b36
commit
c682aa162b
1455 changed files with 7152 additions and 8384 deletions
|
@ -5,8 +5,8 @@ use rustc_middle::{span_bug, ty};
|
|||
use rustc_span::Span;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::build::matches::{DeclareLetBindings, EmitStorageLive, ScheduleDrops};
|
||||
use crate::build::ForGuard::OutsideGuard;
|
||||
use crate::build::matches::{DeclareLetBindings, EmitStorageLive, ScheduleDrops};
|
||||
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
|
|
|
@ -40,10 +40,10 @@ impl<'tcx> CFG<'tcx> {
|
|||
place: Place<'tcx>,
|
||||
rvalue: Rvalue<'tcx>,
|
||||
) {
|
||||
self.push(
|
||||
block,
|
||||
Statement { source_info, kind: StatementKind::Assign(Box::new((place, rvalue))) },
|
||||
);
|
||||
self.push(block, Statement {
|
||||
source_info,
|
||||
kind: StatementKind::Assign(Box::new((place, rvalue))),
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn push_assign_constant(
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
use rustc_ast::Attribute;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::HirId;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_index::{IndexSlice, IndexVec};
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::span_bug;
|
||||
|
|
|
@ -4,11 +4,11 @@ use rustc_middle::mir::*;
|
|||
use rustc_middle::thir::*;
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::cast::mir_cast_kind;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_target::abi::{FieldIdx, VariantIdx};
|
||||
|
||||
use super::{parse_by_kind, PResult, ParseCtxt};
|
||||
use super::{PResult, ParseCtxt, parse_by_kind};
|
||||
use crate::build::custom::ParseError;
|
||||
use crate::build::expr::as_constant::as_constant_inner;
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use rustc_ast as ast;
|
||||
use rustc_hir::LangItem;
|
||||
use rustc_middle::mir::interpret::{
|
||||
Allocation, LitToConstError, LitToConstInput, Scalar, CTFE_ALLOC_SALT,
|
||||
Allocation, CTFE_ALLOC_SALT, LitToConstError, LitToConstInput, Scalar,
|
||||
};
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::thir::*;
|
||||
|
@ -14,7 +14,7 @@ use rustc_middle::{bug, mir, span_bug};
|
|||
use rustc_target::abi::Size;
|
||||
use tracing::{instrument, trace};
|
||||
|
||||
use crate::build::{parse_float_into_constval, Builder};
|
||||
use crate::build::{Builder, parse_float_into_constval};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Compile `expr`, yielding a compile-time constant. Assumes that
|
||||
|
|
|
@ -12,11 +12,11 @@ use rustc_middle::thir::*;
|
|||
use rustc_middle::ty::{self, AdtDef, CanonicalUserTypeAnnotation, Ty, Variance};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
|
||||
use rustc_target::abi::{FIRST_VARIANT, FieldIdx, VariantIdx};
|
||||
use tracing::{debug, instrument, trace};
|
||||
|
||||
use crate::build::expr::category::Category;
|
||||
use crate::build::ForGuard::{OutsideGuard, RefWithinGuard};
|
||||
use crate::build::expr::category::Category;
|
||||
use crate::build::{BlockAnd, BlockAndExtension, Builder, Capture, CaptureMap};
|
||||
|
||||
/// The "outermost" place that holds this value.
|
||||
|
@ -483,19 +483,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
});
|
||||
|
||||
let place = place_builder.to_place(this);
|
||||
this.cfg.push(
|
||||
block,
|
||||
Statement {
|
||||
source_info,
|
||||
kind: StatementKind::AscribeUserType(
|
||||
Box::new((
|
||||
place,
|
||||
UserTypeProjection { base: annotation_index, projs: vec![] },
|
||||
)),
|
||||
Variance::Invariant,
|
||||
),
|
||||
},
|
||||
);
|
||||
this.cfg.push(block, Statement {
|
||||
source_info,
|
||||
kind: StatementKind::AscribeUserType(
|
||||
Box::new((place, UserTypeProjection {
|
||||
base: annotation_index,
|
||||
projs: vec![],
|
||||
})),
|
||||
Variance::Invariant,
|
||||
),
|
||||
});
|
||||
}
|
||||
block.and(place_builder)
|
||||
}
|
||||
|
@ -511,19 +508,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
user_ty: user_ty.clone(),
|
||||
inferred_ty: expr.ty,
|
||||
});
|
||||
this.cfg.push(
|
||||
block,
|
||||
Statement {
|
||||
source_info,
|
||||
kind: StatementKind::AscribeUserType(
|
||||
Box::new((
|
||||
Place::from(temp),
|
||||
UserTypeProjection { base: annotation_index, projs: vec![] },
|
||||
)),
|
||||
Variance::Invariant,
|
||||
),
|
||||
},
|
||||
);
|
||||
this.cfg.push(block, Statement {
|
||||
source_info,
|
||||
kind: StatementKind::AscribeUserType(
|
||||
Box::new((Place::from(temp), UserTypeProjection {
|
||||
base: annotation_index,
|
||||
projs: vec![],
|
||||
})),
|
||||
Variance::Invariant,
|
||||
),
|
||||
});
|
||||
}
|
||||
block.and(PlaceBuilder::from(temp))
|
||||
}
|
||||
|
|
|
@ -7,12 +7,12 @@ use rustc_middle::middle::region;
|
|||
use rustc_middle::mir::interpret::Scalar;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::thir::*;
|
||||
use rustc_middle::ty::cast::{mir_cast_kind, CastTy};
|
||||
use rustc_middle::ty::cast::{CastTy, mir_cast_kind};
|
||||
use rustc_middle::ty::layout::IntegerExt;
|
||||
use rustc_middle::ty::util::IntTypeExt;
|
||||
use rustc_middle::ty::{self, Ty, UpvarArgs};
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
use rustc_target::abi::{Abi, FieldIdx, Primitive};
|
||||
use tracing::debug;
|
||||
|
||||
|
@ -147,23 +147,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
);
|
||||
let storage = this.temp(Ty::new_mut_ptr(tcx, tcx.types.u8), expr_span);
|
||||
let success = this.cfg.start_new_block();
|
||||
this.cfg.terminate(
|
||||
block,
|
||||
source_info,
|
||||
TerminatorKind::Call {
|
||||
func: exchange_malloc,
|
||||
args: [
|
||||
Spanned { node: Operand::Move(size), span: DUMMY_SP },
|
||||
Spanned { node: Operand::Move(align), span: DUMMY_SP },
|
||||
]
|
||||
.into(),
|
||||
destination: storage,
|
||||
target: Some(success),
|
||||
unwind: UnwindAction::Continue,
|
||||
call_source: CallSource::Misc,
|
||||
fn_span: expr_span,
|
||||
},
|
||||
);
|
||||
this.cfg.terminate(block, source_info, TerminatorKind::Call {
|
||||
func: exchange_malloc,
|
||||
args: [Spanned { node: Operand::Move(size), span: DUMMY_SP }, Spanned {
|
||||
node: Operand::Move(align),
|
||||
span: DUMMY_SP,
|
||||
}]
|
||||
.into(),
|
||||
destination: storage,
|
||||
target: Some(success),
|
||||
unwind: UnwindAction::Continue,
|
||||
call_source: CallSource::Misc,
|
||||
fn_span: expr_span,
|
||||
});
|
||||
this.diverge_from(block);
|
||||
block = success;
|
||||
|
||||
|
@ -171,10 +167,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
// and therefore is not considered during coroutine auto-trait
|
||||
// determination. See the comment about `box` at `yield_in_scope`.
|
||||
let result = this.local_decls.push(LocalDecl::new(expr.ty, expr_span));
|
||||
this.cfg.push(
|
||||
block,
|
||||
Statement { source_info, kind: StatementKind::StorageLive(result) },
|
||||
);
|
||||
this.cfg.push(block, Statement {
|
||||
source_info,
|
||||
kind: StatementKind::StorageLive(result),
|
||||
});
|
||||
if let Some(scope) = scope {
|
||||
// schedule a shallow free of that memory, lest we unwind:
|
||||
this.schedule_drop_storage_and_value(expr_span, scope, result);
|
||||
|
@ -268,15 +264,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
);
|
||||
merge_place
|
||||
};
|
||||
this.cfg.push(
|
||||
block,
|
||||
Statement {
|
||||
source_info,
|
||||
kind: StatementKind::Intrinsic(Box::new(
|
||||
NonDivergingIntrinsic::Assume(Operand::Move(assert_place)),
|
||||
)),
|
||||
},
|
||||
);
|
||||
this.cfg.push(block, Statement {
|
||||
source_info,
|
||||
kind: StatementKind::Intrinsic(Box::new(
|
||||
NonDivergingIntrinsic::Assume(Operand::Move(assert_place)),
|
||||
)),
|
||||
});
|
||||
}
|
||||
|
||||
(op, ty)
|
||||
|
@ -721,16 +714,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
);
|
||||
if let Operand::Move(to_drop) = value_operand {
|
||||
let success = this.cfg.start_new_block();
|
||||
this.cfg.terminate(
|
||||
block,
|
||||
outer_source_info,
|
||||
TerminatorKind::Drop {
|
||||
place: to_drop,
|
||||
target: success,
|
||||
unwind: UnwindAction::Continue,
|
||||
replace: false,
|
||||
},
|
||||
);
|
||||
this.cfg.terminate(block, outer_source_info, TerminatorKind::Drop {
|
||||
place: to_drop,
|
||||
target: success,
|
||||
unwind: UnwindAction::Continue,
|
||||
replace: false,
|
||||
});
|
||||
this.diverge_from(block);
|
||||
block = success;
|
||||
}
|
||||
|
|
|
@ -221,14 +221,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
this.in_breakable_scope(Some(loop_block), destination, expr_span, move |this| {
|
||||
// conduct the test, if necessary
|
||||
let body_block = this.cfg.start_new_block();
|
||||
this.cfg.terminate(
|
||||
loop_block,
|
||||
source_info,
|
||||
TerminatorKind::FalseUnwind {
|
||||
real_target: body_block,
|
||||
unwind: UnwindAction::Continue,
|
||||
},
|
||||
);
|
||||
this.cfg.terminate(loop_block, source_info, TerminatorKind::FalseUnwind {
|
||||
real_target: body_block,
|
||||
unwind: UnwindAction::Continue,
|
||||
});
|
||||
this.diverge_from(loop_block);
|
||||
|
||||
// The “return” value of the loop body must always be a unit. We therefore
|
||||
|
@ -259,30 +255,26 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
|
||||
debug!("expr_into_dest: fn_span={:?}", fn_span);
|
||||
|
||||
this.cfg.terminate(
|
||||
block,
|
||||
source_info,
|
||||
TerminatorKind::Call {
|
||||
func: fun,
|
||||
args,
|
||||
unwind: UnwindAction::Continue,
|
||||
destination,
|
||||
// The presence or absence of a return edge affects control-flow sensitive
|
||||
// MIR checks and ultimately whether code is accepted or not. We can only
|
||||
// omit the return edge if a return type is visibly uninhabited to a module
|
||||
// that makes the call.
|
||||
target: expr
|
||||
.ty
|
||||
.is_inhabited_from(this.tcx, this.parent_module, this.param_env)
|
||||
.then_some(success),
|
||||
call_source: if from_hir_call {
|
||||
CallSource::Normal
|
||||
} else {
|
||||
CallSource::OverloadedOperator
|
||||
},
|
||||
fn_span,
|
||||
this.cfg.terminate(block, source_info, TerminatorKind::Call {
|
||||
func: fun,
|
||||
args,
|
||||
unwind: UnwindAction::Continue,
|
||||
destination,
|
||||
// The presence or absence of a return edge affects control-flow sensitive
|
||||
// MIR checks and ultimately whether code is accepted or not. We can only
|
||||
// omit the return edge if a return type is visibly uninhabited to a module
|
||||
// that makes the call.
|
||||
target: expr
|
||||
.ty
|
||||
.is_inhabited_from(this.tcx, this.parent_module, this.param_env)
|
||||
.then_some(success),
|
||||
call_source: if from_hir_call {
|
||||
CallSource::Normal
|
||||
} else {
|
||||
CallSource::OverloadedOperator
|
||||
},
|
||||
);
|
||||
fn_span,
|
||||
});
|
||||
this.diverge_from(block);
|
||||
success.unit()
|
||||
}
|
||||
|
@ -469,11 +461,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let tmp = this.get_unit_temp();
|
||||
let target =
|
||||
this.ast_block(tmp, target, block, source_info).into_block();
|
||||
this.cfg.terminate(
|
||||
target,
|
||||
source_info,
|
||||
TerminatorKind::Goto { target: destination_block },
|
||||
);
|
||||
this.cfg.terminate(target, source_info, TerminatorKind::Goto {
|
||||
target: destination_block,
|
||||
});
|
||||
|
||||
mir::InlineAsmOperand::Label { target_index }
|
||||
}
|
||||
|
@ -484,22 +474,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
|
||||
}
|
||||
|
||||
this.cfg.terminate(
|
||||
block,
|
||||
source_info,
|
||||
TerminatorKind::InlineAsm {
|
||||
template,
|
||||
operands,
|
||||
options,
|
||||
line_spans,
|
||||
targets: targets.into_boxed_slice(),
|
||||
unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
|
||||
UnwindAction::Continue
|
||||
} else {
|
||||
UnwindAction::Unreachable
|
||||
},
|
||||
this.cfg.terminate(block, source_info, TerminatorKind::InlineAsm {
|
||||
template,
|
||||
operands,
|
||||
options,
|
||||
line_spans,
|
||||
targets: targets.into_boxed_slice(),
|
||||
unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
|
||||
UnwindAction::Continue
|
||||
} else {
|
||||
UnwindAction::Unreachable
|
||||
},
|
||||
);
|
||||
});
|
||||
if options.contains(InlineAsmOptions::MAY_UNWIND) {
|
||||
this.diverge_from(block);
|
||||
}
|
||||
|
@ -562,11 +548,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
)
|
||||
);
|
||||
let resume = this.cfg.start_new_block();
|
||||
this.cfg.terminate(
|
||||
block,
|
||||
source_info,
|
||||
TerminatorKind::Yield { value, resume, resume_arg: destination, drop: None },
|
||||
);
|
||||
this.cfg.terminate(block, source_info, TerminatorKind::Yield {
|
||||
value,
|
||||
resume,
|
||||
resume_arg: destination,
|
||||
drop: None,
|
||||
});
|
||||
this.coroutine_drop_cleanup(block);
|
||||
resume.unit()
|
||||
}
|
||||
|
|
|
@ -123,11 +123,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
|
||||
unpack!(block = this.break_for_tail_call(block, &args, source_info));
|
||||
|
||||
this.cfg.terminate(
|
||||
block,
|
||||
source_info,
|
||||
TerminatorKind::TailCall { func: fun, args, fn_span },
|
||||
);
|
||||
this.cfg.terminate(block, source_info, TerminatorKind::TailCall {
|
||||
func: fun,
|
||||
args,
|
||||
fn_span,
|
||||
});
|
||||
|
||||
this.cfg.start_new_block().unit()
|
||||
})
|
||||
|
|
|
@ -2,9 +2,9 @@ use rustc_middle::mir::*;
|
|||
use rustc_middle::thir::{self, *};
|
||||
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
|
||||
|
||||
use crate::build::Builder;
|
||||
use crate::build::expr::as_place::{PlaceBase, PlaceBuilder};
|
||||
use crate::build::matches::{FlatPat, MatchPairTree, TestCase};
|
||||
use crate::build::Builder;
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Builds and returns [`MatchPairTree`] subtrees, one for each pattern in
|
||||
|
@ -162,13 +162,10 @@ impl<'pat, 'tcx> MatchPairTree<'pat, 'tcx> {
|
|||
let ascription = place.map(|source| {
|
||||
let span = pattern.span;
|
||||
let parent_id = cx.tcx.typeck_root_def_id(cx.def_id.to_def_id());
|
||||
let args = ty::InlineConstArgs::new(
|
||||
cx.tcx,
|
||||
ty::InlineConstArgsParts {
|
||||
parent_args: ty::GenericArgs::identity_for_item(cx.tcx, parent_id),
|
||||
ty: cx.infcx.next_ty_var(span),
|
||||
},
|
||||
)
|
||||
let args = ty::InlineConstArgs::new(cx.tcx, ty::InlineConstArgsParts {
|
||||
parent_args: ty::GenericArgs::identity_for_item(cx.tcx, parent_id),
|
||||
ty: cx.infcx.next_ty_var(span),
|
||||
})
|
||||
.args;
|
||||
let user_ty = cx.infcx.canonicalize_user_type_annotation(ty::UserType::TypeOf(
|
||||
def.to_def_id(),
|
||||
|
|
|
@ -18,9 +18,9 @@ use rustc_span::{BytePos, Pos, Span};
|
|||
use rustc_target::abi::VariantIdx;
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard};
|
||||
use crate::build::expr::as_place::PlaceBuilder;
|
||||
use crate::build::scope::DropKind;
|
||||
use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard};
|
||||
use crate::build::{
|
||||
BlockAnd, BlockAndExtension, Builder, GuardFrame, GuardFrameLocal, LocalsForNode,
|
||||
};
|
||||
|
@ -104,11 +104,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
variable_source_info: SourceInfo,
|
||||
declare_let_bindings: DeclareLetBindings,
|
||||
) -> BlockAnd<()> {
|
||||
self.then_else_break_inner(
|
||||
block,
|
||||
expr_id,
|
||||
ThenElseArgs { temp_scope_override, variable_source_info, declare_let_bindings },
|
||||
)
|
||||
self.then_else_break_inner(block, expr_id, ThenElseArgs {
|
||||
temp_scope_override,
|
||||
variable_source_info,
|
||||
declare_let_bindings,
|
||||
})
|
||||
}
|
||||
|
||||
fn then_else_break_inner(
|
||||
|
@ -134,24 +134,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let local_scope = this.local_scope();
|
||||
let (lhs_success_block, failure_block) =
|
||||
this.in_if_then_scope(local_scope, expr_span, |this| {
|
||||
this.then_else_break_inner(
|
||||
block,
|
||||
lhs,
|
||||
ThenElseArgs {
|
||||
declare_let_bindings: DeclareLetBindings::LetNotPermitted,
|
||||
..args
|
||||
},
|
||||
)
|
||||
});
|
||||
let rhs_success_block = this
|
||||
.then_else_break_inner(
|
||||
failure_block,
|
||||
rhs,
|
||||
ThenElseArgs {
|
||||
this.then_else_break_inner(block, lhs, ThenElseArgs {
|
||||
declare_let_bindings: DeclareLetBindings::LetNotPermitted,
|
||||
..args
|
||||
},
|
||||
)
|
||||
})
|
||||
});
|
||||
let rhs_success_block = this
|
||||
.then_else_break_inner(failure_block, rhs, ThenElseArgs {
|
||||
declare_let_bindings: DeclareLetBindings::LetNotPermitted,
|
||||
..args
|
||||
})
|
||||
.into_block();
|
||||
|
||||
// Make the LHS and RHS success arms converge to a common block.
|
||||
|
@ -178,14 +170,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
if this.tcx.sess.instrument_coverage() {
|
||||
this.cfg.push_coverage_span_marker(block, this.source_info(expr_span));
|
||||
}
|
||||
this.then_else_break_inner(
|
||||
block,
|
||||
arg,
|
||||
ThenElseArgs {
|
||||
declare_let_bindings: DeclareLetBindings::LetNotPermitted,
|
||||
..args
|
||||
},
|
||||
)
|
||||
this.then_else_break_inner(block, arg, ThenElseArgs {
|
||||
declare_let_bindings: DeclareLetBindings::LetNotPermitted,
|
||||
..args
|
||||
})
|
||||
});
|
||||
this.break_for_else(success_block, args.variable_source_info);
|
||||
failure_block.unit()
|
||||
|
@ -638,30 +626,27 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let ty_source_info = self.source_info(annotation.span);
|
||||
|
||||
let base = self.canonical_user_type_annotations.push(annotation.clone());
|
||||
self.cfg.push(
|
||||
block,
|
||||
Statement {
|
||||
source_info: ty_source_info,
|
||||
kind: StatementKind::AscribeUserType(
|
||||
Box::new((place, UserTypeProjection { base, projs: Vec::new() })),
|
||||
// We always use invariant as the variance here. This is because the
|
||||
// variance field from the ascription refers to the variance to use
|
||||
// when applying the type to the value being matched, but this
|
||||
// ascription applies rather to the type of the binding. e.g., in this
|
||||
// example:
|
||||
//
|
||||
// ```
|
||||
// let x: T = <expr>
|
||||
// ```
|
||||
//
|
||||
// We are creating an ascription that defines the type of `x` to be
|
||||
// exactly `T` (i.e., with invariance). The variance field, in
|
||||
// contrast, is intended to be used to relate `T` to the type of
|
||||
// `<expr>`.
|
||||
ty::Invariant,
|
||||
),
|
||||
},
|
||||
);
|
||||
self.cfg.push(block, Statement {
|
||||
source_info: ty_source_info,
|
||||
kind: StatementKind::AscribeUserType(
|
||||
Box::new((place, UserTypeProjection { base, projs: Vec::new() })),
|
||||
// We always use invariant as the variance here. This is because the
|
||||
// variance field from the ascription refers to the variance to use
|
||||
// when applying the type to the value being matched, but this
|
||||
// ascription applies rather to the type of the binding. e.g., in this
|
||||
// example:
|
||||
//
|
||||
// ```
|
||||
// let x: T = <expr>
|
||||
// ```
|
||||
//
|
||||
// We are creating an ascription that defines the type of `x` to be
|
||||
// exactly `T` (i.e., with invariance). The variance field, in
|
||||
// contrast, is intended to be used to relate `T` to the type of
|
||||
// `<expr>`.
|
||||
ty::Invariant,
|
||||
),
|
||||
});
|
||||
|
||||
self.schedule_drop_for_binding(var, irrefutable_pat.span, OutsideGuard);
|
||||
block.unit()
|
||||
|
@ -2559,19 +2544,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let source_info = self.source_info(ascription.annotation.span);
|
||||
|
||||
let base = self.canonical_user_type_annotations.push(ascription.annotation);
|
||||
self.cfg.push(
|
||||
block,
|
||||
Statement {
|
||||
source_info,
|
||||
kind: StatementKind::AscribeUserType(
|
||||
Box::new((
|
||||
ascription.source,
|
||||
UserTypeProjection { base, projs: Vec::new() },
|
||||
)),
|
||||
ascription.variance,
|
||||
),
|
||||
},
|
||||
);
|
||||
self.cfg.push(block, Statement {
|
||||
source_info,
|
||||
kind: StatementKind::AscribeUserType(
|
||||
Box::new((ascription.source, UserTypeProjection { base, projs: Vec::new() })),
|
||||
ascription.variance,
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@ use std::mem;
|
|||
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::build::matches::{MatchPairTree, PatternExtraData, TestCase};
|
||||
use crate::build::Builder;
|
||||
use crate::build::matches::{MatchPairTree, PatternExtraData, TestCase};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Simplify a list of match pairs so they all require a test. Stores relevant bindings and
|
||||
|
|
|
@ -16,12 +16,12 @@ use rustc_middle::ty::{self, GenericArg, Ty, TyCtxt};
|
|||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_span::def_id::DefId;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::symbol::{sym, Symbol};
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::symbol::{Symbol, sym};
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::build::matches::{Candidate, MatchPairTree, Test, TestBranch, TestCase, TestKind};
|
||||
use crate::build::Builder;
|
||||
use crate::build::matches::{Candidate, MatchPairTree, Test, TestBranch, TestCase, TestKind};
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Identifies what test is needed to decide if `match_pair` is applicable.
|
||||
|
@ -322,23 +322,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
);
|
||||
// `let temp = <Ty as Deref>::deref(ref_src);`
|
||||
// or `let temp = <Ty as DerefMut>::deref_mut(ref_src);`
|
||||
self.cfg.terminate(
|
||||
block,
|
||||
source_info,
|
||||
TerminatorKind::Call {
|
||||
func: Operand::Constant(Box::new(ConstOperand {
|
||||
span,
|
||||
user_ty: None,
|
||||
const_: method,
|
||||
})),
|
||||
args: [Spanned { node: Operand::Move(ref_src), span }].into(),
|
||||
destination: temp,
|
||||
target: Some(target_block),
|
||||
unwind: UnwindAction::Continue,
|
||||
call_source: CallSource::Misc,
|
||||
fn_span: source_info.span,
|
||||
},
|
||||
);
|
||||
self.cfg.terminate(block, source_info, TerminatorKind::Call {
|
||||
func: Operand::Constant(Box::new(ConstOperand { span, user_ty: None, const_: method })),
|
||||
args: [Spanned { node: Operand::Move(ref_src), span }].into(),
|
||||
destination: temp,
|
||||
target: Some(target_block),
|
||||
unwind: UnwindAction::Continue,
|
||||
call_source: CallSource::Misc,
|
||||
fn_span: source_info.span,
|
||||
});
|
||||
}
|
||||
|
||||
/// Compare using the provided built-in comparison operator
|
||||
|
@ -466,33 +458,29 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let bool_ty = self.tcx.types.bool;
|
||||
let eq_result = self.temp(bool_ty, source_info.span);
|
||||
let eq_block = self.cfg.start_new_block();
|
||||
self.cfg.terminate(
|
||||
block,
|
||||
source_info,
|
||||
TerminatorKind::Call {
|
||||
func: Operand::Constant(Box::new(ConstOperand {
|
||||
span: source_info.span,
|
||||
self.cfg.terminate(block, source_info, TerminatorKind::Call {
|
||||
func: Operand::Constant(Box::new(ConstOperand {
|
||||
span: source_info.span,
|
||||
|
||||
// FIXME(#54571): This constant comes from user input (a
|
||||
// constant in a pattern). Are there forms where users can add
|
||||
// type annotations here? For example, an associated constant?
|
||||
// Need to experiment.
|
||||
user_ty: None,
|
||||
// FIXME(#54571): This constant comes from user input (a
|
||||
// constant in a pattern). Are there forms where users can add
|
||||
// type annotations here? For example, an associated constant?
|
||||
// Need to experiment.
|
||||
user_ty: None,
|
||||
|
||||
const_: method,
|
||||
})),
|
||||
args: [
|
||||
Spanned { node: Operand::Copy(val), span: DUMMY_SP },
|
||||
Spanned { node: expect, span: DUMMY_SP },
|
||||
]
|
||||
.into(),
|
||||
destination: eq_result,
|
||||
target: Some(eq_block),
|
||||
unwind: UnwindAction::Continue,
|
||||
call_source: CallSource::MatchCmp,
|
||||
fn_span: source_info.span,
|
||||
},
|
||||
);
|
||||
const_: method,
|
||||
})),
|
||||
args: [Spanned { node: Operand::Copy(val), span: DUMMY_SP }, Spanned {
|
||||
node: expect,
|
||||
span: DUMMY_SP,
|
||||
}]
|
||||
.into(),
|
||||
destination: eq_result,
|
||||
target: Some(eq_block),
|
||||
unwind: UnwindAction::Continue,
|
||||
call_source: CallSource::MatchCmp,
|
||||
fn_span: source_info.span,
|
||||
});
|
||||
self.diverge_from(block);
|
||||
|
||||
// check the result
|
||||
|
|
|
@ -4,9 +4,9 @@ use rustc_middle::ty::Ty;
|
|||
use rustc_span::Span;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::build::Builder;
|
||||
use crate::build::expr::as_place::PlaceBase;
|
||||
use crate::build::matches::{Binding, Candidate, FlatPat, MatchPairTree, TestCase};
|
||||
use crate::build::Builder;
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
/// Creates a false edge to `imaginary_target` and a real edge to
|
||||
|
@ -20,11 +20,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
source_info: SourceInfo,
|
||||
) {
|
||||
if imaginary_target != real_target {
|
||||
self.cfg.terminate(
|
||||
from_block,
|
||||
source_info,
|
||||
TerminatorKind::FalseEdge { real_target, imaginary_target },
|
||||
);
|
||||
self.cfg.terminate(from_block, source_info, TerminatorKind::FalseEdge {
|
||||
real_target,
|
||||
imaginary_target,
|
||||
});
|
||||
} else {
|
||||
self.cfg.goto(from_block, source_info, real_target)
|
||||
}
|
||||
|
|
|
@ -45,16 +45,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
) -> Place<'tcx> {
|
||||
let usize_ty = self.tcx.types.usize;
|
||||
let temp = self.temp(usize_ty, source_info.span);
|
||||
self.cfg.push_assign_constant(
|
||||
block,
|
||||
source_info,
|
||||
temp,
|
||||
ConstOperand {
|
||||
span: source_info.span,
|
||||
user_ty: None,
|
||||
const_: Const::from_usize(self.tcx, value),
|
||||
},
|
||||
);
|
||||
self.cfg.push_assign_constant(block, source_info, temp, ConstOperand {
|
||||
span: source_info.span,
|
||||
user_ty: None,
|
||||
const_: Const::from_usize(self.tcx, value),
|
||||
});
|
||||
temp
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use itertools::Itertools;
|
||||
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
|
||||
use rustc_apfloat::Float;
|
||||
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
|
||||
use rustc_ast::attr;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_data_structures::sorted_map::SortedIndexMultiMap;
|
||||
|
|
|
@ -92,7 +92,7 @@ use rustc_middle::thir::{ExprId, LintLevel};
|
|||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_session::lint::Level;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder, CFG};
|
||||
|
@ -510,16 +510,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
(Some(normal_block), Some(exit_block)) => {
|
||||
let target = self.cfg.start_new_block();
|
||||
let source_info = self.source_info(span);
|
||||
self.cfg.terminate(
|
||||
normal_block.into_block(),
|
||||
source_info,
|
||||
TerminatorKind::Goto { target },
|
||||
);
|
||||
self.cfg.terminate(
|
||||
exit_block.into_block(),
|
||||
source_info,
|
||||
TerminatorKind::Goto { target },
|
||||
);
|
||||
self.cfg.terminate(normal_block.into_block(), source_info, TerminatorKind::Goto {
|
||||
target,
|
||||
});
|
||||
self.cfg.terminate(exit_block.into_block(), source_info, TerminatorKind::Goto {
|
||||
target,
|
||||
});
|
||||
target.unit()
|
||||
}
|
||||
}
|
||||
|
@ -806,25 +802,21 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
unwind_drops.add_entry_point(block, unwind_entry_point);
|
||||
|
||||
let next = self.cfg.start_new_block();
|
||||
self.cfg.terminate(
|
||||
block,
|
||||
source_info,
|
||||
TerminatorKind::Drop {
|
||||
place: local.into(),
|
||||
target: next,
|
||||
unwind: UnwindAction::Continue,
|
||||
replace: false,
|
||||
},
|
||||
);
|
||||
self.cfg.terminate(block, source_info, TerminatorKind::Drop {
|
||||
place: local.into(),
|
||||
target: next,
|
||||
unwind: UnwindAction::Continue,
|
||||
replace: false,
|
||||
});
|
||||
block = next;
|
||||
}
|
||||
DropKind::Storage => {
|
||||
// Only temps and vars need their storage dead.
|
||||
assert!(local.index() > self.arg_count);
|
||||
self.cfg.push(
|
||||
block,
|
||||
Statement { source_info, kind: StatementKind::StorageDead(local) },
|
||||
);
|
||||
self.cfg.push(block, Statement {
|
||||
source_info,
|
||||
kind: StatementKind::StorageDead(local),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1283,16 +1275,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let assign_unwind = self.cfg.start_new_cleanup_block();
|
||||
self.cfg.push_assign(assign_unwind, source_info, place, value.clone());
|
||||
|
||||
self.cfg.terminate(
|
||||
block,
|
||||
source_info,
|
||||
TerminatorKind::Drop {
|
||||
place,
|
||||
target: assign,
|
||||
unwind: UnwindAction::Cleanup(assign_unwind),
|
||||
replace: true,
|
||||
},
|
||||
);
|
||||
self.cfg.terminate(block, source_info, TerminatorKind::Drop {
|
||||
place,
|
||||
target: assign,
|
||||
unwind: UnwindAction::Cleanup(assign_unwind),
|
||||
replace: true,
|
||||
});
|
||||
self.diverge_from(block);
|
||||
|
||||
assign.unit()
|
||||
|
@ -1312,17 +1300,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
let source_info = self.source_info(span);
|
||||
let success_block = self.cfg.start_new_block();
|
||||
|
||||
self.cfg.terminate(
|
||||
block,
|
||||
source_info,
|
||||
TerminatorKind::Assert {
|
||||
cond,
|
||||
expected,
|
||||
msg: Box::new(msg),
|
||||
target: success_block,
|
||||
unwind: UnwindAction::Continue,
|
||||
},
|
||||
);
|
||||
self.cfg.terminate(block, source_info, TerminatorKind::Assert {
|
||||
cond,
|
||||
expected,
|
||||
msg: Box::new(msg),
|
||||
target: success_block,
|
||||
unwind: UnwindAction::Continue,
|
||||
});
|
||||
self.diverge_from(block);
|
||||
|
||||
success_block
|
||||
|
@ -1397,16 +1381,12 @@ fn build_scope_drops<'tcx>(
|
|||
unwind_drops.add_entry_point(block, unwind_to);
|
||||
|
||||
let next = cfg.start_new_block();
|
||||
cfg.terminate(
|
||||
block,
|
||||
source_info,
|
||||
TerminatorKind::Drop {
|
||||
place: local.into(),
|
||||
target: next,
|
||||
unwind: UnwindAction::Continue,
|
||||
replace: false,
|
||||
},
|
||||
);
|
||||
cfg.terminate(block, source_info, TerminatorKind::Drop {
|
||||
place: local.into(),
|
||||
target: next,
|
||||
unwind: UnwindAction::Continue,
|
||||
replace: false,
|
||||
});
|
||||
block = next;
|
||||
}
|
||||
DropKind::Storage => {
|
||||
|
|
|
@ -12,11 +12,11 @@ use rustc_middle::thir::visit::Visitor;
|
|||
use rustc_middle::thir::*;
|
||||
use rustc_middle::ty::print::with_no_trimmed_paths;
|
||||
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt};
|
||||
use rustc_session::lint::builtin::{DEPRECATED_SAFE_2024, UNSAFE_OP_IN_UNSAFE_FN, UNUSED_UNSAFE};
|
||||
use rustc_session::lint::Level;
|
||||
use rustc_session::lint::builtin::{DEPRECATED_SAFE_2024, UNSAFE_OP_IN_UNSAFE_FN, UNUSED_UNSAFE};
|
||||
use rustc_span::def_id::{DefId, LocalDefId};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_span::{Span, sym};
|
||||
|
||||
use crate::build::ExprCategory;
|
||||
use crate::errors::*;
|
||||
|
@ -499,10 +499,11 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
|
|||
.copied()
|
||||
.filter(|feature| missing.contains(feature))
|
||||
.collect();
|
||||
self.requires_unsafe(
|
||||
expr.span,
|
||||
CallToFunctionWith { function: func_did, missing, build_enabled },
|
||||
);
|
||||
self.requires_unsafe(expr.span, CallToFunctionWith {
|
||||
function: func_did,
|
||||
missing,
|
||||
build_enabled,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1052,11 +1053,9 @@ pub(crate) fn check_unsafety(tcx: TyCtxt<'_>, def: LocalDefId) {
|
|||
warnings.sort_by_key(|w| w.block_span);
|
||||
for UnusedUnsafeWarning { hir_id, block_span, enclosing_unsafe } in warnings {
|
||||
let block_span = tcx.sess.source_map().guess_head_span(block_span);
|
||||
tcx.emit_node_span_lint(
|
||||
UNUSED_UNSAFE,
|
||||
hir_id,
|
||||
block_span,
|
||||
UnusedUnsafe { span: block_span, enclosing: enclosing_unsafe },
|
||||
);
|
||||
tcx.emit_node_span_lint(UNUSED_UNSAFE, hir_id, block_span, UnusedUnsafe {
|
||||
span: block_span,
|
||||
enclosing: enclosing_unsafe,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,8 @@ use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
|||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_pattern_analysis::errors::Uncovered;
|
||||
use rustc_pattern_analysis::rustc::RustcPatCtxt;
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::symbol::Symbol;
|
||||
|
||||
use crate::fluent_generated as fluent;
|
||||
|
||||
|
|
|
@ -54,12 +54,10 @@ fn check_recursion<'tcx>(
|
|||
|
||||
let sp = tcx.def_span(def_id);
|
||||
let hir_id = tcx.local_def_id_to_hir_id(def_id);
|
||||
tcx.emit_node_span_lint(
|
||||
UNCONDITIONAL_RECURSION,
|
||||
hir_id,
|
||||
sp,
|
||||
UnconditionalRecursion { span: sp, call_sites: vis.reachable_recursive_calls },
|
||||
);
|
||||
tcx.emit_node_span_lint(UNCONDITIONAL_RECURSION, hir_id, sp, UnconditionalRecursion {
|
||||
span: sp,
|
||||
call_sites: vis.reachable_recursive_calls,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,13 +17,13 @@ use rustc_middle::ty::{
|
|||
UserType,
|
||||
};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_target::abi::{FieldIdx, FIRST_VARIANT};
|
||||
use rustc_span::{Span, sym};
|
||||
use rustc_target::abi::{FIRST_VARIANT, FieldIdx};
|
||||
use tracing::{debug, info, instrument, trace};
|
||||
|
||||
use crate::errors;
|
||||
use crate::thir::cx::region::Scope;
|
||||
use crate::thir::cx::Cx;
|
||||
use crate::thir::cx::region::Scope;
|
||||
use crate::thir::util::UserAnnotatedTyHelpers;
|
||||
|
||||
impl<'tcx> Cx<'tcx> {
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
use rustc_data_structures::steal::Steal;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::HirId;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_hir::HirId;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::middle::region;
|
||||
use rustc_middle::thir::*;
|
||||
|
@ -182,9 +182,11 @@ impl<'tcx> Cx<'tcx> {
|
|||
let ty = if fn_decl.c_variadic && index == fn_decl.inputs.len() {
|
||||
let va_list_did = self.tcx.require_lang_item(LangItem::VaList, Some(param.span));
|
||||
|
||||
self.tcx
|
||||
.type_of(va_list_did)
|
||||
.instantiate(self.tcx, &[self.tcx.lifetimes.re_erased.into()])
|
||||
self.tcx.type_of(va_list_did).instantiate(self.tcx, &[self
|
||||
.tcx
|
||||
.lifetimes
|
||||
.re_erased
|
||||
.into()])
|
||||
} else {
|
||||
fn_sig.inputs()[index]
|
||||
};
|
||||
|
|
|
@ -3,7 +3,7 @@ use rustc_ast::Mutability;
|
|||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_errors::codes::*;
|
||||
use rustc_errors::{struct_span_code_err, Applicability, ErrorGuaranteed, MultiSpan};
|
||||
use rustc_errors::{Applicability, ErrorGuaranteed, MultiSpan, struct_span_code_err};
|
||||
use rustc_hir::def::*;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::{self as hir, BindingMode, ByRef, HirId};
|
||||
|
@ -22,7 +22,7 @@ use rustc_session::lint::builtin::{
|
|||
BINDINGS_WITH_VARIANT_NAME, IRREFUTABLE_LET_PATTERNS, UNREACHABLE_PATTERNS,
|
||||
};
|
||||
use rustc_span::hygiene::DesugaringKind;
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_span::{Span, sym};
|
||||
use tracing::instrument;
|
||||
|
||||
use crate::errors::*;
|
||||
|
|
|
@ -10,8 +10,8 @@ use rustc_middle::thir::{FieldPat, Pat, PatKind};
|
|||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, ValTree};
|
||||
use rustc_span::Span;
|
||||
use rustc_target::abi::{FieldIdx, VariantIdx};
|
||||
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
|
||||
use rustc_trait_selection::traits::ObligationCause;
|
||||
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
|
||||
use tracing::{debug, instrument, trace};
|
||||
|
||||
use super::PatCtxt;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue