Merge remote-tracking branch 'upstream/master' into rustup
This commit is contained in:
commit
d2b08432db
158 changed files with 3894 additions and 1449 deletions
|
|
@ -83,9 +83,9 @@ pub fn span_lint_and_help<T: LintContext>(
|
|||
cx.struct_span_lint(lint, span, msg.to_string(), |diag| {
|
||||
let help = help.to_string();
|
||||
if let Some(help_span) = help_span {
|
||||
diag.span_help(help_span, help.to_string());
|
||||
diag.span_help(help_span, help);
|
||||
} else {
|
||||
diag.help(help.to_string());
|
||||
diag.help(help);
|
||||
}
|
||||
docs_link(diag, lint);
|
||||
diag
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#![feature(lint_reasons)]
|
||||
#![feature(never_type)]
|
||||
#![feature(rustc_private)]
|
||||
#![feature(assert_matches)]
|
||||
#![recursion_limit = "512"]
|
||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||
#![allow(clippy::missing_errors_doc, clippy::missing_panics_doc, clippy::must_use_candidate)]
|
||||
|
|
@ -110,6 +111,7 @@ use rustc_span::source_map::SourceMap;
|
|||
use rustc_span::symbol::{kw, Ident, Symbol};
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_target::abi::Integer;
|
||||
use visitors::Visitable;
|
||||
|
||||
use crate::consts::{constant, miri_to_const, Constant};
|
||||
use crate::higher::Range;
|
||||
|
|
@ -1286,7 +1288,7 @@ pub fn contains_name<'tcx>(name: Symbol, expr: &'tcx Expr<'_>, cx: &LateContext<
|
|||
}
|
||||
|
||||
/// Returns `true` if `expr` contains a return expression
|
||||
pub fn contains_return(expr: &hir::Expr<'_>) -> bool {
|
||||
pub fn contains_return<'tcx>(expr: impl Visitable<'tcx>) -> bool {
|
||||
for_each_expr(expr, |e| {
|
||||
if matches!(e.kind, hir::ExprKind::Ret(..)) {
|
||||
ControlFlow::Break(())
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ pub const IDENT: [&str; 3] = ["rustc_span", "symbol", "Ident"];
|
|||
pub const IDENT_AS_STR: [&str; 4] = ["rustc_span", "symbol", "Ident", "as_str"];
|
||||
pub const INSERT_STR: [&str; 4] = ["alloc", "string", "String", "insert_str"];
|
||||
pub const ITER_EMPTY: [&str; 5] = ["core", "iter", "sources", "empty", "Empty"];
|
||||
pub const ITER_ONCE: [&str; 5] = ["core", "iter", "sources", "once", "Once"];
|
||||
pub const ITERTOOLS_NEXT_TUPLE: [&str; 3] = ["itertools", "Itertools", "next_tuple"];
|
||||
#[cfg(feature = "internal")]
|
||||
pub const KW_MODULE: [&str; 3] = ["rustc_span", "symbol", "kw"];
|
||||
|
|
@ -163,3 +164,4 @@ pub const DEBUG_STRUCT: [&str; 4] = ["core", "fmt", "builders", "DebugStruct"];
|
|||
pub const ORD_CMP: [&str; 4] = ["core", "cmp", "Ord", "cmp"];
|
||||
#[expect(clippy::invalid_paths)] // not sure why it thinks this, it works so
|
||||
pub const BOOL_THEN: [&str; 4] = ["core", "bool", "<impl bool>", "then"];
|
||||
pub const ARRAY_INTO_ITER: [&str; 4] = ["core", "array", "iter", "IntoIter"];
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use rustc_hir::{BlockCheckMode, Expr, ExprKind, UnsafeSource};
|
|||
use rustc_lint::{LateContext, LintContext};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::source_map::{original_sp, SourceMap};
|
||||
use rustc_span::{hygiene, BytePos, SourceFileAndLine, Pos, SourceFile, Span, SpanData, SyntaxContext, DUMMY_SP};
|
||||
use rustc_span::{hygiene, BytePos, Pos, SourceFile, SourceFileAndLine, Span, SpanData, SyntaxContext, DUMMY_SP};
|
||||
use std::borrow::Cow;
|
||||
use std::ops::Range;
|
||||
|
||||
|
|
@ -362,7 +362,7 @@ pub fn snippet_block_with_context<'a>(
|
|||
}
|
||||
|
||||
/// Same as `snippet_with_applicability`, but first walks the span up to the given context. This
|
||||
/// will result in the macro call, rather then the expansion, if the span is from a child context.
|
||||
/// will result in the macro call, rather than the expansion, if the span is from a child context.
|
||||
/// If the span is not from a child context, it will be used directly instead.
|
||||
///
|
||||
/// e.g. Given the expression `&vec![]`, getting a snippet from the span for `vec![]` as a HIR node
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ impl<'a> Sugg<'a> {
|
|||
}
|
||||
|
||||
/// Same as `hir`, but first walks the span up to the given context. This will result in the
|
||||
/// macro call, rather then the expansion, if the span is from a child context. If the span is
|
||||
/// macro call, rather than the expansion, if the span is from a child context. If the span is
|
||||
/// not from a child context, it will be used directly instead.
|
||||
///
|
||||
/// e.g. Given the expression `&vec![]`, getting a snippet from the span for `vec![]` as a HIR
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ use rustc_target::abi::{Size, VariantIdx};
|
|||
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
|
||||
use rustc_trait_selection::traits::query::normalize::QueryNormalizeExt;
|
||||
use rustc_trait_selection::traits::{Obligation, ObligationCause};
|
||||
use std::assert_matches::debug_assert_matches;
|
||||
use std::iter;
|
||||
|
||||
use crate::{match_def_path, path_res, paths};
|
||||
|
|
@ -259,7 +260,11 @@ pub fn implements_trait_with_env_from_iter<'tcx>(
|
|||
})),
|
||||
);
|
||||
|
||||
debug_assert_eq!(tcx.def_kind(trait_id), DefKind::Trait);
|
||||
debug_assert_matches!(
|
||||
tcx.def_kind(trait_id),
|
||||
DefKind::Trait | DefKind::TraitAlias,
|
||||
"`DefId` must belong to a trait or trait alias"
|
||||
);
|
||||
#[cfg(debug_assertions)]
|
||||
assert_generic_args_match(tcx, trait_id, trait_ref.args);
|
||||
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ fn generic_args_certainty(cx: &LateContext<'_>, args: &GenericArgs<'_>) -> Certa
|
|||
}
|
||||
|
||||
/// Tries to tell whether a `QPath` resolves to something certain, e.g., whether all of its path
|
||||
/// segments generic arguments are are instantiated.
|
||||
/// segments generic arguments are instantiated.
|
||||
///
|
||||
/// `qpath` could refer to either a type or a value. The heuristic never needs the `DefId` of a
|
||||
/// value. So `DefId`s are retained only when `resolves_to_type` is true.
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use core::ops::ControlFlow;
|
|||
use hir::def::Res;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::{self as hir, Expr, ExprKind, HirId, HirIdSet};
|
||||
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
|
||||
use rustc_hir_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, Place, PlaceBase, PlaceWithHirId};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::hir::nested_filter;
|
||||
|
|
@ -37,6 +37,17 @@ pub fn is_potentially_mutated<'tcx>(variable: HirId, expr: &'tcx Expr<'_>, cx: &
|
|||
mutated_variables(expr, cx).map_or(true, |mutated| mutated.contains(&variable))
|
||||
}
|
||||
|
||||
pub fn is_potentially_local_place(local_id: HirId, place: &Place<'_>) -> bool {
|
||||
match place.base {
|
||||
PlaceBase::Local(id) => id == local_id,
|
||||
PlaceBase::Upvar(_) => {
|
||||
// Conservatively assume yes.
|
||||
true
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
struct MutVarsDelegate {
|
||||
used_mutably: HirIdSet,
|
||||
skip: bool,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue