Skip to content

Commit e9b7bf0

Browse files
committed
Auto merge of #118434 - matthiaskrgr:rollup-k1upt8b, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #118342 (Dont suggest `!` for path in function call if it has generic args) - #118383 (Address unused tuple struct fields in the standard library) - #118401 (`rustc_ast_lowering` cleanups) - #118409 (format_foreign.rs: unwrap return Option value for `fn position`, as it always returns Some) - #118413 (Fix the issue of suggesting unwrap/expect for shorthand field) - #118425 (Update cargo) - #118429 (Fix a typo in a `format_args!` note) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f440b5f + 0687dcb commit e9b7bf0

25 files changed

+490
-133
lines changed

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -530,15 +530,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
530530
this.mark_span_with_reason(
531531
DesugaringKind::TryBlock,
532532
expr.span,
533-
this.allow_try_trait.clone(),
533+
Some(this.allow_try_trait.clone()),
534534
),
535535
expr,
536536
)
537537
} else {
538538
let try_span = this.mark_span_with_reason(
539539
DesugaringKind::TryBlock,
540540
this.tcx.sess.source_map().end_point(body.span),
541-
this.allow_try_trait.clone(),
541+
Some(this.allow_try_trait.clone()),
542542
);
543543

544544
(try_span, this.expr_unit(try_span))
@@ -618,8 +618,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
618618
let output = ret_ty.unwrap_or_else(|| hir::FnRetTy::DefaultReturn(self.lower_span(span)));
619619

620620
// Resume argument type: `ResumeTy`
621-
let unstable_span =
622-
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
621+
let unstable_span = self.mark_span_with_reason(
622+
DesugaringKind::Async,
623+
span,
624+
Some(self.allow_gen_future.clone()),
625+
);
623626
let resume_ty = hir::QPath::LangItem(hir::LangItem::ResumeTy, unstable_span);
624627
let input_ty = hir::Ty {
625628
hir_id: self.next_id(),
@@ -741,7 +744,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
741744
let unstable_span = self.mark_span_with_reason(
742745
DesugaringKind::Async,
743746
span,
744-
self.allow_gen_future.clone(),
747+
Some(self.allow_gen_future.clone()),
745748
);
746749
self.lower_attrs(
747750
inner_hir_id,
@@ -788,7 +791,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
788791
let gen_future_span = self.mark_span_with_reason(
789792
DesugaringKind::Await,
790793
full_span,
791-
self.allow_gen_future.clone(),
794+
Some(self.allow_gen_future.clone()),
792795
);
793796
let expr = self.lower_expr_mut(expr);
794797
let expr_hir_id = expr.hir_id;
@@ -1646,13 +1649,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
16461649
let unstable_span = self.mark_span_with_reason(
16471650
DesugaringKind::QuestionMark,
16481651
span,
1649-
self.allow_try_trait.clone(),
1652+
Some(self.allow_try_trait.clone()),
16501653
);
16511654
let try_span = self.tcx.sess.source_map().end_point(span);
16521655
let try_span = self.mark_span_with_reason(
16531656
DesugaringKind::QuestionMark,
16541657
try_span,
1655-
self.allow_try_trait.clone(),
1658+
Some(self.allow_try_trait.clone()),
16561659
);
16571660

16581661
// `Try::branch(<expr>)`
@@ -1745,7 +1748,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17451748
let unstable_span = self.mark_span_with_reason(
17461749
DesugaringKind::YeetExpr,
17471750
span,
1748-
self.allow_try_trait.clone(),
1751+
Some(self.allow_try_trait.clone()),
17491752
);
17501753

17511754
let from_yeet_expr = self.wrap_in_try_constructor(

Diff for: compiler/rustc_ast_lowering/src/index.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::ty::TyCtxt;
1010
use rustc_span::{Span, DUMMY_SP};
1111

1212
/// A visitor that walks over the HIR and collects `Node`s into a HIR map.
13-
pub(super) struct NodeCollector<'a, 'hir> {
13+
struct NodeCollector<'a, 'hir> {
1414
tcx: TyCtxt<'hir>,
1515

1616
bodies: &'a SortedMap<ItemLocalId, &'hir Body<'hir>>,

Diff for: compiler/rustc_ast_lowering/src/item.rs

+38-68
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use hir::definitions::DefPathData;
77
use rustc_ast::ptr::P;
88
use rustc_ast::visit::AssocCtxt;
99
use rustc_ast::*;
10-
use rustc_data_structures::sorted_map::SortedMap;
1110
use rustc_errors::ErrorGuaranteed;
1211
use rustc_hir as hir;
1312
use rustc_hir::def::{DefKind, Res};
@@ -55,42 +54,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
5554
owner: NodeId,
5655
f: impl FnOnce(&mut LoweringContext<'_, 'hir>) -> hir::OwnerNode<'hir>,
5756
) {
58-
let allow_gen_future = Some(if self.tcx.features().async_fn_track_caller {
59-
[sym::gen_future, sym::closure_track_caller][..].into()
60-
} else {
61-
[sym::gen_future][..].into()
62-
});
63-
let mut lctx = LoweringContext {
64-
// Pseudo-globals.
65-
tcx: self.tcx,
66-
resolver: self.resolver,
67-
arena: self.tcx.hir_arena,
68-
69-
// HirId handling.
70-
bodies: Vec::new(),
71-
attrs: SortedMap::default(),
72-
children: Vec::default(),
73-
current_hir_id_owner: hir::CRATE_OWNER_ID,
74-
item_local_id_counter: hir::ItemLocalId::new(0),
75-
node_id_to_local_id: Default::default(),
76-
trait_map: Default::default(),
77-
78-
// Lowering state.
79-
catch_scope: None,
80-
loop_scope: None,
81-
is_in_loop_condition: false,
82-
is_in_trait_impl: false,
83-
is_in_dyn_type: false,
84-
coroutine_kind: None,
85-
task_context: None,
86-
current_item: None,
87-
impl_trait_defs: Vec::new(),
88-
impl_trait_bounds: Vec::new(),
89-
allow_try_trait: Some([sym::try_trait_v2, sym::yeet_desugar_details][..].into()),
90-
allow_gen_future,
91-
generics_def_id_map: Default::default(),
92-
host_param_id: None,
93-
};
57+
let mut lctx = LoweringContext::new(self.tcx, self.resolver);
9458
lctx.with_hir_id_owner(owner, |lctx| f(lctx));
9559

9660
for (def_id, info) in lctx.children {
@@ -136,39 +100,9 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
136100

137101
fn lower_assoc_item(&mut self, item: &AssocItem, ctxt: AssocCtxt) {
138102
let def_id = self.resolver.node_id_to_def_id[&item.id];
139-
140103
let parent_id = self.tcx.local_parent(def_id);
141104
let parent_hir = self.lower_node(parent_id).unwrap();
142-
self.with_lctx(item.id, |lctx| {
143-
// Evaluate with the lifetimes in `params` in-scope.
144-
// This is used to track which lifetimes have already been defined,
145-
// and which need to be replicated when lowering an async fn.
146-
147-
match parent_hir.node().expect_item().kind {
148-
hir::ItemKind::Impl(impl_) => {
149-
lctx.is_in_trait_impl = impl_.of_trait.is_some();
150-
}
151-
hir::ItemKind::Trait(_, _, generics, _, _) if lctx.tcx.features().effects => {
152-
lctx.host_param_id = generics
153-
.params
154-
.iter()
155-
.find(|param| {
156-
parent_hir
157-
.attrs
158-
.get(param.hir_id.local_id)
159-
.iter()
160-
.any(|attr| attr.has_name(sym::rustc_host))
161-
})
162-
.map(|param| param.def_id);
163-
}
164-
_ => {}
165-
}
166-
167-
match ctxt {
168-
AssocCtxt::Trait => hir::OwnerNode::TraitItem(lctx.lower_trait_item(item)),
169-
AssocCtxt::Impl => hir::OwnerNode::ImplItem(lctx.lower_impl_item(item)),
170-
}
171-
})
105+
self.with_lctx(item.id, |lctx| lctx.lower_assoc_item(item, ctxt, parent_hir))
172106
}
173107

174108
fn lower_foreign_item(&mut self, item: &ForeignItem) {
@@ -611,6 +545,42 @@ impl<'hir> LoweringContext<'_, 'hir> {
611545
}
612546
}
613547

548+
fn lower_assoc_item(
549+
&mut self,
550+
item: &AssocItem,
551+
ctxt: AssocCtxt,
552+
parent_hir: &'hir hir::OwnerInfo<'hir>,
553+
) -> hir::OwnerNode<'hir> {
554+
// Evaluate with the lifetimes in `params` in-scope.
555+
// This is used to track which lifetimes have already been defined,
556+
// and which need to be replicated when lowering an async fn.
557+
558+
match parent_hir.node().expect_item().kind {
559+
hir::ItemKind::Impl(impl_) => {
560+
self.is_in_trait_impl = impl_.of_trait.is_some();
561+
}
562+
hir::ItemKind::Trait(_, _, generics, _, _) if self.tcx.features().effects => {
563+
self.host_param_id = generics
564+
.params
565+
.iter()
566+
.find(|param| {
567+
parent_hir
568+
.attrs
569+
.get(param.hir_id.local_id)
570+
.iter()
571+
.any(|attr| attr.has_name(sym::rustc_host))
572+
})
573+
.map(|param| param.def_id);
574+
}
575+
_ => {}
576+
}
577+
578+
match ctxt {
579+
AssocCtxt::Trait => hir::OwnerNode::TraitItem(self.lower_trait_item(item)),
580+
AssocCtxt::Impl => hir::OwnerNode::ImplItem(self.lower_impl_item(item)),
581+
}
582+
}
583+
614584
fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
615585
let hir_id = self.lower_node_id(i.id);
616586
let owner_id = hir_id.expect_owner();

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+42-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#![doc(rust_logo)]
3636
#![feature(box_patterns)]
3737
#![feature(let_chains)]
38-
#![feature(never_type)]
3938
#![recursion_limit = "256"]
4039
#![deny(rustc::untranslatable_diagnostic)]
4140
#![deny(rustc::diagnostic_outside_of_impl)]
@@ -132,8 +131,8 @@ struct LoweringContext<'a, 'hir> {
132131
/// NodeIds that are lowered inside the current HIR owner.
133132
node_id_to_local_id: FxHashMap<NodeId, hir::ItemLocalId>,
134133

135-
allow_try_trait: Option<Lrc<[Symbol]>>,
136-
allow_gen_future: Option<Lrc<[Symbol]>>,
134+
allow_try_trait: Lrc<[Symbol]>,
135+
allow_gen_future: Lrc<[Symbol]>,
137136

138137
/// Mapping from generics `def_id`s to TAIT generics `def_id`s.
139138
/// For each captured lifetime (e.g., 'a), we create a new lifetime parameter that is a generic
@@ -144,6 +143,46 @@ struct LoweringContext<'a, 'hir> {
144143
host_param_id: Option<LocalDefId>,
145144
}
146145

146+
impl<'a, 'hir> LoweringContext<'a, 'hir> {
147+
fn new(tcx: TyCtxt<'hir>, resolver: &'a mut ResolverAstLowering) -> Self {
148+
Self {
149+
// Pseudo-globals.
150+
tcx,
151+
resolver: resolver,
152+
arena: tcx.hir_arena,
153+
154+
// HirId handling.
155+
bodies: Vec::new(),
156+
attrs: SortedMap::default(),
157+
children: Vec::default(),
158+
current_hir_id_owner: hir::CRATE_OWNER_ID,
159+
item_local_id_counter: hir::ItemLocalId::new(0),
160+
node_id_to_local_id: Default::default(),
161+
trait_map: Default::default(),
162+
163+
// Lowering state.
164+
catch_scope: None,
165+
loop_scope: None,
166+
is_in_loop_condition: false,
167+
is_in_trait_impl: false,
168+
is_in_dyn_type: false,
169+
coroutine_kind: None,
170+
task_context: None,
171+
current_item: None,
172+
impl_trait_defs: Vec::new(),
173+
impl_trait_bounds: Vec::new(),
174+
allow_try_trait: [sym::try_trait_v2, sym::yeet_desugar_details].into(),
175+
allow_gen_future: if tcx.features().async_fn_track_caller {
176+
[sym::gen_future, sym::closure_track_caller].into()
177+
} else {
178+
[sym::gen_future].into()
179+
},
180+
generics_def_id_map: Default::default(),
181+
host_param_id: None,
182+
}
183+
}
184+
}
185+
147186
trait ResolverAstLoweringExt {
148187
fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>>;
149188
fn get_partial_res(&self, id: NodeId) -> Option<PartialRes>;

Diff for: compiler/rustc_ast_lowering/src/lifetime_collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl<'ast> Visitor<'ast> for LifetimeCollectVisitor<'ast> {
108108
}
109109
}
110110

111-
pub fn lifetimes_in_bounds(
111+
pub(crate) fn lifetimes_in_bounds(
112112
resolver: &ResolverAstLowering,
113113
bounds: &GenericBounds,
114114
) -> Vec<Lifetime> {

Diff for: compiler/rustc_ast_lowering/src/pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1818
self.arena.alloc(self.lower_pat_mut(pattern))
1919
}
2020

21-
pub(crate) fn lower_pat_mut(&mut self, mut pattern: &Pat) -> hir::Pat<'hir> {
21+
fn lower_pat_mut(&mut self, mut pattern: &Pat) -> hir::Pat<'hir> {
2222
ensure_sufficient_stack(|| {
2323
// loop here to avoid recursion
2424
let node = loop {

Diff for: compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2352,7 +2352,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
23522352
Applicability::MaybeIncorrect,
23532353
);
23542354
} else {
2355-
err.note("the result of `format_args!` can only be assigned directly if no placeholders in it's arguments are used");
2355+
err.note("the result of `format_args!` can only be assigned directly if no placeholders in its arguments are used");
23562356
err.note("to learn more, visit <https://doc.rust-lang.org/std/macro.format_args.html>");
23572357
}
23582358
suggested = true;

Diff for: compiler/rustc_builtin_macros/src/format.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -672,30 +672,22 @@ fn report_missing_placeholders(
672672
if explained.contains(&sub) {
673673
continue;
674674
}
675-
explained.insert(sub.clone());
675+
explained.insert(sub);
676676

677677
if !found_foreign {
678678
found_foreign = true;
679679
show_doc_note = true;
680680
}
681681

682-
if let Some(inner_sp) = pos {
683-
let sp = fmt_span.from_inner(inner_sp);
682+
let sp = fmt_span.from_inner(pos);
684683

685-
if success {
686-
suggestions.push((sp, trn));
687-
} else {
688-
diag.span_note(
689-
sp,
690-
format!("format specifiers use curly braces, and {}", trn),
691-
);
692-
}
684+
if success {
685+
suggestions.push((sp, trn));
693686
} else {
694-
if success {
695-
diag.help(format!("`{}` should be written as `{}`", sub, trn));
696-
} else {
697-
diag.note(format!("`{}` should use curly braces, and {}", sub, trn));
698-
}
687+
diag.span_note(
688+
sp,
689+
format!("format specifiers use curly braces, and {}", trn),
690+
);
699691
}
700692
}
701693

0 commit comments

Comments
 (0)