Skip to content

Commit a474ebb

Browse files
committed
Auto merge of rust-lang#105883 - matthiaskrgr:rollup-v5n53t1, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#105419 (Add tests for rust-lang#41731) - rust-lang#105447 (Add a test for rust-lang#103095) - rust-lang#105842 (print argument name in arg mismatch if possible) - rust-lang#105863 (Update browser-ui-test version to reduce GUI tests flakyness) - rust-lang#105867 (remove redundant fn params that were only "used" in recursion) - rust-lang#105869 (don't clone Copy types) - rust-lang#105873 (use &str / String literals instead of format!()) - rust-lang#105879 (Revert "Introduce lowering_arena to avoid creating AST nodes on the fly") Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2b094b1 + 87a4694 commit a474ebb

File tree

44 files changed

+236
-162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+236
-162
lines changed

compiler/rustc_ast_lowering/src/item.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::errors::{InvalidAbi, InvalidAbiSuggestion, MisplacedRelaxTraitBound};
22
use super::ResolverAstLoweringExt;
3-
use super::{Arena, AstOwner, ImplTraitContext, ImplTraitPosition};
3+
use super::{AstOwner, ImplTraitContext, ImplTraitPosition};
44
use super::{FnDeclKind, LoweringContext, ParamMode};
55

66
use rustc_ast::ptr::P;
@@ -24,7 +24,6 @@ use thin_vec::ThinVec;
2424
pub(super) struct ItemLowerer<'a, 'hir> {
2525
pub(super) tcx: TyCtxt<'hir>,
2626
pub(super) resolver: &'a mut ResolverAstLowering,
27-
pub(super) ast_arena: &'a Arena<'static>,
2827
pub(super) ast_index: &'a IndexVec<LocalDefId, AstOwner<'a>>,
2928
pub(super) owners: &'a mut IndexVec<LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>>,
3029
}
@@ -60,7 +59,6 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
6059
tcx: self.tcx,
6160
resolver: self.resolver,
6261
arena: self.tcx.hir_arena,
63-
ast_arena: self.ast_arena,
6462

6563
// HirId handling.
6664
bodies: Vec::new(),

compiler/rustc_ast_lowering/src/lib.rs

+20-35
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ extern crate tracing;
4242

4343
use crate::errors::{AssocTyParentheses, AssocTyParenthesesSub, MisplacedImplTrait, TraitFnAsync};
4444

45-
use rustc_arena::declare_arena;
4645
use rustc_ast::ptr::P;
4746
use rustc_ast::visit;
4847
use rustc_ast::{self as ast, *};
@@ -94,13 +93,6 @@ struct LoweringContext<'a, 'hir> {
9493
/// Used to allocate HIR nodes.
9594
arena: &'hir hir::Arena<'hir>,
9695

97-
/// Used to allocate temporary AST nodes for use during lowering.
98-
/// This allows us to create "fake" AST -- these nodes can sometimes
99-
/// be allocated on the stack, but other times we need them to live longer
100-
/// than the current stack frame, so they can be collected into vectors
101-
/// and things like that.
102-
ast_arena: &'a Arena<'static>,
103-
10496
/// Bodies inside the owner being lowered.
10597
bodies: Vec<(hir::ItemLocalId, &'hir hir::Body<'hir>)>,
10698
/// Attributes inside the owner being lowered.
@@ -146,15 +138,6 @@ struct LoweringContext<'a, 'hir> {
146138
generics_def_id_map: Vec<FxHashMap<LocalDefId, LocalDefId>>,
147139
}
148140

149-
declare_arena!([
150-
[] tys: rustc_ast::Ty,
151-
[] aba: rustc_ast::AngleBracketedArgs,
152-
[] ptr: rustc_ast::PolyTraitRef,
153-
// This _marker field is needed because `declare_arena` creates `Arena<'tcx>` and we need to
154-
// use `'tcx`. If we don't have this we get a compile error.
155-
[] _marker: std::marker::PhantomData<&'tcx ()>,
156-
]);
157-
158141
trait ResolverAstLoweringExt {
159142
fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>>;
160143
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes>;
@@ -442,13 +425,10 @@ pub fn lower_to_hir<'hir>(tcx: TyCtxt<'hir>, (): ()) -> hir::Crate<'hir> {
442425
tcx.definitions_untracked().def_index_count(),
443426
);
444427

445-
let ast_arena = Arena::default();
446-
447428
for def_id in ast_index.indices() {
448429
item::ItemLowerer {
449430
tcx,
450431
resolver: &mut resolver,
451-
ast_arena: &ast_arena,
452432
ast_index: &ast_index,
453433
owners: &mut owners,
454434
}
@@ -1001,8 +981,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1001981
}
1002982
GenericArgs::Parenthesized(data) => {
1003983
self.emit_bad_parenthesized_trait_in_assoc_ty(data);
1004-
let aba = self.ast_arena.aba.alloc(data.as_angle_bracketed_args());
1005-
self.lower_angle_bracketed_parameter_data(aba, ParamMode::Explicit, itctx).0
984+
self.lower_angle_bracketed_parameter_data(
985+
&data.as_angle_bracketed_args(),
986+
ParamMode::Explicit,
987+
itctx,
988+
)
989+
.0
1006990
}
1007991
};
1008992
gen_args_ctor.into_generic_args(self)
@@ -1067,13 +1051,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10671051

10681052
self.with_dyn_type_scope(false, |this| {
10691053
let node_id = this.next_node_id();
1070-
let ty = this.ast_arena.tys.alloc(Ty {
1071-
id: node_id,
1072-
kind: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()),
1073-
span: this.lower_span(constraint.span),
1074-
tokens: None,
1075-
});
1076-
let ty = this.lower_ty(ty, itctx);
1054+
let ty = this.lower_ty(
1055+
&Ty {
1056+
id: node_id,
1057+
kind: TyKind::ImplTrait(impl_trait_node_id, bounds.clone()),
1058+
span: this.lower_span(constraint.span),
1059+
tokens: None,
1060+
},
1061+
itctx,
1062+
);
10771063

10781064
hir::TypeBindingKind::Equality { term: ty.into() }
10791065
})
@@ -1217,13 +1203,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12171203
&& let Some(Res::Def(DefKind::Trait | DefKind::TraitAlias, _)) = partial_res.full_res()
12181204
{
12191205
let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| {
1220-
let poly_trait_ref = this.ast_arena.ptr.alloc(PolyTraitRef {
1221-
bound_generic_params: vec![],
1222-
trait_ref: TraitRef { path: path.clone(), ref_id: t.id },
1223-
span: t.span
1224-
});
12251206
let bound = this.lower_poly_trait_ref(
1226-
poly_trait_ref,
1207+
&PolyTraitRef {
1208+
bound_generic_params: vec![],
1209+
trait_ref: TraitRef { path: path.clone(), ref_id: t.id },
1210+
span: t.span
1211+
},
12271212
itctx,
12281213
);
12291214
let bounds = this.arena.alloc_from_iter([bound]);

compiler/rustc_borrowck/src/constraints/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl<'s, 'tcx, D: ConstraintGraphDirecton> Iterator for Edges<'s, 'tcx, D> {
148148
if let Some(p) = self.pointer {
149149
self.pointer = self.graph.next_constraints[p];
150150

151-
Some(self.constraints[p].clone())
151+
Some(self.constraints[p])
152152
} else if let Some(next_static_idx) = self.next_static_idx {
153153
self.next_static_idx = if next_static_idx == (self.graph.first_constraints.len() - 1) {
154154
None

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
649649
if !assign_value.is_empty() {
650650
err.span_suggestion_verbose(
651651
sugg_span.shrink_to_hi(),
652-
format!("consider assigning a value"),
652+
"consider assigning a value",
653653
format!(" = {}", assign_value),
654654
Applicability::MaybeIncorrect,
655655
);

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
270270
for extra in extra_info {
271271
match extra {
272272
ExtraConstraintInfo::PlaceholderFromPredicate(span) => {
273-
err.span_note(*span, format!("due to current limitations in the borrow checker, this implies a `'static` lifetime"));
273+
err.span_note(*span, "due to current limitations in the borrow checker, this implies a `'static` lifetime");
274274
}
275275
}
276276
}

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
472472
for extra in extra_info {
473473
match extra {
474474
ExtraConstraintInfo::PlaceholderFromPredicate(span) => {
475-
diag.span_note(span, format!("due to current limitations in the borrow checker, this implies a `'static` lifetime"));
475+
diag.span_note(span, "due to current limitations in the borrow checker, this implies a `'static` lifetime");
476476
}
477477
}
478478
}

compiler/rustc_borrowck/src/region_infer/mod.rs

+3-26
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
831831
if self.eval_verify_bound(
832832
infcx,
833833
param_env,
834-
body,
835834
generic_ty,
836835
type_test.lower_bound,
837836
&type_test.verify_bound,
@@ -962,14 +961,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
962961
// where `ur` is a local bound -- we are sometimes in a
963962
// position to prove things that our caller cannot. See
964963
// #53570 for an example.
965-
if self.eval_verify_bound(
966-
infcx,
967-
param_env,
968-
body,
969-
generic_ty,
970-
ur,
971-
&type_test.verify_bound,
972-
) {
964+
if self.eval_verify_bound(infcx, param_env, generic_ty, ur, &type_test.verify_bound) {
973965
continue;
974966
}
975967

@@ -1190,7 +1182,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
11901182
&self,
11911183
infcx: &InferCtxt<'tcx>,
11921184
param_env: ty::ParamEnv<'tcx>,
1193-
body: &Body<'tcx>,
11941185
generic_ty: Ty<'tcx>,
11951186
lower_bound: RegionVid,
11961187
verify_bound: &VerifyBound<'tcx>,
@@ -1213,25 +1204,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12131204
}
12141205

12151206
VerifyBound::AnyBound(verify_bounds) => verify_bounds.iter().any(|verify_bound| {
1216-
self.eval_verify_bound(
1217-
infcx,
1218-
param_env,
1219-
body,
1220-
generic_ty,
1221-
lower_bound,
1222-
verify_bound,
1223-
)
1207+
self.eval_verify_bound(infcx, param_env, generic_ty, lower_bound, verify_bound)
12241208
}),
12251209

12261210
VerifyBound::AllBounds(verify_bounds) => verify_bounds.iter().all(|verify_bound| {
1227-
self.eval_verify_bound(
1228-
infcx,
1229-
param_env,
1230-
body,
1231-
generic_ty,
1232-
lower_bound,
1233-
verify_bound,
1234-
)
1211+
self.eval_verify_bound(infcx, param_env, generic_ty, lower_bound, verify_bound)
12351212
}),
12361213
}
12371214
}

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
612612

613613
let locations = location.to_locations();
614614
for constraint in constraints.outlives().iter() {
615-
let mut constraint = constraint.clone();
615+
let mut constraint = *constraint;
616616
constraint.locations = locations;
617617
if let ConstraintCategory::Return(_)
618618
| ConstraintCategory::UseAsConst

compiler/rustc_codegen_llvm/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<'ll, 'tcx> AsmBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
144144
// We prefer the latter because it matches the behavior of
145145
// Clang.
146146
if late && matches!(reg, InlineAsmRegOrRegClass::Reg(_)) {
147-
constraints.push(format!("{}", reg_to_llvm(reg, Some(&in_value.layout))));
147+
constraints.push(reg_to_llvm(reg, Some(&in_value.layout)).to_string());
148148
} else {
149149
constraints.push(format!("{}", op_idx[&idx]));
150150
}

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2240,7 +2240,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
22402240
),
22412241
"s",
22422242
),
2243-
[only] => (format!("{only}"), ""),
2243+
[only] => (only.to_string(), ""),
22442244
[] => unreachable!(),
22452245
};
22462246
let last_span = *arg_spans.last().unwrap();

compiler/rustc_hir_analysis/src/check/check.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,17 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
9999
ty: Ty<'tcx>,
100100
tcx: TyCtxt<'tcx>,
101101
param_env: ty::ParamEnv<'tcx>,
102-
span: Span,
103102
) -> bool {
104103
// We don't just accept all !needs_drop fields, due to semver concerns.
105104
match ty.kind() {
106105
ty::Ref(..) => true, // references never drop (even mutable refs, which are non-Copy and hence fail the later check)
107106
ty::Tuple(tys) => {
108107
// allow tuples of allowed types
109-
tys.iter().all(|ty| allowed_union_field(ty, tcx, param_env, span))
108+
tys.iter().all(|ty| allowed_union_field(ty, tcx, param_env))
110109
}
111110
ty::Array(elem, _len) => {
112111
// Like `Copy`, we do *not* special-case length 0.
113-
allowed_union_field(*elem, tcx, param_env, span)
112+
allowed_union_field(*elem, tcx, param_env)
114113
}
115114
_ => {
116115
// Fallback case: allow `ManuallyDrop` and things that are `Copy`.
@@ -124,7 +123,7 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b
124123
for field in &def.non_enum_variant().fields {
125124
let field_ty = field.ty(tcx, substs);
126125

127-
if !allowed_union_field(field_ty, tcx, param_env, span) {
126+
if !allowed_union_field(field_ty, tcx, param_env) {
128127
let (field_span, ty_span) = match tcx.hir().get_if_local(field.did) {
129128
// We are currently checking the type this field came from, so it must be local.
130129
Some(Node::Field(field)) => (field.span, field.ty.span),

compiler/rustc_hir_typeck/src/coercion.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15481548
cause,
15491549
expected,
15501550
found,
1551-
coercion_error.clone(),
1551+
coercion_error,
15521552
fcx,
15531553
parent_id,
15541554
expression,
@@ -1567,7 +1567,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15671567
cause,
15681568
expected,
15691569
found,
1570-
coercion_error.clone(),
1570+
coercion_error,
15711571
fcx,
15721572
id,
15731573
expression,
@@ -1583,7 +1583,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
15831583
cause,
15841584
expected,
15851585
found,
1586-
coercion_error.clone(),
1586+
coercion_error,
15871587
);
15881588
}
15891589
}

compiler/rustc_hir_typeck/src/demand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
163163
let expr = expr.peel_drop_temps();
164164
let cause = self.misc(expr.span);
165165
let expr_ty = self.resolve_vars_with_obligations(checked_ty);
166-
let mut err = self.err_ctxt().report_mismatched_types(&cause, expected, expr_ty, e.clone());
166+
let mut err = self.err_ctxt().report_mismatched_types(&cause, expected, expr_ty, e);
167167

168168
let is_insufficiently_polymorphic =
169169
matches!(e, TypeError::RegionsInsufficientlyPolymorphic(..));
@@ -406,7 +406,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
406406
}
407407

408408
let note_about_variant_field_privacy = (field_is_local && !field_is_accessible)
409-
.then(|| format!(" (its field is private, but it's local to this crate and its privacy can be changed)"));
409+
.then(|| " (its field is private, but it's local to this crate and its privacy can be changed)".to_string());
410410

411411
let sole_field_ty = sole_field.ty(self.tcx, substs);
412412
if self.can_coerce(expr_ty, sole_field_ty) {

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_middle::ty::adjustment::AllowTwoPhase;
2828
use rustc_middle::ty::visit::TypeVisitable;
2929
use rustc_middle::ty::{self, DefIdTree, IsSuggestable, Ty, TypeSuperVisitable, TypeVisitor};
3030
use rustc_session::Session;
31-
use rustc_span::symbol::Ident;
31+
use rustc_span::symbol::{kw, Ident};
3232
use rustc_span::{self, sym, Span};
3333
use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext};
3434

@@ -1013,7 +1013,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10131013
} else {
10141014
args_span
10151015
};
1016-
labels.push((span, format!("multiple arguments are missing")));
1016+
labels.push((span, "multiple arguments are missing".to_string()));
10171017
suggestion_text = match suggestion_text {
10181018
SuggestionText::None | SuggestionText::Provide(_) => {
10191019
SuggestionText::Provide(true)
@@ -1141,6 +1141,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11411141
"()".to_string()
11421142
} else if expected_ty.is_suggestable(tcx, false) {
11431143
format!("/* {} */", expected_ty)
1144+
} else if let Some(fn_def_id) = fn_def_id
1145+
&& self.tcx.def_kind(fn_def_id).is_fn_like()
1146+
&& let self_implicit = matches!(call_expr.kind, hir::ExprKind::MethodCall(..)) as usize
1147+
&& let Some(arg) = self.tcx.fn_arg_names(fn_def_id).get(expected_idx.as_usize() + self_implicit)
1148+
&& arg.name != kw::SelfLower
1149+
{
1150+
format!("/* {} */", arg.name)
11441151
} else {
11451152
"/* value */".to_string()
11461153
}

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
319319
}
320320
}
321321

322-
err.multipart_suggestion_verbose(
323-
format!("use parentheses to call these"),
324-
sugg,
325-
applicability,
326-
);
322+
err.multipart_suggestion_verbose("use parentheses to call these", sugg, applicability);
327323

328324
true
329325
} else {

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10071007
if def_kind == DefKind::AssocFn && lev_candidate.fn_has_self_parameter {
10081008
err.span_suggestion(
10091009
span,
1010-
&format!("there is a method with a similar name",),
1010+
"there is a method with a similar name",
10111011
lev_candidate.name,
10121012
Applicability::MaybeIncorrect,
10131013
);

0 commit comments

Comments
 (0)