Skip to content

Rollup of 7 pull requests #135496

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

Merged
merged 18 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7029347
Enable "jump to def" feature on prelude variants
GuillaumeGomez Dec 12, 2024
f6525a6
Enable "jump to def" feature on patterns
GuillaumeGomez Dec 12, 2024
140640a
Add regression test for patterns support in "jump to def" feature
GuillaumeGomez Dec 12, 2024
12a12c9
Rename `handle_call` into `infer_id`
GuillaumeGomez Dec 12, 2024
377dbc9
Leak check in impossible_predicates to avoid monomorphizing impossibl…
compiler-errors Jan 14, 2025
2c4aee9
Made `Path::name` only have item name rather than full name
AS1100K Dec 29, 2024
94ffced
add note to test
lcnr Jan 14, 2025
3a66b97
Remove remnant of asmjs
kleisauke Jan 14, 2025
99657aa
mir borrowck: cleanup late-bound region handling
lcnr Jan 14, 2025
faafa5c
Fix legacy symbol mangling of closures
compiler-errors Jan 14, 2025
c141f50
Add missing closing backtick in commit hook message 🐸
yotamofek Jan 14, 2025
aeadee0
Rollup merge of #134216 - GuillaumeGomez:jump-to-def-pats, r=fmease
matthiaskrgr Jan 14, 2025
ca9a9d2
Rollup merge of #134880 - as1100k-forks:fix-rustdoc-json-path-name, r…
matthiaskrgr Jan 14, 2025
866e61a
Rollup merge of #135466 - compiler-errors:leak-check-impossible, r=lcnr
matthiaskrgr Jan 14, 2025
e0e2f6a
Rollup merge of #135476 - kleisauke:remove-asmjs-remnant, r=Kobzol
matthiaskrgr Jan 14, 2025
7354f6e
Rollup merge of #135479 - lcnr:method-calls-on-opaques, r=compiler-er…
matthiaskrgr Jan 14, 2025
f9c2c12
Rollup merge of #135493 - compiler-errors:legacy-mangle-closure, r=lqd
matthiaskrgr Jan 14, 2025
eb763f8
Rollup merge of #135495 - yotamofek:close-backtick, r=Kobzol
matthiaskrgr Jan 14, 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
1 change: 0 additions & 1 deletion compiler/rustc_borrowck/src/renumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub(crate) enum RegionCtxt {
Location(Location),
TyContext(TyContext),
Free(Symbol),
Bound(Symbol),
LateBound(Symbol),
Existential(Option<Symbol>),
Placeholder(Symbol),
Expand Down
65 changes: 26 additions & 39 deletions compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,13 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
self.infcx.tcx.local_parent(self.mir_def),
|r| {
debug!(?r);
if !indices.indices.contains_key(&r) {
let region_vid = {
let name = r.get_name_or_anon();
self.infcx.next_nll_region_var(FR, || RegionCtxt::LateBound(name))
};

debug!(?region_vid);
indices.insert_late_bound_region(r, region_vid.as_var());
}
let region_vid = {
let name = r.get_name_or_anon();
self.infcx.next_nll_region_var(FR, || RegionCtxt::LateBound(name))
};

debug!(?region_vid);
indices.insert_late_bound_region(r, region_vid.as_var());
},
);

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

// "Liberate" the late-bound regions. These correspond to
// "local" free regions.
// Converse of above, if this is a function/closure then the late-bound regions declared
// on its signature are local.
//
// We manually loop over `bound_inputs_and_output` instead of using
// `for_each_late_bound_region_in_item` as we may need to add the otherwise
// implicit `ClosureEnv` region.
let bound_inputs_and_output = self.compute_inputs_and_output(&indices, defining_ty);

let inputs_and_output = self.infcx.replace_bound_regions_with_nll_infer_vars(
FR,
self.mir_def,
bound_inputs_and_output,
&mut indices,
);
// Converse of above, if this is a function/closure then the late-bound regions declared on its
// signature are local.
for_each_late_bound_region_in_item(self.infcx.tcx, self.mir_def, |r| {
debug!(?r);
if !indices.indices.contains_key(&r) {
for (idx, bound_var) in bound_inputs_and_output.bound_vars().iter().enumerate() {
if let ty::BoundVariableKind::Region(kind) = bound_var {
let kind = ty::LateParamRegionKind::from_bound(ty::BoundVar::from_usize(idx), kind);
let r = ty::Region::new_late_param(self.infcx.tcx, self.mir_def.to_def_id(), kind);
let region_vid = {
let name = r.get_name_or_anon();
self.infcx.next_nll_region_var(FR, || RegionCtxt::LateBound(name))
Expand All @@ -507,7 +501,12 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
debug!(?region_vid);
indices.insert_late_bound_region(r, region_vid.as_var());
}
});
}
let inputs_and_output = self.infcx.replace_bound_regions_with_nll_infer_vars(
self.mir_def,
bound_inputs_and_output,
&indices,
);

let (unnormalized_output_ty, mut unnormalized_input_tys) =
inputs_and_output.split_last().unwrap();
Expand Down Expand Up @@ -832,10 +831,9 @@ impl<'tcx> BorrowckInferCtxt<'tcx> {
#[instrument(level = "debug", skip(self, indices))]
fn replace_bound_regions_with_nll_infer_vars<T>(
&self,
origin: NllRegionVariableOrigin,
all_outlive_scope: LocalDefId,
value: ty::Binder<'tcx, T>,
indices: &mut UniversalRegionIndices<'tcx>,
indices: &UniversalRegionIndices<'tcx>,
) -> T
where
T: TypeFoldable<TyCtxt<'tcx>>,
Expand All @@ -845,18 +843,7 @@ impl<'tcx> BorrowckInferCtxt<'tcx> {
let kind = ty::LateParamRegionKind::from_bound(br.var, br.kind);
let liberated_region =
ty::Region::new_late_param(self.tcx, all_outlive_scope.to_def_id(), kind);
let region_vid = {
let name = match br.kind.get_name() {
Some(name) => name,
_ => sym::anon,
};

self.next_nll_region_var(origin, || RegionCtxt::Bound(name))
};

indices.insert_late_bound_region(liberated_region, region_vid.as_var());
debug!(?liberated_region, ?region_vid);
region_vid
ty::Region::new_var(self.tcx, indices.to_region_vid(liberated_region))
});
value
}
Expand All @@ -870,7 +857,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
/// well. These are used for error reporting.
fn insert_late_bound_region(&mut self, r: ty::Region<'tcx>, vid: ty::RegionVid) {
debug!("insert_late_bound_region({:?}, {:?})", r, vid);
self.indices.insert(r, vid);
assert_eq!(self.indices.insert(r, vid), None);
}

/// Converts `r` into a local inference variable: `r` can either
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_symbol_mangling/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ pub(super) fn mangle<'tcx>(
let def_id = instance.def_id();

// We want to compute the "type" of this item. Unfortunately, some
// kinds of items (e.g., closures) don't have an entry in the
// item-type array. So walk back up the find the closest parent
// that DOES have an entry.
// kinds of items (e.g., synthetic static allocations from const eval)
// don't have a proper implementation for the `type_of` query. So walk
// back up the find the closest parent that DOES have a type.
let mut ty_def_id = def_id;
let instance_ty;
loop {
let key = tcx.def_key(ty_def_id);
match key.disambiguated_data.data {
DefPathData::TypeNs(_) | DefPathData::ValueNs(_) => {
DefPathData::TypeNs(_) | DefPathData::ValueNs(_) | DefPathData::Closure => {
instance_ty = tcx.type_of(ty_def_id).instantiate_identity();
debug!(?instance_ty);
break;
Expand Down
15 changes: 12 additions & 3 deletions compiler/rustc_trait_selection/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,9 +714,18 @@ pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec<ty::Clause
}
let errors = ocx.select_all_or_error();

let result = !errors.is_empty();
debug!("impossible_predicates = {:?}", result);
result
if !errors.is_empty() {
return true;
}

// Leak check for any higher-ranked trait mismatches.
// We only need to do this in the old solver, since the new solver already
// leak-checks.
if !infcx.next_trait_solver() && infcx.leak_check(ty::UniverseIndex::ROOT, None).is_err() {
return true;
}

false
}

fn instantiate_and_check_impossible_predicates<'tcx>(
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn print_paths(verb: &str, adjective: Option<&str>, paths: &[String]) {
println!("fmt: {verb} {len} {adjective}files");
}
if len > 1000 && !CiEnv::is_ci() {
println!("hint: if this number seems too high, try running `git fetch origin master");
println!("hint: if this number seems too high, try running `git fetch origin master`");
}
}

Expand Down
24 changes: 0 additions & 24 deletions src/ci/docker/scripts/emscripten.sh

This file was deleted.

15 changes: 10 additions & 5 deletions src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ enum Class {
Ident(Span),
Lifetime,
PreludeTy(Span),
PreludeVal,
PreludeVal(Span),
QuestionMark,
Decoration(&'static str),
}
Expand Down Expand Up @@ -385,7 +385,7 @@ impl Class {
Class::Ident(_) => "",
Class::Lifetime => "lifetime",
Class::PreludeTy(_) => "prelude-ty",
Class::PreludeVal => "prelude-val",
Class::PreludeVal(_) => "prelude-val",
Class::QuestionMark => "question-mark",
Class::Decoration(kind) => kind,
}
Expand All @@ -395,7 +395,11 @@ impl Class {
/// a "span" (a tuple representing `(lo, hi)` equivalent of `Span`).
fn get_span(self) -> Option<Span> {
match self {
Self::Ident(sp) | Self::Self_(sp) | Self::Macro(sp) | Self::PreludeTy(sp) => Some(sp),
Self::Ident(sp)
| Self::Self_(sp)
| Self::Macro(sp)
| Self::PreludeTy(sp)
| Self::PreludeVal(sp) => Some(sp),
Self::Comment
| Self::DocComment
| Self::Attribute
Expand All @@ -406,7 +410,6 @@ impl Class {
| Self::Number
| Self::Bool
| Self::Lifetime
| Self::PreludeVal
| Self::QuestionMark
| Self::Decoration(_) => None,
}
Expand Down Expand Up @@ -851,7 +854,9 @@ impl<'src> Classifier<'src> {
TokenKind::Ident => match get_real_ident_class(text, false) {
None => match text {
"Option" | "Result" => Class::PreludeTy(self.new_span(before, text)),
"Some" | "None" | "Ok" | "Err" => Class::PreludeVal,
"Some" | "None" | "Ok" | "Err" => {
Class::PreludeVal(self.new_span(before, text))
}
// "union" is a weak keyword and is only considered as a keyword when declaring
// a union type.
"union" if self.check_if_is_union_keyword() => Class::KeyWord,
Expand Down
33 changes: 29 additions & 4 deletions src/librustdoc/html/render/span_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{ExprKind, HirId, Item, ItemKind, Mod, Node};
use rustc_hir::{ExprKind, HirId, Item, ItemKind, Mod, Node, Pat, PatKind, QPath};
use rustc_middle::hir::nested_filter;
use rustc_middle::ty::TyCtxt;
use rustc_span::hygiene::MacroKind;
Expand Down Expand Up @@ -170,7 +170,7 @@ impl SpanMapVisitor<'_> {
true
}

fn handle_call(&mut self, hir_id: HirId, expr_hir_id: Option<HirId>, span: Span) {
fn infer_id(&mut self, hir_id: HirId, expr_hir_id: Option<HirId>, span: Span) {
let hir = self.tcx.hir();
let body_id = hir.enclosing_body_owner(hir_id);
// FIXME: this is showing error messages for parts of the code that are not
Expand All @@ -189,6 +189,27 @@ impl SpanMapVisitor<'_> {
self.matches.insert(span, link);
}
}

fn handle_pat(&mut self, p: &Pat<'_>) {
match p.kind {
PatKind::Binding(_, _, _, Some(p)) => self.handle_pat(p),
PatKind::Struct(qpath, _, _)
| PatKind::TupleStruct(qpath, _, _)
| PatKind::Path(qpath) => match qpath {
QPath::TypeRelative(_, path) if matches!(path.res, Res::Err) => {
self.infer_id(path.hir_id, Some(p.hir_id), qpath.span());
}
QPath::Resolved(_, path) => self.handle_path(path),
_ => {}
},
PatKind::Or(pats) => {
for pat in pats {
self.handle_pat(pat);
}
}
_ => {}
}
}
}

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

fn visit_pat(&mut self, p: &Pat<'tcx>) {
self.handle_pat(p);
}

fn visit_mod(&mut self, m: &'tcx Mod<'tcx>, span: Span, id: HirId) {
// To make the difference between "mod foo {}" and "mod foo;". In case we "import" another
// file, we want to link to it. Otherwise no need to create a link.
Expand All @@ -228,9 +253,9 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
fn visit_expr(&mut self, expr: &'tcx rustc_hir::Expr<'tcx>) {
match expr.kind {
ExprKind::MethodCall(segment, ..) => {
self.handle_call(segment.hir_id, Some(expr.hir_id), segment.ident.span)
self.infer_id(segment.hir_id, Some(expr.hir_id), segment.ident.span)
}
ExprKind::Call(call, ..) => self.handle_call(call.hir_id, None, call.span),
ExprKind::Call(call, ..) => self.infer_id(call.hir_id, None, call.span),
_ => {
if self.handle_macro(expr.span) {
// We don't want to go deeper into the macro.
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/json/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ impl FromClean<clean::Type> for Type {
impl FromClean<clean::Path> for Path {
fn from_clean(path: clean::Path, renderer: &JsonRenderer<'_>) -> Path {
Path {
name: path.whole_name(),
name: path.last_opt().map_or(String::from(""), |s| String::from(s.as_str())),
id: renderer.id_from_item_default(path.def_id().into()),
args: path.segments.last().map(|args| Box::new(args.clone().args.into_json(renderer))),
}
Expand Down
2 changes: 1 addition & 1 deletion src/rustdoc-json-types/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub type FxHashMap<K, V> = HashMap<K, V>; // re-export for use in src/librustdoc
/// This integer is incremented with every breaking change to the API,
/// and is returned along with the JSON blob as [`Crate::format_version`].
/// Consuming code should assert that this value matches the format version(s) that it supports.
pub const FORMAT_VERSION: u32 = 37;
pub const FORMAT_VERSION: u32 = 38;

/// The root of the emitted JSON blob.
///
Expand Down
6 changes: 6 additions & 0 deletions tests/codegen-units/item-collection/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ pub async fn async_fn() {}
pub fn closure() {
let _ = || {};
}

//~ MONO_ITEM fn A::{constant#0}::{closure#0} @@
trait A where
[(); (|| {}, 1).1]: Sized,
{
}
2 changes: 1 addition & 1 deletion tests/rustdoc-json/return_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mod secret {
}

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