Reimplement lowering of sym operands for asm! so that it also works with global_asm!
This commit is contained in:
parent
f9d4d12b6a
commit
dc345d8bff
28 changed files with 400 additions and 163 deletions
|
@ -1012,6 +1012,12 @@ impl<'a> Resolver<'a> {
|
|||
err.span_label(trait_item_span, "item in trait");
|
||||
err
|
||||
}
|
||||
ResolutionError::InvalidAsmSym => {
|
||||
let mut err = self.session.struct_span_err(span, "invalid `sym` operand");
|
||||
err.span_label(span, &format!("is a local variable"));
|
||||
err.help("`sym` operands must refer to either a function or a static");
|
||||
err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1182,6 +1182,12 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
return Res::Err;
|
||||
}
|
||||
InlineAsmSymRibKind => {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(span, InvalidAsmSym);
|
||||
}
|
||||
return Res::Err;
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some((span, res_err)) = res_err {
|
||||
|
@ -1242,6 +1248,22 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
return Res::Err;
|
||||
}
|
||||
InlineAsmSymRibKind => {
|
||||
let features = self.session.features_untracked();
|
||||
if !features.generic_const_exprs {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::ParamInNonTrivialAnonConst {
|
||||
name: rib_ident.name,
|
||||
is_type: true,
|
||||
},
|
||||
);
|
||||
}
|
||||
return Res::Err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(span) = finalize {
|
||||
|
@ -1306,6 +1328,22 @@ impl<'a> Resolver<'a> {
|
|||
}
|
||||
return Res::Err;
|
||||
}
|
||||
InlineAsmSymRibKind => {
|
||||
let features = self.session.features_untracked();
|
||||
if !features.generic_const_exprs {
|
||||
if let Some(span) = finalize {
|
||||
self.report_error(
|
||||
span,
|
||||
ResolutionError::ParamInNonTrivialAnonConst {
|
||||
name: rib_ident.name,
|
||||
is_type: false,
|
||||
},
|
||||
);
|
||||
}
|
||||
return Res::Err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
||||
// This was an attempt to use a const parameter outside its scope.
|
||||
|
|
|
@ -140,6 +140,10 @@ crate enum RibKind<'a> {
|
|||
/// We are inside of the type of a const parameter. Can't refer to any
|
||||
/// parameters.
|
||||
ConstParamTyRibKind,
|
||||
|
||||
/// We are inside a `sym` inline assembly operand. Can only refer to
|
||||
/// globals.
|
||||
InlineAsmSymRibKind,
|
||||
}
|
||||
|
||||
impl RibKind<'_> {
|
||||
|
@ -153,7 +157,8 @@ impl RibKind<'_> {
|
|||
| ConstantItemRibKind(..)
|
||||
| ModuleRibKind(_)
|
||||
| MacroDefinition(_)
|
||||
| ConstParamTyRibKind => false,
|
||||
| ConstParamTyRibKind
|
||||
| InlineAsmSymRibKind => false,
|
||||
AssocItemRibKind | ItemRibKind(_) | ForwardGenericParamBanRibKind => true,
|
||||
}
|
||||
}
|
||||
|
@ -722,6 +727,23 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
|
|||
visit::walk_where_predicate(self, p);
|
||||
self.diagnostic_metadata.current_where_predicate = previous_value;
|
||||
}
|
||||
|
||||
fn visit_inline_asm_sym(&mut self, sym: &'ast InlineAsmSym) {
|
||||
// This is similar to the code for AnonConst.
|
||||
self.with_rib(ValueNS, InlineAsmSymRibKind, |this| {
|
||||
this.with_rib(TypeNS, InlineAsmSymRibKind, |this| {
|
||||
this.with_label_rib(InlineAsmSymRibKind, |this| {
|
||||
this.smart_resolve_path(
|
||||
sym.id,
|
||||
sym.qself.as_ref(),
|
||||
&sym.path,
|
||||
PathSource::Expr(None),
|
||||
);
|
||||
visit::walk_inline_asm_sym(this, sym);
|
||||
});
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
||||
|
@ -909,7 +931,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
|
|||
| ConstantItemRibKind(..)
|
||||
| ModuleRibKind(..)
|
||||
| ForwardGenericParamBanRibKind
|
||||
| ConstParamTyRibKind => {
|
||||
| ConstParamTyRibKind
|
||||
| InlineAsmSymRibKind => {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -260,6 +260,8 @@ enum ResolutionError<'a> {
|
|||
trait_item_span: Span,
|
||||
code: rustc_errors::DiagnosticId,
|
||||
},
|
||||
/// Inline asm `sym` operand must refer to a `fn` or `static`.
|
||||
InvalidAsmSym,
|
||||
}
|
||||
|
||||
enum VisResolutionError<'a> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue