Skip to content

Commit 5c5be09

Browse files
committed
Auto merge of #53700 - pietroalbini:beta-backports, r=pietroalbini
[beta] Rollup backports Merged and approved: * #53559: add macro check for lint * #53509: resolve: Reject some inaccessible candidates sooner during import resolution * #53239: rustc_codegen_llvm: Restore the closure env alloca hack for LLVM 5. * #53235: Feature gate where clauses on associated type impls * #53516: resolve: Continue search in outer scopes after applying derive resolution fallback r? @ghost
2 parents 0baa114 + ef2b1f1 commit 5c5be09

File tree

12 files changed

+157
-29
lines changed

12 files changed

+157
-29
lines changed

src/librustc_codegen_llvm/mir/mod.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,25 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
572572
};
573573
let upvar_tys = upvar_substs.upvar_tys(def_id, tcx);
574574

575+
// Store the pointer to closure data in an alloca for debuginfo
576+
// because that's what the llvm.dbg.declare intrinsic expects.
577+
578+
// FIXME(eddyb) this shouldn't be necessary but SROA seems to
579+
// mishandle DW_OP_plus not preceded by DW_OP_deref, i.e. it
580+
// doesn't actually strip the offset when splitting the closure
581+
// environment into its components so it ends up out of bounds.
582+
// (cuviper) It seems to be fine without the alloca on LLVM 6 and later.
583+
let env_alloca = !env_ref && unsafe { llvm::LLVMRustVersionMajor() < 6 };
584+
let env_ptr = if env_alloca {
585+
let scratch = PlaceRef::alloca(bx,
586+
bx.cx.layout_of(tcx.mk_mut_ptr(arg.layout.ty)),
587+
"__debuginfo_env_ptr");
588+
bx.store(place.llval, scratch.llval, scratch.align);
589+
scratch.llval
590+
} else {
591+
place.llval
592+
};
593+
575594
for (i, (decl, ty)) in mir.upvar_decls.iter().zip(upvar_tys).enumerate() {
576595
let byte_offset_of_var_in_env = closure_layout.fields.offset(i).bytes();
577596

@@ -583,7 +602,10 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
583602
};
584603

585604
// The environment and the capture can each be indirect.
586-
let mut ops = if env_ref { &ops[..] } else { &ops[1..] };
605+
606+
// FIXME(eddyb) see above why we sometimes have to keep
607+
// a pointer in an alloca for debuginfo atm.
608+
let mut ops = if env_ref || env_alloca { &ops[..] } else { &ops[1..] };
587609

588610
let ty = if let (true, &ty::TyRef(_, ty, _)) = (decl.by_ref, &ty.sty) {
589611
ty
@@ -593,7 +615,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
593615
};
594616

595617
let variable_access = VariableAccess::IndirectVariable {
596-
alloca: place.llval,
618+
alloca: env_ptr,
597619
address_operations: &ops
598620
};
599621
declare_local(

src/librustc_lint/builtin.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnsafeCode {
284284
declare_lint! {
285285
pub MISSING_DOCS,
286286
Allow,
287-
"detects missing documentation for public members"
287+
"detects missing documentation for public members",
288+
report_in_external_macro: true
288289
}
289290

290291
pub struct MissingDoc {

src/librustc_resolve/lib.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -1889,12 +1889,13 @@ impl<'a> Resolver<'a> {
18891889
}
18901890

18911891
ident.span = ident.span.modern();
1892+
let mut poisoned = None;
18921893
loop {
1893-
let (opt_module, poisoned) = if let Some(node_id) = record_used_id {
1894+
let opt_module = if let Some(node_id) = record_used_id {
18941895
self.hygienic_lexical_parent_with_compatibility_fallback(module, &mut ident.span,
1895-
node_id)
1896+
node_id, &mut poisoned)
18961897
} else {
1897-
(self.hygienic_lexical_parent(module, &mut ident.span), None)
1898+
self.hygienic_lexical_parent(module, &mut ident.span)
18981899
};
18991900
module = unwrap_or!(opt_module, break);
19001901
let orig_current_module = self.current_module;
@@ -1917,9 +1918,9 @@ impl<'a> Resolver<'a> {
19171918
}
19181919
return Some(LexicalScopeBinding::Item(binding))
19191920
}
1920-
_ if poisoned.is_some() => break,
1921-
Err(Undetermined) => return None,
1922-
Err(Determined) => {}
1921+
Err(Determined) => continue,
1922+
Err(Undetermined) =>
1923+
span_bug!(ident.span, "undetermined resolution during main resolution pass"),
19231924
}
19241925
}
19251926

@@ -1965,12 +1966,12 @@ impl<'a> Resolver<'a> {
19651966
None
19661967
}
19671968

1968-
fn hygienic_lexical_parent_with_compatibility_fallback(
1969-
&mut self, module: Module<'a>, span: &mut Span, node_id: NodeId
1970-
) -> (Option<Module<'a>>, /* poisoned */ Option<NodeId>)
1971-
{
1969+
fn hygienic_lexical_parent_with_compatibility_fallback(&mut self, module: Module<'a>,
1970+
span: &mut Span, node_id: NodeId,
1971+
poisoned: &mut Option<NodeId>)
1972+
-> Option<Module<'a>> {
19721973
if let module @ Some(..) = self.hygienic_lexical_parent(module, span) {
1973-
return (module, None);
1974+
return module;
19741975
}
19751976

19761977
// We need to support the next case under a deprecation warning
@@ -1991,13 +1992,14 @@ impl<'a> Resolver<'a> {
19911992
// The macro is a proc macro derive
19921993
if module.expansion.looks_like_proc_macro_derive() {
19931994
if parent.expansion.is_descendant_of(span.ctxt().outer()) {
1994-
return (module.parent, Some(node_id));
1995+
*poisoned = Some(node_id);
1996+
return module.parent;
19951997
}
19961998
}
19971999
}
19982000
}
19992001

2000-
(None, None)
2002+
None
20012003
}
20022004

20032005
fn resolve_ident_in_module(&mut self,

src/librustc_resolve/resolve_imports.rs

+5
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ impl<'a> Resolver<'a> {
203203
};
204204
match self.resolve_ident_in_module(module, ident, ns, false, path_span) {
205205
Err(Determined) => continue,
206+
Ok(binding)
207+
if !self.is_accessible_from(binding.vis, single_import.parent) => continue,
206208
Ok(_) | Err(Undetermined) => return Err(Undetermined),
207209
}
208210
}
@@ -255,8 +257,11 @@ impl<'a> Resolver<'a> {
255257
module, ident, ns, false, false, path_span,
256258
);
257259
self.current_module = orig_current_module;
260+
258261
match result {
259262
Err(Determined) => continue,
263+
Ok(binding)
264+
if !self.is_accessible_from(binding.vis, glob_import.parent) => continue,
260265
Ok(_) | Err(Undetermined) => return Err(Undetermined),
261266
}
262267
}

src/libsyntax/feature_gate.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1861,10 +1861,15 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
18611861
"existential types are unstable"
18621862
);
18631863
}
1864-
1865-
ast::ImplItemKind::Type(_) if !ii.generics.params.is_empty() => {
1866-
gate_feature_post!(&self, generic_associated_types, ii.span,
1867-
"generic associated types are unstable");
1864+
ast::ImplItemKind::Type(_) => {
1865+
if !ii.generics.params.is_empty() {
1866+
gate_feature_post!(&self, generic_associated_types, ii.span,
1867+
"generic associated types are unstable");
1868+
}
1869+
if !ii.generics.where_clause.predicates.is_empty() {
1870+
gate_feature_post!(&self, generic_associated_types, ii.span,
1871+
"where clauses on associated types are unstable");
1872+
}
18681873
}
18691874
_ => {}
18701875
}

src/test/ui-fulldeps/proc-macro/generate-mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ struct S;
3131
//~| WARN this was previously accepted
3232
struct Z;
3333

34+
fn inner_block() {
35+
#[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope
36+
//~| WARN cannot find type `OuterDerive` in this scope
37+
//~| WARN this was previously accepted
38+
//~| WARN this was previously accepted
39+
struct InnerZ;
40+
}
41+
3442
#[derive(generate_mod::CheckDeriveLint)] // OK, lint is suppressed
3543
struct W;
3644

src/test/ui-fulldeps/proc-macro/generate-mod.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside
4141
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4242
= note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
4343

44+
warning: cannot find type `FromOutside` in this scope
45+
--> $DIR/generate-mod.rs:35:14
46+
|
47+
LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope
48+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import
49+
|
50+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
51+
= note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
52+
53+
warning: cannot find type `OuterDerive` in this scope
54+
--> $DIR/generate-mod.rs:35:14
55+
|
56+
LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope
57+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import
58+
|
59+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
60+
= note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
61+
4462
error: aborting due to 4 previous errors
4563

4664
For more information about this error, try `rustc --explain E0412`.

src/test/ui/feature-gate-generic_associated_types.rs

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ trait PointerFamily<U> {
1919
}
2020

2121
struct Foo;
22+
2223
impl PointerFamily<u32> for Foo {
2324
type Pointer<usize> = Box<usize>;
2425
//~^ ERROR generic associated types are unstable
@@ -31,5 +32,9 @@ trait Bar {
3132
//~^ ERROR where clauses on associated types are unstable
3233
}
3334

35+
impl Bar for Foo {
36+
type Assoc where Self: Sized = Foo;
37+
//~^ ERROR where clauses on associated types are unstable
38+
}
3439

3540
fn main() {}

src/test/ui/feature-gate-generic_associated_types.stderr

+12-4
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,37 @@ LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
2323
= help: add #![feature(generic_associated_types)] to the crate attributes to enable
2424

2525
error[E0658]: generic associated types are unstable (see issue #44265)
26-
--> $DIR/feature-gate-generic_associated_types.rs:23:5
26+
--> $DIR/feature-gate-generic_associated_types.rs:24:5
2727
|
2828
LL | type Pointer<usize> = Box<usize>;
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3030
|
3131
= help: add #![feature(generic_associated_types)] to the crate attributes to enable
3232

3333
error[E0658]: generic associated types are unstable (see issue #44265)
34-
--> $DIR/feature-gate-generic_associated_types.rs:25:5
34+
--> $DIR/feature-gate-generic_associated_types.rs:26:5
3535
|
3636
LL | type Pointer2<u32> = Box<u32>;
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3838
|
3939
= help: add #![feature(generic_associated_types)] to the crate attributes to enable
4040

4141
error[E0658]: where clauses on associated types are unstable (see issue #44265)
42-
--> $DIR/feature-gate-generic_associated_types.rs:30:5
42+
--> $DIR/feature-gate-generic_associated_types.rs:31:5
4343
|
4444
LL | type Assoc where Self: Sized;
4545
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4646
|
4747
= help: add #![feature(generic_associated_types)] to the crate attributes to enable
4848

49-
error: aborting due to 6 previous errors
49+
error[E0658]: where clauses on associated types are unstable (see issue #44265)
50+
--> $DIR/feature-gate-generic_associated_types.rs:36:5
51+
|
52+
LL | type Assoc where Self: Sized = Foo;
53+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
54+
|
55+
= help: add #![feature(generic_associated_types)] to the crate attributes to enable
56+
57+
error: aborting due to 7 previous errors
5058

5159
For more information about this error, try `rustc --explain E0658`.

src/test/ui/imports/issue-53140.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-pass
12+
13+
mod m {
14+
pub struct S(u8);
15+
16+
use S as Z;
17+
}
18+
19+
use m::*;
20+
21+
fn main() {}

src/test/ui/lint/lints-in-foreign-macros.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
// aux-build:lints-in-foreign-macros.rs
1212
// compile-pass
1313

14-
#![warn(unused_imports)]
14+
#![warn(unused_imports)] //~ missing documentation for crate [missing_docs]
15+
#![warn(missing_docs)]
1516

1617
#[macro_use]
1718
extern crate lints_in_foreign_macros;
@@ -24,5 +25,7 @@ mod a { foo!(); }
2425
mod b { bar!(); }
2526
mod c { baz!(use std::string::ToString;); } //~ WARN: unused import
2627
mod d { baz2!(use std::string::ToString;); } //~ WARN: unused import
28+
baz!(pub fn undocumented() {}); //~ WARN: missing documentation for a function
29+
baz2!(pub fn undocumented2() {}); //~ WARN: missing documentation for a function
2730

2831
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: unused import: `std::string::ToString`
2-
--> $DIR/lints-in-foreign-macros.rs:20:16
2+
--> $DIR/lints-in-foreign-macros.rs:21:16
33
|
44
LL | () => {use std::string::ToString;} //~ WARN: unused import
55
| ^^^^^^^^^^^^^^^^^^^^^
@@ -10,18 +10,48 @@ LL | mod a { foo!(); }
1010
note: lint level defined here
1111
--> $DIR/lints-in-foreign-macros.rs:14:9
1212
|
13-
LL | #![warn(unused_imports)]
13+
LL | #![warn(unused_imports)] //~ missing documentation for crate [missing_docs]
1414
| ^^^^^^^^^^^^^^
1515

1616
warning: unused import: `std::string::ToString`
17-
--> $DIR/lints-in-foreign-macros.rs:25:18
17+
--> $DIR/lints-in-foreign-macros.rs:26:18
1818
|
1919
LL | mod c { baz!(use std::string::ToString;); } //~ WARN: unused import
2020
| ^^^^^^^^^^^^^^^^^^^^^
2121

2222
warning: unused import: `std::string::ToString`
23-
--> $DIR/lints-in-foreign-macros.rs:26:19
23+
--> $DIR/lints-in-foreign-macros.rs:27:19
2424
|
2525
LL | mod d { baz2!(use std::string::ToString;); } //~ WARN: unused import
2626
| ^^^^^^^^^^^^^^^^^^^^^
2727

28+
warning: missing documentation for crate
29+
--> $DIR/lints-in-foreign-macros.rs:14:1
30+
|
31+
LL | / #![warn(unused_imports)] //~ missing documentation for crate [missing_docs]
32+
LL | | #![warn(missing_docs)]
33+
LL | |
34+
LL | | #[macro_use]
35+
... |
36+
LL | |
37+
LL | | fn main() {}
38+
| |____________^
39+
|
40+
note: lint level defined here
41+
--> $DIR/lints-in-foreign-macros.rs:15:9
42+
|
43+
LL | #![warn(missing_docs)]
44+
| ^^^^^^^^^^^^
45+
46+
warning: missing documentation for a function
47+
--> $DIR/lints-in-foreign-macros.rs:28:6
48+
|
49+
LL | baz!(pub fn undocumented() {}); //~ WARN: missing documentation for a function
50+
| ^^^^^^^^^^^^^^^^^^^^^
51+
52+
warning: missing documentation for a function
53+
--> $DIR/lints-in-foreign-macros.rs:29:7
54+
|
55+
LL | baz2!(pub fn undocumented2() {}); //~ WARN: missing documentation for a function
56+
| ^^^^^^^^^^^^^^^^^^^^^^
57+

0 commit comments

Comments
 (0)