Skip to content

Commit f6f9d5e

Browse files
committed
Auto merge of #100151 - matthiaskrgr:rollup-irqwvj2, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #98796 (Do not exclusively suggest `;` when `,` is also a choice) - #99772 (Re-enable submodule archive downloads.) - #100058 (Suggest a positional formatting argument instead of a captured argument) - #100093 (Enable unused_parens for match arms) - #100095 (More EarlyBinder cleanups) - #100138 (Remove more Clean trait implementations) - #100148 (RustWrapper: update for TypedPointerType in LLVM) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3830eca + c2d7321 commit f6f9d5e

File tree

33 files changed

+381
-121
lines changed

33 files changed

+381
-121
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
377377

378378
fn print_string(&mut self, st: &str, style: ast::StrStyle) {
379379
let st = match style {
380-
ast::StrStyle::Cooked => (format!("\"{}\"", st.escape_debug())),
380+
ast::StrStyle::Cooked => format!("\"{}\"", st.escape_debug()),
381381
ast::StrStyle::Raw(n) => {
382382
format!("r{delim}\"{string}\"{delim}", delim = "#".repeat(n as usize), string = st)
383383
}

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ use rustc_middle::mir::{
1616
FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef,
1717
ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm,
1818
};
19-
use rustc_middle::ty::{
20-
self, subst::Subst, suggest_constraining_type_params, EarlyBinder, PredicateKind, Ty,
21-
};
19+
use rustc_middle::ty::{self, subst::Subst, suggest_constraining_type_params, PredicateKind, Ty};
2220
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
2321
use rustc_span::def_id::LocalDefId;
2422
use rustc_span::hygiene::DesugaringKind;
@@ -461,35 +459,37 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
461459
let tcx = self.infcx.tcx;
462460

463461
// Find out if the predicates show that the type is a Fn or FnMut
464-
let find_fn_kind_from_did = |predicates: &[(ty::Predicate<'tcx>, Span)], substs| {
465-
predicates.iter().find_map(|(pred, _)| {
466-
let pred = if let Some(substs) = substs {
467-
EarlyBinder(*pred).subst(tcx, substs).kind().skip_binder()
468-
} else {
469-
pred.kind().skip_binder()
470-
};
471-
if let ty::PredicateKind::Trait(pred) = pred && pred.self_ty() == ty {
462+
let find_fn_kind_from_did =
463+
|predicates: ty::EarlyBinder<&[(ty::Predicate<'tcx>, Span)]>, substs| {
464+
predicates.0.iter().find_map(|(pred, _)| {
465+
let pred = if let Some(substs) = substs {
466+
predicates.rebind(*pred).subst(tcx, substs).kind().skip_binder()
467+
} else {
468+
pred.kind().skip_binder()
469+
};
470+
if let ty::PredicateKind::Trait(pred) = pred && pred.self_ty() == ty {
472471
if Some(pred.def_id()) == tcx.lang_items().fn_trait() {
473472
return Some(hir::Mutability::Not);
474473
} else if Some(pred.def_id()) == tcx.lang_items().fn_mut_trait() {
475474
return Some(hir::Mutability::Mut);
476475
}
477476
}
478-
None
479-
})
480-
};
477+
None
478+
})
479+
};
481480

482481
// If the type is opaque/param/closure, and it is Fn or FnMut, let's suggest (mutably)
483482
// borrowing the type, since `&mut F: FnMut` iff `F: FnMut` and similarly for `Fn`.
484483
// These types seem reasonably opaque enough that they could be substituted with their
485484
// borrowed variants in a function body when we see a move error.
486485
let borrow_level = match ty.kind() {
487486
ty::Param(_) => find_fn_kind_from_did(
488-
tcx.explicit_predicates_of(self.mir_def_id().to_def_id()).predicates,
487+
tcx.bound_explicit_predicates_of(self.mir_def_id().to_def_id())
488+
.map_bound(|p| p.predicates),
489489
None,
490490
),
491491
ty::Opaque(did, substs) => {
492-
find_fn_kind_from_did(tcx.explicit_item_bounds(*did), Some(*substs))
492+
find_fn_kind_from_did(tcx.bound_explicit_item_bounds(*did), Some(*substs))
493493
}
494494
ty::Closure(_, substs) => match substs.as_closure().kind() {
495495
ty::ClosureKind::Fn => Some(hir::Mutability::Not),

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
839839
hir::Node::Expr(hir::Expr {
840840
kind: hir::ExprKind::Closure(&hir::Closure { fn_decl_span, .. }),
841841
..
842-
}) => (tcx.sess.source_map().end_point(fn_decl_span)),
842+
}) => tcx.sess.source_map().end_point(fn_decl_span),
843843
_ => self.body.span,
844844
};
845845

compiler/rustc_builtin_macros/src/format.rs

+32-8
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@ struct Context<'a, 'b> {
280280
unused_names_lint: PositionalNamedArgsLint,
281281
}
282282

283+
pub struct FormatArg {
284+
expr: P<ast::Expr>,
285+
named: bool,
286+
}
287+
283288
/// Parses the arguments from the given list of tokens, returning the diagnostic
284289
/// if there's a parse error so we can continue parsing other format!
285290
/// expressions.
@@ -293,8 +298,8 @@ fn parse_args<'a>(
293298
ecx: &mut ExtCtxt<'a>,
294299
sp: Span,
295300
tts: TokenStream,
296-
) -> PResult<'a, (P<ast::Expr>, Vec<P<ast::Expr>>, FxHashMap<Symbol, (usize, Span)>)> {
297-
let mut args = Vec::<P<ast::Expr>>::new();
301+
) -> PResult<'a, (P<ast::Expr>, Vec<FormatArg>, FxHashMap<Symbol, (usize, Span)>)> {
302+
let mut args = Vec::<FormatArg>::new();
298303
let mut names = FxHashMap::<Symbol, (usize, Span)>::default();
299304

300305
let mut p = ecx.new_parser_from_tts(tts);
@@ -362,7 +367,7 @@ fn parse_args<'a>(
362367
let e = p.parse_expr()?;
363368
if let Some((prev, _)) = names.get(&ident.name) {
364369
ecx.struct_span_err(e.span, &format!("duplicate argument named `{}`", ident))
365-
.span_label(args[*prev].span, "previously here")
370+
.span_label(args[*prev].expr.span, "previously here")
366371
.span_label(e.span, "duplicate argument")
367372
.emit();
368373
continue;
@@ -374,7 +379,7 @@ fn parse_args<'a>(
374379
// args. And remember the names.
375380
let slot = args.len();
376381
names.insert(ident.name, (slot, ident.span));
377-
args.push(e);
382+
args.push(FormatArg { expr: e, named: true });
378383
}
379384
_ => {
380385
let e = p.parse_expr()?;
@@ -385,11 +390,11 @@ fn parse_args<'a>(
385390
);
386391
err.span_label(e.span, "positional arguments must be before named arguments");
387392
for pos in names.values() {
388-
err.span_label(args[pos.0].span, "named argument");
393+
err.span_label(args[pos.0].expr.span, "named argument");
389394
}
390395
err.emit();
391396
}
392-
args.push(e);
397+
args.push(FormatArg { expr: e, named: false });
393398
}
394399
}
395400
}
@@ -1214,7 +1219,7 @@ pub fn expand_preparsed_format_args(
12141219
ecx: &mut ExtCtxt<'_>,
12151220
sp: Span,
12161221
efmt: P<ast::Expr>,
1217-
args: Vec<P<ast::Expr>>,
1222+
args: Vec<FormatArg>,
12181223
names: FxHashMap<Symbol, (usize, Span)>,
12191224
append_newline: bool,
12201225
) -> P<ast::Expr> {
@@ -1304,6 +1309,25 @@ pub fn expand_preparsed_format_args(
13041309
e.span_label(fmt_span.from_inner(InnerSpan::new(span.start, span.end)), label);
13051310
}
13061311
}
1312+
if err.should_be_replaced_with_positional_argument {
1313+
let captured_arg_span =
1314+
fmt_span.from_inner(InnerSpan::new(err.span.start, err.span.end));
1315+
let positional_args = args.iter().filter(|arg| !arg.named).collect::<Vec<_>>();
1316+
if let Ok(arg) = ecx.source_map().span_to_snippet(captured_arg_span) {
1317+
let span = match positional_args.last() {
1318+
Some(arg) => arg.expr.span,
1319+
None => fmt_sp,
1320+
};
1321+
e.multipart_suggestion_verbose(
1322+
"consider using a positional formatting argument instead",
1323+
vec![
1324+
(captured_arg_span, positional_args.len().to_string()),
1325+
(span.shrink_to_hi(), format!(", {}", arg)),
1326+
],
1327+
Applicability::MachineApplicable,
1328+
);
1329+
}
1330+
}
13071331
e.emit();
13081332
return DummyResult::raw_expr(sp, true);
13091333
}
@@ -1318,7 +1342,7 @@ pub fn expand_preparsed_format_args(
13181342

13191343
let mut cx = Context {
13201344
ecx,
1321-
args,
1345+
args: args.into_iter().map(|arg| arg.expr).collect(),
13221346
num_captured_args: 0,
13231347
arg_types,
13241348
arg_unique_types,

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::mir::pretty::display_allocation;
1313
use rustc_middle::traits::Reveal;
1414
use rustc_middle::ty::layout::LayoutOf;
1515
use rustc_middle::ty::print::with_no_trimmed_paths;
16-
use rustc_middle::ty::{self, subst::Subst, EarlyBinder, TyCtxt};
16+
use rustc_middle::ty::{self, subst::Subst, TyCtxt};
1717
use rustc_span::source_map::Span;
1818
use rustc_target::abi::{self, Abi};
1919
use std::borrow::Cow;
@@ -45,7 +45,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
4545
"Unexpected DefKind: {:?}",
4646
ecx.tcx.def_kind(cid.instance.def_id())
4747
);
48-
let layout = ecx.layout_of(EarlyBinder(body.return_ty()).subst(tcx, cid.instance.substs))?;
48+
let layout = ecx.layout_of(body.bound_return_ty().subst(tcx, cid.instance.substs))?;
4949
assert!(!layout.is_unsized());
5050
let ret = ecx.allocate(layout, MemoryKind::Stack)?;
5151

compiler/rustc_lint/src/unused.rs

+14
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ enum UnusedDelimsCtx {
396396
LetScrutineeExpr,
397397
ArrayLenExpr,
398398
AnonConst,
399+
MatchArmExpr,
399400
}
400401

401402
impl From<UnusedDelimsCtx> for &'static str {
@@ -414,6 +415,7 @@ impl From<UnusedDelimsCtx> for &'static str {
414415
UnusedDelimsCtx::BlockRetValue => "block return value",
415416
UnusedDelimsCtx::LetScrutineeExpr => "`let` scrutinee expression",
416417
UnusedDelimsCtx::ArrayLenExpr | UnusedDelimsCtx::AnonConst => "const expression",
418+
UnusedDelimsCtx::MatchArmExpr => "match arm expression",
417419
}
418420
}
419421
}
@@ -805,6 +807,18 @@ impl EarlyLintPass for UnusedParens {
805807
}
806808
return;
807809
}
810+
ExprKind::Match(ref _expr, ref arm) => {
811+
for a in arm {
812+
self.check_unused_delims_expr(
813+
cx,
814+
&a.body,
815+
UnusedDelimsCtx::MatchArmExpr,
816+
false,
817+
None,
818+
None,
819+
);
820+
}
821+
}
808822
_ => {}
809823
}
810824

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -1311,10 +1311,15 @@ extern "C" LLVMTypeKind LLVMRustGetTypeKind(LLVMTypeRef Ty) {
13111311
return LLVMBFloatTypeKind;
13121312
case Type::X86_AMXTyID:
13131313
return LLVMX86_AMXTypeKind;
1314-
#if LLVM_VERSION_GE(15, 0)
1314+
#if LLVM_VERSION_GE(15, 0) && LLVM_VERSION_LT(16, 0)
13151315
case Type::DXILPointerTyID:
13161316
report_fatal_error("Rust does not support DirectX typed pointers.");
13171317
break;
1318+
#endif
1319+
#if LLVM_VERSION_GE(16, 0)
1320+
case Type::TypedPointerTyID:
1321+
report_fatal_error("Rust does not support typed pointers.");
1322+
break;
13181323
#endif
13191324
}
13201325
report_fatal_error("Unhandled TypeID.");

compiler/rustc_middle/src/mir/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,12 @@ impl<'tcx> Body<'tcx> {
431431
self.local_decls[RETURN_PLACE].ty
432432
}
433433

434+
/// Returns the return type; it always return first element from `local_decls` array.
435+
#[inline]
436+
pub fn bound_return_ty(&self) -> ty::EarlyBinder<Ty<'tcx>> {
437+
ty::EarlyBinder(self.local_decls[RETURN_PLACE].ty)
438+
}
439+
434440
/// Gets the location of the terminator for the given block.
435441
#[inline]
436442
pub fn terminator_loc(&self, bb: BasicBlock) -> Location {

compiler/rustc_middle/src/ty/adt.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ impl<'tcx> AdtDef<'tcx> {
563563
///
564564
/// Due to normalization being eager, this applies even if
565565
/// the associated type is behind a pointer (e.g., issue #31299).
566-
pub fn sized_constraint(self, tcx: TyCtxt<'tcx>) -> &'tcx [Ty<'tcx>] {
567-
tcx.adt_sized_constraint(self.did()).0
566+
pub fn sized_constraint(self, tcx: TyCtxt<'tcx>) -> ty::EarlyBinder<&'tcx [Ty<'tcx>]> {
567+
ty::EarlyBinder(tcx.adt_sized_constraint(self.did()).0)
568568
}
569569
}

compiler/rustc_middle/src/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2191,7 +2191,7 @@ impl<'tcx> Ty<'tcx> {
21912191

21922192
ty::Tuple(tys) => tys.iter().all(|ty| ty.is_trivially_sized(tcx)),
21932193

2194-
ty::Adt(def, _substs) => def.sized_constraint(tcx).is_empty(),
2194+
ty::Adt(def, _substs) => def.sized_constraint(tcx).0.is_empty(),
21952195

21962196
ty::Projection(_) | ty::Param(_) | ty::Opaque(..) => false,
21972197

compiler/rustc_middle/src/ty/util.rs

+18
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,24 @@ impl<'tcx> TyCtxt<'tcx> {
680680
pub fn bound_const_param_default(self, def_id: DefId) -> ty::EarlyBinder<ty::Const<'tcx>> {
681681
ty::EarlyBinder(self.const_param_default(def_id))
682682
}
683+
684+
pub fn bound_predicates_of(
685+
self,
686+
def_id: DefId,
687+
) -> ty::EarlyBinder<ty::generics::GenericPredicates<'tcx>> {
688+
ty::EarlyBinder(self.predicates_of(def_id))
689+
}
690+
691+
pub fn bound_explicit_predicates_of(
692+
self,
693+
def_id: DefId,
694+
) -> ty::EarlyBinder<ty::generics::GenericPredicates<'tcx>> {
695+
ty::EarlyBinder(self.explicit_predicates_of(def_id))
696+
}
697+
698+
pub fn bound_impl_subject(self, def_id: DefId) -> ty::EarlyBinder<ty::ImplSubject<'tcx>> {
699+
ty::EarlyBinder(self.impl_subject(def_id))
700+
}
683701
}
684702

685703
struct OpaqueTypeExpander<'tcx> {

compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ impl SplitVarLenSlice {
617617
// The only admissible fixed-length slice is one of the array size. Whether `max_slice`
618618
// is fixed-length or variable-length, it will be the only relevant slice to output
619619
// here.
620-
Some(_) => (0..0), // empty range
620+
Some(_) => 0..0, // empty range
621621
// We cover all arities in the range `(self.arity..infinity)`. We split that range into
622622
// two: lengths smaller than `max_slice.arity()` are treated independently as
623623
// fixed-lengths slices, and lengths above are captured by `max_slice`.

compiler/rustc_mir_transform/src/const_prop.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ use rustc_middle::mir::{
1818
};
1919
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
2020
use rustc_middle::ty::subst::{InternalSubsts, Subst};
21-
use rustc_middle::ty::{
22-
self, ConstKind, EarlyBinder, Instance, ParamEnv, Ty, TyCtxt, TypeVisitable,
23-
};
21+
use rustc_middle::ty::{self, ConstKind, Instance, ParamEnv, Ty, TyCtxt, TypeVisitable};
2422
use rustc_span::{def_id::DefId, Span};
2523
use rustc_target::abi::{self, HasDataLayout, Size, TargetDataLayout};
2624
use rustc_target::spec::abi::Abi as CallAbi;
@@ -387,7 +385,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
387385
);
388386

389387
let ret_layout = ecx
390-
.layout_of(EarlyBinder(body.return_ty()).subst(tcx, substs))
388+
.layout_of(body.bound_return_ty().subst(tcx, substs))
391389
.ok()
392390
// Don't bother allocating memory for large values.
393391
// I don't know how return types can seem to be unsized but this happens in the

compiler/rustc_mir_transform/src/const_prop_lint.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ use rustc_middle::mir::{
2323
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
2424
use rustc_middle::ty::subst::{InternalSubsts, Subst};
2525
use rustc_middle::ty::{
26-
self, ConstInt, ConstKind, EarlyBinder, Instance, ParamEnv, ScalarInt, Ty, TyCtxt,
27-
TypeVisitable,
26+
self, ConstInt, ConstKind, Instance, ParamEnv, ScalarInt, Ty, TyCtxt, TypeVisitable,
2827
};
2928
use rustc_session::lint;
3029
use rustc_span::Span;
@@ -196,7 +195,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
196195
);
197196

198197
let ret_layout = ecx
199-
.layout_of(EarlyBinder(body.return_ty()).subst(tcx, substs))
198+
.layout_of(body.bound_return_ty().subst(tcx, substs))
200199
.ok()
201200
// Don't bother allocating memory for large values.
202201
// I don't know how return types can seem to be unsized but this happens in the

compiler/rustc_parse/src/parser/diagnostics.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ impl<'a> Parser<'a> {
560560
|| (sm.is_multiline(
561561
self.prev_token.span.shrink_to_hi().until(self.token.span.shrink_to_lo())
562562
) && t == &token::Pound)
563-
}) {
563+
}) && !expected.contains(&TokenType::Token(token::Comma))
564+
{
564565
// Missing semicolon typo. This is triggered if the next token could either start a
565566
// new statement or is a block close. For example:
566567
//

0 commit comments

Comments
 (0)