Skip to content

Commit 854b78f

Browse files
committed
Normalize wording of privacy access labels
1 parent 94bbd46 commit 854b78f

File tree

89 files changed

+370
-332
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+370
-332
lines changed

src/librustc_privacy/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,7 @@ impl<'a, 'tcx> NamePrivacyVisitor<'a, 'tcx> {
10381038
def.variant_descr(),
10391039
self.tcx.def_path_str(def.did)
10401040
)
1041-
.span_label(span, format!("field `{}` is private", field.ident))
1041+
.span_label(span, "private field")
10421042
.emit();
10431043
}
10441044
}
@@ -1180,7 +1180,11 @@ impl<'a, 'tcx> TypePrivacyVisitor<'a, 'tcx> {
11801180
fn check_def_id(&mut self, def_id: DefId, kind: &str, descr: &dyn fmt::Display) -> bool {
11811181
let is_error = !self.item_is_accessible(def_id);
11821182
if is_error {
1183-
self.tcx.sess.span_err(self.span, &format!("{} `{}` is private", kind, descr));
1183+
self.tcx
1184+
.sess
1185+
.struct_span_err(self.span, &format!("{} `{}` is private", kind, descr))
1186+
.span_label(self.span, &format!("private {}", kind))
1187+
.emit();
11841188
}
11851189
is_error
11861190
}
@@ -1313,8 +1317,12 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
13131317
hir::QPath::Resolved(_, ref path) => path.to_string(),
13141318
hir::QPath::TypeRelative(_, ref segment) => segment.ident.to_string(),
13151319
};
1316-
let msg = format!("{} `{}` is private", kind.descr(def_id), name);
1317-
self.tcx.sess.span_err(span, &msg);
1320+
let kind = kind.descr(def_id);
1321+
self.tcx
1322+
.sess
1323+
.struct_span_err(span, &format!("{} `{}` is private", kind, name))
1324+
.span_label(span, &format!("private {}", kind))
1325+
.emit();
13181326
return;
13191327
}
13201328
}

src/librustc_resolve/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ impl<'a> Resolver<'a> {
952952
let descr = get_descr(binding);
953953
let mut err =
954954
struct_span_err!(self.session, ident.span, E0603, "{} `{}` is private", descr, ident);
955-
err.span_label(ident.span, &format!("this {} is private", descr));
955+
err.span_label(ident.span, &format!("private {}", descr));
956956
if let Some(span) = ctor_fields_span {
957957
err.span_label(span, "a constructor is private if any of the fields is private");
958958
}

src/librustc_resolve/late/diagnostics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,10 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
506506

507507
match (res, source) {
508508
(Res::Def(DefKind::Macro(MacroKind::Bang), _), _) => {
509-
err.span_suggestion(
510-
span,
509+
err.span_suggestion_verbose(
510+
span.shrink_to_hi(),
511511
"use `!` to invoke the macro",
512-
format!("{}!", path_str),
512+
"!".to_string(),
513513
Applicability::MaybeIncorrect,
514514
);
515515
if path_str == "try" && span.rust_2015() {

src/librustc_typeck/astconv.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,8 +1452,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
14521452
.expect("missing associated type");
14531453

14541454
if !assoc_ty.vis.is_accessible_from(def_scope, tcx) {
1455-
let msg = format!("associated type `{}` is private", binding.item_name);
1456-
tcx.sess.span_err(binding.span, &msg);
1455+
tcx.sess
1456+
.struct_span_err(
1457+
binding.span,
1458+
&format!("associated type `{}` is private", binding.item_name),
1459+
)
1460+
.span_label(binding.span, "private associated type")
1461+
.emit();
14571462
}
14581463
tcx.check_stability(assoc_ty.def_id, Some(hir_ref_id), binding.span);
14591464

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

23172322
let kind = DefKind::AssocTy;
23182323
if !item.vis.is_accessible_from(def_scope, tcx) {
2319-
let msg = format!("{} `{}` is private", kind.descr(item.def_id), assoc_ident);
2320-
tcx.sess.span_err(span, &msg);
2324+
let kind = kind.descr(item.def_id);
2325+
let msg = format!("{} `{}` is private", kind, assoc_ident);
2326+
tcx.sess
2327+
.struct_span_err(span, &msg)
2328+
.span_label(span, &format!("private {}", kind))
2329+
.emit();
23212330
}
23222331
tcx.check_stability(item.def_id, Some(hir_ref_id), span);
23232332

src/librustc_typeck/check/method/suggest.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,14 +769,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
769769
}
770770

771771
MethodError::PrivateMatch(kind, def_id, out_of_scope_traits) => {
772+
let kind = kind.descr(def_id);
772773
let mut err = struct_span_err!(
773774
self.tcx.sess,
774775
span,
775776
E0624,
776777
"{} `{}` is private",
777-
kind.descr(def_id),
778+
kind,
778779
item_name
779780
);
781+
err.span_label(span, &format!("private {}", kind));
780782
self.suggest_valid_traits(&mut err, out_of_scope_traits);
781783
err.emit();
782784
}

src/test/ui/associated-const/associated-const-private-impl.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0624]: associated constant `ID` is private
22
--> $DIR/associated-const-private-impl.rs:13:19
33
|
44
LL | assert_eq!(1, bar1::Foo::ID);
5-
| ^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^ private associated constant
66

77
error: aborting due to previous error
88

src/test/ui/error-codes/E0451.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ error[E0451]: field `b` of struct `bar::Foo` is private
22
--> $DIR/E0451.rs:14:21
33
|
44
LL | let bar::Foo{a, b} = foo;
5-
| ^ field `b` is private
5+
| ^ private field
66

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

1313
error: aborting due to 2 previous errors
1414

src/test/ui/error-codes/E0603.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0603]: constant `PRIVATE` is private
22
--> $DIR/E0603.rs:6:17
33
|
44
LL | SomeModule::PRIVATE;
5-
| ^^^^^^^ this constant is private
5+
| ^^^^^^^ private constant
66
|
77
note: the constant `PRIVATE` is defined here
88
--> $DIR/E0603.rs:2:5

src/test/ui/error-codes/E0624.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0624]: associated function `method` is private
22
--> $DIR/E0624.rs:11:9
33
|
44
LL | foo.method();
5-
| ^^^^^^
5+
| ^^^^^^ private associated function
66

77
error: aborting due to previous error
88

src/test/ui/error-festival.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error[E0603]: constant `FOO` is private
88
--> $DIR/error-festival.rs:22:10
99
|
1010
LL | foo::FOO;
11-
| ^^^ this constant is private
11+
| ^^^ private constant
1212
|
1313
note: the constant `FOO` is defined here
1414
--> $DIR/error-festival.rs:7:5

0 commit comments

Comments
 (0)