From ecde1e1d3b077f22f75ad34e12e35eef0b6c85f3 Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 7 May 2017 00:14:04 -0700 Subject: Lower `?` to `Try` instead of `Carrier` The easy parts of RFC 1859. (Just the trait and the lowering, none of the error message improvements nor the insta-stable impl for Option.) --- src/test/run-pass/try-operator-custom.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/test') diff --git a/src/test/run-pass/try-operator-custom.rs b/src/test/run-pass/try-operator-custom.rs index 577d19a5896..82ba70c9459 100644 --- a/src/test/run-pass/try-operator-custom.rs +++ b/src/test/run-pass/try-operator-custom.rs @@ -8,20 +8,20 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(question_mark, question_mark_carrier)] +#![feature(try_trait)] -use std::ops::Carrier; +use std::ops::Try; enum MyResult { Awesome(T), Terrible(U) } -impl Carrier for MyResult { - type Success = U; +impl Try for MyResult { + type Ok = U; type Error = V; - fn from_success(u: U) -> MyResult { + fn from_ok(u: U) -> MyResult { MyResult::Awesome(u) } @@ -29,12 +29,10 @@ impl Carrier for MyResult { MyResult::Terrible(e) } - fn translate(self) -> T - where T: Carrier - { + fn into_result(self) -> Result { match self { - MyResult::Awesome(u) => T::from_success(u), - MyResult::Terrible(e) => T::from_error(e), + MyResult::Awesome(u) => Ok(u), + MyResult::Terrible(e) => Err(e), } } } -- cgit 1.4.1-3-g733a5 From a333be7cfecbbe9a659f4f180978fa4dd74d455d Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 29 May 2017 18:46:29 +0200 Subject: Add new error code --- src/librustc/diagnostics.rs | 19 ++++++++++++++++++- src/librustc/middle/entry.rs | 2 +- src/librustc/session/mod.rs | 18 +++++++++++------- src/librustc_errors/lib.rs | 6 ++++++ src/libsyntax/diagnostics/macros.rs | 8 ++++++++ src/test/ui/missing-items/m2.stderr | 2 +- src/test/ui/resolve/issue-14254.stderr | 2 +- src/test/ui/resolve/issue-21221-2.stderr | 2 +- .../suggest-path-instead-of-mod-dot-item.stderr | 2 +- src/test/ui/span/issue-35987.stderr | 2 +- src/test/ui/token/issue-10636-2.stderr | 2 +- src/test/ui/token/issue-41155.stderr | 2 +- 12 files changed, 51 insertions(+), 16 deletions(-) (limited to 'src/test') diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 470dcb4bd61..2beb40d6b2f 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1871,7 +1871,9 @@ makes a difference in practice.) E0593: r##" You tried to supply an `Fn`-based type with an incorrect number of arguments -than what was expected. Erroneous code example: +than what was expected. + +Erroneous code example: ```compile_fail,E0593 fn foo(x: F) { } @@ -1883,6 +1885,21 @@ fn main() { ``` "##, +E0601: r##" +No `main` function was found in a binary crate. To fix this error, just add a +`main` function. For example: + +``` +fn main() { + // Your program will start here. + println!("Hello world!"); +} +``` + +If you don't know the basics of Rust, you can go look to the Rust Book to get +started: https://doc.rust-lang.org/book/ +"##, + } diff --git a/src/librustc/middle/entry.rs b/src/librustc/middle/entry.rs index 24748b6cf65..b26cccf5f16 100644 --- a/src/librustc/middle/entry.rs +++ b/src/librustc/middle/entry.rs @@ -162,7 +162,7 @@ fn configure_main(this: &mut EntryContext) { this.session.entry_type.set(Some(config::EntryMain)); } else { // No main function - let mut err = this.session.struct_err("main function not found"); + let mut err = struct_err!(this.session, E0601, "main function not found"); if !this.non_main_fns.is_empty() { // There were some functions named 'main' though. Try to give the user a hint. err.note("the main function must be defined at the crate level \ diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 28531893659..827fa72f034 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -158,14 +158,14 @@ impl Session { pub fn struct_span_warn<'a, S: Into>(&'a self, sp: S, msg: &str) - -> DiagnosticBuilder<'a> { + -> DiagnosticBuilder<'a> { self.diagnostic().struct_span_warn(sp, msg) } pub fn struct_span_warn_with_code<'a, S: Into>(&'a self, sp: S, msg: &str, code: &str) - -> DiagnosticBuilder<'a> { + -> DiagnosticBuilder<'a> { self.diagnostic().struct_span_warn_with_code(sp, msg, code) } pub fn struct_warn<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> { @@ -174,30 +174,34 @@ impl Session { pub fn struct_span_err<'a, S: Into>(&'a self, sp: S, msg: &str) - -> DiagnosticBuilder<'a> { + -> DiagnosticBuilder<'a> { self.diagnostic().struct_span_err(sp, msg) } pub fn struct_span_err_with_code<'a, S: Into>(&'a self, sp: S, msg: &str, code: &str) - -> DiagnosticBuilder<'a> { + -> DiagnosticBuilder<'a> { self.diagnostic().struct_span_err_with_code(sp, msg, code) } - pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> { + // FIXME: This method should be removed (every error should have an associated error code). + pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> { self.diagnostic().struct_err(msg) } + pub fn struct_err_with_code<'a>(&'a self, msg: &str, code: &str) -> DiagnosticBuilder<'a> { + self.diagnostic().struct_err_with_code(msg, code) + } pub fn struct_span_fatal<'a, S: Into>(&'a self, sp: S, msg: &str) - -> DiagnosticBuilder<'a> { + -> DiagnosticBuilder<'a> { self.diagnostic().struct_span_fatal(sp, msg) } pub fn struct_span_fatal_with_code<'a, S: Into>(&'a self, sp: S, msg: &str, code: &str) - -> DiagnosticBuilder<'a> { + -> DiagnosticBuilder<'a> { self.diagnostic().struct_span_fatal_with_code(sp, msg, code) } pub fn struct_fatal<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> { diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index f7191e49216..d1aaaf4ba7b 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -345,9 +345,15 @@ impl Handler { result.code(code.to_owned()); result } + // FIXME: This method should be removed (every error should have an associated error code). pub fn struct_err<'a>(&'a self, msg: &str) -> DiagnosticBuilder<'a> { DiagnosticBuilder::new(self, Level::Error, msg) } + pub fn struct_err_with_code<'a>(&'a self, msg: &str, code: &str) -> DiagnosticBuilder<'a> { + let mut result = DiagnosticBuilder::new(self, Level::Error, msg); + result.code(code.to_owned()); + result + } pub fn struct_span_fatal<'a, S: Into>(&'a self, sp: S, msg: &str) diff --git a/src/libsyntax/diagnostics/macros.rs b/src/libsyntax/diagnostics/macros.rs index 25e0428248d..13016d72127 100644 --- a/src/libsyntax/diagnostics/macros.rs +++ b/src/libsyntax/diagnostics/macros.rs @@ -38,6 +38,14 @@ macro_rules! span_warn { }) } +#[macro_export] +macro_rules! struct_err { + ($session:expr, $code:ident, $($message:tt)*) => ({ + __diagnostic_used!($code); + $session.struct_err_with_code(&format!($($message)*), stringify!($code)) + }) +} + #[macro_export] macro_rules! span_err_or_warn { ($is_warning:expr, $session:expr, $span:expr, $code:ident, $($message:tt)*) => ({ diff --git a/src/test/ui/missing-items/m2.stderr b/src/test/ui/missing-items/m2.stderr index 26748d18ffa..2d699c66359 100644 --- a/src/test/ui/missing-items/m2.stderr +++ b/src/test/ui/missing-items/m2.stderr @@ -1,4 +1,4 @@ -error: main function not found +error[E0601]: main function not found error[E0046]: not all trait items implemented, missing: `CONSTANT`, `Type`, `method` --> $DIR/m2.rs:20:1 diff --git a/src/test/ui/resolve/issue-14254.stderr b/src/test/ui/resolve/issue-14254.stderr index 8aaad906ea2..009d969fc28 100644 --- a/src/test/ui/resolve/issue-14254.stderr +++ b/src/test/ui/resolve/issue-14254.stderr @@ -142,7 +142,7 @@ error[E0425]: cannot find value `bah` in this scope 133 | bah; | ^^^ did you mean `Self::bah`? -error: main function not found +error[E0601]: main function not found error: aborting due to previous error(s) diff --git a/src/test/ui/resolve/issue-21221-2.stderr b/src/test/ui/resolve/issue-21221-2.stderr index f0b22754e64..b35f1bd2670 100644 --- a/src/test/ui/resolve/issue-21221-2.stderr +++ b/src/test/ui/resolve/issue-21221-2.stderr @@ -7,7 +7,7 @@ error[E0405]: cannot find trait `T` in this scope help: possible candidate is found in another module, you can import it into scope | use foo::bar::T; -error: main function not found +error[E0601]: main function not found error: cannot continue compilation due to previous error diff --git a/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr b/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr index 24cef694737..a34c27a47da 100644 --- a/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr +++ b/src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr @@ -72,7 +72,7 @@ error[E0423]: expected function, found module `a::b` | | | did you mean `I`? -error: main function not found +error[E0601]: main function not found error: aborting due to previous error(s) diff --git a/src/test/ui/span/issue-35987.stderr b/src/test/ui/span/issue-35987.stderr index e53ea6a55af..a2597aba0bd 100644 --- a/src/test/ui/span/issue-35987.stderr +++ b/src/test/ui/span/issue-35987.stderr @@ -7,7 +7,7 @@ error[E0404]: expected trait, found type parameter `Add` help: possible better candidate is found in another module, you can import it into scope | use std::ops::Add; -error: main function not found +error[E0601]: main function not found error: cannot continue compilation due to previous error diff --git a/src/test/ui/token/issue-10636-2.stderr b/src/test/ui/token/issue-10636-2.stderr index faa30dca945..4b0b05ca65a 100644 --- a/src/test/ui/token/issue-10636-2.stderr +++ b/src/test/ui/token/issue-10636-2.stderr @@ -22,7 +22,7 @@ error: expected expression, found `)` 19 | } //~ ERROR: incorrect close delimiter | ^ -error: main function not found +error[E0601]: main function not found error: aborting due to previous error(s) diff --git a/src/test/ui/token/issue-41155.stderr b/src/test/ui/token/issue-41155.stderr index 96c2d764e71..56f71a29953 100644 --- a/src/test/ui/token/issue-41155.stderr +++ b/src/test/ui/token/issue-41155.stderr @@ -12,7 +12,7 @@ error[E0412]: cannot find type `S` in this scope 11 | impl S { | ^ not found in this scope -error: main function not found +error[E0601]: main function not found error: aborting due to previous error(s) -- cgit 1.4.1-3-g733a5 From caecb76f08e1365fe245118c7caa4f6add0f95f5 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 21 May 2017 14:11:08 +0300 Subject: Turn sufficiently old compatibility lints into hard errors --- src/librustc/lint/builtin.rs | 65 ------------------- src/librustc_const_eval/pattern.rs | 21 ++----- src/librustc_lint/lib.rs | 73 +++++++++------------- src/librustc_passes/ast_validation.rs | 25 +++----- src/librustc_resolve/lib.rs | 17 ++--- src/librustc_resolve/resolve_imports.rs | 25 +++----- src/librustc_typeck/collect.rs | 9 +-- src/libsyntax/test.rs | 8 --- .../associated-types/bound-lifetime-constrained.rs | 1 - .../bound-lifetime-in-return-only.rs | 1 - src/test/compile-fail/extern-crate-visibility.rs | 6 -- .../compile-fail/future-incompatible-lint-group.rs | 18 ++++++ .../generic-impl-less-params-with-defaults.rs | 2 +- .../generic-impl-more-params-with-defaults.rs | 2 +- src/test/compile-fail/issue-1920-1.rs | 2 +- src/test/compile-fail/issue-1920-3.rs | 2 +- src/test/compile-fail/issue-6804.rs | 2 - src/test/compile-fail/lifetime-underscore.rs | 4 -- src/test/compile-fail/match-argm-statics-2.rs | 2 + .../privacy/restricted/struct-literal-field.rs | 1 - src/test/compile-fail/privacy/restricted/test.rs | 1 - src/test/compile-fail/private-in-public-lint.rs | 2 - .../private-variant-and-crate-reexport.rs | 40 ------------ src/test/compile-fail/private-variant-reexport.rs | 29 +++++++++ .../compile-fail/pub-reexport-priv-extern-crate.rs | 31 +++++++++ src/test/compile-fail/resolve-self-in-impl.rs | 1 - src/test/compile-fail/rfc1445/feature-gate.rs | 3 +- .../rfc1445/match-forbidden-without-eq.rs | 5 -- .../match-requires-both-partialeq-and-eq.rs | 4 -- .../compile-fail/type-parameter-invalid-lint.rs | 5 -- src/test/compile-fail/use-super-global-path.rs | 2 - src/test/run-pass/issue-37020.rs | 25 -------- 32 files changed, 143 insertions(+), 291 deletions(-) create mode 100644 src/test/compile-fail/future-incompatible-lint-group.rs delete mode 100644 src/test/compile-fail/private-variant-and-crate-reexport.rs create mode 100644 src/test/compile-fail/private-variant-reexport.rs create mode 100644 src/test/compile-fail/pub-reexport-priv-extern-crate.rs delete mode 100644 src/test/run-pass/issue-37020.rs (limited to 'src/test') diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 0bc1be70174..5a88731f16c 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -130,68 +130,12 @@ declare_lint! { "detect private items in public interfaces not caught by the old implementation" } -declare_lint! { - pub INACCESSIBLE_EXTERN_CRATE, - Deny, - "use of inaccessible extern crate erroneously allowed" -} - -declare_lint! { - pub INVALID_TYPE_PARAM_DEFAULT, - Deny, - "type parameter default erroneously allowed in invalid location" -} - -declare_lint! { - pub ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN, - Deny, - "floating-point constants cannot be used in patterns" -} - -declare_lint! { - pub ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN, - Deny, - "constants of struct or enum type can only be used in a pattern if \ - the struct or enum has `#[derive(PartialEq, Eq)]`" -} - -declare_lint! { - pub RAW_POINTER_DERIVE, - Warn, - "uses of #[derive] with raw pointers are rarely correct" -} - -declare_lint! { - pub HR_LIFETIME_IN_ASSOC_TYPE, - Deny, - "binding for associated type references higher-ranked lifetime \ - that does not appear in the trait input types" -} - -declare_lint! { - pub OVERLAPPING_INHERENT_IMPLS, - Deny, - "two overlapping inherent impls define an item with the same name were erroneously allowed" -} - declare_lint! { pub RENAMED_AND_REMOVED_LINTS, Warn, "lints that have been renamed or removed" } -declare_lint! { - pub SUPER_OR_SELF_IN_GLOBAL_PATH, - Deny, - "detects super or self keywords at the beginning of global path" -} - -declare_lint! { - pub LIFETIME_UNDERSCORE, - Deny, - "lifetimes or labels named `'_` were erroneously allowed" -} - declare_lint! { pub RESOLVE_TRAIT_ON_DEFAULTED_UNIT, Warn, @@ -280,17 +224,8 @@ impl LintPass for HardwiredLints { TRIVIAL_CASTS, TRIVIAL_NUMERIC_CASTS, PRIVATE_IN_PUBLIC, - INACCESSIBLE_EXTERN_CRATE, - INVALID_TYPE_PARAM_DEFAULT, - ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN, - ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN, CONST_ERR, - RAW_POINTER_DERIVE, - OVERLAPPING_INHERENT_IMPLS, RENAMED_AND_REMOVED_LINTS, - SUPER_OR_SELF_IN_GLOBAL_PATH, - HR_LIFETIME_IN_ASSOC_TYPE, - LIFETIME_UNDERSCORE, RESOLVE_TRAIT_ON_DEFAULTED_UNIT, SAFE_EXTERN_STATICS, PATTERNS_IN_FNS_WITHOUT_BODY, diff --git a/src/librustc_const_eval/pattern.rs b/src/librustc_const_eval/pattern.rs index e15d63a63c2..a2e0bb80d23 100644 --- a/src/librustc_const_eval/pattern.rs +++ b/src/librustc_const_eval/pattern.rs @@ -10,7 +10,6 @@ use eval; -use rustc::lint; use rustc::middle::const_val::{ConstEvalErr, ConstVal}; use rustc::mir::{Field, BorrowKind, Mutability}; use rustc::ty::{self, TyCtxt, AdtDef, Ty, TypeVariants, Region}; @@ -644,11 +643,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> { debug!("expr={:?} pat_ty={:?} pat_id={}", expr, pat_ty, pat_id); match pat_ty.sty { ty::TyFloat(_) => { - self.tcx.sess.add_lint( - lint::builtin::ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN, - pat_id, - span, - format!("floating point constants cannot be used in patterns")); + self.tcx.sess.span_err(span, "floating point constants cannot be used in patterns"); } ty::TyAdt(adt_def, _) if adt_def.is_union() => { // Matching on union fields is unsafe, we can't hide it in constants @@ -656,15 +651,11 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> { } ty::TyAdt(adt_def, _) => { if !self.tcx.has_attr(adt_def.did, "structural_match") { - self.tcx.sess.add_lint( - lint::builtin::ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN, - pat_id, - span, - format!("to use a constant of type `{}` \ - in a pattern, \ - `{}` must be annotated with `#[derive(PartialEq, Eq)]`", - self.tcx.item_path_str(adt_def.did), - self.tcx.item_path_str(adt_def.did))); + let msg = format!("to use a constant of type `{}` in a pattern, \ + `{}` must be annotated with `#[derive(PartialEq, Eq)]`", + self.tcx.item_path_str(adt_def.did), + self.tcx.item_path_str(adt_def.did)); + self.tcx.sess.span_err(span, &msg); } } _ => { } diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index d8f29768ccd..a5b1d39dd86 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -179,7 +179,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { // - Create a lint defaulting to warn as normal, with ideally the same error // message you would normally give // - Add a suitable reference, typically an RFC or tracking issue. Go ahead - // and include the full URL. + // and include the full URL, sort items in ascending order of issue numbers. // - Later, change lint to error // - Eventually, remove lint store.register_future_incompatible(sess, @@ -189,48 +189,12 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { reference: "issue #34537 ", }, FutureIncompatibleInfo { - id: LintId::of(INACCESSIBLE_EXTERN_CRATE), - reference: "issue #36886 ", - }, - FutureIncompatibleInfo { - id: LintId::of(INVALID_TYPE_PARAM_DEFAULT), - reference: "issue #36887 ", - }, - FutureIncompatibleInfo { - id: LintId::of(SUPER_OR_SELF_IN_GLOBAL_PATH), - reference: "issue #36888 ", - }, - FutureIncompatibleInfo { - id: LintId::of(ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN), - reference: "issue #36890 ", - }, - FutureIncompatibleInfo { - id: LintId::of(ILLEGAL_FLOATING_POINT_LITERAL_PATTERN), - reference: "issue #41620 ", - }, - FutureIncompatibleInfo { - id: LintId::of(ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN), - reference: "issue #36891 ", - }, - FutureIncompatibleInfo { - id: LintId::of(HR_LIFETIME_IN_ASSOC_TYPE), - reference: "issue #33685 ", - }, - FutureIncompatibleInfo { - id: LintId::of(LIFETIME_UNDERSCORE), - reference: "issue #36892 ", - }, - FutureIncompatibleInfo { - id: LintId::of(RESOLVE_TRAIT_ON_DEFAULTED_UNIT), - reference: "issue #39216 ", + id: LintId::of(PATTERNS_IN_FNS_WITHOUT_BODY), + reference: "issue #35203 ", }, FutureIncompatibleInfo { id: LintId::of(SAFE_EXTERN_STATICS), - reference: "issue #36247 ", - }, - FutureIncompatibleInfo { - id: LintId::of(PATTERNS_IN_FNS_WITHOUT_BODY), - reference: "issue #35203 ", + reference: "issue #36247 ", }, FutureIncompatibleInfo { id: LintId::of(EXTRA_REQUIREMENT_IN_IMPL), @@ -248,18 +212,26 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { id: LintId::of(LEGACY_CONSTRUCTOR_VISIBILITY), reference: "issue #39207 ", }, + FutureIncompatibleInfo { + id: LintId::of(RESOLVE_TRAIT_ON_DEFAULTED_UNIT), + reference: "issue #39216 ", + }, FutureIncompatibleInfo { id: LintId::of(MISSING_FRAGMENT_SPECIFIER), reference: "issue #40107 ", }, FutureIncompatibleInfo { - id: LintId::of(PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES), - reference: "issue #42238 ", + id: LintId::of(ILLEGAL_FLOATING_POINT_LITERAL_PATTERN), + reference: "issue #41620 ", }, FutureIncompatibleInfo { id: LintId::of(ANONYMOUS_PARAMETERS), reference: "issue #41686 ", }, + FutureIncompatibleInfo { + id: LintId::of(PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES), + reference: "issue #42238 ", + } ]); // Register renamed and removed lints @@ -275,5 +247,20 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { store.register_removed("drop_with_repr_extern", "drop flags have been removed"); store.register_removed("transmute_from_fn_item_types", "always cast functions before transmuting them"); - store.register_removed("overlapping_inherent_impls", "converted into hard error, see #36889"); + store.register_removed("hr_lifetime_in_assoc_type", + "converted into hard error, see https://github.com/rust-lang/rust/issues/33685"); + store.register_removed("inaccessible_extern_crate", + "converted into hard error, see https://github.com/rust-lang/rust/issues/36886"); + store.register_removed("invalid_type_param_default", + "converted into hard error, see https://github.com/rust-lang/rust/issues/36887"); + store.register_removed("super_or_self_in_global_path", + "converted into hard error, see https://github.com/rust-lang/rust/issues/36888"); + store.register_removed("overlapping_inherent_impls", + "converted into hard error, see https://github.com/rust-lang/rust/issues/36889"); + store.register_removed("illegal_floating_point_constant_pattern", + "converted into hard error, see https://github.com/rust-lang/rust/issues/36890"); + store.register_removed("illegal_struct_or_enum_constant_pattern", + "converted into hard error, see https://github.com/rust-lang/rust/issues/36891"); + store.register_removed("lifetime_underscore", + "converted into hard error, see https://github.com/rust-lang/rust/issues/36892"); } diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 79d90210d47..7c443a4ac75 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -36,16 +36,10 @@ impl<'a> AstValidator<'a> { &self.session.parse_sess.span_diagnostic } - fn check_label(&self, label: Ident, span: Span, id: NodeId) { - if label.name == keywords::StaticLifetime.name() { + fn check_label(&self, label: Ident, span: Span) { + if label.name == keywords::StaticLifetime.name() || label.name == "'_" { self.err_handler().span_err(span, &format!("invalid label name `{}`", label.name)); } - if label.name == "'_" { - self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE, - id, - span, - format!("invalid label name `{}`", label.name)); - } } fn invalid_visibility(&self, vis: &Visibility, span: Span, note: Option<&str>) { @@ -104,10 +98,7 @@ impl<'a> AstValidator<'a> { impl<'a> Visitor<'a> for AstValidator<'a> { fn visit_lifetime(&mut self, lt: &'a Lifetime) { if lt.ident.name == "'_" { - self.session.add_lint(lint::builtin::LIFETIME_UNDERSCORE, - lt.id, - lt.span, - format!("invalid lifetime name `{}`", lt.ident)); + self.err_handler().span_err(lt.span, &format!("invalid lifetime name `{}`", lt.ident)); } visit::walk_lifetime(self, lt) @@ -121,7 +112,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { ExprKind::ForLoop(.., Some(ident)) | ExprKind::Break(Some(ident), _) | ExprKind::Continue(Some(ident)) => { - self.check_label(ident.node, ident.span, expr.id); + self.check_label(ident.node, ident.span); } _ => {} } @@ -169,14 +160,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> { visit::walk_ty(self, ty) } - fn visit_path(&mut self, path: &'a Path, id: NodeId) { + fn visit_path(&mut self, path: &'a Path, _: NodeId) { if path.segments.len() >= 2 && path.is_global() { let ident = path.segments[1].identifier; if token::Ident(ident).is_path_segment_keyword() { - self.session.add_lint(lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH, - id, - path.span, - format!("global paths cannot start with `{}`", ident)); + self.err_handler() + .span_err(path.span, &format!("global paths cannot start with `{}`", ident)); } } diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index f1be821d526..a40c191f7bd 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1069,6 +1069,10 @@ impl<'a> NameBinding<'a> { _ => false, } } + + fn descr(&self) -> &'static str { + if self.is_extern_crate() { "extern crate" } else { self.def().kind_name() } + } } /// Interns the names of the primitive types. @@ -3424,18 +3428,7 @@ impl<'a> Resolver<'a> { for &PrivacyError(span, name, binding) in &self.privacy_errors { if !reported_spans.insert(span) { continue } - if binding.is_extern_crate() { - // Warn when using an inaccessible extern crate. - let node_id = match binding.kind { - NameBindingKind::Import { directive, .. } => directive.id, - _ => unreachable!(), - }; - let msg = format!("extern crate `{}` is private", name); - self.session.add_lint(lint::builtin::INACCESSIBLE_EXTERN_CRATE, node_id, span, msg); - } else { - let def = binding.def(); - self.session.span_err(span, &format!("{} `{}` is private", def.kind_name(), name)); - } + self.session.span_err(span, &format!("{} `{}` is private", binding.descr(), name)); } } diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index c077f507932..8745e51f5b4 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -18,7 +18,6 @@ use {names_to_string, module_to_string}; use {resolve_error, ResolutionError}; use rustc::ty; -use rustc::lint::builtin::PRIVATE_IN_PUBLIC; use rustc::hir::def_id::DefId; use rustc::hir::def::*; use rustc::util::nodemap::FxHashMap; @@ -295,8 +294,7 @@ impl<'a> Resolver<'a> { // return the corresponding binding defined by the import directive. pub fn import(&self, binding: &'a NameBinding<'a>, directive: &'a ImportDirective<'a>) -> &'a NameBinding<'a> { - let vis = if binding.pseudo_vis().is_at_least(directive.vis.get(), self) || - !directive.is_glob() && binding.is_extern_crate() { // c.f. `PRIVATE_IN_PUBLIC` + let vis = if binding.pseudo_vis().is_at_least(directive.vis.get(), self) { directive.vis.get() } else { binding.pseudo_vis() @@ -720,13 +718,7 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { // All namespaces must be re-exported with extra visibility for an error to occur. if !any_successful_reexport { - let (ns, binding) = reexport_error.unwrap(); - if ns == TypeNS && binding.is_extern_crate() { - let msg = format!("extern crate `{}` is private, and cannot be reexported \ - (error E0364), consider declaring with `pub`", - ident); - self.session.add_lint(PRIVATE_IN_PUBLIC, directive.id, directive.span, msg); - } else if ns == TypeNS { + if reexport_error.unwrap().0 == TypeNS { struct_span_err!(self.session, directive.span, E0365, "`{}` is private, and cannot be reexported", ident) .span_label(directive.span, format!("reexport of private `{}`", ident)) @@ -792,8 +784,8 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { self.record_def(directive.id, PathResolution::new(module.def().unwrap())); } - // Miscellaneous post-processing, including recording reexports, reporting conflicts, - // reporting the PRIVATE_IN_PUBLIC lint, and reporting unresolved imports. + // Miscellaneous post-processing, including recording reexports, + // reporting conflicts, and reporting unresolved imports. fn finalize_resolutions_in(&mut self, module: Module<'b>) { // Since import resolution is finished, globs will not define any more names. *module.globs.borrow_mut() = Vec::new(); @@ -838,13 +830,12 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { } match binding.kind { - NameBindingKind::Import { binding: orig_binding, directive, .. } => { + NameBindingKind::Import { binding: orig_binding, .. } => { if ns == TypeNS && orig_binding.is_variant() && !orig_binding.vis.is_at_least(binding.vis, &*self) { - let msg = format!("variant `{}` is private, and cannot be reexported \ - (error E0364), consider declaring its enum as `pub`", - ident); - self.session.add_lint(PRIVATE_IN_PUBLIC, directive.id, binding.span, msg); + let msg = format!("variant `{}` is private, and cannot be reexported, \ + consider declaring its enum as `pub`", ident); + self.session.span_err(binding.span, &msg); } } NameBindingKind::Ambiguity { b1, b2, .. } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index fb3bcd31e21..d7813efdd2f 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -54,7 +54,6 @@ There are some shortcomings in this design: */ use astconv::{AstConv, Bounds}; -use lint; use constrained_type_params as ctp; use middle::lang_items::SizedTraitLangItem; use middle::const_val::ConstVal; @@ -897,12 +896,8 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, if !allow_defaults && p.default.is_some() { if !tcx.sess.features.borrow().default_type_parameter_fallback { - tcx.sess.add_lint( - lint::builtin::INVALID_TYPE_PARAM_DEFAULT, - p.id, - p.span, - format!("defaults for type parameters are only allowed in `struct`, \ - `enum`, `type`, or `trait` definitions.")); + tcx.sess.span_err(p.span, "defaults for type parameters are only allowed in \ + `struct`, `enum`, `type`, or `trait` definitions."); } } diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index 837c3eb0100..a0d1785c6ff 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -231,20 +231,12 @@ fn mk_reexport_mod(cx: &mut TestCtxt, -> (P, Ident) { let super_ = Ident::from_str("super"); - // Generate imports with `#[allow(private_in_public)]` to work around issue #36768. - let allow_private_in_public = cx.ext_cx.attribute(DUMMY_SP, cx.ext_cx.meta_list( - DUMMY_SP, - Symbol::intern("allow"), - vec![cx.ext_cx.meta_list_item_word(DUMMY_SP, Symbol::intern("private_in_public"))], - )); let items = tests.into_iter().map(|r| { cx.ext_cx.item_use_simple(DUMMY_SP, ast::Visibility::Public, cx.ext_cx.path(DUMMY_SP, vec![super_, r])) - .map_attrs(|_| vec![allow_private_in_public.clone()]) }).chain(tested_submods.into_iter().map(|(r, sym)| { let path = cx.ext_cx.path(DUMMY_SP, vec![super_, r, sym]); cx.ext_cx.item_use_simple_(DUMMY_SP, ast::Visibility::Public, r, path) - .map_attrs(|_| vec![allow_private_in_public.clone()]) })).collect(); let reexport_mod = ast::Mod { diff --git a/src/test/compile-fail/associated-types/bound-lifetime-constrained.rs b/src/test/compile-fail/associated-types/bound-lifetime-constrained.rs index 7d04372088b..9ba5045f2a0 100644 --- a/src/test/compile-fail/associated-types/bound-lifetime-constrained.rs +++ b/src/test/compile-fail/associated-types/bound-lifetime-constrained.rs @@ -12,7 +12,6 @@ #![allow(dead_code)] #![feature(rustc_attrs)] -#![allow(hr_lifetime_in_assoc_type)] trait Foo<'a> { type Item; diff --git a/src/test/compile-fail/associated-types/bound-lifetime-in-return-only.rs b/src/test/compile-fail/associated-types/bound-lifetime-in-return-only.rs index 7c1fbfa53d9..b9b1317cef5 100644 --- a/src/test/compile-fail/associated-types/bound-lifetime-in-return-only.rs +++ b/src/test/compile-fail/associated-types/bound-lifetime-in-return-only.rs @@ -13,7 +13,6 @@ #![allow(dead_code)] #![feature(rustc_attrs)] #![feature(unboxed_closures)] -#![deny(hr_lifetime_in_assoc_type)] trait Foo { type Item; diff --git a/src/test/compile-fail/extern-crate-visibility.rs b/src/test/compile-fail/extern-crate-visibility.rs index 81e0cb249f3..6bb88e40910 100644 --- a/src/test/compile-fail/extern-crate-visibility.rs +++ b/src/test/compile-fail/extern-crate-visibility.rs @@ -8,21 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(unused)] - mod foo { extern crate core; } // Check that private crates can be used from outside their modules, albeit with warnings -use foo::core; //~ WARN extern crate `core` is private -//~^ WARN this was previously accepted by the compiler but is being phased out use foo::core::cell; //~ ERROR extern crate `core` is private -//~^ WARN this was previously accepted by the compiler but is being phased out fn f() { foo::core::cell::Cell::new(0); //~ ERROR extern crate `core` is private - //~^ WARN this was previously accepted by the compiler but is being phased out use foo::*; mod core {} // Check that private crates are not glob imported diff --git a/src/test/compile-fail/future-incompatible-lint-group.rs b/src/test/compile-fail/future-incompatible-lint-group.rs new file mode 100644 index 00000000000..e6a39f95e66 --- /dev/null +++ b/src/test/compile-fail/future-incompatible-lint-group.rs @@ -0,0 +1,18 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![deny(future_incompatible)] + +trait Tr { + fn f(u8) {} //~ ERROR use of deprecated anonymous parameter + //~^ WARN this was previously accepted +} + +fn main() {} diff --git a/src/test/compile-fail/generic-impl-less-params-with-defaults.rs b/src/test/compile-fail/generic-impl-less-params-with-defaults.rs index 5fa429445a3..3f5f7bb3a53 100644 --- a/src/test/compile-fail/generic-impl-less-params-with-defaults.rs +++ b/src/test/compile-fail/generic-impl-less-params-with-defaults.rs @@ -13,7 +13,7 @@ use std::marker; struct Foo( marker::PhantomData<(A,B,C)>); -impl Foo { +impl Foo { fn new() -> Foo {Foo(marker::PhantomData)} } diff --git a/src/test/compile-fail/generic-impl-more-params-with-defaults.rs b/src/test/compile-fail/generic-impl-more-params-with-defaults.rs index d3babb8982d..31411992089 100644 --- a/src/test/compile-fail/generic-impl-more-params-with-defaults.rs +++ b/src/test/compile-fail/generic-impl-more-params-with-defaults.rs @@ -15,7 +15,7 @@ struct Heap; struct Vec( marker::PhantomData<(T,A)>); -impl Vec { +impl Vec { fn new() -> Vec {Vec(marker::PhantomData)} } diff --git a/src/test/compile-fail/issue-1920-1.rs b/src/test/compile-fail/issue-1920-1.rs index 8fbe4432204..f829d4645a0 100644 --- a/src/test/compile-fail/issue-1920-1.rs +++ b/src/test/compile-fail/issue-1920-1.rs @@ -11,7 +11,7 @@ //! Test that absolute path names are correct when a crate is not linked into the root namespace mod foo { - extern crate core; + pub extern crate core; } fn assert_clone() where T : Clone { } diff --git a/src/test/compile-fail/issue-1920-3.rs b/src/test/compile-fail/issue-1920-3.rs index dfec48e0a83..2f5da907b95 100644 --- a/src/test/compile-fail/issue-1920-3.rs +++ b/src/test/compile-fail/issue-1920-3.rs @@ -11,7 +11,7 @@ //! Test that when a crate is linked multiple times that the shortest absolute path name is used mod foo { - extern crate core; + pub extern crate core; } extern crate core; diff --git a/src/test/compile-fail/issue-6804.rs b/src/test/compile-fail/issue-6804.rs index f7d3ce60c66..2a97945f266 100644 --- a/src/test/compile-fail/issue-6804.rs +++ b/src/test/compile-fail/issue-6804.rs @@ -19,13 +19,11 @@ fn main() { let x = NAN; match x { NAN => {}, //~ ERROR floating point constants cannot be used - //~| WARNING hard error _ => {}, }; match [x, 1.0] { [NAN, _] => {}, //~ ERROR floating point constants cannot be used - //~| WARNING hard error _ => {}, }; } diff --git a/src/test/compile-fail/lifetime-underscore.rs b/src/test/compile-fail/lifetime-underscore.rs index b768009132c..5b518a4931d 100644 --- a/src/test/compile-fail/lifetime-underscore.rs +++ b/src/test/compile-fail/lifetime-underscore.rs @@ -9,17 +9,13 @@ // except according to those terms. fn _f<'_>() //~ ERROR invalid lifetime name `'_` -//~^ WARN this was previously accepted -> &'_ u8 //~ ERROR invalid lifetime name `'_` - //~^ WARN this was previously accepted { panic!(); } fn main() { '_: loop { //~ ERROR invalid label name `'_` - //~^ WARN this was previously accepted break '_ //~ ERROR invalid label name `'_` - //~^ WARN this was previously accepted } } diff --git a/src/test/compile-fail/match-argm-statics-2.rs b/src/test/compile-fail/match-argm-statics-2.rs index 40dcf3d0f12..70e148627c4 100644 --- a/src/test/compile-fail/match-argm-statics-2.rs +++ b/src/test/compile-fail/match-argm-statics-2.rs @@ -10,8 +10,10 @@ use self::Direction::{North, East, South, West}; +#[derive(PartialEq, Eq)] struct NewBool(bool); +#[derive(PartialEq, Eq)] enum Direction { North, East, diff --git a/src/test/compile-fail/privacy/restricted/struct-literal-field.rs b/src/test/compile-fail/privacy/restricted/struct-literal-field.rs index 68458fe3f04..21d90dfea4b 100644 --- a/src/test/compile-fail/privacy/restricted/struct-literal-field.rs +++ b/src/test/compile-fail/privacy/restricted/struct-literal-field.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![deny(private_in_public)] #![allow(warnings)] mod foo { diff --git a/src/test/compile-fail/privacy/restricted/test.rs b/src/test/compile-fail/privacy/restricted/test.rs index 12697d51042..2e065ac051b 100644 --- a/src/test/compile-fail/privacy/restricted/test.rs +++ b/src/test/compile-fail/privacy/restricted/test.rs @@ -10,7 +10,6 @@ // aux-build:pub_restricted.rs -#![deny(private_in_public)] #![allow(warnings)] extern crate pub_restricted; diff --git a/src/test/compile-fail/private-in-public-lint.rs b/src/test/compile-fail/private-in-public-lint.rs index 030fbfc4914..fd92300cd15 100644 --- a/src/test/compile-fail/private-in-public-lint.rs +++ b/src/test/compile-fail/private-in-public-lint.rs @@ -18,8 +18,6 @@ mod m1 { } mod m2 { - #![deny(future_incompatible)] - pub struct Pub; struct Priv; diff --git a/src/test/compile-fail/private-variant-and-crate-reexport.rs b/src/test/compile-fail/private-variant-and-crate-reexport.rs deleted file mode 100644 index dce533e73fe..00000000000 --- a/src/test/compile-fail/private-variant-and-crate-reexport.rs +++ /dev/null @@ -1,40 +0,0 @@ -// 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![deny(private_in_public)] -#![allow(dead_code)] - -extern crate core; -pub use core as reexported_core; //~ ERROR extern crate `core` is private, and cannot be reexported -//~^ WARNING hard error - -mod m1 { - pub use ::E::V; //~ ERROR variant `V` is private, and cannot be reexported - //~^ WARNING hard error -} - -mod m2 { - pub use ::E::{V}; //~ ERROR variant `V` is private, and cannot be reexported - //~^ WARNING hard error -} - -mod m3 { - pub use ::E::V::{self}; //~ ERROR variant `V` is private, and cannot be reexported - //~^ WARNING hard error -} - -mod m4 { - pub use ::E::*; //~ ERROR variant `V` is private, and cannot be reexported - //~^ WARNING hard error -} - -enum E { V } - -fn main() {} diff --git a/src/test/compile-fail/private-variant-reexport.rs b/src/test/compile-fail/private-variant-reexport.rs new file mode 100644 index 00000000000..c77a7532e34 --- /dev/null +++ b/src/test/compile-fail/private-variant-reexport.rs @@ -0,0 +1,29 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +mod m1 { + pub use ::E::V; //~ ERROR variant `V` is private, and cannot be reexported +} + +mod m2 { + pub use ::E::{V}; //~ ERROR variant `V` is private, and cannot be reexported +} + +mod m3 { + pub use ::E::V::{self}; //~ ERROR variant `V` is private, and cannot be reexported +} + +mod m4 { + pub use ::E::*; //~ ERROR variant `V` is private, and cannot be reexported +} + +enum E { V } + +fn main() {} diff --git a/src/test/compile-fail/pub-reexport-priv-extern-crate.rs b/src/test/compile-fail/pub-reexport-priv-extern-crate.rs new file mode 100644 index 00000000000..1249ba774a8 --- /dev/null +++ b/src/test/compile-fail/pub-reexport-priv-extern-crate.rs @@ -0,0 +1,31 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![allow(unused)] + +extern crate core; +pub use core as reexported_core; //~ ERROR `core` is private, and cannot be reexported + +mod foo1 { + extern crate core; +} + +mod foo2 { + use foo1::core; //~ ERROR `core` is private, and cannot be reexported + pub mod bar { + extern crate core; + } +} + +mod baz { + pub use foo2::bar::core; //~ ERROR `core` is private, and cannot be reexported +} + +fn main() {} diff --git a/src/test/compile-fail/resolve-self-in-impl.rs b/src/test/compile-fail/resolve-self-in-impl.rs index 710d8e11ff0..55ae37404a9 100644 --- a/src/test/compile-fail/resolve-self-in-impl.rs +++ b/src/test/compile-fail/resolve-self-in-impl.rs @@ -17,7 +17,6 @@ trait Tr { impl Tr for S {} // OK impl> Tr for S {} // OK -impl Tr for S {} // OK impl Tr for S where Self: Copy {} // OK impl Tr for S where S: Copy {} // OK impl Tr for S where Self::A: Copy {} // OK diff --git a/src/test/compile-fail/rfc1445/feature-gate.rs b/src/test/compile-fail/rfc1445/feature-gate.rs index b51ee3d8b5e..f729220eabb 100644 --- a/src/test/compile-fail/rfc1445/feature-gate.rs +++ b/src/test/compile-fail/rfc1445/feature-gate.rs @@ -16,8 +16,7 @@ // gate-test-structural_match -#![allow(dead_code)] -#![deny(future_incompatible)] +#![allow(unused)] #![feature(rustc_attrs)] #![cfg_attr(with_gate, feature(structural_match))] diff --git a/src/test/compile-fail/rfc1445/match-forbidden-without-eq.rs b/src/test/compile-fail/rfc1445/match-forbidden-without-eq.rs index c573e3e8e28..679be9ce219 100644 --- a/src/test/compile-fail/rfc1445/match-forbidden-without-eq.rs +++ b/src/test/compile-fail/rfc1445/match-forbidden-without-eq.rs @@ -8,9 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(dead_code)] -#![deny(future_incompatible)] - use std::f32; #[derive(PartialEq)] @@ -25,7 +22,6 @@ fn main() { match y { FOO => { } //~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]` - //~| WARNING will become a hard error _ => { } } @@ -33,7 +29,6 @@ fn main() { match x { f32::INFINITY => { } //~^ ERROR floating point constants cannot be used in patterns - //~| WARNING will become a hard error _ => { } } } diff --git a/src/test/compile-fail/rfc1445/match-requires-both-partialeq-and-eq.rs b/src/test/compile-fail/rfc1445/match-requires-both-partialeq-and-eq.rs index 029df08ebc3..e02f9153e7e 100644 --- a/src/test/compile-fail/rfc1445/match-requires-both-partialeq-and-eq.rs +++ b/src/test/compile-fail/rfc1445/match-requires-both-partialeq-and-eq.rs @@ -8,9 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(dead_code)] -#![deny(future_incompatible)] - #[derive(Eq)] struct Foo { x: u32 @@ -29,7 +26,6 @@ fn main() { match y { FOO => { } //~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]` - //~| WARNING will become a hard error _ => { } } } diff --git a/src/test/compile-fail/type-parameter-invalid-lint.rs b/src/test/compile-fail/type-parameter-invalid-lint.rs index a2c8116c9ba..eea6f22644b 100644 --- a/src/test/compile-fail/type-parameter-invalid-lint.rs +++ b/src/test/compile-fail/type-parameter-invalid-lint.rs @@ -10,16 +10,11 @@ // gate-test-default_type_parameter_fallback -#![deny(future_incompatible)] -#![allow(dead_code)] - fn avg(_: T) {} //~^ ERROR defaults for type parameters are only allowed -//~| WARNING hard error struct S(T); impl S {} //~^ ERROR defaults for type parameters are only allowed -//~| WARNING hard error fn main() {} diff --git a/src/test/compile-fail/use-super-global-path.rs b/src/test/compile-fail/use-super-global-path.rs index 3fa0712fb4c..4162e037cf3 100644 --- a/src/test/compile-fail/use-super-global-path.rs +++ b/src/test/compile-fail/use-super-global-path.rs @@ -15,11 +15,9 @@ struct Z; mod foo { use ::super::{S, Z}; //~ ERROR global paths cannot start with `super` - //~^ WARN this was previously accepted by the compiler but is being phased out pub fn g() { use ::super::main; //~ ERROR global paths cannot start with `super` - //~^ WARN this was previously accepted by the compiler but is being phased out main(); } } diff --git a/src/test/run-pass/issue-37020.rs b/src/test/run-pass/issue-37020.rs deleted file mode 100644 index 7d0d20269ab..00000000000 --- a/src/test/run-pass/issue-37020.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2016 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![allow(private_in_public)] - -mod foo { - pub mod bar { - extern crate core; - } -} - -mod baz { - pub use foo::bar::core; -} - -fn main() { - baz::core::cell::Cell::new(0u32); -} -- cgit 1.4.1-3-g733a5 From d73a0fef381f5c6f4720c152bb7235fe02e502fd Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 21 May 2017 15:50:38 +0300 Subject: Turn public reexporting of private extern crates into a lint again --- src/librustc_resolve/resolve_imports.rs | 12 ++++++++++-- src/test/compile-fail/pub-reexport-priv-extern-crate.rs | 4 ++++ 2 files changed, 14 insertions(+), 2 deletions(-) (limited to 'src/test') diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs index 8745e51f5b4..a892f9df6a6 100644 --- a/src/librustc_resolve/resolve_imports.rs +++ b/src/librustc_resolve/resolve_imports.rs @@ -18,6 +18,7 @@ use {names_to_string, module_to_string}; use {resolve_error, ResolutionError}; use rustc::ty; +use rustc::lint::builtin::PRIVATE_IN_PUBLIC; use rustc::hir::def_id::DefId; use rustc::hir::def::*; use rustc::util::nodemap::FxHashMap; @@ -294,7 +295,8 @@ impl<'a> Resolver<'a> { // return the corresponding binding defined by the import directive. pub fn import(&self, binding: &'a NameBinding<'a>, directive: &'a ImportDirective<'a>) -> &'a NameBinding<'a> { - let vis = if binding.pseudo_vis().is_at_least(directive.vis.get(), self) { + let vis = if binding.pseudo_vis().is_at_least(directive.vis.get(), self) || + !directive.is_glob() && binding.is_extern_crate() { // c.f. `PRIVATE_IN_PUBLIC` directive.vis.get() } else { binding.pseudo_vis() @@ -718,7 +720,13 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> { // All namespaces must be re-exported with extra visibility for an error to occur. if !any_successful_reexport { - if reexport_error.unwrap().0 == TypeNS { + let (ns, binding) = reexport_error.unwrap(); + if ns == TypeNS && binding.is_extern_crate() { + let msg = format!("extern crate `{}` is private, and cannot be reexported \ + (error E0365), consider declaring with `pub`", + ident); + self.session.add_lint(PRIVATE_IN_PUBLIC, directive.id, directive.span, msg); + } else if ns == TypeNS { struct_span_err!(self.session, directive.span, E0365, "`{}` is private, and cannot be reexported", ident) .span_label(directive.span, format!("reexport of private `{}`", ident)) diff --git a/src/test/compile-fail/pub-reexport-priv-extern-crate.rs b/src/test/compile-fail/pub-reexport-priv-extern-crate.rs index 1249ba774a8..185da379694 100644 --- a/src/test/compile-fail/pub-reexport-priv-extern-crate.rs +++ b/src/test/compile-fail/pub-reexport-priv-extern-crate.rs @@ -9,9 +9,11 @@ // except according to those terms. #![allow(unused)] +#![deny(private_in_public)] extern crate core; pub use core as reexported_core; //~ ERROR `core` is private, and cannot be reexported + //~^ WARN this was previously accepted mod foo1 { extern crate core; @@ -19,6 +21,7 @@ mod foo1 { mod foo2 { use foo1::core; //~ ERROR `core` is private, and cannot be reexported + //~^ WARN this was previously accepted pub mod bar { extern crate core; } @@ -26,6 +29,7 @@ mod foo2 { mod baz { pub use foo2::bar::core; //~ ERROR `core` is private, and cannot be reexported + //~^ WARN this was previously accepted } fn main() {} -- cgit 1.4.1-3-g733a5 From 26d5c0e20cbdd27af12a756ddfb1758d0888aad3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 27 May 2017 01:52:25 +0300 Subject: Turn `invalid_type_param_default` into a lint again --- src/librustc/lint/builtin.rs | 7 +++++++ src/librustc_lint/lib.rs | 6 ++++-- src/librustc_typeck/collect.rs | 9 +++++++-- src/test/compile-fail/type-parameter-invalid-lint.rs | 5 +++++ 4 files changed, 23 insertions(+), 4 deletions(-) (limited to 'src/test') diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 5a88731f16c..736c3b289e1 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -130,6 +130,12 @@ declare_lint! { "detect private items in public interfaces not caught by the old implementation" } +declare_lint! { + pub INVALID_TYPE_PARAM_DEFAULT, + Deny, + "type parameter default erroneously allowed in invalid location" +} + declare_lint! { pub RENAMED_AND_REMOVED_LINTS, Warn, @@ -224,6 +230,7 @@ impl LintPass for HardwiredLints { TRIVIAL_CASTS, TRIVIAL_NUMERIC_CASTS, PRIVATE_IN_PUBLIC, + INVALID_TYPE_PARAM_DEFAULT, CONST_ERR, RENAMED_AND_REMOVED_LINTS, RESOLVE_TRAIT_ON_DEFAULTED_UNIT, diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index a5b1d39dd86..9870842a28e 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -196,6 +196,10 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { id: LintId::of(SAFE_EXTERN_STATICS), reference: "issue #36247 ", }, + FutureIncompatibleInfo { + id: LintId::of(INVALID_TYPE_PARAM_DEFAULT), + reference: "issue #36887 ", + }, FutureIncompatibleInfo { id: LintId::of(EXTRA_REQUIREMENT_IN_IMPL), reference: "issue #37166 ", @@ -251,8 +255,6 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { "converted into hard error, see https://github.com/rust-lang/rust/issues/33685"); store.register_removed("inaccessible_extern_crate", "converted into hard error, see https://github.com/rust-lang/rust/issues/36886"); - store.register_removed("invalid_type_param_default", - "converted into hard error, see https://github.com/rust-lang/rust/issues/36887"); store.register_removed("super_or_self_in_global_path", "converted into hard error, see https://github.com/rust-lang/rust/issues/36888"); store.register_removed("overlapping_inherent_impls", diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index d7813efdd2f..fb3bcd31e21 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -54,6 +54,7 @@ There are some shortcomings in this design: */ use astconv::{AstConv, Bounds}; +use lint; use constrained_type_params as ctp; use middle::lang_items::SizedTraitLangItem; use middle::const_val::ConstVal; @@ -896,8 +897,12 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, if !allow_defaults && p.default.is_some() { if !tcx.sess.features.borrow().default_type_parameter_fallback { - tcx.sess.span_err(p.span, "defaults for type parameters are only allowed in \ - `struct`, `enum`, `type`, or `trait` definitions."); + tcx.sess.add_lint( + lint::builtin::INVALID_TYPE_PARAM_DEFAULT, + p.id, + p.span, + format!("defaults for type parameters are only allowed in `struct`, \ + `enum`, `type`, or `trait` definitions.")); } } diff --git a/src/test/compile-fail/type-parameter-invalid-lint.rs b/src/test/compile-fail/type-parameter-invalid-lint.rs index eea6f22644b..c7a1197372d 100644 --- a/src/test/compile-fail/type-parameter-invalid-lint.rs +++ b/src/test/compile-fail/type-parameter-invalid-lint.rs @@ -10,11 +10,16 @@ // gate-test-default_type_parameter_fallback +#![deny(invalid_type_param_default)] +#![allow(unused)] + fn avg(_: T) {} //~^ ERROR defaults for type parameters are only allowed +//~| WARN this was previously accepted struct S(T); impl S {} //~^ ERROR defaults for type parameters are only allowed +//~| WARN this was previously accepted fn main() {} -- cgit 1.4.1-3-g733a5 From 62989c1a0cf0840315becf2ba0a141b9b3a1c62b Mon Sep 17 00:00:00 2001 From: Sean McArthur Date: Tue, 30 May 2017 22:21:00 -0700 Subject: associated_consts: check trait obligations and regionck for associated consts Closes #41323 --- src/librustc_typeck/check/compare_method.rs | 10 +++++++- .../associated-const-generic-obligations.rs | 30 ++++++++++++++++++++++ .../associated-const-impl-wrong-lifetime.rs | 27 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/associated-const-generic-obligations.rs create mode 100644 src/test/compile-fail/associated-const-impl-wrong-lifetime.rs (limited to 'src/test') diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 767cf8f48cf..3121f494850 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -787,6 +787,14 @@ pub fn compare_const_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, diag.emit(); } - // FIXME(#41323) Check the obligations in the fulfillment context. + // Check that all obligations are satisfied by the implementation's + // version. + if let Err(ref errors) = inh.fulfillment_cx.borrow_mut().select_all_or_error(&infcx) { + infcx.report_fulfillment_errors(errors); + return; + } + + let fcx = FnCtxt::new(&inh, impl_c_node_id); + fcx.regionck_item(impl_c_node_id, impl_c_span, &[]); }); } diff --git a/src/test/compile-fail/associated-const-generic-obligations.rs b/src/test/compile-fail/associated-const-generic-obligations.rs new file mode 100644 index 00000000000..90afe8d7336 --- /dev/null +++ b/src/test/compile-fail/associated-const-generic-obligations.rs @@ -0,0 +1,30 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(associated_consts)] + +trait Foo { + type Out: Sized; +} + +impl Foo for String { + type Out = String; +} + +trait Bar: Foo { + const FROM: Self::Out; +} + +impl Bar for T { + const FROM: &'static str = "foo"; + //~^ ERROR the trait bound `T: Foo` is not satisfied [E0277] +} + +fn main() {} diff --git a/src/test/compile-fail/associated-const-impl-wrong-lifetime.rs b/src/test/compile-fail/associated-const-impl-wrong-lifetime.rs new file mode 100644 index 00000000000..834f3460694 --- /dev/null +++ b/src/test/compile-fail/associated-const-impl-wrong-lifetime.rs @@ -0,0 +1,27 @@ +// Copyright 2017 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(associated_consts)] + +trait Foo { + const NAME: &'static str; +} + + +impl<'a> Foo for &'a () { +//~^ NOTE the lifetime 'a as defined + const NAME: &'a str = "unit"; + //~^ ERROR mismatched types [E0308] + //~| NOTE lifetime mismatch + //~| NOTE expected type `&'static str` + //~| NOTE ...does not necessarily outlive the static lifetime +} + +fn main() {} -- cgit 1.4.1-3-g733a5 From 86ea93e83cc0d0dbe59067d0154c6e32e73f094a Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Wed, 31 May 2017 18:02:35 +0100 Subject: rustdoc: Cleanup associated const value rendering Rather than (ab)using Debug for outputting the type in plain text use the alternate format parameter which already does exactly that. This fixes type parameters for example which would output raw HTML. Also cleans up adding parens around references to trait objects. --- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/html/format.rs | 206 ++++++++++----------------------------- src/librustdoc/html/render.rs | 4 +- src/test/rustdoc/assoc-consts.rs | 18 ++++ 4 files changed, 74 insertions(+), 156 deletions(-) (limited to 'src/test') diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 48d387f812d..593477b0665 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1487,7 +1487,7 @@ pub struct PolyTrait { /// A representation of a Type suitable for hyperlinking purposes. Ideally one can get the original /// type out of the AST/TyCtxt given one of these, if more information is needed. Most importantly /// it does not preserve mutability or boxes. -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq)] +#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)] pub enum Type { /// structs/enums/traits (most that'd be an hir::TyPath) ResolvedPath { diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 19a863bdc62..6111ea073dd 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -106,16 +106,6 @@ impl<'a, T: fmt::Display> fmt::Display for CommaSep<'a, T> { } } -impl<'a, T: fmt::Debug> fmt::Debug for CommaSep<'a, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - for (i, item) in self.0.iter().enumerate() { - if i != 0 { write!(f, ", ")?; } - fmt::Debug::fmt(item, f)?; - } - Ok(()) - } -} - impl<'a> fmt::Display for TyParamBounds<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let &TyParamBounds(bounds) = self; @@ -469,8 +459,7 @@ pub fn href(did: DefId) -> Option<(String, ItemType, Vec)> { /// Used when rendering a `ResolvedPath` structure. This invokes the `path` /// rendering function with the necessary arguments for linking to a local path. fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path, - print_all: bool, use_absolute: bool, is_not_debug: bool, - need_paren: bool) -> fmt::Result { + print_all: bool, use_absolute: bool) -> fmt::Result { let empty = clean::PathSegment { name: String::new(), params: clean::PathParameters::Parenthesized { @@ -499,13 +488,9 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path, } else { root.push_str(&seg.name); root.push_str("/"); - if is_not_debug { - write!(w, "{}::", - root, - seg.name)?; - } else { - write!(w, "{}::", seg.name)?; - } + write!(w, "{}::", + root, + seg.name)?; } } } @@ -517,39 +502,21 @@ fn resolved_path(w: &mut fmt::Formatter, did: DefId, path: &clean::Path, } } if w.alternate() { - if is_not_debug { - write!(w, "{:#}{:#}", HRef::new(did, &last.name), last.params)?; - } else { - write!(w, "{:?}{}", HRef::new(did, &last.name), last.params)?; - } + write!(w, "{:#}{:#}", HRef::new(did, &last.name), last.params)?; } else { - if is_not_debug { - let path = if use_absolute { - match href(did) { - Some((_, _, fqp)) => format!("{}::{}", - fqp[..fqp.len()-1].join("::"), - HRef::new(did, fqp.last() - .unwrap_or(&String::new()))), - None => format!("{}", HRef::new(did, &last.name)), + let path = if use_absolute { + match href(did) { + Some((_, _, fqp)) => { + format!("{}::{}", + fqp[..fqp.len() - 1].join("::"), + HRef::new(did, fqp.last().unwrap_or(&String::new()))) } - } else { - format!("{}", HRef::new(did, &last.name)) - }; - write!(w, "{}{}{}", if need_paren { "(" } else { "" }, path, last.params)?; + None => format!("{}", HRef::new(did, &last.name)), + } } else { - let path = if use_absolute { - match href(did) { - Some((_, _, fqp)) => format!("{:?}::{:?}", - fqp[..fqp.len()-1].join("::"), - HRef::new(did, fqp.last() - .unwrap_or(&String::new()))), - None => format!("{:?}", HRef::new(did, &last.name)), - } - } else { - format!("{:?}", HRef::new(did, &last.name)) - }; - write!(w, "{}{}{}", if need_paren { "(" } else { "" }, path, last.params)?; - } + format!("{}", HRef::new(did, &last.name)) + }; + write!(w, "{}{}", path, last.params)?; } Ok(()) } @@ -600,17 +567,13 @@ fn primitive_link(f: &mut fmt::Formatter, /// Helper to render type parameters fn tybounds(w: &mut fmt::Formatter, - typarams: &Option>, - need_paren: bool) -> fmt::Result { + typarams: &Option>) -> fmt::Result { match *typarams { Some(ref params) => { for param in params { write!(w, " + ")?; fmt::Display::fmt(param, w)?; } - if need_paren { - write!(w, ")")?; - } Ok(()) } None => Ok(()) @@ -637,30 +600,18 @@ impl<'a> fmt::Display for HRef<'a> { } } -impl<'a> fmt::Debug for HRef<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.text) - } -} - -fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool, - is_not_debug: bool, is_ref: bool) -> fmt::Result { +fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt::Result { match *t { clean::Generic(ref name) => { f.write_str(name) } clean::ResolvedPath{ did, ref typarams, ref path, is_generic } => { // Paths like T::Output and Self::Output should be rendered with all segments - let need_paren = match *typarams { - Some(ref v) => !v.is_empty(), - _ => false, - } && is_ref; - resolved_path(f, did, path, is_generic, use_absolute, is_not_debug, need_paren)?; - tybounds(f, typarams, need_paren) + resolved_path(f, did, path, is_generic, use_absolute)?; + tybounds(f, typarams) } clean::Infer => write!(f, "_"), - clean::Primitive(prim) if is_not_debug => primitive_link(f, prim, prim.as_str()), - clean::Primitive(prim) => write!(f, "{}", prim.as_str()), + clean::Primitive(prim) => primitive_link(f, prim, prim.as_str()), clean::BareFunction(ref decl) => { if f.alternate() { write!(f, "{}{}fn{:#}{:#}", @@ -678,30 +629,26 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool, } clean::Tuple(ref typs) => { match &typs[..] { - &[] if is_not_debug => primitive_link(f, PrimitiveType::Tuple, "()"), - &[] => write!(f, "()"), - &[ref one] if is_not_debug => { + &[] => primitive_link(f, PrimitiveType::Tuple, "()"), + &[ref one] => { primitive_link(f, PrimitiveType::Tuple, "(")?; //carry f.alternate() into this display w/o branching manually fmt::Display::fmt(one, f)?; primitive_link(f, PrimitiveType::Tuple, ",)") } - &[ref one] => write!(f, "({:?},)", one), - many if is_not_debug => { + many => { primitive_link(f, PrimitiveType::Tuple, "(")?; fmt::Display::fmt(&CommaSep(&many), f)?; primitive_link(f, PrimitiveType::Tuple, ")") } - many => write!(f, "({:?})", &CommaSep(&many)), } } - clean::Vector(ref t) if is_not_debug => { + clean::Vector(ref t) => { primitive_link(f, PrimitiveType::Slice, "[")?; fmt::Display::fmt(t, f)?; primitive_link(f, PrimitiveType::Slice, "]") } - clean::Vector(ref t) => write!(f, "[{:?}]", t), - clean::FixedVector(ref t, ref s) if is_not_debug => { + clean::FixedVector(ref t, ref s) => { primitive_link(f, PrimitiveType::Array, "[")?; fmt::Display::fmt(t, f)?; if f.alternate() { @@ -712,17 +659,10 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool, &format!("; {}]", Escape(s))) } } - clean::FixedVector(ref t, ref s) => { - if f.alternate() { - write!(f, "[{:?}; {}]", t, s) - } else { - write!(f, "[{:?}; {}]", t, Escape(s)) - } - } clean::Never => f.write_str("!"), clean::RawPointer(m, ref t) => { match **t { - clean::Generic(_) | clean::ResolvedPath {is_generic: true, ..} if is_not_debug => { + clean::Generic(_) | clean::ResolvedPath {is_generic: true, ..} => { if f.alternate() { primitive_link(f, clean::PrimitiveType::RawPointer, &format!("*{}{:#}", RawMutableSpace(m), t)) @@ -731,21 +671,11 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool, &format!("*{}{}", RawMutableSpace(m), t)) } } - clean::Generic(_) | clean::ResolvedPath {is_generic: true, ..} => { - if f.alternate() { - write!(f, "*{}{:#?}", RawMutableSpace(m), t) - } else { - write!(f, "*{}{:?}", RawMutableSpace(m), t) - } - } - _ if is_not_debug => { + _ => { primitive_link(f, clean::PrimitiveType::RawPointer, &format!("*{}", RawMutableSpace(m)))?; fmt::Display::fmt(t, f) } - _ => { - write!(f, "*{}{:?}", RawMutableSpace(m), t) - } } } clean::BorrowedRef{ lifetime: ref l, mutability, type_: ref ty} => { @@ -757,7 +687,7 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool, match **ty { clean::Vector(ref bt) => { // BorrowedRef{ ... Vector(T) } is &[T] match **bt { - clean::Generic(_) if is_not_debug => { + clean::Generic(_) => { if f.alternate() { primitive_link(f, PrimitiveType::Slice, &format!("&{}{}[{:#}]", lt, m, **bt)) @@ -766,14 +696,7 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool, &format!("&{}{}[{}]", lt, m, **bt)) } } - clean::Generic(_) => { - if f.alternate() { - write!(f, "&{}{}[{:#?}]", lt, m, **bt) - } else { - write!(f, "&{}{}[{:?}]", lt, m, **bt) - } - } - _ if is_not_debug => { + _ => { if f.alternate() { primitive_link(f, PrimitiveType::Slice, &format!("&{}{}[", lt, m))?; @@ -785,26 +708,25 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool, } primitive_link(f, PrimitiveType::Slice, "]") } - _ => { - if f.alternate() { - write!(f, "&{}{}[{:#?}]", lt, m, **bt) - } else { - write!(f, "&{}{}[{:?}]", lt, m, **bt) - } - } } } + clean::ResolvedPath { typarams: Some(ref v), .. } if !v.is_empty() => { + if f.alternate() { + write!(f, "&{}{}", lt, m)?; + } else { + write!(f, "&{}{}", lt, m)?; + } + write!(f, "(")?; + fmt_type(&ty, f, use_absolute)?; + write!(f, ")") + } _ => { if f.alternate() { write!(f, "&{}{}", lt, m)?; - fmt_type(&ty, f, use_absolute, is_not_debug, true) + fmt_type(&ty, f, use_absolute) } else { - if is_not_debug { - write!(f, "&{}{}", lt, m)?; - } else { - write!(f, "&{}{}", lt, m)?; - } - fmt_type(&ty, f, use_absolute, is_not_debug, true) + write!(f, "&{}{}", lt, m)?; + fmt_type(&ty, f, use_absolute) } } } @@ -833,32 +755,16 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool, _ => true, }; if f.alternate() { - if is_not_debug { - if should_show_cast { - write!(f, "<{:#} as {:#}>::", self_type, trait_)? - } else { - write!(f, "{:#}::", self_type)? - } + if should_show_cast { + write!(f, "<{:#} as {:#}>::", self_type, trait_)? } else { - if should_show_cast { - write!(f, "<{:#?} as {:#?}>::", self_type, trait_)? - } else { - write!(f, "{:#?}::", self_type)? - } + write!(f, "{:#}::", self_type)? } } else { - if is_not_debug { - if should_show_cast { - write!(f, "<{} as {}>::", self_type, trait_)? - } else { - write!(f, "{}::", self_type)? - } + if should_show_cast { + write!(f, "<{} as {}>::", self_type, trait_)? } else { - if should_show_cast { - write!(f, "<{:?} as {:?}>::", self_type, trait_)? - } else { - write!(f, "{:?}::", self_type)? - } + write!(f, "{}::", self_type)? } }; match *trait_ { @@ -874,7 +780,7 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool, // look at). box clean::ResolvedPath { did, ref typarams, .. } => { let path = clean::Path::singleton(name.clone()); - resolved_path(f, did, &path, true, use_absolute, is_not_debug, false)?; + resolved_path(f, did, &path, true, use_absolute)?; // FIXME: `typarams` are not rendered, and this seems bad? drop(typarams); @@ -893,13 +799,7 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool, impl fmt::Display for clean::Type { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt_type(self, f, false, true, false) - } -} - -impl fmt::Debug for clean::Type { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt_type(self, f, false, false, false) + fmt_type(self, f, false) } } @@ -933,7 +833,7 @@ fn fmt_impl(i: &clean::Impl, write!(f, " for ")?; } - fmt_type(&i.for_, f, use_absolute, true, false)?; + fmt_type(&i.for_, f, use_absolute)?; fmt::Display::fmt(&WhereClause { gens: &i.generics, indent: 0, end_newline: true }, f)?; Ok(()) @@ -1139,7 +1039,7 @@ impl fmt::Display for clean::Import { impl fmt::Display for clean::ImportSource { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.did { - Some(did) => resolved_path(f, did, &self.path, true, false, true, false), + Some(did) => resolved_path(f, did, &self.path, true, false), _ => { for (i, seg) in self.path.segments.iter().enumerate() { if i > 0 { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index fa9315054a1..a588460d467 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1662,9 +1662,9 @@ fn md_render_assoc_item(item: &clean::Item) -> String { match item.inner { clean::AssociatedConstItem(ref ty, ref default) => { if let Some(default) = default.as_ref() { - format!("```\n{}: {:?} = {}\n```\n\n", item.name.as_ref().unwrap(), ty, default) + format!("```\n{}: {:#} = {}\n```\n\n", item.name.as_ref().unwrap(), ty, default) } else { - format!("```\n{}: {:?}\n```\n\n", item.name.as_ref().unwrap(), ty) + format!("```\n{}: {:#}\n```\n\n", item.name.as_ref().unwrap(), ty) } } _ => String::new(), diff --git a/src/test/rustdoc/assoc-consts.rs b/src/test/rustdoc/assoc-consts.rs index d4119f5d351..04709407e58 100644 --- a/src/test/rustdoc/assoc-consts.rs +++ b/src/test/rustdoc/assoc-consts.rs @@ -26,3 +26,21 @@ impl Bar { // @has - '//*[@class="docblock"]' 'BAR: usize = 3' pub const BAR: usize = 3; } + +pub struct Baz<'a, U: 'a, T>(T, &'a [U]); + +impl Bar { + // @has assoc_consts/struct.Bar.html '//*[@id="associatedconstant.BAZ"]' \ + // "const BAZ: Baz<'static, u8, u32>" + // @has - '//*[@class="docblock"]' "BAZ: Baz<'static, u8, u32> = Baz(321, &[1, 2, 3])" + pub const BAZ: Baz<'static, u8, u32> = Baz(321, &[1, 2, 3]); +} + +pub fn f(_: &(ToString + 'static)) {} + +impl Bar { + // @has assoc_consts/struct.Bar.html '//*[@id="associatedconstant.F"]' \ + // "const F: fn(_: &(ToString + 'static))" + // @has - '//*[@class="docblock"]' "F: fn(_: &(ToString + 'static)) = f" + pub const F: fn(_: &(ToString + 'static)) = f; +} -- cgit 1.4.1-3-g733a5