From d1ed6cce6ca875b3902f34c9979cf75afa403fed Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 18 Feb 2018 19:37:07 +0100 Subject: [PATCH 1/5] Lint passes: add check_where_predicate and check_poly_trait_ref --- src/librustc/lint/context.rs | 21 +++++++++++++++++++++ src/librustc/lint/mod.rs | 6 ++++++ 2 files changed, 27 insertions(+) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index ed937046e5ed7..010534d6bf828 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -793,6 +793,17 @@ impl<'a, 'tcx> hir_visit::Visitor<'tcx> for LateContext<'a, 'tcx> { hir_visit::walk_generics(self, g); } + fn visit_where_predicate(&mut self, p: &'tcx hir::WherePredicate) { + run_lints!(self, check_where_predicate, late_passes, p); + hir_visit::walk_where_predicate(self, p); + } + + fn visit_poly_trait_ref(&mut self, t: &'tcx hir::PolyTraitRef, + m: hir::TraitBoundModifier) { + run_lints!(self, check_poly_trait_ref, late_passes, t, m); + hir_visit::walk_poly_trait_ref(self, t, m); + } + fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { let generics = self.generics.take(); self.generics = Some(&trait_item.generics); @@ -955,6 +966,16 @@ impl<'a> ast_visit::Visitor<'a> for EarlyContext<'a> { ast_visit::walk_generics(self, g); } + fn visit_where_predicate(&mut self, p: &'a ast::WherePredicate) { + run_lints!(self, check_where_predicate, early_passes, p); + ast_visit::walk_where_predicate(self, p); + } + + fn visit_poly_trait_ref(&mut self, t: &'a ast::PolyTraitRef, m: &'a ast::TraitBoundModifier) { + run_lints!(self, check_poly_trait_ref, early_passes, t, m); + ast_visit::walk_poly_trait_ref(self, t, m); + } + fn visit_trait_item(&mut self, trait_item: &'a ast::TraitItem) { self.with_lint_attrs(trait_item.id, &trait_item.attrs, |cx| { run_lints!(cx, check_trait_item, early_passes, trait_item); diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index b2a9859f68a3e..ecaeaf52f5802 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -158,6 +158,9 @@ pub trait LateLintPass<'a, 'tcx>: LintPass { fn check_ty(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Ty) { } fn check_generic_param(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::GenericParam) { } fn check_generics(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::Generics) { } + fn check_where_predicate(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::WherePredicate) { } + fn check_poly_trait_ref(&mut self, _: &LateContext<'a, 'tcx>, _: &'tcx hir::PolyTraitRef, + _: hir::TraitBoundModifier) { } fn check_fn(&mut self, _: &LateContext<'a, 'tcx>, _: FnKind<'tcx>, @@ -230,6 +233,9 @@ pub trait EarlyLintPass: LintPass { fn check_ty(&mut self, _: &EarlyContext, _: &ast::Ty) { } fn check_generic_param(&mut self, _: &EarlyContext, _: &ast::GenericParam) { } fn check_generics(&mut self, _: &EarlyContext, _: &ast::Generics) { } + fn check_where_predicate(&mut self, _: &EarlyContext, _: &ast::WherePredicate) { } + fn check_poly_trait_ref(&mut self, _: &EarlyContext, _: &ast::PolyTraitRef, + _: &ast::TraitBoundModifier) { } fn check_fn(&mut self, _: &EarlyContext, _: ast_visit::FnKind, _: &ast::FnDecl, _: Span, _: ast::NodeId) { } fn check_fn_post(&mut self, _: &EarlyContext, From 86821f7fb6afbbfebd2d7b0a681d14c4cf6a578e Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 18 Feb 2018 19:40:35 +0100 Subject: [PATCH 2/5] add lint to detect ignored generic bounds; this subsumes the previous 'generic bounds in type aliases are ignored' warning --- src/librustc_lint/builtin.rs | 94 ++++++++++++++++++++++++ src/librustc_lint/lib.rs | 1 + src/librustc_typeck/collect.rs | 41 +---------- src/librustc_typeck/diagnostics.rs | 21 +----- src/libsyntax/ast.rs | 19 +++++ src/test/ui/param-bounds-ignored.rs | 79 +++++++++++++++++++- src/test/ui/param-bounds-ignored.stderr | 98 ++++++++++++++++++++++--- 7 files changed, 277 insertions(+), 76 deletions(-) diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index de55710bdf3d0..2452bda8d4372 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1386,3 +1386,97 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnreachablePub { self.perform_lint(cx, "item", impl_item.id, &impl_item.vis, impl_item.span, false); } } + +/// Lint for trait and lifetime bounds that are (accidentally) accepted by the parser, but +/// ignored later. + +pub struct IgnoredGenericBounds; + +declare_lint! { + IGNORED_GENERIC_BOUNDS, + Warn, + "these generic bounds are ignored" +} + +impl LintPass for IgnoredGenericBounds { + fn get_lints(&self) -> LintArray { + lint_array!(IGNORED_GENERIC_BOUNDS) + } +} + +impl IgnoredGenericBounds { + fn ensure_no_param_bounds( + cx: &EarlyContext, + generics: &Vec, + thing: &'static str, + ) { + for param in generics.iter() { + match param { + &ast::GenericParam::Lifetime(ref lifetime) => { + if !lifetime.bounds.is_empty() { + let spans : Vec<_> = lifetime.bounds.iter().map(|b| b.span).collect(); + cx.span_lint( + IGNORED_GENERIC_BOUNDS, + spans, + format!("bounds on generic lifetime parameters are ignored in {}", + thing).as_ref() + ); + } + } + &ast::GenericParam::Type(ref ty) => { + if !ty.bounds.is_empty() { + let spans : Vec<_> = ty.bounds.iter().map(|b| b.span()).collect(); + cx.span_lint( + IGNORED_GENERIC_BOUNDS, + spans, + format!("bounds on generic type parameters are ignored in {}", thing) + .as_ref() + ); + } + } + } + } + } +} + +impl EarlyLintPass for IgnoredGenericBounds { + fn check_item(&mut self, cx: &EarlyContext, item: &ast::Item) { + match item.node { + ast::ItemKind::Ty(_, ref generics) => { + if !generics.where_clause.predicates.is_empty() { + let spans : Vec<_> = generics.where_clause.predicates.iter() + .map(|pred| pred.span()).collect(); + cx.span_lint(IGNORED_GENERIC_BOUNDS, spans, + "where clauses are ignored in type aliases"); + } + IgnoredGenericBounds::ensure_no_param_bounds(cx, &generics.params, + "type aliases"); + } + _ => {} + } + } + + fn check_where_predicate(&mut self, cx: &EarlyContext, p: &ast::WherePredicate) { + if let &ast::WherePredicate::BoundPredicate(ref bound_predicate) = p { + // A type binding, eg `for<'c> Foo: Send+Clone+'c` + IgnoredGenericBounds::ensure_no_param_bounds(cx, + &bound_predicate.bound_generic_params, "higher-ranked trait bounds (i.e., `for`)"); + } + } + + fn check_poly_trait_ref(&mut self, cx: &EarlyContext, t: &ast::PolyTraitRef, + _: &ast::TraitBoundModifier) { + IgnoredGenericBounds::ensure_no_param_bounds(cx, &t.bound_generic_params, + "higher-ranked trait bounds (i.e., `for`)"); + } + + fn check_ty(&mut self, cx: &EarlyContext, ty: &ast::Ty) { + match ty.node { + ast::TyKind::BareFn(ref fn_ty) => { + IgnoredGenericBounds::ensure_no_param_bounds(cx, &fn_ty.generic_params, + "higher-ranked function types (i.e., `for`)"); + } + _ => {} + } + } +} diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index f3c6ff2f2b3a1..de1b79259ddf5 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -109,6 +109,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) { AnonymousParameters, IllegalFloatLiteralPattern, UnusedDocComment, + IgnoredGenericBounds, ); add_early_builtin_with_new!(sess, diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 1c8d22e4666a6..d0424c520887e 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -355,39 +355,6 @@ fn is_param<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } } -fn ensure_no_param_bounds(tcx: TyCtxt, - span: Span, - generics: &hir::Generics, - thing: &'static str) { - let mut warn = false; - - for ty_param in generics.ty_params() { - if !ty_param.bounds.is_empty() { - warn = true; - } - } - - for lft_param in generics.lifetimes() { - if !lft_param.bounds.is_empty() { - warn = true; - } - } - - if !generics.where_clause.predicates.is_empty() { - warn = true; - } - - if warn { - // According to accepted RFC #XXX, we should - // eventually accept these, but it will not be - // part of this PR. Still, convert to warning to - // make bootstrapping easier. - span_warn!(tcx.sess, span, E0122, - "generic bounds are ignored in {}", - thing); - } -} - fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) { let it = tcx.hir.expect_item(item_id); debug!("convert: item {} with id {}", it.name, it.id); @@ -448,13 +415,7 @@ fn convert_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, item_id: ast::NodeId) { convert_variant_ctor(tcx, struct_def.id()); } }, - hir::ItemTy(_, ref generics) => { - ensure_no_param_bounds(tcx, it.span, generics, "type aliases"); - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); - } - hir::ItemStatic(..) | hir::ItemConst(..) | hir::ItemFn(..) => { + hir::ItemTy(..) | hir::ItemStatic(..) | hir::ItemConst(..) | hir::ItemFn(..) => { tcx.generics_of(def_id); tcx.type_of(def_id); tcx.predicates_of(def_id); diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 1c0e084832ebc..617f7615fb979 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1524,26 +1524,6 @@ static BAR: _ = "test"; // error, explicitly write out the type instead ``` "##, -E0122: r##" -An attempt was made to add a generic constraint to a type alias. This constraint -is entirely ignored. For backwards compatibility, Rust still allows this with a -warning. Consider the example below: - -``` -trait Foo{} - -type MyType = (R, ()); - -fn main() { - let t: MyType; -} -``` - -We're able to declare a variable of type `MyType`, despite the fact that -`u32` does not implement `Foo`. As a result, one should avoid using generic -constraints in concert with type aliases. -"##, - E0124: r##" You declared two fields of a struct with the same name. Erroneous code example: @@ -4758,6 +4738,7 @@ register_diagnostics! { // E0086, // E0103, // E0104, +// E0122, // bounds in type aliases are ignored, turned into proper lint // E0123, // E0127, // E0129, diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 6609b77b132c6..245025d3e4f75 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -294,6 +294,15 @@ pub enum TyParamBound { RegionTyParamBound(Lifetime) } +impl TyParamBound { + pub fn span(&self) -> Span { + match self { + &TraitTyParamBound(ref t, ..) => t.span, + &RegionTyParamBound(ref l) => l.span, + } + } +} + /// A modifier on a bound, currently this is only used for `?Sized`, where the /// modifier is `Maybe`. Negative bounds should also be handled here. #[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] @@ -404,6 +413,16 @@ pub enum WherePredicate { EqPredicate(WhereEqPredicate), } +impl WherePredicate { + pub fn span(&self) -> Span { + match self { + &WherePredicate::BoundPredicate(ref p) => p.span, + &WherePredicate::RegionPredicate(ref p) => p.span, + &WherePredicate::EqPredicate(ref p) => p.span, + } + } +} + /// A type bound. /// /// E.g. `for<'c> Foo: Send+Clone+'c` diff --git a/src/test/ui/param-bounds-ignored.rs b/src/test/ui/param-bounds-ignored.rs index 9e09102f2d439..a136ec60252b4 100644 --- a/src/test/ui/param-bounds-ignored.rs +++ b/src/test/ui/param-bounds-ignored.rs @@ -9,12 +9,18 @@ // except according to those terms. // must-compile-successfully +#![allow(dead_code, non_camel_case_types)] use std::rc::Rc; -type SVec = Vec; -type VVec<'b, 'a: 'b> = Vec<&'a i32>; -type WVec<'b, T: 'b> = Vec; +type SVec = Vec; +//~^ WARN bounds on generic type parameters are ignored in type aliases +type VVec<'b, 'a: 'b+'b> = Vec<&'a i32>; +//~^ WARN bounds on generic lifetime parameters are ignored in type aliases +type WVec<'b, T: 'b+'b> = Vec; +//~^ WARN bounds on generic type parameters are ignored in type aliases +type W2Vec<'b, T> where T: 'b, T: 'b = Vec; +//~^ WARN where clauses are ignored in type aliases fn foo<'a>(y: &'a i32) { // If the bounds above would matter, the code below would be rejected. @@ -26,8 +32,73 @@ fn foo<'a>(y: &'a i32) { let mut x : WVec<'static, & 'a i32> = Vec::new(); x.push(y); + + let mut x : W2Vec<'static, & 'a i32> = Vec::new(); + x.push(y); +} + +fn bar1<'a, 'b>( + x: &'a i32, + y: &'b i32, + f: for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32) + //~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked function types +{ + // If the bound in f's type would matter, the call below would (have to) + // be rejected. + f(x, y); } +fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>( + //~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds + x: &'a i32, + y: &'b i32, + f: F) +{ + // If the bound in f's type would matter, the call below would (have to) + // be rejected. + f(x, y); +} + +fn bar3<'a, 'b, F>( + x: &'a i32, + y: &'b i32, + f: F) + where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32 + //~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds +{ + // If the bound in f's type would matter, the call below would (have to) + // be rejected. + f(x, y); +} + +fn bar4<'a, 'b, F>( + x: &'a i32, + y: &'b i32, + f: F) + where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32 + //~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds +{ + // If the bound in f's type would matter, the call below would (have to) + // be rejected. + f(x, y); +} + +struct S1 Fn(&'xa i32, &'xb i32) -> &'xa i32>(F); +//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds +struct S2(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32; +//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds +struct S3(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32; +//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds + +struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32); +//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked function types + +type T1 = Box Fn(&'xa i32, &'xb i32) -> &'xa i32>; +//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds + fn main() { - foo(&42); + let _ : Option fn(&'xa i32, &'xb i32) -> &'xa i32> = None; + //~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked function types + let _ : Option Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None; + //~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds } diff --git a/src/test/ui/param-bounds-ignored.stderr b/src/test/ui/param-bounds-ignored.stderr index fe5986448fa1d..55df5d1c93941 100644 --- a/src/test/ui/param-bounds-ignored.stderr +++ b/src/test/ui/param-bounds-ignored.stderr @@ -1,18 +1,92 @@ -warning[E0122]: generic bounds are ignored in type aliases - --> $DIR/param-bounds-ignored.rs:15:1 +warning: bounds on generic type parameters are ignored in type aliases + --> $DIR/param-bounds-ignored.rs:16:14 | -LL | type SVec = Vec; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | type SVec = Vec; + | ^^^^ ^^^^ + | + = note: #[warn(ignored_generic_bounds)] on by default + +warning: bounds on generic lifetime parameters are ignored in type aliases + --> $DIR/param-bounds-ignored.rs:18:19 + | +LL | type VVec<'b, 'a: 'b+'b> = Vec<&'a i32>; + | ^^ ^^ + +warning: bounds on generic type parameters are ignored in type aliases + --> $DIR/param-bounds-ignored.rs:20:18 + | +LL | type WVec<'b, T: 'b+'b> = Vec; + | ^^ ^^ + +warning: where clauses are ignored in type aliases + --> $DIR/param-bounds-ignored.rs:22:25 + | +LL | type W2Vec<'b, T> where T: 'b, T: 'b = Vec; + | ^^^^^ ^^^^^ + +warning: bounds on generic lifetime parameters are ignored in higher-ranked function types (i.e., `for`) + --> $DIR/param-bounds-ignored.rs:43:22 + | +LL | f: for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32) + | ^^^ + +warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) + --> $DIR/param-bounds-ignored.rs:51:34 + | +LL | fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>( + | ^^^ + +warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) + --> $DIR/param-bounds-ignored.rs:66:28 + | +LL | where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32 + | ^^^ + +warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) + --> $DIR/param-bounds-ignored.rs:78:25 + | +LL | where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32 + | ^^^ + +warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) + --> $DIR/param-bounds-ignored.rs:86:28 + | +LL | struct S1 Fn(&'xa i32, &'xb i32) -> &'xa i32>(F); + | ^^^ + +warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) + --> $DIR/param-bounds-ignored.rs:88:40 + | +LL | struct S2(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32; + | ^^^ + +warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) + --> $DIR/param-bounds-ignored.rs:90:37 + | +LL | struct S3(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32; + | ^^^ + +warning: bounds on generic lifetime parameters are ignored in higher-ranked function types (i.e., `for`) + --> $DIR/param-bounds-ignored.rs:93:29 + | +LL | struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32); + | ^^^ + +warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) + --> $DIR/param-bounds-ignored.rs:96:29 + | +LL | type T1 = Box Fn(&'xa i32, &'xb i32) -> &'xa i32>; + | ^^^ -warning[E0122]: generic bounds are ignored in type aliases - --> $DIR/param-bounds-ignored.rs:16:1 +warning: bounds on generic lifetime parameters are ignored in higher-ranked function types (i.e., `for`) + --> $DIR/param-bounds-ignored.rs:100:34 | -LL | type VVec<'b, 'a: 'b> = Vec<&'a i32>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | let _ : Option fn(&'xa i32, &'xb i32) -> &'xa i32> = None; + | ^^^ -warning[E0122]: generic bounds are ignored in type aliases - --> $DIR/param-bounds-ignored.rs:17:1 +warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) + --> $DIR/param-bounds-ignored.rs:102:38 | -LL | type WVec<'b, T: 'b> = Vec; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | let _ : Option Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None; + | ^^^ From 30b5be0e9530a4de106b581074c3707e6a938329 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 20 Feb 2018 14:52:23 +0100 Subject: [PATCH 3/5] update compile-fail tests; remove now redundant issue-39122.rs It is subsumed by ui/param-bounds-ignored.rs. --- src/test/compile-fail/dst-bad-assign-3.rs | 3 +-- src/test/compile-fail/issue-17994.rs | 2 +- src/test/compile-fail/issue-23046.rs | 2 ++ src/test/compile-fail/issue-39122.rs | 13 ------------- src/test/compile-fail/private-in-public-warn.rs | 4 ++-- src/test/compile-fail/rfc1623.rs | 2 +- 6 files changed, 7 insertions(+), 19 deletions(-) delete mode 100644 src/test/compile-fail/issue-39122.rs diff --git a/src/test/compile-fail/dst-bad-assign-3.rs b/src/test/compile-fail/dst-bad-assign-3.rs index 759da7b2bde21..ceaa371623223 100644 --- a/src/test/compile-fail/dst-bad-assign-3.rs +++ b/src/test/compile-fail/dst-bad-assign-3.rs @@ -12,8 +12,7 @@ #![feature(unsized_tuple_coercion)] -type Fat = (isize, &'static str, T); -//~^ WARNING bounds are ignored +type Fat = (isize, &'static str, T); #[derive(PartialEq,Eq)] struct Bar; diff --git a/src/test/compile-fail/issue-17994.rs b/src/test/compile-fail/issue-17994.rs index ac15bd9d15b04..0f30e2461cf3b 100644 --- a/src/test/compile-fail/issue-17994.rs +++ b/src/test/compile-fail/issue-17994.rs @@ -10,5 +10,5 @@ trait Tr {} type Huh where T: Tr = isize; //~ ERROR type parameter `T` is unused - //~| WARNING E0122 + //~| WARNING where clauses are ignored in type aliases fn main() {} diff --git a/src/test/compile-fail/issue-23046.rs b/src/test/compile-fail/issue-23046.rs index 129f7c8b1ea0e..6ce0887869335 100644 --- a/src/test/compile-fail/issue-23046.rs +++ b/src/test/compile-fail/issue-23046.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![allow(ignored_generic_bounds)] + pub enum Expr<'var, VAR> { Let(Box>, Box Fn(Expr<'v, VAR>) -> Expr<'v, VAR> + 'var>) diff --git a/src/test/compile-fail/issue-39122.rs b/src/test/compile-fail/issue-39122.rs deleted file mode 100644 index 2e8a740f89394..0000000000000 --- a/src/test/compile-fail/issue-39122.rs +++ /dev/null @@ -1,13 +0,0 @@ -// 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. - -type Foo = T; //~ WARNING E0122 - -type Bar where T: std::ops::Add = T; //~ WARNING E0122 diff --git a/src/test/compile-fail/private-in-public-warn.rs b/src/test/compile-fail/private-in-public-warn.rs index aa91ce27c379a..4be01dbd677f0 100644 --- a/src/test/compile-fail/private-in-public-warn.rs +++ b/src/test/compile-fail/private-in-public-warn.rs @@ -58,7 +58,7 @@ mod traits { pub trait PubTr {} pub type Alias = T; //~ ERROR private trait `traits::PrivTr` in public interface - //~^ WARN bounds are ignored in type aliases + //~^ WARNING bounds on generic type parameters are ignored //~| WARNING hard error pub trait Tr1: PrivTr {} //~ ERROR private trait `traits::PrivTr` in public interface //~^ WARNING hard error @@ -85,7 +85,7 @@ mod traits_where { pub type Alias where T: PrivTr = T; //~^ ERROR private trait `traits_where::PrivTr` in public interface //~| WARNING hard error - //~| WARNING E0122 + //~| WARNING where clauses are ignored in type aliases pub trait Tr2 where T: PrivTr {} //~^ ERROR private trait `traits_where::PrivTr` in public interface //~| WARNING hard error diff --git a/src/test/compile-fail/rfc1623.rs b/src/test/compile-fail/rfc1623.rs index e8295e5e2da08..579fa378a1c24 100644 --- a/src/test/compile-fail/rfc1623.rs +++ b/src/test/compile-fail/rfc1623.rs @@ -22,7 +22,7 @@ static NON_ELIDABLE_FN: &fn(&u8, &u8) -> &u8 = struct SomeStruct<'x, 'y, 'z: 'x> { foo: &'x Foo<'z>, bar: &'x Bar<'z>, - f: &'y for<'a, 'b: 'a> Fn(&'a Foo<'b>) -> &'a Bar<'b>, + f: &'y for<'a, 'b> Fn(&'a Foo<'b>) -> &'a Bar<'b>, } fn id(t: T) -> T { From 49abd8748357012e5db10bf11077384f727e2177 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 6 Mar 2018 11:22:24 +0100 Subject: [PATCH 4/5] make bounds on higher-kinded lifetimes a hard error in ast_validation Also move the check for not having type parameters into ast_validation. I was not sure what to do with compile-fail/issue-23046.rs: The issue looks like maybe the bounds actually played a role in triggering the ICE, but that seems unlikely given that the compiler seems to entirely ignore them. However, I couldn't find a testcase without the bounds, so I figured the best I could do is to just remove the bounds and make sure at least that keeps working. --- src/librustc_lint/builtin.rs | 91 ++++------------ src/librustc_passes/ast_validation.rs | 41 +++++++ src/libsyntax/parse/parser.rs | 14 +-- src/test/compile-fail/bounds-lifetime.rs | 17 +++ src/test/compile-fail/issue-23046.rs | 6 +- .../compile-fail/private-in-public-warn.rs | 2 +- src/test/parse-fail/bounds-lifetime.rs | 11 +- src/test/parse-fail/bounds-type.rs | 2 +- src/test/run-pass/impl-trait/lifetimes.rs | 4 +- src/test/ui/param-bounds-ignored.rs | 31 +++--- src/test/ui/param-bounds-ignored.stderr | 102 +++++++++--------- 11 files changed, 160 insertions(+), 161 deletions(-) create mode 100644 src/test/compile-fail/bounds-lifetime.rs diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 2452bda8d4372..b653cfecf9496 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1404,79 +1404,32 @@ impl LintPass for IgnoredGenericBounds { } } -impl IgnoredGenericBounds { - fn ensure_no_param_bounds( - cx: &EarlyContext, - generics: &Vec, - thing: &'static str, - ) { - for param in generics.iter() { - match param { - &ast::GenericParam::Lifetime(ref lifetime) => { - if !lifetime.bounds.is_empty() { - let spans : Vec<_> = lifetime.bounds.iter().map(|b| b.span).collect(); - cx.span_lint( - IGNORED_GENERIC_BOUNDS, - spans, - format!("bounds on generic lifetime parameters are ignored in {}", - thing).as_ref() - ); - } - } - &ast::GenericParam::Type(ref ty) => { - if !ty.bounds.is_empty() { - let spans : Vec<_> = ty.bounds.iter().map(|b| b.span()).collect(); - cx.span_lint( - IGNORED_GENERIC_BOUNDS, - spans, - format!("bounds on generic type parameters are ignored in {}", thing) - .as_ref() - ); - } - } - } - } - } -} - impl EarlyLintPass for IgnoredGenericBounds { fn check_item(&mut self, cx: &EarlyContext, item: &ast::Item) { - match item.node { - ast::ItemKind::Ty(_, ref generics) => { - if !generics.where_clause.predicates.is_empty() { - let spans : Vec<_> = generics.where_clause.predicates.iter() - .map(|pred| pred.span()).collect(); - cx.span_lint(IGNORED_GENERIC_BOUNDS, spans, - "where clauses are ignored in type aliases"); - } - IgnoredGenericBounds::ensure_no_param_bounds(cx, &generics.params, - "type aliases"); - } - _ => {} - } - } - - fn check_where_predicate(&mut self, cx: &EarlyContext, p: &ast::WherePredicate) { - if let &ast::WherePredicate::BoundPredicate(ref bound_predicate) = p { - // A type binding, eg `for<'c> Foo: Send+Clone+'c` - IgnoredGenericBounds::ensure_no_param_bounds(cx, - &bound_predicate.bound_generic_params, "higher-ranked trait bounds (i.e., `for`)"); + let type_alias_generics = match item.node { + ast::ItemKind::Ty(_, ref generics) => generics, + _ => return, + }; + // There must not be a where clause + if !type_alias_generics.where_clause.predicates.is_empty() { + let spans : Vec<_> = type_alias_generics.where_clause.predicates.iter() + .map(|pred| pred.span()).collect(); + cx.span_lint(IGNORED_GENERIC_BOUNDS, spans, + "where clauses are ignored in type aliases"); } - } - - fn check_poly_trait_ref(&mut self, cx: &EarlyContext, t: &ast::PolyTraitRef, - _: &ast::TraitBoundModifier) { - IgnoredGenericBounds::ensure_no_param_bounds(cx, &t.bound_generic_params, - "higher-ranked trait bounds (i.e., `for`)"); - } - - fn check_ty(&mut self, cx: &EarlyContext, ty: &ast::Ty) { - match ty.node { - ast::TyKind::BareFn(ref fn_ty) => { - IgnoredGenericBounds::ensure_no_param_bounds(cx, &fn_ty.generic_params, - "higher-ranked function types (i.e., `for`)"); + // The parameters must not have bounds + for param in type_alias_generics.params.iter() { + let spans : Vec<_> = match param { + &ast::GenericParam::Lifetime(ref l) => l.bounds.iter().map(|b| b.span).collect(), + &ast::GenericParam::Type(ref ty) => ty.bounds.iter().map(|b| b.span()).collect(), + }; + if !spans.is_empty() { + cx.span_lint( + IGNORED_GENERIC_BOUNDS, + spans, + "bounds on generic parameters are ignored in type aliases", + ); } - _ => {} } } } diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index a5dd8f1558e43..55d00f92e4dac 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -136,6 +136,33 @@ impl<'a> AstValidator<'a> { in patterns") } } + + fn check_late_bound_lifetime_defs(&self, params: &Vec) { + // Check: Only lifetime parameters + let non_lifetime_param_spans : Vec<_> = params.iter() + .filter_map(|param| match *param { + GenericParam::Lifetime(_) => None, + GenericParam::Type(ref t) => Some(t.span), + }).collect(); + if !non_lifetime_param_spans.is_empty() { + self.err_handler().span_err(non_lifetime_param_spans, + "only lifetime parameters can be used in this context"); + } + + // Check: No bounds on lifetime parameters + for param in params.iter() { + match *param { + GenericParam::Lifetime(ref l) => { + if !l.bounds.is_empty() { + let spans : Vec<_> = l.bounds.iter().map(|b| b.span).collect(); + self.err_handler().span_err(spans, + "lifetime bounds cannot be used in this context"); + } + } + GenericParam::Type(_) => {} + } + } + } } impl<'a> Visitor<'a> for AstValidator<'a> { @@ -157,6 +184,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { struct_span_err!(self.session, span, E0561, "patterns aren't allowed in function pointer types").emit(); }); + self.check_late_bound_lifetime_defs(&bfty.generic_params); } TyKind::TraitObject(ref bounds, ..) => { let mut any_lifetime_bounds = false; @@ -417,6 +445,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> { visit::walk_pat(self, pat) } + + fn visit_where_predicate(&mut self, p: &'a WherePredicate) { + if let &WherePredicate::BoundPredicate(ref bound_predicate) = p { + // A type binding, eg `for<'c> Foo: Send+Clone+'c` + self.check_late_bound_lifetime_defs(&bound_predicate.bound_generic_params); + } + visit::walk_where_predicate(self, p); + } + + fn visit_poly_trait_ref(&mut self, t: &'a PolyTraitRef, m: &'a TraitBoundModifier) { + self.check_late_bound_lifetime_defs(&t.bound_generic_params); + visit::walk_poly_trait_ref(self, t, m); + } } // Bans nested `impl Trait`, e.g. `impl Into`. diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 09dd00fa5fa3a..ba8ccc2256f20 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -5484,18 +5484,8 @@ impl<'a> Parser<'a> { self.expect_lt()?; let params = self.parse_generic_params()?; self.expect_gt()?; - - let first_non_lifetime_param_span = params.iter() - .filter_map(|param| match *param { - ast::GenericParam::Lifetime(_) => None, - ast::GenericParam::Type(ref t) => Some(t.span), - }) - .next(); - - if let Some(span) = first_non_lifetime_param_span { - self.span_err(span, "only lifetime parameters can be used in this context"); - } - + // We rely on AST validation to rule out invalid cases: There must not be type + // parameters, and the lifetime parameters must not have bounds. Ok(params) } else { Ok(Vec::new()) diff --git a/src/test/compile-fail/bounds-lifetime.rs b/src/test/compile-fail/bounds-lifetime.rs new file mode 100644 index 0000000000000..5bfaa6c54fa9f --- /dev/null +++ b/src/test/compile-fail/bounds-lifetime.rs @@ -0,0 +1,17 @@ +// 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. + +type A = for<'b, 'a: 'b> fn(); //~ ERROR lifetime bounds cannot be used in this context +type B = for<'b, 'a: 'b,> fn(); //~ ERROR lifetime bounds cannot be used in this context +type C = for<'b, 'a: 'b +> fn(); //~ ERROR lifetime bounds cannot be used in this context +type D = for<'a, T> fn(); //~ ERROR only lifetime parameters can be used in this context +type E = for Fn(); //~ ERROR only lifetime parameters can be used in this context + +fn main() {} diff --git a/src/test/compile-fail/issue-23046.rs b/src/test/compile-fail/issue-23046.rs index 6ce0887869335..670706b7a9adf 100644 --- a/src/test/compile-fail/issue-23046.rs +++ b/src/test/compile-fail/issue-23046.rs @@ -8,11 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(ignored_generic_bounds)] - pub enum Expr<'var, VAR> { Let(Box>, - Box Fn(Expr<'v, VAR>) -> Expr<'v, VAR> + 'var>) + Box Fn(Expr<'v, VAR>) -> Expr<'v, VAR> + 'var>) } pub fn add<'var, VAR> @@ -20,7 +18,7 @@ pub fn add<'var, VAR> loop {} } -pub fn let_<'var, VAR, F: for<'v: 'var> Fn(Expr<'v, VAR>) -> Expr<'v, VAR>> +pub fn let_<'var, VAR, F: for<'v> Fn(Expr<'v, VAR>) -> Expr<'v, VAR>> (a: Expr<'var, VAR>, b: F) -> Expr<'var, VAR> { loop {} } diff --git a/src/test/compile-fail/private-in-public-warn.rs b/src/test/compile-fail/private-in-public-warn.rs index 4be01dbd677f0..cc9eed7e65426 100644 --- a/src/test/compile-fail/private-in-public-warn.rs +++ b/src/test/compile-fail/private-in-public-warn.rs @@ -58,7 +58,7 @@ mod traits { pub trait PubTr {} pub type Alias = T; //~ ERROR private trait `traits::PrivTr` in public interface - //~^ WARNING bounds on generic type parameters are ignored + //~^ WARNING bounds on generic parameters are ignored //~| WARNING hard error pub trait Tr1: PrivTr {} //~ ERROR private trait `traits::PrivTr` in public interface //~^ WARNING hard error diff --git a/src/test/parse-fail/bounds-lifetime.rs b/src/test/parse-fail/bounds-lifetime.rs index 5113a6b4803fc..88db205310ce1 100644 --- a/src/test/parse-fail/bounds-lifetime.rs +++ b/src/test/parse-fail/bounds-lifetime.rs @@ -8,17 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: -Z parse-only -Z continue-parse-after-error +// compile-flags: -Z parse-only -type A = for<'a: 'b + 'c> fn(); // OK -type A = for<'a: 'b,> fn(); // OK type A = for<'a:> fn(); // OK type A = for<'a:,> fn(); // OK type A = for<'a> fn(); // OK type A = for<> fn(); // OK -type A = for<'a: 'b +> fn(); // OK - -type A = for<'a, T> fn(); //~ ERROR only lifetime parameters can be used in this context +type A = for<'a: 'b + 'c> fn(); // OK (rejected later by ast_validation) +type A = for<'a: 'b,> fn(); // OK(rejected later by ast_validation) +type A = for<'a: 'b +> fn(); // OK (rejected later by ast_validation) +type A = for<'a, T> fn(); // OK (rejected later by ast_validation) type A = for<,> fn(); //~ ERROR expected one of `>`, identifier, or lifetime, found `,` fn main() {} diff --git a/src/test/parse-fail/bounds-type.rs b/src/test/parse-fail/bounds-type.rs index c224b44a14bf1..0ebe7fde0a63f 100644 --- a/src/test/parse-fail/bounds-type.rs +++ b/src/test/parse-fail/bounds-type.rs @@ -15,7 +15,7 @@ struct S< T: Tr + 'a, // OK T: 'a, // OK T:, // OK - T: ?for<'a: 'b + 'c> Trait, // OK + T: ?for<'a> Trait, // OK T: Tr +, // OK T: ?'a, //~ ERROR `?` may only modify trait bounds, not lifetime bounds >; diff --git a/src/test/run-pass/impl-trait/lifetimes.rs b/src/test/run-pass/impl-trait/lifetimes.rs index 2d5dfb045dbac..fcad23926fc0c 100644 --- a/src/test/run-pass/impl-trait/lifetimes.rs +++ b/src/test/run-pass/impl-trait/lifetimes.rs @@ -69,8 +69,8 @@ fn foo(x: &impl Debug) -> &impl Debug { x } fn foo_explicit_lifetime<'a>(x: &'a impl Debug) -> &'a impl Debug { x } fn foo_explicit_arg(x: &T) -> &impl Debug { x } -fn mixed_lifetimes<'a>() -> impl for<'b: 'a> Fn(&'b u32) { |_| () } -fn mixed_as_static() -> impl Fn(&'static u32) { mixed_lifetimes() } +fn mixed_lifetimes<'a>() -> impl for<'b> Fn(&'b &'a u32) { |_| () } +fn mixed_as_static() -> impl Fn(&'static &'static u32) { mixed_lifetimes() } trait MultiRegionTrait<'a, 'b>: Debug {} diff --git a/src/test/ui/param-bounds-ignored.rs b/src/test/ui/param-bounds-ignored.rs index a136ec60252b4..94bcdec945035 100644 --- a/src/test/ui/param-bounds-ignored.rs +++ b/src/test/ui/param-bounds-ignored.rs @@ -8,17 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// must-compile-successfully #![allow(dead_code, non_camel_case_types)] use std::rc::Rc; type SVec = Vec; -//~^ WARN bounds on generic type parameters are ignored in type aliases +//~^ WARN bounds on generic parameters are ignored in type aliases type VVec<'b, 'a: 'b+'b> = Vec<&'a i32>; -//~^ WARN bounds on generic lifetime parameters are ignored in type aliases +//~^ WARN bounds on generic parameters are ignored in type aliases type WVec<'b, T: 'b+'b> = Vec; -//~^ WARN bounds on generic type parameters are ignored in type aliases +//~^ WARN bounds on generic parameters are ignored in type aliases type W2Vec<'b, T> where T: 'b, T: 'b = Vec; //~^ WARN where clauses are ignored in type aliases @@ -40,8 +39,8 @@ fn foo<'a>(y: &'a i32) { fn bar1<'a, 'b>( x: &'a i32, y: &'b i32, - f: for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32) - //~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked function types + f: for<'xa, 'xb: 'xa+'xa> fn(&'xa i32, &'xb i32) -> &'xa i32) + //~^ ERROR lifetime bounds cannot be used in this context { // If the bound in f's type would matter, the call below would (have to) // be rejected. @@ -49,7 +48,7 @@ fn bar1<'a, 'b>( } fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>( - //~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds + //~^ ERROR lifetime bounds cannot be used in this context x: &'a i32, y: &'b i32, f: F) @@ -64,7 +63,7 @@ fn bar3<'a, 'b, F>( y: &'b i32, f: F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32 - //~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds + //~^ ERROR lifetime bounds cannot be used in this context { // If the bound in f's type would matter, the call below would (have to) // be rejected. @@ -76,7 +75,7 @@ fn bar4<'a, 'b, F>( y: &'b i32, f: F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32 - //~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds + //~^ ERROR lifetime bounds cannot be used in this context { // If the bound in f's type would matter, the call below would (have to) // be rejected. @@ -84,21 +83,21 @@ fn bar4<'a, 'b, F>( } struct S1 Fn(&'xa i32, &'xb i32) -> &'xa i32>(F); -//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds +//~^ ERROR lifetime bounds cannot be used in this context struct S2(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32; -//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds +//~^ ERROR lifetime bounds cannot be used in this context struct S3(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32; -//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds +//~^ ERROR lifetime bounds cannot be used in this context struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32); -//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked function types +//~^ ERROR lifetime bounds cannot be used in this context type T1 = Box Fn(&'xa i32, &'xb i32) -> &'xa i32>; -//~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds +//~^ ERROR lifetime bounds cannot be used in this context fn main() { let _ : Option fn(&'xa i32, &'xb i32) -> &'xa i32> = None; - //~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked function types + //~^ ERROR lifetime bounds cannot be used in this context let _ : Option Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None; - //~^ WARN bounds on generic lifetime parameters are ignored in higher-ranked trait bounds + //~^ ERROR lifetime bounds cannot be used in this context } diff --git a/src/test/ui/param-bounds-ignored.stderr b/src/test/ui/param-bounds-ignored.stderr index 55df5d1c93941..657fec54f9608 100644 --- a/src/test/ui/param-bounds-ignored.stderr +++ b/src/test/ui/param-bounds-ignored.stderr @@ -1,92 +1,94 @@ -warning: bounds on generic type parameters are ignored in type aliases - --> $DIR/param-bounds-ignored.rs:16:14 +error: lifetime bounds cannot be used in this context + --> $DIR/param-bounds-ignored.rs:42:22 | -LL | type SVec = Vec; - | ^^^^ ^^^^ - | - = note: #[warn(ignored_generic_bounds)] on by default - -warning: bounds on generic lifetime parameters are ignored in type aliases - --> $DIR/param-bounds-ignored.rs:18:19 - | -LL | type VVec<'b, 'a: 'b+'b> = Vec<&'a i32>; - | ^^ ^^ - -warning: bounds on generic type parameters are ignored in type aliases - --> $DIR/param-bounds-ignored.rs:20:18 - | -LL | type WVec<'b, T: 'b+'b> = Vec; - | ^^ ^^ - -warning: where clauses are ignored in type aliases - --> $DIR/param-bounds-ignored.rs:22:25 - | -LL | type W2Vec<'b, T> where T: 'b, T: 'b = Vec; - | ^^^^^ ^^^^^ +LL | f: for<'xa, 'xb: 'xa+'xa> fn(&'xa i32, &'xb i32) -> &'xa i32) + | ^^^ ^^^ -warning: bounds on generic lifetime parameters are ignored in higher-ranked function types (i.e., `for`) - --> $DIR/param-bounds-ignored.rs:43:22 - | -LL | f: for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32) - | ^^^ - -warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) - --> $DIR/param-bounds-ignored.rs:51:34 +error: lifetime bounds cannot be used in this context + --> $DIR/param-bounds-ignored.rs:50:34 | LL | fn bar2<'a, 'b, F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32>( | ^^^ -warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) - --> $DIR/param-bounds-ignored.rs:66:28 +error: lifetime bounds cannot be used in this context + --> $DIR/param-bounds-ignored.rs:65:28 | LL | where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32 | ^^^ -warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) - --> $DIR/param-bounds-ignored.rs:78:25 +error: lifetime bounds cannot be used in this context + --> $DIR/param-bounds-ignored.rs:77:25 | LL | where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32 | ^^^ -warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) - --> $DIR/param-bounds-ignored.rs:86:28 +error: lifetime bounds cannot be used in this context + --> $DIR/param-bounds-ignored.rs:85:28 | LL | struct S1 Fn(&'xa i32, &'xb i32) -> &'xa i32>(F); | ^^^ -warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) - --> $DIR/param-bounds-ignored.rs:88:40 +error: lifetime bounds cannot be used in this context + --> $DIR/param-bounds-ignored.rs:87:40 | LL | struct S2(F) where F: for<'xa, 'xb: 'xa> Fn(&'xa i32, &'xb i32) -> &'xa i32; | ^^^ -warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) - --> $DIR/param-bounds-ignored.rs:90:37 +error: lifetime bounds cannot be used in this context + --> $DIR/param-bounds-ignored.rs:89:37 | LL | struct S3(F) where for<'xa, 'xb: 'xa> F: Fn(&'xa i32, &'xb i32) -> &'xa i32; | ^^^ -warning: bounds on generic lifetime parameters are ignored in higher-ranked function types (i.e., `for`) - --> $DIR/param-bounds-ignored.rs:93:29 +error: lifetime bounds cannot be used in this context + --> $DIR/param-bounds-ignored.rs:92:29 | LL | struct S_fnty(for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32); | ^^^ -warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) - --> $DIR/param-bounds-ignored.rs:96:29 +error: lifetime bounds cannot be used in this context + --> $DIR/param-bounds-ignored.rs:95:29 | LL | type T1 = Box Fn(&'xa i32, &'xb i32) -> &'xa i32>; | ^^^ -warning: bounds on generic lifetime parameters are ignored in higher-ranked function types (i.e., `for`) - --> $DIR/param-bounds-ignored.rs:100:34 +error: lifetime bounds cannot be used in this context + --> $DIR/param-bounds-ignored.rs:99:34 | LL | let _ : Option fn(&'xa i32, &'xb i32) -> &'xa i32> = None; | ^^^ -warning: bounds on generic lifetime parameters are ignored in higher-ranked trait bounds (i.e., `for`) - --> $DIR/param-bounds-ignored.rs:102:38 +error: lifetime bounds cannot be used in this context + --> $DIR/param-bounds-ignored.rs:101:38 | LL | let _ : Option Fn(&'xa i32, &'xb i32) -> &'xa i32>> = None; | ^^^ +warning: bounds on generic parameters are ignored in type aliases + --> $DIR/param-bounds-ignored.rs:15:14 + | +LL | type SVec = Vec; + | ^^^^ ^^^^ + | + = note: #[warn(ignored_generic_bounds)] on by default + +warning: bounds on generic parameters are ignored in type aliases + --> $DIR/param-bounds-ignored.rs:17:19 + | +LL | type VVec<'b, 'a: 'b+'b> = Vec<&'a i32>; + | ^^ ^^ + +warning: bounds on generic parameters are ignored in type aliases + --> $DIR/param-bounds-ignored.rs:19:18 + | +LL | type WVec<'b, T: 'b+'b> = Vec; + | ^^ ^^ + +warning: where clauses are ignored in type aliases + --> $DIR/param-bounds-ignored.rs:21:25 + | +LL | type W2Vec<'b, T> where T: 'b, T: 'b = Vec; + | ^^^^^ ^^^^^ + +error: aborting due to 11 previous errors + From 780b544a391fb2dc42d814ce8cb7e6ad3633fa39 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Tue, 6 Mar 2018 11:33:26 +0100 Subject: [PATCH 5/5] note a FIXME --- src/libsyntax/parse/parser.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index ba8ccc2256f20..b60a6b32fab21 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4827,6 +4827,7 @@ impl<'a> Parser<'a> { } )); // FIXME: Decide what should be used here, `=` or `==`. + // FIXME: We are just dropping the binders in lifetime_defs on the floor here. } else if self.eat(&token::Eq) || self.eat(&token::EqEq) { let rhs_ty = self.parse_ty()?; where_clause.predicates.push(ast::WherePredicate::EqPredicate(