Skip to content

Commit

Permalink
Auto merge of #12690 - flip1995:rustup, r=flip1995
Browse files Browse the repository at this point in the history
Rustup

r? `@ghost`

changelog: none
  • Loading branch information
bors committed Apr 18, 2024
2 parents cdd6336 + fca4e16 commit ca3b393
Show file tree
Hide file tree
Showing 36 changed files with 108 additions and 143 deletions.
6 changes: 3 additions & 3 deletions clippy_lints/src/attrs/mixed_attributes_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use super::MIXED_ATTRIBUTES_STYLE;
use clippy_utils::diagnostics::span_lint;
use rustc_ast::{AttrKind, AttrStyle, Attribute};
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::sync::Lrc;
use rustc_lint::{LateContext, LintContext};
use rustc_span::source_map::SourceMap;
use rustc_span::{SourceFile, Span, Symbol};
use std::sync::Arc;

#[derive(Hash, PartialEq, Eq)]
enum SimpleAttrKind {
Expand Down Expand Up @@ -79,7 +79,7 @@ fn lint_mixed_attrs(cx: &LateContext<'_>, attrs: &[Attribute]) {
);
}

fn attr_in_same_src_as_item(source_map: &SourceMap, item_src: &Arc<SourceFile>, attr_span: Span) -> bool {
fn attr_in_same_src_as_item(source_map: &SourceMap, item_src: &Lrc<SourceFile>, attr_span: Span) -> bool {
let attr_src = source_map.lookup_source_file(attr_span.lo());
Arc::ptr_eq(item_src, &attr_src)
Lrc::ptr_eq(item_src, &attr_src)
}
2 changes: 1 addition & 1 deletion clippy_lints/src/casts/ptr_as_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, msrv: &Msrv) {

let (help, final_suggestion) = if let Some(method) = omit_cast.corresponding_item() {
// don't force absolute path
let method = qpath_to_string(method);
let method = qpath_to_string(&cx.tcx, method);
("try call directly", format!("{method}{turbofish}()"))
} else {
let cast_expr_sugg = Sugg::hir_with_applicability(cx, cast_expr, "_", &mut app);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/crate_in_macro_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fn contains_unhygienic_crate_reference(tts: &TokenStream) -> Option<Span> {
if !prev_is_dollar
&& let Some(span) = is_crate_keyword(curr)
&& let Some(next) = cursor.look_ahead(0)
&& is_token(next, &TokenKind::ModSep)
&& is_token(next, &TokenKind::PathSep)
{
return Some(span);
}
Expand Down
2 changes: 2 additions & 0 deletions clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ impl TyCoercionStability {
| TyKind::Array(..)
| TyKind::Ptr(_)
| TyKind::BareFn(_)
| TyKind::Pat(..)
| TyKind::Never
| TyKind::Tup(_)
| TyKind::Path(_) => Self::Deref,
Expand Down Expand Up @@ -869,6 +870,7 @@ impl TyCoercionStability {
| ty::Int(_)
| ty::Uint(_)
| ty::Array(..)
| ty::Pat(..)
| ty::Float(_)
| ty::RawPtr(..)
| ty::FnPtr(_)
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/derivable_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_hir::{
};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::adjustment::{Adjust, PointerCoercion};
use rustc_middle::ty::{self, Adt, AdtDef, GenericArgsRef, Ty, TypeckResults};
use rustc_middle::ty::{self, AdtDef, GenericArgsRef, Ty, TypeckResults};
use rustc_session::impl_lint_pass;
use rustc_span::sym;

Expand Down Expand Up @@ -79,7 +79,7 @@ fn is_path_self(e: &Expr<'_>) -> bool {
fn contains_trait_object(ty: Ty<'_>) -> bool {
match ty.kind() {
ty::Ref(_, ty, _) => contains_trait_object(*ty),
Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object),
ty::Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object),
ty::Dynamic(..) => true,
_ => false,
}
Expand Down Expand Up @@ -198,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
&& let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir)
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
&& let Body { value: func_expr, .. } = cx.tcx.hir().body(*b)
&& let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()
&& 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())
&& !attrs.iter().any(|attr| attr.doc_str().is_some())
&& cx.tcx.hir().attrs(impl_item_hir).is_empty()
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/doc/needless_doctest_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn check(
// of all `#[test]` attributes in not ignored code examples
fn check_code_sample(code: String, edition: Edition, ignore: bool) -> (bool, Vec<Range<usize>>) {
rustc_driver::catch_fatal_errors(|| {
rustc_span::create_session_globals_then(edition, || {
rustc_span::create_session_globals_then(edition, None, || {
let mut test_attr_spans = vec![];
let filename = FileName::anon_source_code(&code);

Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/from_raw_with_void_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clippy_utils::ty::is_c_void;
use rustc_hir::def_id::DefId;
use rustc_hir::{Expr, ExprKind, QPath};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::RawPtr;
use rustc_middle::ty;
use rustc_session::declare_lint_pass;
use rustc_span::sym;

Expand Down Expand Up @@ -44,7 +44,7 @@ impl LateLintPass<'_> for FromRawWithVoidPtr {
&& seg.ident.name == sym!(from_raw)
&& let Some(type_str) = path_def_id(cx, ty).and_then(|id| def_id_matches_type(cx, id))
&& let arg_kind = cx.typeck_results().expr_ty(arg).kind()
&& let RawPtr(ty, _) = arg_kind
&& let ty::RawPtr(ty, _) = arg_kind
&& is_c_void(cx, *ty)
{
let msg = format!("creating a `{type_str}` from a void raw pointer");
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_hir::{self as hir, intravisit, HirIdSet};
use rustc_hir::{self as hir, intravisit, HirId, HirIdSet};
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_span::def_id::LocalDefId;
Expand Down Expand Up @@ -74,7 +74,7 @@ fn check_raw_ptr<'tcx>(
}
}

fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<hir::HirId> {
fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option<HirId> {
if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_, _))) = (
&arg.pat.kind,
cx.maybe_typeck_results()
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/functions/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc_errors::Diag;
use rustc_hir as hir;
use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{Adt, Ty};
use rustc_middle::ty::{self, Ty};
use rustc_span::{sym, Span};

use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
Expand All @@ -25,7 +25,7 @@ fn result_err_ty<'tcx>(
.tcx
.instantiate_bound_regions_with_erased(cx.tcx.fn_sig(id).instantiate_identity().output())
&& is_type_diagnostic_item(cx, ty, sym::Result)
&& let Adt(_, args) = ty.kind()
&& let ty::Adt(_, args) = ty.kind()
{
let err_ty = args.type_at(1);
Some((hir_ty, err_ty))
Expand Down Expand Up @@ -86,7 +86,7 @@ fn check_result_unit_err(cx: &LateContext<'_>, err_ty: Ty<'_>, fn_header_span: S
}

fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty_span: Span, large_err_threshold: u64) {
if let Adt(adt, subst) = err_ty.kind()
if let ty::Adt(adt, subst) = err_ty.kind()
&& let Some(local_def_id) = err_ty
.ty_adt_def()
.expect("already checked this is adt")
Expand Down
3 changes: 2 additions & 1 deletion clippy_lints/src/implicit_saturating_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_data_structures::packed::Pu128;
use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::{Int, IntTy, Ty, Uint, UintTy};
use rustc_middle::ty::{IntTy, Ty, UintTy};
use rustc_session::declare_lint_pass;

declare_clippy_lint! {
Expand Down Expand Up @@ -97,6 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitSaturatingAdd {
}

fn get_int_max(ty: Ty<'_>) -> Option<u128> {
use rustc_middle::ty::{Int, Uint};
match ty.peel_refs().kind() {
Int(IntTy::I8) => i8::MAX.try_into().ok(),
Int(IntTy::I16) => i16::MAX.try_into().ok(),
Expand Down
13 changes: 7 additions & 6 deletions clippy_lints/src/index_refutable_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::HirId;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::nested_filter;
use rustc_middle::ty;
Expand Down Expand Up @@ -87,9 +88,9 @@ impl<'tcx> LateLintPass<'tcx> for IndexRefutableSlice {
extract_msrv_attr!(LateContext);
}

fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<hir::HirId, SliceLintInformation> {
let mut removed_pat: FxHashSet<hir::HirId> = FxHashSet::default();
let mut slices: FxIndexMap<hir::HirId, SliceLintInformation> = FxIndexMap::default();
fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap<HirId, SliceLintInformation> {
let mut removed_pat: FxHashSet<HirId> = FxHashSet::default();
let mut slices: FxIndexMap<HirId, SliceLintInformation> = FxIndexMap::default();
pat.walk_always(|pat| {
// We'll just ignore mut and ref mut for simplicity sake right now
if let hir::PatKind::Binding(
Expand Down Expand Up @@ -206,10 +207,10 @@ impl SliceLintInformation {

fn filter_lintable_slices<'tcx>(
cx: &LateContext<'tcx>,
slice_lint_info: FxIndexMap<hir::HirId, SliceLintInformation>,
slice_lint_info: FxIndexMap<HirId, SliceLintInformation>,
max_suggested_slice: u64,
scope: &'tcx hir::Expr<'tcx>,
) -> FxIndexMap<hir::HirId, SliceLintInformation> {
) -> FxIndexMap<HirId, SliceLintInformation> {
let mut visitor = SliceIndexLintingVisitor {
cx,
slice_lint_info,
Expand All @@ -223,7 +224,7 @@ fn filter_lintable_slices<'tcx>(

struct SliceIndexLintingVisitor<'a, 'tcx> {
cx: &'a LateContext<'tcx>,
slice_lint_info: FxIndexMap<hir::HirId, SliceLintInformation>,
slice_lint_info: FxIndexMap<HirId, SliceLintInformation>,
max_suggested_slice: u64,
}

Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/large_enum_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_errors::Applicability;
use rustc_hir::{Item, ItemKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::{Adt, Ty};
use rustc_middle::ty::{self, Ty};
use rustc_session::impl_lint_pass;
use rustc_span::Span;

Expand Down Expand Up @@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
}
if let ItemKind::Enum(ref def, _) = item.kind {
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
let Adt(adt, subst) = ty.kind() else {
let ty::Adt(adt, subst) = ty.kind() else {
panic!("already checked whether this is an enum")
};
if adt.variants().len() <= 1 {
Expand Down Expand Up @@ -167,7 +167,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
}

fn maybe_copy<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool {
if let Adt(_def, args) = ty.kind()
if let ty::Adt(_def, args) = ty.kind()
&& args.types().next().is_some()
&& let Some(copy_trait) = cx.tcx.lang_items().copy_trait()
{
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/large_include_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl LateLintPass<'_> for LargeIncludeFile {
span_lint_and_note(
cx,
LARGE_INCLUDE_FILE,
expr.span,
expr.span.source_callsite(),
"attempted to include a large file",
None,
format!(
Expand Down
6 changes: 1 addition & 5 deletions clippy_lints/src/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,7 @@ fn elision_suggestions(
}) => {
// expand `&'a T` to `&'a T`
// ^^ ^^^
let span = cx
.sess()
.source_map()
.span_extend_while(usage.ident.span, |ch| ch.is_ascii_whitespace())
.unwrap_or(usage.ident.span);
let span = cx.sess().source_map().span_extend_while_whitespace(usage.ident.span);

(span, String::new())
},
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/matches/match_wild_err_arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) fn check<'tcx>(cx: &LateContext<'tcx>, ex: &Expr<'tcx>, arms: &[Arm<'
if is_type_diagnostic_item(cx, ex_ty, sym::Result) {
for arm in arms {
if let PatKind::TupleStruct(ref path, inner, _) = arm.pat.kind {
let path_str = rustc_hir_pretty::qpath_to_string(path);
let path_str = rustc_hir_pretty::qpath_to_string(&cx.tcx, path);
if path_str == "Err" {
let mut matching_wild = inner.iter().any(is_wild);
let mut ident_bind_name = kw::Underscore;
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/methods/unnecessary_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_ast::ast::LitKind;
use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind, LangItem};
use rustc_lint::LateContext;
use rustc_middle::ty::{Ref, Slice};
use rustc_middle::ty;
use rustc_span::Span;

use super::UNNECESSARY_JOIN;
Expand All @@ -18,9 +18,9 @@ pub(super) fn check<'tcx>(
) {
let applicability = Applicability::MachineApplicable;
let collect_output_adjusted_type = cx.typeck_results().expr_ty_adjusted(join_self_arg);
if let Ref(_, ref_type, _) = collect_output_adjusted_type.kind()
if let ty::Ref(_, ref_type, _) = collect_output_adjusted_type.kind()
// the turbofish for collect is ::<Vec<String>>
&& let Slice(slice) = ref_type.kind()
&& let ty::Slice(slice) = ref_type.kind()
&& is_type_lang_item(cx, *slice, LangItem::String)
// the argument for join is ""
&& let ExprKind::Lit(spanned) = &join_arg.kind
Expand Down
5 changes: 1 addition & 4 deletions clippy_lints/src/methods/unnecessary_to_owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::{BorrowKind, Expr, ExprKind, ItemKind, LangItem, Node};
use rustc_hir_typeck::{FnCtxt, TypeckRootCtxt};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::LateContext;
use rustc_middle::mir::Mutability;
Expand Down Expand Up @@ -437,9 +436,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
Node::Item(item) => {
if let ItemKind::Fn(_, _, body_id) = &item.kind
&& let output_ty = return_ty(cx, item.owner_id)
&& let root_ctxt = TypeckRootCtxt::new(cx.tcx, item.owner_id.def_id)
&& let fn_ctxt = FnCtxt::new(&root_ctxt, cx.param_env, item.owner_id.def_id)
&& fn_ctxt.can_coerce(ty, output_ty)
&& rustc_hir_typeck::can_coerce(cx.tcx, cx.param_env, item.owner_id.def_id, ty, output_ty)
{
if has_lifetime(output_ty) && has_lifetime(ty) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ declare_clippy_lint! {
///
/// ### Known problems
/// The lint does not work properly with desugaring and
/// macro, it has been allowed in the mean time.
/// macro, it has been allowed in the meantime.
///
/// ### Example
/// ```no_run
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/mut_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clippy_utils::{def_path_def_ids, trait_ref_of_method};
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::{Adt, Ty};
use rustc_middle::ty::{self, Ty};
use rustc_session::impl_lint_pass;
use rustc_span::def_id::LocalDefId;
use rustc_span::symbol::sym;
Expand Down Expand Up @@ -153,7 +153,7 @@ impl MutableKeyType {
// generics (because the compiler cannot ensure immutability for unknown types).
fn check_ty_<'tcx>(&self, cx: &LateContext<'tcx>, span: Span, ty: Ty<'tcx>) {
let ty = ty.peel_refs();
if let Adt(def, args) = ty.kind() {
if let ty::Adt(def, args) = ty.kind() {
let is_keyed_type = [sym::HashMap, sym::BTreeMap, sym::HashSet, sym::BTreeSet]
.iter()
.any(|diag_item| cx.tcx.is_diagnostic_item(*diag_item, def.did()));
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/mut_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed {
cx,
arguments.iter().collect(),
cx.typeck_results().expr_ty(fn_expr),
&rustc_hir_pretty::qpath_to_string(path),
&rustc_hir_pretty::qpath_to_string(&cx.tcx, path),
"function",
);
}
Expand Down
13 changes: 3 additions & 10 deletions clippy_lints/src/non_copy_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult, GlobalId};
use rustc_middle::ty::adjustment::Adjust;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_session::impl_lint_pass;
use rustc_span::{sym, InnerSpan, Span};
use rustc_span::{sym, InnerSpan, Span, DUMMY_SP};
use rustc_target::abi::VariantIdx;

// FIXME: this is a correctness problem but there's no suitable
Expand Down Expand Up @@ -290,21 +290,14 @@ impl NonCopyConst {
promoted: None,
};
let param_env = cx.tcx.param_env(def_id).with_reveal_all_normalized(cx.tcx);
let result = cx
.tcx
.const_eval_global_id_for_typeck(param_env, cid, rustc_span::DUMMY_SP);
let result = cx.tcx.const_eval_global_id_for_typeck(param_env, cid, DUMMY_SP);
self.is_value_unfrozen_raw(cx, result, ty)
}

fn is_value_unfrozen_expr<'tcx>(&self, cx: &LateContext<'tcx>, hir_id: HirId, def_id: DefId, ty: Ty<'tcx>) -> bool {
let args = cx.typeck_results().node_args(hir_id);

let result = Self::const_eval_resolve(
cx.tcx,
cx.param_env,
ty::UnevaluatedConst::new(def_id, args),
rustc_span::DUMMY_SP,
);
let result = Self::const_eval_resolve(cx.tcx, cx.param_env, ty::UnevaluatedConst::new(def_id, args), DUMMY_SP);
self.is_value_unfrozen_raw(cx, result, ty)
}

Expand Down
Loading

0 comments on commit ca3b393

Please sign in to comment.