Skip to content
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

Rollup of 8 pull requests #138388

Merged
merged 23 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5d4ff50
Update books
rustbot Mar 10, 2025
436959e
Add PeekMut::refresh
HeroicKatora Mar 7, 2025
c170d0f
Elaborate param-env built for checking DispatchFromDyn for dyn compat
compiler-errors Mar 11, 2025
6133999
Fix `cargo vendor` not working without `rustc` installed
ehuss Mar 11, 2025
faa5b3f
Fix false-positive in `expr_or_init` and in the `invalid_from_utf8` lint
Urgau Mar 9, 2025
64d1433
Refactor pick2_mut & pick3_mut to use get_disjoint_mut
Eclips4 Mar 11, 2025
763db5d
Convert a delayed bug to a bug.
nnethercote Mar 5, 2025
fe04460
Remove an unnecessary `kw::Empty` check.
nnethercote Mar 6, 2025
0b2d706
Introduce `sym::dummy` and `Ident::dummy`.
nnethercote Mar 4, 2025
4eadaff
Convert a `kw::Empty` occurrence to `sym::dummy`.
nnethercote Mar 11, 2025
7398b39
Make panic's more specific
Eclips4 Mar 11, 2025
d7029d7
Remove unused `OwnerNode::ident` method.
nnethercote Mar 7, 2025
ed10418
Inline and remove `State::print_item_type`.
nnethercote Mar 7, 2025
ee9ef82
Factor out some repeated code in `parse_item_impl`.
nnethercote Mar 7, 2025
c0cee43
Remove unnecessary lifetime from `PatInfo`.
nnethercote Jan 30, 2025
4198902
Rollup merge of #138161 - HeroicKatora:heap-peek-mut-refresh, r=dtolnay
matthiaskrgr Mar 12, 2025
143eb4f
Rollup merge of #138174 - compiler-errors:elaborate-unsize-self-pred,…
matthiaskrgr Mar 12, 2025
53e4e6f
Rollup merge of #138313 - rustbot:docs-update, r=jieyouxu
matthiaskrgr Mar 12, 2025
5833dfa
Rollup merge of #138347 - nnethercote:less-kw-Empty-2, r=compiler-errors
matthiaskrgr Mar 12, 2025
b849aa9
Rollup merge of #138360 - Urgau:fix-fp-expr_or_init, r=wesleywiser
matthiaskrgr Mar 12, 2025
2bdb10f
Rollup merge of #138372 - Eclips4:issue-138196, r=scottmcm
matthiaskrgr Mar 12, 2025
4c6edb1
Rollup merge of #138376 - nnethercote:hir-ItemKind-ident-precursors, …
matthiaskrgr Mar 12, 2025
76f9cda
Rollup merge of #138377 - nnethercote:rustc_hir_typeck, r=compiler-er…
matthiaskrgr Mar 12, 2025
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
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,7 @@ impl DummyAstNode for Item {
span: Default::default(),
tokens: Default::default(),
},
ident: Ident::empty(),
ident: Ident::dummy(),
kind: ItemKind::ExternCrate(None),
tokens: Default::default(),
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_attr_parsing/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use rustc_errors::{DiagCtxtHandle, Diagnostic};
use rustc_feature::Features;
use rustc_hir::{AttrArgs, AttrItem, AttrPath, Attribute, HashIgnoredAttrId};
use rustc_session::Session;
use rustc_span::symbol::kw;
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};

use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
Expand Down Expand Up @@ -338,7 +337,7 @@ impl<'sess> AttributeParser<'sess> {
"expr in place where literal is expected (builtin attr parsing)",
);
ast::MetaItemLit {
symbol: kw::Empty,
symbol: sym::dummy,
suffix: None,
kind: ast::LitKind::Err(guar),
span: DUMMY_SP,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_attr_parsing/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_ast::{AttrArgs, DelimArgs, Expr, ExprKind, LitKind, MetaItemLit, Norma
use rustc_ast_pretty::pprust;
use rustc_errors::DiagCtxtHandle;
use rustc_hir::{self as hir, AttrPath};
use rustc_span::symbol::{Ident, kw};
use rustc_span::symbol::{Ident, kw, sym};
use rustc_span::{ErrorGuaranteed, Span, Symbol};

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

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/mbe/quoted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ fn parse_tree<'a>(
let msg =
format!("expected identifier, found `{}`", pprust::token_to_string(token),);
sess.dcx().span_err(token.span, msg);
TokenTree::MetaVar(token.span, Ident::empty())
TokenTree::MetaVar(token.span, Ident::dummy())
}

// There are no more tokens. Just return the `$` we already have.
Expand Down
12 changes: 1 addition & 11 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl<'hir> PathSegment<'hir> {
}

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

pub fn args(&self) -> &GenericArgs<'hir> {
Expand Down Expand Up @@ -4332,16 +4332,6 @@ pub enum OwnerNode<'hir> {
}

impl<'hir> OwnerNode<'hir> {
pub fn ident(&self) -> Option<Ident> {
match self {
OwnerNode::Item(Item { ident, .. })
| OwnerNode::ForeignItem(ForeignItem { ident, .. })
| OwnerNode::ImplItem(ImplItem { ident, .. })
| OwnerNode::TraitItem(TraitItem { ident, .. }) => Some(*ident),
OwnerNode::Crate(..) | OwnerNode::Synthetic => None,
}
}

pub fn span(&self) -> Span {
match self {
OwnerNode::Item(Item { span, .. })
Expand Down
33 changes: 11 additions & 22 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -553,24 +553,6 @@ impl<'a> State<'a> {
self.word(";")
}

fn print_item_type(
&mut self,
item: &hir::Item<'_>,
generics: &hir::Generics<'_>,
inner: impl Fn(&mut Self),
) {
self.head("type");
self.print_ident(item.ident);
self.print_generic_params(generics.params);
self.end(); // end the inner ibox

self.print_where_clause(generics);
self.space();
inner(self);
self.word(";");
self.end(); // end the outer ibox
}

fn print_item(&mut self, item: &hir::Item<'_>) {
self.hardbreak_if_not_bol();
self.maybe_print_comment(item.span.lo());
Expand Down Expand Up @@ -683,10 +665,17 @@ impl<'a> State<'a> {
self.end()
}
hir::ItemKind::TyAlias(ty, generics) => {
self.print_item_type(item, generics, |state| {
state.word_space("=");
state.print_type(ty);
});
self.head("type");
self.print_ident(item.ident);
self.print_generic_params(generics.params);
self.end(); // end the inner ibox

self.print_where_clause(generics);
self.space();
self.word_space("=");
self.print_type(ty);
self.word(";");
self.end(); // end the outer ibox
}
hir::ItemKind::Enum(ref enum_definition, params) => {
self.print_enum_def(enum_definition, params, item.ident.name, item.span);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2933,7 +2933,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

let guar = if field.name == kw::Empty {
self.dcx().span_delayed_bug(field.span, "field name with no name")
self.dcx().span_bug(field.span, "field name with no name")
} else if self.method_exists_for_diagnostic(
field,
base_ty,
Expand Down
17 changes: 8 additions & 9 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,15 +832,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

let trait_missing_method =
matches!(error, method::MethodError::NoMatch(_)) && ty.normalized.is_trait();
if item_name.name != kw::Empty {
self.report_method_error(
hir_id,
ty.normalized,
error,
Expectation::NoExpectation,
trait_missing_method && span.edition().at_least_rust_2021(), // emits missing method for trait only after edition 2021
);
}
assert_ne!(item_name.name, kw::Empty);
self.report_method_error(
hir_id,
ty.normalized,
error,
Expectation::NoExpectation,
trait_missing_method && span.edition().at_least_rust_2021(), // emits missing method for trait only after edition 2021
);

result
});
Expand Down
52 changes: 27 additions & 25 deletions compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ struct TopInfo<'tcx> {
}

#[derive(Copy, Clone)]
struct PatInfo<'a, 'tcx> {
struct PatInfo<'tcx> {
binding_mode: ByRef,
max_ref_mutbl: MutblCap,
top_info: &'a TopInfo<'tcx>,
top_info: TopInfo<'tcx>,
decl_origin: Option<DeclOrigin<'tcx>>,

/// The depth of current pattern
Expand Down Expand Up @@ -303,11 +303,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
origin_expr: Option<&'tcx hir::Expr<'tcx>>,
decl_origin: Option<DeclOrigin<'tcx>>,
) {
let info = TopInfo { expected, origin_expr, span, hir_id: pat.hir_id };
let top_info = TopInfo { expected, origin_expr, span, hir_id: pat.hir_id };
let pat_info = PatInfo {
binding_mode: ByRef::No,
max_ref_mutbl: MutblCap::Mut,
top_info: &info,
top_info,
decl_origin,
current_depth: 0,
};
Expand All @@ -320,7 +320,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Outside of this module, `check_pat_top` should always be used.
/// Conversely, inside this module, `check_pat_top` should never be used.
#[instrument(level = "debug", skip(self, pat_info))]
fn check_pat(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, pat_info: PatInfo<'_, 'tcx>) {
fn check_pat(&self, pat: &'tcx Pat<'tcx>, expected: Ty<'tcx>, pat_info: PatInfo<'tcx>) {
let PatInfo { binding_mode, max_ref_mutbl, top_info: ti, current_depth, .. } = pat_info;

let path_res = match pat.kind {
Expand Down Expand Up @@ -352,13 +352,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
qpath,
path_res.unwrap(),
expected,
ti,
&pat_info.top_info,
);
self.write_ty(*hir_id, ty);
ty
}
PatKind::Expr(lt) => self.check_pat_lit(pat.span, lt, expected, ti),
PatKind::Range(lhs, rhs, _) => self.check_pat_range(pat.span, lhs, rhs, expected, ti),
PatKind::Expr(lt) => self.check_pat_lit(pat.span, lt, expected, &pat_info.top_info),
PatKind::Range(lhs, rhs, _) => {
self.check_pat_range(pat.span, lhs, rhs, expected, &pat_info.top_info)
}
PatKind::Binding(ba, var_id, ident, sub) => {
self.check_pat_ident(pat, ba, var_id, ident, sub, expected, pat_info)
}
Expand Down Expand Up @@ -818,7 +820,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ident: Ident,
sub: Option<&'tcx Pat<'tcx>>,
expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
let PatInfo { binding_mode: def_br, top_info: ti, .. } = pat_info;

Expand Down Expand Up @@ -914,12 +916,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};

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

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

if let Some(p) = sub {
Expand Down Expand Up @@ -1149,7 +1151,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fields: &'tcx [hir::PatField<'tcx>],
has_rest_pat: bool,
expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
// Resolve the path and check the definition for errors.
let (variant, pat_ty) = match self.check_struct_path(qpath, pat.hir_id) {
Expand All @@ -1164,7 +1166,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
};

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

// Type-check subpatterns.
match self.check_struct_pat_fields(pat_ty, pat, variant, fields, has_rest_pat, pat_info) {
Expand Down Expand Up @@ -1353,7 +1355,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
subpats: &'tcx [Pat<'tcx>],
ddpos: hir::DotDotPos,
expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
let tcx = self.tcx;
let on_error = |e| {
Expand Down Expand Up @@ -1403,7 +1405,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let pat_ty = pat_ty.no_bound_vars().expect("expected fn type");

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

// Type-check subpatterns.
Expand Down Expand Up @@ -1610,7 +1612,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
elements: &'tcx [Pat<'tcx>],
ddpos: hir::DotDotPos,
expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
let tcx = self.tcx;
let mut expected_len = elements.len();
Expand All @@ -1625,7 +1627,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let element_tys_iter = (0..max_len).map(|_| self.next_ty_var(span));
let element_tys = tcx.mk_type_list_from_iter(element_tys_iter);
let pat_ty = Ty::new_tup(tcx, element_tys);
if let Err(reported) = self.demand_eqtype_pat(span, expected, pat_ty, pat_info.top_info) {
if let Err(reported) = self.demand_eqtype_pat(span, expected, pat_ty, &pat_info.top_info) {
// Walk subpatterns with an expected type of `err` in this case to silence
// further errors being emitted when using the bindings. #50333
let element_tys_iter = (0..max_len).map(|_| Ty::new_error(tcx, reported));
Expand All @@ -1648,7 +1650,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
variant: &'tcx ty::VariantDef,
fields: &'tcx [hir::PatField<'tcx>],
has_rest_pat: bool,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> Result<(), ErrorGuaranteed> {
let tcx = self.tcx;

Expand Down Expand Up @@ -2257,7 +2259,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span: Span,
inner: &'tcx Pat<'tcx>,
expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
let tcx = self.tcx;
let (box_ty, inner_ty) = self
Expand All @@ -2267,7 +2269,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// think any errors can be introduced by using `demand::eqtype`.
let inner_ty = self.next_ty_var(inner.span);
let box_ty = Ty::new_box(tcx, inner_ty);
self.demand_eqtype_pat(span, expected, box_ty, pat_info.top_info)?;
self.demand_eqtype_pat(span, expected, box_ty, &pat_info.top_info)?;
Ok((box_ty, inner_ty))
})
.unwrap_or_else(|guar| {
Expand All @@ -2283,7 +2285,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
span: Span,
inner: &'tcx Pat<'tcx>,
expected: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
let tcx = self.tcx;
// Register a `DerefPure` bound, which is required by all `deref!()` pats.
Expand Down Expand Up @@ -2324,7 +2326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
inner: &'tcx Pat<'tcx>,
pat_mutbl: Mutability,
mut expected: Ty<'tcx>,
mut pat_info: PatInfo<'_, 'tcx>,
mut pat_info: PatInfo<'tcx>,
) -> Ty<'tcx> {
let tcx = self.tcx;

Expand Down Expand Up @@ -2482,7 +2484,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pat.span,
expected,
ref_ty,
pat_info.top_info,
&pat_info.top_info,
);

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

Expand Down Expand Up @@ -2767,7 +2769,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
span: Span,
expected_ty: Ty<'tcx>,
pat_info: PatInfo<'_, 'tcx>,
pat_info: PatInfo<'tcx>,
) -> ErrorGuaranteed {
let PatInfo { top_info: ti, current_depth, .. } = pat_info;

Expand Down
Loading
Loading