Skip to content

Commit 3eb5c45

Browse files
committed
Auto merge of rust-lang#108211 - matthiaskrgr:rollup-e59onmm, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#108031 (Don't recover lifetimes/labels containing emojis as character literals) - rust-lang#108046 (Don't allow evaluating queries that were fed in a previous compiler run) - rust-lang#108162 (Don't eagerly convert principal to string) - rust-lang#108186 (Deny non-lifetime bound vars in `for<..> ||` closure binders) - rust-lang#108197 (Update cargo) - rust-lang#108205 (link to llvm changes that prompted the special cases) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3701bdc + 6c91efd commit 3eb5c45

File tree

39 files changed

+428
-158
lines changed

39 files changed

+428
-158
lines changed

Diff for: Cargo.lock

+4-15
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ dependencies = [
782782
"declare_clippy_lint",
783783
"if_chain",
784784
"itertools",
785-
"pulldown-cmark 0.9.2",
785+
"pulldown-cmark",
786786
"quine-mc_cluskey",
787787
"regex-syntax",
788788
"rustc-semver",
@@ -2555,7 +2555,7 @@ dependencies = [
25552555
"memchr",
25562556
"once_cell",
25572557
"opener",
2558-
"pulldown-cmark 0.9.2",
2558+
"pulldown-cmark",
25592559
"regex",
25602560
"serde",
25612561
"serde_json",
@@ -2572,7 +2572,7 @@ dependencies = [
25722572
"anyhow",
25732573
"handlebars 3.5.5",
25742574
"pretty_assertions",
2575-
"pulldown-cmark 0.7.2",
2575+
"pulldown-cmark",
25762576
"same-file",
25772577
"serde_json",
25782578
"url",
@@ -3269,17 +3269,6 @@ dependencies = [
32693269
"cc",
32703270
]
32713271

3272-
[[package]]
3273-
name = "pulldown-cmark"
3274-
version = "0.7.2"
3275-
source = "registry+https://github.com/rust-lang/crates.io-index"
3276-
checksum = "ca36dea94d187597e104a5c8e4b07576a8a45aa5db48a65e12940d3eb7461f55"
3277-
dependencies = [
3278-
"bitflags",
3279-
"memchr",
3280-
"unicase",
3281-
]
3282-
32833272
[[package]]
32843273
name = "pulldown-cmark"
32853274
version = "0.9.2"
@@ -4583,7 +4572,7 @@ name = "rustc_resolve"
45834572
version = "0.0.0"
45844573
dependencies = [
45854574
"bitflags",
4586-
"pulldown-cmark 0.9.2",
4575+
"pulldown-cmark",
45874576
"rustc_arena",
45884577
"rustc_ast",
45894578
"rustc_ast_pretty",

Diff for: compiler/rustc_codegen_llvm/src/context.rs

+5
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,13 @@ pub unsafe fn create_module<'ll>(
145145
let llvm_version = llvm_util::get_version();
146146
if llvm_version < (16, 0, 0) {
147147
if sess.target.arch == "s390x" {
148+
// LLVM 16 data layout changed to always set 64-bit vector alignment,
149+
// which is conditional in earlier LLVM versions.
150+
// https://reviews.llvm.org/D131158 for the discussion.
148151
target_data_layout = target_data_layout.replace("-v128:64", "");
149152
} else if sess.target.arch == "riscv64" {
153+
// LLVM 16 introduced this change so as to produce more efficient code.
154+
// See https://reviews.llvm.org/D116735 for the discussion.
150155
target_data_layout = target_data_layout.replace("-n32:64-", "-n64-");
151156
}
152157
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,8 @@ pub enum StashKey {
471471
/// When an invalid lifetime e.g. `'2` should be reinterpreted
472472
/// as a char literal in the parser
473473
LifetimeIsChar,
474+
/// When an invalid lifetime e.g. `'🐱` contains emoji.
475+
LifetimeContainsEmoji,
474476
/// Maybe there was a typo where a comma was forgotten before
475477
/// FRU syntax
476478
MaybeFruTypo,

Diff for: compiler/rustc_feature/src/active.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ declare_features! (
474474
/// Allows using the `non_exhaustive_omitted_patterns` lint.
475475
(active, non_exhaustive_omitted_patterns_lint, "1.57.0", Some(89554), None),
476476
/// Allows `for<T>` binders in where-clauses
477-
(incomplete, non_lifetime_binders, "CURRENT_RUSTC_VERSION", Some(1), None),
477+
(incomplete, non_lifetime_binders, "CURRENT_RUSTC_VERSION", Some(108185), None),
478478
/// Allows making `dyn Trait` well-formed even if `Trait` is not object safe.
479479
/// In that case, `dyn Trait: Trait` does not hold. Moreover, coercions and
480480
/// casts in safe Rust to `dyn Trait` for such a `Trait` is also forbidden.

Diff for: compiler/rustc_hir_analysis/src/astconv/mod.rs

+8-46
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
252252
// (*) -- not late-bound, won't change
253253
}
254254

255+
Some(rbv::ResolvedArg::Error(_)) => {
256+
bug!("only ty/ct should resolve as ResolvedArg::Error")
257+
}
258+
255259
None => {
256260
self.re_infer(def, lifetime.ident.span).unwrap_or_else(|| {
257261
debug!(?lifetime, "unelided lifetime in signature");
@@ -2689,6 +2693,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26892693
let index = generics.param_def_id_to_index[&def_id.to_def_id()];
26902694
tcx.mk_ty_param(index, tcx.hir().ty_param_name(def_id))
26912695
}
2696+
Some(rbv::ResolvedArg::Error(guar)) => tcx.ty_error_with_guaranteed(guar),
26922697
arg => bug!("unexpected bound var resolution for {hir_id:?}: {arg:?}"),
26932698
}
26942699
}
@@ -2893,22 +2898,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
28932898
hir::TyKind::BareFn(bf) => {
28942899
require_c_abi_if_c_variadic(tcx, bf.decl, bf.abi, ast_ty.span);
28952900

2896-
let fn_ptr_ty = tcx.mk_fn_ptr(self.ty_of_fn(
2901+
tcx.mk_fn_ptr(self.ty_of_fn(
28972902
ast_ty.hir_id,
28982903
bf.unsafety,
28992904
bf.abi,
29002905
bf.decl,
29012906
None,
29022907
Some(ast_ty),
2903-
));
2904-
2905-
if let Some(guar) =
2906-
deny_non_region_late_bound(tcx, bf.generic_params, "function pointer")
2907-
{
2908-
tcx.ty_error_with_guaranteed(guar)
2909-
} else {
2910-
fn_ptr_ty
2911-
}
2908+
))
29122909
}
29132910
hir::TyKind::TraitObject(bounds, lifetime, repr) => {
29142911
self.maybe_lint_bare_trait(ast_ty, in_path);
@@ -2917,21 +2914,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
29172914
TraitObjectSyntax::DynStar => ty::DynStar,
29182915
};
29192916

2920-
let object_ty = self.conv_object_ty_poly_trait_ref(
2921-
ast_ty.span,
2922-
bounds,
2923-
lifetime,
2924-
borrowed,
2925-
repr,
2926-
);
2927-
2928-
if let Some(guar) = bounds.iter().find_map(|trait_ref| {
2929-
deny_non_region_late_bound(tcx, trait_ref.bound_generic_params, "trait object")
2930-
}) {
2931-
tcx.ty_error_with_guaranteed(guar)
2932-
} else {
2933-
object_ty
2934-
}
2917+
self.conv_object_ty_poly_trait_ref(ast_ty.span, bounds, lifetime, borrowed, repr)
29352918
}
29362919
hir::TyKind::Path(hir::QPath::Resolved(maybe_qself, path)) => {
29372920
debug!(?maybe_qself, ?path);
@@ -3392,24 +3375,3 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
33923375
}
33933376
}
33943377
}
3395-
3396-
fn deny_non_region_late_bound(
3397-
tcx: TyCtxt<'_>,
3398-
params: &[hir::GenericParam<'_>],
3399-
where_: &str,
3400-
) -> Option<ErrorGuaranteed> {
3401-
params.iter().find_map(|bad_param| {
3402-
let what = match bad_param.kind {
3403-
hir::GenericParamKind::Type { .. } => "type",
3404-
hir::GenericParamKind::Const { .. } => "const",
3405-
hir::GenericParamKind::Lifetime { .. } => return None,
3406-
};
3407-
3408-
let mut diag = tcx.sess.struct_span_err(
3409-
bad_param.span,
3410-
format!("late-bound {what} parameter not allowed on {where_} types"),
3411-
);
3412-
3413-
Some(if tcx.features().non_lifetime_binders { diag.emit() } else { diag.delay_as_bug() })
3414-
})
3415-
}

Diff for: compiler/rustc_hir_analysis/src/collect/generics_of.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,12 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option<S
398398
Some(rbv::ResolvedArg::StaticLifetime | rbv::ResolvedArg::EarlyBound(..)) => {}
399399
Some(rbv::ResolvedArg::LateBound(debruijn, _, _))
400400
if debruijn < self.outer_index => {}
401-
Some(rbv::ResolvedArg::LateBound(..) | rbv::ResolvedArg::Free(..)) | None => {
401+
Some(
402+
rbv::ResolvedArg::LateBound(..)
403+
| rbv::ResolvedArg::Free(..)
404+
| rbv::ResolvedArg::Error(_),
405+
)
406+
| None => {
402407
self.has_late_bound_regions = Some(lt.ident.span);
403408
}
404409
}

Diff for: compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+100-38
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl RegionExt for ResolvedArg {
5050

5151
fn id(&self) -> Option<DefId> {
5252
match *self {
53-
ResolvedArg::StaticLifetime => None,
53+
ResolvedArg::StaticLifetime | ResolvedArg::Error(_) => None,
5454

5555
ResolvedArg::EarlyBound(id)
5656
| ResolvedArg::LateBound(_, _, id)
@@ -336,7 +336,57 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
336336
}
337337
}
338338
}
339+
340+
fn visit_poly_trait_ref_inner(
341+
&mut self,
342+
trait_ref: &'tcx hir::PolyTraitRef<'tcx>,
343+
non_lifetime_binder_allowed: NonLifetimeBinderAllowed,
344+
) {
345+
debug!("visit_poly_trait_ref(trait_ref={:?})", trait_ref);
346+
347+
let (mut binders, scope_type) = self.poly_trait_ref_binder_info();
348+
349+
let initial_bound_vars = binders.len() as u32;
350+
let mut bound_vars: FxIndexMap<LocalDefId, ResolvedArg> = FxIndexMap::default();
351+
let binders_iter =
352+
trait_ref.bound_generic_params.iter().enumerate().map(|(late_bound_idx, param)| {
353+
let pair = ResolvedArg::late(initial_bound_vars + late_bound_idx as u32, param);
354+
let r = late_arg_as_bound_arg(self.tcx, &pair.1, param);
355+
bound_vars.insert(pair.0, pair.1);
356+
r
357+
});
358+
binders.extend(binders_iter);
359+
360+
if let NonLifetimeBinderAllowed::Deny(where_) = non_lifetime_binder_allowed {
361+
deny_non_region_late_bound(self.tcx, &mut bound_vars, where_);
362+
}
363+
364+
debug!(?binders);
365+
self.record_late_bound_vars(trait_ref.trait_ref.hir_ref_id, binders);
366+
367+
// Always introduce a scope here, even if this is in a where clause and
368+
// we introduced the binders around the bounded Ty. In that case, we
369+
// just reuse the concatenation functionality also present in nested trait
370+
// refs.
371+
let scope = Scope::Binder {
372+
hir_id: trait_ref.trait_ref.hir_ref_id,
373+
bound_vars,
374+
s: self.scope,
375+
scope_type,
376+
where_bound_origin: None,
377+
};
378+
self.with(scope, |this| {
379+
walk_list!(this, visit_generic_param, trait_ref.bound_generic_params);
380+
this.visit_trait_ref(&trait_ref.trait_ref);
381+
});
382+
}
383+
}
384+
385+
enum NonLifetimeBinderAllowed {
386+
Deny(&'static str),
387+
Allow,
339388
}
389+
340390
impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
341391
type NestedFilter = nested_filter::OnlyBodies;
342392

@@ -400,7 +450,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
400450
}
401451
}
402452

403-
let (bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) =
453+
let (mut bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) =
404454
bound_generic_params
405455
.iter()
406456
.enumerate()
@@ -411,6 +461,8 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
411461
})
412462
.unzip();
413463

464+
deny_non_region_late_bound(self.tcx, &mut bound_vars, "closures");
465+
414466
self.record_late_bound_vars(e.hir_id, binders);
415467
let scope = Scope::Binder {
416468
hir_id: e.hir_id,
@@ -567,7 +619,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
567619
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx>) {
568620
match ty.kind {
569621
hir::TyKind::BareFn(c) => {
570-
let (bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) = c
622+
let (mut bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) = c
571623
.generic_params
572624
.iter()
573625
.enumerate()
@@ -577,6 +629,9 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
577629
(pair, r)
578630
})
579631
.unzip();
632+
633+
deny_non_region_late_bound(self.tcx, &mut bound_vars, "function pointer types");
634+
580635
self.record_late_bound_vars(ty.hir_id, binders);
581636
let scope = Scope::Binder {
582637
hir_id: ty.hir_id,
@@ -596,7 +651,10 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
596651
let scope = Scope::TraitRefBoundary { s: self.scope };
597652
self.with(scope, |this| {
598653
for bound in bounds {
599-
this.visit_poly_trait_ref(bound);
654+
this.visit_poly_trait_ref_inner(
655+
bound,
656+
NonLifetimeBinderAllowed::Deny("trait object types"),
657+
);
600658
}
601659
});
602660
match lifetime.res {
@@ -967,39 +1025,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
9671025
}
9681026

9691027
fn visit_poly_trait_ref(&mut self, trait_ref: &'tcx hir::PolyTraitRef<'tcx>) {
970-
debug!("visit_poly_trait_ref(trait_ref={:?})", trait_ref);
971-
972-
let (mut binders, scope_type) = self.poly_trait_ref_binder_info();
973-
974-
let initial_bound_vars = binders.len() as u32;
975-
let mut bound_vars: FxIndexMap<LocalDefId, ResolvedArg> = FxIndexMap::default();
976-
let binders_iter =
977-
trait_ref.bound_generic_params.iter().enumerate().map(|(late_bound_idx, param)| {
978-
let pair = ResolvedArg::late(initial_bound_vars + late_bound_idx as u32, param);
979-
let r = late_arg_as_bound_arg(self.tcx, &pair.1, param);
980-
bound_vars.insert(pair.0, pair.1);
981-
r
982-
});
983-
binders.extend(binders_iter);
984-
985-
debug!(?binders);
986-
self.record_late_bound_vars(trait_ref.trait_ref.hir_ref_id, binders);
987-
988-
// Always introduce a scope here, even if this is in a where clause and
989-
// we introduced the binders around the bounded Ty. In that case, we
990-
// just reuse the concatenation functionality also present in nested trait
991-
// refs.
992-
let scope = Scope::Binder {
993-
hir_id: trait_ref.trait_ref.hir_ref_id,
994-
bound_vars,
995-
s: self.scope,
996-
scope_type,
997-
where_bound_origin: None,
998-
};
999-
self.with(scope, |this| {
1000-
walk_list!(this, visit_generic_param, trait_ref.bound_generic_params);
1001-
this.visit_trait_ref(&trait_ref.trait_ref);
1002-
});
1028+
self.visit_poly_trait_ref_inner(trait_ref, NonLifetimeBinderAllowed::Allow);
10031029
}
10041030
}
10051031

@@ -1364,7 +1390,9 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
13641390
return;
13651391
}
13661392

1367-
span_bug!(self.tcx.hir().span(hir_id), "could not resolve {param_def_id:?}",);
1393+
self.tcx
1394+
.sess
1395+
.delay_span_bug(self.tcx.hir().span(hir_id), "could not resolve {param_def_id:?}");
13681396
}
13691397

13701398
#[instrument(level = "debug", skip(self))]
@@ -1915,3 +1943,37 @@ fn is_late_bound_map(
19151943
}
19161944
}
19171945
}
1946+
1947+
pub fn deny_non_region_late_bound(
1948+
tcx: TyCtxt<'_>,
1949+
bound_vars: &mut FxIndexMap<LocalDefId, ResolvedArg>,
1950+
where_: &str,
1951+
) {
1952+
let mut first = true;
1953+
1954+
for (var, arg) in bound_vars {
1955+
let Node::GenericParam(param) = tcx.hir().get_by_def_id(*var) else {
1956+
bug!();
1957+
};
1958+
1959+
let what = match param.kind {
1960+
hir::GenericParamKind::Type { .. } => "type",
1961+
hir::GenericParamKind::Const { .. } => "const",
1962+
hir::GenericParamKind::Lifetime { .. } => continue,
1963+
};
1964+
1965+
let mut diag = tcx.sess.struct_span_err(
1966+
param.span,
1967+
format!("late-bound {what} parameter not allowed on {where_}"),
1968+
);
1969+
1970+
let guar = if tcx.features().non_lifetime_binders && first {
1971+
diag.emit()
1972+
} else {
1973+
diag.delay_as_bug()
1974+
};
1975+
1976+
first = false;
1977+
*arg = ResolvedArg::Error(guar);
1978+
}
1979+
}

0 commit comments

Comments
 (0)