Skip to content

Conversation

@RalfJung
Copy link
Member

This adds a new lint to fix #42181. For consistency and to avoid code duplication, I also moved the existing "bounds in type aliases are ignored" here.

Questions to the reviewer:

  • Is it okay to just remove a diagnostic error code like this? Should I instead keep the warning about type aliases where it is? The old code provided a detailed explanation of what's going on when asked, that information is now lost. On the other hand, span_warn! seems deprecated (after this patch, it has exactly one user left!).
  • Did I miss any syntactic construct that can appear as for in the surface syntax? I covered function types (for<'a> fn(...)), generic traits (for <'a> Fn(...), can appear both as bounds as as trait objects) and bounds (for<'a> F: ...).
  • For the sake of backwards compatibility, this adds a warning, not an error. @nikomatsakis suggested an error in Bounds in HRTB are ignored #42181 (comment), but I feel that can only happen in a new epoch -- right?

Cc @eddyb

@rust-highfive
Copy link
Contributor

r? @petrochenkov

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 18, 2018
@petrochenkov
Copy link
Contributor

Is it okay to just remove a diagnostic error code like this?

It's okay. src/librustc_typeck/diagnostics.rs contains a list of commented out error codes at the very end of the file. E0122 can be added to that list as well with a short note on why it was removed.

On the other hand, span_warn! seems deprecated

Yes, hardcoded warnings should be avoided whenever possible (I don't think we should remove the mechanism itself though).

Did I miss any syntactic construct that can appear as for in the surface syntax?

Everything looks covered.

For the sake of backwards compatibility, this adds a warning, not an error. @nikomatsakis suggested an error in #42181 (comment), but I feel that can only happen in a new epoch -- right?

Crater can answer this! cc @aidanhs

// except according to those terms.

// must-compile-successfully
#![allow(dead_code, non_camel_case_types)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you warn(ignored_generic_bounds) and add //~ WARN ... annotations to the file?
It's very hard to see what is tested, what should be reported, and what shouldn't be reported based on stderr file alone.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I didn't even know //~ WARN was a thing in ui tests. How do the two interact?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

--> $DIR/param-bounds-ignored.rs:39:8
|
39 | f: for<'xa, 'xb: 'xa> fn(&'xa i32, &'xb i32) -> &'xa i32)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spans could be more precise, AST has spans for generics and for the ignored bounds themselves.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm now changing this so the span points at the first ignored bound. Is there a way to "combine" spans? I found no span for all the bounds together, just the generic (which is the wrong place) and individual bounds.

@petrochenkov petrochenkov added S-waiting-on-crater Status: Waiting on a crater run to be completed. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 19, 2018
@petrochenkov
Copy link
Contributor

Crater can answer this!

The warning should be forbid-by-default for cratering though.

@RalfJung
Copy link
Member Author

The warning should be forbid-by-default for cratering though.

So are you saying I should change this PR to make the warning err-by-default?

@RalfJung
Copy link
Member Author

Turns out that even some of the compile-fail tests have these bounds in for. I'd be very surprised if crater wouldn't find tons of cases^^

@RalfJung
Copy link
Member Author

E0122 can be added to that list as well with a short note on why it was removed.

Done.

@RalfJung
Copy link
Member Author

There's a strange failure in compile-fail/enum-discrim-too-small2.rs: the compiler panics with the following backtrace:

thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:535:9 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. stack backtrace: 0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49 1: std::sys_common::backtrace::print at libstd/sys_common/backtrace.rs:71 at libstd/sys_common/backtrace.rs:59 2: std::panicking::default_hook::{{closure}} at libstd/panicking.rs:206 3: std::panicking::default_hook at libstd/panicking.rs:222 4: std::panicking::rust_panic_with_hook at libstd/panicking.rs:400 5: std::panicking::begin_panic at ./src/libstd/panicking.rs:363 6: rustc_errors::Handler::bug at librustc_errors/lib.rs:535 7: <std::thread::local::LocalKey<T>>::with at librustc/session/mod.rs:1179 at librustc/ty/context.rs:1600 at librustc/ty/context.rs:1589 at ./src/libstd/thread/local.rs:377 at ./src/libstd/thread/local.rs:288 8: rustc::ty::context::tls::with_opt at librustc/ty/context.rs:1585 at librustc/ty/context.rs:1600 9: rustc::session::opt_span_bug_fmt at librustc/session/mod.rs:1175 10: rustc::session::bug_fmt at librustc/session/mod.rs:1159 11: <rustc::ty::layout::LayoutCx<'tcx, rustc::ty::context::TyCtxt<'a, 'tcx, 'tcx>>>::layout_raw_uncached at librustc/ty/layout.rs:553 at librustc/ty/layout.rs:1545 12: rustc::ty::layout::layout_raw at librustc/ty/layout.rs:899 13: rustc::ty::maps::<impl rustc::ty::maps::queries::layout_raw<'tcx>>::compute_result at librustc/ty/maps/plumbing.rs:396 14: rustc::dep_graph::graph::DepGraph::with_task_impl at librustc/dep_graph/graph.rs:289 15: rustc_errors::Handler::track_diagnostics at librustc/dep_graph/graph.rs:199 at librustc/ty/maps/plumbing.rs:505 at ./src/librustc_errors/lib.rs:598 16: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check at librustc/ty/maps/plumbing.rs:498 at librustc/ty/maps/plumbing.rs:121 17: rustc::ty::maps::<impl rustc::ty::maps::queries::layout_raw<'tcx>>::force at librustc/ty/maps/plumbing.rs:497 18: rustc::ty::maps::<impl rustc::ty::maps::queries::layout_raw<'tcx>>::try_get at librustc/ty/maps/plumbing.rs:314 at librustc/ty/maps/plumbing.rs:539 19: rustc::ty::maps::TyCtxtAt::layout_raw at librustc/ty/maps/plumbing.rs:578 20: <rustc::ty::layout::LayoutCx<'tcx, rustc::ty::context::TyCtxt<'a, 'tcx, 'tcx>> as rustc::ty::layout::LayoutOf<&'tcx rustc::ty::TyS<'tcx>>>::layout_of at librustc/ty/maps/plumbing.rs:571 at librustc/ty/layout.rs:2052 21: <&'a rustc::lint::context::LateContext<'a, 'tcx> as rustc::ty::layout::LayoutOf<&'tcx rustc::ty::TyS<'tcx>>>::layout_of at librustc/ty/layout.rs:2111 at librustc/lint/context.rs:634 22: <rustc_lint::types::VariantSizeDifferences as rustc::lint::LateLintPass<'a, 'tcx>>::check_item at librustc_lint/types.rs:781 23: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::lint::context::LintContext<'tcx>>::with_lint_attrs at librustc/lint/context.rs:665 at librustc/lint/context.rs:625 at librustc/lint/context.rs:664 at librustc/lint/context.rs:560 24: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod at librustc/lint/context.rs:663 at librustc/hir/intravisit.rs:183 at librustc/hir/intravisit.rs:391 at librustc/lint/context.rs:759 25: rustc::hir::intravisit::walk_crate at librustc/hir/intravisit.rs:377 26: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::lint::context::LintContext<'tcx>>::with_lint_attrs at librustc/lint/context.rs:1040 at librustc/lint/context.rs:560 27: rustc::lint::context::check_crate at librustc/lint/context.rs:1035 28: <std::thread::local::LocalKey<T>>::with at librustc_driver/driver.rs:1092 at ./src/librustc/ty/context.rs:1573 at ./src/libstd/thread/local.rs:377 at ./src/libstd/thread/local.rs:288 29: <std::thread::local::LocalKey<T>>::with at ./src/librustc/ty/context.rs:1570 at ./src/librustc/ty/context.rs:1557 at ./src/libstd/thread/local.rs:377 at ./src/libstd/thread/local.rs:288 30: rustc::ty::context::TyCtxt::create_and_enter at ./src/librustc/ty/context.rs:1554 at ./src/librustc/ty/context.rs:1197 31: rustc_driver::driver::phase_3_run_analysis_passes at librustc_driver/driver.rs:1007 32: rustc_driver::driver::compile_input at librustc_driver/driver.rs:214 33: rustc_driver::run_compiler at librustc_driver/lib.rs:506 note: the compiler unexpectedly panicked. this is a bug. note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports note: rustc 1.25.0-dev running on x86_64-unknown-linux-gnu ------------------------------------------ thread '[compile-fail] compile-fail/enum-discrim-too-small2.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:2892:9 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. stack backtrace: 0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49 1: std::sys_common::backtrace::print at libstd/sys_common/backtrace.rs:71 at libstd/sys_common/backtrace.rs:59 2: std::panicking::default_hook::{{closure}} at libstd/panicking.rs:206 3: std::panicking::default_hook at libstd/panicking.rs:216 4: std::panicking::rust_panic_with_hook at libstd/panicking.rs:400 5: std::panicking::begin_panic 6: compiletest::runtest::ProcRes::fatal 7: compiletest::runtest::TestCx::fatal_proc_rec 8: compiletest::runtest::TestCx::check_no_compiler_crash 9: compiletest::runtest::TestCx::run_cfail_test 10: compiletest::runtest::run 11: <F as alloc::boxed::FnBox<A>>::call_box 12: <F as alloc::boxed::FnBox<A>>::call_box at libtest/lib.rs:1456 at ./src/liballoc/boxed.rs:788 13: __rust_maybe_catch_panic at libpanic_unwind/lib.rs:102 failures: [compile-fail] compile-fail/enum-discrim-too-small2.rs test result: FAILED. 1 passed; 1 failed; 2317 ignored; 0 measured; 0 filtered out thread 'main' panicked at 'Some tests failed', tools/compiletest/src/main.rs:476:22 stack backtrace: 0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49 1: std::sys_common::backtrace::print at libstd/sys_common/backtrace.rs:71 at libstd/sys_common/backtrace.rs:59 2: std::panicking::default_hook::{{closure}} at libstd/panicking.rs:206 3: std::panicking::default_hook at libstd/panicking.rs:222 4: std::panicking::rust_panic_with_hook at libstd/panicking.rs:400 5: std::panicking::begin_panic 6: compiletest::main 7: std::rt::lang_start::{{closure}} 8: std::panicking::try::do_call at libstd/rt.rs:59 at libstd/panicking.rs:305 9: __rust_maybe_catch_panic at libpanic_unwind/lib.rs:102 10: std::rt::lang_start_internal at libstd/panicking.rs:284 at libstd/panic.rs:361 at libstd/rt.rs:58 11: main 12: __libc_start_main 13: _start command did not execute successfully: "/home/r/src/rust/rustc/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/home/r/src/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib" "--run-lib-path" "/home/r/src/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/home/r/src/rust/rustc/build/x86_64-unknown-linux-gnu/stage1/bin/rustc" "--src-base" "/home/r/src/rust/rustc/src/test/compile-fail" "--build-base" "/home/r/src/rust/rustc/build/x86_64-unknown-linux-gnu/test/compile-fail" "--stage-id" "stage1-x86_64-unknown-linux-gnu" "--mode" "compile-fail" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/home/r/src/rust/rustc/build/x86_64-unknown-linux-gnu/llvm/build/bin/FileCheck" "--nodejs" "/usr/bin/node" "--host-rustcflags" "-Crpath -O -Zmiri -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zmiri -Zunstable-options -Lnative=/home/r/src/rust/rustc/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python" "--lldb-python" "/usr/bin/python" "--gdb" "/usr/bin/gdb" "--llvm-version" "6.0.0\n" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" expected success, got: exit code: 101 

I have no idea how my changes could cause that.

@RalfJung
Copy link
Member Author

RalfJung commented Feb 20, 2018

The backtrace points at

 bug!("Integer::repr_discr: `#[repr]` hint too small for \ discriminant range of enum `{}", ty) 

which I did not see because it's JSON-ified:

{"message":"librustc/ty/layout.rs:553: Integer::repr_discr: `#[repr]` hint too small for discriminant range of enum `Ei64","code":null,"level":"error: internal compiler error","spans":[],"children":[],"rendered":"error: internal compiler error: librustc/ty/layout.rs:553: Integer::repr_discr: `#[repr]` hint too small for discriminant range of enum `Ei64\n\n"} 

Since this did not happen on Travis, I assume it's a stage-1-only failure. I'm currently building stage 2 to verify. (EDIT: confirmed stage-1-only failure.)

@RalfJung
Copy link
Member Author

I'm now changing this so the span points at the first ignored bound. Is there a way to "combine" spans? I found no span for all the bounds together, just the generic (which is the wrong place) and individual bounds.

I guess alternatively I could make it warn about every single bound, but that feels excessive?

@hanna-kruppe
Copy link
Contributor

You can pass a MultiSpan (or a Vec<Span>, there's a From impl) instead of a single span to the span_* methods.

type Foo<T: std::ops::Add> = T; //~ WARNING bounds on generic type parameters are ignored

type Bar<T> where T: std::ops::Add = T; //~ WARNING E0122
type Bar<T> where T: std::ops::Add = T; //~ WARNING where clauses are ignored
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is now a strict subset of the new ui/param-bounds-ignored. Should I remove it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the less code the better!

@RalfJung
Copy link
Member Author

You can pass a MultiSpan (or a Vec, there's a From impl) instead of a single span to the span_* methods.

Wow, fancy. Done :)

@RalfJung
Copy link
Member Author

The warning should be forbid-by-default for cratering though.

I made it Deny-by-default. (There are some existing Deny-by-default lint and no Forbid-by-default lint, so I figured I'd stay consistent with them.)

@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 21, 2018

pub enum Expr<'var, VAR> {
Let(Box<Expr<'var, VAR>>,
Box<for<'v: 'var> Fn(Expr<'v, VAR>) -> Expr<'v, VAR> + 'var>)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the use of bounds was intentional here (#23046).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to check whether they are totally ignored during lowering to ty representation or just not enforced properly (and still may cause ICEs or something).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I will bring the bound back. So far I haven't observed anything that would react to these bounds, and AFAIK @eddyb also said they are ignored.

Are you saying I should check the lowering code whether they are ignored? I'm not familiar with that code at all, not even sure where it lives, but I can certainly try.^^

@petrochenkov
Copy link
Contributor

@RalfJung

I made it Deny-by-default. (There are some existing Deny-by-default lint and no Forbid-by-default lint, so I figured I'd stay consistent with them.)

For running crater on existing lints forbid-by-default allows to still catch cases where the lint was allowed, but this is a new lint, so there's no difference.

@petrochenkov
Copy link
Contributor

Travis found some failing run-pass tests that need to be updated.

Everything else looks good to me, only crater run is remaining.
ping @aidanhs again

@petrochenkov petrochenkov removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 21, 2018
@aidanhs
Copy link
Contributor

aidanhs commented Feb 21, 2018

Crater needs to be fed with a try build so it'll need to get through travis, which is unfortunately probably not going to happen with test failures.

(also, please ping @rust-lang/infra for crater runs rather than me directly!)

@Manishearth
Copy link
Member

@bors p=1

segfaulty, not including in rollup, should be tested on its own when there's a slot

@kennytm
Copy link
Member

kennytm commented Mar 8, 2018

@Manishearth The segfault is likely introduced by the miri PR, not this, thus the retry. I agree this (+324, -108) PR shouldn't be rolled up though 😄.

@bors
Copy link
Collaborator

bors commented Mar 9, 2018

⌛ Testing commit 780b544 with merge 50f2d3d3b6c75b4be1f4f44f1cf7555d2f4dba05...

@bors
Copy link
Collaborator

bors commented Mar 9, 2018

💔 Test failed - status-travis

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 9, 2018
@oli-obk
Copy link
Contributor

oli-obk commented Mar 9, 2018

@bors retry segfault on dist x86_64-apple-darwin xcode 7.3

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 9, 2018
@RalfJung
Copy link
Member Author

RalfJung commented Mar 9, 2018

Sent a PR against the only crate this should break (according to crater): rustgd/rhusics#62

bors bot added a commit to rustgd/rhusics that referenced this pull request Mar 9, 2018
62: Remove lifetime bounds in higher-ranked lifetimes r=Rhuagh a=RalfJung Those bounds are ignored by the compiler, and will trigger an error once rust-lang/rust#48326 lands. According to crater, this is the only crate using these bounds. This patch should make the crate work on nightly again. However, I have been unable to compile the crate even with nightly 2018-02-25, which does not include the change mentioned above. So, I couldn't compile-test this PR. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/rustgd/rhusics/62) <!-- Reviewable:end -->
@bors
Copy link
Collaborator

bors commented Mar 9, 2018

⌛ Testing commit 780b544 with merge fedce67...

bors added a commit that referenced this pull request Mar 9, 2018
Warn about ignored generic bounds in `for` This adds a new lint to fix #42181. For consistency and to avoid code duplication, I also moved the existing "bounds in type aliases are ignored" here. Questions to the reviewer: * Is it okay to just remove a diagnostic error code like this? Should I instead keep the warning about type aliases where it is? The old code provided a detailed explanation of what's going on when asked, that information is now lost. On the other hand, `span_warn!` seems deprecated (after this patch, it has exactly one user left!). * Did I miss any syntactic construct that can appear as `for` in the surface syntax? I covered function types (`for<'a> fn(...)`), generic traits (`for <'a> Fn(...)`, can appear both as bounds as as trait objects) and bounds (`for<'a> F: ...`). * For the sake of backwards compatibility, this adds a warning, not an error. @nikomatsakis suggested an error in #42181 (comment), but I feel that can only happen in a new epoch -- right? Cc @eddyb
@bors
Copy link
Collaborator

bors commented Mar 9, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: petrochenkov
Pushing fedce67 to master...

@bors bors merged commit 780b544 into rust-lang:master Mar 9, 2018
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Mar 23, 2018
…chenkov Improve lint for type alias bounds First of all, I learned just today that I was wrong assuming that the bounds in type aliases are entirely ignored: It turns out they are used to resolve associated types in type aliases. So: ```rust type T1<U: Bound> = U::Assoc; // compiles type T2<U> = U::Assoc; // fails type T3<U> = <U as Bound>::Assoc; // "correct" way to write this, maybe? ``` I am sorry for creating this mess. This PR changes the wording of the lint accordingly. Moreover, since just removing the bound is no longer always a possible fix, I tried to detect cases like `T1` above and show a helpful message to the user: ``` warning: bounds on generic parameters are not enforced in type aliases --> $DIR/type-alias-bounds.rs:57:12 | LL | type T1<U: Bound> = U::Assoc; //~ WARN not enforced in type aliases | ^^^^^ | = help: the bound will not be checked when the type alias is used, and should be removed help: use absolute paths (i.e., <T as Trait>::Assoc) to refer to associated types in type aliases --> $DIR/type-alias-bounds.rs:57:21 | LL | type T1<U: Bound> = U::Assoc; //~ WARN not enforced in type aliases | ^^^^^^^^ ``` I am not sure if I got this entirely right. Ideally, we could provide a suggestion involving the correct trait and type name -- however, while I have access to the HIR in the lint, I do not know how to get access to the resolved name information, like which trait `Assoc` belongs to above. The lint does not even run if that resolution fails, so I assume that information is available *somewhere*... This is a follow-up for (parts of) rust-lang#48326. Also see rust-lang#21903. This changes the name of a lint, but that lint was just merged to master yesterday and has never even been on beta.
@RalfJung RalfJung deleted the generic-bounds branch July 10, 2018 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.