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

Explain origin of implicit Sized obligations and provide suggestions when possible #85947

Closed
wants to merge 11 commits into from

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Jun 2, 2021

Built on top of #85799. Only last two commits are relevant.

@rust-highfive
Copy link
Collaborator

r? @jackh726

(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 Jun 2, 2021
Comment on lines +61 to +78
ty::AssocKind::Type => {
let default = match tcx.hir().get_if_local(self.def_id) {
Some(
hir::Node::TraitItem(hir::TraitItem {
kind: hir::TraitItemKind::Type(_, Some(ty)),
..
})
| hir::Node::ImplItem(hir::ImplItem {
kind: hir::ImplItemKind::TyAlias(ty),
..
}),
) => {
format!(" = {:?}", ty)
}
_ => String::new(),
};
format!("type {}{};", self.ident, default)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't have a test. It wasn't meant to be in this commit 🤦

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jun 4, 2021

☔ The latest upstream changes (presumably #85954) made this pull request unmergeable. Please resolve the merge conflicts.

@estebank
Copy link
Contributor Author

estebank commented Jun 4, 2021

@bors try @rust-timer queue

This should likely not be merged as is: the approach of signaling on the predicate isn't great.

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 4, 2021
@bors
Copy link
Contributor

bors commented Jun 4, 2021

🔒 Merge conflict

This pull request and the master branch diverged in a way that cannot be automatically merged. Please rebase on top of the latest master branch, and let the reviewer approve again.

How do I rebase?

Assuming self is your fork and upstream is this repository, you can resolve the conflict following these steps:

  1. git checkout type-trait-bound-span-2 (switch to your branch)
  2. git fetch upstream master (retrieve the latest master)
  3. git rebase upstream/master -p (rebase on top of it)
  4. Follow the on-screen instruction to resolve conflicts (check git status if you got lost).
  5. git push self type-trait-bound-span-2 --force-with-lease (update this PR)

You may also read Git Rebasing to Resolve Conflicts by Drew Blessing for a short tutorial.

Please avoid the "Resolve conflicts" button on GitHub. It uses git merge instead of git rebase which makes the PR commit history more difficult to read.

Sometimes step 4 will complete without asking for resolution. This is usually due to difference between how Cargo.lock conflict is handled during merge and rebase. This is normal, and you should still perform step 5 to update this PR.

Error message
Auto-merging src/tools/clippy/clippy_utils/src/ty.rs
CONFLICT (content): Merge conflict in src/tools/clippy/clippy_utils/src/ty.rs
Auto-merging src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
Auto-merging src/tools/clippy/clippy_lints/src/future_not_send.rs
Auto-merging compiler/rustc_typeck/src/collect.rs
Auto-merging compiler/rustc_mir/src/transform/check_consts/validation.rs
Auto-merging compiler/rustc_middle/src/ty/context.rs
Automatic merge failed; fix conflicts and then commit the result.

JohnTitor added a commit to JohnTitor/rust that referenced this pull request Jun 4, 2021
…r=estebank

don't suggest unsized indirection in where-clauses

Skip where-clauses when suggesting using indirection in combination with
`?Sized` bounds on type parameters.

Fixes rust-lang#85943.

`@estebank` I think this doesn't conflict with your work in rust-lang#85947; please let me know if you'd like me to cherry pick it to a new branch based on yours instead.
@estebank estebank force-pushed the type-trait-bound-span-2 branch 2 times, most recently from 956b415 to ee9375f Compare June 11, 2021 02:59
@estebank
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@bors
Copy link
Contributor

bors commented Jun 11, 2021

⌛ Trying commit 3956224 with merge 847b2268d073e67a8a5f3bebe53ca5846b2fcbe9...

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-10 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
   Compiling libc v0.2.93
   Compiling std v0.0.0 (/checkout/library/std)
   Compiling compiler_builtins v0.1.45
   Compiling unwind v0.0.0 (/checkout/library/unwind)
thread 'rustc' panicked at 'assertion failed: map[k].is_none()', compiler/rustc_middle/src/hir/map/collector.rs:50:5

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.
note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.54.0-nightly (22783366f 2021-06-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z macro-backtrace -Z crate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/") -Z binary-dep-depinfo -Z force-unstable-if-unmarked -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -C debuginfo=0 -C debug-assertions=on -C overflow-checks=off -C link-args=-Wl,-rpath,$ORIGIN/../lib -C prefer-dynamic -C llvm-args=-import-instr-limit=10 -C embed-bitcode=yes --crate-type lib
note: some of the compiler flags provided by cargo are hidden

query stack during panic:
query stack during panic:
thread 'rustc' panicked at 'already borrowed: BorrowMutError', /checkout/compiler/rustc_data_structures/src/sync.rs:423:16
stack backtrace:
   0:     0x7fe5086f0060 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5273f0fbd1c006fb
   1:     0x7fe50875ec0c - core::fmt::write::h9c2f5dc0511907c8
   2:     0x7fe5086e1235 - std::io::Write::write_fmt::h14e3582a4a15dba5
   3:     0x7fe5086f44f7 - std::panicking::default_hook::{{closure}}::h325bba56db83cd67
   4:     0x7fe5086f3ef1 - std::panicking::default_hook::h512e31ed380fe707
   5:     0x7fe50920085d - rustc_driver::report_ice::h775c34be56e050cc
   6:     0x7fe5086f4d18 - std::panicking::rust_panic_with_hook::h8e27854352b22ef1
   7:     0x7fe5086f4827 - std::panicking::begin_panic_handler::{{closure}}::h7062a41d7e6c56f6
   8:     0x7fe5086f051c - std::sys_common::backtrace::__rust_end_short_backtrace::hf35148a98563df89
   9:     0x7fe5086f4789 - rust_begin_unwind
  10:     0x7fe5086b5be1 - core::panicking::panic_fmt::hb520c4f540682c9c
  11:     0x7fe5086b5dd3 - core::result::unwrap_failed::hc6bdcd9ade28635f
  12:     0x7fe509cfb400 - rustc_query_system::query::plumbing::get_query_impl::h46e9c4ff8b45931a
  13:     0x7fe509e64803 - rustc_query_system::query::plumbing::get_query::h8092eec6dcac42b2
  14:     0x7fe50b4b918e - rustc_middle::hir::map::Map::find::h0cbb0c468c6cc92e
  15:     0x7fe50b4bc2e8 - rustc_middle::hir::map::Map::opt_span::h42158e9b3d231f7c
  16:     0x7fe50b4aaec5 - core::ops::function::FnOnce::call_once::h5c05252fbc4d0baa
  17:     0x7fe509d03e9e - rustc_query_system::query::plumbing::get_query_impl::h59336026d9d55034
  18:     0x7fe509e72fb1 - rustc_query_system::query::plumbing::get_query::hcc492a442637fc22
  19:     0x7fe509f53c6b - <rustc_span::def_id::DefId as rustc_query_impl::keys::Key>::default_span::ha6ffbcb0fa28e692
  20:     0x7fe509f53b67 - <rustc_span::def_id::LocalDefId as rustc_query_impl::keys::Key>::default_span::haaa5deacb7f5a586
  21:     0x7fe509fd894f - rustc_query_impl::make_query::hir_owner::h02217af551434ea7
  22:     0x7fe509e263e0 - rustc_query_system::query::plumbing::QueryState<D,K>::try_collect_active_jobs::hcef6d5e18f8d325e
  23:     0x7fe509f77a4b - rustc_query_impl::Queries::try_collect_active_jobs::hf6e79bd2724db55a
  24:     0x7fe509ec8cf1 - rustc_query_system::query::job::print_query_stack::h7a4278bf190dbc07
  25:     0x7fe509318234 - rustc_interface::interface::try_print_query_stack::hf6df9355d28ced88
  26:     0x7fe5092010b9 - rustc_driver::report_ice::h775c34be56e050cc
  27:     0x7fe5086f4d18 - std::panicking::rust_panic_with_hook::h8e27854352b22ef1
  28:     0x7fe5086f47f7 - std::panicking::begin_panic_handler::{{closure}}::h7062a41d7e6c56f6
  29:     0x7fe5086f051c - std::sys_common::backtrace::__rust_end_short_backtrace::hf35148a98563df89
  30:     0x7fe5086f4789 - rust_begin_unwind
  31:     0x7fe5086b5be1 - core::panicking::panic_fmt::hb520c4f540682c9c
  32:     0x7fe5086b5b2d - core::panicking::panic::hc07338839eea1cdf
  33:     0x7fe50b423017 - rustc_middle::hir::map::collector::NodeCollector::insert_entry::h5e8179a3b81bc750
  34:     0x7fe50b4231a4 - rustc_middle::hir::map::collector::NodeCollector::insert_with_hash::he88b3b85d232ff78
  35:     0x7fe50b4249e1 - <rustc_middle::hir::map::collector::NodeCollector as rustc_hir::intravisit::Visitor>::visit_trait_ref::hab0433a1d2ef97f5
  36:     0x7fe50b4b1d0f - rustc_hir::intravisit::walk_where_predicate::hd5761a06516e2086
  37:     0x7fe50b4b05cc - rustc_hir::intravisit::walk_impl_item::hcd4d5e2d4af18c42
  38:     0x7fe50b4246d4 - <rustc_middle::hir::map::collector::NodeCollector as rustc_hir::intravisit::Visitor>::visit_impl_item::h480c2695ceff7233
  39:     0x7fe50b4b4e14 - rustc_hir::intravisit::walk_item::h329d9b04f3ddac90
  40:     0x7fe50b423fd7 - <rustc_middle::hir::map::collector::NodeCollector as rustc_hir::intravisit::Visitor>::visit_item::he0c58ed3451658d7
  41:     0x7fe50b423700 - <rustc_middle::hir::map::collector::NodeCollector as rustc_hir::intravisit::Visitor>::visit_nested_item::h56d5c5181731a48a
  42:     0x7fe50b4b4e9a - rustc_hir::intravisit::walk_item::h329d9b04f3ddac90
  43:     0x7fe50b423fd7 - <rustc_middle::hir::map::collector::NodeCollector as rustc_hir::intravisit::Visitor>::visit_item::he0c58ed3451658d7
  44:     0x7fe50b423700 - <rustc_middle::hir::map::collector::NodeCollector as rustc_hir::intravisit::Visitor>::visit_nested_item::h56d5c5181731a48a
  45:     0x7fe50b4b4e9a - rustc_hir::intravisit::walk_item::h329d9b04f3ddac90
  46:     0x7fe50b423fd7 - <rustc_middle::hir::map::collector::NodeCollector as rustc_hir::intravisit::Visitor>::visit_item::he0c58ed3451658d7
  47:     0x7fe50b423700 - <rustc_middle::hir::map::collector::NodeCollector as rustc_hir::intravisit::Visitor>::visit_nested_item::h56d5c5181731a48a
  48:     0x7fe50b4bd68b - rustc_middle::hir::map::index_hir::h1d2d4fea197db3ca
  49:     0x7fe509d1fcb0 - rustc_query_system::query::plumbing::get_query_impl::h875dae9649ad9d8d
  50:     0x7fe509e55235 - rustc_query_system::query::plumbing::get_query::h2e8f16d97951e3ae
  51:     0x7fe50b4aa41a - core::ops::function::FnOnce::call_once::h0dbd9998b554bf45
  52:     0x7fe509cfb0c7 - rustc_query_system::query::plumbing::get_query_impl::h46e9c4ff8b45931a
  53:     0x7fe509e64803 - rustc_query_system::query::plumbing::get_query::h8092eec6dcac42b2
  54:     0x7fe50b4b918e - rustc_middle::hir::map::Map::find::h0cbb0c468c6cc92e
  55:     0x7fe50b4b965c - rustc_middle::hir::map::Map::item::h7f7f90827d66dd99
  56:     0x7fe50a24e7d8 - rustc_middle::hir::map::Map::visit_item_likes_in_module::h82b331764a65fea4
  57:     0x7fe50a28be3b - rustc_passes::hir_id_validator::check_crate::h2a91ce24192248e8
  58:     0x7fe50932d80f - rustc_interface::passes::analysis::hb76d88494362c076
  59:     0x7fe509cdab3a - rustc_query_system::query::plumbing::get_query_impl::h07878d2cbc2337ab
  60:     0x7fe509e610c8 - rustc_query_system::query::plumbing::get_query::h72c0f73f7ff660e5
  61:     0x7fe50926d7ce - rustc_interface::passes::QueryContext::enter::h46b03bff40819a7b
  62:     0x7fe509248828 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter::hb9ee6c100abc1750
  63:     0x7fe5092178aa - rustc_span::with_source_map::ha64dea0cc5926920
  64:     0x7fe5092498f8 - rustc_interface::interface::create_compiler_and_run::h12980bdad61b3f93
  65:     0x7fe509217f22 - rustc_span::with_session_globals::h2694f79fd8cb6f1a
  66:     0x7fe50926dd9d - std::sys_common::backtrace::__rust_begin_short_backtrace::h9e5fc42faa5c26c7
  67:     0x7fe50926e276 - std::panicking::try::h2aeb1a16afbef4b8
  68:     0x7fe509203293 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h3d5ed8e05a193447
  69:     0x7fe5087016d7 - std::sys::unix::thread::Thread::new::thread_start::h46202cfe4c4c2613
  70:     0x7fe5033b66db - start_thread
  71:     0x7fe50838271f - __clone
  72:                0x0 - <unknown>
error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.


note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.54.0-nightly (22783366f 2021-06-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z macro-backtrace -Z crate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/") -Z binary-dep-depinfo -Z force-unstable-if-unmarked -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -C debuginfo=0 -C debug-assertions=on -C overflow-checks=off -C link-args=-Wl,-rpath,$ORIGIN/../lib -C prefer-dynamic -C llvm-args=-import-instr-limit=10 -C embed-bitcode=yes --crate-type lib
note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
end of query stack
thread panicked while panicking. aborting.
rustc exited with signal: 4 (core dumped)

Caused by:
Caused by:
  process didn't exit successfully: `/checkout/obj/build/bootstrap/debug/rustc --crate-name core --edition=2018 library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -C debuginfo=0 -C debug-assertions=on -C overflow-checks=off -C metadata=eabf50a85df947a1 -C extra-filename=-eabf50a85df947a1 --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps --target x86_64-unknown-linux-gnu -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/release/deps -L dependency=/checkout/obj/build/x86_64-unknown-linux-gnu/stage1-std/release/deps -Zmacro-backtrace '-Clink-args=-Wl,-rpath,$ORIGIN/../lib' -Cprefer-dynamic -Cllvm-args=-import-instr-limit=10 -Cembed-bitcode=yes '-Zcrate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/")' -Z binary-dep-depinfo` (exit status: 254)
error: build failed
command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-Zbinary-dep-depinfo" "-j" "16" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/checkout/library/test/Cargo.toml" "--message-format" "json-render-diagnostics"
expected success, got: exit status: 101
failed to run: /checkout/obj/build/bootstrap/debug/bootstrap --stage 2 test --exclude src/tools/tidy

@bors
Copy link
Contributor

bors commented Jun 11, 2021

☀️ Try build successful - checks-actions
Build commit: 847b2268d073e67a8a5f3bebe53ca5846b2fcbe9 (847b2268d073e67a8a5f3bebe53ca5846b2fcbe9)

@rust-timer
Copy link
Collaborator

Queued 847b2268d073e67a8a5f3bebe53ca5846b2fcbe9 with parent 46ad16b, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (847b2268d073e67a8a5f3bebe53ca5846b2fcbe9): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never
@rustbot label: +S-waiting-on-review -S-waiting-on-perf

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 11, 2021
@tlyu
Copy link
Contributor

tlyu commented Jun 13, 2021

I'm sorry if this is completely off base; I am not completely certain about my understanding of AST lowering and HIR.

thread 'rustc' panicked at 'assertion failed: map[k].is_none()', compiler/rustc_middle/src/hir/map/collector.rs:50:5

To me, this looked like a HIR invariant being violated. I think the ?Sized bound is being duplicated during AST lowering without getting fresh HirId values. Unfortunately, fixing that is somewhat complicated because it isn't a leaf node that's being lowered, so I think we would have to recursively get fresh HirId values?

Also, I think the existing code that moves the ?Sized bound from the where clause to the generic parameters is already fairly complicated and fragile. Adding complexity on top of that seems risky to me. I think it would be better to rethink how the trait bound predicates are being collected during type checking, but that's admittedly also difficult.

On a hunch, I dumped the -Zunpretty=hir-tree from a simple test file:

struct A<T>(&T) where T: ?Sized;

and got something including this (note the repeated HirId values in the TraitRef (local_id = 8) and PathSegment (local_id = 7) inside the PolyTraitRef values; also sorry I don't know how to highlight lines within code blocks):

Generics {
    params: [
        GenericParam {
(param name)
            hir_id: HirId {
                owner: DefId(0:3 ~ lib[317d]::A),
                local_id: 9,
            },
            name: Plain(
                T#0,
            ),
            bounds: [
                Trait(
                    PolyTraitRef {
                        bound_generic_params: [],
                        trait_ref: TraitRef {
                            path: Path {
(span; path resolution)
                                span: lib.rs:1:27: 1:32 (#0),
                                res: Def(
                                    Trait,
                                    DefId(2:2854 ~ core[1d1a]::marker::Sized),
                                ),
                                segments: [
                                    PathSegment {
                                        ident: Sized#0,
                                        hir_id: Some(
                                            HirId {
                                                owner: DefId(0:3 ~ lib[317d]::A),
                                                local_id: 7,
                                            },
                                        ),
(path resolution; trailing fields)
                                        res: Some(
                                            Def(
                                                Trait,
                                                DefId(2:2854 ~ core[1d1a]::marker::Sized),
                                            ),
                                        ),
                                        args: None,
                                        infer_args: false,
                                    },
                                ],
                            },
                            hir_ref_id: HirId {
                                owner: DefId(0:3 ~ lib[317d]::A),
                                local_id: 8,
                            },
(trailing fields)
                        },
                        span: lib.rs:1:26: 1:32 (#0),
                    },
                    Maybe,
                ),
            ],
            span: lib.rs:1:10: 1:11 (#0),
            pure_wrt_drop: false,
            kind: Type {
                default: None,
                synthetic: None,
            },
        },
    ],
    where_clause: WhereClause {
        predicates: [
            BoundPredicate(
                WhereBoundPredicate {
(leading fields; bounded_ty)
                    span: lib.rs:1:23: 1:32 (#0),
                    bound_generic_params: [],
                    bounded_ty: Ty {
                        hir_id: HirId {
                            owner: DefId(0:3 ~ lib[317d]::A),
                            local_id: 10,
                        },
                        kind: Path(
                            Resolved(
                                None,
                                Path {
                                    span: lib.rs:1:23: 1:24 (#0),
                                    res: Def(
                                        TyParam,
                                        DefId(0:5 ~ lib[317d]::A::T),
                                    ),
                                    segments: [
                                        PathSegment {
                                            ident: T#0,
                                            hir_id: Some(
                                                HirId {
                                                    owner: DefId(0:3 ~ lib[317d]::A),
                                                    local_id: 11,
                                                },
                                            ),
                                            res: Some(
                                                Def(
                                                    TyParam,
                                                    DefId(0:5 ~ lib[317d]::A::T),
                                                ),
                                            ),
                                            args: None,
                                            infer_args: false,
                                        },
                                    ],
                                },
                            ),
                        ),
                        span: lib.rs:1:23: 1:24 (#0),
                    },
                    bounds: [
                        Trait(
                            PolyTraitRef {
                                bound_generic_params: [],
                                trait_ref: TraitRef {
                                    path: Path {
(span; path resolution)
                                        span: lib.rs:1:27: 1:32 (#0),
                                        res: Def(
                                            Trait,
                                            DefId(2:2854 ~ core[1d1a]::marker::Sized),
                                        ),
                                        segments: [
                                            PathSegment {
                                                ident: Sized#0,
                                                hir_id: Some(
                                                    HirId {
                                                        owner: DefId(0:3 ~ lib[317d]::A),
                                                        local_id: 7,
                                                    },
(path resolution; trailing fields)
                                                ),
                                                res: Some(
                                                    Def(
                                                        Trait,
                                                        DefId(2:2854 ~ core[1d1a]::marker::Sized),
                                                    ),
                                                ),
                                                args: None,
                                                infer_args: false,
                                            },
                                        ],
                                    },
                                    hir_ref_id: HirId {
                                        owner: DefId(0:3 ~ lib[317d]::A),
                                        local_id: 8,
                                    },
(trailing fields)
                                },
                                span: lib.rs:1:26: 1:32 (#0),
                            },
                            Maybe,
                        ),
                    ],
                },
            ),
        ],
        span: lib.rs:1:17: 1:32 (#0),
    },

@tlyu
Copy link
Contributor

tlyu commented Jun 13, 2021

Also, I confirmed a build failure for the stage1 library/std with

f338867 Suggest removal of ?Sized bound when appropriate

and success with

6fdf73f Fix rebase

Same assertion failure:

thread 'rustc' panicked at 'assertion failed: map[k].is_none()', compiler/rustc_middle/src/hir/map/collector.rs:50:5

during

rustc --crate-name core --edition=2018 library/core/src/lib.rs …

and it looks like f338867 did change some relevant AST lowering code.

@jackh726 jackh726 added the S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. label Jun 24, 2021
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 12, 2021
@JohnTitor JohnTitor removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 13, 2021
@estebank
Copy link
Contributor Author

Closing as #85799 has all the commits here, I'll try to land everything together, and split it if asked by reviewer.

@estebank estebank closed this Jul 20, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Oct 15, 2021
…stebank

move implicit `Sized` predicate to end of list

In `Bounds::predicates()`, move the implicit `Sized` predicate to the
end of the generated list. This means that if there is an explicit
`Sized` bound, it will be checked first, and any resulting
diagnostics will have a more useful span.

Fixes rust-lang#85998, at least partially. ~~Based on rust-lang#85979, but only the last 2 commits are new for this pull request.~~ (edit: rebased) A full fix would need to deal with where-clauses, and that seems difficult. Basically, predicates are being collected in multiple stages, and there are two places where implicit `Sized` predicates can be inserted: once for generic parameters, and once for where-clauses. I think this insertion is happening too early, and we should actually do it only at points where we collect all of the relevant trait bounds for a type parameter.

I could use some help interpreting the changes to the stderr output. It looks like reordering the predicates changed some diagnostics that don't obviously have anything to do with `Sized` bounds. Possibly some error reporting code is making assumptions about ordering of predicates? The diagnostics for src/test/ui/derives/derives-span-Hash-*.rs seem to have improved, no longer pointing at the type parameter identifier, but src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs became less verbose for some reason.

I also ran into an instance of rust-lang#84970 while working on this, but I kind of expected that could happen, because I'm reordering predicates. I can open a separate issue on that if it would be helpful.

`@estebank` this seems likely to conflict (slightly?) with your work on rust-lang#85947; how would you like to resolve that?
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Oct 15, 2021
…stebank

move implicit `Sized` predicate to end of list

In `Bounds::predicates()`, move the implicit `Sized` predicate to the
end of the generated list. This means that if there is an explicit
`Sized` bound, it will be checked first, and any resulting
diagnostics will have a more useful span.

Fixes rust-lang#85998, at least partially. ~~Based on rust-lang#85979, but only the last 2 commits are new for this pull request.~~ (edit: rebased) A full fix would need to deal with where-clauses, and that seems difficult. Basically, predicates are being collected in multiple stages, and there are two places where implicit `Sized` predicates can be inserted: once for generic parameters, and once for where-clauses. I think this insertion is happening too early, and we should actually do it only at points where we collect all of the relevant trait bounds for a type parameter.

I could use some help interpreting the changes to the stderr output. It looks like reordering the predicates changed some diagnostics that don't obviously have anything to do with `Sized` bounds. Possibly some error reporting code is making assumptions about ordering of predicates? The diagnostics for src/test/ui/derives/derives-span-Hash-*.rs seem to have improved, no longer pointing at the type parameter identifier, but src/test/ui/type-alias-impl-trait/generic_duplicate_param_use9.rs became less verbose for some reason.

I also ran into an instance of rust-lang#84970 while working on this, but I kind of expected that could happen, because I'm reordering predicates. I can open a separate issue on that if it would be helpful.

``@estebank`` this seems likely to conflict (slightly?) with your work on rust-lang#85947; how would you like to resolve that?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants