Skip to content

Commit 99ad5a1

Browse files
committed
Auto merge of #80566 - Dylan-DPC:rollup-rns6est, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - #80323 (Update and improve `rustc_codegen_{llvm,ssa}` docs) - #80368 (rustdoc: Render visibilities succinctly) - #80514 (Fix broken ./x.py install) - #80519 (Take type defaults into account in suggestions to reorder generic parameters) - #80526 (Update LLVM) - #80532 (remove unnecessary trailing semicolon from bootstrap) - #80548 (FIx ICE on wf check for foreign fns) - #80551 (support pattern as const parents in type_of) Failed merges: - #80547 (In which we start to parse const generics defaults) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 44e3daf + 96c11f9 commit 99ad5a1

34 files changed

+487
-307
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+31-25
Original file line numberDiff line numberDiff line change
@@ -717,35 +717,46 @@ impl<'a> AstValidator<'a> {
717717

718718
/// Checks that generic parameters are in the correct order,
719719
/// which is lifetimes, then types and then consts. (`<'a, T, const N: usize>`)
720-
fn validate_generic_param_order<'a>(
720+
fn validate_generic_param_order(
721721
sess: &Session,
722722
handler: &rustc_errors::Handler,
723-
generics: impl Iterator<Item = (ParamKindOrd, Option<&'a [GenericBound]>, Span, Option<String>)>,
723+
generics: &[GenericParam],
724724
span: Span,
725725
) {
726726
let mut max_param: Option<ParamKindOrd> = None;
727727
let mut out_of_order = FxHashMap::default();
728728
let mut param_idents = vec![];
729729

730-
for (kind, bounds, span, ident) in generics {
730+
for param in generics {
731+
let ident = Some(param.ident.to_string());
732+
let (kind, bounds, span) = (&param.kind, Some(&*param.bounds), param.ident.span);
733+
let (ord_kind, ident) = match &param.kind {
734+
GenericParamKind::Lifetime => (ParamKindOrd::Lifetime, ident),
735+
GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident),
736+
GenericParamKind::Const { ref ty, kw_span: _ } => {
737+
let ty = pprust::ty_to_string(ty);
738+
let unordered = sess.features_untracked().const_generics;
739+
(ParamKindOrd::Const { unordered }, Some(format!("const {}: {}", param.ident, ty)))
740+
}
741+
};
731742
if let Some(ident) = ident {
732-
param_idents.push((kind, bounds, param_idents.len(), ident));
743+
param_idents.push((kind, ord_kind, bounds, param_idents.len(), ident));
733744
}
734745
let max_param = &mut max_param;
735746
match max_param {
736-
Some(max_param) if *max_param > kind => {
737-
let entry = out_of_order.entry(kind).or_insert((*max_param, vec![]));
747+
Some(max_param) if *max_param > ord_kind => {
748+
let entry = out_of_order.entry(ord_kind).or_insert((*max_param, vec![]));
738749
entry.1.push(span);
739750
}
740-
Some(_) | None => *max_param = Some(kind),
751+
Some(_) | None => *max_param = Some(ord_kind),
741752
};
742753
}
743754

744755
let mut ordered_params = "<".to_string();
745756
if !out_of_order.is_empty() {
746-
param_idents.sort_by_key(|&(po, _, i, _)| (po, i));
757+
param_idents.sort_by_key(|&(_, po, _, i, _)| (po, i));
747758
let mut first = true;
748-
for (_, bounds, _, ident) in param_idents {
759+
for (kind, _, bounds, _, ident) in param_idents {
749760
if !first {
750761
ordered_params += ", ";
751762
}
@@ -756,6 +767,16 @@ fn validate_generic_param_order<'a>(
756767
ordered_params += &pprust::bounds_to_string(&bounds);
757768
}
758769
}
770+
match kind {
771+
GenericParamKind::Type { default: Some(default) } => {
772+
ordered_params += " = ";
773+
ordered_params += &pprust::ty_to_string(default);
774+
}
775+
GenericParamKind::Type { default: None } => (),
776+
GenericParamKind::Lifetime => (),
777+
// FIXME(const_generics:defaults)
778+
GenericParamKind::Const { ty: _, kw_span: _ } => (),
779+
}
759780
first = false;
760781
}
761782
}
@@ -1150,22 +1171,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
11501171
validate_generic_param_order(
11511172
self.session,
11521173
self.err_handler(),
1153-
generics.params.iter().map(|param| {
1154-
let ident = Some(param.ident.to_string());
1155-
let (kind, ident) = match &param.kind {
1156-
GenericParamKind::Lifetime => (ParamKindOrd::Lifetime, ident),
1157-
GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident),
1158-
GenericParamKind::Const { ref ty, kw_span: _ } => {
1159-
let ty = pprust::ty_to_string(ty);
1160-
let unordered = self.session.features_untracked().const_generics;
1161-
(
1162-
ParamKindOrd::Const { unordered },
1163-
Some(format!("const {}: {}", param.ident, ty)),
1164-
)
1165-
}
1166-
};
1167-
(kind, Some(&*param.bounds), param.ident.span, ident)
1168-
}),
1174+
&generics.params,
11691175
generics.span,
11701176
);
11711177

compiler/rustc_codegen_llvm/src/base.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
//! Codegen the completed AST to the LLVM IR.
2-
//!
3-
//! Some functions here, such as codegen_block and codegen_expr, return a value --
4-
//! the result of the codegen to LLVM -- while others, such as codegen_fn
5-
//! and mono_item, are called only for the side effect of adding a
6-
//! particular definition to the LLVM IR output we're producing.
1+
//! Codegen the MIR to the LLVM IR.
72
//!
83
//! Hopefully useful general knowledge about codegen:
94
//!
10-
//! * There's no way to find out the `Ty` type of a Value. Doing so
5+
//! * There's no way to find out the [`Ty`] type of a [`Value`]. Doing so
116
//! would be "trying to get the eggs out of an omelette" (credit:
12-
//! pcwalton). You can, instead, find out its `llvm::Type` by calling `val_ty`,
13-
//! but one `llvm::Type` corresponds to many `Ty`s; for instance, `tup(int, int,
14-
//! int)` and `rec(x=int, y=int, z=int)` will have the same `llvm::Type`.
7+
//! pcwalton). You can, instead, find out its [`llvm::Type`] by calling [`val_ty`],
8+
//! but one [`llvm::Type`] corresponds to many [`Ty`]s; for instance, `tup(int, int,
9+
//! int)` and `rec(x=int, y=int, z=int)` will have the same [`llvm::Type`].
10+
//!
11+
//! [`Ty`]: rustc_middle::ty::Ty
12+
//! [`val_ty`]: common::val_ty
1513
1614
use super::ModuleLlvm;
1715

compiler/rustc_codegen_llvm/src/common.rs

+1
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
314314
}
315315
}
316316

317+
/// Get the [LLVM type][Type] of a [`Value`].
317318
pub fn val_ty(v: &Value) -> &Type {
318319
unsafe { llvm::LLVMTypeOf(v) }
319320
}

compiler/rustc_codegen_ssa/src/base.rs

-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
1-
//! Codegen the completed AST to the LLVM IR.
2-
//!
3-
//! Some functions here, such as `codegen_block` and `codegen_expr`, return a value --
4-
//! the result of the codegen to LLVM -- while others, such as `codegen_fn`
5-
//! and `mono_item`, are called only for the side effect of adding a
6-
//! particular definition to the LLVM IR output we're producing.
7-
//!
8-
//! Hopefully useful general knowledge about codegen:
9-
//!
10-
//! * There's no way to find out the `Ty` type of a `Value`. Doing so
11-
//! would be "trying to get the eggs out of an omelette" (credit:
12-
//! pcwalton). You can, instead, find out its `llvm::Type` by calling `val_ty`,
13-
//! but one `llvm::Type` corresponds to many `Ty`s; for instance, `tup(int, int,
14-
//! int)` and `rec(x=int, y=int, z=int)` will have the same `llvm::Type`.
15-
161
use crate::back::write::{
172
compute_per_cgu_lto_type, start_async_codegen, submit_codegened_module_to_llvm,
183
submit_post_lto_module_to_llvm, submit_pre_lto_module_to_llvm, ComputedLtoType, OngoingCodegen,

compiler/rustc_hir/src/hir.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -760,9 +760,9 @@ pub struct Pat<'hir> {
760760
pub default_binding_modes: bool,
761761
}
762762

763-
impl Pat<'_> {
763+
impl<'hir> Pat<'hir> {
764764
// FIXME(#19596) this is a workaround, but there should be a better way
765-
fn walk_short_(&self, it: &mut impl FnMut(&Pat<'_>) -> bool) -> bool {
765+
fn walk_short_(&self, it: &mut impl FnMut(&Pat<'hir>) -> bool) -> bool {
766766
if !it(self) {
767767
return false;
768768
}
@@ -785,12 +785,12 @@ impl Pat<'_> {
785785
/// Note that when visiting e.g. `Tuple(ps)`,
786786
/// if visiting `ps[0]` returns `false`,
787787
/// then `ps[1]` will not be visited.
788-
pub fn walk_short(&self, mut it: impl FnMut(&Pat<'_>) -> bool) -> bool {
788+
pub fn walk_short(&self, mut it: impl FnMut(&Pat<'hir>) -> bool) -> bool {
789789
self.walk_short_(&mut it)
790790
}
791791

792792
// FIXME(#19596) this is a workaround, but there should be a better way
793-
fn walk_(&self, it: &mut impl FnMut(&Pat<'_>) -> bool) {
793+
fn walk_(&self, it: &mut impl FnMut(&Pat<'hir>) -> bool) {
794794
if !it(self) {
795795
return;
796796
}
@@ -810,7 +810,7 @@ impl Pat<'_> {
810810
/// Walk the pattern in left-to-right order.
811811
///
812812
/// If `it(pat)` returns `false`, the children are not visited.
813-
pub fn walk(&self, mut it: impl FnMut(&Pat<'_>) -> bool) {
813+
pub fn walk(&self, mut it: impl FnMut(&Pat<'hir>) -> bool) {
814814
self.walk_(&mut it)
815815
}
816816

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ fn msg_span_from_early_bound_and_free_regions(
153153
Some(Node::Item(it)) => item_scope_tag(&it),
154154
Some(Node::TraitItem(it)) => trait_item_scope_tag(&it),
155155
Some(Node::ImplItem(it)) => impl_item_scope_tag(&it),
156+
Some(Node::ForeignItem(it)) => foreign_item_scope_tag(&it),
156157
_ => unreachable!(),
157158
};
158159
let (prefix, span) = match *region {
@@ -233,6 +234,13 @@ fn impl_item_scope_tag(item: &hir::ImplItem<'_>) -> &'static str {
233234
}
234235
}
235236

237+
fn foreign_item_scope_tag(item: &hir::ForeignItem<'_>) -> &'static str {
238+
match item.kind {
239+
hir::ForeignItemKind::Fn(..) => "method body",
240+
hir::ForeignItemKind::Static(..) | hir::ForeignItemKind::Type => "associated item",
241+
}
242+
}
243+
236244
fn explain_span(tcx: TyCtxt<'tcx>, heading: &str, span: Span) -> (String, Option<Span>) {
237245
let lo = tcx.sess.source_map().lookup_char_pos(span.lo());
238246
(format!("the {} at {}:{}", heading, lo.line, lo.col.to_usize() + 1), Some(span))

compiler/rustc_typeck/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'tcx> CheckWfFcxBuilder<'tcx> {
5151
let fcx = FnCtxt::new(&inh, param_env, id);
5252
if !inh.tcx.features().trivial_bounds {
5353
// As predicates are cached rather than obligations, this
54-
// needsto be called first so that they are checked with an
54+
// needs to be called first so that they are checked with an
5555
// empty `param_env`.
5656
check_false_global_bounds(&fcx, span, id);
5757
}

compiler/rustc_typeck/src/collect/type_of.rs

+46-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir::def::{DefKind, Res};
66
use rustc_hir::def_id::{DefId, LocalDefId};
77
use rustc_hir::intravisit;
88
use rustc_hir::intravisit::Visitor;
9-
use rustc_hir::Node;
9+
use rustc_hir::{HirId, Node};
1010
use rustc_middle::hir::map::Map;
1111
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
1212
use rustc_middle::ty::util::IntTypeExt;
@@ -22,7 +22,6 @@ use super::{bad_placeholder_type, is_suggestable_infer_ty};
2222
/// This should be called using the query `tcx.opt_const_param_of`.
2323
pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<DefId> {
2424
use hir::*;
25-
2625
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
2726

2827
if let Node::AnonConst(_) = tcx.hir().get(hir_id) {
@@ -62,9 +61,9 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
6261
}
6362

6463
Node::Ty(&Ty { kind: TyKind::Path(_), .. })
65-
| Node::Expr(&Expr { kind: ExprKind::Struct(..), .. })
66-
| Node::Expr(&Expr { kind: ExprKind::Path(_), .. })
67-
| Node::TraitRef(..) => {
64+
| Node::Expr(&Expr { kind: ExprKind::Path(_) | ExprKind::Struct(..), .. })
65+
| Node::TraitRef(..)
66+
| Node::Pat(_) => {
6867
let path = match parent_node {
6968
Node::Ty(&Ty { kind: TyKind::Path(QPath::Resolved(_, path)), .. })
7069
| Node::TraitRef(&TraitRef { path, .. }) => &*path,
@@ -79,6 +78,20 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
7978
let _tables = tcx.typeck(body_owner);
8079
&*path
8180
}
81+
Node::Pat(pat) => {
82+
if let Some(path) = get_path_containing_arg_in_pat(pat, hir_id) {
83+
path
84+
} else {
85+
tcx.sess.delay_span_bug(
86+
tcx.def_span(def_id),
87+
&format!(
88+
"unable to find const parent for {} in pat {:?}",
89+
hir_id, pat
90+
),
91+
);
92+
return None;
93+
}
94+
}
8295
_ => {
8396
tcx.sess.delay_span_bug(
8497
tcx.def_span(def_id),
@@ -91,7 +104,6 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
91104
// We've encountered an `AnonConst` in some path, so we need to
92105
// figure out which generic parameter it corresponds to and return
93106
// the relevant type.
94-
95107
let (arg_index, segment) = path
96108
.segments
97109
.iter()
@@ -144,6 +156,34 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
144156
}
145157
}
146158

159+
fn get_path_containing_arg_in_pat<'hir>(
160+
pat: &'hir hir::Pat<'hir>,
161+
arg_id: HirId,
162+
) -> Option<&'hir hir::Path<'hir>> {
163+
use hir::*;
164+
165+
let is_arg_in_path = |p: &hir::Path<'_>| {
166+
p.segments
167+
.iter()
168+
.filter_map(|seg| seg.args)
169+
.flat_map(|args| args.args)
170+
.any(|arg| arg.id() == arg_id)
171+
};
172+
let mut arg_path = None;
173+
pat.walk(|pat| match pat.kind {
174+
PatKind::Struct(QPath::Resolved(_, path), _, _)
175+
| PatKind::TupleStruct(QPath::Resolved(_, path), _, _)
176+
| PatKind::Path(QPath::Resolved(_, path))
177+
if is_arg_in_path(path) =>
178+
{
179+
arg_path = Some(path);
180+
false
181+
}
182+
_ => true,
183+
});
184+
arg_path
185+
}
186+
147187
pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
148188
let def_id = def_id.expect_local();
149189
use rustc_hir::*;

src/bootstrap/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ impl Merge for TomlConfig {
335335
*x = Some(new);
336336
}
337337
}
338-
};
338+
}
339339
do_merge(&mut self.build, build);
340340
do_merge(&mut self.install, install);
341341
do_merge(&mut self.llvm, llvm);

0 commit comments

Comments
 (0)