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

Refactor away TraitRef::trait_def_id #60465

Open
oli-obk opened this issue May 2, 2019 · 6 comments
Open

Refactor away TraitRef::trait_def_id #60465

oli-obk opened this issue May 2, 2019 · 6 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oli-obk
Copy link
Contributor

oli-obk commented May 2, 2019

The function

rust/src/librustc/hir/mod.rs

Lines 2150 to 2155 in 9b67bd4

pub fn trait_def_id(&self) -> DefId {
match self.path.def {
Def::Trait(did) => did,
Def::TraitAlias(did) => did,
Def::Err => {
FatalError.raise();

can abort compilation in case of errors. We're trying to eliminate as many (if not all) early aborts, so this needs to go. I haven't looked into how to fix this yet at all.

Originally reported in https://github.com/rust-lang/rust/pull/60462/files#r280262620

cc @estebank

@oli-obk oli-obk added A-diagnostics Area: Messages for errors, warnings, and lints E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. labels May 2, 2019
@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 2, 2019
@marmeladema
Copy link
Contributor

Hello! I tried to look at that issue but it looks like its already fixed?

@bjorn3
Copy link
Member

bjorn3 commented Apr 3, 2020

The code was moved to

rust/src/librustc_hir/hir.rs

Lines 2206 to 2212 in 34f7f55

pub fn trait_def_id(&self) -> Option<DefId> {
match self.path.res {
Res::Def(DefKind::Trait | DefKind::TraitAlias, did) => Some(did),
Res::Err => None,
_ => unreachable!(),
}
}

We recently split the librustc crate into multiple smaller crates like librustc_hir. Then librustc got renamed to librustc_middle.

@marmeladema
Copy link
Contributor

In this code, the call to FatalError.raise(); for the Res::Err arm is gone. That's i thought it was fixed. Is the issue about the call to unreachable!() or about the caller that might fatal error when None is returned?

@bjorn3
Copy link
Member

bjorn3 commented Apr 3, 2020

unreachable!() has even worse ergonomics than fatal errors as it causes a compiler panic (ICE). I think this issue if about the _ => ... arm of the match that should be avoided.

@crlf0710 crlf0710 added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jun 11, 2020
@bugadani
Copy link
Contributor

bugadani commented Oct 3, 2020

I've started working on this. So far, I don't understand why some of the downstream code can FatalError.raise(); if the DefId is None, while other parts ignore it.

@estebank
Copy link
Contributor

estebank commented Oct 3, 2020

@bugadani without knowing the specifics, the answer to that is usually just historical baggage: the compiler for a long time just relied on FatalError.raise() to avoid over-complicating later stages of the compiler. Now, in an effort to improve the user experience, we've tried to make errors non-fatal and later stages resilient to incomplete data. In some cases making that kind of change would be so big that we have punted on doing it and left FatalError.raise() in place instead of making their scope fallible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants