Skip to content

Commit bf19905

Browse files
authored
Rollup merge of rust-lang#62417 - alexreg:fix-self-in-type-alias, r=pnkfelix
Fix ICEs when `Self` is used in type aliases I think it is right just to disallow this at resolution stage rather than let typeck produce a cyclic error. This is in line with previous behaviour. There was probably no need at all for the change that introduced this bug in rust-lang#57428, so I've simply reversed it. Fixes rust-lang#62263, rust-lang#62364, rust-lang#62305. r? @eddyb
2 parents 5d8ffb5 + f035630 commit bf19905

11 files changed

+61
-24
lines changed

src/bootstrap/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ pub struct Compiler {
197197

198198
#[derive(PartialEq, Eq, Copy, Clone, Debug)]
199199
pub enum DocTests {
200-
// Default, run normal tests and doc tests.
200+
/// Run normal tests and doc tests (default).
201201
Yes,
202-
// Do not run any doc tests.
202+
/// Do not run any doc tests.
203203
No,
204-
// Only run doc tests.
204+
/// Only run doc tests.
205205
Only,
206206
}
207207

@@ -221,10 +221,10 @@ pub enum GitRepo {
221221
/// methods specifically on this structure itself (to make it easier to
222222
/// organize).
223223
pub struct Build {
224-
// User-specified configuration via config.toml
224+
/// User-specified configuration from `config.toml`.
225225
config: Config,
226226

227-
// Derived properties from the above two configurations
227+
// Properties derived from the above configuration
228228
src: PathBuf,
229229
out: PathBuf,
230230
rust_info: channel::GitInfo,
@@ -240,12 +240,12 @@ pub struct Build {
240240
doc_tests: DocTests,
241241
verbosity: usize,
242242

243-
// Targets for which to build.
243+
// Targets for which to build
244244
build: Interned<String>,
245245
hosts: Vec<Interned<String>>,
246246
targets: Vec<Interned<String>>,
247247

248-
// Stage 0 (downloaded) compiler and cargo or their local rust equivalents.
248+
// Stage 0 (downloaded) compiler and cargo or their local rust equivalents
249249
initial_rustc: PathBuf,
250250
initial_cargo: PathBuf,
251251

@@ -255,7 +255,7 @@ pub struct Build {
255255
cxx: HashMap<Interned<String>, cc::Tool>,
256256
ar: HashMap<Interned<String>, PathBuf>,
257257
ranlib: HashMap<Interned<String>, PathBuf>,
258-
// Misc
258+
// Miscellaneous
259259
crates: HashMap<Interned<String>, Crate>,
260260
is_sudo: bool,
261261
ci_env: CiEnv,

src/librustc_resolve/lib.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -2523,17 +2523,7 @@ impl<'a> Resolver<'a> {
25232523
debug!("(resolving item) resolving {} ({:?})", name, item.node);
25242524

25252525
match item.node {
2526-
ItemKind::Ty(_, ref generics) => {
2527-
self.with_current_self_item(item, |this| {
2528-
this.with_generic_param_rib(HasGenericParams(generics, ItemRibKind), |this| {
2529-
let item_def_id = this.definitions.local_def_id(item.id);
2530-
this.with_self_rib(Res::SelfTy(Some(item_def_id), None), |this| {
2531-
visit::walk_item(this, item)
2532-
})
2533-
})
2534-
});
2535-
}
2536-
2526+
ItemKind::Ty(_, ref generics) |
25372527
ItemKind::Existential(_, ref generics) |
25382528
ItemKind::Fn(_, _, ref generics, _) => {
25392529
self.with_generic_param_rib(

src/librustc_typeck/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4457,7 +4457,7 @@ pub fn check_bounds_are_used<'tcx>(tcx: TyCtxt<'tcx>, generics: &ty::Generics, t
44574457
return;
44584458
}
44594459

4460-
// Make a vector of booleans initially false, set to true when used.
4460+
// Make a vector of booleans initially `false`; set to `true` when used.
44614461
let mut types_used = vec![false; own_counts.types];
44624462

44634463
for leaf_ty in ty.walk() {
@@ -4466,7 +4466,7 @@ pub fn check_bounds_are_used<'tcx>(tcx: TyCtxt<'tcx>, generics: &ty::Generics, t
44664466
types_used[index as usize - own_counts.lifetimes] = true;
44674467
} else if let ty::Error = leaf_ty.sty {
44684468
// If there is already another error, do not emit
4469-
// an error for not using a type Parameter.
4469+
// an error for not using a type parameter.
44704470
assert!(tcx.sess.has_errors());
44714471
return;
44724472
}
File renamed without changes.

src/test/ui/cast_char.stderr src/test/ui/cast-char.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error: only `u8` can be cast into `char`
2-
--> $DIR/cast_char.rs:4:23
2+
--> $DIR/cast-char.rs:4:23
33
|
44
LL | const XYZ: char = 0x1F888 as char;
55
| ^^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{1F888}'`
66
|
77
note: lint level defined here
8-
--> $DIR/cast_char.rs:1:9
8+
--> $DIR/cast-char.rs:1:9
99
|
1010
LL | #![deny(overflowing_literals)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212

1313
error: only `u8` can be cast into `char`
14-
--> $DIR/cast_char.rs:6:22
14+
--> $DIR/cast-char.rs:6:22
1515
|
1616
LL | const XY: char = 129160 as char;
1717
| ^^^^^^^^^^^^^^ help: use a `char` literal instead: `'\u{1F888}'`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
pub trait Trait {
2+
type A;
3+
}
4+
5+
pub type Alias = dyn Trait<A = Self::A>;
6+
//~^ ERROR failed to resolve: use of undeclared type or module `Self` [E0433]
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0433]: failed to resolve: use of undeclared type or module `Self`
2+
--> $DIR/issue-62263-self-in-atb.rs:5:32
3+
|
4+
LL | pub type Alias = dyn Trait<A = Self::A>;
5+
| ^^^^ use of undeclared type or module `Self`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0433`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type Alias = Self::Target;
2+
//~^ ERROR failed to resolve: use of undeclared type or module `Self` [E0433]
3+
4+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0433]: failed to resolve: use of undeclared type or module `Self`
2+
--> $DIR/issue-62305-self-assoc-ty.rs:1:14
3+
|
4+
LL | type Alias = Self::Target;
5+
| ^^^^ use of undeclared type or module `Self`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0433`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
struct Struct<P1> {
2+
field: P1,
3+
}
4+
5+
type Alias<'a> = Struct<&'a Self>;
6+
//~^ ERROR cannot find type `Self` in this scope [E0411]
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0411]: cannot find type `Self` in this scope
2+
--> $DIR/issue-62364-self-ty-arg.rs:5:29
3+
|
4+
LL | type Alias<'a> = Struct<&'a Self>;
5+
| ^^^^ `Self` is only available in impls, traits, and type definitions
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0411`.

0 commit comments

Comments
 (0)