Skip to content

Commit 19996d4

Browse files
committed
The source_did may not be local, so don't unwrap the
`as_local_node_id`, instead just compare against `Some(id)`. Fixes #29161.
1 parent d0a84e0 commit 19996d4

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/librustc_privacy/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ impl<'a, 'tcx> PrivacyVisitor<'a, 'tcx> {
671671
// ancestry. (Both the item being checked and its parent must
672672
// be local.)
673673
let def_id = source_did.unwrap_or(to_check);
674-
let node_id = self.tcx.map.as_local_node_id(def_id).unwrap();
675-
let (err_span, err_msg) = if id == node_id {
674+
let node_id = self.tcx.map.as_local_node_id(def_id);
675+
let (err_span, err_msg) = if Some(id) == node_id {
676676
return Some((span, format!("{} is private", msg), None));
677677
} else {
678678
(span, format!("{} is inaccessible", msg))

src/test/compile-fail/issue-29161.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2015 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+
mod a {
12+
struct A;
13+
14+
impl Default for A {
15+
pub fn default() -> A {
16+
//~^ ERROR E0449
17+
A;
18+
}
19+
}
20+
}
21+
22+
23+
fn main() {
24+
a::A::default();
25+
//~^ ERROR method `default` is inaccessible
26+
}

0 commit comments

Comments
 (0)