Skip to content

Commit

Permalink
Avoid redundant type error label in assert!
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Mar 17, 2024
1 parent 3737314 commit ead1593
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 17 deletions.
8 changes: 4 additions & 4 deletions compiler/rustc_builtin_macros/src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ fn expand_cond(cx: &ExtCtxt<'_>, parser: Parser<'_>, cond_expr: P<Expr>) -> P<Ex
// entire macro call. If a non-`bool` is passed that doesn't implement `trait Not`, we won't
// talk about traits, we'll just state the appropriate type error.
// `let assert_macro: bool = $expr;`
let ident = Ident::new(sym::assert_macro, span);
let ident = Ident::new(sym::assert_macro, DUMMY_SP);
let local = P(ast::Local {
ty: Some(P(ast::Ty {
kind: ast::TyKind::Path(None, ast::Path::from_ident(Ident::new(sym::bool, span))),
kind: ast::TyKind::Path(None, ast::Path::from_ident(Ident::new(sym::bool, DUMMY_SP))),
id: ast::DUMMY_NODE_ID,
span,
span: DUMMY_SP,
tokens: None,
})),
pat: parser.mk_pat_ident(span, ast::BindingAnnotation::NONE, ident),
pat: parser.mk_pat_ident(DUMMY_SP, ast::BindingAnnotation::NONE, ident),
kind: ast::LocalKind::Init(cond_expr),
id: ast::DUMMY_NODE_ID,
span,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) {
match (self.tcx.parent_hir_node(expr.hir_id), error) {
(hir::Node::Local(hir::Local { ty: Some(ty), init: Some(init), .. }), _)
if init.hir_id == expr.hir_id =>
if init.hir_id == expr.hir_id && !ty.span.is_dummy() =>
{
// Point at `let` assignment type.
err.span_label(ty.span, "expected due to this");
Expand Down
5 changes: 1 addition & 4 deletions tests/ui/codemap_tests/issue-28308.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-28308.rs:2:13
|
LL | assert!("foo");
| ^^^^^
| |
| expected `bool`, found `&str`
| expected due to this
| ^^^^^ expected `bool`, found `&str`

error: aborting due to 1 previous error

Expand Down
5 changes: 1 addition & 4 deletions tests/ui/issues/issue-14091-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-14091-2.rs:15:13
|
LL | assert!(x, x);
| ^
| |
| expected `bool`, found `BytePos`
| expected due to this
| ^ expected `bool`, found `BytePos`

error: aborting due to 1 previous error

Expand Down
5 changes: 1 addition & 4 deletions tests/ui/issues/issue-14091.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-14091.rs:2:13
|
LL | assert!(1,1);
| ^
| |
| expected `bool`, found integer
| expected due to this
| ^ expected `bool`, found integer

error: aborting due to 1 previous error

Expand Down

0 comments on commit ead1593

Please sign in to comment.