Skip to content

Commit 92b9270

Browse files
committed
Fix up comments.
Wrap overly long ones, etc.
1 parent 023d1b9 commit 92b9270

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
@@ -1493,8 +1493,9 @@ impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
14931493

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

@@ -2209,7 +2210,8 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
22092210
hir_generics.span.shrink_to_hi().to(where_span)
22102211
};
22112212

2212-
// Due to macro expansions, the `full_where_span` might not actually contain all predicates.
2213+
// Due to macro expansions, the `full_where_span` might not actually contain all
2214+
// predicates.
22132215
if where_lint_spans.iter().all(|&sp| full_where_span.contains(sp)) {
22142216
lint_spans.push(full_where_span);
22152217
} else {
@@ -2586,7 +2588,8 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
25862588
};
25872589
// So we have at least one potentially inhabited variant. Might we have two?
25882590
let Some(second_variant) = potential_variants.next() else {
2589-
// There is only one potentially inhabited variant. So we can recursively check that variant!
2591+
// There is only one potentially inhabited variant. So we can recursively
2592+
// check that variant!
25902593
return variant_find_init_error(
25912594
cx,
25922595
ty,
@@ -2596,10 +2599,10 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
25962599
init,
25972600
);
25982601
};
2599-
// So we have at least two potentially inhabited variants.
2600-
// If we can prove that we have at least two *definitely* inhabited variants,
2601-
// then we have a tag and hence leaving this uninit is definitely disallowed.
2602-
// (Leaving it zeroed could be okay, depending on which variant is encoded as zero tag.)
2602+
// So we have at least two potentially inhabited variants. If we can prove that
2603+
// we have at least two *definitely* inhabited variants, then we have a tag and
2604+
// hence leaving this uninit is definitely disallowed. (Leaving it zeroed could
2605+
// be okay, depending on which variant is encoded as zero tag.)
26032606
if init == InitKind::Uninit {
26042607
let definitely_inhabited = (first_variant.1 as usize)
26052608
+ (second_variant.1 as usize)
@@ -2810,7 +2813,8 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
28102813

28112814
let mut found_labels = Vec::new();
28122815

2813-
// A semicolon might not actually be specified as a separator for all targets, but it seems like LLVM accepts it always
2816+
// A semicolon might not actually be specified as a separator for all targets, but
2817+
// it seems like LLVM accepts it always.
28142818
let statements = template_str.split(|c| matches!(c, '\n' | ';'));
28152819
for statement in statements {
28162820
// If there's a comment, trim it from the statement
@@ -2823,7 +2827,8 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
28232827
let mut chars = possible_label.chars();
28242828

28252829
let Some(start) = chars.next() else {
2826-
// Empty string means a leading ':' in this section, which is not a label.
2830+
// Empty string means a leading ':' in this section, which is not a
2831+
// label.
28272832
break 'label_loop;
28282833
};
28292834

@@ -2840,12 +2845,15 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
28402845

28412846
// Labels continue with ASCII alphanumeric characters, _, or $
28422847
for c in chars {
2843-
// Inside a template format arg, any character is permitted for the puproses of label detection
2844-
// because we assume that it can be replaced with some other valid label string later.
2845-
// `options(raw)` asm blocks cannot have format args, so they are excluded from this special case.
2848+
// Inside a template format arg, any character is permitted for the
2849+
// puproses of label detection because we assume that it can be
2850+
// replaced with some other valid label string later. `options(raw)`
2851+
// asm blocks cannot have format args, so they are excluded from this
2852+
// special case.
28462853
if !raw && in_bracket {
28472854
if c == '{' {
2848-
// Nested brackets are not allowed in format args, this cannot be a label.
2855+
// Nested brackets are not allowed in format args, this cannot
2856+
// be a label.
28492857
break 'label_loop;
28502858
}
28512859

@@ -2858,7 +2866,8 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
28582866
in_bracket = true;
28592867
} else {
28602868
if !(c.is_ascii_alphanumeric() || matches!(c, '_' | '$')) {
2861-
// The potential label had an invalid character inside it, it cannot be a label.
2869+
// The potential label had an invalid character inside it, it
2870+
// cannot be a label.
28622871
break 'label_loop;
28632872
}
28642873
}
@@ -2877,7 +2886,8 @@ impl<'tcx> LateLintPass<'tcx> for NamedAsmLabels {
28772886
.into_iter()
28782887
.filter_map(|label| find_label_span(label))
28792888
.collect::<Vec<Span>>();
2880-
// If there were labels but we couldn't find a span, combine the warnings and use the template span
2889+
// If there were labels but we couldn't find a span, combine the warnings and
2890+
// use the template span.
28812891
let target_spans: MultiSpan =
28822892
if spans.len() > 0 { spans.into() } else { (*template_span).into() };
28832893

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
@@ -748,7 +748,8 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
748748

749749
let level = match Level::from_attr(attr) {
750750
None => continue,
751-
// This is the only lint level with a `LintExpectationId` that can be created from an attribute
751+
// This is the only lint level with a `LintExpectationId` that can be created from
752+
// an attribute.
752753
Some(Level::Expect(unstable_id)) if let Some(hir_id) = source_hir_id => {
753754
let LintExpectationId::Unstable { attr_id, lint_index } = unstable_id else {
754755
bug!("stable id Level::from_attr")
@@ -758,8 +759,8 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
758759
hir_id,
759760
attr_index: attr_index.try_into().unwrap(),
760761
lint_index,
761-
// we pass the previous unstable attr_id such that we can trace the ast id when building a map
762-
// to go from unstable to stable id.
762+
// We pass the previous unstable attr_id such that we can trace the ast id
763+
// when building a map to go from unstable to stable id.
763764
attr_id: Some(attr_id),
764765
};
765766

@@ -858,13 +859,15 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
858859
self.store.check_lint_name(&name, tool_name, self.registered_tools);
859860
match &lint_result {
860861
CheckLintNameResult::Ok(ids) => {
861-
// This checks for instances where the user writes `#[expect(unfulfilled_lint_expectations)]`
862-
// in that case we want to avoid overriding the lint level but instead add an expectation that
863-
// can't be fulfilled. The lint message will include an explanation, that the
862+
// This checks for instances where the user writes
863+
// `#[expect(unfulfilled_lint_expectations)]` in that case we want to avoid
864+
// overriding the lint level but instead add an expectation that can't be
865+
// fulfilled. The lint message will include an explanation, that the
864866
// `unfulfilled_lint_expectations` lint can't be expected.
865867
if let Level::Expect(expect_id) = level {
866-
// The `unfulfilled_lint_expectations` lint is not part of any lint groups. Therefore. we
867-
// only need to check the slice if it contains a single lint.
868+
// The `unfulfilled_lint_expectations` lint is not part of any lint
869+
// groups. Therefore. we only need to check the slice if it contains a
870+
// single lint.
868871
let is_unfulfilled_lint_expectations = match ids {
869872
[lint] => *lint == LintId::of(UNFULFILLED_LINT_EXPECTATIONS),
870873
_ => false,
@@ -995,7 +998,8 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
995998
// we don't warn about the name change.
996999
if let CheckLintNameResult::Renamed(new_name) = lint_result {
9971000
// Ignore any errors or warnings that happen because the new name is inaccurate
998-
// NOTE: `new_name` already includes the tool name, so we don't have to add it again.
1001+
// NOTE: `new_name` already includes the tool name, so we don't have to add it
1002+
// again.
9991003
let CheckLintNameResult::Ok(ids) =
10001004
self.store.check_lint_name(&new_name, None, self.registered_tools)
10011005
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
@@ -259,7 +259,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
259259
}
260260
}
261261

262-
// Detecting if the impl definition is leaking outside of it's defining scope.
262+
// Detecting if the impl definition is leaking outside of its defining scope.
263263
//
264264
// Rule: for each impl, instantiate all local types with inference vars and
265265
// 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)