Skip to content

Commit 8361aef

Browse files
committed
Auto merge of rust-lang#135496 - matthiaskrgr:rollup-ps0cjzn, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#134216 (Enable "jump to def" feature on patterns) - rust-lang#134880 (Made `Path::name` only have item name rather than full name) - rust-lang#135466 (Leak check in `impossible_predicates` to avoid monomorphizing impossible instances) - rust-lang#135476 (Remove remnant of asmjs) - rust-lang#135479 (mir borrowck: cleanup late-bound region handling) - rust-lang#135493 (Fix legacy symbol mangling of closures) - rust-lang#135495 (Add missing closing backtick in commit hook message 🐸) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3736b85 + eb763f8 commit 8361aef

File tree

20 files changed

+230
-92
lines changed

20 files changed

+230
-92
lines changed

Diff for: compiler/rustc_borrowck/src/renumber.rs

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ pub(crate) enum RegionCtxt {
3434
Location(Location),
3535
TyContext(TyContext),
3636
Free(Symbol),
37-
Bound(Symbol),
3837
LateBound(Symbol),
3938
Existential(Option<Symbol>),
4039
Placeholder(Symbol),

Diff for: compiler/rustc_borrowck/src/universal_regions.rs

+26-39
Original file line numberDiff line numberDiff line change
@@ -467,15 +467,13 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
467467
self.infcx.tcx.local_parent(self.mir_def),
468468
|r| {
469469
debug!(?r);
470-
if !indices.indices.contains_key(&r) {
471-
let region_vid = {
472-
let name = r.get_name_or_anon();
473-
self.infcx.next_nll_region_var(FR, || RegionCtxt::LateBound(name))
474-
};
475-
476-
debug!(?region_vid);
477-
indices.insert_late_bound_region(r, region_vid.as_var());
478-
}
470+
let region_vid = {
471+
let name = r.get_name_or_anon();
472+
self.infcx.next_nll_region_var(FR, || RegionCtxt::LateBound(name))
473+
};
474+
475+
debug!(?region_vid);
476+
indices.insert_late_bound_region(r, region_vid.as_var());
479477
},
480478
);
481479

@@ -484,21 +482,17 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
484482
self.infcx.num_region_vars()
485483
};
486484

487-
// "Liberate" the late-bound regions. These correspond to
488-
// "local" free regions.
485+
// Converse of above, if this is a function/closure then the late-bound regions declared
486+
// on its signature are local.
487+
//
488+
// We manually loop over `bound_inputs_and_output` instead of using
489+
// `for_each_late_bound_region_in_item` as we may need to add the otherwise
490+
// implicit `ClosureEnv` region.
489491
let bound_inputs_and_output = self.compute_inputs_and_output(&indices, defining_ty);
490-
491-
let inputs_and_output = self.infcx.replace_bound_regions_with_nll_infer_vars(
492-
FR,
493-
self.mir_def,
494-
bound_inputs_and_output,
495-
&mut indices,
496-
);
497-
// Converse of above, if this is a function/closure then the late-bound regions declared on its
498-
// signature are local.
499-
for_each_late_bound_region_in_item(self.infcx.tcx, self.mir_def, |r| {
500-
debug!(?r);
501-
if !indices.indices.contains_key(&r) {
492+
for (idx, bound_var) in bound_inputs_and_output.bound_vars().iter().enumerate() {
493+
if let ty::BoundVariableKind::Region(kind) = bound_var {
494+
let kind = ty::LateParamRegionKind::from_bound(ty::BoundVar::from_usize(idx), kind);
495+
let r = ty::Region::new_late_param(self.infcx.tcx, self.mir_def.to_def_id(), kind);
502496
let region_vid = {
503497
let name = r.get_name_or_anon();
504498
self.infcx.next_nll_region_var(FR, || RegionCtxt::LateBound(name))
@@ -507,7 +501,12 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
507501
debug!(?region_vid);
508502
indices.insert_late_bound_region(r, region_vid.as_var());
509503
}
510-
});
504+
}
505+
let inputs_and_output = self.infcx.replace_bound_regions_with_nll_infer_vars(
506+
self.mir_def,
507+
bound_inputs_and_output,
508+
&indices,
509+
);
511510

512511
let (unnormalized_output_ty, mut unnormalized_input_tys) =
513512
inputs_and_output.split_last().unwrap();
@@ -832,10 +831,9 @@ impl<'tcx> BorrowckInferCtxt<'tcx> {
832831
#[instrument(level = "debug", skip(self, indices))]
833832
fn replace_bound_regions_with_nll_infer_vars<T>(
834833
&self,
835-
origin: NllRegionVariableOrigin,
836834
all_outlive_scope: LocalDefId,
837835
value: ty::Binder<'tcx, T>,
838-
indices: &mut UniversalRegionIndices<'tcx>,
836+
indices: &UniversalRegionIndices<'tcx>,
839837
) -> T
840838
where
841839
T: TypeFoldable<TyCtxt<'tcx>>,
@@ -845,18 +843,7 @@ impl<'tcx> BorrowckInferCtxt<'tcx> {
845843
let kind = ty::LateParamRegionKind::from_bound(br.var, br.kind);
846844
let liberated_region =
847845
ty::Region::new_late_param(self.tcx, all_outlive_scope.to_def_id(), kind);
848-
let region_vid = {
849-
let name = match br.kind.get_name() {
850-
Some(name) => name,
851-
_ => sym::anon,
852-
};
853-
854-
self.next_nll_region_var(origin, || RegionCtxt::Bound(name))
855-
};
856-
857-
indices.insert_late_bound_region(liberated_region, region_vid.as_var());
858-
debug!(?liberated_region, ?region_vid);
859-
region_vid
846+
ty::Region::new_var(self.tcx, indices.to_region_vid(liberated_region))
860847
});
861848
value
862849
}
@@ -870,7 +857,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
870857
/// well. These are used for error reporting.
871858
fn insert_late_bound_region(&mut self, r: ty::Region<'tcx>, vid: ty::RegionVid) {
872859
debug!("insert_late_bound_region({:?}, {:?})", r, vid);
873-
self.indices.insert(r, vid);
860+
assert_eq!(self.indices.insert(r, vid), None);
874861
}
875862

876863
/// Converts `r` into a local inference variable: `r` can either

Diff for: compiler/rustc_symbol_mangling/src/legacy.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ pub(super) fn mangle<'tcx>(
1919
let def_id = instance.def_id();
2020

2121
// We want to compute the "type" of this item. Unfortunately, some
22-
// kinds of items (e.g., closures) don't have an entry in the
23-
// item-type array. So walk back up the find the closest parent
24-
// that DOES have an entry.
22+
// kinds of items (e.g., synthetic static allocations from const eval)
23+
// don't have a proper implementation for the `type_of` query. So walk
24+
// back up the find the closest parent that DOES have a type.
2525
let mut ty_def_id = def_id;
2626
let instance_ty;
2727
loop {
2828
let key = tcx.def_key(ty_def_id);
2929
match key.disambiguated_data.data {
30-
DefPathData::TypeNs(_) | DefPathData::ValueNs(_) => {
30+
DefPathData::TypeNs(_) | DefPathData::ValueNs(_) | DefPathData::Closure => {
3131
instance_ty = tcx.type_of(ty_def_id).instantiate_identity();
3232
debug!(?instance_ty);
3333
break;

Diff for: compiler/rustc_trait_selection/src/traits/mod.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,18 @@ pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec<ty::Clause
714714
}
715715
let errors = ocx.select_all_or_error();
716716

717-
let result = !errors.is_empty();
718-
debug!("impossible_predicates = {:?}", result);
719-
result
717+
if !errors.is_empty() {
718+
return true;
719+
}
720+
721+
// Leak check for any higher-ranked trait mismatches.
722+
// We only need to do this in the old solver, since the new solver already
723+
// leak-checks.
724+
if !infcx.next_trait_solver() && infcx.leak_check(ty::UniverseIndex::ROOT, None).is_err() {
725+
return true;
726+
}
727+
728+
false
720729
}
721730

722731
fn instantiate_and_check_impossible_predicates<'tcx>(

Diff for: src/bootstrap/src/core/build_steps/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn print_paths(verb: &str, adjective: Option<&str>, paths: &[String]) {
116116
println!("fmt: {verb} {len} {adjective}files");
117117
}
118118
if len > 1000 && !CiEnv::is_ci() {
119-
println!("hint: if this number seems too high, try running `git fetch origin master");
119+
println!("hint: if this number seems too high, try running `git fetch origin master`");
120120
}
121121
}
122122

Diff for: src/ci/docker/scripts/emscripten.sh

-24
This file was deleted.

Diff for: src/librustdoc/html/highlight.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ enum Class {
337337
Ident(Span),
338338
Lifetime,
339339
PreludeTy(Span),
340-
PreludeVal,
340+
PreludeVal(Span),
341341
QuestionMark,
342342
Decoration(&'static str),
343343
}
@@ -385,7 +385,7 @@ impl Class {
385385
Class::Ident(_) => "",
386386
Class::Lifetime => "lifetime",
387387
Class::PreludeTy(_) => "prelude-ty",
388-
Class::PreludeVal => "prelude-val",
388+
Class::PreludeVal(_) => "prelude-val",
389389
Class::QuestionMark => "question-mark",
390390
Class::Decoration(kind) => kind,
391391
}
@@ -395,7 +395,11 @@ impl Class {
395395
/// a "span" (a tuple representing `(lo, hi)` equivalent of `Span`).
396396
fn get_span(self) -> Option<Span> {
397397
match self {
398-
Self::Ident(sp) | Self::Self_(sp) | Self::Macro(sp) | Self::PreludeTy(sp) => Some(sp),
398+
Self::Ident(sp)
399+
| Self::Self_(sp)
400+
| Self::Macro(sp)
401+
| Self::PreludeTy(sp)
402+
| Self::PreludeVal(sp) => Some(sp),
399403
Self::Comment
400404
| Self::DocComment
401405
| Self::Attribute
@@ -406,7 +410,6 @@ impl Class {
406410
| Self::Number
407411
| Self::Bool
408412
| Self::Lifetime
409-
| Self::PreludeVal
410413
| Self::QuestionMark
411414
| Self::Decoration(_) => None,
412415
}
@@ -851,7 +854,9 @@ impl<'src> Classifier<'src> {
851854
TokenKind::Ident => match get_real_ident_class(text, false) {
852855
None => match text {
853856
"Option" | "Result" => Class::PreludeTy(self.new_span(before, text)),
854-
"Some" | "None" | "Ok" | "Err" => Class::PreludeVal,
857+
"Some" | "None" | "Ok" | "Err" => {
858+
Class::PreludeVal(self.new_span(before, text))
859+
}
855860
// "union" is a weak keyword and is only considered as a keyword when declaring
856861
// a union type.
857862
"union" if self.check_if_is_union_keyword() => Class::KeyWord,

Diff for: src/librustdoc/html/render/span_map.rs

+29-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
44
use rustc_hir::def::{DefKind, Res};
55
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
66
use rustc_hir::intravisit::{self, Visitor};
7-
use rustc_hir::{ExprKind, HirId, Item, ItemKind, Mod, Node};
7+
use rustc_hir::{ExprKind, HirId, Item, ItemKind, Mod, Node, Pat, PatKind, QPath};
88
use rustc_middle::hir::nested_filter;
99
use rustc_middle::ty::TyCtxt;
1010
use rustc_span::hygiene::MacroKind;
@@ -170,7 +170,7 @@ impl SpanMapVisitor<'_> {
170170
true
171171
}
172172

173-
fn handle_call(&mut self, hir_id: HirId, expr_hir_id: Option<HirId>, span: Span) {
173+
fn infer_id(&mut self, hir_id: HirId, expr_hir_id: Option<HirId>, span: Span) {
174174
let hir = self.tcx.hir();
175175
let body_id = hir.enclosing_body_owner(hir_id);
176176
// FIXME: this is showing error messages for parts of the code that are not
@@ -189,6 +189,27 @@ impl SpanMapVisitor<'_> {
189189
self.matches.insert(span, link);
190190
}
191191
}
192+
193+
fn handle_pat(&mut self, p: &Pat<'_>) {
194+
match p.kind {
195+
PatKind::Binding(_, _, _, Some(p)) => self.handle_pat(p),
196+
PatKind::Struct(qpath, _, _)
197+
| PatKind::TupleStruct(qpath, _, _)
198+
| PatKind::Path(qpath) => match qpath {
199+
QPath::TypeRelative(_, path) if matches!(path.res, Res::Err) => {
200+
self.infer_id(path.hir_id, Some(p.hir_id), qpath.span());
201+
}
202+
QPath::Resolved(_, path) => self.handle_path(path),
203+
_ => {}
204+
},
205+
PatKind::Or(pats) => {
206+
for pat in pats {
207+
self.handle_pat(pat);
208+
}
209+
}
210+
_ => {}
211+
}
212+
}
192213
}
193214

194215
impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
@@ -206,6 +227,10 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
206227
intravisit::walk_path(self, path);
207228
}
208229

230+
fn visit_pat(&mut self, p: &Pat<'tcx>) {
231+
self.handle_pat(p);
232+
}
233+
209234
fn visit_mod(&mut self, m: &'tcx Mod<'tcx>, span: Span, id: HirId) {
210235
// To make the difference between "mod foo {}" and "mod foo;". In case we "import" another
211236
// file, we want to link to it. Otherwise no need to create a link.
@@ -228,9 +253,9 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
228253
fn visit_expr(&mut self, expr: &'tcx rustc_hir::Expr<'tcx>) {
229254
match expr.kind {
230255
ExprKind::MethodCall(segment, ..) => {
231-
self.handle_call(segment.hir_id, Some(expr.hir_id), segment.ident.span)
256+
self.infer_id(segment.hir_id, Some(expr.hir_id), segment.ident.span)
232257
}
233-
ExprKind::Call(call, ..) => self.handle_call(call.hir_id, None, call.span),
258+
ExprKind::Call(call, ..) => self.infer_id(call.hir_id, None, call.span),
234259
_ => {
235260
if self.handle_macro(expr.span) {
236261
// We don't want to go deeper into the macro.

Diff for: src/librustdoc/json/conversions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl FromClean<clean::Type> for Type {
622622
impl FromClean<clean::Path> for Path {
623623
fn from_clean(path: clean::Path, renderer: &JsonRenderer<'_>) -> Path {
624624
Path {
625-
name: path.whole_name(),
625+
name: path.last_opt().map_or(String::from(""), |s| String::from(s.as_str())),
626626
id: renderer.id_from_item_default(path.def_id().into()),
627627
args: path.segments.last().map(|args| Box::new(args.clone().args.into_json(renderer))),
628628
}

Diff for: src/rustdoc-json-types/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
3030
/// This integer is incremented with every breaking change to the API,
3131
/// and is returned along with the JSON blob as [`Crate::format_version`].
3232
/// Consuming code should assert that this value matches the format version(s) that it supports.
33-
pub const FORMAT_VERSION: u32 = 37;
33+
pub const FORMAT_VERSION: u32 = 38;
3434

3535
/// The root of the emitted JSON blob.
3636
///

Diff for: tests/codegen-units/item-collection/closures.rs

+6
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ pub async fn async_fn() {}
1010
pub fn closure() {
1111
let _ = || {};
1212
}
13+
14+
//~ MONO_ITEM fn A::{constant#0}::{closure#0} @@
15+
trait A where
16+
[(); (|| {}, 1).1]: Sized,
17+
{
18+
}

Diff for: tests/rustdoc-json/return_private.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mod secret {
66
}
77

88
//@ has "$.index[*][?(@.name=='get_secret')].inner.function"
9-
//@ is "$.index[*][?(@.name=='get_secret')].inner.function.sig.output.resolved_path.name" \"secret::Secret\"
9+
//@ is "$.index[*][?(@.name=='get_secret')].inner.function.sig.output.resolved_path.name" \"Secret\"
1010
pub fn get_secret() -> secret::Secret {
1111
secret::Secret
1212
}

0 commit comments

Comments
 (0)