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

Fix issue with specifying generic arguments for primitive types #78089

Merged
merged 1 commit into from
Oct 19, 2020
Merged
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
16 changes: 10 additions & 6 deletions compiler/rustc_typeck/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,16 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
tcx.sess.delay_span_bug(tcx.def_span(def_id), "anon const with Res::Err");
return None;
}
_ => span_bug!(
DUMMY_SP,
"unexpected anon const res {:?} in path: {:?}",
res,
path,
),
_ => {
// If the user tries to specify generics on a type that does not take them,
// e.g. `usize<T>`, we may hit this branch, in which case we treat it as if
// no arguments have been passed. An error should already have been emitted.
tcx.sess.delay_span_bug(
tcx.def_span(def_id),
&format!("unexpected anon const res {:?} in path: {:?}", res, path),
);
return None;
}
};

generics
Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/usize-generic-argument-parent.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn foo() {
let x: usize<foo>; //~ ERROR const arguments are not allowed for this type
}

fn main() {}
9 changes: 9 additions & 0 deletions src/test/ui/usize-generic-argument-parent.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0109]: const arguments are not allowed for this type
--> $DIR/usize-generic-argument-parent.rs:2:18
|
LL | let x: usize<foo>;
| ^^^ const argument not allowed

error: aborting due to previous error

For more information about this error, try `rustc --explain E0109`.