Rollup merge of #123997 - compiler-errors:self-res, r=fmease
Delay span bug when `Self` kw resolves to `DefKind::{Mod,Trait}` Catch the case where `kw::Self` is recovered in the parser and causes us to subsequently resolve `&self`'s implicit type to something that's not a type. This check could be made more accurate, though I'm not sure how hard we have to try here. Fixes #123988
This commit is contained in:
commit
90af17ddcb
@ -1866,6 +1866,17 @@ pub fn lower_path(
|
|||||||
self.set_tainted_by_errors(e);
|
self.set_tainted_by_errors(e);
|
||||||
Ty::new_error(self.tcx(), e)
|
Ty::new_error(self.tcx(), e)
|
||||||
}
|
}
|
||||||
|
Res::Def(..) => {
|
||||||
|
assert_eq!(
|
||||||
|
path.segments.get(0).map(|seg| seg.ident.name),
|
||||||
|
Some(kw::SelfUpper),
|
||||||
|
"only expected incorrect resolution for `Self`"
|
||||||
|
);
|
||||||
|
Ty::new_error(
|
||||||
|
self.tcx(),
|
||||||
|
self.tcx().dcx().span_delayed_bug(span, "incorrect resolution for `Self`"),
|
||||||
|
)
|
||||||
|
}
|
||||||
_ => span_bug!(span, "unexpected resolution: {:?}", path.res),
|
_ => span_bug!(span, "unexpected resolution: {:?}", path.res),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
17
tests/ui/resolve/incorrect-self-res.rs
Normal file
17
tests/ui/resolve/incorrect-self-res.rs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
fn module() {
|
||||||
|
fn test(&mut self) {
|
||||||
|
//~^ ERROR `self` parameter is only allowed in associated functions
|
||||||
|
}
|
||||||
|
mod Self {}
|
||||||
|
//~^ ERROR expected identifier, found keyword `Self`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn trait_() {
|
||||||
|
fn test(&mut self) {
|
||||||
|
//~^ ERROR `self` parameter is only allowed in associated functions
|
||||||
|
}
|
||||||
|
trait Self {}
|
||||||
|
//~^ ERROR expected identifier, found keyword `Self`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
30
tests/ui/resolve/incorrect-self-res.stderr
Normal file
30
tests/ui/resolve/incorrect-self-res.stderr
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
error: expected identifier, found keyword `Self`
|
||||||
|
--> $DIR/incorrect-self-res.rs:5:9
|
||||||
|
|
|
||||||
|
LL | mod Self {}
|
||||||
|
| ^^^^ expected identifier, found keyword
|
||||||
|
|
||||||
|
error: expected identifier, found keyword `Self`
|
||||||
|
--> $DIR/incorrect-self-res.rs:13:11
|
||||||
|
|
|
||||||
|
LL | trait Self {}
|
||||||
|
| ^^^^ expected identifier, found keyword
|
||||||
|
|
||||||
|
error: `self` parameter is only allowed in associated functions
|
||||||
|
--> $DIR/incorrect-self-res.rs:2:13
|
||||||
|
|
|
||||||
|
LL | fn test(&mut self) {
|
||||||
|
| ^^^^^^^^^ not semantically valid as function parameter
|
||||||
|
|
|
||||||
|
= note: associated functions are those in `impl` or `trait` definitions
|
||||||
|
|
||||||
|
error: `self` parameter is only allowed in associated functions
|
||||||
|
--> $DIR/incorrect-self-res.rs:10:13
|
||||||
|
|
|
||||||
|
LL | fn test(&mut self) {
|
||||||
|
| ^^^^^^^^^ not semantically valid as function parameter
|
||||||
|
|
|
||||||
|
= note: associated functions are those in `impl` or `trait` definitions
|
||||||
|
|
||||||
|
error: aborting due to 4 previous errors
|
||||||
|
|
Loading…
Reference in New Issue
Block a user