From e6089d6b9324bc71929bd7b2f5f2ab1eb2eae9b9 Mon Sep 17 00:00:00 2001 From: Yuval Dolev Date: Tue, 23 Nov 2021 19:52:42 +0200 Subject: [PATCH 1/3] Remove clean::Function::header and calculate it on-demand based on the DefId --- src/librustdoc/clean/inline.rs | 10 +-- src/librustdoc/clean/mod.rs | 82 +++--------------------- src/librustdoc/clean/types.rs | 1 - src/librustdoc/html/render/mod.rs | 28 ++++---- src/librustdoc/html/render/print_item.rs | 23 +++++-- src/librustdoc/json/conversions.rs | 66 +++++++++++++++---- src/librustdoc/lib.rs | 1 - 7 files changed, 92 insertions(+), 119 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index d4bf93bb40931..6786f9088f5c0 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -223,20 +223,12 @@ crate fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean::Tra fn build_external_function(cx: &mut DocContext<'_>, did: DefId) -> clean::Function { let sig = cx.tcx.fn_sig(did); - - let constness = - if cx.tcx.is_const_fn_raw(did) { hir::Constness::Const } else { hir::Constness::NotConst }; - let asyncness = cx.tcx.asyncness(did); let predicates = cx.tcx.predicates_of(did); let (generics, decl) = clean::enter_impl_trait(cx, |cx| { // NOTE: generics need to be cleaned before the decl! ((cx.tcx.generics_of(did), predicates).clean(cx), (did, sig).clean(cx)) }); - clean::Function { - decl, - generics, - header: hir::FnHeader { unsafety: sig.unsafety(), abi: sig.abi(), constness, asyncness }, - } + clean::Function { decl, generics } } fn build_enum(cx: &mut DocContext<'_>, did: DefId) -> clean::Enum { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index de1293cd96dfc..62d07101787d2 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -11,7 +11,6 @@ crate mod utils; use rustc_ast as ast; use rustc_attr as attr; -use rustc_const_eval::const_eval::is_unstable_const_fn; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def::{CtorKind, DefKind, Res}; @@ -25,8 +24,6 @@ use rustc_middle::{bug, span_bug}; use rustc_span::hygiene::{AstPass, MacroKind}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{self, ExpnKind}; -use rustc_target::spec::abi::Abi; -use rustc_typeck::check::intrinsic::intrinsic_operation_unsafety; use rustc_typeck::hir_ty_to_ty; use std::assert_matches::assert_matches; @@ -747,14 +744,7 @@ fn clean_fn_or_proc_macro( ProcMacroItem(ProcMacro { kind, helpers }) } None => { - let mut func = (sig, generics, body_id).clean(cx); - let def_id = item.def_id.to_def_id(); - func.header.constness = - if cx.tcx.is_const_fn(def_id) && is_unstable_const_fn(cx.tcx, def_id).is_none() { - hir::Constness::Const - } else { - hir::Constness::NotConst - }; + let func = (sig, generics, body_id).clean(cx); FunctionItem(func) } } @@ -769,7 +759,7 @@ impl<'a> Clean for (&'a hir::FnSig<'a>, &'a hir::Generics<'a>, hir::Bo let decl = clean_fn_decl_with_args(cx, self.0.decl, args); (generics, decl) }); - Function { decl, generics, header: self.0.header } + Function { decl, generics } } } @@ -885,12 +875,7 @@ impl Clean for hir::TraitItem<'_> { AssocConstItem(ty.clean(cx), default.map(|e| print_const_expr(cx.tcx, e))) } hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => { - let mut m = (sig, &self.generics, body).clean(cx); - if m.header.constness == hir::Constness::Const - && is_unstable_const_fn(cx.tcx, local_did).is_some() - { - m.header.constness = hir::Constness::NotConst; - } + let m = (sig, &self.generics, body).clean(cx); MethodItem(m, None) } hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(names)) => { @@ -901,12 +886,7 @@ impl Clean for hir::TraitItem<'_> { let decl = clean_fn_decl_with_args(cx, sig.decl, args); (generics, decl) }); - let mut t = Function { header: sig.header, decl, generics }; - if t.header.constness == hir::Constness::Const - && is_unstable_const_fn(cx.tcx, local_did).is_some() - { - t.header.constness = hir::Constness::NotConst; - } + let t = Function { decl, generics }; TyMethodItem(t) } hir::TraitItemKind::Type(bounds, ref default) => { @@ -932,12 +912,7 @@ impl Clean for hir::ImplItem<'_> { AssocConstItem(ty.clean(cx), Some(print_const_expr(cx.tcx, expr))) } hir::ImplItemKind::Fn(ref sig, body) => { - let mut m = (sig, &self.generics, body).clean(cx); - if m.header.constness == hir::Constness::Const - && is_unstable_const_fn(cx.tcx, local_did).is_some() - { - m.header.constness = hir::Constness::NotConst; - } + let m = (sig, &self.generics, body).clean(cx); MethodItem(m, Some(self.defaultness)) } hir::ImplItemKind::TyAlias(ref hir_ty) => { @@ -1017,40 +992,13 @@ impl Clean for ty::AssocItem { ty::TraitContainer(_) => self.defaultness.has_value(), }; if provided { - let constness = if tcx.is_const_fn_raw(self.def_id) { - hir::Constness::Const - } else { - hir::Constness::NotConst - }; - let asyncness = tcx.asyncness(self.def_id); let defaultness = match self.container { ty::ImplContainer(_) => Some(self.defaultness), ty::TraitContainer(_) => None, }; - MethodItem( - Function { - generics, - decl, - header: hir::FnHeader { - unsafety: sig.unsafety(), - abi: sig.abi(), - constness, - asyncness, - }, - }, - defaultness, - ) + MethodItem(Function { generics, decl }, defaultness) } else { - TyMethodItem(Function { - generics, - decl, - header: hir::FnHeader { - unsafety: sig.unsafety(), - abi: sig.abi(), - constness: hir::Constness::NotConst, - asyncness: hir::IsAsync::NotAsync, - }, - }) + TyMethodItem(Function { generics, decl }) } } ty::AssocKind::Type => { @@ -2020,7 +1968,6 @@ impl Clean for (&hir::ForeignItem<'_>, Option) { cx.with_param_env(def_id, |cx| { let kind = match item.kind { hir::ForeignItemKind::Fn(decl, names, ref generics) => { - let abi = cx.tcx.hir().get_foreign_abi(item.hir_id()); let (generics, decl) = enter_impl_trait(cx, |cx| { // NOTE: generics must be cleaned before args let generics = generics.clean(cx); @@ -2028,20 +1975,7 @@ impl Clean for (&hir::ForeignItem<'_>, Option) { let decl = clean_fn_decl_with_args(cx, decl, args); (generics, decl) }); - ForeignFunctionItem(Function { - decl, - generics, - header: hir::FnHeader { - unsafety: if abi == Abi::RustIntrinsic { - intrinsic_operation_unsafety(item.ident.name) - } else { - hir::Unsafety::Unsafe - }, - abi, - constness: hir::Constness::NotConst, - asyncness: hir::IsAsync::NotAsync, - }, - }) + ForeignFunctionItem(Function { decl, generics }) } hir::ForeignItemKind::Static(ref ty, mutability) => { ForeignStaticItem(Static { type_: ty.clean(cx), mutability, expr: None }) diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index d28f3ce87785b..113269db1fa78 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -1303,7 +1303,6 @@ crate struct Generics { crate struct Function { crate decl: FnDecl, crate generics: Generics, - crate header: hir::FnHeader, } #[derive(Clone, PartialEq, Eq, Debug, Hash)] diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 24baca285c6ff..c6fe85a6c4576 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -873,14 +873,21 @@ fn render_assoc_item( fn method( w: &mut Buffer, meth: &clean::Item, - header: hir::FnHeader, g: &clean::Generics, d: &clean::FnDecl, link: AssocItemLink<'_>, parent: ItemType, cx: &Context<'_>, ) { + let tcx = cx.tcx(); let name = meth.name.as_ref().unwrap(); + let did = meth.def_id.expect_def_id(); + let sig = tcx.fn_sig(did); + let meth_constness = + if tcx.is_const_fn_raw(did) { hir::Constness::Const } else { hir::Constness::NotConst }; + let meth_asyncness = tcx.asyncness(did); + let meth_unsafety = sig.unsafety(); + let href = match link { AssocItemLink::Anchor(Some(ref id)) => Some(format!("#{}", id)), AssocItemLink::Anchor(None) => Some(format!("#{}.{}", meth.type_(), name)), @@ -901,12 +908,11 @@ fn render_assoc_item( } }; let vis = meth.visibility.print_with_space(meth.def_id, cx).to_string(); - let constness = - print_constness_with_space(&header.constness, meth.const_stability(cx.tcx())); - let asyncness = header.asyncness.print_with_space(); - let unsafety = header.unsafety.print_with_space(); + let constness = print_constness_with_space(&meth_constness, meth.const_stability(tcx)); + let asyncness = meth_asyncness.print_with_space(); + let unsafety = meth_unsafety.print_with_space(); let defaultness = print_default_space(meth.is_default()); - let abi = print_abi_with_space(header.abi).to_string(); + let abi = print_abi_with_space(sig.abi()).to_string(); // NOTE: `{:#}` does not print HTML formatting, `{}` does. So `g.print` can't be reused between the length calculation and `write!`. let generics_len = format!("{:#}", g.print(cx)).len(); @@ -945,19 +951,15 @@ fn render_assoc_item( href = href.map(|href| format!("href=\"{}\"", href)).unwrap_or_else(|| "".to_string()), name = name, generics = g.print(cx), - decl = d.full_print(header_len, indent, header.asyncness, cx), + decl = d.full_print(header_len, indent, meth_asyncness, cx), notable_traits = notable_traits_decl(d, cx), where_clause = print_where_clause(g, cx, indent, end_newline), ) } match *item.kind { clean::StrippedItem(..) => {} - clean::TyMethodItem(ref m) => { - method(w, item, m.header, &m.generics, &m.decl, link, parent, cx) - } - clean::MethodItem(ref m, _) => { - method(w, item, m.header, &m.generics, &m.decl, link, parent, cx) - } + clean::TyMethodItem(ref m) => method(w, item, &m.generics, &m.decl, link, parent, cx), + clean::MethodItem(ref m, _) => method(w, item, &m.generics, &m.decl, link, parent, cx), clean::AssocConstItem(ref ty, ref default) => assoc_const( w, item, diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 049d17a4b477a..b4cccbab50205 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -377,8 +377,9 @@ fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[cl } let unsafety_flag = match *myitem.kind { - clean::FunctionItem(ref func) | clean::ForeignFunctionItem(ref func) - if func.header.unsafety == hir::Unsafety::Unsafe => + clean::FunctionItem(_) | clean::ForeignFunctionItem(_) + if cx.tcx().fn_sig(myitem.def_id.expect_def_id()).unsafety() + == hir::Unsafety::Unsafe => { "" } @@ -465,11 +466,19 @@ fn extra_info_tags(item: &clean::Item, parent: &clean::Item, tcx: TyCtxt<'_>) -> } fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean::Function) { + let tcx = cx.tcx(); + let did = it.def_id.expect_def_id(); + let sig = tcx.fn_sig(did); + let it_constness = + if tcx.is_const_fn_raw(did) { hir::Constness::Const } else { hir::Constness::NotConst }; + let it_asyncness = tcx.asyncness(did); + let it_unsafety = sig.unsafety(); + let vis = it.visibility.print_with_space(it.def_id, cx).to_string(); - let constness = print_constness_with_space(&f.header.constness, it.const_stability(cx.tcx())); - let asyncness = f.header.asyncness.print_with_space(); - let unsafety = f.header.unsafety.print_with_space(); - let abi = print_abi_with_space(f.header.abi).to_string(); + let constness = print_constness_with_space(&it_constness, it.const_stability(tcx)); + let asyncness = it_asyncness.print_with_space(); + let unsafety = it_unsafety.print_with_space(); + let abi = print_abi_with_space(sig.abi()).to_string(); let name = it.name.as_ref().unwrap(); let generics_len = format!("{:#}", f.generics.print(cx)).len(); @@ -498,7 +507,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean:: name = name, generics = f.generics.print(cx), where_clause = print_where_clause(&f.generics, cx, 0, true), - decl = f.decl.full_print(header_len, 0, f.header.asyncness, cx), + decl = f.decl.full_print(header_len, 0, it_asyncness, cx), notable_traits = notable_traits_decl(&f.decl, cx), ); }); diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index a46518ef489aa..0532e8ce3a0c5 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -203,12 +203,18 @@ fn from_clean_item(item: clean::Item, tcx: TyCtxt<'_>) -> ItemEnum { StructFieldItem(f) => ItemEnum::StructField(f.into_tcx(tcx)), EnumItem(e) => ItemEnum::Enum(e.into_tcx(tcx)), VariantItem(v) => ItemEnum::Variant(v.into_tcx(tcx)), - FunctionItem(f) => ItemEnum::Function(f.into_tcx(tcx)), - ForeignFunctionItem(f) => ItemEnum::Function(f.into_tcx(tcx)), + FunctionItem(f) => ItemEnum::Function(from_function(f, item.def_id.expect_def_id(), tcx)), + ForeignFunctionItem(f) => { + ItemEnum::Function(from_function(f, item.def_id.expect_def_id(), tcx)) + } TraitItem(t) => ItemEnum::Trait(t.into_tcx(tcx)), TraitAliasItem(t) => ItemEnum::TraitAlias(t.into_tcx(tcx)), - MethodItem(m, _) => ItemEnum::Method(from_function_method(m, true, tcx)), - TyMethodItem(m) => ItemEnum::Method(from_function_method(m, false, tcx)), + MethodItem(m, _) => { + ItemEnum::Method(from_function_method(m, item.def_id.expect_def_id(), true, tcx)) + } + TyMethodItem(m) => { + ItemEnum::Method(from_function_method(m, item.def_id.expect_def_id(), false, tcx)) + } ImplItem(i) => ItemEnum::Impl(i.into_tcx(tcx)), StaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)), ForeignStaticItem(s) => ItemEnum::Static(s.into_tcx(tcx)), @@ -287,18 +293,39 @@ crate fn from_fn_header(header: &rustc_hir::FnHeader) -> HashSet { v } -impl FromWithTcx for Function { - fn from_tcx(function: clean::Function, tcx: TyCtxt<'_>) -> Self { - let clean::Function { decl, generics, header } = function; - Function { - decl: decl.into_tcx(tcx), - generics: generics.into_tcx(tcx), - header: from_fn_header(&header), - abi: header.abi.to_string(), - } +crate fn from_function(function: clean::Function, did: DefId, tcx: TyCtxt<'_>) -> Function { + let clean::Function { decl, generics } = function; + let sig = tcx.fn_sig(did); + let constness = if tcx.is_const_fn_raw(did) { + rustc_hir::Constness::Const + } else { + rustc_hir::Constness::NotConst + }; + let asyncness = tcx.asyncness(did); + let header = + rustc_hir::FnHeader { unsafety: sig.unsafety(), abi: sig.abi(), constness, asyncness }; + + Function { + decl: decl.into_tcx(tcx), + generics: generics.into_tcx(tcx), + header: from_fn_header(&header), + abi: header.abi.to_string(), } } +// impl FromWithTcx for Function { +// fn from_tcx(function: clean::Function, tcx: TyCtxt<'_>) -> Self { +// let clean::Function { decl, generics } = function; +// let header = hir::FnHeader { unsafety: sig.unsafety(), abi: sig.abi(), constness, asyncness } +// Function { +// decl: decl.into_tcx(tcx), +// generics: generics.into_tcx(tcx), +// header: from_fn_header(&header), +// abi: header.abi.to_string(), +// } +// } +// } + impl FromWithTcx for Generics { fn from_tcx(generics: clean::Generics, tcx: TyCtxt<'_>) -> Self { Generics { @@ -535,10 +562,21 @@ impl FromWithTcx for Impl { crate fn from_function_method( function: clean::Function, + did: DefId, has_body: bool, tcx: TyCtxt<'_>, ) -> Method { - let clean::Function { header, decl, generics } = function; + let clean::Function { decl, generics } = function; + let sig = tcx.fn_sig(did); + let constness = if tcx.is_const_fn_raw(did) { + rustc_hir::Constness::Const + } else { + rustc_hir::Constness::NotConst + }; + let asyncness = tcx.asyncness(did); + let header = + rustc_hir::FnHeader { unsafety: sig.unsafety(), abi: sig.abi(), constness, asyncness }; + Method { decl: decl.into_tcx(tcx), generics: generics.into_tcx(tcx), diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index b6311abb5c3e8..fd6a997b57304 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -35,7 +35,6 @@ extern crate rustc_ast; extern crate rustc_ast_lowering; extern crate rustc_ast_pretty; extern crate rustc_attr; -extern crate rustc_const_eval; extern crate rustc_data_structures; extern crate rustc_driver; extern crate rustc_errors; From b6b0b46a4cdc33c9579909c5160be71e1ace7c87 Mon Sep 17 00:00:00 2001 From: Yuval Dolev Date: Fri, 26 Nov 2021 16:04:33 +0200 Subject: [PATCH 2/3] Support Required trait functions and ForeignItem functions from fn_kind --- compiler/rustc_hir/src/hir.rs | 8 +++++--- compiler/rustc_hir/src/intravisit.rs | 6 +++++- compiler/rustc_lint/src/nonstandard_style.rs | 2 +- compiler/rustc_passes/src/naked_functions.rs | 6 +++--- compiler/rustc_resolve/src/late/lifetimes.rs | 7 ++++--- src/librustdoc/json/conversions.rs | 13 ------------- 6 files changed, 18 insertions(+), 24 deletions(-) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index c67d3df3dedd8..bf6be0f480214 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3273,9 +3273,7 @@ impl<'hir> Node<'hir> { _ => None, }, Node::TraitItem(ti) => match ti.kind { - TraitItemKind::Fn(ref sig, TraitFn::Provided(_)) => { - Some(FnKind::Method(ti.ident, sig, None)) - } + TraitItemKind::Fn(ref sig, _) => Some(FnKind::Method(ti.ident, sig, None)), _ => None, }, Node::ImplItem(ii) => match ii.kind { @@ -3286,6 +3284,10 @@ impl<'hir> Node<'hir> { ExprKind::Closure(..) => Some(FnKind::Closure), _ => None, }, + Node::ForeignItem(fi) => match fi.kind { + ForeignItemKind::Fn(..) => Some(FnKind::ForeignFn(fi.ident)), + _ => None, + }, _ => None, } } diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index cff543760f42a..4f8a1979d2e59 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -107,6 +107,9 @@ pub enum FnKind<'a> { /// `|x, y| {}` Closure, + + /// `extern "C" { pub fn foo(); }` + ForeignFn(Ident), } impl<'a> FnKind<'a> { @@ -115,6 +118,7 @@ impl<'a> FnKind<'a> { FnKind::ItemFn(_, _, ref header, _) => Some(header), FnKind::Method(_, ref sig, _) => Some(&sig.header), FnKind::Closure => None, + FnKind::ForeignFn(_) => None, } } @@ -979,7 +983,7 @@ pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V, function_kind: FnKind<' FnKind::ItemFn(_, generics, ..) => { visitor.visit_generics(generics); } - FnKind::Method(..) | FnKind::Closure => {} + FnKind::Method(..) | FnKind::Closure | FnKind::ForeignFn(_) => {} } } diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index bcddc4f3d7643..b49d773851d4c 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -413,7 +413,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase { } self.check_snake_case(cx, "function", ident); } - FnKind::Closure => (), + FnKind::Closure | FnKind::ForeignFn(_) => (), } } diff --git a/compiler/rustc_passes/src/naked_functions.rs b/compiler/rustc_passes/src/naked_functions.rs index d3ecd18a93c5a..54cd8441486a8 100644 --- a/compiler/rustc_passes/src/naked_functions.rs +++ b/compiler/rustc_passes/src/naked_functions.rs @@ -47,9 +47,9 @@ impl<'tcx> Visitor<'tcx> for CheckNakedFunctions<'tcx> { let fn_header; match fk { - FnKind::Closure => { - // Closures with a naked attribute are rejected during attribute - // check. Don't validate them any further. + FnKind::Closure | FnKind::ForeignFn(_) => { + // Closures and Foreign Functions with a naked attribute are + // rejected during attribute check. Don't validate them any further. return; } FnKind::ItemFn(ident, _, ref header, ..) => { diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs index 39e710cb77f3f..c267f6e655e90 100644 --- a/compiler/rustc_resolve/src/late/lifetimes.rs +++ b/compiler/rustc_resolve/src/late/lifetimes.rs @@ -692,15 +692,16 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { intravisit::FnKind::ItemFn(id, _, _, _) => id.as_str(), intravisit::FnKind::Method(id, _, _) => id.as_str(), intravisit::FnKind::Closure => Symbol::intern("closure").as_str(), + intravisit::FnKind::ForeignFn(id) => id.as_str(), }; let name: &str = &name; let span = span!(Level::DEBUG, "visit_fn", name); let _enter = span.enter(); match fk { // Any `Binders` are handled elsewhere - intravisit::FnKind::ItemFn(..) | intravisit::FnKind::Method(..) => { - intravisit::walk_fn(self, fk, fd, b, s, hir_id) - } + intravisit::FnKind::ItemFn(..) + | intravisit::FnKind::Method(..) + | intravisit::FnKind::ForeignFn(..) => intravisit::walk_fn(self, fk, fd, b, s, hir_id), intravisit::FnKind::Closure => { self.map.late_bound_vars.insert(hir_id, vec![]); let scope = Scope::Binder { diff --git a/src/librustdoc/json/conversions.rs b/src/librustdoc/json/conversions.rs index 0532e8ce3a0c5..f925c9d1790b2 100644 --- a/src/librustdoc/json/conversions.rs +++ b/src/librustdoc/json/conversions.rs @@ -313,19 +313,6 @@ crate fn from_function(function: clean::Function, did: DefId, tcx: TyCtxt<'_>) - } } -// impl FromWithTcx for Function { -// fn from_tcx(function: clean::Function, tcx: TyCtxt<'_>) -> Self { -// let clean::Function { decl, generics } = function; -// let header = hir::FnHeader { unsafety: sig.unsafety(), abi: sig.abi(), constness, asyncness } -// Function { -// decl: decl.into_tcx(tcx), -// generics: generics.into_tcx(tcx), -// header: from_fn_header(&header), -// abi: header.abi.to_string(), -// } -// } -// } - impl FromWithTcx for Generics { fn from_tcx(generics: clean::Generics, tcx: TyCtxt<'_>) -> Self { Generics { From 5da08fc03d6a20d8b5392e5b01a45002ea4e2488 Mon Sep 17 00:00:00 2001 From: Yuval Dolev Date: Fri, 26 Nov 2021 17:17:39 +0200 Subject: [PATCH 3/3] Update clippy to work with rustc_hir modifications --- src/tools/clippy/clippy_lints/src/cognitive_complexity.rs | 2 +- .../clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs | 1 + src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs | 1 + src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs | 1 + src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs | 1 + src/tools/clippy/clippy_lints/src/returns.rs | 1 + src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs | 1 + 7 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs b/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs index 1ccb8c5d880f4..5e75987b58169 100644 --- a/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs +++ b/src/tools/clippy/clippy_lints/src/cognitive_complexity.rs @@ -82,7 +82,7 @@ impl CognitiveComplexity { if rust_cc > self.limit.limit() { let fn_span = match kind { - FnKind::ItemFn(ident, _, _, _) | FnKind::Method(ident, _, _) => ident.span, + FnKind::ItemFn(ident, _, _, _) | FnKind::Method(ident, _, _) | FnKind::ForeignFn(ident) => ident.span, FnKind::Closure => { let header_span = body_span.with_hi(decl.output.span().lo()); let pos = snippet_opt(cx, header_span).and_then(|snip| { diff --git a/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index f83789bb2199e..0231a8c86d223 100644 --- a/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -20,6 +20,7 @@ pub(super) fn check_fn( intravisit::FnKind::ItemFn(_, _, hir::FnHeader { unsafety, .. }, _) => unsafety, intravisit::FnKind::Method(_, sig, _) => sig.header.unsafety, intravisit::FnKind::Closure => return, + intravisit::FnKind::ForeignFn(_) => return, }; check_raw_ptr(cx, unsafety, decl, body, cx.tcx.hir().local_def_id(hir_id)); diff --git a/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs b/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs index 5b2584d43a130..afacda2e592dc 100644 --- a/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs +++ b/src/tools/clippy/clippy_lints/src/missing_const_for_fn.rs @@ -128,6 +128,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingConstForFn { } }, FnKind::Closure => return, + FnKind::ForeignFn(_) => return, } let mir = cx.tcx.optimized_mir(def_id); diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index 352dc6f8bec3d..6b4c233774724 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -92,6 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue { }, FnKind::Method(..) => (), FnKind::Closure => return, + FnKind::ForeignFn(_) => return, } // Exclude non-inherent impls diff --git a/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs b/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs index 6229b9608b3cb..c365d831ce99b 100644 --- a/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs +++ b/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs @@ -266,6 +266,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue { }, FnKind::Method(..) => (), FnKind::Closure => return, + FnKind::ForeignFn(_) => return, } // Exclude non-inherent impls diff --git a/src/tools/clippy/clippy_lints/src/returns.rs b/src/tools/clippy/clippy_lints/src/returns.rs index ae85b7087e7b5..8b24fe0a0bd12 100644 --- a/src/tools/clippy/clippy_lints/src/returns.rs +++ b/src/tools/clippy/clippy_lints/src/returns.rs @@ -147,6 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for Return { check_block_return(cx, block); } }, + FnKind::ForeignFn(_) => (), } } } diff --git a/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs b/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs index c940cf077d11c..3a3933c727f05 100644 --- a/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs +++ b/src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs @@ -87,6 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps { } }, FnKind::Closure => return, + FnKind::ForeignFn(_) => return, } // Abort if the method is implementing a trait or of it a trait method.