Skip to content

Commit 57a4736

Browse files
committed
Auto merge of #138388 - matthiaskrgr:rollup-kbax8sz, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #138161 (Add PeekMut::refresh) - #138174 (Elaborate trait assumption in `receiver_is_dispatchable`) - #138313 (Update books) - #138347 (Reduce `kw::Empty` usage, part 2) - #138360 (Fix false-positive in `expr_or_init` and in the `invalid_from_utf8` lint) - #138372 (Refactor `pick2_mut` & `pick3_mut` to use `get_disjoint_mut`) - #138376 (Item-related cleanups) - #138377 (Remove unnecessary lifetime from `PatInfo`.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a21d978 + 76f9cda commit 57a4736

File tree

29 files changed

+359
-202
lines changed

29 files changed

+359
-202
lines changed

compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,7 @@ impl DummyAstNode for Item {
19481948
span: Default::default(),
19491949
tokens: Default::default(),
19501950
},
1951-
ident: Ident::empty(),
1951+
ident: Ident::dummy(),
19521952
kind: ItemKind::ExternCrate(None),
19531953
tokens: Default::default(),
19541954
}

compiler/rustc_attr_parsing/src/context.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_errors::{DiagCtxtHandle, Diagnostic};
99
use rustc_feature::Features;
1010
use rustc_hir::{AttrArgs, AttrItem, AttrPath, Attribute, HashIgnoredAttrId};
1111
use rustc_session::Session;
12-
use rustc_span::symbol::kw;
1312
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1413

1514
use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
@@ -338,7 +337,7 @@ impl<'sess> AttributeParser<'sess> {
338337
"expr in place where literal is expected (builtin attr parsing)",
339338
);
340339
ast::MetaItemLit {
341-
symbol: kw::Empty,
340+
symbol: sym::dummy,
342341
suffix: None,
343342
kind: ast::LitKind::Err(guar),
344343
span: DUMMY_SP,

compiler/rustc_attr_parsing/src/parser.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_ast::{AttrArgs, DelimArgs, Expr, ExprKind, LitKind, MetaItemLit, Norma
1212
use rustc_ast_pretty::pprust;
1313
use rustc_errors::DiagCtxtHandle;
1414
use rustc_hir::{self as hir, AttrPath};
15-
use rustc_span::symbol::{Ident, kw};
15+
use rustc_span::symbol::{Ident, kw, sym};
1616
use rustc_span::{ErrorGuaranteed, Span, Symbol};
1717

1818
pub struct SegmentIterator<'a> {
@@ -360,7 +360,7 @@ fn expr_to_lit(dcx: DiagCtxtHandle<'_>, expr: &Expr, span: Span) -> MetaItemLit
360360
span,
361361
"expr in place where literal is expected (builtin attr parsing)",
362362
);
363-
MetaItemLit { symbol: kw::Empty, suffix: None, kind: LitKind::Err(guar), span }
363+
MetaItemLit { symbol: sym::dummy, suffix: None, kind: LitKind::Err(guar), span }
364364
}
365365
}
366366

compiler/rustc_expand/src/mbe/quoted.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ fn parse_tree<'a>(
274274
let msg =
275275
format!("expected identifier, found `{}`", pprust::token_to_string(token),);
276276
sess.dcx().span_err(token.span, msg);
277-
TokenTree::MetaVar(token.span, Ident::empty())
277+
TokenTree::MetaVar(token.span, Ident::dummy())
278278
}
279279

280280
// There are no more tokens. Just return the `$` we already have.

compiler/rustc_hir/src/hir.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'hir> PathSegment<'hir> {
243243
}
244244

245245
pub fn invalid() -> Self {
246-
Self::new(Ident::empty(), HirId::INVALID, Res::Err)
246+
Self::new(Ident::dummy(), HirId::INVALID, Res::Err)
247247
}
248248

249249
pub fn args(&self) -> &GenericArgs<'hir> {
@@ -4332,16 +4332,6 @@ pub enum OwnerNode<'hir> {
43324332
}
43334333

43344334
impl<'hir> OwnerNode<'hir> {
4335-
pub fn ident(&self) -> Option<Ident> {
4336-
match self {
4337-
OwnerNode::Item(Item { ident, .. })
4338-
| OwnerNode::ForeignItem(ForeignItem { ident, .. })
4339-
| OwnerNode::ImplItem(ImplItem { ident, .. })
4340-
| OwnerNode::TraitItem(TraitItem { ident, .. }) => Some(*ident),
4341-
OwnerNode::Crate(..) | OwnerNode::Synthetic => None,
4342-
}
4343-
}
4344-
43454335
pub fn span(&self) -> Span {
43464336
match self {
43474337
OwnerNode::Item(Item { span, .. })

compiler/rustc_hir_pretty/src/lib.rs

+11-22
Original file line numberDiff line numberDiff line change
@@ -553,24 +553,6 @@ impl<'a> State<'a> {
553553
self.word(";")
554554
}
555555

556-
fn print_item_type(
557-
&mut self,
558-
item: &hir::Item<'_>,
559-
generics: &hir::Generics<'_>,
560-
inner: impl Fn(&mut Self),
561-
) {
562-
self.head("type");
563-
self.print_ident(item.ident);
564-
self.print_generic_params(generics.params);
565-
self.end(); // end the inner ibox
566-
567-
self.print_where_clause(generics);
568-
self.space();
569-
inner(self);
570-
self.word(";");
571-
self.end(); // end the outer ibox
572-
}
573-
574556
fn print_item(&mut self, item: &hir::Item<'_>) {
575557
self.hardbreak_if_not_bol();
576558
self.maybe_print_comment(item.span.lo());
@@ -683,10 +665,17 @@ impl<'a> State<'a> {
683665
self.end()
684666
}
685667
hir::ItemKind::TyAlias(ty, generics) => {
686-
self.print_item_type(item, generics, |state| {
687-
state.word_space("=");
688-
state.print_type(ty);
689-
});
668+
self.head("type");
669+
self.print_ident(item.ident);
670+
self.print_generic_params(generics.params);
671+
self.end(); // end the inner ibox
672+
673+
self.print_where_clause(generics);
674+
self.space();
675+
self.word_space("=");
676+
self.print_type(ty);
677+
self.word(";");
678+
self.end(); // end the outer ibox
690679
}
691680
hir::ItemKind::Enum(ref enum_definition, params) => {
692681
self.print_enum_def(enum_definition, params, item.ident.name, item.span);

compiler/rustc_hir_typeck/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2933,7 +2933,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29332933
}
29342934

29352935
let guar = if field.name == kw::Empty {
2936-
self.dcx().span_delayed_bug(field.span, "field name with no name")
2936+
self.dcx().span_bug(field.span, "field name with no name")
29372937
} else if self.method_exists_for_diagnostic(
29382938
field,
29392939
base_ty,

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -832,15 +832,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
832832

833833
let trait_missing_method =
834834
matches!(error, method::MethodError::NoMatch(_)) && ty.normalized.is_trait();
835-
if item_name.name != kw::Empty {
836-
self.report_method_error(
837-
hir_id,
838-
ty.normalized,
839-
error,
840-
Expectation::NoExpectation,
841-
trait_missing_method && span.edition().at_least_rust_2021(), // emits missing method for trait only after edition 2021
842-
);
843-
}
835+
assert_ne!(item_name.name, kw::Empty);
836+
self.report_method_error(
837+
hir_id,
838+
ty.normalized,
839+
error,
840+
Expectation::NoExpectation,
841+
trait_missing_method && span.edition().at_least_rust_2021(), // emits missing method for trait only after edition 2021
842+
);
844843

845844
result
846845
});

compiler/rustc_hir_typeck/src/pat.rs

+27-25
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ struct TopInfo<'tcx> {
8787
}
8888

8989
#[derive(Copy, Clone)]
90-
struct PatInfo<'a, 'tcx> {
90+
struct PatInfo<'tcx> {
9191
binding_mode: ByRef,
9292
max_ref_mutbl: MutblCap,
93-
top_info: &'a TopInfo<'tcx>,
93+
top_info: TopInfo<'tcx>,
9494
decl_origin: Option<DeclOrigin<'tcx>>,
9595

9696
/// The depth of current pattern
@@ -303,11 +303,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
303303
origin_expr: Option<&'tcx hir::Expr<'tcx>>,
304304
decl_origin: Option<DeclOrigin<'tcx>>,
305305
) {
306-
let info = TopInfo { expected, origin_expr, span, hir_id: pat.hir_id };
306+
let top_info = TopInfo { expected, origin_expr, span, hir_id: pat.hir_id };
307307
let pat_info = PatInfo {
308308
binding_mode: ByRef::No,
309309
max_ref_mutbl: MutblCap::Mut,
310-
top_info: &info,
310+
top_info,
311311
decl_origin,
312312
current_depth: 0,
313313
};
@@ -320,7 +320,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
320320
/// Outside of this module, `check_pat_top` should always be used.
321321
/// Conversely, inside this module, `check_pat_top` should never be used.
322322
#[instrument(level = "debug", skip(self, pat_info))]
323-
fn check_pat(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, pat_info: PatInfo<'_, 'tcx>) {
323+
fn check_pat(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, pat_info: PatInfo<'tcx>) {
324324
let PatInfo { binding_mode, max_ref_mutbl, top_info: ti, current_depth, .. } = pat_info;
325325

326326
let path_res = match pat.kind {
@@ -352,13 +352,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
352352
qpath,
353353
path_res.unwrap(),
354354
expected,
355-
ti,
355+
&pat_info.top_info,
356356
);
357357
self.write_ty(*hir_id, ty);
358358
ty
359359
}
360-
PatKind::Expr(lt) => self.check_pat_lit(pat.span, lt, expected, ti),
361-
PatKind::Range(lhs, rhs, _) => self.check_pat_range(pat.span, lhs, rhs, expected, ti),
360+
PatKind::Expr(lt) => self.check_pat_lit(pat.span, lt, expected, &pat_info.top_info),
361+
PatKind::Range(lhs, rhs, _) => {
362+
self.check_pat_range(pat.span, lhs, rhs, expected, &pat_info.top_info)
363+
}
362364
PatKind::Binding(ba, var_id, ident, sub) => {
363365
self.check_pat_ident(pat, ba, var_id, ident, sub, expected, pat_info)
364366
}
@@ -818,7 +820,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
818820
ident: Ident,
819821
sub: Option<&'tcx Pat<'tcx>>,
820822
expected: Ty<'tcx>,
821-
pat_info: PatInfo<'_, 'tcx>,
823+
pat_info: PatInfo<'tcx>,
822824
) -> Ty<'tcx> {
823825
let PatInfo { binding_mode: def_br, top_info: ti, .. } = pat_info;
824826

@@ -914,12 +916,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
914916
};
915917

916918
// We have a concrete type for the local, so we do not need to taint it and hide follow up errors *using* the local.
917-
let _ = self.demand_eqtype_pat(pat.span, eq_ty, local_ty, ti);
919+
let _ = self.demand_eqtype_pat(pat.span, eq_ty, local_ty, &ti);
918920

919921
// If there are multiple arms, make sure they all agree on
920922
// what the type of the binding `x` ought to be.
921923
if var_id != pat.hir_id {
922-
self.check_binding_alt_eq_ty(user_bind_annot, pat.span, var_id, local_ty, ti);
924+
self.check_binding_alt_eq_ty(user_bind_annot, pat.span, var_id, local_ty, &ti);
923925
}
924926

925927
if let Some(p) = sub {
@@ -1149,7 +1151,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11491151
fields: &'tcx [hir::PatField<'tcx>],
11501152
has_rest_pat: bool,
11511153
expected: Ty<'tcx>,
1152-
pat_info: PatInfo<'_, 'tcx>,
1154+
pat_info: PatInfo<'tcx>,
11531155
) -> Ty<'tcx> {
11541156
// Resolve the path and check the definition for errors.
11551157
let (variant, pat_ty) = match self.check_struct_path(qpath, pat.hir_id) {
@@ -1164,7 +1166,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11641166
};
11651167

11661168
// Type-check the path.
1167-
let _ = self.demand_eqtype_pat(pat.span, expected, pat_ty, pat_info.top_info);
1169+
let _ = self.demand_eqtype_pat(pat.span, expected, pat_ty, &pat_info.top_info);
11681170

11691171
// Type-check subpatterns.
11701172
match self.check_struct_pat_fields(pat_ty, pat, variant, fields, has_rest_pat, pat_info) {
@@ -1353,7 +1355,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13531355
subpats: &'tcx [Pat<'tcx>],
13541356
ddpos: hir::DotDotPos,
13551357
expected: Ty<'tcx>,
1356-
pat_info: PatInfo<'_, 'tcx>,
1358+
pat_info: PatInfo<'tcx>,
13571359
) -> Ty<'tcx> {
13581360
let tcx = self.tcx;
13591361
let on_error = |e| {
@@ -1403,7 +1405,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14031405
let pat_ty = pat_ty.no_bound_vars().expect("expected fn type");
14041406

14051407
// Type-check the tuple struct pattern against the expected type.
1406-
let diag = self.demand_eqtype_pat_diag(pat.span, expected, pat_ty, pat_info.top_info);
1408+
let diag = self.demand_eqtype_pat_diag(pat.span, expected, pat_ty, &pat_info.top_info);
14071409
let had_err = diag.map_err(|diag| diag.emit());
14081410

14091411
// Type-check subpatterns.
@@ -1610,7 +1612,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16101612
elements: &'tcx [Pat<'tcx>],
16111613
ddpos: hir::DotDotPos,
16121614
expected: Ty<'tcx>,
1613-
pat_info: PatInfo<'_, 'tcx>,
1615+
pat_info: PatInfo<'tcx>,
16141616
) -> Ty<'tcx> {
16151617
let tcx = self.tcx;
16161618
let mut expected_len = elements.len();
@@ -1625,7 +1627,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16251627
let element_tys_iter = (0..max_len).map(|_| self.next_ty_var(span));
16261628
let element_tys = tcx.mk_type_list_from_iter(element_tys_iter);
16271629
let pat_ty = Ty::new_tup(tcx, element_tys);
1628-
if let Err(reported) = self.demand_eqtype_pat(span, expected, pat_ty, pat_info.top_info) {
1630+
if let Err(reported) = self.demand_eqtype_pat(span, expected, pat_ty, &pat_info.top_info) {
16291631
// Walk subpatterns with an expected type of `err` in this case to silence
16301632
// further errors being emitted when using the bindings. #50333
16311633
let element_tys_iter = (0..max_len).map(|_| Ty::new_error(tcx, reported));
@@ -1648,7 +1650,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16481650
variant: &'tcx ty::VariantDef,
16491651
fields: &'tcx [hir::PatField<'tcx>],
16501652
has_rest_pat: bool,
1651-
pat_info: PatInfo<'_, 'tcx>,
1653+
pat_info: PatInfo<'tcx>,
16521654
) -> Result<(), ErrorGuaranteed> {
16531655
let tcx = self.tcx;
16541656

@@ -2257,7 +2259,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22572259
span: Span,
22582260
inner: &'tcx Pat<'tcx>,
22592261
expected: Ty<'tcx>,
2260-
pat_info: PatInfo<'_, 'tcx>,
2262+
pat_info: PatInfo<'tcx>,
22612263
) -> Ty<'tcx> {
22622264
let tcx = self.tcx;
22632265
let (box_ty, inner_ty) = self
@@ -2267,7 +2269,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22672269
// think any errors can be introduced by using `demand::eqtype`.
22682270
let inner_ty = self.next_ty_var(inner.span);
22692271
let box_ty = Ty::new_box(tcx, inner_ty);
2270-
self.demand_eqtype_pat(span, expected, box_ty, pat_info.top_info)?;
2272+
self.demand_eqtype_pat(span, expected, box_ty, &pat_info.top_info)?;
22712273
Ok((box_ty, inner_ty))
22722274
})
22732275
.unwrap_or_else(|guar| {
@@ -2283,7 +2285,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22832285
span: Span,
22842286
inner: &'tcx Pat<'tcx>,
22852287
expected: Ty<'tcx>,
2286-
pat_info: PatInfo<'_, 'tcx>,
2288+
pat_info: PatInfo<'tcx>,
22872289
) -> Ty<'tcx> {
22882290
let tcx = self.tcx;
22892291
// Register a `DerefPure` bound, which is required by all `deref!()` pats.
@@ -2324,7 +2326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23242326
inner: &'tcx Pat<'tcx>,
23252327
pat_mutbl: Mutability,
23262328
mut expected: Ty<'tcx>,
2327-
mut pat_info: PatInfo<'_, 'tcx>,
2329+
mut pat_info: PatInfo<'tcx>,
23282330
) -> Ty<'tcx> {
23292331
let tcx = self.tcx;
23302332

@@ -2482,7 +2484,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24822484
pat.span,
24832485
expected,
24842486
ref_ty,
2485-
pat_info.top_info,
2487+
&pat_info.top_info,
24862488
);
24872489

24882490
// Look for a case like `fn foo(&foo: u32)` and suggest
@@ -2605,7 +2607,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26052607
slice: Option<&'tcx Pat<'tcx>>,
26062608
after: &'tcx [Pat<'tcx>],
26072609
expected: Ty<'tcx>,
2608-
pat_info: PatInfo<'_, 'tcx>,
2610+
pat_info: PatInfo<'tcx>,
26092611
) -> Ty<'tcx> {
26102612
let expected = self.try_structurally_resolve_type(span, expected);
26112613

@@ -2767,7 +2769,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27672769
&self,
27682770
span: Span,
27692771
expected_ty: Ty<'tcx>,
2770-
pat_info: PatInfo<'_, 'tcx>,
2772+
pat_info: PatInfo<'tcx>,
27712773
) -> ErrorGuaranteed {
27722774
let PatInfo { top_info: ti, current_depth, .. } = pat_info;
27732775

0 commit comments

Comments
 (0)