Skip to content

Rollup of 6 pull requests #103672

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 15 commits into from
Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/hir_analysis.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,7 @@ hir_analysis_const_impl_for_non_const_trait =

hir_analysis_const_bound_for_non_const_trait =
~const can only be applied to `#[const_trait]` traits

hir_analysis_self_in_impl_self =
`Self` is not valid in the self type of an impl block
.note = replace `Self` with a different type
24 changes: 24 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2418,6 +2418,30 @@ impl<'hir> Ty<'hir> {
}
final_ty
}

pub fn find_self_aliases(&self) -> Vec<Span> {
use crate::intravisit::Visitor;
struct MyVisitor(Vec<Span>);
impl<'v> Visitor<'v> for MyVisitor {
fn visit_ty(&mut self, t: &'v Ty<'v>) {
if matches!(
&t.kind,
TyKind::Path(QPath::Resolved(
_,
Path { res: crate::def::Res::SelfTyAlias { .. }, .. },
))
) {
self.0.push(t.span);
return;
}
crate::intravisit::walk_ty(self, t);
}
}

let mut my_visitor = MyVisitor(vec![]);
my_visitor.visit_ty(self);
my_visitor.0
}
}

/// Not represented directly in the AST; referred to by name through a `ty_path`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
let num_trait_substs = trait_to_impl_substs.len();
let num_impl_substs = tcx.generics_of(impl_m.container_id(tcx)).params.len();
let ty = tcx.fold_regions(ty, |region, _| {
let ty::ReFree(_) = region.kind() else { return region; };
let (ty::ReFree(_) | ty::ReEarlyBound(_)) = region.kind() else { return region; };
let Some(ty::ReEarlyBound(e)) = map.get(&region.into()).map(|r| r.expect_region().kind())
else {
tcx
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,15 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
}
}
ItemKind::TyAlias(self_ty, _) => icx.to_ty(self_ty),
ItemKind::Impl(hir::Impl { self_ty, .. }) => icx.to_ty(*self_ty),
ItemKind::Impl(hir::Impl { self_ty, .. }) => {
match self_ty.find_self_aliases() {
spans if spans.len() > 0 => {
tcx.sess.emit_err(crate::errors::SelfInImplSelf { span: spans.into(), note: (), });
tcx.ty_error()
},
_ => icx.to_ty(*self_ty),
}
},
ItemKind::Fn(..) => {
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
tcx.mk_fn_def(def_id.to_def_id(), substs)
Expand Down
11 changes: 10 additions & 1 deletion compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Errors emitted by `rustc_hir_analysis`.

use rustc_errors::IntoDiagnostic;
use rustc_errors::{error_code, Applicability, DiagnosticBuilder, ErrorGuaranteed, Handler};
use rustc_errors::{IntoDiagnostic, MultiSpan};
use rustc_macros::{Diagnostic, LintDiagnostic};
use rustc_middle::ty::Ty;
use rustc_span::{symbol::Ident, Span, Symbol};
Expand Down Expand Up @@ -270,3 +270,12 @@ pub struct ConstBoundForNonConstTrait {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(hir_analysis_self_in_impl_self)]
pub struct SelfInImplSelf {
#[primary_span]
pub span: MultiSpan,
#[note]
pub note: (),
}
14 changes: 10 additions & 4 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,6 @@ p:last-child {
margin: 0;
}

summary {
outline: none;
}

/* Fix some style changes due to normalize.css 8 */

button {
Expand Down Expand Up @@ -571,10 +567,18 @@ ul.block, .block li {
padding: 13px 8px;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
border-color: var(--example-line-numbers-border-color);
}

.src-line-numbers span {
cursor: pointer;
color: var(--src-line-numbers-span-color);
}
.src-line-numbers .line-highlighted {
background-color: var(--src-line-number-highlighted-background-color);
}
.src-line-numbers :target {
background-color: transparent;
}

.search-loading {
Expand Down Expand Up @@ -1527,6 +1531,8 @@ details.rustdoc-toggle > summary.hideme {

details.rustdoc-toggle > summary {
list-style: none;
/* focus outline is shown on `::before` instead of this */
outline: none;
}
details.rustdoc-toggle > summary::-webkit-details-marker,
details.rustdoc-toggle > summary::marker {
Expand Down
12 changes: 3 additions & 9 deletions src/librustdoc/html/static/css/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ Original by Dempfi (https://github.com/dempfi/ayu)
--code-highlight-question-mark-color: #ff9011;
--code-highlight-comment-color: #788797;
--code-highlight-doc-comment-color: #a1ac88;
--example-line-numbers-border-color: none;
--src-line-numbers-span-color: #5c6773;
--src-line-number-highlighted-background-color: rgba(255, 236, 164, 0.06);
}

.slider {
Expand Down Expand Up @@ -112,10 +115,8 @@ pre, .rustdoc.source .example-wrap {
color: #ff7733;
}

.src-line-numbers span { color: #5c6773; }
.src-line-numbers .line-highlighted {
color: #708090;
background-color: rgba(255, 236, 164, 0.06);
padding-right: 4px;
border-right: 1px solid #ffb44c;
}
Expand Down Expand Up @@ -170,13 +171,6 @@ details.rustdoc-toggle > summary::before {
color: #788797;
}

.src-line-numbers :target { background-color: transparent; }

pre.example-line-numbers {
color: #5c67736e;
border: none;
}

a.test-arrow {
font-size: 100%;
color: #788797;
Expand Down
14 changes: 3 additions & 11 deletions src/librustdoc/html/static/css/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
--code-highlight-question-mark-color: #ff9011;
--code-highlight-comment-color: #8d8d8b;
--code-highlight-doc-comment-color: #8ca375;
--example-line-numbers-border-color: #4a4949;
--src-line-numbers-span-color: #3b91e2;
--src-line-number-highlighted-background-color: #0a042f;
}

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

.src-line-numbers span { color: #3B91E2; }
.src-line-numbers .line-highlighted {
background-color: #0a042f !important;
}

.content .item-info::before { color: #ccc; }

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

.src-line-numbers :target { background-color: transparent; }

pre.example-line-numbers {
border-color: #4a4949;
}

a.test-arrow {
color: #dedede;
background-color: rgba(78, 139, 202, 0.2);
Expand Down
14 changes: 3 additions & 11 deletions src/librustdoc/html/static/css/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
--code-highlight-question-mark-color: #ff9011;
--code-highlight-comment-color: #8e908c;
--code-highlight-doc-comment-color: #4d4d4c;
--example-line-numbers-border-color: #c7c7c7;
--src-line-numbers-span-color: #c67e2d;
--src-line-number-highlighted-background-color: #fdffd3;
}

.slider {
Expand All @@ -68,11 +71,6 @@ input:focus + .slider {
*/
}

.src-line-numbers span { color: #c67e2d; }
.src-line-numbers .line-highlighted {
background-color: #FDFFD3 !important;
}

.content .item-info::before { color: #ccc; }

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

.src-line-numbers :target { background-color: transparent; }

pre.example-line-numbers {
border-color: #c7c7c7;
}

a.test-arrow {
color: #f5f5f5;
background-color: rgba(78, 139, 202, 0.2);
Expand Down
44 changes: 43 additions & 1 deletion src/test/rustdoc-gui/source-code-page.goml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Checks that the interactions with the source code pages are working as expected.
goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
show-text: true
// Check that we can click on the line number.
click: ".src-line-numbers > span:nth-child(4)" // This is the span for line 4.
// Ensure that the page URL was updated.
Expand All @@ -12,6 +13,48 @@ assert-attribute: (".src-line-numbers > span:nth-child(4)", {"class": "line-high
assert-attribute: (".src-line-numbers > span:nth-child(5)", {"class": "line-highlighted"})
assert-attribute: (".src-line-numbers > span:nth-child(6)", {"class": "line-highlighted"})
assert-attribute-false: (".src-line-numbers > span:nth-child(7)", {"class": "line-highlighted"})

define-function: (
"check-colors",
(theme, color, background_color, highlight_color, highlight_background_color),
[
("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
("reload"),
("assert-css", (
".src-line-numbers > span:not(.line-highlighted)",
{"color": |color|, "background-color": |background_color|},
ALL,
)),
("assert-css", (
".src-line-numbers > span.line-highlighted",
{"color": |highlight_color|, "background-color": |highlight_background_color|},
ALL,
)),
],
)

call-function: ("check-colors", {
"theme": "ayu",
"color": "rgb(92, 103, 115)",
"background_color": "rgba(0, 0, 0, 0)",
"highlight_color": "rgb(112, 128, 144)",
"highlight_background_color": "rgba(255, 236, 164, 0.06)",
})
call-function: ("check-colors", {
"theme": "dark",
"color": "rgb(59, 145, 226)",
"background_color": "rgba(0, 0, 0, 0)",
"highlight_color": "rgb(59, 145, 226)",
"highlight_background_color": "rgb(10, 4, 47)",
})
call-function: ("check-colors", {
"theme": "light",
"color": "rgb(198, 126, 45)",
"background_color": "rgba(0, 0, 0, 0)",
"highlight_color": "rgb(198, 126, 45)",
"highlight_background_color": "rgb(253, 255, 211)",
})

// This is to ensure that the content is correctly align with the line numbers.
compare-elements-position: ("//*[@id='1']", ".rust > code > span", ("y"))

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

// Now let's check that clicking on something else than the line number doesn't
// do anything (and certainly not add a `#NaN` to the URL!).
show-text: true
goto: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
// We use this assert-position to know where we will click.
assert-position: ("//*[@id='1']", {"x": 104, "y": 112})
Expand Down
20 changes: 20 additions & 0 deletions src/test/ui/coercion/issue-36007.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// check-pass
#![feature(coerce_unsized, unsize)]

use std::marker::Unsize;
use std::ops::CoerceUnsized;

struct Foo<T: ?Sized>(Box<T>);

impl<T> CoerceUnsized<Foo<dyn Baz>> for Foo<T> where T: Unsize<dyn Baz> {}

struct Bar;

trait Baz {}

impl Baz for Bar {}

fn main() {
let foo = Foo(Box::new(Bar));
let foobar: Foo<Bar> = foo;
}
23 changes: 23 additions & 0 deletions src/test/ui/impl-trait/in-trait/early.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// check-pass
// edition:2021

#![feature(async_fn_in_trait, return_position_impl_trait_in_trait)]
#![allow(incomplete_features)]

pub trait Foo {
async fn bar<'a: 'a>(&'a mut self);
}

impl Foo for () {
async fn bar<'a: 'a>(&'a mut self) {}
}

pub trait Foo2 {
fn bar<'a: 'a>(&'a mut self) -> impl Sized + 'a;
}

impl Foo2 for () {
fn bar<'a: 'a>(&'a mut self) -> impl Sized + 'a {}
}

fn main() {}
2 changes: 1 addition & 1 deletion src/test/ui/resolve/issue-23305.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ pub trait ToNbt<T> {
}

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

fn main() {}
16 changes: 2 additions & 14 deletions src/test/ui/resolve/issue-23305.stderr
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
error[E0391]: cycle detected when computing type of `<impl at $DIR/issue-23305.rs:5:1: 5:21>`
error: `Self` is not valid in the self type of an impl block
--> $DIR/issue-23305.rs:5:16
|
LL | impl dyn ToNbt<Self> {}
| ^^^^
|
= note: ...which immediately requires computing type of `<impl at $DIR/issue-23305.rs:5:1: 5:21>` again
note: cycle used when collecting item types in top-level module
--> $DIR/issue-23305.rs:1:1
|
LL | / pub trait ToNbt<T> {
LL | | fn new(val: T) -> Self;
LL | | }
LL | |
... |
LL | |
LL | | fn main() {}
| |____________^
= note: replace `Self` with a different type

error: aborting due to previous error

For more information about this error, try `rustc --explain E0391`.
9 changes: 5 additions & 4 deletions src/test/ui/resolve/resolve-self-in-impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ impl Tr for S where Self: Copy {} // OK
impl Tr for S where S<Self>: Copy {} // OK
impl Tr for S where Self::A: Copy {} // OK

impl Tr for Self {} //~ ERROR cycle detected
impl Tr for S<Self> {} //~ ERROR cycle detected
impl Self {} //~ ERROR cycle detected
impl S<Self> {} //~ ERROR cycle detected
impl Tr for Self {} //~ ERROR `Self` is not valid in the self type of an impl block
impl Tr for S<Self> {} //~ ERROR `Self` is not valid in the self type of an impl block
impl Self {} //~ ERROR `Self` is not valid in the self type of an impl block
impl S<Self> {} //~ ERROR `Self` is not valid in the self type of an impl block
impl (Self, Self) {} //~ ERROR `Self` is not valid in the self type of an impl block
impl Tr<Self::A> for S {} //~ ERROR cycle detected

fn main() {}
Loading