Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash ./ui/trivial-bounds/trivial-bounds-inconsistent.rs #3969

Closed
matthiaskrgr opened this issue Apr 15, 2019 · 4 comments · Fixed by #5663
Closed

crash ./ui/trivial-bounds/trivial-bounds-inconsistent.rs #3969

matthiaskrgr opened this issue Apr 15, 2019 · 4 comments · Fixed by #5663
Labels
C-bug Category: Clippy is not doing the correct thing E-needs-test Call for participation: writing tests I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@matthiaskrgr
Copy link
Member

#3142

code from rust src/test/trivial-bounds/trivial-bounds-inconsistent.rs

// run-pass

// Check that tautalogically false bounds are accepted, and are used
// in type inference.
#![feature(trivial_bounds)]
#![allow(unused)]


trait A {}

impl A for i32 {}

struct Dst<X: ?Sized> {
    x: X,
}

struct TwoStrs(str, str) where str: Sized;

fn unsized_local() where for<'a> Dst<A + 'a>: Sized {
    let x: Dst<A> = *(Box::new(Dst { x: 1 }) as Box<Dst<A>>);
}

fn return_str() -> str where str: Sized {
    *"Sized".to_string().into_boxed_str()
}

fn use_op(s: String) -> String where String: ::std::ops::Neg<Output=String> {
    -s
}

fn use_for() where i32: Iterator {
    for _ in 2i32 {}
}

fn main() {}
    Checking crash v0.1.0 (/tmp/crash)
error: internal compiler error: src/librustc_traits/normalize_erasing_regions.rs:43: could not fully normalize `<i32 as std::iter::Iterator>::Item`

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:635: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 src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:197
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::util::bug::opt_span_bug_fmt
  13: rustc::util::bug::bug_fmt
  14: rustc::ty::context::GlobalCtxt::enter_local
  15: rustc_traits::normalize_erasing_regions::normalize_ty_after_erasing_regions
  16: rustc::ty::query::__query_compute::normalize_ty_after_erasing_regions
  17: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::normalize_ty_after_erasing_regions>::compute
  18: rustc::dep_graph::graph::DepGraph::with_task_impl
  19: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  20: <rustc::traits::query::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder as rustc::ty::fold::TypeFolder>::fold_ty
  21: rustc_mir::util::elaborate_drops::DropCtxt<D>::move_paths_for_fields::{{closure}}
  22: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T,I>>::from_iter
  23: rustc_mir::util::elaborate_drops::DropCtxt<D>::elaborate_drop
  24: <rustc_mir::transform::elaborate_drops::ElaborateDrops as rustc_mir::transform::MirPass>::run_pass
  25: rustc_mir::transform::run_passes::{{closure}}
  26: rustc_mir::transform::run_passes
  27: rustc_mir::transform::optimized_mir
  28: rustc::ty::query::__query_compute::optimized_mir
  29: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute
  30: rustc::dep_graph::graph::DepGraph::with_task_impl
  31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  32: <clippy_lints::implicit_return::Pass as rustc::lint::LateLintPass>::check_fn
  33: <rustc::lint::context::LateLintPassObjects as rustc::lint::LateLintPass>::check_fn
  34: rustc::hir::intravisit::walk_item
  35: rustc::hir::intravisit::Visitor::visit_nested_item
  36: rustc::hir::intravisit::walk_crate
  37: rustc::lint::context::late_lint_pass_crate
  38: rustc::lint::context::late_lint_crate
  39: rustc_data_structures::sync::serial_join
  40: rustc::util::common::time
  41: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:87
  42: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  43: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:87
  44: rustc_interface::passes::analysis::{{closure}}
  45: rustc::util::common::time
  46: rustc_interface::passes::analysis
  47: rustc::ty::query::__query_compute::analysis
  48: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::analysis>::compute
  49: rustc::dep_graph::graph::DepGraph::with_task_impl
  50: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  51: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  52: rustc_interface::passes::create_global_ctxt::{{closure}}
  53: rustc_interface::interface::run_compiler_in_existing_thread_pool
  54: std::thread::local::LocalKey<T>::with
  55: scoped_tls::ScopedKey<T>::set
  56: syntax::with_globals
query stack during panic:
#0 [normalize_ty_after_erasing_regions] normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All, def_id: None }, value: <i32 as std::iter::Iterator>::Item }`
#1 [optimized_mir] processing `use_for`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error


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.35.0-nightly (3de010678 2019-04-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental -C target-cpu=native --crate-type bin

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `crash`.

To learn more, run the command again with --verbose.

clippy 0.0.212 (37f5c1e 2019-04-09)

@matthiaskrgr matthiaskrgr added C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ labels Apr 15, 2019
@phansch phansch self-assigned this Apr 16, 2019
@phansch
Copy link
Member

phansch commented Apr 16, 2019

I'm not sure if that's a bug in Clippy. As far as I can tell, we do everything right when creating the MIR:

    fn check_fn(
        &mut self,
        cx: &LateContext<'a, 'tcx>,
        _: FnKind<'tcx>,
        _: &'tcx FnDecl,
        body: &'tcx Body,
        span: Span,
        _: HirId,
    ) {
        let def_id = cx.tcx.hir().body_owner_def_id(body.id());
        let mir = cx.tcx.optimized_mir(def_id);
        // crash here ^
    }

With the example code the crash happens in every place where we call tcx.optimized_mir(). Also in redundant_clone and missing_const_for_fn.

I think this may related to rust-lang/rust#54114 and I bet it will also fail in rustc if mir-opt-level=3 is set.

cc @oli-obk

@phansch
Copy link
Member

phansch commented Apr 16, 2019

Oh, maybe we should just use mir_validated instead.

@oli-obk
Copy link
Contributor

oli-obk commented Apr 16, 2019

Oh, maybe we should just use mir_validated instead.

It's likely that won't work, as mir_optimized steals the MIR object from mir_validated.

I think this may related to rust-lang/rust#54114 and I bet it will also fail in rustc if mir-opt-level=3 is set.

I just checked the backtraces. This ICE is happening in transform::elaborate_drops::ElaborateDrops while rust-lang/rust#54114 is a const eval issue. They may have the same underlying rustc problem though

@phansch phansch removed their assignment Apr 20, 2019
@matthiaskrgr matthiaskrgr added the E-needs-test Call for participation: writing tests label May 17, 2020
@matthiaskrgr
Copy link
Member Author

Looks like this no longer crashes.

bors added a commit that referenced this issue May 29, 2020
add testcase that no longer ICEs

Fixes #3969

changelog: none
flip1995 added a commit to flip1995/rust-clippy that referenced this issue May 31, 2020
…shearth

add testcase that no longer ICEs

Fixes rust-lang#3969

changelog: none
@bors bors closed this as completed in b92cc8a May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing E-needs-test Call for participation: writing tests I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants