Skip to content

Commit 22ca74f

Browse files
committed
Fix up comments.
Wrap overly long ones, etc.
1 parent a6416d8 commit 22ca74f

File tree

10 files changed

+69
-51
lines changed

10 files changed

+69
-51
lines changed

compiler/rustc_lint/src/builtin.rs

+26-16
Original file line numberDiff line numberDiff line change
@@ -1494,8 +1494,9 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
14941494

14951495
let ty = cx.tcx.type_of(item.owner_id).skip_binder();
14961496
if ty.has_inherent_projections() {
1497-
// Bounds of type aliases that contain opaque types or inherent projections are respected.
1498-
// E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`, `type X = Type::Inherent;`.
1497+
// Bounds of type aliases that contain opaque types or inherent projections are
1498+
// respected. E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`, `type X =
1499+
// Type::Inherent;`.
14991500
return;
15001501
}
15011502

@@ -2224,7 +2225,8 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
22242225
hir_generics.span.shrink_to_hi().to(where_span)
22252226
};
22262227

2227-
// Due to macro expansions, the `full_where_span` might not actually contain all predicates.
2228+
// Due to macro expansions, the `full_where_span` might not actually contain all
2229+
// predicates.
22282230
if where_lint_spans.iter().all(|&sp| full_where_span.contains(sp)) {
22292231
lint_spans.push(full_where_span);
22302232
} else {
@@ -2601,7 +2603,8 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
26012603
};
26022604
// So we have at least one potentially inhabited variant. Might we have two?
26032605
let Some(second_variant) = potential_variants.next() else {
2604-
// There is only one potentially inhabited variant. So we can recursively check that variant!
2606+
// There is only one potentially inhabited variant. So we can recursively
2607+
// check that variant!
26052608
return variant_find_init_error(
26062609
cx,
26072610
ty,
@@ -2611,10 +2614,10 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
26112614
init,
26122615
);
26132616
};
2614-
// So we have at least two potentially inhabited variants.
2615-
// If we can prove that we have at least two *definitely* inhabited variants,
2616-
// then we have a tag and hence leaving this uninit is definitely disallowed.
2617-
// (Leaving it zeroed could be okay, depending on which variant is encoded as zero tag.)
2617+
// So we have at least two potentially inhabited variants. If we can prove that
2618+
// we have at least two *definitely* inhabited variants, then we have a tag and
2619+
// hence leaving this uninit is definitely disallowed. (Leaving it zeroed could
2620+
// be okay, depending on which variant is encoded as zero tag.)
26182621
if init == InitKind::Uninit {
26192622
let definitely_inhabited = (first_variant.1 as usize)
26202623
+ (second_variant.1 as usize)
@@ -2825,7 +2828,8 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
28252828

28262829
let mut found_labels = Vec::new();
28272830

2828-
// A semicolon might not actually be specified as a separator for all targets, but it seems like LLVM accepts it always
2831+
// A semicolon might not actually be specified as a separator for all targets, but
2832+
// it seems like LLVM accepts it always.
28292833
let statements = template_str.split(|c| matches!(c, '\n' | ';'));
28302834
for statement in statements {
28312835
// If there's a comment, trim it from the statement
@@ -2838,7 +2842,8 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
28382842
let mut chars = possible_label.chars();
28392843

28402844
let Some(start) = chars.next() else {
2841-
// Empty string means a leading ':' in this section, which is not a label.
2845+
// Empty string means a leading ':' in this section, which is not a
2846+
// label.
28422847
break 'label_loop;
28432848
};
28442849

@@ -2855,12 +2860,15 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
28552860

28562861
// Labels continue with ASCII alphanumeric characters, _, or $
28572862
for c in chars {
2858-
// Inside a template format arg, any character is permitted for the puproses of label detection
2859-
// because we assume that it can be replaced with some other valid label string later.
2860-
// `options(raw)` asm blocks cannot have format args, so they are excluded from this special case.
2863+
// Inside a template format arg, any character is permitted for the
2864+
// puproses of label detection because we assume that it can be
2865+
// replaced with some other valid label string later. `options(raw)`
2866+
// asm blocks cannot have format args, so they are excluded from this
2867+
// special case.
28612868
if !raw && in_bracket {
28622869
if c == '{' {
2863-
// Nested brackets are not allowed in format args, this cannot be a label.
2870+
// Nested brackets are not allowed in format args, this cannot
2871+
// be a label.
28642872
break 'label_loop;
28652873
}
28662874

@@ -2873,7 +2881,8 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
28732881
in_bracket = true;
28742882
} else {
28752883
if !(c.is_ascii_alphanumeric() || matches!(c, '_' | '$')) {
2876-
// The potential label had an invalid character inside it, it cannot be a label.
2884+
// The potential label had an invalid character inside it, it
2885+
// cannot be a label.
28772886
break 'label_loop;
28782887
}
28792888
}
@@ -2892,7 +2901,8 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
28922901
.into_iter()
28932902
.filter_map(|label| find_label_span(label))
28942903
.collect::<Vec<Span>>();
2895-
// If there were labels but we couldn't find a span, combine the warnings and use the template span
2904+
// If there were labels but we couldn't find a span, combine the warnings and
2905+
// use the template span.
28962906
let target_spans: MultiSpan =
28972907
if spans.len() > 0 { spans.into() } else { (*template_span).into() };
28982908

compiler/rustc_lint/src/context.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ enum TargetLint {
9494

9595
/// A lint name that should give no warnings and have no effect.
9696
///
97-
/// This is used by rustc to avoid warning about old rustdoc lints before rustdoc registers them as tool lints.
97+
/// This is used by rustc to avoid warning about old rustdoc lints before rustdoc registers
98+
/// them as tool lints.
9899
Ignored,
99100
}
100101

compiler/rustc_lint/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct OverruledAttribute<'a> {
1616
#[subdiagnostic]
1717
pub sub: OverruledAttributeSub,
1818
}
19-
//
19+
2020
pub enum OverruledAttributeSub {
2121
DefaultSource { id: String },
2222
NodeSource { span: Span, reason: Option<Symbol> },

compiler/rustc_lint/src/internal.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ use rustc_span::Span;
1818
use tracing::debug;
1919

2020
declare_tool_lint! {
21-
/// The `default_hash_type` lint detects use of [`std::collections::HashMap`]/[`std::collections::HashSet`],
22-
/// suggesting the use of `FxHashMap`/`FxHashSet`.
21+
/// The `default_hash_type` lint detects use of [`std::collections::HashMap`] and
22+
/// [`std::collections::HashSet`], suggesting the use of `FxHashMap`/`FxHashSet`.
2323
///
24-
/// This can help as `FxHasher` can perform better than the default hasher. DOS protection is not
25-
/// required as input is assumed to be trusted.
24+
/// This can help as `FxHasher` can perform better than the default hasher. DOS protection is
25+
/// not required as input is assumed to be trusted.
2626
pub rustc::DEFAULT_HASH_TYPES,
2727
Allow,
2828
"forbid HashMap and HashSet and suggest the FxHash* variants",
@@ -35,7 +35,7 @@ impl LateLintPass<'_> for DefaultHashTypes {
3535
fn check_path(&mut self, cx: &LateContext<'_>, path: &Path<'_>, hir_id: HirId) {
3636
let Res::Def(rustc_hir::def::DefKind::Struct, def_id) = path.res else { return };
3737
if matches!(cx.tcx.hir_node(hir_id), Node::Item(Item { kind: ItemKind::Use(..), .. })) {
38-
// don't lint imports, only actual usages
38+
// Don't lint imports, only actual usages.
3939
return;
4040
}
4141
let preferred = match cx.tcx.get_diagnostic_name(def_id) {
@@ -75,8 +75,8 @@ declare_tool_lint! {
7575
/// potential query instability, such as iterating over a `HashMap`.
7676
///
7777
/// Due to the [incremental compilation](https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html) model,
78-
/// queries must return deterministic, stable results. `HashMap` iteration order can change between compilations,
79-
/// and will introduce instability if query results expose the order.
78+
/// queries must return deterministic, stable results. `HashMap` iteration order can change
79+
/// between compilations, and will introduce instability if query results expose the order.
8080
pub rustc::POTENTIAL_QUERY_INSTABILITY,
8181
Allow,
8282
"require explicit opt-in when using potentially unstable methods or functions",

compiler/rustc_lint/src/let_underscore.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
113113

114114
let mut top_level = true;
115115

116-
// We recursively walk through all patterns, so that we can catch cases where the lock is nested in a pattern.
117-
// For the basic `let_underscore_drop` lint, we only look at the top level, since there are many legitimate reasons
118-
// to bind a sub-pattern to an `_`, if we're only interested in the rest.
119-
// But with locks, we prefer having the chance of "false positives" over missing cases, since the effects can be
120-
// quite catastrophic.
116+
// We recursively walk through all patterns, so that we can catch cases where the lock is
117+
// nested in a pattern. For the basic `let_underscore_drop` lint, we only look at the top
118+
// level, since there are many legitimate reasons to bind a sub-pattern to an `_`, if we're
119+
// only interested in the rest. But with locks, we prefer having the chance of "false
120+
// positives" over missing cases, since the effects can be quite catastrophic.
121121
local.pat.walk_always(|pat| {
122122
let is_top_level = top_level;
123123
top_level = false;

compiler/rustc_lint/src/levels.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,8 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
750750

751751
let level = match Level::from_attr(attr) {
752752
None => continue,
753-
// This is the only lint level with a `LintExpectationId` that can be created from an attribute
753+
// This is the only lint level with a `LintExpectationId` that can be created from
754+
// an attribute.
754755
Some(Level::Expect(unstable_id)) if let Some(hir_id) = source_hir_id => {
755756
let LintExpectationId::Unstable { attr_id, lint_index } = unstable_id else {
756757
bug!("stable id Level::from_attr")
@@ -760,8 +761,8 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
760761
hir_id,
761762
attr_index: attr_index.try_into().unwrap(),
762763
lint_index,
763-
// we pass the previous unstable attr_id such that we can trace the ast id when building a map
764-
// to go from unstable to stable id.
764+
// We pass the previous unstable attr_id such that we can trace the ast id
765+
// when building a map to go from unstable to stable id.
765766
attr_id: Some(attr_id),
766767
};
767768

@@ -860,13 +861,15 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
860861
self.store.check_lint_name(&name, tool_name, self.registered_tools);
861862
match &lint_result {
862863
CheckLintNameResult::Ok(ids) => {
863-
// This checks for instances where the user writes `#[expect(unfulfilled_lint_expectations)]`
864-
// in that case we want to avoid overriding the lint level but instead add an expectation that
865-
// can't be fulfilled. The lint message will include an explanation, that the
864+
// This checks for instances where the user writes
865+
// `#[expect(unfulfilled_lint_expectations)]` in that case we want to avoid
866+
// overriding the lint level but instead add an expectation that can't be
867+
// fulfilled. The lint message will include an explanation, that the
866868
// `unfulfilled_lint_expectations` lint can't be expected.
867869
if let Level::Expect(expect_id) = level {
868-
// The `unfulfilled_lint_expectations` lint is not part of any lint groups. Therefore. we
869-
// only need to check the slice if it contains a single lint.
870+
// The `unfulfilled_lint_expectations` lint is not part of any lint
871+
// groups. Therefore. we only need to check the slice if it contains a
872+
// single lint.
870873
let is_unfulfilled_lint_expectations = match ids {
871874
[lint] => *lint == LintId::of(UNFULFILLED_LINT_EXPECTATIONS),
872875
_ => false,
@@ -997,7 +1000,8 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
9971000
// we don't warn about the name change.
9981001
if let CheckLintNameResult::Renamed(new_name) = lint_result {
9991002
// Ignore any errors or warnings that happen because the new name is inaccurate
1000-
// NOTE: `new_name` already includes the tool name, so we don't have to add it again.
1003+
// NOTE: `new_name` already includes the tool name, so we don't have to add it
1004+
// again.
10011005
let CheckLintNameResult::Ok(ids) =
10021006
self.store.check_lint_name(&new_name, None, self.registered_tools)
10031007
else {

compiler/rustc_lint/src/methods.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ declare_lint! {
2525
///
2626
/// The inner pointer of a `CString` lives only as long as the `CString` it
2727
/// points to. Getting the inner pointer of a *temporary* `CString` allows the `CString`
28-
/// to be dropped at the end of the statement, as it is not being referenced as far as the typesystem
29-
/// is concerned. This means outside of the statement the pointer will point to freed memory, which
30-
/// causes undefined behavior if the pointer is later dereferenced.
28+
/// to be dropped at the end of the statement, as it is not being referenced as far as the
29+
/// typesystem is concerned. This means outside of the statement the pointer will point to
30+
/// freed memory, which causes undefined behavior if the pointer is later dereferenced.
3131
pub TEMPORARY_CSTRING_AS_PTR,
3232
Warn,
3333
"detects getting the inner pointer of a temporary `CString`"

compiler/rustc_lint/src/non_local_def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
306306
}
307307
}
308308

309-
// Detecting if the impl definition is leaking outside of it's defining scope.
309+
// Detecting if the impl definition is leaking outside of its defining scope.
310310
//
311311
// Rule: for each impl, instantiate all local types with inference vars and
312312
// then assemble candidates for that goal, if there are more than 1 (non-private

compiler/rustc_lint/src/nonstandard_style.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,14 @@ impl NonSnakeCase {
297297
// We cannot provide meaningful suggestions
298298
// if the characters are in the category of "Uppercase Letter".
299299
let sub = if name != sc {
300-
// We have a valid span in almost all cases, but we don't have one when linting a crate
301-
// name provided via the command line.
300+
// We have a valid span in almost all cases, but we don't have one when linting a
301+
// crate name provided via the command line.
302302
if !span.is_dummy() {
303303
let sc_ident = Ident::from_str_and_span(&sc, span);
304304
if sc_ident.is_reserved() {
305-
// We shouldn't suggest a reserved identifier to fix non-snake-case identifiers.
306-
// Instead, recommend renaming the identifier entirely or, if permitted,
307-
// escaping it to create a raw identifier.
305+
// We shouldn't suggest a reserved identifier to fix non-snake-case
306+
// identifiers. Instead, recommend renaming the identifier entirely or, if
307+
// permitted, escaping it to create a raw identifier.
308308
if sc_ident.name.can_be_raw() {
309309
NonSnakeCaseDiagSub::RenameOrConvertSuggestion {
310310
span,

compiler/rustc_lint/src/unused.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,8 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
387387
}
388388
}
389389

390-
// Returns whether further errors should be suppressed because either a lint has been emitted or the type should be ignored.
390+
// Returns whether further errors should be suppressed because either a lint has been
391+
// emitted or the type should be ignored.
391392
fn check_must_use_def(
392393
cx: &LateContext<'_>,
393394
def_id: DefId,
@@ -677,7 +678,8 @@ trait UnusedDelimLint {
677678
return true;
678679
}
679680

680-
// Check if LHS needs parens to prevent false-positives in cases like `fn x() -> u8 { ({ 0 } + 1) }`.
681+
// Check if LHS needs parens to prevent false-positives in cases like
682+
// `fn x() -> u8 { ({ 0 } + 1) }`.
681683
//
682684
// FIXME: https://github.com/rust-lang/rust/issues/119426
683685
// The syntax tree in this code is from after macro expansion, so the
@@ -722,7 +724,8 @@ trait UnusedDelimLint {
722724
}
723725
}
724726

725-
// Check if RHS needs parens to prevent false-positives in cases like `if (() == return) {}`.
727+
// Check if RHS needs parens to prevent false-positives in cases like `if (() == return)
728+
// {}`.
726729
if !followed_by_block {
727730
return false;
728731
}

0 commit comments

Comments
 (0)