Skip to content

Rustup #11250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jul 28, 2023
Merged

Rustup #11250

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
fdb2e36
refactor(rustc_middle): Substs -> GenericArg
mdibaiee Jul 11, 2023
d6d530f
Merge commit 'd9c24d1b1ee61f276e550b967409c9f155eac4e3' into clippyup
flip1995 Jul 17, 2023
2feb9a5
Another fix for incorrect_impls
flip1995 Jul 17, 2023
d1e1dcb
Rename arg_iter to iter_instantiated
compiler-errors Jul 17, 2023
cbca8f9
On nightly, dump ICE backtraces to disk
estebank Mar 3, 2023
5a6c4d7
XSimplifiedType to SimplifiedType::X
lcnr Jul 18, 2023
a147372
clippy: `env!` invocations can't be b"" literals
davidtwco Jul 25, 2023
2b16c37
bless more
RalfJung Jul 24, 2023
3fb714d
Use a builder instead of boolean/option arguments
oli-obk Jul 25, 2023
f20a174
Make everything builtin!
compiler-errors Jul 24, 2023
2cc44cf
Auto merge of #113393 - compiler-errors:next-solver-unsize-rhs, r=lcnr
bors Jul 25, 2023
0f3a149
Rollup merge of #114014 - davidtwco:issue-114010-env-rawstr, r=cjgillot
matthiaskrgr Jul 25, 2023
61e0aac
Auto merge of #114063 - matthiaskrgr:rollup-c90czu6, r=matthiaskrgr
bors Jul 25, 2023
0404b6b
Add `sym::iter_mut` + `sym::as_mut_ptr`
blyxyas Jul 25, 2023
ed2ec81
Auto merge of #114054 - oli-obk:cleanups, r=estebank
bors Jul 26, 2023
8615595
Rollup merge of #114070 - blyxyas:iter_mut_symbol, r=oli-obk
matthiaskrgr Jul 26, 2023
6ca6be6
Unite bless environment variables under `RUSTC_BLESS`
tgross35 Jul 3, 2023
42d3370
Auto merge of #113298 - tgross35:update-bless-envs, r=oli-obk
bors Jul 27, 2023
3d60241
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jul 28, 2023
65c5afd
Bump nightly version -> 2023-07-28
flip1995 Jul 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clippy_lints/src/assertions_on_result_states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
&& let result_type_with_refs = cx.typeck_results().expr_ty(recv)
&& let result_type = result_type_with_refs.peel_refs()
&& is_type_diagnostic_item(cx, result_type, sym::Result)
&& let ty::Adt(_, substs) = result_type.kind()
&& let ty::Adt(_, args) = result_type.kind()
{
if !is_copy(cx, result_type) {
if result_type_with_refs != result_type {
Expand All @@ -61,7 +61,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
let semicolon = if is_expr_final_block_expr(cx.tcx, e) {";"} else {""};
let mut app = Applicability::MachineApplicable;
match method_segment.ident.as_str() {
"is_ok" if type_suitable_to_unwrap(cx, substs.type_at(1)) => {
"is_ok" if type_suitable_to_unwrap(cx, args.type_at(1)) => {
span_lint_and_sugg(
cx,
ASSERTIONS_ON_RESULT_STATES,
Expand All @@ -75,7 +75,7 @@ impl<'tcx> LateLintPass<'tcx> for AssertionsOnResultStates {
app,
);
}
"is_err" if type_suitable_to_unwrap(cx, substs.type_at(0)) => {
"is_err" if type_suitable_to_unwrap(cx, args.type_at(0)) => {
span_lint_and_sugg(
cx,
ASSERTIONS_ON_RESULT_STATES,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/bool_assert_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -
)
})
.map_or(false, |assoc_item| {
let proj = Ty::new_projection(cx.tcx, assoc_item.def_id, cx.tcx.mk_substs_trait(ty, []));
let proj = Ty::new_projection(cx.tcx, assoc_item.def_id, cx.tcx.mk_args_trait(ty, []));
let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj);

nty.is_bool()
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/casts/as_ptr_cast_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
&& let ExprKind::MethodCall(method_name, receiver, [], _) = cast_expr.peel_blocks().kind
&& method_name.ident.name == rustc_span::sym::as_ptr
&& let Some(as_ptr_did) = cx.typeck_results().type_dependent_def_id(cast_expr.peel_blocks().hir_id)
&& let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did).subst_identity()
&& let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did).instantiate_identity()
&& let Some(first_param_ty) = as_ptr_sig.skip_binder().inputs().iter().next()
&& let ty::Ref(_, _, Mutability::Not) = first_param_ty.kind()
&& let Some(recv) = snippet_opt(cx, receiver.span)
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/casts/cast_ptr_alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn is_used_as_unaligned(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
if matches!(name.ident.as_str(), "read_unaligned" | "write_unaligned")
&& let Some(def_id) = cx.typeck_results().type_dependent_def_id(parent.hir_id)
&& let Some(def_id) = cx.tcx.impl_of_method(def_id)
&& cx.tcx.type_of(def_id).subst_identity().is_unsafe_ptr()
&& cx.tcx.type_of(def_id).instantiate_identity().is_unsafe_ptr()
{
true
} else {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/copy_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyIterator {
of_trait: Some(ref trait_ref),
..
}) = item.kind;
let ty = cx.tcx.type_of(item.owner_id).subst_identity();
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
if is_copy(cx, ty);
if let Some(trait_id) = trait_ref.trait_def_id();
if cx.tcx.is_diagnostic_item(sym::Iterator, trait_id);
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
.fields
.iter()
.all(|field| {
is_copy(cx, cx.tcx.type_of(field.did).subst_identity())
is_copy(cx, cx.tcx.type_of(field.did).instantiate_identity())
});
if !has_drop(cx, binding_type) || all_fields_are_copy;
then {
Expand Down Expand Up @@ -219,11 +219,11 @@ impl<'tcx> LateLintPass<'tcx> for Default {

// give correct suggestion if generics are involved (see #6944)
let binding_type = if_chain! {
if let ty::Adt(adt_def, substs) = binding_type.kind();
if !substs.is_empty();
if let ty::Adt(adt_def, args) = binding_type.kind();
if !args.is_empty();
then {
let adt_def_ty_name = cx.tcx.item_name(adt_def.did());
let generic_args = substs.iter().collect::<Vec<_>>();
let generic_args = args.iter().collect::<Vec<_>>();
let tys_str = generic_args
.iter()
.map(ToString::to_string)
Expand Down
8 changes: 4 additions & 4 deletions clippy_lints/src/default_numeric_fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {

ExprKind::MethodCall(_, receiver, args, _) => {
if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) {
let fn_sig = self.cx.tcx.fn_sig(def_id).subst_identity().skip_binder();
let fn_sig = self.cx.tcx.fn_sig(def_id).instantiate_identity().skip_binder();
for (expr, bound) in iter::zip(std::iter::once(*receiver).chain(args.iter()), fn_sig.inputs()) {
self.ty_bounds.push((*bound).into());
self.visit_expr(expr);
Expand All @@ -163,7 +163,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
.iter()
.find_map(|f_def| {
if f_def.ident(self.cx.tcx) == field.ident
{ Some(self.cx.tcx.type_of(f_def.did).subst_identity()) }
{ Some(self.cx.tcx.type_of(f_def.did).instantiate_identity()) }
else { None }
});
self.ty_bounds.push(bound.into());
Expand Down Expand Up @@ -209,9 +209,9 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {

fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<PolyFnSig<'tcx>> {
let node_ty = cx.typeck_results().node_type_opt(hir_id)?;
// We can't use `Ty::fn_sig` because it automatically performs substs, this may result in FNs.
// We can't use `Ty::fn_sig` because it automatically performs args, this may result in FNs.
match node_ty.kind() {
ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id).subst_identity()),
ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id).instantiate_identity()),
ty::FnPtr(fn_sig) => Some(*fn_sig),
_ => None,
}
Expand Down
47 changes: 26 additions & 21 deletions clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
cx,
&mut self.possible_borrowers,
fn_id,
typeck.node_substs(hir_id),
typeck.node_args(hir_id),
i,
ty,
expr,
Expand Down Expand Up @@ -438,11 +438,11 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
&& let arg_ty
= cx.tcx.erase_regions(use_cx.adjustments.last().map_or(expr_ty, |a| a.target))
&& let ty::Ref(_, sub_ty, _) = *arg_ty.kind()
&& let subs = cx
&& let args = cx
.typeck_results()
.node_substs_opt(hir_id).map(|subs| &subs[1..]).unwrap_or_default()
.node_args_opt(hir_id).map(|args| &args[1..]).unwrap_or_default()
&& let impl_ty = if cx.tcx.fn_sig(fn_id)
.subst_identity()
.instantiate_identity()
.skip_binder()
.inputs()[0].is_ref()
{
Expand All @@ -455,7 +455,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
&& cx.tcx.infer_ctxt().build()
.type_implements_trait(
trait_id,
[impl_ty.into()].into_iter().chain(subs.iter().copied()),
[impl_ty.into()].into_iter().chain(args.iter().copied()),
cx.param_env,
)
.must_apply_modulo_regions()
Expand Down Expand Up @@ -917,10 +917,10 @@ impl TyCoercionStability {
| ty::Placeholder(_)
| ty::Dynamic(..)
| ty::Param(_) => Self::Reborrow,
ty::Adt(_, substs)
ty::Adt(_, args)
if ty.has_placeholders()
|| ty.has_opaque_types()
|| (!for_return && substs.has_non_region_param()) =>
|| (!for_return && args.has_non_region_param()) =>
{
Self::Reborrow
},
Expand Down Expand Up @@ -992,7 +992,7 @@ fn needless_borrow_generic_arg_count<'tcx>(
cx: &LateContext<'tcx>,
possible_borrowers: &mut Vec<(LocalDefId, PossibleBorrowerMap<'tcx, 'tcx>)>,
fn_id: DefId,
callee_substs: &'tcx List<GenericArg<'tcx>>,
callee_args: &'tcx List<GenericArg<'tcx>>,
arg_index: usize,
param_ty: ParamTy,
mut expr: &Expr<'tcx>,
Expand All @@ -1001,7 +1001,7 @@ fn needless_borrow_generic_arg_count<'tcx>(
let destruct_trait_def_id = cx.tcx.lang_items().destruct_trait();
let sized_trait_def_id = cx.tcx.lang_items().sized_trait();

let fn_sig = cx.tcx.fn_sig(fn_id).subst_identity().skip_binder();
let fn_sig = cx.tcx.fn_sig(fn_id).instantiate_identity().skip_binder();
let predicates = cx.tcx.param_env(fn_id).caller_bounds();
let projection_predicates = predicates
.iter()
Expand Down Expand Up @@ -1050,9 +1050,9 @@ fn needless_borrow_generic_arg_count<'tcx>(
return 0;
}

// `substs_with_referent_ty` can be constructed outside of `check_referent` because the same
// `args_with_referent_ty` can be constructed outside of `check_referent` because the same
// elements are modified each time `check_referent` is called.
let mut substs_with_referent_ty = callee_substs.to_vec();
let mut args_with_referent_ty = callee_args.to_vec();

let mut check_reference_and_referent = |reference, referent| {
let referent_ty = cx.typeck_results().expr_ty(referent);
Expand All @@ -1076,7 +1076,7 @@ fn needless_borrow_generic_arg_count<'tcx>(
fn_sig,
arg_index,
&projection_predicates,
&mut substs_with_referent_ty,
&mut args_with_referent_ty,
) {
return false;
}
Expand All @@ -1085,14 +1085,14 @@ fn needless_borrow_generic_arg_count<'tcx>(
if let ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder()
&& cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_predicate.trait_ref.def_id)
&& let ty::Param(param_ty) = trait_predicate.self_ty().kind()
&& let GenericArgKind::Type(ty) = substs_with_referent_ty[param_ty.index as usize].unpack()
&& let GenericArgKind::Type(ty) = args_with_referent_ty[param_ty.index as usize].unpack()
&& ty.is_array()
&& !msrv.meets(msrvs::ARRAY_INTO_ITERATOR)
{
return false;
}

let predicate = EarlyBinder::bind(predicate).subst(cx.tcx, &substs_with_referent_ty);
let predicate = EarlyBinder::bind(predicate).instantiate(cx.tcx, &args_with_referent_ty);
let obligation = Obligation::new(cx.tcx, ObligationCause::dummy(), cx.param_env, predicate);
let infcx = cx.tcx.infer_ctxt().build();
infcx.predicate_must_hold_modulo_regions(&obligation)
Expand All @@ -1116,7 +1116,12 @@ fn has_ref_mut_self_method(cx: &LateContext<'_>, trait_def_id: DefId) -> bool {
.in_definition_order()
.any(|assoc_item| {
if assoc_item.fn_has_self_parameter {
let self_ty = cx.tcx.fn_sig(assoc_item.def_id).subst_identity().skip_binder().inputs()[0];
let self_ty = cx
.tcx
.fn_sig(assoc_item.def_id)
.instantiate_identity()
.skip_binder()
.inputs()[0];
matches!(self_ty.kind(), ty::Ref(_, _, Mutability::Mut))
} else {
false
Expand Down Expand Up @@ -1187,7 +1192,7 @@ fn referent_used_exactly_once<'tcx>(
}
}

// Iteratively replaces `param_ty` with `new_ty` in `substs`, and similarly for each resulting
// Iteratively replaces `param_ty` with `new_ty` in `args`, and similarly for each resulting
// projected type that is a type parameter. Returns `false` if replacing the types would have an
// effect on the function signature beyond substituting `new_ty` for `param_ty`.
// See: https://github.com/rust-lang/rust-clippy/pull/9136#discussion_r927212757
Expand All @@ -1198,11 +1203,11 @@ fn replace_types<'tcx>(
fn_sig: FnSig<'tcx>,
arg_index: usize,
projection_predicates: &[ProjectionPredicate<'tcx>],
substs: &mut [ty::GenericArg<'tcx>],
args: &mut [ty::GenericArg<'tcx>],
) -> bool {
let mut replaced = BitSet::new_empty(substs.len());
let mut replaced = BitSet::new_empty(args.len());

let mut deque = VecDeque::with_capacity(substs.len());
let mut deque = VecDeque::with_capacity(args.len());
deque.push_back((param_ty, new_ty));

while let Some((param_ty, new_ty)) = deque.pop_front() {
Expand All @@ -1216,7 +1221,7 @@ fn replace_types<'tcx>(
return false;
}

substs[param_ty.index as usize] = ty::GenericArg::from(new_ty);
args[param_ty.index as usize] = ty::GenericArg::from(new_ty);

// The `replaced.insert(...)` check provides some protection against infinite loops.
if replaced.insert(param_ty.index) {
Expand All @@ -1231,7 +1236,7 @@ fn replace_types<'tcx>(
));

if let Ok(projected_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, projection)
&& substs[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty)
&& args[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty)
{
deque.push_back((*term_param_ty, projected_ty));
}
Expand Down
21 changes: 11 additions & 10 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, SubstsRef, Ty, TypeckResults};
use rustc_middle::ty::{self, Adt, AdtDef, GenericArgsRef, Ty, TypeckResults};
use rustc_session::{declare_tool_lint, 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),
ty::Adt(def, substs) => def.is_box() && substs[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 All @@ -91,18 +91,19 @@ fn check_struct<'tcx>(
self_ty: &hir::Ty<'_>,
func_expr: &Expr<'_>,
adt_def: AdtDef<'_>,
substs: SubstsRef<'_>,
ty_args: GenericArgsRef<'_>,
typeck_results: &'tcx TypeckResults<'tcx>,
) {
if let TyKind::Path(QPath::Resolved(_, p)) = self_ty.kind {
if let Some(PathSegment { args, .. }) = p.segments.last() {
let args = args.map(|a| a.args).unwrap_or(&[]);

// substs contains the generic parameters of the type declaration, while args contains the arguments
// used at instantiation time. If both len are not equal, it means that some parameters were not
// provided (which means that the default values were used); in this case we will not risk
// suggesting too broad a rewrite. We won't either if any argument is a type or a const.
if substs.len() != args.len() || args.iter().any(|arg| !matches!(arg, GenericArg::Lifetime(_))) {
// ty_args contains the generic parameters of the type declaration, while args contains the
// arguments used at instantiation time. If both len are not equal, it means that some
// parameters were not provided (which means that the default values were used); in this
// case we will not risk suggesting too broad a rewrite. We won't either if any argument
// is a type or a const.
if ty_args.len() != args.len() || args.iter().any(|arg| !matches!(arg, GenericArg::Lifetime(_))) {
return;
}
}
Expand Down Expand Up @@ -213,15 +214,15 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
if let Some(Node::ImplItem(impl_item)) = cx.tcx.hir().find(impl_item_hir);
if let ImplItemKind::Fn(_, b) = &impl_item.kind;
if let Body { value: func_expr, .. } = cx.tcx.hir().body(*b);
if let &Adt(adt_def, substs) = cx.tcx.type_of(item.owner_id).subst_identity().kind();
if let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind();
if let attrs = cx.tcx.hir().attrs(item.hir_id());
if !attrs.iter().any(|attr| attr.doc_str().is_some());
if let child_attrs = cx.tcx.hir().attrs(impl_item_hir);
if !child_attrs.iter().any(|attr| attr.doc_str().is_some());

then {
if adt_def.is_struct() {
check_struct(cx, item, self_ty, func_expr, adt_def, substs, cx.tcx.typeck_body(*b));
check_struct(cx, item, self_ty, func_expr, adt_def, args, cx.tcx.typeck_body(*b));
} else if adt_def.is_enum() && self.msrv.meets(msrvs::DEFAULT_ENUM_ATTRIBUTE) {
check_enum(cx, item, func_expr, adt_def);
}
Expand Down
Loading