Preserve explicit register names in inline asm diagnostics - #160068
Preserve explicit register names in inline asm diagnostics#160068qaijuang wants to merge 2 commits into
Conversation
|
|
|
cc @rust-lang/clippy |
77c0f58 to
d33866e
Compare
| _ => None, | ||
| }; | ||
| let reg_str = |idx| -> &str { | ||
| // HIR asm doesn't preserve the original alias string of the explicit register, |
There was a problem hiding this comment.
Is there a reason it shouldn't, instead of this scheme of re-adding it in metadata?
There was a problem hiding this comment.
I don't see or find any reason why it shouldn't
There was a problem hiding this comment.
May I see how the PR looks like in that form instead, then?
There was a problem hiding this comment.
That would be duplicating the InlineAsmRegOrRegClass type and impl in HiR, is it acceptable?
There was a problem hiding this comment.
The exact HiR impl
/// Stores explicit register name from source
/// for diagnostics only.
#[derive(Debug, Clone, Copy, StableHash)]
pub enum InlineAsmRegOrRegClass {
Reg { reg: asm::InlineAsmReg, source_name: Option<Symbol> },
RegClass(asm::InlineAsmRegClass),
}
impl InlineAsmRegOrRegClass {
// For `rustc_mir_build` and `clippy_utils`
pub fn as_target(self) -> asm::InlineAsmRegOrRegClass {
match self {
Self::Reg { reg, .. } => asm::InlineAsmRegOrRegClass::Reg(reg),
Self::RegClass(reg_class) => asm::InlineAsmRegOrRegClass::RegClass(reg_class),
}
}
// For `rustc_ast_lowering`
pub fn reg_class(self) -> asm::InlineAsmRegClass {
self.as_target().reg_class()
}
// For `rustc_ast_lowering`
pub fn source_name(self) -> Option<Symbol> {
match self {
Self::Reg { source_name, .. } => source_name,
Self::RegClass(_) => None,
}
}
}
// For `rustc_hir_pretty`
impl fmt::Display for InlineAsmRegOrRegClass {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.as_target().fmt(f)
}
}There was a problem hiding this comment.
Either variants seems fine to me.
There was a problem hiding this comment.
@workingjubilee let me know the direction we are taking.
|
@rustbot reroll (reviewer seems busy) |
|
@rustbot reroll |
This PR adds diagnostic-only metadata directly to each register-bearing HIR operand, and replaces #117912 AST lookup with the new HIR metadata.
r? @workingjubilee
Fixes #159409