Skip to content

Commit

Permalink
Fix one instance of rustfmt refusing to work with a lengthy string li…
Browse files Browse the repository at this point in the history
…teral, and change "`unsafe` fn" to "`unsafe fn`"
  • Loading branch information
steffahn committed Feb 6, 2022
1 parent 9411232 commit 3cecf81
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 41 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ pub enum UnusedUnsafe {
// `unsafe` block nested under another (used) `unsafe` block
// ``… because it's nested under this `unsafe` block``
InUnsafeBlock(hir::HirId),
// `unsafe` block nested under `unsafe` fn
// ``… because it's nested under this `unsafe` fn``
// `unsafe` block nested under `unsafe fn`
// ``… because it's nested under this `unsafe fn` ``
//
// the second HirId here indicates the first usage of the `unsafe` block,
// which allows retrival of the LintLevelSource for why that operation would
Expand Down
16 changes: 13 additions & 3 deletions compiler/rustc_mir_transform/src/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,21 @@ fn report_unused_unsafe(tcx: TyCtxt<'_>, kind: UnusedUnsafe, id: HirId) {
db.span_label(
tcx.sess.source_map().guess_head_span(tcx.hir().span(id)),
format!("because it's nested under this `unsafe` fn"),
)
.note(
"this `unsafe` block does contain unsafe operations, \
but those are already allowed in an `unsafe fn`",
);
db.note("this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn");
let (level, source) = tcx.lint_level_at_node(UNSAFE_OP_IN_UNSAFE_FN, usage_lint_root);
let (level, source) =
tcx.lint_level_at_node(UNSAFE_OP_IN_UNSAFE_FN, usage_lint_root);
assert_eq!(level, Level::Allow);
lint::explain_lint_level_source(tcx.sess, UNSAFE_OP_IN_UNSAFE_FN, Level::Allow, source, &mut db);
lint::explain_lint_level_source(
tcx.sess,
UNSAFE_OP_IN_UNSAFE_FN,
Level::Allow,
source,
&mut db,
);
}
}

Expand Down
68 changes: 34 additions & 34 deletions src/test/ui/span/lint-unused-unsafe.mir.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ LL | unsafe fn bad5() { unsafe { unsf() } }
| |
| because it's nested under this `unsafe` fn
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`
= note: `#[allow(unsafe_op_in_unsafe_fn)]` on by default

error: unnecessary `unsafe` block
Expand All @@ -60,7 +60,7 @@ LL | unsafe {
LL | unsafe {
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:71:9
Expand Down Expand Up @@ -281,7 +281,7 @@ LL | unsafe {
LL | unsafe { unsf() }
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`
note: the lint level is defined here
--> $DIR/lint-unused-unsafe.rs:191:13
|
Expand All @@ -297,7 +297,7 @@ LL | unsafe fn granularity_2() {
LL | unsafe { unsf() }
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:196:13
Expand All @@ -308,7 +308,7 @@ LL | unsafe fn granularity_2() {
LL | unsafe { unsf() }
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:202:9
Expand All @@ -318,7 +318,7 @@ LL | unsafe fn top_level_used_2() {
LL | unsafe {
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`
note: the lint level is defined here
--> $DIR/lint-unused-unsafe.rs:200:13
|
Expand All @@ -334,7 +334,7 @@ LL | unsafe fn top_level_used_2() {
LL | unsafe { unsf() }
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:205:13
Expand All @@ -345,7 +345,7 @@ LL | unsafe fn top_level_used_2() {
LL | unsafe { unsf() }
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:206:13
Expand All @@ -356,7 +356,7 @@ LL | unsafe fn top_level_used_2() {
LL | unsafe { unsf() }
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:217:17
Expand Down Expand Up @@ -405,7 +405,7 @@ LL | unsafe fn granular_disallow_op_in_unsafe_fn_3() {
LL | unsafe {
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`
note: the lint level is defined here
--> $DIR/lint-unused-unsafe.rs:249:13
|
Expand Down Expand Up @@ -639,7 +639,7 @@ LL | let _ = || unsafe {
LL | let _ = || unsafe { unsf() };
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`
note: the lint level is defined here
--> $DIR/lint-unused-unsafe.rs:403:13
|
Expand All @@ -655,7 +655,7 @@ LL | unsafe fn granularity_2() {
LL | let _ = || unsafe { unsf() };
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:408:24
Expand All @@ -666,7 +666,7 @@ LL | unsafe fn granularity_2() {
LL | let _ = || unsafe { unsf() };
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:414:20
Expand All @@ -676,7 +676,7 @@ LL | unsafe fn top_level_used_2() {
LL | let _ = || unsafe {
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`
note: the lint level is defined here
--> $DIR/lint-unused-unsafe.rs:412:13
|
Expand All @@ -692,7 +692,7 @@ LL | unsafe fn top_level_used_2() {
LL | let _ = || unsafe { unsf() };
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:417:24
Expand All @@ -703,7 +703,7 @@ LL | unsafe fn top_level_used_2() {
LL | let _ = || unsafe { unsf() };
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:418:24
Expand All @@ -714,7 +714,7 @@ LL | unsafe fn top_level_used_2() {
LL | let _ = || unsafe { unsf() };
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:429:28
Expand Down Expand Up @@ -763,7 +763,7 @@ LL | unsafe fn granular_disallow_op_in_unsafe_fn_3() {
LL | let _ = || unsafe {
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`
note: the lint level is defined here
--> $DIR/lint-unused-unsafe.rs:461:13
|
Expand Down Expand Up @@ -997,7 +997,7 @@ LL | let _ = || unsafe {
LL | let _ = || unsafe { let _ = || unsf(); };
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`
note: the lint level is defined here
--> $DIR/lint-unused-unsafe.rs:616:13
|
Expand All @@ -1013,7 +1013,7 @@ LL | unsafe fn granularity_2() {
LL | let _ = || unsafe { let _ = || unsf(); };
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:621:24
Expand All @@ -1024,7 +1024,7 @@ LL | unsafe fn granularity_2() {
LL | let _ = || unsafe { let _ = || unsf(); };
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:627:20
Expand All @@ -1034,7 +1034,7 @@ LL | unsafe fn top_level_used_2() {
LL | let _ = || unsafe {
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`
note: the lint level is defined here
--> $DIR/lint-unused-unsafe.rs:625:13
|
Expand All @@ -1050,7 +1050,7 @@ LL | unsafe fn top_level_used_2() {
LL | let _ = || unsafe { let _ = || unsf(); };
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:630:24
Expand All @@ -1061,7 +1061,7 @@ LL | unsafe fn top_level_used_2() {
LL | let _ = || unsafe { let _ = || unsf(); };
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:631:24
Expand All @@ -1072,7 +1072,7 @@ LL | unsafe fn top_level_used_2() {
LL | let _ = || unsafe { let _ = || unsf(); };
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:642:28
Expand Down Expand Up @@ -1121,7 +1121,7 @@ LL | unsafe fn granular_disallow_op_in_unsafe_fn_3() {
LL | let _ = || unsafe {
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`
note: the lint level is defined here
--> $DIR/lint-unused-unsafe.rs:674:13
|
Expand All @@ -1144,7 +1144,7 @@ LL | unsafe fn multiple_unsafe_op_in_unsafe_fn_allows() {
LL | unsafe {
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`
note: the lint level is defined here
--> $DIR/lint-unused-unsafe.rs:721:21
|
Expand Down Expand Up @@ -1199,7 +1199,7 @@ LL | async unsafe fn async_blocks() {
LL | let _ = async { unsafe { let _ = async { unsf() }; }};
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`
note: the lint level is defined here
--> $DIR/lint-unused-unsafe.rs:747:17
|
Expand All @@ -1215,7 +1215,7 @@ LL | async unsafe fn async_blocks() {
LL | let _ = async { unsafe { let _ = async { unsf() }; }};
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:752:33
Expand All @@ -1226,7 +1226,7 @@ LL | async unsafe fn async_blocks() {
LL | let _ = async { unsafe { let _ = async { unsf() }; }};
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:754:29
Expand All @@ -1237,7 +1237,7 @@ LL | async unsafe fn async_blocks() {
LL | let _ = async { unsafe {
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:756:33
Expand All @@ -1248,7 +1248,7 @@ LL | async unsafe fn async_blocks() {
LL | let _ = async { unsafe { let _ = async { unsf() }; }};
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:757:33
Expand All @@ -1259,7 +1259,7 @@ LL | async unsafe fn async_blocks() {
LL | let _ = async { unsafe { let _ = async { unsf() }; }};
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:758:33
Expand All @@ -1270,7 +1270,7 @@ LL | async unsafe fn async_blocks() {
LL | let _ = async { unsafe { let _ = async { unsf() }; }};
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`

error: unnecessary `unsafe` block
--> $DIR/lint-unused-unsafe.rs:768:22
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/unsafe/rfc-2585-unsafe_op_in_unsafe_fn.mir.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ LL | unsafe fn allow_level() {
LL | unsafe { unsf() }
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`
note: the lint level is defined here
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:51:9
|
Expand All @@ -106,7 +106,7 @@ LL | unsafe fn nested_allow_level() {
LL | unsafe { unsf() }
| ^^^^^^ unnecessary `unsafe` block
|
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe` fn
= note: this `unsafe` block does contain unsafe operations, but those are already allowed in an `unsafe fn`
note: the lint level is defined here
--> $DIR/rfc-2585-unsafe_op_in_unsafe_fn.rs:63:13
|
Expand Down

0 comments on commit 3cecf81

Please sign in to comment.