Skip to content

Commit bb37d00

Browse files
committed
more robust method checking through DefId and diagnostic_item
1 parent 7ff57ed commit bb37d00

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/libcore/mem/maybe_uninit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ impl<T> MaybeUninit<T> {
440440
/// ```
441441
#[stable(feature = "maybe_uninit", since = "1.36.0")]
442442
#[inline(always)]
443+
#[cfg_attr(all(not(bootstrap)), rustc_diagnostic_item = "assume_init")]
443444
pub unsafe fn assume_init(self) -> T {
444445
intrinsics::panic_if_uninhabited::<T>();
445446
ManuallyDrop::into_inner(self.value)

src/librustc_lint/builtin.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1933,9 +1933,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
19331933
}
19341934
}
19351935
}
1936-
} else if let hir::ExprKind::MethodCall(ref path, _, ref args) = expr.kind {
1936+
} else if let hir::ExprKind::MethodCall(_, _, ref args) = expr.kind {
19371937
// Find problematic calls to `MaybeUninit::assume_init`.
1938-
if path.ident.name == sym::assume_init {
1938+
let def_id = cx.tables.type_dependent_def_id(expr.hir_id)?;
1939+
if cx.tcx.is_diagnostic_item(sym::assume_init, def_id) {
19391940
// This is a call to *some* method named `assume_init`.
19401941
// See if the `self` parameter is one of the dangerous constructors.
19411942
if let hir::ExprKind::Call(ref path_expr, _) = args[0].kind {

0 commit comments

Comments
 (0)