Rollup merge of #137686 - nbdd0121:asm_const, r=compiler-errors
Handle asm const similar to inline const Previously, asm consts are handled similar to anon consts rather than inline consts. Anon consts are not good at dealing with lifetimes, because `type_of` has lifetimes erased already. Inline consts can deal with lifetimes because they live in an outer typeck context. And since `global_asm!` lacks an outer typeck context, we have implemented asm consts with anon consts while they're in fact more similar to inline consts. This was changed in #137180, and this means that handling asm consts as inline consts are possible. While as `@compiler-errors` pointed out, `const` currently can't be used with any types with lifetime, this is about to change if #128464 is implemented. This PR is a preparatory PR for that feature. As an unintentional side effect, fix #117877. cc `@Amanieu` r? `@compiler-errors`
This commit is contained in:
commit
174bbfb369
18 changed files with 132 additions and 99 deletions
|
@ -730,12 +730,20 @@ impl<'tcx> ThirBuildCx<'tcx> {
|
|||
}
|
||||
}
|
||||
hir::InlineAsmOperand::Const { ref anon_const } => {
|
||||
let value =
|
||||
mir::Const::from_unevaluated(tcx, anon_const.def_id.to_def_id())
|
||||
.instantiate_identity();
|
||||
let span = tcx.def_span(anon_const.def_id);
|
||||
let ty = self.typeck_results.node_type(anon_const.hir_id);
|
||||
let did = anon_const.def_id.to_def_id();
|
||||
let typeck_root_def_id = tcx.typeck_root_def_id(did);
|
||||
let parent_args = tcx.erase_regions(GenericArgs::identity_for_item(
|
||||
tcx,
|
||||
typeck_root_def_id,
|
||||
));
|
||||
let args =
|
||||
InlineConstArgs::new(tcx, InlineConstArgsParts { parent_args, ty })
|
||||
.args;
|
||||
|
||||
InlineAsmOperand::Const { value, span }
|
||||
let uneval = mir::UnevaluatedConst::new(did, args);
|
||||
let value = mir::Const::Unevaluated(uneval, ty);
|
||||
InlineAsmOperand::Const { value, span: tcx.def_span(did) }
|
||||
}
|
||||
hir::InlineAsmOperand::SymFn { expr } => {
|
||||
InlineAsmOperand::SymFn { value: self.mirror_expr(expr) }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue