Skip to content

Commit 67aa270

Browse files
committed
Auto merge of #42136 - petrochenkov:oldhard, r=nikomatsakis
Turn sufficiently old compatibility lints into hard errors It's been almost 7 months since #36894 was merged, so it's time to take the next step. [breaking-change], needs crater run. PRs/issues submitted to affected crates: https://github.com/alexcrichton/ctest/pull/17 Sean1708/rusty-cheddar#55 m-r-r/helianto#3 azdle/virgil#1 rust-locale/rust-locale#24 mneumann/acyclic-network-rs#1 reem/rust-typemap#38 cc https://internals.rust-lang.org/t/moving-forward-on-forward-compatibility-lints/4204 cc #34537 #36887 Closes #36886 Closes #36888 Closes #36890 Closes #36891 Closes #36892 r? @nikomatsakis
2 parents e0cc22b + 26d5c0e commit 67aa270

29 files changed

+107
-224
lines changed

src/librustc/lint/builtin.rs

-58
Original file line numberDiff line numberDiff line change
@@ -130,68 +130,18 @@ declare_lint! {
130130
"detect private items in public interfaces not caught by the old implementation"
131131
}
132132

133-
declare_lint! {
134-
pub INACCESSIBLE_EXTERN_CRATE,
135-
Deny,
136-
"use of inaccessible extern crate erroneously allowed"
137-
}
138-
139133
declare_lint! {
140134
pub INVALID_TYPE_PARAM_DEFAULT,
141135
Deny,
142136
"type parameter default erroneously allowed in invalid location"
143137
}
144138

145-
declare_lint! {
146-
pub ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN,
147-
Deny,
148-
"floating-point constants cannot be used in patterns"
149-
}
150-
151-
declare_lint! {
152-
pub ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN,
153-
Deny,
154-
"constants of struct or enum type can only be used in a pattern if \
155-
the struct or enum has `#[derive(PartialEq, Eq)]`"
156-
}
157-
158-
declare_lint! {
159-
pub RAW_POINTER_DERIVE,
160-
Warn,
161-
"uses of #[derive] with raw pointers are rarely correct"
162-
}
163-
164-
declare_lint! {
165-
pub HR_LIFETIME_IN_ASSOC_TYPE,
166-
Deny,
167-
"binding for associated type references higher-ranked lifetime \
168-
that does not appear in the trait input types"
169-
}
170-
171-
declare_lint! {
172-
pub OVERLAPPING_INHERENT_IMPLS,
173-
Deny,
174-
"two overlapping inherent impls define an item with the same name were erroneously allowed"
175-
}
176-
177139
declare_lint! {
178140
pub RENAMED_AND_REMOVED_LINTS,
179141
Warn,
180142
"lints that have been renamed or removed"
181143
}
182144

183-
declare_lint! {
184-
pub SUPER_OR_SELF_IN_GLOBAL_PATH,
185-
Deny,
186-
"detects super or self keywords at the beginning of global path"
187-
}
188-
189-
declare_lint! {
190-
pub LIFETIME_UNDERSCORE,
191-
Deny,
192-
"lifetimes or labels named `'_` were erroneously allowed"
193-
}
194-
195145
declare_lint! {
196146
pub RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
197147
Warn,
@@ -280,17 +230,9 @@ impl LintPass for HardwiredLints {
280230
TRIVIAL_CASTS,
281231
TRIVIAL_NUMERIC_CASTS,
282232
PRIVATE_IN_PUBLIC,
283-
INACCESSIBLE_EXTERN_CRATE,
284233
INVALID_TYPE_PARAM_DEFAULT,
285-
ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN,
286-
ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN,
287234
CONST_ERR,
288-
RAW_POINTER_DERIVE,
289-
OVERLAPPING_INHERENT_IMPLS,
290235
RENAMED_AND_REMOVED_LINTS,
291-
SUPER_OR_SELF_IN_GLOBAL_PATH,
292-
HR_LIFETIME_IN_ASSOC_TYPE,
293-
LIFETIME_UNDERSCORE,
294236
RESOLVE_TRAIT_ON_DEFAULTED_UNIT,
295237
SAFE_EXTERN_STATICS,
296238
PATTERNS_IN_FNS_WITHOUT_BODY,

src/librustc_const_eval/pattern.rs

+6-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
use eval;
1212

13-
use rustc::lint;
1413
use rustc::middle::const_val::{ConstEvalErr, ConstVal};
1514
use rustc::mir::{Field, BorrowKind, Mutability};
1615
use rustc::ty::{self, TyCtxt, AdtDef, Ty, TypeVariants, Region};
@@ -644,27 +643,19 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
644643
debug!("expr={:?} pat_ty={:?} pat_id={}", expr, pat_ty, pat_id);
645644
match pat_ty.sty {
646645
ty::TyFloat(_) => {
647-
self.tcx.sess.add_lint(
648-
lint::builtin::ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN,
649-
pat_id,
650-
span,
651-
format!("floating point constants cannot be used in patterns"));
646+
self.tcx.sess.span_err(span, "floating point constants cannot be used in patterns");
652647
}
653648
ty::TyAdt(adt_def, _) if adt_def.is_union() => {
654649
// Matching on union fields is unsafe, we can't hide it in constants
655650
self.tcx.sess.span_err(span, "cannot use unions in constant patterns");
656651
}
657652
ty::TyAdt(adt_def, _) => {
658653
if !self.tcx.has_attr(adt_def.did, "structural_match") {
659-
self.tcx.sess.add_lint(
660-
lint::builtin::ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN,
661-
pat_id,
662-
span,
663-
format!("to use a constant of type `{}` \
664-
in a pattern, \
665-
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
666-
self.tcx.item_path_str(adt_def.did),
667-
self.tcx.item_path_str(adt_def.did)));
654+
let msg = format!("to use a constant of type `{}` in a pattern, \
655+
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
656+
self.tcx.item_path_str(adt_def.did),
657+
self.tcx.item_path_str(adt_def.did));
658+
self.tcx.sess.span_err(span, &msg);
668659
}
669660
}
670661
_ => { }

src/librustc_lint/lib.rs

+30-41
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
179179
// - Create a lint defaulting to warn as normal, with ideally the same error
180180
// message you would normally give
181181
// - Add a suitable reference, typically an RFC or tracking issue. Go ahead
182-
// and include the full URL.
182+
// and include the full URL, sort items in ascending order of issue numbers.
183183
// - Later, change lint to error
184184
// - Eventually, remove lint
185185
store.register_future_incompatible(sess,
@@ -189,48 +189,16 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
189189
reference: "issue #34537 <https://github.com/rust-lang/rust/issues/34537>",
190190
},
191191
FutureIncompatibleInfo {
192-
id: LintId::of(INACCESSIBLE_EXTERN_CRATE),
193-
reference: "issue #36886 <https://github.com/rust-lang/rust/issues/36886>",
194-
},
195-
FutureIncompatibleInfo {
196-
id: LintId::of(INVALID_TYPE_PARAM_DEFAULT),
197-
reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
198-
},
199-
FutureIncompatibleInfo {
200-
id: LintId::of(SUPER_OR_SELF_IN_GLOBAL_PATH),
201-
reference: "issue #36888 <https://github.com/rust-lang/rust/issues/36888>",
202-
},
203-
FutureIncompatibleInfo {
204-
id: LintId::of(ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN),
205-
reference: "issue #36890 <https://github.com/rust-lang/rust/issues/36890>",
206-
},
207-
FutureIncompatibleInfo {
208-
id: LintId::of(ILLEGAL_FLOATING_POINT_LITERAL_PATTERN),
209-
reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>",
210-
},
211-
FutureIncompatibleInfo {
212-
id: LintId::of(ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN),
213-
reference: "issue #36891 <https://github.com/rust-lang/rust/issues/36891>",
214-
},
215-
FutureIncompatibleInfo {
216-
id: LintId::of(HR_LIFETIME_IN_ASSOC_TYPE),
217-
reference: "issue #33685 <https://github.com/rust-lang/rust/issues/33685>",
218-
},
219-
FutureIncompatibleInfo {
220-
id: LintId::of(LIFETIME_UNDERSCORE),
221-
reference: "issue #36892 <https://github.com/rust-lang/rust/issues/36892>",
222-
},
223-
FutureIncompatibleInfo {
224-
id: LintId::of(RESOLVE_TRAIT_ON_DEFAULTED_UNIT),
225-
reference: "issue #39216 <https://github.com/rust-lang/rust/issues/39216>",
192+
id: LintId::of(PATTERNS_IN_FNS_WITHOUT_BODY),
193+
reference: "issue #35203 <https://github.com/rust-lang/rust/issues/35203>",
226194
},
227195
FutureIncompatibleInfo {
228196
id: LintId::of(SAFE_EXTERN_STATICS),
229-
reference: "issue #36247 <https://github.com/rust-lang/rust/issues/35112>",
197+
reference: "issue #36247 <https://github.com/rust-lang/rust/issues/36247>",
230198
},
231199
FutureIncompatibleInfo {
232-
id: LintId::of(PATTERNS_IN_FNS_WITHOUT_BODY),
233-
reference: "issue #35203 <https://github.com/rust-lang/rust/issues/35203>",
200+
id: LintId::of(INVALID_TYPE_PARAM_DEFAULT),
201+
reference: "issue #36887 <https://github.com/rust-lang/rust/issues/36887>",
234202
},
235203
FutureIncompatibleInfo {
236204
id: LintId::of(EXTRA_REQUIREMENT_IN_IMPL),
@@ -248,18 +216,26 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
248216
id: LintId::of(LEGACY_CONSTRUCTOR_VISIBILITY),
249217
reference: "issue #39207 <https://github.com/rust-lang/rust/issues/39207>",
250218
},
219+
FutureIncompatibleInfo {
220+
id: LintId::of(RESOLVE_TRAIT_ON_DEFAULTED_UNIT),
221+
reference: "issue #39216 <https://github.com/rust-lang/rust/issues/39216>",
222+
},
251223
FutureIncompatibleInfo {
252224
id: LintId::of(MISSING_FRAGMENT_SPECIFIER),
253225
reference: "issue #40107 <https://github.com/rust-lang/rust/issues/40107>",
254226
},
255227
FutureIncompatibleInfo {
256-
id: LintId::of(PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES),
257-
reference: "issue #42238 <https://github.com/rust-lang/rust/issues/42238>",
228+
id: LintId::of(ILLEGAL_FLOATING_POINT_LITERAL_PATTERN),
229+
reference: "issue #41620 <https://github.com/rust-lang/rust/issues/41620>",
258230
},
259231
FutureIncompatibleInfo {
260232
id: LintId::of(ANONYMOUS_PARAMETERS),
261233
reference: "issue #41686 <https://github.com/rust-lang/rust/issues/41686>",
262234
},
235+
FutureIncompatibleInfo {
236+
id: LintId::of(PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES),
237+
reference: "issue #42238 <https://github.com/rust-lang/rust/issues/42238>",
238+
}
263239
]);
264240

265241
// Register renamed and removed lints
@@ -275,5 +251,18 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
275251
store.register_removed("drop_with_repr_extern", "drop flags have been removed");
276252
store.register_removed("transmute_from_fn_item_types",
277253
"always cast functions before transmuting them");
278-
store.register_removed("overlapping_inherent_impls", "converted into hard error, see #36889");
254+
store.register_removed("hr_lifetime_in_assoc_type",
255+
"converted into hard error, see https://github.com/rust-lang/rust/issues/33685");
256+
store.register_removed("inaccessible_extern_crate",
257+
"converted into hard error, see https://github.com/rust-lang/rust/issues/36886");
258+
store.register_removed("super_or_self_in_global_path",
259+
"converted into hard error, see https://github.com/rust-lang/rust/issues/36888");
260+
store.register_removed("overlapping_inherent_impls",
261+
"converted into hard error, see https://github.com/rust-lang/rust/issues/36889");
262+
store.register_removed("illegal_floating_point_constant_pattern",
263+
"converted into hard error, see https://github.com/rust-lang/rust/issues/36890");
264+
store.register_removed("illegal_struct_or_enum_constant_pattern",
265+
"converted into hard error, see https://github.com/rust-lang/rust/issues/36891");
266+
store.register_removed("lifetime_underscore",
267+
"converted into hard error, see https://github.com/rust-lang/rust/issues/36892");
279268
}

src/librustc_passes/ast_validation.rs

+7-18
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,10 @@ impl<'a> AstValidator<'a> {
3636
&self.session.parse_sess.span_diagnostic
3737
}
3838

39-
fn check_label(&self, label: Ident, span: Span, id: NodeId) {
40-
if label.name == keywords::StaticLifetime.name() {
39+
fn check_label(&self, label: Ident, span: Span) {
40+
if label.name == keywords::StaticLifetime.name() || label.name == "'_" {
4141
self.err_handler().span_err(span, &format!("invalid label name `{}`", label.name));
4242
}
43-
if label.name == "'_" {
44-
self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
45-
id,
46-
span,
47-
format!("invalid label name `{}`", label.name));
48-
}
4943
}
5044

5145
fn invalid_visibility(&self, vis: &Visibility, span: Span, note: Option<&str>) {
@@ -104,10 +98,7 @@ impl<'a> AstValidator<'a> {
10498
impl<'a> Visitor<'a> for AstValidator<'a> {
10599
fn visit_lifetime(&mut self, lt: &'a Lifetime) {
106100
if lt.ident.name == "'_" {
107-
self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE,
108-
lt.id,
109-
lt.span,
110-
format!("invalid lifetime name `{}`", lt.ident));
101+
self.err_handler().span_err(lt.span, &format!("invalid lifetime name `{}`", lt.ident));
111102
}
112103

113104
visit::walk_lifetime(self, lt)
@@ -121,7 +112,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
121112
ExprKind::ForLoop(.., Some(ident)) |
122113
ExprKind::Break(Some(ident), _) |
123114
ExprKind::Continue(Some(ident)) => {
124-
self.check_label(ident.node, ident.span, expr.id);
115+
self.check_label(ident.node, ident.span);
125116
}
126117
_ => {}
127118
}
@@ -169,14 +160,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
169160
visit::walk_ty(self, ty)
170161
}
171162

172-
fn visit_path(&mut self, path: &'a Path, id: NodeId) {
163+
fn visit_path(&mut self, path: &'a Path, _: NodeId) {
173164
if path.segments.len() >= 2 && path.is_global() {
174165
let ident = path.segments[1].identifier;
175166
if token::Ident(ident).is_path_segment_keyword() {
176-
self.session.add_lint(lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH,
177-
id,
178-
path.span,
179-
format!("global paths cannot start with `{}`", ident));
167+
self.err_handler()
168+
.span_err(path.span, &format!("global paths cannot start with `{}`", ident));
180169
}
181170
}
182171

src/librustc_resolve/lib.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,10 @@ impl<'a> NameBinding<'a> {
10691069
_ => false,
10701070
}
10711071
}
1072+
1073+
fn descr(&self) -> &'static str {
1074+
if self.is_extern_crate() { "extern crate" } else { self.def().kind_name() }
1075+
}
10721076
}
10731077

10741078
/// Interns the names of the primitive types.
@@ -3424,18 +3428,7 @@ impl<'a> Resolver<'a> {
34243428

34253429
for &PrivacyError(span, name, binding) in &self.privacy_errors {
34263430
if !reported_spans.insert(span) { continue }
3427-
if binding.is_extern_crate() {
3428-
// Warn when using an inaccessible extern crate.
3429-
let node_id = match binding.kind {
3430-
NameBindingKind::Import { directive, .. } => directive.id,
3431-
_ => unreachable!(),
3432-
};
3433-
let msg = format!("extern crate `{}` is private", name);
3434-
self.session.add_lint(lint::builtin::INACCESSIBLE_EXTERN_CRATE, node_id, span, msg);
3435-
} else {
3436-
let def = binding.def();
3437-
self.session.span_err(span, &format!("{} `{}` is private", def.kind_name(), name));
3438-
}
3431+
self.session.span_err(span, &format!("{} `{}` is private", binding.descr(), name));
34393432
}
34403433
}
34413434

src/librustc_resolve/resolve_imports.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
723723
let (ns, binding) = reexport_error.unwrap();
724724
if ns == TypeNS && binding.is_extern_crate() {
725725
let msg = format!("extern crate `{}` is private, and cannot be reexported \
726-
(error E0364), consider declaring with `pub`",
726+
(error E0365), consider declaring with `pub`",
727727
ident);
728728
self.session.add_lint(PRIVATE_IN_PUBLIC, directive.id, directive.span, msg);
729729
} else if ns == TypeNS {
@@ -792,8 +792,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
792792
self.record_def(directive.id, PathResolution::new(module.def().unwrap()));
793793
}
794794

795-
// Miscellaneous post-processing, including recording reexports, reporting conflicts,
796-
// reporting the PRIVATE_IN_PUBLIC lint, and reporting unresolved imports.
795+
// Miscellaneous post-processing, including recording reexports,
796+
// reporting conflicts, and reporting unresolved imports.
797797
fn finalize_resolutions_in(&mut self, module: Module<'b>) {
798798
// Since import resolution is finished, globs will not define any more names.
799799
*module.globs.borrow_mut() = Vec::new();
@@ -838,13 +838,12 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
838838
}
839839

840840
match binding.kind {
841-
NameBindingKind::Import { binding: orig_binding, directive, .. } => {
841+
NameBindingKind::Import { binding: orig_binding, .. } => {
842842
if ns == TypeNS && orig_binding.is_variant() &&
843843
!orig_binding.vis.is_at_least(binding.vis, &*self) {
844-
let msg = format!("variant `{}` is private, and cannot be reexported \
845-
(error E0364), consider declaring its enum as `pub`",
846-
ident);
847-
self.session.add_lint(PRIVATE_IN_PUBLIC, directive.id, binding.span, msg);
844+
let msg = format!("variant `{}` is private, and cannot be reexported, \
845+
consider declaring its enum as `pub`", ident);
846+
self.session.span_err(binding.span, &msg);
848847
}
849848
}
850849
NameBindingKind::Ambiguity { b1, b2, .. }

src/libsyntax/test.rs

-8
Original file line numberDiff line numberDiff line change
@@ -231,20 +231,12 @@ fn mk_reexport_mod(cx: &mut TestCtxt,
231231
-> (P<ast::Item>, Ident) {
232232
let super_ = Ident::from_str("super");
233233

234-
// Generate imports with `#[allow(private_in_public)]` to work around issue #36768.
235-
let allow_private_in_public = cx.ext_cx.attribute(DUMMY_SP, cx.ext_cx.meta_list(
236-
DUMMY_SP,
237-
Symbol::intern("allow"),
238-
vec![cx.ext_cx.meta_list_item_word(DUMMY_SP, Symbol::intern("private_in_public"))],
239-
));
240234
let items = tests.into_iter().map(|r| {
241235
cx.ext_cx.item_use_simple(DUMMY_SP, ast::Visibility::Public,
242236
cx.ext_cx.path(DUMMY_SP, vec![super_, r]))
243-
.map_attrs(|_| vec![allow_private_in_public.clone()])
244237
}).chain(tested_submods.into_iter().map(|(r, sym)| {
245238
let path = cx.ext_cx.path(DUMMY_SP, vec![super_, r, sym]);
246239
cx.ext_cx.item_use_simple_(DUMMY_SP, ast::Visibility::Public, r, path)
247-
.map_attrs(|_| vec![allow_private_in_public.clone()])
248240
})).collect();
249241

250242
let reexport_mod = ast::Mod {

src/test/compile-fail/associated-types/bound-lifetime-constrained.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#![allow(dead_code)]
1414
#![feature(rustc_attrs)]
15-
#![allow(hr_lifetime_in_assoc_type)]
1615

1716
trait Foo<'a> {
1817
type Item;

0 commit comments

Comments
 (0)