Skip to content
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

resolve, try_resolve_as_non_binding: use delay_span_bug due to parser recovery #70555

Merged
merged 1 commit into from
Mar 31, 2020
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
16 changes: 7 additions & 9 deletions src/librustc_resolve/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1536,20 +1536,18 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
let is_syntactic_ambiguity = !has_sub && bm == BindingMode::ByValue(Mutability::Not);

match res {
Res::Def(DefKind::Ctor(_, CtorKind::Const), _)
| Res::Def(DefKind::Const, _)
| Res::Def(DefKind::ConstParam, _)
if is_syntactic_ambiguity =>
{
Res::SelfCtor(_) // See #70549.
| Res::Def(
DefKind::Ctor(_, CtorKind::Const) | DefKind::Const | DefKind::ConstParam,
petrochenkov marked this conversation as resolved.
Show resolved Hide resolved
_,
) if is_syntactic_ambiguity => {
// Disambiguate in favor of a unit struct/variant or constant pattern.
if let Some(binding) = binding {
self.r.record_use(ident, ValueNS, binding, false);
}
Some(res)
}
Res::Def(DefKind::Ctor(..), _)
| Res::Def(DefKind::Const, _)
| Res::Def(DefKind::Static, _) => {
Res::Def(DefKind::Ctor(..) | DefKind::Const | DefKind::Static, _) => {
// This is unambiguously a fresh binding, either syntactically
// (e.g., `IDENT @ PAT` or `ref IDENT`) or because `IDENT` resolves
// to something unusable as a pattern (e.g., constructor function),
Expand All @@ -1572,7 +1570,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
_ => span_bug!(
ident.span,
"unexpected resolution for an identifier in pattern: {:?}",
res
res,
),
}
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#![feature(bool_to_option)]
#![feature(crate_visibility_modifier)]
#![feature(nll)]
#![feature(or_patterns)]
#![recursion_limit = "256"]

pub use rustc_hir::def::{Namespace, PerNS};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
struct S {}

impl S {
fn foo(&mur Self) {}
//~^ ERROR expected identifier, found keyword `Self`
//~| ERROR expected one of `:`, `@`
//~| ERROR the `Self` constructor can only be used with
fn bar(&'static mur Self) {}
//~^ ERROR unexpected lifetime
//~| ERROR expected identifier, found keyword `Self`
//~| ERROR expected one of `:`, `@`
//~| ERROR the `Self` constructor can only be used with

fn baz(&mur Self @ _) {}
//~^ ERROR expected one of `:`, `@`
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
error: expected identifier, found keyword `Self`
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:4:17
|
LL | fn foo(&mur Self) {}
| ^^^^ expected identifier, found keyword

error: expected one of `:`, `@`, or `|`, found keyword `Self`
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:4:17
|
LL | fn foo(&mur Self) {}
| -----^^^^
| | |
| | expected one of `:`, `@`, or `|`
| help: declare the type after the parameter binding: `<identifier>: <type>`

error: unexpected lifetime `'static` in pattern
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:8:13
|
LL | fn bar(&'static mur Self) {}
| ^^^^^^^ help: remove the lifetime

error: expected identifier, found keyword `Self`
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:8:25
|
LL | fn bar(&'static mur Self) {}
| ^^^^ expected identifier, found keyword

error: expected one of `:`, `@`, or `|`, found keyword `Self`
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:8:25
|
LL | fn bar(&'static mur Self) {}
| -------------^^^^
| | |
| | expected one of `:`, `@`, or `|`
| help: declare the type after the parameter binding: `<identifier>: <type>`

error: expected one of `:`, `@`, or `|`, found keyword `Self`
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:14:17
|
LL | fn baz(&mur Self @ _) {}
| ^^^^ expected one of `:`, `@`, or `|`

error: the `Self` constructor can only be used with tuple or unit structs
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:4:17
|
LL | fn foo(&mur Self) {}
| ^^^^ help: use curly brackets: `Self { /* fields */ }`

error: the `Self` constructor can only be used with tuple or unit structs
--> $DIR/issue-70549-resolve-after-recovered-self-ctor.rs:8:25
|
LL | fn bar(&'static mur Self) {}
| ^^^^ help: use curly brackets: `Self { /* fields */ }`

error: aborting due to 8 previous errors