-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use get_diagnostic_name
more
#90985
Use get_diagnostic_name
more
#90985
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -742,15 +742,13 @@ impl BorrowedContentSource<'tcx> { | |
BorrowedContentSource::DerefRawPointer => "a raw pointer".to_string(), | ||
BorrowedContentSource::DerefSharedRef => "a shared reference".to_string(), | ||
BorrowedContentSource::DerefMutableRef => "a mutable reference".to_string(), | ||
BorrowedContentSource::OverloadedDeref(ty) => match ty.kind() { | ||
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Rc, def.did) => { | ||
"an `Rc`".to_string() | ||
} | ||
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Arc, def.did) => { | ||
"an `Arc`".to_string() | ||
} | ||
_ => format!("dereference of `{}`", ty), | ||
}, | ||
BorrowedContentSource::OverloadedDeref(ty) => ty | ||
.ty_adt_def() | ||
.and_then(|adt| match tcx.get_diagnostic_name(adt.did)? { | ||
name @ (sym::Rc | sym::Arc) => Some(format!("an `{}`", name)), | ||
_ => None, | ||
}) | ||
.unwrap_or_else(|| format!("dereference of `{}`", ty)), | ||
BorrowedContentSource::OverloadedIndex(ty) => format!("index of `{}`", ty), | ||
} | ||
} | ||
|
@@ -774,15 +772,13 @@ impl BorrowedContentSource<'tcx> { | |
BorrowedContentSource::DerefMutableRef => { | ||
bug!("describe_for_immutable_place: DerefMutableRef isn't immutable") | ||
} | ||
BorrowedContentSource::OverloadedDeref(ty) => match ty.kind() { | ||
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Rc, def.did) => { | ||
"an `Rc`".to_string() | ||
} | ||
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Arc, def.did) => { | ||
"an `Arc`".to_string() | ||
} | ||
_ => format!("a dereference of `{}`", ty), | ||
}, | ||
BorrowedContentSource::OverloadedDeref(ty) => ty | ||
.ty_adt_def() | ||
.and_then(|adt| match tcx.get_diagnostic_name(adt.did)? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
name @ (sym::Rc | sym::Arc) => Some(format!("an `{}`", name)), | ||
_ => None, | ||
}) | ||
.unwrap_or_else(|| format!("dereference of `{}`", ty)), | ||
BorrowedContentSource::OverloadedIndex(ty) => format!("an index of `{}`", ty), | ||
} | ||
} | ||
|
@@ -966,8 +962,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { | |
_ => None, | ||
}); | ||
let is_option_or_result = parent_self_ty.map_or(false, |def_id| { | ||
tcx.is_diagnostic_item(sym::Option, def_id) | ||
|| tcx.is_diagnostic_item(sym::Result, def_id) | ||
matches!(tcx.get_diagnostic_name(def_id), Some(sym::Option | sym::Result)) | ||
}); | ||
FnSelfUseKind::Normal { self_arg, implicit_into_iter, is_option_or_result } | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -309,14 +309,21 @@ fn panic_call<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>) -> (Span, | |
// Unwrap more levels of macro expansion, as panic_2015!() | ||
// was likely expanded from panic!() and possibly from | ||
// [debug_]assert!(). | ||
for &i in | ||
&[sym::std_panic_macro, sym::core_panic_macro, sym::assert_macro, sym::debug_assert_macro] | ||
{ | ||
loop { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This...isn't exactly the same, right? Previously, we can only match each diagnostic item once? But now we can match the same on continously? Also, now we can ascend many times. I'm not sure there are actually any semantic changes, just worth mentioning. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the current implementation, I think the order of the list is significant because |
||
let parent = expn.call_site.ctxt().outer_expn_data(); | ||
if parent.macro_def_id.map_or(false, |id| cx.tcx.is_diagnostic_item(i, id)) { | ||
expn = parent; | ||
panic_macro = i; | ||
let Some(id) = parent.macro_def_id else { break }; | ||
let Some(name) = cx.tcx.get_diagnostic_name(id) else { break }; | ||
if !matches!( | ||
name, | ||
sym::core_panic_macro | ||
| sym::std_panic_macro | ||
| sym::assert_macro | ||
| sym::debug_assert_macro | ||
) { | ||
break; | ||
} | ||
expn = parent; | ||
panic_macro = name; | ||
} | ||
|
||
let macro_symbol = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of a nit, but I think I prefer having a separate
and_then
forget_diagnostic_name
, rather than using the question mark.