Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7f45f53
store segment and module in `UnresolvedImportError`
bvanjoi Mar 20, 2024
42526e1
simplify_branches: add comment
RalfJung Mar 24, 2024
08d7379
Use the correct span for simplifying or-patterns
Nadrieril Mar 5, 2024
70e1d23
CFI: Pad out associated type resolution with erased lifetimes
maurer Mar 25, 2024
d1d9aa3
Consistently merge simplifiable or-patterns
Nadrieril Mar 5, 2024
d0bf6e6
triagebot: Add notification of 2024 issues
ehuss Mar 25, 2024
22da5e0
Add my former address to .mailmap
kpreid Mar 26, 2024
a241ffc
Fix link to BufWriter
ding-young Mar 26, 2024
17c6101
Delegation: fix ICE on wrong `self` resolution
Bryanskiy Mar 22, 2024
3b94f33
Remove `CacheSelector` trait now that we can use GATs
oli-obk Mar 26, 2024
c2de5af
Revert `cargo update` changes
clubby789 Mar 26, 2024
03f5c4f
Rollup merge of #122766 - bvanjoi:fix-115185, r=petrochenkov
matthiaskrgr Mar 26, 2024
d549d4f
Rollup merge of #122996 - RalfJung:simplify_branches, r=cjgillot
matthiaskrgr Mar 26, 2024
6ecbc34
Rollup merge of #123047 - ehuss:triagebot-edition-2024, r=fmease
matthiaskrgr Mar 26, 2024
1fd3ee0
Rollup merge of #123066 - maurer:cfi-erased-lifetime-ice, r=compiler-…
matthiaskrgr Mar 26, 2024
94e8c6c
Rollup merge of #123067 - Nadrieril:always-simplify-or, r=oli-obk
matthiaskrgr Mar 26, 2024
17aabac
Rollup merge of #123069 - clubby789:un-often-cargo-update, r=Kobzol
matthiaskrgr Mar 26, 2024
9ea8f23
Rollup merge of #123070 - kpreid:patch-1, r=workingjubilee
matthiaskrgr Mar 26, 2024
a4bf722
Rollup merge of #123086 - ding-young:fix-ref-to-BufWriter, r=the8472
matthiaskrgr Mar 26, 2024
e7c983c
Rollup merge of #123090 - oli-obk:gatify, r=compiler-errors
matthiaskrgr Mar 26, 2024
4d1fb9e
Rollup merge of #123091 - Bryanskiy:delegation-fixes, r=petrochenkov
matthiaskrgr Mar 26, 2024
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
53 changes: 42 additions & 11 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2531,7 +2531,17 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
}

ItemKind::Delegation(ref delegation) => {
self.resolve_delegation(delegation);
let span = delegation.path.segments.last().unwrap().ident.span;
self.with_generic_param_rib(
&[],
RibKind::Item(HasGenericParams::Yes(span), def_kind),
LifetimeRibKind::Generics {
binder: item.id,
kind: LifetimeBinderKind::Function,
span,
},
|this| this.resolve_delegation(delegation),
);
}

ItemKind::ExternCrate(..) => {}
Expand Down Expand Up @@ -2819,7 +2829,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
walk_assoc_item(self, generics, LifetimeBinderKind::Function, item);
}
AssocItemKind::Delegation(delegation) => {
self.resolve_delegation(delegation);
self.with_generic_param_rib(
&[],
RibKind::AssocItem,
LifetimeRibKind::Generics {
binder: item.id,
kind: LifetimeBinderKind::Function,
span: delegation.path.segments.last().unwrap().ident.span,
},
|this| this.resolve_delegation(delegation),
);
}
AssocItemKind::Type(box TyAlias { generics, .. }) => self
.with_lifetime_rib(LifetimeRibKind::AnonymousReportError, |this| {
Expand Down Expand Up @@ -3069,16 +3088,28 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
}
AssocItemKind::Delegation(box delegation) => {
debug!("resolve_implementation AssocItemKind::Delegation");
self.check_trait_item(
item.id,
item.ident,
&item.kind,
ValueNS,
item.span,
seen_trait_items,
|i, s, c| MethodNotMemberOfTrait(i, s, c),
self.with_generic_param_rib(
&[],
RibKind::AssocItem,
LifetimeRibKind::Generics {
binder: item.id,
kind: LifetimeBinderKind::Function,
span: delegation.path.segments.last().unwrap().ident.span,
},
|this| {
this.check_trait_item(
item.id,
item.ident,
&item.kind,
ValueNS,
item.span,
seen_trait_items,
|i, s, c| MethodNotMemberOfTrait(i, s, c),
);

this.resolve_delegation(delegation)
},
);
self.resolve_delegation(delegation);
}
AssocItemKind::MacCall(_) => {
panic!("unexpanded macro in resolve!")
Expand Down
38 changes: 38 additions & 0 deletions tests/ui/delegation/target-expr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#![feature(fn_delegation)]
#![allow(incomplete_features)]

trait Trait {
fn static_method(x: i32) -> i32 { x }
}

struct F;

struct S(F);
impl Trait for S {}

fn foo(x: i32) -> i32 { x }

fn bar<T: Default>(_: T) {
reuse Trait::static_method {
//~^ ERROR delegation with early bound generics is not supported yet
//~| ERROR mismatched types
let _ = T::Default();
//~^ ERROR can't use generic parameters from outer item
}
}

fn main() {
let y = 0;
reuse <S as Trait>::static_method {
let x = y;
//~^ ERROR can't capture dynamic environment in a fn item
foo(self);

let reuse_ptr: fn(i32) -> i32 = static_method;
reuse_ptr(0)
}
self.0;
//~^ ERROR expected value, found module `self`
let z = x;
//~^ ERROR cannot find value `x` in this scope
}
65 changes: 65 additions & 0 deletions tests/ui/delegation/target-expr.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
error[E0401]: can't use generic parameters from outer item
--> $DIR/target-expr.rs:19:17
|
LL | fn bar<T: Default>(_: T) {
| - type parameter from outer item
LL | reuse Trait::static_method {
| - help: try introducing a local generic parameter here: `T,`
...
LL | let _ = T::Default();
| ^^^^^^^^^^ use of generic parameter from outer item

error[E0434]: can't capture dynamic environment in a fn item
--> $DIR/target-expr.rs:27:17
|
LL | let x = y;
| ^
|
= help: use the `|| { ... }` closure form instead

error[E0424]: expected value, found module `self`
--> $DIR/target-expr.rs:34:5
|
LL | fn main() {
| ---- this function can't have a `self` parameter
...
LL | self.0;
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter

error[E0425]: cannot find value `x` in this scope
--> $DIR/target-expr.rs:36:13
|
LL | let z = x;
| ^
|
help: the binding `x` is available in a different scope in the same function
--> $DIR/target-expr.rs:27:13
|
LL | let x = y;
| ^

error: delegation with early bound generics is not supported yet
--> $DIR/target-expr.rs:16:18
|
LL | fn static_method(x: i32) -> i32 { x }
| ------------------------------- callee defined here
...
LL | reuse Trait::static_method {
| ^^^^^^^^^^^^^

error[E0308]: mismatched types
--> $DIR/target-expr.rs:16:32
|
LL | reuse Trait::static_method {
| ________________________________^
LL | |
LL | |
LL | | let _ = T::Default();
LL | |
LL | | }
| |_____^ expected `i32`, found `()`

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0308, E0401, E0424, E0425, E0434.
For more information about an error, try `rustc --explain E0308`.