mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-28 20:16:58 +03:00
Auto merge of #138416 - Manishearth:rollup-fejor9p, r=Manishearth
Rollup of 12 pull requests Successful merges: - #134076 (Stabilize `std::io::ErrorKind::InvalidFilename`) - #137504 (Move methods from Map to TyCtxt, part 4.) - #138175 (Support rmeta inputs for --crate-type=bin --emit=obj) - #138259 (Disentangle `ForwardGenericParamBan` and `ConstParamTy` ribs) - #138280 (fix ICE in pretty-printing `global_asm!`) - #138318 (Rustdoc: remove a bunch of `@ts-expect-error` from main.js) - #138331 (Use `RUSTC_LINT_FLAGS` more) - #138357 (merge `TypeChecker` and `TypeVerifier`) - #138394 (remove unnecessary variant) - #138403 (Delegation: one more ICE fix for `MethodCall` generation) - #138407 (Delegation: reject C-variadics) - #138409 (Use sa_sigaction instead of sa_union.__su_sigaction for AIX) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
@@ -139,12 +139,12 @@ defined in the map. By matching on this, you can find out what sort of
|
||||
node the `HirId` referred to and also get a pointer to the data
|
||||
itself. Often, you know what sort of node `n` is – e.g. if you know
|
||||
that `n` must be some HIR expression, you can do
|
||||
[`tcx.hir().expect_expr(n)`][expect_expr], which will extract and return the
|
||||
[`tcx.hir_expect_expr(n)`][expect_expr], which will extract and return the
|
||||
[`&hir::Expr`][Expr], panicking if `n` is not in fact an expression.
|
||||
|
||||
[find]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.find
|
||||
[`Node`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.Node.html
|
||||
[expect_expr]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/hir/map/struct.Map.html#method.expect_expr
|
||||
[expect_expr]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.expect_expr
|
||||
[Expr]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.Expr.html
|
||||
|
||||
Finally, you can use the HIR map to find the parents of nodes, via
|
||||
|
||||
@@ -181,7 +181,7 @@ pub(crate) fn try_inline_glob(
|
||||
.filter_map(|child| child.res.opt_def_id())
|
||||
.filter(|def_id| !cx.tcx.is_doc_hidden(def_id))
|
||||
.collect();
|
||||
let attrs = cx.tcx.hir().attrs(import.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(import.hir_id());
|
||||
let mut items = build_module_items(
|
||||
cx,
|
||||
did,
|
||||
@@ -455,7 +455,7 @@ pub(crate) fn build_impl(
|
||||
}
|
||||
|
||||
let impl_item = match did.as_local() {
|
||||
Some(did) => match &tcx.hir().expect_item(did).kind {
|
||||
Some(did) => match &tcx.hir_expect_item(did).kind {
|
||||
hir::ItemKind::Impl(impl_) => Some(impl_),
|
||||
_ => panic!("`DefID` passed to `build_impl` is not an `impl"),
|
||||
},
|
||||
|
||||
@@ -112,7 +112,7 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
|
||||
items.extend(doc.inlined_foreigns.iter().flat_map(|((_, renamed), (res, local_import_id))| {
|
||||
let Some(def_id) = res.opt_def_id() else { return Vec::new() };
|
||||
let name = renamed.unwrap_or_else(|| cx.tcx.item_name(def_id));
|
||||
let import = cx.tcx.hir().expect_item(*local_import_id);
|
||||
let import = cx.tcx.hir_expect_item(*local_import_id);
|
||||
match import.kind {
|
||||
hir::ItemKind::Use(path, kind) => {
|
||||
let hir::UsePath { segments, span, .. } = *path;
|
||||
@@ -125,7 +125,7 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
|
||||
items.extend(doc.items.values().flat_map(|(item, renamed, _)| {
|
||||
// Now we actually lower the imports, skipping everything else.
|
||||
if let hir::ItemKind::Use(path, hir::UseKind::Glob) = item.kind {
|
||||
let name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id()));
|
||||
let name = renamed.unwrap_or_else(|| cx.tcx.hir_name(item.hir_id()));
|
||||
clean_use_statement(item, name, path, hir::UseKind::Glob, cx, &mut inserted)
|
||||
} else {
|
||||
// skip everything else
|
||||
@@ -986,7 +986,7 @@ fn clean_proc_macro<'tcx>(
|
||||
kind: MacroKind,
|
||||
cx: &mut DocContext<'tcx>,
|
||||
) -> ItemKind {
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(item.hir_id());
|
||||
if kind == MacroKind::Derive
|
||||
&& let Some(derive_name) =
|
||||
hir_attr_lists(attrs, sym::proc_macro_derive).find_map(|mi| mi.ident())
|
||||
@@ -1019,7 +1019,7 @@ fn clean_fn_or_proc_macro<'tcx>(
|
||||
name: &mut Symbol,
|
||||
cx: &mut DocContext<'tcx>,
|
||||
) -> ItemKind {
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(item.hir_id());
|
||||
let macro_kind = attrs.iter().find_map(|a| {
|
||||
if a.has_name(sym::proc_macro) {
|
||||
Some(MacroKind::Bang)
|
||||
@@ -1756,7 +1756,7 @@ fn maybe_expand_private_type_alias<'tcx>(
|
||||
let alias = if !cx.cache.effective_visibilities.is_exported(cx.tcx, def_id.to_def_id())
|
||||
&& !cx.current_type_aliases.contains_key(&def_id.to_def_id())
|
||||
{
|
||||
&cx.tcx.hir().expect_item(def_id).kind
|
||||
&cx.tcx.hir_expect_item(def_id).kind
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
@@ -2762,7 +2762,7 @@ fn clean_maybe_renamed_item<'tcx>(
|
||||
use hir::ItemKind;
|
||||
|
||||
let def_id = item.owner_id.to_def_id();
|
||||
let mut name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id()));
|
||||
let mut name = renamed.unwrap_or_else(|| cx.tcx.hir_name(item.hir_id()));
|
||||
cx.with_param_env(def_id, |cx| {
|
||||
let kind = match item.kind {
|
||||
ItemKind::Static(ty, mutability, body_id) => StaticItem(Static {
|
||||
@@ -2937,7 +2937,7 @@ fn clean_extern_crate<'tcx>(
|
||||
let cnum = cx.tcx.extern_mod_stmt_cnum(krate.owner_id.def_id).unwrap_or(LOCAL_CRATE);
|
||||
// this is the ID of the crate itself
|
||||
let crate_def_id = cnum.as_def_id();
|
||||
let attrs = cx.tcx.hir().attrs(krate.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(krate.hir_id());
|
||||
let ty_vis = cx.tcx.visibility(krate.owner_id);
|
||||
let please_inline = ty_vis.is_public()
|
||||
&& attrs.iter().any(|a| {
|
||||
@@ -3006,7 +3006,7 @@ fn clean_use_statement_inner<'tcx>(
|
||||
}
|
||||
|
||||
let visibility = cx.tcx.visibility(import.owner_id);
|
||||
let attrs = cx.tcx.hir().attrs(import.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(import.hir_id());
|
||||
let inline_attr = hir_attr_lists(attrs, sym::doc).get_word_attr(sym::inline);
|
||||
let pub_underscore = visibility.is_public() && name == kw::Underscore;
|
||||
let current_mod = cx.tcx.parent_module_from_def_id(import.owner_id.def_id);
|
||||
|
||||
@@ -216,7 +216,7 @@ pub(crate) fn run(dcx: DiagCtxtHandle<'_>, input: Input, options: RustdocOptions
|
||||
|
||||
let collector = rustc_interface::create_and_enter_global_ctxt(compiler, krate, |tcx| {
|
||||
let crate_name = tcx.crate_name(LOCAL_CRATE).to_string();
|
||||
let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID);
|
||||
let crate_attrs = tcx.hir_attrs(CRATE_HIR_ID);
|
||||
let opts = scrape_test_config(crate_name, crate_attrs, args_path);
|
||||
let enable_per_target_ignores = options.enable_per_target_ignores;
|
||||
|
||||
|
||||
@@ -95,7 +95,7 @@ fn visit_testable<F: FnOnce(&mut Self)>(
|
||||
sp: Span,
|
||||
nested: F,
|
||||
) {
|
||||
let ast_attrs = self.tcx.hir().attrs(self.tcx.local_def_id_to_hir_id(def_id));
|
||||
let ast_attrs = self.tcx.hir_attrs(self.tcx.local_def_id_to_hir_id(def_id));
|
||||
if let Some(ref cfg) =
|
||||
extract_cfg_from_attrs(ast_attrs.iter(), self.tcx, &FxHashSet::default())
|
||||
&& !cfg.matches(&self.tcx.sess.psess, Some(self.tcx.features()))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Local js definitions:
|
||||
/* global addClass, getSettingValue, hasClass, searchState, updateLocalStorage */
|
||||
/* global addClass, getSettingValue, hasClass, updateLocalStorage */
|
||||
/* global onEachLazy, removeClass, getVar */
|
||||
|
||||
"use strict";
|
||||
@@ -121,12 +121,9 @@ function getNakedUrl() {
|
||||
* doesn't have a parent node.
|
||||
*
|
||||
* @param {HTMLElement} newNode
|
||||
* @param {HTMLElement} referenceNode
|
||||
* @param {HTMLElement & { parentNode: HTMLElement }} referenceNode
|
||||
*/
|
||||
function insertAfter(newNode, referenceNode) {
|
||||
// You're not allowed to pass an element with no parent.
|
||||
// I dunno how to make TS's typechecker see that.
|
||||
// @ts-expect-error
|
||||
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
|
||||
}
|
||||
|
||||
@@ -305,11 +302,10 @@ function preLoadCss(cssUrl) {
|
||||
window.searchState.timeout = null;
|
||||
}
|
||||
},
|
||||
// @ts-expect-error
|
||||
isDisplayed: () => {
|
||||
const outputElement = window.searchState.outputElement();
|
||||
return outputElement &&
|
||||
outputElement.parentElement &&
|
||||
return !!outputElement &&
|
||||
!!outputElement.parentElement &&
|
||||
outputElement.parentElement.id === ALTERNATIVE_DISPLAY_ID;
|
||||
},
|
||||
// Sets the focus on the search bar at the top of the page
|
||||
@@ -325,8 +321,6 @@ function preLoadCss(cssUrl) {
|
||||
search = window.searchState.outputElement();
|
||||
}
|
||||
switchDisplayedElement(search);
|
||||
// @ts-expect-error
|
||||
window.searchState.mouseMovedAfterSearch = false;
|
||||
document.title = window.searchState.title;
|
||||
},
|
||||
removeQueryParameters: () => {
|
||||
@@ -503,34 +497,40 @@ function preLoadCss(cssUrl) {
|
||||
handleHashes(ev);
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
/**
|
||||
* @param {HTMLElement|null} elem
|
||||
*/
|
||||
function openParentDetails(elem) {
|
||||
while (elem) {
|
||||
if (elem.tagName === "DETAILS") {
|
||||
// @ts-expect-error
|
||||
elem.open = true;
|
||||
}
|
||||
elem = elem.parentNode;
|
||||
elem = elem.parentElement;
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
/**
|
||||
* @param {string} id
|
||||
*/
|
||||
function expandSection(id) {
|
||||
openParentDetails(document.getElementById(id));
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
/**
|
||||
* @param {KeyboardEvent} ev
|
||||
*/
|
||||
function handleEscape(ev) {
|
||||
// @ts-expect-error
|
||||
searchState.clearInputTimeout();
|
||||
// @ts-expect-error
|
||||
searchState.hideResults();
|
||||
window.searchState.clearInputTimeout();
|
||||
window.searchState.hideResults();
|
||||
ev.preventDefault();
|
||||
// @ts-expect-error
|
||||
searchState.defocus();
|
||||
window.searchState.defocus();
|
||||
window.hideAllModals(true); // true = reset focus for tooltips
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
/**
|
||||
* @param {KeyboardEvent} ev
|
||||
*/
|
||||
function handleShortcut(ev) {
|
||||
// Don't interfere with browser shortcuts
|
||||
const disableShortcuts = getSettingValue("disable-shortcuts") === "true";
|
||||
@@ -538,8 +538,8 @@ function preLoadCss(cssUrl) {
|
||||
return;
|
||||
}
|
||||
|
||||
// @ts-expect-error
|
||||
if (document.activeElement.tagName === "INPUT" &&
|
||||
if (document.activeElement &&
|
||||
document.activeElement.tagName === "INPUT" &&
|
||||
// @ts-expect-error
|
||||
document.activeElement.type !== "checkbox" &&
|
||||
// @ts-expect-error
|
||||
@@ -559,8 +559,7 @@ function preLoadCss(cssUrl) {
|
||||
case "S":
|
||||
case "/":
|
||||
ev.preventDefault();
|
||||
// @ts-expect-error
|
||||
searchState.focus();
|
||||
window.searchState.focus();
|
||||
break;
|
||||
|
||||
case "+":
|
||||
@@ -586,7 +585,6 @@ function preLoadCss(cssUrl) {
|
||||
document.addEventListener("keydown", handleShortcut);
|
||||
|
||||
function addSidebarItems() {
|
||||
// @ts-expect-error
|
||||
if (!window.SIDEBAR_ITEMS) {
|
||||
return;
|
||||
}
|
||||
@@ -675,7 +673,6 @@ function preLoadCss(cssUrl) {
|
||||
}
|
||||
|
||||
// <https://github.com/search?q=repo%3Arust-lang%2Frust+[RUSTDOCIMPL]+trait.impl&type=code>
|
||||
// @ts-expect-error
|
||||
window.register_implementors = imp => {
|
||||
const implementors = document.getElementById("implementors-list");
|
||||
const synthetic_implementors = document.getElementById("synthetic-implementors-list");
|
||||
@@ -767,9 +764,7 @@ function preLoadCss(cssUrl) {
|
||||
}
|
||||
}
|
||||
};
|
||||
// @ts-expect-error
|
||||
if (window.pending_implementors) {
|
||||
// @ts-expect-error
|
||||
window.register_implementors(window.pending_implementors);
|
||||
}
|
||||
|
||||
@@ -802,16 +797,14 @@ function preLoadCss(cssUrl) {
|
||||
*
|
||||
* - After processing all of the impls, it sorts the sidebar items by name.
|
||||
*
|
||||
* @param {{[cratename: string]: Array<Array<string|0>>}} imp
|
||||
* @param {rustdoc.TypeImpls} imp
|
||||
*/
|
||||
// @ts-expect-error
|
||||
window.register_type_impls = imp => {
|
||||
// @ts-expect-error
|
||||
if (!imp || !imp[window.currentCrate]) {
|
||||
return;
|
||||
}
|
||||
// @ts-expect-error
|
||||
window.pending_type_impls = null;
|
||||
window.pending_type_impls = undefined;
|
||||
const idMap = new Map();
|
||||
|
||||
let implementations = document.getElementById("implementations-list");
|
||||
@@ -997,9 +990,7 @@ function preLoadCss(cssUrl) {
|
||||
list.replaceChildren(...newChildren);
|
||||
}
|
||||
};
|
||||
// @ts-expect-error
|
||||
if (window.pending_type_impls) {
|
||||
// @ts-expect-error
|
||||
window.register_type_impls(window.pending_type_impls);
|
||||
}
|
||||
|
||||
@@ -1695,8 +1686,7 @@ function preLoadCss(cssUrl) {
|
||||
addSidebarCrates();
|
||||
onHashChange(null);
|
||||
window.addEventListener("hashchange", onHashChange);
|
||||
// @ts-expect-error
|
||||
searchState.setup();
|
||||
window.searchState.setup();
|
||||
}());
|
||||
|
||||
// Hide, show, and resize the sidebar
|
||||
|
||||
+25
@@ -7,6 +7,8 @@ declare global {
|
||||
interface Window {
|
||||
/** Make the current theme easy to find */
|
||||
currentTheme: HTMLLinkElement|null;
|
||||
/** Generated in `render/context.rs` */
|
||||
SIDEBAR_ITEMS?: { [key: string]: string[] };
|
||||
/** Used by the popover tooltip code. */
|
||||
RUSTDOC_TOOLTIP_HOVER_MS: number;
|
||||
/** Used by the popover tooltip code. */
|
||||
@@ -42,6 +44,17 @@ declare global {
|
||||
* Set up event listeners for a scraped source example.
|
||||
*/
|
||||
updateScrapedExample?: function(HTMLElement, HTMLElement),
|
||||
/**
|
||||
* register trait implementors, called by code generated in
|
||||
* `write_shared.rs`
|
||||
*/
|
||||
register_implementors?: function(rustdoc.Implementors): void,
|
||||
/**
|
||||
* fallback in case `register_implementors` isn't defined yet.
|
||||
*/
|
||||
pending_implementors?: rustdoc.Implementors,
|
||||
register_type_impls?: function(rustdoc.TypeImpls): void,
|
||||
pending_type_impls?: rustdoc.TypeImpls,
|
||||
}
|
||||
interface HTMLElement {
|
||||
/** Used by the popover tooltip code. */
|
||||
@@ -413,4 +426,16 @@ declare namespace rustdoc {
|
||||
};
|
||||
|
||||
type VlqData = VlqData[] | number;
|
||||
|
||||
/**
|
||||
* Maps from crate names to trait implementation data.
|
||||
* Provied by generated `trait.impl` files.
|
||||
*/
|
||||
type Implementors = {
|
||||
[key: string]: Array<[string, number, Array<string>]>
|
||||
}
|
||||
|
||||
type TypeImpls = {
|
||||
[cratename: string]: Array<Array<string|0>>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ pub(crate) fn visit(mut self) -> Module<'tcx> {
|
||||
&& self.cx.tcx.has_attr(def_id, sym::macro_export)
|
||||
&& inserted.insert(def_id)
|
||||
{
|
||||
let item = self.cx.tcx.hir().expect_item(local_def_id);
|
||||
let item = self.cx.tcx.hir_expect_item(local_def_id);
|
||||
top_level_module
|
||||
.items
|
||||
.insert((local_def_id, Some(item.ident.name)), (item, None, None));
|
||||
@@ -153,8 +153,7 @@ pub(crate) fn visit(mut self) -> Module<'tcx> {
|
||||
self.cx.cache.hidden_cfg = self
|
||||
.cx
|
||||
.tcx
|
||||
.hir()
|
||||
.attrs(CRATE_HIR_ID)
|
||||
.hir_attrs(CRATE_HIR_ID)
|
||||
.iter()
|
||||
.filter(|attr| attr.has_name(sym::doc))
|
||||
.flat_map(|attr| attr.meta_item_list().into_iter().flatten())
|
||||
@@ -245,7 +244,7 @@ fn maybe_inline_local(
|
||||
};
|
||||
|
||||
let document_hidden = self.cx.render_options.document_hidden;
|
||||
let use_attrs = tcx.hir().attrs(tcx.local_def_id_to_hir_id(def_id));
|
||||
let use_attrs = tcx.hir_attrs(tcx.local_def_id_to_hir_id(def_id));
|
||||
// Don't inline `doc(hidden)` imports so they can be stripped at a later stage.
|
||||
let is_no_inline = hir_attr_lists(use_attrs, sym::doc).has_word(sym::no_inline)
|
||||
|| (document_hidden && hir_attr_lists(use_attrs, sym::doc).has_word(sym::hidden));
|
||||
@@ -449,7 +448,7 @@ fn visit_item_inner(
|
||||
continue;
|
||||
}
|
||||
|
||||
let attrs = tcx.hir().attrs(tcx.local_def_id_to_hir_id(item.owner_id.def_id));
|
||||
let attrs = tcx.hir_attrs(tcx.local_def_id_to_hir_id(item.owner_id.def_id));
|
||||
|
||||
// If there was a private module in the current path then don't bother inlining
|
||||
// anything as it will probably be stripped anyway.
|
||||
|
||||
@@ -465,7 +465,7 @@ pub fn new(conf: &'static Conf) -> Self {
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for Attributes {
|
||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(item.hir_id());
|
||||
if is_relevant_item(cx, item) {
|
||||
inline_always::check(cx, item.span, item.ident.name, attrs);
|
||||
}
|
||||
@@ -474,13 +474,13 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
|
||||
if is_relevant_impl(cx, item) {
|
||||
inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id()));
|
||||
inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir_attrs(item.hir_id()));
|
||||
}
|
||||
}
|
||||
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
|
||||
if is_relevant_trait(cx, item) {
|
||||
inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id()));
|
||||
inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir_attrs(item.hir_id()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ fn is_zst<'tcx>(cx: &LateContext<'tcx>, field: &FieldDef, args: ty::GenericArgsR
|
||||
}
|
||||
|
||||
fn has_c_repr_attr(cx: &LateContext<'_>, hir_id: HirId) -> bool {
|
||||
let attrs = cx.tcx.hir().attrs(hir_id);
|
||||
let attrs = cx.tcx.hir_attrs(hir_id);
|
||||
|
||||
find_attr!(attrs, AttributeKind::Repr(r) if r.iter().any(|(x, _)| *x == ReprAttr::ReprC))
|
||||
}
|
||||
|
||||
@@ -197,9 +197,9 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
|
||||
&& let Body { value: func_expr, .. } = cx.tcx.hir_body(*b)
|
||||
&& let &ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()
|
||||
&& let attrs = cx.tcx.hir().attrs(item.hir_id())
|
||||
&& let attrs = cx.tcx.hir_attrs(item.hir_id())
|
||||
&& !attrs.iter().any(|attr| attr.doc_str().is_some())
|
||||
&& cx.tcx.hir().attrs(impl_item_hir).is_empty()
|
||||
&& cx.tcx.hir_attrs(impl_item_hir).is_empty()
|
||||
{
|
||||
if adt_def.is_struct() {
|
||||
check_struct(cx, item, self_ty, func_expr, adt_def, args, cx.tcx.typeck_body(*b));
|
||||
|
||||
@@ -384,7 +384,7 @@ fn has_unsafe<'tcx>(cx: &LateContext<'tcx>, item: &'tcx Item<'_>) -> bool {
|
||||
.tcx
|
||||
.inherent_impls(def.did())
|
||||
.iter()
|
||||
.map(|imp_did| cx.tcx.hir().expect_item(imp_did.expect_local()))
|
||||
.map(|imp_did| cx.tcx.hir_expect_item(imp_did.expect_local()))
|
||||
.any(|imp| has_unsafe(cx, imp))
|
||||
{
|
||||
span_lint_hir_and_then(
|
||||
|
||||
@@ -25,7 +25,7 @@ pub fn check(
|
||||
&& cx
|
||||
.tcx
|
||||
.hir_parent_iter(owner_id.into())
|
||||
.any(|(id, _node)| is_doc_hidden(cx.tcx.hir().attrs(id)))
|
||||
.any(|(id, _node)| is_doc_hidden(cx.tcx.hir_attrs(id)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -163,7 +163,6 @@ fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {
|
||||
|
||||
fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) {
|
||||
if cmt.place.projections.is_empty() {
|
||||
let map = &self.cx.tcx.hir();
|
||||
if is_argument(self.cx.tcx, cmt.hir_id) {
|
||||
// Skip closure arguments
|
||||
let parent_id = self.cx.tcx.parent_hir_id(cmt.hir_id);
|
||||
@@ -174,7 +173,7 @@ fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) {
|
||||
// skip if there is a `self` parameter binding to a type
|
||||
// that contains `Self` (i.e.: `self: Box<Self>`), see #4804
|
||||
if let Some(trait_self_ty) = self.trait_self_ty {
|
||||
if map.name(cmt.hir_id) == kw::SelfLower && cmt.place.ty().contains(trait_self_ty) {
|
||||
if self.cx.tcx.hir_name(cmt.hir_id) == kw::SelfLower && cmt.place.ty().contains(trait_self_ty) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
|
||||
_ => return,
|
||||
};
|
||||
if cx.effective_visibilities.is_exported(item.owner_id.def_id)
|
||||
&& let attrs = cx.tcx.hir().attrs(item.hir_id())
|
||||
&& let attrs = cx.tcx.hir_attrs(item.hir_id())
|
||||
&& !attrs.iter().any(|a| a.has_name(sym::non_exhaustive))
|
||||
&& fields.iter().all(|f| cx.tcx.visibility(f.def_id).is_public())
|
||||
{
|
||||
|
||||
@@ -209,9 +209,8 @@ fn check_format_arg_self(&self, arg: &Expr<'_>) {
|
||||
// Handle dereference of &self -> self that is equivalent (i.e. via *self in fmt() impl)
|
||||
// Since the argument to fmt is itself a reference: &self
|
||||
let reference = peel_ref_operators(self.cx, arg);
|
||||
let map = self.cx.tcx.hir();
|
||||
// Is the reference self?
|
||||
if path_to_local(reference).map(|x| map.name(x)) == Some(kw::SelfLower) {
|
||||
if path_to_local(reference).map(|x| self.cx.tcx.hir_name(x)) == Some(kw::SelfLower) {
|
||||
let FormatTraitNames { name, .. } = self.format_trait_impl;
|
||||
span_lint(
|
||||
self.cx,
|
||||
|
||||
@@ -43,8 +43,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
|
||||
let sm = cx.sess().source_map();
|
||||
let mut span = cx
|
||||
.tcx
|
||||
.hir()
|
||||
.attrs(item.hir_id())
|
||||
.hir_attrs(item.hir_id())
|
||||
.iter()
|
||||
.filter(|i| i.is_doc_comment())
|
||||
.fold(item.span.shrink_to_lo(), |span, attr| span.to(attr.span()));
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
use super::{DOUBLE_MUST_USE, MUST_USE_CANDIDATE, MUST_USE_UNIT};
|
||||
|
||||
pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(item.hir_id());
|
||||
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
|
||||
if let hir::ItemKind::Fn {
|
||||
ref sig,
|
||||
@@ -51,7 +51,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
|
||||
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind {
|
||||
let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
|
||||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(item.hir_id());
|
||||
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
|
||||
if let Some(attr) = attr {
|
||||
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr, attrs, sig);
|
||||
@@ -74,7 +74,7 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr
|
||||
let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
|
||||
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
|
||||
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(item.hir_id());
|
||||
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
|
||||
if let Some(attr) = attr {
|
||||
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr, attrs, sig);
|
||||
|
||||
@@ -182,7 +182,7 @@ fn suggestion<'tcx>(
|
||||
}
|
||||
|
||||
fn field_with_attrs_span(tcx: TyCtxt<'_>, field: &hir::ExprField<'_>) -> Span {
|
||||
if let Some(attr) = tcx.hir().attrs(field.hir_id).first() {
|
||||
if let Some(attr) = tcx.hir_attrs(field.hir_id).first() {
|
||||
field.span.with_lo(attr.span().lo())
|
||||
} else {
|
||||
field.span
|
||||
|
||||
@@ -34,8 +34,7 @@ fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>
|
||||
if let TraitItemKind::Fn(_, TraitFn::Required(_)) = item.kind
|
||||
&& let Some(attr) = cx
|
||||
.tcx
|
||||
.hir()
|
||||
.attrs(item.hir_id())
|
||||
.hir_attrs(item.hir_id())
|
||||
.iter()
|
||||
.find(|a| a.has_name(sym::inline))
|
||||
{
|
||||
|
||||
@@ -98,7 +98,7 @@ fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
|
||||
if cx.sess().opts.edition >= Edition::Edition2018
|
||||
&& let hir::ItemKind::Use(path, _kind) = &item.kind
|
||||
&& let hir_id = item.hir_id()
|
||||
&& let attrs = cx.tcx.hir().attrs(hir_id)
|
||||
&& let attrs = cx.tcx.hir_attrs(hir_id)
|
||||
&& let Some(mac_attr) = attrs.iter().find(|attr| attr.has_name(sym::macro_use))
|
||||
&& let Some(id) = path.res.iter().find_map(|res| match res {
|
||||
Res::Def(DefKind::Mod, id) => Some(id),
|
||||
|
||||
@@ -89,11 +89,11 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
match item.kind {
|
||||
ItemKind::Enum(def, _) if def.variants.len() > 1 => {
|
||||
let iter = def.variants.iter().filter_map(|v| {
|
||||
(matches!(v.data, VariantData::Unit(_, _)) && is_doc_hidden(cx.tcx.hir().attrs(v.hir_id)))
|
||||
(matches!(v.data, VariantData::Unit(_, _)) && is_doc_hidden(cx.tcx.hir_attrs(v.hir_id)))
|
||||
.then_some((v.def_id, v.span))
|
||||
});
|
||||
if let Ok((id, span)) = iter.exactly_one()
|
||||
&& !attr::contains_name(cx.tcx.hir().attrs(item.hir_id()), sym::non_exhaustive)
|
||||
&& !attr::contains_name(cx.tcx.hir_attrs(item.hir_id()), sym::non_exhaustive)
|
||||
{
|
||||
self.potential_enums.push((item.owner_id.def_id, id, item.span, span));
|
||||
}
|
||||
@@ -114,7 +114,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
"this seems like a manual implementation of the non-exhaustive pattern",
|
||||
|diag| {
|
||||
if let Some(non_exhaustive) =
|
||||
attr::find_by_name(cx.tcx.hir().attrs(item.hir_id()), sym::non_exhaustive)
|
||||
attr::find_by_name(cx.tcx.hir_attrs(item.hir_id()), sym::non_exhaustive)
|
||||
{
|
||||
diag.span_note(non_exhaustive.span(), "the struct is already non-exhaustive");
|
||||
} else {
|
||||
|
||||
@@ -42,7 +42,7 @@ pub(super) fn check_match<'tcx>(
|
||||
cx,
|
||||
scrutinee,
|
||||
arms.iter()
|
||||
.map(|arm| (cx.tcx.hir().attrs(arm.hir_id), Some(arm.pat), arm.body, arm.guard)),
|
||||
.map(|arm| (cx.tcx.hir_attrs(arm.hir_id), Some(arm.pat), arm.body, arm.guard)),
|
||||
e,
|
||||
false,
|
||||
)
|
||||
|
||||
@@ -75,7 +75,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, arms: &'tcx [Arm<'_>]) {
|
||||
HirIdMapEntry::Occupied(entry) => return *entry.get() == b_id,
|
||||
}
|
||||
// the names technically don't have to match; this makes the lint more conservative
|
||||
&& cx.tcx.hir().name(a_id) == cx.tcx.hir().name(b_id)
|
||||
&& cx.tcx.hir_name(a_id) == cx.tcx.hir_name(b_id)
|
||||
&& cx.typeck_results().expr_ty(a) == cx.typeck_results().expr_ty(b)
|
||||
&& pat_contains_local(lhs.pat, a_id)
|
||||
&& pat_contains_local(rhs.pat, b_id)
|
||||
|
||||
@@ -41,7 +41,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &'_ Expr<'_>, receiver: &Expr<'_
|
||||
fn is_under_cfg(cx: &LateContext<'_>, id: HirId) -> bool {
|
||||
cx.tcx
|
||||
.hir_parent_id_iter(id)
|
||||
.any(|id| cx.tcx.hir().attrs(id).iter().any(|attr| attr.has_name(sym::cfg)))
|
||||
.any(|id| cx.tcx.hir_attrs(id).iter().any(|attr| attr.has_name(sym::cfg)))
|
||||
}
|
||||
|
||||
/// Similar to [`clippy_utils::expr_or_init`], but does not go up the chain if the initialization
|
||||
|
||||
@@ -4731,7 +4731,7 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::Impl
|
||||
}
|
||||
let name = impl_item.ident.name.as_str();
|
||||
let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id;
|
||||
let item = cx.tcx.hir().expect_item(parent);
|
||||
let item = cx.tcx.hir_expect_item(parent);
|
||||
let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
||||
|
||||
let implements_trait = matches!(item.kind, hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }));
|
||||
|
||||
@@ -182,7 +182,7 @@ fn check_attributes_post(&mut self, _: &LateContext<'tcx>, _: &'tcx [Attribute])
|
||||
}
|
||||
|
||||
fn check_crate(&mut self, cx: &LateContext<'tcx>) {
|
||||
let attrs = cx.tcx.hir().attrs(hir::CRATE_HIR_ID);
|
||||
let attrs = cx.tcx.hir_attrs(hir::CRATE_HIR_ID);
|
||||
self.check_missing_docs_attrs(cx, CRATE_DEF_ID, attrs, cx.tcx.def_span(CRATE_DEF_ID), "the", "crate");
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
|
||||
|
||||
let (article, desc) = cx.tcx.article_and_description(it.owner_id.to_def_id());
|
||||
|
||||
let attrs = cx.tcx.hir().attrs(it.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(it.hir_id());
|
||||
if !is_from_proc_macro(cx, it) {
|
||||
self.check_missing_docs_attrs(cx, it.owner_id.def_id, attrs, it.span, article, desc);
|
||||
}
|
||||
@@ -234,7 +234,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
|
||||
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx hir::TraitItem<'_>) {
|
||||
let (article, desc) = cx.tcx.article_and_description(trait_item.owner_id.to_def_id());
|
||||
|
||||
let attrs = cx.tcx.hir().attrs(trait_item.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(trait_item.hir_id());
|
||||
if !is_from_proc_macro(cx, trait_item) {
|
||||
self.check_missing_docs_attrs(cx, trait_item.owner_id.def_id, attrs, trait_item.span, article, desc);
|
||||
}
|
||||
@@ -252,7 +252,7 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::Impl
|
||||
}
|
||||
|
||||
let (article, desc) = cx.tcx.article_and_description(impl_item.owner_id.to_def_id());
|
||||
let attrs = cx.tcx.hir().attrs(impl_item.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(impl_item.hir_id());
|
||||
if !is_from_proc_macro(cx, impl_item) {
|
||||
self.check_missing_docs_attrs(cx, impl_item.owner_id.def_id, attrs, impl_item.span, article, desc);
|
||||
}
|
||||
@@ -261,7 +261,7 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::Impl
|
||||
|
||||
fn check_field_def(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::FieldDef<'_>) {
|
||||
if !sf.is_positional() {
|
||||
let attrs = cx.tcx.hir().attrs(sf.hir_id);
|
||||
let attrs = cx.tcx.hir_attrs(sf.hir_id);
|
||||
if !is_from_proc_macro(cx, sf) {
|
||||
self.check_missing_docs_attrs(cx, sf.def_id, attrs, sf.span, "a", "struct field");
|
||||
}
|
||||
@@ -270,7 +270,7 @@ fn check_field_def(&mut self, cx: &LateContext<'tcx>, sf: &'tcx hir::FieldDef<'_
|
||||
}
|
||||
|
||||
fn check_variant(&mut self, cx: &LateContext<'tcx>, v: &'tcx hir::Variant<'_>) {
|
||||
let attrs = cx.tcx.hir().attrs(v.hir_id);
|
||||
let attrs = cx.tcx.hir_attrs(v.hir_id);
|
||||
if !is_from_proc_macro(cx, v) {
|
||||
self.check_missing_docs_attrs(cx, v.def_id, attrs, v.span, "a", "variant");
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
|
||||
match it.kind {
|
||||
hir::ItemKind::Fn { .. } => {
|
||||
let desc = "a function";
|
||||
let attrs = cx.tcx.hir().attrs(it.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(it.hir_id());
|
||||
check_missing_inline_attrs(cx, attrs, it.span, desc);
|
||||
},
|
||||
hir::ItemKind::Trait(ref _is_auto, ref _unsafe, _generics, _bounds, trait_items) => {
|
||||
@@ -114,7 +114,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
|
||||
// an impl is not provided
|
||||
let desc = "a default trait method";
|
||||
let item = cx.tcx.hir_trait_item(tit.id);
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(item.hir_id());
|
||||
check_missing_inline_attrs(cx, attrs, item.span, desc);
|
||||
}
|
||||
},
|
||||
@@ -168,7 +168,7 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx hir::Impl
|
||||
}
|
||||
}
|
||||
|
||||
let attrs = cx.tcx.hir().attrs(impl_item.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(impl_item.hir_id());
|
||||
check_missing_inline_attrs(cx, attrs, impl_item.span, desc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
self.cx,
|
||||
MIXED_READ_WRITE_IN_EXPRESSION,
|
||||
expr.span,
|
||||
format!("unsequenced read of `{}`", self.cx.tcx.hir().name(self.var)),
|
||||
format!("unsequenced read of `{}`", self.cx.tcx.hir_name(self.var)),
|
||||
|diag| {
|
||||
diag.span_note(
|
||||
self.write_expr.span,
|
||||
|
||||
@@ -65,7 +65,7 @@ fn check_stmt<'tcx>(&mut self, cx: &LateContext<'tcx>, stmt: &Stmt<'tcx>) {
|
||||
stmt.span,
|
||||
"this `if` branch is empty",
|
||||
"you can remove it",
|
||||
if cond.can_have_side_effects() || !cx.tcx.hir().attrs(stmt.hir_id).is_empty() {
|
||||
if cond.can_have_side_effects() || !cx.tcx.hir_attrs(stmt.hir_id).is_empty() {
|
||||
// `{ foo }` or `{ foo } && bar` placed into a statement position would be
|
||||
// interpreted as a block statement, force it to be an expression
|
||||
if cond_snippet.starts_with('{') {
|
||||
|
||||
@@ -261,7 +261,7 @@ fn check<'tcx>(
|
||||
binding_id: HirId,
|
||||
) -> Option<()> {
|
||||
let usage = first_usage(cx, binding_id, local_stmt.hir_id, block)?;
|
||||
let binding_name = cx.tcx.hir().opt_name(binding_id)?;
|
||||
let binding_name = cx.tcx.hir_opt_name(binding_id)?;
|
||||
let let_snippet = local_snippet_without_semicolon(cx, local)?;
|
||||
|
||||
match usage.expr.kind {
|
||||
|
||||
@@ -147,7 +147,7 @@ fn check_fn(
|
||||
// We don't check unsafe functions.
|
||||
return;
|
||||
}
|
||||
let attrs = cx.tcx.hir().attrs(hir_id);
|
||||
let attrs = cx.tcx.hir_attrs(hir_id);
|
||||
if header.abi != ExternAbi::Rust || requires_exact_signature(attrs) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ fn check_fn(
|
||||
|
||||
match kind {
|
||||
FnKind::ItemFn(.., header) => {
|
||||
let attrs = cx.tcx.hir().attrs(hir_id);
|
||||
let attrs = cx.tcx.hir_attrs(hir_id);
|
||||
if header.abi != ExternAbi::Rust || requires_exact_signature(attrs) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
|
||||
if let ItemKind::Fn { sig: fn_sig, .. } = &item.kind
|
||||
&& !item.span.from_expansion()
|
||||
{
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(item.hir_id());
|
||||
let mut app = Applicability::MaybeIncorrect;
|
||||
let fn_snippet = snippet_with_applicability(cx, fn_sig.span.with_hi(item.ident.span.lo()), "..", &mut app);
|
||||
for attr in attrs {
|
||||
|
||||
@@ -351,7 +351,7 @@ fn check_trait_item(&mut self, cx: &LateContext<'tcx>, trait_item: &'tcx TraitIt
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'_>) {
|
||||
if let ImplItemKind::Const(_, body_id) = &impl_item.kind {
|
||||
let item_def_id = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id;
|
||||
let item = cx.tcx.hir().expect_item(item_def_id);
|
||||
let item = cx.tcx.hir_expect_item(item_def_id);
|
||||
|
||||
match &item.kind {
|
||||
ItemKind::Impl(Impl {
|
||||
|
||||
@@ -181,7 +181,7 @@ fn in_impl<'tcx>(
|
||||
) -> Option<(&'tcx rustc_hir::Ty<'tcx>, &'tcx rustc_hir::Ty<'tcx>)> {
|
||||
if let Some(block) = get_enclosing_block(cx, e.hir_id)
|
||||
&& let Some(impl_def_id) = cx.tcx.impl_of_method(block.hir_id.owner.to_def_id())
|
||||
&& let item = cx.tcx.hir().expect_item(impl_def_id.expect_local())
|
||||
&& let item = cx.tcx.hir_expect_item(impl_def_id.expect_local())
|
||||
&& let ItemKind::Impl(item) = &item.kind
|
||||
&& let Some(of_trait) = &item.of_trait
|
||||
&& let Some(seg) = of_trait.path.segments.last()
|
||||
@@ -200,7 +200,7 @@ fn in_impl<'tcx>(
|
||||
fn are_equal(cx: &LateContext<'_>, middle_ty: Ty<'_>, hir_ty: &rustc_hir::Ty<'_>) -> bool {
|
||||
if let ty::Adt(adt_def, _) = middle_ty.kind()
|
||||
&& let Some(local_did) = adt_def.did().as_local()
|
||||
&& let item = cx.tcx.hir().expect_item(local_did)
|
||||
&& let item = cx.tcx.hir_expect_item(local_did)
|
||||
&& let middle_ty_id = item.owner_id.to_def_id()
|
||||
&& let TyKind::Path(QPath::Resolved(_, path)) = hir_ty.kind
|
||||
&& let Res::Def(_, hir_ty_id) = path.res
|
||||
|
||||
@@ -280,7 +280,7 @@ fn check_fn(
|
||||
if header.abi != ExternAbi::Rust {
|
||||
return;
|
||||
}
|
||||
let attrs = cx.tcx.hir().attrs(hir_id);
|
||||
let attrs = cx.tcx.hir_attrs(hir_id);
|
||||
for a in attrs {
|
||||
if let Some(meta_items) = a.meta_item_list() {
|
||||
if a.has_name(sym::proc_macro_derive)
|
||||
|
||||
@@ -74,7 +74,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||
// Only pertains to fields that start with an underscore, and are public.
|
||||
if field.ident.as_str().starts_with('_') && is_visible(field)
|
||||
// We ignore fields that have `#[doc(hidden)]`.
|
||||
&& !is_doc_hidden(cx.tcx.hir().attrs(field.hir_id))
|
||||
&& !is_doc_hidden(cx.tcx.hir_attrs(field.hir_id))
|
||||
// We ignore fields that are `PhantomData`.
|
||||
&& !is_path_lang_item(cx, field.ty, LangItem::PhantomData)
|
||||
{
|
||||
|
||||
@@ -93,7 +93,7 @@ fn check_block(&mut self, cx: &LateContext<'tcx>, block: &hir::Block<'tcx>) {
|
||||
},
|
||||
),
|
||||
VecInitKind::WithExprCapacity(hir_id) => {
|
||||
let e = cx.tcx.hir().expect_expr(hir_id);
|
||||
let e = cx.tcx.hir_expect_expr(hir_id);
|
||||
span_lint_hir_and_then(
|
||||
cx,
|
||||
READ_ZERO_BYTE_VEC,
|
||||
|
||||
@@ -74,7 +74,7 @@ fn check_method(cx: &LateContext<'_>, decl: &FnDecl<'_>, fn_def: LocalDefId, spa
|
||||
// We only show this warning for public exported methods.
|
||||
&& cx.effective_visibilities.is_exported(fn_def)
|
||||
// We don't want to emit this lint if the `#[must_use]` attribute is already there.
|
||||
&& !cx.tcx.hir().attrs(owner_id.into()).iter().any(|attr| attr.has_name(sym::must_use))
|
||||
&& !cx.tcx.hir_attrs(owner_id.into()).iter().any(|attr| attr.has_name(sym::must_use))
|
||||
&& cx.tcx.visibility(fn_def.to_def_id()).is_public()
|
||||
&& let ret_ty = return_ty(cx, owner_id)
|
||||
&& let self_arg = nth_arg(cx, owner_id, 0)
|
||||
|
||||
@@ -231,7 +231,7 @@ fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'_>) {
|
||||
&& let Some(stmt) = block.stmts.iter().last()
|
||||
&& let StmtKind::Let(local) = &stmt.kind
|
||||
&& local.ty.is_none()
|
||||
&& cx.tcx.hir().attrs(local.hir_id).is_empty()
|
||||
&& cx.tcx.hir_attrs(local.hir_id).is_empty()
|
||||
&& let Some(initexpr) = &local.init
|
||||
&& let PatKind::Binding(_, local_id, _, _) = local.pat.kind
|
||||
&& path_to_local_id(retexpr, local_id)
|
||||
@@ -401,7 +401,7 @@ fn check_final_expr<'tcx>(
|
||||
// This allows the addition of attributes, like `#[allow]` (See: clippy#9361)
|
||||
// `#[expect(clippy::needless_return)]` needs to be handled separately to
|
||||
// actually fulfill the expectation (clippy::#12998)
|
||||
match cx.tcx.hir().attrs(expr.hir_id) {
|
||||
match cx.tcx.hir_attrs(expr.hir_id) {
|
||||
[] => {},
|
||||
[attr] => {
|
||||
if matches!(Level::from_attr(attr), Some(Level::Expect(_)))
|
||||
|
||||
@@ -52,7 +52,7 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<
|
||||
}
|
||||
|
||||
let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id;
|
||||
let item = cx.tcx.hir().expect_item(parent);
|
||||
let item = cx.tcx.hir_expect_item(parent);
|
||||
let self_ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
|
||||
let ret_ty = return_ty(cx, impl_item.owner_id);
|
||||
|
||||
|
||||
@@ -429,8 +429,7 @@ fn block_has_safety_comment(cx: &LateContext<'_>, span: Span) -> bool {
|
||||
fn include_attrs_in_span(cx: &LateContext<'_>, hir_id: HirId, span: Span) -> Span {
|
||||
span.to(cx
|
||||
.tcx
|
||||
.hir()
|
||||
.attrs(hir_id)
|
||||
.hir_attrs(hir_id)
|
||||
.iter()
|
||||
.fold(span, |acc, attr| acc.to(attr.span())))
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &ImplItem<'_>)
|
||||
return;
|
||||
}
|
||||
let parent = cx.tcx.hir_get_parent_item(impl_item.hir_id()).def_id;
|
||||
let parent_item = cx.tcx.hir().expect_item(parent);
|
||||
let parent_item = cx.tcx.hir_expect_item(parent);
|
||||
let assoc_item = cx.tcx.associated_item(impl_item.owner_id);
|
||||
let contains_todo = |cx, body: &'_ Body<'_>| -> bool {
|
||||
clippy_utils::visitors::for_each_expr_without_closures(body.value, |e| {
|
||||
|
||||
@@ -318,7 +318,7 @@ fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
|
||||
{
|
||||
if call_to_unwrap == unwrappable.safe_to_unwrap {
|
||||
let is_entire_condition = unwrappable.is_entire_condition;
|
||||
let unwrappable_variable_name = self.cx.tcx.hir().name(unwrappable.local_id);
|
||||
let unwrappable_variable_name = self.cx.tcx.hir_name(unwrappable.local_id);
|
||||
let suggested_pattern = if call_to_unwrap {
|
||||
unwrappable.kind.success_variant_pattern()
|
||||
} else {
|
||||
|
||||
@@ -793,7 +793,7 @@ macro_rules! kind {
|
||||
}
|
||||
|
||||
fn has_attr(cx: &LateContext<'_>, hir_id: HirId) -> bool {
|
||||
let attrs = cx.tcx.hir().attrs(hir_id);
|
||||
let attrs = cx.tcx.hir_attrs(hir_id);
|
||||
get_attr(cx.sess(), attrs, "author").count() > 0
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,6 @@ fn check_impl_item(&mut self, cx: &LateContext<'_>, item: &hir::ImplItem<'_>) {
|
||||
}
|
||||
|
||||
fn has_attr(cx: &LateContext<'_>, hir_id: hir::HirId) -> bool {
|
||||
let attrs = cx.tcx.hir().attrs(hir_id);
|
||||
let attrs = cx.tcx.hir_attrs(hir_id);
|
||||
get_attr(cx.sess(), attrs, "dump").count() > 0
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ fn check_invalid_clippy_version_attribute(cx: &LateContext<'_>, item: &'_ Item<'
|
||||
/// This function extracts the version value of a `clippy::version` attribute if the given value has
|
||||
/// one
|
||||
pub(super) fn extract_clippy_version_value(cx: &LateContext<'_>, item: &'_ Item<'_>) -> Option<Symbol> {
|
||||
let attrs = cx.tcx.hir().attrs(item.hir_id());
|
||||
let attrs = cx.tcx.hir_attrs(item.hir_id());
|
||||
attrs.iter().find_map(|attr| {
|
||||
if let hir::Attribute::Unparsed(attr_kind) = &attr
|
||||
// Identify attribute
|
||||
|
||||
@@ -2036,15 +2036,14 @@ pub fn has_attr(attrs: &[hir::Attribute], symbol: Symbol) -> bool {
|
||||
}
|
||||
|
||||
pub fn has_repr_attr(cx: &LateContext<'_>, hir_id: HirId) -> bool {
|
||||
find_attr!(cx.tcx.hir().attrs(hir_id), AttributeKind::Repr(..))
|
||||
find_attr!(cx.tcx.hir_attrs(hir_id), AttributeKind::Repr(..))
|
||||
}
|
||||
|
||||
pub fn any_parent_has_attr(tcx: TyCtxt<'_>, node: HirId, symbol: Symbol) -> bool {
|
||||
let map = &tcx.hir();
|
||||
let mut prev_enclosing_node = None;
|
||||
let mut enclosing_node = node;
|
||||
while Some(enclosing_node) != prev_enclosing_node {
|
||||
if has_attr(map.attrs(enclosing_node), symbol) {
|
||||
if has_attr(tcx.hir_attrs(enclosing_node), symbol) {
|
||||
return true;
|
||||
}
|
||||
prev_enclosing_node = Some(enclosing_node);
|
||||
@@ -2061,7 +2060,7 @@ pub fn in_automatically_derived(tcx: TyCtxt<'_>, id: HirId) -> bool {
|
||||
.filter(|(_, node)| matches!(node, OwnerNode::Item(item) if matches!(item.kind, ItemKind::Impl(_))))
|
||||
.any(|(id, _)| {
|
||||
has_attr(
|
||||
tcx.hir().attrs(tcx.local_def_id_to_hir_id(id.def_id)),
|
||||
tcx.hir_attrs(tcx.local_def_id_to_hir_id(id.def_id)),
|
||||
sym::automatically_derived,
|
||||
)
|
||||
})
|
||||
@@ -2344,16 +2343,14 @@ pub fn std_or_core(cx: &LateContext<'_>) -> Option<&'static str> {
|
||||
|
||||
pub fn is_no_std_crate(cx: &LateContext<'_>) -> bool {
|
||||
cx.tcx
|
||||
.hir()
|
||||
.attrs(hir::CRATE_HIR_ID)
|
||||
.hir_attrs(hir::CRATE_HIR_ID)
|
||||
.iter()
|
||||
.any(|attr| attr.name_or_empty() == sym::no_std)
|
||||
}
|
||||
|
||||
pub fn is_no_core_crate(cx: &LateContext<'_>) -> bool {
|
||||
cx.tcx
|
||||
.hir()
|
||||
.attrs(hir::CRATE_HIR_ID)
|
||||
.hir_attrs(hir::CRATE_HIR_ID)
|
||||
.iter()
|
||||
.any(|attr| attr.name_or_empty() == sym::no_core)
|
||||
}
|
||||
@@ -2643,8 +2640,7 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId, f: impl Fn(&[Sym
|
||||
// We could also check for the type name `test::TestDescAndFn`
|
||||
if let Res::Def(DefKind::Struct, _) = path.res {
|
||||
let has_test_marker = tcx
|
||||
.hir()
|
||||
.attrs(item.hir_id())
|
||||
.hir_attrs(item.hir_id())
|
||||
.iter()
|
||||
.any(|a| a.has_name(sym::rustc_test_marker));
|
||||
if has_test_marker {
|
||||
@@ -2688,7 +2684,7 @@ pub fn is_in_test_function(tcx: TyCtxt<'_>, id: HirId) -> bool {
|
||||
/// This only checks directly applied attributes, to see if a node is inside a `#[cfg(test)]` parent
|
||||
/// use [`is_in_cfg_test`]
|
||||
pub fn is_cfg_test(tcx: TyCtxt<'_>, id: HirId) -> bool {
|
||||
tcx.hir().attrs(id).iter().any(|attr| {
|
||||
tcx.hir_attrs(id).iter().any(|attr| {
|
||||
if attr.has_name(sym::cfg)
|
||||
&& let Some(items) = attr.meta_item_list()
|
||||
&& let [item] = &*items
|
||||
@@ -2713,12 +2709,10 @@ pub fn is_in_test(tcx: TyCtxt<'_>, hir_id: HirId) -> bool {
|
||||
|
||||
/// Checks if the item of any of its parents has `#[cfg(...)]` attribute applied.
|
||||
pub fn inherits_cfg(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||
let hir = tcx.hir();
|
||||
|
||||
tcx.has_attr(def_id, sym::cfg)
|
||||
|| tcx
|
||||
.hir_parent_iter(tcx.local_def_id_to_hir_id(def_id))
|
||||
.flat_map(|(parent_id, _)| hir.attrs(parent_id))
|
||||
.flat_map(|(parent_id, _)| tcx.hir_attrs(parent_id))
|
||||
.any(|attr| attr.has_name(sym::cfg))
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ pub fn current(self, cx: &LateContext<'_>) -> Option<RustcVersion> {
|
||||
let start = cx.last_node_with_lint_attrs;
|
||||
if let Some(msrv_attr) = once(start)
|
||||
.chain(cx.tcx.hir_parent_id_iter(start))
|
||||
.find_map(|id| parse_attrs(cx.tcx.sess, cx.tcx.hir().attrs(id)))
|
||||
.find_map(|id| parse_attrs(cx.tcx.sess, cx.tcx.hir_attrs(id)))
|
||||
{
|
||||
return Some(msrv_attr);
|
||||
}
|
||||
|
||||
@@ -847,7 +847,7 @@ fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {
|
||||
let mut start_snip = snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability);
|
||||
|
||||
// identifier referring to the variable currently triggered (i.e.: `fp`)
|
||||
let ident_str = map.name(id).to_string();
|
||||
let ident_str = self.cx.tcx.hir_name(id).to_string();
|
||||
// full identifier that includes projection (i.e.: `fp.field`)
|
||||
let ident_str_with_proj = snippet(self.cx, span, "..").to_string();
|
||||
|
||||
@@ -876,7 +876,7 @@ fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {
|
||||
// item is used in a call
|
||||
// i.e.: `Call`: `|x| please(x)` or `MethodCall`: `|x| [1, 2, 3].contains(x)`
|
||||
ExprKind::Call(_, call_args) | ExprKind::MethodCall(_, _, call_args, _) => {
|
||||
let expr = self.cx.tcx.hir().expect_expr(cmt.hir_id);
|
||||
let expr = self.cx.tcx.hir_expect_expr(cmt.hir_id);
|
||||
let arg_ty_kind = self.cx.typeck_results().expr_ty(expr).kind();
|
||||
|
||||
if matches!(arg_ty_kind, ty::Ref(_, _, Mutability::Not)) {
|
||||
|
||||
Reference in New Issue
Block a user