Skip to content

Commit 20053bd

Browse files
authored
Unrolled build for rust-lang#135663
Rollup merge of rust-lang#135663 - frank-king:fix/135614, r=compiler-errors Fix ICE in resolving associated items as non-bindings Fixes rust-lang#135614 so that imported associated functions of traits can be shadowed by local bindings and associated constants of traits can be used in patterns.
2 parents 1d55f72 + 067cac9 commit 20053bd

6 files changed

+110
-3
lines changed

compiler/rustc_resolve/src/late.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3960,7 +3960,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
39603960
match res {
39613961
Res::SelfCtor(_) // See #70549.
39623962
| Res::Def(
3963-
DefKind::Ctor(_, CtorKind::Const) | DefKind::Const | DefKind::ConstParam,
3963+
DefKind::Ctor(_, CtorKind::Const) | DefKind::Const | DefKind::AssocConst | DefKind::ConstParam,
39643964
_,
39653965
) if is_syntactic_ambiguity => {
39663966
// Disambiguate in favor of a unit struct/variant or constant pattern.
@@ -3969,7 +3969,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
39693969
}
39703970
Some(res)
39713971
}
3972-
Res::Def(DefKind::Ctor(..) | DefKind::Const | DefKind::Static { .. }, _) => {
3972+
Res::Def(DefKind::Ctor(..) | DefKind::Const | DefKind::AssocConst | DefKind::Static { .. }, _) => {
39733973
// This is unambiguously a fresh binding, either syntactically
39743974
// (e.g., `IDENT @ PAT` or `ref IDENT`) or because `IDENT` resolves
39753975
// to something unusable as a pattern (e.g., constructor function),
@@ -4005,7 +4005,7 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
40054005
);
40064006
None
40074007
}
4008-
Res::Def(DefKind::Fn, _) | Res::Local(..) | Res::Err => {
4008+
Res::Def(DefKind::Fn | DefKind::AssocFn, _) | Res::Local(..) | Res::Err => {
40094009
// These entities are explicitly allowed to be shadowed by fresh bindings.
40104010
None
40114011
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0005]: refutable pattern in local binding
2+
--> $DIR/resolve-issue-135614-assoc-const.rs:21:9
3+
|
4+
LL | let DEFAULT: u32 = 0;
5+
| ^^^^^^^ pattern `1_u32..=u32::MAX` not covered
6+
LL | const DEFAULT: u32 = 0;
7+
| ------------------ missing patterns are not covered because `DEFAULT` is interpreted as a constant pattern, not a new variable
8+
|
9+
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
10+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
11+
= note: the matched value is of type `u32`
12+
help: introduce a variable instead
13+
|
14+
LL | let DEFAULT_var: u32 = 0;
15+
| ~~~~~~~~~~~
16+
17+
error: aborting due to 1 previous error
18+
19+
For more information about this error, try `rustc --explain E0005`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0658]: `use` associated items of traits is unstable
2+
--> $DIR/resolve-issue-135614-assoc-const.rs:6:5
3+
|
4+
LL | use MyDefault::DEFAULT;
5+
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #134691 <https://github.com/rust-lang/rust/issues/134691> for more information
8+
= help: add `#![feature(import_trait_associated_functions)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error[E0005]: refutable pattern in local binding
12+
--> $DIR/resolve-issue-135614-assoc-const.rs:21:9
13+
|
14+
LL | let DEFAULT: u32 = 0;
15+
| ^^^^^^^ pattern `1_u32..=u32::MAX` not covered
16+
LL | const DEFAULT: u32 = 0;
17+
| ------------------ missing patterns are not covered because `DEFAULT` is interpreted as a constant pattern, not a new variable
18+
|
19+
= note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant
20+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-02-refutability.html
21+
= note: the matched value is of type `u32`
22+
help: introduce a variable instead
23+
|
24+
LL | let DEFAULT_var: u32 = 0;
25+
| ~~~~~~~~~~~
26+
27+
error: aborting due to 2 previous errors
28+
29+
Some errors have detailed explanations: E0005, E0658.
30+
For more information about an error, try `rustc --explain E0005`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//@ revisions: normal import_trait_associated_functions
2+
#![cfg_attr(import_trait_associated_functions, feature(import_trait_associated_functions))]
3+
4+
// Makes sure that imported constant can be used in pattern bindings.
5+
6+
use MyDefault::DEFAULT; //[normal]~ ERROR `use` associated items of traits is unstable
7+
8+
trait MyDefault {
9+
const DEFAULT: Self;
10+
}
11+
12+
impl MyDefault for u32 {
13+
const DEFAULT: u32 = 0;
14+
}
15+
16+
impl MyDefault for () {
17+
const DEFAULT: () = ();
18+
}
19+
20+
fn foo(x: u32) -> u32 {
21+
let DEFAULT: u32 = 0; //~ ERROR refutable pattern in local binding
22+
const DEFAULT: u32 = 0;
23+
if let DEFAULT = x { DEFAULT } else { 1 }
24+
}
25+
26+
fn bar() {
27+
let DEFAULT = ();
28+
}
29+
30+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0658]: `use` associated items of traits is unstable
2+
--> $DIR/resolve-issue-135614.rs:7:5
3+
|
4+
LL | use A::b;
5+
| ^^^^
6+
|
7+
= note: see issue #134691 <https://github.com/rust-lang/rust/issues/134691> for more information
8+
= help: add `#![feature(import_trait_associated_functions)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0658`.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ revisions: normal import_trait_associated_functions
2+
//@[import_trait_associated_functions] check-pass
3+
#![cfg_attr(import_trait_associated_functions, feature(import_trait_associated_functions))]
4+
5+
// Makes sure that imported associated functions are shadowed by the local declarations.
6+
7+
use A::b; //[normal]~ ERROR `use` associated items of traits is unstable
8+
9+
trait A {
10+
fn b() {}
11+
}
12+
13+
fn main() {
14+
let b: ();
15+
}

0 commit comments

Comments
 (0)