Skip to content

Commit 65b85a5

Browse files
authored
Rollup merge of #70555 - Centril:fix-70549, r=petrochenkov
resolve, `try_resolve_as_non_binding`: use `delay_span_bug` due to parser recovery Fixes #70549 r? @petrochenkov
2 parents cbe3266 + 9f86d28 commit 65b85a5

File tree

4 files changed

+82
-9
lines changed

4 files changed

+82
-9
lines changed

src/librustc_resolve/late.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1536,20 +1536,18 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
15361536
let is_syntactic_ambiguity = !has_sub && bm == BindingMode::ByValue(Mutability::Not);
15371537

15381538
match res {
1539-
Res::Def(DefKind::Ctor(_, CtorKind::Const), _)
1540-
| Res::Def(DefKind::Const, _)
1541-
| Res::Def(DefKind::ConstParam, _)
1542-
if is_syntactic_ambiguity =>
1543-
{
1539+
Res::SelfCtor(_) // See #70549.
1540+
| Res::Def(
1541+
DefKind::Ctor(_, CtorKind::Const) | DefKind::Const | DefKind::ConstParam,
1542+
_,
1543+
) if is_syntactic_ambiguity => {
15441544
// Disambiguate in favor of a unit struct/variant or constant pattern.
15451545
if let Some(binding) = binding {
15461546
self.r.record_use(ident, ValueNS, binding, false);
15471547
}
15481548
Some(res)
15491549
}
1550-
Res::Def(DefKind::Ctor(..), _)
1551-
| Res::Def(DefKind::Const, _)
1552-
| Res::Def(DefKind::Static, _) => {
1550+
Res::Def(DefKind::Ctor(..) | DefKind::Const | DefKind::Static, _) => {
15531551
// This is unambiguously a fresh binding, either syntactically
15541552
// (e.g., `IDENT @ PAT` or `ref IDENT`) or because `IDENT` resolves
15551553
// to something unusable as a pattern (e.g., constructor function),
@@ -1572,7 +1570,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
15721570
_ => span_bug!(
15731571
ident.span,
15741572
"unexpected resolution for an identifier in pattern: {:?}",
1575-
res
1573+
res,
15761574
),
15771575
}
15781576
}

src/librustc_resolve/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#![feature(bool_to_option)]
1111
#![feature(crate_visibility_modifier)]
1212
#![feature(nll)]
13+
#![feature(or_patterns)]
1314
#![recursion_limit = "256"]
1415

1516
pub use rustc_hir::def::{Namespace, PerNS};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
struct S {}
2+
3+
impl S {
4+
fn foo(&mur Self) {}
5+
//~^ ERROR expected identifier, found keyword `Self`
6+
//~| ERROR expected one of `:`, `@`
7+
//~| ERROR the `Self` constructor can only be used with
8+
fn bar(&'static mur Self) {}
9+
//~^ ERROR unexpected lifetime
10+
//~| ERROR expected identifier, found keyword `Self`
11+
//~| ERROR expected one of `:`, `@`
12+
//~| ERROR the `Self` constructor can only be used with
13+
14+
fn baz(&mur Self @ _) {}
15+
//~^ ERROR expected one of `:`, `@`
16+
}
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
error: expected identifier, found keyword `Self`
2+
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:4:17
3+
|
4+
LL | fn foo(&mur Self) {}
5+
| ^^^^ expected identifier, found keyword
6+
7+
error: expected one of `:`, `@`, or `|`, found keyword `Self`
8+
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:4:17
9+
|
10+
LL | fn foo(&mur Self) {}
11+
| -----^^^^
12+
| | |
13+
| | expected one of `:`, `@`, or `|`
14+
| help: declare the type after the parameter binding: `<identifier>: <type>`
15+
16+
error: unexpected lifetime `'static` in pattern
17+
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:8:13
18+
|
19+
LL | fn bar(&'static mur Self) {}
20+
| ^^^^^^^ help: remove the lifetime
21+
22+
error: expected identifier, found keyword `Self`
23+
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:8:25
24+
|
25+
LL | fn bar(&'static mur Self) {}
26+
| ^^^^ expected identifier, found keyword
27+
28+
error: expected one of `:`, `@`, or `|`, found keyword `Self`
29+
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:8:25
30+
|
31+
LL | fn bar(&'static mur Self) {}
32+
| -------------^^^^
33+
| | |
34+
| | expected one of `:`, `@`, or `|`
35+
| help: declare the type after the parameter binding: `<identifier>: <type>`
36+
37+
error: expected one of `:`, `@`, or `|`, found keyword `Self`
38+
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:14:17
39+
|
40+
LL | fn baz(&mur Self @ _) {}
41+
| ^^^^ expected one of `:`, `@`, or `|`
42+
43+
error: the `Self` constructor can only be used with tuple or unit structs
44+
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:4:17
45+
|
46+
LL | fn foo(&mur Self) {}
47+
| ^^^^ help: use curly brackets: `Self { /* fields */ }`
48+
49+
error: the `Self` constructor can only be used with tuple or unit structs
50+
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:8:25
51+
|
52+
LL | fn bar(&'static mur Self) {}
53+
| ^^^^ help: use curly brackets: `Self { /* fields */ }`
54+
55+
error: aborting due to 8 previous errors
56+

0 commit comments

Comments
 (0)