Fix a hole in generic parameter import future-proofing
Add some tests for buggy derive helpers
This commit is contained in:
parent
79134c0517
commit
250935d0c7
@ -67,7 +67,7 @@
|
||||
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
|
||||
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::{cmp, fmt, iter, ptr};
|
||||
use std::{cmp, fmt, iter, mem, ptr};
|
||||
use std::collections::BTreeSet;
|
||||
use std::mem::replace;
|
||||
use rustc_data_structures::ptr_key::PtrKey;
|
||||
@ -2375,11 +2375,27 @@ fn future_proof_import(&mut self, use_tree: &ast::UseTree) {
|
||||
ast::UseTreeKind::Simple(..) if segments.len() == 1 => &[TypeNS, ValueNS][..],
|
||||
_ => &[TypeNS],
|
||||
};
|
||||
let report_error = |this: &Self, ns| {
|
||||
let what = if ns == TypeNS { "type parameters" } else { "local variables" };
|
||||
this.session.span_err(ident.span, &format!("imports cannot refer to {}", what));
|
||||
};
|
||||
|
||||
for &ns in nss {
|
||||
if let Some(LexicalScopeBinding::Def(..)) =
|
||||
self.resolve_ident_in_lexical_scope(ident, ns, None, use_tree.prefix.span) {
|
||||
let what = if ns == TypeNS { "type parameters" } else { "local variables" };
|
||||
self.session.span_err(ident.span, &format!("imports cannot refer to {}", what));
|
||||
match self.resolve_ident_in_lexical_scope(ident, ns, None, use_tree.prefix.span) {
|
||||
Some(LexicalScopeBinding::Def(..)) => {
|
||||
report_error(self, ns);
|
||||
}
|
||||
Some(LexicalScopeBinding::Item(binding)) => {
|
||||
let orig_blacklisted_binding =
|
||||
mem::replace(&mut self.blacklisted_binding, Some(binding));
|
||||
if let Some(LexicalScopeBinding::Def(..)) =
|
||||
self.resolve_ident_in_lexical_scope(ident, ns, None,
|
||||
use_tree.prefix.span) {
|
||||
report_error(self, ns);
|
||||
}
|
||||
self.blacklisted_binding = orig_blacklisted_binding;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
} else if let ast::UseTreeKind::Nested(use_trees) = &use_tree.kind {
|
||||
|
@ -223,6 +223,11 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
|
||||
}
|
||||
|
||||
let check_usable = |this: &mut Self, binding: &'a NameBinding<'a>| {
|
||||
if let Some(blacklisted_binding) = this.blacklisted_binding {
|
||||
if ptr::eq(binding, blacklisted_binding) {
|
||||
return Err((Determined, Weak::No));
|
||||
}
|
||||
}
|
||||
// `extern crate` are always usable for backwards compatibility, see issue #37020,
|
||||
// remove this together with `PUB_USE_OF_PRIVATE_EXTERN_CRATE`.
|
||||
let usable = this.is_accessible(binding.vis) || binding.is_extern_crate();
|
||||
|
@ -43,7 +43,7 @@ LL | use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
|
||||
= note: `issue_56125` could refer to an extern crate passed with `--extern`
|
||||
= help: use `::issue_56125` to refer to this extern crate unambiguously
|
||||
note: `issue_56125` could also refer to the module imported here
|
||||
--> $DIR/issue-56125.rs:17:9
|
||||
--> $DIR/issue-56125.rs:18:9
|
||||
|
|
||||
LL | use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
@ -5,6 +5,26 @@
|
||||
|
||||
#[my_attr] //~ ERROR `my_attr` is ambiguous
|
||||
#[derive(MyTrait)]
|
||||
struct S;
|
||||
struct S {
|
||||
// FIXME No ambiguity, attributes in non-macro positions are not resolved properly
|
||||
#[my_attr]
|
||||
field: [u8; {
|
||||
// FIXME No ambiguity, derive helpers are not put into scope for non-attributes
|
||||
use my_attr;
|
||||
|
||||
fn main() {}
|
||||
// FIXME No ambiguity, derive helpers are not put into scope for inner items
|
||||
#[my_attr]
|
||||
struct U;
|
||||
|
||||
mod inner {
|
||||
#[my_attr] //~ ERROR attribute `my_attr` is currently unknown
|
||||
struct V;
|
||||
}
|
||||
|
||||
0
|
||||
}]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let s = S { field: [] };
|
||||
}
|
||||
|
@ -1,3 +1,11 @@
|
||||
error[E0658]: The attribute `my_attr` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
|
||||
--> $DIR/derive-helper-shadowing.rs:20:15
|
||||
|
|
||||
LL | #[my_attr] //~ ERROR attribute `my_attr` is currently unknown
|
||||
| ^^^^^^^
|
||||
|
|
||||
= help: add #![feature(custom_attribute)] to the crate attributes to enable
|
||||
|
||||
error[E0659]: `my_attr` is ambiguous (derive helper attribute vs any other name)
|
||||
--> $DIR/derive-helper-shadowing.rs:6:3
|
||||
|
|
||||
@ -16,6 +24,7 @@ LL | use derive_helper_shadowing::*;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= help: use `crate::my_attr` to refer to this attribute macro unambiguously
|
||||
|
||||
error: aborting due to previous error
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0659`.
|
||||
Some errors occurred: E0658, E0659.
|
||||
For more information about an error, try `rustc --explain E0658`.
|
||||
|
@ -16,7 +16,7 @@ fn type_param<T>() {
|
||||
}
|
||||
|
||||
fn self_import<T>() {
|
||||
use T; // FIXME Should be an error, but future-proofing fails due to `T` being "self-shadowed"
|
||||
use T; //~ ERROR imports cannot refer to type parameters
|
||||
}
|
||||
|
||||
fn let_binding() {
|
||||
|
@ -16,6 +16,12 @@ error: imports cannot refer to type parameters
|
||||
LL | use T::*; //~ ERROR imports cannot refer to type parameters
|
||||
| ^
|
||||
|
||||
error: imports cannot refer to type parameters
|
||||
--> $DIR/future-proofing-locals.rs:19:9
|
||||
|
|
||||
LL | use T; //~ ERROR imports cannot refer to type parameters
|
||||
| ^
|
||||
|
||||
error: imports cannot refer to local variables
|
||||
--> $DIR/future-proofing-locals.rs:25:9
|
||||
|
|
||||
@ -46,5 +52,5 @@ error: imports cannot refer to local variables
|
||||
LL | use {T as _, x}; //~ ERROR imports cannot refer to type parameters
|
||||
| ^
|
||||
|
||||
error: aborting due to 8 previous errors
|
||||
error: aborting due to 9 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user