Skip to content

Commit

Permalink
convert from hard error to future-incompatible lint
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jan 5, 2016
1 parent 27d6b9d commit 6dd3f61
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
7 changes: 7 additions & 0 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ declare_lint! {
"detect private items in public interfaces not caught by the old implementation"
}

declare_lint! {
pub INVALID_TYPE_PARAM_DEFAULT,
Warn,
"type parameter default erroneously allowed in invalid location"
}

/// Does nothing as a lint pass, but registers some `Lint`s
/// which are used by other parts of the compiler.
#[derive(Copy, Clone)]
Expand All @@ -152,6 +158,7 @@ impl LintPass for HardwiredLints {
TRIVIAL_CASTS,
TRIVIAL_NUMERIC_CASTS,
PRIVATE_IN_PUBLIC,
INVALID_TYPE_PARAM_DEFAULT,
CONST_ERR
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
UNUSED_MUT, UNREACHABLE_CODE, UNUSED_MUST_USE,
UNUSED_UNSAFE, PATH_STATEMENTS, UNUSED_ATTRIBUTES);

add_lint_group!(sess, "future_incompatible",
PRIVATE_IN_PUBLIC);
add_lint_group!(sess, FUTURE_INCOMPATIBLE,
PRIVATE_IN_PUBLIC, INVALID_TYPE_PARAM_DEFAULT);

// We have one lint pass defined specially
store.register_late_pass(sess, false, box lint::GatherNodeLevels);
Expand Down
15 changes: 7 additions & 8 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ There are some shortcomings in this design:
*/

use astconv::{self, AstConv, ty_of_arg, ast_ty_to_ty, ast_region_to_region};
use lint;
use middle::def;
use middle::def_id::DefId;
use constrained_type_params as ctp;
Expand Down Expand Up @@ -92,7 +93,6 @@ use syntax::abi;
use syntax::ast;
use syntax::attr;
use syntax::codemap::Span;
use syntax::feature_gate::{GateIssue, emit_feature_err};
use syntax::parse::token::special_idents;
use syntax::ptr::P;
use rustc_front::hir;
Expand Down Expand Up @@ -1936,13 +1936,12 @@ fn get_or_create_type_parameter_def<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,

if space != TypeSpace && default.is_some() {
if !tcx.sess.features.borrow().default_type_parameter_fallback {
emit_feature_err(&tcx.sess.parse_sess.span_diagnostic,
"default_type_parameter_fallback",
param.span,
GateIssue::Language,
"other than on a `struct` or `enum` definition, \
defaults for type parameters are experimental \
and known to be buggy");
tcx.sess.add_lint(
lint::builtin::INVALID_TYPE_PARAM_DEFAULT,
param.id,
param.span,
format!("defaults for type parameters are only allowed \
on `struct` or `enum` definitions (see issue #27336)"));
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/test/compile-fail/type-parameter-invalid-lint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![deny(future_incompatible)]
#![allow(dead_code)]

fn avg<T=i32>(_: T) {}
//~^ ERROR defaults for type parameters are only allowed
//~| NOTE HARD ERROR
fn main() {}

0 comments on commit 6dd3f61

Please sign in to comment.