Skip to content

Commit eb411c1

Browse files
committed
Avoid redundant type error label in assert!
1 parent 4bf9b53 commit eb411c1

File tree

5 files changed

+8
-17
lines changed

5 files changed

+8
-17
lines changed

compiler/rustc_builtin_macros/src/assert.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,15 @@ fn expand_cond(cx: &ExtCtxt<'_>, parser: Parser<'_>, cond_expr: P<Expr>) -> P<Ex
171171
// entire macro call. If a non-`bool` is passed that doesn't implement `trait Not`, we won't
172172
// talk about traits, we'll just state the appropriate type error.
173173
// `let assert_macro: bool = $expr;`
174-
let ident = Ident::new(sym::assert_macro, span);
174+
let ident = Ident::new(sym::assert_macro, DUMMY_SP);
175175
let local = P(ast::Local {
176176
ty: Some(P(ast::Ty {
177-
kind: ast::TyKind::Path(None, ast::Path::from_ident(Ident::new(sym::bool, span))),
177+
kind: ast::TyKind::Path(None, ast::Path::from_ident(Ident::new(sym::bool, DUMMY_SP))),
178178
id: ast::DUMMY_NODE_ID,
179-
span,
179+
span: DUMMY_SP,
180180
tokens: None,
181181
})),
182-
pat: parser.mk_pat_ident(span, ast::BindingAnnotation::NONE, ident),
182+
pat: parser.mk_pat_ident(DUMMY_SP, ast::BindingAnnotation::NONE, ident),
183183
kind: ast::LocalKind::Init(cond_expr),
184184
id: ast::DUMMY_NODE_ID,
185185
span,

compiler/rustc_hir_typeck/src/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
679679
) {
680680
match (self.tcx.parent_hir_node(expr.hir_id), error) {
681681
(hir::Node::Local(hir::Local { ty: Some(ty), init: Some(init), .. }), _)
682-
if init.hir_id == expr.hir_id =>
682+
if init.hir_id == expr.hir_id && !ty.span.is_dummy() =>
683683
{
684684
// Point at `let` assignment type.
685685
err.span_label(ty.span, "expected due to this");

tests/ui/codemap_tests/issue-28308.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-28308.rs:2:13
33
|
44
LL | assert!("foo");
5-
| ^^^^^
6-
| |
7-
| expected `bool`, found `&str`
8-
| expected due to this
5+
| ^^^^^ expected `bool`, found `&str`
96

107
error: aborting due to 1 previous error
118

tests/ui/issues/issue-14091-2.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-14091-2.rs:15:13
33
|
44
LL | assert!(x, x);
5-
| ^
6-
| |
7-
| expected `bool`, found `BytePos`
8-
| expected due to this
5+
| ^ expected `bool`, found `BytePos`
96

107
error: aborting due to 1 previous error
118

tests/ui/issues/issue-14091.stderr

+1-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-14091.rs:2:13
33
|
44
LL | assert!(1,1);
5-
| ^
6-
| |
7-
| expected `bool`, found integer
8-
| expected due to this
5+
| ^ expected `bool`, found integer
96

107
error: aborting due to 1 previous error
118

0 commit comments

Comments
 (0)