Skip to content

Commit 065a1f5

Browse files
committed
Auto merge of rust-lang#112900 - GuillaumeGomez:rollup-1blf4io, r=GuillaumeGomez
Rollup of 4 pull requests Successful merges: - rust-lang#112538 (Removed unnecessary &String -> &str, now that &String implements StableOrd as well) - rust-lang#112868 (Liberate bound vars properly when suggesting missing async-fn-in-trait) - rust-lang#112892 (resolve: Minor cleanup to `fn resolve_path_with_ribs`) - rust-lang#112894 (Fix union fields display) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 006a26c + f5470af commit 065a1f5

File tree

15 files changed

+134
-95
lines changed

15 files changed

+134
-95
lines changed

compiler/rustc_data_structures/src/unord.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ impl<T, I: Iterator<Item = T>> UnordItems<T, I> {
107107
{
108108
UnordItems(self.0.flat_map(f))
109109
}
110+
111+
pub fn collect<C: From<UnordItems<T, I>>>(self) -> C {
112+
self.into()
113+
}
110114
}
111115

112116
impl<T> UnordItems<T, std::iter::Empty<T>> {
@@ -161,10 +165,6 @@ impl<T: Ord, I: Iterator<Item = T>> UnordItems<T, I> {
161165
items.sort_by_cached_key(|x| x.to_stable_hash_key(hcx));
162166
items
163167
}
164-
165-
pub fn collect<C: From<UnordItems<T, I>>>(self) -> C {
166-
self.into()
167-
}
168168
}
169169

170170
/// This is a set collection type that tries very hard to not expose

compiler/rustc_hir_analysis/src/check/mod.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -470,19 +470,16 @@ fn suggestion_signature<'tcx>(
470470
);
471471

472472
match assoc.kind {
473-
ty::AssocKind::Fn => {
474-
// We skip the binder here because the binder would deanonymize all
475-
// late-bound regions, and we don't want method signatures to show up
476-
// `as for<'r> fn(&'r MyType)`. Pretty-printing handles late-bound
477-
// regions just fine, showing `fn(&MyType)`.
478-
fn_sig_suggestion(
479-
tcx,
480-
tcx.fn_sig(assoc.def_id).subst(tcx, substs).skip_binder(),
481-
assoc.ident(tcx),
482-
tcx.predicates_of(assoc.def_id).instantiate_own(tcx, substs),
483-
assoc,
484-
)
485-
}
473+
ty::AssocKind::Fn => fn_sig_suggestion(
474+
tcx,
475+
tcx.liberate_late_bound_regions(
476+
assoc.def_id,
477+
tcx.fn_sig(assoc.def_id).subst(tcx, substs),
478+
),
479+
assoc.ident(tcx),
480+
tcx.predicates_of(assoc.def_id).instantiate_own(tcx, substs),
481+
assoc,
482+
),
486483
ty::AssocKind::Type => {
487484
let (generics, where_clauses) = bounds_from_generic_predicates(
488485
tcx,

compiler/rustc_incremental/src/persist/dirty_clean.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
198198
let (name, mut auto) = self.auto_labels(item_id, attr);
199199
let except = self.except(attr);
200200
let loaded_from_disk = self.loaded_from_disk(attr);
201-
for e in except.items().map(|x| x.as_str()).into_sorted_stable_ord() {
201+
for e in except.items().into_sorted_stable_ord() {
202202
if !auto.remove(e) {
203203
self.tcx.sess.emit_fatal(errors::AssertionAuto { span: attr.span, name, e });
204204
}
@@ -377,17 +377,15 @@ impl<'tcx> DirtyCleanVisitor<'tcx> {
377377
continue;
378378
};
379379
self.checked_attrs.insert(attr.id);
380-
for label in assertion.clean.items().map(|x| x.as_str()).into_sorted_stable_ord() {
380+
for label in assertion.clean.items().into_sorted_stable_ord() {
381381
let dep_node = DepNode::from_label_string(self.tcx, &label, def_path_hash).unwrap();
382382
self.assert_clean(item_span, dep_node);
383383
}
384-
for label in assertion.dirty.items().map(|x| x.as_str()).into_sorted_stable_ord() {
384+
for label in assertion.dirty.items().into_sorted_stable_ord() {
385385
let dep_node = DepNode::from_label_string(self.tcx, &label, def_path_hash).unwrap();
386386
self.assert_dirty(item_span, dep_node);
387387
}
388-
for label in
389-
assertion.loaded_from_disk.items().map(|x| x.as_str()).into_sorted_stable_ord()
390-
{
388+
for label in assertion.loaded_from_disk.items().into_sorted_stable_ord() {
391389
let dep_node = DepNode::from_label_string(self.tcx, &label, def_path_hash).unwrap();
392390
self.assert_loaded_from_disk(item_span, dep_node);
393391
}

compiler/rustc_incremental/src/persist/fs.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -855,12 +855,11 @@ fn all_except_most_recent(
855855
let most_recent = deletion_candidates.items().map(|(&(timestamp, _), _)| timestamp).max();
856856

857857
if let Some(most_recent) = most_recent {
858-
UnordMap::from(
859-
deletion_candidates
860-
.into_items()
861-
.filter(|&((timestamp, _), _)| timestamp != most_recent)
862-
.map(|((_, path), lock)| (path, lock)),
863-
)
858+
deletion_candidates
859+
.into_items()
860+
.filter(|&((timestamp, _), _)| timestamp != most_recent)
861+
.map(|((_, path), lock)| (path, lock))
862+
.collect()
864863
} else {
865864
UnordMap::default()
866865
}

compiler/rustc_resolve/src/ident.rs

+38-51
Original file line numberDiff line numberDiff line change
@@ -1459,60 +1459,47 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14591459
});
14601460
}
14611461

1462-
enum FindBindingResult<'a> {
1463-
Binding(Result<&'a NameBinding<'a>, Determinacy>),
1464-
Res(Res),
1465-
}
1466-
let find_binding_in_ns = |this: &mut Self, ns| {
1467-
let binding = if let Some(module) = module {
1468-
this.resolve_ident_in_module(
1469-
module,
1470-
ident,
1471-
ns,
1472-
parent_scope,
1473-
finalize,
1474-
ignore_binding,
1475-
)
1476-
} else if let Some(ribs) = ribs
1477-
&& let Some(TypeNS | ValueNS) = opt_ns
1478-
{
1479-
match this.resolve_ident_in_lexical_scope(
1480-
ident,
1481-
ns,
1482-
parent_scope,
1483-
finalize,
1484-
&ribs[ns],
1485-
ignore_binding,
1486-
) {
1487-
// we found a locally-imported or available item/module
1488-
Some(LexicalScopeBinding::Item(binding)) => Ok(binding),
1489-
// we found a local variable or type param
1490-
Some(LexicalScopeBinding::Res(res)) => return FindBindingResult::Res(res),
1491-
_ => Err(Determinacy::determined(finalize.is_some())),
1462+
let binding = if let Some(module) = module {
1463+
self.resolve_ident_in_module(
1464+
module,
1465+
ident,
1466+
ns,
1467+
parent_scope,
1468+
finalize,
1469+
ignore_binding,
1470+
)
1471+
} else if let Some(ribs) = ribs && let Some(TypeNS | ValueNS) = opt_ns {
1472+
match self.resolve_ident_in_lexical_scope(
1473+
ident,
1474+
ns,
1475+
parent_scope,
1476+
finalize,
1477+
&ribs[ns],
1478+
ignore_binding,
1479+
) {
1480+
// we found a locally-imported or available item/module
1481+
Some(LexicalScopeBinding::Item(binding)) => Ok(binding),
1482+
// we found a local variable or type param
1483+
Some(LexicalScopeBinding::Res(res)) => {
1484+
record_segment_res(self, res);
1485+
return PathResult::NonModule(PartialRes::with_unresolved_segments(
1486+
res,
1487+
path.len() - 1,
1488+
));
14921489
}
1493-
} else {
1494-
let scopes = ScopeSet::All(ns, opt_ns.is_none());
1495-
this.early_resolve_ident_in_lexical_scope(
1496-
ident,
1497-
scopes,
1498-
parent_scope,
1499-
finalize,
1500-
finalize.is_some(),
1501-
ignore_binding,
1502-
)
1503-
};
1504-
FindBindingResult::Binding(binding)
1505-
};
1506-
let binding = match find_binding_in_ns(self, ns) {
1507-
FindBindingResult::Res(res) => {
1508-
record_segment_res(self, res);
1509-
return PathResult::NonModule(PartialRes::with_unresolved_segments(
1510-
res,
1511-
path.len() - 1,
1512-
));
1490+
_ => Err(Determinacy::determined(finalize.is_some())),
15131491
}
1514-
FindBindingResult::Binding(binding) => binding,
1492+
} else {
1493+
self.early_resolve_ident_in_lexical_scope(
1494+
ident,
1495+
ScopeSet::All(ns, opt_ns.is_none()),
1496+
parent_scope,
1497+
finalize,
1498+
finalize.is_some(),
1499+
ignore_binding,
1500+
)
15151501
};
1502+
15161503
match binding {
15171504
Ok(binding) => {
15181505
if segment_idx == 1 {

src/librustdoc/html/render/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,10 @@ fn document<'a, 'cx: 'a>(
421421
display_fn(move |f| {
422422
document_item_info(cx, item, parent).render_into(f).unwrap();
423423
if parent.is_none() {
424-
write!(f, "{}", document_full_collapsible(item, cx, heading_offset))?;
424+
write!(f, "{}", document_full_collapsible(item, cx, heading_offset))
425425
} else {
426-
write!(f, "{}", document_full(item, cx, heading_offset))?;
426+
write!(f, "{}", document_full(item, cx, heading_offset))
427427
}
428-
Ok(())
429428
})
430429
}
431430

src/librustdoc/html/templates/item_info.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% if !items.is_empty() %}
2-
<span class="item-info"> {# #}
2+
<span class="item-info">
33
{% for item in items %}
44
{{item|safe}} {# #}
55
{% endfor %}

src/librustdoc/html/templates/item_union.html

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
</code></pre>
55
{{ self.document() | safe }}
66
{% if self.fields_iter().peek().is_some() %}
7-
<h2 id="fields" class="fields small-section-header">
8-
Fields<a href="#fields" class="anchor">§</a>
7+
<h2 id="fields" class="fields small-section-header"> {# #}
8+
Fields<a href="#fields" class="anchor">§</a> {# #}
99
</h2>
1010
{% for (field, ty) in self.fields_iter() %}
1111
{% let name = field.name.expect("union field name") %}
12-
<span id="structfield.{{ name }}" class="{{ ItemType::StructField }} small-section-header">
13-
<a href="#structfield.{{ name }}" class="anchor field">§</a>
14-
<code>{{ name }}: {{ self.print_ty(ty) | safe }}</code>
12+
<span id="structfield.{{ name }}" {#+ #}
13+
class="{{ ItemType::StructField +}} small-section-header"> {# #}
14+
<a href="#structfield.{{ name }}" class="anchor field">§</a> {# #}
15+
<code>{{ name }}: {{+ self.print_ty(ty) | safe }}</code> {# #}
1516
</span>
1617
{% if let Some(stability_class) = self.stability_field(field) %}
1718
<span class="stab {{ stability_class }}"></span>

src/librustdoc/html/templates/print_item.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="main-heading"> {# #}
2-
<h1> {# #}
2+
<h1>
33
{{typ}}
44
{# The breadcrumbs of the item path, like std::string #}
55
{% for component in path_components %}
@@ -12,7 +12,7 @@ <h1> {# #}
1212
alt="Copy item path"> {# #}
1313
</button> {# #}
1414
</h1> {# #}
15-
<span class="out-of-band"> {# #}
15+
<span class="out-of-band">
1616
{% if !stability_since_raw.is_empty() %}
1717
{{ stability_since_raw|safe +}} · {#+ #}
1818
{% endif %}

tests/rustdoc-gui/fields.goml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This test checks that fields are displayed as expected (one by line).
2+
go-to: "file://" + |DOC_PATH| + "/test_docs/fields/struct.Struct.html"
3+
store-position: ("#structfield\.a", {"y": a_y})
4+
store-position: ("#structfield\.b", {"y": b_y})
5+
assert: |a_y| < |b_y|
6+
7+
go-to: "file://" + |DOC_PATH| + "/test_docs/fields/union.Union.html"
8+
store-position: ("#structfield\.a", {"y": a_y})
9+
store-position: ("#structfield\.b", {"y": b_y})
10+
assert: |a_y| < |b_y|
11+
12+
go-to: "file://" + |DOC_PATH| + "/test_docs/fields/enum.Enum.html"
13+
store-position: ("#variant\.A\.field\.a", {"y": a_y})
14+
store-position: ("#variant\.A\.field\.b", {"y": b_y})
15+
assert: |a_y| < |b_y|
16+
store-position: ("#variant\.B\.field\.a", {"y": a_y})
17+
store-position: ("#variant\.B\.field\.b", {"y": b_y})
18+
assert: |a_y| < |b_y|

tests/rustdoc-gui/src/test_docs/lib.rs

+21
Original file line numberDiff line numberDiff line change
@@ -486,3 +486,24 @@ pub mod search_results {
486486
}
487487

488488
}
489+
490+
pub mod fields {
491+
pub struct Struct {
492+
pub a: u8,
493+
pub b: u32,
494+
}
495+
pub union Union {
496+
pub a: u8,
497+
pub b: u32,
498+
}
499+
pub enum Enum {
500+
A {
501+
a: u8,
502+
b: u32,
503+
},
504+
B {
505+
a: u8,
506+
b: u32,
507+
},
508+
}
509+
}

tests/rustdoc/union-fields-html.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#![crate_name = "foo"]
2+
3+
// @has 'foo/union.Union.html'
4+
// Checking that there is a whitespace after `:`.
5+
// @has - '//*[@id="structfield.a"]/code' 'a: u8'
6+
// @has - '//*[@id="structfield.b"]/code' 'b: u32'
7+
pub union Union {
8+
pub a: u8,
9+
/// tadam
10+
pub b: u32,
11+
}

tests/ui/impl-trait/in-trait/suggest-missing-item.fixed

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ trait Trait {
99
async fn bar() -> i32;
1010

1111
fn test(&self) -> impl Sized + '_;
12+
13+
async fn baz(&self) -> &i32;
1214
}
1315

1416
struct S;
1517

16-
impl Trait for S {fn test(&self) -> impl Sized + '_ { todo!() }
18+
impl Trait for S {async fn baz(&self) -> &i32 { todo!() }
19+
fn test(&self) -> impl Sized + '_ { todo!() }
1720
async fn bar() -> i32 { todo!() }
1821
async fn foo() { todo!() }
1922
}

tests/ui/impl-trait/in-trait/suggest-missing-item.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ trait Trait {
99
async fn bar() -> i32;
1010

1111
fn test(&self) -> impl Sized + '_;
12+
13+
async fn baz(&self) -> &i32;
1214
}
1315

1416
struct S;

tests/ui/impl-trait/in-trait/suggest-missing-item.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
error[E0046]: not all trait items implemented, missing: `foo`, `bar`, `test`
2-
--> $DIR/suggest-missing-item.rs:16:1
1+
error[E0046]: not all trait items implemented, missing: `foo`, `bar`, `test`, `baz`
2+
--> $DIR/suggest-missing-item.rs:18:1
33
|
44
LL | async fn foo();
55
| --------------- `foo` from trait
@@ -9,9 +9,12 @@ LL | async fn bar() -> i32;
99
LL |
1010
LL | fn test(&self) -> impl Sized + '_;
1111
| ---------------------------------- `test` from trait
12+
LL |
13+
LL | async fn baz(&self) -> &i32;
14+
| ---------------------------- `baz` from trait
1215
...
1316
LL | impl Trait for S {}
14-
| ^^^^^^^^^^^^^^^^ missing `foo`, `bar`, `test` in implementation
17+
| ^^^^^^^^^^^^^^^^ missing `foo`, `bar`, `test`, `baz` in implementation
1518

1619
error: aborting due to previous error
1720

0 commit comments

Comments
 (0)