Skip to content

Commit f2702e9

Browse files
committed
Auto merge of rust-lang#103502 - JohnTitor:rollup-o6mhyzq, r=JohnTitor
Rollup of 11 pull requests Successful merges: - rust-lang#103333 (Fix assertion failed for break_last_token and trailing token) - rust-lang#103350 (Change terminology for assoc method suggestions when they are not called) - rust-lang#103382 (Don't ICE when reporting borrowck errors involving regions from `anonymous_lifetime_in_impl_trait`) - rust-lang#103409 (Delay span bug when we can't map lifetimes back in `collect_trait_impl_trait_tys`) - rust-lang#103410 (-Z docs: Add link to unstable book) - rust-lang#103462 (rustdoc: remove no-op CSS `.source pre.rust { white-space: pre }`) - rust-lang#103465 (E0210 explanation: remove redundant sentence) - rust-lang#103486 (Use functions in highlight-colors rustdoc GUI test) - rust-lang#103493 (rustdoc: remove unused `.sidebar-logo` DOM on source pages) - rust-lang#103494 (rustdoc: remove redundant CSS `a.test-arrow:hover`) - rust-lang#103495 (rustdoc: Use `unix_sigpipe` instead of `rustc_driver::set_sigpipe_handler`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 758f196 + d0ffd20 commit f2702e9

File tree

24 files changed

+376
-102
lines changed

24 files changed

+376
-102
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+92-8
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
251251
.or_else(|| self.give_name_if_anonymous_region_appears_in_upvars(fr))
252252
.or_else(|| self.give_name_if_anonymous_region_appears_in_output(fr))
253253
.or_else(|| self.give_name_if_anonymous_region_appears_in_yield_ty(fr))
254-
.or_else(|| self.give_name_if_anonymous_region_appears_in_impl_signature(fr));
254+
.or_else(|| self.give_name_if_anonymous_region_appears_in_impl_signature(fr))
255+
.or_else(|| self.give_name_if_anonymous_region_appears_in_arg_position_impl_trait(fr));
255256

256257
if let Some(ref value) = value {
257258
self.region_names.try_borrow_mut().unwrap().insert(fr, value.clone());
@@ -869,13 +870,8 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
869870
return None;
870871
}
871872

872-
let mut found = false;
873-
tcx.fold_regions(tcx.type_of(region_parent), |r: ty::Region<'tcx>, _| {
874-
if *r == ty::ReEarlyBound(region) {
875-
found = true;
876-
}
877-
r
878-
});
873+
let found = tcx
874+
.any_free_region_meets(&tcx.type_of(region_parent), |r| *r == ty::ReEarlyBound(region));
879875

880876
Some(RegionName {
881877
name: self.synthesize_region_name(),
@@ -888,4 +884,92 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
888884
),
889885
})
890886
}
887+
888+
fn give_name_if_anonymous_region_appears_in_arg_position_impl_trait(
889+
&self,
890+
fr: RegionVid,
891+
) -> Option<RegionName> {
892+
let ty::ReEarlyBound(region) = *self.to_error_region(fr)? else {
893+
return None;
894+
};
895+
if region.has_name() {
896+
return None;
897+
};
898+
899+
let predicates = self
900+
.infcx
901+
.tcx
902+
.predicates_of(self.body.source.def_id())
903+
.instantiate_identity(self.infcx.tcx)
904+
.predicates;
905+
906+
if let Some(upvar_index) = self
907+
.regioncx
908+
.universal_regions()
909+
.defining_ty
910+
.upvar_tys()
911+
.position(|ty| self.any_param_predicate_mentions(&predicates, ty, region))
912+
{
913+
let (upvar_name, upvar_span) = self.regioncx.get_upvar_name_and_span_for_region(
914+
self.infcx.tcx,
915+
&self.upvars,
916+
upvar_index,
917+
);
918+
let region_name = self.synthesize_region_name();
919+
920+
Some(RegionName {
921+
name: region_name,
922+
source: RegionNameSource::AnonRegionFromUpvar(upvar_span, upvar_name),
923+
})
924+
} else if let Some(arg_index) = self
925+
.regioncx
926+
.universal_regions()
927+
.unnormalized_input_tys
928+
.iter()
929+
.position(|ty| self.any_param_predicate_mentions(&predicates, *ty, region))
930+
{
931+
let (arg_name, arg_span) = self.regioncx.get_argument_name_and_span_for_region(
932+
self.body,
933+
&self.local_names,
934+
arg_index,
935+
);
936+
let region_name = self.synthesize_region_name();
937+
938+
Some(RegionName {
939+
name: region_name,
940+
source: RegionNameSource::AnonRegionFromArgument(
941+
RegionNameHighlight::CannotMatchHirTy(arg_span, arg_name?.to_string()),
942+
),
943+
})
944+
} else {
945+
None
946+
}
947+
}
948+
949+
fn any_param_predicate_mentions(
950+
&self,
951+
predicates: &[ty::Predicate<'tcx>],
952+
ty: Ty<'tcx>,
953+
region: ty::EarlyBoundRegion,
954+
) -> bool {
955+
let tcx = self.infcx.tcx;
956+
ty.walk().any(|arg| {
957+
if let ty::GenericArgKind::Type(ty) = arg.unpack()
958+
&& let ty::Param(_) = ty.kind()
959+
{
960+
predicates.iter().any(|pred| {
961+
match pred.kind().skip_binder() {
962+
ty::PredicateKind::Trait(data) if data.self_ty() == ty => {}
963+
ty::PredicateKind::Projection(data) if data.projection_ty.self_ty() == ty => {}
964+
_ => return false,
965+
}
966+
tcx.any_free_region_meets(pred, |r| {
967+
*r == ty::ReEarlyBound(region)
968+
})
969+
})
970+
} else {
971+
false
972+
}
973+
})
974+
}
891975
}

compiler/rustc_error_codes/src/error_codes/E0210.md

-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,5 @@ Let `Ti` be the first such type.
7676
For information on the design of the orphan rules,
7777
see [RFC 2451] and [RFC 1023].
7878

79-
For information on the design of the orphan rules, see [RFC 1023].
80-
8179
[RFC 2451]: https://rust-lang.github.io/rfcs/2451-re-rebalancing-coherence.html
8280
[RFC 1023]: https://github.com/rust-lang/rfcs/blob/master/text/1023-rebalancing-coherence.md

compiler/rustc_hir_analysis/src/check/compare_method.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,16 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
598598
let num_impl_substs = tcx.generics_of(impl_m.container_id(tcx)).params.len();
599599
let ty = tcx.fold_regions(ty, |region, _| {
600600
let ty::ReFree(_) = region.kind() else { return region; };
601-
let ty::ReEarlyBound(e) = map[&region.into()].expect_region().kind()
602-
else { bug!("expected ReFree to map to ReEarlyBound"); };
601+
let Some(ty::ReEarlyBound(e)) = map.get(&region.into()).map(|r| r.expect_region().kind())
602+
else {
603+
tcx
604+
.sess
605+
.delay_span_bug(
606+
return_span,
607+
"expected ReFree to map to ReEarlyBound"
608+
);
609+
return tcx.lifetimes.re_static;
610+
};
603611
tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
604612
def_id: e.def_id,
605613
name: e.name,

compiler/rustc_parse/src/parser/attr_wrapper.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -273,16 +273,23 @@ impl<'a> Parser<'a> {
273273
let cursor_snapshot_next_calls = cursor_snapshot.num_next_calls;
274274
let mut end_pos = self.token_cursor.num_next_calls;
275275

276+
let mut captured_trailing = false;
277+
276278
// Capture a trailing token if requested by the callback 'f'
277279
match trailing {
278280
TrailingToken::None => {}
281+
TrailingToken::Gt => {
282+
assert_eq!(self.token.kind, token::Gt);
283+
}
279284
TrailingToken::Semi => {
280285
assert_eq!(self.token.kind, token::Semi);
281286
end_pos += 1;
287+
captured_trailing = true;
282288
}
283289
TrailingToken::MaybeComma => {
284290
if self.token.kind == token::Comma {
285291
end_pos += 1;
292+
captured_trailing = true;
286293
}
287294
}
288295
}
@@ -292,11 +299,7 @@ impl<'a> Parser<'a> {
292299
// was not actually bumped past it. When the `LazyAttrTokenStream` gets converted
293300
// into an `AttrTokenStream`, we will create the proper token.
294301
if self.token_cursor.break_last_token {
295-
assert_eq!(
296-
trailing,
297-
TrailingToken::None,
298-
"Cannot set `break_last_token` and have trailing token"
299-
);
302+
assert!(!captured_trailing, "Cannot set break_last_token and have trailing token");
300303
end_pos += 1;
301304
}
302305

compiler/rustc_parse/src/parser/expr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3142,6 +3142,8 @@ impl<'a> Parser<'a> {
31423142
&& this.token.kind == token::Semi
31433143
{
31443144
TrailingToken::Semi
3145+
} else if this.token.kind == token::Gt {
3146+
TrailingToken::Gt
31453147
} else {
31463148
// FIXME - pass this through from the place where we know
31473149
// we need a comma, rather than assuming that `#[attr] expr,`

compiler/rustc_parse/src/parser/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pub enum ForceCollect {
7979
pub enum TrailingToken {
8080
None,
8181
Semi,
82+
Gt,
8283
/// If the trailing token is a comma, then capture it
8384
/// Otherwise, ignore the trailing token
8485
MaybeComma,

compiler/rustc_resolve/src/late/diagnostics.rs

+29-13
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ type Res = def::Res<ast::NodeId>;
3838
/// A field or associated item from self type suggested in case of resolution failure.
3939
enum AssocSuggestion {
4040
Field,
41-
MethodWithSelf,
42-
AssocFn,
41+
MethodWithSelf { called: bool },
42+
AssocFn { called: bool },
4343
AssocType,
4444
AssocConst,
4545
}
@@ -48,8 +48,14 @@ impl AssocSuggestion {
4848
fn action(&self) -> &'static str {
4949
match self {
5050
AssocSuggestion::Field => "use the available field",
51-
AssocSuggestion::MethodWithSelf => "call the method with the fully-qualified path",
52-
AssocSuggestion::AssocFn => "call the associated function",
51+
AssocSuggestion::MethodWithSelf { called: true } => {
52+
"call the method with the fully-qualified path"
53+
}
54+
AssocSuggestion::MethodWithSelf { called: false } => {
55+
"refer to the method with the fully-qualified path"
56+
}
57+
AssocSuggestion::AssocFn { called: true } => "call the associated function",
58+
AssocSuggestion::AssocFn { called: false } => "refer to the associated function",
5359
AssocSuggestion::AssocConst => "use the associated `const`",
5460
AssocSuggestion::AssocType => "use the associated type",
5561
}
@@ -516,7 +522,9 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
516522
let typo_sugg =
517523
self.lookup_typo_candidate(path, source.namespace(), is_expected).to_opt_suggestion();
518524
if path.len() == 1 && self.self_type_is_available() {
519-
if let Some(candidate) = self.lookup_assoc_candidate(ident, ns, is_expected) {
525+
if let Some(candidate) =
526+
self.lookup_assoc_candidate(ident, ns, is_expected, source.is_call())
527+
{
520528
let self_is_available = self.self_value_is_available(path[0].ident.span);
521529
match candidate {
522530
AssocSuggestion::Field => {
@@ -531,16 +539,21 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
531539
err.span_label(span, "a field by this name exists in `Self`");
532540
}
533541
}
534-
AssocSuggestion::MethodWithSelf if self_is_available => {
542+
AssocSuggestion::MethodWithSelf { called } if self_is_available => {
543+
let msg = if called {
544+
"you might have meant to call the method"
545+
} else {
546+
"you might have meant to refer to the method"
547+
};
535548
err.span_suggestion(
536549
span,
537-
"you might have meant to call the method",
550+
msg,
538551
format!("self.{path_str}"),
539552
Applicability::MachineApplicable,
540553
);
541554
}
542-
AssocSuggestion::MethodWithSelf
543-
| AssocSuggestion::AssocFn
555+
AssocSuggestion::MethodWithSelf { .. }
556+
| AssocSuggestion::AssocFn { .. }
544557
| AssocSuggestion::AssocConst
545558
| AssocSuggestion::AssocType => {
546559
err.span_suggestion(
@@ -1498,6 +1511,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
14981511
ident: Ident,
14991512
ns: Namespace,
15001513
filter_fn: FilterFn,
1514+
called: bool,
15011515
) -> Option<AssocSuggestion>
15021516
where
15031517
FilterFn: Fn(Res) -> bool,
@@ -1539,9 +1553,9 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
15391553
return Some(match &assoc_item.kind {
15401554
ast::AssocItemKind::Const(..) => AssocSuggestion::AssocConst,
15411555
ast::AssocItemKind::Fn(box ast::Fn { sig, .. }) if sig.decl.has_self() => {
1542-
AssocSuggestion::MethodWithSelf
1556+
AssocSuggestion::MethodWithSelf { called }
15431557
}
1544-
ast::AssocItemKind::Fn(..) => AssocSuggestion::AssocFn,
1558+
ast::AssocItemKind::Fn(..) => AssocSuggestion::AssocFn { called },
15451559
ast::AssocItemKind::Type(..) => AssocSuggestion::AssocType,
15461560
ast::AssocItemKind::MacCall(_) => continue,
15471561
});
@@ -1560,10 +1574,12 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
15601574
let res = binding.res();
15611575
if filter_fn(res) {
15621576
if self.r.has_self.contains(&res.def_id()) {
1563-
return Some(AssocSuggestion::MethodWithSelf);
1577+
return Some(AssocSuggestion::MethodWithSelf { called });
15641578
} else {
15651579
match res {
1566-
Res::Def(DefKind::AssocFn, _) => return Some(AssocSuggestion::AssocFn),
1580+
Res::Def(DefKind::AssocFn, _) => {
1581+
return Some(AssocSuggestion::AssocFn { called });
1582+
}
15671583
Res::Def(DefKind::AssocConst, _) => {
15681584
return Some(AssocSuggestion::AssocConst);
15691585
}

src/doc/rustc/src/command-line-arguments.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ _Note:_ The order of these lint level arguments is taken into account, see [lint
302302
This flag will allow you to set unstable options of rustc. In order to set multiple options,
303303
the -Z flag can be used multiple times. For example: `rustc -Z verbose -Z time-passes`.
304304
Specifying options with -Z is only available on nightly. To view all available options
305-
run: `rustc -Z help`.
305+
run: `rustc -Z help`, or see [The Unstable Book](../unstable-book/index.html).
306306

307307
<a id="option-cap-lints"></a>
308308
## `--cap-lints`: set the most restrictive lint level

src/librustdoc/html/static/css/noscript.css

+4
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ nav.sub {
1818
/* The search bar and related controls don't work without JS */
1919
display: none;
2020
}
21+
22+
.source .sidebar {
23+
display: none;
24+
}

src/librustdoc/html/static/css/rustdoc.css

-8
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,6 @@ img {
402402
overflow-y: hidden;
403403
}
404404

405-
.rustdoc.source .sidebar .sidebar-logo {
406-
display: none;
407-
}
408-
409405
.source .sidebar, #sidebar-toggle, #source-sidebar {
410406
background-color: var(--sidebar-background-color);
411407
}
@@ -538,7 +534,6 @@ ul.block, .block li {
538534
}
539535

540536
.source .content pre.rust {
541-
white-space: pre;
542537
overflow: auto;
543538
padding-left: 0;
544539
}
@@ -1233,9 +1228,6 @@ a.test-arrow {
12331228
.example-wrap:hover .test-arrow {
12341229
visibility: visible;
12351230
}
1236-
a.test-arrow:hover {
1237-
text-decoration: none;
1238-
}
12391231

12401232
.code-attribute {
12411233
font-weight: 300;

src/librustdoc/html/templates/page.html

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ <h2></h2> {#- -#}
8989
</nav> {#- -#}
9090
{%- endif -%}
9191
<nav class="sidebar"> {#- -#}
92+
{%- if page.css_class != "source" -%}
9293
<a class="sidebar-logo" href="{{page.root_path|safe}}{{krate_with_trailing_slash|safe}}index.html"> {#- -#}
9394
<div class="logo-container"> {#- -#}
9495
{%- if !layout.logo.is_empty() %}
@@ -98,6 +99,7 @@ <h2></h2> {#- -#}
9899
{%- endif -%}
99100
</div> {#- -#}
100101
</a> {#- -#}
102+
{%- endif -%}
101103
{{- sidebar|safe -}}
102104
</nav> {#- -#}
103105
<main> {#- -#}

src/librustdoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ pub fn main() {
154154
}
155155
}
156156

157-
rustc_driver::set_sigpipe_handler();
158157
rustc_driver::install_ice_hook();
159158

160159
// When using CI artifacts (with `download_stage1 = true`), tracing is unconditionally built

0 commit comments

Comments
 (0)