Skip to content

Rollup of 7 pull requests #100395

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 22 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
847f461
Never inline Windows dtor access
ChrisDenton Aug 1, 2022
127b6c4
cleanup code w/ pointers in std a little
WaffleLapkin Aug 1, 2022
a7c45ec
improve documentation of `pointer::align_offset`
WaffleLapkin Aug 1, 2022
18a21e1
Remove duplicated temporaries creating during box derefs elaboration
tmiasko Aug 6, 2022
7d2131a
./x.py test --bless
tmiasko Aug 6, 2022
d52ed82
move an `assert!` to the right place
WaffleLapkin Aug 9, 2022
5938fd7
rustdoc: simplify highlight.rs
jsha Jul 16, 2022
16bcc18
Improve crate selection on rustdoc search results page
steffahn Jul 3, 2022
e957480
Two small improvements:
steffahn Jul 11, 2022
107e039
Add missing ID into the ID map
GuillaumeGomez Aug 10, 2022
ea05be2
Update GUI test
GuillaumeGomez Aug 10, 2022
e1e25a8
Generalize trait object generic param check to aliases.
cjgillot Aug 7, 2022
0df84ae
Ban indirect references to `Self` too.
cjgillot Aug 7, 2022
a3b84ad
Check if extern crate enum has non exhaustive variant when cast
Jan 10, 2022
dfb3713
Update error message to clarify that it's not the enum itself that's …
scottmcm Aug 10, 2022
23acd82
Rollup merge of #92744 - lambinoo:I-91161-non-exhaustive-foreign-vari…
Dylan-DPC Aug 11, 2022
72d0be4
Rollup merge of #99337 - jsha:simplify-highlight, r=GuillaumeGomez
Dylan-DPC Aug 11, 2022
5b2ad6e
Rollup merge of #100007 - ChrisDenton:dtor-inline-never, r=michaelwoe…
Dylan-DPC Aug 11, 2022
8bdb414
Rollup merge of #100030 - WaffleLapkin:nice_pointer_sis, r=scottmcm
Dylan-DPC Aug 11, 2022
58dc085
Rollup merge of #100192 - tmiasko:rm-duplicated-locals, r=nagisa
Dylan-DPC Aug 11, 2022
a9f3a27
Rollup merge of #100247 - cjgillot:verify-dyn-trait-alias-defaults, r…
Dylan-DPC Aug 11, 2022
5a5cd6b
Rollup merge of #100374 - GuillaumeGomez:improve_rustdoc_search_resul…
Dylan-DPC Aug 11, 2022
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
Prev Previous commit
Next Next commit
Ban indirect references to Self too.
  • Loading branch information
cjgillot committed Aug 10, 2022
commit 0df84ae67c01d44c3d6c0887333bafca1ea7f060
38 changes: 31 additions & 7 deletions compiler/rustc_typeck/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use rustc_trait_selection::traits::error_reporting::{
};
use rustc_trait_selection::traits::wf::object_region_bounds;

use smallvec::SmallVec;
use smallvec::{smallvec, SmallVec};
use std::collections::BTreeSet;
use std::slice;

Expand Down Expand Up @@ -1444,19 +1444,26 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// Verify that `dummy_self` did not leak inside default type parameters. This
// could not be done at path creation, since we need to see through trait aliases.
let mut missing_type_params = vec![];
let mut references_self = false;
let generics = tcx.generics_of(trait_ref.def_id);
let substs: Vec<_> = trait_ref
.substs
.iter()
.enumerate()
.skip(1) // Remove `Self` for `ExistentialPredicate`.
.map(|(index, arg)| {
if let ty::GenericArgKind::Type(ty) = arg.unpack()
&& ty == dummy_self
{
let param = &generics.params[index];
missing_type_params.push(param.name);
tcx.ty_error().into()
if let ty::GenericArgKind::Type(ty) = arg.unpack() {
debug!(?ty);
if ty == dummy_self {
let param = &generics.params[index];
missing_type_params.push(param.name);
tcx.ty_error().into()
} else if ty.walk().any(|arg| arg == dummy_self.into()) {
references_self = true;
tcx.ty_error().into()
} else {
arg
}
} else {
arg
}
Expand All @@ -1476,6 +1483,23 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
empty_generic_args,
);

if references_self {
let def_id = i.bottom().0.def_id();
let mut err = struct_span_err!(
tcx.sess,
i.bottom().1,
E0038,
"the {} `{}` cannot be made into an object",
tcx.def_kind(def_id).descr(def_id),
tcx.item_name(def_id),
);
err.note(
rustc_middle::traits::ObjectSafetyViolation::SupertraitSelf(smallvec![])
.error_msg(),
);
err.emit();
}

ty::ExistentialTraitRef { def_id: trait_ref.def_id, substs }
})
});
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/traits/alias/self-in-generics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(trait_alias)]

pub trait SelfInput = Fn(&mut Self);

pub fn f(_f: &dyn SelfInput) {}
//~^ ERROR the trait alias `SelfInput` cannot be made into an object [E0038]

fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/traits/alias/self-in-generics.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0038]: the trait alias `SelfInput` cannot be made into an object
--> $DIR/self-in-generics.rs:5:19
|
LL | pub fn f(_f: &dyn SelfInput) {}
| ^^^^^^^^^
|
= note: it cannot use `Self` as a type parameter in a supertrait or `where`-clause

error: aborting due to previous error

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