Skip to content

Commit 6e6d741

Browse files
committed
Some fixes + WIP on tests
1 parent 226f00a commit 6e6d741

File tree

4 files changed

+90
-9
lines changed

4 files changed

+90
-9
lines changed

compiler/rustc_ast_lowering/src/delegation.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use rustc_hir::def_id::DefId;
4949
use rustc_middle::span_bug;
5050
use rustc_middle::ty::{Asyncness, DelegationFnSigAttrs, ResolverAstLowering};
5151
use rustc_span::symbol::kw;
52-
use rustc_span::{Ident, Span, Symbol, sym};
52+
use rustc_span::{Ident, Span, Symbol};
5353
use {rustc_ast as ast, rustc_hir as hir};
5454

5555
use super::{GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode};
@@ -75,7 +75,7 @@ struct AttributeAdditionStatus {
7575

7676
enum AttributeAdditionKind {
7777
Default,
78-
Inherit { symbol: Symbol, flag: DelegationFnSigAttrs },
78+
Inherit { flag: DelegationFnSigAttrs },
7979
}
8080

8181
const PARENT_ID: hir::ItemLocalId = hir::ItemLocalId::ZERO;
@@ -84,10 +84,7 @@ static ATTRS_ADDITIONS: &'static [AttributeAdditionInfo; 2] = &[
8484
AttributeAdditionInfo {
8585
factory: |span| hir::Attribute::Parsed(AttributeKind::MustUse { span, reason: None }),
8686
equals: |a| matches!(a, hir::Attribute::Parsed(AttributeKind::MustUse { .. })),
87-
kind: AttributeAdditionKind::Inherit {
88-
symbol: sym::must_use,
89-
flag: DelegationFnSigAttrs::MUST_USE,
90-
},
87+
kind: AttributeAdditionKind::Inherit { flag: DelegationFnSigAttrs::MUST_USE },
9188
},
9289
AttributeAdditionInfo {
9390
factory: |span| hir::Attribute::Parsed(AttributeKind::Inline(InlineAttr::Hint, span)),
@@ -191,11 +188,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
191188
true => None,
192189
false => match a.info.kind {
193190
AttributeAdditionKind::Default => Some((a.info.factory)(span)),
194-
AttributeAdditionKind::Inherit { symbol, flag } => {
195-
// Check if an anttribute present on the target of delegation,
191+
AttributeAdditionKind::Inherit { flag } => {
192+
// Check if an attribute present on the target of delegation,
196193
// either in this crate or others
197194
let should_inherit = match sig_id.as_local() {
198-
None => self.tcx.get_attr(sig_id, symbol).is_some(),
195+
None => self
196+
.tcx
197+
.get_all_attrs(sig_id)
198+
.iter()
199+
.any(|base_attr| (a.info.equals)(base_attr)),
199200
Some(local_id) => self
200201
.resolver
201202
.delegation_fn_sigs
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ edition:2021
2+
3+
#[must_use]
4+
pub unsafe fn unsafe_fn_extern() -> usize { 1 }
5+
6+
#[must_use]
7+
pub extern "C" fn extern_fn_extern() -> usize { 1 }
8+
9+
pub const fn const_fn_extern() -> usize { 1 }
10+
11+
#[must_use]
12+
pub async fn async_fn_extern() { }
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//@ edition:2021
2+
//@ aux-crate:to_reuse_functions=to-reuse-functions.rs
3+
//@ pretty-mode:hir
4+
//@ pretty-compare-only
5+
//@ pp-exact:delegation-inherit-attributes.pp
6+
7+
#![allow(incomplete_features)]
8+
#![feature(fn_delegation)]
9+
#[attr = MacroUse {arguments: UseAll}]
10+
extern crate std;
11+
#[prelude_import]
12+
use std::prelude::rust_2021::*;
13+
14+
extern crate to_reuse_functions;
15+
16+
mod to_reuse {
17+
#[attr = MustUse]
18+
fn foo(x: usize) -> usize { x }
19+
}
20+
21+
#[attr = MustUse]
22+
#[attr = Inline(Hint)]
23+
fn bar(arg0: _) -> _ { to_reuse::foo(self + 1) }
24+
25+
#[attr = MustUse]
26+
#[attr = Inline(Hint)]
27+
unsafe fn unsafe_fn_extern() -> _ { to_reuse_functions::unsafe_fn_extern() }
28+
#[attr = MustUse]
29+
#[attr = Inline(Hint)]
30+
extern "C" fn extern_fn_extern()
31+
-> _ { to_reuse_functions::extern_fn_extern() }
32+
#[attr = Inline(Hint)]
33+
const fn const_fn_extern() -> _ { to_reuse_functions::const_fn_extern() }
34+
#[attr = MustUse]
35+
#[attr = Inline(Hint)]
36+
async fn async_fn_extern() -> _ { to_reuse_functions::async_fn_extern() }
37+
38+
39+
fn main() { }
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//@ edition:2021
2+
//@ aux-crate:to_reuse_functions=to-reuse-functions.rs
3+
//@ pretty-mode:hir
4+
//@ pretty-compare-only
5+
//@ pp-exact:delegation-inherit-attributes.pp
6+
7+
#![allow(incomplete_features)]
8+
#![feature(fn_delegation)]
9+
10+
extern crate to_reuse_functions;
11+
12+
mod to_reuse {
13+
#[must_use]
14+
pub fn foo(x: usize) -> usize {
15+
x
16+
}
17+
}
18+
19+
reuse to_reuse::foo as bar {
20+
self + 1
21+
}
22+
23+
reuse to_reuse_functions::unsafe_fn_extern;
24+
reuse to_reuse_functions::extern_fn_extern;
25+
reuse to_reuse_functions::const_fn_extern;
26+
reuse to_reuse_functions::async_fn_extern;
27+
28+
29+
fn main() {}

0 commit comments

Comments
 (0)