Skip to content

Commit ff4ed97

Browse files
committed
fix panic on macro-expanded impls with primitive self type
The new is_macro_expanded path in get_attributes_for_automatic_derive runs for any macro-expanded impl, not just #[automatically_derived] ones. Unlike derive impls, macro-expanded impls can target primitive types (e.g. vstd's std_specs/ops.rs generates impl ... for u8/usize/... via macro_rules!), whose Res is PrimTy and has no DefId. Calling path.res.def_id() on those panics; switch to opt_def_id() and fall through to normal classification when there's no def_id, matching the existing fallback arms.
1 parent 74f4ef6 commit ff4ed97

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

source/rust_verify/src/external.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,18 @@ fn get_attributes_for_automatic_derive<'tcx>(
684684
};
685685

686686
let type_def_id = match impll.self_ty.kind {
687+
// self type may resolve to a primitive (e.g. macro-generated impls
688+
// on u8, usize, etc. in vstd), which has no def_id
687689
rustc_hir::TyKind::Path(rustc_hir::QPath::Resolved(None, path)) => {
688-
path.res.def_id()
690+
match path.res.opt_def_id() {
691+
Some(def_id) => def_id,
692+
None => {
693+
if is_auto_derived {
694+
warn_unknown();
695+
}
696+
return None;
697+
}
698+
}
689699
}
690700
_ => {
691701
if is_auto_derived {

0 commit comments

Comments
 (0)