Skip to content

Commit 03b01c5

Browse files
committed
Auto merge of #109253 - matthiaskrgr:rollup-2xmv5zk, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #108958 (Remove box expressions from HIR) - #109044 (Prevent stable `libtest` from supporting `-Zunstable-options`) - #109155 (Fix riscv64 fuchsia LLVM target name) - #109156 (Fix linker detection for clang with prefix) - #109181 (inherit_overflow: adapt pattern to also work with v0 mangling) - #109198 (Install projection from RPITIT to default trait method opaque correctly) - #109215 (Use sort_by_key instead of sort_by) - #109229 (Fix invalid markdown link references) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c50c62d + 0584bde commit 03b01c5

File tree

83 files changed

+451
-192
lines changed

Some content is hidden

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

83 files changed

+451
-192
lines changed

compiler/rustc_ast/src/util/parser.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ pub enum ExprPrecedence {
259259
Assign,
260260
AssignOp,
261261

262-
Box,
263262
AddrOf,
264263
Let,
265264
Unary,
@@ -319,8 +318,7 @@ impl ExprPrecedence {
319318
ExprPrecedence::AssignOp => AssocOp::Assign.precedence() as i8,
320319

321320
// Unary, prefix
322-
ExprPrecedence::Box
323-
| ExprPrecedence::AddrOf
321+
ExprPrecedence::AddrOf
324322
// Here `let pats = expr` has `let pats =` as a "unary" prefix of `expr`.
325323
// However, this is not exactly right. When `let _ = a` is the LHS of a binop we
326324
// need parens sometimes. E.g. we can print `(let _ = a) && b` as `let _ = a && b`

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ fn sccs_info<'cx, 'tcx>(
255255
let var_to_origin = infcx.reg_var_to_origin.borrow();
256256

257257
let mut var_to_origin_sorted = var_to_origin.clone().into_iter().collect::<Vec<_>>();
258-
var_to_origin_sorted.sort_by(|a, b| a.0.cmp(&b.0));
258+
var_to_origin_sorted.sort_by_key(|vto| vto.0);
259259
let mut debug_str = "region variables to origins:\n".to_string();
260260
for (reg_var, origin) in var_to_origin_sorted.into_iter() {
261261
debug_str.push_str(&format!("{:?}: {:?}\n", reg_var, origin));
@@ -2216,7 +2216,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22162216
// is in the same SCC or something. In that case, find what
22172217
// appears to be the most interesting point to report to the
22182218
// user via an even more ad-hoc guess.
2219-
categorized_path.sort_by(|p0, p1| p0.category.cmp(&p1.category));
2219+
categorized_path.sort_by_key(|p| p.category);
22202220
debug!("sorted_path={:#?}", categorized_path);
22212221

22222222
(categorized_path.remove(0), extra_info)

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1199,15 +1199,17 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
11991199
.and_then(|(lhs, rhs)| rhs.chars().all(char::is_numeric).then_some(lhs))
12001200
.unwrap_or(stem);
12011201

1202-
// GCC can have an optional target prefix.
1202+
// GCC/Clang can have an optional target prefix.
12031203
let flavor = if stem == "emcc" {
12041204
LinkerFlavor::EmCc
12051205
} else if stem == "gcc"
12061206
|| stem.ends_with("-gcc")
12071207
|| stem == "g++"
12081208
|| stem.ends_with("-g++")
12091209
|| stem == "clang"
1210+
|| stem.ends_with("-clang")
12101211
|| stem == "clang++"
1212+
|| stem.ends_with("-clang++")
12111213
{
12121214
LinkerFlavor::from_cli(LinkerFlavorCli::Gcc, &sess.target)
12131215
} else if stem == "wasm-ld" || stem.ends_with("-wasm-ld") {

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,6 @@ pub struct Expr<'hir> {
16731673
impl Expr<'_> {
16741674
pub fn precedence(&self) -> ExprPrecedence {
16751675
match self.kind {
1676-
ExprKind::Box(_) => ExprPrecedence::Box,
16771676
ExprKind::ConstBlock(_) => ExprPrecedence::ConstBlock,
16781677
ExprKind::Array(_) => ExprPrecedence::Array,
16791678
ExprKind::Call(..) => ExprPrecedence::Call,
@@ -1763,7 +1762,6 @@ impl Expr<'_> {
17631762
| ExprKind::Lit(_)
17641763
| ExprKind::ConstBlock(..)
17651764
| ExprKind::Unary(..)
1766-
| ExprKind::Box(..)
17671765
| ExprKind::AddrOf(..)
17681766
| ExprKind::Binary(..)
17691767
| ExprKind::Yield(..)
@@ -1851,7 +1849,6 @@ impl Expr<'_> {
18511849
| ExprKind::InlineAsm(..)
18521850
| ExprKind::AssignOp(..)
18531851
| ExprKind::ConstBlock(..)
1854-
| ExprKind::Box(..)
18551852
| ExprKind::Binary(..)
18561853
| ExprKind::Yield(..)
18571854
| ExprKind::DropTemps(..)
@@ -1862,8 +1859,7 @@ impl Expr<'_> {
18621859
/// To a first-order approximation, is this a pattern?
18631860
pub fn is_approximately_pattern(&self) -> bool {
18641861
match &self.kind {
1865-
ExprKind::Box(_)
1866-
| ExprKind::Array(_)
1862+
ExprKind::Array(_)
18671863
| ExprKind::Call(..)
18681864
| ExprKind::Tup(_)
18691865
| ExprKind::Lit(_)
@@ -1910,8 +1906,6 @@ pub fn is_range_literal(expr: &Expr<'_>) -> bool {
19101906

19111907
#[derive(Debug, HashStable_Generic)]
19121908
pub enum ExprKind<'hir> {
1913-
/// A `box x` expression.
1914-
Box(&'hir Expr<'hir>),
19151909
/// Allow anonymous constants from an inline `const` block
19161910
ConstBlock(AnonConst),
19171911
/// An array (e.g., `[a, b, c, d]`).

compiler/rustc_hir/src/intravisit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,6 @@ pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonCo
682682
pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>) {
683683
visitor.visit_id(expression.hir_id);
684684
match expression.kind {
685-
ExprKind::Box(ref subexpression) => visitor.visit_expr(subexpression),
686685
ExprKind::Array(subexpressions) => {
687686
walk_list!(visitor, visit_expr, subexpressions);
688687
}

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
557557
check_opaque(tcx, id);
558558
}
559559
DefKind::ImplTraitPlaceholder => {
560-
let parent = tcx.impl_trait_in_trait_parent(id.owner_id.to_def_id());
560+
let parent = tcx.impl_trait_in_trait_parent_fn(id.owner_id.to_def_id());
561561
// Only check the validity of this opaque type if the function has a default body
562562
if let hir::Node::TraitItem(hir::TraitItem {
563563
kind: hir::TraitItemKind::Fn(_, hir::TraitFn::Provided(_)),

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::autoderef::Autoderef;
22
use crate::constrained_generic_params::{identify_constrained_generic_params, Parameter};
33

4-
use hir::def::DefKind;
54
use rustc_ast as ast;
65
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
76
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed};
@@ -1548,16 +1547,27 @@ fn check_return_position_impl_trait_in_trait_bounds<'tcx>(
15481547
if let Some(assoc_item) = tcx.opt_associated_item(fn_def_id.to_def_id())
15491548
&& assoc_item.container == ty::AssocItemContainer::TraitContainer
15501549
{
1550+
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): Even with the new lowering
1551+
// strategy, we can't just call `check_associated_item` on the new RPITITs,
1552+
// because tests like `tests/ui/async-await/in-trait/implied-bounds.rs` will fail.
1553+
// That's because we need to check that the bounds of the RPITIT hold using
1554+
// the special substs that we create during opaque type lowering, otherwise we're
1555+
// getting a bunch of early bound and free regions mixed up... Haven't looked too
1556+
// deep into this, though.
15511557
for arg in fn_output.walk() {
15521558
if let ty::GenericArgKind::Type(ty) = arg.unpack()
1553-
&& let ty::Alias(ty::Opaque, proj) = ty.kind()
1554-
&& tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder
1555-
&& tcx.impl_trait_in_trait_parent(proj.def_id) == fn_def_id.to_def_id()
1559+
// RPITITs are always eagerly normalized into opaques, so always look for an
1560+
// opaque here.
1561+
&& let ty::Alias(ty::Opaque, opaque_ty) = ty.kind()
1562+
&& let Some(opaque_def_id) = opaque_ty.def_id.as_local()
1563+
&& let opaque = tcx.hir().expect_item(opaque_def_id).expect_opaque_ty()
1564+
&& let hir::OpaqueTyOrigin::FnReturn(source) | hir::OpaqueTyOrigin::AsyncFn(source) = opaque.origin
1565+
&& source == fn_def_id
15561566
{
1557-
let span = tcx.def_span(proj.def_id);
1558-
let bounds = wfcx.tcx().explicit_item_bounds(proj.def_id);
1567+
let span = tcx.def_span(opaque_ty.def_id);
1568+
let bounds = wfcx.tcx().explicit_item_bounds(opaque_ty.def_id);
15591569
let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| {
1560-
let bound = ty::EarlyBinder(bound).subst(tcx, proj.substs);
1570+
let bound = ty::EarlyBinder(bound).subst(tcx, opaque_ty.substs);
15611571
let normalized_bound = wfcx.normalize(span, None, bound);
15621572
traits::wf::predicate_obligations(
15631573
wfcx.infcx,

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::astconv::AstConv;
33
use rustc_hir as hir;
44
use rustc_infer::traits::util;
55
use rustc_middle::ty::subst::InternalSubsts;
6-
use rustc_middle::ty::{self, ImplTraitInTraitData, Ty, TyCtxt};
6+
use rustc_middle::ty::{self, Ty, TyCtxt};
77
use rustc_span::def_id::DefId;
88
use rustc_span::Span;
99

@@ -76,18 +76,26 @@ pub(super) fn explicit_item_bounds(
7676
tcx: TyCtxt<'_>,
7777
def_id: DefId,
7878
) -> &'_ [(ty::Predicate<'_>, Span)] {
79-
// If the def_id is about an RPITIT, delegate explicit_item_bounds to the opaque_def_id that
80-
// generated the synthesized associate type.
81-
let rpitit_info = if let Some(ImplTraitInTraitData::Trait { opaque_def_id, .. }) =
82-
tcx.opt_rpitit_info(def_id)
83-
{
84-
Some(opaque_def_id)
85-
} else {
86-
None
87-
};
79+
match tcx.opt_rpitit_info(def_id) {
80+
// RPITIT's bounds are the same as opaque type bounds, but with
81+
// a projection self type.
82+
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {
83+
let item = tcx.hir().get_by_def_id(opaque_def_id.expect_local()).expect_item();
84+
let opaque_ty = item.expect_opaque_ty();
85+
return opaque_type_bounds(
86+
tcx,
87+
opaque_def_id,
88+
opaque_ty.bounds,
89+
tcx.mk_projection(def_id, ty::InternalSubsts::identity_for_item(tcx, def_id)),
90+
item.span,
91+
);
92+
}
93+
// These should have been fed!
94+
Some(ty::ImplTraitInTraitData::Impl { .. }) => unreachable!(),
95+
None => {}
96+
}
8897

89-
let bounds_def_id = rpitit_info.unwrap_or(def_id);
90-
let hir_id = tcx.hir().local_def_id_to_hir_id(bounds_def_id.expect_local());
98+
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
9199
match tcx.hir().get(hir_id) {
92100
hir::Node::TraitItem(hir::TraitItem {
93101
kind: hir::TraitItemKind::Type(bounds, _),
@@ -100,12 +108,12 @@ pub(super) fn explicit_item_bounds(
100108
..
101109
}) => {
102110
let substs = InternalSubsts::identity_for_item(tcx, def_id);
103-
let item_ty = if *in_trait || rpitit_info.is_some() {
111+
let item_ty = if *in_trait && !tcx.lower_impl_trait_in_trait_to_assoc_ty() {
104112
tcx.mk_projection(def_id, substs)
105113
} else {
106114
tcx.mk_opaque(def_id, substs)
107115
};
108-
opaque_type_bounds(tcx, bounds_def_id, bounds, item_ty, *span)
116+
opaque_type_bounds(tcx, def_id, bounds, item_ty, *span)
109117
}
110118
_ => bug!("item_bounds called on {:?}", def_id),
111119
}

compiler/rustc_hir_analysis/src/variance/mod.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,14 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
112112
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
113113
match t.kind() {
114114
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
115-
if matches!(
116-
self.tcx.def_kind(*def_id),
117-
DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder
118-
) =>
115+
if matches!(self.tcx.def_kind(*def_id), DefKind::OpaqueTy) =>
116+
{
117+
self.visit_opaque(*def_id, substs)
118+
}
119+
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty) check whether this is necessary
120+
// at all for RPITITs.
121+
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
122+
if self.tcx.is_impl_trait_in_trait(*def_id) =>
119123
{
120124
self.visit_opaque(*def_id, substs)
121125
}

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,10 +1366,6 @@ impl<'a> State<'a> {
13661366
self.ibox(INDENT_UNIT);
13671367
self.ann.pre(self, AnnNode::Expr(expr));
13681368
match expr.kind {
1369-
hir::ExprKind::Box(expr) => {
1370-
self.word_space("Box::new");
1371-
self.print_call_post(std::slice::from_ref(expr));
1372-
}
13731369
hir::ExprKind::Array(exprs) => {
13741370
self.print_expr_vec(exprs);
13751371
}

0 commit comments

Comments
 (0)