Skip to content

Commit 8853aae

Browse files
authored
Rollup merge of #83944 - jackh726:binder-refactor-fix2, r=lcnr
Fix a couple resolve bugs from binder refactor Fixes #83753 Fixes #83907
2 parents a5c68d7 + 3ae5fed commit 8853aae

5 files changed

+56
-1
lines changed

compiler/rustc_resolve/src/late/lifetimes.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -2719,6 +2719,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
27192719
Some(next) => next,
27202720
None => break None,
27212721
};
2722+
// See issue #83753. If someone writes an associated type on a non-trait, just treat it as
2723+
// there being no supertrait HRTBs.
2724+
match tcx.def_kind(def_id) {
2725+
DefKind::Trait | DefKind::TraitAlias | DefKind::Impl => {}
2726+
_ => break None,
2727+
}
2728+
27222729
if trait_defines_associated_type_named(def_id) {
27232730
break Some(bound_vars.into_iter().collect());
27242731
}
@@ -2764,7 +2771,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
27642771
| Scope::TraitRefBoundary { ref s, .. } => {
27652772
scope = *s;
27662773
}
2767-
Scope::Root => bug!("In fn_like_elision without appropriate scope above"),
2774+
Scope::Root => {
2775+
// See issue #83907. Just bail out from looking inside.
2776+
self.tcx.sess.delay_span_bug(
2777+
rustc_span::DUMMY_SP,
2778+
"In fn_like_elision without appropriate scope above",
2779+
);
2780+
return;
2781+
}
27682782
}
27692783
};
27702784
// While not strictly necessary, we gather anon lifetimes *before* actually
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// check-fail
2+
3+
struct Foo {}
4+
impl Foo {
5+
fn bar(foo: Foo<Target = usize>) {}
6+
//~^ associated type bindings are not allowed here
7+
}
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0229]: associated type bindings are not allowed here
2+
--> $DIR/issue-83753-invalid-associated-type-supertrait-hrtb.rs:5:21
3+
|
4+
LL | fn bar(foo: Foo<Target = usize>) {}
5+
| ^^^^^^^^^^^^^^ associated type not allowed here
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0229`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// check-fail
2+
3+
static STATIC_VAR_FIVE: &One();
4+
//~^ cannot find type
5+
//~| free static item without body
6+
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: free static item without body
2+
--> $DIR/issue-83907-invalid-fn-like-path.rs:3:1
3+
|
4+
LL | static STATIC_VAR_FIVE: &One();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
6+
| |
7+
| help: provide a definition for the static: `= <expr>;`
8+
9+
error[E0412]: cannot find type `One` in this scope
10+
--> $DIR/issue-83907-invalid-fn-like-path.rs:3:26
11+
|
12+
LL | static STATIC_VAR_FIVE: &One();
13+
| ^^^ not found in this scope
14+
15+
error: aborting due to 2 previous errors
16+
17+
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)