Skip to content

Commit e117b47

Browse files
committed
Catch errors for any new item, not just trait implementations
This matches the previous behavior of everybody_loops and is also more consistent than special-casing impls.
1 parent 6eec9fb commit e117b47

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/librustc_resolve/late.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,10 @@ struct LateResolutionVisitor<'a, 'b, 'ast> {
407407
impl<'a, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
408408
fn visit_item(&mut self, item: &'ast Item) {
409409
let prev = replace(&mut self.diagnostic_metadata.current_item, Some(item));
410+
// Always report errors in items we just entered.
411+
let old_ignore = replace(&mut self.in_func_body, false);
410412
self.resolve_item(item);
413+
self.in_func_body = old_ignore;
411414
self.diagnostic_metadata.current_item = prev;
412415
}
413416
fn visit_arm(&mut self, arm: &'ast Arm) {
@@ -1174,8 +1177,6 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
11741177
impl_items: &'ast [P<AssocItem>],
11751178
) {
11761179
debug!("resolve_implementation");
1177-
// Never ignore errors in trait implementations.
1178-
let old_ignore = replace(&mut self.in_func_body, false);
11791180
// If applicable, create a rib for the type parameters.
11801181
self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| {
11811182
// Dummy self type for better errors if `Self` is used in the trait path.
@@ -1271,7 +1272,6 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
12711272
});
12721273
});
12731274
});
1274-
self.in_func_body = old_ignore;
12751275
}
12761276

12771277
fn check_trait_item<F>(&mut self, ident: Ident, ns: Namespace, span: Span, err: F)

src/test/rustdoc-ui/impl-fn-nesting.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ pub fn f<B: UnknownBound>(a: UnknownType, b: B) {
4141
can_define_macros_here_too!();
4242

4343
/// This also is documented.
44-
pub fn doubly_nested(c: UnknownTypeShouldBeIgnored) {
45-
44+
pub fn doubly_nested(c: UnknownType) {
45+
//~^ ERROR cannot find type `UnknownType` in this scope
4646
}
4747
}
4848
}

src/test/rustdoc-ui/impl-fn-nesting.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,15 @@ error[E0412]: cannot find type `UnknownType` in this scope
5252
LL | type Item = UnknownType;
5353
| ^^^^^^^^^^^ not found in this scope
5454

55+
error[E0412]: cannot find type `UnknownType` in this scope
56+
--> $DIR/impl-fn-nesting.rs:44:37
57+
|
58+
LL | pub fn doubly_nested(c: UnknownType) {
59+
| ^^^^^^^^^^^ not found in this scope
60+
5561
error: Compilation failed, aborting rustdoc
5662

57-
error: aborting due to 10 previous errors
63+
error: aborting due to 11 previous errors
5864

5965
Some errors have detailed explanations: E0405, E0412.
6066
For more information about an error, try `rustc --explain E0405`.

0 commit comments

Comments
 (0)