Skip to content

Commit 898f463

Browse files
committed
Auto merge of #103672 - matthiaskrgr:rollup-dyk3civ, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #103585 (Migrate source line numbers CSS to CSS variables) - #103608 (Remap early bound lifetimes in return-position `impl Trait` in traits too) - #103609 (Emit a nicer error on `impl Self {`) - #103631 (Add test for issue 36007) - #103643 (rustdoc: stop hiding focus outlines on non-rustdoc-toggle details tags) - #103645 (Update cargo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents cdd7afe + 2f00f57 commit 898f463

File tree

17 files changed

+181
-114
lines changed

17 files changed

+181
-114
lines changed

compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,7 @@ hir_analysis_const_impl_for_non_const_trait =
146146
147147
hir_analysis_const_bound_for_non_const_trait =
148148
~const can only be applied to `#[const_trait]` traits
149+
150+
hir_analysis_self_in_impl_self =
151+
`Self` is not valid in the self type of an impl block
152+
.note = replace `Self` with a different type

compiler/rustc_hir/src/hir.rs

+24
Original file line numberDiff line numberDiff line change
@@ -2418,6 +2418,30 @@ impl<'hir> Ty<'hir> {
24182418
}
24192419
final_ty
24202420
}
2421+
2422+
pub fn find_self_aliases(&self) -> Vec<Span> {
2423+
use crate::intravisit::Visitor;
2424+
struct MyVisitor(Vec<Span>);
2425+
impl<'v> Visitor<'v> for MyVisitor {
2426+
fn visit_ty(&mut self, t: &'v Ty<'v>) {
2427+
if matches!(
2428+
&t.kind,
2429+
TyKind::Path(QPath::Resolved(
2430+
_,
2431+
Path { res: crate::def::Res::SelfTyAlias { .. }, .. },
2432+
))
2433+
) {
2434+
self.0.push(t.span);
2435+
return;
2436+
}
2437+
crate::intravisit::walk_ty(self, t);
2438+
}
2439+
}
2440+
2441+
let mut my_visitor = MyVisitor(vec![]);
2442+
my_visitor.visit_ty(self);
2443+
my_visitor.0
2444+
}
24212445
}
24222446

24232447
/// Not represented directly in the AST; referred to by name through a `ty_path`.

compiler/rustc_hir_analysis/src/check/compare_method.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
597597
let num_trait_substs = trait_to_impl_substs.len();
598598
let num_impl_substs = tcx.generics_of(impl_m.container_id(tcx)).params.len();
599599
let ty = tcx.fold_regions(ty, |region, _| {
600-
let ty::ReFree(_) = region.kind() else { return region; };
600+
let (ty::ReFree(_) | ty::ReEarlyBound(_)) = region.kind() else { return region; };
601601
let Some(ty::ReEarlyBound(e)) = map.get(&region.into()).map(|r| r.expect_region().kind())
602602
else {
603603
tcx

compiler/rustc_hir_analysis/src/collect/type_of.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,15 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
319319
}
320320
}
321321
ItemKind::TyAlias(self_ty, _) => icx.to_ty(self_ty),
322-
ItemKind::Impl(hir::Impl { self_ty, .. }) => icx.to_ty(*self_ty),
322+
ItemKind::Impl(hir::Impl { self_ty, .. }) => {
323+
match self_ty.find_self_aliases() {
324+
spans if spans.len() > 0 => {
325+
tcx.sess.emit_err(crate::errors::SelfInImplSelf { span: spans.into(), note: (), });
326+
tcx.ty_error()
327+
},
328+
_ => icx.to_ty(*self_ty),
329+
}
330+
},
323331
ItemKind::Fn(..) => {
324332
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
325333
tcx.mk_fn_def(def_id.to_def_id(), substs)

compiler/rustc_hir_analysis/src/errors.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Errors emitted by `rustc_hir_analysis`.
22
3-
use rustc_errors::IntoDiagnostic;
43
use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler};
4+
use rustc_errors::{IntoDiagnostic, MultiSpan};
55
use rustc_macros::{Diagnostic, LintDiagnostic};
66
use rustc_middle::ty::Ty;
77
use rustc_span::{symbol::Ident, Span, Symbol};
@@ -270,3 +270,12 @@ pub struct ConstBoundForNonConstTrait {
270270
#[primary_span]
271271
pub span: Span,
272272
}
273+
274+
#[derive(Diagnostic)]
275+
#[diag(hir_analysis_self_in_impl_self)]
276+
pub struct SelfInImplSelf {
277+
#[primary_span]
278+
pub span: MultiSpan,
279+
#[note]
280+
pub note: (),
281+
}

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

+10-4
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,6 @@ p:last-child {
292292
margin: 0;
293293
}
294294

295-
summary {
296-
outline: none;
297-
}
298-
299295
/* Fix some style changes due to normalize.css 8 */
300296

301297
button {
@@ -571,10 +567,18 @@ ul.block, .block li {
571567
padding: 13px 8px;
572568
border-top-left-radius: 5px;
573569
border-bottom-left-radius: 5px;
570+
border-color: var(--example-line-numbers-border-color);
574571
}
575572

576573
.src-line-numbers span {
577574
cursor: pointer;
575+
color: var(--src-line-numbers-span-color);
576+
}
577+
.src-line-numbers .line-highlighted {
578+
background-color: var(--src-line-number-highlighted-background-color);
579+
}
580+
.src-line-numbers :target {
581+
background-color: transparent;
578582
}
579583

580584
.search-loading {
@@ -1527,6 +1531,8 @@ details.rustdoc-toggle > summary.hideme {
15271531

15281532
details.rustdoc-toggle > summary {
15291533
list-style: none;
1534+
/* focus outline is shown on `::before` instead of this */
1535+
outline: none;
15301536
}
15311537
details.rustdoc-toggle > summary::-webkit-details-marker,
15321538
details.rustdoc-toggle > summary::marker {

src/librustdoc/html/static/css/themes/ayu.css

+3-9
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Original by Dempfi (https://github.com/dempfi/ayu)
5555
--code-highlight-question-mark-color: #ff9011;
5656
--code-highlight-comment-color: #788797;
5757
--code-highlight-doc-comment-color: #a1ac88;
58+
--example-line-numbers-border-color: none;
59+
--src-line-numbers-span-color: #5c6773;
60+
--src-line-number-highlighted-background-color: rgba(255, 236, 164, 0.06);
5861
}
5962

6063
.slider {
@@ -112,10 +115,8 @@ pre, .rustdoc.source .example-wrap {
112115
color: #ff7733;
113116
}
114117

115-
.src-line-numbers span { color: #5c6773; }
116118
.src-line-numbers .line-highlighted {
117119
color: #708090;
118-
background-color: rgba(255, 236, 164, 0.06);
119120
padding-right: 4px;
120121
border-right: 1px solid #ffb44c;
121122
}
@@ -170,13 +171,6 @@ details.rustdoc-toggle > summary::before {
170171
color: #788797;
171172
}
172173

173-
.src-line-numbers :target { background-color: transparent; }
174-
175-
pre.example-line-numbers {
176-
color: #5c67736e;
177-
border: none;
178-
}
179-
180174
a.test-arrow {
181175
font-size: 100%;
182176
color: #788797;

src/librustdoc/html/static/css/themes/dark.css

+3-11
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
--code-highlight-question-mark-color: #ff9011;
5151
--code-highlight-comment-color: #8d8d8b;
5252
--code-highlight-doc-comment-color: #8ca375;
53+
--example-line-numbers-border-color: #4a4949;
54+
--src-line-numbers-span-color: #3b91e2;
55+
--src-line-number-highlighted-background-color: #0a042f;
5356
}
5457

5558
.slider {
@@ -69,11 +72,6 @@ input:focus + .slider {
6972
drop-shadow(0 -1px 0 #fff)
7073
}
7174

72-
.src-line-numbers span { color: #3B91E2; }
73-
.src-line-numbers .line-highlighted {
74-
background-color: #0a042f !important;
75-
}
76-
7775
.content .item-info::before { color: #ccc; }
7876

7977
body.source .example-wrap pre.rust a {
@@ -95,12 +93,6 @@ details.rustdoc-toggle > summary::before {
9593
filter: invert(69%) sepia(60%) saturate(6613%) hue-rotate(184deg) brightness(100%) contrast(91%);
9694
}
9795

98-
.src-line-numbers :target { background-color: transparent; }
99-
100-
pre.example-line-numbers {
101-
border-color: #4a4949;
102-
}
103-
10496
a.test-arrow {
10597
color: #dedede;
10698
background-color: rgba(78, 139, 202, 0.2);

src/librustdoc/html/static/css/themes/light.css

+3-11
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
--code-highlight-question-mark-color: #ff9011;
5151
--code-highlight-comment-color: #8e908c;
5252
--code-highlight-doc-comment-color: #4d4d4c;
53+
--example-line-numbers-border-color: #c7c7c7;
54+
--src-line-numbers-span-color: #c67e2d;
55+
--src-line-number-highlighted-background-color: #fdffd3;
5356
}
5457

5558
.slider {
@@ -68,11 +71,6 @@ input:focus + .slider {
6871
*/
6972
}
7073

71-
.src-line-numbers span { color: #c67e2d; }
72-
.src-line-numbers .line-highlighted {
73-
background-color: #FDFFD3 !important;
74-
}
75-
7674
.content .item-info::before { color: #ccc; }
7775

7876
body.source .example-wrap pre.rust a {
@@ -90,12 +88,6 @@ body.source .example-wrap pre.rust a {
9088
filter: invert(44%) sepia(18%) saturate(23%) hue-rotate(317deg) brightness(96%) contrast(93%);
9189
}
9290

93-
.src-line-numbers :target { background-color: transparent; }
94-
95-
pre.example-line-numbers {
96-
border-color: #c7c7c7;
97-
}
98-
9991
a.test-arrow {
10092
color: #f5f5f5;
10193
background-color: rgba(78, 139, 202, 0.2);

src/test/rustdoc-gui/source-code-page.goml

+43-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Checks that the interactions with the source code pages are working as expected.
22
goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
3+
show-text: true
34
// Check that we can click on the line number.
45
click: ".src-line-numbers > span:nth-child(4)" // This is the span for line 4.
56
// Ensure that the page URL was updated.
@@ -12,6 +13,48 @@ assert-attribute: (".src-line-numbers > span:nth-child(4)", {"class": "line-high
1213
assert-attribute: (".src-line-numbers > span:nth-child(5)", {"class": "line-highlighted"})
1314
assert-attribute: (".src-line-numbers > span:nth-child(6)", {"class": "line-highlighted"})
1415
assert-attribute-false: (".src-line-numbers > span:nth-child(7)", {"class": "line-highlighted"})
16+
17+
define-function: (
18+
"check-colors",
19+
(theme, color, background_color, highlight_color, highlight_background_color),
20+
[
21+
("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
22+
("reload"),
23+
("assert-css", (
24+
".src-line-numbers > span:not(.line-highlighted)",
25+
{"color": |color|, "background-color": |background_color|},
26+
ALL,
27+
)),
28+
("assert-css", (
29+
".src-line-numbers > span.line-highlighted",
30+
{"color": |highlight_color|, "background-color": |highlight_background_color|},
31+
ALL,
32+
)),
33+
],
34+
)
35+
36+
call-function: ("check-colors", {
37+
"theme": "ayu",
38+
"color": "rgb(92, 103, 115)",
39+
"background_color": "rgba(0, 0, 0, 0)",
40+
"highlight_color": "rgb(112, 128, 144)",
41+
"highlight_background_color": "rgba(255, 236, 164, 0.06)",
42+
})
43+
call-function: ("check-colors", {
44+
"theme": "dark",
45+
"color": "rgb(59, 145, 226)",
46+
"background_color": "rgba(0, 0, 0, 0)",
47+
"highlight_color": "rgb(59, 145, 226)",
48+
"highlight_background_color": "rgb(10, 4, 47)",
49+
})
50+
call-function: ("check-colors", {
51+
"theme": "light",
52+
"color": "rgb(198, 126, 45)",
53+
"background_color": "rgba(0, 0, 0, 0)",
54+
"highlight_color": "rgb(198, 126, 45)",
55+
"highlight_background_color": "rgb(253, 255, 211)",
56+
})
57+
1558
// This is to ensure that the content is correctly align with the line numbers.
1659
compare-elements-position: ("//*[@id='1']", ".rust > code > span", ("y"))
1760

@@ -20,7 +63,6 @@ assert-css: (".src-line-numbers", {"text-align": "right"})
2063

2164
// Now let's check that clicking on something else than the line number doesn't
2265
// do anything (and certainly not add a `#NaN` to the URL!).
23-
show-text: true
2466
goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
2567
// We use this assert-position to know where we will click.
2668
assert-position: ("//*[@id='1']", {"x": 104, "y": 112})

src/test/ui/coercion/issue-36007.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// check-pass
2+
#![feature(coerce_unsized, unsize)]
3+
4+
use std::marker::Unsize;
5+
use std::ops::CoerceUnsized;
6+
7+
struct Foo<T: ?Sized>(Box<T>);
8+
9+
impl<T> CoerceUnsized<Foo<dyn Baz>> for Foo<T> where T: Unsize<dyn Baz> {}
10+
11+
struct Bar;
12+
13+
trait Baz {}
14+
15+
impl Baz for Bar {}
16+
17+
fn main() {
18+
let foo = Foo(Box::new(Bar));
19+
let foobar: Foo<Bar> = foo;
20+
}
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// check-pass
2+
// edition:2021
3+
4+
#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)]
5+
#![allow(incomplete_features)]
6+
7+
pub trait Foo {
8+
async fn bar<'a: 'a>(&'a mut self);
9+
}
10+
11+
impl Foo for () {
12+
async fn bar<'a: 'a>(&'a mut self) {}
13+
}
14+
15+
pub trait Foo2 {
16+
fn bar<'a: 'a>(&'a mut self) -> impl Sized + 'a;
17+
}
18+
19+
impl Foo2 for () {
20+
fn bar<'a: 'a>(&'a mut self) -> impl Sized + 'a {}
21+
}
22+
23+
fn main() {}

src/test/ui/resolve/issue-23305.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ pub trait ToNbt<T> {
33
}
44

55
impl dyn ToNbt<Self> {}
6-
//~^ ERROR cycle detected
6+
//~^ ERROR `Self` is not valid in the self type of an impl block
77

88
fn main() {}
+2-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1-
error[E0391]: cycle detected when computing type of `<impl at $DIR/issue-23305.rs:5:1: 5:21>`
1+
error: `Self` is not valid in the self type of an impl block
22
--> $DIR/issue-23305.rs:5:16
33
|
44
LL | impl dyn ToNbt<Self> {}
55
| ^^^^
66
|
7-
= note: ...which immediately requires computing type of `<impl at $DIR/issue-23305.rs:5:1: 5:21>` again
8-
note: cycle used when collecting item types in top-level module
9-
--> $DIR/issue-23305.rs:1:1
10-
|
11-
LL | / pub trait ToNbt<T> {
12-
LL | | fn new(val: T) -> Self;
13-
LL | | }
14-
LL | |
15-
... |
16-
LL | |
17-
LL | | fn main() {}
18-
| |____________^
7+
= note: replace `Self` with a different type
198

209
error: aborting due to previous error
2110

22-
For more information about this error, try `rustc --explain E0391`.

src/test/ui/resolve/resolve-self-in-impl.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ impl Tr for S where Self: Copy {} // OK
1111
impl Tr for S where S<Self>: Copy {} // OK
1212
impl Tr for S where Self::A: Copy {} // OK
1313

14-
impl Tr for Self {} //~ ERROR cycle detected
15-
impl Tr for S<Self> {} //~ ERROR cycle detected
16-
impl Self {} //~ ERROR cycle detected
17-
impl S<Self> {} //~ ERROR cycle detected
14+
impl Tr for Self {} //~ ERROR `Self` is not valid in the self type of an impl block
15+
impl Tr for S<Self> {} //~ ERROR `Self` is not valid in the self type of an impl block
16+
impl Self {} //~ ERROR `Self` is not valid in the self type of an impl block
17+
impl S<Self> {} //~ ERROR `Self` is not valid in the self type of an impl block
18+
impl (Self, Self) {} //~ ERROR `Self` is not valid in the self type of an impl block
1819
impl Tr<Self::A> for S {} //~ ERROR cycle detected
1920

2021
fn main() {}

0 commit comments

Comments
 (0)