Skip to content

Commit 8374ab6

Browse files
samratmdholloway
authored andcommitted
Don't add attribute to allow unused-qualifications to derive impl's
Currently `#![forbid(unused_qualifications)]` is incompatible with all derive's because we add `#[allow(unused_qualifications)]` in all generated impl's.
1 parent ed91732 commit 8374ab6

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -727,16 +727,8 @@ impl<'a> TraitDef<'a> {
727727

728728
let attr = cx.attribute(cx.meta_word(self.span, sym::automatically_derived));
729729
let opt_trait_ref = Some(trait_ref);
730-
let unused_qual = {
731-
let word = rustc_ast::attr::mk_nested_word_item(Ident::new(
732-
sym::unused_qualifications,
733-
self.span,
734-
));
735-
let list = rustc_ast::attr::mk_list_item(Ident::new(sym::allow, self.span), vec![word]);
736-
cx.attribute(list)
737-
};
738730

739-
let mut a = vec![attr, unused_qual];
731+
let mut a = vec![attr];
740732
a.extend(self.attributes.iter().cloned());
741733

742734
cx.item(
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// force-host
2+
// no-prefer-dynamic
3+
4+
#![crate_type = "proc-macro"]
5+
6+
extern crate proc_macro;
7+
8+
use proc_macro::TokenStream;
9+
10+
#[proc_macro_derive(AddImpl)]
11+
// Unnecessary qualification `bar::foo`
12+
// https://github.com/rust-lang/rust/issues/71898
13+
pub fn derive(input: TokenStream) -> TokenStream {
14+
"impl B {
15+
fn foo(&self) { use bar::foo; bar::foo() }
16+
}
17+
18+
fn foo() {}
19+
20+
mod bar { pub fn foo() {} }
21+
".parse().unwrap()
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// run-pass
2+
// aux-build:add-impl.rs
3+
4+
#![forbid(unused_qualifications)]
5+
6+
#[macro_use]
7+
extern crate add_impl;
8+
9+
#[derive(AddImpl)]
10+
struct B;
11+
12+
fn main() {
13+
B.foo();
14+
foo();
15+
bar::foo();
16+
}

0 commit comments

Comments
 (0)