2017-07-03 08:24:52 -05:00
|
|
|
//! A group of attributes that can be attached to Rust code in order
|
|
|
|
//! to generate a clippy lint detecting said code automatically.
|
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
use clippy_utils::{get_attr, higher};
|
2020-12-06 15:00:24 -06:00
|
|
|
use rustc_ast::ast::{LitFloatType, LitKind};
|
2021-12-06 05:33:31 -06:00
|
|
|
use rustc_ast::LitIntType;
|
2018-12-29 09:04:45 -06:00
|
|
|
use rustc_data_structures::fx::FxHashMap;
|
2020-01-06 10:39:50 -06:00
|
|
|
use rustc_hir as hir;
|
2022-08-30 17:36:53 -05:00
|
|
|
use rustc_hir::{
|
|
|
|
ArrayLen, BindingAnnotation, Closure, ExprKind, FnRetTy, HirId, Lit, PatKind, QPath, StmtKind, TyKind,
|
|
|
|
};
|
2020-01-12 00:08:41 -06:00
|
|
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
2020-01-11 05:37:08 -06:00
|
|
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
2021-12-06 05:33:31 -06:00
|
|
|
use rustc_span::symbol::{Ident, Symbol};
|
2022-10-23 08:18:45 -05:00
|
|
|
use std::cell::Cell;
|
2021-12-06 05:33:31 -06:00
|
|
|
use std::fmt::{Display, Formatter, Write as _};
|
2017-07-03 08:24:52 -05:00
|
|
|
|
2018-03-28 08:24:26 -05:00
|
|
|
declare_clippy_lint! {
|
2021-07-29 05:16:06 -05:00
|
|
|
/// ### What it does
|
|
|
|
/// Generates clippy code that detects the offending pattern
|
2019-03-05 10:50:33 -06:00
|
|
|
///
|
2021-07-29 05:16:06 -05:00
|
|
|
/// ### Example
|
2019-08-02 01:13:54 -05:00
|
|
|
/// ```rust,ignore
|
2019-03-05 10:50:33 -06:00
|
|
|
/// // ./tests/ui/my_lint.rs
|
|
|
|
/// fn foo() {
|
|
|
|
/// // detect the following pattern
|
|
|
|
/// #[clippy::author]
|
|
|
|
/// if x == 42 {
|
|
|
|
/// // but ignore everything from here on
|
|
|
|
/// #![clippy::author = "ignore"]
|
|
|
|
/// }
|
2019-08-02 01:13:54 -05:00
|
|
|
/// ()
|
2019-03-05 10:50:33 -06:00
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// Running `TESTNAME=ui/my_lint cargo uitest` will produce
|
|
|
|
/// a `./tests/ui/new_lint.stdout` file with the generated code:
|
|
|
|
///
|
2019-08-02 01:13:54 -05:00
|
|
|
/// ```rust,ignore
|
2019-03-05 10:50:33 -06:00
|
|
|
/// // ./tests/ui/new_lint.stdout
|
2022-10-23 08:18:45 -05:00
|
|
|
/// if ExprKind::If(ref cond, ref then, None) = item.kind
|
|
|
|
/// && let ExprKind::Binary(BinOp::Eq, ref left, ref right) = cond.kind
|
|
|
|
/// && let ExprKind::Path(ref path) = left.kind
|
|
|
|
/// && let ExprKind::Lit(ref lit) = right.kind
|
|
|
|
/// && let LitKind::Int(42, _) = lit.node
|
|
|
|
/// {
|
|
|
|
/// // report your lint here
|
2019-03-05 10:50:33 -06:00
|
|
|
/// }
|
|
|
|
/// ```
|
2017-07-03 08:24:52 -05:00
|
|
|
pub LINT_AUTHOR,
|
2018-03-29 06:41:53 -05:00
|
|
|
internal_warn,
|
2017-07-03 08:24:52 -05:00
|
|
|
"helper for writing lints"
|
|
|
|
}
|
|
|
|
|
2019-04-08 15:43:55 -05:00
|
|
|
declare_lint_pass!(Author => [LINT_AUTHOR]);
|
2017-07-03 08:24:52 -05:00
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
/// Writes a line of output with indentation added
|
|
|
|
macro_rules! out {
|
|
|
|
($($t:tt)*) => {
|
|
|
|
println!(" {}", format_args!($($t)*))
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The variables passed in are replaced with `&Binding`s where the `value` field is set
|
|
|
|
/// to the original value of the variable. The `name` field is set to the name of the variable
|
|
|
|
/// (using `stringify!`) and is adjusted to avoid duplicate names.
|
|
|
|
/// Note that the `Binding` may be printed directly to output the `name`.
|
|
|
|
macro_rules! bind {
|
|
|
|
($self:ident $(, $name:ident)+) => {
|
|
|
|
$(let $name = & $self.bind(stringify!($name), $name);)+
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-05-05 09:12:52 -05:00
|
|
|
/// Transforms the given `Option<T>` variables into `OptionPat<Binding<T>>`.
|
2021-12-06 05:33:31 -06:00
|
|
|
/// This displays as `Some($name)` or `None` when printed. The name of the inner binding
|
|
|
|
/// is set to the name of the variable passed to the macro.
|
|
|
|
macro_rules! opt_bind {
|
|
|
|
($self:ident $(, $name:ident)+) => {
|
|
|
|
$(let $name = OptionPat::new($name.map(|o| $self.bind(stringify!($name), o)));)+
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Creates a `Binding` that accesses the field of an existing `Binding`
|
|
|
|
macro_rules! field {
|
|
|
|
($binding:ident.$field:ident) => {
|
|
|
|
&Binding {
|
|
|
|
name: $binding.name.to_string() + stringify!(.$field),
|
|
|
|
value: $binding.value.$field,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-23 08:18:45 -05:00
|
|
|
/// Print a condition of a let chain, `chain!(self, "let Some(x) = y")` will print
|
|
|
|
/// `if let Some(x) = y` on the first call and ` && let Some(x) = y` thereafter
|
|
|
|
macro_rules! chain {
|
|
|
|
($self:ident, $($t:tt)*) => {
|
|
|
|
if $self.first.take() {
|
|
|
|
println!("if {}", format_args!($($t)*));
|
|
|
|
} else {
|
|
|
|
println!(" && {}", format_args!($($t)*));
|
|
|
|
}
|
|
|
|
}
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|
|
|
|
|
2020-06-25 15:41:36 -05:00
|
|
|
impl<'tcx> LateLintPass<'tcx> for Author {
|
|
|
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
2021-12-06 05:33:31 -06:00
|
|
|
check_item(cx, item.hir_id());
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|
|
|
|
|
2020-06-25 15:41:36 -05:00
|
|
|
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
|
2021-12-06 05:33:31 -06:00
|
|
|
check_item(cx, item.hir_id());
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|
|
|
|
|
2020-06-25 15:41:36 -05:00
|
|
|
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
|
2021-12-06 05:33:31 -06:00
|
|
|
check_item(cx, item.hir_id());
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
fn check_arm(&mut self, cx: &LateContext<'tcx>, arm: &'tcx hir::Arm<'_>) {
|
|
|
|
check_node(cx, arm.hir_id, |v| {
|
|
|
|
v.arm(&v.bind("arm", arm));
|
|
|
|
});
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|
|
|
|
|
2020-06-25 15:41:36 -05:00
|
|
|
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) {
|
2021-12-06 05:33:31 -06:00
|
|
|
check_node(cx, expr.hir_id, |v| {
|
|
|
|
v.expr(&v.bind("expr", expr));
|
|
|
|
});
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|
|
|
|
|
2020-06-25 15:41:36 -05:00
|
|
|
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx hir::Stmt<'_>) {
|
2021-07-29 05:16:06 -05:00
|
|
|
match stmt.kind {
|
|
|
|
StmtKind::Expr(e) | StmtKind::Semi(e) if has_attr(cx, e.hir_id) => return,
|
|
|
|
_ => {},
|
|
|
|
}
|
2021-12-06 05:33:31 -06:00
|
|
|
check_node(cx, stmt.hir_id, |v| {
|
|
|
|
v.stmt(&v.bind("stmt", stmt));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_item(cx: &LateContext<'_>, hir_id: HirId) {
|
|
|
|
let hir = cx.tcx.hir();
|
2022-09-20 00:11:23 -05:00
|
|
|
if let Some(body_id) = hir.maybe_body_owned_by(hir_id.expect_owner().def_id) {
|
2021-12-06 05:33:31 -06:00
|
|
|
check_node(cx, hir_id, |v| {
|
2022-09-09 06:36:26 -05:00
|
|
|
v.expr(&v.bind("expr", hir.body(body_id).value));
|
2021-12-06 05:33:31 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn check_node(cx: &LateContext<'_>, hir_id: HirId, f: impl Fn(&PrintVisitor<'_, '_>)) {
|
|
|
|
if has_attr(cx, hir_id) {
|
|
|
|
f(&PrintVisitor::new(cx));
|
2022-10-23 08:18:45 -05:00
|
|
|
println!("{{");
|
|
|
|
println!(" // report your lint here");
|
|
|
|
println!("}}");
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|
2021-12-06 05:33:31 -06:00
|
|
|
}
|
2017-07-03 08:24:52 -05:00
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
struct Binding<T> {
|
|
|
|
name: String,
|
|
|
|
value: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Display for Binding<T> {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
f.write_str(&self.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct OptionPat<T> {
|
|
|
|
pub opt: Option<T>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> OptionPat<T> {
|
|
|
|
fn new(opt: Option<T>) -> Self {
|
|
|
|
Self { opt }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn if_some(&self, f: impl Fn(&T)) {
|
|
|
|
if let Some(t) = &self.opt {
|
|
|
|
f(t);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T: Display> Display for OptionPat<T> {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
|
|
match &self.opt {
|
|
|
|
None => f.write_str("None"),
|
|
|
|
Some(node) => write!(f, "Some({node})"),
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
struct PrintVisitor<'a, 'tcx> {
|
|
|
|
cx: &'a LateContext<'tcx>,
|
|
|
|
/// Fields are the current index that needs to be appended to pattern
|
|
|
|
/// binding names
|
2022-10-23 08:18:45 -05:00
|
|
|
ids: Cell<FxHashMap<&'static str, u32>>,
|
|
|
|
/// Currently at the first condition in the if chain
|
|
|
|
first: Cell<bool>,
|
2021-12-06 05:33:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(clippy::unused_self)]
|
|
|
|
impl<'a, 'tcx> PrintVisitor<'a, 'tcx> {
|
|
|
|
fn new(cx: &'a LateContext<'tcx>) -> Self {
|
2017-08-21 06:32:12 -05:00
|
|
|
Self {
|
2021-12-06 05:33:31 -06:00
|
|
|
cx,
|
2022-10-23 08:18:45 -05:00
|
|
|
ids: Cell::default(),
|
|
|
|
first: Cell::new(true),
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
fn next(&self, s: &'static str) -> String {
|
|
|
|
let mut ids = self.ids.take();
|
|
|
|
let out = match *ids.entry(s).and_modify(|n| *n += 1).or_default() {
|
|
|
|
// first usage of the name, use it as is
|
|
|
|
0 => s.to_string(),
|
|
|
|
// append a number starting with 1
|
|
|
|
n => format!("{s}{n}"),
|
|
|
|
};
|
|
|
|
self.ids.set(ids);
|
|
|
|
out
|
|
|
|
}
|
|
|
|
|
|
|
|
fn bind<T>(&self, name: &'static str, value: T) -> Binding<T> {
|
|
|
|
let name = self.next(name);
|
|
|
|
Binding { name, value }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn option<T: Copy>(&self, option: &Binding<Option<T>>, name: &'static str, f: impl Fn(&Binding<T>)) {
|
|
|
|
match option.value {
|
2022-10-23 08:18:45 -05:00
|
|
|
None => chain!(self, "{option}.is_none()"),
|
2021-12-06 05:33:31 -06:00
|
|
|
Some(value) => {
|
|
|
|
let value = &self.bind(name, value);
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "let Some({value}) = {option}");
|
2021-12-06 05:33:31 -06:00
|
|
|
f(value);
|
2017-08-09 02:30:56 -05:00
|
|
|
},
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|
|
|
|
}
|
2018-02-24 12:34:51 -06:00
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
fn slice<T>(&self, slice: &Binding<&[T]>, f: impl Fn(&Binding<&T>)) {
|
|
|
|
if slice.value.is_empty() {
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "{slice}.is_empty()");
|
2020-08-28 09:10:16 -05:00
|
|
|
} else {
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "{slice}.len() == {}", slice.value.len());
|
2021-12-06 05:33:31 -06:00
|
|
|
for (i, value) in slice.value.iter().enumerate() {
|
|
|
|
let name = format!("{slice}[{i}]");
|
|
|
|
f(&Binding { name, value });
|
|
|
|
}
|
2020-08-04 08:24:13 -05:00
|
|
|
}
|
2018-02-24 12:34:51 -06:00
|
|
|
}
|
2017-07-03 08:24:52 -05:00
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
fn destination(&self, destination: &Binding<hir::Destination>) {
|
|
|
|
self.option(field!(destination.label), "label", |label| {
|
|
|
|
self.ident(field!(label.ident));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ident(&self, ident: &Binding<Ident>) {
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "{ident}.as_str() == {:?}", ident.value.as_str());
|
2021-12-06 05:33:31 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn symbol(&self, symbol: &Binding<Symbol>) {
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "{symbol}.as_str() == {:?}", symbol.value.as_str());
|
2021-12-06 05:33:31 -06:00
|
|
|
}
|
2017-07-03 08:24:52 -05:00
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
fn qpath(&self, qpath: &Binding<&QPath<'_>>) {
|
2021-11-16 14:44:25 -06:00
|
|
|
if let QPath::LangItem(lang_item, ..) = *qpath.value {
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "matches!({qpath}, QPath::LangItem(LangItem::{lang_item:?}, _))");
|
2021-12-06 05:33:31 -06:00
|
|
|
} else {
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "match_qpath({qpath}, &[{}])", path_to_string(qpath.value));
|
2021-12-06 05:33:31 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn lit(&self, lit: &Binding<&Lit>) {
|
2022-10-23 08:18:45 -05:00
|
|
|
let kind = |kind| chain!(self, "let LitKind::{kind} = {lit}.node");
|
2021-12-06 05:33:31 -06:00
|
|
|
macro_rules! kind {
|
|
|
|
($($t:tt)*) => (kind(format_args!($($t)*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
match lit.value.node {
|
|
|
|
LitKind::Bool(val) => kind!("Bool({val:?})"),
|
|
|
|
LitKind::Char(c) => kind!("Char({c:?})"),
|
2022-08-21 22:27:52 -05:00
|
|
|
LitKind::Err => kind!("Err"),
|
2021-12-06 05:33:31 -06:00
|
|
|
LitKind::Byte(b) => kind!("Byte({b})"),
|
|
|
|
LitKind::Int(i, suffix) => {
|
|
|
|
let int_ty = match suffix {
|
|
|
|
LitIntType::Signed(int_ty) => format!("LitIntType::Signed(IntTy::{int_ty:?})"),
|
|
|
|
LitIntType::Unsigned(uint_ty) => format!("LitIntType::Unsigned(UintTy::{uint_ty:?})"),
|
|
|
|
LitIntType::Unsuffixed => String::from("LitIntType::Unsuffixed"),
|
|
|
|
};
|
|
|
|
kind!("Int({i}, {int_ty})");
|
|
|
|
},
|
|
|
|
LitKind::Float(_, suffix) => {
|
|
|
|
let float_ty = match suffix {
|
|
|
|
LitFloatType::Suffixed(suffix_ty) => format!("LitFloatType::Suffixed(FloatTy::{suffix_ty:?})"),
|
|
|
|
LitFloatType::Unsuffixed => String::from("LitFloatType::Unsuffixed"),
|
|
|
|
};
|
|
|
|
kind!("Float(_, {float_ty})");
|
|
|
|
},
|
2022-11-28 20:35:44 -06:00
|
|
|
LitKind::ByteStr(ref vec, _) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, vec);
|
|
|
|
kind!("ByteStr(ref {vec})");
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "let [{:?}] = **{vec}", vec.value);
|
2021-12-06 05:33:31 -06:00
|
|
|
},
|
2023-03-05 09:03:22 -06:00
|
|
|
LitKind::CStr(ref vec, _) => {
|
|
|
|
bind!(self, vec);
|
|
|
|
kind!("CStr(ref {vec})");
|
|
|
|
chain!(self, "let [{:?}] = **{vec}", vec.value);
|
2023-05-20 08:39:26 -05:00
|
|
|
},
|
2021-12-06 05:33:31 -06:00
|
|
|
LitKind::Str(s, _) => {
|
|
|
|
bind!(self, s);
|
|
|
|
kind!("Str({s}, _)");
|
|
|
|
self.symbol(s);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn arm(&self, arm: &Binding<&hir::Arm<'_>>) {
|
|
|
|
self.pat(field!(arm.pat));
|
|
|
|
match arm.value.guard {
|
2022-10-23 08:18:45 -05:00
|
|
|
None => chain!(self, "{arm}.guard.is_none()"),
|
2021-12-06 05:33:31 -06:00
|
|
|
Some(hir::Guard::If(expr)) => {
|
|
|
|
bind!(self, expr);
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "let Some(Guard::If({expr})) = {arm}.guard");
|
2021-12-06 05:33:31 -06:00
|
|
|
self.expr(expr);
|
|
|
|
},
|
2022-05-09 08:48:57 -05:00
|
|
|
Some(hir::Guard::IfLet(let_expr)) => {
|
|
|
|
bind!(self, let_expr);
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "let Some(Guard::IfLet({let_expr}) = {arm}.guard");
|
2022-05-09 08:48:57 -05:00
|
|
|
self.pat(field!(let_expr.pat));
|
|
|
|
self.expr(field!(let_expr.init));
|
2021-12-06 05:33:31 -06:00
|
|
|
},
|
|
|
|
}
|
|
|
|
self.expr(field!(arm.body));
|
|
|
|
}
|
2020-01-09 01:13:22 -06:00
|
|
|
|
2019-01-13 09:19:02 -06:00
|
|
|
#[allow(clippy::too_many_lines)]
|
2021-12-06 05:33:31 -06:00
|
|
|
fn expr(&self, expr: &Binding<&hir::Expr<'_>>) {
|
2023-05-05 10:45:49 -05:00
|
|
|
if let Some(higher::While { condition, body, .. }) = higher::While::hir(expr.value) {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, condition, body);
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(
|
|
|
|
self,
|
|
|
|
"let Some(higher::While {{ condition: {condition}, body: {body} }}) \
|
|
|
|
= higher::While::hir({expr})"
|
2021-12-06 05:33:31 -06:00
|
|
|
);
|
|
|
|
self.expr(condition);
|
|
|
|
self.expr(body);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(higher::WhileLet {
|
|
|
|
let_pat,
|
|
|
|
let_expr,
|
|
|
|
if_then,
|
|
|
|
}) = higher::WhileLet::hir(expr.value)
|
|
|
|
{
|
|
|
|
bind!(self, let_pat, let_expr, if_then);
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(
|
|
|
|
self,
|
|
|
|
"let Some(higher::WhileLet {{ let_pat: {let_pat}, let_expr: {let_expr}, if_then: {if_then} }}) \
|
|
|
|
= higher::WhileLet::hir({expr})"
|
2021-12-06 05:33:31 -06:00
|
|
|
);
|
|
|
|
self.pat(let_pat);
|
|
|
|
self.expr(let_expr);
|
|
|
|
self.expr(if_then);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(higher::ForLoop { pat, arg, body, .. }) = higher::ForLoop::hir(expr.value) {
|
|
|
|
bind!(self, pat, arg, body);
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(
|
|
|
|
self,
|
|
|
|
"let Some(higher::ForLoop {{ pat: {pat}, arg: {arg}, body: {body}, .. }}) \
|
|
|
|
= higher::ForLoop::hir({expr})"
|
2021-12-06 05:33:31 -06:00
|
|
|
);
|
|
|
|
self.pat(pat);
|
|
|
|
self.expr(arg);
|
|
|
|
self.expr(body);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-23 08:18:45 -05:00
|
|
|
let kind = |kind| chain!(self, "let ExprKind::{kind} = {expr}.kind");
|
2021-12-06 05:33:31 -06:00
|
|
|
macro_rules! kind {
|
|
|
|
($($t:tt)*) => (kind(format_args!($($t)*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
match expr.value.kind {
|
2021-10-13 02:44:47 -05:00
|
|
|
ExprKind::Let(let_expr) => {
|
|
|
|
bind!(self, let_expr);
|
|
|
|
kind!("Let({let_expr})");
|
|
|
|
self.pat(field!(let_expr.pat));
|
|
|
|
// Does what ExprKind::Cast does, only adds a clause for the type
|
|
|
|
// if it's a path
|
|
|
|
if let Some(TyKind::Path(ref qpath)) = let_expr.value.ty.as_ref().map(|ty| &ty.kind) {
|
|
|
|
bind!(self, qpath);
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "let TyKind::Path(ref {qpath}) = {let_expr}.ty.kind");
|
2021-10-13 02:44:47 -05:00
|
|
|
self.qpath(qpath);
|
|
|
|
}
|
|
|
|
self.expr(field!(let_expr.init));
|
2021-08-08 09:49:13 -05:00
|
|
|
},
|
2021-04-08 10:50:13 -05:00
|
|
|
ExprKind::Array(elements) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, elements);
|
|
|
|
kind!("Array({elements})");
|
|
|
|
self.slice(elements, |e| self.expr(e));
|
2017-07-03 08:24:52 -05:00
|
|
|
},
|
2021-04-08 10:50:13 -05:00
|
|
|
ExprKind::Call(func, args) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, func, args);
|
|
|
|
kind!("Call({func}, {args})");
|
|
|
|
self.expr(func);
|
|
|
|
self.slice(args, |e| self.expr(e));
|
2017-07-03 08:24:52 -05:00
|
|
|
},
|
2022-09-01 04:43:35 -05:00
|
|
|
ExprKind::MethodCall(method_name, receiver, args, _) => {
|
|
|
|
bind!(self, method_name, receiver, args);
|
|
|
|
kind!("MethodCall({method_name}, {receiver}, {args}, _)");
|
2021-12-06 05:33:31 -06:00
|
|
|
self.ident(field!(method_name.ident));
|
2022-09-01 04:43:35 -05:00
|
|
|
self.expr(receiver);
|
2021-12-06 05:33:31 -06:00
|
|
|
self.slice(args, |e| self.expr(e));
|
2017-07-03 08:24:52 -05:00
|
|
|
},
|
2021-04-08 10:50:13 -05:00
|
|
|
ExprKind::Tup(elements) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, elements);
|
|
|
|
kind!("Tup({elements})");
|
|
|
|
self.slice(elements, |e| self.expr(e));
|
|
|
|
},
|
|
|
|
ExprKind::Binary(op, left, right) => {
|
|
|
|
bind!(self, op, left, right);
|
|
|
|
kind!("Binary({op}, {left}, {right})");
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "BinOpKind::{:?} == {op}.node", op.value.node);
|
2021-12-06 05:33:31 -06:00
|
|
|
self.expr(left);
|
|
|
|
self.expr(right);
|
|
|
|
},
|
|
|
|
ExprKind::Unary(op, inner) => {
|
|
|
|
bind!(self, inner);
|
|
|
|
kind!("Unary(UnOp::{op:?}, {inner})");
|
|
|
|
self.expr(inner);
|
2017-07-03 08:24:52 -05:00
|
|
|
},
|
2023-03-25 05:12:35 -05:00
|
|
|
ExprKind::Lit(lit) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, lit);
|
|
|
|
kind!("Lit(ref {lit})");
|
|
|
|
self.lit(lit);
|
|
|
|
},
|
|
|
|
ExprKind::Cast(expr, cast_ty) => {
|
|
|
|
bind!(self, expr, cast_ty);
|
|
|
|
kind!("Cast({expr}, {cast_ty})");
|
|
|
|
if let TyKind::Path(ref qpath) = cast_ty.value.kind {
|
|
|
|
bind!(self, qpath);
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "let TyKind::Path(ref {qpath}) = {cast_ty}.kind");
|
2021-12-06 05:33:31 -06:00
|
|
|
self.qpath(qpath);
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|
2021-12-06 05:33:31 -06:00
|
|
|
self.expr(expr);
|
2017-07-03 08:24:52 -05:00
|
|
|
},
|
2021-04-08 10:50:13 -05:00
|
|
|
ExprKind::Type(expr, _ty) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, expr);
|
|
|
|
kind!("Type({expr}, _)");
|
|
|
|
self.expr(expr);
|
|
|
|
},
|
|
|
|
ExprKind::Loop(body, label, des, _) => {
|
|
|
|
bind!(self, body);
|
|
|
|
opt_bind!(self, label);
|
|
|
|
kind!("Loop({body}, {label}, LoopSource::{des:?}, _)");
|
|
|
|
self.block(body);
|
|
|
|
label.if_some(|l| self.ident(field!(l.ident)));
|
|
|
|
},
|
|
|
|
ExprKind::If(cond, then, else_expr) => {
|
|
|
|
bind!(self, cond, then);
|
|
|
|
opt_bind!(self, else_expr);
|
|
|
|
kind!("If({cond}, {then}, {else_expr})");
|
|
|
|
self.expr(cond);
|
|
|
|
self.expr(then);
|
|
|
|
else_expr.if_some(|e| self.expr(e));
|
|
|
|
},
|
|
|
|
ExprKind::Match(scrutinee, arms, des) => {
|
|
|
|
bind!(self, scrutinee, arms);
|
|
|
|
kind!("Match({scrutinee}, {arms}, MatchSource::{des:?})");
|
|
|
|
self.expr(scrutinee);
|
|
|
|
self.slice(arms, |arm| self.arm(arm));
|
|
|
|
},
|
2022-06-30 05:18:51 -05:00
|
|
|
ExprKind::Closure(&Closure {
|
2022-06-11 14:25:25 -05:00
|
|
|
capture_clause,
|
|
|
|
fn_decl,
|
|
|
|
body: body_id,
|
|
|
|
movability,
|
|
|
|
..
|
2022-06-30 05:18:51 -05:00
|
|
|
}) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
let movability = OptionPat::new(movability.map(|m| format!("Movability::{m:?}")));
|
|
|
|
|
|
|
|
let ret_ty = match fn_decl.output {
|
|
|
|
FnRetTy::DefaultReturn(_) => "FnRetTy::DefaultReturn(_)",
|
|
|
|
FnRetTy::Return(_) => "FnRetTy::Return(_ty)",
|
|
|
|
};
|
|
|
|
|
|
|
|
bind!(self, fn_decl, body_id);
|
2022-06-11 14:25:25 -05:00
|
|
|
kind!("Closure(CaptureBy::{capture_clause:?}, {fn_decl}, {body_id}, _, {movability})");
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "let {ret_ty} = {fn_decl}.output");
|
2021-12-06 05:33:31 -06:00
|
|
|
self.body(body_id);
|
|
|
|
},
|
|
|
|
ExprKind::Yield(sub, source) => {
|
|
|
|
bind!(self, sub);
|
|
|
|
kind!("Yield(sub, YieldSource::{source:?})");
|
|
|
|
self.expr(sub);
|
|
|
|
},
|
|
|
|
ExprKind::Block(block, label) => {
|
|
|
|
bind!(self, block);
|
|
|
|
opt_bind!(self, label);
|
|
|
|
kind!("Block({block}, {label})");
|
|
|
|
self.block(block);
|
|
|
|
label.if_some(|l| self.ident(field!(l.ident)));
|
2017-07-03 08:24:52 -05:00
|
|
|
},
|
2021-04-08 10:50:13 -05:00
|
|
|
ExprKind::Assign(target, value, _) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, target, value);
|
|
|
|
kind!("Assign({target}, {value}, _span)");
|
|
|
|
self.expr(target);
|
|
|
|
self.expr(value);
|
|
|
|
},
|
|
|
|
ExprKind::AssignOp(op, target, value) => {
|
|
|
|
bind!(self, op, target, value);
|
|
|
|
kind!("AssignOp({op}, {target}, {value})");
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "BinOpKind::{:?} == {op}.node", op.value.node);
|
2021-12-06 05:33:31 -06:00
|
|
|
self.expr(target);
|
|
|
|
self.expr(value);
|
|
|
|
},
|
|
|
|
ExprKind::Field(object, field_name) => {
|
|
|
|
bind!(self, object, field_name);
|
|
|
|
kind!("Field({object}, {field_name})");
|
|
|
|
self.ident(field_name);
|
|
|
|
self.expr(object);
|
2017-07-03 08:24:52 -05:00
|
|
|
},
|
2023-08-03 14:43:17 -05:00
|
|
|
ExprKind::Index(object, index, _) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, object, index);
|
|
|
|
kind!("Index({object}, {index})");
|
|
|
|
self.expr(object);
|
|
|
|
self.expr(index);
|
|
|
|
},
|
|
|
|
ExprKind::Path(ref qpath) => {
|
|
|
|
bind!(self, qpath);
|
|
|
|
kind!("Path(ref {qpath})");
|
|
|
|
self.qpath(qpath);
|
2017-07-03 08:24:52 -05:00
|
|
|
},
|
2021-04-08 10:50:13 -05:00
|
|
|
ExprKind::AddrOf(kind, mutability, inner) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, inner);
|
|
|
|
kind!("AddrOf(BorrowKind::{kind:?}, Mutability::{mutability:?}, {inner})");
|
|
|
|
self.expr(inner);
|
|
|
|
},
|
|
|
|
ExprKind::Break(destination, value) => {
|
|
|
|
bind!(self, destination);
|
|
|
|
opt_bind!(self, value);
|
|
|
|
kind!("Break({destination}, {value})");
|
|
|
|
self.destination(destination);
|
|
|
|
value.if_some(|e| self.expr(e));
|
|
|
|
},
|
|
|
|
ExprKind::Continue(destination) => {
|
|
|
|
bind!(self, destination);
|
|
|
|
kind!("Continue({destination})");
|
|
|
|
self.destination(destination);
|
|
|
|
},
|
|
|
|
ExprKind::Ret(value) => {
|
|
|
|
opt_bind!(self, value);
|
|
|
|
kind!("Ret({value})");
|
|
|
|
value.if_some(|e| self.expr(e));
|
2017-07-03 08:24:52 -05:00
|
|
|
},
|
2023-06-21 09:00:51 -05:00
|
|
|
ExprKind::Become(value) => {
|
|
|
|
bind!(self, value);
|
|
|
|
kind!("Become({value})");
|
|
|
|
self.expr(value);
|
|
|
|
},
|
2020-05-06 09:03:53 -05:00
|
|
|
ExprKind::InlineAsm(_) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
kind!("InlineAsm(_)");
|
|
|
|
out!("// unimplemented: `ExprKind::InlineAsm` is not further destructured at the moment");
|
2020-05-06 09:03:53 -05:00
|
|
|
},
|
2022-09-11 02:37:49 -05:00
|
|
|
ExprKind::OffsetOf(container, ref fields) => {
|
|
|
|
bind!(self, container, fields);
|
|
|
|
kind!("OffsetOf({container}, {fields})");
|
2023-05-05 10:45:49 -05:00
|
|
|
},
|
2021-12-06 05:33:31 -06:00
|
|
|
ExprKind::Struct(qpath, fields, base) => {
|
|
|
|
bind!(self, qpath, fields);
|
|
|
|
opt_bind!(self, base);
|
|
|
|
kind!("Struct({qpath}, {fields}, {base})");
|
|
|
|
self.qpath(qpath);
|
|
|
|
self.slice(fields, |field| {
|
|
|
|
self.ident(field!(field.ident));
|
|
|
|
self.expr(field!(field.expr));
|
|
|
|
});
|
|
|
|
base.if_some(|e| self.expr(e));
|
|
|
|
},
|
|
|
|
ExprKind::ConstBlock(_) => kind!("ConstBlock(_)"),
|
|
|
|
ExprKind::Repeat(value, length) => {
|
|
|
|
bind!(self, value, length);
|
|
|
|
kind!("Repeat({value}, {length})");
|
|
|
|
self.expr(value);
|
2021-12-23 03:02:05 -06:00
|
|
|
match length.value {
|
2022-10-23 08:18:45 -05:00
|
|
|
ArrayLen::Infer(..) => chain!(self, "let ArrayLen::Infer(..) = length"),
|
2021-12-23 03:02:05 -06:00
|
|
|
ArrayLen::Body(anon_const) => {
|
|
|
|
bind!(self, anon_const);
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "let ArrayLen::Body({anon_const}) = {length}");
|
2021-12-23 03:02:05 -06:00
|
|
|
self.body(field!(anon_const.body));
|
2022-01-13 06:18:19 -06:00
|
|
|
},
|
2021-12-23 03:02:05 -06:00
|
|
|
}
|
2021-12-06 05:33:31 -06:00
|
|
|
},
|
2023-03-10 03:53:50 -06:00
|
|
|
ExprKind::Err(_) => kind!("Err(_)"),
|
2021-04-08 10:50:13 -05:00
|
|
|
ExprKind::DropTemps(expr) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, expr);
|
|
|
|
kind!("DropTemps({expr})");
|
|
|
|
self.expr(expr);
|
2019-04-28 02:11:20 -05:00
|
|
|
},
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
fn block(&self, block: &Binding<&hir::Block<'_>>) {
|
|
|
|
self.slice(field!(block.stmts), |stmt| self.stmt(stmt));
|
|
|
|
self.option(field!(block.expr), "trailing_expr", |expr| {
|
|
|
|
self.expr(expr);
|
|
|
|
});
|
2019-05-19 09:52:44 -05:00
|
|
|
}
|
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
fn body(&self, body_id: &Binding<hir::BodyId>) {
|
2022-08-26 00:43:00 -05:00
|
|
|
let expr = self.cx.tcx.hir().body(body_id.value).value;
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, expr);
|
2022-10-23 08:18:45 -05:00
|
|
|
chain!(self, "{expr} = &cx.tcx.hir().body({body_id}).value");
|
2021-12-06 05:33:31 -06:00
|
|
|
self.expr(expr);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn pat(&self, pat: &Binding<&hir::Pat<'_>>) {
|
2022-10-23 08:18:45 -05:00
|
|
|
let kind = |kind| chain!(self, "let PatKind::{kind} = {pat}.kind");
|
2021-12-06 05:33:31 -06:00
|
|
|
macro_rules! kind {
|
|
|
|
($($t:tt)*) => (kind(format_args!($($t)*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
match pat.value.kind {
|
|
|
|
PatKind::Wild => kind!("Wild"),
|
2022-08-30 17:36:53 -05:00
|
|
|
PatKind::Binding(ann, _, name, sub) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, name);
|
|
|
|
opt_bind!(self, sub);
|
2022-08-30 17:36:53 -05:00
|
|
|
let ann = match ann {
|
|
|
|
BindingAnnotation::NONE => "NONE",
|
|
|
|
BindingAnnotation::REF => "REF",
|
|
|
|
BindingAnnotation::MUT => "MUT",
|
|
|
|
BindingAnnotation::REF_MUT => "REF_MUT",
|
|
|
|
};
|
|
|
|
kind!("Binding(BindingAnnotation::{ann}, _, {name}, {sub})");
|
2021-12-06 05:33:31 -06:00
|
|
|
self.ident(name);
|
|
|
|
sub.if_some(|p| self.pat(p));
|
|
|
|
},
|
|
|
|
PatKind::Struct(ref qpath, fields, ignore) => {
|
|
|
|
bind!(self, qpath, fields);
|
|
|
|
kind!("Struct(ref {qpath}, {fields}, {ignore})");
|
|
|
|
self.qpath(qpath);
|
|
|
|
self.slice(fields, |field| {
|
|
|
|
self.ident(field!(field.ident));
|
|
|
|
self.pat(field!(field.pat));
|
|
|
|
});
|
2018-11-27 14:14:15 -06:00
|
|
|
},
|
2021-04-08 10:50:13 -05:00
|
|
|
PatKind::Or(fields) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, fields);
|
|
|
|
kind!("Or({fields})");
|
|
|
|
self.slice(fields, |pat| self.pat(pat));
|
|
|
|
},
|
|
|
|
PatKind::TupleStruct(ref qpath, fields, skip_pos) => {
|
|
|
|
bind!(self, qpath, fields);
|
|
|
|
kind!("TupleStruct(ref {qpath}, {fields}, {skip_pos:?})");
|
|
|
|
self.qpath(qpath);
|
|
|
|
self.slice(fields, |pat| self.pat(pat));
|
|
|
|
},
|
|
|
|
PatKind::Path(ref qpath) => {
|
|
|
|
bind!(self, qpath);
|
|
|
|
kind!("Path(ref {qpath})");
|
|
|
|
self.qpath(qpath);
|
2018-11-27 14:14:15 -06:00
|
|
|
},
|
2021-04-08 10:50:13 -05:00
|
|
|
PatKind::Tuple(fields, skip_pos) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, fields);
|
|
|
|
kind!("Tuple({fields}, {skip_pos:?})");
|
|
|
|
self.slice(fields, |field| self.pat(field));
|
2018-11-27 14:14:15 -06:00
|
|
|
},
|
2021-04-08 10:50:13 -05:00
|
|
|
PatKind::Box(pat) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, pat);
|
|
|
|
kind!("Box({pat})");
|
|
|
|
self.pat(pat);
|
2018-05-11 12:05:34 -05:00
|
|
|
},
|
2021-04-08 10:50:13 -05:00
|
|
|
PatKind::Ref(pat, muta) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, pat);
|
|
|
|
kind!("Ref({pat}, Mutability::{muta:?})");
|
|
|
|
self.pat(pat);
|
2018-05-11 12:05:34 -05:00
|
|
|
},
|
2021-04-08 10:50:13 -05:00
|
|
|
PatKind::Lit(lit_expr) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, lit_expr);
|
|
|
|
kind!("Lit({lit_expr})");
|
|
|
|
self.expr(lit_expr);
|
|
|
|
},
|
|
|
|
PatKind::Range(start, end, end_kind) => {
|
|
|
|
opt_bind!(self, start, end);
|
|
|
|
kind!("Range({start}, {end}, RangeEnd::{end_kind:?})");
|
|
|
|
start.if_some(|e| self.expr(e));
|
|
|
|
end.if_some(|e| self.expr(e));
|
|
|
|
},
|
|
|
|
PatKind::Slice(start, middle, end) => {
|
|
|
|
bind!(self, start, end);
|
|
|
|
opt_bind!(self, middle);
|
|
|
|
kind!("Slice({start}, {middle}, {end})");
|
|
|
|
middle.if_some(|p| self.pat(p));
|
|
|
|
self.slice(start, |pat| self.pat(pat));
|
|
|
|
self.slice(end, |pat| self.pat(pat));
|
2018-11-27 14:14:15 -06:00
|
|
|
},
|
2018-05-11 12:05:34 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
fn stmt(&self, stmt: &Binding<&hir::Stmt<'_>>) {
|
2022-10-23 08:18:45 -05:00
|
|
|
let kind = |kind| chain!(self, "let StmtKind::{kind} = {stmt}.kind");
|
2021-12-06 05:33:31 -06:00
|
|
|
macro_rules! kind {
|
|
|
|
($($t:tt)*) => (kind(format_args!($($t)*)));
|
|
|
|
}
|
2018-05-11 12:05:34 -05:00
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
match stmt.value.kind {
|
|
|
|
StmtKind::Local(local) => {
|
|
|
|
bind!(self, local);
|
|
|
|
kind!("Local({local})");
|
|
|
|
self.option(field!(local.init), "init", |init| {
|
|
|
|
self.expr(init);
|
|
|
|
});
|
|
|
|
self.pat(field!(local.pat));
|
|
|
|
},
|
|
|
|
StmtKind::Item(_) => kind!("Item(item_id)"),
|
2021-04-08 10:50:13 -05:00
|
|
|
StmtKind::Expr(e) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, e);
|
|
|
|
kind!("Expr({e})");
|
|
|
|
self.expr(e);
|
2018-05-11 12:05:34 -05:00
|
|
|
},
|
2021-04-08 10:50:13 -05:00
|
|
|
StmtKind::Semi(e) => {
|
2021-12-06 05:33:31 -06:00
|
|
|
bind!(self, e);
|
|
|
|
kind!("Semi({e})");
|
|
|
|
self.expr(e);
|
2018-05-11 12:05:34 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|
|
|
|
|
2020-12-06 15:00:24 -06:00
|
|
|
fn has_attr(cx: &LateContext<'_>, hir_id: hir::HirId) -> bool {
|
|
|
|
let attrs = cx.tcx.hir().attrs(hir_id);
|
|
|
|
get_attr(cx.sess(), attrs, "author").count() > 0
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|
|
|
|
|
2021-12-06 05:33:31 -06:00
|
|
|
fn path_to_string(path: &QPath<'_>) -> String {
|
|
|
|
fn inner(s: &mut String, path: &QPath<'_>) {
|
|
|
|
match *path {
|
|
|
|
QPath::Resolved(_, path) => {
|
|
|
|
for (i, segment) in path.segments.iter().enumerate() {
|
|
|
|
if i > 0 {
|
|
|
|
*s += ", ";
|
|
|
|
}
|
|
|
|
write!(s, "{:?}", segment.ident.as_str()).unwrap();
|
2017-08-09 02:30:56 -05:00
|
|
|
}
|
2017-09-05 04:33:04 -05:00
|
|
|
},
|
2021-12-06 05:33:31 -06:00
|
|
|
QPath::TypeRelative(ty, segment) => match &ty.kind {
|
|
|
|
hir::TyKind::Path(inner_path) => {
|
|
|
|
inner(s, inner_path);
|
|
|
|
*s += ", ";
|
|
|
|
write!(s, "{:?}", segment.ident.as_str()).unwrap();
|
|
|
|
},
|
2022-10-06 02:44:38 -05:00
|
|
|
other => write!(s, "/* unimplemented: {other:?}*/").unwrap(),
|
2021-12-06 05:33:31 -06:00
|
|
|
},
|
|
|
|
QPath::LangItem(..) => panic!("path_to_string: called for lang item qpath"),
|
|
|
|
}
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|
2021-12-06 05:33:31 -06:00
|
|
|
let mut s = String::new();
|
|
|
|
inner(&mut s, path);
|
|
|
|
s
|
2017-07-03 08:24:52 -05:00
|
|
|
}
|