diff --git a/src/librustc_codegen_llvm/mir/mod.rs b/src/librustc_codegen_llvm/mir/mod.rs index 312939408c62c..aaae7b3cf897e 100644 --- a/src/librustc_codegen_llvm/mir/mod.rs +++ b/src/librustc_codegen_llvm/mir/mod.rs @@ -572,6 +572,25 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>, }; let upvar_tys = upvar_substs.upvar_tys(def_id, tcx); + // Store the pointer to closure data in an alloca for debuginfo + // because that's what the llvm.dbg.declare intrinsic expects. + + // FIXME(eddyb) this shouldn't be necessary but SROA seems to + // mishandle DW_OP_plus not preceded by DW_OP_deref, i.e. it + // doesn't actually strip the offset when splitting the closure + // environment into its components so it ends up out of bounds. + // (cuviper) It seems to be fine without the alloca on LLVM 6 and later. + let env_alloca = !env_ref && unsafe { llvm::LLVMRustVersionMajor() < 6 }; + let env_ptr = if env_alloca { + let scratch = PlaceRef::alloca(bx, + bx.cx.layout_of(tcx.mk_mut_ptr(arg.layout.ty)), + "__debuginfo_env_ptr"); + bx.store(place.llval, scratch.llval, scratch.align); + scratch.llval + } else { + place.llval + }; + for (i, (decl, ty)) in mir.upvar_decls.iter().zip(upvar_tys).enumerate() { let byte_offset_of_var_in_env = closure_layout.fields.offset(i).bytes(); @@ -583,7 +602,10 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>, }; // The environment and the capture can each be indirect. - let mut ops = if env_ref { &ops[..] } else { &ops[1..] }; + + // FIXME(eddyb) see above why we sometimes have to keep + // a pointer in an alloca for debuginfo atm. + let mut ops = if env_ref || env_alloca { &ops[..] } else { &ops[1..] }; let ty = if let (true, &ty::TyRef(_, ty, _)) = (decl.by_ref, &ty.sty) { ty @@ -593,7 +615,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>, }; let variable_access = VariableAccess::IndirectVariable { - alloca: place.llval, + alloca: env_ptr, address_operations: &ops }; declare_local( diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 561f5fbf5c41e..95da9ffe3a540 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -284,7 +284,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnsafeCode { declare_lint! { pub MISSING_DOCS, Allow, - "detects missing documentation for public members" + "detects missing documentation for public members", + report_in_external_macro: true } pub struct MissingDoc { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 9714679949ff4..d41f3ec1d9bd9 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1889,12 +1889,13 @@ impl<'a> Resolver<'a> { } ident.span = ident.span.modern(); + let mut poisoned = None; loop { - let (opt_module, poisoned) = if let Some(node_id) = record_used_id { + let opt_module = if let Some(node_id) = record_used_id { self.hygienic_lexical_parent_with_compatibility_fallback(module, &mut ident.span, - node_id) + node_id, &mut poisoned) } else { - (self.hygienic_lexical_parent(module, &mut ident.span), None) + self.hygienic_lexical_parent(module, &mut ident.span) }; module = unwrap_or!(opt_module, break); let orig_current_module = self.current_module; @@ -1917,9 +1918,9 @@ impl<'a> Resolver<'a> { } return Some(LexicalScopeBinding::Item(binding)) } - _ if poisoned.is_some() => break, - Err(Undetermined) => return None, - Err(Determined) => {} + Err(Determined) => continue, + Err(Undetermined) => + span_bug!(ident.span, "undetermined resolution during main resolution pass"), } } @@ -1965,12 +1966,12 @@ impl<'a> Resolver<'a> { None } - fn hygienic_lexical_parent_with_compatibility_fallback( - &mut self, module: Module<'a>, span: &mut Span, node_id: NodeId - ) -> (Option>, /* poisoned */ Option) - { + fn hygienic_lexical_parent_with_compatibility_fallback(&mut self, module: Module<'a>, + span: &mut Span, node_id: NodeId, + poisoned: &mut Option) + -> Option> { if let module @ Some(..) = self.hygienic_lexical_parent(module, span) { - return (module, None); + return module; } // We need to support the next case under a deprecation warning @@ -1991,13 +1992,14 @@ impl<'a> Resolver<'a> { // The macro is a proc macro derive if module.expansion.looks_like_proc_macro_derive() { if parent.expansion.is_descendant_of(span.ctxt().outer()) { - return (module.parent, Some(node_id)); + *poisoned = Some(node_id); + return module.parent; } } } } - (None, None) + None } fn resolve_ident_in_module(&mut self, diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index acdb7c4d4edfc..afeb8c122bb7b 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -203,6 +203,8 @@ impl<'a> Resolver<'a> { }; match self.resolve_ident_in_module(module, ident, ns, false, path_span) { Err(Determined) => continue, + Ok(binding) + if !self.is_accessible_from(binding.vis, single_import.parent) => continue, Ok(_) | Err(Undetermined) => return Err(Undetermined), } } @@ -255,8 +257,11 @@ impl<'a> Resolver<'a> { module, ident, ns, false, false, path_span, ); self.current_module = orig_current_module; + match result { Err(Determined) => continue, + Ok(binding) + if !self.is_accessible_from(binding.vis, glob_import.parent) => continue, Ok(_) | Err(Undetermined) => return Err(Undetermined), } } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 40fb2c69e57cb..a961ec5a9edd1 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1861,10 +1861,15 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { "existential types are unstable" ); } - - ast::ImplItemKind::Type(_) if !ii.generics.params.is_empty() => { - gate_feature_post!(&self, generic_associated_types, ii.span, - "generic associated types are unstable"); + ast::ImplItemKind::Type(_) => { + if !ii.generics.params.is_empty() { + gate_feature_post!(&self, generic_associated_types, ii.span, + "generic associated types are unstable"); + } + if !ii.generics.where_clause.predicates.is_empty() { + gate_feature_post!(&self, generic_associated_types, ii.span, + "where clauses on associated types are unstable"); + } } _ => {} } diff --git a/src/test/ui-fulldeps/proc-macro/generate-mod.rs b/src/test/ui-fulldeps/proc-macro/generate-mod.rs index ee0077c3ed3ff..ac59984658d45 100644 --- a/src/test/ui-fulldeps/proc-macro/generate-mod.rs +++ b/src/test/ui-fulldeps/proc-macro/generate-mod.rs @@ -31,6 +31,14 @@ struct S; //~| WARN this was previously accepted struct Z; +fn inner_block() { + #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope + //~| WARN cannot find type `OuterDerive` in this scope + //~| WARN this was previously accepted + //~| WARN this was previously accepted + struct InnerZ; +} + #[derive(generate_mod::CheckDeriveLint)] // OK, lint is suppressed struct W; diff --git a/src/test/ui-fulldeps/proc-macro/generate-mod.stderr b/src/test/ui-fulldeps/proc-macro/generate-mod.stderr index c024aeffbb086..87e5fe2554264 100644 --- a/src/test/ui-fulldeps/proc-macro/generate-mod.stderr +++ b/src/test/ui-fulldeps/proc-macro/generate-mod.stderr @@ -41,6 +41,24 @@ LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #50504 +warning: cannot find type `FromOutside` in this scope + --> $DIR/generate-mod.rs:35:14 + | +LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope + | ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #50504 + +warning: cannot find type `OuterDerive` in this scope + --> $DIR/generate-mod.rs:35:14 + | +LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope + | ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #50504 + error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0412`. diff --git a/src/test/ui/feature-gate-generic_associated_types.rs b/src/test/ui/feature-gate-generic_associated_types.rs index 3470662686643..bbaae1ef449fc 100644 --- a/src/test/ui/feature-gate-generic_associated_types.rs +++ b/src/test/ui/feature-gate-generic_associated_types.rs @@ -19,6 +19,7 @@ trait PointerFamily { } struct Foo; + impl PointerFamily for Foo { type Pointer = Box; //~^ ERROR generic associated types are unstable @@ -31,5 +32,9 @@ trait Bar { //~^ ERROR where clauses on associated types are unstable } +impl Bar for Foo { + type Assoc where Self: Sized = Foo; + //~^ ERROR where clauses on associated types are unstable +} fn main() {} diff --git a/src/test/ui/feature-gate-generic_associated_types.stderr b/src/test/ui/feature-gate-generic_associated_types.stderr index d7891f13c6b4d..f12cbe727fbed 100644 --- a/src/test/ui/feature-gate-generic_associated_types.stderr +++ b/src/test/ui/feature-gate-generic_associated_types.stderr @@ -23,7 +23,7 @@ LL | type Pointer2: Deref where T: Clone, U: Clone; = help: add #![feature(generic_associated_types)] to the crate attributes to enable error[E0658]: generic associated types are unstable (see issue #44265) - --> $DIR/feature-gate-generic_associated_types.rs:23:5 + --> $DIR/feature-gate-generic_associated_types.rs:24:5 | LL | type Pointer = Box; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -31,7 +31,7 @@ LL | type Pointer = Box; = help: add #![feature(generic_associated_types)] to the crate attributes to enable error[E0658]: generic associated types are unstable (see issue #44265) - --> $DIR/feature-gate-generic_associated_types.rs:25:5 + --> $DIR/feature-gate-generic_associated_types.rs:26:5 | LL | type Pointer2 = Box; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -39,13 +39,21 @@ LL | type Pointer2 = Box; = help: add #![feature(generic_associated_types)] to the crate attributes to enable error[E0658]: where clauses on associated types are unstable (see issue #44265) - --> $DIR/feature-gate-generic_associated_types.rs:30:5 + --> $DIR/feature-gate-generic_associated_types.rs:31:5 | LL | type Assoc where Self: Sized; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: add #![feature(generic_associated_types)] to the crate attributes to enable -error: aborting due to 6 previous errors +error[E0658]: where clauses on associated types are unstable (see issue #44265) + --> $DIR/feature-gate-generic_associated_types.rs:36:5 + | +LL | type Assoc where Self: Sized = Foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(generic_associated_types)] to the crate attributes to enable + +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/imports/issue-53140.rs b/src/test/ui/imports/issue-53140.rs new file mode 100644 index 0000000000000..dcfa054f2513f --- /dev/null +++ b/src/test/ui/imports/issue-53140.rs @@ -0,0 +1,21 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-pass + +mod m { + pub struct S(u8); + + use S as Z; +} + +use m::*; + +fn main() {} diff --git a/src/test/ui/lint/lints-in-foreign-macros.rs b/src/test/ui/lint/lints-in-foreign-macros.rs index 0f9003877cc06..3785968df871a 100644 --- a/src/test/ui/lint/lints-in-foreign-macros.rs +++ b/src/test/ui/lint/lints-in-foreign-macros.rs @@ -11,7 +11,8 @@ // aux-build:lints-in-foreign-macros.rs // compile-pass -#![warn(unused_imports)] +#![warn(unused_imports)] //~ missing documentation for crate [missing_docs] +#![warn(missing_docs)] #[macro_use] extern crate lints_in_foreign_macros; @@ -24,5 +25,7 @@ mod a { foo!(); } mod b { bar!(); } mod c { baz!(use std::string::ToString;); } //~ WARN: unused import mod d { baz2!(use std::string::ToString;); } //~ WARN: unused import +baz!(pub fn undocumented() {}); //~ WARN: missing documentation for a function +baz2!(pub fn undocumented2() {}); //~ WARN: missing documentation for a function fn main() {} diff --git a/src/test/ui/lint/lints-in-foreign-macros.stderr b/src/test/ui/lint/lints-in-foreign-macros.stderr index e9f6d3d381541..2ddca7781231f 100644 --- a/src/test/ui/lint/lints-in-foreign-macros.stderr +++ b/src/test/ui/lint/lints-in-foreign-macros.stderr @@ -1,5 +1,5 @@ warning: unused import: `std::string::ToString` - --> $DIR/lints-in-foreign-macros.rs:20:16 + --> $DIR/lints-in-foreign-macros.rs:21:16 | LL | () => {use std::string::ToString;} //~ WARN: unused import | ^^^^^^^^^^^^^^^^^^^^^ @@ -10,18 +10,48 @@ LL | mod a { foo!(); } note: lint level defined here --> $DIR/lints-in-foreign-macros.rs:14:9 | -LL | #![warn(unused_imports)] +LL | #![warn(unused_imports)] //~ missing documentation for crate [missing_docs] | ^^^^^^^^^^^^^^ warning: unused import: `std::string::ToString` - --> $DIR/lints-in-foreign-macros.rs:25:18 + --> $DIR/lints-in-foreign-macros.rs:26:18 | LL | mod c { baz!(use std::string::ToString;); } //~ WARN: unused import | ^^^^^^^^^^^^^^^^^^^^^ warning: unused import: `std::string::ToString` - --> $DIR/lints-in-foreign-macros.rs:26:19 + --> $DIR/lints-in-foreign-macros.rs:27:19 | LL | mod d { baz2!(use std::string::ToString;); } //~ WARN: unused import | ^^^^^^^^^^^^^^^^^^^^^ +warning: missing documentation for crate + --> $DIR/lints-in-foreign-macros.rs:14:1 + | +LL | / #![warn(unused_imports)] //~ missing documentation for crate [missing_docs] +LL | | #![warn(missing_docs)] +LL | | +LL | | #[macro_use] +... | +LL | | +LL | | fn main() {} + | |____________^ + | +note: lint level defined here + --> $DIR/lints-in-foreign-macros.rs:15:9 + | +LL | #![warn(missing_docs)] + | ^^^^^^^^^^^^ + +warning: missing documentation for a function + --> $DIR/lints-in-foreign-macros.rs:28:6 + | +LL | baz!(pub fn undocumented() {}); //~ WARN: missing documentation for a function + | ^^^^^^^^^^^^^^^^^^^^^ + +warning: missing documentation for a function + --> $DIR/lints-in-foreign-macros.rs:29:7 + | +LL | baz2!(pub fn undocumented2() {}); //~ WARN: missing documentation for a function + | ^^^^^^^^^^^^^^^^^^^^^^ +