Skip to content

Commit 475c181

Browse files
committed
Move more early buffered lints for rustc_resolve to dyn lint diagnostics
1 parent 5b98c56 commit 475c181

File tree

9 files changed

+76
-153
lines changed

9 files changed

+76
-153
lines changed

compiler/rustc_lint/messages.ftl

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
lint_abs_path_with_module = absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
22
.suggestion = use `crate`
33
4-
lint_ambiguous_glob_reexport = ambiguous glob re-exports
5-
.label_first_reexport = the name `{$name}` in the {$namespace} namespace is first re-exported here
6-
.label_duplicate_reexport = but the name `{$name}` in the {$namespace} namespace is also re-exported here
7-
84
lint_ambiguous_negative_literals = `-` has lower precedence than method calls, which might be unexpected
95
.example = e.g. `-4.abs()` equals `-4`; while `(-4).abs()` equals `4`
106
.negative_literal = add parentheses around the `-` and the literal to call the method on a negative literal
@@ -16,13 +12,6 @@ lint_ambiguous_wide_pointer_comparisons = ambiguous wide pointer comparison, the
1612
.cast_suggestion = use untyped pointers to only compare their addresses
1713
.expect_suggestion = or expect the lint to compare the pointers metadata and addresses
1814
19-
lint_associated_const_elided_lifetime = {$elided ->
20-
[true] `&` without an explicit lifetime name cannot be used here
21-
*[false] `'_` cannot be used here
22-
}
23-
.suggestion = use the `'static` lifetime
24-
.note = cannot automatically infer `'static` because of other lifetimes in scope
25-
2615
lint_async_fn_in_trait = use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified
2716
.note = you can suppress this lint if you plan to use the trait only in your own code, or do not care about auto traits like `Send` on the `Future`
2817
.suggestion = you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send`, but these cannot be relaxed without a breaking API change
@@ -330,10 +319,6 @@ lint_forgetting_references = calls to `std::mem::forget` with a reference instea
330319
lint_function_casts_as_integer = direct cast of function item into an integer
331320
.cast_as_fn = first cast to a pointer `as *const ()`
332321
333-
lint_hidden_glob_reexport = private item shadows public glob re-export
334-
.note_glob_reexport = the name `{$name}` in the {$namespace} namespace is supposed to be publicly re-exported here
335-
.note_private_item = but the private item here shadows it
336-
337322
lint_hidden_lifetime_parameters = hidden lifetime parameters in types are deprecated
338323
339324
lint_identifier_non_ascii_char = identifier contains non-ASCII characters
@@ -912,9 +897,6 @@ lint_unknown_lint =
912897
lint_unknown_tool_in_scoped_lint = unknown tool name `{$tool_name}` found in scoped lint: `{$tool_name}::{$lint_name}`
913898
.help = add `#![register_tool({$tool_name})]` to the crate root
914899
915-
lint_unnecessary_qualification = unnecessary qualification
916-
.suggestion = remove the unnecessary path segments
917-
918900
lint_unpredictable_fn_pointer_comparisons = function pointer comparisons do not produce meaningful results since their addresses are not guaranteed to be unique
919901
.note_duplicated_fn = the address of the same function can vary between different codegen units
920902
.note_deduplicated_fn = furthermore, different functions could have the same address after being merged together

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -135,53 +135,6 @@ pub fn decorate_builtin_lint(
135135
BuiltinLintDiag::SingleUseLifetime { use_span: None, deletion_span, ident, .. } => {
136136
lints::UnusedLifetime { deletion_span, ident }.decorate_lint(diag);
137137
}
138-
BuiltinLintDiag::AmbiguousGlobReexports {
139-
name,
140-
namespace,
141-
first_reexport_span,
142-
duplicate_reexport_span,
143-
} => {
144-
lints::AmbiguousGlobReexports {
145-
first_reexport: first_reexport_span,
146-
duplicate_reexport: duplicate_reexport_span,
147-
name,
148-
namespace,
149-
}
150-
.decorate_lint(diag);
151-
}
152-
BuiltinLintDiag::HiddenGlobReexports {
153-
name,
154-
namespace,
155-
glob_reexport_span,
156-
private_item_span,
157-
} => {
158-
lints::HiddenGlobReexports {
159-
glob_reexport: glob_reexport_span,
160-
private_item: private_item_span,
161-
162-
name,
163-
namespace,
164-
}
165-
.decorate_lint(diag);
166-
}
167-
BuiltinLintDiag::UnusedQualifications { removal_span } => {
168-
lints::UnusedQualifications { removal_span }.decorate_lint(diag);
169-
}
170-
BuiltinLintDiag::AssociatedConstElidedLifetime {
171-
elided,
172-
span: lt_span,
173-
lifetimes_in_scope,
174-
} => {
175-
let lt_span = if elided { lt_span.shrink_to_hi() } else { lt_span };
176-
let code = if elided { "'static " } else { "'static" };
177-
lints::AssociatedConstElidedLifetime {
178-
span: lt_span,
179-
code,
180-
elided,
181-
lifetimes_in_scope,
182-
}
183-
.decorate_lint(diag);
184-
}
185138
BuiltinLintDiag::AttributeLint(kind) => decorate_attribute_lint(sess, tcx, &kind, diag),
186139
}
187140
}

compiler/rustc_lint/src/lints.rs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2710,51 +2710,6 @@ pub(crate) struct UnusedLifetime {
27102710
pub ident: Ident,
27112711
}
27122712

2713-
#[derive(LintDiagnostic)]
2714-
#[diag(lint_ambiguous_glob_reexport)]
2715-
pub(crate) struct AmbiguousGlobReexports {
2716-
#[label(lint_label_first_reexport)]
2717-
pub first_reexport: Span,
2718-
#[label(lint_label_duplicate_reexport)]
2719-
pub duplicate_reexport: Span,
2720-
2721-
pub name: String,
2722-
// FIXME: make this translatable
2723-
pub namespace: String,
2724-
}
2725-
2726-
#[derive(LintDiagnostic)]
2727-
#[diag(lint_hidden_glob_reexport)]
2728-
pub(crate) struct HiddenGlobReexports {
2729-
#[note(lint_note_glob_reexport)]
2730-
pub glob_reexport: Span,
2731-
#[note(lint_note_private_item)]
2732-
pub private_item: Span,
2733-
2734-
pub name: String,
2735-
// FIXME: make this translatable
2736-
pub namespace: String,
2737-
}
2738-
2739-
#[derive(LintDiagnostic)]
2740-
#[diag(lint_unnecessary_qualification)]
2741-
pub(crate) struct UnusedQualifications {
2742-
#[suggestion(style = "verbose", code = "", applicability = "machine-applicable")]
2743-
pub removal_span: Span,
2744-
}
2745-
2746-
#[derive(LintDiagnostic)]
2747-
#[diag(lint_associated_const_elided_lifetime)]
2748-
pub(crate) struct AssociatedConstElidedLifetime {
2749-
#[suggestion(style = "verbose", code = "{code}", applicability = "machine-applicable")]
2750-
pub span: Span,
2751-
2752-
pub code: &'static str,
2753-
pub elided: bool,
2754-
#[note]
2755-
pub lifetimes_in_scope: MultiSpan,
2756-
}
2757-
27582713
#[derive(LintDiagnostic)]
27592714
#[diag(lint_static_mut_refs_lint)]
27602715
pub(crate) struct RefOfMutStatic<'a> {

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::fx::FxIndexSet;
77
use rustc_data_structures::stable_hasher::{
88
HashStable, StableCompare, StableHasher, ToStableHashKey,
99
};
10-
use rustc_error_messages::{DiagArgValue, IntoDiagArg, MultiSpan};
10+
use rustc_error_messages::{DiagArgValue, IntoDiagArg};
1111
use rustc_hir_id::{HashStableContext, HirId, ItemLocalId};
1212
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
1313
use rustc_span::def_id::DefPathHash;
@@ -684,35 +684,6 @@ pub enum BuiltinLintDiag {
684684
use_span: Option<(Span, bool)>,
685685
ident: Ident,
686686
},
687-
AmbiguousGlobReexports {
688-
/// The name for which collision(s) have occurred.
689-
name: String,
690-
/// The name space for which the collision(s) occurred in.
691-
namespace: String,
692-
/// Span where the name is first re-exported.
693-
first_reexport_span: Span,
694-
/// Span where the same name is also re-exported.
695-
duplicate_reexport_span: Span,
696-
},
697-
HiddenGlobReexports {
698-
/// The name of the local binding which shadows the glob re-export.
699-
name: String,
700-
/// The namespace for which the shadowing occurred in.
701-
namespace: String,
702-
/// The glob reexport that is shadowed by the local binding.
703-
glob_reexport_span: Span,
704-
/// The local binding that shadows the glob reexport.
705-
private_item_span: Span,
706-
},
707-
UnusedQualifications {
708-
/// The span of the unnecessarily-qualified path to remove.
709-
removal_span: Span,
710-
},
711-
AssociatedConstElidedLifetime {
712-
elided: bool,
713-
span: Span,
714-
lifetimes_in_scope: MultiSpan,
715-
},
716687
AttributeLint(AttributeLintKind),
717688
}
718689

compiler/rustc_resolve/messages.ftl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ resolve_add_as_non_derive =
88
resolve_added_macro_use =
99
have you added the `#[macro_use]` on the module/import?
1010
11+
resolve_ambiguous_glob_reexport = ambiguous glob re-exports
12+
.label_first_reexport = the name `{$name}` in the {$namespace} namespace is first re-exported here
13+
.label_duplicate_reexport = but the name `{$name}` in the {$namespace} namespace is also re-exported here
14+
1115
resolve_ancestor_only =
1216
visibilities can only be restricted to ancestor modules
1317
@@ -17,6 +21,13 @@ resolve_anonymous_lifetime_non_gat_report_error = missing lifetime in associated
1721
1822
resolve_arguments_macro_use_not_allowed = arguments to `macro_use` are not allowed here
1923
24+
resolve_associated_const_elided_lifetime = {$elided ->
25+
[true] `&` without an explicit lifetime name cannot be used here
26+
*[false] `'_` cannot be used here
27+
}
28+
.suggestion = use the `'static` lifetime
29+
.note = cannot automatically infer `'static` because of other lifetimes in scope
30+
2031
resolve_associated_const_with_similar_name_exists =
2132
there is an associated constant with a similar name
2233
@@ -197,6 +208,10 @@ resolve_generic_params_from_outer_item_static = a `static` is a separate item fr
197208
198209
resolve_generic_params_from_outer_item_ty_param = type parameter from outer item
199210
211+
resolve_hidden_glob_reexport = private item shadows public glob re-export
212+
.note_glob_reexport = the name `{$name}` in the {$namespace} namespace is supposed to be publicly re-exported here
213+
.note_private_item = but the private item here shadows it
214+
200215
resolve_ident_bound_more_than_once_in_parameter_list =
201216
identifier `{$identifier}` is bound more than once in this parameter list
202217
.label = used as parameter more than once
@@ -490,6 +505,9 @@ resolve_unknown_diagnostic_attribute_typo_sugg = an attribute with a similar nam
490505
resolve_unnamed_crate_root_import =
491506
crate root imports need to be explicitly named: `use crate as name;`
492507
508+
resolve_unnecessary_qualification = unnecessary qualification
509+
.suggestion = remove the unnecessary path segments
510+
493511
resolve_unreachable_label =
494512
use of unreachable label `{$name}`
495513
.label = unreachable label `{$name}`

compiler/rustc_resolve/src/check_unused.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ impl Resolver<'_, '_> {
554554
UNUSED_QUALIFICATIONS,
555555
unn_qua.node_id,
556556
unn_qua.path_span,
557-
BuiltinLintDiag::UnusedQualifications { removal_span: unn_qua.removal_span },
557+
crate::errors::UnusedQualifications { removal_span: unn_qua.removal_span },
558558
);
559559
}
560560

compiler/rustc_resolve/src/errors.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,3 +1486,45 @@ impl<'a> LintDiagnostic<'a, ()> for Ambiguity {
14861486
self.decorate(diag);
14871487
}
14881488
}
1489+
1490+
#[derive(LintDiagnostic)]
1491+
#[diag(resolve_unnecessary_qualification)]
1492+
pub(crate) struct UnusedQualifications {
1493+
#[suggestion(style = "verbose", code = "", applicability = "machine-applicable")]
1494+
pub removal_span: Span,
1495+
}
1496+
1497+
#[derive(LintDiagnostic)]
1498+
#[diag(resolve_associated_const_elided_lifetime)]
1499+
pub(crate) struct AssociatedConstElidedLifetime {
1500+
#[suggestion(style = "verbose", code = "{code}", applicability = "machine-applicable")]
1501+
pub span: Span,
1502+
pub code: &'static str,
1503+
pub elided: bool,
1504+
#[note]
1505+
pub lifetimes_in_scope: MultiSpan,
1506+
}
1507+
1508+
#[derive(LintDiagnostic)]
1509+
#[diag(resolve_ambiguous_glob_reexport)]
1510+
pub(crate) struct AmbiguousGlobReexports {
1511+
#[label(resolve_label_first_reexport)]
1512+
pub first_reexport: Span,
1513+
#[label(resolve_label_duplicate_reexport)]
1514+
pub duplicate_reexport: Span,
1515+
pub name: String,
1516+
// FIXME: make this translatable
1517+
pub namespace: &'static str,
1518+
}
1519+
1520+
#[derive(LintDiagnostic)]
1521+
#[diag(resolve_hidden_glob_reexport)]
1522+
pub(crate) struct HiddenGlobReexports {
1523+
#[note(resolve_note_glob_reexport)]
1524+
pub glob_reexport: Span,
1525+
#[note(resolve_note_private_item)]
1526+
pub private_item: Span,
1527+
pub name: Symbol,
1528+
// FIXME: make this translatable
1529+
pub namespace: &'static str,
1530+
}

compiler/rustc_resolve/src/imports.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -666,11 +666,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
666666
AMBIGUOUS_GLOB_REEXPORTS,
667667
import.root_id,
668668
import.root_span,
669-
BuiltinLintDiag::AmbiguousGlobReexports {
669+
crate::errors::AmbiguousGlobReexports {
670+
first_reexport: import.root_span,
671+
duplicate_reexport: amb_binding.span,
670672
name: key.ident.to_string(),
671-
namespace: key.ns.descr().to_string(),
672-
first_reexport_span: import.root_span,
673-
duplicate_reexport_span: amb_binding.span,
673+
namespace: key.ns.descr(),
674674
},
675675
);
676676
}
@@ -699,11 +699,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
699699
HIDDEN_GLOB_REEXPORTS,
700700
binding_id,
701701
binding.span,
702-
BuiltinLintDiag::HiddenGlobReexports {
703-
name: key.ident.name.to_string(),
704-
namespace: key.ns.descr().to_owned(),
705-
glob_reexport_span: glob_binding.span,
706-
private_item_span: binding.span,
702+
crate::errors::HiddenGlobReexports {
703+
glob_reexport: glob_binding.span,
704+
private_item: binding.span,
705+
name: key.ident.name,
706+
namespace: key.ns.descr(),
707707
},
708708
);
709709
}

compiler/rustc_resolve/src/late.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,13 +1852,15 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
18521852
);
18531853
return;
18541854
} else if emit_lint {
1855+
let span = lifetime.ident.span;
18551856
self.r.lint_buffer.buffer_lint(
18561857
lint::builtin::ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
18571858
node_id,
1858-
lifetime.ident.span,
1859-
lint::BuiltinLintDiag::AssociatedConstElidedLifetime {
1859+
span,
1860+
errors::AssociatedConstElidedLifetime {
1861+
span: if elided { span.shrink_to_hi() } else { span },
18601862
elided,
1861-
span: lifetime.ident.span,
1863+
code: if elided { "'static " } else { "'static" },
18621864
lifetimes_in_scope: lifetimes_in_scope.into(),
18631865
},
18641866
);

0 commit comments

Comments
 (0)