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

Don't use Res::Err without emitting an error 1/* #72108

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/librustc_ast_lowering/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::LocalDefId;
use rustc_span::source_map::{respan, DesugaringKind};
use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::Span;
use rustc_span::{Span, DUMMY_SP};
use rustc_target::spec::abi;

use log::debug;
Expand Down Expand Up @@ -482,7 +482,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
let mut resolutions = self.expect_full_res_from_use(id);
// We want to return *something* from this function, so hold onto the first item
// for later.
let ret_res = self.lower_res(resolutions.next().unwrap_or(Res::Err));
let ret_res = self.lower_res(resolutions.next().unwrap_or_else(|| {
self.sess.delay_span_bug(
DUMMY_SP,
&format!("missing `ret_res` for use_tree: {:?}", tree),
);
Res::Err
}));

// Here, we are looping over namespaces, if they exist for the definition
// being imported. We only handle type and value namespaces because we
Expand Down
25 changes: 12 additions & 13 deletions src/librustc_passes/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,19 @@ impl Visitor<'tcx> for ExprVisitor<'tcx> {
}

fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) {
let res = if let hir::ExprKind::Path(ref qpath) = expr.kind {
self.tables.qpath_res(qpath, expr.hir_id)
} else {
Res::Err
};
if let Res::Def(DefKind::Fn, did) = res {
if self.def_id_is_transmute(did) {
let typ = self.tables.node_type(expr.hir_id);
let sig = typ.fn_sig(self.tcx);
let from = sig.inputs().skip_binder()[0];
let to = *sig.output().skip_binder();
self.check_transmute(expr.span, from, to);
if let hir::ExprKind::Path(ref qpath) = expr.kind {
let res = self.tables.qpath_res(qpath, expr.hir_id);

if let Res::Def(DefKind::Fn, did) = res {
if self.def_id_is_transmute(did) {
let typ = self.tables.node_type(expr.hir_id);
let sig = typ.fn_sig(self.tcx);
let from = sig.inputs().skip_binder()[0];
let to = *sig.output().skip_binder();
self.check_transmute(expr.span, from, to);
}
}
}
};

intravisit::walk_expr(self, expr);
}
Expand Down