Skip to content

Commit

Permalink
Normalize wording of privacy access labels
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Mar 22, 2020
1 parent 94bbd46 commit 854b78f
Show file tree
Hide file tree
Showing 89 changed files with 370 additions and 332 deletions.
16 changes: 12 additions & 4 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ impl<'a, 'tcx> NamePrivacyVisitor<'a, 'tcx> {
def.variant_descr(),
self.tcx.def_path_str(def.did)
)
.span_label(span, format!("field `{}` is private", field.ident))
.span_label(span, "private field")
.emit();
}
}
Expand Down Expand Up @@ -1180,7 +1180,11 @@ impl<'a, 'tcx> TypePrivacyVisitor<'a, 'tcx> {
fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display) -> bool {
let is_error = !self.item_is_accessible(def_id);
if is_error {
self.tcx.sess.span_err(self.span, &format!("{} `{}` is private", kind, descr));
self.tcx
.sess
.struct_span_err(self.span, &format!("{} `{}` is private", kind, descr))
.span_label(self.span, &format!("private {}", kind))
.emit();
}
is_error
}
Expand Down Expand Up @@ -1313,8 +1317,12 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
hir::QPath::Resolved(_, ref path) => path.to_string(),
hir::QPath::TypeRelative(_, ref segment) => segment.ident.to_string(),
};
let msg = format!("{} `{}` is private", kind.descr(def_id), name);
self.tcx.sess.span_err(span, &msg);
let kind = kind.descr(def_id);
self.tcx
.sess
.struct_span_err(span, &format!("{} `{}` is private", kind, name))
.span_label(span, &format!("private {}", kind))
.emit();
return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ impl<'a> Resolver<'a> {
let descr = get_descr(binding);
let mut err =
struct_span_err!(self.session, ident.span, E0603, "{} `{}` is private", descr, ident);
err.span_label(ident.span, &format!("this {} is private", descr));
err.span_label(ident.span, &format!("private {}", descr));
if let Some(span) = ctor_fields_span {
err.span_label(span, "a constructor is private if any of the fields is private");
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_resolve/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,10 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {

match (res, source) {
(Res::Def(DefKind::Macro(MacroKind::Bang), _), _) => {
err.span_suggestion(
span,
err.span_suggestion_verbose(
span.shrink_to_hi(),
"use `!` to invoke the macro",
format!("{}!", path_str),
"!".to_string(),
Applicability::MaybeIncorrect,
);
if path_str == "try" && span.rust_2015() {
Expand Down
17 changes: 13 additions & 4 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1452,8 +1452,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
.expect("missing associated type");

if !assoc_ty.vis.is_accessible_from(def_scope, tcx) {
let msg = format!("associated type `{}` is private", binding.item_name);
tcx.sess.span_err(binding.span, &msg);
tcx.sess
.struct_span_err(
binding.span,
&format!("associated type `{}` is private", binding.item_name),
)
.span_label(binding.span, "private associated type")
.emit();
}
tcx.check_stability(assoc_ty.def_id, Some(hir_ref_id), binding.span);

Expand Down Expand Up @@ -2316,8 +2321,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {

let kind = DefKind::AssocTy;
if !item.vis.is_accessible_from(def_scope, tcx) {
let msg = format!("{} `{}` is private", kind.descr(item.def_id), assoc_ident);
tcx.sess.span_err(span, &msg);
let kind = kind.descr(item.def_id);
let msg = format!("{} `{}` is private", kind, assoc_ident);
tcx.sess
.struct_span_err(span, &msg)
.span_label(span, &format!("private {}", kind))
.emit();
}
tcx.check_stability(item.def_id, Some(hir_ref_id), span);

Expand Down
4 changes: 3 additions & 1 deletion src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,14 +769,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

MethodError::PrivateMatch(kind, def_id, out_of_scope_traits) => {
let kind = kind.descr(def_id);
let mut err = struct_span_err!(
self.tcx.sess,
span,
E0624,
"{} `{}` is private",
kind.descr(def_id),
kind,
item_name
);
err.span_label(span, &format!("private {}", kind));
self.suggest_valid_traits(&mut err, out_of_scope_traits);
err.emit();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0624]: associated constant `ID` is private
--> $DIR/associated-const-private-impl.rs:13:19
|
LL | assert_eq!(1, bar1::Foo::ID);
| ^^^^^^^^^^^^^
| ^^^^^^^^^^^^^ private associated constant

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/error-codes/E0451.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ error[E0451]: field `b` of struct `bar::Foo` is private
--> $DIR/E0451.rs:14:21
|
LL | let bar::Foo{a, b} = foo;
| ^ field `b` is private
| ^ private field

error[E0451]: field `b` of struct `bar::Foo` is private
--> $DIR/E0451.rs:18:29
|
LL | let f = bar::Foo{ a: 0, b: 0 };
| ^^^^ field `b` is private
| ^^^^ private field

error: aborting due to 2 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0603.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0603]: constant `PRIVATE` is private
--> $DIR/E0603.rs:6:17
|
LL | SomeModule::PRIVATE;
| ^^^^^^^ this constant is private
| ^^^^^^^ private constant
|
note: the constant `PRIVATE` is defined here
--> $DIR/E0603.rs:2:5
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0624.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0624]: associated function `method` is private
--> $DIR/E0624.rs:11:9
|
LL | foo.method();
| ^^^^^^
| ^^^^^^ private associated function

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-festival.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ error[E0603]: constant `FOO` is private
--> $DIR/error-festival.rs:22:10
|
LL | foo::FOO;
| ^^^ this constant is private
| ^^^ private constant
|
note: the constant `FOO` is defined here
--> $DIR/error-festival.rs:7:5
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/explore-issue-38412.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ error[E0624]: associated function `pub_crate` is private
--> $DIR/explore-issue-38412.rs:50:7
|
LL | r.pub_crate();
| ^^^^^^^^^
| ^^^^^^^^^ private associated function

error[E0624]: associated function `pub_mod` is private
--> $DIR/explore-issue-38412.rs:51:7
|
LL | r.pub_mod();
| ^^^^^^^
| ^^^^^^^ private associated function

error[E0624]: associated function `private` is private
--> $DIR/explore-issue-38412.rs:52:7
|
LL | r.private();
| ^^^^^^^
| ^^^^^^^ private associated function

error[E0658]: use of unstable library feature 'unstable_undeclared'
--> $DIR/explore-issue-38412.rs:57:7
Expand All @@ -119,19 +119,19 @@ error[E0624]: associated function `pub_crate` is private
--> $DIR/explore-issue-38412.rs:63:7
|
LL | t.pub_crate();
| ^^^^^^^^^
| ^^^^^^^^^ private associated function

error[E0624]: associated function `pub_mod` is private
--> $DIR/explore-issue-38412.rs:64:7
|
LL | t.pub_mod();
| ^^^^^^^
| ^^^^^^^ private associated function

error[E0624]: associated function `private` is private
--> $DIR/explore-issue-38412.rs:65:7
|
LL | t.private();
| ^^^^^^^
| ^^^^^^^ private associated function

error: aborting due to 19 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/export-import.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0603]: function `unexported` is private
--> $DIR/export-import.rs:1:8
|
LL | use m::unexported;
| ^^^^^^^^^^ this function is private
| ^^^^^^^^^^ private function
|
note: the function `unexported` is defined here
--> $DIR/export-import.rs:7:5
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/export-tag-variant.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0603]: enum `Y` is private
--> $DIR/export-tag-variant.rs:7:26
|
LL | fn main() { let z = foo::Y::Y1; }
| ^ this enum is private
| ^ private enum
|
note: the enum `Y` is defined here
--> $DIR/export-tag-variant.rs:4:5
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/export.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ error[E0603]: function `z` is private
--> $DIR/export.rs:10:18
|
LL | fn main() { foo::z(10); }
| ^ this function is private
| ^ private function
|
note: the function `z` is defined here
--> $DIR/export.rs:5:5
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/extern/extern-crate-visibility.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0603]: crate import `core` is private
--> $DIR/extern-crate-visibility.rs:6:10
|
LL | use foo::core::cell;
| ^^^^ this crate import is private
| ^^^^ private crate import
|
note: the crate import `core` is defined here
--> $DIR/extern-crate-visibility.rs:2:5
Expand All @@ -14,7 +14,7 @@ error[E0603]: crate import `core` is private
--> $DIR/extern-crate-visibility.rs:9:10
|
LL | foo::core::cell::Cell::new(0);
| ^^^^ this crate import is private
| ^^^^ private crate import
|
note: the crate import `core` is defined here
--> $DIR/extern-crate-visibility.rs:2:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0451]: field `secret_uid` of struct `foo::S` is private
--> $DIR/functional-struct-update-respects-privacy.rs:28:49
|
LL | let s_2 = foo::S { b: format!("ess two"), ..s_1 }; // FRU ...
| ^^^ field `secret_uid` is private
| ^^^ private field

error: aborting due to previous error

Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/hygiene/fields.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: type `foo::S` is private
--> $DIR/fields.rs:15:17
|
LL | let s = S { x: 0 };
| ^^^^^^^^^^
| ^^^^^^^^^^ private type
...
LL | let s = foo::m!(S, x);
| ------------- in this macro invocation
Expand All @@ -13,7 +13,7 @@ error: type `foo::S` is private
--> $DIR/fields.rs:16:17
|
LL | let _ = s.x;
| ^
| ^ private type
...
LL | let s = foo::m!(S, x);
| ------------- in this macro invocation
Expand All @@ -24,7 +24,7 @@ error: type `foo::T` is private
--> $DIR/fields.rs:18:17
|
LL | let t = T(0);
| ^^^^
| ^^^^ private type
...
LL | let s = foo::m!(S, x);
| ------------- in this macro invocation
Expand All @@ -35,7 +35,7 @@ error: type `foo::T` is private
--> $DIR/fields.rs:19:17
|
LL | let _ = t.0;
| ^
| ^ private type
...
LL | let s = foo::m!(S, x);
| ------------- in this macro invocation
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/hygiene/impl_items.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: type `for<'r> fn(&'r foo::S) {foo::S::f}` is private
--> $DIR/impl_items.rs:12:23
|
LL | let _: () = S.f();
| ^
| ^ private type
...
LL | foo::m!();
| ---------- in this macro invocation
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/hygiene/intercrate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error: type `fn() -> u32 {intercrate::foo::bar::f}` is private
--> $DIR/intercrate.rs:10:16
|
LL | assert_eq!(intercrate::foo::m!(), 1);
| ^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^^^^ private type
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/hygiene/privacy.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0603]: function `f` is private
--> $DIR/privacy.rs:16:14
|
LL | foo::f()
| ^ this function is private
| ^ private function
|
note: the function `f` is defined here
--> $DIR/privacy.rs:4:5
Expand Down
14 changes: 12 additions & 2 deletions src/test/ui/hygiene/rustc-macro-transparency.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@ error[E0423]: expected value, found macro `semitransparent`
--> $DIR/rustc-macro-transparency.rs:29:5
|
LL | semitransparent;
| ^^^^^^^^^^^^^^^ help: use `!` to invoke the macro: `semitransparent!`
| ^^^^^^^^^^^^^^^
|
help: use `!` to invoke the macro
|
LL | semitransparent!;
| ^

error[E0423]: expected value, found macro `opaque`
--> $DIR/rustc-macro-transparency.rs:30:5
|
LL | opaque;
| ^^^^^^ help: use `!` to invoke the macro: `opaque!`
| ^^^^^^
|
help: use `!` to invoke the macro
|
LL | opaque!;
| ^

error: aborting due to 3 previous errors

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/import.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ error[E0603]: unresolved item import `foo` is private
--> $DIR/import.rs:15:10
|
LL | zed::foo();
| ^^^ this unresolved item import is private
| ^^^ private unresolved item import
|
note: the unresolved item import `foo` is defined here
--> $DIR/import.rs:10:9
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/imports/issue-55884-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0603]: struct import `ParseOptions` is private
--> $DIR/issue-55884-2.rs:12:17
|
LL | pub use parser::ParseOptions;
| ^^^^^^^^^^^^ this struct import is private
| ^^^^^^^^^^^^ private struct import
|
note: the struct import `ParseOptions` is defined here...
--> $DIR/issue-55884-2.rs:9:9
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/imports/reexports.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ error[E0603]: module import `foo` is private
--> $DIR/reexports.rs:33:15
|
LL | use b::a::foo::S;
| ^^^ this module import is private
| ^^^ private module import
|
note: the module import `foo` is defined here...
--> $DIR/reexports.rs:21:17
Expand All @@ -31,7 +31,7 @@ error[E0603]: module import `foo` is private
--> $DIR/reexports.rs:34:15
|
LL | use b::b::foo::S as T;
| ^^^ this module import is private
| ^^^ private module import
|
note: the module import `foo` is defined here...
--> $DIR/reexports.rs:26:17
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/imports/unresolved-imports-used.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ error[E0603]: function `quz` is private
--> $DIR/unresolved-imports-used.rs:9:10
|
LL | use qux::quz;
| ^^^ this function is private
| ^^^ private function
|
note: the function `quz` is defined here
--> $DIR/unresolved-imports-used.rs:5:4
Expand Down
Loading

0 comments on commit 854b78f

Please sign in to comment.