Skip to content

Commit

Permalink
Rollup merge of #70555 - Centril:fix-70549, r=petrochenkov
Browse files Browse the repository at this point in the history
resolve, `try_resolve_as_non_binding`: use `delay_span_bug` due to parser recovery

Fixes #70549

r? @petrochenkov
  • Loading branch information
Centril authored Mar 30, 2020
2 parents 5bb5d11 + 9f86d28 commit 52ddd32
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 9 deletions.
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,
_,
) 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

0 comments on commit 52ddd32

Please sign in to comment.